use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class DialogsActivity method onItemLongClick.
private boolean onItemLongClick(View view, int position, float x, float y, int dialogsType, RecyclerListView.Adapter adapter) {
if (getParentActivity() == null) {
return false;
}
if (!actionBar.isActionModeShowed() && !AndroidUtilities.isTablet() && !onlySelect && view instanceof DialogCell) {
DialogCell cell = (DialogCell) view;
if (cell.isPointInsideAvatar(x, y)) {
return showChatPreview(cell);
}
}
if (adapter == searchViewPager.dialogsSearchAdapter) {
Object item = searchViewPager.dialogsSearchAdapter.getItem(position);
if (searchViewPager.dialogsSearchAdapter.isRecentSearchDisplayed()) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("ClearSearchSingleAlertTitle", R.string.ClearSearchSingleAlertTitle));
long did;
if (item instanceof TLRPC.Chat) {
TLRPC.Chat chat = (TLRPC.Chat) item;
builder.setMessage(LocaleController.formatString("ClearSearchSingleChatAlertText", R.string.ClearSearchSingleChatAlertText, chat.title));
did = -chat.id;
} else if (item instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) item;
if (user.id == getUserConfig().clientUserId) {
builder.setMessage(LocaleController.formatString("ClearSearchSingleChatAlertText", R.string.ClearSearchSingleChatAlertText, LocaleController.getString("SavedMessages", R.string.SavedMessages)));
} else {
builder.setMessage(LocaleController.formatString("ClearSearchSingleUserAlertText", R.string.ClearSearchSingleUserAlertText, ContactsController.formatName(user.first_name, user.last_name)));
}
did = user.id;
} else if (item instanceof TLRPC.EncryptedChat) {
TLRPC.EncryptedChat encryptedChat = (TLRPC.EncryptedChat) item;
TLRPC.User user = getMessagesController().getUser(encryptedChat.user_id);
builder.setMessage(LocaleController.formatString("ClearSearchSingleUserAlertText", R.string.ClearSearchSingleUserAlertText, ContactsController.formatName(user.first_name, user.last_name)));
did = DialogObject.makeEncryptedDialogId(encryptedChat.id);
} else {
return false;
}
builder.setPositiveButton(LocaleController.getString("ClearSearchRemove", R.string.ClearSearchRemove).toUpperCase(), (dialogInterface, i) -> searchViewPager.dialogsSearchAdapter.removeRecentSearch(did));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog alertDialog = builder.create();
showDialog(alertDialog);
TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
return true;
}
}
TLRPC.Dialog dialog;
if (adapter == searchViewPager.dialogsSearchAdapter) {
long dialogId = 0;
if (view instanceof ProfileSearchCell && !searchViewPager.dialogsSearchAdapter.isGlobalSearch(position)) {
dialogId = ((ProfileSearchCell) view).getDialogId();
}
if (dialogId != 0) {
showOrUpdateActionMode(dialogId, view);
return true;
}
return false;
} else {
DialogsAdapter dialogsAdapter = (DialogsAdapter) adapter;
ArrayList<TLRPC.Dialog> dialogs = getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen);
position = dialogsAdapter.fixPosition(position);
if (position < 0 || position >= dialogs.size()) {
return false;
}
dialog = dialogs.get(position);
}
if (dialog == null) {
return false;
}
if (onlySelect) {
if (initialDialogsType != 3 && initialDialogsType != 10) {
return false;
}
if (!validateSlowModeDialog(dialog.id)) {
return false;
}
if (!(initialDialogsType == 3 && selectAlertString != null)) {
addOrRemoveSelectedDialog(dialog.id, view);
updateSelectedCount();
}
} else {
if (dialog instanceof TLRPC.TL_dialogFolder) {
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity());
final boolean hasUnread = getMessagesStorage().getArchiveUnreadCount() != 0;
int[] icons = new int[] { hasUnread ? R.drawable.menu_read : 0, SharedConfig.archiveHidden ? R.drawable.chats_pin : R.drawable.chats_unpin };
CharSequence[] items = new CharSequence[] { hasUnread ? LocaleController.getString("MarkAllAsRead", R.string.MarkAllAsRead) : null, SharedConfig.archiveHidden ? LocaleController.getString("PinInTheList", R.string.PinInTheList) : LocaleController.getString("HideAboveTheList", R.string.HideAboveTheList) };
builder.setItems(items, icons, (d, which) -> {
if (which == 0) {
getMessagesStorage().readAllDialogs(1);
} else if (which == 1 && viewPages != null) {
for (int a = 0; a < viewPages.length; a++) {
if (viewPages[a].dialogsType != 0 || viewPages[a].getVisibility() != View.VISIBLE) {
continue;
}
View child = viewPages[a].listView.getChildAt(0);
DialogCell dialogCell = null;
if (child instanceof DialogCell && ((DialogCell) child).isFolderCell()) {
dialogCell = (DialogCell) child;
}
viewPages[a].listView.toggleArchiveHidden(true, dialogCell);
}
}
});
showDialog(builder.create());
return false;
}
if (actionBar.isActionModeShowed() && isDialogPinned(dialog)) {
return false;
}
showOrUpdateActionMode(dialog.id, view);
}
return true;
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class VoIPHelper method showRateAlert.
public static void showRateAlert(final Context context, final Runnable onDismiss, boolean isVideo, final long callID, final long accessHash, final int account, final boolean userInitiative) {
final File log = getLogFile(callID);
final int[] page = { 0 };
LinearLayout alertView = new LinearLayout(context);
alertView.setOrientation(LinearLayout.VERTICAL);
int pad = AndroidUtilities.dp(16);
alertView.setPadding(pad, pad, pad, 0);
TextView text = new TextView(context);
text.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
text.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
text.setGravity(Gravity.CENTER);
text.setText(LocaleController.getString("VoipRateCallAlert", R.string.VoipRateCallAlert));
alertView.addView(text);
final BetterRatingView bar = new BetterRatingView(context);
alertView.addView(bar, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL, 0, 16, 0, 0));
final LinearLayout problemsWrap = new LinearLayout(context);
problemsWrap.setOrientation(LinearLayout.VERTICAL);
View.OnClickListener problemCheckboxClickListener = v -> {
CheckBoxCell check = (CheckBoxCell) v;
check.setChecked(!check.isChecked(), true);
};
final String[] problems = { isVideo ? "distorted_video" : null, isVideo ? "pixelated_video" : null, "echo", "noise", "interruptions", "distorted_speech", "silent_local", "silent_remote", "dropped" };
for (int i = 0; i < problems.length; i++) {
if (problems[i] == null) {
continue;
}
CheckBoxCell check = new CheckBoxCell(context, 1);
check.setClipToPadding(false);
check.setTag(problems[i]);
String label = null;
switch(i) {
case 0:
label = LocaleController.getString("RateCallVideoDistorted", R.string.RateCallVideoDistorted);
break;
case 1:
label = LocaleController.getString("RateCallVideoPixelated", R.string.RateCallVideoPixelated);
break;
case 2:
label = LocaleController.getString("RateCallEcho", R.string.RateCallEcho);
break;
case 3:
label = LocaleController.getString("RateCallNoise", R.string.RateCallNoise);
break;
case 4:
label = LocaleController.getString("RateCallInterruptions", R.string.RateCallInterruptions);
break;
case 5:
label = LocaleController.getString("RateCallDistorted", R.string.RateCallDistorted);
break;
case 6:
label = LocaleController.getString("RateCallSilentLocal", R.string.RateCallSilentLocal);
break;
case 7:
label = LocaleController.getString("RateCallSilentRemote", R.string.RateCallSilentRemote);
break;
case 8:
label = LocaleController.getString("RateCallDropped", R.string.RateCallDropped);
break;
}
check.setText(label, null, false, false);
check.setOnClickListener(problemCheckboxClickListener);
check.setTag(problems[i]);
problemsWrap.addView(check);
}
alertView.addView(problemsWrap, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, -8, 0, -8, 0));
problemsWrap.setVisibility(View.GONE);
final EditTextBoldCursor commentBox = new EditTextBoldCursor(context);
commentBox.setHint(LocaleController.getString("VoipFeedbackCommentHint", R.string.VoipFeedbackCommentHint));
commentBox.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
commentBox.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
commentBox.setHintTextColor(Theme.getColor(Theme.key_dialogTextHint));
commentBox.setBackgroundDrawable(Theme.createEditTextDrawable(context, true));
commentBox.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4));
commentBox.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
commentBox.setVisibility(View.GONE);
alertView.addView(commentBox, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 8, 8, 8, 0));
final boolean[] includeLogs = { true };
final CheckBoxCell checkbox = new CheckBoxCell(context, 1);
View.OnClickListener checkClickListener = v -> {
includeLogs[0] = !includeLogs[0];
checkbox.setChecked(includeLogs[0], true);
};
checkbox.setText(LocaleController.getString("CallReportIncludeLogs", R.string.CallReportIncludeLogs), null, true, false);
checkbox.setClipToPadding(false);
checkbox.setOnClickListener(checkClickListener);
alertView.addView(checkbox, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, -8, 0, -8, 0));
final TextView logsText = new TextView(context);
logsText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
logsText.setTextColor(Theme.getColor(Theme.key_dialogTextGray3));
logsText.setText(LocaleController.getString("CallReportLogsExplain", R.string.CallReportLogsExplain));
logsText.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0);
logsText.setOnClickListener(checkClickListener);
alertView.addView(logsText);
checkbox.setVisibility(View.GONE);
logsText.setVisibility(View.GONE);
if (!log.exists()) {
includeLogs[0] = false;
}
final AlertDialog alert = new AlertDialog.Builder(context).setTitle(LocaleController.getString("CallMessageReportProblem", R.string.CallMessageReportProblem)).setView(alertView).setPositiveButton(LocaleController.getString("Send", R.string.Send), (dialog, which) -> {
// SendMessagesHelper.getInstance(currentAccount).sendMessage(commentBox.getText().toString(), VOIP_SUPPORT_ID, null, null, true, null, null, null);
}).setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null).setOnDismissListener(dialog -> {
if (onDismiss != null)
onDismiss.run();
}).create();
if (BuildVars.LOGS_ENABLED && log.exists()) {
alert.setNeutralButton("Send log", (dialog, which) -> {
Intent intent = new Intent(context, LaunchActivity.class);
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(log));
context.startActivity(intent);
});
}
alert.show();
alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
final View btn = alert.getButton(DialogInterface.BUTTON_POSITIVE);
btn.setEnabled(false);
bar.setOnRatingChangeListener(rating -> {
btn.setEnabled(rating > 0);
/*commentBox.setHint(rating<4 ? LocaleController.getString("CallReportHint", R.string.CallReportHint) : LocaleController.getString("VoipFeedbackCommentHint", R.string.VoipFeedbackCommentHint));
commentBox.setVisibility(rating < 5 && rating > 0 ? View.VISIBLE : View.GONE);
if (commentBox.getVisibility() == View.GONE) {
((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(commentBox.getWindowToken(), 0);
}
*/
((TextView) btn).setText((rating < 4 ? LocaleController.getString("Next", R.string.Next) : LocaleController.getString("Send", R.string.Send)).toUpperCase());
});
btn.setOnClickListener(v -> {
int rating = bar.getRating();
if (rating >= 4 || page[0] == 1) {
final int currentAccount = UserConfig.selectedAccount;
final TLRPC.TL_phone_setCallRating req = new TLRPC.TL_phone_setCallRating();
req.rating = bar.getRating();
ArrayList<String> problemTags = new ArrayList<>();
for (int i = 0; i < problemsWrap.getChildCount(); i++) {
CheckBoxCell check = (CheckBoxCell) problemsWrap.getChildAt(i);
if (check.isChecked())
problemTags.add("#" + check.getTag());
}
if (req.rating < 5) {
req.comment = commentBox.getText().toString();
} else {
req.comment = "";
}
if (!problemTags.isEmpty() && !includeLogs[0]) {
req.comment += " " + TextUtils.join(" ", problemTags);
}
req.peer = new TLRPC.TL_inputPhoneCall();
req.peer.access_hash = accessHash;
req.peer.id = callID;
req.user_initiative = userInitiative;
ConnectionsManager.getInstance(account).sendRequest(req, (response, error) -> {
if (response instanceof TLRPC.TL_updates) {
TLRPC.TL_updates updates = (TLRPC.TL_updates) response;
MessagesController.getInstance(currentAccount).processUpdates(updates, false);
}
if (includeLogs[0] && log.exists() && req.rating < 4) {
AccountInstance accountInstance = AccountInstance.getInstance(UserConfig.selectedAccount);
SendMessagesHelper.prepareSendingDocument(accountInstance, log.getAbsolutePath(), log.getAbsolutePath(), null, TextUtils.join(" ", problemTags), "text/plain", VOIP_SUPPORT_ID, null, null, null, null, true, 0);
Toast.makeText(context, LocaleController.getString("CallReportSent", R.string.CallReportSent), Toast.LENGTH_LONG).show();
}
});
alert.dismiss();
} else {
page[0] = 1;
bar.setVisibility(View.GONE);
// text.setText(LocaleController.getString("CallReportHint", R.string.CallReportHint));
text.setVisibility(View.GONE);
alert.setTitle(LocaleController.getString("CallReportHint", R.string.CallReportHint));
commentBox.setVisibility(View.VISIBLE);
if (log.exists()) {
checkbox.setVisibility(View.VISIBLE);
logsText.setVisibility(View.VISIBLE);
}
problemsWrap.setVisibility(View.VISIBLE);
((TextView) btn).setText(LocaleController.getString("Send", R.string.Send).toUpperCase());
}
});
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class VoIPHelper method permissionDenied.
@TargetApi(Build.VERSION_CODES.M)
public static void permissionDenied(final Activity activity, final Runnable onFinish, int code) {
if (!activity.shouldShowRequestPermissionRationale(Manifest.permission.RECORD_AUDIO) || code == 102 && !activity.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
AlertDialog dlg = new AlertDialog.Builder(activity).setTitle(LocaleController.getString("AppName", R.string.AppName)).setMessage(code == 102 ? LocaleController.getString("VoipNeedMicCameraPermission", R.string.VoipNeedMicCameraPermission) : LocaleController.getString("VoipNeedMicPermission", R.string.VoipNeedMicPermission)).setPositiveButton(LocaleController.getString("OK", R.string.OK), null).setNegativeButton(LocaleController.getString("Settings", R.string.Settings), (dialog, which) -> {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
intent.setData(uri);
activity.startActivity(intent);
}).show();
dlg.setOnDismissListener(dialog -> {
if (onFinish != null)
onFinish.run();
});
}
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class DataUsageActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setTitle(LocaleController.getString("NetworkUsage", R.string.NetworkUsage));
if (AndroidUtilities.isTablet()) {
actionBar.setOccupyStatusBar(false);
}
actionBar.setExtraHeight(AndroidUtilities.dp(44));
actionBar.setAllowOverlayTitle(false);
actionBar.setAddToContainer(false);
actionBar.setClipContent(true);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
hasOwnBackground = true;
mobileAdapter = new ListAdapter(context, 0);
wifiAdapter = new ListAdapter(context, 1);
roamingAdapter = new ListAdapter(context, 2);
scrollSlidingTextTabStrip = new ScrollSlidingTextTabStrip(context);
scrollSlidingTextTabStrip.setUseSameWidth(true);
actionBar.addView(scrollSlidingTextTabStrip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 44, Gravity.LEFT | Gravity.BOTTOM));
scrollSlidingTextTabStrip.setDelegate(new ScrollSlidingTextTabStrip.ScrollSlidingTabStripDelegate() {
@Override
public void onPageSelected(int id, boolean forward) {
if (viewPages[0].selectedType == id) {
return;
}
swipeBackEnabled = id == scrollSlidingTextTabStrip.getFirstTabId();
viewPages[1].selectedType = id;
viewPages[1].setVisibility(View.VISIBLE);
switchToCurrentSelectedMode(true);
animatingForward = forward;
}
@Override
public void onPageScrolled(float progress) {
if (progress == 1 && viewPages[1].getVisibility() != View.VISIBLE) {
return;
}
if (animatingForward) {
viewPages[0].setTranslationX(-progress * viewPages[0].getMeasuredWidth());
viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() - progress * viewPages[0].getMeasuredWidth());
} else {
viewPages[0].setTranslationX(progress * viewPages[0].getMeasuredWidth());
viewPages[1].setTranslationX(progress * viewPages[0].getMeasuredWidth() - viewPages[0].getMeasuredWidth());
}
if (progress == 1) {
ViewPage tempPage = viewPages[0];
viewPages[0] = viewPages[1];
viewPages[1] = tempPage;
viewPages[1].setVisibility(View.GONE);
}
}
});
ViewConfiguration configuration = ViewConfiguration.get(context);
maximumVelocity = configuration.getScaledMaximumFlingVelocity();
FrameLayout frameLayout;
fragmentView = frameLayout = new FrameLayout(context) {
private int startedTrackingPointerId;
private boolean startedTracking;
private boolean maybeStartTracking;
private int startedTrackingX;
private int startedTrackingY;
private VelocityTracker velocityTracker;
private boolean globalIgnoreLayout;
private boolean prepareForMoving(MotionEvent ev, boolean forward) {
int id = scrollSlidingTextTabStrip.getNextPageId(forward);
if (id < 0) {
return false;
}
getParent().requestDisallowInterceptTouchEvent(true);
maybeStartTracking = false;
startedTracking = true;
startedTrackingX = (int) ev.getX();
actionBar.setEnabled(false);
scrollSlidingTextTabStrip.setEnabled(false);
viewPages[1].selectedType = id;
viewPages[1].setVisibility(View.VISIBLE);
animatingForward = forward;
switchToCurrentSelectedMode(true);
if (forward) {
viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth());
} else {
viewPages[1].setTranslationX(-viewPages[0].getMeasuredWidth());
}
return true;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(widthSize, heightSize);
measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0);
int actionBarHeight = actionBar.getMeasuredHeight();
globalIgnoreLayout = true;
for (int a = 0; a < viewPages.length; a++) {
if (viewPages[a] == null) {
continue;
}
if (viewPages[a].listView != null) {
viewPages[a].listView.setPadding(0, actionBarHeight, 0, AndroidUtilities.dp(4));
}
}
globalIgnoreLayout = false;
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (child == null || child.getVisibility() == GONE || child == actionBar) {
continue;
}
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
}
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
if (parentLayout != null) {
parentLayout.drawHeaderShadow(canvas, actionBar.getMeasuredHeight() + (int) actionBar.getTranslationY());
}
}
@Override
public void requestLayout() {
if (globalIgnoreLayout) {
return;
}
super.requestLayout();
}
public boolean checkTabsAnimationInProgress() {
if (tabsAnimationInProgress) {
boolean cancel = false;
if (backAnimation) {
if (Math.abs(viewPages[0].getTranslationX()) < 1) {
viewPages[0].setTranslationX(0);
viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() * (animatingForward ? 1 : -1));
cancel = true;
}
} else if (Math.abs(viewPages[1].getTranslationX()) < 1) {
viewPages[0].setTranslationX(viewPages[0].getMeasuredWidth() * (animatingForward ? -1 : 1));
viewPages[1].setTranslationX(0);
cancel = true;
}
if (cancel) {
if (tabsAnimation != null) {
tabsAnimation.cancel();
tabsAnimation = null;
}
tabsAnimationInProgress = false;
}
return tabsAnimationInProgress;
}
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return checkTabsAnimationInProgress() || scrollSlidingTextTabStrip.isAnimatingIndicator() || onTouchEvent(ev);
}
@Override
protected void onDraw(Canvas canvas) {
backgroundPaint.setColor(Theme.getColor(Theme.key_windowBackgroundGray));
canvas.drawRect(0, actionBar.getMeasuredHeight() + actionBar.getTranslationY(), getMeasuredWidth(), getMeasuredHeight(), backgroundPaint);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (!parentLayout.checkTransitionAnimation() && !checkTabsAnimationInProgress()) {
if (ev != null) {
if (velocityTracker == null) {
velocityTracker = VelocityTracker.obtain();
}
velocityTracker.addMovement(ev);
}
if (ev != null && ev.getAction() == MotionEvent.ACTION_DOWN && !startedTracking && !maybeStartTracking) {
startedTrackingPointerId = ev.getPointerId(0);
maybeStartTracking = true;
startedTrackingX = (int) ev.getX();
startedTrackingY = (int) ev.getY();
velocityTracker.clear();
} else if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE && ev.getPointerId(0) == startedTrackingPointerId) {
int dx = (int) (ev.getX() - startedTrackingX);
int dy = Math.abs((int) ev.getY() - startedTrackingY);
if (startedTracking && (animatingForward && dx > 0 || !animatingForward && dx < 0)) {
if (!prepareForMoving(ev, dx < 0)) {
maybeStartTracking = true;
startedTracking = false;
viewPages[0].setTranslationX(0);
viewPages[1].setTranslationX(animatingForward ? viewPages[0].getMeasuredWidth() : -viewPages[0].getMeasuredWidth());
scrollSlidingTextTabStrip.selectTabWithId(viewPages[1].selectedType, 0);
}
}
if (maybeStartTracking && !startedTracking) {
float touchSlop = AndroidUtilities.getPixelsInCM(0.3f, true);
if (Math.abs(dx) >= touchSlop && Math.abs(dx) > dy) {
prepareForMoving(ev, dx < 0);
}
} else if (startedTracking) {
if (animatingForward) {
viewPages[0].setTranslationX(dx);
viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() + dx);
} else {
viewPages[0].setTranslationX(dx);
viewPages[1].setTranslationX(dx - viewPages[0].getMeasuredWidth());
}
float scrollProgress = Math.abs(dx) / (float) viewPages[0].getMeasuredWidth();
scrollSlidingTextTabStrip.selectTabWithId(viewPages[1].selectedType, scrollProgress);
}
} else if (ev == null || ev.getPointerId(0) == startedTrackingPointerId && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
velocityTracker.computeCurrentVelocity(1000, maximumVelocity);
float velX;
float velY;
if (ev != null && ev.getAction() != MotionEvent.ACTION_CANCEL) {
velX = velocityTracker.getXVelocity();
velY = velocityTracker.getYVelocity();
if (!startedTracking) {
if (Math.abs(velX) >= 3000 && Math.abs(velX) > Math.abs(velY)) {
prepareForMoving(ev, velX < 0);
}
}
} else {
velX = 0;
velY = 0;
}
if (startedTracking) {
float x = viewPages[0].getX();
tabsAnimation = new AnimatorSet();
backAnimation = Math.abs(x) < viewPages[0].getMeasuredWidth() / 3.0f && (Math.abs(velX) < 3500 || Math.abs(velX) < Math.abs(velY));
float distToMove;
float dx;
if (backAnimation) {
dx = Math.abs(x);
if (animatingForward) {
tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, 0), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, viewPages[1].getMeasuredWidth()));
} else {
tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, 0), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, -viewPages[1].getMeasuredWidth()));
}
} else {
dx = viewPages[0].getMeasuredWidth() - Math.abs(x);
if (animatingForward) {
tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, -viewPages[0].getMeasuredWidth()), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, 0));
} else {
tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, viewPages[0].getMeasuredWidth()), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, 0));
}
}
tabsAnimation.setInterpolator(interpolator);
int width = getMeasuredWidth();
int halfWidth = width / 2;
float distanceRatio = Math.min(1.0f, 1.0f * dx / (float) width);
float distance = (float) halfWidth + (float) halfWidth * AndroidUtilities.distanceInfluenceForSnapDuration(distanceRatio);
velX = Math.abs(velX);
int duration;
if (velX > 0) {
duration = 4 * Math.round(1000.0f * Math.abs(distance / velX));
} else {
float pageDelta = dx / getMeasuredWidth();
duration = (int) ((pageDelta + 1.0f) * 100.0f);
}
duration = Math.max(150, Math.min(duration, 600));
tabsAnimation.setDuration(duration);
tabsAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animator) {
tabsAnimation = null;
if (backAnimation) {
viewPages[1].setVisibility(View.GONE);
} else {
ViewPage tempPage = viewPages[0];
viewPages[0] = viewPages[1];
viewPages[1] = tempPage;
viewPages[1].setVisibility(View.GONE);
swipeBackEnabled = viewPages[0].selectedType == scrollSlidingTextTabStrip.getFirstTabId();
scrollSlidingTextTabStrip.selectTabWithId(viewPages[0].selectedType, 1.0f);
}
tabsAnimationInProgress = false;
maybeStartTracking = false;
startedTracking = false;
actionBar.setEnabled(true);
scrollSlidingTextTabStrip.setEnabled(true);
}
});
tabsAnimation.start();
tabsAnimationInProgress = true;
startedTracking = false;
} else {
maybeStartTracking = false;
actionBar.setEnabled(true);
scrollSlidingTextTabStrip.setEnabled(true);
}
if (velocityTracker != null) {
velocityTracker.recycle();
velocityTracker = null;
}
}
return startedTracking;
}
return false;
}
};
frameLayout.setWillNotDraw(false);
int scrollToPositionOnRecreate = -1;
int scrollToOffsetOnRecreate = 0;
for (int a = 0; a < viewPages.length; a++) {
if (a == 0) {
if (viewPages[a] != null && viewPages[a].layoutManager != null) {
scrollToPositionOnRecreate = viewPages[a].layoutManager.findFirstVisibleItemPosition();
if (scrollToPositionOnRecreate != viewPages[a].layoutManager.getItemCount() - 1) {
RecyclerListView.Holder holder = (RecyclerListView.Holder) viewPages[a].listView.findViewHolderForAdapterPosition(scrollToPositionOnRecreate);
if (holder != null) {
scrollToOffsetOnRecreate = holder.itemView.getTop();
} else {
scrollToPositionOnRecreate = -1;
}
} else {
scrollToPositionOnRecreate = -1;
}
}
}
final ViewPage ViewPage = new ViewPage(context) {
@Override
public void setTranslationX(float translationX) {
super.setTranslationX(translationX);
if (tabsAnimationInProgress) {
if (viewPages[0] == this) {
float scrollProgress = Math.abs(viewPages[0].getTranslationX()) / (float) viewPages[0].getMeasuredWidth();
scrollSlidingTextTabStrip.selectTabWithId(viewPages[1].selectedType, scrollProgress);
}
}
}
};
frameLayout.addView(ViewPage, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
viewPages[a] = ViewPage;
final LinearLayoutManager layoutManager = viewPages[a].layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) {
@Override
public boolean supportsPredictiveItemAnimations() {
return false;
}
};
RecyclerListView listView = new RecyclerListView(context);
viewPages[a].listView = listView;
viewPages[a].listView.setScrollingTouchSlop(RecyclerView.TOUCH_SLOP_PAGING);
viewPages[a].listView.setItemAnimator(null);
viewPages[a].listView.setClipToPadding(false);
viewPages[a].listView.setSectionsType(2);
viewPages[a].listView.setLayoutManager(layoutManager);
viewPages[a].addView(viewPages[a].listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
viewPages[a].listView.setOnItemClickListener((view, position) -> {
if (getParentActivity() == null) {
return;
}
ListAdapter adapter = (ListAdapter) listView.getAdapter();
if (position == adapter.resetRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("ResetStatisticsAlertTitle", R.string.ResetStatisticsAlertTitle));
builder.setMessage(LocaleController.getString("ResetStatisticsAlert", R.string.ResetStatisticsAlert));
builder.setPositiveButton(LocaleController.getString("Reset", R.string.Reset), (dialogInterface, i) -> {
StatsController.getInstance(currentAccount).resetStats(adapter.currentType);
adapter.notifyDataSetChanged();
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog dialog = builder.create();
showDialog(dialog);
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
}
});
viewPages[a].listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState != RecyclerView.SCROLL_STATE_DRAGGING) {
int scrollY = (int) -actionBar.getTranslationY();
int actionBarHeight = ActionBar.getCurrentActionBarHeight();
if (scrollY != 0 && scrollY != actionBarHeight) {
if (scrollY < actionBarHeight / 2) {
viewPages[0].listView.smoothScrollBy(0, -scrollY);
} else {
viewPages[0].listView.smoothScrollBy(0, actionBarHeight - scrollY);
}
}
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (recyclerView == viewPages[0].listView) {
float currentTranslation = actionBar.getTranslationY();
float newTranslation = currentTranslation - dy;
if (newTranslation < -ActionBar.getCurrentActionBarHeight()) {
newTranslation = -ActionBar.getCurrentActionBarHeight();
} else if (newTranslation > 0) {
newTranslation = 0;
}
if (newTranslation != currentTranslation) {
setScrollY(newTranslation);
}
}
}
});
if (a == 0 && scrollToPositionOnRecreate != -1) {
layoutManager.scrollToPositionWithOffset(scrollToPositionOnRecreate, scrollToOffsetOnRecreate);
}
if (a != 0) {
viewPages[a].setVisibility(View.GONE);
}
}
frameLayout.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
updateTabs();
switchToCurrentSelectedMode(false);
swipeBackEnabled = scrollSlidingTextTabStrip.getCurrentTabId() == scrollSlidingTextTabStrip.getFirstTabId();
return fragmentView;
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class DataSettingsActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setTitle(LocaleController.getString("DataSettings", R.string.DataSettings));
if (AndroidUtilities.isTablet()) {
actionBar.setOccupyStatusBar(false);
}
actionBar.setAllowOverlayTitle(true);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
listAdapter = new ListAdapter(context);
fragmentView = new FrameLayout(context);
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
FrameLayout frameLayout = (FrameLayout) fragmentView;
listView = new RecyclerListView(context);
listView.setVerticalScrollBarEnabled(false);
listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
listView.setAdapter(listAdapter);
listView.setOnItemClickListener((view, position, x, y) -> {
if (position == mobileRow || position == roamingRow || position == wifiRow) {
if (LocaleController.isRTL && x <= AndroidUtilities.dp(76) || !LocaleController.isRTL && x >= view.getMeasuredWidth() - AndroidUtilities.dp(76)) {
boolean wasEnabled = listAdapter.isRowEnabled(resetDownloadRow);
NotificationsCheckCell cell = (NotificationsCheckCell) view;
boolean checked = cell.isChecked();
DownloadController.Preset preset;
DownloadController.Preset defaultPreset;
String key;
String key2;
int num;
if (position == mobileRow) {
preset = DownloadController.getInstance(currentAccount).mobilePreset;
defaultPreset = DownloadController.getInstance(currentAccount).mediumPreset;
key = "mobilePreset";
key2 = "currentMobilePreset";
num = 0;
} else if (position == wifiRow) {
preset = DownloadController.getInstance(currentAccount).wifiPreset;
defaultPreset = DownloadController.getInstance(currentAccount).highPreset;
key = "wifiPreset";
key2 = "currentWifiPreset";
num = 1;
} else {
preset = DownloadController.getInstance(currentAccount).roamingPreset;
defaultPreset = DownloadController.getInstance(currentAccount).lowPreset;
key = "roamingPreset";
key2 = "currentRoamingPreset";
num = 2;
}
if (!checked && preset.enabled) {
preset.set(defaultPreset);
} else {
preset.enabled = !preset.enabled;
}
SharedPreferences.Editor editor = MessagesController.getMainSettings(currentAccount).edit();
editor.putString(key, preset.toString());
editor.putInt(key2, 3);
editor.commit();
cell.setChecked(!checked);
RecyclerView.ViewHolder holder = listView.findContainingViewHolder(view);
if (holder != null) {
listAdapter.onBindViewHolder(holder, position);
}
DownloadController.getInstance(currentAccount).checkAutodownloadSettings();
DownloadController.getInstance(currentAccount).savePresetToServer(num);
if (wasEnabled != listAdapter.isRowEnabled(resetDownloadRow)) {
listAdapter.notifyItemChanged(resetDownloadRow);
}
} else {
int type;
if (position == mobileRow) {
type = 0;
} else if (position == wifiRow) {
type = 1;
} else {
type = 2;
}
presentFragment(new DataAutoDownloadActivity(type));
}
} else if (position == resetDownloadRow) {
if (getParentActivity() == null || !view.isEnabled()) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("ResetAutomaticMediaDownloadAlertTitle", R.string.ResetAutomaticMediaDownloadAlertTitle));
builder.setMessage(LocaleController.getString("ResetAutomaticMediaDownloadAlert", R.string.ResetAutomaticMediaDownloadAlert));
builder.setPositiveButton(LocaleController.getString("Reset", R.string.Reset), (dialogInterface, i) -> {
DownloadController.Preset preset;
DownloadController.Preset defaultPreset;
String key;
SharedPreferences.Editor editor = MessagesController.getMainSettings(currentAccount).edit();
for (int a = 0; a < 3; a++) {
if (a == 0) {
preset = DownloadController.getInstance(currentAccount).mobilePreset;
defaultPreset = DownloadController.getInstance(currentAccount).mediumPreset;
key = "mobilePreset";
} else if (a == 1) {
preset = DownloadController.getInstance(currentAccount).wifiPreset;
defaultPreset = DownloadController.getInstance(currentAccount).highPreset;
key = "wifiPreset";
} else {
preset = DownloadController.getInstance(currentAccount).roamingPreset;
defaultPreset = DownloadController.getInstance(currentAccount).lowPreset;
key = "roamingPreset";
}
preset.set(defaultPreset);
preset.enabled = defaultPreset.isEnabled();
editor.putInt("currentMobilePreset", DownloadController.getInstance(currentAccount).currentMobilePreset = 3);
editor.putInt("currentWifiPreset", DownloadController.getInstance(currentAccount).currentWifiPreset = 3);
editor.putInt("currentRoamingPreset", DownloadController.getInstance(currentAccount).currentRoamingPreset = 3);
editor.putString(key, preset.toString());
}
editor.commit();
DownloadController.getInstance(currentAccount).checkAutodownloadSettings();
for (int a = 0; a < 3; a++) {
DownloadController.getInstance(currentAccount).savePresetToServer(a);
}
listAdapter.notifyItemRangeChanged(mobileRow, 4);
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog dialog = builder.create();
showDialog(dialog);
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
} else if (position == storageUsageRow) {
presentFragment(new CacheControlActivity());
} else if (position == useLessDataForCallsRow) {
final SharedPreferences preferences = MessagesController.getGlobalMainSettings();
int selected = 0;
switch(preferences.getInt("VoipDataSaving", VoIPHelper.getDataSavingDefault())) {
case Instance.DATA_SAVING_NEVER:
selected = 0;
break;
case Instance.DATA_SAVING_ROAMING:
selected = 1;
break;
case Instance.DATA_SAVING_MOBILE:
selected = 2;
break;
case Instance.DATA_SAVING_ALWAYS:
selected = 3;
break;
}
Dialog dlg = AlertsCreator.createSingleChoiceDialog(getParentActivity(), new String[] { LocaleController.getString("UseLessDataNever", R.string.UseLessDataNever), LocaleController.getString("UseLessDataOnRoaming", R.string.UseLessDataOnRoaming), LocaleController.getString("UseLessDataOnMobile", R.string.UseLessDataOnMobile), LocaleController.getString("UseLessDataAlways", R.string.UseLessDataAlways) }, LocaleController.getString("VoipUseLessData", R.string.VoipUseLessData), selected, (dialog, which) -> {
int val = -1;
switch(which) {
case 0:
val = Instance.DATA_SAVING_NEVER;
break;
case 1:
val = Instance.DATA_SAVING_ROAMING;
break;
case 2:
val = Instance.DATA_SAVING_MOBILE;
break;
case 3:
val = Instance.DATA_SAVING_ALWAYS;
break;
}
if (val != -1) {
preferences.edit().putInt("VoipDataSaving", val).commit();
}
if (listAdapter != null) {
listAdapter.notifyItemChanged(position);
}
});
setVisibleDialog(dlg);
dlg.show();
} else if (position == dataUsageRow) {
presentFragment(new DataUsageActivity());
} else if (position == storageNumRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("StoragePath", R.string.StoragePath));
final LinearLayout linearLayout = new LinearLayout(getParentActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
builder.setView(linearLayout);
String dir = storageDirs.get(0).getAbsolutePath();
if (!TextUtils.isEmpty(SharedConfig.storageCacheDir)) {
for (int a = 0, N = storageDirs.size(); a < N; a++) {
String path = storageDirs.get(a).getAbsolutePath();
if (path.startsWith(SharedConfig.storageCacheDir)) {
dir = path;
break;
}
}
}
for (int a = 0, N = storageDirs.size(); a < N; a++) {
String storageDir = storageDirs.get(a).getAbsolutePath();
RadioColorCell cell = new RadioColorCell(context);
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
cell.setTag(a);
cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
cell.setTextAndValue(storageDir, storageDir.startsWith(dir));
linearLayout.addView(cell);
cell.setOnClickListener(v -> {
SharedConfig.storageCacheDir = storageDir;
SharedConfig.saveConfig();
ImageLoader.getInstance().checkMediaPaths();
builder.getDismissRunnable().run();
listAdapter.notifyItemChanged(storageNumRow);
});
}
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
} else if (position == proxyRow) {
presentFragment(new ProxyListActivity());
} else if (position == enableStreamRow) {
SharedConfig.toggleStreamMedia();
TextCheckCell textCheckCell = (TextCheckCell) view;
textCheckCell.setChecked(SharedConfig.streamMedia);
} else if (position == enableAllStreamRow) {
SharedConfig.toggleStreamAllVideo();
TextCheckCell textCheckCell = (TextCheckCell) view;
textCheckCell.setChecked(SharedConfig.streamAllVideo);
} else if (position == enableMkvRow) {
SharedConfig.toggleStreamMkv();
TextCheckCell textCheckCell = (TextCheckCell) view;
textCheckCell.setChecked(SharedConfig.streamMkv);
} else if (position == enableCacheStreamRow) {
SharedConfig.toggleSaveStreamMedia();
TextCheckCell textCheckCell = (TextCheckCell) view;
textCheckCell.setChecked(SharedConfig.saveStreamMedia);
} else if (position == quickRepliesRow) {
presentFragment(new QuickRepliesSettingsActivity());
} else if (position == autoplayGifsRow) {
SharedConfig.toggleAutoplayGifs();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(SharedConfig.autoplayGifs);
}
} else if (position == autoplayVideoRow) {
SharedConfig.toggleAutoplayVideo();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(SharedConfig.autoplayVideo);
}
} else if (position == clearDraftsRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AreYouSureClearDraftsTitle", R.string.AreYouSureClearDraftsTitle));
builder.setMessage(LocaleController.getString("AreYouSureClearDrafts", R.string.AreYouSureClearDrafts));
builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
TLRPC.TL_messages_clearAllDrafts req = new TLRPC.TL_messages_clearAllDrafts();
getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> getMediaDataController().clearAllDrafts(true)));
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog alertDialog = builder.create();
showDialog(alertDialog);
TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
}
});
return fragmentView;
}
Aggregations