Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Menu
Open sidebar
termapps
termoneplus
Commits
a0620116
Commit
a0620116
authored
Nov 12, 2017
by
Roumen Petrov
Browse files
switch between dark and light theme in "File Selection" activity
parent
05cc9282
Changes
3
Hide whitespace changes
Inline
Side-by-side
term/src/main/java/com/termoneplus/shortcuts/FileSelection.java
View file @
a0620116
...
...
@@ -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
,
...
...
term/src/main/res/menu/menu_file_selection.xml
0 → 100644
View file @
a0620116
<?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>
term/src/main/res/values/styles.xml
View file @
a0620116
...
...
@@ -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>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment