Browse Source

Merge branch 'ipu-v3.0' of http://10.1.235.20:3000/ipu/android-share into ipu-v3.0

* 'ipu-v3.0' of http://10.1.235.20:3000/ipu/android-share:
  增加WaveView
  修改getPhoto和getPicture插件压缩方法
  把loadingstaop放在主线程执行
  去掉一个无关代码
  调用系统相机录像可传入压缩比
  添加图片加水印的插件
  修改mobileUi
  206演示环境 配置修改
  修改依赖jar版本为snapshot版
  添加closeUrl插件
  测试修改

# Conflicts:
#	ipu-plugin-basic/build.gradle
#	ipu-plugin-basic/gradle.properties
leijie 5 years ago
parent
commit
b0766ffa64

+ 162 - 156
display-server/pom.xml

@ -1,157 +1,163 @@
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4

5
	<parent>
6
		<groupId>com.ai.ipu</groupId>
7
		<artifactId>ipu-server-libs</artifactId>
8
		<version>3.0</version>
9
	</parent>
10

11
	<artifactId>display-server</artifactId>
12
	<packaging>war</packaging>
13
	<name>展示平台</name>
14
	<description>3.0以后的展示平台工程全部支持Maven和Ant两种构建方式</description>
15

16
	<dependencies>
17
		<!-- 公共必选依赖 -->
18
		<!-- Central jar -->
19
		<dependency>
20
			<groupId>junit</groupId>
21
			<artifactId>junit</artifactId>
22
		</dependency>
23
		<dependency>
24
			<groupId>javax.servlet</groupId>
25
			<artifactId>servlet-api</artifactId>
26
		</dependency>
27
		<dependency>
28
			<groupId>org.apache.commons</groupId>
29
			<artifactId>commons-lang3</artifactId>
30
		</dependency>
31
		<dependency>
32
			<groupId>log4j</groupId>
33
			<artifactId>log4j</artifactId>
34
		</dependency>
35
		<dependency>
36
			<groupId>dom4j</groupId>
37
			<artifactId>dom4j</artifactId>
38
		</dependency>
39
		<dependency>
40
			<groupId>jaxen</groupId>
41
			<artifactId>jaxen</artifactId>
42
		</dependency>
43
		<dependency>
44
			<groupId>com.mashape.unirest</groupId>
45
			<artifactId>unirest-java</artifactId>
46
		</dependency>
47
		<dependency>
48
			<groupId>org.beetl</groupId>
49
			<artifactId>beetl-core</artifactId>
50
		</dependency>
51
		<dependency>
52
			<groupId>org.apache.velocity</groupId>
53
			<artifactId>velocity</artifactId>
54
		</dependency>
55
		<!-- 3rd party jar -->
56
		<dependency>
57
			<groupId>com</groupId>
58
			<artifactId>java_memcache-release</artifactId>
59
		</dependency>
60
		<!-- ipu jar -->
61
		<dependency>
62
			<groupId>com.ai.ipu</groupId>
63
			<artifactId>ipu-basic</artifactId>
64
		</dependency>
65
		<dependency>
66
			<groupId>com.ai.ipu</groupId>
67
			<artifactId>ipu-common</artifactId>
68
		</dependency>
69
		<dependency>
70
			<groupId>com.ai.ipu</groupId>
71
			<artifactId>ipu-server-web</artifactId>
72
		</dependency>
73
		<dependency>
74
			<groupId>com.ai.ipu</groupId>
75
			<artifactId>ipu-spring-boot</artifactId>
76
		</dependency>
77
		<dependency>
78
			<groupId>com.ai.ipu</groupId>
79
			<artifactId>ipu-file-system</artifactId>
80
		</dependency>
81
		<dependency>
82
			<groupId>com.ai.wade</groupId>
83
			<artifactId>wade-data</artifactId>
84
		</dependency>
85
		<dependency>
86
			<groupId>com.ai.wade</groupId>
87
			<artifactId>wade-cache</artifactId>
88
		</dependency>
89
		<dependency>
90
			<groupId>com.ai.wade</groupId>
91
			<artifactId>wade-database</artifactId>
92
		</dependency>
93
		<dependency>
94
			<groupId>com.ai.wade</groupId>
95
			<artifactId>wade-apache</artifactId>
96
		</dependency>
97
		<dependency>
98
			<groupId>com.ai.wade</groupId>
99
			<artifactId>wade-common</artifactId>
100
		</dependency>
101
		<dependency>
102
			<groupId>com.ai.wade</groupId>
103
			<artifactId>wade-sqlite-jdbc</artifactId>
104
		</dependency>
105

106
		<!-- 公共可选依赖 -->
107
		<dependency>
108
			<groupId>org.jsoup</groupId>
109
			<artifactId>jsoup</artifactId>
110
		</dependency>
111
		<dependency>
112
			<groupId>commons-dbcp</groupId>
113
			<artifactId>commons-dbcp</artifactId>
114
		</dependency>
115
		<dependency>
116
			<groupId>mysql</groupId>
117
			<artifactId>mysql-connector-java</artifactId>
118
		</dependency>
119
		<dependency>
120
			<groupId>commons-fileupload</groupId>
121
			<artifactId>commons-fileupload</artifactId>
122
		</dependency>
123
		<dependency>
124
			<groupId>commons-codec</groupId>
125
			<artifactId>commons-codec</artifactId>
126
		</dependency>
127
		<!-- 额外依赖 -->
128

129
	</dependencies>
130

131
	<build>
132
		<plugins>
133
			<!-- clean中间文件 -->
134
			<plugin>
135
				<artifactId>maven-clean-plugin</artifactId>
136
			</plugin>
137
			<!-- 复制资源 -->
138
			<plugin>
139
				<artifactId>maven-resources-plugin</artifactId>
140
			</plugin>
141
			<!-- 编译 -->
142
			<plugin>
143
				<artifactId>maven-compiler-plugin</artifactId>
144
			</plugin>
145
			<!-- 生成文件版本号和文件加密 -->
