From 27cb0aa2604f035f4d168df5e77b6fa6e21eba57 Mon Sep 17 00:00:00 2001 From: seven332 Date: Sat, 7 Jun 2014 02:57:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20SuperToast?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- res/layout/super_toast.xml | 54 ++++++++++++++ .../hippo/ehviewer/ui/FavouriteActivity.java | 3 +- .../{ui => widget}/ActionableToastBar.java | 2 +- src/com/hippo/ehviewer/widget/SuperToast.java | 73 +++++++++++++++++++ 4 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 res/layout/super_toast.xml rename src/com/hippo/ehviewer/{ui => widget}/ActionableToastBar.java (99%) create mode 100644 src/com/hippo/ehviewer/widget/SuperToast.java diff --git a/res/layout/super_toast.xml b/res/layout/super_toast.xml new file mode 100644 index 000000000..8dddfdc42 --- /dev/null +++ b/res/layout/super_toast.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/com/hippo/ehviewer/ui/FavouriteActivity.java b/src/com/hippo/ehviewer/ui/FavouriteActivity.java index ca8e243aa..7836e3c13 100644 --- a/src/com/hippo/ehviewer/ui/FavouriteActivity.java +++ b/src/com/hippo/ehviewer/ui/FavouriteActivity.java @@ -57,14 +57,15 @@ 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.ui.ActionableToastBar.ActionClickedListener; import com.hippo.ehviewer.util.Cache; import com.hippo.ehviewer.util.Log; import com.hippo.ehviewer.util.Ui; +import com.hippo.ehviewer.widget.ActionableToastBar; import com.hippo.ehviewer.widget.DialogBuilder; import com.hippo.ehviewer.widget.FswView; import com.hippo.ehviewer.widget.LoadImageView; import com.hippo.ehviewer.widget.OnFitSystemWindowsListener; +import com.hippo.ehviewer.widget.ActionableToastBar.ActionClickedListener; import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu; public class FavouriteActivity extends AbstractGalleryActivity diff --git a/src/com/hippo/ehviewer/ui/ActionableToastBar.java b/src/com/hippo/ehviewer/widget/ActionableToastBar.java similarity index 99% rename from src/com/hippo/ehviewer/ui/ActionableToastBar.java rename to src/com/hippo/ehviewer/widget/ActionableToastBar.java index 678f920c5..c2297f9cf 100644 --- a/src/com/hippo/ehviewer/ui/ActionableToastBar.java +++ b/src/com/hippo/ehviewer/widget/ActionableToastBar.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.hippo.ehviewer.ui; +package com.hippo.ehviewer.widget; import com.hippo.ehviewer.R; diff --git a/src/com/hippo/ehviewer/widget/SuperToast.java b/src/com/hippo/ehviewer/widget/SuperToast.java new file mode 100644 index 000000000..964b0d5c8 --- /dev/null +++ b/src/com/hippo/ehviewer/widget/SuperToast.java @@ -0,0 +1,73 @@ +/* + * 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.widget; + +import com.hippo.ehviewer.R; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.Toast; + +public class SuperToast extends Toast { + + private Context mContext; + + private LinearLayout mMainView; + private ImageView mIcon; + private TextView mMessage; + + public SuperToast(Context context) { + super(context); + + mContext = context; + + LayoutInflater inflate = (LayoutInflater) + context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + mMainView = (LinearLayout)inflate.inflate(R.layout.super_toast, null); + mIcon = (ImageView)mMainView.findViewById(R.id.icon); + mMessage = (TextView)mMainView.findViewById(R.id.message); + + mIcon.setVisibility(View.GONE); + + setDuration(Toast.LENGTH_SHORT); + setView(mMainView); + } + + public SuperToast setIcon(int resId) { + return setIcon(mContext.getResources().getDrawable(resId)); + } + + public SuperToast setIcon(Drawable drawable) { + mIcon.setVisibility(View.VISIBLE); + mIcon.setImageDrawable(drawable); + return this; + } + + public SuperToast setMessage(int resId) { + return setMessage(mContext.getResources().getString(resId)); + } + + public SuperToast setMessage(CharSequence text) { + mMessage.setText(text); + return this; + } +}