4

I have app , one of its activity is infinite galley with images stored in res drawable folder ,

im trying to have double tab and Pinch Zoom for images ,

i searched Google no any example related to zoom effect with infinite gallery ,

any advice will be appreciated .

DayGallery.java:

 @SuppressWarnings("deprecation")
public class DayGallery extends Activity {
TextView tv;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN);  
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
// Set the layout to use
setContentView(R.layout.main);
if (customTitleSupported) { 
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title); 
     tv = (TextView) findViewById(R.id.title_tv1); 
     tv.setTypeface(FontFactory.getBFantezy(getBaseContext()));
     }           
InfiniteGallery galleryOne = (InfiniteGallery) findViewById(R.id.galleryOne);
galleryOne.setAdapter(initializeImages()); 
galleryOne.setSelection(galleryOne.getCount()/2);  
}  

private InfiniteGalleryAdapter initializeImages() {
InfiniteGalleryAdapter galleryAdapter = null;

String day = getIntent().getStringExtra("dayname");

if(day.equalsIgnoreCase("Day1")){
    int[] tempimages = { R.drawable.day_one_1, R.drawable.day_one_2,R.drawable.day_one_3, 
            R.drawable.day_one_4, R.drawable.day_one_5,R.drawable.day_one_6,R.drawable.day_one_7,       
            R.drawable.day_one_8, R.drawable.day_one_9,R.drawable.day_one_10,R.drawable.day_one_11,
            R.drawable.day_one_12
    };  
    String[] name = { "00:35","00:35","00:35","1:07","2:00","2:01","2:09",
                      "2:12","2:15","6:13","6:13","6:13"
    };  
    tv.setText("Day one pictures");
    galleryAdapter=new InfiniteGalleryAdapter(this, tempimages, name); 
    }       
else if(day.equalsIgnoreCase("Day2")){
    int[] tempimages = { R.drawable.day_two_1, R.drawable.day_two_2,R.drawable.day_two_3, 
            R.drawable.day_two_4, R.drawable.day_two_5,R.drawable.day_two_6,R.drawable.day_two_7,
            R.drawable.day_two_8, R.drawable.day_two_9,R.drawable.day_two_10,R.drawable.day_two_11,
            R.drawable.day_two_12
    };  
    String[] name = { "12:04","12:04", "12:04","12:05","12:06", "12:07",
                      "12:07","12:07","12:08","12:10","12:10","12:10"
    };  
    tv.setText("Day two pictures"); 
    galleryAdapter=new InfiniteGalleryAdapter(this, tempimages, name); 
    }

// AND THE SAME FOR REST OF DAYS TILL Day10//

return galleryAdapter; 
}
}

class InfiniteGalleryAdapter extends BaseAdapter { 
private Context mContext;
private int[] images;   
private String[] name;
public InfiniteGalleryAdapter(Context c, int[] imageIds,String[] names) { 
this.mContext = c; 
images = imageIds;
name=names;
inflater = (LayoutInflater)mContext.getSystemService ( Context.LAYOUT_INFLATER_SERVICE); 
} 
public int getCount() { 
return Integer.MAX_VALUE; 
} 
public Object getItem(int position) { 
return position; 
} 
public long getItemId(int position) { 
return position; 
} 
private LayoutInflater inflater=null; 

public class ViewHolder{ 
public TextView text; 
public ImageView image; 
} 

public View getView(int position, View convertView, ViewGroup parent) { 
ImageView i = getImageView(); 

int itemPos = (position % images.length); 

try { i.setImageResource(images[itemPos]); ((BitmapDrawable) i.getDrawable()).setAntiAlias(true); 
} 
catch (OutOfMemoryError e) { Log.e("InfiniteGalleryAdapter", "Out of memory creating imageview. Using empty view.", e); 
} 
View vi=convertView; 
ViewHolder holder; 
if(convertView==null){ 
    vi = inflater.inflate(R.layout.gallery_items, null); 
    holder=new ViewHolder(); 
    holder.text=(TextView)vi.findViewById(R.id.textView1); 
    holder.image=(ImageView)vi.findViewById(R.id.image); 
    vi.setTag(holder); 
    } 
else holder=(ViewHolder)vi.getTag(); 
holder.text.setText(name[itemPos]); 

final int stub_id=images[itemPos]; 
holder.image.setImageResource(stub_id); 

return vi; 
} 

private ImageView getImageView() { 

ImageView i = new ImageView(mContext); 

return i; 
} 
}

 @SuppressWarnings("deprecation")
