-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #10 theme switcher in settings and a black mode for AMOLED screens
- Loading branch information
Showing
8 changed files
with
119 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
app/src/main/java/com/github/yeriomin/yalpstore/ThemeManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.github.yeriomin.yalpstore; | ||
|
||
import android.app.Activity; | ||
import android.content.SharedPreferences; | ||
import android.os.Build; | ||
import android.preference.PreferenceManager; | ||
|
||
public class ThemeManager { | ||
|
||
static public void setTheme(Activity activity) { | ||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); | ||
String theme = prefs.getString(PreferenceActivity.PREFERENCE_UI_THEME, PreferenceActivity.THEME_NONE); | ||
switch (theme) { | ||
case PreferenceActivity.THEME_NONE: | ||
break; | ||
case PreferenceActivity.THEME_LIGHT: | ||
activity.setTheme(getThemeLight()); | ||
break; | ||
case PreferenceActivity.THEME_DARK: | ||
activity.setTheme(getThemeDark()); | ||
break; | ||
case PreferenceActivity.THEME_BLACK: | ||
activity.setTheme(getThemeDark()); | ||
activity.getWindow().setBackgroundDrawableResource(android.R.color.black); | ||
break; | ||
} | ||
} | ||
|
||
static private int getThemeLight() { | ||
int sdk = Build.VERSION.SDK_INT; | ||
if (sdk >= Build.VERSION_CODES.LOLLIPOP) { | ||
return android.R.style.Theme_Material_Light; | ||
} else if (sdk >= Build.VERSION_CODES.HONEYCOMB) { | ||
return android.R.style.Theme_Holo_Light; | ||
} else { | ||
return android.R.style.Theme_Light; | ||
} | ||
} | ||
|
||
static private int getThemeDark() { | ||
int sdk = Build.VERSION.SDK_INT; | ||
if (sdk >= Build.VERSION_CODES.LOLLIPOP) { | ||
return android.R.style.Theme_Material; | ||
} else if (sdk >= Build.VERSION_CODES.HONEYCOMB) { | ||
return android.R.style.Theme_Holo; | ||
} else { | ||
return android.R.style.Theme; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters