浏览代码

Merge branch 'master' of http://10.1.235.20:3000/ipu/android-share

* 'master' of http://10.1.235.20:3000/ipu/android-share:
  添加图片加水印的插件
  修改包名错误
  dataRequestAsync插件,dataRequest的异步版本,新建线程做网络请求
leijie 5 年之前
父节点
当前提交
3b90449297

+ 24 - 0
ipu-plugin-basic/build.gradle

@ -0,0 +1,24 @@
1
apply plugin: 'java'
2
3
group = 'com.ai.ipu.mobile'
4
version = '3.0-SNAPSHOT'
5
6
tasks.withType(JavaCompile) {
7
	options.encoding = 'UTF-8'
8
}
9
10
repositories {
11
    maven { url "http://114.215.100.48:9090/nexus/content/groups/public/" }
12
}
13
14
dependencies {
15
	compileOnly group: 'junit', name: 'junit', version:'4.12'
16
	compileOnly group: 'android', name: 'android', version:'22'
17
	compileOnly group: 'com.ai.wade', name: 'wade-mobile-data', version:'1.0'
18
    compileOnly "android:android-lite-http:1.0"
19
	compileOnly "com.ai.ipu:ipu-basic:${IPU_VERSION}"
20
	compileOnly "com.ai.ipu.mobile:ipu-mobile-basic:${IPU_VERSION}"
21
	compileOnly "com.ai.ipu.mobile:ipu-mobile-framework:${IPU_VERSION}"
22
    compileOnly "com.ai.ipu.mobile:ipu-plugin-extend:${IPU_VERSION}"
23
    compileOnly "com.ai.ipu.mobile:ipu-mobile-ui:${IPU_VERSION}"
24
}

+ 18 - 0
ipu-plugin-basic/gradle.properties

@ -0,0 +1,18 @@
1
## Project-wide Gradle settings.
2
#
3
# For more details on how to configure your build environment visit
4
# http://www.gradle.org/docs/current/userguide/build_environment.html
5
#
6
# Specifies the JVM arguments used for the daemon process.
7
# The setting is particularly useful for tweaking memory settings.
8
# Default value: -Xmx1024m -XX:MaxPermSize=256m
9
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10
#
11
# When configured, Gradle will run in incubating parallel mode.
12
# This option should only be used with decoupled projects. More details, visit
13
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14
# org.gradle.parallel=true
15
#
16
android_support_v4=1.0
17
IPU_VERSION=3.0-SNAPSHOT
18

+ 9 - 0
ipu-plugin-basic/pom.xml

@ -68,5 +68,14 @@
68 68
			<artifactId>ipu-plugin-extend</artifactId>
69 69
			<version>${ipu}</version>
70 70
		</dependency>
71
		<dependency>
72
			<groupId>com.ai.wade</groupId>
73
			<artifactId>wade-mobile-data</artifactId>
74
		</dependency>
75
		<dependency>
76
			<groupId>com.ai.ipu.mobile</groupId>
77
			<artifactId>ipu-mobile-basic</artifactId>
78
			<version>${ipu}</version>
79
		</dependency>
71 80
	</dependencies>
72 81
</project>

+ 90 - 0
ipu-plugin-basic/src/main/java/com/ai/ipu/mobile/plugin/MobileCamera.java

@ -1,6 +1,10 @@
1 1
package com.ai.ipu.mobile.plugin;
2 2
3
import java.io.BufferedOutputStream;
3 4
import java.io.File;
5
import java.io.FileNotFoundException;
6
import java.io.FileOutputStream;
7
import java.io.IOException;
4 8
import java.text.SimpleDateFormat;
5 9
import java.util.Date;
6 10
@ -12,6 +16,8 @@ import android.content.Intent;
12 16
import android.database.Cursor;
13 17
import android.graphics.Bitmap;
14 18
import android.graphics.BitmapFactory;
19
import android.graphics.Canvas;
20
import android.graphics.Rect;
15 21
import android.net.Uri;
16 22
import android.os.Bundle;
17 23
import android.provider.MediaStore;
@ -23,6 +29,7 @@ import com.ai.ipu.mobile.frame.plugin.Plugin;
23 29
import com.ai.ipu.mobile.ui.HintUtil;
24 30
import com.ai.ipu.mobile.ui.image.MobileGraphics;
25 31
import com.ai.ipu.mobile.util.DirectionUtil;
32
import com.ai.ipu.mobile.util.IpuMobileLog;
26 33
import com.ai.ipu.mobile.util.IpuMobileUtility;
27 34
import com.ailk.common.data.IData;
28 35
import com.ailk.common.data.impl.DataMap;
@ -288,4 +295,87 @@ public class MobileCamera extends Plugin {
288 295
		//cursor.close(); //关闭会报错
289 296
		return path;
290 297
	}
298
	
299
	public void addWaterMarkForImage(JSONArray param) throws Exception {
300
	    String path = param.getString(0);
301
	    String waterPath = param.getString(1);
302
	    double left = param.getDouble(2);
303
	    double top = param.getDouble(3);
304
	    double right = param.getDouble(4);
305
	    double bottom = param.getDouble(5);
306
	    
307
	    String resultPath = addWaterMark(path, waterPath, left, top, right, bottom);
308
	    
309
	    callback(resultPath);
310
	}
311
	
312
	/**
313
    * @param path 原图片路径
314
    * @param waterPath 水印图片路径
315
    * @param left 水印图片左边位置,值为占整个图片的宽的比例
316
    * @param top 水印图片上边位置,值为占整个图片的高的比例
317
    * @param right 水印图片右边位置,值为占整个图片的宽的比例
318
    * @param bottom 水印图片下边位置,值为占整个图片的高的比例
319
    * @return 加了水印的图片路径
320
    */
321
   private String addWaterMark(String path, String waterPath, double left, double top, double right, double bottom) {
322
       Bitmap bitmap1 = BitmapFactory.decodeFile(path);
323
       Bitmap bitmap2 = BitmapFactory.decodeFile(waterPath);
324
       bitmap1 = bitmap1.copy(bitmap1.getConfig(), true);
325
       Canvas canvas = new Canvas(bitmap1);
326
327
       Rect rect = buildRect(bitmap1, left, top, right, bottom);
328
       canvas.drawBitmap(bitmap2, null, rect, null);
329
330
       String fileName = format.format(new Date()) + "-mark.png";
331
       File f = new File(DirectionUtil.getInstance(context).getImageDirection(true), fileName);
332
       if (!f.getParentFile().exists()) {
333
           f.getParentFile().mkdirs();
334
       }
335
       String res = f.getAbsolutePath();
336
       BufferedOutputStream bos = null;
337
       try {
338
           FileOutputStream outputStream = new FileOutputStream(f);
339
           bos = new BufferedOutputStream(outputStream);
340
           bitmap1.compress(Bitmap.CompressFormat.PNG, 100, bos);
341
       } catch (FileNotFoundException e) {
342
           e.printStackTrace();
343
           res = null;
344
       } finally {
345
           if (bos != null) {
346
               try {
347
                   bos.close();
348
               } catch (IOException e) {
349
                   e.printStackTrace();
350
               }
351
           }
352
       }
353
354
       return res;
355
   }
356
357
   private Rect buildRect(Bitmap bitmap, double left, double top, double right, double bottom) {
358
       left = fixIn1(left);
359
       right = fixIn1(right);
360
       top = fixIn1(top);
361
       bottom = fixIn1(bottom);
362
       int w = bitmap.getWidth();
363
       int h = bitmap.getHeight();
364
       int l = (int) (w * left);
365
       int t = (int) (h * top);
366
       int r = (int) (w * right);
367
       int b = (int) (h * bottom);
368
       if (l >= r || t >= b) {
369
           IpuMobileLog.w(TAG, "buildRect: invalid params");
370
           return new Rect(0, 0, w/4, h/4);
371
       }
372
       Rect rect = new Rect(l, t, r, b);
373
       return rect;
374
   }
375
376
   private double fixIn1(double v) {
377
       if (v > 1) v = 1;
378
       if (v < 0) v = 0;
379
       return v;
380
   }
291 381
}

+ 22 - 0
ipu-plugin-basic/src/main/java/com/ai/ipu/mobile/plugin/MobileNetWork.java

@ -28,6 +28,7 @@ import com.ai.ipu.mobile.common.bluetooth.util.BluetoothTool;
28 28
import com.ai.ipu.mobile.common.sms.listener.OnSmsReceiveListener;
29 29
import com.ai.ipu.mobile.common.sms.util.SmsTool;
30 30
import com.ai.ipu.mobile.frame.IIpuMobile;
31
import com.ai.ipu.mobile.frame.activity.IpuMobileActivity;
31 32
import com.ai.ipu.mobile.frame.config.MobileConfig;
32 33
import com.ai.ipu.mobile.frame.config.ServerDataConfig;
33 34
import com.ai.ipu.mobile.frame.plugin.Plugin;
@ -175,6 +176,27 @@ public class MobileNetWork extends Plugin {
175 176
		callback(result);
176 177
	}
177 178
	
179
	public void dataRequestAsync(final JSONArray param) throws Exception {
180
	    final String dataAction = param.getString(0);
181
        final String data = param.getString(1);
182
        final String headers = param.optString(5);
183
        
184
        new Thread(new Runnable() {
185
            
186
            @Override
187
            public void run() {
188
                String result = null;
189
                try {
190
                    result = isNull(headers) ? dataRequest(dataAction, isNull(data) ? null : new DataMap(data)) :
191
                        dataRequest(dataAction, isNull(data) ? null : new DataMap(data),new DataMap(headers));
192
                } catch (Exception e) {
193
                    exceptionInThread(e, "dataRequest", param);
194
                }
195
               callback(result);
196
            }
197
        }).start();
198
	}
199
	
178 200
	public void dataRequestWithHost(JSONArray param) throws Exception {
179 201
	    String requestUrl = param.getString(0);// http://ip:port/servername/mobiledata
180 202
        String dataAction = param.getString(1);

+ 1 - 1
ipu-plugin-basic/src/main/java/com/ai/ipu/mobile/plugin/MobileUI.java

@ -65,7 +65,7 @@ import com.ailk.common.data.IDataset;
65 65
import com.ailk.common.data.impl.DataMap;
66 66

67 67
public class MobileUI extends Plugin {
68
	private SimpleProgressDialog progressDialog = null;
68
	private static SimpleProgressDialog progressDialog = null;
69 69
	private final int REQUEST_CODE_CUSTOM_DIALOG = 100;
70 70
	private final int REQUEST_CODE_CUSTOM_WINDOW = 200;
71 71
	private final int REQUEST_CODE_SLIDING_MENU = 300;

+ 1 - 1
ipu-scan-lib/AndroidManifest.xml

@ -1,6 +1,6 @@
1 1
<?xml version="1.0" encoding="utf-8"?>
2 2
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
    package="com.ipu.scan"
3
    package="com.ai.ipu.scan"
4 4
    android:versionCode="1"
5 5
    android:versionName="1.0" >
6 6

+ 1 - 1
ipu-scan-lib/res/layout/activity_scan_multiple.xml

@ -52,7 +52,7 @@
52 52
		            android:src="@drawable/scan_flashlight_off" />
53 53
	        </RelativeLayout>
54 54
		
55
		        <com.ipu.scan.view.ViewfinderView
55
		        <com.ai.ipu.scan.view.ViewfinderView
56 56
			        android:id="@+id/viewfinder_view"
57 57
			        android:layout_width="wrap_content"
58 58
			        android:layout_height="wrap_content"

+ 1 - 1
ipu-scan-lib/res/layout/scan_zxing_capture.xml

@ -30,7 +30,7 @@
30 30
            android:layout_alignParentTop="true"
31 31
            android:src="@drawable/scan_flashlight_off" />
32 32
33
        <com.ipu.scan.view.ViewfinderView
33
        <com.ai.ipu.scan.view.ViewfinderView
34 34
	        android:id="@+id/viewfinder_view"
35 35
	        android:layout_width="wrap_content"
36 36
	        android:layout_height="wrap_content"/>