Black theme - Apply to settings

This commit is contained in:
stom79 2018-05-11 10:40:58 +02:00
parent 4b09e5d106
commit ca384748ea
5 changed files with 64 additions and 30 deletions

View File

@ -70,7 +70,7 @@ public class SettingsFragment extends Fragment {
private Context context;
private static final int ACTIVITY_CHOOSE_FILE = 411;
private TextView set_folder;
int count1, count2 = 0;
int count1, count2, count3 = 0;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -428,25 +428,56 @@ public class SettingsFragment extends Fragment {
file_chooser.setVisibility(View.GONE);
}
final SwitchCompat set_night_mode = rootView.findViewById(R.id.set_night_mode);
set_night_mode.setChecked(theme == Helper.THEME_DARK);
set_night_mode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
final Spinner set_night_mode = rootView.findViewById(R.id.set_night_mode);
ArrayAdapter<CharSequence> adapterTheme = ArrayAdapter.createFromResource(getContext(),
R.array.settings_theme, android.R.layout.simple_spinner_item);
set_night_mode.setAdapter(adapterTheme);
int positionSpinnerTheme;
switch (sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK)){
case Helper.THEME_DARK:
positionSpinnerTheme = 0;
break;
case Helper.THEME_LIGHT:
positionSpinnerTheme = 1;
break;
case Helper.THEME_BLACK:
positionSpinnerTheme = 2;
break;
default:
positionSpinnerTheme = 0;
}
set_night_mode.setSelection(positionSpinnerTheme);
set_night_mode.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putInt(Helper.SET_THEME, isChecked?Helper.THEME_DARK:Helper.THEME_LIGHT);
editor.apply();
if( isChecked){
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if( count3 > 0){
SharedPreferences.Editor editor = sharedpreferences.edit();
switch (position){
case 0:
editor.putInt(Helper.SET_THEME, Helper.THEME_DARK);
editor.apply();
break;
case 1:
editor.putInt(Helper.SET_THEME, Helper.THEME_LIGHT);
editor.apply();
break;
case 2:
editor.putInt(Helper.SET_THEME, Helper.THEME_BLACK);
editor.apply();
break;
}
if( getActivity() != null)
getActivity().setTheme(R.style.AppThemeDark);
getActivity().recreate();
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra(INTENT_ACTION, CHANGE_THEME_INTENT);
startActivity(intent);
}else {
if( getActivity() != null)
getActivity().setTheme(R.style.AppTheme);
count3++;
}
getActivity().recreate();
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra(INTENT_ACTION, CHANGE_THEME_INTENT);
startActivity(intent);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});

View File

@ -248,8 +248,10 @@ public class Helper {
public static final int ATTACHMENT_ALWAYS = 1;
public static final int ATTACHMENT_WIFI = 2;
public static final int ATTACHMENT_ASK = 3;
public static final int THEME_LIGHT = 1;
public static final int THEME_DARK = 2;
public static final int THEME_BLACK = 3;
public static final int LED_COLOUR = 0;

View File

@ -314,15 +314,11 @@
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set_night_mode"/>
<android.support.v7.widget.SwitchCompat
android:text="@string/set_theme"/>
<Spinner
android:id="@+id/set_night_mode"
android:layout_gravity="center_vertical"
android:gravity="center"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
android:layout_height="wrap_content" />
</LinearLayout>
<!-- TOOTS visibility -->

View File

@ -302,6 +302,8 @@
/>
</LinearLayout>
</LinearLayout>
<!-- THEME -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -311,15 +313,11 @@
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set_night_mode"/>
<android.support.v7.widget.SwitchCompat
android:text="@string/set_theme"/>
<Spinner
android:id="@+id/set_night_mode"
android:layout_gravity="center_vertical"
android:gravity="center"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
android:layout_height="wrap_content" />
</LinearLayout>
<!-- TOOTS visibility -->

View File

@ -352,6 +352,12 @@
<item>No</item>
</string-array>
<string-array name="settings_theme">
<item>Dark</item>
<item>Light</item>
<item>Black</item>
</string-array>
<string-array name="settings_resize_picture">
<item>No</item>
<item>512 Kb</item>
@ -526,6 +532,7 @@
<string name="poxy_port">Port</string>
<string name="poxy_login">Login</string>
<string name="poxy_password">Password</string>
<string name="set_theme">Theme:</string>
<string-array translatable="false" name="proxy_type_choice">
<item>HTTP</item>
<item>SOCKS</item>