146
			<plugin>
147
				<groupId>org.codehaus.mojo</groupId>
148
				<artifactId>exec-maven-plugin</artifactId>
149
			</plugin>
150
			<plugin>
151
				<artifactId>maven-dependency-plugin</artifactId>
152
			</plugin>
153
		</plugins>
154

155
		<finalName>display</finalName>
156
	</build>
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4
5
	<parent>
6
		<groupId>com.ai.ipu</groupId>
7
		<artifactId>ipu-server-libs</artifactId>
8
		<version>3.0</version>
9
	</parent>
10
11
	<artifactId>display-server</artifactId>
12
	<packaging>war</packaging>
13
	<name>展示平台</name>
14
	<description>3.0以后的展示平台工程全部支持Maven和Ant两种构建方式</description>
15
16
	<dependencies>
17
		<!-- 公共必选依赖 -->
18
		<!-- Central jar -->
19
		<dependency>
20
			<groupId>junit</groupId>
21
			<artifactId>junit</artifactId>
22
		</dependency>
23
		<dependency>
24
			<groupId>javax.servlet</groupId>
25
			<artifactId>servlet-api</artifactId>
26
		</dependency>
27
		<dependency>
28
			<groupId>org.apache.commons</groupId>
29
			<artifactId>commons-lang3</artifactId>
30
		</dependency>
31
		<dependency>
32
			<groupId>log4j</groupId>
33
			<artifactId>log4j</artifactId>
34
		</dependency>
35
		<dependency>
36
			<groupId>dom4j</groupId>
37
			<artifactId>dom4j</artifactId>
38
		</dependency>
39
		<dependency>
40
			<groupId>jaxen</groupId>
41
			<artifactId>jaxen</artifactId>
42
		</dependency>
43
		<dependency>
44
			<groupId>com.mashape.unirest</groupId>
45
			<artifactId>unirest-java</artifactId>
46
		</dependency>
47
		<dependency>
48
			<groupId>org.beetl</groupId>
49
			<artifactId>beetl-core</artifactId>
50
		</dependency>
51
		<dependency>
52
			<groupId>org.apache.velocity</groupId>
53
			<artifactId>velocity</artifactId>
54
		</dependency>
55
		<!-- 3rd party jar -->
56
		<dependency>
57
			<groupId>com</groupId>
58
			<artifactId>java_memcache-release</artifactId>
59
		</dependency>
60
		<!-- ipu jar -->
61
		<dependency>
62
			<groupId>com.ai.ipu</groupId>
63
			<artifactId>ipu-basic</artifactId>
64
		</dependency>
65
		<dependency>
66
			<groupId>com.ai.ipu</groupId>
67
			<artifactId>ipu-common</artifactId>
68
		</dependency>
69
		<dependency>
70
			<groupId>com.ai.ipu</groupId>
71
			<artifactId>ipu-server-web</artifactId>
72
			<version>3.0-SNAPSHOT</version>
73
		</dependency>
74
		<dependency>
75
			<groupId>com.ai.ipu</groupId>
76
			<artifactId>ipu-spring-boot</artifactId>
77
		</dependency>
78
		<dependency>
79
			<groupId>com.ai.ipu</groupId>
80
			<artifactId>ipu-file-system</artifactId>
81
		</dependency>
82
		<dependency>
83
			<groupId>com.ai.ipu</groupId>
84
			<artifactId>ipu-cache</artifactId>
85
			<version>${ipu}</version>
86
		</dependency>
87
		<dependency>
88
			<groupId>com.ai.wade</groupId>
89
			<artifactId>wade-data</artifactId>
90
		</dependency>
91
		<!--<dependency>
92
			<groupId>com.ai.wade</groupId>
93
			<artifactId>wade-cache</artifactId>
94
		</dependency>-->
95
		<dependency>
96
			<groupId>com.ai.wade</groupId>
97
			<artifactId>wade-database</artifactId>
98
		</dependency>
99
		<dependency>
100
			<groupId>com.ai.wade</groupId>
101
			<artifactId>wade-apache</artifactId>
102
		</dependency>
103
		<dependency>
104
			<groupId>com.ai.wade</groupId>
105
			<artifactId>wade-common</artifactId>
106
		</dependency>
107
		<dependency>
108
			<groupId>com.ai.wade</groupId>
109
			<artifactId>wade-sqlite-jdbc</artifactId>
110
		</dependency>
111
112
		<!-- 公共可选依赖 -->
113
		<dependency>
114
			<groupId>org.jsoup</groupId>
115
			<artifactId>jsoup</artifactId>
116
		</dependency>
117
		<dependency>
118
			<groupId>commons-dbcp</groupId>
119
			<artifactId>commons-dbcp</artifactId>
120
		</dependency>
121
		<dependency>
122
			<groupId>mysql</groupId>
123
			<artifactId>mysql-connector-java</artifactId>
124
		</dependency>
125
		<dependency>
126
			<groupId>commons-fileupload</groupId>
127
			<artifactId>commons-fileupload</artifactId>
128
		</dependency>
129
		<dependency>
130
			<groupId>commons-codec</groupId>
131
			<artifactId>commons-codec</artifactId>
132
		</dependency>
133
		<!-- 额外依赖 -->
134
135
	</dependencies>
136
137
	<build>
138
		<plugins>
139
			<!-- clean中间文件 -->
140
			<plugin>
141
				<artifactId>maven-clean-plugin</artifactId>
142
			</plugin>
143
			<!-- 复制资源 -->
144
			<plugin>
145
				<artifactId>maven-resources-plugin</artifactId>
146
			</plugin>
147
			<!-- 编译 -->
148
			<plugin>
149
				<artifactId>maven-compiler-plugin</artifactId>
150
			</plugin>
151
			<!-- 生成文件版本号和文件加密 -->
152
			<plugin>
153
				<groupId>org.codehaus.mojo</groupId>
154
				<artifactId>exec-maven-plugin</artifactId>
155
			</plugin>
