|
|
@@ -0,0 +1,322 @@
|
|
|
+package com.uas.pda_wms.activity;
|
|
|
+
|
|
|
+import android.Manifest;
|
|
|
+import android.content.Intent;
|
|
|
+import android.content.pm.PackageManager;
|
|
|
+import android.graphics.drawable.BitmapDrawable;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.support.annotation.NonNull;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.Gravity;
|
|
|
+import android.view.MotionEvent;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.AdapterView;
|
|
|
+import android.widget.GridView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.PopupWindow;
|
|
|
+import android.widget.SimpleAdapter;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.android.volley.Request;
|
|
|
+import com.android.volley.toolbox.StringRequest;
|
|
|
+import com.uas.pda_wms.R;
|
|
|
+import com.uas.pda_wms.application.PdaApplication;
|
|
|
+import com.uas.pda_wms.global.GloableParams;
|
|
|
+import com.uas.pda_wms.tools.DataSourceManager;
|
|
|
+import com.uas.pda_wms.tools.SharedPreUtil;
|
|
|
+import com.uas.pda_wms.tools.VolleyUtil;
|
|
|
+import com.uas.pda_wms.util.CommonUtil;
|
|
|
+import com.uas.pda_wms.util.Constants;
|
|
|
+import com.uas.pda_wms.util.FastjsonUtil;
|
|
|
+import com.uas.pda_wms.util.HttpCallback;
|
|
|
+import com.uas.pda_wms.util.HttpParams;
|
|
|
+import com.uas.pda_wms.util.PermissionUtil;
|
|
|
+import com.uas.pda_wms.util.VolleyRequest;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @note:主菜单界面,与Application生命周期同步,在销毁时,清除App本地缓存
|
|
|
+ */
|
|
|
+public class IndexActivity extends BaseActivity implements AdapterView.OnItemClickListener {
|
|
|
+ private ArrayList<HashMap<String, Object>> gridItemList;
|
|
|
+ private GridView menuGridView;
|
|
|
+ private TextView actionbarTextVeiw;
|
|
|
+ int pageType = VolleyUtil.ACTIVITY_MENU;
|
|
|
+ private PopupWindow mExitPopupWindow;
|
|
|
+ private TextView mCancelTextView, mMinimizeTextView, mExitTextView;
|
|
|
+ private StringRequest mStringRequest;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ //清除全部App缓存
|
|
|
+// SharedPreUtil.removeAll(getApplicationContext());
|
|
|
+ VolleyUtil.distoryVolley();
|
|
|
+ super.onDestroy();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+
|
|
|
+ /* //请求储位
|
|
|
+ VolleyUtil.requestGetUseLocationOrNot(getApplicationContext(), GloableParams.ADDRESS_GET_FIELD_DATA,
|
|
|
+ VolleyUtil.METHOD_POST, pageType);
|
|
|
+ //原材料出库采集方式
|
|
|
+ VolleyUtil.requestProdOutType(getApplicationContext(), GloableParams.ADDRESS_GET_FIELD_DATA);
|
|
|
+ //获取条码打印模板
|
|
|
+ getPrintTemplate();*/
|
|
|
+ getCheckSetting();
|
|
|
+
|
|
|
+ initPermissions();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getCheckSetting() {
|
|
|
+ VolleyRequest.getInstance().stringRequest(new HttpParams.Builder()
|
|
|
+ .url(GloableParams.ADDRESS_JLT_JCOMMON_GETDBSETTING)
|
|
|
+ .method(Request.Method.GET)
|
|
|
+ .tag("getdbsetting")
|
|
|
+ .flag(0)
|
|
|
+ .build(), new HttpCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int flag, Object o) throws Exception {
|
|
|
+ try {
|
|
|
+ String result = o.toString();
|
|
|
+ JSONObject resultObject = JSON.parseObject(result);
|
|
|
+ if (resultObject == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject dataObject = resultObject.getJSONObject("data");
|
|
|
+ if (dataObject == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int vldate = FastjsonUtil.getInt(dataObject, "VLDATE");
|
|
|
+ if (vldate < 0) {
|
|
|
+ vldate = 0;
|
|
|
+ }
|
|
|
+ String checkboxReg = FastjsonUtil.getText(dataObject, "CHECKBOX");
|
|
|
+
|
|
|
+ SharedPreUtil.saveInt(IndexActivity.this, Constants.FLAG.JLT_VALID_DAYS_CACHE, vldate);
|
|
|
+ SharedPreUtil.saveString(IndexActivity.this, Constants.FLAG.JLT_CHECK_BOX_REG_CACHE, checkboxReg);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int flag, String failStr) throws Exception {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getPrintTemplate() {
|
|
|
+ VolleyRequest.getInstance().stringRequest(mStringRequest,
|
|
|
+ new HttpParams.Builder()
|
|
|
+ .url(GloableParams.ADDRESS_BARINFO_PRINTMODEL)
|
|
|
+ .method(Request.Method.GET)
|
|
|
+ .flag(0)
|
|
|
+ .tag("barinfoPrint")
|
|
|
+ .addParam("caller", "Barcode!PDAPrint")
|
|
|
+ .build(), new HttpCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int flag, Object o) throws Exception {
|
|
|
+ try {
|
|
|
+ String result = o.toString();
|
|
|
+ Log.e("prints", result);
|
|
|
+ if (FastjsonUtil.validate(result)) {
|
|
|
+ JSONObject resultObject = JSON.parseObject(result);
|
|
|
+ JSONArray dataArray = resultObject.getJSONArray("data");
|
|
|
+ if (dataArray != null && dataArray.size() > 0) {
|
|
|
+ SharedPreUtil.saveString(IndexActivity.this, Constants.FLAG.PRINT_TEMPLATE_CACHE, dataArray.toJSONString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int flag, String failStr) throws Exception {
|
|
|
+ Log.e("printf", failStr);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initPermissions() {
|
|
|
+ String[] permissions = {
|
|
|
+ Manifest.permission.CAMERA
|
|
|
+ , Manifest.permission.WRITE_EXTERNAL_STORAGE
|
|
|
+ };
|
|
|
+ for (String permission : permissions) {
|
|
|
+ if (PermissionUtil.lacksPermissions(this, permission)) {
|
|
|
+ PermissionUtil.requestPermission(this, PermissionUtil.DEFAULT_REQUEST, permission);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initViews() {
|
|
|
+ setContentView(R.layout.activity_index);
|
|
|
+ menuGridView = (GridView) findViewById(R.id.grid_menu);
|
|
|
+ actionbarTextVeiw = (TextView) findViewById(R.id.actionbar);
|
|
|
+ actionbarTextVeiw.setText(getResources().getString(R.string.title_activity_menu));
|
|
|
+ gridItemList = DataSourceManager.getDataSourceManager().getIndexMainGridItemList();
|
|
|
+ SimpleAdapter adapter = new SimpleAdapter(this, gridItemList, R.layout.item_grid,
|
|
|
+ new String[]{DataSourceManager.KEY_GRID_ITEMIMG, DataSourceManager.KEY_GRID_ITEMNAME},
|
|
|
+ new int[]{R.id.griditem_img, R.id.griditem_name});
|
|
|
+ menuGridView.setAdapter(adapter);
|
|
|
+
|
|
|
+
|
|
|
+ View view = View.inflate(this, R.layout.pop_exit_application, null);
|
|
|
+ mCancelTextView = (TextView) view.findViewById(R.id.pop_exit_cancel_tv);
|
|
|
+ mMinimizeTextView = (TextView) view.findViewById(R.id.pop_exit_minimize_tv);
|
|
|
+ mExitTextView = (TextView) view.findViewById(R.id.pop_exit_exit_tv);
|
|
|
+
|
|
|
+ mExitPopupWindow = new PopupWindow(view, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
|
|
|
+ mExitPopupWindow.setBackgroundDrawable(new BitmapDrawable());
|
|
|
+ mExitPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss() {
|
|
|
+ closeExitPopupWindow();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initEvents() {
|
|
|
+ menuGridView.setOnItemClickListener(this);
|
|
|
+ menuGridView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
+ @Override
|
|
|
+ public boolean onTouch(View v, MotionEvent event) {
|
|
|
+ //控制gridView不滚动
|
|
|
+ if (event.getAction() == MotionEvent.ACTION_MOVE)
|
|
|
+ return true;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mCancelTextView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ closeExitPopupWindow();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ mExitTextView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ PdaApplication.removeAllDataCache();
|
|
|
+ System.exit(0);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ mMinimizeTextView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ closeExitPopupWindow();
|
|
|
+ moveTaskToBack(isFinishing());
|
|
|
+// Intent intent = new Intent(Intent.ACTION_MAIN);
|
|
|
+// intent.addCategory(Intent.CATEGORY_HOME);
|
|
|
+// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+// startActivity(intent);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initDatas() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ SharedPreUtil.saveString(this, "printAddress", "");
|
|
|
+ SharedPreUtil.saveInt(this, "printConnect", 0);
|
|
|
+ SharedPreUtil.saveInt(this, "printDpi", 203);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
+ //将选中的ItemName传递给功能Activity(FunctionActivity)
|
|
|
+ String itemName = (String) gridItemList.get(position).get(DataSourceManager.KEY_GRID_ITEMNAME);
|
|
|
+// if (!itemName.equals(GloableParams.GRIDNAME_UPPER_SHELF)) {
|
|
|
+
|
|
|
+ /*List<String> powerList = (List<String>) PdaApplication.getDataCacheFromMap(Constants.FLAG.POWER_CALLER_CACHE);
|
|
|
+ boolean isPower = false;
|
|
|
+ if (powerList != null) {
|
|
|
+ for (int i = 0; i < powerList.size(); i++) {
|
|
|
+ String power = powerList.get(i);
|
|
|
+
|
|
|
+ if ((GloableParams.GRIDNAME_IN_STORAGE.equals(itemName)
|
|
|
+ || GloableParams.GRIDNAME_STOCK_INQUIRY.equals(itemName))
|
|
|
+ && Constants.CONSTANT.AUTHORITY_PRODINOUT.equals(power)) {
|
|
|
+ isPower = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((GloableParams.GRIDNAME_UPPER_SHELF.equals(itemName)
|
|
|
+ || GloableParams.GRIDNAME_STOCK_INQUIRY.equals(itemName))
|
|
|
+ && Constants.CONSTANT.AUTHORITY_SHOP.equals(power)) {
|
|
|
+ isPower = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (itemName.equals(GloableParams.GRIDNAME_SETTING)) {
|
|
|
+ isPower = true;
|
|
|
+ }*/
|
|
|
+
|
|
|
+ if (GloableParams.GRIDNAME_INVENTORY.equals(itemName)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (true) {
|
|
|
+ Intent intent = new Intent(IndexActivity.this, FunctionActivity.class);
|
|
|
+ intent.putExtra(DataSourceManager.KEY_GRID_ITEMNAME, itemName);
|
|
|
+ startActivity(intent);
|
|
|
+ } else {
|
|
|
+ CommonUtil.toastNoRepeat(this, getString(R.string.have_no_power));
|
|
|
+ }
|
|
|
+
|
|
|
+// } else {
|
|
|
+// CommonUtil.toastNoRepeat(this, "该功能正在内测");
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
+ if (requestCode == PermissionUtil.DEFAULT_REQUEST) {
|
|
|
+ if (grantResults.length != 1 || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
|
|
|
+ //没有获取到权限
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onBackPressed() {
|
|
|
+ if (mExitPopupWindow.isShowing()) {
|
|
|
+ closeExitPopupWindow();
|
|
|
+ } else {
|
|
|
+ if (mExitPopupWindow != null) {
|
|
|
+ CommonUtil.setBackgroundAlpha(this, 0.5f);
|
|
|
+ mExitPopupWindow.showAtLocation(getWindow().getDecorView(), Gravity.CENTER, 0, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void closeExitPopupWindow() {
|
|
|
+ if (mExitPopupWindow != null) {
|
|
|
+ mExitPopupWindow.dismiss();
|
|
|
+ CommonUtil.setBackgroundAlpha(this, 1f);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|