From 103cfe17499dc4519359ccbf2fccf7e907e5a8e2 Mon Sep 17 00:00:00 2001 From: seven332 Date: Wed, 10 Sep 2014 00:29:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E6=90=9C=E7=B4=A2=E6=A0=8F=E5=A4=B1?= =?UTF-8?q?=E5=8E=BB=E7=84=A6=E7=82=B9=E6=97=B6=E9=9A=90=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ehviewer/service/DownloadService.java | 15 +-- .../ehviewer/ui/GalleryListActivity.java | 113 ++++++++++-------- 2 files changed, 68 insertions(+), 60 deletions(-) diff --git a/src/com/hippo/ehviewer/service/DownloadService.java b/src/com/hippo/ehviewer/service/DownloadService.java index afdff84fd..6847100e4 100644 --- a/src/com/hippo/ehviewer/service/DownloadService.java +++ b/src/com/hippo/ehviewer/service/DownloadService.java @@ -16,7 +16,6 @@ package com.hippo.ehviewer.service; -import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; @@ -240,7 +239,6 @@ public class DownloadService extends Service } @Override - @SuppressWarnings("deprecation") public void onStart(int gid) { if (mCurDownloadInfo == null) return; @@ -253,14 +251,13 @@ public class DownloadService extends Service mBuilder.setContentTitle(getString(R.string.start_download) + " " + gid) .setContentText(null) .setProgress(0, 0, true); - mNotifyManager.notify(DOWNLOAD_NOTIFY_ID, mBuilder.getNotification()); + mNotifyManager.notify(DOWNLOAD_NOTIFY_ID, mBuilder.build()); mNotifyManager.cancel(gid); notifyUpdate(); } @Override - @SuppressWarnings("deprecation") public void onDownload(int gid, int downloadSize, int totalSize) { if (mCurDownloadInfo == null) return; @@ -273,13 +270,12 @@ public class DownloadService extends Service mBuilder.setContentTitle(getString(R.string.downloading) + " " + gid) .setContentText(mSpeedStr) .setProgress(totalSize, downloadSize, false); - mNotifyManager.notify(DOWNLOAD_NOTIFY_ID, mBuilder.getNotification()); + mNotifyManager.notify(DOWNLOAD_NOTIFY_ID, mBuilder.build()); notifyUpdate(); } @Override - @SuppressWarnings("deprecation") public void onUpdateSpeed(int gid, int speed) { if (mCurDownloadInfo == null) return; @@ -293,19 +289,18 @@ public class DownloadService extends Service .setContentText(mSpeedStr) .setProgress(mCurDownloadInfo.total, mCurDownloadInfo.download, mCurDownloadInfo.total == -1 ? true :false); - mNotifyManager.notify(DOWNLOAD_NOTIFY_ID, mBuilder.getNotification()); + mNotifyManager.notify(DOWNLOAD_NOTIFY_ID, mBuilder.build()); notifyUpdate(); } @Override - @SuppressWarnings("deprecation") public void onDownloadOver(int gid, int legacy) { if (mCurDownloadInfo == null) return; mCurDownloadInfo.legacy = legacy; - Notification.Builder builder = new Notification.Builder(mContext); + NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); builder.setSmallIcon(R.drawable.ic_launcher); Intent intent = new Intent(DownloadService.this,DownloadActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(DownloadService.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); @@ -314,7 +309,7 @@ public class DownloadService extends Service .setContentText(legacy == 0 ? getString(R.string.done) : String.format(getString(R.string.legacy_pages), legacy)) .setOngoing(false).setAutoCancel(true); - mNotifyManager.notify(gid, builder.getNotification()); + mNotifyManager.notify(gid, builder.build()); mNotifyManager.cancel(DOWNLOAD_NOTIFY_ID); mCurDownloadInfo.legacy = legacy; diff --git a/src/com/hippo/ehviewer/ui/GalleryListActivity.java b/src/com/hippo/ehviewer/ui/GalleryListActivity.java index 81f377cd5..36b7f6bdb 100644 --- a/src/com/hippo/ehviewer/ui/GalleryListActivity.java +++ b/src/com/hippo/ehviewer/ui/GalleryListActivity.java @@ -126,7 +126,9 @@ import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu; * @author Hippo */ public class GalleryListActivity extends AbsGalleryActivity - implements View.OnClickListener { + implements View.OnClickListener, SearchView.OnQueryTextListener, + SearchView.OnFocusChangeListener, SlidingMenu.OnOpenedListener, + SlidingMenu.OnClosedListener { @SuppressWarnings("unused") private static final String TAG = GalleryListActivity.class.getSimpleName(); @@ -152,10 +154,12 @@ public class GalleryListActivity extends AbsGalleryActivity private SlidingMenu mSlidingMenu; private View mMenuLeft; private LinearLayout mUserPanel; - private SearchView mSearchView; private ListView itemListMenu; private TagListView tagListMenu; + private SearchView mSearchView; + private MenuItem mSearchItem; + private ImageView avatar; private TextView userView; private Button loginButton; @@ -912,6 +916,22 @@ public class GalleryListActivity extends AbsGalleryActivity return R.layout.gallery_list; } + @Override + public void onOpened() { + if (mShowDrawer) { + setTitle(R.string.app_name); + invalidateOptionsMenu(); + } + } + + @Override + public void onClosed() { + if (mShowDrawer) { + setTitle(mTitle); + invalidateOptionsMenu(); + } + } + @Override @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public void onCreate(Bundle savedInstanceState) { @@ -939,24 +959,8 @@ public class GalleryListActivity extends AbsGalleryActivity mSlidingMenu.setShadowWidthRes(R.dimen.shadow_width); mSlidingMenu.setShadowDrawable(R.drawable.shadow); mSlidingMenu.setSecondaryShadowDrawable(R.drawable.shadow_right); - mSlidingMenu.setOnOpenedListener(new SlidingMenu.OnOpenedListener() { - @Override - public void onOpened() { - if (mShowDrawer) { - setTitle(R.string.app_name); - invalidateOptionsMenu(); - } - } - }); - mSlidingMenu.setOnClosedListener(new SlidingMenu.OnClosedListener() { - @Override - public void onClosed() { - if (mShowDrawer) { - setTitle(mTitle); - invalidateOptionsMenu(); - } - } - }); + mSlidingMenu.setOnOpenedListener(this); + mSlidingMenu.setOnClosedListener(this); if (mShowDrawer) mSlidingMenu.setBehindWidth( mResources.getDimensionPixelOffset(R.dimen.menu_width)); @@ -1252,6 +1256,41 @@ public class GalleryListActivity extends AbsGalleryActivity mStaggeredGridView.getPaddingRight(), paddingBottom); } + @Override + public boolean onQueryTextSubmit(String query) { + // Store suggestion + SearchRecentSuggestions suggestions = new SearchRecentSuggestions( + GalleryListActivity.this, SimpleSuggestionProvider.AUTHORITY, + SimpleSuggestionProvider.MODE); + suggestions.saveRecentQuery(query, null); + // collapse search view + if (mSearchItem != null) + mSearchItem.collapseActionView(); + + String t = null; + if (query == null || query.isEmpty()) + t = getString(android.R.string.search_go); + else + t = query; + + lus = new ListUrls(ListUrls.NONE, query); + refresh(); + mTitle = t; + setTitle(mTitle); + return true; + } + + @Override + public boolean onQueryTextChange(String newText) { + return false; + } + + @Override + public void onFocusChange(View v, boolean hasFocus) { + if (!hasFocus && mSearchItem != null) + mSearchItem.collapseActionView(); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { // Do not show menu when mSlidingMenu is shown @@ -1262,38 +1301,12 @@ public class GalleryListActivity extends AbsGalleryActivity SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); - final MenuItem searchItem = menu.findItem(R.id.action_search); - mSearchView = (SearchView) searchItem.getActionView(); + mSearchItem = menu.findItem(R.id.action_search); + mSearchView = (SearchView) mSearchItem.getActionView(); mSearchView.setSearchableInfo( searchManager.getSearchableInfo(getComponentName())); - mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextChange(String newText) { - return false; - } - @Override - public boolean onQueryTextSubmit(String query) { - // Store suggestion - SearchRecentSuggestions suggestions = new SearchRecentSuggestions( - GalleryListActivity.this, SimpleSuggestionProvider.AUTHORITY, - SimpleSuggestionProvider.MODE); - suggestions.saveRecentQuery(query, null); - - searchItem.collapseActionView(); - - String t = null; - if (query == null || query.isEmpty()) - t = getString(android.R.string.search_go); - else - t = query; - - lus = new ListUrls(ListUrls.NONE, query); - refresh(); - mTitle = t; - setTitle(mTitle); - return true; - } - }); + mSearchView.setOnQueryTextListener(this); + mSearchView.setOnQueryTextFocusChangeListener(this); // Make search view custom look int searchTextID = mResources.getIdentifier("android:id/search_src_text", null, null);