diff options
author | Andrew Dolgov <[email protected]> | 2012-12-02 20:51:29 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2012-12-02 20:51:29 +0400 |
commit | df1b02237bfb79b51a29392ca4b3d2cd094dcacb (patch) | |
tree | ae6f8d5bd4d24521ccef473e37d0d4093a420bdb /src | |
parent | 176279a33a42c986328b28d1b9a889a3cefdb3b9 (diff) |
runtime thumbnails
Diffstat (limited to 'src')
-rw-r--r-- | src/org/fox/ttcomics/ComicFragment.java | 137 | ||||
-rw-r--r-- | src/org/fox/ttcomics/ComicPager.java | 36 |
2 files changed, 123 insertions, 50 deletions
diff --git a/src/org/fox/ttcomics/ComicFragment.java b/src/org/fox/ttcomics/ComicFragment.java index 5a06a66..18b221d 100644 --- a/src/org/fox/ttcomics/ComicFragment.java +++ b/src/org/fox/ttcomics/ComicFragment.java @@ -31,6 +31,8 @@ public class ComicFragment extends Fragment implements GestureDetector.OnDoubleT private int m_page;
private CommonActivity m_activity;
private GestureDetector m_detector;
+ private ComicArchive m_archive;
+ private boolean m_thumbnail = true;
public ComicFragment() {
super();
@@ -40,8 +42,43 @@ public class ComicFragment extends Fragment implements GestureDetector.OnDoubleT super();
m_page = page;
}
+
+ public void setThumbnail(final boolean thumbnail) {
+ Log.d(TAG, "setThumbnail=" + thumbnail + " isAdded=" + isAdded() + " view=" + getView());
+
+ if (isAdded() && getView() != null && m_thumbnail != thumbnail) {
+
+ AsyncTask<ComicArchive, Void, Bitmap> loadTask = new AsyncTask<ComicArchive, Void, Bitmap>() {
+ @Override
+ protected Bitmap doInBackground(ComicArchive... params) {
+ return loadImage(params[0], m_page, thumbnail);
+ }
+
+ @Override
+ protected void onPostExecute(Bitmap result) {
+ CommonActivity activity = (CommonActivity) getActivity();
+
+ if (activity != null && isAdded() && getView() != null) {
+ ImageViewTouch image = (ImageViewTouch) getView().findViewById(R.id.comic_image);
+
+ if (result != null) {
+ image.setImageBitmap(result);
+ } else {
+ activity.toast(R.string.error_loading_image);
+ image.setImageResource(R.drawable.badimage);
+ }
+ }
+ }
+ };
+
+ loadTask.execute(m_archive);
+
+ }
+
+ m_thumbnail = thumbnail;
+ }
- public Bitmap loadImage(ComicArchive archive, int page) {
+ private Bitmap loadImage(ComicArchive archive, int page, boolean thumbnail) {
CommonActivity activity = (CommonActivity) getActivity();
try {
@@ -49,10 +86,14 @@ public class ComicFragment extends Fragment implements GestureDetector.OnDoubleT options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(archive.getItem(page), null, options);
- if (CommonActivity.isCompatMode()) {
- options.inSampleSize = CommonActivity.calculateInSampleSize(options, 512, 512);
- } else {
- options.inSampleSize = CommonActivity.calculateInSampleSize(options, 1024, 1024);
+ if (thumbnail) {
+ options.inSampleSize = CommonActivity.calculateInSampleSize(options, 256, 256);
+ } else {
+ if (CommonActivity.isCompatMode()) {
+ options.inSampleSize = CommonActivity.calculateInSampleSize(options, 512, 512);
+ } else {
+ options.inSampleSize = CommonActivity.calculateInSampleSize(options, 1024, 1024);
+ }
}
options.inJustDecodeBounds = false;
@@ -81,53 +122,54 @@ public class ComicFragment extends Fragment implements GestureDetector.OnDoubleT m_page = savedInstanceState.getInt("page");
}
+ if (CommonActivity.isCompatMode() && m_prefs.getBoolean("use_dark_theme", false)) {
+ image.setBackgroundColor(0xff000000);
+ }
+
+ image.setFitToScreen(true);
+
ComicPager pager = (ComicPager) getActivity().getSupportFragmentManager().findFragmentByTag(CommonActivity.FRAG_COMICS_PAGER);
- if (pager != null) {
- if (CommonActivity.isCompatMode() && m_prefs.getBoolean("use_dark_theme", false)) {
- image.setBackgroundColor(0xff000000);
+ if (pager != null) {
+ m_thumbnail = pager.getPosition() != m_page;
+ }
+
+ AsyncTask<ComicArchive, Void, Bitmap> loadTask = new AsyncTask<ComicArchive, Void, Bitmap>() {
+ @Override
+ protected Bitmap doInBackground(ComicArchive... params) {
+ return loadImage(params[0], m_page, m_thumbnail);
}
- image.setFitToScreen(true);
-
- AsyncTask<ComicArchive, Void, Bitmap> loadTask = new AsyncTask<ComicArchive, Void, Bitmap>() {
- @Override
- protected Bitmap doInBackground(ComicArchive... params) {
- return loadImage(params[0], m_page);
- }
+ @Override
+ protected void onPostExecute(Bitmap result) {
+ CommonActivity activity = (CommonActivity) getActivity();
- @Override
- protected void onPostExecute(Bitmap result) {
- CommonActivity activity = (CommonActivity) getActivity();
-
- if (activity != null && isAdded()) {
- if (result != null) {
- image.setImageBitmap(result);
- } else {
- activity.toast(R.string.error_loading_image);
- image.setImageResource(R.drawable.badimage);
- }
- }
- }
- };
-
- loadTask.execute(pager.getArchive());
-
- image.setOnScaleChangedListener(new ImageViewTouch.OnScaleChangedListener() {
- @Override
- public void onScaleChanged(float scale) {
- // TODO: shared scale change?
- }
- });
+ if (activity != null && isAdded()) {
+ if (result != null) {
+ image.setImageBitmap(result);
+ } else {
+ activity.toast(R.string.error_loading_image);
+ image.setImageResource(R.drawable.badimage);
+ }
+ }
+ }
+ };
+
+ loadTask.execute(m_archive);
+
+ image.setOnScaleChangedListener(new ImageViewTouch.OnScaleChangedListener() {
+ @Override
+ public void onScaleChanged(float scale) {
+ // TODO: shared scale change?
+ }
+ });
- image.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View view, MotionEvent event) {
- return m_detector.onTouchEvent(event);
- }
- });
-
- }
+ image.setOnTouchListener(new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View view, MotionEvent event) {
+ return m_detector.onTouchEvent(event);
+ }
+ });
TextView page = (TextView) view.findViewById(R.id.comic_page);
@@ -180,6 +222,9 @@ public class ComicFragment extends Fragment implements GestureDetector.OnDoubleT m_prefs = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
m_activity = (CommonActivity) activity;
+ ComicPager pager = (ComicPager) getActivity().getSupportFragmentManager().findFragmentByTag(CommonActivity.FRAG_COMICS_PAGER);
+ m_archive = pager.getArchive();
+
m_detector = new GestureDetector(m_activity, new GestureDetector.OnGestureListener() {
@Override
diff --git a/src/org/fox/ttcomics/ComicPager.java b/src/org/fox/ttcomics/ComicPager.java index 934aaa7..d3c8c70 100644 --- a/src/org/fox/ttcomics/ComicPager.java +++ b/src/org/fox/ttcomics/ComicPager.java @@ -1,6 +1,7 @@ package org.fox.ttcomics;
import java.io.IOException;
+import java.util.HashMap;
import com.github.junrar.exception.RarException;
@@ -25,19 +26,33 @@ public class ComicPager extends Fragment { private CommonActivity m_activity;
private class PagerAdapter extends FragmentStatePagerAdapter {
+ HashMap<Integer, ComicFragment> m_fragments = new HashMap<Integer, ComicFragment>();
+
public PagerAdapter(FragmentManager fm) {
super(fm);
}
-
+
@Override
public Fragment getItem(int position) {
- return new ComicFragment(position);
+ ComicFragment cf = new ComicFragment(position);
+ m_fragments.put(position, cf);
+ return cf;
}
-
+
@Override
public int getCount() {
return m_archive.getCount();
}
+
+ @Override
+ public void destroyItem(View container, int position, Object object) {
+ super.destroyItem(container, position, object);
+ m_fragments.remove(position);
+ }
+
+ public ComicFragment getFragmentAt(int position) {
+ return m_fragments.get(position);
+ }
}
private PagerAdapter m_adapter;
@@ -124,15 +139,28 @@ public class ComicPager extends Fragment { }
pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
+ private ComicFragment m_current;
public void onPageSelected(int position) {
m_activity.onComicSelected(m_fileName, position);
-
m_activity.setProgress(Math.round(((float)position / (float)(m_archive.getCount()-1)) * 10000));
if (!CommonActivity.isCompatMode() && m_prefs.getBoolean("dim_status_bar", false)) {
view.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
}
+
+ ComicFragment cf = m_adapter.getFragmentAt(position);
+
+ Log.d(TAG, "cf=" + cf);
+
+ if (cf != null) {
+ if (m_current != null) {
+ m_current.setThumbnail(true);
+ }
+
+ cf.setThumbnail(false);
+ m_current = cf;
+ }
}
public void onPageScrolled(int arg0, float arg1, int arg2) {
|