Initial setup screen (#212)
* enabled the launcher icon * added an initial setup screen, for when TT9 is disabled * documentation update
This commit is contained in:
parent
eee786ce56
commit
787ba1c1ef
19 changed files with 230 additions and 16 deletions
|
|
@ -0,0 +1,27 @@
|
|||
package io.github.sspanak.tt9.ime.helpers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
|
||||
public class GlobalKeyboardSettings {
|
||||
private final InputMethodManager inputManager;
|
||||
private final String packageName;
|
||||
|
||||
|
||||
public GlobalKeyboardSettings(Context context, InputMethodManager inputManager) {
|
||||
this.inputManager = inputManager;
|
||||
packageName = context.getPackageName();
|
||||
}
|
||||
|
||||
|
||||
public boolean isTT9Enabled() {
|
||||
for (final InputMethodInfo imeInfo : inputManager.getEnabledInputMethodList()) {
|
||||
if (packageName.equals(imeInfo.getPackageName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package io.github.sspanak.tt9.preferences;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
|
|
@ -14,20 +15,24 @@ import androidx.preference.PreferenceFragmentCompat;
|
|||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.db.DictionaryDb;
|
||||
import io.github.sspanak.tt9.db.DictionaryLoader;
|
||||
import io.github.sspanak.tt9.ime.helpers.GlobalKeyboardSettings;
|
||||
import io.github.sspanak.tt9.ime.helpers.InputModeValidator;
|
||||
import io.github.sspanak.tt9.preferences.screens.AppearanceScreen;
|
||||
import io.github.sspanak.tt9.preferences.screens.DictionariesScreen;
|
||||
import io.github.sspanak.tt9.preferences.screens.HotkeysScreen;
|
||||
import io.github.sspanak.tt9.preferences.screens.SetupScreen;
|
||||
import io.github.sspanak.tt9.preferences.screens.KeyPadScreen;
|
||||
import io.github.sspanak.tt9.preferences.screens.MainSettingsScreen;
|
||||
import io.github.sspanak.tt9.ui.DictionaryLoadingBar;
|
||||
|
||||
public class PreferencesActivity extends AppCompatActivity implements PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
|
||||
public SettingsStore settings;
|
||||
public GlobalKeyboardSettings globalKeyboardSettings;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
globalKeyboardSettings = new GlobalKeyboardSettings(this, (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE));
|
||||
settings = new SettingsStore(this);
|
||||
applyTheme();
|
||||
|
||||
|
|
@ -78,7 +83,7 @@ public class PreferencesActivity extends AppCompatActivity implements Preference
|
|||
case "KeyPad":
|
||||
return new KeyPadScreen(this);
|
||||
default:
|
||||
return new MainSettingsScreen(this);
|
||||
return globalKeyboardSettings.isTT9Enabled() ? new MainSettingsScreen(this) : new SetupScreen(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -107,7 +112,7 @@ public class PreferencesActivity extends AppCompatActivity implements Preference
|
|||
}
|
||||
|
||||
setContentView(R.layout.preferences_container);
|
||||
displayScreen(new MainSettingsScreen(this), false);
|
||||
displayScreen(getScreen("default"), false);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package io.github.sspanak.tt9.preferences.items;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import io.github.sspanak.tt9.preferences.PreferencesActivity;
|
||||
|
||||
public class ItemSelectGlobalKeyboard extends ItemClickable {
|
||||
private final Intent clickIntent;
|
||||
private final PreferencesActivity activity;
|
||||
|
||||
public ItemSelectGlobalKeyboard(Preference item, PreferencesActivity prefs) {
|
||||
super(item);
|
||||
this.activity = prefs;
|
||||
|
||||
clickIntent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS);
|
||||
clickIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onClick(Preference p) {
|
||||
activity.startActivity(clickIntent);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package io.github.sspanak.tt9.preferences.items;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import io.github.sspanak.tt9.preferences.PreferencesActivity;
|
||||
|
||||
public class ItemSetDefaultGlobalKeyboard extends ItemClickable {
|
||||
private final PreferencesActivity activity;
|
||||
|
||||
public ItemSetDefaultGlobalKeyboard(Preference item, PreferencesActivity prefs) {
|
||||
super(item);
|
||||
this.activity = prefs;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onClick(Preference p) {
|
||||
((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)).showInputMethodPicker();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package io.github.sspanak.tt9.preferences.screens;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import io.github.sspanak.tt9.BuildConfig;
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.preferences.PreferencesActivity;
|
||||
import io.github.sspanak.tt9.preferences.items.ItemSelectGlobalKeyboard;
|
||||
import io.github.sspanak.tt9.preferences.items.ItemSetDefaultGlobalKeyboard;
|
||||
|
||||
public class SetupScreen extends BaseScreenFragment {
|
||||
public SetupScreen() { init(); }
|
||||
public SetupScreen(PreferencesActivity activity) { init(activity); }
|
||||
|
||||
@Override protected int getTitle() { return R.string.pref_category_setup;}
|
||||
@Override protected int getXml() { return R.xml.prefs_screen_setup; }
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
createKeyboardSection();
|
||||
createAboutSection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
createKeyboardSection();
|
||||
}
|
||||
|
||||
private void createKeyboardSection() {
|
||||
boolean isTT9On = activity.globalKeyboardSettings.isTT9Enabled();
|
||||
|
||||
Preference statusItem = findPreference("global_tt9_status");
|
||||
if (statusItem != null) {
|
||||
statusItem.setSummary(
|
||||
isTT9On ? R.string.setup_tt9_on : R.string.setup_tt9_off
|
||||
);
|
||||
|
||||
new ItemSelectGlobalKeyboard(statusItem, activity).enableClickHandler();
|
||||
}
|
||||
|
||||
Preference defaultKeyboardItem = findPreference("global_default_keyboard");
|
||||
if (defaultKeyboardItem != null) {
|
||||
new ItemSetDefaultGlobalKeyboard(defaultKeyboardItem, activity).enableClickHandler();
|
||||
}
|
||||
|
||||
Preference goToMain = findPreference("goto_main_screen");
|
||||
if (goToMain != null) {
|
||||
goToMain.setEnabled(isTT9On);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void createAboutSection() {
|
||||
Preference vi = findPreference("version_info");
|
||||
if (vi != null) {
|
||||
vi.setSummary(BuildConfig.VERSION_FULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue