From 0b26341d27977770d3ba46bcfee970b7976b7d5c Mon Sep 17 00:00:00 2001 From: Gerard Fowley Date: Tue, 9 Jul 2013 22:39:23 -0400 Subject: [PATCH 1/2] added fix from keppelcao for issue #21 (repeated setImageDrawable not working) --- .gitignore | 2 + example/AndroidManifest.xml | 1 + example/build.xml | 92 +++++++++++++++++++ example/proguard-project.txt | 20 ++++ example/project.properties | 2 +- .../polites/android/example/ChangeImage.java | 39 ++++++++ .../src/com/polites/android/example/Main.java | 2 + main/local.properties | 10 -- main/proguard-project.txt | 20 ++++ main/project.properties | 2 +- .../com/polites/android/GestureImageView.java | 8 +- 11 files changed, 184 insertions(+), 14 deletions(-) create mode 100644 example/build.xml create mode 100644 example/proguard-project.txt create mode 100644 example/src/com/polites/android/example/ChangeImage.java delete mode 100644 main/local.properties create mode 100644 main/proguard-project.txt diff --git a/.gitignore b/.gitignore index a374eb6..c9789bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ example/bin example/gen +example/local.properties main/bin/ main/gen/ +main/local.properties diff --git a/example/AndroidManifest.xml b/example/AndroidManifest.xml index 2cb5ec7..8002d09 100644 --- a/example/AndroidManifest.xml +++ b/example/AndroidManifest.xml @@ -25,6 +25,7 @@ + diff --git a/example/build.xml b/example/build.xml new file mode 100644 index 0000000..603b851 --- /dev/null +++ b/example/build.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example/proguard-project.txt b/example/proguard-project.txt new file mode 100644 index 0000000..f2fe155 --- /dev/null +++ b/example/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/example/project.properties b/example/project.properties index b68977e..2b8238b 100644 --- a/example/project.properties +++ b/example/project.properties @@ -8,5 +8,5 @@ # project structure. # Project target. -target=android-7 +target=android-17 android.library.reference.1=../main diff --git a/example/src/com/polites/android/example/ChangeImage.java b/example/src/com/polites/android/example/ChangeImage.java new file mode 100644 index 0000000..316e16b --- /dev/null +++ b/example/src/com/polites/android/example/ChangeImage.java @@ -0,0 +1,39 @@ +package com.polites.android.example; + +import android.app.Activity; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.view.ViewGroup; +import android.widget.LinearLayout.LayoutParams; +import com.polites.android.GestureImageView; + +public class ChangeImage extends Activity { + + private GestureImageView view; + private static final int IMAGE_LOAD = 10001; + private final Handler handler = new Handler() { + + @Override + public void handleMessage(Message msg) { + if(msg.what == IMAGE_LOAD) { + view.setImageResource(R.drawable.image); + view.redraw(); + } + super.handleMessage(msg); + } + }; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.empty); + LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); + view = new GestureImageView(this); + view.setImageResource(R.drawable.square); + view.setLayoutParams(params); + ViewGroup layout = (ViewGroup) findViewById(R.id.layout); + layout.addView(view); + handler.sendEmptyMessageDelayed(IMAGE_LOAD, 5000); + } +} \ No newline at end of file diff --git a/example/src/com/polites/android/example/Main.java b/example/src/com/polites/android/example/Main.java index 3692c6e..33f8d2f 100644 --- a/example/src/com/polites/android/example/Main.java +++ b/example/src/com/polites/android/example/Main.java @@ -40,6 +40,7 @@ public class Main extends ListActivity { "Single Image Programmatic with onClick event", "Single Image Programmatic with start scale & position", "Single Image XML Layout with start scale & position", + "Change Image (With delayed load)", "Double Image (With delayed load)", "ScaleType CENTER Large", "ScaleType CENTER_CROP Large", @@ -61,6 +62,7 @@ public class Main extends ListActivity { StandardImageProgrammaticWithOnClick.class, StandardImageProgrammaticWithStartSettings.class, StandardImageXMLWithStartSettings.class, + ChangeImage.class, DoubleImage.class, ScaleTypeCenter.class, ScaleTypeCenterCrop.class, diff --git a/main/local.properties b/main/local.properties deleted file mode 100644 index 13de829..0000000 --- a/main/local.properties +++ /dev/null @@ -1,10 +0,0 @@ -# This file is automatically generated by Android Tools. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must *NOT* be checked in Version Control Systems, -# as it contains information specific to your local configuration. - -# location of the SDK. This is only used by Ant -# For customization when using a Version Control System, please read the -# header note. -sdk.dir=/android diff --git a/main/proguard-project.txt b/main/proguard-project.txt new file mode 100644 index 0000000..f2fe155 --- /dev/null +++ b/main/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/main/project.properties b/main/project.properties index 337e8f3..e61077f 100644 --- a/main/project.properties +++ b/main/project.properties @@ -8,5 +8,5 @@ # project structure. # Project target. -target=android-7 +target=android-17 android.library=true diff --git a/main/src/com/polites/android/GestureImageView.java b/main/src/com/polites/android/GestureImageView.java index b0d72c6..dda551c 100644 --- a/main/src/com/polites/android/GestureImageView.java +++ b/main/src/com/polites/android/GestureImageView.java @@ -373,11 +373,15 @@ protected void initImage() { if(colorFilter != null) { this.drawable.setColorFilter(colorFilter); } + // Keppel.Cao + layout = false; + startingScale = -1.0f; } - if(!layout) { requestLayout(); - redraw(); + // Keppel.Cao + // redraw(); + reset(); } } From 80a53744d6ec38eeae8969beab321edadd8ef29b Mon Sep 17 00:00:00 2001 From: Gerard Fowley Date: Sat, 13 Jul 2013 13:00:04 -0400 Subject: [PATCH 2/2] added setTo(...) to set imageview scale and position and sync touch listener --- example/project.properties | 2 +- main/project.properties | 2 +- .../src/com/polites/android/GestureImageView.java | 10 ++++++++++ .../android/GestureImageViewTouchListener.java | 15 +++++++++++++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/example/project.properties b/example/project.properties index 2b8238b..b68977e 100644 --- a/example/project.properties +++ b/example/project.properties @@ -8,5 +8,5 @@ # project structure. # Project target. -target=android-17 +target=android-7 android.library.reference.1=../main diff --git a/main/project.properties b/main/project.properties index e61077f..337e8f3 100644 --- a/main/project.properties +++ b/main/project.properties @@ -8,5 +8,5 @@ # project structure. # Project target. -target=android-17 +target=android-7 android.library=true diff --git a/main/src/com/polites/android/GestureImageView.java b/main/src/com/polites/android/GestureImageView.java index dda551c..f964ba0 100644 --- a/main/src/com/polites/android/GestureImageView.java +++ b/main/src/com/polites/android/GestureImageView.java @@ -498,6 +498,16 @@ public void reset() { redraw(); } + public void setTo(float newX, float newY, float newScale) { + x = newX; + y = newY; + scaleAdjust = newScale; + if (gestureImageViewTouchListener != null) { + gestureImageViewTouchListener.setTo(newX, newY, newScale); + } + redraw(); + } + public void setRotation(float rotation) { this.rotation = rotation; } diff --git a/main/src/com/polites/android/GestureImageViewTouchListener.java b/main/src/com/polites/android/GestureImageViewTouchListener.java index 42e6cda..de8481c 100644 --- a/main/src/com/polites/android/GestureImageViewTouchListener.java +++ b/main/src/com/polites/android/GestureImageViewTouchListener.java @@ -359,6 +359,7 @@ protected void handleUp() { multiTouch = false; + //currentScale = image.getScale(); // fix by silentw for issue #27 initialDistance = 0; lastScale = currentScale; @@ -453,7 +454,7 @@ protected boolean handleDrag(float x, float y) { return false; } - + public void reset() { currentScale = startingScale; next.x = centerX; @@ -463,7 +464,17 @@ public void reset() { image.setPosition(next.x, next.y); image.redraw(); } - + + public void setTo(float newX, float newY, float newScale) { + currentScale = newScale; + lastScale = newScale; + next.x = newX; + next.y = newY; + calculateBoundaries(); + image.setScale(currentScale); + image.setPosition(next.x, next.y); + image.redraw(); + } public float getMaxScale() { return maxScale;