class InfiniteGallery extends Gallery {

public InfiniteGallery(Context context) {
super(context);
init(); 
}

public InfiniteGallery(Context context, AttributeSet attrs) {
super(context, attrs);
init(); 
}

public InfiniteGallery(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(); 
}

private void init(){
// These are just to make it look pretty
setSpacing(25);
setHorizontalFadingEdgeEnabled(false); 
}
}

main.xml

<?xml version="1.0" encoding="utf-8" ?> 
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   android:orientation="vertical" 
   android:background="#FFDAB9">
 <com.test.demo.InfiniteGallery 
   android:id="@+id/galleryOne" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" /> 
</LinearLayout>

UPDATE:

as per Yoann Hercouet answer i replace this code :

 private ImageView getImageView() { 
  ImageView i = new ImageView(mContext); 
  return i; 
 } 
 }

with the following below code :

 private GestureImageView getImageView() {   
  GestureImageView i = new GestureImageView(mContext); 
   return i; 
  } 
  }

also adjust the getview , so finally my class will be as below :

 @SuppressWarnings("deprecation")
public class DayGallery extends Activity {
 TextView tv;

    /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
   getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
    WindowManager.LayoutParams.FLAG_FULLSCREEN);  
   getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
 Boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 

 setContentView(R.layout.main);
 if (customTitleSupported) { 
   getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title); 
     tv = (TextView) findViewById(R.id.title_tv1); 
     tv.setTypeface(FontFactory.getBFantezy(getBaseContext()));
    } 

 InfiniteGallery galleryOne = (InfiniteGallery) findViewById(R.id.galleryOne);
  galleryOne.setAdapter(initializeImages()); 
  galleryOne.setSelection(galleryOne.getCount()/2);  
  }  

 private InfiniteGalleryAdapter initializeImages() {
  InfiniteGalleryAdapter galleryAdapter = null;

   String day = getIntent().getStringExtra("dayname");

  if(day.equalsIgnoreCase("Day1")){
   int[] tempimages = { R.drawable.day_one_1, R.drawable.day_one_2,R.drawable.day_one_3, 
        R.drawable.day_one_4, R.drawable.day_one_5,R.drawable.day_one_6,R.drawable.day_one_7,       
        R.drawable.day_one_8, R.drawable.day_one_9,R.drawable.day_one_10,R.drawable.day_one_11,
        R.drawable.day_one_12
};  
String[] name = { "00:35","00:35","00:35","1:07","2:00","2:01","2:09",
                  "2:12","2:15","6:13","6:13","6:13"
};  
tv.setText("Day one pictures");
galleryAdapter=new InfiniteGalleryAdapter(this, tempimages, name); 
}       
else if(day.equalsIgnoreCase("Day2")){
   int[] tempimages = { R.drawable.day_two_1, R.drawable.day_two_2,R.drawable.day_two_3, 
        R.drawable.day_two_4, R.drawable.day_two_5,R.drawable.day_two_6,R.drawable.day_two_7,
        R.drawable.day_two_8, R.drawable.day_two_9,R.drawable.day_two_10,R.drawable.day_two_11,
        R.drawable.day_two_12
};  
String[] name = { "12:04","12:04", "12:04","12:05","12:06", "12:07",
                  "12:07","12:07","12:08","12:10","12:10","12:10"
};  
tv.setText("Day two pictures"); 
galleryAdapter=new InfiniteGalleryAdapter(this, tempimages, name); 
}

        // AND THE SAME FOR REST OF DAYS TILL Day10//

return galleryAdapter; 
 }
 }

 class InfiniteGalleryAdapter extends BaseAdapter { 
private Context mContext;
private int[] images;   
private String[] name;
public InfiniteGalleryAdapter(Context c, int[] imageIds,String[] names) { 
    this.mContext = c; 
    images = imageIds;
    name=names;
    inflater = (LayoutInflater)mContext.getSystemService ( Context.LAYOUT_INFLATER_SERVICE); 
    }

public int getCount() { 
    return Integer.MAX_VALUE; 
    } 

public Object getItem(int position) { 
    return position; 
    } 

public long getItemId(int position) { 
    return position; 
    } 

private LayoutInflater inflater=null; 

public class ViewHolder{ 
    public TextView text; 
    public ImageView image; 
    } 
public View getView(int position, View convertView, ViewGroup parent) { 
    GestureImageView i = getImageView(); 
    int itemPos = (position % images.length); 
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);//addition

    try { 
        i.setImageResource(images[itemPos]); 
        ((BitmapDrawable) i.getDrawable()).setAntiAlias(true);
        i.setLayoutParams(params); //addition
    } 
    catch (OutOfMemoryError e) { 
        Log.e("InfiniteGalleryAdapter", "Out of memory creating   imageview. Using empty view.", e); 
    } 
    View vi=convertView; 
    ViewHolder holder; 
    if(convertView==null){ 
        vi = inflater.inflate(R.layout.gallery_items, null); 
        holder=new ViewHolder(); 
        holder.text=(TextView)vi.findViewById(R.id.textView1); 
        holder.image=(ImageView)vi.findViewById(R.id.image); 
        vi.setTag(holder); 
        } 

    else holder=(ViewHolder)vi.getTag(); 
    holder.text.setText(name[itemPos]); 

    final int stub_id=images[itemPos]; 
    holder.image.setImageResource(stub_id); 

    return vi; 
    } 

 private GestureImageView getImageView() {   
   GestureImageView i = new GestureImageView(mContext); 
    return i; 
   } 

  @SuppressWarnings("deprecation")
  class InfiniteGallery extends Gallery {

public InfiniteGallery(Context context) {
    super(context);
    init(); 
    }

public InfiniteGallery(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(); 
    }

public InfiniteGallery(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init(); 
    }

private void init(){
    // These are just to make it look pretty
    setSpacing(25);
    setHorizontalFadingEdgeEnabled(false); 
}
}   
}

AND if i use my modified class with my original main.xmla below :

<?xml version="1.0" encoding="utf-8" ?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:orientation="vertical" 
  android:background="#FFDAB9">
<com.test.demo.InfiniteGallery
  android:id="@+id/galleryOne" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" /> 
</LinearLayout>

it gave force clos with the below logcat:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.demo/com.ttest.demo.DayGallery}: android.view.InflateException: Binary XML file line #7: Error inflating class com.test.demo.InfiniteGallery
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
   Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.tsn.dr.InfiniteGallery
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:216)
at android.app.Activity.setContentView(Activity.java:1660)
at com.test.demo.DayGallery.onCreate(DayGallery.java:35)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more
  Caused by: java.lang.ClassNotFoundException: com.test.demo.InfiniteGallery in loader dalvik.system.PathClassLoader[/data/app/com.test.demo-1.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.view.LayoutInflater.createView(LayoutInflater.java:471)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
... 20 more

AND if i use the modified class with my modified main.xml as below :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:gesture-image="http://schemas.polites.com/android"
  android:id="@+id/layout"
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:orientation="vertical" 
  android:background="#FFDAB9">
<com.test.demo.InfiniteGallery 
   android:id="@+id/galleryOne" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" /> 

 <com.polites.android.GestureImageView
   android:id="@+id/image"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent" 
   gesture-image:min-scale="0.75"
  gesture-image:max-scale="10.0"
 />

it gave also force close with the below logcat:

  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.demo/com.test.demo.DayGallery}: android.view.InflateException: Binary XML file line #9: Error inflating class com.test.demo.InfiniteGallery
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
 Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class com.test.demo.InfiniteGallery
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:216)
at android.app.Activity.setContentView(Activity.java:1660)
at com.test.demo.DayGallery.onCreate(DayGallery.java:35)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more
  Caused by: java.lang.ClassNotFoundException: com.tsn.dr.InfiniteGallery in loader dalvik.system.PathClassLoader[/data/app/com.tsn.dr-1.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.view.LayoutInflater.createView(LayoutInflater.java:471)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
... 20 more

UPDATE 2

enter image description here

Android Stack
  • 4,314
  • 6
  • 31
  • 49

5 Answers5

1

you can use custom imagGallery control.. check this https://github.com/kilaka/ImageViewZoom you can swipe images as gallery view and able to do a pinch zoom. in this example you have a adapter class.. check it out.

Sanket Kachhela
  • 10,861
  • 8
  • 50
  • 75
  • please can you simplified your answer with some code corresponding with my code , i check that link you provide , actually i cant solve my problem with that project, thanks – Android Stack Aug 19 '13 at 17:17
  • please can you explain more with piece of code how to add it to my DayGallery class , thanks – Android Stack Aug 26 '13 at 08:33
1

You can use my Pinch to zoom Gallery project. You can choose any image from gallery and then in onDoubleTap(MotionEvent e) open full image and zoom it. You should use two widget classes PinchZoomGallery, TouchImageView and activity class PinchZoomActivity or add gallery functionality into your activity class.

Artyom Kiriliyk
  • 2,513
  • 1
  • 17
  • 21
  • please can you explain more with piece of code how to add it to my DayGallery class , thanks – Android Stack Aug 26 '13 at 08:33
  • Why your gallery is infinite? 120 images isn't infinity. Change your class InfiniteGallery with my class PinchZoomGallery (add checking day 1, etc), then change class InfiniteGalleryAdapter with my class ImageAdapter and add TextView functionality. Remove GestureImageView and add TouchImageView. Remove unnecessary code from onCreate and add this `super.onCreate(savedInstanceState); setContentView(R.layout.main); gallery = (PinchZoomGallery) findViewById(R.id.gallery); gallery.setSpacing(15); gallery.setAdapter(new ImageAdapter(this)); gallery.setSelection(1);` – Artyom Kiriliyk Aug 26 '13 at 21:43
1

I use the following library on my apps: https://github.com/jasonpolites/gesture-imageview

This library offers what you are asking (double tap and pinch zoom) along with other features.

You can setup programmatically the image doing this:

GestureImageView view = new GestureImageView(this);
view.setImageResource(R.drawable.image);
view.setAdjustViewBounds(true);
view.setLayoutParams(params);

Then you just need to add the view in your layout, in your case the idea would be to provide these views to your InfiniteGalleryAdapter but I did not find much information about this library.

This class is pretty easy to setup, just integrate it in your project and follow the example in the link.

EDIT:

The changes must be done in your InfiniteGalleryAdapter, I think you can give it a try by changing your getImageView function this way:

private GestureImageView getImageView() {   
    GestureImageView i = new GestureImageView(mContext); 

    return i; 
} 

You might also need to modify the try part of your adapter to add the layout parameters:

public View getView(int position, View convertView, ViewGroup parent) { 
GestureImageView i = getImageView(); 

int itemPos = (position % images.length); 
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);//addition

try { 
    i.setImageResource(images[itemPos]); 
    ((BitmapDrawable) i.getDrawable()).setAntiAlias(true);
    i.setLayoutParams(params); //addition
} 
catch (OutOfMemoryError e) { 
    Log.e("InfiniteGalleryAdapter", "Out of memory creating   imageview. Using empty view.", e); 
} 

For the XML, there is an example in the website where the library is from. In our case the GestureImageView is added programmatically, so it seems you just need to modify a little the XML file by adding the line xmlns:gesture-image="http://schemas.polites.com/android":

<?xml version="1.0" encoding="utf-8" ?> 
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:gesture-image="http://schemas.polites.com/android"
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   android:orientation="vertical" 
   android:background="#FFDAB9">
<com.test.demo.InfiniteGallery 
   android:id="@+id/galleryOne" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" /> 
</LinearLayout>

EDIT2:

Here is what you can try to block the scroll from "burning" the event, replace the original onTouch function from the GestureImageViewTouchListener class by the one below, I just added a check on the motion action:

@Override
    public boolean onTouch(View v, MotionEvent event) {

        if(event.getAction() != MotionEvent.ACTION_SCROLL){
            if(!inZoom) {

                if(!tapDetector.onTouchEvent(event)) {
                    if(event.getPointerCount() == 1 && flingDetector.onTouchEvent(event)) {
                        startFling();
                    }

                    if(event.getAction() == MotionEvent.ACTION_UP) {
                        handleUp();
                    }
                    else if(event.getAction() == MotionEvent.ACTION_DOWN) {
                        stopAnimations();

                        last.x = event.getX();
                        last.y = event.getY();

                        if(imageListener != null) {
                            imageListener.onTouch(last.x, last.y);
                        }

                        touched = true;
                    }
                    else if(event.getAction() == MotionEvent.ACTION_MOVE) {
                        if(event.getPointerCount() > 1) {
                            multiTouch = true;
                            if(initialDistance > 0) {

                                pinchVector.set(event);
                                pinchVector.calculateLength();

                                float distance = pinchVector.length;

                                if(initialDistance != distance) {

                                    float newScale = (distance / initialDistance) * lastScale;

                                    if(newScale <= maxScale) {
                                        scaleVector.length *= newScale;

                                        scaleVector.calculateEndPoint();

                                        scaleVector.length /= newScale;

                                        float newX = scaleVector.end.x;
                                        float newY = scaleVector.end.y;

                                        handleScale(newScale, newX, newY);
                                    }
                                }
                            }
                            else {
                                initialDistance = MathUtils.distance(event);

                                MathUtils.midpoint(event, midpoint);

                                scaleVector.setStart(midpoint);
                                scaleVector.setEnd(next);

                                scaleVector.calculateLength();
                                scaleVector.calculateAngle();

                                scaleVector.length /= lastScale;
                            }
                        }
                        else {
                            if(!touched) {
                                touched = true;
                                last.x = event.getX();
                                last.y = event.getY();
                                next.x = image.getImageX();
                                next.y = image.getImageY();
                            }
                            else if(!multiTouch) {
                                if(handleDrag(event.getX(), event.getY())) {
                                    image.redraw();
                                }
                            }
                        }
                    }
                }           
            }
            return true;
        } 
        else {
            return false;
        }
    }
Yoann Hercouet
  • 17,894
  • 5
  • 58
  • 85
  • i add this library to my project , but please can you explain with piece of code how to add it to my DayGallery class , thanks – Android Stack Aug 25 '13 at 17:25
  • does i need to add any thing to layout .xml – Android Stack Aug 26 '13 at 08:27
  • please check update main.xml , is it right or keep it as previous one , thanks – Android Stack Aug 26 '13 at 08:30
  • The problem is not the code I provided here, it seems you did not add the class `InfiniteGallery` in your project. Please fix that first if you want to go further. – Yoann Hercouet Aug 26 '13 at 09:57
  • my project already working and infinite gallery appear but i think some thing with layout – Android Stack Aug 26 '13 at 10:01
  • In some cases you put `com.tsn.dr.InfiniteGallery`, others `com.test.demo.InfiniteGallery`. You must set the path of the package where you installed the library. – Yoann Hercouet Aug 26 '13 at 10:12
  • its already com.test.demo.InfiniteGallery i adjust it with same result – Android Stack Aug 26 '13 at 10:14
  • I added an XML you can try. I followed the example here: https://github.com/jasonpolites/gesture-imageview/blob/master/example/src/com/polites/android/example/StandardImageProgrammatic.java – Yoann Hercouet Aug 26 '13 at 10:23
  • its work now but i lost the scrolling ability when my finger on image but it scroll normally with finger on text (my xml layout show image on upper two third of screen and text below it in lower one third ) do you get me,thanks – Android Stack Aug 27 '13 at 11:17
  • Try maybe adding `view.setAdjustViewBounds(true);` during the GestureImageView creation. I updated the answer. – Yoann Hercouet Aug 27 '13 at 11:26
  • That's probably due to the GestureImageView consuming the touch event - thus the Gallery never receives information about those touches. Not sure if it would help, but you could try editing the onTouch (View v, MotionEvent event) method in the GestureImageViewTouchListener class - make it return false instead of true. That way the OS would think that these notifications are not yet handled and send them to the parent view - in your case the Gallery. – Samuil Yanovski Aug 27 '13 at 11:39
  • @Yoann Hercouet I add view.setAdjustViewBounds(true); but still the same , please check UPDATE2 ,THANKS – Android Stack Aug 27 '13 at 11:54
  • I think Samuil might be right, the listener is already handling the `onTouch` event. You can maybe filter the motion action in the function, I will add in my answer what I mean by that, but I cannot guarantee it will work, you will have to run some tests. – Yoann Hercouet Aug 27 '13 at 13:11
  • @Yoann Hercouet it doesn't solve it , please if you have any other advice, thanks – Android Stack Aug 27 '13 at 15:10
  • َ@Yoann Hercouet my friend still i cant solve it , but you deserve the bounty , if reach to new thing please let me know , thanks . – Android Stack Aug 27 '13 at 15:59
  • Thanks :-). I guess you are very close now to the solution, I think you should create another question just to present this last problem with the scroll not working on the imageview. I am sure you will get good feedbacks to solve this last problem. – Yoann Hercouet Aug 27 '13 at 16:18
1

I'm using PhotoView in my projects. It is similar to the GestureImageView you're trying now.

Here is an example of PhotoView's usage:

<ProgressBar
    android:id="@+id/progress"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:indeterminate="true"
    android:visibility="gone" />

<RelativeLayout
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <uk.co.senab.photoview.PhotoView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/buttonsContainer"
        android:layout_centerInParent="true"
        android:layout_marginBottom="@dimen/offset_vertical"
        android:layout_marginLeft="@dimen/offset_horizontal"
        android:layout_marginRight="@dimen/offset_horizontal"
        android:layout_marginTop="@dimen/offset_vertical"
        tools:ignore="ContentDescription" />

    <LinearLayout
        android:id="@+id/buttonsContainer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" >

        <Button
            android:id="@+id/makeAvatarButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/make_avatar" />

        <Button
            android:id="@+id/deleteButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/delete" />
    </LinearLayout>
</RelativeLayout>

In your Java code, you could use it as if it is a simple ImageView. Here is my code (I've used the UrlImageViewHelper to load images asynchronously):

protected void processData() {
    View view = getView();
    if (null != view) {
        View makeAvatarButton = view.findViewById(R.id.makeAvatarButton);
        String link = JSONUtils.getLink(jsonData, "url");
        ImageView image = (ImageView) view.findViewById(R.id.image);
        UrlImageViewHelper.setUrlDrawable(image, link);

        boolean avatar = jsonData.optBoolean("avatar", false);
        if (avatar) {
            makeAvatarButton.setVisibility(View.GONE);
        } else {
            makeAvatarButton.setVisibility(View.VISIBLE);
        }
    }
}

You have an error in your code in the public View getView(int position, View convertView, ViewGroup parent) method. You create a GestureImageView at line 96, but you don't use it after that. Instead you are inflating the contents of gallery_items.xml and return them. I guess gallery_items.xml contains just an image with a text label, so here is an example which should work fine:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<uk.co.senab.photoview.PhotoView
    android:id="@+id/thumbnail"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="100dp"
    android:padding="5dp"
    android:scaleType="fitXY"
    tools:ignore="ContentDescription" >
</uk.co.senab.photoview.PhotoView>

<TextView
    android:id="@+id/label"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal" /></LinearLayout>

Then you could simplify your getView method to something like that:

public View getView(int position, View convertView, ViewGroup parent) {
    int itemPos = (position % images.length);
    View vi = convertView;
    ViewHolder holder;
    if (convertView == null) {
        vi = inflater.inflate(R.layout.gallery_items, null);
        holder = new ViewHolder();
        holder.text = (TextView) vi.findViewById(R.id.textView1);
        holder.image = (ImageView) vi.findViewById(R.id.image);
        vi.setTag(holder);
    } else {
        holder = (ViewHolder) vi.getTag();
    }
    holder.text.setText(name[itemPos]);

    final int stub_id = images[itemPos];
    holder.image.setImageResource(stub_id);

    return vi;
}

If you have troubles running the code, I could assemble a simple gallery project for you. :)

Samuil Yanovski
  • 2,837
  • 17
  • 19
0

I think your ClassNotFoundException is due to the android runtime trying to instantiate a com.tsn.dr.InfiniteGallery, which you specified in your activity:

<com.test.demo.InfiniteGallery 
android:id="@+id/galleryOne" 
android:layout_width="match_parent" 
android:layout_height="match_parent" /> 

But the InfiniteGallery class is private, and inside DayGallery:

public class DayGallery {
    ....
    @SuppressWarnings("deprecation")
    class InfiniteGallery extends Gallery {

Make it public and fix the package path in the .xml to match it's actual namespace. (sorry for the c# terminology, haven't done android work in a few months)

Zachary Yates
  • 12,966
  • 7
  • 55
  • 87
  • this different backage name by mistack , coz i have my main big project and smal project just to test the zoom effect , so no problem with package name its correct for each project, thanks , i will try change private to public – Android Stack Aug 26 '13 at 21:00