List of usage examples for android.widget FrameLayout addView
public void addView(View child, int index)
From source file:kr.wdream.ui.MediaActivity.java
@Override public View createView(Context context) { Log.d(LOG_TAG, "createView"); actionBar.setBackButtonDrawable(new BackDrawable(false)); actionBar.setTitle(""); actionBar.setAllowOverlayTitle(false); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override/*from w ww . ja v a 2 s.c o m*/ public void onItemClick(int id) { if (id == -1) { if (actionBar.isActionModeShowed()) { for (int a = 1; a >= 0; a--) { selectedFiles[a].clear(); } cantDeleteMessagesCount = 0; actionBar.hideActionMode(); listView.invalidateViews(); } else { finishFragment(); } } else if (id == shared_media_item) { if (selectedMode == 0) { return; } selectedMode = 0; switchToCurrentSelectedMode(); } else if (id == files_item) { if (selectedMode == 1) { return; } selectedMode = 1; switchToCurrentSelectedMode(); } else if (id == links_item) { if (selectedMode == 3) { return; } selectedMode = 3; switchToCurrentSelectedMode(); } else if (id == music_item) { if (selectedMode == 4) { return; } selectedMode = 4; switchToCurrentSelectedMode(); } else if (id == delete) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.formatString("AreYouSureDeleteMessages", kr.wdream.storyshop.R.string.AreYouSureDeleteMessages, LocaleController.formatPluralString("items", selectedFiles[0].size() + selectedFiles[1].size()))); builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { for (int a = 1; a >= 0; a--) { ArrayList<Integer> ids = new ArrayList<>(selectedFiles[a].keySet()); ArrayList<Long> random_ids = null; TLRPC.EncryptedChat currentEncryptedChat = null; int channelId = 0; if (!ids.isEmpty()) { MessageObject msg = selectedFiles[a].get(ids.get(0)); if (channelId == 0 && msg.messageOwner.to_id.channel_id != 0) { channelId = msg.messageOwner.to_id.channel_id; } } if ((int) dialog_id == 0) { currentEncryptedChat = MessagesController.getInstance() .getEncryptedChat((int) (dialog_id >> 32)); } if (currentEncryptedChat != null) { random_ids = new ArrayList<>(); for (HashMap.Entry<Integer, MessageObject> entry : selectedFiles[a] .entrySet()) { MessageObject msg = entry.getValue(); if (msg.messageOwner.random_id != 0 && msg.type != 10) { random_ids.add(msg.messageOwner.random_id); } } } MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat, channelId); selectedFiles[a].clear(); } actionBar.hideActionMode(); actionBar.closeSearchField(); cantDeleteMessagesCount = 0; } }); builder.setNegativeButton( LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null); showDialog(builder.create()); } else if (id == forward) { Bundle args = new Bundle(); args.putBoolean("onlySelect", true); args.putInt("dialogsType", 1); DialogsActivity fragment = new DialogsActivity(args); fragment.setDelegate(new DialogsActivity.DialogsActivityDelegate() { @Override public void didSelectDialog(DialogsActivity fragment, long did, boolean param) { int lower_part = (int) did; if (lower_part != 0) { Bundle args = new Bundle(); args.putBoolean("scrollToTopOnResume", true); if (lower_part > 0) { args.putInt("user_id", lower_part); } else if (lower_part < 0) { args.putInt("chat_id", -lower_part); } if (!MessagesController.checkCanOpenChat(args, fragment)) { return; } ArrayList<MessageObject> fmessages = new ArrayList<>(); for (int a = 1; a >= 0; a--) { ArrayList<Integer> ids = new ArrayList<>(selectedFiles[a].keySet()); Collections.sort(ids); for (Integer id : ids) { if (id > 0) { fmessages.add(selectedFiles[a].get(id)); } } selectedFiles[a].clear(); } cantDeleteMessagesCount = 0; actionBar.hideActionMode(); NotificationCenter.getInstance() .postNotificationName(NotificationCenter.closeChats); ChatActivity chatActivity = new ChatActivity(args); presentFragment(chatActivity, true); chatActivity.showReplyPanel(true, null, fmessages, null, false, false); if (!AndroidUtilities.isTablet()) { removeSelfFromStack(); } } else { fragment.finishFragment(); } } }); presentFragment(fragment); } } }); for (int a = 1; a >= 0; a--) { selectedFiles[a].clear(); } cantDeleteMessagesCount = 0; actionModeViews.clear(); final ActionBarMenu menu = actionBar.createMenu(); searchItem = menu.addItem(0, kr.wdream.storyshop.R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override public void onSearchExpand() { dropDownContainer.setVisibility(View.GONE); searching = true; } @Override public void onSearchCollapse() { dropDownContainer.setVisibility(View.VISIBLE); if (selectedMode == 1) { documentsSearchAdapter.search(null); } else if (selectedMode == 3) { linksSearchAdapter.search(null); } else if (selectedMode == 4) { audioSearchAdapter.search(null); } searching = false; searchWas = false; switchToCurrentSelectedMode(); } @Override public void onTextChanged(EditText editText) { String text = editText.getText().toString(); if (text.length() != 0) { searchWas = true; switchToCurrentSelectedMode(); } if (selectedMode == 1) { if (documentsSearchAdapter == null) { return; } documentsSearchAdapter.search(text); } else if (selectedMode == 3) { if (linksSearchAdapter == null) { return; } linksSearchAdapter.search(text); } else if (selectedMode == 4) { if (audioSearchAdapter == null) { return; } audioSearchAdapter.search(text); } } }); searchItem.getSearchField() .setHint(LocaleController.getString("Search", kr.wdream.storyshop.R.string.Search)); searchItem.setVisibility(View.GONE); dropDownContainer = new ActionBarMenuItem(context, menu, 0); dropDownContainer.setSubMenuOpenSide(1); dropDownContainer.addSubItem(shared_media_item, LocaleController.getString("SharedMediaTitle", kr.wdream.storyshop.R.string.SharedMediaTitle), 0); dropDownContainer.addSubItem(files_item, LocaleController.getString("DocumentsTitle", kr.wdream.storyshop.R.string.DocumentsTitle), 0); if ((int) dialog_id != 0) { dropDownContainer.addSubItem(links_item, LocaleController.getString("LinksTitle", kr.wdream.storyshop.R.string.LinksTitle), 0); dropDownContainer.addSubItem(music_item, LocaleController.getString("AudioTitle", kr.wdream.storyshop.R.string.AudioTitle), 0); } else { TLRPC.EncryptedChat currentEncryptedChat = MessagesController.getInstance() .getEncryptedChat((int) (dialog_id >> 32)); if (currentEncryptedChat != null && AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46) { dropDownContainer.addSubItem(music_item, LocaleController.getString("AudioTitle", kr.wdream.storyshop.R.string.AudioTitle), 0); } } actionBar.addView(dropDownContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 64 : 56, 0, 40, 0)); dropDownContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dropDownContainer.toggleSubMenu(); } }); dropDown = new TextView(context); dropDown.setGravity(Gravity.LEFT); dropDown.setSingleLine(true); dropDown.setLines(1); dropDown.setMaxLines(1); dropDown.setEllipsize(TextUtils.TruncateAt.END); dropDown.setTextColor(0xffffffff); dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, kr.wdream.storyshop.R.drawable.ic_arrow_drop_down, 0); dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4)); dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0); dropDownContainer.addView(dropDown, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 16, 0, 0, 0)); final ActionBarMenu actionMode = actionBar.createActionMode(); selectedMessagesCountTextView = new NumberTextView(actionMode.getContext()); selectedMessagesCountTextView.setTextSize(18); selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); selectedMessagesCountTextView.setTextColor(0xff737373); selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); actionMode.addView(selectedMessagesCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 65, 0, 0, 0)); if ((int) dialog_id != 0) { actionModeViews.add(actionMode.addItem(forward, kr.wdream.storyshop.R.drawable.ic_ab_fwd_forward, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54))); } actionModeViews.add(actionMode.addItem(delete, kr.wdream.storyshop.R.drawable.ic_ab_fwd_delete, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54))); photoVideoAdapter = new SharedPhotoVideoAdapter(context); documentsAdapter = new SharedDocumentsAdapter(context, 1); audioAdapter = new SharedDocumentsAdapter(context, 4); documentsSearchAdapter = new MediaSearchAdapter(context, 1); audioSearchAdapter = new MediaSearchAdapter(context, 4); linksSearchAdapter = new MediaSearchAdapter(context, 3); linksAdapter = new SharedLinksAdapter(context); FrameLayout frameLayout; fragmentView = frameLayout = new FrameLayout(context); listView = new SectionsListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setDrawSelectorOnTop(true); listView.setClipToPadding(false); frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) { if ((selectedMode == 1 || selectedMode == 4) && view instanceof SharedDocumentCell) { MediaActivity.this.onItemClick(i, view, ((SharedDocumentCell) view).getMessage(), 0); } else if (selectedMode == 3 && view instanceof SharedLinkCell) { MediaActivity.this.onItemClick(i, view, ((SharedLinkCell) view).getMessage(), 0); } } }); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) { AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus()); } scrolling = scrollState != SCROLL_STATE_IDLE; } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (searching && searchWas) { return; } if (visibleItemCount != 0 && firstVisibleItem + visibleItemCount > totalItemCount - 2 && !sharedMediaData[selectedMode].loading) { int type; if (selectedMode == 0) { type = SharedMediaQuery.MEDIA_PHOTOVIDEO; } else if (selectedMode == 1) { type = SharedMediaQuery.MEDIA_FILE; } else if (selectedMode == 2) { type = SharedMediaQuery.MEDIA_AUDIO; } else if (selectedMode == 4) { type = SharedMediaQuery.MEDIA_MUSIC; } else { type = SharedMediaQuery.MEDIA_URL; } if (!sharedMediaData[selectedMode].endReached[0]) { sharedMediaData[selectedMode].loading = true; SharedMediaQuery.loadMedia(dialog_id, 0, 50, sharedMediaData[selectedMode].max_id[0], type, true, classGuid); } else if (mergeDialogId != 0 && !sharedMediaData[selectedMode].endReached[1]) { sharedMediaData[selectedMode].loading = true; SharedMediaQuery.loadMedia(mergeDialogId, 0, 50, sharedMediaData[selectedMode].max_id[1], type, true, classGuid); } } } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int i, long id) { if ((selectedMode == 1 || selectedMode == 4) && view instanceof SharedDocumentCell) { SharedDocumentCell cell = (SharedDocumentCell) view; MessageObject message = cell.getMessage(); return MediaActivity.this.onItemLongClick(message, view, 0); } else if (selectedMode == 3 && view instanceof SharedLinkCell) { SharedLinkCell cell = (SharedLinkCell) view; MessageObject message = cell.getMessage(); return MediaActivity.this.onItemLongClick(message, view, 0); } return false; } }); for (int a = 0; a < 6; a++) { cellCache.add(new SharedPhotoVideoCell(context)); } emptyView = new LinearLayout(context); emptyView.setOrientation(LinearLayout.VERTICAL); emptyView.setGravity(Gravity.CENTER); emptyView.setVisibility(View.GONE); emptyView.setBackgroundColor(0xfff0f0f0); frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); emptyView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); emptyImageView = new ImageView(context); emptyView.addView(emptyImageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT)); emptyTextView = new TextView(context); emptyTextView.setTextColor(0xff8a8a8a); emptyTextView.setGravity(Gravity.CENTER); emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17); emptyTextView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), AndroidUtilities.dp(128)); emptyView.addView(emptyTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 24, 0, 0)); progressView = new LinearLayout(context); progressView.setGravity(Gravity.CENTER); progressView.setOrientation(LinearLayout.VERTICAL); progressView.setVisibility(View.GONE); progressView.setBackgroundColor(0xfff0f0f0); frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); ProgressBar progressBar = new ProgressBar(context); progressView.addView(progressBar, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT)); switchToCurrentSelectedMode(); if (!AndroidUtilities.isTablet()) { frameLayout.addView(new PlayerView(context, this), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 39, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0)); } return fragmentView; }
From source file:org.telegram.ui.Components.AudioPlayerAlert.java
private void onSubItemClick(int id) { final MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject(); if (messageObject == null || parentActivity == null) { return;//from w w w.ja v a 2 s . c om } if (id == 1) { if (UserConfig.selectedAccount != currentAccount) { parentActivity.switchToAccount(currentAccount, true); } Bundle args = new Bundle(); args.putBoolean("onlySelect", true); args.putInt("dialogsType", 3); DialogsActivity fragment = new DialogsActivity(args); final ArrayList<MessageObject> fmessages = new ArrayList<>(); fmessages.add(messageObject); fragment.setDelegate((fragment1, dids, message, param) -> { if (dids.size() > 1 || dids.get(0) == UserConfig.getInstance(currentAccount).getClientUserId() || message != null) { for (int a = 0; a < dids.size(); a++) { long did = dids.get(a); if (message != null) { SendMessagesHelper.getInstance(currentAccount).sendMessage(message.toString(), did, null, null, true, null, null, null); } SendMessagesHelper.getInstance(currentAccount).sendMessage(fmessages, did); } fragment1.finishFragment(); } else { long did = dids.get(0); int lower_part = (int) did; int high_part = (int) (did >> 32); Bundle args1 = new Bundle(); args1.putBoolean("scrollToTopOnResume", true); if (lower_part != 0) { if (lower_part > 0) { args1.putInt("user_id", lower_part); } else if (lower_part < 0) { args1.putInt("chat_id", -lower_part); } } else { args1.putInt("enc_id", high_part); } NotificationCenter.getInstance(currentAccount) .postNotificationName(NotificationCenter.closeChats); ChatActivity chatActivity = new ChatActivity(args1); if (parentActivity.presentFragment(chatActivity, true, false)) { chatActivity.showFieldPanelForForward(true, fmessages); } else { fragment1.finishFragment(); } } }); parentActivity.presentFragment(fragment); dismiss(); } else if (id == 2) { try { File f = null; boolean isVideo = false; if (!TextUtils.isEmpty(messageObject.messageOwner.attachPath)) { f = new File(messageObject.messageOwner.attachPath); if (!f.exists()) { f = null; } } if (f == null) { f = FileLoader.getPathToMessage(messageObject.messageOwner); } if (f.exists()) { Intent intent = new Intent(Intent.ACTION_SEND); if (messageObject != null) { intent.setType(messageObject.getMimeType()); } else { intent.setType("audio/mp3"); } if (Build.VERSION.SDK_INT >= 24) { try { intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(ApplicationLoader.applicationContext, BuildConfig.APPLICATION_ID + ".provider", f)); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } catch (Exception ignore) { intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f)); } } else { intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f)); } parentActivity.startActivityForResult(Intent.createChooser(intent, LocaleController.getString("ShareFile", R.string.ShareFile)), 500); } else { AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); builder.setMessage(LocaleController.getString("PleaseDownload", R.string.PleaseDownload)); builder.show(); } } catch (Exception e) { FileLog.e(e); } } else if (id == 3) { AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); //builder.setMessage(LocaleController.formatString("AreYouSureDeleteAudio", R.string.AreYouSureDeleteAudio)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); final boolean deleteForAll[] = new boolean[1]; int lower_id = (int) messageObject.getDialogId(); if (lower_id != 0) { TLRPC.Chat currentChat; TLRPC.User currentUser; if (lower_id > 0) { currentUser = MessagesController.getInstance(currentAccount).getUser(lower_id); currentChat = null; } else { currentUser = null; currentChat = MessagesController.getInstance(currentAccount).getChat(-lower_id); } if (currentUser != null || !ChatObject.isChannel(currentChat)) { boolean hasOutgoing = false; int currentDate = ConnectionsManager.getInstance(currentAccount).getCurrentTime(); if (currentUser != null && currentUser.id != UserConfig.getInstance(currentAccount).getClientUserId() || currentChat != null) { if ((messageObject.messageOwner.action == null || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionEmpty) && messageObject.isOut() && (currentDate - messageObject.messageOwner.date) <= 2 * 24 * 60 * 60) { FrameLayout frameLayout = new FrameLayout(parentActivity); CheckBoxCell cell = new CheckBoxCell(parentActivity, 1); cell.setBackgroundDrawable(Theme.getSelectorDrawable(false)); if (currentChat != null) { cell.setText(LocaleController.getString("DeleteForAll", R.string.DeleteForAll), "", false, false); } else { cell.setText(LocaleController.formatString("DeleteForUser", R.string.DeleteForUser, UserObject.getFirstName(currentUser)), "", false, false); } cell.setPadding( LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0); frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 0)); cell.setOnClickListener(v -> { CheckBoxCell cell1 = (CheckBoxCell) v; deleteForAll[0] = !deleteForAll[0]; cell1.setChecked(deleteForAll[0], true); }); builder.setView(frameLayout); } } } } builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> { dismiss(); ArrayList<Integer> arr = new ArrayList<>(); arr.add(messageObject.getId()); ArrayList<Long> random_ids = null; TLRPC.EncryptedChat encryptedChat = null; if ((int) messageObject.getDialogId() == 0 && messageObject.messageOwner.random_id != 0) { random_ids = new ArrayList<>(); random_ids.add(messageObject.messageOwner.random_id); encryptedChat = MessagesController.getInstance(currentAccount) .getEncryptedChat((int) (messageObject.getDialogId() >> 32)); } MessagesController.getInstance(currentAccount).deleteMessages(arr, random_ids, encryptedChat, messageObject.messageOwner.to_id.channel_id, deleteForAll[0]); }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.show(); } else if (id == 4) { if (UserConfig.selectedAccount != currentAccount) { parentActivity.switchToAccount(currentAccount, true); } Bundle args = new Bundle(); long did = messageObject.getDialogId(); int lower_part = (int) did; int high_id = (int) (did >> 32); if (lower_part != 0) { if (high_id == 1) { args.putInt("chat_id", lower_part); } else { if (lower_part > 0) { args.putInt("user_id", lower_part); } else if (lower_part < 0) { TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_part); if (chat != null && chat.migrated_to != null) { args.putInt("migrated_to", lower_part); lower_part = -chat.migrated_to.channel_id; } args.putInt("chat_id", -lower_part); } } } else { args.putInt("enc_id", high_id); } args.putInt("message_id", messageObject.getId()); NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.closeChats); parentActivity.presentFragment(new ChatActivity(args), false, false); dismiss(); } }
From source file:net.bluehack.ui.Components.EmojiView.java
public EmojiView(boolean needStickers, boolean needGif, final Context context) { super(context); showGifs = needGif;/*from ww w . j av a 2 s.c om*/ dotDrawable = context.getResources().getDrawable(R.drawable.bluecircle); if (Build.VERSION.SDK_INT >= 21) { outlineProvider = new ViewOutlineProvider() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void getOutline(View view, Outline outline) { outline.setRoundRect(view.getPaddingLeft(), view.getPaddingTop(), view.getMeasuredWidth() - view.getPaddingRight(), view.getMeasuredHeight() - view.getPaddingBottom(), AndroidUtilities.dp(6)); } }; } for (int i = 0; i < EmojiData.dataColored.length + 1; i++) { GridView gridView = new GridView(context); if (AndroidUtilities.isTablet()) { gridView.setColumnWidth(AndroidUtilities.dp(60)); } else { gridView.setColumnWidth(AndroidUtilities.dp(45)); } gridView.setNumColumns(-1); EmojiGridAdapter emojiGridAdapter = new EmojiGridAdapter(i - 1); AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7); gridView.setAdapter(emojiGridAdapter); adapters.add(emojiGridAdapter); emojiGrids.add(gridView); FrameLayout frameLayout = new FrameLayout(context); frameLayout.addView(gridView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0)); views.add(frameLayout); } if (needStickers) { stickersWrap = new FrameLayout(context); StickersQuery.checkStickers(StickersQuery.TYPE_IMAGE); StickersQuery.checkFeaturedStickers(); stickersGridView = new RecyclerListView(context) { @Override public boolean onInterceptTouchEvent(MotionEvent event) { boolean result = StickerPreviewViewer.getInstance().onInterceptTouchEvent(event, stickersGridView, EmojiView.this.getMeasuredHeight()); return super.onInterceptTouchEvent(event) || result; } @Override public void setVisibility(int visibility) { if (gifsGridView != null && gifsGridView.getVisibility() == VISIBLE || trendingGridView != null && trendingGridView.getVisibility() == VISIBLE) { super.setVisibility(GONE); return; } super.setVisibility(visibility); } }; stickersGridView.setLayoutManager(stickersLayoutManager = new GridLayoutManager(context, 5)); stickersLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (position == stickersGridAdapter.totalItems) { return stickersGridAdapter.stickersPerRow; } return 1; } }); stickersGridView.setPadding(0, AndroidUtilities.dp(4 + 48), 0, 0); stickersGridView.setClipToPadding(false); views.add(stickersWrap); stickersGridView.setAdapter(stickersGridAdapter = new StickersGridAdapter(context)); stickersGridView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return StickerPreviewViewer.getInstance().onTouch(event, stickersGridView, EmojiView.this.getMeasuredHeight(), stickersOnItemClickListener); } }); stickersOnItemClickListener = new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (!(view instanceof StickerEmojiCell)) { return; } StickerPreviewViewer.getInstance().reset(); StickerEmojiCell cell = (StickerEmojiCell) view; if (cell.isDisabled()) { return; } cell.disable(); listener.onStickerSelected(cell.getSticker()); } }; stickersGridView.setOnItemClickListener(stickersOnItemClickListener); stickersGridView.setGlowColor(0xfff5f6f7); stickersWrap.addView(stickersGridView); trendingGridView = new RecyclerListView(context); trendingGridView.setItemAnimator(null); trendingGridView.setLayoutAnimation(null); trendingGridView.setLayoutManager(trendingLayoutManager = new GridLayoutManager(context, 5) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }); trendingLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (trendingGridAdapter.cache.get(position) instanceof Integer || position == trendingGridAdapter.totalItems) { return trendingGridAdapter.stickersPerRow; } return 1; } }); trendingGridView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { checkStickersTabY(recyclerView, dy); } }); trendingGridView.setClipToPadding(false); trendingGridView.setPadding(0, AndroidUtilities.dp(48), 0, 0); trendingGridView.setAdapter(trendingGridAdapter = new TrendingGridAdapter(context)); trendingGridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { TLRPC.StickerSetCovered pack = trendingGridAdapter.positionsToSets.get(position); if (pack != null) { listener.onShowStickerSet(pack); } } }); trendingGridAdapter.notifyDataSetChanged(); trendingGridView.setGlowColor(0xfff5f6f7); trendingGridView.setVisibility(GONE); stickersWrap.addView(trendingGridView); if (needGif) { gifsGridView = new RecyclerListView(context); gifsGridView.setClipToPadding(false); gifsGridView.setPadding(0, AndroidUtilities.dp(48), 0, 0); gifsGridView.setLayoutManager(flowLayoutManager = new ExtendedGridLayoutManager(context, 100) { private Size size = new Size(); @Override protected Size getSizeForItem(int i) { TLRPC.Document document = recentGifs.get(i); size.width = document.thumb != null && document.thumb.w != 0 ? document.thumb.w : 100; size.height = document.thumb != null && document.thumb.h != 0 ? document.thumb.h : 100; for (int b = 0; b < document.attributes.size(); b++) { TLRPC.DocumentAttribute attribute = document.attributes.get(b); if (attribute instanceof TLRPC.TL_documentAttributeImageSize || attribute instanceof TLRPC.TL_documentAttributeVideo) { size.width = attribute.w; size.height = attribute.h; break; } } return size; } }); flowLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { return flowLayoutManager.getSpanSizeForItem(position); } }); gifsGridView.addItemDecoration(new RecyclerView.ItemDecoration() { @Override public void getItemOffsets(android.graphics.Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { outRect.left = 0; outRect.top = 0; outRect.bottom = 0; int position = parent.getChildAdapterPosition(view); if (!flowLayoutManager.isFirstRow(position)) { outRect.top = AndroidUtilities.dp(2); } outRect.right = flowLayoutManager.isLastInRow(position) ? 0 : AndroidUtilities.dp(2); } }); gifsGridView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER); gifsGridView.setAdapter(gifsAdapter = new GifsAdapter(context)); gifsGridView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { checkStickersTabY(recyclerView, dy); } }); gifsGridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (position < 0 || position >= recentGifs.size() || listener == null) { return; } listener.onGifSelected(recentGifs.get(position)); } }); gifsGridView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() { @Override public boolean onItemClick(View view, int position) { if (position < 0 || position >= recentGifs.size()) { return false; } final TLRPC.Document searchImage = recentGifs.get(position); AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.getString("DeleteGif", R.string.DeleteGif)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK).toUpperCase(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { StickersQuery.removeRecentGif(searchImage); recentGifs = StickersQuery.getRecentGifs(); if (gifsAdapter != null) { gifsAdapter.notifyDataSetChanged(); } if (recentGifs.isEmpty()) { updateStickerTabs(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.show().setCanceledOnTouchOutside(true); return true; } }); gifsGridView.setVisibility(GONE); stickersWrap.addView(gifsGridView); } stickersEmptyView = new TextView(context); stickersEmptyView.setText(LocaleController.getString("NoStickers", R.string.NoStickers)); stickersEmptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); stickersEmptyView.setTextColor(0xff888888); stickersWrap.addView(stickersEmptyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 48, 0, 0)); stickersGridView.setEmptyView(stickersEmptyView); stickersTab = new ScrollSlidingTabStrip(context) { boolean startedScroll; float lastX; float lastTranslateX; boolean first = true; @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent ev) { if (first) { first = false; lastX = ev.getX(); } float newTranslationX = stickersTab.getTranslationX(); if (stickersTab.getScrollX() == 0 && newTranslationX == 0) { if (!startedScroll && lastX - ev.getX() < 0) { if (pager.beginFakeDrag()) { startedScroll = true; lastTranslateX = stickersTab.getTranslationX(); } } else if (startedScroll && lastX - ev.getX() > 0) { if (pager.isFakeDragging()) { pager.endFakeDrag(); startedScroll = false; } } } if (startedScroll) { int dx = (int) (ev.getX() - lastX + newTranslationX - lastTranslateX); try { pager.fakeDragBy(dx); lastTranslateX = newTranslationX; } catch (Exception e) { try { pager.endFakeDrag(); } catch (Exception e2) { //don't promt } startedScroll = false; FileLog.e("tmessages", e); } } lastX = ev.getX(); if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) { first = true; if (startedScroll) { pager.endFakeDrag(); startedScroll = false; } } return startedScroll || super.onTouchEvent(ev); } }; stickersTab.setUnderlineHeight(AndroidUtilities.dp(1)); stickersTab.setIndicatorColor(0xffe2e5e7); stickersTab.setUnderlineColor(0xffe2e5e7); stickersTab.setBackgroundColor(0xfff5f6f7); stickersTab.setVisibility(INVISIBLE); addView(stickersTab, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP)); stickersTab.setTranslationX(AndroidUtilities.displaySize.x); updateStickerTabs(); stickersTab.setDelegate(new ScrollSlidingTabStrip.ScrollSlidingTabStripDelegate() { @Override public void onPageSelected(int page) { if (gifsGridView != null) { if (page == gifTabNum + 1) { if (gifsGridView.getVisibility() != VISIBLE) { listener.onGifTab(true); showGifTab(); } } else if (page == trendingTabNum + 1) { if (trendingGridView.getVisibility() != VISIBLE) { showTrendingTab(); } } else { if (gifsGridView.getVisibility() == VISIBLE) { listener.onGifTab(false); gifsGridView.setVisibility(GONE); stickersGridView.setVisibility(VISIBLE); stickersEmptyView .setVisibility(stickersGridAdapter.getItemCount() != 0 ? GONE : VISIBLE); saveNewPage(); } else if (trendingGridView.getVisibility() == VISIBLE) { trendingGridView.setVisibility(GONE); stickersGridView.setVisibility(VISIBLE); stickersEmptyView .setVisibility(stickersGridAdapter.getItemCount() != 0 ? GONE : VISIBLE); saveNewPage(); } } } if (page == 0) { pager.setCurrentItem(0); return; } else { if (page == gifTabNum + 1 || page == trendingTabNum + 1) { return; } else if (page == recentTabBum + 1) { stickersLayoutManager.scrollToPositionWithOffset(0, 0); checkStickersTabY(null, 0); stickersTab.onPageScrolled(recentTabBum + 1, (recentTabBum > 0 ? recentTabBum : stickersTabOffset) + 1); return; } } int index = page - 1 - stickersTabOffset; if (index >= stickerSets.size()) { if (listener != null) { listener.onStickersSettingsClick(); } return; } if (index >= stickerSets.size()) { index = stickerSets.size() - 1; } stickersLayoutManager.scrollToPositionWithOffset( stickersGridAdapter.getPositionForPack(stickerSets.get(index)), 0); checkStickersTabY(null, 0); checkScroll(); } }); stickersGridView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { checkScroll(); checkStickersTabY(recyclerView, dy); } }); } pager = new ViewPager(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; pager.setAdapter(new EmojiPagesAdapter()); emojiTab = new LinearLayout(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; emojiTab.setOrientation(LinearLayout.HORIZONTAL); addView(emojiTab, LayoutHelper.createFrame(LayoutParams.MATCH_PARENT, 48)); pagerSlidingTabStrip = new PagerSlidingTabStrip(context); pagerSlidingTabStrip.setViewPager(pager); pagerSlidingTabStrip.setShouldExpand(true); pagerSlidingTabStrip.setIndicatorHeight(AndroidUtilities.dp(2)); pagerSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1)); pagerSlidingTabStrip.setIndicatorColor(0xff2b96e2); pagerSlidingTabStrip.setUnderlineColor(0xffe2e5e7); emojiTab.addView(pagerSlidingTabStrip, LayoutHelper.createLinear(0, 48, 1.0f)); pagerSlidingTabStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { EmojiView.this.onPageScrolled(position, getMeasuredWidth() - getPaddingLeft() - getPaddingRight(), positionOffsetPixels); } @Override public void onPageSelected(int position) { saveNewPage(); } @Override public void onPageScrollStateChanged(int state) { } }); FrameLayout frameLayout = new FrameLayout(context); emojiTab.addView(frameLayout, LayoutHelper.createLinear(52, 48)); backspaceButton = new ImageView(context) { @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { backspacePressed = true; backspaceOnce = false; postBackspaceRunnable(350); } else if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) { backspacePressed = false; if (!backspaceOnce) { if (listener != null && listener.onBackspace()) { backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); } } } super.onTouchEvent(event); return true; } }; backspaceButton.setImageResource(R.drawable.ic_smiles_backspace); backspaceButton.setBackgroundResource(R.drawable.ic_emoji_backspace); backspaceButton.setScaleType(ImageView.ScaleType.CENTER); frameLayout.addView(backspaceButton, LayoutHelper.createFrame(52, 48)); View view = new View(context); view.setBackgroundColor(0xffe2e5e7); frameLayout.addView(view, LayoutHelper.createFrame(52, 1, Gravity.LEFT | Gravity.BOTTOM)); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoRecent", R.string.NoRecent)); textView.setTextSize(18); textView.setTextColor(0xff888888); textView.setGravity(Gravity.CENTER); textView.setClickable(false); textView.setFocusable(false); ((FrameLayout) views.get(0)).addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 48, 0, 0)); emojiGrids.get(0).setEmptyView(textView); addView(pager, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP)); emojiSize = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 40 : 32); pickerView = new EmojiColorPickerView(context); pickerViewPopup = new EmojiPopupWindow(pickerView, popupWidth = AndroidUtilities.dp((AndroidUtilities.isTablet() ? 40 : 32) * 6 + 10 + 4 * 5), popupHeight = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 64 : 56)); pickerViewPopup.setOutsideTouchable(true); pickerViewPopup.setClippingEnabled(true); pickerViewPopup.setInputMethodMode(EmojiPopupWindow.INPUT_METHOD_NOT_NEEDED); pickerViewPopup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED); pickerViewPopup.getContentView().setFocusableInTouchMode(true); pickerViewPopup.getContentView().setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_UP && pickerViewPopup != null && pickerViewPopup.isShowing()) { pickerViewPopup.dismiss(); return true; } return false; } }); currentPage = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE).getInt("selected_page", 0); loadRecents(); }
From source file:kr.wdream.ui.Components.EmojiView.java
public EmojiView(boolean needStickers, boolean needGif, final Context context) { super(context); showGifs = needGif;//from w w w . j a va 2s. c o m dotDrawable = context.getResources().getDrawable(kr.wdream.storyshop.R.drawable.bluecircle); if (Build.VERSION.SDK_INT >= 21) { outlineProvider = new ViewOutlineProvider() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void getOutline(View view, Outline outline) { outline.setRoundRect(view.getPaddingLeft(), view.getPaddingTop(), view.getMeasuredWidth() - view.getPaddingRight(), view.getMeasuredHeight() - view.getPaddingBottom(), AndroidUtilities.dp(6)); } }; } for (int i = 0; i < EmojiData.dataColored.length + 1; i++) { GridView gridView = new GridView(context); if (AndroidUtilities.isTablet()) { gridView.setColumnWidth(AndroidUtilities.dp(60)); } else { gridView.setColumnWidth(AndroidUtilities.dp(45)); } gridView.setNumColumns(-1); EmojiGridAdapter emojiGridAdapter = new EmojiGridAdapter(i - 1); AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7); gridView.setAdapter(emojiGridAdapter); adapters.add(emojiGridAdapter); emojiGrids.add(gridView); FrameLayout frameLayout = new FrameLayout(context); frameLayout.addView(gridView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0)); views.add(frameLayout); } if (needStickers) { stickersWrap = new FrameLayout(context); StickersQuery.checkStickers(StickersQuery.TYPE_IMAGE); StickersQuery.checkFeaturedStickers(); stickersGridView = new RecyclerListView(context) { @Override public boolean onInterceptTouchEvent(MotionEvent event) { boolean result = StickerPreviewViewer.getInstance().onInterceptTouchEvent(event, stickersGridView, EmojiView.this.getMeasuredHeight()); return super.onInterceptTouchEvent(event) || result; } @Override public void setVisibility(int visibility) { if (gifsGridView != null && gifsGridView.getVisibility() == VISIBLE || trendingGridView != null && trendingGridView.getVisibility() == VISIBLE) { super.setVisibility(GONE); return; } super.setVisibility(visibility); } }; stickersGridView.setLayoutManager(stickersLayoutManager = new GridLayoutManager(context, 5)); stickersLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (position == stickersGridAdapter.totalItems) { return stickersGridAdapter.stickersPerRow; } return 1; } }); stickersGridView.setPadding(0, AndroidUtilities.dp(4 + 48), 0, 0); stickersGridView.setClipToPadding(false); views.add(stickersWrap); stickersGridView.setAdapter(stickersGridAdapter = new StickersGridAdapter(context)); stickersGridView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return StickerPreviewViewer.getInstance().onTouch(event, stickersGridView, EmojiView.this.getMeasuredHeight(), stickersOnItemClickListener); } }); stickersOnItemClickListener = new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (!(view instanceof StickerEmojiCell)) { return; } StickerPreviewViewer.getInstance().reset(); StickerEmojiCell cell = (StickerEmojiCell) view; if (cell.isDisabled()) { return; } cell.disable(); listener.onStickerSelected(cell.getSticker()); } }; stickersGridView.setOnItemClickListener(stickersOnItemClickListener); stickersGridView.setGlowColor(0xfff5f6f7); stickersWrap.addView(stickersGridView); trendingGridView = new RecyclerListView(context); trendingGridView.setItemAnimator(null); trendingGridView.setLayoutAnimation(null); trendingGridView.setLayoutManager(trendingLayoutManager = new GridLayoutManager(context, 5) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }); trendingLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (trendingGridAdapter.cache.get(position) instanceof Integer || position == trendingGridAdapter.totalItems) { return trendingGridAdapter.stickersPerRow; } return 1; } }); trendingGridView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { checkStickersTabY(recyclerView, dy); } }); trendingGridView.setClipToPadding(false); trendingGridView.setPadding(0, AndroidUtilities.dp(48), 0, 0); trendingGridView.setAdapter(trendingGridAdapter = new TrendingGridAdapter(context)); trendingGridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { TLRPC.StickerSetCovered pack = trendingGridAdapter.positionsToSets.get(position); if (pack != null) { listener.onShowStickerSet(pack); } } }); trendingGridAdapter.notifyDataSetChanged(); trendingGridView.setGlowColor(0xfff5f6f7); trendingGridView.setVisibility(GONE); stickersWrap.addView(trendingGridView); if (needGif) { gifsGridView = new RecyclerListView(context); gifsGridView.setClipToPadding(false); gifsGridView.setPadding(0, AndroidUtilities.dp(48), 0, 0); gifsGridView.setLayoutManager(flowLayoutManager = new ExtendedGridLayoutManager(context, 100) { private Size size = new Size(); @Override protected Size getSizeForItem(int i) { TLRPC.Document document = recentGifs.get(i); size.width = document.thumb != null && document.thumb.w != 0 ? document.thumb.w : 100; size.height = document.thumb != null && document.thumb.h != 0 ? document.thumb.h : 100; for (int b = 0; b < document.attributes.size(); b++) { TLRPC.DocumentAttribute attribute = document.attributes.get(b); if (attribute instanceof TLRPC.TL_documentAttributeImageSize || attribute instanceof TLRPC.TL_documentAttributeVideo) { size.width = attribute.w; size.height = attribute.h; break; } } return size; } }); flowLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { return flowLayoutManager.getSpanSizeForItem(position); } }); gifsGridView.addItemDecoration(new RecyclerView.ItemDecoration() { @Override public void getItemOffsets(android.graphics.Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { outRect.left = 0; outRect.top = 0; outRect.bottom = 0; int position = parent.getChildAdapterPosition(view); if (!flowLayoutManager.isFirstRow(position)) { outRect.top = AndroidUtilities.dp(2); } outRect.right = flowLayoutManager.isLastInRow(position) ? 0 : AndroidUtilities.dp(2); } }); gifsGridView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER); gifsGridView.setAdapter(gifsAdapter = new GifsAdapter(context)); gifsGridView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { checkStickersTabY(recyclerView, dy); } }); gifsGridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (position < 0 || position >= recentGifs.size() || listener == null) { return; } listener.onGifSelected(recentGifs.get(position)); } }); gifsGridView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() { @Override public boolean onItemClick(View view, int position) { if (position < 0 || position >= recentGifs.size()) { return false; } final TLRPC.Document searchImage = recentGifs.get(position); AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()); builder.setTitle( LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); builder.setMessage( LocaleController.getString("DeleteGif", kr.wdream.storyshop.R.string.DeleteGif)); builder.setPositiveButton( LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK).toUpperCase(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { StickersQuery.removeRecentGif(searchImage); recentGifs = StickersQuery.getRecentGifs(); if (gifsAdapter != null) { gifsAdapter.notifyDataSetChanged(); } if (recentGifs.isEmpty()) { updateStickerTabs(); } } }); builder.setNegativeButton( LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null); builder.show().setCanceledOnTouchOutside(true); return true; } }); gifsGridView.setVisibility(GONE); stickersWrap.addView(gifsGridView); } stickersEmptyView = new TextView(context); stickersEmptyView .setText(LocaleController.getString("NoStickers", kr.wdream.storyshop.R.string.NoStickers)); stickersEmptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); stickersEmptyView.setTextColor(0xff888888); stickersWrap.addView(stickersEmptyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 48, 0, 0)); stickersGridView.setEmptyView(stickersEmptyView); stickersTab = new ScrollSlidingTabStrip(context) { boolean startedScroll; float lastX; float lastTranslateX; boolean first = true; @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent ev) { if (first) { first = false; lastX = ev.getX(); } float newTranslationX = stickersTab.getTranslationX(); if (stickersTab.getScrollX() == 0 && newTranslationX == 0) { if (!startedScroll && lastX - ev.getX() < 0) { if (pager.beginFakeDrag()) { startedScroll = true; lastTranslateX = stickersTab.getTranslationX(); } } else if (startedScroll && lastX - ev.getX() > 0) { if (pager.isFakeDragging()) { pager.endFakeDrag(); startedScroll = false; } } } if (startedScroll) { int dx = (int) (ev.getX() - lastX + newTranslationX - lastTranslateX); try { pager.fakeDragBy(dx); lastTranslateX = newTranslationX; } catch (Exception e) { try { pager.endFakeDrag(); } catch (Exception e2) { //don't promt } startedScroll = false; FileLog.e("tmessages", e); } } lastX = ev.getX(); if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) { first = true; if (startedScroll) { pager.endFakeDrag(); startedScroll = false; } } return startedScroll || super.onTouchEvent(ev); } }; stickersTab.setUnderlineHeight(AndroidUtilities.dp(1)); stickersTab.setIndicatorColor(0xffe2e5e7); stickersTab.setUnderlineColor(0xffe2e5e7); stickersTab.setBackgroundColor(0xfff5f6f7); stickersTab.setVisibility(INVISIBLE); addView(stickersTab, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP)); stickersTab.setTranslationX(AndroidUtilities.displaySize.x); updateStickerTabs(); stickersTab.setDelegate(new ScrollSlidingTabStrip.ScrollSlidingTabStripDelegate() { @Override public void onPageSelected(int page) { if (gifsGridView != null) { if (page == gifTabNum + 1) { if (gifsGridView.getVisibility() != VISIBLE) { listener.onGifTab(true); showGifTab(); } } else if (page == trendingTabNum + 1) { if (trendingGridView.getVisibility() != VISIBLE) { showTrendingTab(); } } else { if (gifsGridView.getVisibility() == VISIBLE) { listener.onGifTab(false); gifsGridView.setVisibility(GONE); stickersGridView.setVisibility(VISIBLE); stickersEmptyView .setVisibility(stickersGridAdapter.getItemCount() != 0 ? GONE : VISIBLE); saveNewPage(); } else if (trendingGridView.getVisibility() == VISIBLE) { trendingGridView.setVisibility(GONE); stickersGridView.setVisibility(VISIBLE); stickersEmptyView .setVisibility(stickersGridAdapter.getItemCount() != 0 ? GONE : VISIBLE); saveNewPage(); } } } if (page == 0) { pager.setCurrentItem(0); return; } else { if (page == gifTabNum + 1 || page == trendingTabNum + 1) { return; } else if (page == recentTabBum + 1) { stickersLayoutManager.scrollToPositionWithOffset(0, 0); checkStickersTabY(null, 0); stickersTab.onPageScrolled(recentTabBum + 1, (recentTabBum > 0 ? recentTabBum : stickersTabOffset) + 1); return; } } int index = page - 1 - stickersTabOffset; if (index >= stickerSets.size()) { if (listener != null) { listener.onStickersSettingsClick(); } return; } if (index >= stickerSets.size()) { index = stickerSets.size() - 1; } stickersLayoutManager.scrollToPositionWithOffset( stickersGridAdapter.getPositionForPack(stickerSets.get(index)), 0); checkStickersTabY(null, 0); checkScroll(); } }); stickersGridView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { checkScroll(); checkStickersTabY(recyclerView, dy); } }); } pager = new ViewPager(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; pager.setAdapter(new EmojiPagesAdapter()); emojiTab = new LinearLayout(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; emojiTab.setOrientation(LinearLayout.HORIZONTAL); addView(emojiTab, LayoutHelper.createFrame(LayoutParams.MATCH_PARENT, 48)); pagerSlidingTabStrip = new PagerSlidingTabStrip(context); pagerSlidingTabStrip.setViewPager(pager); pagerSlidingTabStrip.setShouldExpand(true); pagerSlidingTabStrip.setIndicatorHeight(AndroidUtilities.dp(0)); pagerSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1)); //? ? pagerSlidingTabStrip.setIndicatorColor(0xff2b96e2); pagerSlidingTabStrip.setUnderlineColor(0xffe2e5e7); emojiTab.addView(pagerSlidingTabStrip, LayoutHelper.createLinear(0, 48, 1.0f)); pagerSlidingTabStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { EmojiView.this.onPageScrolled(position, getMeasuredWidth() - getPaddingLeft() - getPaddingRight(), positionOffsetPixels); } @Override public void onPageSelected(int position) { saveNewPage(); } @Override public void onPageScrollStateChanged(int state) { } }); FrameLayout frameLayout = new FrameLayout(context); emojiTab.addView(frameLayout, LayoutHelper.createLinear(52, 48)); backspaceButton = new ImageView(context) { @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { backspacePressed = true; backspaceOnce = false; postBackspaceRunnable(350); } else if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) { backspacePressed = false; if (!backspaceOnce) { if (listener != null && listener.onBackspace()) { backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); } } } super.onTouchEvent(event); return true; } }; backspaceButton.setImageResource(kr.wdream.storyshop.R.drawable.ic_smiles_backspace); backspaceButton.setBackgroundResource(kr.wdream.storyshop.R.drawable.ic_emoji_backspace); backspaceButton.setScaleType(ImageView.ScaleType.CENTER); frameLayout.addView(backspaceButton, LayoutHelper.createFrame(52, 48)); View view = new View(context); view.setBackgroundColor(0xffe2e5e7); frameLayout.addView(view, LayoutHelper.createFrame(52, 1, Gravity.LEFT | Gravity.BOTTOM)); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoRecent", kr.wdream.storyshop.R.string.NoRecent)); textView.setTextSize(18); textView.setTextColor(0xff888888); textView.setGravity(Gravity.CENTER); textView.setClickable(false); textView.setFocusable(false); ((FrameLayout) views.get(0)).addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 48, 0, 0)); emojiGrids.get(0).setEmptyView(textView); addView(pager, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP)); emojiSize = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 40 : 32); pickerView = new EmojiColorPickerView(context); pickerViewPopup = new EmojiPopupWindow(pickerView, popupWidth = AndroidUtilities.dp((AndroidUtilities.isTablet() ? 40 : 32) * 6 + 10 + 4 * 5), popupHeight = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 64 : 56)); pickerViewPopup.setOutsideTouchable(true); pickerViewPopup.setClippingEnabled(true); pickerViewPopup.setInputMethodMode(EmojiPopupWindow.INPUT_METHOD_NOT_NEEDED); pickerViewPopup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED); pickerViewPopup.getContentView().setFocusableInTouchMode(true); pickerViewPopup.getContentView().setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_UP && pickerViewPopup != null && pickerViewPopup.isShowing()) { pickerViewPopup.dismiss(); return true; } return false; } }); currentPage = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE).getInt("selected_page", 0); loadRecents(); }
From source file:net.granoeste.scaffold.app.ScaffoldWebViewFragment.java
@SuppressLint("SetJavaScriptEnabled") @Override//from w w w .j av a2 s . c om public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); FrameLayout root = new FrameLayout(getActivity()); // ------------------ // Progress content // ------------------ mPFrame = new LinearLayout(getActivity()); mPFrame.setId(INTERNAL_PROGRESS_CONTAINER_ID); mPFrame.setOrientation(LinearLayout.VERTICAL); mPFrame.setGravity(Gravity.CENTER); ProgressBar progress = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge); mPFrame.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); // ---------------- // WebView content // ---------------- mCFrame = new FrameLayout(getActivity()); mCFrame.setId(INTERNAL_CONTENT_CONTAINER_ID); mWebView = new InternalWebView(getActivity()); mWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); mWebView.getSettings().setJavaScriptEnabled(true); // Flash Support if (UIUtils.hasKitkat()) { // Flash(4.4?????) } else if (UIUtils.hasJellyBeanMr2()) { mWebView.getSettings().setPluginState(WebSettings.PluginState.ON); } else if (UIUtils.hasFroyo()) { // Deprecated Since API level 9, and removed in API level 18 (JellyBeanMr2) // mWebView.getSettings().setPluginEnabled(true); } // mWebView.getSettings().setVerticalScrollbarOverlay(true); mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); // ? mWebView.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setType(mimetype); intent.setData(Uri.parse(url)); startActivity(intent); } }); mWebView.setWebViewClient(new InternalWebViewClient(root, mCallbacks)); mCFrame.addView(mWebView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // ------------------------------------------------------------------ root.addView(mCFrame, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); root.addView(mPFrame, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); return root; }
From source file:org.telegram.ui.DialogsActivity.java
@Override public View createView(final Context context) { searching = false;/*from w ww. jav a 2 s .co m*/ searchWas = false; AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { Theme.loadRecources(context); } }); ActionBarMenu menu = actionBar.createMenu(); if (!onlySelect && searchString == null) { passcodeItem = menu.addItem(1, R.drawable.lock_close); updatePasscodeButton(); } final ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override public void onSearchExpand() { searching = true; if (listView != null) { if (searchString != null) { listView.setEmptyView(searchEmptyView); progressView.setVisibility(View.GONE); emptyView.setVisibility(View.GONE); } if (!onlySelect) { floatingButton.setVisibility(View.GONE); } } updatePasscodeButton(); } @Override public boolean canCollapseSearch() { if (searchString != null) { finishFragment(); return false; } return true; } @Override public void onSearchCollapse() { searching = false; searchWas = false; if (listView != null) { searchEmptyView.setVisibility(View.GONE); if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) { emptyView.setVisibility(View.GONE); listView.setEmptyView(progressView); } else { progressView.setVisibility(View.GONE); listView.setEmptyView(emptyView); } if (!onlySelect) { floatingButton.setVisibility(View.VISIBLE); floatingHidden = true; floatingButton.setTranslationY(AndroidUtilities.dp(100)); hideFloatingButton(false); } if (listView.getAdapter() != dialogsAdapter) { listView.setAdapter(dialogsAdapter); dialogsAdapter.notifyDataSetChanged(); } } if (dialogsSearchAdapter != null) { dialogsSearchAdapter.searchDialogs(null); } updatePasscodeButton(); } @Override public void onTextChanged(EditText editText) { String text = editText.getText().toString(); if (text.length() != 0 || dialogsSearchAdapter != null && dialogsSearchAdapter.hasRecentRearch()) { searchWas = true; if (dialogsSearchAdapter != null && listView.getAdapter() != dialogsSearchAdapter) { listView.setAdapter(dialogsSearchAdapter); dialogsSearchAdapter.notifyDataSetChanged(); } if (searchEmptyView != null && listView.getEmptyView() != searchEmptyView) { emptyView.setVisibility(View.GONE); progressView.setVisibility(View.GONE); searchEmptyView.showTextView(); listView.setEmptyView(searchEmptyView); } } if (dialogsSearchAdapter != null) { dialogsSearchAdapter.searchDialogs(text); } } }); item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search)); if (onlySelect) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setTitle(LocaleController.getString("SelectChat", R.string.SelectChat)); } else { if (searchString != null) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); } else { actionBar.setBackButtonDrawable(new MenuDrawable()); } if (BuildVars.DEBUG_VERSION) { actionBar.setTitle(LocaleController.getString("AppNameBeta", R.string.AppNameBeta)); } else { actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName)); } } actionBar.setAllowOverlayTitle(true); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { if (onlySelect) { finishFragment(); } else if (parentLayout != null) { parentLayout.getDrawerLayoutContainer().openDrawer(false); } } else if (id == 1) { UserConfig.appLocked = !UserConfig.appLocked; UserConfig.saveConfig(false); updatePasscodeButton(); } } }); FrameLayout frameLayout = new FrameLayout(context); fragmentView = frameLayout; fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.chat_list_background)); listView = new RecyclerListView(context); listView.setVerticalScrollBarEnabled(true); listView.setItemAnimator(null); listView.setInstantClick(true); listView.setLayoutAnimation(null); listView.setTag(4); layoutManager = new LinearLayoutManager(context) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }; layoutManager.setOrientation(LinearLayoutManager.VERTICAL); listView.setLayoutManager(layoutManager); listView.setVerticalScrollbarPosition( LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT); frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (listView == null || listView.getAdapter() == null) { return; } long dialog_id = 0; int message_id = 0; RecyclerView.Adapter adapter = listView.getAdapter(); if (adapter == dialogsAdapter) { TLRPC.TL_dialog dialog = dialogsAdapter.getItem(position); if (dialog == null) { return; } dialog_id = dialog.id; } else if (adapter == dialogsSearchAdapter) { Object obj = dialogsSearchAdapter.getItem(position); if (obj instanceof TLRPC.User) { dialog_id = ((TLRPC.User) obj).id; if (dialogsSearchAdapter.isGlobalSearch(position)) { ArrayList<TLRPC.User> users = new ArrayList<>(); users.add((TLRPC.User) obj); MessagesController.getInstance().putUsers(users, false); MessagesStorage.getInstance().putUsersAndChats(users, null, false, true); } if (!onlySelect) { dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.User) obj); } } else if (obj instanceof TLRPC.Chat) { if (dialogsSearchAdapter.isGlobalSearch(position)) { ArrayList<TLRPC.Chat> chats = new ArrayList<>(); chats.add((TLRPC.Chat) obj); MessagesController.getInstance().putChats(chats, false); MessagesStorage.getInstance().putUsersAndChats(null, chats, false, true); } if (((TLRPC.Chat) obj).id > 0) { dialog_id = -((TLRPC.Chat) obj).id; } else { dialog_id = AndroidUtilities.makeBroadcastId(((TLRPC.Chat) obj).id); } if (!onlySelect) { dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.Chat) obj); } } else if (obj instanceof TLRPC.EncryptedChat) { dialog_id = ((long) ((TLRPC.EncryptedChat) obj).id) << 32; if (!onlySelect) { dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.EncryptedChat) obj); } } else if (obj instanceof MessageObject) { MessageObject messageObject = (MessageObject) obj; dialog_id = messageObject.getDialogId(); message_id = messageObject.getId(); dialogsSearchAdapter.addHashtagsFromMessage(dialogsSearchAdapter.getLastSearchString()); } else if (obj instanceof String) { actionBar.openSearchField((String) obj); } } if (dialog_id == 0) { return; } if (onlySelect) { didSelectResult(dialog_id, true, false); } else { Bundle args = new Bundle(); int lower_part = (int) dialog_id; int high_id = (int) (dialog_id >> 32); if (lower_part != 0) { if (high_id == 1) { args.putInt("chat_id", lower_part); } else { if (lower_part > 0) { args.putInt("user_id", lower_part); } else if (lower_part < 0) { if (message_id != 0) { TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_part); if (chat != null && chat.migrated_to != null) { args.putInt("migrated_to", lower_part); lower_part = -chat.migrated_to.channel_id; } } args.putInt("chat_id", -lower_part); } } } else { args.putInt("enc_id", high_id); } if (message_id != 0) { args.putInt("message_id", message_id); } else { if (actionBar != null) { actionBar.closeSearchField(); } } if (AndroidUtilities.isTablet()) { if (openedDialogId == dialog_id && adapter != dialogsSearchAdapter) { return; } if (dialogsAdapter != null) { dialogsAdapter.setOpenedDialogId(openedDialogId = dialog_id); updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG); } } if (searchString != null) { if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) { NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); presentFragment(new ChatActivity(args)); } } else { if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) { presentFragment(new ChatActivity(args)); } } } } }); listView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() { @Override public boolean onItemClick(View view, int position) { if (onlySelect || searching && searchWas || getParentActivity() == null) { if (searchWas && searching || dialogsSearchAdapter.isRecentSearchDisplayed()) { RecyclerView.Adapter adapter = listView.getAdapter(); if (adapter == dialogsSearchAdapter) { Object item = dialogsSearchAdapter.getItem(position); if (item instanceof String || dialogsSearchAdapter.isRecentSearchDisplayed()) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch)); builder.setPositiveButton(LocaleController .getString("ClearButton", R.string.ClearButton).toUpperCase(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (dialogsSearchAdapter.isRecentSearchDisplayed()) { dialogsSearchAdapter.clearRecentSearch(); } else { dialogsSearchAdapter.clearRecentHashtags(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); return true; } } } return false; } TLRPC.TL_dialog dialog; ArrayList<TLRPC.TL_dialog> dialogs = getDialogsArray(); if (position < 0 || position >= dialogs.size()) { return false; } dialog = dialogs.get(position); selectedDialog = dialog.id; BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity()); int lower_id = (int) selectedDialog; int high_id = (int) (selectedDialog >> 32); if (DialogObject.isChannel(dialog)) { final TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_id); CharSequence items[]; if (chat != null && chat.megagroup) { items = new CharSequence[] { LocaleController.getString("ClearHistoryCache", R.string.ClearHistoryCache), chat == null || !chat.creator ? LocaleController.getString("LeaveMegaMenu", R.string.LeaveMegaMenu) : LocaleController.getString("DeleteMegaMenu", R.string.DeleteMegaMenu) }; } else { items = new CharSequence[] { LocaleController.getString("ClearHistoryCache", R.string.ClearHistoryCache), chat == null || !chat.creator ? LocaleController.getString("LeaveChannelMenu", R.string.LeaveChannelMenu) : LocaleController.getString("ChannelDeleteMenu", R.string.ChannelDeleteMenu) }; } builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, final int which) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); if (which == 0) { if (chat != null && chat.megagroup) { builder.setMessage(LocaleController.getString("AreYouSureClearHistorySuper", R.string.AreYouSureClearHistorySuper)); } else { builder.setMessage(LocaleController.getString("AreYouSureClearHistoryChannel", R.string.AreYouSureClearHistoryChannel)); } builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().deleteDialog(selectedDialog, 2); } }); } else { if (chat != null && chat.megagroup) { if (!chat.creator) { builder.setMessage(LocaleController.getString("MegaLeaveAlert", R.string.MegaLeaveAlert)); } else { builder.setMessage(LocaleController.getString("MegaDeleteAlert", R.string.MegaDeleteAlert)); } } else { if (chat == null || !chat.creator) { builder.setMessage(LocaleController.getString("ChannelLeaveAlert", R.string.ChannelLeaveAlert)); } else { builder.setMessage(LocaleController.getString("ChannelDeleteAlert", R.string.ChannelDeleteAlert)); } } builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().deleteUserFromChat( (int) -selectedDialog, UserConfig.getCurrentUser(), null); if (AndroidUtilities.isTablet()) { NotificationCenter.getInstance().postNotificationName( NotificationCenter.closeChats, selectedDialog); } } }); } builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } }); showDialog(builder.create()); } else { final boolean isChat = lower_id < 0 && high_id != 1; TLRPC.User user = null; if (!isChat && lower_id > 0 && high_id != 1) { user = MessagesController.getInstance().getUser(lower_id); } final boolean isBot = user != null && user.bot; builder.setItems( new CharSequence[] { LocaleController.getString("ClearHistory", R.string.ClearHistory), isChat ? LocaleController.getString("DeleteChat", R.string.DeleteChat) : isBot ? LocaleController.getString("DeleteAndStop", R.string.DeleteAndStop) : LocaleController.getString("Delete", R.string.Delete) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, final int which) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); if (which == 0) { builder.setMessage(LocaleController.getString("AreYouSureClearHistory", R.string.AreYouSureClearHistory)); } else { if (isChat) { builder.setMessage(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit)); } else { builder.setMessage(LocaleController.getString( "AreYouSureDeleteThisChat", R.string.AreYouSureDeleteThisChat)); } } builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (which != 0) { if (isChat) { TLRPC.Chat currentChat = MessagesController .getInstance().getChat((int) -selectedDialog); if (currentChat != null && ChatObject.isNotInChat(currentChat)) { MessagesController.getInstance() .deleteDialog(selectedDialog, 0); } else { MessagesController.getInstance().deleteUserFromChat( (int) -selectedDialog, MessagesController.getInstance().getUser( UserConfig.getClientUserId()), null); } } else { MessagesController.getInstance() .deleteDialog(selectedDialog, 0); } if (isBot) { MessagesController.getInstance() .blockUser((int) selectedDialog); } if (AndroidUtilities.isTablet()) { NotificationCenter.getInstance().postNotificationName( NotificationCenter.closeChats, selectedDialog); } } else { MessagesController.getInstance() .deleteDialog(selectedDialog, 1); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } }); showDialog(builder.create()); } return true; } }); searchEmptyView = new EmptyTextProgressView(context); searchEmptyView.setVisibility(View.GONE); searchEmptyView.setShowAtCenter(true); searchEmptyView.setText(LocaleController.getString("NoResult", R.string.NoResult)); frameLayout.addView(searchEmptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); emptyView = new LinearLayout(context); emptyView.setOrientation(LinearLayout.VERTICAL); emptyView.setVisibility(View.GONE); emptyView.setGravity(Gravity.CENTER); frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); emptyView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoChats", R.string.NoChats)); textView.setTextColor(0xff959595); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); emptyView.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT)); textView = new TextView(context); String help = LocaleController.getString("NoChatsHelp", R.string.NoChatsHelp); if (AndroidUtilities.isTablet() && !AndroidUtilities.isSmallTablet()) { help = help.replace('\n', ' '); } textView.setText(help); textView.setTextColor(0xff959595); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); textView.setGravity(Gravity.CENTER); textView.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(6), AndroidUtilities.dp(8), 0); textView.setLineSpacing(AndroidUtilities.dp(2), 1); emptyView.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT)); progressView = new ProgressBar(context); progressView.setVisibility(View.GONE); frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); // TODO fab color floatingButton = new FloatingActionButton(context); floatingButton.setVisibility(onlySelect ? View.GONE : View.VISIBLE); //floatingButton.setScaleType(ImageView.ScaleType.CENTER); //floatingButton.setBackgroundResource(R.drawable.floating_states); floatingButton.setImageResource(R.drawable.floating_pencil); floatingButton.getDrawable().setTint(ContextCompat.getColor(context, R.color.fab)); 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(56, 56, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14)); floatingButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle args = new Bundle(); args.putBoolean("destroyAfterSelect", true); presentFragment(new ContactsActivity(args)); } }); listView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_DRAGGING && searching && searchWas) { AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus()); } } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { int firstVisibleItem = layoutManager.findFirstVisibleItemPosition(); int visibleItemCount = Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1; int totalItemCount = recyclerView.getAdapter().getItemCount(); if (searching && searchWas) { if (visibleItemCount > 0 && layoutManager.findLastVisibleItemPosition() == totalItemCount - 1 && !dialogsSearchAdapter.isMessagesSearchEndReached()) { dialogsSearchAdapter.loadMoreSearchMessages(); } return; } if (visibleItemCount > 0) { if (layoutManager.findLastVisibleItemPosition() >= getDialogsArray().size() - 10) { MessagesController.getInstance().loadDialogs(-1, 100, !MessagesController.getInstance().dialogsEndReached); } } 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 (searchString == null) { dialogsAdapter = new DialogsAdapter(context, dialogsType); if (AndroidUtilities.isTablet() && openedDialogId != 0) { dialogsAdapter.setOpenedDialogId(openedDialogId); } listView.setAdapter(dialogsAdapter); } int type = 0; if (searchString != null) { type = 2; } else if (!onlySelect) { type = 1; } dialogsSearchAdapter = new DialogsSearchAdapter(context, type, dialogsType); dialogsSearchAdapter.setDelegate(new DialogsSearchAdapter.DialogsSearchAdapterDelegate() { @Override public void searchStateChanged(boolean search) { if (searching && searchWas && searchEmptyView != null) { if (search) { searchEmptyView.showProgress(); } else { searchEmptyView.showTextView(); } } } @Override public void didPressedOnSubDialog(int did) { if (onlySelect) { didSelectResult(did, true, false); } else { Bundle args = new Bundle(); if (did > 0) { args.putInt("user_id", did); } else { args.putInt("chat_id", -did); } if (actionBar != null) { actionBar.closeSearchField(); } if (AndroidUtilities.isTablet()) { if (dialogsAdapter != null) { dialogsAdapter.setOpenedDialogId(openedDialogId = did); updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG); } } if (searchString != null) { if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) { NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); presentFragment(new ChatActivity(args)); } } else { if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) { presentFragment(new ChatActivity(args)); } } } } @Override public void needRemoveHint(final int did) { if (getParentActivity() == null) { return; } TLRPC.User user = MessagesController.getInstance().getUser(did); if (user == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.formatString("ChatHintsDelete", R.string.ChatHintsDelete, ContactsController.formatName(user.first_name, user.last_name))); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { SearchQuery.removePeer(did); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } }); if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) { searchEmptyView.setVisibility(View.GONE); emptyView.setVisibility(View.GONE); listView.setEmptyView(progressView); } else { searchEmptyView.setVisibility(View.GONE); progressView.setVisibility(View.GONE); listView.setEmptyView(emptyView); } if (searchString != null) { actionBar.openSearchField(searchString); } if (!onlySelect && dialogsType == 0) { frameLayout.addView(new PlayerView(context, this), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 39, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0)); } return fragmentView; }
From source file:org.telegraph.ui.Components.EmojiView.java
public EmojiView(boolean needStickers, Context context) { super(context); showStickers = needStickers;//from w w w. ja va2 s. co m for (int i = 0; i < Emoji.data.length + 1; i++) { GridView gridView = new GridView(context); if (AndroidUtilities.isTablet()) { gridView.setColumnWidth(AndroidUtilities.dp(60)); } else { gridView.setColumnWidth(AndroidUtilities.dp(45)); } gridView.setNumColumns(-1); views.add(gridView); EmojiGridAdapter emojiGridAdapter = new EmojiGridAdapter(i - 1); gridView.setAdapter(emojiGridAdapter); AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7); adapters.add(emojiGridAdapter); } if (showStickers) { StickersQuery.checkStickers(); stickersGridView = new GridView(context) { @Override public boolean onInterceptTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { int x = (int) event.getX(); int y = (int) event.getY(); int count = stickersGridView.getChildCount(); for (int a = 0; a < count; a++) { View view = stickersGridView.getChildAt(a); int top = view.getTop(); int bottom = view.getBottom(); int left = view.getLeft(); int right = view.getRight(); if (top > y || bottom < y || left > x || right < x) { continue; } if (!(view instanceof StickerEmojiCell) || !((StickerEmojiCell) view).showingBitmap()) { return super.onInterceptTouchEvent(event); } startX = x; startY = y; currentStickerPreviewCell = (StickerEmojiCell) view; openStickerPreviewRunnable = new Runnable() { @Override public void run() { if (openStickerPreviewRunnable == null) { return; } stickersGridView.setOnItemClickListener(null); stickersGridView.requestDisallowInterceptTouchEvent(true); openStickerPreviewRunnable = null; StickerPreviewViewer.getInstance().setParentActivity((Activity) getContext()); StickerPreviewViewer.getInstance() .setKeyboardHeight(EmojiView.this.getMeasuredHeight()); StickerPreviewViewer.getInstance().open(currentStickerPreviewCell.getSticker()); currentStickerPreviewCell.setScaled(true); } }; AndroidUtilities.runOnUIThread(openStickerPreviewRunnable, 200); return true; } } return false; } }; stickersGridView.setSelector(R.drawable.transparent); stickersGridView.setColumnWidth(AndroidUtilities.dp(72)); stickersGridView.setNumColumns(-1); stickersGridView.setPadding(0, AndroidUtilities.dp(4), 0, 0); stickersGridView.setClipToPadding(false); views.add(stickersGridView); stickersGridAdapter = new StickersGridAdapter(context); stickersGridView.setAdapter(stickersGridAdapter); stickersGridView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (openStickerPreviewRunnable != null || StickerPreviewViewer.getInstance().isVisible()) { if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_POINTER_UP) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { stickersGridView.setOnItemClickListener(stickersOnItemClickListener); } }, 150); if (openStickerPreviewRunnable != null) { AndroidUtilities.cancelRunOnUIThread(openStickerPreviewRunnable); openStickerPreviewRunnable = null; } else if (StickerPreviewViewer.getInstance().isVisible()) { StickerPreviewViewer.getInstance().close(); if (currentStickerPreviewCell != null) { currentStickerPreviewCell.setScaled(false); currentStickerPreviewCell = null; } } } else if (event.getAction() != MotionEvent.ACTION_DOWN) { if (StickerPreviewViewer.getInstance().isVisible()) { if (event.getAction() == MotionEvent.ACTION_MOVE) { int x = (int) event.getX(); int y = (int) event.getY(); int count = stickersGridView.getChildCount(); for (int a = 0; a < count; a++) { View view = stickersGridView.getChildAt(a); int top = view.getTop(); int bottom = view.getBottom(); int left = view.getLeft(); int right = view.getRight(); if (top > y || bottom < y || left > x || right < x) { continue; } if (!(view instanceof StickerEmojiCell) || view == currentStickerPreviewCell) { break; } if (currentStickerPreviewCell != null) { currentStickerPreviewCell.setScaled(false); } currentStickerPreviewCell = (StickerEmojiCell) view; StickerPreviewViewer.getInstance() .setKeyboardHeight(EmojiView.this.getMeasuredHeight()); StickerPreviewViewer.getInstance() .open(currentStickerPreviewCell.getSticker()); currentStickerPreviewCell.setScaled(true); return true; } } return true; } else if (openStickerPreviewRunnable != null) { if (event.getAction() == MotionEvent.ACTION_MOVE) { if (Math.hypot(startX - event.getX(), startY - event.getY()) > AndroidUtilities .dp(10)) { AndroidUtilities.cancelRunOnUIThread(openStickerPreviewRunnable); openStickerPreviewRunnable = null; } } else { AndroidUtilities.cancelRunOnUIThread(openStickerPreviewRunnable); openStickerPreviewRunnable = null; } } } } return false; } }); stickersOnItemClickListener = new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long i) { if (!(view instanceof StickerEmojiCell)) { return; } if (openStickerPreviewRunnable != null) { AndroidUtilities.cancelRunOnUIThread(openStickerPreviewRunnable); openStickerPreviewRunnable = null; } if (currentStickerPreviewCell != null) { currentStickerPreviewCell.setScaled(false); currentStickerPreviewCell = null; } StickerEmojiCell cell = (StickerEmojiCell) view; if (cell.isDisabled()) { return; } cell.disable(); TLRPC.Document document = cell.getSticker(); Integer count = stickersUseHistory.get(document.id); if (count == null) { count = 0; } if (count == 0 && stickersUseHistory.size() > 19) { for (int a = recentStickers.size() - 1; a >= 0; a--) { TLRPC.Document sticker = recentStickers.get(a); stickersUseHistory.remove(sticker.id); recentStickers.remove(a); if (stickersUseHistory.size() <= 19) { break; } } } stickersUseHistory.put(document.id, ++count); long id = StickersQuery.getStickerSetId(document); if (id != -1) { count = stickerSetsUseCount.get(id); if (count == null) { count = 0; } stickerSetsUseCount.put(id, ++count); } saveRecentStickers(); if (listener != null) { listener.onStickerSelected(document); } } }; stickersGridView.setOnItemClickListener(stickersOnItemClickListener); AndroidUtilities.setListViewEdgeEffectColor(stickersGridView, 0xfff5f6f7); stickersWrap = new FrameLayout(context); stickersWrap.addView(stickersGridView); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoStickers", R.string.NoStickers)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); textView.setTextColor(0xff888888); stickersWrap.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); stickersGridView.setEmptyView(textView); scrollSlidingTabStrip = new ScrollSlidingTabStrip(context) { boolean startedScroll; float lastX; float lastTranslateX; boolean first = true; @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent ev) { if (Build.VERSION.SDK_INT >= 11) { if (first) { first = false; lastX = ev.getX(); } float newTranslationX = ViewProxy.getTranslationX(scrollSlidingTabStrip); if (scrollSlidingTabStrip.getScrollX() == 0 && newTranslationX == 0) { if (!startedScroll && lastX - ev.getX() < 0) { if (pager.beginFakeDrag()) { startedScroll = true; lastTranslateX = ViewProxy.getTranslationX(scrollSlidingTabStrip); } } else if (startedScroll && lastX - ev.getX() > 0) { if (pager.isFakeDragging()) { pager.endFakeDrag(); startedScroll = false; } } } if (startedScroll) { int dx = (int) (ev.getX() - lastX + newTranslationX - lastTranslateX); try { pager.fakeDragBy(dx); lastTranslateX = newTranslationX; } catch (Exception e) { try { pager.endFakeDrag(); } catch (Exception e2) { //don't promt } startedScroll = false; FileLog.e("tmessages", e); } } lastX = ev.getX(); if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) { first = true; if (startedScroll) { pager.endFakeDrag(); startedScroll = false; } } return startedScroll || super.onTouchEvent(ev); } return super.onTouchEvent(ev); } }; scrollSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1)); scrollSlidingTabStrip.setIndicatorColor(0xffe2e5e7); scrollSlidingTabStrip.setUnderlineColor(0xffe2e5e7); scrollSlidingTabStrip.setVisibility(INVISIBLE); addView(scrollSlidingTabStrip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP)); ViewProxy.setTranslationX(scrollSlidingTabStrip, AndroidUtilities.displaySize.x); updateStickerTabs(); scrollSlidingTabStrip.setDelegate(new ScrollSlidingTabStrip.ScrollSlidingTabStripDelegate() { @Override public void onPageSelected(int page) { if (page == 0) { pager.setCurrentItem(0); return; } else if (page == 1 && !recentStickers.isEmpty()) { views.get(6).setSelection(0); return; } int index = page - (recentStickers.isEmpty() ? 1 : 2); if (index >= stickerSets.size()) { index = stickerSets.size() - 1; } views.get(6).setSelection(stickersGridAdapter.getPositionForPack(stickerSets.get(index))); } }); stickersGridView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { int count = view.getChildCount(); for (int a = 0; a < count; a++) { View child = view.getChildAt(a); if (child.getHeight() + child.getTop() < AndroidUtilities.dp(5)) { firstVisibleItem++; } else { break; } } scrollSlidingTabStrip .onPageScrolled(stickersGridAdapter.getTabForPosition(firstVisibleItem) + 1, 0); } }); } setBackgroundColor(0xfff5f6f7); pager = new ViewPager(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; pager.setAdapter(new EmojiPagesAdapter()); pagerSlidingTabStripContainer = new LinearLayout(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; pagerSlidingTabStripContainer.setOrientation(LinearLayout.HORIZONTAL); pagerSlidingTabStripContainer.setBackgroundColor(0xfff5f6f7); addView(pagerSlidingTabStripContainer, LayoutHelper.createFrame(LayoutParams.MATCH_PARENT, 48)); PagerSlidingTabStrip pagerSlidingTabStrip = new PagerSlidingTabStrip(context); pagerSlidingTabStrip.setViewPager(pager); pagerSlidingTabStrip.setShouldExpand(true); pagerSlidingTabStrip.setIndicatorHeight(AndroidUtilities.dp(2)); pagerSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1)); pagerSlidingTabStrip.setIndicatorColor(0xff2b96e2); pagerSlidingTabStrip.setUnderlineColor(0xffe2e5e7); pagerSlidingTabStripContainer.addView(pagerSlidingTabStrip, LayoutHelper.createLinear(0, 48, 1.0f)); pagerSlidingTabStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { EmojiView.this.onPageScrolled(position, getMeasuredWidth(), positionOffsetPixels); } @Override public void onPageSelected(int position) { } @Override public void onPageScrollStateChanged(int state) { } }); FrameLayout frameLayout = new FrameLayout(context); pagerSlidingTabStripContainer.addView(frameLayout, LayoutHelper.createLinear(52, 48)); backspaceButton = new ImageView(context) { @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { backspacePressed = true; backspaceOnce = false; postBackspaceRunnable(350); } else if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) { backspacePressed = false; if (!backspaceOnce) { if (listener != null && listener.onBackspace()) { backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); } } } super.onTouchEvent(event); return true; } }; backspaceButton.setImageResource(R.drawable.ic_smiles_backspace); backspaceButton.setBackgroundResource(R.drawable.ic_emoji_backspace); backspaceButton.setScaleType(ImageView.ScaleType.CENTER); frameLayout.addView(backspaceButton, LayoutHelper.createFrame(52, 48)); View view = new View(context); view.setBackgroundColor(0xffe2e5e7); frameLayout.addView(view, LayoutHelper.createFrame(52, 1, Gravity.LEFT | Gravity.BOTTOM)); recentsWrap = new FrameLayout(context); recentsWrap.addView(views.get(0)); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoRecent", R.string.NoRecent)); textView.setTextSize(18); textView.setTextColor(0xff888888); textView.setGravity(Gravity.CENTER); recentsWrap.addView(textView); views.get(0).setEmptyView(textView); addView(pager, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 48, 0, 0)); loadRecents(); if (Emoji.data[0] == null || Emoji.data[0].length == 0) { pager.setCurrentItem(1); } }
From source file:org.telegram.ui.Components.AudioPlayerAlert.java
public AudioPlayerAlert(final Context context) { super(context, true); MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject(); if (messageObject != null) { currentAccount = messageObject.currentAccount; } else {//from w w w . ja va 2s.c om currentAccount = UserConfig.selectedAccount; } parentActivity = (LaunchActivity) context; noCoverDrawable = context.getResources().getDrawable(R.drawable.nocover).mutate(); noCoverDrawable.setColorFilter( new PorterDuffColorFilter(Theme.getColor(Theme.key_player_placeholder), PorterDuff.Mode.MULTIPLY)); TAG = DownloadController.getInstance(currentAccount).generateObserverTag(); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidReset); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingPlayStateChanged); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidStart); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingProgressDidChanged); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.musicDidLoad); shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow).mutate(); shadowDrawable.setColorFilter( new PorterDuffColorFilter(Theme.getColor(Theme.key_player_background), PorterDuff.Mode.MULTIPLY)); paint.setColor(Theme.getColor(Theme.key_player_placeholderBackground)); containerView = new FrameLayout(context) { private boolean ignoreLayout = false; @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0 && ev.getY() < scrollOffsetY && placeholderImageView.getTranslationX() == 0) { dismiss(); return true; } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent e) { return !isDismissed() && super.onTouchEvent(e); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height = MeasureSpec.getSize(heightMeasureSpec); int contentSize = AndroidUtilities.dp(178) + playlist.size() * AndroidUtilities.dp(56) + backgroundPaddingTop + ActionBar.getCurrentActionBarHeight() + AndroidUtilities.statusBarHeight; int padding; heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (searching) { padding = AndroidUtilities.dp(178) + ActionBar.getCurrentActionBarHeight() + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0); } else { if (contentSize < height) { padding = height - contentSize; } else { padding = (contentSize < height ? 0 : height - (height / 5 * 3)); } padding += ActionBar.getCurrentActionBarHeight() + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0); } if (listView.getPaddingTop() != padding) { ignoreLayout = true; listView.setPadding(0, padding, 0, AndroidUtilities.dp(8)); ignoreLayout = false; } super.onMeasure(widthMeasureSpec, heightMeasureSpec); inFullSize = getMeasuredHeight() >= height; int availableHeight = height - ActionBar.getCurrentActionBarHeight() - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0) - AndroidUtilities.dp(120); int maxSize = Math.max(availableHeight, getMeasuredWidth()); thumbMaxX = (getMeasuredWidth() - maxSize) / 2 - AndroidUtilities.dp(17); thumbMaxY = AndroidUtilities.dp(19); panelEndTranslation = getMeasuredHeight() - playerLayout.getMeasuredHeight(); thumbMaxScale = maxSize / (float) placeholderImageView.getMeasuredWidth() - 1.0f; endTranslation = ActionBar.getCurrentActionBarHeight() + AndroidUtilities.dp(5); int scaledHeight = (int) Math .ceil(placeholderImageView.getMeasuredHeight() * (1.0f + thumbMaxScale)); if (scaledHeight > availableHeight) { endTranslation -= (scaledHeight - availableHeight); } } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); int y = actionBar.getMeasuredHeight(); shadow.layout(shadow.getLeft(), y, shadow.getRight(), y + shadow.getMeasuredHeight()); updateLayout(); setFullAnimationProgress(fullAnimationProgress); } @Override public void requestLayout() { if (ignoreLayout) { return; } super.requestLayout(); } @Override protected void onDraw(Canvas canvas) { shadowDrawable.setBounds(0, Math.max(actionBar.getMeasuredHeight(), scrollOffsetY) - backgroundPaddingTop, getMeasuredWidth(), getMeasuredHeight()); shadowDrawable.draw(canvas); } }; containerView.setWillNotDraw(false); containerView.setPadding(backgroundPaddingLeft, 0, backgroundPaddingLeft, 0); actionBar = new ActionBar(context); actionBar.setBackgroundColor(Theme.getColor(Theme.key_player_actionBar)); actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setItemsColor(Theme.getColor(Theme.key_player_actionBarItems), false); actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_player_actionBarSelector), false); actionBar.setTitleColor(Theme.getColor(Theme.key_player_actionBarTitle)); actionBar.setSubtitleColor(Theme.getColor(Theme.key_player_actionBarSubtitle)); actionBar.setAlpha(0.0f); actionBar.setTitle("1"); actionBar.setSubtitle("1"); actionBar.getTitleTextView().setAlpha(0.0f); actionBar.getSubtitleTextView().setAlpha(0.0f); avatarContainer = new ChatAvatarContainer(context, null, false); avatarContainer.setEnabled(false); avatarContainer.setTitleColors(Theme.getColor(Theme.key_player_actionBarTitle), Theme.getColor(Theme.key_player_actionBarSubtitle)); if (messageObject != null) { long did = messageObject.getDialogId(); int lower_id = (int) did; int high_id = (int) (did >> 32); if (lower_id != 0) { if (lower_id > 0) { TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(lower_id); if (user != null) { avatarContainer.setTitle(ContactsController.formatName(user.first_name, user.last_name)); avatarContainer.setUserAvatar(user); } } else { TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_id); if (chat != null) { avatarContainer.setTitle(chat.title); avatarContainer.setChatAvatar(chat); } } } else { TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance(currentAccount) .getEncryptedChat(high_id); if (encryptedChat != null) { TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(encryptedChat.user_id); if (user != null) { avatarContainer.setTitle(ContactsController.formatName(user.first_name, user.last_name)); avatarContainer.setUserAvatar(user); } } } } avatarContainer.setSubtitle(LocaleController.getString("AudioTitle", R.string.AudioTitle)); actionBar.addView(avatarContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 56, 0, 40, 0)); ActionBarMenu menu = actionBar.createMenu(); menuItem = menu.addItem(0, R.drawable.ic_ab_other); menuItem.addSubItem(1, LocaleController.getString("Forward", R.string.Forward)); menuItem.addSubItem(2, LocaleController.getString("ShareFile", R.string.ShareFile)); //menuItem.addSubItem(3, LocaleController.getString("Delete", R.string.Delete)); menuItem.addSubItem(4, LocaleController.getString("ShowInChat", R.string.ShowInChat)); menuItem.setTranslationX(AndroidUtilities.dp(48)); menuItem.setAlpha(0.0f); searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override public void onSearchCollapse() { avatarContainer.setVisibility(View.VISIBLE); if (hasOptions) { menuItem.setVisibility(View.INVISIBLE); } if (searching) { searchWas = false; searching = false; setAllowNestedScroll(true); listAdapter.search(null); } } @Override public void onSearchExpand() { searchOpenPosition = layoutManager.findLastVisibleItemPosition(); View firstVisView = layoutManager.findViewByPosition(searchOpenPosition); searchOpenOffset = ((firstVisView == null) ? 0 : firstVisView.getTop()) - listView.getPaddingTop(); avatarContainer.setVisibility(View.GONE); if (hasOptions) { menuItem.setVisibility(View.GONE); } searching = true; setAllowNestedScroll(false); listAdapter.notifyDataSetChanged(); } @Override public void onTextChanged(EditText editText) { if (editText.length() > 0) { listAdapter.search(editText.getText().toString()); } else { searchWas = false; listAdapter.search(null); } } }); EditTextBoldCursor editText = searchItem.getSearchField(); editText.setHint(LocaleController.getString("Search", R.string.Search)); editText.setTextColor(Theme.getColor(Theme.key_player_actionBarTitle)); editText.setHintTextColor(Theme.getColor(Theme.key_player_time)); editText.setCursorColor(Theme.getColor(Theme.key_player_actionBarTitle)); if (!AndroidUtilities.isTablet()) { actionBar.showActionModeTop(); actionBar.setActionModeTopColor(Theme.getColor(Theme.key_player_actionBarTop)); } actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { dismiss(); } else { onSubItemClick(id); } } }); shadow = new View(context); shadow.setAlpha(0.0f); shadow.setBackgroundResource(R.drawable.header_shadow); shadow2 = new View(context); shadow2.setAlpha(0.0f); shadow2.setBackgroundResource(R.drawable.header_shadow); playerLayout = new FrameLayout(context); playerLayout.setBackgroundColor(Theme.getColor(Theme.key_player_background)); placeholderImageView = new BackupImageView(context) { private RectF rect = new RectF(); @Override protected void onDraw(Canvas canvas) { if (hasNoCover == 1 || hasNoCover == 2 && (!getImageReceiver().hasBitmapImage() || getImageReceiver().getCurrentAlpha() != 1.0f)) { rect.set(0, 0, getMeasuredWidth(), getMeasuredHeight()); canvas.drawRoundRect(rect, getRoundRadius(), getRoundRadius(), paint); float plusScale = thumbMaxScale / getScaleX() / 3; int s = (int) (AndroidUtilities.dp(63) * Math.max(plusScale / thumbMaxScale, 1.0f / thumbMaxScale)); int x = (int) (rect.centerX() - s / 2); int y = (int) (rect.centerY() - s / 2); noCoverDrawable.setBounds(x, y, x + s, y + s); noCoverDrawable.draw(canvas); } if (hasNoCover != 1) { super.onDraw(canvas); } } }; placeholderImageView.setRoundRadius(AndroidUtilities.dp(20)); placeholderImageView.setPivotX(0); placeholderImageView.setPivotY(0); placeholderImageView.setOnClickListener(view -> { if (animatorSet != null) { animatorSet.cancel(); animatorSet = null; } animatorSet = new AnimatorSet(); if (scrollOffsetY <= actionBar.getMeasuredHeight()) { animatorSet.playTogether(ObjectAnimator.ofFloat(AudioPlayerAlert.this, "fullAnimationProgress", isInFullMode ? 0.0f : 1.0f)); } else { animatorSet.playTogether( ObjectAnimator.ofFloat(AudioPlayerAlert.this, "fullAnimationProgress", isInFullMode ? 0.0f : 1.0f), ObjectAnimator.ofFloat(actionBar, "alpha", isInFullMode ? 0.0f : 1.0f), ObjectAnimator.ofFloat(shadow, "alpha", isInFullMode ? 0.0f : 1.0f), ObjectAnimator.ofFloat(shadow2, "alpha", isInFullMode ? 0.0f : 1.0f)); } animatorSet.setInterpolator(new DecelerateInterpolator()); animatorSet.setDuration(250); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (animation.equals(animatorSet)) { if (!isInFullMode) { listView.setScrollEnabled(true); if (hasOptions) { menuItem.setVisibility(View.INVISIBLE); } searchItem.setVisibility(View.VISIBLE); } else { if (hasOptions) { menuItem.setVisibility(View.VISIBLE); } searchItem.setVisibility(View.INVISIBLE); } animatorSet = null; } } }); animatorSet.start(); if (hasOptions) { menuItem.setVisibility(View.VISIBLE); } searchItem.setVisibility(View.VISIBLE); isInFullMode = !isInFullMode; listView.setScrollEnabled(false); if (isInFullMode) { shuffleButton.setAdditionalOffset(-AndroidUtilities.dp(20 + 48)); } else { shuffleButton.setAdditionalOffset(-AndroidUtilities.dp(10)); } }); titleTextView = new TextView(context); titleTextView.setTextColor(Theme.getColor(Theme.key_player_actionBarTitle)); titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); titleTextView.setEllipsize(TextUtils.TruncateAt.END); titleTextView.setSingleLine(true); playerLayout.addView(titleTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 72, 18, 60, 0)); authorTextView = new TextView(context); authorTextView.setTextColor(Theme.getColor(Theme.key_player_time)); authorTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); authorTextView.setEllipsize(TextUtils.TruncateAt.END); authorTextView.setSingleLine(true); playerLayout.addView(authorTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 72, 40, 60, 0)); optionsButton = new ActionBarMenuItem(context, null, 0, Theme.getColor(Theme.key_player_actionBarItems)); optionsButton.setLongClickEnabled(false); optionsButton.setIcon(R.drawable.ic_ab_other); optionsButton.setAdditionalOffset(-AndroidUtilities.dp(120)); playerLayout.addView(optionsButton, LayoutHelper.createFrame(40, 40, Gravity.TOP | Gravity.RIGHT, 0, 19, 10, 0)); optionsButton.addSubItem(1, LocaleController.getString("Forward", R.string.Forward)); optionsButton.addSubItem(2, LocaleController.getString("ShareFile", R.string.ShareFile)); //optionsButton.addSubItem(3, LocaleController.getString("Delete", R.string.Delete)); optionsButton.addSubItem(4, LocaleController.getString("ShowInChat", R.string.ShowInChat)); optionsButton.setOnClickListener(v -> optionsButton.toggleSubMenu()); optionsButton.setDelegate(this::onSubItemClick); seekBarView = new SeekBarView(context); seekBarView.setDelegate(progress -> MediaController.getInstance() .seekToProgress(MediaController.getInstance().getPlayingMessageObject(), progress)); playerLayout.addView(seekBarView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 30, Gravity.TOP | Gravity.LEFT, 8, 62, 8, 0)); progressView = new LineProgressView(context); progressView.setVisibility(View.INVISIBLE); progressView.setBackgroundColor(Theme.getColor(Theme.key_player_progressBackground)); progressView.setProgressColor(Theme.getColor(Theme.key_player_progress)); playerLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 2, Gravity.TOP | Gravity.LEFT, 20, 78, 20, 0)); timeTextView = new SimpleTextView(context); timeTextView.setTextSize(12); timeTextView.setText("0:00"); timeTextView.setTextColor(Theme.getColor(Theme.key_player_time)); playerLayout.addView(timeTextView, LayoutHelper.createFrame(100, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 20, 92, 0, 0)); durationTextView = new TextView(context); durationTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); durationTextView.setTextColor(Theme.getColor(Theme.key_player_time)); durationTextView.setGravity(Gravity.CENTER); playerLayout.addView(durationTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.RIGHT, 0, 90, 20, 0)); FrameLayout bottomView = new FrameLayout(context) { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int dist = ((right - left) - AndroidUtilities.dp(8 + 48 * 5)) / 4; for (int a = 0; a < 5; a++) { int l = AndroidUtilities.dp(4 + 48 * a) + dist * a; int t = AndroidUtilities.dp(9); buttons[a].layout(l, t, l + buttons[a].getMeasuredWidth(), t + buttons[a].getMeasuredHeight()); } } }; playerLayout.addView(bottomView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 66, Gravity.TOP | Gravity.LEFT, 0, 106, 0, 0)); buttons[0] = shuffleButton = new ActionBarMenuItem(context, null, 0, 0); shuffleButton.setLongClickEnabled(false); shuffleButton.setAdditionalOffset(-AndroidUtilities.dp(10)); bottomView.addView(shuffleButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP)); shuffleButton.setOnClickListener(v -> shuffleButton.toggleSubMenu()); TextView textView = shuffleButton.addSubItem(1, LocaleController.getString("ReverseOrder", R.string.ReverseOrder)); textView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(16), 0); playOrderButtons[0] = context.getResources().getDrawable(R.drawable.music_reverse).mutate(); textView.setCompoundDrawablePadding(AndroidUtilities.dp(8)); textView.setCompoundDrawablesWithIntrinsicBounds(playOrderButtons[0], null, null, null); textView = shuffleButton.addSubItem(2, LocaleController.getString("Shuffle", R.string.Shuffle)); textView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(16), 0); playOrderButtons[1] = context.getResources().getDrawable(R.drawable.pl_shuffle).mutate(); textView.setCompoundDrawablePadding(AndroidUtilities.dp(8)); textView.setCompoundDrawablesWithIntrinsicBounds(playOrderButtons[1], null, null, null); shuffleButton.setDelegate(id -> { MediaController.getInstance().toggleShuffleMusic(id); updateShuffleButton(); listAdapter.notifyDataSetChanged(); }); ImageView prevButton; buttons[1] = prevButton = new ImageView(context); prevButton.setScaleType(ImageView.ScaleType.CENTER); prevButton.setImageDrawable(Theme.createSimpleSelectorDrawable(context, R.drawable.pl_previous, Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive))); bottomView.addView(prevButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP)); prevButton.setOnClickListener(v -> MediaController.getInstance().playPreviousMessage()); buttons[2] = playButton = new ImageView(context); playButton.setScaleType(ImageView.ScaleType.CENTER); playButton.setImageDrawable(Theme.createSimpleSelectorDrawable(context, R.drawable.pl_play, Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive))); bottomView.addView(playButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP)); playButton.setOnClickListener(v -> { if (MediaController.getInstance().isDownloadingCurrentMessage()) { return; } if (MediaController.getInstance().isMessagePaused()) { MediaController.getInstance().playMessage(MediaController.getInstance().getPlayingMessageObject()); } else { MediaController.getInstance().pauseMessage(MediaController.getInstance().getPlayingMessageObject()); } }); ImageView nextButton; buttons[3] = nextButton = new ImageView(context); nextButton.setScaleType(ImageView.ScaleType.CENTER); nextButton.setImageDrawable(Theme.createSimpleSelectorDrawable(context, R.drawable.pl_next, Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive))); bottomView.addView(nextButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP)); nextButton.setOnClickListener(v -> MediaController.getInstance().playNextMessage()); buttons[4] = repeatButton = new ImageView(context); repeatButton.setScaleType(ImageView.ScaleType.CENTER); repeatButton.setPadding(0, 0, AndroidUtilities.dp(8), 0); bottomView.addView(repeatButton, LayoutHelper.createFrame(50, 48, Gravity.LEFT | Gravity.TOP)); repeatButton.setOnClickListener(v -> { SharedConfig.toggleRepeatMode(); updateRepeatButton(); }); listView = new RecyclerListView(context) { boolean ignoreLayout; @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); if (searchOpenPosition != -1 && !actionBar.isSearchFieldVisible()) { ignoreLayout = true; layoutManager.scrollToPositionWithOffset(searchOpenPosition, searchOpenOffset); super.onLayout(false, l, t, r, b); ignoreLayout = false; searchOpenPosition = -1; } else if (scrollToSong) { scrollToSong = false; boolean found = false; MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject(); if (playingMessageObject != null) { int count = listView.getChildCount(); for (int a = 0; a < count; a++) { View child = listView.getChildAt(a); if (child instanceof AudioPlayerCell) { if (((AudioPlayerCell) child).getMessageObject() == playingMessageObject) { if (child.getBottom() <= getMeasuredHeight()) { found = true; } break; } } } if (!found) { int idx = playlist.indexOf(playingMessageObject); if (idx >= 0) { ignoreLayout = true; if (SharedConfig.playOrderReversed) { layoutManager.scrollToPosition(idx); } else { layoutManager.scrollToPosition(playlist.size() - idx); } super.onLayout(false, l, t, r, b); ignoreLayout = false; } } } } } @Override public void requestLayout() { if (ignoreLayout) { return; } super.requestLayout(); } @Override protected boolean allowSelectChildAtPosition(float x, float y) { float p = playerLayout.getY() + playerLayout.getMeasuredHeight(); return playerLayout == null || y > playerLayout.getY() + playerLayout.getMeasuredHeight(); } @Override public boolean drawChild(Canvas canvas, View child, long drawingTime) { canvas.save(); canvas.clipRect(0, (actionBar != null ? actionBar.getMeasuredHeight() : 0) + AndroidUtilities.dp(50), getMeasuredWidth(), getMeasuredHeight()); boolean result = super.drawChild(canvas, child, drawingTime); canvas.restore(); return result; } }; listView.setPadding(0, 0, 0, AndroidUtilities.dp(8)); listView.setClipToPadding(false); listView.setLayoutManager( layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false)); listView.setHorizontalScrollBarEnabled(false); listView.setVerticalScrollBarEnabled(false); containerView.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); listView.setAdapter(listAdapter = new ListAdapter(context)); listView.setGlowColor(Theme.getColor(Theme.key_dialogScrollGlow)); listView.setOnItemClickListener((view, position) -> { if (view instanceof AudioPlayerCell) { ((AudioPlayerCell) view).didPressedButton(); } }); listView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_DRAGGING && searching && searchWas) { AndroidUtilities.hideKeyboard(getCurrentFocus()); } } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { updateLayout(); } }); playlist = MediaController.getInstance().getPlaylist(); listAdapter.notifyDataSetChanged(); containerView.addView(playerLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 178)); containerView.addView(shadow2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3)); containerView.addView(placeholderImageView, LayoutHelper.createFrame(40, 40, Gravity.TOP | Gravity.LEFT, 17, 19, 0, 0)); containerView.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3)); containerView.addView(actionBar); updateTitle(false); updateRepeatButton(); updateShuffleButton(); }
From source file:org.telegram.ui.ThemePreviewActivity.java
@Override public View createView(Context context) { page1 = new FrameLayout(context); ActionBarMenu menu = actionBar.createMenu(); final ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override/*from w ww. j a va 2 s . c o m*/ public void onSearchExpand() { } @Override public boolean canCollapseSearch() { return true; } @Override public void onSearchCollapse() { } @Override public void onTextChanged(EditText editText) { } }); item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search)); actionBar.setBackButtonDrawable(new MenuDrawable()); actionBar.setAddToContainer(false); actionBar.setTitle(LocaleController.getString("ThemePreview", R.string.ThemePreview)); page1 = new FrameLayout(context) { @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(); if (actionBar.getVisibility() == VISIBLE) { heightSize -= actionBarHeight; } FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.topMargin = actionBarHeight; listView.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY)); measureChildWithMargins(floatingButton, widthMeasureSpec, 0, heightMeasureSpec, 0); } @Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result = super.drawChild(canvas, child, drawingTime); if (child == actionBar && parentLayout != null) { parentLayout.drawHeaderShadow(canvas, actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() : 0); } return result; } }; page1.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); listView = new RecyclerListView(context); listView.setVerticalScrollBarEnabled(true); listView.setItemAnimator(null); listView.setLayoutAnimation(null); listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)); listView.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT : RecyclerListView.SCROLLBAR_POSITION_RIGHT); page1.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP)); floatingButton = new ImageView(context); 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.floating_pencil); 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)); } }); } page1.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)); dialogsAdapter = new DialogsAdapter(context); listView.setAdapter(dialogsAdapter); page2 = new SizeNotifierFrameLayout(context) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); setMeasuredDimension(widthSize, heightSize); measureChildWithMargins(actionBar2, widthMeasureSpec, 0, heightMeasureSpec, 0); int actionBarHeight = actionBar2.getMeasuredHeight(); if (actionBar2.getVisibility() == VISIBLE) { heightSize -= actionBarHeight; } FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView2.getLayoutParams(); layoutParams.topMargin = actionBarHeight; listView2.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY)); } @Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result = super.drawChild(canvas, child, drawingTime); if (child == actionBar2 && parentLayout != null) { parentLayout.drawHeaderShadow(canvas, actionBar2.getVisibility() == VISIBLE ? actionBar2.getMeasuredHeight() : 0); } return result; } }; page2.setBackgroundImage(Theme.getCachedWallpaper()); actionBar2 = createActionBar(context); actionBar2.setBackButtonDrawable(new BackDrawable(false)); actionBar2.setTitle("Reinhardt"); actionBar2.setSubtitle(LocaleController.formatDateOnline(System.currentTimeMillis() / 1000 - 60 * 60)); page2.addView(actionBar2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); listView2 = new RecyclerListView(context); listView2.setVerticalScrollBarEnabled(true); listView2.setItemAnimator(null); listView2.setLayoutAnimation(null); listView2.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4)); listView2.setClipToPadding(false); listView2.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true)); listView2.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT : RecyclerListView.SCROLLBAR_POSITION_RIGHT); page2.addView(listView2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP)); messagesAdapter = new MessagesAdapter(context); listView2.setAdapter(messagesAdapter); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; final ViewPager viewPager = new ViewPager(context); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { dotsContainer.invalidate(); } @Override public void onPageScrollStateChanged(int state) { } }); viewPager.setAdapter(new PagerAdapter() { @Override public int getCount() { return 2; } @Override public boolean isViewFromObject(View view, Object object) { return object == view; } @Override public int getItemPosition(Object object) { return POSITION_UNCHANGED; } @Override public Object instantiateItem(ViewGroup container, int position) { View view = position == 0 ? page1 : page2; container.addView(view); return view; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } @Override public void unregisterDataSetObserver(DataSetObserver observer) { if (observer != null) { super.unregisterDataSetObserver(observer); } } }); AndroidUtilities.setViewPagerEdgeEffectColor(viewPager, Theme.getColor(Theme.key_actionBarDefault)); frameLayout.addView(viewPager, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 48)); View shadow = new View(context); shadow.setBackgroundResource(R.drawable.header_shadow_reverse); frameLayout.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.LEFT | Gravity.BOTTOM, 0, 0, 0, 48)); FrameLayout bottomLayout = new FrameLayout(context); bottomLayout.setBackgroundColor(0xffffffff); frameLayout.addView(bottomLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM)); dotsContainer = new View(context) { private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); @Override protected void onDraw(Canvas canvas) { int selected = viewPager.getCurrentItem(); for (int a = 0; a < 2; a++) { paint.setColor(a == selected ? 0xff999999 : 0xffcccccc); canvas.drawCircle(AndroidUtilities.dp(3 + 15 * a), AndroidUtilities.dp(4), AndroidUtilities.dp(3), paint); } } }; bottomLayout.addView(dotsContainer, LayoutHelper.createFrame(22, 8, Gravity.CENTER)); TextView cancelButton = new TextView(context); cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); cancelButton.setTextColor(0xff19a7e8); cancelButton.setGravity(Gravity.CENTER); cancelButton.setBackgroundDrawable(Theme.createSelectorDrawable(0x2f000000, 0)); cancelButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0); cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase()); cancelButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); bottomLayout.addView(cancelButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Theme.applyPreviousTheme(); parentLayout.rebuildAllFragmentViews(false); finishFragment(); } }); TextView doneButton = new TextView(context); doneButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); doneButton.setTextColor(0xff19a7e8); doneButton.setGravity(Gravity.CENTER); doneButton.setBackgroundDrawable(Theme.createSelectorDrawable(0x2f000000, 0)); doneButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0); doneButton.setText(LocaleController.getString("ApplyTheme", R.string.ApplyTheme).toUpperCase()); doneButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); bottomLayout.addView(doneButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT)); doneButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { applied = true; parentLayout.rebuildAllFragmentViews(false); Theme.applyThemeFile(themeFile, applyingTheme.name, false); finishFragment(); } }); return fragmentView; }
From source file:org.cafemember.ui.DialogsActivity.java
@Override public View createView(final Context context) { Commands.checkChannels(MessagesController.getInstance().getDialogs()); int today = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); if (today != Defaults.getInstance().getLastDay()) { Defaults.getInstance().setLastDay(today); AlertDialog.Builder builder = null; /*if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { builder = new AlertDialog.Builder(context, R.style.MyDialog); }//from w w w .j a v a 2 s . co m else {*/ builder = new AlertDialog.Builder(context); // } builder.setTitle(" "); builder.setMessage( AndroidUtilities.replaceTags(LocaleController.getString("giftText", R.string.giftText))); builder.setPositiveButton("", null); showDialog(builder.create()); } searching = false; searchWas = false; Theme.loadRecources(context); ActionBarMenu menu = actionBar.createMenu(); if (!onlySelect && searchString == null) { passcodeItem = menu.addItem(1, R.drawable.lock_close); updatePasscodeButton(); } joinCoins = menu.addItemResource(7, R.layout.join_coins_view); FontManager.instance().setTypefaceImmediate(joinCoins); // viewCoins = menu.addItemResource(8, R.layout.view_coins_view); // final ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { // @Override // public void onSearchExpand() { // searching = true; // if (listView != null) { // if (searchString != null) { // listView.setEmptyView(searchEmptyView); // progressView.setVisibility(View.GONE); // emptyView.setVisibility(View.GONE); // } // if (!onlySelect) { // floatingButton.setVisibility(View.GONE); // } // } // updatePasscodeButton(); // } // // @Override // public boolean canCollapseSearch() { // if (searchString != null) { // finishFragment(); // return false; // } // return true; // } // // @Override // public void onSearchCollapse() { // searching = false; // searchWas = false; // if (listView != null) { // searchEmptyView.setVisibility(View.GONE); // if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) { // emptyView.setVisibility(View.GONE); // listView.setEmptyView(progressView); // } else { // progressView.setVisibility(View.GONE); // listView.setEmptyView(emptyView); // } // if (!onlySelect) { // floatingButton.setVisibility(View.VISIBLE); // floatingHidden = true; // ViewProxy.setTranslationY(floatingButton, AndroidUtilities.dp(100)); // hideFloatingButton(false); // } // if (listView.getAdapter() != dialogsAdapter) { // listView.setAdapter(dialogsAdapter); // dialogsAdapter.notifyDataSetChanged(); // } // } // if (dialogsSearchAdapter != null) { // dialogsSearchAdapter.searchDialogs(null); // } // updatePasscodeButton(); // } // // @Override // public void onTextChanged(EditText editText) { // String text = editText.getText().toString(); // if (text.length() != 0 || dialogsSearchAdapter != null && dialogsSearchAdapter.hasRecentRearch()) { // searchWas = true; // if (dialogsSearchAdapter != null && listView.getAdapter() != dialogsSearchAdapter) { // listView.setAdapter(dialogsSearchAdapter); // dialogsSearchAdapter.notifyDataSetChanged(); // } // if (searchEmptyView != null && listView.getEmptyView() != searchEmptyView) { // emptyView.setVisibility(View.GONE); // progressView.setVisibility(View.GONE); // searchEmptyView.showTextView(); // listView.setEmptyView(searchEmptyView); // } // } // if (dialogsSearchAdapter != null) { // dialogsSearchAdapter.searchDialogs(text); // } // } // }); // item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search)); if (onlySelect) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setTitle(LocaleController.getString("SelectChat", R.string.SelectChat)); } else { if (searchString != null) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); } else { actionBar.setBackButtonDrawable(new MenuDrawable()); } if (BuildVars.DEBUG_VERSION) { actionBar.setTitle(LocaleController.getString("AppNameBeta", R.string.AppNameBeta)); } else { actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName)); } } actionBar.setAllowOverlayTitle(true); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { if (onlySelect) { finishFragment(); } else if (parentLayout != null) { parentLayout.getDrawerLayoutContainer().openDrawer(false); } } else if (id == 1) { UserConfig.appLocked = !UserConfig.appLocked; UserConfig.saveConfig(false); updatePasscodeButton(); } } }); FrameLayout frameLayout = new FrameLayout(context); // fragmentView = frameLayout; fragmentView = Views.getTabLayout((FragmentActivity) context, this, frameLayout); listView = new RecyclerListView(context); listView.setVerticalScrollBarEnabled(true); listView.setItemAnimator(null); listView.setInstantClick(true); listView.setLayoutAnimation(null); layoutManager = new LinearLayoutManager(context) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }; layoutManager.setOrientation(LinearLayoutManager.VERTICAL); listView.setLayoutManager(layoutManager); if (Build.VERSION.SDK_INT >= 11) { listView.setVerticalScrollbarPosition( LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT); } frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); listView.setOnAddChannelClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (listView == null || listView.getAdapter() == null) { return; } long dialog_id = 0; int message_id = 0; RecyclerView.Adapter adapter = listView.getAdapter(); if (adapter == dialogsAdapter) { TLRPC.Dialog dialog = dialogsAdapter.getItem(position); if (dialog == null) { return; } int lower_id = (int) dialog.id; final TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_id); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("MemberBegirTitle", R.string.MemberBegirTitle)); /*builder.setItems(Defaults.MEMBERS_COUNT , new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Commands.addChannel(chat,Integer.parseInt(Defaults.MEMBERS_COUNT[which])); } });*/ /*builder.setAdapter(new ReserveAdapter(getParentActivity(),R.layout.adapter_buy_coin,1), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Commands.addChannel(chat,Integer.parseInt(Defaults.MEMBERS_COUNT[which])); } });*/ builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } } }); listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (listView == null || listView.getAdapter() == null) { return; } long dialog_id = 0; int message_id = 0; RecyclerView.Adapter adapter = listView.getAdapter(); if (adapter == dialogsAdapter) { TLRPC.Dialog dialog = dialogsAdapter.getItem(position); if (dialog == null) { return; } dialog_id = dialog.id; } else if (adapter == dialogsSearchAdapter) { Object obj = dialogsSearchAdapter.getItem(position); if (obj instanceof TLRPC.User) { dialog_id = ((TLRPC.User) obj).id; if (dialogsSearchAdapter.isGlobalSearch(position)) { ArrayList<TLRPC.User> users = new ArrayList<>(); users.add((TLRPC.User) obj); MessagesController.getInstance().putUsers(users, false); MessagesStorage.getInstance().putUsersAndChats(users, null, false, true); } if (!onlySelect) { dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.User) obj); } } else if (obj instanceof TLRPC.Chat) { if (dialogsSearchAdapter.isGlobalSearch(position)) { ArrayList<TLRPC.Chat> chats = new ArrayList<>(); chats.add((TLRPC.Chat) obj); MessagesController.getInstance().putChats(chats, false); MessagesStorage.getInstance().putUsersAndChats(null, chats, false, true); } if (((TLRPC.Chat) obj).id > 0) { dialog_id = -((TLRPC.Chat) obj).id; } else { dialog_id = AndroidUtilities.makeBroadcastId(((TLRPC.Chat) obj).id); } if (!onlySelect) { dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.Chat) obj); } } else if (obj instanceof TLRPC.EncryptedChat) { dialog_id = ((long) ((TLRPC.EncryptedChat) obj).id) << 32; if (!onlySelect) { dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.EncryptedChat) obj); } } else if (obj instanceof MessageObject) { MessageObject messageObject = (MessageObject) obj; dialog_id = messageObject.getDialogId(); message_id = messageObject.getId(); dialogsSearchAdapter.addHashtagsFromMessage(dialogsSearchAdapter.getLastSearchString()); } else if (obj instanceof String) { actionBar.openSearchField((String) obj); } } if (dialog_id == 0) { return; } if (onlySelect) { didSelectResult(dialog_id, true, false); } else { Bundle args = new Bundle(); int lower_part = (int) dialog_id; int high_id = (int) (dialog_id >> 32); if (lower_part != 0) { if (high_id == 1) { args.putInt("chat_id", lower_part); } else { if (lower_part > 0) { args.putInt("user_id", lower_part); } else if (lower_part < 0) { if (message_id != 0) { TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_part); if (chat != null && chat.migrated_to != null) { args.putInt("migrated_to", lower_part); lower_part = -chat.migrated_to.channel_id; } } args.putInt("chat_id", -lower_part); } } } else { args.putInt("enc_id", high_id); } if (message_id != 0) { args.putInt("message_id", message_id); } else { if (actionBar != null) { actionBar.closeSearchField(); } } if (AndroidUtilities.isTablet()) { if (openedDialogId == dialog_id && adapter != dialogsSearchAdapter) { return; } if (dialogsAdapter != null) { dialogsAdapter.setOpenedDialogId(openedDialogId = dialog_id); updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG); } } if (searchString != null) { if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) { NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); presentFragment(new ChatActivity(args)); } } else { if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) { presentFragment(new ChatActivity(args)); } } } } }); listView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() { @Override public boolean onItemClick(View view, int position) { if (onlySelect || searching && searchWas || getParentActivity() == null) { if (searchWas && searching || dialogsSearchAdapter.isRecentSearchDisplayed()) { RecyclerView.Adapter adapter = listView.getAdapter(); if (adapter == dialogsSearchAdapter) { Object item = dialogsSearchAdapter.getItem(position); if (item instanceof String || dialogsSearchAdapter.isRecentSearchDisplayed()) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch)); builder.setPositiveButton(LocaleController .getString("ClearButton", R.string.ClearButton).toUpperCase(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (dialogsSearchAdapter.isRecentSearchDisplayed()) { dialogsSearchAdapter.clearRecentSearch(); } else { dialogsSearchAdapter.clearRecentHashtags(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); return true; } } } return false; } TLRPC.Dialog dialog; ArrayList<TLRPC.Dialog> dialogs = getDialogsArray(); if (position < 0 || position >= dialogs.size()) { return false; } dialog = dialogs.get(position); selectedDialog = dialog.id; BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity()); int lower_id = (int) selectedDialog; int high_id = (int) (selectedDialog >> 32); if (dialog instanceof TLRPC.TL_dialogChannel) { final TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_id); CharSequence items[]; if (chat != null && chat.megagroup) { items = new CharSequence[] { LocaleController.getString("ClearHistoryCache", R.string.ClearHistoryCache), chat == null || !chat.creator ? LocaleController.getString("LeaveMegaMenu", R.string.LeaveMegaMenu) : LocaleController.getString("DeleteMegaMenu", R.string.DeleteMegaMenu) }; } else { items = new CharSequence[] { LocaleController.getString("ClearHistoryCache", R.string.ClearHistoryCache), chat == null || !chat.creator ? LocaleController.getString("LeaveChannelMenu", R.string.LeaveChannelMenu) : LocaleController.getString("ChannelDeleteMenu", R.string.ChannelDeleteMenu), LocaleController.getString("MemberBegir", R.string.MemberBegir) }; } builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, final int which) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); if (which == 0) { if (chat != null && chat.megagroup) { builder.setMessage(LocaleController.getString("AreYouSureClearHistorySuper", R.string.AreYouSureClearHistorySuper)); } else { builder.setMessage(LocaleController.getString("AreYouSureClearHistoryChannel", R.string.AreYouSureClearHistoryChannel)); } builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().deleteDialog(selectedDialog, 2); } }); } else if (which == 2) { builder.setTitle( LocaleController.getString("MemberBegirTitle", R.string.MemberBegirTitle)); /*builder.setAdapter(new ReserveAdapter(getParentActivity(),R.layout.adapter_buy_coin,1), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Commands.addChannel(chat,Integer.parseInt(Defaults.MEMBERS_COUNT[which])); } });*/ /*builder.setItems(Defaults.MEMBERS_COUNT , new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Commands.addChannel(chat,Integer.parseInt(Defaults.MEMBERS_COUNT[which])); } });*/ } else { if (chat != null && chat.megagroup) { if (!chat.creator) { builder.setMessage(LocaleController.getString("MegaLeaveAlert", R.string.MegaLeaveAlert)); } else { builder.setMessage(LocaleController.getString("MegaDeleteAlert", R.string.MegaDeleteAlert)); } } else { if (chat == null || !chat.creator) { builder.setMessage(LocaleController.getString("ChannelLeaveAlert", R.string.ChannelLeaveAlert)); } else { builder.setMessage(LocaleController.getString("ChannelDeleteAlert", R.string.ChannelDeleteAlert)); } } builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().deleteUserFromChat( (int) -selectedDialog, UserConfig.getCurrentUser(), null); if (AndroidUtilities.isTablet()) { NotificationCenter.getInstance().postNotificationName( NotificationCenter.closeChats, selectedDialog); } } }); } builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } }); showDialog(builder.create()); } else { final boolean isChat = lower_id < 0 && high_id != 1; TLRPC.User user = null; if (!isChat && lower_id > 0 && high_id != 1) { user = MessagesController.getInstance().getUser(lower_id); } final boolean isBot = user != null && user.bot; builder.setItems( new CharSequence[] { LocaleController.getString("ClearHistory", R.string.ClearHistory), isChat ? LocaleController.getString("DeleteChat", R.string.DeleteChat) : isBot ? LocaleController.getString("DeleteAndStop", R.string.DeleteAndStop) : LocaleController.getString("Delete", R.string.Delete) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, final int which) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); if (which == 0) { builder.setMessage(LocaleController.getString("AreYouSureClearHistory", R.string.AreYouSureClearHistory)); } else { if (isChat) { builder.setMessage(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit)); } else { builder.setMessage(LocaleController.getString( "AreYouSureDeleteThisChat", R.string.AreYouSureDeleteThisChat)); } } builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (which != 0) { if (isChat) { TLRPC.Chat currentChat = MessagesController .getInstance().getChat((int) -selectedDialog); if (currentChat != null && ChatObject.isNotInChat(currentChat)) { MessagesController.getInstance() .deleteDialog(selectedDialog, 0); } else { MessagesController.getInstance().deleteUserFromChat( (int) -selectedDialog, MessagesController.getInstance().getUser( UserConfig.getClientUserId()), null); } } else { MessagesController.getInstance() .deleteDialog(selectedDialog, 0); } if (isBot) { MessagesController.getInstance() .blockUser((int) selectedDialog); } if (AndroidUtilities.isTablet()) { NotificationCenter.getInstance().postNotificationName( NotificationCenter.closeChats, selectedDialog); } } else { MessagesController.getInstance() .deleteDialog(selectedDialog, 1); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } }); showDialog(builder.create()); } return true; } }); searchEmptyView = new EmptyTextProgressView(context); searchEmptyView.setVisibility(View.GONE); searchEmptyView.setShowAtCenter(true); searchEmptyView.setText(LocaleController.getString("NoResult", R.string.NoResult)); frameLayout.addView(searchEmptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); emptyView = new LinearLayout(context); emptyView.setOrientation(LinearLayout.VERTICAL); emptyView.setVisibility(View.GONE); emptyView.setGravity(Gravity.CENTER); frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); emptyView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoChats", R.string.NoChats)); textView.setTextColor(0xff959595); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); emptyView.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT)); textView = new TextView(context); String help = LocaleController.getString("NoChatsHelp", R.string.NoChatsHelp); if (AndroidUtilities.isTablet() && !AndroidUtilities.isSmallTablet()) { help = help.replace('\n', ' '); } textView.setText(help); textView.setTextColor(0xff959595); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); textView.setGravity(Gravity.CENTER); textView.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(6), AndroidUtilities.dp(8), 0); textView.setLineSpacing(AndroidUtilities.dp(2), 1); emptyView.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT)); progressView = new ProgressBar(context); progressView.setVisibility(View.GONE); frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); floatingButton = new ImageView(context); floatingButton.setVisibility(onlySelect ? View.GONE : View.VISIBLE); floatingButton.setScaleType(ImageView.ScaleType.CENTER); floatingButton.setBackgroundResource(R.drawable.floating_states); floatingButton.setImageResource(R.drawable.floating_pencil); 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(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14)); floatingButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle args = new Bundle(); args.putBoolean("destroyAfterSelect", true); presentFragment(new ContactsActivity(args)); } }); listView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_DRAGGING && searching && searchWas) { AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus()); } } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { int firstVisibleItem = layoutManager.findFirstVisibleItemPosition(); int visibleItemCount = Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1; int totalItemCount = recyclerView.getAdapter().getItemCount(); if (searching && searchWas) { if (visibleItemCount > 0 && layoutManager.findLastVisibleItemPosition() == totalItemCount - 1 && !dialogsSearchAdapter.isMessagesSearchEndReached()) { dialogsSearchAdapter.loadMoreSearchMessages(); } return; } if (visibleItemCount > 0) { if (layoutManager.findLastVisibleItemPosition() >= getDialogsArray().size() - 10) { MessagesController.getInstance().loadDialogs(-1, 100, !MessagesController.getInstance().dialogsEndReached); } } 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 (searchString == null) { dialogsAdapter = new DialogsAdapter(context, dialogsType); if (AndroidUtilities.isTablet() && openedDialogId != 0) { dialogsAdapter.setOpenedDialogId(openedDialogId); } listView.setAdapter(dialogsAdapter); } int type = 0; if (searchString != null) { type = 2; } else if (!onlySelect) { type = 1; } dialogsSearchAdapter = new DialogsSearchAdapter(context, type, dialogsType); dialogsSearchAdapter.setDelegate(new DialogsSearchAdapter.MessagesActivitySearchAdapterDelegate() { @Override public void searchStateChanged(boolean search) { if (searching && searchWas && searchEmptyView != null) { if (search) { searchEmptyView.showProgress(); } else { searchEmptyView.showTextView(); } } } }); if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) { searchEmptyView.setVisibility(View.GONE); emptyView.setVisibility(View.GONE); listView.setEmptyView(progressView); } else { searchEmptyView.setVisibility(View.GONE); progressView.setVisibility(View.GONE); listView.setEmptyView(emptyView); } if (searchString != null) { actionBar.openSearchField(searchString); } if (!onlySelect && dialogsType == 0) { frameLayout.addView(new PlayerView(context, this), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 39, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0)); } // fragmentView = Views.getTabLayout((FragmentActivity) context, this, frameLayout); return fragmentView; }