diff options
author | Andrew Dolgov <[email protected]> | 2012-12-01 21:57:54 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2012-12-01 21:57:54 +0400 |
commit | 3d161d94e865ec1249d3142a2253a0431f0bc181 (patch) | |
tree | 081aeec0907132e7e17f17a6e5046af241046483 | |
parent | 6a31f8c3ca009aac6a649a495985e04233633706 (diff) |
use gesturedetector to detect side taps, toggle actionbar when tapping
on the middle of the screen
-rw-r--r-- | AndroidManifest.xml | 4 | ||||
-rw-r--r-- | src/org/fox/ttcomics/ComicFragment.java | 113 | ||||
-rw-r--r-- | src/org/fox/ttcomics/CommonActivity.java | 2 | ||||
-rw-r--r-- | src/org/fox/ttcomics/ViewComicActivity.java | 14 |
4 files changed, 98 insertions, 35 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 9ef125b..97c8cf8 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,7 +1,7 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.fox.ttcomics"
- android:versionCode="27"
- android:versionName="1.0.15" >
+ android:versionCode="28"
+ android:versionName="1.0.16" >
<uses-sdk
android:minSdkVersion="8"
diff --git a/src/org/fox/ttcomics/ComicFragment.java b/src/org/fox/ttcomics/ComicFragment.java index 21c50fd..5a06a66 100644 --- a/src/org/fox/ttcomics/ComicFragment.java +++ b/src/org/fox/ttcomics/ComicFragment.java @@ -5,6 +5,7 @@ import it.sephiroth.android.library.imagezoom.ImageViewTouch; import java.io.IOException;
import java.io.InputStream;
+import android.app.ActionBar;
import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
@@ -14,6 +15,7 @@ import android.os.Bundle; import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.util.Log;
+import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -22,12 +24,13 @@ import android.widget.ImageView; import android.widget.ImageView.ScaleType;
import android.widget.TextView;
-public class ComicFragment extends Fragment {
+public class ComicFragment extends Fragment implements GestureDetector.OnDoubleTapListener {
private final String TAG = this.getClass().getSimpleName();
private SharedPreferences m_prefs;
private int m_page;
private CommonActivity m_activity;
+ private GestureDetector m_detector;
public ComicFragment() {
super();
@@ -113,32 +116,14 @@ public class ComicFragment extends Fragment { image.setOnScaleChangedListener(new ImageViewTouch.OnScaleChangedListener() {
@Override
public void onScaleChanged(float scale) {
- /* ViewPager pager = (ViewPager) getActivity().findViewById(R.id.comics_pager);
-
- if (pager != null) {
- pager.setPagingEnabled(widthFits);
- } */
+ // TODO: shared scale change?
}
});
image.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
- switch (event.getAction()) {
- case MotionEvent.ACTION_UP:
- int x = Math.round(event.getX());
- //int y = Math.round(event.getY());
-
- int width = view.getWidth();
-
- if (x <= width/10) {
- onLeftSideTapped();
- } else if (x >= width-(width/10)) {
- onRightSideTapped();
- }
- break;
- }
- return false;
+ return m_detector.onTouchEvent(event);
}
});
@@ -169,7 +154,11 @@ public class ComicFragment extends Fragment { public boolean canScroll(int direction) {
ImageViewTouch image = (ImageViewTouch) getView().findViewById(R.id.comic_image);
- return image.canScroll(direction);
+ if (image != null) {
+ return image.canScroll(direction);
+ } else {
+ return false;
+ }
}
private void onRightSideTapped() {
@@ -190,6 +179,49 @@ public class ComicFragment extends Fragment { m_prefs = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
m_activity = (CommonActivity) activity;
+
+ m_detector = new GestureDetector(m_activity, new GestureDetector.OnGestureListener() {
+
+ @Override
+ public boolean onSingleTapUp(MotionEvent e) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void onShowPress(MotionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
+ float distanceY) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void onLongPress(MotionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
+ float velocityY) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean onDown(MotionEvent e) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+ });
+
+ m_detector.setOnDoubleTapListener(this);
}
@Override
@@ -197,5 +229,40 @@ public class ComicFragment extends Fragment { super.onSaveInstanceState(out);
out.putInt("page", m_page);
}
-
+
+ @Override
+ public boolean onDoubleTap(MotionEvent e) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean onDoubleTapEvent(MotionEvent e) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean onSingleTapConfirmed(MotionEvent e) {
+
+ int width = getView().getWidth();
+
+ int x = Math.round(e.getX());
+
+ if (x <= width/10) {
+ onLeftSideTapped();
+ } else if (x >= width-(width/10)) {
+ onRightSideTapped();
+ } else if (!CommonActivity.isCompatMode()) {
+ ActionBar bar = m_activity.getActionBar();
+
+ if (bar.isShowing()) {
+ bar.hide();
+ } else {
+ bar.show();
+ }
+ }
+
+ return false;
+ }
}
diff --git a/src/org/fox/ttcomics/CommonActivity.java b/src/org/fox/ttcomics/CommonActivity.java index d535fe6..77b8427 100644 --- a/src/org/fox/ttcomics/CommonActivity.java +++ b/src/org/fox/ttcomics/CommonActivity.java @@ -22,6 +22,7 @@ import android.support.v4.app.FragmentActivity; import android.util.Log;
import android.view.Display;
import android.view.MenuItem;
+import android.view.WindowManager;
import android.widget.Toast;
public class CommonActivity extends FragmentActivity {
@@ -530,5 +531,4 @@ public class CommonActivity extends FragmentActivity { }
-
}
diff --git a/src/org/fox/ttcomics/ViewComicActivity.java b/src/org/fox/ttcomics/ViewComicActivity.java index 95917c5..7d26de7 100644 --- a/src/org/fox/ttcomics/ViewComicActivity.java +++ b/src/org/fox/ttcomics/ViewComicActivity.java @@ -34,7 +34,6 @@ 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")
@@ -67,13 +66,14 @@ public class ViewComicActivity extends CommonActivity { }
setTitle(new File(m_fileName).getName());
-
+
if (m_prefs.getBoolean("use_full_screen", false)) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ WindowManager.LayoutParams.FLAG_FULLSCREEN);
- getActionBar().hide();
- m_fullScreen = true;
+ if (!isCompatMode()) {
+ getActionBar().hide();
+ }
}
}
@@ -84,10 +84,6 @@ public class ViewComicActivity extends CommonActivity { menu.findItem(R.id.menu_sync_location).setVisible(m_prefs.getBoolean("use_position_sync", false) && m_syncClient.hasOwner());
- if (m_fullScreen && !isCompatMode()) {
- menu.findItem(R.id.menu_share).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
- }
-
return true;
}
|