diff options
author | Andrew Dolgov <[email protected]> | 2012-12-01 15:36:09 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2012-12-01 15:36:09 +0400 |
commit | 8245607f3d6f055bb3feec288777f4216196b366 (patch) | |
tree | ddf0a9fa4784b1e9be13dcf8fce44297b83da5ec /src | |
parent | 022b17a79b02d1199b4c6fe3b98d98ad3c2ef1e7 (diff) | |
parent | f00ef55ad2687d0dd783c9b0b7a29d125ce13684 (diff) |
Merge branch 'master' of github.com:gothfox/Tiny-Comics-Reader
Conflicts:
res/values/strings.xml
Diffstat (limited to 'src')
-rw-r--r-- | src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java | 6 | ||||
-rw-r--r-- | src/org/fox/ttcomics/ComicFragment.java | 35 | ||||
-rw-r--r-- | src/org/fox/ttcomics/ComicPager.java | 12 | ||||
-rw-r--r-- | src/org/fox/ttcomics/CommonActivity.java | 6 | ||||
-rw-r--r-- | src/org/fox/ttcomics/ViewComicActivity.java | 29 | ||||
-rw-r--r-- | src/org/fox/ttcomics/ViewPager.java | 39 |
6 files changed, 80 insertions, 47 deletions
diff --git a/src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java b/src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java index f3399fd..73392b1 100644 --- a/src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java +++ b/src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java @@ -7,7 +7,6 @@ import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.Log; -import android.view.Display; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.MotionEvent; @@ -34,7 +33,7 @@ public class ImageViewTouch extends ImageViewTouchBase { private OnImageViewTouchDoubleTapListener doubleTapListener; public interface OnScaleChangedListener { - public void onScaleChanged(float scale, boolean widthFits); + public void onScaleChanged(float scale); } protected OnScaleChangedListener mScaleChangedListener; @@ -121,8 +120,7 @@ public class ImageViewTouch extends ImageViewTouchBase { if ( !mScaleDetector.isInProgress() ) mCurrentScaleFactor = scale; if (mScaleChangedListener != null) { - RectF bitmapRect = getBitmapRect(); - mScaleChangedListener.onScaleChanged(mCurrentScaleFactor, getWidth() >= (bitmapRect.right - bitmapRect.left)); + mScaleChangedListener.onScaleChanged(mCurrentScaleFactor); } } diff --git a/src/org/fox/ttcomics/ComicFragment.java b/src/org/fox/ttcomics/ComicFragment.java index da34ce4..21c50fd 100644 --- a/src/org/fox/ttcomics/ComicFragment.java +++ b/src/org/fox/ttcomics/ComicFragment.java @@ -102,6 +102,7 @@ public class ComicFragment extends Fragment { image.setImageBitmap(result);
} else {
activity.toast(R.string.error_loading_image);
+ image.setImageResource(R.drawable.badimage);
}
}
}
@@ -111,12 +112,12 @@ public class ComicFragment extends Fragment { image.setOnScaleChangedListener(new ImageViewTouch.OnScaleChangedListener() {
@Override
- public void onScaleChanged(float scale, boolean widthFits) {
- ViewPager pager = (ViewPager) getActivity().findViewById(R.id.comics_pager);
+ public void onScaleChanged(float scale) {
+ /* ViewPager pager = (ViewPager) getActivity().findViewById(R.id.comics_pager);
if (pager != null) {
pager.setPagingEnabled(widthFits);
- }
+ } */
}
});
@@ -154,11 +155,33 @@ public class ComicFragment extends Fragment { }
private void onLeftSideTapped() {
- m_activity.selectPreviousComic();
+ ImageViewTouch image = (ImageViewTouch) getView().findViewById(R.id.comic_image);
+
+ if (image != null) {
+ boolean atLeftEdge = !image.canScroll(1);
+
+ if (atLeftEdge) {
+ m_activity.selectPreviousComic();
+ }
+ }
}
-
+
+ public boolean canScroll(int direction) {
+ ImageViewTouch image = (ImageViewTouch) getView().findViewById(R.id.comic_image);
+
+ return image.canScroll(direction);
+ }
+
private void onRightSideTapped() {
- m_activity.selectNextComic();
+ ImageViewTouch image = (ImageViewTouch) getView().findViewById(R.id.comic_image);
+
+ if (image != null) {
+ boolean atRightEdge = !image.canScroll(-1);
+
+ if (atRightEdge) {
+ m_activity.selectNextComic();
+ }
+ }
}
@Override
diff --git a/src/org/fox/ttcomics/ComicPager.java b/src/org/fox/ttcomics/ComicPager.java index ab40936..934aaa7 100644 --- a/src/org/fox/ttcomics/ComicPager.java +++ b/src/org/fox/ttcomics/ComicPager.java @@ -164,17 +164,5 @@ public class ComicPager extends Fragment { out.putString("fileName", m_fileName);
}
-
- public boolean isPagingEnabled() {
-
- ViewPager pager = (ViewPager) getView().findViewById(R.id.comics_pager);
-
- if (pager != null) {
- return pager.isPagingEnabled();
- }
-
- return false;
- }
-
}
diff --git a/src/org/fox/ttcomics/CommonActivity.java b/src/org/fox/ttcomics/CommonActivity.java index 873ccd3..d535fe6 100644 --- a/src/org/fox/ttcomics/CommonActivity.java +++ b/src/org/fox/ttcomics/CommonActivity.java @@ -492,7 +492,7 @@ public class CommonActivity extends FragmentActivity { public void selectPreviousComic() {
ComicPager frag = (ComicPager) getSupportFragmentManager().findFragmentByTag(FRAG_COMICS_PAGER);
- if (frag != null && frag.isAdded() && frag.getPosition() > 0 && frag.isPagingEnabled()) {
+ if (frag != null && frag.isAdded() && frag.getPosition() > 0) {
frag.setCurrentItem(frag.getPosition() - 1);
}
}
@@ -500,11 +500,9 @@ public class CommonActivity extends FragmentActivity { public void selectNextComic() {
ComicPager frag = (ComicPager) getSupportFragmentManager().findFragmentByTag(FRAG_COMICS_PAGER);
- if (frag != null && frag.isAdded() && frag.getPosition() < frag.getCount()-1 && frag.isPagingEnabled()) {
+ if (frag != null && frag.isAdded() && frag.getPosition() < frag.getCount()-1) {
frag.setCurrentItem(frag.getPosition() + 1);
}
-
-
}
public void cleanupSqliteCache(String baseDir) {
diff --git a/src/org/fox/ttcomics/ViewComicActivity.java b/src/org/fox/ttcomics/ViewComicActivity.java index 48bfa9e..95917c5 100644 --- a/src/org/fox/ttcomics/ViewComicActivity.java +++ b/src/org/fox/ttcomics/ViewComicActivity.java @@ -12,6 +12,8 @@ import android.content.BroadcastReceiver; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
@@ -33,6 +35,7 @@ public class ViewComicActivity extends CommonActivity { private String m_fileName;
private String m_tmpFileName;
private boolean m_fullScreen = false;
+ private boolean m_orientationLocked = false;
@SuppressLint("NewApi")
@Override
@@ -54,8 +57,11 @@ public class ViewComicActivity extends CommonActivity { } else {
m_fileName = savedInstanceState.getString("fileName");
m_tmpFileName = savedInstanceState.getString("tmpFileName");
+ m_orientationLocked = savedInstanceState.getBoolean("orientationLocked");
}
+ setOrientationLock(m_orientationLocked);
+
if (!isCompatMode()) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
@@ -91,6 +97,7 @@ public class ViewComicActivity extends CommonActivity { out.putString("fileName", m_fileName);
out.putString("tmpFileName", m_tmpFileName);
+ out.putBoolean("orientationLocked", m_orientationLocked);
}
@Override
@@ -103,7 +110,7 @@ public class ViewComicActivity extends CommonActivity { // upload progress
if (m_prefs.getBoolean("use_position_sync", false) && m_syncClient.hasOwner()) {
- toast(R.string.sync_uploading);
+ //toast(R.string.sync_uploading);
m_syncClient.setPosition(sha1(new File(m_fileName).getName()), getLastPosition(m_fileName));
}
}
@@ -162,10 +169,30 @@ public class ViewComicActivity extends CommonActivity { super.onActivityResult(requestCode, resultCode, intent);
}
+ private void setOrientationLock(boolean locked) {
+ if (locked) {
+ int currentOrientation = getResources().getConfiguration().orientation;
+
+ if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
+ }
+ else {
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
+ }
+ } else {
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
+ }
+
+ m_orientationLocked = locked;
+ }
+
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_share:
shareComic();
+ return true;
+ case R.id.menu_toggle_orientation_lock:
+ setOrientationLock(!m_orientationLocked);
return true;
case R.id.menu_sync_location:
m_syncClient.getPosition(sha1(new File(m_fileName).getName()), new SyncClient.PositionReceivedListener() {
diff --git a/src/org/fox/ttcomics/ViewPager.java b/src/org/fox/ttcomics/ViewPager.java index c5d2f13..6d9c68f 100644 --- a/src/org/fox/ttcomics/ViewPager.java +++ b/src/org/fox/ttcomics/ViewPager.java @@ -1,43 +1,42 @@ package org.fox.ttcomics;
+import it.sephiroth.android.library.imagezoom.ImageViewTouch;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
+import android.view.View;
public class ViewPager extends android.support.v4.view.ViewPager {
private final String TAG = this.getClass().getSimpleName();
- private boolean enabled;
public ViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
- this.enabled = true;
}
@Override
+ protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
+ if (v instanceof ImageViewTouch) {
+ ImageViewTouch ivt = (ImageViewTouch) v;
+ try {
+ return ivt.canScroll(dx);
+ } catch (NullPointerException e) {
+ // bad image, etc
+ return false;
+ }
+ } else {
+ return super.canScroll(v, checkV, dx, x, y);
+ }
+ }
+
+ @Override
public boolean onTouchEvent(MotionEvent event) {
- if (this.enabled) {
- return super.onTouchEvent(event);
- }
-
- return false;
+ return super.onTouchEvent(event);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
- if (this.enabled) {
- return super.onInterceptTouchEvent(event);
- }
-
- return false;
- }
-
- public void setPagingEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public boolean isPagingEnabled() {
- return this.enabled;
+ return super.onInterceptTouchEvent(event);
}
}
\ No newline at end of file |