/** * 检查网络状态 * * @return 1表示仅有 移动网络 2表示仅有wifi 3表示移动wifi都开通 4表示移动wifi都不通 */ public int checkNetwork() { if (Machine.isTablet(mContext)) { return 0; } ConnectivityManager conMan = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); if (conMan == null) { return 0; } android.net.NetworkInfo.State mobilestate = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); android.net.NetworkInfo.State wifistate = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); if (wifistate != android.net.NetworkInfo.State.CONNECTED && mobilestate == android.net.NetworkInfo.State.CONNECTED) { return 1; } if (mobilestate != android.net.NetworkInfo.State.CONNECTED && wifistate == android.net.NetworkInfo.State.CONNECTED) { return 2; } if (mobilestate == android.net.NetworkInfo.State.CONNECTED && wifistate == android.net.NetworkInfo.State.CONNECTED) { return 3; } if (mobilestate != android.net.NetworkInfo.State.CONNECTED && wifistate != android.net.NetworkInfo.State.CONNECTED) { return 4; } return 0; }
/** * 获取Drawable图片 * * @param drawableId * @param addHashMap 是否添加进hashMap的标识 * @return */ public Drawable getViewDrawable(int drawableId, boolean addHashMap) { Drawable image = getDrawable(drawableId); // 在此过滤自定义的图片资源ID if (drawableId != KILL_ICON_COPY) { if (image == null) { try { if (Machine.isTablet(mContext)) { image = ImageExplorer.getInstance(mContext) .getDrawableForDensity(mContext.getResources(), drawableId); if (addHashMap) { putViewDrawable(drawableId, image); } } else { image = mContext.getResources().getDrawable(drawableId); } } catch (Exception e) { e.printStackTrace(); } } } return image; }
/** * 获得屏幕高度 * * @return */ public int getScreenHeight() { if (Machine.isTablet(mContext)) { return DrawUtils.getTabletScreenHeight(mContext); } return mMetrics.heightPixels; }
/** * 获得屏幕宽度 * * @return */ public int getScreenWidth() { if (Machine.isTablet(mContext)) { return DrawUtils.getTabletScreenWidth(mContext); } return mMetrics.widthPixels; }