Skip to content
This repository has been archived by the owner on Aug 26, 2019. It is now read-only.

Commit

Permalink
详情界面的 Activity 跳转不关闭自身
Browse files Browse the repository at this point in the history
  • Loading branch information
seven332 committed Aug 22, 2014
1 parent e96d911 commit e3b5ed8
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 38 deletions.
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
android:name=".ui.GalleryListActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTask"
android:launchMode="singleTop"
android:screenOrientation="behind"
android:theme="@style/AppTheme.Main.ListActivity" >
<intent-filter>
Expand Down
2 changes: 1 addition & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
<!-- Gallery -->
<string name="gallery_tip">Long press the screen to download from the current page. If the item is being downloaded, just load current page first.</string>
<string name="read_image_error">Read image error</string>
<string name="not_loaded">Not loader</string>
<string name="not_loaded">Not loaded</string>
<string name="loading_percent">Loading %d%%</string>
<string name="wait_for_more">Waiting to get page information</string>

Expand Down
2 changes: 1 addition & 1 deletion res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</style>

<style name="AppTheme.Main">
<item name="@android:homeAsUpIndicator">@drawable/ic_navigation_drawer</item>
<!-- nop -->
</style>

<style name="AppTheme.Main.ListActivity">
Expand Down
3 changes: 2 additions & 1 deletion src/com/hippo/ehviewer/gallery/GalleryView.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ public synchronized void onDownloading(int index, float percent) {
showItems[targetIndex].recycle();

showItems[targetIndex] = new Text(
String.format("正在加载 %d%%", Math.round(percent * 100)));
String.format(mContext.getString(R.string.loading_percent),
Math.round(percent * 100)));
resetSizePosition(targetIndex);
}
}
Expand Down
19 changes: 18 additions & 1 deletion src/com/hippo/ehviewer/ui/DownloadActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.List;

