Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added setTo(...) to set scale and position and sync touch listener for #50 #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
example/bin
example/gen
example/local.properties
main/bin/
main/gen/
main/local.properties
1 change: 1 addition & 0 deletions example/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<activity android:name="StandardImageProgrammatic"></activity>
<activity android:name="StandardImageXML"></activity>
<activity android:name="StandardImageXMLWithStartSettings"></activity>
<activity android:name="ChangeImage"></activity>
<activity android:name="DoubleImage"></activity>
<activity android:name="ScaleTypeCenter"></activity>
<activity android:name="ScaleTypeCenterCrop"></activity>
Expand Down
92 changes: 92 additions & 0 deletions example/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Main" default="help">

<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />

<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:

source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.

For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml

Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.

This file is an integral part of the build system for your
application and should be checked into Version Control Systems.

-->
<property file="ant.properties" />

<!-- if sdk.dir was not set from one of the property file, then
get it from the ANDROID_HOME env var.
This must be done before we load project.properties since
the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>

<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.

This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).

This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />

<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>

<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />

<!-- Import the actual build file.

To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.

***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />

</project>
20 changes: 20 additions & 0 deletions example/proguard-project.txt
Original file line number Diff line number Diff line change
@@ -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 *;
#}
39 changes: 39 additions & 0 deletions example/src/com/polites/android/example/ChangeImage.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 2 additions & 0 deletions example/src/com/polites/android/example/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -61,6 +62,7 @@ public class Main extends ListActivity {
StandardImageProgrammaticWithOnClick.class,
StandardImageProgrammaticWithStartSettings.class,
StandardImageXMLWithStartSettings.class,
ChangeImage.class,
DoubleImage.class,
ScaleTypeCenter.class,
ScaleTypeCenterCrop.class,
Expand Down
10 changes: 0 additions & 10 deletions main/local.properties

This file was deleted.

20 changes: 20 additions & 0 deletions main/proguard-project.txt
Original file line number Diff line number Diff line change
@@ -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 *;
#}
18 changes: 16 additions & 2 deletions main/src/com/polites/android/GestureImageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -494,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;
}
Expand Down
15 changes: 13 additions & 2 deletions main/src/com/polites/android/GestureImageViewTouchListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ protected void handleUp() {

multiTouch = false;

//currentScale = image.getScale(); // fix by silentw for issue #27
initialDistance = 0;
lastScale = currentScale;

Expand Down Expand Up @@ -453,7 +454,7 @@ protected boolean handleDrag(float x, float y) {

return false;
}

public void reset() {
currentScale = startingScale;
next.x = centerX;
Expand All @@ -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;
Expand Down