Skip to content

Commit

Permalink
夜间模式
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry-1123 committed Jan 31, 2018
1 parent d65895b commit b9be5c4
Show file tree
Hide file tree
Showing 23 changed files with 87 additions and 29 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/com/xxx/ency/base/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ public abstract class BaseActivity extends SupportActivity {

protected abstract void initialize();

// protected abstract void initTheme();

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// initTheme();
setContentView(getLayoutId());
mContext = this;
ButterKnife.bind(this);
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/com/xxx/ency/config/EncyApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.xxx.ency.di.component.DaggerAppComponent;
import com.xxx.ency.di.module.ApplicationModule;
import com.xxx.ency.di.module.HttpModule;
import com.xxx.ency.model.prefs.SharePrefManager;
import com.xxx.ency.util.AppApplicationUtil;

import me.yokeyword.fragmentation.Fragmentation;
Expand All @@ -24,6 +25,8 @@ public class EncyApplication extends Application {

public static AppComponent appComponent;

private SharePrefManager sharePrefManager;

public static synchronized EncyApplication getInstance() {
return instance;
}
Expand All @@ -32,8 +35,6 @@ public static synchronized EncyApplication getInstance() {
public void onCreate() {
super.onCreate();

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);

instance = this;

appComponent = DaggerAppComponent
Expand All @@ -42,6 +43,14 @@ public void onCreate() {
.httpModule(new HttpModule())
.build();

sharePrefManager = appComponent.getSharePrefManager();

if (sharePrefManager.getNightMode()) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}

// 初始化Bugly
CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(getApplicationContext());
strategy.setAppVersion(String.valueOf(AppApplicationUtil.getVersionCode(getApplicationContext())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void showBingBean(BingBean bingBean) {
GlideApp.with(mContext)
.load(bingBean.getData().getOriginal_pic())
.centerCrop()
.error(R.drawable.bg_about)
.error(R.drawable.bg_about_day)
.priority(Priority.LOW)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.into(mImgAbout);
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/xxx/ency/view/like/LikeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ public boolean onItemLongClick(BaseQuickAdapter adapter, View view, final int po
new MaterialDialog.Builder(mContext)
.content("确认要删除该收藏吗?")
.negativeText("取消")
.negativeColor(R.color.black)
.negativeColorRes(R.color.colorNegative)
.positiveText("确定")
.positiveColorRes(R.color.colorPositive)
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/xxx/ency/view/main/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ private void initDialog() {
.content(R.string.permission_application_content)
.cancelable(false)
.positiveText(R.string.setting)
.positiveColorRes(R.color.colorPositive)
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
Expand All @@ -163,6 +164,7 @@ public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which)
}
})
.negativeText(R.string.no)
.negativeColorRes(R.color.colorNegative)
.onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
Expand Down Expand Up @@ -198,10 +200,10 @@ public void showUpdateDialog(UpdateBean updateBean) {
new MaterialDialog.Builder(mContext)
.title(R.string.app_update)
.content(updateBean.getChangelog())
.positiveText(R.string.update)
.positiveColorRes(R.color.black)
.negativeText(R.string.no)
.negativeColorRes(R.color.black)
.negativeColorRes(R.color.colorNegative)
.positiveText(R.string.update)
.positiveColorRes(R.color.colorPositive)
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.preference.PreferenceFragment;
import android.preference.SwitchPreference;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatDelegate;

import com.xxx.ency.R;
import com.xxx.ency.config.Constants;
Expand Down Expand Up @@ -60,6 +61,14 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
sharePrefManager.setProvincialTrafficPatterns((Boolean) newValue);
} else if (preference == nightModePreference) {
sharePrefManager.setNightMode((Boolean) newValue);
if ((Boolean) newValue) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
if(getActivity() instanceof SettingActivity){
getActivity().recreate();
}
}
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/color/nav_menu_icon_color.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/colorPrimary"/>
<item android:state_checked="false" android:color="@color/iconItemUnselected"/>
<item android:state_checked="true" android:color="@color/colorItemSelected"/>
<item android:state_checked="false" android:color="@color/colorItemUnselected"/>
</selector>
4 changes: 2 additions & 2 deletions app/src/main/res/color/nav_menu_text_color.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/colorPrimary"/>
<item android:state_checked="false" android:color="@color/txtcolor"/>
<item android:state_checked="true" android:color="@color/colorItemSelected"/>
<item android:state_checked="false" android:color="@color/colorTxt"/>
</selector>
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="10dp"
android:background="@color/lineColor" />
android:background="@color/colorLine" />

<LinearLayout
android:layout_width="match_parent"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/fragment_gank.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
android:id="@+id/tablayout"
android:layout_width="match_parent"
android:layout_height="40dp"
app:tabIndicatorColor="@color/colorPrimaryDark"
app:tabSelectedTextColor="@color/colorPrimaryDark"
app:tabIndicatorColor="@color/colorItemSelected"
app:tabSelectedTextColor="@color/colorItemSelected"
app:tabTextColor="#9b9b9b" />

<android.support.v4.view.ViewPager
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_one.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
android:layout_marginBottom="20dp"
android:clickable="true"
android:src="@drawable/ic_top"
app:backgroundTint="@color/toggleColor"
app:backgroundTint="@color/colorBackground"
app:fabSize="mini"
app:pressedTranslationZ="2dp" />

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_gank_image.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:id="@+id/txt_gank_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textColor="@color/colorTxt"
android:textSize="14sp"
tools:text="标题XXXXXX" />

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_gank_txt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:id="@+id/txt_gank_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textColor="@color/colorTxt"
android:textSize="14sp"
tools:text="标题XXXXXX" />

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/item_like.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
android:layout_margin="10dp"
android:ellipsize="end"
android:lines="2"
android:textColor="@color/black"
android:textColor="@color/colorTxt"
android:textSize="14sp"
tools:text="XXXXXXXXXXXXXXXXXX这是标题" />

Expand All @@ -38,7 +38,7 @@
android:layout_alignParentBottom="true"
android:layout_margin="10dp"
android:layout_marginLeft="10dp"
android:textColor="@color/txtcolor_gray"
android:textColor="@color/colorTxt2"
android:textSize="12sp"
tools:text="类型" />

Expand All @@ -51,7 +51,7 @@
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:textColor="@color/txtcolor_gray"
android:textColor="@color/colorTxt2"
android:textSize="12sp"
tools:text="这是时间" />

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/item_weixin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
android:layout_margin="10dp"
android:ellipsize="end"
android:lines="2"
android:textColor="@color/black"
android:textColor="@color/colorTxt"
android:textSize="14sp"
tools:text="XXXXXXXXXXXXXXXXXX这是标题" />

Expand All @@ -34,7 +34,7 @@
android:layout_alignParentBottom="true"
android:layout_margin="10dp"
android:layout_marginLeft="10dp"
android:textColor="@color/txtcolor_gray"
android:textColor="@color/colorTxt2"
android:textSize="12sp"
tools:text="这是作者" />

Expand All @@ -46,7 +46,7 @@
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/txt_weixin_author"
android:textColor="@color/txtcolor_gray"
android:textColor="@color/colorTxt2"
android:textSize="12sp"
tools:text="这是时间" />

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout/nav_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_weather" />
android:background="@drawable/bg_weather_day" />

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -20,7 +20,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:textColor="@color/toggleColor"
android:textColor="@color/colorBackground"
android:textSize="45sp"
android:typeface="monospace"
tools:text="18°" />
Expand All @@ -35,15 +35,15 @@
android:id="@+id/txt_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/toggleColor"
android:textColor="@color/colorBackground"
android:textSize="17sp"
tools:text="苏州市" />

<TextView
android:id="@+id/txt_weather"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/toggleColor"
android:textColor="@color/colorBackground"
android:textSize="15sp"
tools:text="" />

Expand Down
17 changes: 17 additions & 0 deletions app/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#35464e</color>
<color name="colorPrimaryDark">#35464e</color>
<color name="colorAccent">#35464e</color>
<color name="colorPositive">#e4e4e4</color>
<color name="colorNegative">#e4e4e4</color>
<color name="colorTxt">#e4e4e4</color>
<color name="colorTxt2">#7E7E7E</color>
<color name="colorBackground">#FFFFFF</color>
<color name="colorItemSelected">#e4e4e4</color>
<color name="colorItemUnselected">#9b9b9b</color>
<color name="colorLine">#f1f1f1</color>

<color name="black">#000000</color>
<color name="white">#FFFFFF</color>
</resources>
17 changes: 17 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#0AACF4</color>
<color name="colorPrimaryDark">#0AACF4</color>
<color name="colorAccent">#0AACF4</color>
<color name="colorPositive">#0AACF4</color>
<color name="colorNegative">#000000</color>
<color name="colorTxt">#2c2c2c</color>
<color name="colorTxt2">#7E7E7E</color>
<color name="colorBackground">#FFFFFF</color>
<color name="colorItemSelected">#0AACF4</color>
<color name="colorItemUnselected">#9b9b9b</color>
<color name="colorLine">#f1f1f1</color>

<color name="black">#000000</color>
<color name="white">#FFFFFF</color>
</resources>
4 changes: 2 additions & 2 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
</style>

<style name="AppTheme" parent="BaseAppTheme">
<item name="android:textColor">@color/txtcolor</item>
<item name="android:textColor">@color/colorTxt</item>
<!--设置切换动画-->
<item name="android:windowAnimationStyle">@style/WindowAnimTheme</item>
<!--ActionBarDrawerToggle设置颜色-->
<item name="colorControlNormal">@color/toggleColor</item>
<item name="colorControlNormal">@color/white</item>
</style>

<style name="AppTheme.Main">
Expand Down

0 comments on commit b9be5c4

Please sign in to comment.