use of org.telegram.ui.Components.SizeNotifierFrameLayout in project Telegram-FOSS by Telegram-FOSS-Team.
the class ExternalActionActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
ApplicationLoader.postInitApplication();
requestWindowFeature(Window.FEATURE_NO_TITLE);
setTheme(R.style.Theme_TMessages);
getWindow().setBackgroundDrawableResource(R.drawable.transparent);
if (SharedConfig.passcodeHash.length() > 0 && !SharedConfig.allowScreenCapture) {
try {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
} catch (Exception e) {
FileLog.e(e);
}
}
super.onCreate(savedInstanceState);
if (SharedConfig.passcodeHash.length() != 0 && SharedConfig.appLocked) {
SharedConfig.lastPauseTime = (int) (SystemClock.elapsedRealtime() / 1000);
}
AndroidUtilities.fillStatusBarHeight(this);
Theme.createDialogsResources(this);
Theme.createChatResources(this, false);
actionBarLayout = new ActionBarLayout(this);
drawerLayoutContainer = new DrawerLayoutContainer(this);
drawerLayoutContainer.setAllowOpenDrawer(false, false);
setContentView(drawerLayoutContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
if (AndroidUtilities.isTablet()) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
RelativeLayout launchLayout = new RelativeLayout(this);
drawerLayoutContainer.addView(launchLayout);
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) launchLayout.getLayoutParams();
layoutParams1.width = LayoutHelper.MATCH_PARENT;
layoutParams1.height = LayoutHelper.MATCH_PARENT;
launchLayout.setLayoutParams(layoutParams1);
backgroundTablet = new SizeNotifierFrameLayout(this) {
@Override
protected boolean isActionBarVisible() {
return false;
}
};
backgroundTablet.setOccupyStatusBar(false);
backgroundTablet.setBackgroundImage(Theme.getCachedWallpaper(), Theme.isWallpaperMotion());
launchLayout.addView(backgroundTablet, LayoutHelper.createRelative(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
launchLayout.addView(actionBarLayout, LayoutHelper.createRelative(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
FrameLayout shadowTablet = new FrameLayout(this);
shadowTablet.setBackgroundColor(0x7F000000);
launchLayout.addView(shadowTablet, LayoutHelper.createRelative(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
shadowTablet.setOnTouchListener((v, event) -> {
if (!actionBarLayout.fragmentsStack.isEmpty() && event.getAction() == MotionEvent.ACTION_UP) {
float x = event.getX();
float y = event.getY();
int[] location = new int[2];
layersActionBarLayout.getLocationOnScreen(location);
int viewX = location[0];
int viewY = location[1];
if (layersActionBarLayout.checkTransitionAnimation() || x > viewX && x < viewX + layersActionBarLayout.getWidth() && y > viewY && y < viewY + layersActionBarLayout.getHeight()) {
return false;
} else {
if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
layersActionBarLayout.removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
a--;
}
layersActionBarLayout.closeLastFragment(true);
}
return true;
}
}
return false;
});
shadowTablet.setOnClickListener(v -> {
});
layersActionBarLayout = new ActionBarLayout(this);
layersActionBarLayout.setRemoveActionBarExtraHeight(true);
layersActionBarLayout.setBackgroundView(shadowTablet);
layersActionBarLayout.setUseAlphaAnimations(true);
layersActionBarLayout.setBackgroundResource(R.drawable.boxshadow);
launchLayout.addView(layersActionBarLayout, LayoutHelper.createRelative(530, (AndroidUtilities.isSmallTablet() ? 528 : 700)));
layersActionBarLayout.init(layerFragmentsStack);
layersActionBarLayout.setDelegate(this);
layersActionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer);
} else {
RelativeLayout launchLayout = new RelativeLayout(this);
drawerLayoutContainer.addView(launchLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
backgroundTablet = new SizeNotifierFrameLayout(this) {
@Override
protected boolean isActionBarVisible() {
return false;
}
};
backgroundTablet.setOccupyStatusBar(false);
backgroundTablet.setBackgroundImage(Theme.getCachedWallpaper(), Theme.isWallpaperMotion());
launchLayout.addView(backgroundTablet, LayoutHelper.createRelative(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
launchLayout.addView(actionBarLayout, LayoutHelper.createRelative(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
}
// drawerLayoutContainer.setDrawerLayout(listView);
drawerLayoutContainer.setParentActionBarLayout(actionBarLayout);
actionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer);
actionBarLayout.init(mainFragmentsStack);
actionBarLayout.setDelegate(this);
passcodeView = new PasscodeView(this);
drawerLayoutContainer.addView(passcodeView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.closeOtherAppActivities, this);
actionBarLayout.removeAllFragments();
if (layersActionBarLayout != null) {
layersActionBarLayout.removeAllFragments();
}
handleIntent(getIntent(), false, savedInstanceState != null, false, UserConfig.selectedAccount, 0);
needLayout();
}
use of org.telegram.ui.Components.SizeNotifierFrameLayout in project Telegram-FOSS by Telegram-FOSS-Team.
the class PopupNotificationActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Theme.createDialogsResources(this);
Theme.createChatResources(this, false);
AndroidUtilities.fillStatusBarHeight(this);
for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
NotificationCenter.getInstance(a).addObserver(this, NotificationCenter.appDidLogout);
NotificationCenter.getInstance(a).addObserver(this, NotificationCenter.updateInterfaces);
NotificationCenter.getInstance(a).addObserver(this, NotificationCenter.messagePlayingProgressDidChanged);
NotificationCenter.getInstance(a).addObserver(this, NotificationCenter.messagePlayingDidReset);
NotificationCenter.getInstance(a).addObserver(this, NotificationCenter.contactsDidLoad);
}
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.pushMessagesUpdated);
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.emojiLoaded);
classGuid = ConnectionsManager.generateClassGuid();
statusDrawables[0] = new TypingDotsDrawable(false);
statusDrawables[1] = new RecordStatusDrawable(false);
statusDrawables[2] = new SendingFileDrawable(false);
statusDrawables[3] = new PlayingGameDrawable(false, null);
statusDrawables[4] = new RoundStatusDrawable(false);
SizeNotifierFrameLayout contentView = new SizeNotifierFrameLayout(this) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(widthSize, heightSize);
int keyboardSize = measureKeyboardHeight();
if (keyboardSize <= AndroidUtilities.dp(20)) {
heightSize -= chatActivityEnterView.getEmojiPadding();
}
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
if (chatActivityEnterView.isPopupView(child)) {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(child.getLayoutParams().height, MeasureSpec.EXACTLY));
} else if (chatActivityEnterView.isRecordCircle(child)) {
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
} else {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(Math.max(AndroidUtilities.dp(10), heightSize + AndroidUtilities.dp(2)), MeasureSpec.EXACTLY));
}
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int count = getChildCount();
int paddingBottom = measureKeyboardHeight() <= AndroidUtilities.dp(20) ? chatActivityEnterView.getEmojiPadding() : 0;
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
int width = child.getMeasuredWidth();
int height = child.getMeasuredHeight();
int childLeft;
int childTop;
int gravity = lp.gravity;
if (gravity == -1) {
gravity = Gravity.TOP | Gravity.LEFT;
}
final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
switch(absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.CENTER_HORIZONTAL:
childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
break;
case Gravity.RIGHT:
childLeft = r - width - lp.rightMargin;
break;
case Gravity.LEFT:
default:
childLeft = lp.leftMargin;
}
switch(verticalGravity) {
case Gravity.CENTER_VERTICAL:
childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin;
break;
case Gravity.BOTTOM:
childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin;
break;
default:
childTop = lp.topMargin;
}
if (chatActivityEnterView.isPopupView(child)) {
childTop = paddingBottom != 0 ? getMeasuredHeight() - paddingBottom : getMeasuredHeight();
} else if (chatActivityEnterView.isRecordCircle(child)) {
childTop = popupContainer.getTop() + popupContainer.getMeasuredHeight() - child.getMeasuredHeight() - lp.bottomMargin;
childLeft = popupContainer.getLeft() + popupContainer.getMeasuredWidth() - child.getMeasuredWidth() - lp.rightMargin;
}
child.layout(childLeft, childTop, childLeft + width, childTop + height);
}
notifyHeightChanged();
}
};
setContentView(contentView);
contentView.setBackgroundColor(0x99000000);
RelativeLayout relativeLayout = new RelativeLayout(this);
contentView.addView(relativeLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
popupContainer = new RelativeLayout(this) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int w = chatActivityEnterView.getMeasuredWidth();
int h = chatActivityEnterView.getMeasuredHeight();
for (int a = 0, count; a < getChildCount(); a++) {
View v = getChildAt(a);
if (v.getTag() instanceof String) {
v.measure(MeasureSpec.makeMeasureSpec(w, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(h - AndroidUtilities.dp(3), MeasureSpec.EXACTLY));
}
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
for (int a = 0, count; a < getChildCount(); a++) {
View v = getChildAt(a);
if (v.getTag() instanceof String) {
v.layout(v.getLeft(), chatActivityEnterView.getTop() + AndroidUtilities.dp(3), v.getRight(), chatActivityEnterView.getBottom());
}
}
}
};
popupContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
relativeLayout.addView(popupContainer, LayoutHelper.createRelative(LayoutHelper.MATCH_PARENT, 240, 12, 0, 12, 0, RelativeLayout.CENTER_IN_PARENT));
if (chatActivityEnterView != null) {
chatActivityEnterView.onDestroy();
}
chatActivityEnterView = new ChatActivityEnterView(this, contentView, null, false);
chatActivityEnterView.setId(id_chat_compose_panel);
popupContainer.addView(chatActivityEnterView, LayoutHelper.createRelative(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, RelativeLayout.ALIGN_PARENT_BOTTOM));
chatActivityEnterView.setDelegate(new ChatActivityEnterView.ChatActivityEnterViewDelegate() {
@Override
public void onMessageSend(CharSequence message, boolean notify, int scheduleDate) {
if (currentMessageObject == null) {
return;
}
if (currentMessageNum >= 0 && currentMessageNum < popupMessages.size()) {
popupMessages.remove(currentMessageNum);
}
MessagesController.getInstance(currentMessageObject.currentAccount).markDialogAsRead(currentMessageObject.getDialogId(), currentMessageObject.getId(), Math.max(0, currentMessageObject.getId()), currentMessageObject.messageOwner.date, true, 0, 0, true, 0);
currentMessageObject = null;
getNewMessage();
}
@Override
public void onTextChanged(CharSequence text, boolean big) {
}
@Override
public void onTextSelectionChanged(int start, int end) {
}
@Override
public void onTextSpansChanged(CharSequence text) {
}
@Override
public void onStickersExpandedChange() {
}
@Override
public void onSwitchRecordMode(boolean video) {
}
@Override
public void onPreAudioVideoRecord() {
}
@Override
public void onMessageEditEnd(boolean loading) {
}
@Override
public void needSendTyping() {
if (currentMessageObject != null) {
MessagesController.getInstance(currentMessageObject.currentAccount).sendTyping(currentMessageObject.getDialogId(), 0, 0, classGuid);
}
}
@Override
public void onAttachButtonHidden() {
}
@Override
public void onAttachButtonShow() {
}
@Override
public void onWindowSizeChanged(int size) {
}
@Override
public void onStickersTab(boolean opened) {
}
@Override
public void didPressAttachButton() {
}
@Override
public void needStartRecordVideo(int state, boolean notify, int scheduleDate) {
}
@Override
public void needStartRecordAudio(int state) {
}
@Override
public void needChangeVideoPreviewState(int state, float seekProgress) {
}
@Override
public void needShowMediaBanHint() {
}
@Override
public void onUpdateSlowModeButton(View button, boolean show, CharSequence time) {
}
@Override
public void onSendLongClick() {
}
@Override
public void onAudioVideoInterfaceUpdated() {
}
});
messageContainer = new FrameLayoutTouch(this);
popupContainer.addView(messageContainer, 0);
actionBar = new ActionBar(this);
actionBar.setOccupyStatusBar(false);
actionBar.setBackButtonImage(R.drawable.ic_close_white);
actionBar.setBackgroundColor(Theme.getColor(Theme.key_actionBarDefault));
actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_actionBarDefaultSelector), false);
popupContainer.addView(actionBar);
ViewGroup.LayoutParams layoutParams = actionBar.getLayoutParams();
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
actionBar.setLayoutParams(layoutParams);
ActionBarMenu menu = actionBar.createMenu();
ActionBarMenuItem view = menu.addItemWithWidth(2, 0, AndroidUtilities.dp(56));
countText = new TextView(this);
countText.setTextColor(Theme.getColor(Theme.key_actionBarDefaultSubtitle));
countText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
countText.setGravity(Gravity.CENTER);
view.addView(countText, LayoutHelper.createFrame(56, LayoutHelper.MATCH_PARENT));
avatarContainer = new FrameLayout(this);
avatarContainer.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
actionBar.addView(avatarContainer);
FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) avatarContainer.getLayoutParams();
layoutParams2.height = LayoutHelper.MATCH_PARENT;
layoutParams2.width = LayoutHelper.WRAP_CONTENT;
layoutParams2.rightMargin = AndroidUtilities.dp(48);
layoutParams2.leftMargin = AndroidUtilities.dp(60);
layoutParams2.gravity = Gravity.TOP | Gravity.LEFT;
avatarContainer.setLayoutParams(layoutParams2);
avatarImageView = new BackupImageView(this);
avatarImageView.setRoundRadius(AndroidUtilities.dp(21));
avatarContainer.addView(avatarImageView);
layoutParams2 = (FrameLayout.LayoutParams) avatarImageView.getLayoutParams();
layoutParams2.width = AndroidUtilities.dp(42);
layoutParams2.height = AndroidUtilities.dp(42);
layoutParams2.topMargin = AndroidUtilities.dp(3);
avatarImageView.setLayoutParams(layoutParams2);
nameTextView = new TextView(this);
nameTextView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultTitle));
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
nameTextView.setLines(1);
nameTextView.setMaxLines(1);
nameTextView.setSingleLine(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
nameTextView.setGravity(Gravity.LEFT);
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
avatarContainer.addView(nameTextView);
layoutParams2 = (FrameLayout.LayoutParams) nameTextView.getLayoutParams();
layoutParams2.width = LayoutHelper.WRAP_CONTENT;
layoutParams2.height = LayoutHelper.WRAP_CONTENT;
layoutParams2.leftMargin = AndroidUtilities.dp(54);
layoutParams2.bottomMargin = AndroidUtilities.dp(22);
layoutParams2.gravity = Gravity.BOTTOM;
nameTextView.setLayoutParams(layoutParams2);
onlineTextView = new TextView(this);
onlineTextView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultSubtitle));
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
onlineTextView.setLines(1);
onlineTextView.setMaxLines(1);
onlineTextView.setSingleLine(true);
onlineTextView.setEllipsize(TextUtils.TruncateAt.END);
onlineTextView.setGravity(Gravity.LEFT);
avatarContainer.addView(onlineTextView);
layoutParams2 = (FrameLayout.LayoutParams) onlineTextView.getLayoutParams();
layoutParams2.width = LayoutHelper.WRAP_CONTENT;
layoutParams2.height = LayoutHelper.WRAP_CONTENT;
layoutParams2.leftMargin = AndroidUtilities.dp(54);
layoutParams2.bottomMargin = AndroidUtilities.dp(4);
layoutParams2.gravity = Gravity.BOTTOM;
onlineTextView.setLayoutParams(layoutParams2);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
onFinish();
finish();
} else if (id == 1) {
openCurrentMessage();
} else if (id == 2) {
switchToNextMessage();
}
}
});
PowerManager pm = (PowerManager) ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "screen");
wakeLock.setReferenceCounted(false);
handleIntent(getIntent());
}
use of org.telegram.ui.Components.SizeNotifierFrameLayout in project Telegram-FOSS by Telegram-FOSS-Team.
the class PhotoPickerActivity method createView.
@SuppressWarnings("unchecked")
@Override
public View createView(Context context) {
listSort = false;
actionBar.setBackgroundColor(Theme.getColor(dialogBackgroundKey));
actionBar.setTitleColor(Theme.getColor(textKey));
actionBar.setItemsColor(Theme.getColor(textKey), false);
actionBar.setItemsBackgroundColor(Theme.getColor(selectorKey), false);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
if (selectedAlbum != null) {
actionBar.setTitle(selectedAlbum.bucketName);
} else if (type == 0) {
actionBar.setTitle(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
} else if (type == 1) {
actionBar.setTitle(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == change_sort) {
listSort = !listSort;
if (listSort) {
listView.setPadding(0, 0, 0, AndroidUtilities.dp(48));
} else {
listView.setPadding(AndroidUtilities.dp(6), AndroidUtilities.dp(8), AndroidUtilities.dp(6), AndroidUtilities.dp(50));
}
listView.stopScroll();
layoutManager.scrollToPositionWithOffset(0, 0);
listAdapter.notifyDataSetChanged();
} else if (id == open_in) {
if (delegate != null) {
delegate.onOpenInPressed();
}
finishFragment();
}
}
});
if (isDocumentsPicker) {
ActionBarMenu menu = actionBar.createMenu();
ActionBarMenuItem menuItem = menu.addItem(0, R.drawable.ic_ab_other);
menuItem.setSubMenuDelegate(new ActionBarMenuItem.ActionBarSubMenuItemDelegate() {
@Override
public void onShowSubMenu() {
showAsListItem.setText(listSort ? LocaleController.getString("ShowAsGrid", R.string.ShowAsGrid) : LocaleController.getString("ShowAsList", R.string.ShowAsList));
showAsListItem.setIcon(listSort ? R.drawable.msg_media : R.drawable.msg_list);
}
@Override
public void onHideSubMenu() {
}
});
showAsListItem = menuItem.addSubItem(change_sort, R.drawable.msg_list, LocaleController.getString("ShowAsList", R.string.ShowAsList));
menuItem.addSubItem(open_in, R.drawable.msg_openin, LocaleController.getString("OpenInExternalApp", R.string.OpenInExternalApp));
}
if (selectedAlbum == null) {
ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
}
@Override
public boolean canCollapseSearch() {
finishFragment();
return false;
}
@Override
public void onTextChanged(EditText editText) {
if (editText.getText().length() == 0) {
searchResult.clear();
searchResultKeys.clear();
lastSearchString = null;
imageSearchEndReached = true;
searching = false;
if (imageReqId != 0) {
ConnectionsManager.getInstance(currentAccount).cancelRequest(imageReqId, true);
imageReqId = 0;
}
emptyView.setText(LocaleController.getString("NoRecentSearches", R.string.NoRecentSearches));
updateSearchInterface();
}
}
@Override
public void onSearchPressed(EditText editText) {
processSearch(editText);
}
});
EditTextBoldCursor editText = searchItem.getSearchField();
editText.setTextColor(Theme.getColor(textKey));
editText.setCursorColor(Theme.getColor(textKey));
editText.setHintTextColor(Theme.getColor(Theme.key_chat_messagePanelHint));
}
if (selectedAlbum == null) {
if (type == 0) {
searchItem.setSearchFieldHint(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
} else if (type == 1) {
searchItem.setSearchFieldHint(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
}
}
sizeNotifierFrameLayout = new SizeNotifierFrameLayout(context) {
private int lastNotifyWidth;
private boolean ignoreLayout;
private int lastItemSize;
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int totalHeight = MeasureSpec.getSize(heightMeasureSpec);
int availableWidth = MeasureSpec.getSize(widthMeasureSpec);
if (AndroidUtilities.isTablet()) {
itemsPerRow = 4;
} else if (AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y) {
itemsPerRow = 4;
} else {
itemsPerRow = 3;
}
ignoreLayout = true;
itemSize = (availableWidth - AndroidUtilities.dp(6 * 2) - AndroidUtilities.dp(5 * 2)) / itemsPerRow;
if (lastItemSize != itemSize) {
lastItemSize = itemSize;
AndroidUtilities.runOnUIThread(() -> listAdapter.notifyDataSetChanged());
}
if (listSort) {
layoutManager.setSpanCount(1);
} else {
layoutManager.setSpanCount(itemSize * itemsPerRow + AndroidUtilities.dp(5) * (itemsPerRow - 1));
}
ignoreLayout = false;
onMeasureInternal(widthMeasureSpec, MeasureSpec.makeMeasureSpec(totalHeight, MeasureSpec.EXACTLY));
}
private void onMeasureInternal(int widthMeasureSpec, int heightMeasureSpec) {
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(widthSize, heightSize);
int kbHeight = measureKeyboardHeight();
int keyboardSize = SharedConfig.smoothKeyboard ? 0 : kbHeight;
if (keyboardSize <= AndroidUtilities.dp(20)) {
if (!AndroidUtilities.isInMultiwindow && commentTextView != null && frameLayout2.getParent() == this) {
heightSize -= commentTextView.getEmojiPadding();
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
}
}
if (kbHeight > AndroidUtilities.dp(20) && commentTextView != null) {
ignoreLayout = true;
commentTextView.hideEmojiView();
ignoreLayout = false;
}
if (SharedConfig.smoothKeyboard && commentTextView != null && commentTextView.isPopupShowing()) {
fragmentView.setTranslationY(0);
listView.setTranslationY(0);
emptyView.setTranslationY(0);
}
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (child == null || child.getVisibility() == GONE) {
continue;
}
if (commentTextView != null && commentTextView.isPopupView(child)) {
if (AndroidUtilities.isInMultiwindow || AndroidUtilities.isTablet()) {
if (AndroidUtilities.isTablet()) {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(AndroidUtilities.isTablet() ? 200 : 320), heightSize - AndroidUtilities.statusBarHeight + getPaddingTop()), MeasureSpec.EXACTLY));
} else {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize - AndroidUtilities.statusBarHeight + getPaddingTop(), MeasureSpec.EXACTLY));
}
} else {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(child.getLayoutParams().height, MeasureSpec.EXACTLY));
}
} else {
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
}
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
if (lastNotifyWidth != r - l) {
lastNotifyWidth = r - l;
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
sendPopupWindow.dismiss();
}
}
final int count = getChildCount();
int keyboardSize = SharedConfig.smoothKeyboard ? 0 : measureKeyboardHeight();
int paddingBottom = commentTextView != null && frameLayout2.getParent() == this && keyboardSize <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow && !AndroidUtilities.isTablet() ? commentTextView.getEmojiPadding() : 0;
setBottomClip(paddingBottom);
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final int width = child.getMeasuredWidth();
final int height = child.getMeasuredHeight();
int childLeft;
int childTop;
int gravity = lp.gravity;
if (gravity == -1) {
gravity = Gravity.TOP | Gravity.LEFT;
}
final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
switch(absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.CENTER_HORIZONTAL:
childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
break;
case Gravity.RIGHT:
childLeft = (r - l) - width - lp.rightMargin - getPaddingRight();
break;
case Gravity.LEFT:
default:
childLeft = lp.leftMargin + getPaddingLeft();
}
switch(verticalGravity) {
case Gravity.TOP:
childTop = lp.topMargin + getPaddingTop();
break;
case Gravity.CENTER_VERTICAL:
childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin;
break;
case Gravity.BOTTOM:
childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin;
break;
default:
childTop = lp.topMargin;
}
if (commentTextView != null && commentTextView.isPopupView(child)) {
if (AndroidUtilities.isTablet()) {
childTop = getMeasuredHeight() - child.getMeasuredHeight();
} else {
childTop = getMeasuredHeight() + keyboardSize - child.getMeasuredHeight();
}
}
child.layout(childLeft, childTop, childLeft + width, childTop + height);
}
notifyHeightChanged();
}
@Override
public void requestLayout() {
if (ignoreLayout) {
return;
}
super.requestLayout();
}
};
sizeNotifierFrameLayout.setBackgroundColor(Theme.getColor(dialogBackgroundKey));
fragmentView = sizeNotifierFrameLayout;
listView = new RecyclerListView(context);
listView.setPadding(AndroidUtilities.dp(6), AndroidUtilities.dp(8), AndroidUtilities.dp(6), AndroidUtilities.dp(50));
listView.setClipToPadding(false);
listView.setHorizontalScrollBarEnabled(false);
listView.setVerticalScrollBarEnabled(false);
listView.setItemAnimator(null);
listView.setLayoutAnimation(null);
listView.setLayoutManager(layoutManager = new GridLayoutManager(context, 4) {
@Override
public boolean supportsPredictiveItemAnimations() {
return false;
}
});
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (listAdapter.getItemViewType(position) == 1 || listSort || selectedAlbum == null && TextUtils.isEmpty(lastSearchString)) {
return layoutManager.getSpanCount();
} else {
return itemSize + (position % itemsPerRow != itemsPerRow - 1 ? AndroidUtilities.dp(5) : 0);
}
}
});
sizeNotifierFrameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
listView.setAdapter(listAdapter = new ListAdapter(context));
listView.setGlowColor(Theme.getColor(dialogBackgroundKey));
listView.setOnItemClickListener((view, position) -> {
if (selectedAlbum == null && searchResult.isEmpty()) {
if (position < recentSearches.size()) {
String text = recentSearches.get(position);
if (searchDelegate != null) {
searchDelegate.shouldSearchText(text);
} else {
searchItem.getSearchField().setText(text);
searchItem.getSearchField().setSelection(text.length());
processSearch(searchItem.getSearchField());
}
} else if (position == recentSearches.size() + 1) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("ClearSearchAlertTitle", R.string.ClearSearchAlertTitle));
builder.setMessage(LocaleController.getString("ClearSearchAlert", R.string.ClearSearchAlert));
builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), (dialogInterface, i) -> {
if (searchDelegate != null) {
searchDelegate.shouldClearRecentSearch();
} else {
clearRecentSearch();
}
});
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));
}
return;
}
return;
}
ArrayList<Object> arrayList;
if (selectedAlbum != null) {
arrayList = (ArrayList) selectedAlbum.photos;
} else {
arrayList = (ArrayList) searchResult;
}
if (position < 0 || position >= arrayList.size()) {
return;
}
if (searchItem != null) {
AndroidUtilities.hideKeyboard(searchItem.getSearchField());
}
if (listSort) {
onListItemClick(view, arrayList.get(position));
} else {
int type;
if (selectPhotoType == PhotoAlbumPickerActivity.SELECT_TYPE_AVATAR || selectPhotoType == PhotoAlbumPickerActivity.SELECT_TYPE_AVATAR_VIDEO) {
type = PhotoViewer.SELECT_TYPE_AVATAR;
} else if (selectPhotoType == PhotoAlbumPickerActivity.SELECT_TYPE_WALLPAPER) {
type = PhotoViewer.SELECT_TYPE_WALLPAPER;
} else if (selectPhotoType == PhotoAlbumPickerActivity.SELECT_TYPE_QR) {
type = PhotoViewer.SELECT_TYPE_QR;
} else if (chatActivity == null) {
type = 4;
} else {
type = 0;
}
PhotoViewer.getInstance().setParentActivity(getParentActivity());
PhotoViewer.getInstance().setMaxSelectedPhotos(maxSelectedPhotos, allowOrder);
PhotoViewer.getInstance().openPhotoForSelect(arrayList, position, type, isDocumentsPicker, provider, chatActivity);
}
});
if (maxSelectedPhotos != 1) {
listView.setOnItemLongClickListener((view, position) -> {
if (listSort) {
onListItemClick(view, selectedAlbum.photos.get(position));
return true;
} else {
if (view instanceof PhotoAttachPhotoCell) {
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
itemRangeSelector.setIsActive(view, true, position, shouldSelect = !cell.isChecked());
}
}
return false;
});
}
itemRangeSelector = new RecyclerViewItemRangeSelector(new RecyclerViewItemRangeSelector.RecyclerViewItemRangeSelectorDelegate() {
@Override
public int getItemCount() {
return listAdapter.getItemCount();
}
@Override
public void setSelected(View view, int index, boolean selected) {
if (selected != shouldSelect || !(view instanceof PhotoAttachPhotoCell)) {
return;
}
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
cell.callDelegate();
}
@Override
public boolean isSelected(int index) {
Object key;
if (selectedAlbum != null) {
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
key = photoEntry.imageId;
} else {
MediaController.SearchImage photoEntry = searchResult.get(index);
key = photoEntry.id;
}
return selectedPhotos.containsKey(key);
}
@Override
public boolean isIndexSelectable(int index) {
return listAdapter.getItemViewType(index) == 0;
}
@Override
public void onStartStopSelection(boolean start) {
alertOnlyOnce = start ? 1 : 0;
if (start) {
parentLayout.requestDisallowInterceptTouchEvent(true);
}
listView.hideSelector(true);
}
});
if (maxSelectedPhotos != 1) {
listView.addOnItemTouchListener(itemRangeSelector);
}
emptyView = new EmptyTextProgressView(context);
emptyView.setTextColor(0xff93999d);
emptyView.setProgressBarColor(0xff527da3);
if (selectedAlbum != null) {
emptyView.setShowAtCenter(false);
emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
} else {
emptyView.setShowAtTop(true);
emptyView.setPadding(0, AndroidUtilities.dp(200), 0, 0);
emptyView.setText(LocaleController.getString("NoRecentSearches", R.string.NoRecentSearches));
}
sizeNotifierFrameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, selectPhotoType != PhotoAlbumPickerActivity.SELECT_TYPE_ALL ? 0 : 48));
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (selectedAlbum == null) {
int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
int visibleItemCount = firstVisibleItem == RecyclerView.NO_POSITION ? 0 : Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1;
if (visibleItemCount > 0) {
int totalItemCount = layoutManager.getItemCount();
if (firstVisibleItem + visibleItemCount > totalItemCount - 2 && !searching) {
if (!imageSearchEndReached) {
searchImages(type == 1, lastSearchString, nextImagesSearchOffset, true);
}
}
}
}
}
});
if (selectedAlbum == null) {
updateSearchInterface();
}
if (needsBottomLayout) {
shadow = new View(context);
shadow.setBackgroundResource(R.drawable.header_shadow_reverse);
shadow.setTranslationY(AndroidUtilities.dp(48));
sizeNotifierFrameLayout.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
frameLayout2 = new FrameLayout(context);
frameLayout2.setBackgroundColor(Theme.getColor(dialogBackgroundKey));
frameLayout2.setVisibility(View.INVISIBLE);
frameLayout2.setTranslationY(AndroidUtilities.dp(48));
sizeNotifierFrameLayout.addView(frameLayout2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));
frameLayout2.setOnTouchListener((v, event) -> true);
if (commentTextView != null) {
commentTextView.onDestroy();
}
commentTextView = new EditTextEmoji(context, sizeNotifierFrameLayout, null, EditTextEmoji.STYLE_DIALOG);
InputFilter[] inputFilters = new InputFilter[1];
inputFilters[0] = new InputFilter.LengthFilter(MessagesController.getInstance(UserConfig.selectedAccount).maxCaptionLength);
commentTextView.setFilters(inputFilters);
commentTextView.setHint(LocaleController.getString("AddCaption", R.string.AddCaption));
commentTextView.onResume();
EditTextBoldCursor editText = commentTextView.getEditText();
editText.setMaxLines(1);
editText.setSingleLine(true);
frameLayout2.addView(commentTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 84, 0));
if (caption != null) {
commentTextView.setText(caption);
}
commentTextView.getEditText().addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (delegate != null) {
delegate.onCaptionChanged(s);
}
}
});
writeButtonContainer = new FrameLayout(context) {
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
info.setText(LocaleController.formatPluralString("AccDescrSendPhotos", selectedPhotos.size()));
info.setClassName(Button.class.getName());
info.setLongClickable(true);
info.setClickable(true);
}
};
writeButtonContainer.setFocusable(true);
writeButtonContainer.setFocusableInTouchMode(true);
writeButtonContainer.setVisibility(View.INVISIBLE);
writeButtonContainer.setScaleX(0.2f);
writeButtonContainer.setScaleY(0.2f);
writeButtonContainer.setAlpha(0.0f);
sizeNotifierFrameLayout.addView(writeButtonContainer, LayoutHelper.createFrame(60, 60, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 12, 10));
writeButton = new ImageView(context);
writeButtonDrawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_dialogFloatingButton), Theme.getColor(Build.VERSION.SDK_INT >= 21 ? Theme.key_dialogFloatingButtonPressed : Theme.key_dialogFloatingButton));
if (Build.VERSION.SDK_INT < 21) {
Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow_profile).mutate();
shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, writeButtonDrawable, 0, 0);
combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
writeButtonDrawable = combinedDrawable;
}
writeButton.setBackgroundDrawable(writeButtonDrawable);
writeButton.setImageResource(R.drawable.attach_send);
writeButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
writeButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogFloatingIcon), PorterDuff.Mode.MULTIPLY));
writeButton.setScaleType(ImageView.ScaleType.CENTER);
if (Build.VERSION.SDK_INT >= 21) {
writeButton.setOutlineProvider(new ViewOutlineProvider() {
@SuppressLint("NewApi")
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
}
});
}
writeButtonContainer.addView(writeButton, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, Gravity.LEFT | Gravity.TOP, Build.VERSION.SDK_INT >= 21 ? 2 : 0, 0, 0, 0));
writeButton.setOnClickListener(v -> {
if (chatActivity != null && chatActivity.isInScheduleMode()) {
AlertsCreator.createScheduleDatePickerDialog(getParentActivity(), chatActivity.getDialogId(), this::sendSelectedPhotos);
} else {
sendSelectedPhotos(true, 0);
}
});
writeButton.setOnLongClickListener(view -> {
if (chatActivity == null || maxSelectedPhotos == 1) {
return false;
}
TLRPC.Chat chat = chatActivity.getCurrentChat();
TLRPC.User user = chatActivity.getCurrentUser();
if (sendPopupLayout == null) {
sendPopupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getParentActivity());
sendPopupLayout.setAnimationEnabled(false);
sendPopupLayout.setOnTouchListener(new View.OnTouchListener() {
private android.graphics.Rect popupRect = new android.graphics.Rect();
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
v.getHitRect(popupRect);
if (!popupRect.contains((int) event.getX(), (int) event.getY())) {
sendPopupWindow.dismiss();
}
}
}
return false;
}
});
sendPopupLayout.setDispatchKeyEventListener(keyEvent -> {
if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0 && sendPopupWindow != null && sendPopupWindow.isShowing()) {
sendPopupWindow.dismiss();
}
});
sendPopupLayout.setShownFromBotton(false);
itemCells = new ActionBarMenuSubItem[2];
for (int a = 0; a < 2; a++) {
if (a == 0 && !chatActivity.canScheduleMessage() || a == 1 && UserObject.isUserSelf(user)) {
continue;
}
int num = a;
itemCells[a] = new ActionBarMenuSubItem(getParentActivity(), a == 0, a == 1);
if (num == 0) {
if (UserObject.isUserSelf(user)) {
itemCells[a].setTextAndIcon(LocaleController.getString("SetReminder", R.string.SetReminder), R.drawable.msg_schedule);
} else {
itemCells[a].setTextAndIcon(LocaleController.getString("ScheduleMessage", R.string.ScheduleMessage), R.drawable.msg_schedule);
}
} else {
itemCells[a].setTextAndIcon(LocaleController.getString("SendWithoutSound", R.string.SendWithoutSound), R.drawable.input_notify_off);
}
itemCells[a].setMinimumWidth(AndroidUtilities.dp(196));
sendPopupLayout.addView(itemCells[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
itemCells[a].setOnClickListener(v -> {
if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
sendPopupWindow.dismiss();
}
if (num == 0) {
AlertsCreator.createScheduleDatePickerDialog(getParentActivity(), chatActivity.getDialogId(), this::sendSelectedPhotos);
} else {
sendSelectedPhotos(true, 0);
}
});
}
sendPopupLayout.setupRadialSelectors(Theme.getColor(selectorKey));
sendPopupWindow = new ActionBarPopupWindow(sendPopupLayout, LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
sendPopupWindow.setAnimationEnabled(false);
sendPopupWindow.setAnimationStyle(R.style.PopupContextAnimation2);
sendPopupWindow.setOutsideTouchable(true);
sendPopupWindow.setClippingEnabled(true);
sendPopupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED);
sendPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
sendPopupWindow.getContentView().setFocusableInTouchMode(true);
}
sendPopupLayout.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST));
sendPopupWindow.setFocusable(true);
int[] location = new int[2];
view.getLocationInWindow(location);
sendPopupWindow.showAtLocation(view, Gravity.LEFT | Gravity.TOP, location[0] + view.getMeasuredWidth() - sendPopupLayout.getMeasuredWidth() + AndroidUtilities.dp(8), location[1] - sendPopupLayout.getMeasuredHeight() - AndroidUtilities.dp(2));
sendPopupWindow.dimBehind();
view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
return false;
});
textPaint.setTextSize(AndroidUtilities.dp(12));
textPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
selectedCountView = new View(context) {
@Override
protected void onDraw(Canvas canvas) {
String text = String.format("%d", Math.max(1, selectedPhotosOrder.size()));
int textSize = (int) Math.ceil(textPaint.measureText(text));
int size = Math.max(AndroidUtilities.dp(16) + textSize, AndroidUtilities.dp(24));
int cx = getMeasuredWidth() / 2;
int cy = getMeasuredHeight() / 2;
textPaint.setColor(Theme.getColor(Theme.key_dialogRoundCheckBoxCheck));
paint.setColor(Theme.getColor(dialogBackgroundKey));
rect.set(cx - size / 2, 0, cx + size / 2, getMeasuredHeight());
canvas.drawRoundRect(rect, AndroidUtilities.dp(12), AndroidUtilities.dp(12), paint);
paint.setColor(Theme.getColor(Theme.key_dialogRoundCheckBox));
rect.set(cx - size / 2 + AndroidUtilities.dp(2), AndroidUtilities.dp(2), cx + size / 2 - AndroidUtilities.dp(2), getMeasuredHeight() - AndroidUtilities.dp(2));
canvas.drawRoundRect(rect, AndroidUtilities.dp(10), AndroidUtilities.dp(10), paint);
canvas.drawText(text, cx - textSize / 2, AndroidUtilities.dp(16.2f), textPaint);
}
};
selectedCountView.setAlpha(0.0f);
selectedCountView.setScaleX(0.2f);
selectedCountView.setScaleY(0.2f);
sizeNotifierFrameLayout.addView(selectedCountView, LayoutHelper.createFrame(42, 24, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, -2, 9));
if (selectPhotoType != PhotoAlbumPickerActivity.SELECT_TYPE_ALL) {
commentTextView.setVisibility(View.GONE);
}
}
allowIndices = (selectedAlbum != null || type == 0 || type == 1) && allowOrder;
listView.setEmptyView(emptyView);
updatePhotosButton(0);
return fragmentView;
}
use of org.telegram.ui.Components.SizeNotifierFrameLayout in project Telegram-FOSS by Telegram-FOSS-Team.
the class PhotoPickerSearchActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackgroundColor(Theme.getColor(Theme.key_dialogBackground));
actionBar.setTitleColor(Theme.getColor(Theme.key_dialogTextBlack));
actionBar.setItemsColor(Theme.getColor(Theme.key_dialogTextBlack), false);
actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_dialogButtonSelector), false);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
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;
ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(search_button, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
imagesSearch.getActionBar().openSearchField("", false);
gifsSearch.getActionBar().openSearchField("", false);
searchItem.getSearchField().requestFocus();
}
@Override
public boolean canCollapseSearch() {
finishFragment();
return false;
}
@Override
public void onTextChanged(EditText editText) {
imagesSearch.getActionBar().setSearchFieldText(editText.getText().toString());
gifsSearch.getActionBar().setSearchFieldText(editText.getText().toString());
}
@Override
public void onSearchPressed(EditText editText) {
imagesSearch.getActionBar().onSearchPressed();
gifsSearch.getActionBar().onSearchPressed();
}
});
searchItem.setSearchFieldHint(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
EditTextBoldCursor editText = searchItem.getSearchField();
editText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
editText.setCursorColor(Theme.getColor(Theme.key_dialogTextBlack));
editText.setHintTextColor(Theme.getColor(Theme.key_chat_messagePanelHint));
scrollSlidingTextTabStrip = new ScrollSlidingTextTabStrip(context);
scrollSlidingTextTabStrip.setUseSameWidth(true);
scrollSlidingTextTabStrip.setColors(Theme.key_chat_attachActiveTab, Theme.key_chat_attachActiveTab, Theme.key_chat_attachUnactiveTab, Theme.key_dialogButtonSelector);
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;
if (id == 0) {
searchItem.setSearchFieldHint(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
} else {
searchItem.setSearchFieldHint(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
}
}
@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();
SizeNotifierFrameLayout sizeNotifierFrameLayout;
fragmentView = sizeNotifierFrameLayout = new SizeNotifierFrameLayout(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
public void forceHasOverlappingRendering(boolean hasOverlappingRendering) {
super.forceHasOverlappingRendering(hasOverlappingRendering);
}
@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 keyboardSize = SharedConfig.smoothKeyboard ? 0 : measureKeyboardHeight();
if (keyboardSize <= AndroidUtilities.dp(20)) {
if (!AndroidUtilities.isInMultiwindow) {
heightSize -= commentTextView.getEmojiPadding();
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
}
} else {
globalIgnoreLayout = true;
commentTextView.hideEmojiView();
globalIgnoreLayout = false;
}
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(AndroidUtilities.dp(4), actionBarHeight + AndroidUtilities.dp(4), AndroidUtilities.dp(4), 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;
}
if (commentTextView != null && commentTextView.isPopupView(child)) {
if (AndroidUtilities.isInMultiwindow || AndroidUtilities.isTablet()) {
if (AndroidUtilities.isTablet()) {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(AndroidUtilities.isTablet() ? 200 : 320), heightSize - AndroidUtilities.statusBarHeight + getPaddingTop()), MeasureSpec.EXACTLY));
} else {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize - AndroidUtilities.statusBarHeight + getPaddingTop(), MeasureSpec.EXACTLY));
}
} else {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(child.getLayoutParams().height, MeasureSpec.EXACTLY));
}
} else {
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
}
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int count = getChildCount();
int keyboardSize = SharedConfig.smoothKeyboard ? 0 : measureKeyboardHeight();
int paddingBottom = keyboardSize <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow && !AndroidUtilities.isTablet() ? commentTextView.getEmojiPadding() : 0;
setBottomClip(paddingBottom);
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final int width = child.getMeasuredWidth();
final int height = child.getMeasuredHeight();
int childLeft;
int childTop;
int gravity = lp.gravity;
if (gravity == -1) {
gravity = Gravity.TOP | Gravity.LEFT;
}
final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
switch(absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.CENTER_HORIZONTAL:
childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
break;
case Gravity.RIGHT:
childLeft = (r - l) - width - lp.rightMargin - getPaddingRight();
break;
case Gravity.LEFT:
default:
childLeft = lp.leftMargin + getPaddingLeft();
}
switch(verticalGravity) {
case Gravity.TOP:
childTop = lp.topMargin + getPaddingTop();
break;
case Gravity.CENTER_VERTICAL:
childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin;
break;
case Gravity.BOTTOM:
childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin;
break;
default:
childTop = lp.topMargin;
}
if (commentTextView != null && commentTextView.isPopupView(child)) {
if (AndroidUtilities.isTablet()) {
childTop = getMeasuredHeight() - child.getMeasuredHeight();
} else {
childTop = getMeasuredHeight() + keyboardSize - child.getMeasuredHeight();
}
}
child.layout(childLeft, childTop, childLeft + width, childTop + height);
}
notifyHeightChanged();
}
@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) {
viewPages[0].setTranslationX(dx);
if (animatingForward) {
viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() + dx);
} else {
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;
}
};
sizeNotifierFrameLayout.setWillNotDraw(false);
imagesSearch.setParentFragment(this);
commentTextView = imagesSearch.commentTextView;
commentTextView.setSizeNotifierLayout(sizeNotifierFrameLayout);
for (int a = 0; a < 4; a++) {
View view;
switch(a) {
case 0:
view = imagesSearch.frameLayout2;
break;
case 1:
view = imagesSearch.writeButtonContainer;
break;
case 2:
view = imagesSearch.selectedCountView;
break;
case 3:
default:
view = imagesSearch.shadow;
break;
}
ViewGroup parent = (ViewGroup) view.getParent();
parent.removeView(view);
}
gifsSearch.setLayoutViews(imagesSearch.frameLayout2, imagesSearch.writeButtonContainer, imagesSearch.selectedCountView, imagesSearch.shadow, imagesSearch.commentTextView);
gifsSearch.setParentFragment(this);
for (int a = 0; a < viewPages.length; a++) {
viewPages[a] = 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);
}
}
}
};
sizeNotifierFrameLayout.addView(viewPages[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
if (a == 0) {
viewPages[a].parentFragment = imagesSearch;
viewPages[a].listView = imagesSearch.getListView();
} else if (a == 1) {
viewPages[a].parentFragment = gifsSearch;
viewPages[a].listView = gifsSearch.getListView();
viewPages[a].setVisibility(View.GONE);
}
viewPages[a].listView.setScrollingTouchSlop(RecyclerView.TOUCH_SLOP_PAGING);
viewPages[a].fragmentView = (FrameLayout) viewPages[a].parentFragment.getFragmentView();
viewPages[a].listView.setClipToPadding(false);
viewPages[a].actionBar = viewPages[a].parentFragment.getActionBar();
viewPages[a].addView(viewPages[a].fragmentView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
viewPages[a].addView(viewPages[a].actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
viewPages[a].actionBar.setVisibility(View.GONE);
RecyclerView.OnScrollListener onScrollListener = viewPages[a].listView.getOnScrollListener();
viewPages[a].listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
onScrollListener.onScrollStateChanged(recyclerView, 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) {
onScrollListener.onScrolled(recyclerView, dx, 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);
}
}
}
});
}
sizeNotifierFrameLayout.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
sizeNotifierFrameLayout.addView(imagesSearch.shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
sizeNotifierFrameLayout.addView(imagesSearch.frameLayout2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));
sizeNotifierFrameLayout.addView(imagesSearch.writeButtonContainer, LayoutHelper.createFrame(60, 60, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 12, 10));
sizeNotifierFrameLayout.addView(imagesSearch.selectedCountView, LayoutHelper.createFrame(42, 24, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, -2, 9));
updateTabs();
switchToCurrentSelectedMode(false);
swipeBackEnabled = scrollSlidingTextTabStrip.getCurrentTabId() == scrollSlidingTextTabStrip.getFirstTabId();
return fragmentView;
}
use of org.telegram.ui.Components.SizeNotifierFrameLayout in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method showGifHint.
private boolean showGifHint() {
if (chatActivityEnterView == null || chatActivityEnterView.getVisibility() != View.VISIBLE) {
return false;
}
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
if (preferences.getBoolean("gifhint", false)) {
return false;
}
preferences.edit().putBoolean("gifhint", true).commit();
if (getParentActivity() == null || fragmentView == null || gifHintTextView != null) {
return false;
}
if (!allowContextBotPanelSecond) {
if (chatActivityEnterView != null) {
chatActivityEnterView.setOpenGifsTabFirst();
}
return false;
}
SizeNotifierFrameLayout frameLayout = (SizeNotifierFrameLayout) fragmentView;
int index = frameLayout.indexOfChild(chatActivityEnterView);
if (index == -1) {
return false;
}
chatActivityEnterView.setOpenGifsTabFirst();
emojiButtonRed = new View(getParentActivity());
emojiButtonRed.setBackgroundResource(R.drawable.redcircle);
frameLayout.addView(emojiButtonRed, index + 1, LayoutHelper.createFrame(10, 10, Gravity.BOTTOM | Gravity.LEFT, 30, 0, 0, 27));
gifHintTextView = new HintView(getParentActivity(), 9, themeDelegate);
gifHintTextView.setText(LocaleController.getString("TapHereGifs", R.string.TapHereGifs));
frameLayout.addView(gifHintTextView, index + 1, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.BOTTOM, 5, 0, 5, 3));
AnimatorSet AnimatorSet = new AnimatorSet();
AnimatorSet.playTogether(ObjectAnimator.ofFloat(gifHintTextView, View.ALPHA, 0.0f, 1.0f), ObjectAnimator.ofFloat(emojiButtonRed, View.ALPHA, 0.0f, 1.0f));
AnimatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
AndroidUtilities.runOnUIThread(() -> {
if (gifHintTextView == null) {
return;
}
AnimatorSet AnimatorSet = new AnimatorSet();
AnimatorSet.playTogether(ObjectAnimator.ofFloat(gifHintTextView, View.ALPHA, 0.0f));
AnimatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (gifHintTextView != null) {
gifHintTextView.setVisibility(View.GONE);
}
}
});
AnimatorSet.setDuration(300);
AnimatorSet.start();
}, 2000);
}
});
AnimatorSet.setDuration(300);
AnimatorSet.start();
View emojiButton = chatActivityEnterView.getEmojiButton();
if (emojiButton != null) {
gifHintTextView.showForView(emojiButton, true);
}
return true;
}
Aggregations