|
|
@@ -2,6 +2,7 @@ package com.uas.appme.settings.activity;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
import android.app.AlertDialog;
|
|
|
+import android.app.ProgressDialog;
|
|
|
import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.net.Uri;
|
|
|
@@ -9,14 +10,35 @@ import android.os.Bundle;
|
|
|
import android.view.View;
|
|
|
import android.widget.ImageView;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.common.LogUtil;
|
|
|
+import com.common.data.JSONUtil;
|
|
|
+import com.common.data.ListUtils;
|
|
|
+import com.common.data.StringUtil;
|
|
|
import com.common.ui.CameraUtil;
|
|
|
+import com.common.ui.ProgressDialogUtil;
|
|
|
import com.core.app.MyApplication;
|
|
|
import com.core.base.BaseActivity;
|
|
|
+import com.core.net.http.ViewUtil;
|
|
|
+import com.core.utils.CommonUtil;
|
|
|
import com.core.utils.ToastUtil;
|
|
|
+import com.lidroid.xutils.HttpUtils;
|
|
|
+import com.lidroid.xutils.exception.HttpException;
|
|
|
+import com.lidroid.xutils.http.ResponseInfo;
|
|
|
+import com.lidroid.xutils.http.callback.RequestCallBack;
|
|
|
+import com.lidroid.xutils.http.client.HttpRequest;
|
|
|
+import com.me.network.app.http.HttpClient;
|
|
|
+import com.me.network.app.http.Method;
|
|
|
+import com.me.network.app.http.rx.ResultListener;
|
|
|
+import com.me.network.app.http.rx.ResultSubscriber;
|
|
|
import com.uas.appme.R;
|
|
|
import com.umeng.socialize.utils.Log;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* Created by FANGlh on 2017/10/10.
|
|
|
@@ -30,6 +52,7 @@ public class ImageSettingActivity extends BaseActivity implements View.OnClickLi
|
|
|
private static final int REQUEST_CODE_PICK_PHOTO = 2;//单选照片
|
|
|
private int Max_Size = 1;
|
|
|
private String photoselect=null;
|
|
|
+ private ProgressDialog mProgressDialog;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
@@ -40,10 +63,10 @@ public class ImageSettingActivity extends BaseActivity implements View.OnClickLi
|
|
|
}
|
|
|
|
|
|
private void initView() {
|
|
|
-
|
|
|
mImageIm = (ImageView) findViewById(R.id.image_im);
|
|
|
findViewById(R.id.image_tv).setOnClickListener(this);
|
|
|
findViewById(R.id.btn_save).setOnClickListener(this);
|
|
|
+ mProgressDialog = ProgressDialogUtil.init(mContext, null, getString(R.string.please_wait));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -51,9 +74,88 @@ public class ImageSettingActivity extends BaseActivity implements View.OnClickLi
|
|
|
if (v.getId() == R.id.image_tv){
|
|
|
showSelectPictureDialog();
|
|
|
}else if (v.getId() == R.id.btn_save){
|
|
|
+ doSaveImage();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ private void doSaveImage() {
|
|
|
+ if (StringUtil.isEmpty(photoselect)) return;
|
|
|
+ File waterBitmapToFile= new File(photoselect);
|
|
|
+ if (!waterBitmapToFile.isFile()){
|
|
|
+ return;
|
|
|
+ }else {
|
|
|
+ com.lidroid.xutils.http.RequestParams params = new com.lidroid.xutils.http.RequestParams();
|
|
|
+ params.addQueryStringParameter("master", CommonUtil.getSharedPreferences(ct, "erp_master"));
|
|
|
+ params.addHeader("Cookie", "JSESSIONID=" + CommonUtil.getSharedPreferences(ct, "sessionId"));
|
|
|
+ params.addBodyParameter("userid", MyApplication.getInstance().mLoginUser.getUserId());
|
|
|
+ params.addBodyParameter("file1", waterBitmapToFile);
|
|
|
+ String url = "http://113.105.74.140:8080/upload/UploadServlet";
|
|
|
+ final HttpUtils http = new HttpUtils();
|
|
|
+ http.send(HttpRequest.HttpMethod.POST, url, params, new RequestCallBack<String>() {
|
|
|
+ @Override
|
|
|
+ public void onStart() {
|
|
|
+ progressDialog.show();
|
|
|
+ ViewUtil.ToastMessage(ct, getString(com.uas.appworks.R.string.sending_picture)+"...");
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void onLoading(long total, long current, boolean isUploading) {
|
|
|
+ if (isUploading) {
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onSuccess(ResponseInfo<String> responseInfo) {
|
|
|
+ if (JSONUtil.validate(responseInfo.result) && JSON.parseObject(responseInfo.result).getBoolean("success")) {
|
|
|
+ LogUtil.prinlnLongMsg("UploadServlet", responseInfo.result + "");
|
|
|
+
|
|
|
+ try {
|
|
|
+ JSONObject object = JSON.parseObject(responseInfo.result);
|
|
|
+ JSONObject dataobject = object.getJSONObject("data");
|
|
|
+ if (dataobject == null) return;
|
|
|
+ JSONArray imagearray = dataobject.getJSONArray("images");
|
|
|
+ if (ListUtils.isEmpty(imagearray)) return;
|
|
|
+ String oUrl = imagearray.getJSONObject(0).getString("oUrl");
|
|
|
+ if (!StringUtil.isEmpty(oUrl))
|
|
|
+ doUpdateUrl(oUrl);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailure(HttpException error, String msg) {
|
|
|
+ ViewUtil.ToastMessage(ct, getString(com.uas.appworks.R.string.common_save_failed) + msg);
|
|
|
+ progressDialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+ private void doUpdateUrl(String oUrl) {
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("sc_imageurl",oUrl);
|
|
|
+ params.put("sc_uu",201);
|
|
|
+// params.put("sc_uu", CommonUtil.getSharedPreferences(MyApplication.getInstance().getApplicationContext(), "erp_uu"));
|
|
|
+ HttpClient httpClient = new HttpClient.Builder("http://113.105.74.140:8092/").isDebug(true).build(true);
|
|
|
+ httpClient.Api().send(new HttpClient.Builder()
|
|
|
+ .url("user/appStorurl")
|
|
|
+ .add("map",JSONUtil.map2JSON(params))
|
|
|
+ .add("token",MyApplication.getInstance().mAccessToken)
|
|
|
+ .method(Method.POST)
|
|
|
+ .build(),new ResultSubscriber<>(new ResultListener<Object>() {
|
|
|
+ @Override
|
|
|
+ public void onResponse(Object o) {
|
|
|
+ LogUtil.prinlnLongMsg("hi/appStorurl", o.toString()+"ddd");
|
|
|
+ if (!JSONUtil.validate(o.toString()) || o == null) return;
|
|
|
+ if (o.toString().contains("result") && JSON.parseObject(o.toString()).getBoolean("result")){
|
|
|
+ ToastMessage(getString(R.string.common_save_success));
|
|
|
+ progressDialog.dismiss();
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }));
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -88,7 +190,6 @@ public class ImageSettingActivity extends BaseActivity implements View.OnClickLi
|
|
|
|
|
|
private void showSelectPictureDialog() {
|
|
|
String[] items = new String[]{getString(com.uas.appworks.R.string.c_take_picture), getString(com.uas.appworks.R.string.c_photo_album)};
|
|
|
-// String[] items = new String[]{getString(R.string.c_take_picture)};
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this).setSingleChoiceItems(items, 0,
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
@Override
|