List of usage examples for android.view ViewGroup removeView
@Override public void removeView(View view)
Note: do not invoke this method from #draw(android.graphics.Canvas) , #onDraw(android.graphics.Canvas) , #dispatchDraw(android.graphics.Canvas) or any related method.
From source file:com.android.systemui.qs.QSDragPanel.java
@Override protected void setupViews() { updateResources();//from ww w. j a v a2 s. co m mDetail = LayoutInflater.from(mContext).inflate(R.layout.qs_detail, this, false); mDetailButtons = (ViewGroup) mDetail.findViewById(R.id.buttons); mDetailContent = (ViewGroup) mDetail.findViewById(android.R.id.content); mDetailRemoveButton = (TextView) mDetail.findViewById(android.R.id.button3); mDetailSettingsButton = (TextView) mDetail.findViewById(android.R.id.button2); mDetailDoneButton = (TextView) mDetail.findViewById(android.R.id.button1); updateDetailText(); mDetail.setVisibility(GONE); mDetail.setClickable(true); mQsPanelTop = (QSPanelTopView) LayoutInflater.from(mContext).inflate(R.layout.qs_tile_top, this, false); mBrightnessView = mQsPanelTop.getBrightnessView(); mFooter = new QSFooter(this, mContext); // add target click listener mQsPanelTop.getAddTarget().setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { TilesListAdapter adapter = new TilesListAdapter(mContext, QSDragPanel.this); showDetailAdapter(true, adapter, v.getLocationOnScreen()); mDetail.bringToFront(); } }); mViewPager = new QSViewPager(getContext()); mViewPager.setDragPanel(this); mPageIndicator = new CirclePageIndicator(getContext()); addView(mDetail); addView(mQsPanelTop); addView(mViewPager); addView(mPageIndicator); addView(mFooter.getView()); mClipper = new QSDetailClipper(mDetail); mBrightnessController = new BrightnessController(getContext(), (ImageView) mQsPanelTop.getBrightnessView().findViewById(R.id.brightness_icon), (ToggleSlider) mQsPanelTop.getBrightnessView().findViewById(R.id.brightness_slider)); mDetailDoneButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { announceForAccessibility(mContext.getString(R.string.accessibility_desc_quick_settings)); closeDetail(); } }); mPagerAdapter = new PagerAdapter() { @Override public Object instantiateItem(ViewGroup container, int position) { if (DEBUG_TILES) { Log.d(TAG, "instantiateItem() called with " + "container = [" + container + "], position = [" + position + "]"); } if (mEditing && position == 0) { QSSettings qss = (QSSettings) View.inflate(container.getContext(), R.layout.qs_settings, null); qss.setHost(mHost); container.addView(qss, 0); return qss; } else { final int adjustedPosition = mEditing ? position - 1 : position; QSPage page = mPages.get(adjustedPosition); if (!page.isAttachedToWindow()) { container.addView(page); } return page; } } @Override public void destroyItem(ViewGroup container, int position, Object object) { if (DEBUG_TILES) { Log.d(TAG, "destroyItem() called with " + "container = [" + container + "], position = [" + position + "], object = [" + object + "]"); } if (object instanceof View) { container.removeView((View) object); } } @Override public int getItemPosition(Object object) { if (object instanceof QSPage) { if (mEditing != ((QSPage) object).getAdapterEditingState()) { // position of item changes when we set change the editing mode, // sync it and send the new position ((QSPage) object).setAdapterEditingState(mEditing); // calculate new position int indexOf = ((QSPage) object).getPageIndex(); if (mEditing) return indexOf + 1; else return indexOf; } else if (!mPages.contains(object) && !mDragging) { // only return none if we aren't dragging (object may be removed from // the records array temporarily and we might think we have less pages, // we don't want to prematurely remove this page return POSITION_NONE; } else { return POSITION_UNCHANGED; } } else if (object instanceof QSSettings) { if (((QSSettings) object).getAdapterEditingState() != mEditing) { ((QSSettings) object).setAdapterEditingState(mEditing); if (mEditing) return 0 /* locked at position 0 */; else return POSITION_NONE; } else { return POSITION_UNCHANGED; } } return super.getItemPosition(object); } @Override public int getCount() { final int qsPages = Math.max(getCurrentMaxPageCount(), 1); if (mPages != null && qsPages > mPages.size()) { for (int i = mPages.size(); i < qsPages; i++) { mPages.add(i, new QSPage(mViewPager.getContext(), QSDragPanel.this, i)); } } if (mEditing) return qsPages + 1; return qsPages; } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } }; mViewPager.setAdapter(mPagerAdapter); mPageIndicator.setViewPager(mViewPager); mPageIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (DEBUG_DRAG) { Log.i(TAG, "onPageScrolled() called with " + "position = [" + position + "], positionOffset = [" + positionOffset + "], positionOffsetPixels = [" + positionOffsetPixels + "]"); } if (mEditing) { float targetTranslationX = 0; // targetTranslationX = where it's supposed to be - diff int homeLocation = mViewPager.getMeasuredWidth(); // how far away from homeLocation is the scroll? if (positionOffsetPixels < homeLocation && position == 0) { targetTranslationX = homeLocation - positionOffsetPixels; } mQsPanelTop.setTranslationX(targetTranslationX); } } @Override public void onPageSelected(int position) { if (mDragging && position != mDraggingRecord.page && !mViewPager.isFakeDragging() && !mRestoring) { if (DEBUG_DRAG) { Log.w(TAG, "moving drag record to page: " + position); } // remove it from the previous page and add it here final QSPage sourceP = getPage(mDraggingRecord.page); final QSPage targetP = getPage(position); sourceP.removeView(mDraggingRecord.tileView); mDraggingRecord.page = position; targetP.addView(mDraggingRecord.tileView); // set coords off screen until we're ready to place it mDraggingRecord.tileView.setX(-mDraggingRecord.tileView.getMeasuredWidth()); mDraggingRecord.tileView.setY(-mDraggingRecord.tileView.getMeasuredHeight()); } } @Override public void onPageScrollStateChanged(int state) { } }); mViewPager.setOverScrollMode(OVER_SCROLL_NEVER); setClipChildren(false); mSettingsObserver = new SettingsObserver(new Handler()); mViewPager.setOnDragListener(QSDragPanel.this); mQsPanelTop.setOnDragListener(QSDragPanel.this); mPageIndicator.setOnDragListener(QSDragPanel.this); setOnDragListener(QSDragPanel.this); mViewPager.setOverScrollMode(View.OVER_SCROLL_NEVER); }
From source file:com.android.launcher2.Launcher.java
private void removeCling(int id) { final View cling = findViewById(id); if (cling != null) { final ViewGroup parent = (ViewGroup) cling.getParent(); parent.post(new Runnable() { @Override//w w w.j a v a 2 s . c o m public void run() { parent.removeView(cling); } }); mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer); } }
From source file:com.cairoconfessions.MainActivity.java
public void addItem(View view) { // Instantiate a new "row" view. final ViewGroup mFilter = (ViewGroup) findViewById(R.id.filter_cat); final ViewGroup mFilterLoc = (ViewGroup) findViewById(R.id.filter_loc); final ViewGroup mFilterMain = (ViewGroup) findViewById(R.id.filter_main); final ViewGroup newView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.list_item_example, null); final ViewGroup newViewLoc = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.list_item_example, null);//from w ww . ja va2s . c o m final ViewGroup newViewMain = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.list_item_example, null); ArrayList<View> presentView = new ArrayList<View>(); mFilter.findViewsWithText(presentView, ((TextView) view).getText(), 1); if (presentView.size() == 0) { final String filterName = ((TextView) view).getText().toString(); switch (((LinearLayout) view.getParent()).getId()) { case R.id.cat_filter_list: Categories.add(filterName); break; case R.id.locations: Cities.add(filterName); break; } if (filterName.equals("Love")) { newView.getChildAt(0).setBackgroundResource(R.color.love); newViewLoc.getChildAt(0).setBackgroundResource(R.color.love); newViewMain.getChildAt(0).setBackgroundResource(R.color.love); } if (filterName.equals("Pain")) { newView.getChildAt(0).setBackgroundResource(R.color.pain); newViewLoc.getChildAt(0).setBackgroundResource(R.color.pain); newViewMain.getChildAt(0).setBackgroundResource(R.color.pain); } if (filterName.equals("Guilt")) { newView.getChildAt(0).setBackgroundResource(R.color.guilt); newViewLoc.getChildAt(0).setBackgroundResource(R.color.guilt); newViewMain.getChildAt(0).setBackgroundResource(R.color.guilt); } if (filterName.equals("Fantasy")) { newView.getChildAt(0).setBackgroundResource(R.color.fantasy); newViewLoc.getChildAt(0).setBackgroundResource(R.color.fantasy); newViewMain.getChildAt(0).setBackgroundResource(R.color.fantasy); } if (filterName.equals("Dream")) { newView.getChildAt(0).setBackgroundResource(R.color.dream); newViewLoc.getChildAt(0).setBackgroundResource(R.color.dream); newViewMain.getChildAt(0).setBackgroundResource(R.color.dream); } ((TextView) newView.findViewById(android.R.id.text1)).setText(filterName); ((TextView) newViewLoc.findViewById(android.R.id.text1)).setText(filterName); ((TextView) newViewMain.findViewById(android.R.id.text1)).setText(filterName); // Set a click listener for the "X" button in the row that will // remove the row. newView.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mFilter.removeView(newView); mFilterLoc.removeView(newViewLoc); mFilterMain.removeView(newViewMain); if (mFilter.getChildCount() == 0) { findViewById(R.id.content_loc).setVisibility(View.GONE); findViewById(R.id.content_cat).setVisibility(View.GONE); findViewById(R.id.content_main).setVisibility(View.GONE); } if (Categories.contains(filterName)) while (Categories.remove(filterName)) ; if (Cities.contains(filterName)) while (Cities.remove(filterName)) ; updateFilters(); } }); newViewLoc.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mFilterLoc.removeView(newViewLoc); mFilter.removeView(newView); mFilterMain.removeView(newViewMain); if (mFilterLoc.getChildCount() == 0) { findViewById(R.id.content_loc).setVisibility(View.GONE); findViewById(R.id.content_cat).setVisibility(View.GONE); findViewById(R.id.content_main).setVisibility(View.GONE); } if (Categories.contains(filterName)) while (Categories.remove(filterName)) ; if (Cities.contains(filterName)) while (Cities.remove(filterName)) ; updateFilters(); } }); newViewMain.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mFilterLoc.removeView(newViewLoc); mFilter.removeView(newView); mFilterMain.removeView(newViewMain); if (mFilterMain.getChildCount() == 0) { findViewById(R.id.content_loc).setVisibility(View.GONE); findViewById(R.id.content_cat).setVisibility(View.GONE); findViewById(R.id.content_main).setVisibility(View.GONE); } if (Categories.contains(filterName)) while (Categories.remove(filterName)) ; if (Cities.contains(filterName)) while (Cities.remove(filterName)) ; updateFilters(); } }); // Because mFilter has android:animateLayoutChanges set to true, // adding this view is automatically animated. // mFilterCat.addView(newViewCat); mFilter.addView(newView, 0); mFilterLoc.addView(newViewLoc, 0); mFilterMain.addView(newViewMain, 0); findViewById(R.id.content_loc).setVisibility(View.VISIBLE); findViewById(R.id.content_cat).setVisibility(View.VISIBLE); findViewById(R.id.content_main).setVisibility(View.VISIBLE); updateFilters(); Toast.makeText(this, filterName + " filter added!", Toast.LENGTH_LONG).show(); } else Toast.makeText(this, "Already added!", Toast.LENGTH_LONG).show(); }
From source file:com.popdeem.sdk.uikit.fragment.PDUIRewardsFragment.java
@Nullable @Override/*w w w. j a v a 2 s. c om*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (mView == null) { mView = inflater.inflate(R.layout.fragment_pd_rewards, container, false); noItemsView = mView.findViewById(R.id.pd_rewards_no_items_view); recyclerView = (RecyclerView) mView.findViewById(R.id.pd_rewards_recycler_view); mRecyclerViewAdapter = new PDUIRewardsRecyclerViewAdapter(mRewards); mRecyclerViewAdapter.setOnItemClickListener(new PDUIRewardsRecyclerViewAdapter.OnItemClickListener() { @Override public void onItemClick(final View view) { if (!hasBeenClicked) { hasBeenClicked = true; new Handler().postDelayed(new Runnable() { @Override public void run() { hasBeenClicked = false; } }, 2000); // performRewardClick(view); if ((PDSocialUtils.isLoggedInToFacebook() || PDSocialUtils.isTwitterLoggedIn() || PDSocialUtils.isInstagramLoggedIn()) && PDUtils.getUserToken() != null) { performRewardClick(view); } else { PDSocialUtils.isInstagramLoggedIn(new PDAPICallback<Boolean>() { @Override public void success(Boolean aBoolean) { if ((aBoolean || PDSocialUtils.isInstagramLoggedIn()) && PDUtils.getUserToken() != null) { performRewardClick(view); } else { if (PDPreferencesUtils.getIsMultiLoginEnabled(getActivity())) { PopdeemSDK.showSocialMultiLogin(getActivity(), mRewards); } else PopdeemSDK.showSocialLogin(getActivity(), mRewards); } } @Override public void failure(int statusCode, Exception e) { if (PDSocialUtils.isInstagramLoggedIn() && PDUtils.getUserToken() != null) { performRewardClick(view); } } }); } } } }); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()); recyclerView.setLayoutManager(linearLayoutManager); recyclerView.setNestedScrollingEnabled(true); // recyclerView.addItemDecoration(new PDUIDividerItemDecoration(getActivity(), R.color.pd_reward_list_divider_color)); recyclerView.setAdapter(mRecyclerViewAdapter); mSwipeRefreshLayout = (PDUISwipeRefreshLayout) mView; mSwipeRefreshLayout.addLinearLayoutManager(linearLayoutManager); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refreshRewards(); } }); loadList(); refreshRewards(); mLocationManager = new PDLocationManager(getActivity()); mLocationManager.startLocationUpdates(this); } else { container.removeView(mView); } return mView; }
From source file:org.telepatch.ui.ChatActivity.java
public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back); if (AndroidUtilities.isTablet()) { actionBarLayer.setExtraLeftMargin(4); }/*from w w w . jav a 2 s . co m*/ actionBarLayer.setBackOverlay(R.layout.updating_state_layout); actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == -2) { selectedMessagesIds.clear(); selectedMessagesCanCopyIds.clear(); actionBarLayer.hideActionMode(); updateVisibleRows(); } else if (id == attach_photo) { try { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File image = Utilities.generatePicturePath(); if (image != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image)); currentPicturePath = image.getAbsolutePath(); } startActivityForResult(takePictureIntent, 0); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (id == attach_gallery) { PhotoPickerActivity fragment = new PhotoPickerActivity(); fragment.setDelegate(new PhotoPickerActivity.PhotoPickerActivityDelegate() { @Override public void didSelectPhotos(ArrayList<String> photos) { SendMessagesHelper.prepareSendingPhotos(photos, null, dialog_id); } @Override public void startPhotoSelectActivity() { try { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, 1); } catch (Exception e) { FileLog.e("tmessages", e); } } }); presentFragment(fragment); } else if (id == attach_video) { try { Intent pickIntent = new Intent(); pickIntent.setType("video/*"); pickIntent.setAction(Intent.ACTION_GET_CONTENT); pickIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1000)); Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); File video = Utilities.generateVideoPath(); if (video != null) { if (Build.VERSION.SDK_INT >= 18) { takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(video)); } takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1000)); currentPicturePath = video.getAbsolutePath(); } Intent chooserIntent = Intent.createChooser(pickIntent, ""); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { takeVideoIntent }); startActivityForResult(chooserIntent, 2); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (id == attach_location) { if (!isGoogleMapsInstalled()) { return; } LocationActivity fragment = new LocationActivity(); fragment.setDelegate(new LocationActivity.LocationActivityDelegate() { @Override public void didSelectLocation(double latitude, double longitude) { SendMessagesHelper.getInstance().sendMessage(latitude, longitude, dialog_id); if (chatListView != null) { chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop()); } if (paused) { scrollToTopOnResume = true; } } }); presentFragment(fragment); } else if (id == attach_document) { DocumentSelectActivity fragment = new DocumentSelectActivity(); fragment.setDelegate(new DocumentSelectActivity.DocumentSelectActivityDelegate() { @Override public void didSelectFile(DocumentSelectActivity activity, String path) { activity.finishFragment(); SendMessagesHelper.prepareSendingDocument(path, path, dialog_id); } @Override public void startDocumentSelectActivity() { try { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("*/*"); startActivityForResult(photoPickerIntent, 21); } catch (Exception e) { FileLog.e("tmessages", e); } } }); presentFragment(fragment); } else if (id == chat_menu_avatar) { if (currentUser != null) { Bundle args = new Bundle(); args.putInt("user_id", currentUser.id); if (currentEncryptedChat != null) { args.putLong("dialog_id", dialog_id); } presentFragment(new UserProfileActivity(args)); } else if (currentChat != null) { if (info != null && info instanceof TLRPC.TL_chatParticipantsForbidden) { return; } int count = currentChat.participants_count; if (info != null) { count = info.participants.size(); } if (count == 0 || currentChat.left || currentChat instanceof TLRPC.TL_chatForbidden) { return; } Bundle args = new Bundle(); args.putInt("chat_id", currentChat.id); ChatProfileActivity fragment = new ChatProfileActivity(args); fragment.setChatInfo(info); presentFragment(fragment); } } else if (id == copy) { String str = ""; ArrayList<Integer> ids = new ArrayList<Integer>(selectedMessagesCanCopyIds.keySet()); if (currentEncryptedChat == null) { Collections.sort(ids); } else { Collections.sort(ids, Collections.reverseOrder()); } for (Integer messageId : ids) { MessageObject messageObject = selectedMessagesCanCopyIds.get(messageId); if (str.length() != 0) { str += "\n"; } if (messageObject.messageOwner.message != null) { str += messageObject.messageOwner.message; } else { str += messageObject.messageText; } } if (str.length() != 0) { if (Build.VERSION.SDK_INT < 11) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplicationLoader.applicationContext .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(str); } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext .getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("label", str); clipboard.setPrimaryClip(clip); } } selectedMessagesIds.clear(); selectedMessagesCanCopyIds.clear(); actionBarLayer.hideActionMode(); updateVisibleRows(); } else if (id == delete) { ArrayList<Integer> ids = new ArrayList<Integer>(selectedMessagesIds.keySet()); ArrayList<Long> random_ids = null; if (currentEncryptedChat != null) { random_ids = new ArrayList<Long>(); for (HashMap.Entry<Integer, MessageObject> entry : selectedMessagesIds.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); //TODO qui utilizzo un mio metodo per cancellare i messaggi, cosi' prima mostro un alert deleteMessages(ids, random_ids, currentEncryptedChat); actionBarLayer.hideActionMode(); } else if (id == forward) { Bundle args = new Bundle(); args.putBoolean("onlySelect", true); args.putBoolean("serverOnly", true); args.putString("selectAlertString", LocaleController.getString("ForwardMessagesTo", R.string.ForwardMessagesTo)); args.putString("selectAlertStringGroup", LocaleController .getString("ForwardMessagesToGroup", R.string.ForwardMessagesToGroup)); MessagesActivity fragment = new MessagesActivity(args); fragment.setDelegate(ChatActivity.this); presentFragment(fragment); } } }); updateSubtitle(); if (currentEncryptedChat != null) { actionBarLayer.setTitleIcon(R.drawable.ic_lock_white, AndroidUtilities.dp(4)); } else if (currentChat != null && currentChat.id < 0) { actionBarLayer.setTitleIcon(R.drawable.broadcast2, AndroidUtilities.dp(4)); } ActionBarMenu menu = actionBarLayer.createMenu(); if (currentEncryptedChat != null) { timeItem = menu.addItemResource(chat_enc_timer, R.layout.chat_header_enc_layout); } //TODO aggiungo il pulsante di ricerca item_search = menu.addItem(chat_menu_search, R.drawable.ic_ab_search); item_search.setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override public void onSearchExpand() { searching = true; } @Override public void onSearchCollapse() { searching = false; //MessagesController.getInstance().loadMessages(dialog_id, 0, 20, maxMessageId, !cacheEndReaced, minDate, classGuid, false, false); //NotificationCenter.getInstance().postNotificationName(dialogsNeedReload); } @Override public void onTextChanged(final EditText editText) { editText.requestFocus(); editText.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { boolean result = false; // se l'evento e' un "tasto premuto" sul tasto enter if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { //fai azione if (!editText.getText().toString().equals("")) { searchMessages(dialog_id, editText.getText().toString(), new FutureSearch()); try { presentFragment(new SearchResultsActivity( doSearchAndBlock(dialog_id, editText.getText().toString()), getArguments())); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } catch (NullPointerException e) { Log.e("xela92", "NullPointerException. Forse la connessione di rete e' assente? La ricerca stata annullata. "); e.printStackTrace(); } } result = true; } return result; } }); } }); ActionBarMenuItem item = menu.addItem(chat_menu_attach, R.drawable.ic_ab_attach); item.addSubItem(attach_photo, LocaleController.getString("ChatTakePhoto", R.string.ChatTakePhoto), R.drawable.ic_attach_photo); item.addSubItem(attach_gallery, LocaleController.getString("ChatGallery", R.string.ChatGallery), R.drawable.ic_attach_gallery); item.addSubItem(attach_video, LocaleController.getString("ChatVideo", R.string.ChatVideo), R.drawable.ic_attach_video); item.addSubItem(attach_document, LocaleController.getString("ChatDocument", R.string.ChatDocument), R.drawable.ic_ab_doc); item.addSubItem(attach_location, LocaleController.getString("ChatLocation", R.string.ChatLocation), R.drawable.ic_attach_location); menuItem = item; actionModeViews.clear(); final ActionBarMenu actionMode = actionBarLayer.createActionMode(); actionModeViews.add(actionMode.addItem(-2, R.drawable.ic_ab_done_gray, R.drawable.bar_selector_mode)); FrameLayout layout = new FrameLayout(actionMode.getContext()); layout.setBackgroundColor(0xffe5e5e5); actionMode.addView(layout); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) layout.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(1); layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT; layoutParams.topMargin = AndroidUtilities.dp(12); layoutParams.bottomMargin = AndroidUtilities.dp(12); layoutParams.gravity = Gravity.CENTER_VERTICAL; layout.setLayoutParams(layoutParams); actionModeViews.add(layout); selectedMessagesCountTextView = new TextView(actionMode.getContext()); selectedMessagesCountTextView.setTextSize(18); selectedMessagesCountTextView.setTextColor(0xff000000); selectedMessagesCountTextView.setSingleLine(true); selectedMessagesCountTextView.setLines(1); selectedMessagesCountTextView.setEllipsize(TextUtils.TruncateAt.END); selectedMessagesCountTextView.setPadding(AndroidUtilities.dp(11), 0, 0, 0); selectedMessagesCountTextView.setGravity(Gravity.CENTER_VERTICAL); selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); actionMode.addView(selectedMessagesCountTextView); layoutParams = (LinearLayout.LayoutParams) selectedMessagesCountTextView.getLayoutParams(); layoutParams.weight = 1; layoutParams.width = 0; layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT; selectedMessagesCountTextView.setLayoutParams(layoutParams); if (currentEncryptedChat == null) { actionModeViews .add(actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy, R.drawable.bar_selector_mode)); actionModeViews.add( actionMode.addItem(forward, R.drawable.ic_ab_fwd_forward, R.drawable.bar_selector_mode)); actionModeViews .add(actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete, R.drawable.bar_selector_mode)); } else { actionModeViews .add(actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy, R.drawable.bar_selector_mode)); actionModeViews .add(actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete, R.drawable.bar_selector_mode)); } actionMode.getItem(copy) .setVisibility(selectedMessagesCanCopyIds.size() != 0 ? View.VISIBLE : View.GONE); View avatarLayout = menu.addItemResource(chat_menu_avatar, R.layout.chat_header_layout); avatarImageView = (BackupImageView) avatarLayout.findViewById(R.id.chat_avatar_image); avatarImageView.processDetach = false; checkActionBarMenu(); fragmentView = inflater.inflate(R.layout.chat_layout, container, false); View contentView = fragmentView.findViewById(R.id.chat_layout); TextView emptyView = (TextView) fragmentView.findViewById(R.id.searchEmptyView); emptyViewContainer = fragmentView.findViewById(R.id.empty_view); emptyViewContainer.setVisibility(View.GONE); emptyViewContainer.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); emptyView.setText(LocaleController.getString("NoMessages", R.string.NoMessages)); chatListView = (LayoutListView) fragmentView.findViewById(R.id.chat_list_view); chatListView.setAdapter(chatAdapter = new ChatAdapter(getParentActivity())); topPanel = fragmentView.findViewById(R.id.top_panel); topPlaneClose = (ImageView) fragmentView.findViewById(R.id.top_plane_close); topPanelText = (TextView) fragmentView.findViewById(R.id.top_panel_text); bottomOverlay = fragmentView.findViewById(R.id.bottom_overlay); bottomOverlayText = (TextView) fragmentView.findViewById(R.id.bottom_overlay_text); bottomOverlayChat = fragmentView.findViewById(R.id.bottom_overlay_chat); progressView = fragmentView.findViewById(R.id.progressLayout); pagedownButton = fragmentView.findViewById(R.id.pagedown_button); pagedownButton.setVisibility(View.GONE); View progressViewInner = progressView.findViewById(R.id.progressLayoutInner); updateContactStatus(); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); int selectedBackground = preferences.getInt("selectedBackground", 1000001); int selectedColor = preferences.getInt("selectedColor", 0); if (selectedColor != 0) { contentView.setBackgroundColor(selectedColor); chatListView.setCacheColorHint(selectedColor); } else { chatListView.setCacheColorHint(0); try { if (selectedBackground == 1000001) { ((SizeNotifierRelativeLayout) contentView).setBackgroundImage(R.drawable.background_hd); } else { File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg"); if (toFile.exists()) { if (ApplicationLoader.cachedWallpaper != null) { ((SizeNotifierRelativeLayout) contentView) .setBackgroundImage(ApplicationLoader.cachedWallpaper); } else { Drawable drawable = Drawable.createFromPath(toFile.getAbsolutePath()); if (drawable != null) { ((SizeNotifierRelativeLayout) contentView).setBackgroundImage(drawable); ApplicationLoader.cachedWallpaper = drawable; } else { contentView.setBackgroundColor(-2693905); chatListView.setCacheColorHint(-2693905); } } isCustomTheme = true; } else { ((SizeNotifierRelativeLayout) contentView).setBackgroundImage(R.drawable.background_hd); } } } catch (Exception e) { contentView.setBackgroundColor(-2693905); chatListView.setCacheColorHint(-2693905); FileLog.e("tmessages", e); } } if (currentEncryptedChat != null) { emptyView.setVisibility(View.GONE); View secretChatPlaceholder = contentView.findViewById(R.id.secret_placeholder); secretChatPlaceholder.setVisibility(View.VISIBLE); if (isCustomTheme) { secretChatPlaceholder.setBackgroundResource(R.drawable.system_black); } else { secretChatPlaceholder.setBackgroundResource(R.drawable.system_blue); } secretViewStatusTextView = (TextView) contentView.findViewById(R.id.invite_text); secretChatPlaceholder.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(12), AndroidUtilities.dp(16), AndroidUtilities.dp(12)); View v = contentView.findViewById(R.id.secret_placeholder); v.setVisibility(View.VISIBLE); if (currentEncryptedChat.admin_id == UserConfig.getClientUserId()) { if (currentUser.first_name.length() > 0) { secretViewStatusTextView .setText(LocaleController.formatString("EncryptedPlaceholderTitleOutgoing", R.string.EncryptedPlaceholderTitleOutgoing, currentUser.first_name)); } else { secretViewStatusTextView .setText(LocaleController.formatString("EncryptedPlaceholderTitleOutgoing", R.string.EncryptedPlaceholderTitleOutgoing, currentUser.last_name)); } } else { if (currentUser.first_name.length() > 0) { secretViewStatusTextView .setText(LocaleController.formatString("EncryptedPlaceholderTitleIncoming", R.string.EncryptedPlaceholderTitleIncoming, currentUser.first_name)); } else { secretViewStatusTextView .setText(LocaleController.formatString("EncryptedPlaceholderTitleIncoming", R.string.EncryptedPlaceholderTitleIncoming, currentUser.last_name)); } } updateSecretStatus(); } if (isCustomTheme) { progressViewInner.setBackgroundResource(R.drawable.system_loader2); emptyView.setBackgroundResource(R.drawable.system_black); } else { progressViewInner.setBackgroundResource(R.drawable.system_loader1); emptyView.setBackgroundResource(R.drawable.system_blue); } emptyView.setPadding(AndroidUtilities.dp(7), AndroidUtilities.dp(1), AndroidUtilities.dp(7), AndroidUtilities.dp(1)); if (currentUser != null && (currentUser.id / 1000 == 333 || currentUser.id % 1000 == 0)) { emptyView.setText(LocaleController.getString("GotAQuestion", R.string.GotAQuestion)); } chatListView.setOnItemLongClickListener(onItemLongClickListener); chatListView.setOnItemClickListener(onItemClickListener); final Rect scrollRect = new Rect(); chatListView.setOnInterceptTouchEventListener(new LayoutListView.OnInterceptTouchEventListener() { @Override public boolean onInterceptTouchEvent(MotionEvent event) { if (actionBarLayer.isActionModeShowed()) { return false; } if (event.getAction() == MotionEvent.ACTION_DOWN) { int x = (int) event.getX(); int y = (int) event.getY(); int count = chatListView.getChildCount(); Rect rect = new Rect(); for (int a = 0; a < count; a++) { View view = chatListView.getChildAt(a); int top = view.getTop(); int bottom = view.getBottom(); view.getLocalVisibleRect(rect); if (top > y || bottom < y) { continue; } if (!(view instanceof ChatMediaCell)) { break; } final ChatMediaCell cell = (ChatMediaCell) view; final MessageObject messageObject = cell.getMessageObject(); if (messageObject == null || !messageObject.isSecretPhoto() || !cell.getPhotoImage().isInsideImage(x, y - top)) { break; } File file = FileLoader.getPathToMessage(messageObject.messageOwner); if (!file.exists()) { break; } startX = x; startY = y; chatListView.setOnItemClickListener(null); openSecretPhotoRunnable = new Runnable() { @Override public void run() { if (openSecretPhotoRunnable == null) { return; } chatListView.requestDisallowInterceptTouchEvent(true); chatListView.setOnItemLongClickListener(null); chatListView.setLongClickable(false); openSecretPhotoRunnable = null; if (sendSecretMessageRead(messageObject)) { cell.invalidate(); } SecretPhotoViewer.getInstance().setParentActivity(getParentActivity()); SecretPhotoViewer.getInstance().openPhoto(messageObject); } }; AndroidUtilities.RunOnUIThread(openSecretPhotoRunnable, 100); return true; } } return false; } }); chatListView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (openSecretPhotoRunnable != null || SecretPhotoViewer.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() { chatListView.setOnItemClickListener(onItemClickListener); } }, 150); if (openSecretPhotoRunnable != null) { AndroidUtilities.CancelRunOnUIThread(openSecretPhotoRunnable); openSecretPhotoRunnable = null; try { Toast.makeText(v.getContext(), LocaleController.getString("PhotoTip", R.string.PhotoTip), Toast.LENGTH_SHORT).show(); } catch (Exception e) { FileLog.e("tmessages", e); } } else { if (SecretPhotoViewer.getInstance().isVisible()) { AndroidUtilities.RunOnUIThread(new Runnable() { @Override public void run() { chatListView.setOnItemLongClickListener(onItemLongClickListener); chatListView.setLongClickable(true); } }); SecretPhotoViewer.getInstance().closePhoto(); } } } else if (event.getAction() != MotionEvent.ACTION_DOWN) { if (SecretPhotoViewer.getInstance().isVisible()) { return true; } else if (openSecretPhotoRunnable != null) { if (event.getAction() == MotionEvent.ACTION_MOVE) { if (Math.hypot(startX - event.getX(), startY - event.getY()) > AndroidUtilities .dp(5)) { AndroidUtilities.CancelRunOnUIThread(openSecretPhotoRunnable); openSecretPhotoRunnable = null; } } else { AndroidUtilities.CancelRunOnUIThread(openSecretPhotoRunnable); openSecretPhotoRunnable = null; } } } } return false; } }); chatListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (visibleItemCount > 0) { if (firstVisibleItem <= 10) { if (!endReached && !loading) { if (messagesByDays.size() != 0) { MessagesController.getInstance().loadMessages(dialog_id, 20, maxMessageId, !cacheEndReaced, minDate, classGuid, false, false, null); } else { MessagesController.getInstance().loadMessages(dialog_id, 20, 0, !cacheEndReaced, minDate, classGuid, false, false, null); } loading = true; } } if (firstVisibleItem + visibleItemCount >= totalItemCount - 6) { if (!unread_end_reached && !loadingForward) { MessagesController.getInstance().loadMessages(dialog_id, 20, minMessageId, true, maxDate, classGuid, false, true, null); loadingForward = true; } } if (firstVisibleItem + visibleItemCount == totalItemCount && unread_end_reached) { showPagedownButton(false, true); } } for (int a = 0; a < visibleItemCount; a++) { View view = absListView.getChildAt(a); if (view instanceof ChatMessageCell) { ChatMessageCell messageCell = (ChatMessageCell) view; messageCell.getLocalVisibleRect(scrollRect); messageCell.setVisiblePart(scrollRect.top, scrollRect.bottom - scrollRect.top); } } } }); bottomOverlayChatText = (TextView) fragmentView.findViewById(R.id.bottom_overlay_chat_text); TextView textView = (TextView) fragmentView.findViewById(R.id.secret_title); textView.setText( LocaleController.getString("EncryptedDescriptionTitle", R.string.EncryptedDescriptionTitle)); textView = (TextView) fragmentView.findViewById(R.id.secret_description1); textView.setText(LocaleController.getString("EncryptedDescription1", R.string.EncryptedDescription1)); textView = (TextView) fragmentView.findViewById(R.id.secret_description2); textView.setText(LocaleController.getString("EncryptedDescription2", R.string.EncryptedDescription2)); textView = (TextView) fragmentView.findViewById(R.id.secret_description3); textView.setText(LocaleController.getString("EncryptedDescription3", R.string.EncryptedDescription3)); textView = (TextView) fragmentView.findViewById(R.id.secret_description4); textView.setText(LocaleController.getString("EncryptedDescription4", R.string.EncryptedDescription4)); if (loading && messages.isEmpty()) { progressView.setVisibility(View.VISIBLE); chatListView.setEmptyView(null); } else { progressView.setVisibility(View.GONE); chatListView.setEmptyView(emptyViewContainer); } pagedownButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { scrollToLastMessage(); } }); bottomOverlayChat.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); if (currentUser != null && userBlocked) { builder.setMessage(LocaleController.getString("AreYouSureUnblockContact", R.string.AreYouSureUnblockContact)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().unblockUser(currentUser.id); } }); } 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) { MessagesController.getInstance().deleteDialog(dialog_id, 0, false); finishFragment(); } }); } builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showAlertDialog(builder); } }); updateBottomOverlay(); chatActivityEnterView.setContainerView(getParentActivity(), fragmentView); } else { ViewGroup parent = (ViewGroup) fragmentView.getParent(); if (parent != null) { parent.removeView(fragmentView); } } return fragmentView; }
From source file:org.telegram.ui.ChatActivity.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (fragmentView == null) { fragmentView = inflater.inflate(R.layout.chat_layout, container, false); sizeNotifierRelativeLayout = (SizeNotifierRelativeLayout) fragmentView.findViewById(R.id.chat_layout); sizeNotifierRelativeLayout.delegate = this; contentView = sizeNotifierRelativeLayout; emptyView = (TextView) fragmentView.findViewById(R.id.searchEmptyView); chatListView = (LayoutListView) fragmentView.findViewById(R.id.chat_list_view); chatListView.setAdapter(chatAdapter = new ChatAdapter(parentActivity)); topPanel = fragmentView.findViewById(R.id.top_panel); topPlaneClose = (ImageView) fragmentView.findViewById(R.id.top_plane_close); topPanelText = (TextView) fragmentView.findViewById(R.id.top_panel_text); bottomOverlay = fragmentView.findViewById(R.id.bottom_overlay); bottomOverlayText = (TextView) fragmentView.findViewById(R.id.bottom_overlay_text); View bottomOverlayChat = fragmentView.findViewById(R.id.bottom_overlay_chat); progressView = fragmentView.findViewById(R.id.progressLayout); pagedownButton = fragmentView.findViewById(R.id.pagedown_button); audioSendButton = (ImageButton) fragmentView.findViewById(R.id.chat_audio_send_button); View progressViewInner = progressView.findViewById(R.id.progressLayoutInner); updateContactStatus();// w w w. jav a 2 s . c o m ImageView backgroundImage = (ImageView) fragmentView.findViewById(R.id.background_image); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); int selectedBackground = preferences.getInt("selectedBackground", 1000001); int selectedColor = preferences.getInt("selectedColor", 0); if (selectedColor != 0) { backgroundImage.setBackgroundColor(selectedColor); chatListView.setCacheColorHint(selectedColor); } else { chatListView.setCacheColorHint(0); if (selectedBackground == 1000001) { backgroundImage.setImageResource(R.drawable.background_hd); } else { File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg"); if (toFile.exists()) { if (ApplicationLoader.cachedWallpaper != null) { backgroundImage.setImageBitmap(ApplicationLoader.cachedWallpaper); } else { backgroundImage.setImageURI(Uri.fromFile(toFile)); if (backgroundImage.getDrawable() instanceof BitmapDrawable) { ApplicationLoader.cachedWallpaper = ((BitmapDrawable) backgroundImage.getDrawable()) .getBitmap(); } } isCustomTheme = true; } else { backgroundImage.setImageResource(R.drawable.background_hd); } } } if (currentEncryptedChat != null) { secretChatPlaceholder = contentView.findViewById(R.id.secret_placeholder); if (isCustomTheme) { secretChatPlaceholder.setBackgroundResource(R.drawable.system_black); } else { secretChatPlaceholder.setBackgroundResource(R.drawable.system_blue); } secretViewStatusTextView = (TextView) contentView.findViewById(R.id.invite_text); secretChatPlaceholder.setPadding(Utilities.dp(16), Utilities.dp(12), Utilities.dp(16), Utilities.dp(12)); View v = contentView.findViewById(R.id.secret_placeholder); v.setVisibility(View.VISIBLE); if (currentEncryptedChat.admin_id == UserConfig.clientUserId) { if (currentUser.first_name.length() > 0) { secretViewStatusTextView .setText(String.format(getStringEntry(R.string.EncryptedPlaceholderTitleOutgoing), currentUser.first_name)); } else { secretViewStatusTextView.setText(String.format( getStringEntry(R.string.EncryptedPlaceholderTitleOutgoing), currentUser.last_name)); } } else { if (currentUser.first_name.length() > 0) { secretViewStatusTextView .setText(String.format(getStringEntry(R.string.EncryptedPlaceholderTitleIncoming), currentUser.first_name)); } else { secretViewStatusTextView.setText(String.format( getStringEntry(R.string.EncryptedPlaceholderTitleIncoming), currentUser.last_name)); } } updateSecretStatus(); } if (isCustomTheme) { progressViewInner.setBackgroundResource(R.drawable.system_loader2); emptyView.setBackgroundResource(R.drawable.system_black); } else { progressViewInner.setBackgroundResource(R.drawable.system_loader1); emptyView.setBackgroundResource(R.drawable.system_blue); } emptyView.setPadding(Utilities.dp(7), Utilities.dp(1), Utilities.dp(7), Utilities.dp(1)); if (currentUser != null && currentUser.id == 333000) { emptyView.setText(R.string.GotAQuestion); } chatListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapter, View view, int position, long id) { if (mActionMode == null) { createMenu(view, false); } return true; } }); chatListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (visibleItemCount > 0) { if (firstVisibleItem <= 4) { if (!endReached && !loading) { if (messagesByDays.size() != 0) { MessagesController.Instance.loadMessages(dialog_id, 0, 20, maxMessageId, !cacheEndReaced, minDate, classGuid, false, false); } else { MessagesController.Instance.loadMessages(dialog_id, 0, 20, 0, !cacheEndReaced, minDate, classGuid, false, false); } loading = true; } } if (firstVisibleItem + visibleItemCount >= totalItemCount - 6) { if (!unread_end_reached && !loadingForward) { MessagesController.Instance.loadMessages(dialog_id, 0, 20, minMessageId, true, maxDate, classGuid, false, true); loadingForward = true; } } if (firstVisibleItem + visibleItemCount == totalItemCount && unread_end_reached) { showPagedownButton(false, true); } } else { showPagedownButton(false, false); } } }); messsageEditText = (EditText) fragmentView.findViewById(R.id.chat_text_edit); sendButton = (ImageButton) fragmentView.findViewById(R.id.chat_send_button); sendButton.setEnabled(false); sendButton.setVisibility(View.INVISIBLE); emojiButton = (ImageView) fragmentView.findViewById(R.id.chat_smile_button); if (loading && messages.isEmpty()) { progressView.setVisibility(View.VISIBLE); chatListView.setEmptyView(null); } else { progressView.setVisibility(View.GONE); if (currentEncryptedChat == null) { chatListView.setEmptyView(emptyView); } else { chatListView.setEmptyView(secretChatPlaceholder); } } emojiButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (emojiPopup == null) { showEmojiPopup(true); } else { showEmojiPopup(!emojiPopup.isShowing()); } } }); messsageEditText.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View view, int i, KeyEvent keyEvent) { if (i == 4 && !keyboardVisible && emojiPopup != null && emojiPopup.isShowing()) { if (keyEvent.getAction() == 1) { showEmojiPopup(false); } return true; } else if (i == KeyEvent.KEYCODE_ENTER && sendByEnter && keyEvent.getAction() == KeyEvent.ACTION_DOWN) { sendMessage(); return true; } return false; } }); messsageEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_SEND) { sendMessage(); return true; } else if (sendByEnter) { if (keyEvent != null && i == EditorInfo.IME_NULL && keyEvent.getAction() == KeyEvent.ACTION_DOWN) { sendMessage(); return true; } } return false; } }); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { sendMessage(); } }); audioSendButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { startRecording(); } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { stopRecording(); } return false; } }); pagedownButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (unread_end_reached || first_unread_id == 0) { chatListView.setSelectionFromTop(messages.size() - 1, -10000 - chatListView.getPaddingTop()); } else { messages.clear(); messagesByDays.clear(); messagesDict.clear(); progressView.setVisibility(View.VISIBLE); chatListView.setEmptyView(null); maxMessageId = Integer.MAX_VALUE; minMessageId = Integer.MIN_VALUE; maxDate = Integer.MIN_VALUE; minDate = 0; MessagesController.Instance.loadMessages(dialog_id, 0, 30, 0, true, 0, classGuid, true, false); loading = true; chatAdapter.notifyDataSetChanged(); } } }); checkSendButton(); messsageEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { String message = charSequence.toString().trim(); message = message.replaceAll("\n\n+", "\n\n"); message = message.replaceAll(" +", " "); sendButton.setEnabled(message.length() != 0); checkSendButton(); if (message.length() != 0 && lastTypingTimeSend < System.currentTimeMillis() - 5000 && !ignoreTextChange) { int currentTime = ConnectionsManager.Instance.getCurrentTime(); if (currentUser != null && currentUser.status != null && currentUser.status.expires < currentTime && currentUser.status.was_online < currentTime) { return; } lastTypingTimeSend = System.currentTimeMillis(); MessagesController.Instance.sendTyping(dialog_id, classGuid); } } @Override public void afterTextChanged(Editable editable) { if (sendByEnter && editable.length() > 0 && editable.charAt(editable.length() - 1) == '\n') { sendMessage(); } int i = 0; ImageSpan[] arrayOfImageSpan = editable.getSpans(0, editable.length(), ImageSpan.class); int j = arrayOfImageSpan.length; while (true) { if (i >= j) { Emoji.replaceEmoji(editable); return; } editable.removeSpan(arrayOfImageSpan[i]); i++; } } }); bottomOverlayChat.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (currentChat != null) { MessagesController.Instance.deleteDialog(-currentChat.id, 0, false); finishFragment(); } } }); chatListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { if (mActionMode != null) { processRowSelect(view); return; } if (!spanClicked(chatListView, view, R.id.chat_message_text)) { createMenu(view, true); } } }); chatListView.setOnTouchListener(new OnSwipeTouchListener() { public void onSwipeRight() { try { if (visibleDialog != null) { visibleDialog.dismiss(); visibleDialog = null; } } catch (Exception e) { FileLog.e("tmessages", e); } finishFragment(true); } public void onSwipeLeft() { if (swipeOpening) { return; } try { if (visibleDialog != null) { visibleDialog.dismiss(); visibleDialog = null; } } catch (Exception e) { FileLog.e("tmessages", e); } if (avatarImageView != null) { swipeOpening = true; avatarImageView.performClick(); } } @Override public void onTouchUp(MotionEvent event) { mLastTouch.right = (int) event.getX(); mLastTouch.bottom = (int) event.getY(); } }); emptyView.setOnTouchListener(new OnSwipeTouchListener() { public void onSwipeRight() { finishFragment(true); } public void onSwipeLeft() { if (swipeOpening) { return; } if (avatarImageView != null) { swipeOpening = true; avatarImageView.performClick(); } } }); if (currentChat != null && (currentChat instanceof TLRPC.TL_chatForbidden || currentChat.left)) { bottomOverlayChat.setVisibility(View.VISIBLE); } else { bottomOverlayChat.setVisibility(View.GONE); } } else { ViewGroup parent = (ViewGroup) fragmentView.getParent(); if (parent != null) { parent.removeView(fragmentView); } } return fragmentView; }
From source file:xyz.klinker.blur.launcher3.Workspace.java
public void addToCustomContentPage(View customContent, Launcher.CustomContentCallbacks callbacks, String description) {//from ww w. j a va2s . co m if (getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID) < 0) { throw new RuntimeException("Expected custom content screen to exist"); } // Add the custom content to the full screen custom page CellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID); int spanX = customScreen.getCountX(); int spanY = customScreen.getCountY(); CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, spanX, spanY); lp.canReorder = false; lp.isFullscreen = true; if (customContent instanceof Insettable) { ((Insettable) customContent).setInsets(mInsets); } // Verify that the child is removed from any existing parent. if (customContent.getParent() instanceof ViewGroup) { ViewGroup parent = (ViewGroup) customContent.getParent(); parent.removeView(customContent); } customScreen.removeAllViews(); customContent.setFocusable(true); customContent.setOnKeyListener(new FullscreenKeyEventListener()); customContent.setOnFocusChangeListener(mLauncher.mFocusHandler.getHideIndicatorOnFocusListener()); customScreen.addViewToCellLayout(customContent, 0, 0, lp, true); mCustomContentDescription = description; mCustomContentCallbacks = callbacks; }
From source file:com.android.launcher3.Workspace.java
public void addToCustomContentPage(View customContent, CustomContentCallbacks callbacks, String description) { if (getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID) < 0) { throw new RuntimeException("Expected custom content screen to exist"); }//from ww w . j a v a 2s .com // Add the custom content to the full screen custom page CellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID); int spanX = customScreen.getCountX(); int spanY = customScreen.getCountY(); CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, spanX, spanY); lp.canReorder = false; lp.isFullscreen = true; if (customContent instanceof Insettable) { ((Insettable) customContent).setInsets(mInsets); } // Verify that the child is removed from any existing parent. if (customContent.getParent() instanceof ViewGroup) { ViewGroup parent = (ViewGroup) customContent.getParent(); parent.removeView(customContent); } customScreen.removeAllViews(); customScreen.addViewToCellLayout(customContent, 0, 0, lp, true); mCustomContentDescription = description; mCustomContentCallbacks = callbacks; }
From source file:com.cognizant.trumobi.PersonaLauncher.java
void closeFolder(PersonaFolder personaFolder) { personaFolder.getInfo().opened = false; ViewGroup parent = (ViewGroup) personaFolder.getParent(); if (parent != null) { parent.removeView(personaFolder); }//from w w w. j av a2 s .c om personaFolder.onClose(); }