예제 #1
0
 /**
  * 检查网络状态
  *
  * @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;
 }
예제 #2
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;
 }
  /**
   * 设置壁纸
   *
   * @param context context
   * @param resources 如果是主题包,必须用主题包的resource
   * @param resId 图片资源id
   */
  private void setWallpaper(Context context, Resources resources, int resId) {
    OutOfMemoryHandler.handle();

    if (context == null || resources == null || resId < 0) {
      return;
    }

    boolean bSetOk = false;

    WallpaperManager wpm = null;
    Drawable drb = null;
    BitmapDrawable bdrb = null;
    //		InputStream in = null;
    ByteArrayOutputStream out = null;
    try {
      // 获取宽高
      // 竖屏状态
      int screenW = 0;
      int screenH = 0;
      if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        screenW = resources.getDisplayMetrics().widthPixels;
        screenH = resources.getDisplayMetrics().heightPixels;
      } else {
        screenW = resources.getDisplayMetrics().heightPixels;
        screenH = resources.getDisplayMetrics().widthPixels;
      }

      wpm = (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE);
      drb = resources.getDrawable(resId);
      {
        // 图片处理
        // 对Lephone的特殊处理
        if (Machine.isLephone()) {
          bdrb = WindowControl.prepareWallpaper((BitmapDrawable) drb, screenH, screenH, resources);
        } else {
          bdrb =
              WindowControl.prepareWallpaper(
                  (BitmapDrawable) drb,
                  screenW * WindowControl.WALLPAPER_SCREENS_SPAN,
                  screenH,
                  resources);
        }
        out = new ByteArrayOutputStream();
        boolean b = bdrb.getBitmap().compress(CompressFormat.JPEG, 100, out);
        if (b) {
          mInputStream = new BufferedInputStream(new ByteArrayInputStream(out.toByteArray()));
          out.close();
          out = null;

        } else {
          mInputStream = resources.openRawResource(resId);
        }
        bSetOk = true;
        mHandler.sendEmptyMessage(MSG_SET_WALLPAPER_INPUTSTREAM);
      }
    } catch (OutOfMemoryError e) {
      // 内存爆掉,不进行图片处理
      OutOfMemoryHandler.handle();

      try {
        if (wpm != null) {
          mInputStream = resources.openRawResource(resId);
          mHandler.sendEmptyMessage(MSG_SET_WALLPAPER_INPUTSTREAM);
        }
        bSetOk = true;
      } catch (Throwable e2) {
        Log.i(LogConstants.HEART_TAG, "fail to re-change wallpaper " + e2);
      }
    } catch (IOException e) {
      Log.i(LogConstants.HEART_TAG, "fail to change wallpaper " + e);
    } catch (Exception e) {
      Log.i(LogConstants.HEART_TAG, "fail to change wallpaper " + e);
    } finally {
      if (null != out) {
        try {
          out.close();
        } catch (Exception e2) {
          e2.printStackTrace();
        }
      }
    }
  }
예제 #4
0
 /**
  * 获得屏幕高度
  *
  * @return
  */
 public int getScreenHeight() {
   if (Machine.isTablet(mContext)) {
     return DrawUtils.getTabletScreenHeight(mContext);
   }
   return mMetrics.heightPixels;
 }
예제 #5
0
 /**
  * 获得屏幕宽度
  *
  * @return
  */
 public int getScreenWidth() {
   if (Machine.isTablet(mContext)) {
     return DrawUtils.getTabletScreenWidth(mContext);
   }
   return mMetrics.widthPixels;
 }