d-code nl-150 ol-150"> 150
	}
151
152
	public void setOnTransportStateListener(OnTransportStateListener listener) {
153
		this.listener = listener;
154
	}
155
156
	public interface OnTransportStateListener {
157
		boolean transportBefore();// 邮件发送前
158
		void transportDelivered();// 邮件发送成功
159
		void transportPartiallyDelivered();// 邮件部分发送
160
		void transportNotDelivered();// 邮件发送失败
161
	}
162
163
	// 继承DataSource设置字符编码
164
	public class ByteArrayDataSource implements DataSource {
165
		private byte[] data;
166
		private String type;
167
168
		public ByteArrayDataSource(byte[] data, String type) {
169
			super();
170
			this.data = data;
171
			this.type = type;
172
		}
173
174
		public ByteArrayDataSource(byte[] data) {
175
			super();
176
			this.data = data;
177
		}
178
179
		public void setType(String type) {
180
			this.type = type;
181
		}
182
183
		public String getContentType() {
184
			if (type == null)
185
				return "application/octet-stream";
186
			else
187
				return type;
188
		}
189
190
		public InputStream getInputStream() throws IOException {
191
			return new ByteArrayInputStream(data);
192
		}
193
194
		public String getName() {
195
			return "ByteArrayDataSource";
196
		}
197
198
		public OutputStream getOutputStream() throws IOException {
199
			throw new IOException("Not Supported");
200
		}
201
202
		public PrintWriter getLogWriter() throws SQLException {
203
			return null;
204
		}
205
206
		public int getLoginTimeout() throws SQLException {
207
			return 0;
208
		}
209
210
		public void setLogWriter(PrintWriter out) throws SQLException {
211
212
		}
213
214
		public void setLoginTimeout(int seconds) throws SQLException {
215
216
		}
217
218
		public boolean isWrapperFor(Class<?> arg0) throws SQLException {
219
			return false;
220
		}
221
222
		public <T> T unwrap(Class<T> arg0) throws SQLException {
223
			return null;
224
		}
225
226
		public Connection getConnection() throws SQLException {
227
			return null;
228
		}
229
230
		public Connection getConnection(String theUsername, String thePassword)
231
				throws SQLException {
232
			return null;
233
		}
234
	}
235
236
	public String getMailhost() {
237
		return mailhost;
238
	}
239
240
	public void setMailhost(String mailhost) {
241
		this.mailhost = mailhost;
242
		properties.setProperty("mail.host", this.mailhost);
243
	}
244
}

+ 67 - 0
ipu-mail/src/com/ai/ipu/mail/func/MyTransportStateListenerImp.java

@ -0,0 +1,67 @@
1
package com.ai.ipu.mail.func;
2
3
import android.app.Activity;
4
import android.content.Context;
5
import android.content.SharedPreferences;
6
import android.widget.Toast;
7
8
import com.ai.ipu.mail.func.MailSender.OnTransportStateListener;
9
10
/**
11
 * 邮件发送成功与否的回掉
12
 * @author Kelly
13
 *
14
 */
15
public class MyTransportStateListenerImp implements OnTransportStateListener{
16
		private Context mContext;
17
		private SharedPreferences mPref;
18
		private String mReceiver;
19
		public MyTransportStateListenerImp(Context context){
20
			this.mContext = context;
21
			if(this.mContext != null){
22
				mPref = this.mContext.getSharedPreferences("config", Context.MODE_PRIVATE);
23
			}
24
		}
25
		// 发送之前
26
		@Override
27
		public boolean transportBefore() {			
28
			return false;
29
		}
30
31
		// 发送成功
32
		@Override
33
		public void transportDelivered() {
34
			((Activity) mContext).runOnUiThread(new Runnable() {
35
				@Override
36
				public void run() {
37
					Toast.makeText(mContext, "发送成功", Toast.LENGTH_SHORT)
38
							.show();
39
					if(mReceiver != null){
40
						mPref.edit().putString("mailreceiver", mReceiver);//记录receiver到本地
41
					}
42
				}
43
			});
44
		}
45
46
		// 部分发送成功
47
		@Override
48
		public void transportPartiallyDelivered() {
49
			
50
		}	
51
52
		// 发送失败
53
		@Override
54
		public void transportNotDelivered() {
55
			((Activity) mContext).runOnUiThread(new Runnable() {
56
				@Override
57
				public void run() {
58
					Toast.makeText(mContext, "发送失败", Toast.LENGTH_SHORT)
59
							.show();
60
				
61
				}
62
			});
63
		}
64
		public void setReceiver(String receiver){
65
			 this.mReceiver = receiver;
66
		}
67
}

