|
|
@@ -1,106 +0,0 @@
|
|
|
-package com.xzjmyk.pm.activity.ui.erp.util;
|
|
|
-
|
|
|
-import android.content.Context;
|
|
|
-import android.os.Handler;
|
|
|
-import android.os.Message;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.xzjmyk.pm.activity.view.crouton.Crouton;
|
|
|
-
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-import static com.xzjmyk.pm.activity.ui.erp.net.ViewUtil.ct;
|
|
|
-
|
|
|
-/**
|
|
|
- * 因为没有处理好内存,该类会引起内存泄露
|
|
|
- * Created by gongpm on 2016/8/5.
|
|
|
- */
|
|
|
-@Deprecated
|
|
|
-public class CodeUtil {
|
|
|
- private static CodeUtil instance = null;//多次使用,转为静态
|
|
|
- private static OnCodeLinstener linstener;
|
|
|
-
|
|
|
- public static CodeUtil getInstance() {
|
|
|
- if (instance == null) {
|
|
|
- synchronized (CodeUtil.class) {
|
|
|
- instance = new CodeUtil();
|
|
|
- }
|
|
|
- }
|
|
|
- return instance;
|
|
|
- }
|
|
|
-
|
|
|
- //多次重复使用,采用静态方式保证内存唯一
|
|
|
- private static Handler handler = new Handler() {
|
|
|
- @Override
|
|
|
- public void handleMessage(Message msg) {
|
|
|
- String message = msg.getData().getString("result");
|
|
|
- String code = null;
|
|
|
- if (msg.what == 0x11) {
|
|
|
- JSONObject json = JSON.parseObject(message);
|
|
|
- code = json.getString("code");
|
|
|
- if (linstener != null) {
|
|
|
- linstener.callBack(code);
|
|
|
- return;
|
|
|
- }
|
|
|
- } else if (msg.what == 0x12) {
|
|
|
- if (JSON.parseObject(message).containsKey("success") && JSON.parseObject(message).getBoolean("success")) {
|
|
|
- code = String.valueOf(JSON.parseObject(message).getInteger("id"));
|
|
|
- } else {
|
|
|
- Crouton.makeText(ct, "获取id错误");
|
|
|
- }
|
|
|
- if (linstener != null) {
|
|
|
- linstener.callBack(code);
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- //TODO 容错、待修改(网络修复后)
|
|
|
- if (linstener != null) {
|
|
|
- linstener.callBack(code);
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- //外勤
|
|
|
- private void getIdByNet(Context context, String sql) {
|
|
|
- String url = CommonUtil.getSharedPreferences(context, "erp_baseurl") + "common/getId.action";
|
|
|
- final Map<String, Object> param = new HashMap<>();
|
|
|
- param.put("seq", sql);
|
|
|
- LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
|
|
|
- headers.put("Cookie", "JSESSIONID=" + CommonUtil.getSharedPreferences(context, "sessionId"));
|
|
|
- com.xzjmyk.pm.activity.ui.erp.net.ViewUtil.httpSendRequest(context, url, param, handler, headers, 0x12, null, null, "post");
|
|
|
- }
|
|
|
-
|
|
|
- // private void
|
|
|
- private void getCodeByNet(Context context, String titleName) {
|
|
|
- String url = CommonUtil.getSharedPreferences(context, "erp_baseurl") + "common/getCodeString.action";
|
|
|
- final Map<String, Object> param = new HashMap<>();
|
|
|
- String caller = titleName;
|
|
|
- param.put("caller", caller);
|
|
|
- param.put("type", 2);
|
|
|
- param.put("sessionId", CommonUtil.getSharedPreferences(context, "sessionId"));
|
|
|
- LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
|
|
|
- headers.put("Cookie", "JSESSIONID=" + CommonUtil.getSharedPreferences(context, "sessionId"));
|
|
|
- com.xzjmyk.pm.activity.ui.erp.net.ViewUtil.httpSendRequest(context, url, param, handler, headers, 0x11, null, null, "post");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private CodeUtil() {
|
|
|
- }
|
|
|
-
|
|
|
- public void getId(Context context, String sql, OnCodeLinstener linstener) {
|
|
|
- this.linstener = linstener;
|
|
|
- getIdByNet(context, sql);
|
|
|
- }
|
|
|
-
|
|
|
- public void getCode(Context context, String titleName, OnCodeLinstener linstener) {
|
|
|
- this.linstener = linstener;
|
|
|
- getCodeByNet(context, titleName);
|
|
|
- }
|
|
|
-
|
|
|
- public interface OnCodeLinstener {
|
|
|
- void callBack(String code);
|
|
|
- }
|
|
|
-}
|