Skip to content

Commit

Permalink
getSystemService ANR and no browser installed (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkkr authored Feb 1, 2025
1 parent c4601fb commit c2160d3
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 22 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
compileSdk 35
minSdkVersion 19
targetSdkVersion 35
versionCode 110
versionName "5.24"
versionCode 111
versionName "5.25"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import android.view.HapticFeedbackConstants;
import android.view.View;

import java.util.concurrent.Executors;

import rkr.simplekeyboard.inputmethod.latin.common.Constants;
import rkr.simplekeyboard.inputmethod.latin.settings.SettingsValues;

Expand Down Expand Up @@ -54,8 +56,10 @@ public static void init(final Context context) {
}

private void initInternal(final Context context) {
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
Executors.newSingleThreadExecutor().execute(() -> {
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
});
}

public boolean hasVibrator() {
Expand Down Expand Up @@ -99,7 +103,14 @@ public void performAudioFeedback(final int code) {
sound = AudioManager.FX_KEYPRESS_STANDARD;
break;
}
mAudioManager.playSoundEffect(sound, mSettingsValues.mKeypressSoundVolume);
playSoundEffect(sound, mSettingsValues.mKeypressSoundVolume);
}

public void playSoundEffect(final int effectType, final float volume) {
if (mAudioManager == null) {
return;
}
mAudioManager.playSoundEffect(effectType, volume);
}

public void performHapticFeedback(final View viewToPerformHapticFeedbackOn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ private void setupKeypressSoundVolumeSettings() {
}
final SharedPreferences prefs = getSharedPreferences();
final Resources res = getResources();
final AudioManager am = (AudioManager)getActivity().getSystemService(Context.AUDIO_SERVICE);
pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
private static final float PERCENTAGE_FLOAT = 100.0f;

Expand Down Expand Up @@ -153,7 +152,7 @@ public String getValueText(final int value) {

@Override
public void feedbackValue(final int value) {
am.playSoundEffect(
AudioAndHapticFeedbackManager.getInstance().playSoundEffect(
AudioManager.FX_KEYPRESS_STANDARD, getValueFromPercentage(value));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@

package rkr.simplekeyboard.inputmethod.latin.settings;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceScreen;
import android.util.Log;

import rkr.simplekeyboard.inputmethod.R;
import rkr.simplekeyboard.inputmethod.latin.utils.ApplicationUtils;

public final class SettingsFragment extends InputMethodSettingsFragment {
private static final String TAG = "SettingsFragment";

@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
Expand All @@ -31,5 +39,30 @@ public void onCreate(final Bundle icicle) {
final PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.setTitle(
ApplicationUtils.getActivityTitleResId(getActivity(), SettingsActivity.class));
final Resources res = getResources();

findPreference("privacy_policy").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
openUrl(res.getString(R.string.privacy_policy_url));
return true;
}
});
findPreference("license").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
openUrl(res.getString(R.string.license_url));
return true;
}
});
}

private void openUrl(String uri) {
try {
final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(browserIntent);
} catch (ActivityNotFoundException e) {
Log.e(TAG, "Browser not found");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ public static List<Subtype> getDefaultSubtypes(final Resources resources) {
if (bestLocale != null && !addedLocales.contains(bestLocale)) {
addedLocales.add(bestLocale);
final String bestLocaleString = LocaleUtils.getLocaleString(bestLocale);
subtypes.add(getDefaultSubtype(bestLocaleString, resources));
final Subtype bestSubtype = getDefaultSubtype(bestLocaleString, resources);
if (bestSubtype != null) {
subtypes.add(bestSubtype);
}
}
}
if (subtypes.size() == 0) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings-appname.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@
<resources>
<string name="english_ime_name" translatable="false">Simple Keyboard</string>
<string name="english_ime_settings" translatable="false">Simple Keyboard Settings</string>
<string name="privacy_policy_url" translatable="false">https://github.com/rkkr/simple-keyboard/blob/master/PRIVACY.md</string>
<string name="license_url" translatable="false">https://github.com/rkkr/simple-keyboard/blob/master/LICENSE</string>
</resources>
16 changes: 4 additions & 12 deletions app/src/main/res/xml/prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,9 @@
android:title="@string/settings_screen_appearance"
android:key="screen_appearance" />
<Preference
android:title="@string/privacy_policy">
<intent
android:action="android.intent.action.VIEW"
android:data="https://github.com/rkkr/simple-keyboard/blob/master/PRIVACY.md"
/>
</Preference>
android:title="@string/privacy_policy"
android:key="privacy_policy" />
<Preference
android:title="@string/license">
<intent
android:action="android.intent.action.VIEW"
android:data="https://github.com/rkkr/simple-keyboard/blob/master/LICENSE"
/>
</Preference>
android:title="@string/license"
android:key="license" />
</PreferenceScreen>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.7.3'
classpath 'com.android.tools.build:gradle:8.8.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip

0 comments on commit c2160d3

Please sign in to comment.