1
0
Fork 0

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:
sspanak 2024-04-19 14:52:02 +03:00 committed by Dimo Karaivanov
parent 16fbef0b8f
commit 2e019409e8
5 changed files with 33 additions and 16 deletions

View file

@ -17,13 +17,13 @@ public class AppearanceScreen extends BaseScreenFragment {
protected void onCreate() { protected void onCreate() {
(new ItemSelectTheme(activity, findPreference(ItemSelectTheme.NAME))) (new ItemSelectTheme(activity, findPreference(ItemSelectTheme.NAME)))
.populate() .populate()
.enableClickHandler() .preview()
.preview(); .enableClickHandler();
(new ItemSelectLayoutType(activity, findPreference(ItemSelectLayoutType.NAME))) (new ItemSelectLayoutType(activity, findPreference(ItemSelectLayoutType.NAME)))
.populate() .populate()
.enableClickHandler() .preview()
.preview(); .enableClickHandler();
(new ItemStatusIcon(findPreference(ItemStatusIcon.NAME), activity.getSettings())).populate(); (new ItemStatusIcon(findPreference(ItemStatusIcon.NAME), activity.getSettings())).populate();
} }

View file

@ -1,34 +1,34 @@
package io.github.sspanak.tt9.preferences.screens.appearance; package io.github.sspanak.tt9.preferences.screens.appearance;
import android.content.Context;
import androidx.preference.DropDownPreference; import androidx.preference.DropDownPreference;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import io.github.sspanak.tt9.R; 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.items.ItemDropDown;
import io.github.sspanak.tt9.preferences.settings.SettingsUI; import io.github.sspanak.tt9.preferences.settings.SettingsUI;
public class ItemSelectLayoutType extends ItemDropDown { public class ItemSelectLayoutType extends ItemDropDown {
public static final String NAME = "pref_layout_type"; 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); super(item);
this.context = context; this.activity = activity;
} }
public ItemDropDown populate() { public ItemDropDown populate() {
LinkedHashMap<Integer, String> items = new LinkedHashMap<>(); LinkedHashMap<Integer, String> items = new LinkedHashMap<>();
items.put(SettingsUI.LAYOUT_STEALTH, context.getString(R.string.pref_layout_stealth)); items.put(SettingsUI.LAYOUT_STEALTH, activity.getString(R.string.pref_layout_stealth));
items.put(SettingsUI.LAYOUT_TRAY, context.getString(R.string.pref_layout_tray)); items.put(SettingsUI.LAYOUT_TRAY, activity.getString(R.string.pref_layout_tray));
items.put(SettingsUI.LAYOUT_SMALL, context.getString(R.string.pref_layout_small)); items.put(SettingsUI.LAYOUT_SMALL, activity.getString(R.string.pref_layout_small));
items.put(SettingsUI.LAYOUT_NUMPAD, context.getString(R.string.pref_layout_numpad)); items.put(SettingsUI.LAYOUT_NUMPAD, activity.getString(R.string.pref_layout_numpad));
super.populateIntegers(items); super.populateIntegers(items);
super.setValue(String.valueOf(activity.getSettings().getMainViewLayout()));
return this; return this;
} }

View file

@ -33,7 +33,14 @@ public class SettingsUI extends SettingsTyping {
} }
public int getMainViewLayout() { 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; } public boolean isMainLayoutNumpad() { return getMainViewLayout() == LAYOUT_NUMPAD; }

View file

@ -1,13 +1,24 @@
package io.github.sspanak.tt9.util; package io.github.sspanak.tt9.util;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Build; import android.os.Build;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
public class DeviceInfo { public class DeviceInfo {
public static boolean noTouchScreen(Context context) { 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() { public static boolean isQinF21() {

View file

@ -9,7 +9,6 @@
app:title="@string/pref_dark_theme" /> app:title="@string/pref_dark_theme" />
<DropDownPreference <DropDownPreference
app:defaultValue="3"
app:iconSpaceReserved="false" app:iconSpaceReserved="false"
app:key="pref_layout_type" app:key="pref_layout_type"
app:layout="@layout/pref_dropdown" app:layout="@layout/pref_dropdown"