156
			<plugin>
157
				<artifactId>maven-dependency-plugin</artifactId>
158
			</plugin>
159
		</plugins>
160
161
		<finalName>display</finalName>
162
	</build>
157 163
</project>

+ 2 - 3
display-server/src/main/resources/count-servers.xml

@ -1,5 +1,4 @@
1 1
<?xml version="1.0" encoding="UTF-8"?>
2
<servers>
3
    <server url="114.215.100.48:9100" weight="1"/>
4
    <server url="114.215.100.48:9200" weight="2"/>
2
<servers strategy="1">
3
    <server ip="121.42.183.206" port="6000" weight="1"/>
5 4
</servers>

+ 148 - 0
ipu-mobile-ui/src/main/java/com/ai/ipu/mobile/ui/comp/view/WaveView.java

@ -0,0 +1,148 @@
1
package com.ai.ipu.mobile.ui.comp.view;
2
3
import android.animation.ValueAnimator;
4
import android.content.Context;
5
import android.graphics.Canvas;
6
import android.graphics.Paint;
7
import android.graphics.Path;
8
import android.util.AttributeSet;
9
import android.view.View;
10
import android.view.animation.LinearInterpolator;
11
12
public class WaveView extends View {
13
    private static final long PERIOD = 1500;
14
    private Paint mPaint1 = new Paint(Paint.ANTI_ALIAS_FLAG);
15
    private Paint mPaint2 = new Paint(Paint.ANTI_ALIAS_FLAG);
16
    private Paint mPaint3 = new Paint(Paint.ANTI_ALIAS_FLAG);
17
    private Path mPath1 = new Path();
18
    private Path mPath2 = new Path();
19
    private Path mPath3 = new Path();
20
21
    private static final int DX = 20;
22
    private double omega;
23
    private int mWaveLength;
24
    private int mWaveHeight;
25
    private float offset;
26
    private ValueAnimator mValueAnimatior;
27
28
    public WaveView(Context context) {
29
        super(context);
30
    }
31
32
    public WaveView(Context context, AttributeSet attrs) {
33
        super(context, attrs);
34
    }
35
36
    public WaveView(Context context, AttributeSet attrs, int defStyleAttr) {
37
        super(context, attrs, defStyleAttr);
38
    }
39
40
    @Override
41
    public void onWindowFocusChanged(boolean hasWindowFocus) {
42
        super.onWindowFocusChanged(hasWindowFocus);
43
        if (hasWindowFocus) {
44
            if (mWaveLength == 0) {
45
                init();
46
            }
47
        }
48
    }
49
50
    @Override
51
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
52
        super.onLayout(changed, left, top, right, bottom);
53
        if (mWaveLength==0){
54
            init();
55
        }
56
    }
57
58
    private void init() {
59
        mWaveLength = getWidth();
60
        mWaveHeight = getHeight();
61
        if (mWaveLength != 0) {
62
            omega = Math.PI * 4 / mWaveLength;
63
        }
64
        mPaint1.setStyle(Paint.Style.STROKE);
65
        mPaint2.setStyle(Paint.Style.STROKE);
66
        mPaint3.setStyle(Paint.Style.STROKE);
67
        mPaint1.setColor(0xFF3F93F8);
68
        mPaint2.setColor(0xff999999);
69
        mPaint3.setColor(0xff888888);
70
    }
71
72
    @Override
73
    protected void onDraw(Canvas canvas) {
74
        computePaths();
75
        canvas.drawPath(mPath1, mPaint1);
76
        canvas.drawPath(mPath2, mPaint2);
77
        canvas.drawPath(mPath3, mPaint3);
78
    }
79
80
    private void computePaths() {
81
        mPath1.reset();
82
        mPath2.reset();
83
        mPath3.reset();
84
        float x, y;
85
        for (x=0; x<mWaveLength+DX; x+=DX) {
86
            y = ((float) Math.sin(omega*x + offset) + 1) * mWaveHeight / 2;
87
            mPath1.lineTo(x, y);
88
        }
89
90
        for (x=0; x<mWaveLength+DX; x+=DX) {
91
            y = ((float) Math.sin(omega*x + Math.PI + offset) + 1) * mWaveHeight / 2;
92
            mPath2.lineTo(x, y);
93
        }
94
95
        for (x=0; x<mWaveLength+DX; x+=DX) {
96
            y = ((float) Math.sin(omega*x + Math.PI/2 + offset) + 1) * mWaveHeight / 2;
97
            mPath3.lineTo(x, y);
98
        }
99
    }
100
101
    /**
102
     * 设置3根波浪线的颜色值
103
     * @param c1
104
     * @param c2
105
     * @param c3
106
     */
107
    public void setColors(int c1, int c2, int c3) {
108
        mPaint1.setColor(c1);
109
        mPaint2.setColor(c2);
110
        mPaint3.setColor(c3);
111
    }
112
113
    private void startAnimator() {
114
        mValueAnimatior = ValueAnimator.ofFloat(0, (float) Math.PI*2);
115
        mValueAnimatior.setDuration(PERIOD);
116
        mValueAnimatior.setInterpolator(new LinearInterpolator());
117
        mValueAnimatior.setRepeatCount(ValueAnimator.INFINITE);
118
        mValueAnimatior.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
119
            @Override
120
            public void onAnimationUpdate(ValueAnimator animation) {
121
                offset = (Float) animation.getAnimatedValue();
122
                invalidate();
123
            }
124
        });
125
        mValueAnimatior.start();
126
    }
127
128
    @Override
129
    protected void onAttachedToWindow() {
130
        super.onAttachedToWindow();
131
        startAnimator();
132
    }
133
134
    @Override
135
    protected void onDetachedFromWindow() {
136
        super.onDetachedFromWindow();
137
        stopAnimator();
138
    }
139
140
    /**
141
     * 停止动画
142
     */
143
    public void stopAnimator() {
144
        if(mValueAnimatior != null && mValueAnimatior.isRunning()) {
145
            mValueAnimatior.cancel();
146
        }
147
    }
148
}

+ 18 - 48
ipu-plugin-basic/build.gradle

@ -1,54 +1,24 @@
1
allprojects {
2
    repositories {
3
        jcenter()
4
        maven { url "http://114.215.100.48:9090/nexus/content/groups/public/"}
5
        maven { url "http://114.215.100.48:9090/nexus/content/repositories/ipu-snapshots/"}
6
    }
7
}
8
9
apply plugin: 'com.android.library'
10
android {
11
    compileSdkVersion 23
12
    buildToolsVersion "26.0.2"
13
14
    defaultConfig {
15
        minSdkVersion 11
16
        targetSdkVersion 23
17
    }
18
19
        //源文件目录设置
20
    sourceSets {
21
        main {
22
            assets.srcDirs = ['src/main/java/assets']
23
            resources.srcDirs = ['src/main/java/']
24
            resources.includes = ['**/*.properties']
25
        }
26
27
    }
1
apply plugin: 'java'
28 2
29
    aaptOptions.cruncherEnabled = false;
30
    aaptOptions.useNewCruncher = false;
3
group = 'com.ai.ipu.mobile'
4
version = '3.0-SNAPSHOT'
31 5
32
    buildTypes {
33
        release {
34
            minifyEnabled false
35
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
36
        }
37
    }
6
tasks.withType(JavaCompile) {
7
	options.encoding = 'UTF-8'
38 8
}
39 9
40
10
repositories {
11
    maven { url "http://114.215.100.48:9090/nexus/content/groups/public/" }
12
}
41 13
42 14
dependencies {
43
    provided "com.ai.ipu:ipu-basic:${IPU_VERSION}"
44
    provided "com.ai.ipu.mobile:ipu-mobile-basic:${IPU_VERSION}"
45
    provided "com.ai.ipu.mobile:ipu-count-client:${IPU_VERSION}"
46
    compileOnly 'com.android.support:appcompat-v7:23.0.1'
47
48
    implementation 'com.qihoo360.replugin:replugin-host-lib:2.3.1'
49
50
    compileOnly project(':ipu-mobile-framework')
51
    provided "com.ai.ipu.mobile:ipu-plugin-extend:${IPU_VERSION}"
52
    provided "android:android-lite-http:${Http}"
53
    provided "com.ai.ipu.mobile:ipu-mobile-ui:${IPU_VERSION}"
54
}
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
}

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

@ -15,5 +15,4 @@
15 15
#
16 16
android_support_v4=1.0
17 17
IPU_VERSION=3.0-SNAPSHOT
18
Http=1.0
19 18

+ 1 - 1
ipu-plugin-basic/pom.xml

@ -66,7 +66,7 @@
66 66
		<dependency>
67 67
			<groupId>com.ai.ipu.mobile</groupId>
68 68
			<artifactId>ipu-plugin-extend</artifactId>
69
			<version>3.0</version>
69
			<version>${ipu}</version>
70 70
		</dependency>
71 71
	</dependencies>
72 72
</project>

+ 313 - 70
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,11 +16,18 @@ 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.Color;
21
import android.graphics.Paint;
22
import android.graphics.Path;
23
import android.graphics.Rect;
15 24
import android.net.Uri;
16 25
import android.os.Bundle;
17 26
import android.provider.MediaStore;
27
import android.util.Log;
18 28
19 29
import com.ai.ipu.basic.file.FileUtil;
30
import com.ai.ipu.basic.string.StringUtil;
20 31
import com.ai.ipu.mobile.app.IpuAppInfo;
21 32
import com.ai.ipu.mobile.frame.IIpuMobile;
22 33
import com.ai.ipu.mobile.frame.plugin.Plugin;
@ -33,6 +44,9 @@ import com.ailk.common.data.impl.DataMap;
33 44
 * @desc 图片和照相机功能集合
34 45
 */
35 46
public class MobileCamera extends Plugin {
47
	private static final int DEFAULT_COLOR = 0xffdcdcdc;
48
	private static final int MAX_PIXELS = 1920 * 1080;
49
36 50
	public enum TYPE {
37 51
		BASE64_AND_PATH(2), //Base64编码和文件路径
38 52
		PATH(1), //文件路径
@ -51,6 +65,8 @@ public class MobileCamera extends Plugin {
51 65
52 66
	private SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd-hhmmss");
53 67
	private String photoFullPath;
68
	private int minWidth;
69
	private int minFileSize;
54 70
55 71
	private Function func;
56 72
	private enum Function {
@ -71,6 +87,8 @@ public class MobileCamera extends Plugin {
71 87
	public void getPicture(JSONArray param) throws JSONException {
72 88
		this.func = Function.getPicture;
73 89
		int type = param.getInt(0);
90
		minFileSize = param.optInt(1, 400 * 1024);
91
		minWidth = param.optInt(2, 300);
74 92
		/* 使用相册打开 */
75 93
		Intent intent = new Intent(Intent.ACTION_PICK,
76 94
				android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
@ -86,6 +104,8 @@ public class MobileCamera extends Plugin {
86 104
	public void getPhoto(JSONArray param) throws Exception {
87 105
		this.func = Function.getPhoto;
88 106
		int type = param.getInt(0);
107
		minFileSize = param.optInt(1, 400 * 1024);
108
        minWidth = param.optInt(2, 300);
89 109
90 110
		String appName = IpuAppInfo.getAppPath();
91 111
		String photoName = appName + "-" + format.format(new Date()) + ".jpg";// 生成照片名称
@ -168,7 +188,7 @@ public class MobileCamera extends Plugin {
168 188
//		}
169 189
//	}
170 190
171
	public void onActivityResult(int requestCode, int resultCode, Intent intent) {
191
	public void onActivityResult(final int requestCode, int resultCode, final Intent intent) {
172 192
		// Activity.RESULT_CANCELED|Activity.RESULT_OK
173 193
		if (func == Function.scanQrCode) {
174 194
			if (resultCode == Activity.RESULT_OK) {
@ -179,77 +199,94 @@ public class MobileCamera extends Plugin {
179 199
		} else if (func.equals(Function.getPhoto)) {
180 200
			// 照相功能
181 201
			if (resultCode == Activity.RESULT_OK) {
182
				Bitmap bitmap = null; 
183
				try {
184
					bitmap = getBitmapByImage(photoFullPath); //核实照片文件是否已经生成???????
185
				} catch (Exception e) {
186
					HintUtil.alert(context, e.getMessage());
187
					return;
188
				}
189
				
190
				if (requestCode == TYPE.PATH.getType()) {
191
					//MobileGraphics.savePicToLocal(bitmap, photoFullPath); //保存压缩文件
192
					callback(photoFullPath);
193
				}else if(requestCode == TYPE.BASE64.getType()){
194
					bitmap = MobileGraphics.compressImage(bitmap, 50, quality);	//压缩到50k
195
					Bitmap base64Bitmap = MobileGraphics.compressImage(bitmap, 10, 30);	//quality=30?
196
					String out = MobileGraphics.bitmapToString(base64Bitmap); //base64缩略图
197
					base64Bitmap.recycle();
198
					callback(out);
199
				}else{
200
					//MobileGraphics.savePicToLocal(bitmap, photoFullPath); //保存压缩文件
201
					bitmap = MobileGraphics.compressImage(bitmap, 50, quality);	//压缩到50k
202
					Bitmap base64Bitmap = MobileGraphics.compressImage(bitmap, 10, 30);	//quality=30?
203
					String out = MobileGraphics.bitmapToString(base64Bitmap); //base64处理
204
					base64Bitmap.recycle();
205
					IData result = new DataMap();
206
					result.put("thumbnail", out); //缩略图
207
					result.put("path", photoFullPath); //路径
208
					callback(result.toString());
209
				}
210
				bitmap.recycle();
211
				photoFullPath = null;
202
				new Thread(new Runnable() {
203
					@Override
204
					public void run() {
205
						Bitmap bitmap = null;
206
						try {
207
							bitmap = getBitmapByImage(photoFullPath); //核实照片文件是否已经生成???????
208
						} catch (Exception e) {
209
							HintUtil.alert(context, e.getMessage());
210
							return;
211
						}
212
213
						if (requestCode == TYPE.PATH.getType()) {
214
							//MobileGraphics.savePicToLocal(bitmap, photoFullPath); //保存压缩文件
215
							if (minFileSize > 0) {
216
								photoFullPath = MobileGraphics.compressImgToLength(bitmap, minFileSize, minWidth, requestCode, photoFullPath);
217
							}
218
							callback(photoFullPath);
219
						}else if(requestCode == TYPE.BASE64.getType()){
220
							String out = MobileGraphics.compressImgToLength(bitmap, minFileSize, minWidth, requestCode, null);
221
							callback(out);
222
						}else{
223
							//MobileGraphics.savePicToLocal(bitmap, photoFullPath); //保存压缩文件
224
							bitmap = MobileGraphics.compressImage(bitmap, 50, quality);	//压缩到50k
225
							Bitmap base64Bitmap = MobileGraphics.compressImage(bitmap, 10, 30);	//quality=30?
226
							String out = MobileGraphics.bitmapToString(base64Bitmap); //base64处理
227
							base64Bitmap.recycle();
228
							IData result = new DataMap();
229
							result.put("thumbnail", out); //缩略图
230
							result.put("path", photoFullPath); //路径
231
							callback(result.toString());
232
						}
233
						bitmap.recycle();
234
						photoFullPath = null;
235
					}
236
				}).start();
212 237
			}
213 238
		} else if (func.equals(Function.getPicture)) {// 从媒体库中获取
214 239
			if (resultCode == Activity.RESULT_OK) {
215
				Uri uri = intent.getData();
216
				String picturePath = null;
217
				if (uri.toString().startsWith("file:")) {
218
					picturePath = uri.getPath();
219
				} else if (uri.toString().startsWith("content:")) {
220
					picturePath = getPath(uri);
221
				} else {
222
					HintUtil.alert(context,"请选择相册或者文件浏览器");
223
					return;
224
				}
225
226
				Bitmap bitmap = null; 
227
				try {
228
					bitmap = getBitmapByImage(picturePath);
229
				} catch (Exception e) {
230
					HintUtil.alert(context, e.getMessage());
231
					return;
232
				}
233
				
234
				if (requestCode == TYPE.PATH.getType()) {
235
					callback(picturePath);
236
				}else if(requestCode == TYPE.BASE64.getType()){
237
					bitmap = MobileGraphics.compressImage(bitmap, 50, quality);	//压缩到50k
238
					Bitmap base64Bitmap = MobileGraphics.compressImage(bitmap, 10, 30);
239
					String out = MobileGraphics.bitmapToString(base64Bitmap);//base64缩略图
240
					base64Bitmap.recycle();
241
					callback(out);
242
				}else{
243
					bitmap = MobileGraphics.compressImage(bitmap, 50, quality);	//压缩到50k
244
					Bitmap base64Bitmap = MobileGraphics.compressImage(bitmap, 10, 30);	//quality=30?
245
					String out = MobileGraphics.bitmapToString(base64Bitmap); //base64处理
246
					base64Bitmap.recycle();
247
					IData result = new DataMap();
248
					result.put("thumbnail", out); //缩略图
249
					result.put("path", picturePath); //路径
250
					callback(result.toString());
251
				}
252
				bitmap.recycle();
240
				new Thread(new Runnable() {
241
					@Override
242
					public void run() {
243
						Uri uri = intent.getData();
244
						String picturePath = null;
245
						if (uri.toString().startsWith("file:")) {
246
							picturePath = uri.getPath();
247
						} else if (uri.toString().startsWith("content:")) {
248
							picturePath = getPath(uri);
249
						} else {
250
							HintUtil.alert(context,"请选择相册或者文件浏览器");
251
							return;
252
						}
253
254
						Bitmap bitmap = null;
255
						try {
256
							bitmap = getBitmapByImage(picturePath);
257
						} catch (Exception e) {
258
							HintUtil.alert(context, e.getMessage());
259
							return;
260
						}
261
262
						if (requestCode == TYPE.PATH.getType()) {
263
							String resultPath = picturePath;
264
							if (minFileSize > 0) {
265
								String fileName = format.format(new Date()) + ".jpg";
266
								String dir = DirectionUtil.getInstance(context).getImageDirection(true);
267
								File dirFile = new File(dir);
268
								if (!dirFile.exists()) dirFile.mkdirs();
269
								resultPath = FileUtil.connectFilePath(dir,
270
										fileName);
271
								resultPath = MobileGraphics.compressImgToLength(bitmap, minFileSize, minWidth, requestCode, resultPath);
272
							}
273
							callback(resultPath);
274
						}else if(requestCode == TYPE.BASE64.getType()){
275
							String out = MobileGraphics.compressImgToLength(bitmap, minFileSize, minWidth, requestCode, null);
276
							callback(out);
277
						}else{
278
							bitmap = MobileGraphics.compressImage(bitmap, 50, quality);	//压缩到50k
279
							Bitmap base64Bitmap = MobileGraphics.compressImage(bitmap, 10, 30);	//quality=30?
280
							String out = MobileGraphics.bitmapToString(base64Bitmap); //base64处理
281
							base64Bitmap.recycle();
282
							IData result = new DataMap();
283
							result.put("thumbnail", out); //缩略图
284
							result.put("path", picturePath); //路径
285
							callback(result.toString());
286
						}
287
						bitmap.recycle();
288
					}
289
				}).start();
253 290
			}
254 291
		}
255 292
	}
@ -264,7 +301,7 @@ public class MobileCamera extends Plugin {
264 301
	public Bitmap getBitmapByImage(String imagePath){
265 302
		BitmapFactory.Options opts = getBitmapOptions();
266 303
		BitmapFactory.decodeFile(imagePath, opts);
267
		opts.inSampleSize = MobileGraphics.computeSampleSize(opts, -1, 800 * 480);
304
		opts.inSampleSize = MobileGraphics.computeSampleSize(opts, -1, MAX_PIXELS);
268 305
		opts.inJustDecodeBounds = false;// 还原
269 306
		Bitmap bitmap = null;
270 307
		try {
@ -288,4 +325,210 @@ public class MobileCamera extends Plugin {
288 325
		//cursor.close(); //关闭会报错
289 326
		return path;
290 327
	}
328
329
330
	public void addImageWaterMarkForImage(JSONArray param) throws Exception {
331
		String picPath = param.getString(0);
332
		String mark = param.getString(1);
333
		String p = param.getString(2);
334
		if (p== null || !StringUtil.isDataMap(p)) {
335
			throw new IllegalArgumentException("没有DataMap参数");
336
		}
337
		DataMap dataMap = new DataMap(p);
338
	    double x = dataMap.getDouble("markX");
339
	    double y = dataMap.getDouble("markY");
340
		double width = dataMap.getDouble("width", 0.2);
341
		String resultPath = addWaterMark(picPath, mark, x, y, width);
342
	    	    
343
	    callback(resultPath);
344
	}
345
346
	public void addTextWaterMarkForImage(JSONArray params) throws Exception {
347
		String res = null;
348
		String picPath = params.getString(0);
349
		String text = params.getString(1);
350
		String p = params.getString(2);
351
		if (p== null || !StringUtil.isDataMap(p)) {
352
			throw new IllegalArgumentException("没有DataMap参数");
353
		}
354
		DataMap dataMap = new DataMap(p);
355
		double textSize = dataMap.getDouble("textSize", 0.05);
356
		String textColor = dataMap.getString("textColor");
357
		double angle = dataMap.getDouble("angle");
358
		double rowSpaceRatio, colSpaceRatio, markXRatio, markYRatio;
359
		boolean isRepeat = dataMap.getBoolean("isRepeat");
360
		if (isRepeat) {
361
			rowSpaceRatio = dataMap.getDouble("rowSpace", 0.2);
362
			colSpaceRatio = dataMap.getDouble("colSpace", 0.2);
363
			res = addText(picPath, text, textSize, textColor, angle, rowSpaceRatio, colSpaceRatio);
364
		} else {
365
			markXRatio = dataMap.getDouble("markX");
366
			markYRatio = dataMap.getDouble("markY");
367
			res = addText(picPath, text, markXRatio, markYRatio, textSize, textColor, angle);
368
		}
369
370
		callback(res);
371
	}
372
373
	/**
374
	 * 在指定位置添加一行文字水印
375
	 * @param picPath
376
	 * @param text
377
	 * @param markXRatio
378
	 * @param markYRatio
379
	 * @param textSizeRatio
380
	 * @param textColor
381
	 * @param angle
382
	 * @return
383
	 */
384
	private String addText(String picPath, String text, double markXRatio, double markYRatio, double textSizeRatio, String textColor, double angle) {
385
		String result;
386
		Bitmap bitmap = BitmapFactory.decodeFile(picPath);
387
		bitmap = bitmap.copy(bitmap.getConfig(), true);
388
		int picWidth = bitmap.getWidth();
389
		Canvas canvas = new Canvas(bitmap);
390
		Paint paint = new Paint();
391
		paint.setColor(textColor == null ? 0xffdcdcdc : Color.parseColor(textColor)); //默认灰色
392
		int textSize = (int) (picWidth * textSizeRatio);
393
		int x = (int) (markXRatio * picWidth);
394
		int y = (int) (markYRatio * bitmap.getHeight());
395
		paint.setTextSize(textSize); //图片宽度的20分之一作为字体大小
396
397
		// 用path确定文字位置和方向
398
		Path path = new Path();
399
		double radians = Math.toRadians(angle);
400
		x -= textSize * Math.sin(radians);
401
		y += textSize * Math.cos(radians);
402
		path.moveTo(x, y);
403
		int textLength = (int) paint.measureText(text);
404
		x += textLength;
405
		y += textLength * Math.tan(radians);
406
		path.lineTo(x, y);
407
408
		canvas.drawTextOnPath(text, path, 0, 0, paint);
409
		result = saveBmpFile(bitmap);
410
		return result;
411
	}
412
413
	/**
414
	 * 平铺模式添加文字水印
415
	 * @param picPath
416
	 * @param text
417
	 * @param textSizeRatio
418
	 * @param textColor
419
	 * @param angle
420
	 * @param rowSpaceRatio
421
	 * @param colSpaceRatio
422
	 * @return
423
	 */
424
	private String addText(String picPath, String text, double textSizeRatio, String textColor, double angle, double rowSpaceRatio, double colSpaceRatio) {
425
		String result;
426
		Bitmap bitmap = BitmapFactory.decodeFile(picPath);
427
		bitmap = bitmap.copy(bitmap.getConfig(), true);
428
		int picWidth = bitmap.getWidth();
429
		int picHeight = bitmap.getHeight();
430
		Canvas canvas = new Canvas(bitmap);
431
		Paint paint = new Paint();
432
		paint.setColor(textColor == null ? DEFAULT_COLOR : Color.parseColor(textColor)); //默认灰色
433
		int textSize = (int) (textSizeRatio * picWidth);
434
		paint.setTextSize(textSize);
435
		canvas.translate(picWidth / 2, picHeight / 2);
436
		canvas.rotate((float) angle);
437
438
		int textWidth = (int) paint.measureText(text);
439
		int l = Math.max(picHeight, picWidth) * 3 / 2;
440
		int colSpace = (int) (rowSpaceRatio * picWidth);
441
		int rowSpace = (int) (colSpaceRatio * picHeight);
442
		for (int x = -l/2; x<l/2; x+=colSpace+textWidth) {
443
			for(int y=-l/2;y<l/2;y+=rowSpace) {
444
				canvas.drawText(text, x, y, paint);
445
			}
446
		}
447
		result = saveBmpFile(bitmap);
448
		return result;
449
	}
450
451
	/**
452
    * @param path 原图片路径
453
    * @param waterPath 水印图片路径
454
    * @param x 水印图片左边位置,值为占整个图片的宽的比例
455
    * @param y 水印图片上边位置,值为占整个图片的高的比例
456
    * @param width 水印图片宽度,值为占整个图片的宽的比例
457
    * @return 加了水印的图片路径
458
    */
459
   private String addWaterMark(String path, String waterPath, double x, double y, double width) throws Exception {
460
       Bitmap bitmap1 = BitmapFactory.decodeFile(path);
461
       Bitmap bitmap2 = BitmapFactory.decodeFile(waterPath);
462
       bitmap1 = bitmap1.copy(bitmap1.getConfig(), true);
463
       Canvas canvas = new Canvas(bitmap1);
464
465
       Rect rect = buildRect(bitmap1, bitmap2, x, y, width);
466
       canvas.drawBitmap(bitmap2, null, rect, null);
467
468
       String res = saveBmpFile(bitmap1);
469
470
       return res;
471
   }
472
473
	/**
474
	 * 将bitmap保存到ipu应用的image目录,命名为“日期-mark.png”
475
	 * @param bitmap
476
	 * @return 文件路径,失败返回null
477
	 */
478
	String saveBmpFile(Bitmap bitmap) {
479
	   String fileName = format.format(new Date()) + "-mark.png";
480
	   File f = new File(DirectionUtil.getInstance(context).getImageDirection(true), fileName);
481
	   if (!f.getParentFile().exists()) {
482
		   f.getParentFile().mkdirs();
483
	   }
484
	   String res = f.getAbsolutePath();
485
	   BufferedOutputStream bos = null;
486
		FileOutputStream outputStream = null;
487
	   try {
488
		   outputStream = new FileOutputStream(f);
489
		   bos = new BufferedOutputStream(outputStream);
490
		   bitmap.compress(Bitmap.CompressFormat.PNG, 100, bos);
491
	   } catch (FileNotFoundException e) {
492
		   Log.e(TAG, "addWaterMark: ", e);
493
		   res = null;
494
	   } finally {
495
		   if (bos != null) {
496
			   try {
497
				   bos.close();
498
			   } catch (IOException e) {
499
				   Log.e(TAG, "addWaterMark: ", e);
500
			   }
501
		   }
502
		   if (outputStream != null) {
503
			   try {
504
				   outputStream.close();
505
			   } catch (IOException e) {
506
				   Log.e(TAG, "addWaterMark: ", e);
507
			   }
508
		   }
509
	   }
510
511
	   return res;
512
   }
513
514
   private Rect buildRect(Bitmap pic, Bitmap mark, double xPercent, double yPercent, double wPercent) throws Exception {
515
       xPercent = fixIn1(xPercent);
516
       yPercent = fixIn1(yPercent);
517
       wPercent = fixIn1(wPercent);
518
       int w = pic.getWidth();
519
       int h = pic.getHeight();
520
       int l = (int) (w * xPercent);
521
       int t = (int) (h * yPercent);
522
       int r = (int) (w * wPercent + l);
523
       int b = (int) (w * wPercent * mark.getHeight() / mark.getWidth() + t);
524
525
       Rect rect = new Rect(l, t, r, b);
526
       return rect;
527
   }
528
529
   private double fixIn1(double v) {
530
       if (v > 1) v = 1;
531
       if (v < 0) v = 0;
532
       return v;
533
   }
291 534
}

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

@ -19,6 +19,7 @@ import android.app.TimePickerDialog;
19 19
import android.content.DialogInterface;
20 20
import android.content.Intent;
21 21
import android.graphics.Color;
22
import android.util.Log;
22 23
import android.view.Gravity;
23 24
import android.view.View;
24 25
import android.webkit.WebView;
@ -35,6 +36,7 @@ import com.ai.ipu.mobile.common.contacts.util.ContactsConstant;
35 36
import com.ai.ipu.mobile.frame.IIpuMobile;
36 37
import com.ai.ipu.mobile.frame.activity.IpuMobileActivity;
37 38
import com.ai.ipu.mobile.frame.client.IpuWebViewClient;
39
import com.ai.ipu.mobile.frame.client.MobileClient;
38 40
import com.ai.ipu.mobile.frame.config.ServerPageConfig;
39 41
import com.ai.ipu.mobile.frame.event.IKeyListenerEvent.Action;
40 42
import com.ai.ipu.mobile.frame.event.impl.TemplateWebViewEvent;
@ -45,6 +47,7 @@ import com.ai.ipu.mobile.ui.HintUtil;
45 47
import com.ai.ipu.mobile.ui.UiTool;
46 48
import com.ai.ipu.mobile.ui.activity.CustomDialogActivity;
47 49
import com.ai.ipu.mobile.ui.activity.CustomWindowActivity;
50
import com.ai.ipu.mobile.ui.activity.IpuUrlActivity;
48 51
import com.ai.ipu.mobile.ui.activity.SlidingMenuActivity;
49 52
import com.ai.ipu.mobile.ui.anim.AnimationResource;
50 53
import com.ai.ipu.mobile.ui.build.dialog.progressdialog.SimpleProgressDialog;
@ -120,6 +123,23 @@ public class MobileUI extends Plugin {
120 123
        startActivityForResult(intent, REQUEST_CODE_OPEN_URL);
121 124
    }
122 125
	
126
	/**
127
	 * 关闭当前IpuUrlActivity,可传递参数到之前调用openUrl的回调
128
	 * @param param 
129
	 * @throws Exception
130
	 */
131
	public void closeUrl(JSONArray param) throws Exception {
132
        String resultData = param.getString(0);
133
        resultData = isNull(resultData) ? null : resultData;
134
        
135
        int resultState = param.optInt(1, IpuUrlActivity.SUCCESS_CODE);
136
        if (context instanceof IpuUrlActivity) {
137
            ((IpuUrlActivity) context).closeUrl(resultData, resultState);
138
        } else {
139
            HintUtil.tip(context, "没有调用openUrl");
140
        }
141
    }
142
	
123 143
    public void openUrlWithPlug(JSONArray array){
124 144
        try {
125 145
            String url = array.getString(0);
@ -560,9 +580,15 @@ public class MobileUI extends Plugin {
560 580
		final String msg = isNull(message) ? Messages.DIALOG_LOADING : message;
561 581
		Runnable runnable = new Runnable() {
562 582
			private void clear() {
583
				if(!MobileClient.isActivityrunning(context)){
584
					progressDialog = null;
585
				}
563 586
				if (progressDialog != null
564 587
						&& progressDialog.getProgressDialog().isShowing()) {
565
					progressDialog.getProgressDialog().dismiss();
588
					try {
589
						progressDialog.getProgressDialog().dismiss();
590
					} catch (Exception e) {
591
					}
566 592
					progressDialog = null;
567 593
				}
568 594
			}
@ -594,35 +620,47 @@ public class MobileUI extends Plugin {
594 620
										clear();// 设置取消按钮的事件,可以让setCancelable(false)也失效
595 621
									}
596 622
								});
597
				MobileUI.progressDialog.build().show();
623
				if(MobileClient.isActivityrunning(context)){
624
					try {
625
						MobileUI.progressDialog.build().show();
626
					} catch (Exception e) {
627
					}
628
				}
598 629
			}
599 630
		};
600 631
		this.context.runOnUiThread(runnable);
601 632
	}
602 633

603 634
	public void loadingStop(JSONArray param) throws Exception {
604
		int count = 0;
605
		while (!loadingStop()) {
606
			Thread.sleep(500);
607
			count++;
608
			if (count > 3) {
609
				break;
610
			}
611
		}
635
		loadingStop();
612 636
	}
613 637

614 638
	/**
615 639
	 * JS Loading效果关闭
616 640
	 */
617
	public boolean loadingStop() {
618
		if (progressDialog != null
619
				&& progressDialog.getProgressDialog().isShowing()) {
620
			progressDialog.getProgressDialog().dismiss();
621
			progressDialog = null;
622
			return true;
623
		} else {
624
			return false;
625
		}
641
	public void loadingStop() {
642
		Runnable runnable = new Runnable() {
643
			
644
			@Override
645
			public void run() {
646
				if(!MobileClient.isActivityrunning(context)){
647
					progressDialog = null;
648
				}
649
				if (progressDialog != null
650
						&& progressDialog.getProgressDialog().isShowing()) {
651
					try {
652
						progressDialog.getProgressDialog().dismiss();
653
					} catch (Exception e) {
654
					}
655
					progressDialog = null;
656
					return;
657
				} else {
658
					return;
659
				}
660
			}
661
		};
662
		context.runOnUiThread(runnable);
663
		
626 664
	}
627 665

628 666
	public void confirm(JSONArray param) throws Exception {
@ -1086,7 +1124,13 @@ public class MobileUI extends Plugin {
1086 1124
			data.put("COLOR", record.getColor());
1087 1125
			callback(data.toString());
1088 1126
		} else if (requestCode == REQUEST_CODE_OPEN_URL) {
1089
		    callback("");
1127
		    String resultData = null;
1128
		    if (intent != null) {
1129
		        resultData = intent
1130
	                    .getStringExtra(CustomWindowActivity.KEY_RESULT);
1131
		    }
1132
		    callback(resultData);
1133
		    
1090 1134
		}
1091 1135
	}
1092 1136
	

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

@ -67,7 +67,7 @@ public class MobileVideo extends Plugin {
67 67
		// set the video file name
68 68
		intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
69 69
		// set the video quality high
70
		intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
70
		intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, compressRatioDouble);
71 71
		// 限制时长
72 72
		intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, timeLimitInt);
73 73
		// start the video capture Intent