-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
188 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.elishaazaria.sayboard; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
|
||
import androidx.annotation.IntegerRes; | ||
import androidx.annotation.StringRes; | ||
|
||
public class AppCtx { | ||
@SuppressLint("StaticFieldLeak") // App context | ||
private static Context appCtx; | ||
|
||
public static void setAppCtx(Context context) { | ||
appCtx = context.getApplicationContext(); | ||
} | ||
|
||
public static Context getAppCtx() { | ||
return appCtx; | ||
} | ||
|
||
public static String getStringRes(@StringRes int res) { | ||
return appCtx.getString(res); | ||
} | ||
|
||
public static int getIntegerRes(@IntegerRes int res){ | ||
return appCtx.getResources().getInteger(res); | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/elishaazaria/sayboard/preferences/MyPreferences.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,20 @@ | ||
package com.elishaazaria.sayboard.preferences; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
|
||
import com.elishaazaria.sayboard.AppCtx; | ||
import com.elishaazaria.sayboard.R; | ||
|
||
public class MyPreferences { | ||
private static SharedPreferences sharedPref; | ||
|
||
public static SharedPreferences getSharedPref() { | ||
if (sharedPref == null) { | ||
sharedPref = AppCtx.getAppCtx().getSharedPreferences( | ||
AppCtx.getStringRes(R.string.main_shared_pref), Context.MODE_PRIVATE); | ||
} | ||
return sharedPref; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/elishaazaria/sayboard/preferences/ThemePreferences.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,23 @@ | ||
package com.elishaazaria.sayboard.preferences; | ||
|
||
import android.graphics.Color; | ||
import android.os.Build; | ||
|
||
import com.elishaazaria.sayboard.AppCtx; | ||
import com.elishaazaria.sayboard.R; | ||
|
||
public class ThemePreferences { | ||
public static int getForegroundColor() { | ||
// TODO: if min-api 26, switch to Color objects | ||
return MyPreferences.getSharedPref() | ||
.getInt(AppCtx.getStringRes(R.string.pref_theme_foreground_c), | ||
AppCtx.getIntegerRes(R.integer.pref_foreground_color_default)); | ||
} | ||
|
||
public static int getBackgroundColor() { | ||
// TODO: if min-api 26, switch to Color objects | ||
return MyPreferences.getSharedPref() | ||
.getInt(AppCtx.getStringRes(R.string.pref_theme_background_c), | ||
AppCtx.getIntegerRes(R.integer.pref_background_color_default)); | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<integer name="pref_foreground_color_default">0xFF377A00</integer> | ||
<integer name="pref_background_color_default">0xFFFFFFFF</integer> | ||
</resources> |
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,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="main_shared_pref" translatable="false">main_shared_pref</string> | ||
<string name="pref_theme_foreground_c" translatable="false">c_foreground</string> | ||
<string name="pref_theme_background_c" translatable="false">c_background</string> | ||
|
||
</resources> |
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
Oops, something went wrong.