|
|
@@ -1,20 +1,15 @@
|
|
|
package com.xzjmyk.pm.activity.ui.erp.net;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
-import android.app.ActivityManager;
|
|
|
-import android.app.ActivityManager.RunningTaskInfo;
|
|
|
-import android.content.ComponentName;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
import android.os.Message;
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
|
|
-import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
-import android.widget.EditText;
|
|
|
import android.widget.ListAdapter;
|
|
|
import android.widget.ListView;
|
|
|
import android.widget.Toast;
|
|
|
@@ -23,6 +18,7 @@ import com.afollestad.materialdialogs.MaterialDialog;
|
|
|
import com.afollestad.materialdialogs.MaterialDialog.ButtonCallback;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.xzjmyk.pm.activity.MyApplication;
|
|
|
+import com.xzjmyk.pm.activity.R;
|
|
|
import com.xzjmyk.pm.activity.ui.MainActivity;
|
|
|
import com.xzjmyk.pm.activity.ui.account.DataDownloadActivity;
|
|
|
import com.xzjmyk.pm.activity.ui.base.BaseActivity;
|
|
|
@@ -34,10 +30,8 @@ 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.LogUtil;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.StringUtils;
|
|
|
+import com.xzjmyk.pm.activity.view.crouton.Crouton;
|
|
|
|
|
|
-import java.io.PrintWriter;
|
|
|
-import java.io.StringWriter;
|
|
|
-import java.io.Writer;
|
|
|
import java.text.DateFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
@@ -66,44 +60,16 @@ public class ViewUtil {
|
|
|
public static String erp_company;
|
|
|
public static MaterialDialog mdProcessDialog;
|
|
|
private static MaterialDialog loginERPDialog;
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取Listview的高度
|
|
|
- *
|
|
|
- * @param listView
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static void setListViewHeightBasedOnChildren(ListView listView) {
|
|
|
- ListAdapter listAdapter = listView.getAdapter();
|
|
|
- if (listAdapter == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- int totalHeight = 0;
|
|
|
- for (int i = 0; i < listAdapter.getCount(); i++) {
|
|
|
- View listItem = listAdapter.getView(i, null, listView);
|
|
|
- listItem.measure(0, 0);
|
|
|
- totalHeight += listItem.getMeasuredHeight();
|
|
|
- }
|
|
|
-
|
|
|
- ViewGroup.LayoutParams params = listView.getLayoutParams();
|
|
|
- params.height = totalHeight
|
|
|
- + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
|
|
|
- listView.setLayoutParams(params);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ private static List<LoginEntity> erpEntities;
|
|
|
+ private static boolean hasErp = true;//是否有erp
|
|
|
/**
|
|
|
* 获取Listview的高度,然后设置ViewPager的高度
|
|
|
- *
|
|
|
* @param listView
|
|
|
* @return
|
|
|
*/
|
|
|
public static int setListViewHeightBasedOnChildren1(ListView listView) {
|
|
|
- // 获取ListView对应的Adapter
|
|
|
ListAdapter listAdapter = listView.getAdapter();
|
|
|
if (listAdapter == null) {
|
|
|
- // pre-condition
|
|
|
return 0;
|
|
|
}
|
|
|
int totalHeight = 0;
|
|
|
@@ -112,12 +78,9 @@ public class ViewUtil {
|
|
|
listItem.measure(0, 0); // 计算子项View 的宽高
|
|
|
totalHeight += listItem.getMeasuredHeight(); // 统计所有子项的总高度
|
|
|
}
|
|
|
-
|
|
|
ViewGroup.LayoutParams params = listView.getLayoutParams();
|
|
|
params.height = totalHeight
|
|
|
+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
|
|
|
- // listView.getDividerHeight()获取子项间分隔符占用的高度
|
|
|
- // params.height最后得到整个ListView完整显示需要的高度
|
|
|
listView.setLayoutParams(params);
|
|
|
return params.height;
|
|
|
}
|
|
|
@@ -125,29 +88,19 @@ public class ViewUtil {
|
|
|
|
|
|
/**
|
|
|
* 弹出Toast消息
|
|
|
- *
|
|
|
* @param msg
|
|
|
*/
|
|
|
public static void ToastMessage(Context cont, String msg) {
|
|
|
- Toast.makeText(cont, msg, Toast.LENGTH_SHORT).show();
|
|
|
- }
|
|
|
-
|
|
|
- public static void ToastMessage(Context cont, int msg) {
|
|
|
- Toast.makeText(cont, msg, Toast.LENGTH_SHORT).show();
|
|
|
- }
|
|
|
-
|
|
|
- public static void ToastMessage(Context cont, String msg, int time) {
|
|
|
- Toast.makeText(cont, msg, time).show();
|
|
|
- }
|
|
|
-
|
|
|
- public static void ShowAppCrashTitle(Context ct) {
|
|
|
- new MaterialDialog.Builder(ct).title("信息提示").content("系统出现未知错误,很抱歉!")
|
|
|
- .show();
|
|
|
+ if (cont instanceof Activity){
|
|
|
+ Crouton.makeText((Activity)cont,msg,cont.getResources().getColor(R.color.light_green),2000).show();
|
|
|
+ }else{
|
|
|
+ Toast.makeText(cont, msg, Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
public static void ShowMessageTitle(Context ct, String msg) {
|
|
|
- final MaterialDialog messageDialog = new MaterialDialog.Builder(ct).title("系統提示").content(msg)
|
|
|
+ new MaterialDialog.Builder(ct).title("系統提示").content(msg)
|
|
|
.positiveText("关闭").autoDismiss(false)
|
|
|
.callback(new ButtonCallback() {
|
|
|
@Override
|
|
|
@@ -156,8 +109,7 @@ public class ViewUtil {
|
|
|
}
|
|
|
}).show();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
public static void ShowMessageTitleAutoDismiss(Context ct, String msg, long time) {
|
|
|
final MaterialDialog messageDialog = new MaterialDialog.Builder(ct).title("系統提示").content(msg)
|
|
|
.positiveText("关闭").autoDismiss(false)
|
|
|
@@ -176,11 +128,6 @@ public class ViewUtil {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private static EditText phone;
|
|
|
- private static EditText password;// 密码
|
|
|
- private static View positiveAction;
|
|
|
-
|
|
|
-
|
|
|
public static String getDataFromServer(String url,
|
|
|
Map<String, String> params, String method) {
|
|
|
String result = null;
|
|
|
@@ -243,7 +190,6 @@ public class ViewUtil {
|
|
|
final int what, final Message message, final Bundle bundle,
|
|
|
final String request) {
|
|
|
new Thread(new Runnable() {
|
|
|
-
|
|
|
@Override
|
|
|
public void run() {
|
|
|
boolean isNetHas = CommonUtil.isNetWorkConnected(ct);
|
|
|
@@ -302,7 +248,7 @@ public class ViewUtil {
|
|
|
bundle, "get");
|
|
|
}
|
|
|
|
|
|
- public static void LoginTaskERP(String user_phone, String user_password, Context ct) {
|
|
|
+/* public static void LoginTaskERP(String user_phone, String user_password, Context ct) {
|
|
|
ViewUtil.ct = ct;
|
|
|
String url = Constants.BASE_URL_LOGIN;
|
|
|
Map<String, String> params = new HashMap<String, String>();
|
|
|
@@ -314,7 +260,7 @@ public class ViewUtil {
|
|
|
bundle.putString("password", user_password);
|
|
|
startNetThread(url, params, handler, Constants.SUCCESS_LOGIN, message,
|
|
|
bundle, "get");
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
// 登录B2B
|
|
|
public static void LoginB2BTask(String phone, String password) {
|
|
|
@@ -328,16 +274,15 @@ public class ViewUtil {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private static List<LoginEntity> erpEntities;
|
|
|
+
|
|
|
public static Handler handler = new Handler() {
|
|
|
public void handleMessage(Message msg) {
|
|
|
switch (msg.what) {
|
|
|
case Constants.SUCCESS_LOGIN:
|
|
|
LoginSucess(msg);
|
|
|
break;
|
|
|
- case Constants.SUCCESS_ERP://切换公司成功
|
|
|
+ case Constants.SUCCESS_ERP:
|
|
|
String result = msg.getData().getString("result");
|
|
|
- Log.i("Arison", "" + result);
|
|
|
boolean success = JSON.parseObject(result).getBoolean("success");
|
|
|
if (success) {
|
|
|
Intent intent = new Intent("com.app.home.update");
|
|
|
@@ -346,7 +291,6 @@ public class ViewUtil {
|
|
|
ChangeStatusERP(msg.getData().getString("result"));
|
|
|
} else {
|
|
|
String reason = JSON.parseObject(result).getString("reason");
|
|
|
-
|
|
|
ToastMessage(ct, reason);
|
|
|
}
|
|
|
break;
|
|
|
@@ -495,7 +439,7 @@ public class ViewUtil {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return true; // allow selection
|
|
|
+ return true;
|
|
|
}
|
|
|
}).positiveText("确定").show();
|
|
|
}
|
|
|
@@ -509,7 +453,7 @@ public class ViewUtil {
|
|
|
*/
|
|
|
public static void LoginSucess(Message msg) {
|
|
|
String json = msg.getData().getString("result");
|
|
|
- CommonUtil.setSharedPreferences(ct, "loginJson", json);// 保存在本地
|
|
|
+ CommonUtil.setSharedPreferences(ct, "loginJson", json);
|
|
|
String phone = msg.getData().getString("phone");
|
|
|
String password = msg.getData().getString("password");
|
|
|
Log.i("Login", "login sucess:" + json);
|
|
|
@@ -559,7 +503,7 @@ public class ViewUtil {
|
|
|
|
|
|
;
|
|
|
|
|
|
- private static boolean hasErp = true;//是否有erp
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* @author LiuJie
|
|
|
@@ -592,27 +536,7 @@ public class ViewUtil {
|
|
|
startNetThread(url, param, handler, what, null, null, "get");
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 判断某个界面是否在前台
|
|
|
- *
|
|
|
- * @param context
|
|
|
- * @param className 某个界面名称
|
|
|
- */
|
|
|
- public static boolean isForeground(Context context, String className) {
|
|
|
- if (context == null || TextUtils.isEmpty(className)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- ActivityManager am = (ActivityManager) context
|
|
|
- .getSystemService(Context.ACTIVITY_SERVICE);
|
|
|
- List<RunningTaskInfo> list = am.getRunningTasks(1);
|
|
|
- if (list != null && list.size() > 0) {
|
|
|
- ComponentName cpn = list.get(0).topActivity;
|
|
|
- if (className.equals(cpn.getClassName())) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -634,16 +558,16 @@ public class ViewUtil {
|
|
|
public void run() {
|
|
|
boolean isNetHas = CommonUtil.isNetWorkConnected(ct);
|
|
|
if (isNetHas) {
|
|
|
+ headers.put("sessionUser", CommonUtil.getSharedPreferences(ct, "erp_username"));
|
|
|
Log.i("result", "url=" + url);
|
|
|
HttpUtil.Response result = httpSendTask(url, params, headers, request);
|
|
|
if (result != null) {
|
|
|
- Log.i("result", "http 请求-----------------------------------------");
|
|
|
- Log.i("result", "result:" + result);
|
|
|
+ Log.i("result", "http 发送请求-----------------------------------------");
|
|
|
Log.i("result", "url:" + url);
|
|
|
- Log.i("result", "parm:" + params.toString());
|
|
|
+ Log.i("result", "parms:" + params.toString());
|
|
|
Log.i("result", "statusCode:" + result.getStatusCode());
|
|
|
LogUtil.prinlnLongMsg("result", result.getResponseText());
|
|
|
- Log.i("result", "http 响应-----------------------------------------");
|
|
|
+ Log.i("result", "http 接收响应-----------------------------------------");
|
|
|
if (result.getStatusCode() == 200) {
|
|
|
if (bundle == null || message == null) {
|
|
|
Bundle bundle = new Bundle();
|
|
|
@@ -718,64 +642,19 @@ public class ViewUtil {
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
- public static String getExceptionMsg(Context ct, Throwable ex) {
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
- sb.append("----------------------异常信息输出-------------------------------------\n");
|
|
|
- Writer writer = new StringWriter();
|
|
|
- PrintWriter printWriter = new PrintWriter(writer);
|
|
|
- ex.printStackTrace(printWriter);
|
|
|
- // 原因打印
|
|
|
- Throwable cause = ex.getCause();
|
|
|
- while (cause != null) {
|
|
|
- cause.printStackTrace(printWriter);
|
|
|
- cause = cause.getCause();
|
|
|
- }
|
|
|
- printWriter.close();
|
|
|
- String result = writer.toString();
|
|
|
- String phone = CommonUtil.getSharedPreferences(ct, "user_phone");
|
|
|
- String password = CommonUtil.getSharedPreferences(ct, "user_password");
|
|
|
- String master_ch = CommonUtil.getSharedPreferences(ct, "Master_ch");
|
|
|
- String company = CommonUtil.getSharedPreferences(ct, "erp_commpany");
|
|
|
- sb.append(result);
|
|
|
- sb.append("\n----------------------用户信息输出-------------------------------------");
|
|
|
- sb.append("\n phone:" + phone);
|
|
|
- sb.append("\n password:" + password);
|
|
|
- sb.append("\n master_ch:" + master_ch);
|
|
|
- sb.append("\n company:" + company);
|
|
|
- sb.append("\n----------------------设备信息输出-------------------------------------");
|
|
|
- //获取设备大小
|
|
|
- String deviceInfo = CommonUtil.getDeviceInfo(ct);
|
|
|
- System.out.println("deviceInfo=" + deviceInfo);
|
|
|
- sb.append("\n" + deviceInfo);
|
|
|
- sb.append("\n手机型号:" + CommonUtil.getDeviceModel());
|
|
|
- sb.append("\n手机生产厂商:" + CommonUtil.getDeviceManufacturer());
|
|
|
- //获取应用程序内存使用情况
|
|
|
- sb.append("\n----------------------内存信息输出-------------------------------------\n");
|
|
|
- sb.append(CommonUtil.getMemory());
|
|
|
- //获取应用程序的当前版本号
|
|
|
- sb.append("\n----------------------版本信息输出-------------------------------------\n");
|
|
|
- sb.append("\n应用版本号:" + CommonUtil.ApkVersionCode(ct));
|
|
|
- return sb.toString();
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @注释:ERP自动登录
|
|
|
*/
|
|
|
public static void AutoLoginErp(Context ct) {
|
|
|
- Log.i("LoginErp", "自动登录...");
|
|
|
if (!StringUtils.isEmpty(Constants.getAppBaseUrl(ct))) {
|
|
|
ViewUtil.ct = ct;
|
|
|
String url = Constants.getAppBaseUrl(ct);
|
|
|
String master = CommonUtil.getSharedPreferences(ct, "erp_master");
|
|
|
String phone = CommonUtil.getSharedPreferences(ct, "user_phone");
|
|
|
String password = CommonUtil.getSharedPreferences(ct, "user_password");
|
|
|
- Log.i("LoginErp", "自动登录..." + url);
|
|
|
- Log.i("LoginErp", "master..." + master);
|
|
|
- Log.i("LoginErp", "phone..." + phone);
|
|
|
- Log.i("LoginErp", "password..." + password);
|
|
|
LoginERPTask(ct, url, master, phone, password);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
// 登录ERP
|
|
|
@@ -785,7 +664,6 @@ public class ViewUtil {
|
|
|
params.put("username", username);
|
|
|
params.put("password", password);
|
|
|
params.put("master", master);
|
|
|
- Log.i("Arison", "erp login:" + JSON.toJSONString(params));
|
|
|
httpSendRequest(ct, url, params, handler, null, Constants.SUCCESS_ERP, null, null, "post");
|
|
|
}
|
|
|
|
|
|
@@ -814,7 +692,6 @@ public class ViewUtil {
|
|
|
params.put("master", master);
|
|
|
// httpSendRequest(ct, url, params, handler, null, Constants.SUCCESS_ERP, null, null, "post");
|
|
|
startNetThread(url, params, handler, Constants.SUCCESS_ERP, null, null, "post");
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -823,7 +700,7 @@ public class ViewUtil {
|
|
|
* @param: url 经过登录验证之后的URL路径跳转
|
|
|
* text 客户端嵌入网页页面动态显示文字
|
|
|
*/
|
|
|
- public static void WebLinks(Context ct, String url, String text) {
|
|
|
+ public static void webLinks(Context ct, String url, String text) {
|
|
|
Intent intent_web = new Intent(ct, WebViewCommActivity.class);
|
|
|
intent_web.putExtra("url", url);
|
|
|
intent_web.putExtra("p", text);
|
|
|
@@ -835,7 +712,7 @@ public class ViewUtil {
|
|
|
* @param: url 经过登录验证之后的URL路径跳转
|
|
|
* text 客户端嵌入网页页面动态显示文字
|
|
|
*/
|
|
|
- public static void WebLinks(Context ct, String url, String text, boolean isCookie) {
|
|
|
+ public static void webLinks(Context ct, String url, String text, boolean isCookie) {
|
|
|
Intent intent_web = new Intent(ct, WebViewCommActivity.class);
|
|
|
intent_web.putExtra("url", url);
|
|
|
intent_web.putExtra("p", text);
|
|
|
@@ -853,6 +730,5 @@ public class ViewUtil {
|
|
|
CommonUtil.clearSharedPreferences(ct, "b2b_login");
|
|
|
CommonUtil.clearSharedPreferences(ct, "b2b_uu");
|
|
|
CommonUtil.clearSharedPreferences(ct, "Master_ch");
|
|
|
-
|
|
|
}
|
|
|
}
|