コード例 #1
0
 public static int dp2px(int dip) {
   Context context = KissTools.getApplicationContext();
   Resources resources = context.getResources();
   int px =
       Math.round(
           TypedValue.applyDimension(
               TypedValue.COMPLEX_UNIT_DIP, dip, resources.getDisplayMetrics()));
   return px;
 }
コード例 #2
0
  public static final String getAndroidId() {
    Context context = KissTools.getApplicationContext();
    String androidID = null;
    try {
      androidID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
    } catch (Exception e) {

    }
    return androidID;
  }
コード例 #3
0
  public static final String getWlanMac() {
    Context context = KissTools.getApplicationContext();
    String wlanMac = null;
    try {
      WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
      wlanMac = wm.getConnectionInfo().getMacAddress();
    } catch (Exception e) {

    }
    return wlanMac;
  }
コード例 #4
0
  public static final String getIMEI() {
    Context context = KissTools.getApplicationContext();
    String deviceIMEI = null;
    try {
      TelephonyManager teleManager =
          (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
      deviceIMEI = teleManager.getDeviceId();
    } catch (Exception e) {

    }
    return deviceIMEI;
  }
コード例 #5
0
 public static float getScreenInches() {
   Context context = KissTools.getApplicationContext();
   float screenInches = -1;
   try {
     Resources resources = context.getResources();
     DisplayMetrics dm = resources.getDisplayMetrics();
     double width = Math.pow(dm.widthPixels / dm.xdpi, 2);
     double height = Math.pow(dm.heightPixels / dm.ydpi, 2);
     screenInches = (float) (Math.sqrt(width + height));
   } catch (Exception e) {
   }
   return screenInches;
 }
コード例 #6
0
 public static int sp2px(float sp) {
   Context context = KissTools.getApplicationContext();
   final float scale = context.getResources().getDisplayMetrics().scaledDensity;
   int px = Math.round(sp * scale);
   return px;
 }
コード例 #7
0
 public static int px2dp(int px) {
   Context context = KissTools.getApplicationContext();
   DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
   int dp = Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
   return dp;
 }