Permalink
Browse files

Add pinch zoom supports

  • Loading branch information...
1 parent 2638926 commit 662de990afb5d4418243e7de115c5755221a0403 @ghk committed Jul 4, 2011
View
@@ -1,5 +1,7 @@
Android comic library for perfect viewer https://market.android.com/details?id=com.rookiestudio.perfectviewer&hl=en
+It reads perfectviewer bookdata.db
+
Using coverflow widget: http://www.inter-fuser.com/2010/02/android-coverflow-widget-v2.html
Icons by: http://www.customicondesign.com/
@@ -40,13 +40,18 @@
* The maximum angle the Child ImageView will be rotated by
*/
private int mMaxRotationAngle = 30;
+
+ /**
+ * The base z translation
+ */
+ private float mZoom = -350.0f;
/**
- * The maximum zoom on the centre Child
+ * The maximum zoom (z translation) on the centre Child
+ * so the center child translations equals to mZoom + mMaxZoom
*/
private int mMaxZoom = -100;
- private float mZoom = -350.0f;
/**
* The Centre of the Coverflow
@@ -105,6 +110,15 @@ public int getMaxZoom() {
public void setMaxZoom(int maxZoom) {
mMaxZoom = maxZoom;
}
+
+
+ public void setZoom(float zoom){
+ mZoom = zoom;
+ }
+
+ public float getZoom(){
+ return mZoom;
+ }
/**
* Get the Centre of the Coverflow
@@ -42,7 +42,8 @@ public ItemAdapter(Context c, List<Item> items, boolean useReflection) {
if(useReflection){
bitmaps = createReflectedImages(bitmaps);
}
-
+ for(Item item: items)
+ item.clearImage();
}
private List<Bitmap> createReflectedImages(List<Bitmap> originalImages) {
@@ -13,14 +13,47 @@
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
+import android.view.MotionEvent;
+import android.view.ScaleGestureDetector;
import android.view.View;
import android.webkit.MimeTypeMap;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.TextView;
public class SeriesActivity extends Activity {
+
private Item selectedItem;
+ private CoverFlow coverFlow;
+
+ private ScaleGestureDetector scaleDetector = new ScaleGestureDetector(this,
+
+ new ScaleGestureDetector.OnScaleGestureListener() {
+
+ float minZoom = -400;
+ float maxZoom = -200;
+
+ @Override
+ public void onScaleEnd(ScaleGestureDetector detector) {
+ }
+
+ @Override
+ public boolean onScaleBegin(ScaleGestureDetector detector) {
+ return true;
+ }
+
+ @Override
+ public boolean onScale(ScaleGestureDetector detector) {
+ float newZoom = coverFlow.getZoom()*detector.getScaleFactor();
+ if(newZoom > maxZoom)
+ newZoom = maxZoom;
+ if(newZoom < minZoom)
+ newZoom = minZoom;
+ coverFlow.setZoom(newZoom);
+ coverFlow.setSelection(coverFlow.getSelectedItemPosition());
+ return true;
+ }
+ });
/** Called when the activity is first created. */
@Override
@@ -44,10 +77,25 @@ public void onCreate(Bundle savedInstanceState) {
initialize(items);
}
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ if(scaleDetector == null)
+ return false;
+
+ return scaleDetector.onTouchEvent(event);
+ }
+
private void initialize(final List<Item> items){
setContentView(R.layout.main);
- CoverFlow coverFlow = (CoverFlow) findViewById(R.id.coverflow);
+ ItemAdapter coverImageAdapter = new ItemAdapter(this, items, true);
+
+ coverFlow = (CoverFlow) findViewById(R.id.coverflow);
+ coverFlow.setAdapter(coverImageAdapter);
+ coverFlow.setSpacing(0);
+ coverFlow.setAnimationDuration(1000);
+
coverFlow.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
@@ -59,15 +107,6 @@ public void onNothingSelected(android.widget.AdapterView<?> arg0) {
setSelectedItem(null);
};
});
-
- ItemAdapter coverImageAdapter = new ItemAdapter(this, items, true);
- coverFlow.setAdapter(coverImageAdapter);
- for(Item item: items)
- item.clearImage();
-
- coverFlow.setSpacing(0);
- coverFlow.setAnimationDuration(1000);
-
coverFlow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,

0 comments on commit 662de99

Please sign in to comment.