首页 > 代码库 > xifu-1011-Config--配置--demo

xifu-1011-Config--配置--demo

@SuppressLint("SimpleDateFormat")public class Config {    private static final Boolean DEBUG = false;    // 全局--量public static final String SERVER_URL = "http://192.168.1.113:7700/app/v2/";public static final int PAY_TIMEOUT = 50000;// xx时的超时时间    // public static final int OTHER_TIMEOUT = 10000;// 其它的超时时间    //    public static final String KEY_LOGIN = "login";    public static final String KEY_LOGOUT= "logout";    public static final String KEY_VERIFYCODE = "verifycode";/*** 一卡通部分 ******/    public static final String KEY_YKT_RECHARGE = "ykt_recharge";    public static final String KEY_YKT_REPORTLOSS = "ykt_reportloss";/* 支付pay部分 */    public static final String KEY_BINDED_CARDS_LIST = "binded_cards_list";    public static final String KEY_BIND_CARD = "bind_card";    public static final String KEY_CARD_BIN = "card_bin";

// 服务器端返回的数据字段名(get code)GC_? public static final String GC_MSG = "msg"; public static final String GC_DATA = "http://www.mamicode.com/data"; public static final String GC_USERID = "userid";// 服务器返回的retcode状态码RE_? public static final String RE_OK = "0000"; // 成功 public static final String RE_DBERR = "2000"; // 数据库查询错误 public static final String RE_THIRDERR = "2001"; // 第三方系统错误 public static final String RE_SESSIONERR = "2002"; // 用户未登录 public static final String RE_DATAERR = "2003"; // 数据错误 public static final String RE_VERIFYCODE = "1001"; // 验证码不正确 public static final String RE_REGISTERERR = "1000"; // 注册失败 public static final String RE_RETMSG = "retmsg"; // 错误信息 public static final String APPDATA = "http://www.mamicode.com/datas"; // public static final String LOCKDATA = "http://www.mamicode.com/lockdata"; // private static ProgressDialog proDialog; public static final int ATYSET = 1; public static final int ATYRECHARGE = 2; public static final int ATYREPORTLOSS = 3; public static final int ATYCONSUMERQUERY = 4; public static final int ATYDFPAYMENT = 5; public static final int ATYDFRECORD = 6; public static final int ATYPAYDIALOG = 7; public static final int ATYMYBANKCARDS = 8; public static final int ATYRETRIEVEPAYPWD = 9; /** * 获取当前时间 * * @return */ public static String getCurTime() { Date now = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("MMddHHmm"); String time = dateFormat.format(now); return time; } public static int getDay() { Calendar now = Calendar.getInstance(); int day = now.get(Calendar.DAY_OF_MONTH); return day; } public static int getMonth() { Calendar now = Calendar.getInstance(); int month = now.get(Calendar.MONTH); return month; } public static String getWeek() { Calendar now = Calendar.getInstance(); int week = now.get(Calendar.DAY_OF_WEEK); String str_week = ""; switch (week) { case 1: str_week = "星期日"; break; case 2: str_week = "星期一"; break; case 3: str_week = "星期二"; break; case 4: str_week = "星期三"; break; case 5: str_week = "星期四"; break; case 6: str_week = "星期五"; break; case 7: str_week = "星期六"; break; default: break; } return str_week; } /** * 判断手机网络 * * @param activity * @return */ public static boolean hasInternet(Activity activity) { ConnectivityManager manager = (ConnectivityManager) activity .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); if (info == null || !info.isAvailable()) { return false; } if (info.isRoaming()) { return true; } return true; } public static String getNetStatusCode(String retcode) { int i = Integer.parseInt(retcode); String str_status = ""; switch (i) { case 0: break; case 1000: str_status = "注册失败"; break; case 1001: str_status = "验证码错误"; break; case 2000: str_status = "数据库查询错误"; break; case 2001: str_status = "第三方系统错误"; break; case 2002: str_status = "用户未登录"; break; case 2003: str_status = "数据错误"; break; case 2004: str_status = "文件读写错误"; break;default: str_status = "未知错误"; break; } return str_status; } /** * 判断是否为数字 * * @param str * @return */ public static boolean isNumeric(String str) { Pattern pattern = Pattern.compile("[0-9]*"); return pattern.matcher(str).matches(); } public static void showProgress(Context context, String message) { proDialog = new ProgressDialog(context); proDialog.setMessage(message); proDialog.setCanceledOnTouchOutside(false); proDialog.setCancelable(false); proDialog.show(); } public static void showProgress(Context context, int message) { proDialog = new ProgressDialog(context); proDialog.setMessage(context.getString(message)); proDialog.setCanceledOnTouchOutside(false); proDialog.setCancelable(false); proDialog.show(); } public static void hideProgress() { if (proDialog != null && proDialog.isShowing()) { proDialog.dismiss(); } } public static SchemeRegistry getSchemeRegistry() { try { KeyStore trustStore = KeyStore.getInstance(KeyStore .getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 10000); HttpConnectionParams.setSoTimeout(params, 10000); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory .getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); return registry; } catch (Exception e) { return null; } } /** * 检查网络环境并提示用户 * * @return */ public static void showNetWorkWarring(final Context context) { Dialog dialog = new AlertDialog.Builder(context) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle(R.string.prompt) .setMessage(R.string.NetWork_prompt) .setNegativeButton(R.string.text_cancel, null) .setPositiveButton(R.string.text_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Intent mIntent = new Intent( Settings.ACTION_SETTINGS); context.startActivity(mIntent); } }).create(); dialog.setCanceledOnTouchOutside(false); dialog.show(); } public static int getVerCode(Context context) { int verCode = -1; try { verCode = context.getPackageManager().getPackageInfo( context.getPackageName(), 0).versionCode; } catch (NameNotFoundException e) { } return verCode; } public static String getVerName(Context context) { String verName = ""; try { verName = context.getPackageManager().getPackageInfo( context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { } return verName; } public static void putLog(String logs) { if (DEBUG) { System.out.println(logs); } } public static void putLog(Object logs) { if (DEBUG) { System.out.println(logs); } } public static void putLog(String tag, String msg) { if (DEBUG) { Log.i(tag, msg); } } public static void showThrowableMsg(Throwable throwable, Context context) { int msgid = R.string.socket_timout_exception; if (throwable instanceof SocketTimeoutException) { msgid = R.string.socket_timout_exception; } else if (throwable instanceof HttpHostConnectException) { msgid = R.string.http_connect_exception; } Toast.makeText(context, msgid, Toast.LENGTH_SHORT).show(); } /** * 验证身份证号是否符合规则 * * @param text * 身份证号 * @return */ public static boolean personIdValidation(String text) { String regx = "[0-9]{17}x"; String reg1 = "[0-9]{15}"; String regex = "[0-9]{18}"; return text.matches(regx) || text.matches(reg1) || text.matches(regex); } public static void showSoftInput(final EditText edittext) { Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() { InputMethodManager inputManager = (InputMethodManager) edittext.getContext().getSystemService( Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(edittext, 0); } }, 400); } public static String getDeviceInfo(Context context) { try { org.json.JSONObject json = new org.json.JSONObject(); android.telephony.TelephonyManager tm = (android.telephony.TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); String device_id = tm.getDeviceId(); android.net.wifi.WifiManager wifi = (android.net.wifi.WifiManager) context .getSystemService(Context.WIFI_SERVICE); String mac = wifi.getConnectionInfo().getMacAddress(); json.put("mac", mac); if (TextUtils.isEmpty(device_id)) { device_id = mac; } if (TextUtils.isEmpty(device_id)) { device_id = android.provider.Settings.Secure.getString( context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); } json.put("device_id", device_id); return json.toString(); } catch (Exception e) { e.printStackTrace(); } return null; } public static RequestParams addOSInfo(Context context) { RequestParams params = new RequestParams(); params.add("os", "android"); params.add("osversion", android.os.Build.VERSION.RELEASE); params.add("moblietype", android.os.Build.MODEL); params.add("appversion", getVerName(context)); putLog("=====:" + params.toString()); return params; }}

 

xifu-1011-Config--配置--demo