Example #1
0
    @Override
    public UnreadCount workInBackground(Void... params) throws TaskException {
      if (!AppContext.isLogedin()) return null;

      UnreadCount result =
          SinaSDK.getInstance(AppContext.getToken()).remindUnread(AppContext.getUser().getIdstr());
      //			result.setMention_status(500);
      //			result.setMention_cmt(100);
      //			result.setCmt(20);
      //			result.setFollower(10);

      AppContext.setUnreadCount(new UnreadCount());
      ;
      if (AppSettings.isNotifyComment()) AppContext.getUnreadCount().setCmt(result.getCmt());
      if (AppSettings.isNotifyCommentMention())
        AppContext.getUnreadCount().setMention_cmt(result.getMention_cmt());
      if (AppSettings.isNotifyStatusMention())
        AppContext.getUnreadCount().setMention_status(result.getMention_status());
      if (AppSettings.isNotifyFollower())
        AppContext.getUnreadCount().setFollower(result.getFollower());
      if (AppSettings.isNotifyDm()) AppContext.getUnreadCount().setDm(result.getDm());

      // 更新DB
      result.setId(AppContext.getUser().getIdstr());
      SinaDB.getSqlite().insert(null, AppContext.getUnreadCount());
      return result;
    }
Example #2
0
  private void resetTheTime() {
    Logger.v(TAG, "reset unread block");

    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);

    // 指定时间
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.SECOND, AppSettings.getUnreadInterval());
    Logger.v(TAG, String.format("未读消息,在%s后还是读取", AppSettings.getUnreadInterval()));

    am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), getOperation());
  }
Example #3
0
  public static void startService() {
    if (!AppSettings.isNotifyEnable()) return;

    Intent intent = new Intent(GlobalContext.getInstance(), UnreadService.class);
    intent.setAction(ACTION_GET);
    GlobalContext.getInstance().startService(intent);
  }
Example #4
0
  private void setFabType() {
    if (fabType != AppSettings.getFabBtnType()) {
      fabType = AppSettings.getFabBtnType();
      invalidateOptionsMenu();
      if (fabType == 0) {
        btnFab.setImageResource(R.drawable.ic_menu_edit_white);
      } else {
        btnFab.setImageResource(R.drawable.ic_refresh_light);
      }
    }
    btnFab.setVisibility(canFragmentRefresh() ? View.VISIBLE : View.INVISIBLE);

    FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) btnFab.getLayoutParams();
    params.gravity = Gravity.BOTTOM;
    if (AppSettings.getFabBtnPosition() == 0) params.gravity |= Gravity.LEFT;
    else params.gravity |= Gravity.RIGHT;
  }
Example #5
0
  /**
   * 显示高清头像
   *
   * @param user
   * @return
   */
  public static String getUserPhoto(WeiBoUser user) {
    if (user == null) return "";

    if (AppSettings.isLargePhoto()) {
      return user.getAvatar_large();
    }

    return user.getProfile_image_url();
  }
Example #6
0
 void fabBtnCLicked(View v) {
   if (AppSettings.getFabBtnType() == 0) {
     PublishActivity.publishStatus(this, null);
   } else {
     Fragment fragment = getFragmentManager().findFragmentByTag(FRAGMENT_TAG);
     if (fragment != null && fragment instanceof AStripTabsFragment) {
       fragment = ((AStripTabsFragment) fragment).getCurrentFragment();
       if (fragment != null && fragment instanceof ARefreshFragment) {
         ((ARefreshFragment) fragment).setRefreshingRequestData();
       }
     }
   }
 }
Example #7
0
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    menu.findItem(R.id.publish).setVisible(AppSettings.getFabBtnType() == 1);

    if (OfflineService.getInstance() == null
        || OfflineService.getInstance().getStatus() == OfflineService.OfflineStatus.init
        || OfflineService.getInstance().getStatus() == OfflineService.OfflineStatus.finished) {
      menu.findItem(R.id.toggle_offline).setVisible(true);
      menu.findItem(R.id.stop_offline).setVisible(false);
    } else {
      menu.findItem(R.id.toggle_offline).setVisible(false);
      menu.findItem(R.id.stop_offline).setVisible(true);
    }
    menu.findItem(R.id.notification_settings)
        .setVisible(menuFragment.getSelectedId() == MenuFragment.MENU_NOTIFICATION);

    return super.onPrepareOptionsMenu(menu);
  }
