|
@ -20,7 +20,9 @@ import android.os.Environment;
|
20
|
20
|
import android.os.Handler;
|
21
|
21
|
import android.os.Message;
|
22
|
22
|
import android.provider.MediaStore;
|
|
23
|
|
23
|
24
|
import androidx.appcompat.app.AlertDialog;
|
|
25
|
|
24
|
26
|
import android.text.Editable;
|
25
|
27
|
import android.text.Html;
|
26
|
28
|
import android.text.TextUtils;
|
|
@ -58,6 +60,7 @@ import com.electric.chargingpile.util.Bimp;
|
58
|
60
|
import com.electric.chargingpile.util.CommonParams;
|
59
|
61
|
import com.electric.chargingpile.util.DateUtils;
|
60
|
62
|
import com.electric.chargingpile.util.DensityUtil;
|
|
63
|
import com.electric.chargingpile.util.FileUtils;
|
61
|
64
|
import com.electric.chargingpile.util.ImageItem;
|
62
|
65
|
import com.electric.chargingpile.util.JsonUtils;
|
63
|
66
|
import com.electric.chargingpile.util.LoadingDialog;
|
|
@ -71,6 +74,10 @@ import com.upyun.library.common.ParallelUploader;
|
71
|
74
|
import com.upyun.library.common.UploadEngine;
|
72
|
75
|
import com.upyun.library.listener.UpCompleteListener;
|
73
|
76
|
import com.upyun.library.listener.UpProgressListener;
|
|
77
|
import com.zhihu.matisse.Matisse;
|
|
78
|
import com.zhihu.matisse.MimeType;
|
|
79
|
import com.zhihu.matisse.engine.impl.GlideEngine;
|
|
80
|
import com.zhihu.matisse.internal.entity.CaptureStrategy;
|
74
|
81
|
import com.zhy.http.okhttp.OkHttpUtils;
|
75
|
82
|
import com.zhy.http.okhttp.callback.StringCallback;
|
76
|
83
|
|
|
@ -145,6 +152,8 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
|
145
|
152
|
private ProgressDialog uploadDialog;
|
146
|
153
|
private PublishItemSerializable intentData;
|
147
|
154
|
|
|
155
|
public static final int REQUEST_CODE_CHOOSE = 342;
|
|
156
|
|
148
|
157
|
|
149
|
158
|
@Override
|
150
|
159
|
protected void onCreate(Bundle savedInstanceState) {
|
|
@ -175,11 +184,6 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
|
175
|
184
|
if (parallelUploader == null) {
|
176
|
185
|
parallelUploader = new ParallelUploader();
|
177
|
186
|
}
|
178
|
|
//图文路径
|
179
|
|
// String p = "/d/file/liaoliao/img/" + y + "/" + m + "/" + d;
|
180
|
|
//视频路径
|
181
|
|
// p = "/d/file/liaoliao/video/" + y + "/" + m + "/" + d;
|
182
|
|
|
183
|
187
|
}
|
184
|
188
|
|
185
|
189
|
private void initView() {
|
|
@ -209,12 +213,10 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
|
209
|
213
|
}
|
210
|
214
|
}
|
211
|
215
|
|
212
|
|
// dialog.show();
|
213
|
216
|
MobclickAgent.onEvent(getApplicationContext(), "1035");
|
214
|
217
|
uploadDialog.show();
|
215
|
218
|
//获取又拍云数据
|
216
|
219
|
getYouPaiData();
|
217
|
|
|
218
|
220
|
}
|
219
|
221
|
});
|
220
|
222
|
rl_point = (RelativeLayout) findViewById(R.id.rl_point);
|
|
@ -253,27 +255,6 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
|
253
|
255
|
et_context.setSelection(500);
|
254
|
256
|
}
|
255
|
257
|
|
256
|
|
// if (containsEmoji(s)) {
|
257
|
|
// tv_right.setEnabled(false);
|
258
|
|
// tv_right.setTextColor(getResources().getColor(R.color.ui_68));
|
259
|
|
// ToastUtil.showToast(getApplicationContext(), "不支持输入表情", Toast.LENGTH_SHORT);
|
260
|
|
// return;
|
261
|
|
// }
|
262
|
|
// if (s.length() > 500) {
|
263
|
|
// tv_right.setEnabled(false);
|
264
|
|
// tv_right.setBackgroundColor(Color.parseColor("color_9ed3ae"));
|
265
|
|
//// tv_right.setTextColor(getResources().getColor(R.color.ui_68));
|
266
|
|
// ToastUtil.showToast(getApplicationContext(), "输入字数不能超过500", Toast.LENGTH_SHORT);
|
267
|
|
// return;
|
268
|
|
// }
|
269
|
|
// if (!s.trim().isEmpty() && s.length() > 0 && null != Bimp.tempSelectBitmap && Bimp.tempSelectBitmap.size() > 0) {
|
270
|
|
// tv_right.setEnabled(true);
|
271
|
|
// tv_right.setBackgroundColor(Color.parseColor("#02b637"));
|
272
|
|
// } else {
|
273
|
|
// tv_right.setEnabled(false);
|
274
|
|
// tv_right.setBackgroundColor(Color.parseColor("#9ed3ae"));
|
275
|
|
// }
|
276
|
|
|
277
|
258
|
if (TextUtils.isEmpty(s))
|
278
|
259
|
publishtopic_word_num.setText("0");
|
279
|
260
|
else
|
|
@ -298,8 +279,6 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
|
298
|
279
|
for (int i = 0; i < Bimp.tempSelectBitmap.size(); i++) {
|
299
|
280
|
|
300
|
281
|
ImageItem imageItem = Bimp.tempSelectBitmap.get(i);
|
301
|
|
// String fileNameDir = Bimp.tempSelectBitmap.get(i).getImagePath();
|
302
|
|
// String fileName = fileNameDir.substring(fileNameDir.lastIndexOf("/") + 1);
|
303
|
282
|
if (TextUtils.isEmpty(fileNames)) {
|
304
|
283
|
fileNames = imageItem.fName;
|
305
|
284
|
} else {
|
|
@ -332,7 +311,7 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
|
332
|
311
|
for (int i = 0; i < publishCount; i++) {
|
333
|
312
|
String sign = signBeans.get(i).sign;
|
334
|
313
|
String policy = signBeans.get(i).policy;
|
335
|
|
formUpload(Bimp.tempSelectBitmap.get(i).getImagePath(), sign, policy);
|
|
314
|
formUpload(Bimp.tempSelectBitmap.get(i).getFile(), sign, policy);
|
336
|
315
|
}
|
337
|
316
|
}
|
338
|
317
|
} else if ("8010".equals(code)) {
|
|
@ -509,14 +488,14 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
|
509
|
488
|
*/
|
510
|
489
|
private void callGallery() {
|
511
|
490
|
MobclickAgent.onEvent(getApplicationContext(), "1024");
|
512
|
|
Log.e(TAG, "callGallery: " + (Bimp.max - Bimp.tempSelectBitmap.size()));
|
513
|
|
//调用第三方图库选择
|
514
|
|
PhotoPicker.builder()
|
515
|
|
.setPhotoCount(PIC_NUM - Bimp.tempSelectBitmap.size())//可选择图片数量
|
516
|
|
.setShowCamera(true)//是否显示拍照按钮
|
517
|
|
.setShowGif(true)//是否显示动态图
|
518
|
|
.setPreviewEnabled(true)//是否可以预览
|
519
|
|
.start(this, PhotoPicker.REQUEST_CODE);
|
|
491
|
Matisse.from(PublishPicTopicActivity.this)
|
|
492
|
.choose(MimeType.of(MimeType.JPEG, MimeType.PNG, MimeType.GIF))
|
|
493
|
.countable(true)
|
|
494
|
.maxSelectable(PIC_NUM - Bimp.tempSelectBitmap.size())
|
|
495
|
.capture(true)
|
|
496
|
.captureStrategy(new CaptureStrategy(true, "com.electric.chargingpile.provider"))
|
|
497
|
.imageEngine(new GlideEngine())
|
|
498
|
.forResult(REQUEST_CODE_CHOOSE);
|
520
|
499
|
}
|
521
|
500
|
|
522
|
501
|
@Override
|
|
@ -534,7 +513,7 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
|
534
|
513
|
if (data != null) {
|
535
|
514
|
if (requestCode == 1) {
|
536
|
515
|
//处理调用系统图库
|
537
|
|
} else if (requestCode == PhotoPicker.REQUEST_CODE) {
|
|
516
|
} else if (requestCode == REQUEST_CODE_CHOOSE) {
|
538
|
517
|
MobclickAgent.onEvent(getApplicationContext(), "1026");
|
539
|
518
|
//异步方式插入图片
|
540
|
519
|
insertImagesSync(data);
|
|
@ -554,13 +533,14 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
|
554
|
533
|
@Override
|
555
|
534
|
public void subscribe(ObservableEmitter<String> subscriber) throws Exception {
|
556
|
535
|
try {
|
557
|
|
ArrayList<String> photos = data.getStringArrayListExtra(PhotoPicker.KEY_SELECTED_PHOTOS);
|
558
|
|
//可以同时插入多张图片
|
|
536
|
List<Uri> uriList = Matisse.obtainResult(data);
|
559
|
537
|
int i = 0;
|
560
|
|
for (String imagePath : photos) {
|
|
538
|
for (Uri uri : uriList) {
|
561
|
539
|
i++;
|
562
|
|
Log.e(TAG, "call: imagePath " + imagePath);
|
563
|
|
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);//压缩图片
|
|
540
|
Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
|
|
541
|
File file = FileUtils.from(PublishPicTopicActivity.this, uri);
|
|
542
|
|
|
543
|
bitmap = FileUtils.rotateIfRequired(file, bitmap);
|
564
|
544
|
bitmap = imageZoom(bitmap);
|
565
|
545
|
ImageItem takePhoto = new ImageItem();
|
566
|
546
|
String deviceId = JPushInterface.getUdid(MainApplication.context);
|
|
@ -572,17 +552,15 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
|
572
|
552
|
}
|
573
|
553
|
takePhoto.fName += "_00" + i;
|
574
|
554
|
|
575
|
|
String suffix = imagePath.substring(imagePath.lastIndexOf(".") + 1);
|
|
555
|
String filePath = file.getAbsolutePath();
|
|
556
|
String suffix = filePath.substring(filePath.lastIndexOf(".") + 1);
|
576
|
557
|
takePhoto.fName += "." + suffix;
|
577
|
|
|
578
|
558
|
takePhoto.setBitmap(bitmap);
|
579
|
|
takePhoto.setImagePath(imagePath);
|
580
|
|
|
|
559
|
takePhoto.setFile(file);
|
581
|
560
|
Bimp.tempSelectBitmap.add(takePhoto);
|
582
|
|
subscriber.onNext(imagePath);
|
|
561
|
subscriber.onNext("");
|
583
|
562
|
}
|
584
|
563
|
subscriber.onComplete();
|
585
|
|
|
586
|
564
|
} catch (Exception e) {
|
587
|
565
|
e.printStackTrace();
|
588
|
566
|
subscriber.onError(e);
|
|
@ -870,14 +848,17 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
|
870
|
848
|
this, "充电桩想要获取您的图片读取权限,是否允许?",
|
871
|
849
|
RC_ALBUM_PERM,
|
872
|
850
|
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
873
|
|
Manifest.permission.READ_EXTERNAL_STORAGE);
|
|
851
|
Manifest.permission.READ_EXTERNAL_STORAGE,
|
|
852
|
Manifest.permission.CAMERA
|
|
853
|
);
|
874
|
854
|
}
|
875
|
855
|
}
|
876
|
856
|
|
877
|
857
|
private boolean isPermissionOK() {
|
878
|
858
|
return EasyPermissions.hasPermissions(this,
|
879
|
859
|
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
880
|
|
Manifest.permission.READ_EXTERNAL_STORAGE
|
|
860
|
Manifest.permission.READ_EXTERNAL_STORAGE,
|
|
861
|
Manifest.permission.CAMERA
|
881
|
862
|
);
|
882
|
863
|
}
|
883
|
864
|
|
|
@ -885,13 +866,10 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
|
885
|
866
|
/**
|
886
|
867
|
* 表单上传
|
887
|
868
|
*
|
888
|
|
* @param SAMPLE_PIC_FILE
|
889
|
869
|
* @param sign
|
890
|
870
|
* @param policyServer
|
891
|
871
|
*/
|
892
|
|
private void formUpload(String SAMPLE_PIC_FILE, String sign, String policyServer) {
|
893
|
|
File temp = new File(SAMPLE_PIC_FILE);
|
894
|
|
|
|
872
|
private void formUpload(File file, String sign, String policyServer) {
|
895
|
873
|
// //进度回调,可为空
|
896
|
874
|
UpProgressListener progressListener = new UpProgressListener() {
|
897
|
875
|
@Override
|
|
@ -929,7 +907,7 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
|
929
|
907
|
};
|
930
|
908
|
|
931
|
909
|
//表单上传(服务器签名方式)
|
932
|
|
UploadEngine.getInstance().formUpload(temp, policyServer, OPERATER, sign, completeListener,
|
|
910
|
UploadEngine.getInstance().formUpload(file, policyServer, OPERATER, sign, completeListener,
|
933
|
911
|
progressListener);
|
934
|
912
|
|
935
|
913
|
}
|