使用预设颜色,避免随机生成的奇怪颜色
This commit is contained in:
1 parent
ba7f1a5aed
commit
ff2ed3205d
9 files changed
+70
-64
No files matched your search
@@ -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<String, Integer> 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("+");
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<AlertButton> mButtonList;
|
||||
private int mThemeColor;
|
||||
|
||||
|
||||
private final Context mContext;
|
||||
private final View mView;
|
||||
private final LinearLayout mRootView;
|
||||
private final LinearLayout mContainer;
|
||||
|
||||
private final List<AlertButton> 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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user