Example #8
0
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    menu.findItem(R.id.friendGroups).setVisible(false);

    menu.findItem(R.id.publish).setVisible(AppSettings.getFabBtnType() == 1);

    menu.findItem(R.id.about).setVisible(false);
    menu.findItem(R.id.feedback).setVisible(false);

    // 离线功能暂时没空维护,先屏蔽
    menu.findItem(R.id.toggle_offline).setVisible(false);

    // 显示的是首页
    if (lastSelectedMenu != null) {
      if (lastSelectedMenu.getType().equals("1")) menu.findItem(R.id.friendGroups).setVisible(true);
    }

    return super.onPrepareOptionsMenu(menu);
  }
Example #9
0
  @Override
  public boolean onBackClick() {
    if (AppSettings.isAppResident()) {
      if (lastSelectedMenu != null && !"1".equals(lastSelectedMenu.getType())) {
        onMenuSelected(MenuGenerator.generateMenu("1"), true, null);
        return true;
      } else {
        if (isDrawerOpened()) {
          closeDrawer();

          return true;
        }
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addCategory(Intent.CATEGORY_HOME);
        startActivity(intent);
      }
      return true;
    } else {
      if (!canFinish) {
        canFinish = true;

        showMessage(R.string.comm_hint_exit);

        new Handler()
            .postDelayed(
                new Runnable() {

                  @Override
                  public void run() {
                    canFinish = false;
                  }
                },
                1500);

        return true;
      }

      setMDestory(true);
      return super.onBackClick();
    }
  }
Example #10
0
  public static String getStatusMulImage(String thumbImage) {
    switch (AppSettings.getPictureMode()) {
        // MODE_AUTO
      case 2:
        if (SystemUtils.getNetworkType() == SystemUtils.NetWorkType.wifi)
          return thumbImage.replace("thumbnail", "bmiddle");

        return thumbImage;
        // MODE_ALWAYS_ORIG
      case 1:
        return thumbImage.replace("thumbnail", "bmiddle");
      case 3:
        return thumbImage.replace("thumbnail", "bmiddle");
        // MODE_ALWAYS_THUMB
      case 0:
        return thumbImage;
      default:
        return thumbImage;
    }
  }
Example #11
0
  @Override
  public boolean onBackClick() {
    if (AppSettings.isAppResident()) {
      //            if (menuFragment.backToMain()) {
      //                return true;
      //            } else {
      if (isDrawerOpened()) {
        closeDrawer();

        return true;
      }
      Intent intent = new Intent(Intent.ACTION_MAIN);
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent.addCategory(Intent.CATEGORY_HOME);
      startActivity(intent);
      //            }
      return true;
    } else {
      if (!canFinish) {
        canFinish = true;

        showMessage(R.string.hint_exit);

        new Handler()
            .postDelayed(
                new Runnable() {

                  @Override
                  public void run() {
                    canFinish = false;
                  }
                },
                1500);

        return true;
      }

      return super.onBackClick();
    }
  }
Example #12
0
  public static void setStatusBar(Activity activity) {
    if (true) return;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      activity.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
      Window window = activity.getWindow();
      window.clearFlags(
          WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
              | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
      window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); // |
      // View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
      window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
      //            window.setStatusBarColor(Utils.resolveColor(activity,
      // R.attr.theme_statusbar_color, Color.BLUE));
      window.setStatusBarColor(Color.parseColor("#20000000"));
      window.setNavigationBarColor(
          activity
              .getResources()
              .getColor(ThemeUtils.themeColorArr[AppSettings.getThemeColor()][1]));
      //            window.setNavigationBarColor(Utils.resolveColor(activity, R.attr.theme_color,
      // Color.BLUE));

      //            Window window = activity.getWindow();
      //            window.requestFeature(Window.FEATURE_NO_TITLE);
      //            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
      //                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
      //
      // window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
      //                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
      //                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
      //            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
      //            window.setStatusBarColor(Color.TRANSPARENT);
      //            window.setNavigationBarColor(Utils.resolveColor(activity,
      // R.attr.theme_statusbar_color, Color.TRANSPARENT));
    }
  }
