use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatAttachAlertDocumentLayout method onDestroy.
@Override
void onDestroy() {
try {
if (receiverRegistered) {
ApplicationLoader.applicationContext.unregisterReceiver(receiver);
}
} catch (Exception e) {
FileLog.e(e);
}
parentAlert.actionBar.closeSearchField();
ActionBarMenu menu = parentAlert.actionBar.createMenu();
menu.removeView(sortItem);
menu.removeView(searchItem);
}
use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatAttachAlertLocationLayout method onDestroy.
@Override
void onDestroy() {
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.locationPermissionGranted);
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.locationPermissionDenied);
// setMyLocationEnabled(false);
if (mapView != null) {
mapView.setTranslationY(-AndroidUtilities.displaySize.y * 3);
}
try {
if (mapView != null) {
mapView.onPause();
if (mapView.getOverlays().contains(myLocationOverlay)) {
mapView.getOverlays().remove(myLocationOverlay);
}
myLocationOverlay.disableMyLocation();
}
} catch (Exception ignore) {
}
if (adapter != null) {
adapter.destroy();
}
if (searchAdapter != null) {
searchAdapter.destroy();
}
parentAlert.actionBar.closeSearchField();
ActionBarMenu menu = parentAlert.actionBar.createMenu();
menu.removeView(searchItem);
}
use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChangeUsernameActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("Username", R.string.Username));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
saveName();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56), LocaleController.getString("Done", R.string.Done));
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(UserConfig.getInstance(currentAccount).getClientUserId());
if (user == null) {
user = UserConfig.getInstance(currentAccount).getCurrentUser();
}
fragmentView = new LinearLayout(context);
LinearLayout linearLayout = (LinearLayout) fragmentView;
linearLayout.setOrientation(LinearLayout.VERTICAL);
fragmentView.setOnTouchListener((v, event) -> true);
firstNameField = new EditTextBoldCursor(context);
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
firstNameField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
firstNameField.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
firstNameField.setMaxLines(1);
firstNameField.setLines(1);
firstNameField.setPadding(0, 0, 0, 0);
firstNameField.setSingleLine(true);
firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
firstNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
firstNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
firstNameField.setHint(LocaleController.getString("UsernamePlaceholder", R.string.UsernamePlaceholder));
firstNameField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
firstNameField.setCursorSize(AndroidUtilities.dp(20));
firstNameField.setCursorWidth(1.5f);
firstNameField.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
doneButton.performClick();
return true;
}
return false;
});
firstNameField.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
if (ignoreCheck) {
return;
}
checkUserName(firstNameField.getText().toString(), false);
}
@Override
public void afterTextChanged(Editable editable) {
String name = firstNameField.getText().toString();
if (name.startsWith("@")) {
name = name.substring(1);
}
if (name.length() > 0) {
String url = "https://" + MessagesController.getInstance(currentAccount).linkPrefix + "/" + name;
String text = LocaleController.formatString("UsernameHelpLink", R.string.UsernameHelpLink, url);
int index = text.indexOf(url);
SpannableStringBuilder textSpan = new SpannableStringBuilder(text);
if (index >= 0) {
textSpan.setSpan(new LinkSpan(url), index, index + url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
helpTextView.setText(TextUtils.concat(infoText, "\n\n", textSpan));
} else {
helpTextView.setText(infoText);
}
}
});
linearLayout.addView(firstNameField, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 24, 24, 24, 0));
checkTextView = new TextView(context);
checkTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
checkTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
linearLayout.addView(checkTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 24, 12, 24, 0));
helpTextView = new TextView(context);
helpTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
helpTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText8));
helpTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
helpTextView.setText(infoText = AndroidUtilities.replaceTags(LocaleController.getString("UsernameHelp", R.string.UsernameHelp)));
helpTextView.setLinkTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkText));
helpTextView.setHighlightColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkSelection));
helpTextView.setMovementMethod(new LinkMovementMethodMy());
linearLayout.addView(helpTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 24, 10, 24, 0));
checkTextView.setVisibility(View.GONE);
if (user != null && user.username != null && user.username.length() > 0) {
ignoreCheck = true;
firstNameField.setText(user.username);
firstNameField.setSelection(firstNameField.length());
ignoreCheck = false;
}
return fragmentView;
}
use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChangeNameActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("EditName", R.string.EditName));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
if (firstNameField.getText().length() != 0) {
saveName();
finishFragment();
}
}
}
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56), LocaleController.getString("Done", R.string.Done));
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(UserConfig.getInstance(currentAccount).getClientUserId());
if (user == null) {
user = UserConfig.getInstance(currentAccount).getCurrentUser();
}
LinearLayout linearLayout = new LinearLayout(context);
fragmentView = linearLayout;
fragmentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
((LinearLayout) fragmentView).setOrientation(LinearLayout.VERTICAL);
fragmentView.setOnTouchListener((v, event) -> true);
firstNameField = new EditTextBoldCursor(context);
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
firstNameField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
firstNameField.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
firstNameField.setMaxLines(1);
firstNameField.setLines(1);
firstNameField.setSingleLine(true);
firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
firstNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
firstNameField.setImeOptions(EditorInfo.IME_ACTION_NEXT);
firstNameField.setHint(LocaleController.getString("FirstName", R.string.FirstName));
firstNameField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
firstNameField.setCursorSize(AndroidUtilities.dp(20));
firstNameField.setCursorWidth(1.5f);
linearLayout.addView(firstNameField, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 24, 24, 24, 0));
firstNameField.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_NEXT) {
lastNameField.requestFocus();
lastNameField.setSelection(lastNameField.length());
return true;
}
return false;
});
lastNameField = new EditTextBoldCursor(context);
lastNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
lastNameField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
lastNameField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
lastNameField.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
lastNameField.setMaxLines(1);
lastNameField.setLines(1);
lastNameField.setSingleLine(true);
lastNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
lastNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
lastNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
lastNameField.setHint(LocaleController.getString("LastName", R.string.LastName));
lastNameField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
lastNameField.setCursorSize(AndroidUtilities.dp(20));
lastNameField.setCursorWidth(1.5f);
linearLayout.addView(lastNameField, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 24, 16, 24, 0));
lastNameField.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE) {
doneButton.performClick();
return true;
}
return false;
});
if (user != null) {
firstNameField.setText(user.first_name);
firstNameField.setSelection(firstNameField.length());
lastNameField.setText(user.last_name);
}
return fragmentView;
}
use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class CallLogActivity method createView.
@Override
public View createView(Context context) {
greenDrawable = getParentActivity().getResources().getDrawable(R.drawable.ic_call_made_green_18dp).mutate();
greenDrawable.setBounds(0, 0, greenDrawable.getIntrinsicWidth(), greenDrawable.getIntrinsicHeight());
greenDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_calls_callReceivedGreenIcon), PorterDuff.Mode.MULTIPLY));
iconOut = new ImageSpan(greenDrawable, ImageSpan.ALIGN_BOTTOM);
greenDrawable2 = getParentActivity().getResources().getDrawable(R.drawable.ic_call_received_green_18dp).mutate();
greenDrawable2.setBounds(0, 0, greenDrawable2.getIntrinsicWidth(), greenDrawable2.getIntrinsicHeight());
greenDrawable2.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_calls_callReceivedGreenIcon), PorterDuff.Mode.MULTIPLY));
iconIn = new ImageSpan(greenDrawable2, ImageSpan.ALIGN_BOTTOM);
redDrawable = getParentActivity().getResources().getDrawable(R.drawable.ic_call_received_green_18dp).mutate();
redDrawable.setBounds(0, 0, redDrawable.getIntrinsicWidth(), redDrawable.getIntrinsicHeight());
redDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_calls_callReceivedRedIcon), PorterDuff.Mode.MULTIPLY));
iconMissed = new ImageSpan(redDrawable, ImageSpan.ALIGN_BOTTOM);
actionBar.setBackButtonDrawable(new BackDrawable(false));
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("Calls", R.string.Calls));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (actionBar.isActionModeShowed()) {
hideActionMode(true);
} else {
finishFragment();
}
} else if (id == delete_all_calls) {
showDeleteAlert(true);
} else if (id == delete) {
showDeleteAlert(false);
}
}
});
ActionBarMenu menu = actionBar.createMenu();
otherItem = menu.addItem(10, R.drawable.ic_ab_other);
otherItem.setContentDescription(LocaleController.getString("AccDescrMoreOptions", R.string.AccDescrMoreOptions));
otherItem.addSubItem(delete_all_calls, R.drawable.msg_delete, LocaleController.getString("DeleteAllCalls", R.string.DeleteAllCalls));
fragmentView = new FrameLayout(context);
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
FrameLayout frameLayout = (FrameLayout) fragmentView;
flickerLoadingView = new FlickerLoadingView(context);
flickerLoadingView.setViewType(FlickerLoadingView.CALL_LOG_TYPE);
flickerLoadingView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
flickerLoadingView.showDate(false);
emptyView = new EmptyTextProgressView(context, flickerLoadingView);
frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView = new RecyclerListView(context);
listView.setEmptyView(emptyView);
listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
listView.setAdapter(listViewAdapter = new ListAdapter(context));
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT : RecyclerListView.SCROLLBAR_POSITION_RIGHT);
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView.setOnItemClickListener((view, position) -> {
if (view instanceof CallCell) {
CallLogRow row = calls.get(position - listViewAdapter.callsStartRow);
if (actionBar.isActionModeShowed()) {
addOrRemoveSelectedDialog(row.calls, (CallCell) view);
} else {
Bundle args = new Bundle();
args.putLong("user_id", row.user.id);
args.putInt("message_id", row.calls.get(0).id);
getNotificationCenter().postNotificationName(NotificationCenter.closeChats);
presentFragment(new ChatActivity(args), true);
}
} else if (view instanceof GroupCallCell) {
GroupCallCell cell = (GroupCallCell) view;
Bundle args = new Bundle();
args.putLong("chat_id", cell.currentChat.id);
getNotificationCenter().postNotificationName(NotificationCenter.closeChats);
presentFragment(new ChatActivity(args), true);
}
});
listView.setOnItemLongClickListener((view, position) -> {
if (view instanceof CallCell) {
addOrRemoveSelectedDialog(calls.get(position - listViewAdapter.callsStartRow).calls, (CallCell) view);
return true;
}
return false;
});
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
int visibleItemCount = firstVisibleItem == RecyclerView.NO_POSITION ? 0 : Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1;
if (visibleItemCount > 0) {
int totalItemCount = listViewAdapter.getItemCount();
if (!endReached && !loading && !calls.isEmpty() && firstVisibleItem + visibleItemCount >= totalItemCount - 5) {
final CallLogRow row = calls.get(calls.size() - 1);
AndroidUtilities.runOnUIThread(() -> getCalls(row.calls.get(row.calls.size() - 1).id, 100));
}
}
if (floatingButton.getVisibility() != View.GONE) {
final View topChild = recyclerView.getChildAt(0);
int firstViewTop = 0;
if (topChild != null) {
firstViewTop = topChild.getTop();
}
boolean goingDown;
boolean changed = true;
if (prevPosition == firstVisibleItem) {
final int topDelta = prevTop - firstViewTop;
goingDown = firstViewTop < prevTop;
changed = Math.abs(topDelta) > 1;
} else {
goingDown = firstVisibleItem > prevPosition;
}
if (changed && scrollUpdated) {
hideFloatingButton(goingDown);
}
prevPosition = firstVisibleItem;
prevTop = firstViewTop;
scrollUpdated = true;
}
}
});
if (loading) {
emptyView.showProgress();
} else {
emptyView.showTextView();
}
floatingButton = new ImageView(context);
floatingButton.setVisibility(View.VISIBLE);
floatingButton.setScaleType(ImageView.ScaleType.CENTER);
Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_chats_actionBackground), Theme.getColor(Theme.key_chats_actionPressedBackground));
if (Build.VERSION.SDK_INT < 21) {
Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow).mutate();
shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0);
combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
drawable = combinedDrawable;
}
floatingButton.setBackgroundDrawable(drawable);
floatingButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionIcon), PorterDuff.Mode.MULTIPLY));
floatingButton.setImageResource(R.drawable.ic_call);
floatingButton.setContentDescription(LocaleController.getString("Call", R.string.Call));
if (Build.VERSION.SDK_INT >= 21) {
StateListAnimator animator = new StateListAnimator();
animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator.ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
animator.addState(new int[] {}, ObjectAnimator.ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
floatingButton.setStateListAnimator(animator);
floatingButton.setOutlineProvider(new ViewOutlineProvider() {
@SuppressLint("NewApi")
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
}
});
}
frameLayout.addView(floatingButton, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14));
floatingButton.setOnClickListener(v -> {
Bundle args = new Bundle();
args.putBoolean("destroyAfterSelect", true);
args.putBoolean("returnAsResult", true);
args.putBoolean("onlyUsers", true);
args.putBoolean("allowSelf", false);
ContactsActivity contactsFragment = new ContactsActivity(args);
contactsFragment.setDelegate((user, param, activity) -> {
TLRPC.UserFull userFull = getMessagesController().getUserFull(user.id);
VoIPHelper.startCall(lastCallUser = user, false, userFull != null && userFull.video_calls_available, getParentActivity(), null, getAccountInstance());
});
presentFragment(contactsFragment);
});
return fragmentView;
}
Aggregations