fix some warnings, disable "with gesture typing" text

This commit is contained in:
Helium314 2023-09-07 15:54:08 +02:00
parent 27fdd6d081
commit c6efd5a843
9 changed files with 72 additions and 111 deletions

View file

@ -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());
}
}
}

View file

@ -118,8 +118,7 @@ public final class CorrectionSettingsFragment extends SubScreenFragment
}
private void overwriteUserDictionaryPreference(final Preference userDictionaryPreference) {
final Activity activity = getActivity();
final TreeSet<String> localeList = UserDictionaryList.getUserDictionaryLocalesSet(activity);
final TreeSet<String> 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.

View file

@ -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

View file

@ -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;
}
}

View file

@ -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) {

View file

@ -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;
}
}
}

View file

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Before After
Before After

View file

@ -20,7 +20,6 @@
<string name="key_preview_popup_dismiss_delay">"কী প\'পআপৰ প্ৰত্যাখ্যান বিলম্ব"</string>
<string name="key_preview_popup_dismiss_no_delay">"কোনো বিলম্ব নাই"</string>
<string name="key_preview_popup_dismiss_default_delay">"ডিফ\'ল্ট"</string>
<string name="abbreviation_unit_milliseconds">"</string>
<string name="settings_system_default">"ছিষ্টেম ডিফ\'ল্ট"</string>
<string name="use_contacts_dict">"সম্পৰ্ক নামৰ পৰামৰ্শ দিয়ক"</string>
<string name="use_contacts_dict_summary">"পৰামৰ্শ আৰু শুধৰণিৰ বাবে সম্পৰ্কসূচীৰ পৰা নামবোৰ ব্যৱহাৰ কৰক"</string>
@ -67,7 +66,6 @@
<string name="prefs_enable_emoji_alt_physical_key">"কায়িক কীব\'ৰ্ডৰ বাবে ইম\'জী"</string>
<string name="prefs_enable_emoji_alt_physical_key_summary">"কায়িক Alt কীয়ে ইম\'জী পেলেট দেখুৱায়"</string>
<string name="button_default">"ডিফ\'ল্ট"</string>
<string name="setup_welcome_title">"</string>
<string name="setup_welcome_additional_description">"আঙুলি পিছলাই দিয়া নিৰ্দেশেৰে টাইপ কৰাৰ সুবিধাৰ সৈতে"</string>
<string name="setup_start_action">"আৰম্ভ কৰক"</string>
<string name="setup_next_action">"পৰৱৰ্তী পদক্ষেপ"</string>

View file

@ -162,7 +162,6 @@
<string name="settings_category_suggestions">Javaslatok</string>
<string name="settings_category_experimental">Kísérlet</string>
<string name="settings_category_miscellaneous">Vegyes</string>
<string name="abbreviation_unit_minutes">&lt;xliff:g xmlns:xliff=\"urn:oasis:names:tc:xliff:document:1.2\" id=\"MINUTES\"&gt;perc.</string>
<string name="settings_no_limit">Nincs korlát</string>
<string name="enable_clipboard_history">A vágólap előzményeinek engedélyezése</string>
<string name="theme_family">Téma család</string>