Skip to content

Commit a58e9c1

Browse files
committed
夜间模式主题适配
1 parent 25e0fcd commit a58e9c1

19 files changed

+143
-32
lines changed

.idea/misc.xml

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ dependencies {
124124
compile 'io.reactivex.rxjava2:rxjava:2.1.0'
125125
// 主题切换
126126
compile 'skin.support:skin-support:2.1.2'
127+
compile 'com.kyleduo.switchbutton:library:1.4.6'
127128
}
128129

129130
// 热更新

app/src/main/java/com/rae/cnblogs/ThemeCompat.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,16 @@ public static Drawable getDrawable(Context context, String name) {
7575
* 切换夜间模式
7676
*/
7777
public static void switchNightMode() {
78-
if (isNight()) {
78+
switchNightMode(isNight());
79+
}
80+
81+
/**
82+
* 切换夜间模式
83+
*
84+
* @param isNight 是否为夜间模式
85+
*/
86+
public static void switchNightMode(boolean isNight) {
87+
if (isNight) {
7988
// 切换正常模式
8089
SkinCompatManager.getInstance().restoreDefaultTheme();
8190
} else {
@@ -86,7 +95,6 @@ public static void switchNightMode() {
8695
EventBus.getDefault().post(new ThemeChangedEvent(ThemeCompat.isNight()));
8796
}
8897

89-
9098
/**
9199
* 刷新状态栏颜色
92100
*
@@ -123,4 +131,5 @@ private static void changeMiUIStatusMode(Window window, boolean dark) {
123131
}
124132
}
125133
}
134+
126135
}

app/src/main/java/com/rae/cnblogs/activity/CategoryActivity.java

+7
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,17 @@ public class CategoryActivity extends BaseActivity {
1717

1818
@Override
1919
protected void onCreate(@Nullable Bundle savedInstanceState) {
20+
overridePendingTransition(com.rae.cnblogs.R.anim.slide_in_bottom, 0);
2021
super.onCreate(savedInstanceState);
2122
setContentView(R.layout.activity_category);
2223
showHomeAsUp();
2324
List<CategoryBean> data = getIntent().getParcelableArrayListExtra("data");
2425
getSupportFragmentManager().beginTransaction().add(R.id.content, CategoriesFragment.newInstance(data)).commit();
2526
}
27+
28+
@Override
29+
public void finish() {
30+
super.finish();
31+
overridePendingTransition(0, com.rae.cnblogs.R.anim.slide_out_bottom);
32+
}
2633
}

app/src/main/java/com/rae/cnblogs/activity/LoginActivity.java

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
* Created by ChenRui on 2017/1/19 0019 9:59.
3737
*/
3838
public class LoginActivity extends BaseActivity implements ILoginPresenter.ILoginView
39-
// , WebLoginListener
4039
{
4140

4241
@BindView(com.rae.cnblogs.R.id.ll_login_container)

app/src/main/java/com/rae/cnblogs/activity/MainActivity.java

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ protected void accept(VersionInfo versionInfo) {
157157

158158
// 请求权限
159159
requestPermissions();
160+
160161
}
161162

162163
/**

app/src/main/java/com/rae/cnblogs/activity/SearchActivity.java

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class SearchActivity extends BaseFragmentActivity {
1515

1616
@Override
1717
protected void onCreate(@Nullable Bundle savedInstanceState) {
18+
overridePendingTransition(com.rae.cnblogs.R.anim.slide_in_bottom, 0);
1819
super.onCreate(savedInstanceState);
1920
mToolBar.setVisibility(View.GONE);
2021
}
@@ -23,4 +24,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
2324
protected Fragment newFragment() {
2425
return SearchFragment.newInstance();
2526
}
27+
28+
@Override
29+
public void finish() {
30+
super.finish();
31+
overridePendingTransition(0, com.rae.cnblogs.R.anim.slide_out_bottom);
32+
}
2633
}

app/src/main/java/com/rae/cnblogs/fragment/MineFragment.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import android.support.annotation.Nullable;
55
import android.text.TextUtils;
66
import android.view.View;
7+
import android.widget.CompoundButton;
78
import android.widget.ImageView;
89
import android.widget.TextView;
910

11+
import com.kyleduo.switchbutton.SwitchButton;
1012
import com.rae.cnblogs.AppRoute;
1113
import com.rae.cnblogs.AppUI;
1214
import com.rae.cnblogs.R;
@@ -50,6 +52,9 @@ public static MineFragment newInstance() {
5052
@BindView(R.id.ll_follow_fans)
5153
View mFansAndFollowLayout;
5254

55+
@BindView(R.id.sb_night_mode)
56+
SwitchButton mNightModeButton;
57+
5358

5459
@Override
5560
protected int getLayoutId() {
@@ -59,6 +64,12 @@ protected int getLayoutId() {
5964
@Override
6065
protected void onCreateView(View view) {
6166
super.onCreateView(view);
67+
mNightModeButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
68+
@Override
69+
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
70+
ThemeCompat.switchNightMode(isChecked);
71+
}
72+
});
6273
}
6374

6475
@Override
@@ -215,7 +226,7 @@ public void onSettingClick() {
215226
*/
216227
@OnClick(R.id.ll_night)
217228
public void onNightClick() {
218-
ThemeCompat.switchNightMode();
229+
mNightModeButton.toggle();
219230
}
220231

221232
}

app/src/main/java/com/rae/cnblogs/fragment/WebViewFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public void onClick(View v) {
195195
});
196196
}
197197

198-
PlaceholderView placeholderView = getActivity().findViewById(R.id.placeholder_web);
198+
PlaceholderView placeholderView = (PlaceholderView) getActivity().findViewById(R.id.placeholder_web);
199199
if (placeholderView != null && mRaeWebViewClient != null && mRaeWebViewClient instanceof RaeWebViewClient) {
200200
placeholderView.dismiss();
201201
placeholderView.setOnRetryClickListener(new View.OnClickListener() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item>
4+
<shape>
5+
<solid android:color="@color/white_night"/>
6+
<corners android:radius="@dimen/default_radius"/>
7+
</shape>
8+
</item>
9+
</selector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item android:state_checked="true">
5+
<shape>
6+
<stroke
7+
android:width="2dp"
8+
android:color="#2b2c2e"/>
9+
<corners android:radius="10dp"/>
10+
</shape>
11+
12+
</item>
13+
<item>
14+
<shape>
15+
<stroke
16+
android:width="2dp"
17+
android:color="#F5FAFD"/>
18+
<corners android:radius="10dp"/>
19+
</shape>
20+
</item>
21+
</selector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item android:state_checked="true">
5+
<shape android:shape="oval">
6+
<solid android:color="#424b50"/>
7+
</shape>
8+
</item>
9+
<item>
10+
<shape android:shape="oval">
11+
<solid android:color="#9C9FA6"/>
12+
</shape>
13+
</item>
14+
</selector>

app/src/main/res/layout/activity_login.xml

+16-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
android:id="@+id/back"
2323
android:layout_width="wrap_content"
2424
android:layout_height="wrap_content"
25+
android:layout_alignParentEnd="true"
2526
android:layout_alignParentRight="true"
2627
android:layout_centerVertical="true"
2728
android:background="@android:color/transparent"
@@ -31,6 +32,20 @@
3132
android:paddingTop="18dp"
3233
android:scaleType="center"
3334
android:src="@drawable/login_btn_close"/>
35+
36+
<!-- <TextView
37+
38+
android:layout_alignParentRight="true"
39+
android:layout_centerVertical="true"
40+
android:id="@+id/tv_register"
41+
android:layout_width="wrap_content"
42+
android:layout_height="wrap_content"
43+
android:layout_gravity="right"
44+
android:padding="12dp"
45+
android:text="@string/register"
46+
android:textColor="@color/ph4"
47+
android:textSize="12sp"/>-->
48+
3449
</RelativeLayout>
3550

3651

@@ -40,7 +55,7 @@
4055
android:layout_height="wrap_content"
4156
android:layout_gravity="center"
4257
android:layout_marginBottom="46dp"
43-
android:layout_marginTop="4dp"
58+
android:layout_marginTop="30dp"
4459
android:src="@drawable/ic_login_logo"/>
4560

4661
<LinearLayout

app/src/main/res/layout/dialog_blog_default.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
android:background="@drawable/bg_button_white_selector"
6161
android:gravity="center"
6262
android:text="确定"
63-
android:textColor="@color/colorPrimary"
63+
android:textColor="@color/buttonColorPrimary"
6464
android:textSize="@dimen/h2"/>
6565
</LinearLayout>
6666

app/src/main/res/layout/fm_mine.xml

+29-13
Original file line numberDiff line numberDiff line change
@@ -133,58 +133,74 @@
133133
android:background="@color/background_divider"/>
134134

135135
<LinearLayout
136-
android:id="@+id/ll_favorites"
136+
android:id="@+id/ll_night"
137+
style="@style/ItemStyle"
137138
android:layout_width="match_parent"
138-
android:layout_height="wrap_content">
139+
android:layout_height="wrap_content"
140+
android:gravity="center_vertical">
139141

140142
<TextView
141-
style="@style/ItemStyle"
142-
android:layout_width="match_parent"
143+
android:layout_width="0dp"
143144
android:layout_height="wrap_content"
144-
android:text="@string/my_favorites"
145-
android:textColor="@color/ph1"/>
145+
android:layout_weight="1"
146+
android:drawableRight="@android:color/transparent"
147+
android:text="@string/night_mode"
148+
android:textColor="@color/ph1"
149+
android:textSize="16sp"/>
150+
151+
<com.kyleduo.switchbutton.SwitchButton
152+
android:id="@+id/sb_night_mode"
153+
android:layout_width="wrap_content"
154+
android:layout_height="wrap_content"
155+
android:layout_centerInParent="true"
156+
app:kswBackDrawable="@drawable/sb_default_back_drawable"
157+
app:kswBackMeasureRatio="2.5"
158+
app:kswThumbDrawable="@drawable/sb_default_thumb_drawable"
159+
app:kswThumbHeight="10dp"
160+
app:kswThumbMargin="3dp"
161+
app:kswThumbWidth="10dp"/>
146162

147163
</LinearLayout>
148164

149165
<LinearLayout
150-
android:id="@+id/ll_feedback"
166+
android:id="@+id/ll_favorites"
151167
android:layout_width="match_parent"
152168
android:layout_height="wrap_content">
153169

154170
<TextView
155171
style="@style/ItemStyle"
156172
android:layout_width="match_parent"
157173
android:layout_height="wrap_content"
158-
android:text="@string/feedback"
174+
android:text="@string/my_favorites"
159175
android:textColor="@color/ph1"/>
160176

161177
</LinearLayout>
162178

163-
164179
<LinearLayout
165-
android:id="@+id/ll_setting"
180+
android:id="@+id/ll_feedback"
166181
android:layout_width="match_parent"
167182
android:layout_height="wrap_content">
168183

169184
<TextView
170185
style="@style/ItemStyle"
171186
android:layout_width="match_parent"
172187
android:layout_height="wrap_content"
173-
android:text="@string/setting"
188+
android:text="@string/feedback"
174189
android:textColor="@color/ph1"/>
175190

176191
</LinearLayout>
177192

193+
178194
<LinearLayout
179-
android:id="@+id/ll_night"
195+
android:id="@+id/ll_setting"
180196
android:layout_width="match_parent"
181197
android:layout_height="wrap_content">
182198

183199
<TextView
184200
style="@style/ItemStyle"
185201
android:layout_width="match_parent"
186202
android:layout_height="wrap_content"
187-
android:text="@string/night_mode"
203+
android:text="@string/setting"
188204
android:textColor="@color/ph1"/>
189205

190206
</LinearLayout>

app/src/main/res/values/colors.xml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<color name="colorPrimaryBlack">#409DDB</color>
77
<color name="colorAccent">#1783CB</color>
88
<color name="colorHintPrimary">#EEEEEE</color>
9+
<color name="buttonColorPrimary">#3ba7ee</color>
910
<color name="transparent">#00000000</color>
1011
<color name="navBar">@color/white</color>
1112
<color name="dividerPrimary">#b2b2b2</color>

app/src/main/res/values/colors_night.xml

+1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@
3131
<color name="homeTabSelectedTextColor_night">#8f9091</color>
3232
<color name="bloggerStatusBarColor_night">@color/nightColorPrimary</color>
3333
<color name="colorHintPrimary_night">@color/white</color>
34+
<color name="buttonColorPrimary_night">#8f9091</color>
3435
</resources>

build.gradle

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ buildscript {
1414

1515
allprojects {
1616
repositories {
17-
google()
17+
// maven { url 'https://maven.google.com.hk'}
1818
maven { url 'http://maven.raeblog.com:8081/repository/maven-public/' }
1919
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
2020
jcenter()
@@ -53,9 +53,9 @@ task cleanCache(type: Delete) {
5353
}
5454
}
5555
ext {
56-
compileSdkVersion=25
57-
buildToolsVersion='26.0.1'
58-
targetSdkVersion=25
59-
minSdkVersion=15
60-
supportVersion = '25.4.0'
56+
compileSdkVersion = 26
57+
buildToolsVersion = '26.0.1'
58+
targetSdkVersion = 26
59+
minSdkVersion = 15
60+
supportVersion = '25.1.0'
6161
}

0 commit comments

Comments
 (0)