diff --git a/src/com/hippo/ehviewer/ui/DetailSectionFragment.java b/src/com/hippo/ehviewer/ui/DetailSectionFragment.java index 9aebf3f46..197170a62 100644 --- a/src/com/hippo/ehviewer/ui/DetailSectionFragment.java +++ b/src/com/hippo/ehviewer/ui/DetailSectionFragment.java @@ -268,21 +268,21 @@ public class DetailSectionFragment extends Fragment int color = Config.getThemeColor(); // Set random color if (isRandomColor) - color = Theme.getRandomDeepColor(); + color = Theme.getRandomDarkColor(); mReadButton.setBackgroundDrawable(Theme.getClickDrawable(mActivity, color)); mRateButton.setBackgroundDrawable(Theme.getClickDrawable(mActivity, color)); if (isRandomColor) - color = Theme.getRandomDeepColor(); + color = Theme.getRandomDarkColor(); mColorfulBar.setBackgroundColor(color); if (isRandomColor) - color = Theme.getRandomDeepColor(); + color = Theme.getRandomDarkColor(); mRefreshButton.setBackgroundDrawable(Theme.getClickDrawable(mActivity, color)); mCancelButton.setBackgroundDrawable(Theme.getClickDrawable(mActivity, color)); mOnceButton.setBackgroundDrawable(Theme.getClickDrawable(mActivity, color)); mEveryButton.setBackgroundDrawable(Theme.getClickDrawable(mActivity, color)); mKnownButton.setBackgroundDrawable(Theme.getClickDrawable(mActivity, color)); if (isRandomColor) - color = Theme.getRandomDeepColor(); + color = Theme.getRandomDarkColor(); mPreviewNumText.setBackgroundDrawable(Theme.getClickDrawable(mActivity, color)); mBackButton.setBackgroundDrawable(getArrowClickDrawable(color, true)); mFrontButton.setBackgroundDrawable(getArrowClickDrawable(color, false)); @@ -452,7 +452,7 @@ public class DetailSectionFragment extends Fragment // tags // get random color if (isRandomColor) - color = Theme.getRandomDeepColor(); + color = Theme.getRandomDarkColor(); for (SimpleEntry tag : tagGroup.getValue()) { final String tagText = tag.getKey(); Button tagView = new Button(mActivity); @@ -501,7 +501,7 @@ public class DetailSectionFragment extends Fragment // Add tag if (isRandomColor) - color = Theme.getRandomDeepColor(); + color = Theme.getRandomDarkColor(); Button addtagView = new Button(mActivity); addtagView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tagTextSize); addtagView.setText("+"); diff --git a/src/com/hippo/ehviewer/ui/FavouriteActivity.java b/src/com/hippo/ehviewer/ui/FavouriteActivity.java index 8e7be3cb6..d9c11aae3 100644 --- a/src/com/hippo/ehviewer/ui/FavouriteActivity.java +++ b/src/com/hippo/ehviewer/ui/FavouriteActivity.java @@ -273,7 +273,7 @@ public class FavouriteActivity extends AbstractGalleryActivity }); // Set random color - int color = Config.getRandomThemeColor() ? Theme.getRandomDeepColor() : Config.getThemeColor(); + int color = Config.getRandomThemeColor() ? Theme.getRandomDarkColor() : Config.getThemeColor(); color = color & 0x00ffffff | 0xdd000000; Drawable drawable = new ColorDrawable(color); actionBar.setBackgroundDrawable(drawable); diff --git a/src/com/hippo/ehviewer/ui/MangaDetailActivity.java b/src/com/hippo/ehviewer/ui/MangaDetailActivity.java index 59374b76d..e89b6db42 100644 --- a/src/com/hippo/ehviewer/ui/MangaDetailActivity.java +++ b/src/com/hippo/ehviewer/ui/MangaDetailActivity.java @@ -143,7 +143,7 @@ public class MangaDetailActivity extends AbstractFragmentActivity actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Set random color - int color = Config.getRandomThemeColor() ? Theme.getRandomDeepColor() : Config.getThemeColor(); + int color = Config.getRandomThemeColor() ? Theme.getRandomDarkColor() : Config.getThemeColor(); color = color & 0x00ffffff | 0xdd000000; Drawable drawable = new ColorDrawable(color); actionBar.setBackgroundDrawable(drawable); diff --git a/src/com/hippo/ehviewer/ui/MangaListActivity.java b/src/com/hippo/ehviewer/ui/MangaListActivity.java index d890df9a2..746d90f8e 100644 --- a/src/com/hippo/ehviewer/ui/MangaListActivity.java +++ b/src/com/hippo/ehviewer/ui/MangaListActivity.java @@ -1113,7 +1113,7 @@ public class MangaListActivity extends AbstractGalleryActivity }); // Set random color - int color = Config.getRandomThemeColor() ? Theme.getRandomDeepColor() : Config.getThemeColor(); + int color = Config.getRandomThemeColor() ? Theme.getRandomDarkColor() : Config.getThemeColor(); color = color & 0x00ffffff | 0xdd000000; Drawable drawable = new ColorDrawable(color); final ActionBar actionBar = getActionBar(); diff --git a/src/com/hippo/ehviewer/ui/SettingsActivity.java b/src/com/hippo/ehviewer/ui/SettingsActivity.java index 86e1a7caf..434651c77 100644 --- a/src/com/hippo/ehviewer/ui/SettingsActivity.java +++ b/src/com/hippo/ehviewer/ui/SettingsActivity.java @@ -128,7 +128,7 @@ public class SettingsActivity extends AbstractPreferenceActivity { super.onCreate(savedInstanceState); // Set random color - int color = Config.getRandomThemeColor() ? Theme.getRandomDeepColor() : Config.getThemeColor(); + int color = Config.getRandomThemeColor() ? Theme.getRandomDarkColor() : Config.getThemeColor(); color = color & 0x00ffffff | 0xdd000000; Drawable drawable = new ColorDrawable(color); final ActionBar actionBar = getActionBar(); diff --git a/src/com/hippo/ehviewer/util/Theme.java b/src/com/hippo/ehviewer/util/Theme.java index e2acf44a2..d5e6a19d9 100644 --- a/src/com/hippo/ehviewer/util/Theme.java +++ b/src/com/hippo/ehviewer/util/Theme.java @@ -23,7 +23,7 @@ import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.StateListDrawable; -public class Theme { +public final class Theme { private static final Random random = new Random(System.currentTimeMillis()); @@ -32,35 +32,40 @@ public class Theme { new ColorDrawable(0xffaaaaaa); /** - * Ignore alpha - * @param color - * @return + * Colors from colors_material.xml + * + * material_red_300, material_red_500, material_red_700, + * material_red_A200, material_blue_500, material_blue_700, + * material_blue_A200, material_blue_A400, material_teal_700, + * material_green_500, material_green_700, material_lime_700, + * material_yellow_500, material_yellow_700, material_orange_500, + * material_orange_700, material_orange_A400, material_deep_orange_500, + * material_deep_orange_700, material_deep_orange_A200, + * material_deep_orange_A400, material_grey_600, material_grey_700, + * material_blue_grey_500, material_blue_grey_600, + * material_blue_grey_700, material_blue_grey_800, + * material_brown_500, material_brown_700 */ - public static boolean isDeepColor(int color) { - int grayLevel = (int)(((color >> 16) & 0xff) * 0.299 - + ((color >> 8) & 0xff) * 0.587 + (color & 0xff) * 0.114); - if (grayLevel < 128) // I think 128 is better than 192 - return true; - else - return false; - } - - /** - * Get random color, alpha is 0xff - * @return - */ - public static int getRandomColor() { - return random.nextInt() | 0xff000000; - } + private static final int[] DARK_COLOR_TABLE = { + 0xffe67c73, 0xffdb4437, 0xffc53929, 0xffff5252, + 0xff4285f4, 0xff3367d6, 0xff448aff, 0xff2979ff, + 0xff0097a7, + 0xff0f9d58, 0xff0b8043, + 0xffafb42b, + 0xfff4b400, 0xfff09300, + 0xffff9800, 0xfff57c00, 0xffff9100, + 0xffff5722, 0xffc53929, 0xffff5252, 0xffff1744, + 0xff757575, 0xff717171, + 0xff607d8b, 0xff546e7a, 0xff455a64, 0xff37474f, + 0xff795548, 0xff5d4037 + }; /** * Get random deep color, alpha is 0xff * @return */ - public static int getRandomDeepColor() { - int deepColor; - while(!isDeepColor(deepColor = getRandomColor())); - return deepColor; + public static int getRandomDarkColor() { + return DARK_COLOR_TABLE[Math.abs(random.nextInt()) % DARK_COLOR_TABLE.length]; } /** diff --git a/src/com/hippo/ehviewer/widget/ButtonsDialogBuilder.java b/src/com/hippo/ehviewer/widget/ButtonsDialogBuilder.java index c69f83883..291f10e06 100644 --- a/src/com/hippo/ehviewer/widget/ButtonsDialogBuilder.java +++ b/src/com/hippo/ehviewer/widget/ButtonsDialogBuilder.java @@ -19,11 +19,8 @@ package com.hippo.ehviewer.widget; import java.util.LinkedList; import java.util.List; -import com.hippo.ehviewer.R; -import com.hippo.ehviewer.util.Config; -import com.hippo.ehviewer.util.Theme; - import android.app.AlertDialog; +import android.app.Dialog; import android.content.Context; import android.graphics.Color; import android.view.LayoutInflater; @@ -31,18 +28,22 @@ import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; +import com.hippo.ehviewer.R; +import com.hippo.ehviewer.util.Config; +import com.hippo.ehviewer.util.Theme; + public class ButtonsDialogBuilder extends AlertDialog.Builder { - + private static final float WEIGHT = 1.0f; - - private Context mContext; - private View mView; - private LinearLayout mRootView; - private LinearLayout mContainer; - - private List mButtonList; - private int mThemeColor; - + + private final Context mContext; + private final View mView; + private final LinearLayout mRootView; + private final LinearLayout mContainer; + + private final List mButtonList; + private final int mThemeColor; + public ButtonsDialogBuilder(Context context) { super(context); mContext = context; @@ -57,10 +58,10 @@ public class ButtonsDialogBuilder extends AlertDialog.Builder { LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); mRootView.addView(mContainer, lp); super.setView(mView); - - mThemeColor = Config.getRandomThemeColor() ? Theme.getRandomDeepColor() : Config.getThemeColor(); + + mThemeColor = Config.getRandomThemeColor() ? Theme.getRandomDarkColor() : Config.getThemeColor(); } - + /** * Set the title using the given resource id. * @@ -71,7 +72,7 @@ public class ButtonsDialogBuilder extends AlertDialog.Builder { setTitle(mContext.getText(titleId)); return this; } - + /** * Set the title displayed in the {@link Dialog}. * @@ -86,7 +87,7 @@ public class ButtonsDialogBuilder extends AlertDialog.Builder { mView.findViewById(R.id.title_layout).setBackgroundColor(mThemeColor); return this; } - + public ButtonsDialogBuilder addButton(AlertButton button) { button.setBackgroundResource(R.drawable.clickable_bg_white); button.setTextColor(Color.BLACK); @@ -97,7 +98,7 @@ public class ButtonsDialogBuilder extends AlertDialog.Builder { mContainer.addView(button, lp); return this; } - + @Override public AlertDialog create() { AlertDialog dialog = super.create(); diff --git a/src/com/hippo/ehviewer/widget/DialogBuilder.java b/src/com/hippo/ehviewer/widget/DialogBuilder.java index 659718df7..e584d19e0 100644 --- a/src/com/hippo/ehviewer/widget/DialogBuilder.java +++ b/src/com/hippo/ehviewer/widget/DialogBuilder.java @@ -57,7 +57,7 @@ public class DialogBuilder extends AlertDialog.Builder { mView = inflater.inflate(R.layout.dialog, null); super.setView(mView); - mThemeColor = Config.getRandomThemeColor() ? Theme.getRandomDeepColor() : Config.getThemeColor(); + mThemeColor = Config.getRandomThemeColor() ? Theme.getRandomDarkColor() : Config.getThemeColor(); } /** diff --git a/src/com/hippo/ehviewer/widget/SuperToast.java b/src/com/hippo/ehviewer/widget/SuperToast.java index 72259c959..01fc18596 100644 --- a/src/com/hippo/ehviewer/widget/SuperToast.java +++ b/src/com/hippo/ehviewer/widget/SuperToast.java @@ -16,10 +16,6 @@ package com.hippo.ehviewer.widget; -import com.hippo.ehviewer.R; -import com.hippo.ehviewer.util.Config; -import com.hippo.ehviewer.util.Theme; - import android.content.Context; import android.graphics.drawable.Drawable; import android.view.LayoutInflater; @@ -30,13 +26,17 @@ import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; +import com.hippo.ehviewer.R; +import com.hippo.ehviewer.util.Config; +import com.hippo.ehviewer.util.Theme; + public class SuperToast extends Toast { public static final int NONE = 0; public static final int WARNING = 1; public static final int ERROR = 2; - private Context mContext; + private final Context mContext; private LinearLayout mMainView; private ImageView mIcon; @@ -45,7 +45,7 @@ public class SuperToast extends Toast { public SuperToast(Context context) { super(context); mContext = context; - + init(); } @@ -75,12 +75,12 @@ public class SuperToast extends Toast { FrameLayout view = (FrameLayout)inflate.inflate(R.layout.super_toast, null); mMainView = (LinearLayout)view.getChildAt(0); // Set random color - mMainView.setBackgroundColor(Config.getRandomThemeColor() ? Theme.getRandomDeepColor() : Config.getThemeColor()); + mMainView.setBackgroundColor(Config.getRandomThemeColor() ? Theme.getRandomDarkColor() : Config.getThemeColor()); mIcon = (ImageView)mMainView.findViewById(R.id.icon); mMessage = (TextView)mMainView.findViewById(R.id.message); - + mIcon.setVisibility(View.GONE); - + setDuration(Toast.LENGTH_SHORT); setView(view); }