使用原生 Toast 样式

This commit is contained in:
seven332 committed 2014-08-13 23:06:20 +08:00
1 parent 0e125738e2
commit a98cd0bc79
31 files changed
+454 -505

No files matched your search

+2 -2
View File
@@ -34,7 +34,7 @@ import com.hippo.ehviewer.util.Download;
import com.hippo.ehviewer.util.Favorite;
import com.hippo.ehviewer.util.ThreadPool;
import com.hippo.ehviewer.util.Ui;
import com.hippo.ehviewer.widget.SuperToast;
import com.hippo.ehviewer.widget.MaterialToast;
public class AppContext extends Application implements UncaughtExceptionHandler {
@@ -62,7 +62,7 @@ public class AppContext extends Application implements UncaughtExceptionHandler
Download.init(this);
Favorite.init(this);
Data.createInstance(this);
SuperToast.setContext(this);
MaterialToast.setContext(this);
// Do catch error prepare
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
@@ -71,8 +71,11 @@ public class GallerysDownloader implements Runnable {
mContext = context;
mGalleryInfo = galleryInfo;
mPageIndex = startIndex;
mDownloadDir = new File(Config.getDownloadPath(),
Utils.rightFileName(mGalleryInfo.gid + '-' + mGalleryInfo.title));
Utils.standardizeFilename(mGalleryInfo.gid + '-' + mGalleryInfo.title));
mDownloadDir.mkdirs();
// TODO What if these is a file with the same name
@@ -81,6 +84,9 @@ public class GallerysDownloader implements Runnable {
mRequstPage = new LinkedList<Integer>();
}
public void start() {
mMainThread.start();
}
+1 -1
View File
@@ -104,7 +104,7 @@ public class ImageLoader {
}
private class ImageDownloader {
private static final int MAX_DOWNLOAD_THREADS = 3;
private static final int MAX_DOWNLOAD_THREADS = 5;
private final Stack<LoadTask> mDownloadTasks;
private int mWorkingThreadNum = 0;
private final Object mLock;
@@ -1143,7 +1143,7 @@ public class EhClient {
}
//Create folder
File folder = new File(Config.getDownloadPath() + File.separatorChar + Utils.rightFileName(curDownloadInfo.title)); // TODO For title contain invailed char
File folder = new File(Config.getDownloadPath() + File.separatorChar + Utils.standardizeFilename(curDownloadInfo.title)); // TODO For title contain invailed char
if (!folder.mkdirs() && !folder.isDirectory()) {
listener.onDownloadMangaOver(curDownloadInfo.gid, false);
curDownloadInfo.status = DownloadInfo.FAILED;
@@ -157,7 +157,7 @@ public class HttpHelper {
return SAD_PANDA_ERROR;
else if (e instanceof GetBodyException)
return "Sad Panda"; // TODO
return "Null"; // TODO
else
return e.getClass().getSimpleName() + ": " +e.getMessage();
@@ -624,6 +624,7 @@ public class HttpHelper {
@Override
public Object onAfterConnect(HttpURLConnection conn)
throws Exception {
// TODO If read out of time, bitmap might be incomplete.
Bitmap bmp = BitmapFactory.decodeStream(conn.getInputStream(), null, Ui.getBitmapOpt());
if (bmp == null)
throw new GetBodyException();
@@ -40,7 +40,7 @@ import com.hippo.ehviewer.util.Utils;
import com.hippo.ehviewer.widget.AlertButton;
import com.hippo.ehviewer.widget.ColorPickerView;
import com.hippo.ehviewer.widget.DialogBuilder;
import com.hippo.ehviewer.widget.SuperToast;
import com.hippo.ehviewer.widget.MaterialToast;
public class ColorPreference extends Preference implements Preference.OnPreferenceClickListener {
@@ -208,8 +208,7 @@ public class ColorPreference extends Preference implements Preference.OnPreferen
@Override
public void onClick(View v) {
((AlertButton)v).dialog.dismiss();
new SuperToast(R.string.restart_to_take_effect).show();
MaterialToast.showToast(R.string.restart_to_take_effect);
int color = getColor() | 0xff000000;
Config.setThemeColor(color);
setColor(color);
@@ -28,7 +28,7 @@ import com.hippo.ehviewer.R;
import com.hippo.ehviewer.util.Config;
import com.hippo.ehviewer.widget.AlertButton;
import com.hippo.ehviewer.widget.DialogBuilder;
import com.hippo.ehviewer.widget.SuperToast;
import com.hippo.ehviewer.widget.MaterialToast;
public class NumberOfColumnsPreference extends Preference
implements Preference.OnPreferenceClickListener {
@@ -114,7 +114,7 @@ public class NumberOfColumnsPreference extends Preference
throw new Exception();
}
} catch (Exception e) {
new SuperToast(R.string.invalid_input, SuperToast.ERROR).show();
MaterialToast.showToast(R.string.invalid_input);
}
}
}).create().show();
@@ -34,9 +34,9 @@ import com.hippo.ehviewer.cache.ImageCache;
import com.hippo.ehviewer.data.GalleryInfo;
import com.hippo.ehviewer.ehclient.EhClient;
import com.hippo.ehviewer.ehclient.ListParser;
import com.hippo.ehviewer.widget.MaterialToast;
import com.hippo.ehviewer.widget.PullViewGroup;
import com.hippo.ehviewer.widget.RefreshTextView;
import com.hippo.ehviewer.widget.SuperToast;
public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
implements PullViewGroup.OnFooterRefreshListener,
@@ -277,7 +277,6 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
mRefreshTextView.setDefaultRefresh("点击重试", new RefreshTextView.OnRefreshListener() { // TODO
@Override
public void onRefresh() {
mRefreshTextView.setRefreshing(true);
retry();
}
});
@@ -487,7 +486,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
default:
mRefreshTextView.setRefreshing(false);
mRefreshTextView.setVisibility(View.GONE);
new SuperToast(eMsg, SuperToast.ERROR).show();
MaterialToast.showToast(eMsg);
}
mPullViewGroup.setAnyRefreshComplete(false);
}
@@ -83,7 +83,7 @@ public class DownloadActivity extends AbstractActivity {
case 1: // Remove info item
mServiceConn.getService().cancel(Download.getKey(longClickItemIndex));
mDlAdapter.notifyDataSetChanged();
File dir = new File(Config.getDownloadPath(), Utils.rightFileName(Download.get(longClickItemIndex).title));
File dir = new File(Config.getDownloadPath(), Utils.standardizeFilename(Download.get(longClickItemIndex).title));
try {
Utils.deleteContents(dir);
} catch (IOException e) {
@@ -67,10 +67,10 @@ import com.hippo.ehviewer.widget.ActionableToastBar;
import com.hippo.ehviewer.widget.ActionableToastBar.ActionClickedListener;
import com.hippo.ehviewer.widget.DialogBuilder;
import com.hippo.ehviewer.widget.LoadImageView;
import com.hippo.ehviewer.widget.MaterialToast;
import com.hippo.ehviewer.widget.ProgressDialogBulider;
import com.hippo.ehviewer.widget.PullViewGroup;
import com.hippo.ehviewer.widget.RatingView;
import com.hippo.ehviewer.widget.SuperToast;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
public class FavouriteActivity extends AbstractGalleryActivity
@@ -276,9 +276,7 @@ public class FavouriteActivity extends AbstractGalleryActivity
// Check login
if (!mClient.isLogin()) {
SuperToast superToast = new SuperToast("未检测到登陆状态,仅可使用本地收藏。由于开发者的问题,本地收藏不可靠,请尽快登陆,将本地收藏转移至账户中的收藏。"); // TODO
superToast.setDuration(SuperToast.LENGTH_LONG);
superToast.show();
MaterialToast.showToast("未检测到登陆状态,仅可使用本地收藏。由于开发者的问题,本地收藏不可靠,请尽快登陆,将本地收藏转移至账户中的收藏。");// TODO
}
// TODO Should show default favourite
@@ -428,7 +426,7 @@ public class FavouriteActivity extends AbstractGalleryActivity
mPdb = null;
mProgressDialog.dismiss();
mProgressDialog = null;
new SuperToast(R.string.move_successfully).show();
MaterialToast.showToast(R.string.move_successfully);
}
}
@@ -439,7 +437,7 @@ public class FavouriteActivity extends AbstractGalleryActivity
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if (mMenuIndex == position) {
new SuperToast(R.string.dst_src_same, SuperToast.WARNING).show();
MaterialToast.showToast(R.string.dst_src_same);
return;
}
@@ -572,7 +570,7 @@ public class FavouriteActivity extends AbstractGalleryActivity
mLastModifyGiList = gis;
mLastModifyPageNum = pageNum;
refresh();
new SuperToast(mSuccStr).show();
MaterialToast.showToast(mSuccStr);
// add to local
if (mToLocal)
+6 -18
View File
@@ -45,7 +45,7 @@ import com.hippo.ehviewer.network.Downloader;
import com.hippo.ehviewer.util.Config;
import com.hippo.ehviewer.util.Log;
import com.hippo.ehviewer.util.Utils;
import com.hippo.ehviewer.widget.SuperToast;
import com.hippo.ehviewer.widget.MaterialToast;
public class GalleryActivity extends AbstractActivity {
private final String TAG = "MangaActivity";
@@ -197,9 +197,8 @@ public class GalleryActivity extends AbstractActivity {
retryTimes++;
int targetPage = (Integer)checkFlag;
if (retryTimes < maxRetry) {
new SuperToast(eMsg + " " +
String.format(getString(R.string.em_retry_times), retryTimes),
SuperToast.WARNING).show(); // TODO
MaterialToast.showToast(eMsg + " " +
String.format(getString(R.string.em_retry_times), retryTimes)); // TODO
if (targetPage == firstPage - 1 &&
getPrePage == true) {
mEhClient.getMangaUrl(allPrePageUrl, targetPage, new MangaUrlGetListener());
@@ -213,10 +212,10 @@ public class GalleryActivity extends AbstractActivity {
if (targetPage == firstPage - 1 &&
getPrePage == true) {
getPrePage = false;
new SuperToast(R.string.retry_max_pre, SuperToast.WARNING).show();
MaterialToast.showToast(R.string.retry_max_pre);
}
else {
new SuperToast(R.string.retry_max_next, SuperToast.WARNING).show();
MaterialToast.showToast(R.string.retry_max_next);
mStop = true;
}
mImageSet.changeState(targetPage, ImageSet.STATE_FAIL);
@@ -275,7 +274,7 @@ public class GalleryActivity extends AbstractActivity {
lastPage = firstPage;
gid = intent.getIntExtra("gid", 0);
title = intent.getStringExtra("title");
mFolder = new File(Config.getDownloadPath(), Utils.rightFileName(title));
mFolder = new File(Config.getDownloadPath(), Utils.standardizeFilename(title));
if (mFolder.isFile())
mFolder.delete();
mFolder.mkdirs();
@@ -283,17 +282,6 @@ public class GalleryActivity extends AbstractActivity {
mImageSet = new ImageSet(this, gid, mFolder, pageSum, firstPage, lastPage, null);
GalleryView isv = new GalleryView(getApplicationContext(), mImageSet, firstPage);
isv.setOnEdgeListener(new GalleryView.OnEdgeListener() {
@Override
public void onLastPageEdge() {
new SuperToast(R.string.last_page).show();
}
@Override
public void onFirstPageEdge() {
new SuperToast(R.string.first_page).show();
}
});
isv.setOnTapTextListener(new GalleryView.OnTapTextListener() {
@Override
public void onTapText(int index) {
@@ -89,12 +89,12 @@ import com.hippo.ehviewer.widget.DialogBuilder;
import com.hippo.ehviewer.widget.LinkifyTextView;
import com.hippo.ehviewer.widget.LoadImageView;
import com.hippo.ehviewer.widget.MaterialProgress;
import com.hippo.ehviewer.widget.MaterialToast;
import com.hippo.ehviewer.widget.ProgressiveRatingBar;
import com.hippo.ehviewer.widget.RefreshTextView;
import com.hippo.ehviewer.widget.ResponedScrollView;
import com.hippo.ehviewer.widget.SimpleGridLayout;
import com.hippo.ehviewer.widget.SuperButton;
import com.hippo.ehviewer.widget.SuperToast;
import com.hippo.ehviewer.windowsanimate.WindowsAnimate;
public class GalleryDetailActivity extends AbstractActivity
@@ -103,7 +103,7 @@ public class GalleryDetailActivity extends AbstractActivity
View.OnTouchListener , ViewSwitcher.ViewFactory,
ProgressiveRatingBar.OnUserRateListener, PreviewList.PreviewHolder,
View.OnLayoutChangeListener, AdapterView.OnItemClickListener,
AdapterView.OnItemLongClickListener {
AdapterView.OnItemLongClickListener, RefreshTextView.OnRefreshListener {
@SuppressWarnings("unused")
private static final String TAG = GalleryDetailActivity.class.getSimpleName();
@@ -431,6 +431,7 @@ public class GalleryDetailActivity extends AbstractActivity
mPreviewFront.setOnClickListener(this);
mPreviewRefresh.setOnClickListener(this);
mReply.setOnClickListener(this);
mRefreshText.setDefaultRefresh("点击重试", this);
doPreLayout();
@@ -450,10 +451,18 @@ public class GalleryDetailActivity extends AbstractActivity
return super.onOptionsItemSelected(item);
}
private void doPreLayout() {
private void getDetailInfo() {
String detailUrl = mClient.getDetailUrl(
mGalleryInfo.gid, mGalleryInfo.token);
if (mGalleryInfo instanceof GalleryDetail)
mClient.getGDetail(detailUrl, (GalleryDetail)mGalleryInfo, new GDetailGetListener());
else if (mGalleryInfo instanceof LofiGalleryDetail)
mClient.getLGDetail(detailUrl, (LofiGalleryDetail)mGalleryInfo, new GLDetailGetListener());
else if (mGalleryInfo instanceof ApiGalleryDetail)
; // TODO
}
private void doPreLayout() {
mRefreshText.setRefreshing(true);
if (mGalleryInfo.title != null) {
@@ -468,12 +477,7 @@ public class GalleryDetailActivity extends AbstractActivity
mUploader.setText(mGalleryInfo.uploader);
}
if (mGalleryInfo instanceof GalleryDetail)
mClient.getGDetail(detailUrl, (GalleryDetail)mGalleryInfo, new GDetailGetListener());
else if (mGalleryInfo instanceof LofiGalleryDetail)
mClient.getLGDetail(detailUrl, (LofiGalleryDetail)mGalleryInfo, new GLDetailGetListener());
else if (mGalleryInfo instanceof ApiGalleryDetail)
; // TODO
getDetailInfo();
}
private String getRatingText(float rating) {
@@ -797,6 +801,11 @@ public class GalleryDetailActivity extends AbstractActivity
}
}
@Override
public void onRefresh() {
getDetailInfo();
}
@Override
@SuppressWarnings("deprecation")
public void onClick(View v) {
@@ -809,7 +818,7 @@ public class GalleryDetailActivity extends AbstractActivity
mServiceConn.getService().add(String.valueOf(mGalleryInfo.gid), mGalleryInfo.thumb,
EhClient.getDetailUrl(mGalleryInfo.gid, mGalleryInfo.token, 0, Config.getMode()),
mGalleryInfo.title);
new SuperToast(R.string.toast_add_download).show();
MaterialToast.showToast(R.string.toast_add_download);
} else if (v == mReadButton) {
//mData.addRead(mGalleryInfo);
if (mGalleryInfo instanceof GalleryDetail) {
@@ -853,7 +862,7 @@ public class GalleryDetailActivity extends AbstractActivity
if (isCheckmark) {
int rating = (int)(mRating.getRating() * 2 + 0.5);
if (rating <= 0 || rating > 10) {
new SuperToast(R.string.invalid_rating, SuperToast.ERROR).show();
MaterialToast.showToast(R.string.invalid_rating);
return;
}
mClient.rate(mGalleryInfo.gid, mGalleryInfo.token, rating, new EhClient.OnRateListener() {
@@ -866,7 +875,7 @@ public class GalleryDetailActivity extends AbstractActivity
@Override
public void onFailure(String eMsg) {
mRatingText.setText("评分失败"); // TODO
new SuperToast(eMsg, SuperToast.WARNING).show();
MaterialToast.showToast(eMsg);
}
});
mRatingText.setText("感谢评分"); // TODO
@@ -930,7 +939,7 @@ public class GalleryDetailActivity extends AbstractActivity
}
@Override
public void onFailure(String eMsg) {
new SuperToast(eMsg, SuperToast.WARNING).show();
MaterialToast.showToast(eMsg);
}
});
}
@@ -1072,7 +1081,7 @@ public class GalleryDetailActivity extends AbstractActivity
case 0:
ClipboardManager cm = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
cm.setPrimaryClip(ClipData.newPlainText(null, c.comment));
new SuperToast(R.string.copyed).show();
MaterialToast.showToast(R.string.copyed);
break;
case 1:
@@ -1129,8 +1138,7 @@ public class GalleryDetailActivity extends AbstractActivity
@Override
public void onFailure(String eMsg) {
// TODO
new SuperToast(eMsg, SuperToast.ERROR).show();
mRefreshText.setEmesg(eMsg, true);
}
}
@@ -1146,8 +1154,7 @@ public class GalleryDetailActivity extends AbstractActivity
@Override
public void onFailure(String eMsg) {
// TODO
new SuperToast(eMsg, SuperToast.ERROR).show();
mRefreshText.setEmesg(eMsg, true);
}
}
@@ -1189,7 +1196,7 @@ public class GalleryDetailActivity extends AbstractActivity
int page = (Integer)checkFlag;
if (page == mCurPreviewPage) {
new SuperToast(eMsg, SuperToast.WARNING).show();
MaterialToast.showToast(eMsg);
mPreviewWait.setVisibility(View.GONE);
mPreviewRefresh.setVisibility(View.VISIBLE);
}
@@ -32,7 +32,6 @@ import com.hippo.ehviewer.gallery.data.DownloadImageSet;
import com.hippo.ehviewer.gallery.ui.GLRootView;
import com.hippo.ehviewer.util.Config;
import com.hippo.ehviewer.util.Utils;
import com.hippo.ehviewer.widget.SuperToast;
public class GalleryDownloadActivity extends AbstractActivity {
private static final String TAG = "MangaDownloadActivity";
@@ -76,20 +75,10 @@ public class GalleryDownloadActivity extends AbstractActivity {
int endIndex = intent.getIntExtra(KEY_END_INDEX, 0);
GLRootView glrv= (GLRootView)findViewById(R.id.gl_root_view);
File folder = new File(Config.getDownloadPath(), Utils.rightFileName(title));
File folder = new File(Config.getDownloadPath(), Utils.standardizeFilename(title));
folder.mkdirs();
mDownloadImageSet = new DownloadImageSet(this, gid, folder, size, 0, endIndex, null);
GalleryView isv = new GalleryView(getApplicationContext(), mDownloadImageSet, 0);
isv.setOnEdgeListener(new GalleryView.OnEdgeListener() {
@Override
public void onLastPageEdge() {
new SuperToast(R.string.last_page).show();
}
@Override
public void onFirstPageEdge() {
new SuperToast(R.string.first_page).show();
}
});
glrv.setContentPane(isv);
// Avoid error when use Movie
@@ -89,10 +89,10 @@ import com.hippo.ehviewer.widget.AlertButton;
import com.hippo.ehviewer.widget.CategoryTable;
import com.hippo.ehviewer.widget.DialogBuilder;
import com.hippo.ehviewer.widget.LoadImageView;
import com.hippo.ehviewer.widget.MaterialToast;
import com.hippo.ehviewer.widget.PrefixEditText;
import com.hippo.ehviewer.widget.RatingView;
import com.hippo.ehviewer.widget.SuperDialogUtil;
import com.hippo.ehviewer.widget.SuperToast;
import com.hippo.ehviewer.widget.TagListView;
import com.hippo.ehviewer.widget.TagsAdapter;
import com.hippo.ehviewer.windowsanimate.WindowsAnimate;
@@ -220,7 +220,7 @@ public class GalleryListActivity extends AbstractGalleryActivity
@Override
public void onFailure(String eMsg) {
setUserPanel();
new SuperToast(eMsg, SuperToast.ERROR).show();
MaterialToast.showToast(eMsg);
if (!GalleryListActivity.this.isFinishing())
loginDialog.show();
}
@@ -234,11 +234,11 @@ public class GalleryListActivity extends AbstractGalleryActivity
setUserPanel();
break;
case EhClient.NO_AVATAR:
new SuperToast("无头像").show(); // TODO
MaterialToast.showToast("无头像"); // TODO
break;
case EhClient.GET_AVATAR_ERROR:
default:
new SuperToast("获取头像失败", SuperToast.ERROR).show(); // TODO
MaterialToast.showToast("获取头像失败"); // TODO
break;
}
}
@@ -503,10 +503,10 @@ public class GalleryListActivity extends AbstractGalleryActivity
String filePath = (String)mSearchImageText.getText();
File file = new File(filePath);
if (!file.exists()) {
new SuperToast("图片不存在", SuperToast.ERROR).show();
MaterialToast.showToast("图片不存在");
} else {
if (!file.canRead()) {
new SuperToast("图片不可读", SuperToast.ERROR).show();
MaterialToast.showToast("图片不可读");
} else {
CheckBox similar = (CheckBox)view.findViewById(R.id.checkboxSimilar);
@@ -543,7 +543,7 @@ public class GalleryListActivity extends AbstractGalleryActivity
startService(it);
mServiceConn.getService().add(String.valueOf(gi.gid), gi.thumb,
mClient.getDetailUrl(gi.gid, gi.token), gi.title);
new SuperToast(R.string.toast_add_download).show();
MaterialToast.showToast(R.string.toast_add_download);
break;
default:
break;
@@ -581,7 +581,7 @@ public class GalleryListActivity extends AbstractGalleryActivity
if (targetPage < 0 || targetPage >= getPageNum())
throw new Exception();
} catch(Exception e) {
new SuperToast(R.string.toast_invalid_page, SuperToast.ERROR).show();
MaterialToast.showToast(R.string.toast_invalid_page);
return;
}
@@ -622,9 +622,9 @@ public class GalleryListActivity extends AbstractGalleryActivity
public void onClick(View v) {
String key = et.getText().toString();
if (key.length() == 0)
new SuperToast(R.string.tag_name_empty, SuperToast.WARNING).show();
MaterialToast.showToast(R.string.tag_name_empty);
else if (listMenuTag.contains(key) && !key.equals(oldStr))
new SuperToast(R.string.tag_name_empty, SuperToast.WARNING).show();
MaterialToast.showToast(R.string.tag_name_empty);
else {
((AlertButton)v).dialog.dismiss();
if (listener != null) {
@@ -1346,7 +1346,7 @@ public class GalleryListActivity extends AbstractGalleryActivity
public void onBackPressed() {
if (System.currentTimeMillis() - curBackTime > BACK_PRESSED_INTERVAL) {
curBackTime = System.currentTimeMillis();
new SuperToast(R.string.exit_tip).show();
MaterialToast.showToast(R.string.exit_tip);
} else
finish();
}
@@ -1576,8 +1576,8 @@ public class GalleryListActivity extends AbstractGalleryActivity
listener.onSuccess(mAdapter, taskStamp, gis, gis.size() == 0 ? 0 : 1);
// Show update time
if (timeStamp != -1 && Config.getShowPopularUpdateTime())
new SuperToast(String.format(getString(R.string.popular_update_time),
AppContext.sFormatter.format(timeStamp))).show();
MaterialToast.showToast(String.format(getString(R.string.popular_update_time),
AppContext.sFormatter.format(timeStamp)));
}
@Override
public void onFailure(String eMsg) {
@@ -66,8 +66,8 @@ import com.hippo.ehviewer.widget.AlertButton;
import com.hippo.ehviewer.widget.CategoryTable;
import com.hippo.ehviewer.widget.DialogBuilder;
import com.hippo.ehviewer.widget.FileExplorerView;
import com.hippo.ehviewer.widget.MaterialToast;
import com.hippo.ehviewer.widget.SuperDialogUtil;
import com.hippo.ehviewer.widget.SuperToast;
public class SettingsActivity extends AbstractPreferenceActivity {
@SuppressWarnings("unused")
@@ -236,7 +236,7 @@ public class SettingsActivity extends AbstractPreferenceActivity {
Config.screenOriPre2Value(Integer.parseInt((String) newValue)));
} else if (KEY_RANDOM_THEME_COLOR.equals(key)) {
new SuperToast(R.string.restart_to_take_effect).show();
MaterialToast.showToast(R.string.restart_to_take_effect);
mThemeColor.setEnabled(!(Boolean)newValue);
}
@@ -594,7 +594,7 @@ public class SettingsActivity extends AbstractPreferenceActivity {
@Override
public void onClick(View v) {
if (!fileExplorerView.canWrite())
new SuperToast(R.string.cur_dir_not_writable, SuperToast.WARNING).show();
MaterialToast.showToast(R.string.cur_dir_not_writable);
else {
String downloadPath = fileExplorerView.getCurPath();
+7 -7
View File
@@ -31,7 +31,7 @@ import com.hippo.ehviewer.data.Data;
import com.hippo.ehviewer.data.GalleryInfo;
import com.hippo.ehviewer.ehclient.EhClient;
import com.hippo.ehviewer.widget.DialogBuilder;
import com.hippo.ehviewer.widget.SuperToast;
import com.hippo.ehviewer.widget.MaterialToast;
public class Favorite {
@@ -61,18 +61,18 @@ public class Favorite {
break;
case -1:
Data.getInstance().addLocalFavourite(gi);
new SuperToast(R.string.toast_add_favourite).show();
MaterialToast.showToast(R.string.toast_add_favourite);
break;
default:
EhClient.getInstance().addToFavorite(gi.gid,
gi.token, defaultFavorite, null, new EhClient.OnAddToFavoriteListener() {
@Override
public void onSuccess() {
new SuperToast(R.string.toast_add_favourite).show();
MaterialToast.showToast(R.string.toast_add_favourite);
}
@Override
public void onFailure(String eMsg) {
new SuperToast(R.string.failed_to_add).show();
MaterialToast.showToast(R.string.failed_to_add);
}
});
}
@@ -100,18 +100,18 @@ public class Favorite {
switch (position) {
case 0:
Data.getInstance().addLocalFavourite(gi);
new SuperToast(R.string.toast_add_favourite).show();
MaterialToast.showToast(R.string.toast_add_favourite);
break;
default:
EhClient.getInstance().addToFavorite(gi.gid,
gi.token, position - 1, null, new EhClient.OnAddToFavoriteListener() {
@Override
public void onSuccess() {
new SuperToast(R.string.toast_add_favourite).show();
MaterialToast.showToast(R.string.toast_add_favourite);
}
@Override
public void onFailure(String eMsg) {
new SuperToast(R.string.failed_to_add).show();
MaterialToast.showToast(R.string.failed_to_add);
}
});
}
+1 -2
View File
@@ -35,8 +35,7 @@ public final class Theme {
private static final int[] DARK_COLOR_TABLE = {
0xffe51c23, 0xffe91e63, 0xff9c27b0,
0xff673ab7, 0xff3f51b5, 0xff5677fc,
0xff03a9f4, 0xff009688, 0xff259b24,
0xff8bc34a, 0xff795548, 0xff607d8b
0xff03a9f4, 0xff009688, 0xff259b24
};
/**
+246 -12
View File
@@ -34,7 +34,7 @@ import android.os.AsyncTask;
import android.os.Build;
import android.view.View;
public class Utils {
public final class Utils {
@SuppressWarnings("unused")
private static String TAG = "Util";
@@ -269,17 +269,31 @@ public class Utils {
}
}
private static final String[] ESCAPE_CHARATER_LIST = {
"&amp;",
"&lt;",
"&gt;",
"&quot;",
"&#039;",
"&times;"
};
private static final String[] UNESCAPE_CHARATER_LIST = {
"&",
"<",
">",
"\"",
"'",
"×"
};
/**
* Mostly title and url need it
* @param str
* @return
*/
public static final String htmlUnsescape(String str) {
return str.replace("&amp;", "&")
.replace("&lt;", "<")
.replace("&gt;", ">")
.replace("&quot;", "\"")
.replace("&#039;", "'");
public static String htmlUnsescape(String str) {
return replaceEach(str, ESCAPE_CHARATER_LIST, UNESCAPE_CHARATER_LIST);
}
/**
@@ -287,9 +301,10 @@ public class Utils {
* @param name
* @return
*/
public static final String rightFileName(String name) {
name = name.replaceAll("[\\\\|/|:|*|?|\"|<|>|\\|]", "");
return name.length() > 255 ? name.substring(0, 255) : name;
public static String standardizeFilename(String name) {
name = name.replaceAll("[\\\\/:*?\"<>\\|]", "");
name = name.length() > 255 ? name.substring(0, 255) : name;
return name.replaceAll("^[\\s]+", "").replace("[\\s]+$", "");
}
/**
@@ -300,7 +315,7 @@ public class Utils {
* @param separator
* @return
*/
public static final String join(final Object[] array,
public static String join(final Object[] array,
final Object separator) {
final StringBuilder sb = new StringBuilder(array.length * 16);
for (int i = 0; i < array.length; i++) {
@@ -311,7 +326,226 @@ public class Utils {
return sb.toString();
}
public static final boolean int2boolean(int integer) {
/**
* <p>
* Replaces all occurrences of Strings within another String.
* </p>
*
* <p>
* A {@code null} reference passed to this method is a no-op, or if
* any "search string" or "string to replace" is null, that replace will be
* ignored. This will not repeat. For repeating replaces, call the
* overloaded method.
* </p>
*
* <pre>
* StringUtils.replaceEach(null, *, *) = null
* StringUtils.replaceEach("", *, *) = ""
* StringUtils.replaceEach("aba", null, null) = "aba"
* StringUtils.replaceEach("aba", new String[0], null) = "aba"
* StringUtils.replaceEach("aba", null, new String[0]) = "aba"
* StringUtils.replaceEach("aba", new String[]{"a"}, null) = "aba"
* StringUtils.replaceEach("aba", new String[]{"a"}, new String[]{""}) = "b"
* StringUtils.replaceEach("aba", new String[]{null}, new String[]{"a"}) = "aba"
* StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"w", "t"}) = "wcte"
* (example of how it does not repeat)
* StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}) = "dcte"
* </pre>
*
* @param text
* text to search and replace in, no-op if null
* @param searchList
* the Strings to search for, no-op if null
* @param replacementList
* the Strings to replace them with, no-op if null
* @return the text with any replacements processed, {@code null} if
* null String input
* @throws IllegalArgumentException
* if the lengths of the arrays are not the same (null is ok,
* and/or size 0)
*/
// Get from org.apache.commons.lang3.StringUtils
public static String replaceEach(final String text, final String[] searchList, final String[] replacementList) {
return replaceEach(text, searchList, replacementList, false, 0);
}
/**
* <p>
* Replaces all occurrences of Strings within another String.
* </p>
*
* <p>
* A {@code null} reference passed to this method is a no-op, or if
* any "search string" or "string to replace" is null, that replace will be
* ignored.
* </p>
*
* <pre>
* StringUtils.replaceEach(null, *, *, *) = null
* StringUtils.replaceEach("", *, *, *) = ""
* StringUtils.replaceEach("aba", null, null, *) = "aba"
* StringUtils.replaceEach("aba", new String[0], null, *) = "aba"
* StringUtils.replaceEach("aba", null, new String[0], *) = "aba"
* StringUtils.replaceEach("aba", new String[]{"a"}, null, *) = "aba"
* StringUtils.replaceEach("aba", new String[]{"a"}, new String[]{""}, *) = "b"
* StringUtils.replaceEach("aba", new String[]{null}, new String[]{"a"}, *) = "aba"
* StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"w", "t"}, *) = "wcte"
* (example of how it repeats)
* StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}, false) = "dcte"
* StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}, true) = "tcte"
* StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "ab"}, *) = IllegalStateException
* </pre>
*
* @param text
* text to search and replace in, no-op if null
* @param searchList
* the Strings to search for, no-op if null
* @param replacementList
* the Strings to replace them with, no-op if null
* @param repeat if true, then replace repeatedly
* until there are no more possible replacements or timeToLive < 0
* @param timeToLive
* if less than 0 then there is a circular reference and endless
* loop
* @return the text with any replacements processed, {@code null} if
* null String input
* @throws IllegalStateException
* if the search is repeating and there is an endless loop due
* to outputs of one being inputs to another
* @throws IllegalArgumentException
* if the lengths of the arrays are not the same (null is ok,
* and/or size 0)
*/
// Get from org.apache.commons.lang3.StringUtils
private static String replaceEach(
final String text, final String[] searchList, final String[] replacementList, final boolean repeat, final int timeToLive) {
// mchyzer Performance note: This creates very few new objects (one major goal)
// let me know if there are performance requests, we can create a harness to measure
if (text == null || text.isEmpty() || searchList == null ||
searchList.length == 0 || replacementList == null || replacementList.length == 0) {
return text;
}
// if recursing, this shouldn't be less than 0
if (timeToLive < 0) {
throw new IllegalStateException("Aborting to protect against StackOverflowError - " +
"output of one loop is the input of another");
}
final int searchLength = searchList.length;
final int replacementLength = replacementList.length;
// make sure lengths are ok, these need to be equal
if (searchLength != replacementLength) {
throw new IllegalArgumentException("Search and Replace array lengths don't match: "
+ searchLength
+ " vs "
+ replacementLength);
}
// keep track of which still have matches
final boolean[] noMoreMatchesForReplIndex = new boolean[searchLength];
// index on index that the match was found
int textIndex = -1;
int replaceIndex = -1;
int tempIndex = -1;
// index of replace array that will replace the search string found
// NOTE: logic duplicated below START
for (int i = 0; i < searchLength; i++) {
if (noMoreMatchesForReplIndex[i] || searchList[i] == null ||
searchList[i].isEmpty() || replacementList[i] == null) {
continue;
}
tempIndex = text.indexOf(searchList[i]);
// see if we need to keep searching for this
if (tempIndex == -1) {
noMoreMatchesForReplIndex[i] = true;
} else {
if (textIndex == -1 || tempIndex < textIndex) {
textIndex = tempIndex;
replaceIndex = i;
}
}
}
// NOTE: logic mostly below END
// no search strings found, we are done
if (textIndex == -1) {
return text;
}
int start = 0;
// get a good guess on the size of the result buffer so it doesn't have to double if it goes over a bit
int increase = 0;
// count the replacement text elements that are larger than their corresponding text being replaced
for (int i = 0; i < searchList.length; i++) {
if (searchList[i] == null || replacementList[i] == null) {
continue;
}
final int greater = replacementList[i].length() - searchList[i].length();
if (greater > 0) {
increase += 3 * greater; // assume 3 matches
}
}
// have upper-bound at 20% increase, then let Java take over
increase = Math.min(increase, text.length() / 5);
final StringBuilder buf = new StringBuilder(text.length() + increase);
while (textIndex != -1) {
for (int i = start; i < textIndex; i++) {
buf.append(text.charAt(i));
}
buf.append(replacementList[replaceIndex]);
start = textIndex + searchList[replaceIndex].length();
textIndex = -1;
replaceIndex = -1;
tempIndex = -1;
// find the next earliest match
// NOTE: logic mostly duplicated above START
for (int i = 0; i < searchLength; i++) {
if (noMoreMatchesForReplIndex[i] || searchList[i] == null ||
searchList[i].isEmpty() || replacementList[i] == null) {
continue;
}
tempIndex = text.indexOf(searchList[i], start);
// see if we need to keep searching for this
if (tempIndex == -1) {
noMoreMatchesForReplIndex[i] = true;
} else {
if (textIndex == -1 || tempIndex < textIndex) {
textIndex = tempIndex;
replaceIndex = i;
}
}
}
// NOTE: logic duplicated above END
}
final int textLength = text.length();
for (int i = start; i < textLength; i++) {
buf.append(text.charAt(i));
}
final String result = buf.toString();
if (!repeat) {
return result;
}
return replaceEach(result, searchList, replacementList, repeat, timeToLive - 1);
}
public static boolean int2boolean(int integer) {
return integer == 0 ? false : true;
}
}
@@ -0,0 +1,64 @@
/*
* 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 android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.hippo.ehviewer.R;
public class MaterialToast extends Toast {
private static Context sContext;
public static void setContext(Context context) {
sContext = context;
}
@SuppressLint("InflateParams")
public MaterialToast(String mesg) {
super(sContext);
init(mesg);
}
@SuppressLint("InflateParams")
public MaterialToast(int resId) {
this(sContext.getString(resId));
}
@SuppressLint("InflateParams")
private void init(String mesg) {
View v = LayoutInflater.from(sContext)
.inflate(R.layout.material_toast, null);
TextView tv = (TextView)v.findViewById(R.id.message);
tv.setText(mesg);
setView(v);
setDuration(LENGTH_SHORT);
}
public static final void showToast(String mesg) {
new MaterialToast(mesg).show();
}
public static final void showToast(int resId) {
new MaterialToast(resId).show();
}
}
@@ -69,8 +69,13 @@ public class RefreshTextView extends TextView
@Override
public void onClick(View v) {
if (!mIsRefreshing && mListener != null)
if (mIsRefreshing)
return;
if (mListener != null)
mListener.onRefresh();
setRefreshing(true);
}
public void setRefreshing(boolean refreshing) {
@@ -1,126 +0,0 @@
/*
* 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 android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
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 LinearLayout mMainView;
private ImageView mIcon;
private TextView mMessage;
private static Context sContext;
public static void setContext(Context context) {
sContext = context;
}
public SuperToast() {
super(sContext);
init();
}
public SuperToast(int strResId) {
this();
setMessage(strResId);
}
public SuperToast(String mesg) {
this();
setMessage(mesg);
}
public SuperToast(int strResId, int type) {
this(strResId);
setTypeIcon(type);
}
public SuperToast(String mesg, int type) {
this(mesg);
setTypeIcon(type);
}
@SuppressLint("InflateParams")
private void init() {
FrameLayout view = (FrameLayout)LayoutInflater.from(sContext)
.inflate(R.layout.super_toast, null);
mMainView = (LinearLayout)view.getChildAt(0);
// Set random color
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);
}
public SuperToast setTypeIcon(int type) {
switch(type) {
case WARNING:
setIcon(R.drawable.ic_warning);
break;
case ERROR:
setIcon(R.drawable.ic_error);
break;
case NONE:
default:
// nop
break;
}
return this;
}
public SuperToast setIcon(int resId) {
return setIcon(sContext.getResources().getDrawable(resId));
}
public SuperToast setIcon(Drawable drawable) {
mIcon.setVisibility(View.VISIBLE);
mIcon.setImageDrawable(drawable);
return this;
}
public SuperToast setMessage(int resId) {
return setMessage(sContext.getResources().getString(resId));
}
public SuperToast setMessage(CharSequence text) {
mMessage.setText(text);
return this;
}
}