|
|
@@ -1,20 +1,33 @@
|
|
|
package com.xzjmyk.pm.activity.ui.erp.activity.oa;
|
|
|
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
+import android.net.Uri;
|
|
|
import android.os.AsyncTask;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
import android.os.Message;
|
|
|
+import android.support.v7.app.AlertDialog;
|
|
|
import android.view.Menu;
|
|
|
import android.view.MenuItem;
|
|
|
+import android.view.View;
|
|
|
import android.widget.EditText;
|
|
|
+import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.lidroid.xutils.HttpUtils;
|
|
|
import com.lidroid.xutils.ViewUtils;
|
|
|
+import com.lidroid.xutils.exception.HttpException;
|
|
|
+import com.lidroid.xutils.http.RequestParams;
|
|
|
+import com.lidroid.xutils.http.ResponseInfo;
|
|
|
+import com.lidroid.xutils.http.callback.RequestCallBack;
|
|
|
+import com.lidroid.xutils.http.client.HttpRequest;
|
|
|
import com.lidroid.xutils.view.annotation.ViewInject;
|
|
|
+import com.nostra13.universalimageloader.core.ImageLoader;
|
|
|
import com.xzjmyk.pm.activity.MyApplication;
|
|
|
import com.xzjmyk.pm.activity.R;
|
|
|
import com.xzjmyk.pm.activity.bean.oa.OutSigninBean;
|
|
|
@@ -24,13 +37,19 @@ import com.xzjmyk.pm.activity.ui.erp.util.CodeUtil;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.CommonUtil;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.Constants;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.FlexJsonUtil;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.JsonValidator;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.StringUtils;
|
|
|
+import com.xzjmyk.pm.activity.util.CameraUtil;
|
|
|
import com.xzjmyk.pm.activity.util.TimeUtils;
|
|
|
import com.xzjmyk.pm.activity.util.ToastUtil;
|
|
|
-import com.xzjmyk.pm.activity.view.MyListView;
|
|
|
+import com.xzjmyk.pm.activity.view.crouton.Crouton;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
//外勤签到
|
|
|
public class OutSigninOKActivity extends BaseActivity {
|
|
|
@@ -42,9 +61,12 @@ public class OutSigninOKActivity extends BaseActivity {
|
|
|
private TextView com_tv;
|
|
|
@ViewInject(R.id.text_edit)
|
|
|
private EditText text_edit;
|
|
|
- @ViewInject(R.id.listview)
|
|
|
- private MyListView listview;
|
|
|
+ @ViewInject(R.id.image_tag)
|
|
|
+ private ImageView image_tag;
|
|
|
+ @ViewInject(R.id.image)
|
|
|
+ private ImageView image;
|
|
|
private String baseUrl;
|
|
|
+ private Uri mNewPhotoUri;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
@@ -64,10 +86,15 @@ public class OutSigninOKActivity extends BaseActivity {
|
|
|
CodeUtil.getInstance().getCode(ct, "mobile_outsign", new CodeUtil.OnCodeLinstener() {
|
|
|
@Override
|
|
|
public void callBack(String code) {
|
|
|
- doSignin(code);
|
|
|
+ doSignin(code, 0);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+// if (!StringUtils.isEmpty(path) && new File(path).isFile())
|
|
|
+// uploadFile(path);
|
|
|
+// else
|
|
|
+//
|
|
|
+// }
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
}
|
|
|
|
|
|
@@ -90,31 +117,132 @@ public class OutSigninOKActivity extends BaseActivity {
|
|
|
com_tv.setText(com);
|
|
|
task.execute();
|
|
|
addr_tv.setText(addr);
|
|
|
-// if (json != null)
|
|
|
-// listview.setAdapter(new SigninAdapter(json));
|
|
|
-// else
|
|
|
-// loadLog();
|
|
|
+ image_tag.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ showPopup();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- //获取打卡记录 date:yyyy-MM-dd
|
|
|
- private void loadLog() {
|
|
|
- progressDialog.show();
|
|
|
- //获取网络数据
|
|
|
- String url = CommonUtil.getSharedPreferences(ct, "erp_baseurl") + "mobile/common/list.action";
|
|
|
- String emcode = CommonUtil.getSharedPreferences(ct, "erp_username");
|
|
|
- final Map<String, Object> param = new HashMap<>();
|
|
|
- param.put("currentMaster", CommonUtil.getSharedPreferences(ct, "erp_master"));
|
|
|
- param.put("page", 1);
|
|
|
- param.put("pageSize", 1000);
|
|
|
- param.put("emcode", emcode);
|
|
|
- param.put("condition", "mo_mancode='" + emcode + "' and to_char(mo_signtime,'yyyy-MM-dd')='" + TimeUtils.s_long_2_str(System.currentTimeMillis()) + "'");
|
|
|
- param.put("caller", "Mobile_outsign");
|
|
|
- param.put("sessionId", CommonUtil.getSharedPreferences(ct, "sessionId"));
|
|
|
- LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
|
|
|
- headers.put("Cookie", "JSESSIONID=" + CommonUtil.getSharedPreferences(ct, "sessionId"));
|
|
|
- com.xzjmyk.pm.activity.ui.erp.util.ViewUtil.httpSendRequest(ct, url, param, handler, headers, 0x13, null, null, "get");
|
|
|
+ private static final int REQUEST_CODE_CAPTURE_PHOTO = 1;// 拍照
|
|
|
+ private static final int REQUEST_CODE_PICK_PHOTO = 2;// 图库
|
|
|
+ private String path = null;
|
|
|
+
|
|
|
+ private void showPopup() {
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(ct);
|
|
|
+ String[] items = {"拍照", "从照片中选择"};
|
|
|
+ builder.setTitle("选择操作");
|
|
|
+ builder.setItems(items, new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
+ if (i == 0) {
|
|
|
+ //调用拍照
|
|
|
+ mNewPhotoUri = CameraUtil.getOutputMediaFileUri(OutSigninOKActivity.this, CameraUtil.MEDIA_TYPE_IMAGE);
|
|
|
+ CameraUtil.captureImage(OutSigninOKActivity.this, mNewPhotoUri, REQUEST_CODE_CAPTURE_PHOTO);
|
|
|
+ } else if (i == 1) {
|
|
|
+ if (!CommonUtil.setSharedPreferences(ct, "isImage", false)) {
|
|
|
+ Crouton.makeText(ct, "您没有被允许使用系统相册,请使用拍照");
|
|
|
+ } else {
|
|
|
+ //调用系统相册
|
|
|
+ CameraUtil.pickImageSimple(OutSigninOKActivity.this, REQUEST_CODE_PICK_PHOTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ private int getID(String chche) {
|
|
|
+ if (StringUtils.isEmpty(chche)) return 0;
|
|
|
+ Pattern p = Pattern.compile("(\\d+)");
|
|
|
+ Matcher m = p.matcher(chche);
|
|
|
+ if (m.find()) {
|
|
|
+ return Integer.parseInt(m.group(0));
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ int id = 0;
|
|
|
+
|
|
|
+ private void uploadFile(String path) {
|
|
|
+ if (StringUtils.isEmpty(path)) return;
|
|
|
+ File finalFile = new File(path);
|
|
|
+ if (!finalFile.isFile()) return;
|
|
|
+ RequestParams params = new RequestParams();
|
|
|
+ params.addQueryStringParameter("master", CommonUtil.getSharedPreferences(ct, "erp_master"));
|
|
|
+ params.addHeader("Cookie", "JSESSIONID=" + CommonUtil.getSharedPreferences(ct, "sessionId"));
|
|
|
+ params.addBodyParameter("em_code", CommonUtil.getSharedPreferences(ct, "erp_username"));
|
|
|
+ params.addBodyParameter("type", "common");
|
|
|
+ params.addBodyParameter("img", finalFile);
|
|
|
+ String url = Constants.getAppBaseUrl(ct) + "mobile/uploadEmployeeAttach.action";
|
|
|
+ final HttpUtils http = new HttpUtils();
|
|
|
+ http.send(HttpRequest.HttpMethod.POST, url, params, new RequestCallBack<String>() {
|
|
|
+ @Override
|
|
|
+ public void onStart() {
|
|
|
+ progressDialog.show();
|
|
|
+ ViewUtil.ToastMessage(ct, "正在上传图片...");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onLoading(long total, long current, boolean isUploading) {
|
|
|
+ if (isUploading) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(ResponseInfo<String> responseInfo) {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ ViewUtil.ToastMessage(ct, "上传成功:");
|
|
|
+ JsonValidator validator = new JsonValidator();
|
|
|
+ if (validator.validate(responseInfo.result) && JSON.parseObject(responseInfo.result).getBoolean("success")) {
|
|
|
+ id = getID(JSON.parseObject(responseInfo.result).getString("id"));
|
|
|
+ }
|
|
|
+ CodeUtil.getInstance().getCode(ct, "mobile_outsign", new CodeUtil.OnCodeLinstener() {
|
|
|
+ @Override
|
|
|
+ public void callBack(String code) {
|
|
|
+ doSignin(code, id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailure(HttpException error, String msg) {
|
|
|
+ ViewUtil.ToastMessage(ct, "上传失败:" + msg);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ if (requestCode == REQUEST_CODE_CAPTURE_PHOTO) {// 拍照返回
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ if (mNewPhotoUri != null) {
|
|
|
+ path = mNewPhotoUri.getPath();
|
|
|
+ path = CameraUtil.getImagePathFromUri(ct, mNewPhotoUri);
|
|
|
+ if (StringUtils.isEmpty(path)) return;
|
|
|
+ ImageLoader.getInstance().displayImage(Uri.fromFile(new File(path)).toString(), image);
|
|
|
+ } else {
|
|
|
+ ToastUtil.showToast(this, R.string.c_take_picture_failed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (requestCode == REQUEST_CODE_PICK_PHOTO) {// 选择一张图片,然后立即调用裁减
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ if (data != null && data.getData() != null) {
|
|
|
+ path = CameraUtil.getImagePathFromUri(ct, data.getData());
|
|
|
+ if (StringUtils.isEmpty(path)) return;
|
|
|
+ ImageLoader.getInstance().displayImage(Uri.fromFile(new File(path)).toString(), image);
|
|
|
+ } else {
|
|
|
+ ToastUtil.showToast(this, R.string.c_photo_album_failed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private final int whatSignin = 0x12;
|
|
|
private Handler handler = new Handler() {
|
|
|
@Override
|
|
|
@@ -134,9 +262,6 @@ public class OutSigninOKActivity extends BaseActivity {
|
|
|
ToastUtil.showToast(ct, "签到失败");
|
|
|
}
|
|
|
break;
|
|
|
- case 0x13:
|
|
|
-// listview.setAdapter(new SigninAdapter(JSON.parseObject(message).getJSONArray("listdata")));
|
|
|
- break;
|
|
|
case Constants.APP_SOCKETIMEOUTEXCEPTION:
|
|
|
ToastUtil.showToast(ct, message == null ? "" : message);
|
|
|
break;
|
|
|
@@ -169,7 +294,7 @@ public class OutSigninOKActivity extends BaseActivity {
|
|
|
*
|
|
|
* @param code 编号
|
|
|
*/
|
|
|
- private void doSignin(String code) {
|
|
|
+ private void doSignin(String code, int id) {
|
|
|
progressDialog.show();
|
|
|
//获取网络数据
|
|
|
String url = baseUrl + "mobile/oa/saveOutSign.action";
|
|
|
@@ -180,7 +305,7 @@ public class OutSigninOKActivity extends BaseActivity {
|
|
|
bean.setMo_mancode(CommonUtil.getSharedPreferences(this, "erp_username"));
|
|
|
bean.setMo_man(MyApplication.getInstance().mLoginUser.getNickName());
|
|
|
bean.setMo_remark(text_edit.getText().toString());
|
|
|
- bean.setMo_attachid(201);
|
|
|
+ bean.setMo_attachid(id);
|
|
|
bean.setMo_company(com_tv.getText().toString().trim());
|
|
|
bean.setMo_signtime(TimeUtils.f_long_2_str(System.currentTimeMillis()));
|
|
|
String formStore = FlexJsonUtil.toJson(bean);
|