├── .classpath
├── .gitignore
├── LICENSE
├── README.md
├── android
├── .settings
│ ├── org.eclipse.jdt.apt.core.prefs
│ └── org.eclipse.jdt.core.prefs
├── LICENSE
├── assets
│ └── README
├── build.gradle
├── build.xml
├── dist
│ ├── org.iotashan.TiTouchImageView-android-4.0.0.zip
│ └── org.iotashan.TiTouchImageView-android-4.0.1.zip
├── documentation
│ └── index.md
├── example
│ ├── app.js
│ ├── demo.jpg
│ └── demo2.jpg
├── lib
│ └── README
├── manifest
├── manifest.bak
├── platform
│ └── README
├── src
│ └── org
│ │ ├── .DS_Store
│ │ └── iotashan
│ │ ├── .DS_Store
│ │ └── TiTouchImageView
│ │ ├── TiTouchImageViewModule.java
│ │ └── ViewProxy.java
└── timodule.xml
├── assets
└── README
├── dist
├── org.iotashan.TiTouchImageView-android-2.0.0.zip
├── org.iotashan.titouchimageview-android-0.1.0.zip
├── org.iotashan.titouchimageview-android-1.0.0.zip
├── org.iotashan.titouchimageview-android-1.0.1.zip
├── org.iotashan.titouchimageview-android-1.0.2.zip
└── org.iotashan.titouchimageview-android-1.1.2.zip
├── documentation
└── index.md
└── example
├── app.js
├── demo.jpg
└── demo2.jpg
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | android/bin
2 | android/build
3 | titouchimageview.jar
4 | build.properties
5 | .project
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 iotashan
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TiTouchImageView Module
2 |
3 | Titanium native module wrapper for TouchImageView: https://github.com/MikeOrtiz/TouchImageView
4 |
5 | Do you like pinching and zooming on iOS? Wish it just worked on Android too? Here you go!
6 |
7 | ## Get it [](http://gitt.io/component/org.iotashan.TiTouchImageView)
8 | Download the latest distribution ZIP-file and consult the [Titanium Documentation](http://docs.appcelerator.com/titanium/latest/#!/guide/Using_a_Module) on how install it, or simply use the [gitTio CLI](http://gitt.io/cli):
9 |
10 | ```bash
11 | gittio install org.iotashan.TiTouchImageView
12 | ```
13 |
14 | ## Referencing the module in your Ti mobile application
15 |
16 | Simply add the following lines to your `tiapp.xml` file:
17 |
18 | ```xml
19 |
20 | org.iotashan.titouchimageview
21 |
22 | ```
23 |
24 | To use your module in code, you will need to require it.
25 |
26 | ```javascript
27 | var TiTouchImageView = require('org.iotashan.TiTouchImageView');
28 | var myView = TiTouchImageView.createView();
29 | ```
30 |
31 | ## API Properties
32 |
33 | ### image
34 |
35 | Accepts a string path to a local file, remote files or a TiBlob image object.
36 |
37 | ### maxZoom
38 |
39 | Maximum zoom value, as a decimal. "5.5" means you can zoom in 550%
40 |
41 | ### minZoom
42 |
43 | Minimum zoom value, as a decimal. "0.5" means you can zoom out to 50%
44 |
45 | ### zoom
46 |
47 | Zoom value for the view, as a decimal. Want to zoom to 300%? Set the value to 3.
48 |
49 | ## API Methods
50 |
51 | ### createView(props)
52 |
53 | Accepts a dictonary of properties. TiTouchImageView extends TiUIView, so you can set other properties like top/left, backgroundColor, etc. Returns the view.
54 |
55 | ### resetZoom()
56 |
57 | Resets the zoom to the default value for the view.
58 |
59 | ### scrollTo(x, y)
60 |
61 | Scrolls the view to the point specified as a float.
62 |
63 | ### getCurrentZoom()
64 |
65 | Returns the current zoom level as a float.
66 |
67 | ### getScrollPosition()
68 |
69 | Returns the current scroll position as point co-ordinates (x, y) as a float.
70 |
--------------------------------------------------------------------------------
/android/.settings/org.eclipse.jdt.apt.core.prefs:
--------------------------------------------------------------------------------
1 | #Thu Sep 02 15:18:34 CDT 2010
2 | eclipse.preferences.version=1
3 | org.eclipse.jdt.apt.aptEnabled=true
4 | org.eclipse.jdt.apt.genSrcDir=.apt_generated
5 | org.eclipse.jdt.apt.reconcileEnabled=true
6 |
7 | org.eclipse.jdt.apt.processorOptions/kroll.jsonFile=TiTouchImageView.json
8 |
--------------------------------------------------------------------------------
/android/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.6
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.processAnnotations=enabled
12 | org.eclipse.jdt.core.compiler.source=1.6
13 |
--------------------------------------------------------------------------------
/android/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 iotashan
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/android/assets/README:
--------------------------------------------------------------------------------
1 | Place your assets like PNG files in this directory and they will be packaged
2 | with your module.
3 |
4 | All JavaScript files in the assets directory are IGNORED except if you create a
5 | file named "org.iotashan.TiTouchImageView.js" in this directory in which case it will be
6 | wrapped by native code, compiled, and used as your module. This allows you to
7 | run pure JavaScript modules that are pre-compiled.
8 |
9 | Note: Mobile Web does not support this assets directory.
10 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | repositories {
2 | maven { url 'https://jitpack.io' }
3 | }
4 |
5 | dependencies {
6 | implementation 'com.github.MikeOrtiz:TouchImageView:3.7.1'
7 | }
8 |
--------------------------------------------------------------------------------
/android/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Ant build script for Titanium Android module TiTouchImageView
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/android/dist/org.iotashan.TiTouchImageView-android-4.0.0.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iotashan/TiTouchImageView/22431ca97aa4f037168598cee1222da970b4fc3b/android/dist/org.iotashan.TiTouchImageView-android-4.0.0.zip
--------------------------------------------------------------------------------
/android/dist/org.iotashan.TiTouchImageView-android-4.0.1.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iotashan/TiTouchImageView/22431ca97aa4f037168598cee1222da970b4fc3b/android/dist/org.iotashan.TiTouchImageView-android-4.0.1.zip
--------------------------------------------------------------------------------
/android/documentation/index.md:
--------------------------------------------------------------------------------
1 | # TiTouchImageView Module
2 | ================
3 |
4 | Titanium native module wrapper for TouchImageView: https://github.com/MikeOrtiz/TouchImageView
5 |
6 | Do you like pinching and zooming on iOS? Wish it just worked on Android too? Here you go!
7 |
8 | ## Get it [](http://gitt.io/component/org.iotashan.TiTouchImageView)
9 | Download the latest distribution ZIP-file and consult the [Titanium Documentation](http://docs.appcelerator.com/titanium/latest/#!/guide/Using_a_Module) on how install it, or simply use the [gitTio CLI](http://gitt.io/cli):
10 |
11 | `$ gittio install org.iotashan.TiTouchImageView`
12 |
13 | ## Referencing the module in your Ti mobile application
14 |
15 | Simply add the following lines to your `tiapp.xml` file:
16 |
17 |
18 | org.iotashan.titouchimageview
19 |
20 |
21 | To use your module in code, you will need to require it.
22 |
23 | var TiTouchImageView = require('org.iotashan.TiTouchImageView');
24 | var myView = TiTouchImageView.createView();
25 |
26 | ## API Properties
27 |
28 | ### image
29 |
30 | Accepts a string path to a local file, or a TiBlob image object.
31 |
32 | ### maxZoom
33 |
34 | Maximum zoom value, as a decimal. "5.5" means you can zoom in 550%
35 |
36 | ### minZoom
37 |
38 | Minimum zoom value, as a decimal. "0.5" means you can zoom out to 50%
39 |
40 | ### zoom
41 |
42 | Zoom value for the view, as a decimal. Want to zoom to 300%? Set the value to 3.
43 |
44 | ## API Methods
45 |
46 | ### createView(props)
47 |
48 | Accepts a dictonary of properties. TiTouchImageView extends TiUIView, so you can set other properties like top/left, backgroundColor, etc. Returns the view.
49 |
50 | ### resetZoom()
51 |
52 | Resets the zoom to the default value for the view.
53 |
54 | ### scrollTo(x,y)
55 |
56 | Scrolls the view to the point specified.
57 |
58 | ### getCurrentZoom()
59 |
60 | Returns the current zoom level as a float.
61 |
62 | ### getScrollPosition()
63 |
64 | Returns the current scroll position as point co-ordinates (x,y)
65 |
66 | ### recycleBitmap ()
67 |
68 | Call this before you remove the view to prevent memory leaks (assuming you aren't going to reuse the view)
69 |
70 |
--------------------------------------------------------------------------------
/android/example/app.js:
--------------------------------------------------------------------------------
1 | // This is a test harness for your module
2 | // You should do something interesting in this harness
3 | // to test out the module and to provide instructions
4 | // to users on how to use it by example.
5 |
6 |
7 | // open a single window
8 | var win = Ti.UI.createWindow({
9 | backgroundColor:'white'
10 | });
11 |
12 | var TiTouchImageView = require('org.iotashan.TiTouchImageView');
13 | Ti.API.info("module is => " + TiTouchImageView);
14 |
15 | var imageView = TiTouchImageView.createView({
16 | backgroundColor:'#0f0',
17 | top:0,
18 | left:0,
19 | right:0,
20 | bottom:0,
21 | image:'demo2.jpg',
22 | zoom:0.5,
23 | maxZoom:5,
24 | minZoom:0.25,
25 | });
26 |
27 | win.add(imageView);
28 |
29 | var btn = Ti.UI.createButton({
30 | top:10,
31 | color:'#000',
32 | backgroundColor:'#fff',
33 | title:'Demo Methods',
34 | });
35 | btn.addEventListener('click',function(){
36 | imageView.image = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory,'demo.jpg').read();
37 | imageView.zoom = 5;
38 | imageView.scrollTo(500,500);
39 | });
40 | win.add(btn);
41 |
42 | var btn2 = Ti.UI.createButton({
43 | bottom:10,
44 | color:'#000',
45 | backgroundColor:'#fff',
46 | title:'Reset',
47 | });
48 | btn2.addEventListener('click',function(){
49 | imageView.image = 'demo2.jpg';
50 | imageView.resetZoom();
51 | });
52 | win.add(btn2);
53 |
54 | win.open();
55 |
--------------------------------------------------------------------------------
/android/example/demo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iotashan/TiTouchImageView/22431ca97aa4f037168598cee1222da970b4fc3b/android/example/demo.jpg
--------------------------------------------------------------------------------
/android/example/demo2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iotashan/TiTouchImageView/22431ca97aa4f037168598cee1222da970b4fc3b/android/example/demo2.jpg
--------------------------------------------------------------------------------
/android/lib/README:
--------------------------------------------------------------------------------
1 | You can place any .jar dependencies in this directory and they will be included
2 | when your module is being compiled.
--------------------------------------------------------------------------------
/android/manifest:
--------------------------------------------------------------------------------
1 | #
2 | # this is your module manifest and used by Titanium
3 | # during compilation, packaging, distribution, etc.
4 | #
5 | version: 4.0.1
6 | apiversion: 4
7 | architectures: arm64-v8a armeabi-v7a x86 x86_64
8 | description: TiTouchImageView
9 | author: Shannon Hicks
10 | license: MIT
11 | copyright: Copyright (c) 2014 by Shannon Hicks
12 |
13 | # these should not be edited
14 | name: titouchimageview
15 | moduleid: org.iotashan.TiTouchImageView
16 | guid: 773f5121-35cb-47cc-9081-6d0f84bf1606
17 | platform: android
18 | minsdk: 9.0.0
19 |
--------------------------------------------------------------------------------
/android/manifest.bak:
--------------------------------------------------------------------------------
1 | #
2 | # this is your module manifest and used by Titanium
3 | # during compilation, packaging, distribution, etc.
4 | #
5 | version: 2.0.2
6 | apiversion: 4
7 | description: TiTouchImageView
8 | author: Shannon Hicks
9 | license: MIT
10 | copyright: Copyright (c) 2014 by Shannon Hicks
11 |
12 | # these should not be edited
13 | name: titouchimageview
14 | moduleid: org.iotashan.TiTouchImageView
15 | guid: 773f5121-35cb-47cc-9081-6d0f84bf1606
16 | platform: android
17 | minsdk: 7.0.0.GA
18 | architectures: arm64-v8a armeabi-v7a x86
19 |
--------------------------------------------------------------------------------
/android/platform/README:
--------------------------------------------------------------------------------
1 | You can place platform-specific files here in sub-folders named "android" and/or "iphone", just as you can with normal Titanium Mobile SDK projects. Any folders and files you place here will be merged with the platform-specific files in a Titanium Mobile project that uses this module.
2 |
3 | When a Titanium Mobile project that uses this module is built, the files from this platform/ folder will be treated the same as files (if any) from the Titanium Mobile project's platform/ folder.
4 |
--------------------------------------------------------------------------------
/android/src/org/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iotashan/TiTouchImageView/22431ca97aa4f037168598cee1222da970b4fc3b/android/src/org/.DS_Store
--------------------------------------------------------------------------------
/android/src/org/iotashan/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iotashan/TiTouchImageView/22431ca97aa4f037168598cee1222da970b4fc3b/android/src/org/iotashan/.DS_Store
--------------------------------------------------------------------------------
/android/src/org/iotashan/TiTouchImageView/TiTouchImageViewModule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file was auto-generated by the Titanium Module SDK helper for Android
3 | * Appcelerator Titanium Mobile
4 | * Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
5 | * Licensed under the terms of the Apache Public License
6 | * Please see the LICENSE included with this distribution for details.
7 | *
8 | */
9 | package org.iotashan.TiTouchImageView;
10 |
11 | import org.appcelerator.kroll.KrollModule;
12 | import org.appcelerator.kroll.annotations.Kroll;
13 |
14 | import org.appcelerator.titanium.TiApplication;
15 | import org.appcelerator.kroll.common.TiConfig;
16 |
17 | @Kroll.module(name="TiTouchImageView", id="org.iotashan.TiTouchImageView")
18 | public class TiTouchImageViewModule extends KrollModule
19 | {
20 |
21 | // Standard Debugging variables
22 | private static final String LCAT = "TiTouchImageViewModule";
23 | private static final boolean DBG = TiConfig.LOGD;
24 |
25 | // You can define constants with @Kroll.constant, for example:
26 | // @Kroll.constant public static final String EXTERNAL_NAME = value;
27 |
28 | public TiTouchImageViewModule()
29 | {
30 | super();
31 | }
32 |
33 | @Kroll.onAppCreate
34 | public static void onAppCreate(TiApplication app)
35 | {
36 | }
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/android/src/org/iotashan/TiTouchImageView/ViewProxy.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file was auto-generated by the Titanium Module SDK helper for Android
3 | * Appcelerator Titanium Mobile
4 | * Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
5 | * Licensed under the terms of the Apache Public License
6 | * Please see the LICENSE included with this distribution for details.
7 | *
8 | */
9 | package org.iotashan.TiTouchImageView;
10 |
11 | import java.io.IOException;
12 | import java.io.InputStream;
13 | import java.util.HashMap;
14 |
15 | import org.appcelerator.kroll.KrollDict;
16 | import org.appcelerator.kroll.KrollProxy;
17 | import org.appcelerator.kroll.annotations.Kroll;
18 | import org.appcelerator.kroll.common.AsyncResult;
19 | import org.appcelerator.kroll.common.Log;
20 | import org.appcelerator.kroll.common.TiConfig;
21 | import org.appcelerator.kroll.common.TiMessenger;
22 | import org.appcelerator.titanium.TiApplication;
23 | import org.appcelerator.titanium.TiBlob;
24 | import org.appcelerator.titanium.util.TiConvert;
25 | import org.appcelerator.titanium.util.TiUIHelper;
26 | import org.appcelerator.titanium.io.TiBaseFile;
27 | import org.appcelerator.titanium.io.TiFileFactory;
28 | import org.appcelerator.titanium.proxy.TiViewProxy;
29 | import org.appcelerator.titanium.view.TiDrawableReference;
30 | import org.appcelerator.titanium.view.TiUIView;
31 |
32 | import com.ortiz.touchview.TouchImageView;
33 |
34 | import android.app.Activity;
35 | import android.graphics.Bitmap;
36 | import android.graphics.BitmapFactory;
37 | import android.graphics.drawable.BitmapDrawable;
38 | import android.graphics.PointF;
39 | import android.os.AsyncTask;
40 | import android.os.Message;
41 | import android.widget.ImageView;
42 |
43 |
44 | @Kroll.proxy(creatableInModule=TiTouchImageViewModule.class, propertyAccessors = { "zoom", "image", "maxZoom", "minZoom" })
45 | public class ViewProxy extends TiViewProxy
46 | {
47 | // Standard Debugging variables
48 | private static final String LCAT = "TiTouchImageView";
49 | private static final boolean DBG = TiConfig.LOGD;
50 |
51 | private static final int MSG_FIRST_ID = TiViewProxy.MSG_LAST_ID + 1;
52 | public static final int MSG_RESET_ZOOM = MSG_FIRST_ID + 101;
53 | public static final int MSG_SCROLL_TO = MSG_FIRST_ID + 102;
54 |
55 |
56 | private class DownloadImageTask extends AsyncTask {
57 | ImageView bmImage;
58 |
59 | public DownloadImageTask(ImageView bmImage) {
60 | this.bmImage = bmImage;
61 | }
62 |
63 | protected Bitmap doInBackground(String... urls) {
64 | String urldisplay = urls[0];
65 | Bitmap mIcon11 = null;
66 | String error = "TiTouchImageView: bitmap is null for url: " + urldisplay;
67 | InputStream inputStream = null;
68 | try {
69 | inputStream = new java.net.URL(urldisplay).openStream();
70 | mIcon11 = BitmapFactory.decodeStream(inputStream);
71 | } catch (Exception e) {
72 | error += ", error: " + e.getMessage();
73 | e.printStackTrace();
74 | }
75 |
76 | if (inputStream != null) {
77 | try {
78 | inputStream.close();
79 | } catch (IOException e) {
80 | error += ", could not close stream: " + e.getMessage();
81 | }
82 | }
83 |
84 | if (mIcon11 == null) {
85 | throw new RuntimeException(error);
86 | }
87 |
88 | return mIcon11;
89 | }
90 |
91 | protected void onPostExecute(Bitmap result) {
92 | bmImage.setImageBitmap(result);
93 | }
94 | }
95 |
96 | private class TiTouchImageView extends TiUIView
97 | {
98 | TouchImageView tiv;
99 |
100 | public TiTouchImageView(final TiViewProxy proxy) {
101 | super(proxy);
102 |
103 | tiv = new TouchImageView(proxy.getActivity());
104 |
105 | getLayoutParams().autoFillsHeight = true;
106 | getLayoutParams().autoFillsWidth = true;
107 |
108 | setNativeView(tiv);
109 | }
110 |
111 | @Override
112 | public void processProperties(KrollDict props)
113 | {
114 | super.processProperties(props);
115 |
116 | if (props.containsKey("zoom")) {
117 | tiv.setZoom(TiConvert.toFloat(proxy.getProperty("zoom")));
118 | }
119 | if (props.containsKey("image")) {
120 | handleImage(proxy.getProperty("image"));
121 | }
122 | if (props.containsKey("maxZoom")) {
123 | tiv.setMaxZoom(TiConvert.toFloat(proxy.getProperty("maxZoom")));
124 | }
125 | if (props.containsKey("minZoom")) {
126 | tiv.setMinZoom(TiConvert.toFloat(proxy.getProperty("minZoom")));
127 | }
128 | }
129 |
130 | @Override
131 | public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy)
132 | {
133 | if (key.equals("zoom")) {
134 | tiv.setZoom(TiConvert.toFloat(newValue));
135 | }
136 | if (key.equals("image")) {
137 | handleImage(newValue);
138 | }
139 | if (key.equals("maxZoom")) {
140 | tiv.setMaxZoom(TiConvert.toFloat(newValue));
141 | }
142 | if (key.equals("minZoom")) {
143 | tiv.setMinZoom(TiConvert.toFloat(newValue));
144 | }
145 | }
146 |
147 | public void setScrollPosition(float x, float y)
148 | {
149 | tiv.setScrollPosition(x,y);
150 | }
151 |
152 | public void resetZoom()
153 | {
154 | tiv.resetZoom();
155 | }
156 |
157 | public float getCurrentZoom()
158 | {
159 | return tiv.getCurrentZoom();
160 | }
161 |
162 | public PointF getScrollPosition()
163 | {
164 | return tiv.getScrollPosition();
165 | }
166 |
167 | private Bitmap loadImageFromApplication(String imageName) {
168 | Bitmap result = null;
169 | try {
170 | // Load the image from the application assets
171 | String url = getPathToApplicationAsset(imageName);
172 | TiBaseFile file = TiFileFactory.createTitaniumFile(new String[] { url }, false);
173 | result = TiUIHelper.createBitmap(file.getInputStream());
174 | } catch (IOException e) {
175 | Log.e(LCAT, " TiTouchImageView only supports local image files");
176 | }
177 | return result;
178 | }
179 |
180 | private void handleImage(Object val)
181 | {
182 |
183 | if (val instanceof TiBlob) {
184 | // this is a blob, parse accordingly
185 | TiBlob imgBlob = (TiBlob)val;
186 | TiDrawableReference ref = TiDrawableReference.fromBlob(proxy.getActivity(), imgBlob);
187 | Bitmap bm = ref.getBitmap();
188 | tiv.setImageBitmap(bm);
189 | if (bm == null) {
190 | String path = imgBlob.getNativePath();
191 | if (path == null) {
192 | path = "";
193 | }
194 | throw new RuntimeException("TiTouchImageView: bitmap is null for TiBlob: " + path);
195 | }
196 | } else {
197 | String imgValue = (String)val;
198 |
199 | if (imgValue.indexOf("http://") > -1 || imgValue.indexOf("https://") > -1) {
200 | new DownloadImageTask(tiv).execute(imgValue);
201 | } else{
202 | Bitmap bm = loadImageFromApplication(imgValue);
203 | tiv.setImageBitmap(bm);
204 | if (bm == null) {
205 | throw new RuntimeException("TiTouchImageView: bitmap is null for String: " + imgValue);
206 | }
207 | }
208 | }
209 | }
210 |
211 | private String getPathToApplicationAsset(String assetName) {
212 | // The url for an application asset can be created by resolving the specified
213 | // path with the proxy context. This locates a resource relative to the
214 | // application resources folder
215 | String result = resolveUrl(null, assetName);
216 |
217 | return result;
218 | }
219 |
220 | public void recycleBitmap ()
221 | {
222 | ((BitmapDrawable)tiv.getDrawable()).getBitmap().recycle();
223 | }
224 | }
225 |
226 |
227 | // Constructor
228 | public ViewProxy()
229 | {
230 | super();
231 | }
232 |
233 | @Override
234 | public TiUIView createView(Activity activity)
235 | {
236 | return new TiTouchImageView(this);
237 | }
238 |
239 | protected TiTouchImageView getView()
240 | {
241 | return (TiTouchImageView) getOrCreateView();
242 | }
243 |
244 | public boolean handleMessage(Message msg)
245 | {
246 | boolean handled = false;
247 |
248 | switch(msg.what) {
249 | case MSG_RESET_ZOOM:
250 | getView().resetZoom();
251 | handled = true;
252 | break;
253 | case MSG_SCROLL_TO:
254 | handleScrollTo(msg.arg1, msg.arg2);
255 | AsyncResult result = (AsyncResult) msg.obj;
256 | result.setResult(null); // signal scrolled
257 | handled = true;
258 | break;
259 | default:
260 | handled = super.handleMessage(msg);
261 | }
262 |
263 | return handled;
264 | }
265 |
266 | // Methods
267 | @Kroll.method
268 | public void resetZoom()
269 | {
270 | getMainHandler().removeMessages(MSG_RESET_ZOOM);
271 | getMainHandler().sendEmptyMessage(MSG_RESET_ZOOM);
272 | }
273 |
274 | @Kroll.method
275 | public void scrollTo(float x, float y) {
276 | if (!TiApplication.isUIThread()) {
277 | TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SCROLL_TO, (int)x, (int)y), getActivity());
278 | } else {
279 | handleScrollTo(x,y);
280 | }
281 | }
282 |
283 | private void handleScrollTo(float x, float y) {
284 | getView().setScrollPosition(x,y);
285 | }
286 |
287 | @Kroll.method
288 | public float getCurrentZoom() {
289 | return getView().getCurrentZoom();
290 | }
291 |
292 | @Kroll.method
293 | public KrollDict getScrollPosition() {
294 | PointF point = getView().getScrollPosition();
295 | KrollDict result = new KrollDict();
296 | result.put("x", point.x);
297 | result.put("y", point.y);
298 | return result;
299 | }
300 |
301 | @Kroll.method
302 | public void recycleBitmap() {
303 | getView().recycleBitmap();
304 | }
305 | }
306 |
--------------------------------------------------------------------------------
/android/timodule.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/assets/README:
--------------------------------------------------------------------------------
1 | Place your assets like PNG files in this directory and they will be packaged
2 | with your module.
3 |
4 | All JavaScript files in the assets directory are IGNORED except if you create a
5 | file named "org.iotashan.TiTouchImageView.js" in this directory in which case it will be
6 | wrapped by native code, compiled, and used as your module. This allows you to
7 | run pure JavaScript modules that are pre-compiled.
8 |
9 | Note: Mobile Web does not support this assets directory.
10 |
--------------------------------------------------------------------------------
/dist/org.iotashan.TiTouchImageView-android-2.0.0.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iotashan/TiTouchImageView/22431ca97aa4f037168598cee1222da970b4fc3b/dist/org.iotashan.TiTouchImageView-android-2.0.0.zip
--------------------------------------------------------------------------------
/dist/org.iotashan.titouchimageview-android-0.1.0.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iotashan/TiTouchImageView/22431ca97aa4f037168598cee1222da970b4fc3b/dist/org.iotashan.titouchimageview-android-0.1.0.zip
--------------------------------------------------------------------------------
/dist/org.iotashan.titouchimageview-android-1.0.0.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iotashan/TiTouchImageView/22431ca97aa4f037168598cee1222da970b4fc3b/dist/org.iotashan.titouchimageview-android-1.0.0.zip
--------------------------------------------------------------------------------
/dist/org.iotashan.titouchimageview-android-1.0.1.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iotashan/TiTouchImageView/22431ca97aa4f037168598cee1222da970b4fc3b/dist/org.iotashan.titouchimageview-android-1.0.1.zip
--------------------------------------------------------------------------------
/dist/org.iotashan.titouchimageview-android-1.0.2.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iotashan/TiTouchImageView/22431ca97aa4f037168598cee1222da970b4fc3b/dist/org.iotashan.titouchimageview-android-1.0.2.zip
--------------------------------------------------------------------------------
/dist/org.iotashan.titouchimageview-android-1.1.2.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iotashan/TiTouchImageView/22431ca97aa4f037168598cee1222da970b4fc3b/dist/org.iotashan.titouchimageview-android-1.1.2.zip
--------------------------------------------------------------------------------
/documentation/index.md:
--------------------------------------------------------------------------------
1 | # TiTouchImageView Module
2 |
3 | ## Description
4 |
5 | TODO: Enter your module description here
6 |
7 | ## Accessing the TiTouchImageView Module
8 |
9 | To access this module from JavaScript, you would do the following:
10 |
11 | var titouchimageview = require("org.iotashan.TiTouchImageView");
12 |
13 | The titouchimageview variable is a reference to the Module object.
14 |
15 | ## Reference
16 |
17 | TODO: If your module has an API, you should document
18 | the reference here.
19 |
20 | ### titouchimageview.function
21 |
22 | TODO: This is an example of a module function.
23 |
24 | ### titouchimageview.property
25 |
26 | TODO: This is an example of a module property.
27 |
28 | ## Usage
29 |
30 | TODO: Enter your usage example here
31 |
32 | ## Author
33 |
34 | TODO: Enter your author name, email and other contact
35 | details you want to share here.
36 |
37 | ## License
38 |
39 | TODO: Enter your license/legal information here.
40 |
--------------------------------------------------------------------------------
/example/app.js:
--------------------------------------------------------------------------------
1 | // This is a test harness for your module
2 | // You should do something interesting in this harness
3 | // to test out the module and to provide instructions
4 | // to users on how to use it by example.
5 |
6 |
7 | // open a single window
8 | var win = Ti.UI.createWindow({
9 | backgroundColor:'white'
10 | });
11 |
12 | var TiTouchImageView = require('org.iotashan.TiTouchImageView');
13 | Ti.API.info("module is => " + TiTouchImageView);
14 |
15 | var imageView = TiTouchImageView.createView({
16 | backgroundColor:'#0f0',
17 | top:0,
18 | left:0,
19 | right:0,
20 | bottom:0,
21 | image:'demo2.jpg',
22 | zoom:0.5,
23 | maxZoom:5,
24 | minZoom:0.25,
25 | });
26 |
27 | win.add(imageView);
28 |
29 | var btn = Ti.UI.createButton({
30 | top:10,
31 | color:'#000',
32 | backgroundColor:'#fff',
33 | title:'Demo Methods',
34 | });
35 | btn.addEventListener('click',function(){
36 | imageView.image = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory,'demo.jpg').read();
37 | imageView.zoom = 5;
38 | imageView.scrollTo(500,500);
39 | });
40 | win.add(btn);
41 |
42 | var btn2 = Ti.UI.createButton({
43 | bottom:10,
44 | color:'#000',
45 | backgroundColor:'#fff',
46 | title:'Reset',
47 | });
48 | btn2.addEventListener('click',function(){
49 | imageView.image = 'demo2.jpg';
50 | imageView.resetZoom();
51 | });
52 | win.add(btn2);
53 |
54 | win.open();
55 |
--------------------------------------------------------------------------------
/example/demo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iotashan/TiTouchImageView/22431ca97aa4f037168598cee1222da970b4fc3b/example/demo.jpg
--------------------------------------------------------------------------------
/example/demo2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iotashan/TiTouchImageView/22431ca97aa4f037168598cee1222da970b4fc3b/example/demo2.jpg
--------------------------------------------------------------------------------