Skip to content

Commit

Permalink
HotBitmapGG#50 delete old theme change lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
HotBitmapGG committed Jul 3, 2017
1 parent 780169e commit fc27335
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 355 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ dependencies {
compile 'com.facebook.stetho:stetho:1.3.1'
compile 'com.facebook.stetho:stetho-okhttp3:1.3.1'
compile 'com.miguelcatalan:materialsearchview:1.4.0'
compile 'com.bilibili:magicasakura:0.1.1@aar'
compile 'jp.wasabeef:glide-transformations:2.0.1'
compile 'com.jakewharton:butterknife:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
Expand Down
118 changes: 18 additions & 100 deletions app/src/main/java/com/hotbitmapgg/bilibili/BilibiliApp.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
package com.hotbitmapgg.bilibili;

import android.app.Application;
import android.content.Context;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;

import com.bilibili.magicasakura.utils.ThemeUtils;
import com.facebook.stetho.Stetho;
import com.hotbitmapgg.bilibili.utils.ThemeHelper;
import com.hotbitmapgg.ohmybilibili.R;
import com.squareup.leakcanary.LeakCanary;

/**
Expand All @@ -17,106 +11,30 @@
* <p/>
* 哔哩哔哩动画App
*/
public class BilibiliApp extends Application implements ThemeUtils.switchColor {
public static BilibiliApp mInstance;
public class BilibiliApp extends Application {

@Override
public void onCreate() {
super.onCreate();
mInstance = this;
init();
}
public static BilibiliApp mInstance;

private void init() {
// 初始化主题切换
ThemeUtils.setSwitchColor(this);
//初始化Leak内存泄露检测工具
LeakCanary.install(this);
//初始化Stetho调试工具
Stetho.initialize(
Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
.build());
}

public static BilibiliApp getInstance() {
return mInstance;
}

@Override
public int replaceColorById(Context context, @ColorRes int colorId) {
if (ThemeHelper.isDefaultTheme(context)) {
return context.getResources().getColor(colorId);
}
String theme = getTheme(context);
if (theme != null) {
colorId = getThemeColorId(context, colorId, theme);
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
init();
}
return context.getResources().getColor(colorId);
}

@Override
public int replaceColor(Context context, @ColorInt int color) {
if (ThemeHelper.isDefaultTheme(context)) {
return color;
private void init() {
//初始化Leak内存泄露检测工具
LeakCanary.install(this);
//初始化Stetho调试工具
Stetho.initialize(
Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
.build());
}
String theme = getTheme(context);
int colorId = -1;

if (theme != null) {
colorId = getThemeColor(context, color, theme);
}
return colorId != -1 ? getResources().getColor(colorId) : color;
}


private String getTheme(Context context) {
if (ThemeHelper.getTheme(context) == ThemeHelper.CARD_STORM) {
return "blue";
} else if (ThemeHelper.getTheme(context) == ThemeHelper.CARD_HOPE) {
return "purple";
} else if (ThemeHelper.getTheme(context) == ThemeHelper.CARD_WOOD) {
return "green";
} else if (ThemeHelper.getTheme(context) == ThemeHelper.CARD_LIGHT) {
return "green_light";
} else if (ThemeHelper.getTheme(context) == ThemeHelper.CARD_THUNDER) {
return "yellow";
} else if (ThemeHelper.getTheme(context) == ThemeHelper.CARD_SAND) {
return "orange";
} else if (ThemeHelper.getTheme(context) == ThemeHelper.CARD_FIREY) {
return "red";
public static BilibiliApp getInstance() {
return mInstance;
}
return null;
}


private
@ColorRes
int getThemeColorId(Context context, int colorId, String theme) {
switch (colorId) {
case R.color.theme_color_primary:
return context.getResources().getIdentifier(theme, "color", getPackageName());
case R.color.theme_color_primary_dark:
return context.getResources().getIdentifier(theme + "_dark", "color", getPackageName());
case R.color.theme_color_primary_trans:
return context.getResources().getIdentifier(theme + "_trans", "color", getPackageName());
}
return colorId;
}


private
@ColorRes
int getThemeColor(Context context, int color, String theme) {
switch (color) {
case 0xfffb7299:
return context.getResources().getIdentifier(theme, "color", getPackageName());
case 0xffb85671:
return context.getResources().getIdentifier(theme + "_dark", "color", getPackageName());
case 0x99f0486c:
return context.getResources().getIdentifier(theme + "_trans", "color", getPackageName());
}
return -1;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
package com.hotbitmapgg.bilibili.base;

import android.app.Activity;
import android.app.ActivityManager;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.bilibili.magicasakura.utils.ThemeUtils;
import com.hotbitmapgg.bilibili.utils.ThemeHelper;
import com.hotbitmapgg.bilibili.widget.dialog.CardPickerDialog;
import com.hotbitmapgg.ohmybilibili.R;

import com.trello.rxlifecycle.components.support.RxAppCompatActivity;

import butterknife.ButterKnife;
Expand All @@ -23,7 +13,7 @@
* <p/>
* Activity基类
*/
public abstract class RxBaseActivity extends RxAppCompatActivity implements CardPickerDialog.ClickListener {
public abstract class RxBaseActivity extends RxAppCompatActivity {
private Unbinder bind;

@Override
Expand Down Expand Up @@ -95,49 +85,6 @@ public void initRefreshLayout() {
public void finishTask() {
}


@Override
public void onConfirm(int currentTheme) {
if (ThemeHelper.getTheme(RxBaseActivity.this) != currentTheme) {
ThemeHelper.setTheme(RxBaseActivity.this, currentTheme);
ThemeUtils.refreshUI(RxBaseActivity.this, new ThemeUtils.ExtraRefreshable() {
@Override
public void refreshGlobal(Activity activity) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
final RxBaseActivity context = RxBaseActivity.this;
ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(null, null,
ThemeUtils.getThemeAttrColor(context, android.R.attr.colorPrimary));
setTaskDescription(taskDescription);
getWindow().setStatusBarColor(ThemeUtils.getColorById(context,
R.color.theme_color_primary_dark));
}
}


@Override
public void refreshSpecificView(View view) {
}
}
);
}
}


@Override
public void onPostCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onPostCreate(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(ThemeUtils.getColorById(this, R.color.theme_color_primary_dark));
ActivityManager.TaskDescription description = new ActivityManager.TaskDescription(null, null,
ThemeUtils.getThemeAttrColor(this, android.R.attr.colorPrimary));
setTaskDescription(description);
}
}


@Override
protected void onDestroy() {
super.onDestroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.hotbitmapgg.bilibili.utils.PreferenceUtil;
import com.hotbitmapgg.bilibili.utils.ToastUtil;
import com.hotbitmapgg.bilibili.widget.CircleImageView;
import com.hotbitmapgg.bilibili.widget.dialog.CardPickerDialog;
import com.hotbitmapgg.ohmybilibili.R;

import butterknife.BindView;
Expand Down Expand Up @@ -170,9 +169,6 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
return true;
case R.id.item_theme:
// 主题选择
CardPickerDialog dialog = new CardPickerDialog();
dialog.setClickListener(this);
dialog.show(getSupportFragmentManager(), CardPickerDialog.TAG);
return true;
case R.id.item_app:
// 应用推荐
Expand Down
60 changes: 0 additions & 60 deletions app/src/main/java/com/hotbitmapgg/bilibili/utils/ThemeHelper.java

This file was deleted.

Loading

0 comments on commit fc27335

Please sign in to comment.