import android.app.ActionBar;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
Expand All @@ -27,6 +28,7 @@
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
Expand Down Expand Up @@ -98,6 +100,9 @@ protected void onCreate(Bundle savedInstanceState) {
filter.addAction(DownloadService.ACTION_UPDATE);
registerReceiver(mReceiver, filter);

ActionBar actionBar = getActionBar();
getActionBar().setDisplayHomeAsUpEnabled(true);

mDownloads = Data.getInstance().getAllDownloads();
for (DownloadInfo di : mDownloads)
di.selected = false;
Expand All @@ -113,7 +118,7 @@ protected void onCreate(Bundle savedInstanceState) {
mThemeColor = Config.getRandomThemeColor() ? Theme.getRandomDarkColor() : Config.getThemeColor();
int actionBarColor = mThemeColor & 0x00ffffff | 0xdd000000;
Drawable drawable = new ColorDrawable(actionBarColor);
getActionBar().setBackgroundDrawable(drawable);
actionBar.setBackgroundDrawable(drawable);
Ui.translucent(this, actionBarColor);
}

Expand All @@ -125,6 +130,18 @@ protected void onDestroy() {
mWindowsAnimate.free();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Expand Down
6 changes: 1 addition & 5 deletions src/com/hippo/ehviewer/ui/GalleryDetailActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -555,13 +555,13 @@ private void addTag(LinkedHashMap<String, LinkedList<String>> tags) {
tagView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
Intent intent = new Intent(GalleryDetailActivity.this,
GalleryListActivity.class);
intent.setAction(GalleryListActivity.ACTION_GALLERY_LIST);
intent.putExtra(GalleryListActivity.KEY_MODE,
ListUrls.MODE_TAG);
intent.putExtra(GalleryListActivity.KEY_TAG, groupName + ":" + tag);
intent.setAction(GalleryListActivity.ACTION_GALLERY_LIST);
startActivity(intent);
}
});
Expand Down Expand Up @@ -830,21 +830,18 @@ public void onClick(View v) {
intent.putExtra(GalleryActivity.KEY_START_INDEX, 0);
startActivity(intent);
} else if (v == mCategory) {
finish();
Intent intent = new Intent(this, GalleryListActivity.class);
intent.setAction(GalleryListActivity.ACTION_GALLERY_LIST);
intent.putExtra(GalleryListActivity.KEY_MODE, ListUrls.MODE_NORMAL);
intent.putExtra(GalleryListActivity.KEY_CATEGORY, mGalleryInfo.category);
startActivity(intent);
} else if (v == mMoreOfUploader) {
finish();
Intent intent = new Intent(this, GalleryListActivity.class);
intent.setAction(GalleryListActivity.ACTION_GALLERY_LIST);
intent.putExtra(GalleryListActivity.KEY_MODE, ListUrls.MODE_UPLOADER);
intent.putExtra(GalleryListActivity.KEY_UPLOADER, mGalleryInfo.uploader);
startActivity(intent);
} else if (v == mSimilar) {
finish();
Intent intent = new Intent(this, GalleryListActivity.class);
intent.setAction(GalleryListActivity.ACTION_GALLERY_LIST);
intent.putExtra(GalleryListActivity.KEY_MODE, ListUrls.MODE_IMAGE_SEARCH);
Expand Down Expand Up @@ -1081,7 +1078,6 @@ public void onItemClick(AdapterView<?> parent, View view,
break;

case 1:
finish();
Intent intent = new Intent(GalleryDetailActivity.this, GalleryListActivity.class);
intent.setAction(GalleryListActivity.ACTION_GALLERY_LIST);
intent.putExtra(GalleryListActivity.KEY_MODE, ListUrls.MODE_UPLOADER);
Expand Down
87 changes: 59 additions & 28 deletions src/com/hippo/ehviewer/ui/GalleryListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Locale;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.SearchManager;
Expand All @@ -36,6 +37,7 @@
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.provider.MediaStore;
Expand Down Expand Up @@ -172,6 +174,7 @@ public class GalleryListActivity extends AbsGalleryActivity
private Data mData;

private int longClickItemIndex;
private boolean mShowDrawer;

private AlertDialog loginDialog;
private AlertDialog mSearchDialog;
Expand Down Expand Up @@ -820,8 +823,11 @@ protected void onResume() {
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mSlidingMenu.setBehindWidth(
mResources.getDimensionPixelOffset(R.dimen.menu_width));
if (mShowDrawer)
mSlidingMenu.setBehindWidth(
mResources.getDimensionPixelOffset(R.dimen.menu_width));
else
mSlidingMenu.setBehindWidth(0);
}

/**
Expand All @@ -843,7 +849,6 @@ private void handleIntent(Intent intent) {
lus.setTag(tag);
mTitle = tag;
setTitle(mTitle);
refresh();
break;

case ListUrls.MODE_UPLOADER:
Expand All @@ -852,7 +857,6 @@ private void handleIntent(Intent intent) {
lus.setMode(ListUrls.MODE_UPLOADER);
mTitle = uploader;
setTitle(mTitle);
refresh();
break;

case ListUrls.MODE_IMAGE_SEARCH:
Expand All @@ -862,7 +866,6 @@ private void handleIntent(Intent intent) {
EhClient.IMAGE_SEARCH_USE_SIMILARITY_SCAN);
mTitle = getString(R.string.similar_content); // TODO
setTitle(mTitle);
refresh();
break;

case ListUrls.MODE_NORMAL:
Expand All @@ -871,7 +874,6 @@ private void handleIntent(Intent intent) {
lus = new ListUrls(category);
mTitle = Ui.getCategoryText(category);
setTitle(mTitle);
refresh();
break;

default:
Expand All @@ -889,6 +891,7 @@ private void handleIntent(Intent intent) {
protected void onNewIntent(Intent intent) {
setIntent(intent);
handleIntent(intent);
refresh();
}

@Override
Expand All @@ -909,6 +912,7 @@ protected int getLayoutRes() {
}

@Override
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Expand All @@ -919,32 +923,44 @@ public void onCreate(Bundle savedInstanceState) {
mWindowsAnimate.init(this);

handleIntent(getIntent());
// Check show drawer or not
if (ACTION_GALLERY_LIST.equals(getIntent().getAction()))
mShowDrawer = false;
else
mShowDrawer = true;

setBehindContentView(R.layout.list_menu_left);
setSlidingActionBarEnabled(false);
mSlidingMenu = getSlidingMenu();
mSlidingMenu.setSecondaryMenu(R.layout.list_menu_right);
mSlidingMenu.setMode(SlidingMenu.LEFT_RIGHT);
mSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
mSlidingMenu.setBehindWidth(
mResources.getDimensionPixelOffset(R.dimen.menu_width));
mSlidingMenu.setShadowDrawable(R.drawable.shadow);
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() {
setTitle(R.string.app_name);
invalidateOptionsMenu();
if (mShowDrawer) {
setTitle(R.string.app_name);
invalidateOptionsMenu();
}
}
});
mSlidingMenu.setOnClosedListener(new SlidingMenu.OnClosedListener() {
@Override
public void onClosed() {
setTitle(mTitle);
invalidateOptionsMenu();
if (mShowDrawer) {
setTitle(mTitle);
invalidateOptionsMenu();
}
}
});
if (mShowDrawer)
mSlidingMenu.setBehindWidth(
mResources.getDimensionPixelOffset(R.dimen.menu_width));
else
mSlidingMenu.setBehindWidth(0);

// Download service
Intent it = new Intent(GalleryListActivity.this, DownloadService.class);
Expand Down Expand Up @@ -975,8 +991,10 @@ public void onClosed() {
setNoneText(mResources.getString(R.string.no_found));

// Drawer
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
if (mShowDrawer && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
actionBar.setHomeAsUpIndicator(mResources.getDrawable(R.drawable.ic_navigation_drawer));

// leftDrawer
final int[] data = {R.drawable.ic_action_home, R.string.homepage,
Expand Down Expand Up @@ -1159,16 +1177,12 @@ public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int color = Config.getRandomThemeColor() ? Theme.getRandomDarkColor() : Config.getThemeColor();
color = color & 0x00ffffff | 0xdd000000;
Drawable drawable = new ColorDrawable(color);
final ActionBar actionBar = getActionBar();
actionBar = getActionBar();
actionBar.setBackgroundDrawable(drawable);
Ui.translucent(this, color);
mMenuLeft.setBackgroundColor(color);
tagListMenu.setBackgroundColor(color);

// Check update
if (Config.isAutoCheckForUpdate())
checkUpdate();

// Update user panel
setUserPanel();

Expand All @@ -1179,6 +1193,15 @@ public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
// get MangeList
firstTimeRefresh();

// If not show drawer, just return
if (!mShowDrawer) {
return;
}

// Check update
if (Config.isAutoCheckForUpdate())
checkUpdate();

if (Config.isFirstTime()) {
Config.firstTime();

Expand Down Expand Up @@ -1343,11 +1366,15 @@ else if (mListMode == LIST_MODE_THUMB)
// Double click back exit
@Override
public void onBackPressed() {
if (System.currentTimeMillis() - curBackTime > BACK_PRESSED_INTERVAL) {
curBackTime = System.currentTimeMillis();
MaterialToast.showToast(R.string.exit_tip);
} else
if (!mShowDrawer) {
finish();
} else {
if (System.currentTimeMillis() - curBackTime > BACK_PRESSED_INTERVAL) {
curBackTime = System.currentTimeMillis();
MaterialToast.showToast(R.string.exit_tip);
} else
finish();
}
}

private void jump() {
Expand All @@ -1359,10 +1386,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case android.R.id.home:
if (mSlidingMenu.isMenuShowing())
showContent();
else
showMenu();
if (mShowDrawer) {
if (mSlidingMenu.isMenuShowing())
showContent();
else
showMenu();
} else {
finish();
}
return true;
case R.id.action_refresh:
refresh();
Expand Down

0 comments on commit e3b5ed8

Please sign in to comment.