充电桩app代码

InputCodeActivity.java 14KB

    package com.electric.chargingpile.activity; import android.Manifest; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.text.TextUtils; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.Toast; import com.blankj.utilcode.util.EmptyUtils; import com.blankj.utilcode.util.LogUtils; import com.electric.chargingpile.R; import com.electric.chargingpile.application.MainApplication; import com.electric.chargingpile.util.BarColorUtil; import com.electric.chargingpile.util.JsonUtils; import com.electric.chargingpile.util.LoadingDialog; import com.electric.chargingpile.util.ToastUtil; import com.electric.chargingpile.view.AlertDialogTwo; import com.google.zxing.client.android.constant.ChargingConstants; import com.google.zxing.client.android.constant.UrlConstants; import com.tencent.bugly.crashreport.CrashReport; import com.zhy.autolayout.AutoLayoutActivity; import com.zhy.http.okhttp.OkHttpUtils; import com.zhy.http.okhttp.callback.StringCallback; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.List; import okhttp3.Call; import pub.devrel.easypermissions.AfterPermissionGranted; import pub.devrel.easypermissions.AppSettingsDialog; import pub.devrel.easypermissions.EasyPermissions; public class InputCodeActivity extends AutoLayoutActivity implements View.OnClickListener, EasyPermissions.PermissionCallbacks { private static final String TAG = "InputCodeActivity"; private EditText et_code; private String chargingCode = ""; private String stubGroupId; InputMethodManager imm; private LoadingDialog dialog; private String password = ""; int i = 0; int count = 0; private InputCodeActivity activity; private static final String numType = "2"; private static final int startInterface = 2; private AlertDialogTwo alertDialog; private static final int RC_TELL_PERM = 124; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_input_code); BarColorUtil.initStatusBarColor(InputCodeActivity.this); activity = this; dialog = new LoadingDialog(this); dialog.setCanceledOnTouchOutside(false); initViews(); } private void initViews() { findViewById(R.id.iv_back).setOnClickListener(this); findViewById(R.id.tv_cancel).setOnClickListener(this); findViewById(R.id.tv_sure).setOnClickListener(this); alertDialog = new AlertDialogTwo(this); et_code = (EditText) findViewById(R.id.et_code); imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.iv_back: finish(); // startActivity(new Intent(getApplicationContext(),MainScanActivity.class)); break; case R.id.tv_cancel: finish(); break; case R.id.tv_sure: if (imm.isActive()) { View view = getWindow().peekDecorView(); if (view != null) { imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } } chargingCode = et_code.getText().toString(); if (TextUtils.isEmpty(chargingCode)) { ToastUtil.showToast(getApplicationContext(), "请输入充电桩编码", Toast.LENGTH_SHORT); } else { startCharging(chargingCode); } break; } } private void startCharging(String result) { dialog.show(); OkHttpUtils.get().url(UrlConstants.START_CHARGING_URL) .addParams(ChargingConstants.FLAG, numType) .addParams(ChargingConstants.URL, URLEncoder.encode(result)) .addParams(ChargingConstants.USERID, MainApplication.userId) .addParams(ChargingConstants.PWD, MainApplication.userPassword) .build().connTimeOut(30000).readTimeOut(30000).execute(new StringCallback() { @Override public void onError(Call call, Exception e) { ToastUtil.showToast(getApplicationContext(), "网络异常,请检查您的网络连接", Toast.LENGTH_SHORT); CrashReport.postCatchedException(e); } @Override public void onResponse(String response) { LogUtils.e(response); if (EmptyUtils.isNotEmpty(response)) { cancelDialog(); handlingOperations(response, startInterface); } } }); } private void handlingOperations(String response, int interfaceType) { String rtnCode = JsonUtils.getKeyResult(response, "rtnCode"); String rtnMsg = JsonUtils.getKeyResult(response, "rtnMsg"); switch (rtnCode) { case "01": if (interfaceType == startInterface) { String data = JsonUtils.getKeyResult(response, "data"); String orderid = JsonUtils.getKeyResult(data, "orderId"); Intent intent = new Intent(getApplicationContext(), TLDLoadingActivity.class); intent.putExtra(ChargingConstants.ORDERID, orderid); startActivity(intent); } break; case "304": alertDialog.builder() .setMsg(rtnMsg) .setPositiveButton("去充值", new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), AccountRechargeActivity.class); startActivity(intent); } }) // .setNegativeButton("开通免密支付", new View.OnClickListener() { // @Override // public void onClick(View v) { // Intent intent = new Intent(getApplicationContext(),NonSecretSeettingActivity.class); // Uri uri = Uri.parse("chongdianzhuang://"); // intent.setData(uri); // startActivity(intent); // } // }) .show(); break; case "305": alertDialog.builder() .setMsg(rtnMsg) .setPositiveButton("联系客服", new View.OnClickListener() { @Override public void onClick(View v) { //tellTask(); wechatAlert(); } }).setNegativeButton("取消", new View.OnClickListener() { @Override public void onClick(View v) { } }).show(); break; case "309": alertDialog.builder() .setMsg(rtnMsg) .setPositiveButton("联系客服", new View.OnClickListener() { @Override public void onClick(View v) { // tellTask(); wechatAlert(); } }).setNegativeButton("取消", new View.OnClickListener() { @Override public void onClick(View v) { } }).show(); break; case "306": //跳转到充电详情界面 String data306 = JsonUtils.getKeyResult(response, "data"); String orderid = JsonUtils.getKeyResult(data306, "orderId"); Intent intent306 = new Intent(getApplicationContext(), ChargingStatusActivity.class); intent306.putExtra(ChargingConstants.ORDERID, orderid); startActivity(intent306); finish(); break; case "307": alertDialog.builder() .setMsg(rtnMsg) .setPositiveButton("去充值", new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), AccountRechargeActivity.class); startActivity(intent); } }).show(); break; case "311": alertDialog.builder() .setMsg(rtnMsg) .setPositiveButton("开通免密支付", new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), NonSecretSeettingActivity.class); Uri uri = Uri.parse("chongdianzhuang://"); intent.setData(uri); startActivity(intent); } }).show(); break; case "1800": String data1800 = JsonUtils.getKeyResult(response, "data"); String pileId = JsonUtils.getKeyResult(data1800, "pileId"); Intent intent1800 = new Intent(getApplicationContext(), SelectPileActivity.class); intent1800.putExtra(ChargingConstants.ORDERID, pileId); startActivity(intent1800); break; default: ToastUtil.showToast(getApplicationContext(), rtnMsg, Toast.LENGTH_SHORT); break; } } public static String md5(String string) { byte[] hash; try { hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8")); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Huh, MD5 should be supported?", e); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Huh, UTF-8 should be supported?", e); } StringBuilder hex = new StringBuilder(hash.length * 2); for (byte b : hash) { if ((b & 0xFF) < 0x10) hex.append("0"); hex.append(Integer.toHexString(b & 0xFF)); } return hex.toString(); } @Override protected void onDestroy() { super.onDestroy(); } private void cancelDialog() { if (activity != null && !activity.isFinishing()) { if (dialog.isShowing()) { dialog.dismiss(); } } } private void wechatAlert() { AlertDialogTwo wechatAlert = new AlertDialogTwo(InputCodeActivity.this); wechatAlert.builder().setTitle("温馨提示") .setMsg("客服微信:chongdianzhuang2") .setPositiveButton("复制", new View.OnClickListener(){ @Override public void onClick(View view) { ClipboardManager cm = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); ClipData cdzData = ClipData.newPlainText("Label", "chongdianzhuang2"); cm.setPrimaryClip(cdzData); ToastUtil.showToast(getApplicationContext(), "微信号复制成功", Toast.LENGTH_SHORT); } }).show(); } @AfterPermissionGranted(RC_TELL_PERM) public void tellTask() { if (hasTellPermission()) { // Have permission, do the thing! // Toast.makeText(this, "TODO: Camera things", Toast.LENGTH_LONG).show(); String telNum = "4008810405"; Intent intent = new Intent(); intent.setAction("android.intent.action.CALL"); intent.addCategory("android.intent.category.DEFAULT"); intent.setData(Uri.parse("tel:" + telNum)); InputCodeActivity.this.startActivity(intent); } else { LogUtils.e("@@@@@@@"); // Ask for one permission EasyPermissions.requestPermissions( this, "该功能需要开启拨号权限,是否前往开启?", RC_TELL_PERM, Manifest.permission.CALL_PHONE); } } private boolean hasTellPermission() { return EasyPermissions.hasPermissions(this, Manifest.permission.CALL_PHONE); } @Override public void onPermissionsGranted(int requestCode, List<String> perms) { } @Override public void onPermissionsDenied(int requestCode, List<String> perms) { if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) { // TODO add by hyg20200525 new AppSettingsDialog.Builder(InputCodeActivity.this).build().show(); // new AppSettingsDialog.Builder(InputCodeActivity.this, // "该功能需要开启拨号权限,是否前往开启??").build().show(); } } }