Example #13
0
 @Override
 protected int configTheme() {
   return ThemeUtils.themeArr[AppSettings.getThemeColor()][1];
 }
Example #14
0
  public static File getUploadFile(File source) {
    if (source.getName().toLowerCase().endsWith(".gif")) {
      Logger.w("上传图片是GIF图片,上传原图");
      return source;
    }

    File file = null;

    String imagePath =
        GlobalContext.getInstance().getAppPath()
            + SettingUtility.getStringSetting("draft")
            + File.separator;

    int sample = 1;
    int maxSize = 0;

    int type = AppSettings.getUploadSetting();
    // 自动,WIFI时原图,移动网络时高
    if (type == 0) {
      if (SystemUtils.getNetworkType() == SystemUtils.NetWorkType.wifi) type = 1;
      else type = 2;
    }
    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(source.getAbsolutePath(), opts);
    switch (type) {
        // 原图
      case 1:
        Logger.w("原图上传");
        file = source;
        break;
        // 高
      case 2:
        sample = BitmapDecoder.calculateInSampleSize(opts, 1920, 1080);
        Logger.w("高质量上传");
        maxSize = 700 * 1024;
        imagePath = imagePath + "高" + File.separator + source.getName();
        file = new File(imagePath);
        break;
        // 中
      case 3:
        Logger.w("中质量上传");
        sample = BitmapDecoder.calculateInSampleSize(opts, 1280, 720);
        maxSize = 300 * 1024;
        imagePath = imagePath + "中" + File.separator + source.getName();
        file = new File(imagePath);
        break;
        // 低
      case 4:
        Logger.w("低质量上传");
        sample = BitmapDecoder.calculateInSampleSize(opts, 1280, 720);
        maxSize = 100 * 1024;
        imagePath = imagePath + "低" + File.separator + source.getName();
        file = new File(imagePath);
        break;
      default:
        break;
    }

    // 压缩图片
    if (type != 1 && !file.exists()) {
      Logger.w(String.format("压缩图片,原图片 path = %s", source.getAbsolutePath()));
      byte[] imageBytes = FileUtils.readFileToBytes(source);
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      try {
        out.write(imageBytes);
      } catch (Exception e) {
      }

      Logger.w(String.format("原图片大小%sK", String.valueOf(imageBytes.length / 1024)));
      if (imageBytes.length > maxSize) {
        // 尺寸做压缩
        BitmapFactory.Options options = new BitmapFactory.Options();

        if (sample > 1) {
          options.inSampleSize = sample;
          Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length, options);
          Logger.w(String.format("压缩图片至大小:%d*%d", bitmap.getWidth(), bitmap.getHeight()));
          out.reset();
          bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
          imageBytes = out.toByteArray();
        }

        options.inSampleSize = 1;
        if (imageBytes.length > maxSize) {
          BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length, options);
          Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length, options);

          int quality = 90;
          out.reset();
          Logger.w(String.format("压缩图片至原来的百分之%d大小", quality));
          bitmap.compress(Bitmap.CompressFormat.JPEG, quality, out);
          while (out.toByteArray().length > maxSize) {
            out.reset();
            quality -= 10;
            Logger.w(String.format("压缩图片至原来的百分之%d大小", quality));
            bitmap.compress(Bitmap.CompressFormat.JPEG, quality, out);
          }
        }
      }

      try {
        if (!file.getParentFile().exists()) file.getParentFile().mkdirs();

        Logger.w(String.format("最终图片大小%sK", String.valueOf(out.toByteArray().length / 1024)));
        FileOutputStream fo = new FileOutputStream(file);
        fo.write(out.toByteArray());
        fo.flush();
        fo.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    return file;
  }
Example #15
0
  public static String getUserScreenName(WeiBoUser user) {
    if (AppSettings.isShowRemark() && !TextUtils.isEmpty(user.getRemark())) return user.getRemark();

    return user.getScreen_name();
  }
Example #16
0
 public static void setTextSize(TextView textView) {
   textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, AppSettings.getTextSize());
 }