From f39cfc787511a0673294f08d5faad5bac00d33d4 Mon Sep 17 00:00:00 2001 From: seven332 Date: Fri, 13 Jun 2014 18:14:41 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9A=8F=E6=9C=BA=E4=B8=BB=E9=A2=98=E9=85=8D?= =?UTF-8?q?=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- res/layout/buttons_dialog.xml | 1 + res/layout/detail.xml | 1 + res/layout/dialog.xml | 1 + res/layout/list_menu_left.xml | 1 + res/layout/preview_list_panel.xml | 18 ++-- res/values-v19/themes.xml | 36 ++++++++ .../ehviewer/ui/DetailSectionFragment.java | 67 +++++++++++++- .../hippo/ehviewer/ui/FavouriteActivity.java | 19 ++-- .../ehviewer/ui/MangaDetailActivity.java | 11 +-- .../hippo/ehviewer/ui/MangaListActivity.java | 20 +++-- .../hippo/ehviewer/ui/SettingsActivity.java | 14 ++- src/com/hippo/ehviewer/util/Theme.java | 89 +++++++++++++++++++ src/com/hippo/ehviewer/util/Ui.java | 6 +- .../ehviewer/widget/ButtonsDialogBuilder.java | 6 ++ .../hippo/ehviewer/widget/DialogBuilder.java | 28 ++++-- src/com/hippo/ehviewer/widget/SuperToast.java | 3 + 16 files changed, 275 insertions(+), 46 deletions(-) create mode 100644 res/values-v19/themes.xml create mode 100644 src/com/hippo/ehviewer/util/Theme.java diff --git a/res/layout/buttons_dialog.xml b/res/layout/buttons_dialog.xml index 80797f860..3b3ea75ed 100644 --- a/res/layout/buttons_dialog.xml +++ b/res/layout/buttons_dialog.xml @@ -20,6 +20,7 @@ android:orientation="vertical" > diff --git a/res/layout/dialog.xml b/res/layout/dialog.xml index 45f47d726..880c04557 100644 --- a/res/layout/dialog.xml +++ b/res/layout/dialog.xml @@ -20,6 +20,7 @@ android:orientation="vertical" > - + android:layout_width="24.0dp" + android:layout_height="48.0dp" /> - + android:layout_width="24.0dp" + android:layout_height="48.0dp" /> \ No newline at end of file diff --git a/res/values-v19/themes.xml b/res/values-v19/themes.xml new file mode 100644 index 000000000..c48531ab2 --- /dev/null +++ b/res/values-v19/themes.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/com/hippo/ehviewer/ui/DetailSectionFragment.java b/src/com/hippo/ehviewer/ui/DetailSectionFragment.java index bbca03cf9..f10b14034 100644 --- a/src/com/hippo/ehviewer/ui/DetailSectionFragment.java +++ b/src/com/hippo/ehviewer/ui/DetailSectionFragment.java @@ -35,6 +35,7 @@ import com.hippo.ehviewer.ehclient.DetailParser; import com.hippo.ehviewer.ehclient.EhClient; import com.hippo.ehviewer.util.Cache; import com.hippo.ehviewer.util.Log; +import com.hippo.ehviewer.util.Theme; import com.hippo.ehviewer.util.Ui; import com.hippo.ehviewer.util.Util; import com.hippo.ehviewer.widget.AlertButton; @@ -57,8 +58,12 @@ import android.content.res.ColorStateList; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Color; +import android.graphics.Path; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.ShapeDrawable; +import android.graphics.drawable.StateListDrawable; +import android.graphics.drawable.shapes.PathShape; import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.TypedValue; @@ -119,6 +124,40 @@ public class DetailSectionFragment extends Fragment private int mCurPage; private boolean mShowPreview = false; + private ShapeDrawable getArrowShapeDrawable(int color, boolean isToLeft) { + Path path = new Path(); + if (isToLeft) { + path.moveTo(50, 0); + path.lineTo(50, 100); + path.lineTo(0, 50); + path.close(); + } else { + path.moveTo(0, 0); + path.lineTo(0, 100); + path.lineTo(50, 50); + path.close(); + } + ShapeDrawable d = new ShapeDrawable(new PathShape(path, 50, 100)); + d.getPaint().setColor(color); + //d.setBounds(0, 0, Ui.dp2pix(24), Ui.dp2pix(48)); + return d; + } + + private StateListDrawable getArrowClickDrawable(int color, boolean isToLeft) { + StateListDrawable sld = new StateListDrawable(); + ShapeDrawable normal = getArrowShapeDrawable(color, isToLeft); + ShapeDrawable grey = getArrowShapeDrawable(Theme.GREY_COLOR, isToLeft); + ShapeDrawable dark = getArrowShapeDrawable(Theme.getDarkerColor(color), isToLeft); + sld.addState(new int[]{-android.R.attr.state_enabled}, grey); + sld.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_selected}, dark); + sld.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_focused}, dark); + sld.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed}, dark); + sld.addState(new int[]{}, normal); + //sld.setBounds(0, 0, Ui.dp2pix(24), Ui.dp2pix(48)); + return sld; + } + + @SuppressWarnings("deprecation") @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -162,6 +201,24 @@ public class DetailSectionFragment extends Fragment mFrontButton = mPreviewListMain.findViewById(R.id.front); mDivider = mNormalView.findViewById(R.id.divider); + int color; + // Set random color + color = Theme.getRandomDeepColor(); + mReadButton.setBackgroundDrawable(Theme.getClickDrawable(mActivity, color)); + mRateButton.setBackgroundDrawable(Theme.getClickDrawable(mActivity, color)); + color = Theme.getRandomDeepColor(); + mRootView.findViewById(R.id.crude_divider).setBackgroundColor(Theme.getRandomDeepColor()); + color = Theme.getRandomDeepColor(); + 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)); + color = Theme.getRandomDeepColor(); + mPreviewNumText.setBackgroundDrawable(Theme.getClickDrawable(mActivity, color)); + mBackButton.setBackgroundDrawable(getArrowClickDrawable(color, true)); + mFrontButton.setBackgroundDrawable(getArrowClickDrawable(color, false)); + mRefreshButton.setOnClickListener(this); FswView align = (FswView)mActivity.findViewById(R.id.alignment); @@ -193,8 +250,6 @@ public class DetailSectionFragment extends Fragment } }); - - LoadImageView thumb = (LoadImageView)mRootView.findViewById(R.id.detail_cover); Bitmap bmp = null; if (Cache.memoryCache != null && @@ -398,6 +453,7 @@ public class DetailSectionFragment extends Fragment }).create(); } + @SuppressWarnings("deprecation") private void addTags() { LinearLayout tagsLayout = (LinearLayout)mRootView.findViewById(R.id.tags_layout); LinkedHashMap>> tagGroups = @@ -406,6 +462,7 @@ public class DetailSectionFragment extends Fragment int x = Ui.dp2pix(4); int y = Ui.dp2pix(4); Resources resources = getResources(); + // Get tag view resources int tagTextSize = resources.getDimensionPixelOffset(R.dimen.button_small_size); ColorStateList tagTextColor = resources.getColorStateList(R.color.blue_bn_text); @@ -425,13 +482,15 @@ public class DetailSectionFragment extends Fragment tagGroupLayout.addView(groupNameView, lp); // tags + // get random color + int tagColor = Theme.getRandomDeepColor(); for (SimpleEntry tag : tagGroup.getValue()) { final String tagText = tag.getKey(); Button tagView = new Button(mActivity); tagView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tagTextSize); tagView.setText(String.format("%s (%d)", tagText, tag.getValue())); tagView.setTextColor(tagTextColor); - tagView.setBackgroundResource(R.drawable.clickable_bg_blue); + tagView.setBackgroundDrawable(Theme.getClickDrawable(mActivity, tagColor)); tagView.setPadding(tagPaddingX, tagPaddingY, tagPaddingX, tagPaddingY); tagView.setOnClickListener(new OnClickListener() { @Override @@ -476,7 +535,7 @@ public class DetailSectionFragment extends Fragment addtagView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tagTextSize); addtagView.setText("+"); addtagView.setTextColor(tagTextColor); - addtagView.setBackgroundResource(R.drawable.clickable_bg_blue); + addtagView.setBackgroundDrawable(Theme.getClickDrawable(mActivity, Theme.getRandomDeepColor())); addtagView.setPadding(tagPaddingX, tagPaddingY, tagPaddingX, tagPaddingY); addtagView.setOnClickListener(new View.OnClickListener() { @Override diff --git a/src/com/hippo/ehviewer/ui/FavouriteActivity.java b/src/com/hippo/ehviewer/ui/FavouriteActivity.java index 1dc4ac06c..1ba444205 100644 --- a/src/com/hippo/ehviewer/ui/FavouriteActivity.java +++ b/src/com/hippo/ehviewer/ui/FavouriteActivity.java @@ -23,7 +23,6 @@ import java.util.Set; import android.app.ActionBar; import android.app.AlertDialog; -import android.app.ProgressDialog; import android.content.Intent; import android.content.res.Configuration; import android.content.res.Resources; @@ -55,6 +54,7 @@ import com.hippo.ehviewer.data.GalleryInfo; import com.hippo.ehviewer.ehclient.EhClient; import com.hippo.ehviewer.service.DownloadService; import com.hippo.ehviewer.service.DownloadServiceConnection; +import com.hippo.ehviewer.util.Theme; import com.hippo.ehviewer.util.Ui; import com.hippo.ehviewer.widget.ActionableToastBar; import com.hippo.ehviewer.widget.DialogBuilder; @@ -139,12 +139,7 @@ public class FavouriteActivity extends AbstractGalleryActivity mImageGeterManager = mAppContext.getImageGeterManager(); mClient = mAppContext.getEhClient(); - int color = getResources().getColor(android.R.color.holo_blue_dark) - & 0x00ffffff | 0xdd000000; - Drawable drawable = new ColorDrawable(color); - Ui.translucent(this, drawable); final ActionBar actionBar = getActionBar(); - actionBar.setBackgroundDrawable(drawable); getActionBar().setDisplayHomeAsUpEnabled(true); // Download service @@ -283,6 +278,13 @@ public class FavouriteActivity extends AbstractGalleryActivity } }); + // Set random color + int color = Theme.getRandomDeepColor() & 0x00ffffff | 0xdd000000; + Drawable drawable = new ColorDrawable(color); + actionBar.setBackgroundDrawable(drawable); + Ui.translucent(this, color); + mMenuList.setBackgroundColor(color); + // Check login if (!mClient.isLogin()) { SuperToast superToast = new SuperToast(this, "未检测到登陆状态,仅可使用本地收藏。由于开发者的问题,本地收藏不可靠,请尽快登陆,将本地收藏转移至账户中的收藏。"); @@ -366,7 +368,7 @@ public class FavouriteActivity extends AbstractGalleryActivity private void startMoveFromLocal2Cloud() { mPdb = new ProgressDialogBulider(FavouriteActivity.this); - mPdb.setCancelable(true).setTitle("正在移动..."); + mPdb.setCancelable(false).setTitle("正在移动..."); mPdb.setMax(mChoiceGiSetCopy.size()).setProgress(0); mProgressDialog = mPdb.create(); mProgressDialog.show(); @@ -519,8 +521,7 @@ public class FavouriteActivity extends AbstractGalleryActivity @Override public void onSuccess(ArrayList gis, int indexPerPage, int maxPage) { - if (mTargetCat == mMenuIndex - 1) - setGalleryInfos(gis, maxPage); + setGalleryInfos(gis, maxPage); mHlv.setRefreshing(false); new SuperToast(FavouriteActivity.this, mSuccStr).show(); diff --git a/src/com/hippo/ehviewer/ui/MangaDetailActivity.java b/src/com/hippo/ehviewer/ui/MangaDetailActivity.java index 6cfe766f2..957c2126c 100644 --- a/src/com/hippo/ehviewer/ui/MangaDetailActivity.java +++ b/src/com/hippo/ehviewer/ui/MangaDetailActivity.java @@ -27,6 +27,7 @@ import com.hippo.ehviewer.ehclient.DetailUrlParser; import com.hippo.ehviewer.ehclient.EhClient; import com.hippo.ehviewer.service.DownloadService; import com.hippo.ehviewer.service.DownloadServiceConnection; +import com.hippo.ehviewer.util.Theme; import com.hippo.ehviewer.util.Ui; import com.hippo.ehviewer.widget.AlertButton; import com.hippo.ehviewer.widget.DialogBuilder; @@ -126,15 +127,15 @@ public class MangaDetailActivity extends AbstractFragmentActivity handleIntent(getIntent()); - int color = getResources().getColor(android.R.color.holo_blue_dark) - & 0x00ffffff | 0xdd000000; - Drawable drawable = new ColorDrawable(color); - Ui.translucent(this, drawable); - final ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); + + // Set random color + int color = Theme.getRandomDeepColor() & 0x00ffffff | 0xdd000000; + Drawable drawable = new ColorDrawable(color); actionBar.setBackgroundDrawable(drawable); + Ui.translucent(this, color); SectionsPagerAdapter adapter = new SectionsPagerAdapter(getSupportFragmentManager()); diff --git a/src/com/hippo/ehviewer/ui/MangaListActivity.java b/src/com/hippo/ehviewer/ui/MangaListActivity.java index 72e3390f3..34cee517d 100644 --- a/src/com/hippo/ehviewer/ui/MangaListActivity.java +++ b/src/com/hippo/ehviewer/ui/MangaListActivity.java @@ -38,6 +38,7 @@ import com.hippo.ehviewer.service.DownloadService; import com.hippo.ehviewer.service.DownloadServiceConnection; import com.hippo.ehviewer.util.Config; import com.hippo.ehviewer.util.Log; +import com.hippo.ehviewer.util.Theme; import com.hippo.ehviewer.util.Ui; import com.hippo.ehviewer.util.Util; import com.hippo.ehviewer.widget.AlertButton; @@ -74,6 +75,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.ViewGroup.LayoutParams; import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; @@ -137,7 +139,7 @@ public class MangaListActivity extends AbstractGalleryActivity private Resources mResources; private SlidingMenu mSlidingMenu; - + private View mMenuLeft; private LinearLayout mUserPanel; private SearchView mSearchView; private ListView itemListMenu; @@ -926,13 +928,6 @@ public class MangaListActivity extends AbstractGalleryActivity } }); - int color = getResources().getColor(android.R.color.holo_blue_dark) - & 0x00ffffff | 0xdd000000; - Drawable drawable = new ColorDrawable(color); - final ActionBar actionBar = getActionBar(); - actionBar.setBackgroundDrawable(drawable); - Ui.translucent(this, drawable); - // Download service Intent it = new Intent(MangaListActivity.this, DownloadService.class); bindService(it, mServiceConn, BIND_AUTO_CREATE); @@ -951,6 +946,7 @@ public class MangaListActivity extends AbstractGalleryActivity // Get View + mMenuLeft = findViewById(R.id.list_menu_left); mUserPanel = (LinearLayout)findViewById(R.id.user_panel); itemListMenu = (ListView) findViewById(R.id.list_menu_item_list); tagListMenu = (TagListView) findViewById(R.id.list_menu_tag_list); @@ -1144,6 +1140,14 @@ public class MangaListActivity extends AbstractGalleryActivity } }); + // Set random color + int color = Theme.getRandomDeepColor() & 0x00ffffff | 0xdd000000; + Drawable drawable = new ColorDrawable(color); + final ActionBar actionBar = getActionBar(); + actionBar.setBackgroundDrawable(drawable); + Ui.translucent(this, color); + mMenuLeft.setBackgroundColor(color); + tagListMenu.setBackgroundColor(color); // Check update if (Config.isAutoCheckForUpdate()) diff --git a/src/com/hippo/ehviewer/ui/SettingsActivity.java b/src/com/hippo/ehviewer/ui/SettingsActivity.java index 2041c579e..1c446cb33 100644 --- a/src/com/hippo/ehviewer/ui/SettingsActivity.java +++ b/src/com/hippo/ehviewer/ui/SettingsActivity.java @@ -29,6 +29,7 @@ import com.hippo.ehviewer.R; import com.hippo.ehviewer.UpdateHelper; import com.hippo.ehviewer.util.Cache; import com.hippo.ehviewer.util.Config; +import com.hippo.ehviewer.util.Theme; import com.hippo.ehviewer.util.Ui; import com.hippo.ehviewer.util.Util; import com.hippo.ehviewer.widget.AlertButton; @@ -40,9 +41,12 @@ import com.hippo.ehviewer.network.Downloader; import com.hippo.ehviewer.preference.AutoListPreference; import com.readystatesoftware.systembartint.SystemBarTintManager.SystemBarConfig; +import android.app.ActionBar; import android.app.AlertDialog; import android.content.Intent; import android.content.res.Configuration; +import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.preference.CheckBoxPreference; @@ -112,9 +116,15 @@ public class SettingsActivity extends AbstractPreferenceActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - getActionBar().setDisplayHomeAsUpEnabled(true); + // Set random color + int color = Theme.getRandomDeepColor() & 0x00ffffff | 0xdd000000; + Drawable drawable = new ColorDrawable(color); + final ActionBar actionBar = getActionBar(); + actionBar.setBackgroundDrawable(drawable); + mSystemBarConfig = Ui.translucent(this, color); + + actionBar.setDisplayHomeAsUpEnabled(true); - mSystemBarConfig = Ui.translucent(this); mFragments = new LinkedList(); mListView = getListView(); diff --git a/src/com/hippo/ehviewer/util/Theme.java b/src/com/hippo/ehviewer/util/Theme.java new file mode 100644 index 000000000..cd9a3faad --- /dev/null +++ b/src/com/hippo/ehviewer/util/Theme.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2014 Hippo Seven + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hippo.ehviewer.util; + +import java.util.Random; + +import android.content.Context; +import android.content.res.ColorStateList; +import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.StateListDrawable; + +public class Theme { + + private static final Random random = + new Random(System.currentTimeMillis()); + public static final int GREY_COLOR = 0xffaaaaaa; + public static final ColorDrawable GREY_DRAWABLE = + new ColorDrawable(0xffaaaaaa); + + /** + * Ignore alpha + * @param color + * @return + */ + 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; + } + + /** + * Get random deep color, alpha is 0xff + * @return + */ + public static int getRandomDeepColor() { + int deepColor; + while(!isDeepColor(deepColor = getRandomColor())); + return deepColor; + } + + /** + * get darker color of target color, alpha not change + * @param color + * @return + */ + public static int getDarkerColor(int color) { + return (((color & 0xff0000) >> 1) & 0xff0000) + | (((color & 0xff00) >> 1) & 0xff00) + | (((color & 0xff) >> 1) & 0xff) + | (color & 0xff000000); + } + + public static StateListDrawable getClickDrawable(Context context, int color) { + StateListDrawable sld = new StateListDrawable(); + ColorDrawable normal = new ColorDrawable(color); + ColorDrawable dark = new ColorDrawable(getDarkerColor(color)); + sld.addState(new int[]{-android.R.attr.state_enabled}, GREY_DRAWABLE); + sld.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_selected}, dark); + sld.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_focused}, dark); + sld.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed}, dark); + sld.addState(new int[]{}, normal); + return sld; + } +} diff --git a/src/com/hippo/ehviewer/util/Ui.java b/src/com/hippo/ehviewer/util/Ui.java index e0286e585..fece02a8f 100644 --- a/src/com/hippo/ehviewer/util/Ui.java +++ b/src/com/hippo/ehviewer/util/Ui.java @@ -280,14 +280,14 @@ public class Ui { public static SystemBarConfig translucentColor( Activity activity, int color) { - return translucent(activity, new ColorDrawable(color)); + return translucent(activity, color); } public static SystemBarConfig translucent( - Activity activity, Drawable drawable) { + Activity activity, int color) { SystemBarTintManager tintManager = new SystemBarTintManager(activity); tintManager.setStatusBarTintEnabled(true); - tintManager.setStatusBarTintDrawable(drawable); + tintManager.setStatusBarTintColor(color); tintManager.setNavigationBarTintEnabled(true); tintManager.setNavigationBarAlpha(0.0f); return tintManager.getConfig(); diff --git a/src/com/hippo/ehviewer/widget/ButtonsDialogBuilder.java b/src/com/hippo/ehviewer/widget/ButtonsDialogBuilder.java index 1864ae3c0..5c77565bb 100644 --- a/src/com/hippo/ehviewer/widget/ButtonsDialogBuilder.java +++ b/src/com/hippo/ehviewer/widget/ButtonsDialogBuilder.java @@ -20,6 +20,7 @@ import java.util.LinkedList; import java.util.List; import com.hippo.ehviewer.R; +import com.hippo.ehviewer.util.Theme; import android.app.AlertDialog; import android.content.Context; @@ -39,6 +40,7 @@ public class ButtonsDialogBuilder extends AlertDialog.Builder { private LinearLayout mContainer; private List mButtonList; + private int mThemeColor; public ButtonsDialogBuilder(Context context) { super(context); @@ -54,6 +56,8 @@ public class ButtonsDialogBuilder extends AlertDialog.Builder { LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); mRootView.addView(mContainer, lp); super.setView(mView); + + mThemeColor = Theme.getRandomDeepColor(); } /** @@ -77,6 +81,8 @@ public class ButtonsDialogBuilder extends AlertDialog.Builder { TextView titleView = (TextView)mView.findViewById(R.id.title); titleView.setVisibility(View.VISIBLE); titleView.setText(title); + // Set random color + mView.findViewById(R.id.title_layout).setBackgroundColor(mThemeColor); return this; } diff --git a/src/com/hippo/ehviewer/widget/DialogBuilder.java b/src/com/hippo/ehviewer/widget/DialogBuilder.java index 534b094cb..9692a789c 100644 --- a/src/com/hippo/ehviewer/widget/DialogBuilder.java +++ b/src/com/hippo/ehviewer/widget/DialogBuilder.java @@ -19,6 +19,7 @@ package com.hippo.ehviewer.widget; import java.util.List; import com.hippo.ehviewer.R; +import com.hippo.ehviewer.util.Theme; import android.app.AlertDialog; import android.content.Context; @@ -38,8 +39,12 @@ import android.widget.ScrollView; import android.widget.TextView; public class DialogBuilder extends AlertDialog.Builder { + private View mView; private Context mContext; + + private int mThemeColor; + public DialogBuilder(Context context) { super(context); mContext = context; @@ -47,6 +52,8 @@ public class DialogBuilder extends AlertDialog.Builder { Context.LAYOUT_INFLATER_SERVICE); mView = inflater.inflate(R.layout.dialog, null); super.setView(mView); + + mThemeColor = Theme.getRandomDeepColor(); } /** @@ -70,6 +77,8 @@ public class DialogBuilder extends AlertDialog.Builder { TextView titleView = (TextView)mView.findViewById(R.id.title); titleView.setVisibility(View.VISIBLE); titleView.setText(title); + // Set random color + mView.findViewById(R.id.title_layout).setBackgroundColor(mThemeColor); return this; } @@ -135,7 +144,7 @@ public class DialogBuilder extends AlertDialog.Builder { lp.gravity = Gravity.CENTER; } else { lp = new LinearLayout.LayoutParams( - LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); + LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); } setView(view, lp); return this; @@ -180,11 +189,14 @@ public class DialogBuilder extends AlertDialog.Builder { * * @return This Builder object to allow for chaining of calls to set methods */ + @SuppressWarnings("deprecation") public DialogBuilder setPositiveButton(CharSequence text, final View.OnClickListener listener) { Button button = (Button)mView.findViewById(R.id.positive_button); button.setVisibility(View.VISIBLE); button.setText(text); button.setOnClickListener(listener); + // Set random color + button.setBackgroundDrawable(Theme.getClickDrawable(mContext, mThemeColor)); return this; } @@ -207,19 +219,19 @@ public class DialogBuilder extends AlertDialog.Builder { * * @return This Builder object to allow for chaining of calls to set methods */ + @SuppressWarnings("deprecation") public DialogBuilder setNegativeButton(CharSequence text, final View.OnClickListener listener) { Button button = (Button)mView.findViewById(R.id.negative_button); button.setVisibility(View.VISIBLE); button.setText(text); button.setOnClickListener(listener); + // Set random color + button.setBackgroundDrawable(Theme.getClickDrawable(mContext, mThemeColor)); return this; } public DialogBuilder setSimpleNegativeButton() { - Button button = (Button)mView.findViewById(R.id.negative_button); - button.setVisibility(View.VISIBLE); - button.setText(android.R.string.cancel); - button.setOnClickListener(new View.OnClickListener() { + setNegativeButton(android.R.string.cancel, new View.OnClickListener() { @Override public void onClick(View v) { ((AlertButton)v).dialog.dismiss(); @@ -247,11 +259,14 @@ public class DialogBuilder extends AlertDialog.Builder { * * @return This Builder object to allow for chaining of calls to set methods */ + @SuppressWarnings("deprecation") public DialogBuilder setNeutralButton(CharSequence text, final View.OnClickListener listener) { Button button = (Button)mView.findViewById(R.id.neutral_button); button.setVisibility(View.VISIBLE); button.setText(text); button.setOnClickListener(listener); + // Set random color + button.setBackgroundDrawable(Theme.getClickDrawable(mContext, mThemeColor)); return this; } @@ -329,12 +344,15 @@ public class DialogBuilder extends AlertDialog.Builder { return this; } + @SuppressWarnings("deprecation") public DialogBuilder setAction(Drawable drawable, View.OnClickListener listener) { ImageView actionView = (ImageView)mView.findViewById(R.id.action); actionView.setVisibility(View.VISIBLE); if (drawable != null) actionView.setImageDrawable(drawable); actionView.setOnClickListener(listener); + // Set random color + actionView.setBackgroundDrawable(Theme.getClickDrawable(mContext, mThemeColor)); return this; } diff --git a/src/com/hippo/ehviewer/widget/SuperToast.java b/src/com/hippo/ehviewer/widget/SuperToast.java index 307a44691..f8acc4d1a 100644 --- a/src/com/hippo/ehviewer/widget/SuperToast.java +++ b/src/com/hippo/ehviewer/widget/SuperToast.java @@ -17,6 +17,7 @@ package com.hippo.ehviewer.widget; import com.hippo.ehviewer.R; +import com.hippo.ehviewer.util.Theme; import android.content.Context; import android.graphics.drawable.Drawable; @@ -72,6 +73,8 @@ public class SuperToast extends Toast { mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); FrameLayout view = (FrameLayout)inflate.inflate(R.layout.super_toast, null); mMainView = (LinearLayout)view.getChildAt(0); + // Set random color + mMainView.setBackgroundColor(Theme.getRandomDeepColor()); mIcon = (ImageView)mMainView.findViewById(R.id.icon); mMessage = (TextView)mMainView.findViewById(R.id.message);