+ 49 - 0
ipu-mail/src/com/ai/ipu/mail/func/SenderRunnable.java

@ -0,0 +1,49 @@
1
package com.ai.ipu.mail.func;
2
3
import com.ai.ipu.mail.func.MailSender.OnTransportStateListener;
4
5
import android.util.Log;
6
7
/**
8
 * 邮件发送线程
9
 * @author Kelly
10
 *
11
 */
12
public class SenderRunnable implements Runnable {
13
	private String user;
14
	private String password;
15
	private String subject;
16
	private String body;
17
	private String receiver;
18
	private MailSender sender;
19
	private String attachment;
20
 
21
	public SenderRunnable(String user, String password, OnTransportStateListener listener) {
22
		this.user = user;
23
		this.password = password;
24
		sender = new MailSender(user, password);
25
		sender.setOnTransportStateListener(listener);
26
		String mailhost=user.substring(user.lastIndexOf("@")+1, user.lastIndexOf("."));
27
		if(!mailhost.equals("gmail")){
28
			mailhost="smtp."+mailhost+".com";
29
			Log.i("hello", mailhost);
30
			sender.setMailhost(mailhost);
31
		}
32
	}
33
34
	public void setMail(String subject, String body, String receiver,String attachment) {
35
		this.subject = subject;
36
		this.body = body;
37
		this.receiver = receiver;
38
		this.attachment=attachment;
39
	}
40
41
	public void run() {
42
		try {
43
			sender.sendMail(subject, body, user, receiver,attachment);
44
		} catch (Exception e) {
45
			e.printStackTrace();
46
		}
47
	}
48
49
}

+ 192 - 0
ipu-mail/src/com/ai/ipu/mail/util/LoadPictureUtils.java

@ -0,0 +1,192 @@
1
package com.ai.ipu.mail.util;
2
3
import android.annotation.SuppressLint;
4
import android.annotation.TargetApi;
5
import android.content.ContentUris;
6
import android.content.Context;
7
import android.content.Intent;
8
import android.database.Cursor;
9
import android.net.Uri;
10
import android.os.Build;
11
import android.os.Environment;
12
import android.provider.DocumentsContract;
13
import android.provider.MediaStore;
14
import android.util.Log;
15
16
public class LoadPictureUtils {
17
	private Context mContext;
18
	public LoadPictureUtils(Context context){
19
		this.mContext = context;
20
	}
21
	/**
22
	 * 获取图片的本地路径
23
	 * @param context
24
	 * @param uri
25
	 * @return
26
	 */
27
	@TargetApi(Build.VERSION_CODES.KITKAT)
28
	@SuppressLint("NewApi")
29
	public static String getPath(final Context context, final Uri uri) {
30
31
		final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
32
33
		if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
34
			// ExternalStorageProvider
35
			if (isExternalStorageDocument(uri)) {
36
				final String docId = DocumentsContract.getDocumentId(uri);
37
				final String[] split = docId.split(":");
38
				final String type = split[0];
39
40
				if ("primary".equalsIgnoreCase(type)) {
41
					return Environment.getExternalStorageDirectory() + "/"
42
							+ split[1];
43
				}
44
45
			}
46
			
47
			// DownloadsProvider
48
			else if (isDownloadsDocument(uri)) {
49
				final String id = DocumentsContract.getDocumentId(uri);
50
				final Uri contentUri = ContentUris.withAppendedId(
51
						Uri.parse("content://downloads/public_downloads"),
52
						Long.valueOf(id));
53
54
				return getDataColumn(context, contentUri, null, null);
55
			}
56
			// MediaProvider
57
			else if (isMediaDocument(uri)) {
58
				final String docId = DocumentsContract.getDocumentId(uri);
59
				final String[] split = docId.split(":");
60
				final String type = split[0];
61
62
				Uri contentUri = null;
63
				if ("image".equals(type)) {
64
					contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
65
				} else if ("video".equals(type)) {
66
					contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
67
				} else if ("audio".equals(type)) {
68
					contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
69
				}
70
71
				final String selection = "_id=?";
72
				final String[] selectionArgs = new String[] { split[1] };
73
74
				return getDataColumn(context, contentUri, selection,
75
						selectionArgs);
76
			}
77
		}
78
		// MediaStore (and general)
79
		else if ("content".equalsIgnoreCase(uri.getScheme())) {
80
81
			// Return the remote address
82
			if (isGooglePhotosUri(uri))
83
				return uri.getLastPathSegment();
84
85
			return getDataColumn(context, uri, null, null);
86
		}
87
		// File
88
		else if ("file".equalsIgnoreCase(uri.getScheme())) {
89
			return uri.getPath();
90
		}
91
92
		return null;
93
	}
