on initial startup, after installation, the presence of touchscreen and keypad/keyboard is automatically detected, to select automatically the appropriate MainView layout
This commit is contained in:
parent
16fbef0b8f
commit
2e019409e8
5 changed files with 33 additions and 16 deletions
|
|
@ -17,13 +17,13 @@ public class AppearanceScreen extends BaseScreenFragment {
|
|||
protected void onCreate() {
|
||||
(new ItemSelectTheme(activity, findPreference(ItemSelectTheme.NAME)))
|
||||
.populate()
|
||||
.enableClickHandler()
|
||||
.preview();
|
||||
.preview()
|
||||
.enableClickHandler();
|
||||
|
||||
(new ItemSelectLayoutType(activity, findPreference(ItemSelectLayoutType.NAME)))
|
||||
.populate()
|
||||
.enableClickHandler()
|
||||
.preview();
|
||||
.preview()
|
||||
.enableClickHandler();
|
||||
|
||||
(new ItemStatusIcon(findPreference(ItemStatusIcon.NAME), activity.getSettings())).populate();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,34 +1,34 @@
|
|||
package io.github.sspanak.tt9.preferences.screens.appearance;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.DropDownPreference;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.preferences.PreferencesActivity;
|
||||
import io.github.sspanak.tt9.preferences.items.ItemDropDown;
|
||||
import io.github.sspanak.tt9.preferences.settings.SettingsUI;
|
||||
|
||||
public class ItemSelectLayoutType extends ItemDropDown {
|
||||
public static final String NAME = "pref_layout_type";
|
||||
|
||||
private final Context context;
|
||||
private final PreferencesActivity activity;
|
||||
|
||||
public ItemSelectLayoutType(Context context, DropDownPreference item) {
|
||||
public ItemSelectLayoutType(PreferencesActivity activity, DropDownPreference item) {
|
||||
|
||||
super(item);
|
||||
this.context = context;
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
public ItemDropDown populate() {
|
||||
LinkedHashMap<Integer, String> items = new LinkedHashMap<>();
|
||||
items.put(SettingsUI.LAYOUT_STEALTH, context.getString(R.string.pref_layout_stealth));
|
||||
items.put(SettingsUI.LAYOUT_TRAY, context.getString(R.string.pref_layout_tray));
|
||||
items.put(SettingsUI.LAYOUT_SMALL, context.getString(R.string.pref_layout_small));
|
||||
items.put(SettingsUI.LAYOUT_NUMPAD, context.getString(R.string.pref_layout_numpad));
|
||||
items.put(SettingsUI.LAYOUT_STEALTH, activity.getString(R.string.pref_layout_stealth));
|
||||
items.put(SettingsUI.LAYOUT_TRAY, activity.getString(R.string.pref_layout_tray));
|
||||
items.put(SettingsUI.LAYOUT_SMALL, activity.getString(R.string.pref_layout_small));
|
||||
items.put(SettingsUI.LAYOUT_NUMPAD, activity.getString(R.string.pref_layout_numpad));
|
||||
|
||||
super.populateIntegers(items);
|
||||
super.setValue(String.valueOf(activity.getSettings().getMainViewLayout()));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,14 @@ public class SettingsUI extends SettingsTyping {
|
|||
}
|
||||
|
||||
public int getMainViewLayout() {
|
||||
return getStringifiedInt("pref_layout_type", LAYOUT_SMALL);
|
||||
int defaultLayout = LAYOUT_SMALL;
|
||||
if (DeviceInfo.noTouchScreen(context)) {
|
||||
defaultLayout = LAYOUT_TRAY;
|
||||
} else if (DeviceInfo.noKeyboard(context)) {
|
||||
defaultLayout = LAYOUT_NUMPAD;
|
||||
}
|
||||
|
||||
return getStringifiedInt("pref_layout_type", defaultLayout);
|
||||
}
|
||||
|
||||
public boolean isMainLayoutNumpad() { return getMainViewLayout() == LAYOUT_NUMPAD; }
|
||||
|
|
|
|||
|
|
@ -1,13 +1,24 @@
|
|||
package io.github.sspanak.tt9.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.view.KeyCharacterMap;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class DeviceInfo {
|
||||
public static boolean noTouchScreen(Context context) {
|
||||
return !context.getPackageManager().hasSystemFeature("android.hardware.touchscreen");
|
||||
return !context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN);
|
||||
}
|
||||
|
||||
public static boolean noKeyboard(Context context) {
|
||||
return
|
||||
context.getResources().getConfiguration().keyboard == Configuration.KEYBOARD_NOKEYS
|
||||
&& !KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_STAR)
|
||||
&& !KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_POUND);
|
||||
}
|
||||
|
||||
public static boolean isQinF21() {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
app:title="@string/pref_dark_theme" />
|
||||
|
||||
<DropDownPreference
|
||||
app:defaultValue="3"
|
||||
app:iconSpaceReserved="false"
|
||||
app:key="pref_layout_type"
|
||||
app:layout="@layout/pref_dropdown"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue