Commit a0620116 authored by Roumen Petrov's avatar Roumen Petrov
Browse files

switch between dark and light theme in "File Selection" activity

parent 05cc9282
......@@ -17,6 +17,7 @@
package com.termoneplus.shortcuts;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
......@@ -27,6 +28,7 @@
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
......@@ -42,6 +44,9 @@
import jackpal.androidterm.R;
public class FileSelection extends AppCompatActivity {
private final String PREFERENCES_FILE = "file_selection";
private final String PREFERENCE_LIGHT_THEME = "light_theme";
private final String STATE_CWD = "CWD";
private String cwd; // current working directory
......@@ -49,7 +54,16 @@ public class FileSelection extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
{
SharedPreferences preferences = getSharedPreferences(PREFERENCES_FILE, MODE_PRIVATE);
boolean light = preferences.getBoolean(PREFERENCE_LIGHT_THEME, false);
// override activity theme defined in manifest file
if (light)
setTheme(R.style.AppTheme_Light_NoActionBar);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_file_selection);
setResult(RESULT_CANCELED);
......@@ -123,11 +137,20 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_file_selection, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home: // Action bar home/up button selected
finish();
return true;
case R.id.menu_switch_theme:
onSwitchTheme();
return true;
}
return super.onOptionsItemSelected(item);
}
......@@ -138,6 +161,23 @@ protected void onSaveInstanceState(Bundle outState) {
outState.putString(STATE_CWD, cwd);
}
private void onSwitchTheme() {
SharedPreferences preferences = getSharedPreferences(PREFERENCES_FILE, MODE_PRIVATE);
boolean light = preferences.getBoolean(PREFERENCE_LIGHT_THEME, false);
{
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("light_theme", !light);
editor.apply();
}
Intent intent = getIntent();
intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
intent.putExtra("COMMAND_PATH", cwd);
startActivityForResult(intent, -1);
finish();
}
@IntDef({
ViewType.UP_ENTRY,
ViewType.DIR_ENTRY,
......
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_switch_theme"
android:title="@string/fsnavigator_change_theme"/>
</menu>
......@@ -43,4 +43,17 @@
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
<style name="AppTheme.Light" parent="Theme.AppCompat.Light">
<!-- Customize TermOnePlus theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.Light.AppBarOverlay" parent="ThemeOverlay.AppCompat.ActionBar"/>
<style name="AppTheme.Light.PopupOverlay" parent="ThemeOverlay.AppCompat"/>
</resources>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment