Просмотр исходного кода

插件模块改造-mobileBasic功能移出&更新func包

leijie лет назад: 8
Родитель
Сommit
aa1b900749

+ 4 - 4
display-client/assets/mobile-action.xml

@ -1,10 +1,10 @@
1 1
<?xml version="1.0" encoding="UTF-8"?>
2 2
<actions>
3 3
    <!-- MobileBasic -->
4
	<action name="call" class="com.wade.mobile.func.MobileBasic" method="call"/>
5
	<action name="beep" class="com.wade.mobile.func.MobileBasic" method="beep"/>
6
	<action name="sms" class="com.wade.mobile.func.MobileBasic" method = "sms"/>
7
	<action name="shock" class="com.wade.mobile.func.MobileBasic" method="shock"/>
4
	<action name="call" class="com.ai.ipu.func.MobileBasic" method="call"/>
5
	<action name="beep" class="com.ai.ipu.func.MobileBasic" method="beep"/>
6
	<action name="sms" class="com.ai.ipu.func.MobileBasic" method = "sms"/>
7
	<action name="shock" class="com.ai.ipu.func.MobileBasic" method="shock"/>
8 8
	<!-- MobileApp -->
9 9
	<action name="close" class="com.wade.mobile.func.MobileApp" method="close"/>
10 10
	<action name="logCat" class="com.wade.mobile.func.MobileApp" method="logCat"/>

BIN
wade-mobile-common/libs/wade-mobile-func.jar


+ 0 - 151
wade-mobile-func/src/com/wade/mobile/func/MobileBasic.java

@ -1,151 +0,0 @@
1
package com.wade.mobile.func;
2

3
import java.util.ArrayList;
4

5
import org.json.JSONArray;
6

7
import android.app.PendingIntent;
8
import android.content.Context;
9
import android.content.Intent;
10
import android.media.Ringtone;
11
import android.media.RingtoneManager;
12
import android.net.Uri;
13
import android.os.Vibrator;
14
import android.telephony.SmsManager;
15
import android.widget.Toast;
16

17
import com.wade.mobile.frame.IWadeMobile;
18
import com.wade.mobile.frame.plugin.Plugin;
19
import com.wade.mobile.util.Constant;
20
import com.wade.mobile.util.Messages;
21

22
public class MobileBasic extends Plugin {
23

24
	public MobileBasic(IWadeMobile wademobile) {
25
		super(wademobile);
26
	}
27

28
	public void call(JSONArray param) throws Exception {
29
		if(param.length()<2){
30
			throw new Exception(Messages.EXCEPTION_PARAM);
31
		}
32
		String sn = param.getString(0);
33
		boolean flag  = param.getBoolean(1);
34
		call(sn, flag);
35
	}
36
	
37
	/**
38
	 * 呼出电话
39
	 * @param sn
40
	 */
41
	public void call(String sn,boolean autoCall) {
42
		if(autoCall){
43
			/**权限:android.permission.CALL_PHONE*/
44
			Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+ sn));
45
			this.context.startActivity(intent);
46
		}else{
47
			/**Intent.ACTION_CALL|Intent.ACTION_DIAL*/
48
			Intent intent = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+ sn));
49
			this.context.startActivity(intent);
50
		}
51
	}
52
	
53
	public void sms(JSONArray param) throws Exception {
54
		if(param.length()<3){
55
			throw new Exception(Messages.EXCEPTION_PARAM);
56
		}
57
		String sn = param.getString(0);
58
		String message = param.getString(1);
59
		boolean flag  = param.getBoolean(2);
60
		sms(sn,message, flag);
61
	}
62
	
63
	/**
64
	 * 短信
65
	 */
66
	public void sms(String sn,String message,boolean flag) {
67
		if(flag){
68
			/**权限:android.permission.SEND_SMS*/
69
			Intent intent = new Intent(Intent.ACTION_SENDTO);
70
			SmsManager smsManager = SmsManager.getDefault();   
71
	        PendingIntent pi = PendingIntent.getActivity(this.context, 0, intent, 0);   
72
	        //短信内容长度超过70则分多条发送
73
	        if (message.length() > 70){
74
	            ArrayList<String> msgs = smsManager.divideMessage(message);   
75
	            for (String msg : msgs){   
76
	                smsManager.sendTextMessage(sn, null, msg, pi, null);   
77
	            }
78
	        }else{   
79
	            smsManager.sendTextMessage(sn, null, message, pi, null);   
80
	        }
81
	        if(message.length()>30){
82
	        	message = message.substring(0,30)+"……"+Constant.LINE_SEPARATOR+Messages.SMS_SUCCESS;
83
	        }else{
84
	        	message = message+Constant.LINE_SEPARATOR+Messages.SMS_SUCCESS;
85
	        }
86
	        Toast.makeText(this.context, message, Toast.LENGTH_SHORT).show();
87
		}else{
88
			Intent intent = new Intent(Intent.ACTION_VIEW);
89
			intent.setData(Uri.parse("sms:"+ sn));
90
			intent.putExtra("address", sn);
91
			intent.putExtra("sms_body", message); 
92
			intent.setType("vnd.android-dir/mms-sms");
93
			this.context.startActivity(intent);
94
		}
95
	}
96
	
97
	public void beep(JSONArray param) throws Exception {
98
		if(param.length()<1){
99
			throw new Exception(Messages.EXCEPTION_PARAM);
100
		}
101
		long count = param.getLong(0);
102
		beep(count);
103
	}
104
	
105
	/**
106
	 * 响铃
107
	 */
108
	public void beep(long count) {
109
		Uri ringtone = RingtoneManager
110
				.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
111
		Ringtone notification = RingtoneManager.getRingtone(this.context,
112
				ringtone);
113

114
		// If phone is not set to silent mode
115
		if (notification != null) {
116
			for (long i = 0; i < count; i++) {
117
				notification.play();
118
				long timeout = 5000;
119
				while (notification.isPlaying() && (timeout > 0)) {
120
					timeout = timeout - 100;
121
					try {
122
						Thread.sleep(100);
123
					} catch (InterruptedException e) {
124
					}
125
				}
126
			}
127
		}
128
	}
129
	
130
	public void shock(JSONArray param) throws Exception {
131
		if(param.length()<1){
132
			throw new Exception(Messages.EXCEPTION_PARAM);
133
		}
134
		long time = param.getLong(0);
135
		shock(time);
136
	}
137
	
138
	/**
139
	 * 震动
140
	 */
141
	public void shock(long time) {
142
		// Start the vibration, 0 defaults to half a second.
143
		if (time < 500) {
144
			time = 500;
145
		} else if (time > 10000) {
146
			time = 10000;
147
		}
148
		Vibrator vibrator = (Vibrator) this.context.getSystemService(Context.VIBRATOR_SERVICE);
149
		vibrator.vibrate(time);
150
	}
151
}