mirror of https://github.com/M66B/FairEmail.git
DeepL: >Use a small font for the source text
This commit is contained in:
parent
3e9ed34c68
commit
e040d12285
|
@ -1606,8 +1606,8 @@ public class FragmentCompose extends FragmentBase {
|
|||
} else if (itemId == R.id.menu_answer_create) {
|
||||
onMenuAnswerCreate();
|
||||
return true;
|
||||
} else if (itemId == R.id.menu_translate_key) {
|
||||
onMenuTranslateKey();
|
||||
} else if (itemId == R.id.menu_translate_configure) {
|
||||
onMenuTranslateConfigure();
|
||||
return true;
|
||||
} else if (item.getGroupId() == R.id.group_translate) {
|
||||
onMenuTranslate(item.getIntent().getStringExtra("target"));
|
||||
|
@ -1981,9 +1981,9 @@ public class FragmentCompose extends FragmentBase {
|
|||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
private void onMenuTranslateKey() {
|
||||
private void onMenuTranslateConfigure() {
|
||||
FragmentDialogDeepL fragment = new FragmentDialogDeepL();
|
||||
fragment.show(getParentFragmentManager(), "deepl:translate");
|
||||
fragment.show(getParentFragmentManager(), "deepl:configure");
|
||||
}
|
||||
|
||||
private Pair<Integer, Integer> getParagraph() {
|
||||
|
@ -2059,6 +2059,9 @@ public class FragmentCompose extends FragmentBase {
|
|||
if (activity == null)
|
||||
return;
|
||||
|
||||
Context context = getContext();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
// Insert translated text
|
||||
StringBuilder sb = new StringBuilder("\n");
|
||||
if (paragraph.second == edit.length() ||
|
||||
|
@ -2067,9 +2070,19 @@ public class FragmentCompose extends FragmentBase {
|
|||
edit.insert(paragraph.second, sb + translated);
|
||||
etBody.setSelection(paragraph.second + sb.length() + translated.length());
|
||||
|
||||
boolean small = prefs.getBoolean("deepl_small", false);
|
||||
if (small) {
|
||||
RelativeSizeSpan[] spans = edit.getSpans(
|
||||
paragraph.first, paragraph.second, RelativeSizeSpan.class);
|
||||
for (RelativeSizeSpan span : spans)
|
||||
edit.removeSpan(span);
|
||||
edit.setSpan(new RelativeSizeSpan(HtmlHelper.FONT_SMALL),
|
||||
paragraph.first, paragraph.second,
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
// Updated frequency
|
||||
String key = "translated_" + args.getString("target");
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
int count = prefs.getInt(key, 0);
|
||||
prefs.edit().putInt(key, count + 1).apply();
|
||||
|
||||
|
@ -6746,11 +6759,13 @@ public class FragmentCompose extends FragmentBase {
|
|||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String domain = prefs.getString("deepl_domain", null);
|
||||
String key = prefs.getString("deepl_key", null);
|
||||
boolean small = prefs.getBoolean("deepl_small", false);
|
||||
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.dialog_deepl, null);
|
||||
final ImageButton ibInfo = view.findViewById(R.id.ibInfo);
|
||||
final EditText etDomain = view.findViewById(R.id.etDomain);
|
||||
final EditText etKey = view.findViewById(R.id.etKey);
|
||||
final CheckBox cbSmall = view.findViewById(R.id.cbSmall);
|
||||
final TextView tvUsage = view.findViewById(R.id.tvUsage);
|
||||
|
||||
ibInfo.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -6762,6 +6777,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
etDomain.setText(domain);
|
||||
etKey.setText(key);
|
||||
cbSmall.setChecked(small);
|
||||
|
||||
tvUsage.setVisibility(View.GONE);
|
||||
|
||||
|
@ -6772,7 +6788,6 @@ public class FragmentCompose extends FragmentBase {
|
|||
new SimpleTask<Integer[]>() {
|
||||
@Override
|
||||
protected Integer[] onExecute(Context context, Bundle args) throws Throwable {
|
||||
String key = args.getString("key");
|
||||
return DeepL.getUsage(context);
|
||||
}
|
||||
|
||||
|
@ -6811,6 +6826,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
else
|
||||
editor.putString("deepl_domain", domain);
|
||||
}
|
||||
editor.putBoolean("deepl_small", cbSmall.isChecked());
|
||||
editor.apply();
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1,73 +1,88 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<eu.faircode.email.ScrollViewEx xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="24dp">
|
||||
android:padding="24dp"
|
||||
android:scrollbarStyle="outsideOverlay">
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvDeepL"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:labelFor="@+id/etKey"
|
||||
android:text="DeepL"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||
app:layout_constraintEnd_toStartOf="@id/ibInfo"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ibInfo"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/title_info"
|
||||
android:padding="6dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:tooltipText="@string/title_info"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/tvDeepL"
|
||||
app:srcCompat="@drawable/twotone_info_24" />
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvDeepL"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:labelFor="@+id/etKey"
|
||||
android:text="DeepL"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||
app:layout_constraintEnd_toStartOf="@id/ibInfo"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<eu.faircode.email.EditTextPlain
|
||||
android:id="@+id/etDomain"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:hint="api-free.deepl.com"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="text"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvDeepL">
|
||||
<ImageButton
|
||||
android:id="@+id/ibInfo"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/title_info"
|
||||
android:padding="6dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:tooltipText="@string/title_info"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/tvDeepL"
|
||||
app:srcCompat="@drawable/twotone_info_24" />
|
||||
|
||||
<requestFocus />
|
||||
</eu.faircode.email.EditTextPlain>
|
||||
<eu.faircode.email.EditTextPlain
|
||||
android:id="@+id/etDomain"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:hint="api-free.deepl.com"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="text"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvDeepL">
|
||||
|
||||
<eu.faircode.email.EditTextPlain
|
||||
android:id="@+id/etKey"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:hint="@string/title_translate_key"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="text"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etDomain">
|
||||
<requestFocus />
|
||||
</eu.faircode.email.EditTextPlain>
|
||||
|
||||
<requestFocus />
|
||||
</eu.faircode.email.EditTextPlain>
|
||||
<eu.faircode.email.EditTextPlain
|
||||
android:id="@+id/etKey"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:hint="@string/title_translate_key"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="text"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etDomain">
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvUsage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="Usage"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etKey" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
<requestFocus />
|
||||
</eu.faircode.email.EditTextPlain>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_translate_small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etKey" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvUsage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="Usage"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbSmall" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</eu.faircode.email.ScrollViewEx>
|
||||
|
|
|
@ -74,8 +74,8 @@
|
|||
<menu>
|
||||
<group android:id="@+id/group_translate">
|
||||
<item
|
||||
android:id="@+id/menu_translate_key"
|
||||
android:title="@string/title_translate_key" />
|
||||
android:id="@+id/menu_translate_configure"
|
||||
android:title="@string/title_translate_configure" />
|
||||
</group>
|
||||
</menu>
|
||||
</item>
|
||||
|
|
|
@ -1108,8 +1108,10 @@
|
|||
<string name="title_insert_template">Insert template</string>
|
||||
<string name="title_create_template">Create template</string>
|
||||
<string name="title_translate">Translate</string>
|
||||
<string name="title_translate_configure">Configure …</string>
|
||||
<string name="title_translate_key">Enter key</string>
|
||||
<string name="title_translating">Translating …</string>
|
||||
<string name="title_translate_small">Use a small font for the source text</string>
|
||||
<string name="title_edit_plain_text">Edit as plain text</string>
|
||||
<string name="title_edit_formatted_text">Edit as reformatted text</string>
|
||||
<string name="title_select_certificate">Select public key</string>
|
||||
|
|
Loading…
Reference in New Issue