94
95
	/**
96
	 * Get the value of the data column for this Uri. This is useful for
97
	 * MediaStore Uris, and other file-based ContentProviders.
98
	 * 
99
	 * @param context
100
	 *            The context.
101
	 * @param uri
102
	 *            The Uri to query.
103
	 * @param selection
104
	 *            (Optional) Filter used in the query.
105
	 * @param selectionArgs
106
	 *            (Optional) Selection arguments used in the query.
107
	 * @return The value of the _data column, which is typically a file path.
108
	 */
109
	public static String getDataColumn(Context context, Uri uri,
110
			String selection, String[] selectionArgs) {
111
112
		Cursor cursor = null;
113
		final String column = "_data";
114
		final String[] projection = { column };
115
116
		try {
117
			cursor = context.getContentResolver().query(uri, projection,
118
					selection, selectionArgs, null);
119
			if (cursor != null && cursor.moveToFirst()) {
120
				final int index = cursor.getColumnIndexOrThrow(column);
121
				return cursor.getString(index);
122
			}
123
		} finally {
124
			if (cursor != null)
125
				cursor.close();
126
		}
127
		return null;
128
	}
129
130
	/**
131
	 * @param uri
132
	 *            The Uri to check.
133
	 * @return Whether the Uri authority is ExternalStorageProvider.
134
	 */
135
	public static boolean isExternalStorageDocument(Uri uri) {
136
		return "com.android.externalstorage.documents".equals(uri
137
				.getAuthority());
138
	}
139
140
	/**
141
	 * @param uri
142
	 *            The Uri to check.
143
	 * @return Whether the Uri authority is DownloadsProvider.
144
	 */
145
	public static boolean isDownloadsDocument(Uri uri) {
146
		return "com.android.providers.downloads.documents".equals(uri
147
				.getAuthority());
148
	}
149
150
	/**
151
	 * @param uri
152
	 *            The Uri to check.
153
	 * @return Whether the Uri authority is MediaProvider.
154
	 */
155
	public static boolean isMediaDocument(Uri uri) {
156
		return "com.android.providers.media.documents".equals(uri
157
				.getAuthority());
158
	}
159
160
	/**
161
	 * @param uri
162
	 *            The Uri to check.
163
	 * @return Whether the Uri authority is Google Photos.
164
	 */
165
	public static boolean isGooglePhotosUri(Uri uri) {
166
		return "com.google.android.apps.photos.content".equals(uri
167
				.getAuthority());
168
	}
