@Override
  protected void onBindView(@NonNull View view) {
    super.onBindView(view);
    final NetworkUsageInfo usage = mUsage;
    if (usage == null) return;
    final double[][] chartUsage = usage.getChartUsage();
    final int days = chartUsage.length;

    final BarSet apiSet = new BarSet();
    final BarSet mediaSet = new BarSet();
    final BarSet usageStatisticsSet = new BarSet();

    double dayUsageMax = 0;
    for (int i = 0; i < days; i++) {
      String day = String.valueOf(i + 1);
      final double[] dayUsage = chartUsage[i];
      apiSet.addBar(day, (float) dayUsage[RequestType.API.getValue()]);
      mediaSet.addBar(day, (float) dayUsage[RequestType.MEDIA.getValue()]);
      usageStatisticsSet.addBar(day, (float) dayUsage[RequestType.USAGE_STATISTICS.getValue()]);
      dayUsageMax = Math.max(dayUsageMax, MathUtils.sum(dayUsage));
    }

    apiSet.setColor(Color.RED);
    mediaSet.setColor(Color.GREEN);
    usageStatisticsSet.setColor(Color.BLUE);

    mTotalUsage.setText(
        Utils.calculateProperSize((usage.getTotalSent() + usage.getTotalReceived()) * 1024));
    mTotalUsageSent.setText(Utils.calculateProperSize(usage.getTotalSent() * 1024));
    mTotalUsageReceived.setText(Utils.calculateProperSize(usage.getTotalReceived() * 1024));
    mDayUsageMax.setText(Utils.calculateProperSize((usage.getDayUsageMax()) * 1024));
    mDayMin.setText(String.valueOf(usage.getDayMin()));
    mDayMid.setText(String.valueOf((usage.getDayMin() + usage.getDayMax()) / 2));
    mDayMax.setText(String.valueOf(usage.getDayMax()));
  }
Example #2
0
 public DraftsAdapter(final Context context) {
   super(context, R.layout.list_item_draft, null, new String[0], new int[0], 0);
   DaggerGeneralComponent.builder()
       .applicationModule(ApplicationModule.get(context))
       .build()
       .inject(this);
   mMediaLoadingHandler = new MediaLoadingHandler(R.id.media_preview_progress);
   mMediaPreviewStyle =
       Utils.getMediaPreviewStyle(mPreferences.getString(KEY_MEDIA_PREVIEW_STYLE, null));
 }
 @Override
 protected void onApplyThemeResource(@NonNull Resources.Theme theme, int resId, boolean first) {
   mCurrentThemeColor = getThemeColor();
   mCurrentActionBarColor = getActionBarColor();
   mCurrentThemeFontFamily = getThemeFontFamily();
   mCurrentThemeBackgroundAlpha = getThemeBackgroundAlpha();
   mCurrentThemeBackgroundOption = getThemeBackgroundOption();
   mProfileImageStyle = Utils.getProfileImageStyle(this);
   super.onApplyThemeResource(theme, resId, first);
 }
 protected long[] getAccountIds() {
   final Bundle args = getArguments();
   if (args != null && args.getLong(EXTRA_ACCOUNT_ID) > 0) {
     return new long[] {args.getLong(EXTRA_ACCOUNT_ID)};
   }
   final FragmentActivity activity = getActivity();
   if (activity instanceof HomeActivity) {
     return ((HomeActivity) activity).getActivatedAccountIds();
   }
   return Utils.getActivatedAccountIds(getActivity());
 }
  /**
   * Send registration token to backend server if available
   *
   * @param token
   */
  private void sendRegistrationToServer(final String token) {
    PushBackendServer backend = new PushBackendServer(this);

    // We do this once for every account.
    // The backend server only accepts our reg id if at least one account
    // is configured server-side.
    for (long userId : Utils.getAccountIds(this)) {
      if (backend.register(String.valueOf(userId), token)) {
        mPreferences.edit().putBoolean(SharedPreferenceConstants.GCM_TOKEN_SENT, true).apply();
        break;
      }
    }
  }
Example #6
0
  @Override
  public void bindView(final View view, final Context context, final Cursor cursor) {
    final DraftViewHolder holder = (DraftViewHolder) view.getTag();
    final long[] accountIds =
        TwidereArrayUtils.parseLongArray(cursor.getString(mIndices.account_ids), ',');
    final String text = cursor.getString(mIndices.text);
    final ParcelableMediaUpdate[] mediaUpdates =
        ParcelableMediaUpdate.fromJSONString(cursor.getString(mIndices.media));
    final long timestamp = cursor.getLong(mIndices.timestamp);
    final int actionType = cursor.getInt(mIndices.action_type);
    final String actionName = getActionName(context, actionType);
    holder.media_preview_container.setStyle(mMediaPreviewStyle);
    if (actionType == Drafts.ACTION_UPDATE_STATUS) {
      final ParcelableMedia[] media = ParcelableMedia.fromMediaUpdates(mediaUpdates);
      holder.media_preview_container.setVisibility(View.VISIBLE);
      holder.media_preview_container.displayMedia(
          media, mImageLoader, -1L, null, mMediaLoadingHandler);
    } else {
      holder.media_preview_container.setVisibility(View.GONE);
    }
    holder.content.drawEnd(getAccountColors(context, accountIds));
    holder.setTextSize(mTextSize);
    final boolean emptyContent = TextUtils.isEmpty(text);
    if (emptyContent) {
      holder.text.setText(R.string.empty_content);
    } else {
      holder.text.setText(text);
    }
    holder.text.setTypeface(
        holder.text.getTypeface(), emptyContent ? Typeface.ITALIC : Typeface.NORMAL);

    if (timestamp > 0) {
      final String timeString = Utils.formatSameDayTime(context, timestamp);
      holder.time.setText(
          context.getString(R.string.action_name_saved_at_time, actionName, timeString));
    } else {
      holder.time.setText(actionName);
    }
  }
 @Override
 public void onUserClick(int position, DirectMessageEntry entry) {
   Utils.openUserProfile(
       getActivity(), entry.account_id, entry.conversation_id, entry.screen_name, null);
 }
 @Override
 public void onEntryClick(int position, DirectMessageEntry entry) {
   Utils.openMessageConversation(getActivity(), entry.account_id, entry.conversation_id);
 }
 @Override
 public final void restart() {
   Utils.restartActivity(this);
 }