DeepL: >Use a small font for the source text

pull/199/head
M66B 3 years ago
parent 3e9ed34c68
commit e040d12285

@ -1606,8 +1606,8 @@ public class FragmentCompose extends FragmentBase {
} else if (itemId == R.id.menu_answer_create) { } else if (itemId == R.id.menu_answer_create) {
onMenuAnswerCreate(); onMenuAnswerCreate();
return true; return true;
} else if (itemId == R.id.menu_translate_key) { } else if (itemId == R.id.menu_translate_configure) {
onMenuTranslateKey(); onMenuTranslateConfigure();
return true; return true;
} else if (item.getGroupId() == R.id.group_translate) { } else if (item.getGroupId() == R.id.group_translate) {
onMenuTranslate(item.getIntent().getStringExtra("target")); onMenuTranslate(item.getIntent().getStringExtra("target"));
@ -1981,9 +1981,9 @@ public class FragmentCompose extends FragmentBase {
fragmentTransaction.commit(); fragmentTransaction.commit();
} }
private void onMenuTranslateKey() { private void onMenuTranslateConfigure() {
FragmentDialogDeepL fragment = new FragmentDialogDeepL(); FragmentDialogDeepL fragment = new FragmentDialogDeepL();
fragment.show(getParentFragmentManager(), "deepl:translate"); fragment.show(getParentFragmentManager(), "deepl:configure");
} }
private Pair<Integer, Integer> getParagraph() { private Pair<Integer, Integer> getParagraph() {
@ -2059,6 +2059,9 @@ public class FragmentCompose extends FragmentBase {
if (activity == null) if (activity == null)
return; return;
Context context = getContext();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
// Insert translated text // Insert translated text
StringBuilder sb = new StringBuilder("\n"); StringBuilder sb = new StringBuilder("\n");
if (paragraph.second == edit.length() || if (paragraph.second == edit.length() ||
@ -2067,9 +2070,19 @@ public class FragmentCompose extends FragmentBase {
edit.insert(paragraph.second, sb + translated); edit.insert(paragraph.second, sb + translated);
etBody.setSelection(paragraph.second + sb.length() + translated.length()); 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 // Updated frequency
String key = "translated_" + args.getString("target"); String key = "translated_" + args.getString("target");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
int count = prefs.getInt(key, 0); int count = prefs.getInt(key, 0);
prefs.edit().putInt(key, count + 1).apply(); prefs.edit().putInt(key, count + 1).apply();
@ -6746,11 +6759,13 @@ public class FragmentCompose extends FragmentBase {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String domain = prefs.getString("deepl_domain", null); String domain = prefs.getString("deepl_domain", null);
String key = prefs.getString("deepl_key", 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); View view = LayoutInflater.from(context).inflate(R.layout.dialog_deepl, null);
final ImageButton ibInfo = view.findViewById(R.id.ibInfo); final ImageButton ibInfo = view.findViewById(R.id.ibInfo);
final EditText etDomain = view.findViewById(R.id.etDomain); final EditText etDomain = view.findViewById(R.id.etDomain);
final EditText etKey = view.findViewById(R.id.etKey); final EditText etKey = view.findViewById(R.id.etKey);
final CheckBox cbSmall = view.findViewById(R.id.cbSmall);
final TextView tvUsage = view.findViewById(R.id.tvUsage); final TextView tvUsage = view.findViewById(R.id.tvUsage);
ibInfo.setOnClickListener(new View.OnClickListener() { ibInfo.setOnClickListener(new View.OnClickListener() {
@ -6762,6 +6777,7 @@ public class FragmentCompose extends FragmentBase {
etDomain.setText(domain); etDomain.setText(domain);
etKey.setText(key); etKey.setText(key);
cbSmall.setChecked(small);
tvUsage.setVisibility(View.GONE); tvUsage.setVisibility(View.GONE);
@ -6772,7 +6788,6 @@ public class FragmentCompose extends FragmentBase {
new SimpleTask<Integer[]>() { new SimpleTask<Integer[]>() {
@Override @Override
protected Integer[] onExecute(Context context, Bundle args) throws Throwable { protected Integer[] onExecute(Context context, Bundle args) throws Throwable {
String key = args.getString("key");
return DeepL.getUsage(context); return DeepL.getUsage(context);
} }
@ -6811,6 +6826,7 @@ public class FragmentCompose extends FragmentBase {
else else
editor.putString("deepl_domain", domain); editor.putString("deepl_domain", domain);
} }
editor.putBoolean("deepl_small", cbSmall.isChecked());
editor.apply(); editor.apply();
} }
}) })

@ -1,73 +1,88 @@
<?xml version="1.0" encoding="utf-8"?> <?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" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="24dp"> android:padding="24dp"
android:scrollbarStyle="outsideOverlay">
<eu.faircode.email.FixedTextView <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/tvDeepL" android:layout_width="match_parent"
android:layout_width="0dp" android:layout_height="wrap_content">
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" />
<ImageButton <eu.faircode.email.FixedTextView
android:id="@+id/ibInfo" android:id="@+id/tvDeepL"
android:layout_width="36dp" android:layout_width="0dp"
android:layout_height="36dp" android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackgroundBorderless" android:labelFor="@+id/etKey"
android:contentDescription="@string/title_info" android:text="DeepL"
android:padding="6dp" android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:scaleType="fitCenter" app:layout_constraintEnd_toStartOf="@id/ibInfo"
android:tooltipText="@string/title_info" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="@id/tvDeepL"
app:srcCompat="@drawable/twotone_info_24" />
<eu.faircode.email.EditTextPlain <ImageButton
android:id="@+id/etDomain" android:id="@+id/ibInfo"
android:layout_width="0dp" android:layout_width="36dp"
android:layout_height="wrap_content" android:layout_height="36dp"
android:layout_marginTop="24dp" android:background="?android:attr/selectableItemBackgroundBorderless"
android:hint="api-free.deepl.com" android:contentDescription="@string/title_info"
android:imeOptions="actionDone" android:padding="6dp"
android:inputType="text" android:scaleType="fitCenter"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:tooltipText="@string/title_info"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@id/tvDeepL"
app:layout_constraintTop_toBottomOf="@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 <requestFocus />
android:id="@+id/etKey" </eu.faircode.email.EditTextPlain>
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
</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 <requestFocus />
android:id="@+id/tvUsage" </eu.faircode.email.EditTextPlain>
android:layout_width="wrap_content"
android:layout_height="wrap_content" <CheckBox
android:layout_marginTop="12dp" android:id="@+id/cbSmall"
android:text="Usage" android:layout_width="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent" android:layout_marginTop="12dp"
app:layout_constraintTop_toBottomOf="@id/etKey" /> android:text="@string/title_translate_small"
</androidx.constraintlayout.widget.ConstraintLayout> 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> <menu>
<group android:id="@+id/group_translate"> <group android:id="@+id/group_translate">
<item <item
android:id="@+id/menu_translate_key" android:id="@+id/menu_translate_configure"
android:title="@string/title_translate_key" /> android:title="@string/title_translate_configure" />
</group> </group>
</menu> </menu>
</item> </item>

@ -1108,8 +1108,10 @@
<string name="title_insert_template">Insert template</string> <string name="title_insert_template">Insert template</string>
<string name="title_create_template">Create template</string> <string name="title_create_template">Create template</string>
<string name="title_translate">Translate</string> <string name="title_translate">Translate</string>
<string name="title_translate_configure">Configure &#8230;</string>
<string name="title_translate_key">Enter key</string> <string name="title_translate_key">Enter key</string>
<string name="title_translating">Translating &#8230;</string> <string name="title_translating">Translating &#8230;</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_plain_text">Edit as plain text</string>
<string name="title_edit_formatted_text">Edit as reformatted text</string> <string name="title_edit_formatted_text">Edit as reformatted text</string>
<string name="title_select_certificate">Select public key</string> <string name="title_select_certificate">Select public key</string>

Loading…
Cancel
Save