Java Code Examples for org.telegram.messenger.AndroidUtilities#formatShortDuration()

The following examples show how to use org.telegram.messenger.AndroidUtilities#formatShortDuration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VideoTimelineView.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void setTime(int timeInSeconds) {
    if (timeInSeconds != lastTime) {
        lastTime = timeInSeconds;
        String s = AndroidUtilities.formatShortDuration(timeInSeconds);
        tooltipLayout = new StaticLayout(s, tooltipPaint, (int) tooltipPaint.measureText(s), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
    }
}
 
Example 2
Source File: WebPlayerView.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void setDuration(int value) {
    if (duration == value || value < 0 || isStream) {
        return;
    }
    duration = value;
    durationLayout = new StaticLayout(AndroidUtilities.formatShortDuration(duration), textPaint, AndroidUtilities.dp(1000), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    if (durationLayout.getLineCount() > 0) {
        durationWidth = (int) Math.ceil(durationLayout.getLineWidth(0));
    }
    invalidate();
}
 
Example 3
Source File: WebPlayerView.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void setProgress(int value) {
    if (progressPressed || value < 0 || isStream) {
        return;
    }
    progress = value;
    progressLayout = new StaticLayout(AndroidUtilities.formatShortDuration(progress), textPaint, AndroidUtilities.dp(1000), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    invalidate();
}
 
Example 4
Source File: VideoTimelineView.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void setTime(int timeInSeconds) {
    if (timeInSeconds != lastTime) {
        lastTime = timeInSeconds;
        String s = AndroidUtilities.formatShortDuration(timeInSeconds);
        tooltipLayout = new StaticLayout(s, tooltipPaint, (int) tooltipPaint.measureText(s), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
    }
}
 
Example 5
Source File: WebPlayerView.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void setDuration(int value) {
    if (duration == value || value < 0 || isStream) {
        return;
    }
    duration = value;
    durationLayout = new StaticLayout(AndroidUtilities.formatShortDuration(duration), textPaint, AndroidUtilities.dp(1000), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    if (durationLayout.getLineCount() > 0) {
        durationWidth = (int) Math.ceil(durationLayout.getLineWidth(0));
    }
    invalidate();
}
 
Example 6
Source File: WebPlayerView.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void setProgress(int value) {
    if (progressPressed || value < 0 || isStream) {
        return;
    }
    progress = value;
    progressLayout = new StaticLayout(AndroidUtilities.formatShortDuration(progress), textPaint, AndroidUtilities.dp(1000), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    invalidate();
}
 
Example 7
Source File: DataUsageActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    switch (holder.getItemViewType()) {
        case 0: {
            if (position == resetSection2Row) {
                holder.itemView.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
            } else {
                holder.itemView.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
            }
            break;
        }
        case 1: {
            TextSettingsCell textCell = (TextSettingsCell) holder.itemView;
            if (position == resetRow) {
                textCell.setTag(Theme.key_windowBackgroundWhiteRedText2);
                textCell.setText(LocaleController.getString("ResetStatistics", R.string.ResetStatistics), false);
                textCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText2));
            } else {
                int type;
                textCell.setTag(Theme.key_windowBackgroundWhiteBlackText);
                textCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                if (position == callsSentRow || position == callsReceivedRow || position == callsBytesSentRow || position == callsBytesReceivedRow) {
                    type = StatsController.TYPE_CALLS;
                } else if (position == messagesSentRow || position == messagesReceivedRow || position == messagesBytesSentRow || position == messagesBytesReceivedRow) {
                    type = StatsController.TYPE_MESSAGES;
                } else if (position == photosSentRow || position == photosReceivedRow || position == photosBytesSentRow || position == photosBytesReceivedRow) {
                    type = StatsController.TYPE_PHOTOS;
                } else if (position == audiosSentRow || position == audiosReceivedRow || position == audiosBytesSentRow || position == audiosBytesReceivedRow) {
                    type = StatsController.TYPE_AUDIOS;
                } else if (position == videosSentRow || position == videosReceivedRow || position == videosBytesSentRow || position == videosBytesReceivedRow) {
                    type = StatsController.TYPE_VIDEOS;
                } else if (position == filesSentRow || position == filesReceivedRow || position == filesBytesSentRow || position == filesBytesReceivedRow) {
                    type = StatsController.TYPE_FILES;
                } else {
                    type = StatsController.TYPE_TOTAL;
                }
                if (position == callsSentRow) {
                    textCell.setTextAndValue(LocaleController.getString("OutgoingCalls", R.string.OutgoingCalls), String.format("%d", StatsController.getInstance(currentAccount).getSentItemsCount(currentType, type)), true);
                } else if (position == callsReceivedRow) {
                    textCell.setTextAndValue(LocaleController.getString("IncomingCalls", R.string.IncomingCalls), String.format("%d", StatsController.getInstance(currentAccount).getRecivedItemsCount(currentType, type)), true);
                } else if (position == callsTotalTimeRow) {
                    String time = AndroidUtilities.formatShortDuration(StatsController.getInstance(currentAccount).getCallsTotalTime(currentType));
                    textCell.setTextAndValue(LocaleController.getString("CallsTotalTime", R.string.CallsTotalTime), time, false);
                } else if (position == messagesSentRow || position == photosSentRow || position == videosSentRow || position == audiosSentRow || position == filesSentRow) {
                    textCell.setTextAndValue(LocaleController.getString("CountSent", R.string.CountSent), String.format("%d", StatsController.getInstance(currentAccount).getSentItemsCount(currentType, type)), true);
                } else if (position == messagesReceivedRow || position == photosReceivedRow || position == videosReceivedRow || position == audiosReceivedRow || position == filesReceivedRow) {
                    textCell.setTextAndValue(LocaleController.getString("CountReceived", R.string.CountReceived), String.format("%d", StatsController.getInstance(currentAccount).getRecivedItemsCount(currentType, type)), true);
                } else if (position == messagesBytesSentRow || position == photosBytesSentRow || position == videosBytesSentRow || position == audiosBytesSentRow || position == filesBytesSentRow || position == callsBytesSentRow || position == totalBytesSentRow) {
                    textCell.setTextAndValue(LocaleController.getString("BytesSent", R.string.BytesSent), AndroidUtilities.formatFileSize(StatsController.getInstance(currentAccount).getSentBytesCount(currentType, type)), true);
                } else if (position == messagesBytesReceivedRow || position == photosBytesReceivedRow || position == videosBytesReceivedRow || position == audiosBytesReceivedRow || position == filesBytesReceivedRow || position == callsBytesReceivedRow || position == totalBytesReceivedRow) {
                    textCell.setTextAndValue(LocaleController.getString("BytesReceived", R.string.BytesReceived), AndroidUtilities.formatFileSize(StatsController.getInstance(currentAccount).getReceivedBytesCount(currentType, type)), position == callsBytesReceivedRow);
                }
            }
            break;
        }
        case 2: {
            HeaderCell headerCell = (HeaderCell) holder.itemView;
            if (position == totalSectionRow) {
                headerCell.setText(LocaleController.getString("TotalDataUsage", R.string.TotalDataUsage));
            } else if (position == callsSectionRow) {
                headerCell.setText(LocaleController.getString("CallsDataUsage", R.string.CallsDataUsage));
            } else if (position == filesSectionRow) {
                headerCell.setText(LocaleController.getString("FilesDataUsage", R.string.FilesDataUsage));
            } else if (position == audiosSectionRow) {
                headerCell.setText(LocaleController.getString("LocalAudioCache", R.string.LocalAudioCache));
            } else if (position == videosSectionRow) {
                headerCell.setText(LocaleController.getString("LocalVideoCache", R.string.LocalVideoCache));
            } else if (position == photosSectionRow) {
                headerCell.setText(LocaleController.getString("LocalPhotoCache", R.string.LocalPhotoCache));
            } else if (position == messagesSectionRow) {
                headerCell.setText(LocaleController.getString("MessagesDataUsage", R.string.MessagesDataUsage));
            }
            break;
        }
        case 3: {
            TextInfoPrivacyCell cell = (TextInfoPrivacyCell) holder.itemView;
            cell.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
            cell.setText(LocaleController.formatString("NetworkUsageSince", R.string.NetworkUsageSince, LocaleController.getInstance().formatterStats.format(StatsController.getInstance(currentAccount).getResetStatsDate(currentType))));
            break;
        }
        default:
            break;
    }
}
 
Example 8
Source File: DataUsageActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    switch (holder.getItemViewType()) {
        case 0: {
            if (position == resetSection2Row) {
                holder.itemView.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
            } else {
                holder.itemView.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
            }
            break;
        }
        case 1: {
            TextSettingsCell textCell = (TextSettingsCell) holder.itemView;
            if (position == resetRow) {
                textCell.setTag(Theme.key_windowBackgroundWhiteRedText2);
                textCell.setText(LocaleController.getString("ResetStatistics", R.string.ResetStatistics), false);
                textCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText2));
            } else {
                int type;
                textCell.setTag(Theme.key_windowBackgroundWhiteBlackText);
                textCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                if (position == callsSentRow || position == callsReceivedRow || position == callsBytesSentRow || position == callsBytesReceivedRow) {
                    type = StatsController.TYPE_CALLS;
                } else if (position == messagesSentRow || position == messagesReceivedRow || position == messagesBytesSentRow || position == messagesBytesReceivedRow) {
                    type = StatsController.TYPE_MESSAGES;
                } else if (position == photosSentRow || position == photosReceivedRow || position == photosBytesSentRow || position == photosBytesReceivedRow) {
                    type = StatsController.TYPE_PHOTOS;
                } else if (position == audiosSentRow || position == audiosReceivedRow || position == audiosBytesSentRow || position == audiosBytesReceivedRow) {
                    type = StatsController.TYPE_AUDIOS;
                } else if (position == videosSentRow || position == videosReceivedRow || position == videosBytesSentRow || position == videosBytesReceivedRow) {
                    type = StatsController.TYPE_VIDEOS;
                } else if (position == filesSentRow || position == filesReceivedRow || position == filesBytesSentRow || position == filesBytesReceivedRow) {
                    type = StatsController.TYPE_FILES;
                } else {
                    type = StatsController.TYPE_TOTAL;
                }
                if (position == callsSentRow) {
                    textCell.setTextAndValue(LocaleController.getString("OutgoingCalls", R.string.OutgoingCalls), String.format("%d", StatsController.getInstance(currentAccount).getSentItemsCount(currentType, type)), true);
                } else if (position == callsReceivedRow) {
                    textCell.setTextAndValue(LocaleController.getString("IncomingCalls", R.string.IncomingCalls), String.format("%d", StatsController.getInstance(currentAccount).getRecivedItemsCount(currentType, type)), true);
                } else if (position == callsTotalTimeRow) {
                    String time = AndroidUtilities.formatShortDuration(StatsController.getInstance(currentAccount).getCallsTotalTime(currentType));
                    textCell.setTextAndValue(LocaleController.getString("CallsTotalTime", R.string.CallsTotalTime), time, false);
                } else if (position == messagesSentRow || position == photosSentRow || position == videosSentRow || position == audiosSentRow || position == filesSentRow) {
                    textCell.setTextAndValue(LocaleController.getString("CountSent", R.string.CountSent), String.format("%d", StatsController.getInstance(currentAccount).getSentItemsCount(currentType, type)), true);
                } else if (position == messagesReceivedRow || position == photosReceivedRow || position == videosReceivedRow || position == audiosReceivedRow || position == filesReceivedRow) {
                    textCell.setTextAndValue(LocaleController.getString("CountReceived", R.string.CountReceived), String.format("%d", StatsController.getInstance(currentAccount).getRecivedItemsCount(currentType, type)), true);
                } else if (position == messagesBytesSentRow || position == photosBytesSentRow || position == videosBytesSentRow || position == audiosBytesSentRow || position == filesBytesSentRow || position == callsBytesSentRow || position == totalBytesSentRow) {
                    textCell.setTextAndValue(LocaleController.getString("BytesSent", R.string.BytesSent), AndroidUtilities.formatFileSize(StatsController.getInstance(currentAccount).getSentBytesCount(currentType, type)), true);
                } else if (position == messagesBytesReceivedRow || position == photosBytesReceivedRow || position == videosBytesReceivedRow || position == audiosBytesReceivedRow || position == filesBytesReceivedRow || position == callsBytesReceivedRow || position == totalBytesReceivedRow) {
                    textCell.setTextAndValue(LocaleController.getString("BytesReceived", R.string.BytesReceived), AndroidUtilities.formatFileSize(StatsController.getInstance(currentAccount).getReceivedBytesCount(currentType, type)), position == callsBytesReceivedRow);
                }
            }
            break;
        }
        case 2: {
            HeaderCell headerCell = (HeaderCell) holder.itemView;
            if (position == totalSectionRow) {
                headerCell.setText(LocaleController.getString("TotalDataUsage", R.string.TotalDataUsage));
            } else if (position == callsSectionRow) {
                headerCell.setText(LocaleController.getString("CallsDataUsage", R.string.CallsDataUsage));
            } else if (position == filesSectionRow) {
                headerCell.setText(LocaleController.getString("FilesDataUsage", R.string.FilesDataUsage));
            } else if (position == audiosSectionRow) {
                headerCell.setText(LocaleController.getString("LocalAudioCache", R.string.LocalAudioCache));
            } else if (position == videosSectionRow) {
                headerCell.setText(LocaleController.getString("LocalVideoCache", R.string.LocalVideoCache));
            } else if (position == photosSectionRow) {
                headerCell.setText(LocaleController.getString("LocalPhotoCache", R.string.LocalPhotoCache));
            } else if (position == messagesSectionRow) {
                headerCell.setText(LocaleController.getString("MessagesDataUsage", R.string.MessagesDataUsage));
            }
            break;
        }
        case 3: {
            TextInfoPrivacyCell cell = (TextInfoPrivacyCell) holder.itemView;
            cell.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
            cell.setText(LocaleController.formatString("NetworkUsageSince", R.string.NetworkUsageSince, LocaleController.getInstance().formatterStats.format(StatsController.getInstance(currentAccount).getResetStatsDate(currentType))));
            break;
        }
        default:
            break;
    }
}