Add theme selector to settings, fix action-bar text color.
This commit is contained in:
parent
59c1e4afa8
commit
5e3193744d
5 changed files with 114 additions and 25 deletions
|
@ -5,16 +5,29 @@ import android.graphics.Color;
|
|||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.InputFilter;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
|
||||
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
|
||||
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
private static final int SYSTEM_DEFAULT = 0;
|
||||
private static final int DAY_THEME = 1;
|
||||
private static final int NIGHT_THEME = 2;
|
||||
|
||||
private Spinner themeSpinner;
|
||||
private EditText nsIp;
|
||||
private EditText servAddr;
|
||||
private EditText servPort;
|
||||
|
@ -34,6 +47,22 @@ public class SettingsActivity extends AppCompatActivity {
|
|||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
themeSpinner = findViewById(R.id.applicationThemeSpinner);
|
||||
themeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapterView, View view, int selectedItemPosition, long selectedItemId) {
|
||||
setApplicationTheme(selectedItemPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> adapterView) { }
|
||||
});
|
||||
|
||||
ArrayAdapter<CharSequence> themeAdapter = ArrayAdapter.createFromResource(this,
|
||||
R.array.dayNightSelector, android.R.layout.simple_spinner_item);
|
||||
themeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
themeSpinner.setAdapter(themeAdapter);
|
||||
// Set NS IP field
|
||||
nsIp = findViewById(R.id.nsIpEditText);
|
||||
servAddr = findViewById(R.id.servAddrTextEdit);
|
||||
|
@ -47,11 +76,12 @@ public class SettingsActivity extends AppCompatActivity {
|
|||
|
||||
// TODO: Disable controls
|
||||
if (savedInstanceState == null){
|
||||
SharedPreferences sp = getSharedPreferences("NSUSBloader", MODE_PRIVATE); //.getInt("PROTOCOL", NsConstants.PROTO_TF_USB);
|
||||
nsIp.setText(sp.getString("SNsIP", "192.168.1.42"));
|
||||
autoDetectIp.setChecked(sp.getBoolean("SAutoIP", true));
|
||||
servAddr.setText(sp.getString("SServerIP", "192.168.1.142"));
|
||||
servPort.setText(String.valueOf(sp.getInt("SServerPort", 6042)));
|
||||
SharedPreferences preferences = getSharedPreferences("NSUSBloader", MODE_PRIVATE); //.getInt("PROTOCOL", NsConstants.PROTO_TF_USB);
|
||||
themeSpinner.setSelection(preferences.getInt("ApplicationTheme", 0));
|
||||
nsIp.setText(preferences.getString("SNsIP", "192.168.1.42"));
|
||||
autoDetectIp.setChecked(preferences.getBoolean("SAutoIP", true));
|
||||
servAddr.setText(preferences.getString("SServerIP", "192.168.1.142"));
|
||||
servPort.setText(String.valueOf(preferences.getInt("SServerPort", 6042)));
|
||||
}
|
||||
// else { } // not needed
|
||||
|
||||
|
@ -108,12 +138,26 @@ public class SettingsActivity extends AppCompatActivity {
|
|||
});
|
||||
// Shitcode practices end
|
||||
}
|
||||
private void setApplicationTheme(int itemId){
|
||||
switch (itemId){
|
||||
case SYSTEM_DEFAULT:
|
||||
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM);
|
||||
break;
|
||||
case DAY_THEME:
|
||||
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
|
||||
break;
|
||||
case NIGHT_THEME:
|
||||
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
SharedPreferences.Editor spEditor = getSharedPreferences("NSUSBloader", MODE_PRIVATE).edit();
|
||||
|
||||
spEditor.putInt("ApplicationTheme", themeSpinner.getSelectedItemPosition());
|
||||
|
||||
if (nsIp.getText().toString().matches("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"))
|
||||
spEditor.putString("SNsIP", nsIp.getText().toString());
|
||||
|
||||
|
@ -149,21 +193,17 @@ public class SettingsActivity extends AppCompatActivity {
|
|||
return null;
|
||||
};
|
||||
|
||||
private static InputFilter inputFilterForPort = new InputFilter() {
|
||||
@Override
|
||||
public CharSequence filter(CharSequence charSequence, int start, int end, Spanned destination, int dStart, int dEnd) {
|
||||
if (end > start) {
|
||||
String destTxt = destination.toString();
|
||||
String resultingTxt = destTxt.substring(0, dStart) +
|
||||
charSequence.subSequence(start, end) +
|
||||
destTxt.substring(dEnd);
|
||||
if (!resultingTxt.matches ("^[0-9]+"))
|
||||
return "";
|
||||
if (Integer.parseInt(resultingTxt) > 65535)
|
||||
return "";
|
||||
}
|
||||
return null;
|
||||
private static InputFilter inputFilterForPort = (charSequence, start, end, destination, dStart, dEnd) -> {
|
||||
if (end > start) {
|
||||
String destTxt = destination.toString();
|
||||
String resultingTxt = destTxt.substring(0, dStart) +
|
||||
charSequence.subSequence(start, end) +
|
||||
destTxt.substring(dEnd);
|
||||
if (!resultingTxt.matches ("^[0-9]+"))
|
||||
return "";
|
||||
if (Integer.parseInt(resultingTxt) > 65535)
|
||||
return "";
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -19,11 +19,42 @@
|
|||
tools:context=".SettingsActivity"
|
||||
tools:showIn="@layout/activity_settings">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView7"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="3dp"
|
||||
android:paddingBottom="3dp"
|
||||
android:text="@string/settings_application_settings"
|
||||
android:textStyle="bold|italic" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView8"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/settings_app_theme" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/applicationThemeSpinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/tf_net" />
|
||||
android:paddingTop="3dp"
|
||||
android:paddingBottom="3dp"
|
||||
android:text="@string/tf_net"
|
||||
android:textStyle="bold|italic" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
@ -45,7 +76,8 @@
|
|||
android:digits="0123456789."
|
||||
android:ems="10"
|
||||
android:hint="xxx.xxx.xxx.xxx"
|
||||
android:inputType="number" />
|
||||
android:inputType="number"
|
||||
android:importantForAutofill="no" />
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
|
@ -74,6 +106,7 @@
|
|||
android:digits="0123456789."
|
||||
android:ems="10"
|
||||
android:hint="xxx.xxx.xxx.xxx"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="number" />
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -98,6 +131,7 @@
|
|||
android:digits="0123456789"
|
||||
android:ems="10"
|
||||
android:hint="1024-65535"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="number" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -39,4 +39,11 @@
|
|||
<string name="notification_transfer_in_progress">Идет передача данных</string>
|
||||
<string name="notification_chan_desc_progress">Уведомление демонстрирует прогресс передачи данных</string>
|
||||
<string name="notification_chan_name_progress">Передача данных</string>
|
||||
<string-array name="dayNightSelector">
|
||||
<item>Системная</item>
|
||||
<item>Светлая тема</item>
|
||||
<item>Ночная тема</item>
|
||||
</string-array>
|
||||
<string name="settings_application_settings">Настройки приложения</string>
|
||||
<string name="settings_app_theme">Тема:</string>
|
||||
</resources>
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
<string name="interrupt_btn">Interrupt</string>
|
||||
<string name="navigation_drawer_open">Open navigation drawer</string>
|
||||
<string name="navigation_drawer_close">Close navigation drawer</string>
|
||||
<string name="tf_usb" translatable="false">TinFoil USB</string>
|
||||
<string name="tf_usb" translatable="false">Tinfoil USB</string>
|
||||
<string name="gl" translatable="false">GoldLeaf v0.5</string>
|
||||
<string name="tf_net" translatable="false">TinFoil NET</string>
|
||||
<string name="tf_net" translatable="false">Tinfoil NET</string>
|
||||
<string name="about_app">About this app</string>
|
||||
<string name="other">Other</string>
|
||||
<string name="one_item_for_gl_notification">Only one file could be selected for GoldLeaf v0.5</string>
|
||||
|
@ -46,4 +46,11 @@
|
|||
<string name="notification_chan_name_progress">Transfer in progress</string>
|
||||
<string name="notification_chan_desc_progress">Notification indicates transfer progress</string>
|
||||
<string name="about_translators" translatable="false">* 中文(繁體) - <a href="https://github.com/qazrfv1234">qazrfv1234</a>\n* 中文(简体) - FFT9 <a href="http://www.xxgame.net">(XXGAME GROUP)</a></string>
|
||||
<string-array name="dayNightSelector">
|
||||
<item>System default</item>
|
||||
<item>Day theme</item>
|
||||
<item>Night theme</item>
|
||||
</string-array>
|
||||
<string name="settings_application_settings">Application settings</string>
|
||||
<string name="settings_app_theme">Application theme:</string>
|
||||
</resources>
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.DayNight.ActionBar">
|
||||
<item name="fontFamily">@font/play</item>
|
||||
<item name="android:textColorPrimary">@android:color/white</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.DayNight" />
|
||||
|
|
Loading…
Reference in a new issue