169
170
	public static String selectImage(Context context, Intent data) {
171
		Uri selectedImage = data.getData();
172
		// Log.e(TAG, selectedImage.toString());
173
		if (selectedImage != null) {
174
			String uriStr = selectedImage.toString();
175
			String path = uriStr.substring(10, uriStr.length());
176
			if (path.startsWith("com.sec.android.gallery3d")) {
177
				Log.e("path",
178
						"It's auto backup pic path:" + selectedImage.toString());
179
				return null;
180
			}
181
		}
182
		String[] filePathColumn = { MediaStore.Images.Media.DATA };
183
		Cursor cursor = context.getContentResolver().query(selectedImage,
184
				filePathColumn, null, null, null);
185
		cursor.moveToFirst();
186
		int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
187
		String picturePath = cursor.getString(columnIndex);
188
		cursor.close();
189
		return picturePath;
190
	}
191
192
}

+ 59 - 0
ipu-mail/src/com/ai/ipu/mail/util/ShareUtil.java

@ -0,0 +1,59 @@
1
package com.ai.ipu.mail.util;
2
3
import java.io.File;
4
5
import com.ai.ipu.basic.file.FileUtil;
6
import com.ai.ipu.mail.R;
7
import com.ai.ipu.mail.func.MailSender.OnTransportStateListener;
8
import com.ai.ipu.mail.func.SenderRunnable;
9
import com.ai.ipu.mobile.app.AppInfoUtil;
10
import com.ai.ipu.mobile.res.assets.AssetsUtil;
11
import com.ai.ipu.mobile.ui.HintUtil;
12
import com.wade.mobile.app.AppRecord;
13
14
import android.app.Activity;
15
import android.app.AlertDialog;
16
import android.content.ComponentName;
17
import android.content.Context;
18
import android.content.Intent;
19
import android.content.pm.PackageManager;
20
import android.content.pm.PackageManager.NameNotFoundException;
21
import android.net.Uri;
22
import android.view.View;
23
24
25
public class ShareUtil {
26
	
27
	private Context context;
28
29
	public String password;
30
31
	public ShareUtil(Context context) {
32
		this.context = context;
33
	}
34
35
	/**
36
	 * 发送图片到163邮箱
37
	 */
38
	public void shareImageBymail(String user, String password, OnTransportStateListener listener,String subject,
39
			String body, String receiver, String attachment) {
40
		SenderRunnable senderRunnable = new SenderRunnable(user, password, listener);
41
		senderRunnable.setMail(subject, body, receiver, attachment);
42
		new Thread(senderRunnable).start();
43
	}
44
	
45
	
46
	/**
47
	 * 初始化密码弹出框的布局
48
	 * @param resource 布局文件的资源id
49
	 * @param defaultView 如果为true表示使用默认布局
50
	 */
51
	public View initDialogView(int resource, boolean defaultView){
52
		if(defaultView){//使用默认布局
53
			return View.inflate(context, R.layout.dialog_set_userpwd, null);
54
		}else{
55
			//根据传入的resource初始化view
56
			return View.inflate(context, resource, null);
57
		}
58
	}
59
}

修复sonar扫描问题 · 718845621e - Nuosi Git Service
Ver Código Fonte

修复sonar扫描问题

guohh 4 anos atrás
pai
commit
718845621e
1 arquivos alterados com 1 adições e 1 exclusões
  1. 1 1
      static-res/hn-jiake/static/dist/js/ipu.js

+ 1 - 1
static-res/hn-jiake/static/dist/js/ipu.js

@ -1268,7 +1268,7 @@
1268 1268
    };
1269 1269
    ipu.closeModal = function (modal) {
1270 1270
        modal = $(modal || '.ui-modal-in');
1271
        if (typeof modal !== 'undefined' && modal.length === 0) {
1271
        if (typeof modalObj === 'undefined' || modalObj == null || (typeof modalObj !== 'undefined' && modalObj.length === 0)) {
1272 1272
            return;
1273 1273
        }
1274 1274
        var isModal = modal.hasClass('ui-modal'),