forked from HotBitmapGG/bilibili-android-client
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
009d53a
commit 80be8d8
Showing
232 changed files
with
32,853 additions
and
33,519 deletions.
There are no files selected for viewing
221 changes: 103 additions & 118 deletions
221
app/src/main/java/com/hotbitmapgg/bilibili/BilibiliApp.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 |
---|---|---|
@@ -1,151 +1,136 @@ | ||
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; | ||
|
||
import android.app.Application; | ||
import android.content.Context; | ||
import android.support.annotation.ColorInt; | ||
import android.support.annotation.ColorRes; | ||
|
||
/** | ||
* Created by hcc on 16/8/7 21:18 | ||
* 100332338@qq.com | ||
* <p/> | ||
* 哔哩哔哩动画App | ||
*/ | ||
public class BilibiliApp extends Application implements ThemeUtils.switchColor | ||
{ | ||
public class BilibiliApp extends Application implements ThemeUtils.switchColor { | ||
|
||
public static BilibiliApp mInstance; | ||
public static BilibiliApp mInstance; | ||
|
||
@Override | ||
public void onCreate() | ||
{ | ||
|
||
super.onCreate(); | ||
@Override | ||
public void onCreate() { | ||
|
||
mInstance = this; | ||
init(); | ||
} | ||
super.onCreate(); | ||
|
||
mInstance = this; | ||
init(); | ||
} | ||
|
||
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() | ||
{ | ||
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()); | ||
} | ||
|
||
return mInstance; | ||
|
||
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); | ||
} | ||
return context.getResources().getColor(colorId); | ||
} | ||
|
||
@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); | ||
} | ||
return context.getResources().getColor(colorId); | ||
|
||
@Override | ||
public int replaceColor(Context context, @ColorInt int color) { | ||
|
||
if (ThemeHelper.isDefaultTheme(context)) { | ||
return color; | ||
} | ||
String theme = getTheme(context); | ||
int colorId = -1; | ||
|
||
@Override | ||
public int replaceColor(Context context, @ColorInt int color) | ||
{ | ||
|
||
if (ThemeHelper.isDefaultTheme(context)) | ||
{ | ||
return color; | ||
} | ||
String theme = getTheme(context); | ||
int colorId = -1; | ||
|
||
if (theme != null) | ||
{ | ||
colorId = getThemeColor(context, color, theme); | ||
} | ||
return colorId != -1 ? getResources().getColor(colorId) : color; | ||
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"; | ||
} | ||
return null; | ||
} | ||
|
||
|
||
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"; | ||
} | ||
return null; | ||
} | ||
private | ||
@ColorRes | ||
int getThemeColorId(Context context, int colorId, String theme) { | ||
|
||
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; | ||
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) { | ||
|
||
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; | ||
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; | ||
} | ||
} |
Oops, something went wrong.