コード例 #1
0
 @Override
 public void update(Observable arg0, Object data) {
   if (data instanceof DownloadTask) {
     DownloadTask task = (DownloadTask) data;
     if (task.getType() == DownloadTask.SKIN) {
       reshUI(task);
     }
   } else if (data instanceof SkinThemeApp) {
     SkinThemeApp skinTheme = (SkinThemeApp) data;
     if (selectedIndex != -1) {
       reshPICStatusUI(selectedIndex);
     }
     for (int i = 0; i < datas.size(); i++) {
       if (skinTheme.getID().equals(datas.get(i).getTid())) {
         selectedIndex = i;
         reshPICStatusUI(selectedIndex);
         break;
       }
     }
   } else if (data instanceof MessageIntent) {
     MessageIntent mi = (MessageIntent) data;
     if (mi.getAction().equals(MessageIntent.SKINTHEMEERROR)) {
       ToastUtil.showText("皮肤加载失败!");
       notifyDataSetChanged();
     }
   }
 }
コード例 #2
0
  /**
   * 刷新ui
   *
   * @param task
   */
  private void reshUI(final DownloadTask task) {
    if (task.getStatus() == DownloadTask.DOWNLOAD_FINISH) {
      new Thread() {

        @Override
        public void run() {
          boolean isExists = SkinThemeDB.getSkinThemeDB(context).skinThemeIsExists(task.getTid());
          if (!isExists) {

            // 往皮肤数据库添加数据
            SkinThemeApp skinTheme = new SkinThemeApp();
            skinTheme.setID(task.getTid());
            skinTheme.setThemeName(task.gettName());
            skinTheme.setAssetsType(SkinThemeApp.NET);
            skinTheme.setAddTime(DateUtil.dateToString(new Date()));
            skinTheme.setDownloadPath(task.getFilePath());

            // 解压皮肤文件
            String path = context.getFilesDir().getParent() + File.separator + "files";
            String outputDirectory =
                path + File.separator + "skin" + File.separator + task.getTid();

            String zipPath = task.getFilePath();
            String zipName = task.getTid();

            skinTheme.setUnZipPath(outputDirectory);

            SkinThemeDB.getSkinThemeDB(context).add(skinTheme);

            UnzipUtil.unZip(context, zipName, zipPath, outputDirectory);

            Message msg = new Message();
            msg.obj = skinTheme;
            ObserverManage.getObserver().setMessage(msg);
          }
        }
      }.start();

      ToastUtil.showText("皮肤: " + task.gettName() + " 下载完成");
    }

    for (int i = 0; i < datas.size(); i++) {
      DownloadTask temp = datas.get(i);
      if (task.getTid().equals(temp.getTid())) {
        datas.remove(i);
        datas.add(i, task);
        reshPICStatusUI(i);
        break;
      }
    }
  }