From c6efd5a84383c0596f5e316e8eac3520c6fc3fb6 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Thu, 7 Sep 2023 15:54:08 +0200 Subject: [PATCH] fix some warnings, disable "with gesture typing" text --- .../settings/AdvancedSettingsFragment.java | 89 +++++++----------- .../settings/CorrectionSettingsFragment.java | 3 +- .../settings/PreferencesSettingsFragment.java | 6 +- .../settings/SeekBarDialogPreference.java | 1 - .../latin/settings/SettingsFragment.java | 13 +-- .../latin/setup/SetupWizardActivity.java | 68 +++++-------- .../setup_welcome_image.png | Bin app/src/main/res/values-as/strings.xml | 2 - app/src/main/res/values-hu-rZZ/strings.xml | 1 - 9 files changed, 72 insertions(+), 111 deletions(-) rename app/src/main/res/{raw => drawable-nodpi}/setup_welcome_image.png (100%) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/AdvancedSettingsFragment.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/AdvancedSettingsFragment.java index a2a5acc5e..8494e5d2a 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/AdvancedSettingsFragment.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/AdvancedSettingsFragment.java @@ -18,7 +18,6 @@ package org.dslul.openboard.inputmethod.latin.settings; import android.app.Activity; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; @@ -31,9 +30,9 @@ import androidx.preference.Preference; import org.dslul.openboard.inputmethod.latin.AudioAndHapticFeedbackManager; import org.dslul.openboard.inputmethod.latin.R; import org.dslul.openboard.inputmethod.latin.SystemBroadcastReceiver; +import org.dslul.openboard.inputmethod.latin.common.FileUtils; import org.dslul.openboard.inputmethod.latin.define.JniLibName; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -56,8 +55,7 @@ public final class AdvancedSettingsFragment extends SubScreenFragment { super.onCreate(icicle); addPreferencesFromResource(R.xml.prefs_screen_advanced); - final Resources res = getResources(); - final Context context = getActivity(); + final Context context = requireContext(); // When we are called from the Settings application but we are not already running, some // singleton and utility classes may not have been initialized. We have to call @@ -71,44 +69,35 @@ public final class AdvancedSettingsFragment extends SubScreenFragment { } setupKeyLongpressTimeoutSettings(); - final Preference bla = findPreference("load_gesture_library"); - if (bla != null) { - bla.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - // get architecture for telling user which file to use - String abi; - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { - abi = Build.SUPPORTED_ABIS[0]; - } else { - abi = Build.CPU_ABI; - } - // show delete / add dialog - final AlertDialog.Builder builder = new AlertDialog.Builder(context) - .setTitle(R.string.load_gesture_library) - .setMessage(context.getString(R.string.load_gesture_library_message, abi)) - .setPositiveButton(R.string.load_gesture_library_button_load, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - final Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT) - .addCategory(Intent.CATEGORY_OPENABLE) - .setType("application/octet-stream"); - startActivityForResult(intent, REQUEST_CODE_GESTURE_LIBRARY); - } - }) - .setNegativeButton(android.R.string.cancel, null); - libfile = new File(context.getFilesDir().getAbsolutePath() + File.separator + JniLibName.JNI_LIB_IMPORT_FILE_NAME); - if (libfile.exists()) - builder.setNeutralButton(R.string.load_gesture_library_button_delete, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - libfile.delete(); - Runtime.getRuntime().exit(0); - } - }); - builder.show(); - return true; + final Preference loadGestureLibrary = findPreference("load_gesture_library"); + if (loadGestureLibrary != null) { + loadGestureLibrary.setOnPreferenceClickListener(preference -> { + // get architecture for telling user which file to use + String abi; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + abi = Build.SUPPORTED_ABIS[0]; + } else { + abi = Build.CPU_ABI; } + // show delete / add dialog + final AlertDialog.Builder builder = new AlertDialog.Builder(context) + .setTitle(R.string.load_gesture_library) + .setMessage(context.getString(R.string.load_gesture_library_message, abi)) + .setPositiveButton(R.string.load_gesture_library_button_load, (dialogInterface, i) -> { + final Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT) + .addCategory(Intent.CATEGORY_OPENABLE) + .setType("application/octet-stream"); + startActivityForResult(intent, REQUEST_CODE_GESTURE_LIBRARY); + }) + .setNegativeButton(android.R.string.cancel, null); + libfile = new File(context.getFilesDir().getAbsolutePath() + File.separator + JniLibName.JNI_LIB_IMPORT_FILE_NAME); + if (libfile.exists()) + builder.setNeutralButton(R.string.load_gesture_library_button_delete, (dialogInterface, i) -> { + libfile.delete(); + Runtime.getRuntime().exit(0); + }); + builder.show(); + return true; }); } } @@ -118,17 +107,11 @@ public final class AdvancedSettingsFragment extends SubScreenFragment { if (requestCode != REQUEST_CODE_GESTURE_LIBRARY || resultCode != Activity.RESULT_OK || resultData == null) return; if (resultData.getData() != null && libfile != null) { try { - FileOutputStream out = new FileOutputStream(libfile); - final InputStream in = getActivity().getContentResolver().openInputStream(resultData.getData()); - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - } - out.flush(); - Runtime.getRuntime().exit(0); + final InputStream in = requireContext().getContentResolver().openInputStream(resultData.getData()); + FileUtils.copyStreamToNewFile(in, libfile); + Runtime.getRuntime().exit(0); // exit will restart the app, so library will be loaded } catch (IOException e) { - // should inform user + // todo: should inform user } } } @@ -165,7 +148,7 @@ public final class AdvancedSettingsFragment extends SubScreenFragment { @Override public String getValueText(final int value) { - return res.getString(R.string.abbreviation_unit_milliseconds, value); + return res.getString(R.string.abbreviation_unit_milliseconds, Integer.toString(value)); } @Override @@ -176,7 +159,7 @@ public final class AdvancedSettingsFragment extends SubScreenFragment { @Override public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) { if (key.equals(Settings.PREF_SHOW_SETUP_WIZARD_ICON)) { - SystemBroadcastReceiver.toggleAppIcon(getActivity()); + SystemBroadcastReceiver.toggleAppIcon(requireContext()); } } } diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CorrectionSettingsFragment.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CorrectionSettingsFragment.java index 3f4c2a657..c7689364c 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CorrectionSettingsFragment.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CorrectionSettingsFragment.java @@ -118,8 +118,7 @@ public final class CorrectionSettingsFragment extends SubScreenFragment } private void overwriteUserDictionaryPreference(final Preference userDictionaryPreference) { - final Activity activity = getActivity(); - final TreeSet localeList = UserDictionaryList.getUserDictionaryLocalesSet(activity); + final TreeSet localeList = UserDictionaryList.getUserDictionaryLocalesSet(requireActivity()); if (null == localeList) { // The locale list is null if and only if the user dictionary service is // not present or disabled. In this case we need to remove the preference. diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/PreferencesSettingsFragment.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/PreferencesSettingsFragment.java index 79de4afc3..2ad231308 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/PreferencesSettingsFragment.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/PreferencesSettingsFragment.java @@ -133,7 +133,7 @@ public final class PreferencesSettingsFragment extends SubScreenFragment { if (value < 0) { return res.getString(R.string.settings_system_default); } - return res.getString(R.string.abbreviation_unit_milliseconds, value); + return res.getString(R.string.abbreviation_unit_milliseconds, Integer.toString(value)); } }); } @@ -146,7 +146,7 @@ public final class PreferencesSettingsFragment extends SubScreenFragment { } final SharedPreferences prefs = getSharedPreferences(); final Resources res = getResources(); - final AudioManager am = (AudioManager)getActivity().getSystemService(Context.AUDIO_SERVICE); + final AudioManager am = (AudioManager) requireContext().getSystemService(Context.AUDIO_SERVICE); pref.setInterface(new SeekBarDialogPreference.ValueProxy() { private static final float PERCENTAGE_FLOAT = 100.0f; @@ -228,7 +228,7 @@ public final class PreferencesSettingsFragment extends SubScreenFragment { if (value <= 0) { return res.getString(R.string.settings_no_limit); } - return res.getString(R.string.abbreviation_unit_minutes, value); + return res.getString(R.string.abbreviation_unit_minutes, Integer.toString(value)); } @Override diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SeekBarDialogPreference.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SeekBarDialogPreference.java index 7a5262718..33cb57d77 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SeekBarDialogPreference.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SeekBarDialogPreference.java @@ -123,7 +123,6 @@ public final class SeekBarDialogPreference extends Preference final int value = getClippedValueFromProgress(mSeekBar.getProgress()); setSummary(mValueProxy.getValueText(value)); mValueProxy.writeValue(value, key); - return; } } diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SettingsFragment.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SettingsFragment.java index 8baa03027..78925bd6a 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SettingsFragment.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SettingsFragment.java @@ -27,6 +27,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.inputmethod.InputMethodSubtype; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; @@ -104,7 +105,7 @@ public final class SettingsFragment extends PreferenceFragmentCompat { } @Override - public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { + public void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInflater inflater) { if (FeedbackUtils.isHelpAndFeedbackFormSupported()) { menu.add(NO_MENU_GROUP, MENU_HELP_AND_FEEDBACK /* itemId */, MENU_HELP_AND_FEEDBACK /* order */, R.string.help_and_feedback); @@ -116,7 +117,7 @@ public final class SettingsFragment extends PreferenceFragmentCompat { } @Override - public boolean onOptionsItemSelected(final MenuItem item) { + public boolean onOptionsItemSelected(@NonNull final MenuItem item) { final Activity activity = getActivity(); if (!isUserSetupComplete(activity)) { // If setup is not complete, it's not safe to launch Help or other activities @@ -151,14 +152,14 @@ public final class SettingsFragment extends PreferenceFragmentCompat { for (final InputMethodSubtype subtype : subtypes) { if (sb.length() > 0) sb.append(", "); - sb.append(subtype.getDisplayName(getActivity(), getActivity().getPackageName(), getActivity().getApplicationInfo())); + sb.append(subtype.getDisplayName(getActivity(), requireContext().getPackageName(), requireContext().getApplicationInfo())); } return sb.toString(); } private void askAboutCrashReports() { // find crash report files - final File dir = getActivity().getExternalFilesDir(null); + final File dir = requireContext().getExternalFilesDir(null); if (dir == null) return; final File[] allFiles = dir.listFiles(); if (allFiles == null) return; @@ -168,7 +169,7 @@ public final class SettingsFragment extends PreferenceFragmentCompat { crashReportFiles.add(file); } if (crashReportFiles.isEmpty()) return; - new AlertDialog.Builder(getActivity()) + new AlertDialog.Builder(requireContext()) .setMessage("Crash report files found") .setPositiveButton("get", (dialogInterface, i) -> { final Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); @@ -196,7 +197,7 @@ public final class SettingsFragment extends PreferenceFragmentCompat { if (uri == null) return; final OutputStream os; try { - os = getActivity().getContentResolver().openOutputStream(uri); + os = requireContext().getContentResolver().openOutputStream(uri); final BufferedOutputStream bos = new BufferedOutputStream(os); final ZipOutputStream z = new ZipOutputStream(bos); for (File file : crashReportFiles) { diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/setup/SetupWizardActivity.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/setup/SetupWizardActivity.java index 23621b3b2..3ddde2b56 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/setup/SetupWizardActivity.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/setup/SetupWizardActivity.java @@ -20,7 +20,6 @@ import android.app.Activity; import android.content.ContentResolver; import android.content.Intent; import android.content.res.Resources; -import android.media.MediaPlayer; import android.net.Uri; import android.os.Bundle; import android.os.Message; @@ -93,15 +92,13 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL if (setupWizardActivity == null) { return; } - switch (msg.what) { - case MSG_POLLING_IME_SETTINGS: + if (msg.what == MSG_POLLING_IME_SETTINGS) { if (UncachedInputMethodManagerUtils.isThisImeEnabled(setupWizardActivity, mImmInHandler)) { setupWizardActivity.invokeSetupWizardOfThisIme(); return; } startPollingImeSettings(); - break; } } @@ -137,6 +134,10 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL final TextView welcomeTitle = findViewById(R.id.setup_welcome_title); welcomeTitle.setText(getString(R.string.setup_welcome_title, applicationName)); + // disable the "with gesture typing" for now, as it's not really correct, even though it can be enabled... + final TextView welcomeDescription = findViewById(R.id.setup_welcome_description); + welcomeDescription.setText(""); + mSetupScreen = findViewById(R.id.setup_steps_screen); final TextView stepsTitle = findViewById(R.id.setup_title); stepsTitle.setText(getString(R.string.setup_steps_title, applicationName)); @@ -153,12 +154,9 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL R.string.setup_step1_finished_instruction, R.drawable.ic_setup_step1, R.string.setup_step1_action); final SettingsPoolingHandler handler = mHandler; - step1.setAction(new Runnable() { - @Override - public void run() { - invokeLanguageAndInputSettings(); - handler.startPollingImeSettings(); - } + step1.setAction(() -> { + invokeLanguageAndInputSettings(); + handler.startPollingImeSettings(); }); mSetupStepGroup.addStep(step1); @@ -167,12 +165,7 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL R.string.setup_step2_title, R.string.setup_step2_instruction, 0 /* finishedInstruction */, R.drawable.ic_setup_step2, R.string.setup_step2_action); - step2.setAction(new Runnable() { - @Override - public void run() { - invokeInputMethodPicker(); - } - }); + step2.setAction(this::invokeInputMethodPicker); mSetupStepGroup.addStep(step2); final SetupStep step3 = new SetupStep(STEP_3, applicationName, @@ -180,14 +173,11 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL R.string.setup_step3_title, R.string.setup_step3_instruction, 0 /* finishedInstruction */, R.drawable.ic_setup_step3, R.string.setup_step3_action); - step3.setAction(new Runnable() { - @Override - public void run() { - final Intent intent = new Intent(getApplicationContext(), SettingsActivity.class); - intent.setAction(Intent.ACTION_VIEW); - startActivity(intent); - finish(); - } + step3.setAction(() -> { + final Intent intent = new Intent(getApplicationContext(), SettingsActivity.class); + intent.setAction(Intent.ACTION_VIEW); + startActivity(intent); + finish(); }); mSetupStepGroup.addStep(step3); @@ -197,22 +187,16 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL .path(Integer.toString(R.raw.setup_welcome_video)) .build(); final VideoView welcomeVideoView = findViewById(R.id.setup_welcome_video); - welcomeVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { - @Override - public void onPrepared(final MediaPlayer mp) { - // Now VideoView has been laid-out and ready to play, remove background of it to - // reveal the video. - welcomeVideoView.setBackgroundResource(0); - mp.setLooping(true); - } + welcomeVideoView.setOnPreparedListener(mp -> { + // Now VideoView has been laid-out and ready to play, remove background of it to + // reveal the video. + welcomeVideoView.setBackgroundResource(0); + mp.setLooping(true); }); - welcomeVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() { - @Override - public boolean onError(final MediaPlayer mp, final int what, final int extra) { - Log.e(TAG, "Playing welcome video causes error: what=" + what + " extra=" + extra); - hideWelcomeVideoAndShowWelcomeImage(); - return true; - } + welcomeVideoView.setOnErrorListener((mp, what, extra) -> { + Log.e(TAG, "Playing welcome video causes error: what=" + what + " extra=" + extra); + hideWelcomeVideoAndShowWelcomeImage(); + return true; }); mWelcomeVideoView = welcomeVideoView; mWelcomeImageView = findViewById(R.id.setup_welcome_image); @@ -365,7 +349,7 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL void hideWelcomeVideoAndShowWelcomeImage() { mWelcomeVideoView.setVisibility(View.GONE); - mWelcomeImageView.setImageResource(R.raw.setup_welcome_image); + mWelcomeImageView.setImageResource(R.drawable.setup_welcome_image); mWelcomeImageView.setVisibility(View.VISIBLE); } @@ -471,10 +455,8 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL @Override public void onClick(final View v) { - if (v == mActionLabel && mAction != null) { + if (v == mActionLabel && mAction != null) mAction.run(); - return; - } } } diff --git a/app/src/main/res/raw/setup_welcome_image.png b/app/src/main/res/drawable-nodpi/setup_welcome_image.png similarity index 100% rename from app/src/main/res/raw/setup_welcome_image.png rename to app/src/main/res/drawable-nodpi/setup_welcome_image.png diff --git a/app/src/main/res/values-as/strings.xml b/app/src/main/res/values-as/strings.xml index 941adcb08..92d7146a1 100644 --- a/app/src/main/res/values-as/strings.xml +++ b/app/src/main/res/values-as/strings.xml @@ -20,7 +20,6 @@ "কী প\'পআপৰ প্ৰত্যাখ্যান বিলম্ব" "কোনো বিলম্ব নাই" "ডিফ\'ল্ট" - " "ছিষ্টেম ডিফ\'ল্ট" "সম্পৰ্ক নামৰ পৰামৰ্শ দিয়ক" "পৰামৰ্শ আৰু শুধৰণিৰ বাবে সম্পৰ্কসূচীৰ পৰা নামবোৰ ব্যৱহাৰ কৰক" @@ -67,7 +66,6 @@ "কায়িক কীব\'ৰ্ডৰ বাবে ইম\'জী" "কায়িক Alt কীয়ে ইম\'জী পেলেট দেখুৱায়" "ডিফ\'ল্ট" - " "আঙুলি পিছলাই দিয়া নিৰ্দেশেৰে টাইপ কৰাৰ সুবিধাৰ সৈতে" "আৰম্ভ কৰক" "পৰৱৰ্তী পদক্ষেপ" diff --git a/app/src/main/res/values-hu-rZZ/strings.xml b/app/src/main/res/values-hu-rZZ/strings.xml index acd14bd1b..48bea3cf3 100644 --- a/app/src/main/res/values-hu-rZZ/strings.xml +++ b/app/src/main/res/values-hu-rZZ/strings.xml @@ -162,7 +162,6 @@ Javaslatok Kísérlet Vegyes - <xliff:g xmlns:xliff=\"urn:oasis:names:tc:xliff:document:1.2\" id=\"MINUTES\">perc. Nincs korlát A vágólap előzményeinek engedélyezése Téma család