Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
Theme: Add Dark theme
Browse files Browse the repository at this point in the history
Signed-off-by: fython <fython@163.com>
  • Loading branch information
fython committed Feb 2, 2016
1 parent 53c22b2 commit c6b289e
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme.Light">

<activity android:name=".ui.LaunchActivity">
<intent-filter>
Expand Down
56 changes: 55 additions & 1 deletion app/src/main/java/info/papdt/blackblub/ui/LaunchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class LaunchActivity extends AppCompatActivity implements PopupMenu.OnMen

private PopupMenu popupMenu;

private boolean isRunning = false;
private boolean isRunning = false, hasDismissFirstRunDialog = false;
private Settings mSettings;

@Override
Expand All @@ -51,6 +51,10 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

if (mSettings.getBoolean(Settings.KEY_DARK_THEME, false)) {
setTheme(R.style.AppTheme_Dark);
}

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting);

Expand All @@ -76,6 +80,47 @@ public void onCheckedChanged(boolean b) {
intent.putExtra(C.EXTRA_BRIGHTNESS, mSeekbar.getProgress());
startService(intent);
isRunning = true;

// For safe
if (mSettings.getBoolean(Settings.KEY_FIRST_RUN, true)) {
hasDismissFirstRunDialog = false;
final AlertDialog dialog = new AlertDialog.Builder(LaunchActivity.this)
.setTitle(R.string.dialog_first_run_title)
.setMessage(R.string.dialog_first_run_message)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
mSettings.putBoolean(Settings.KEY_FIRST_RUN, false);
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
hasDismissFirstRunDialog = true;
}
})
.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
mSwitch.toggle();
if (mSettings.getBoolean(Settings.KEY_FIRST_RUN, true)) {
Intent intent = new Intent(LaunchActivity.this, MaskService.class);
intent.putExtra(C.EXTRA_ACTION, C.ACTION_STOP);
stopService(intent);
isRunning = false;
}
}
})
.show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (dialog.isShowing() && !hasDismissFirstRunDialog) {
dialog.dismiss();
}
}
}, 5000);
}
} else {
Intent intent = new Intent(LaunchActivity.this, MaskService.class);
intent.putExtra(C.EXTRA_ACTION, C.ACTION_STOP);
Expand Down Expand Up @@ -115,6 +160,9 @@ public void onStopTrackingTouch(DiscreteSeekBar seekBar) {
popupMenu.getMenu()
.findItem(R.id.action_overlay_system)
.setChecked(mSettings.getBoolean(Settings.KEY_OVERLAY_SYSTEM, false));
popupMenu.getMenu()
.findItem(R.id.action_dark_theme)
.setChecked(mSettings.getBoolean(Settings.KEY_DARK_THEME, false));
popupMenu.setOnMenuItemClickListener(this);
menuBtn.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -196,6 +244,12 @@ public void onClick(DialogInterface dialogInterface, int i) {
.show();
}
return true;
} else if (id == R.id.action_dark_theme) {
mSettings.putBoolean(Settings.KEY_DARK_THEME, !menuItem.isChecked());
menuItem.setChecked(!menuItem.isChecked());
finish();
startActivity(new Intent(this, LaunchActivity.class));
return true;
}
return false;
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/info/papdt/blackblub/utils/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ public class Settings {

public static final String PREFERENCES_NAME = "settings";

public static final String KEY_BRIGHTNESS = "brightness", KEY_ALIVE = "alive", KEY_OVERLAY_SYSTEM = "overlay_system";
public static final String KEY_BRIGHTNESS = "brightness", KEY_ALIVE = "alive",
KEY_OVERLAY_SYSTEM = "overlay_system", KEY_FIRST_RUN = "first_run",
KEY_DARK_THEME = "dark_theme";

private static Settings sInstance;

Expand Down
9 changes: 7 additions & 2 deletions app/src/main/res/layout/activity_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
android:layout_margin="8dp"
android:layout_gravity="center_vertical"
android:clickable="true"
app:cardElevation="5dp">
app:cardElevation="5dp"
app:cardBackgroundColor="?attr/card_background_color">

<LinearLayout
android:orientation="vertical"
Expand All @@ -35,6 +36,7 @@
android:layout_marginLeft="24dp"
android:layout_marginRight="12dp"
android:src="@drawable/ic_logo_teal"
android:tint="?attr/icon_tint"
android:scaleType="centerInside"/>

<android.support.v7.widget.AppCompatTextView
Expand Down Expand Up @@ -62,7 +64,7 @@
android:layout_marginRight="12dp"
android:id="@+id/btn_menu"
android:src="@drawable/ic_more_vert_black_24dp"
android:tint="#6f000000"
android:tint="?attr/overflow_tint"
android:background="?attr/selectableItemBackgroundBorderless"/>

</LinearLayout>
Expand All @@ -75,6 +77,9 @@
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:dsb_progressColor="?attr/progress_bar_color"
app:dsb_indicatorColor="?attr/progress_bar_color"
app:dsb_trackColor="?attr/progress_bar_color"
app:dsb_min="25"
app:dsb_max="100"/>

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/menu/menu_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
android:checkable="true"
android:checked="false"/>

<item android:id="@+id/action_dark_theme"
android:title="@string/action_dark_theme"
android:checkable="true"
android:checked="false"/>


<item android:id="@+id/action_about"
android:title="@string/action_about"/>

Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values-v19/styles.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<resources>

<style name="AppTheme" parent="BaseAppTheme">
<style name="AppTheme.Light" parent="BaseAppTheme.Light">
<item name="android:windowTranslucentStatus">true</item>
</style>

<style name="AppTheme.Dark" parent="BaseAppTheme.Dark">
<item name="android:windowTranslucentStatus">true</item>
</style>

Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/values-v21/styles.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<resources>

<style name="AppTheme" parent="BaseAppTheme">
<style name="AppTheme.Light" parent="BaseAppTheme.Light">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
</style>

<style name="AppTheme.Dark" parent="BaseAppTheme.Dark">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

<string name="action_about">关于</string>
<string name="action_overlay_system">覆盖系统状态栏</string>
<string name="action_dark_theme">暗色主题</string>

<string name="about_author">作者: 纸飞机开发团队 - 烧饼</string>
<string name="about_text">"夜间屏幕可以帮助你减少夜晚屏幕强光对眼睛造成的损害。\n一些设备的最低亮度对于用户来讲仍然较高,我们可以通过创建遮罩使亮度更低。\n\n如果你想在物质上支持这个应用,你可以打赏到我的支付宝ww: 316643843\@qq.com"</string>
<string name="about_other">Github 项目地址: <a href="https://github.com/fython/Blackbulb">https://github.com/fython/Blackbulb</a>\n我的博客: <a href="http://feng.moe">http://feng.moe</a>\n新浪微博: <a href="http://weibo.com/fython">http://weibo.com/fython</a></string>
<string name="about_other">Github 项目地址: <a href="https://github.com/fython/Blackbulb">https://github.com/fython/Blackbulb</a>\n我的博客: <a href="http://feng.moe">http://feng.moe</a>\n新浪微博: <a href="http://weibo.com/fython">http://weibo.com/fython</a>\n图标设计: 新浪\@翟宅宅Jack</string>

<string name="dialog_overlay_enable_title">启用覆盖系统状态栏</string>
<string name="dialog_overlay_enable_message">启用这个可以让遮罩覆盖到屏幕最顶层,但在一些设备上需要得到权限(例如 MIUI 和 Android 6.0)\n如果启用该项后不生效,请自行去设置调整权限。</string>

<string name="mask_fail_to_start">无法启动遮罩。请检查系统是否禁止权限。</string>

<string name="dialog_first_run_title">首次启动</string>
<string name="dialog_first_run_message">你能看见这条信息吗?如果可以,这证明夜间屏幕正常工作。\n在 5 秒之内不按“确定”会自动停止</string>

</resources>
6 changes: 5 additions & 1 deletion app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

<string name="action_about">關於</string>
<string name="action_overlay_system">覆蓋系統狀態列</string>
<string name="action_dark_theme">暗色主題</string>

<string name="about_author">作者: 紙飛機開發團隊 - 燒餅</string>
<string name="about_text">"夜间荧幕有助減少夜間螢幕強光對視力造成的損傷。\n一些設備對某些用戶而言仍偏高,我們可以通過創建遮罩以讓亮度更低。\n\n如果你願意在物質上支援本應用程式,你可以打賞到我的支付寶ww: 316643843\@qq.com"</string>
<string name="about_other">Github 項目地址: <a href="https://github.com/fython/Blackbulb">https://github.com/fython/Blackbulb</a>\n我的博客: <a href="http://feng.moe">http://feng.moe</a>\n新浪微博: <a href="http://weibo.com/fython">http://weibo.com/fython</a></string>
<string name="about_other">Github 項目地址: <a href="https://github.com/fython/Blackbulb">https://github.com/fython/Blackbulb</a>\n我的博客: <a href="http://feng.moe">http://feng.moe</a>\n新浪微博: <a href="http://weibo.com/fython">http://weibo.com/fython</a>\n徽標設計: 新浪\@翟宅宅Jack</string>

<string name="dialog_overlay_enable_title">啟用覆蓋系統狀態列</string>
<string name="dialog_overlay_enable_message">啟用本項可以令遮罩置頂於螢幕,但在一些設備上需要得到權限(譬如 MIUI 與 Android 6.0)\n如果啟用本項後不生效,請自行去設置權限。</string>

<string name="mask_fail_to_start">無法啟用遮罩。請檢查系統是否禁止權限。</string>

<string name="dialog_first_run_title">首次啟動</string>
<string name="dialog_first_run_message">你能看到這條訊息嗎?如果可以,這證實夜間螢幕正常運作。\n在 5 秒之內不按“確認”會自動停止</string>

</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@
<attr name="ball_press_color" format="color"/>
</declare-styleable>

<declare-styleable name="Blackbulb">
<attr name="card_background_color" format="color"/>
<attr name="progress_bar_color" format="color"/>
<attr name="icon_tint" format="color"/>
<attr name="overflow_tint" format="color"/>
</declare-styleable>

</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
<color name="deep_orange_100">#FFCCBC</color>
<color name="deep_orange_700">#E64A19</color>

<color name="teal_500">#009688</color>
<color name="teal_700">#00796B</color>

</resources>
6 changes: 5 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

<string name="action_about">About</string>
<string name="action_overlay_system">Overlay Status Bar</string>
<string name="action_dark_theme">Dark theme</string>

<string name="about_author">Author: Paper Airplane Dev - Fung Jichun</string>
<string name="about_text">"Night Screen can help you prevent from the harm of strong light at night.\nSome devices\' lowest brightness are still high so we can make it lower by creating a mask on screen.\n\nIf you want to support this application, you could send a bit money to my Alipay: 316643843\@qq.com"</string>
<string name="about_other">Github Repo: <a href="https://github.com/fython/Blackbulb">https://github.com/fython/Blackbulb</a>\nMy blog: <a href="http://feng.moe">http://feng.moe</a>\nMy sina weibo: <a href="http://weibo.com/fython">\@某烧饼</a></string>
<string name="about_other">Github Repo: <a href="https://github.com/fython/Blackbulb">https://github.com/fython/Blackbulb</a>\nMy blog: <a href="http://feng.moe">http://feng.moe</a>\nMy sina weibo: <a href="http://weibo.com/fython">\@某烧饼</a>\nLogo Designer: Google+ Youlun Zhai</string>

<string name="dialog_overlay_enable_title">Enable Overlay Status Bar</string>
<string name="dialog_overlay_enable_message">Enable this can make mask on the top of screen, but it may needs a permission in some devices (Such as MIUI and Android 6.0)\nIf it couldn\'t work, please allow this app to show system alert window.</string>

<string name="mask_fail_to_start">Failed to start mask. Please check if system has denied the permissions.</string>

<string name="dialog_first_run_title">First run</string>
<string name="dialog_first_run_message">Can you see this message? If you can, it proves that Night Screen is working well. \nIt will automatically stop after 5 seconds if you didn\t press OK.</string>

</resources>
21 changes: 19 additions & 2 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
<resources>

<style name="BaseAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<style name="BaseAppTheme.Light" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@color/translucentBackgroundColor</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item>
<item name="card_background_color">#EEEEEE</item>
<item name="progress_bar_color">@color/teal_700</item>
<item name="icon_tint">@color/teal_500</item>
<item name="overflow_tint">#6f000000</item>
</style>

<style name="AppTheme" parent="BaseAppTheme"></style>
<style name="BaseAppTheme.Dark" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@color/translucentBackgroundColor</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item>
<item name="card_background_color">#212121</item>
<item name="progress_bar_color">#eeeeee</item>
<item name="icon_tint">#ffffff</item>
<item name="overflow_tint">#6fffffff</item>
</style>

<style name="AppTheme" parent="BaseAppTheme.Light"></style>

</resources>

0 comments on commit c6b289e

Please sign in to comment.