List of usage examples for android.view TouchDelegate TouchDelegate
public TouchDelegate(Rect bounds, View delegateView)
From source file:Main.java
public static void enlargeBtnTouchScope(View parent, Button btn, Rect rect, float width, float height) { rect.top = btn.getTop();//from ww w. ja v a 2 s .c o m rect.bottom = btn.getBottom(); rect.left = btn.getLeft(); rect.right = btn.getRight(); rect.top -= height; rect.bottom += height; rect.left -= width; rect.right += width; parent.setTouchDelegate(new TouchDelegate(rect, btn)); }
From source file:Main.java
/** * @param top//from ww w . j a va2s. c om * @param left * @param bottom * @param right * @param delegate */ public static void increaseHitRectBy(final int top, final int left, final int bottom, final int right, final View delegate) { final View parent = (View) delegate.getParent(); if (parent != null && delegate.getContext() != null) { parent.post(new Runnable() { // Post in the parent's message queue to make sure the parent // lays out its children before we call getHitRect() public void run() { final float densityDpi = delegate.getContext().getResources().getDisplayMetrics().densityDpi; final Rect r = new Rect(); delegate.getHitRect(r); r.top -= transformToDensityPixel(top, densityDpi); r.left -= transformToDensityPixel(left, densityDpi); r.bottom += transformToDensityPixel(bottom, densityDpi); r.right += transformToDensityPixel(right, densityDpi); parent.setTouchDelegate(new TouchDelegate(r, delegate)); } }); } }
From source file:cl.monsoon.s1next.binding.TextViewBindingAdapter.java
@BindingAdapter("increaseClickingArea") public static void increaseClickingArea(TextView textView, float size) { // fork from http://stackoverflow.com/a/1343796 View parent = (View) textView.getParent(); // post in the parent's message queue to make sure the parent // lays out its children before we call View#getHitRect() parent.post(() -> {//from w ww. j a v a 2 s . co m final int halfSize = (int) (size / 2 + 0.5); Rect rect = new Rect(); textView.getHitRect(rect); rect.top -= halfSize; rect.right += halfSize; rect.bottom += halfSize; rect.left -= halfSize; // use TouchDelegate to increase count's clicking area parent.setTouchDelegate(new TouchDelegate(rect, textView)); }); }
From source file:org.chromium.chrome.browser.omnibox.LocationBarPhone.java
@Override protected void onFinishInflate() { super.onFinishInflate(); mFirstVisibleFocusedView = findViewById(R.id.url_bar); mIncognitoBadge = findViewById(R.id.incognito_badge); mIncognitoBadgePadding = getResources().getDimensionPixelSize(R.dimen.location_bar_incognito_badge_padding); mGoogleGContainer = findViewById(R.id.google_g_container); mGoogleG = findViewById(R.id.google_g); mGoogleGWidth = getResources().getDimensionPixelSize(R.dimen.location_bar_google_g_width); mGoogleGMargin = getResources().getDimensionPixelSize(R.dimen.location_bar_google_g_margin); mUrlActionsContainer = findViewById(R.id.url_action_container); Rect delegateArea = new Rect(); mUrlActionsContainer.getHitRect(delegateArea); delegateArea.left -= ACTION_BUTTON_TOUCH_OVERFLOW_LEFT; TouchDelegate touchDelegate = new TouchDelegate(delegateArea, mUrlActionsContainer); assert mUrlActionsContainer.getParent() == this; setTouchDelegate(touchDelegate);/*from w ww. j a va2 s. co m*/ mMenuButton = (TintedImageButton) findViewById(R.id.document_menu_button); mMenuBadge = (ImageView) findViewById(R.id.document_menu_badge); mMenuButtonWrapper = findViewById(R.id.document_menu_button_wrapper); ((ViewGroup) mMenuButtonWrapper.getParent()).removeView(mMenuButtonWrapper); }
From source file:com.xandy.calendar.selectcalendars.SelectCalendarsSyncAdapter.java
@Override public View getView(final int position, View convertView, ViewGroup parent) { if (position >= mRowCount) { return null; }// w w w .j a va2 s.co m String name = mData[position].displayName; boolean selected = mData[position].synced; int color = Utils.getDisplayColorFromColor(mData[position].color); View view; if (convertView == null) { view = mInflater.inflate(LAYOUT, parent, false); final View delegate = view.findViewById(R.id.color); final View delegateParent = (View) delegate.getParent(); delegateParent.post(new Runnable() { @Override public void run() { final Rect r = new Rect(); delegate.getHitRect(r); r.top -= mColorViewTouchAreaIncrease; r.bottom += mColorViewTouchAreaIncrease; r.left -= mColorViewTouchAreaIncrease; r.right += mColorViewTouchAreaIncrease; delegateParent.setTouchDelegate(new TouchDelegate(r, delegate)); } }); } else { view = convertView; } view.setTag(mData[position]); CheckBox cb = (CheckBox) view.findViewById(R.id.sync); cb.setChecked(selected); if (selected) { setText(view, R.id.status, mSyncedString); } else { setText(view, R.id.status, mNotSyncedString); } View colorView = view.findViewById(R.id.color); colorView.setEnabled(hasMoreColors(position)); colorView.setBackgroundColor(color); colorView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Purely for sanity check--view should be disabled if account has no more colors if (!hasMoreColors(position)) { return; } if (mColorPickerDialog == null) { mColorPickerDialog = CalendarColorPickerDialog.newInstance(mData[position].id, mIsTablet); } else { mColorPickerDialog.setCalendarId(mData[position].id); } mFragmentManager.executePendingTransactions(); if (!mColorPickerDialog.isAdded()) { mColorPickerDialog.show(mFragmentManager, COLOR_PICKER_DIALOG_TAG); } } }); setText(view, R.id.calendar, name); return view; }
From source file:com.tingtingapps.securesms.ContactSelectionActivity.java
private void expandTapArea(final View container, final View child, final int padding) { container.post(new Runnable() { @Override// w w w . j av a2 s .co m public void run() { Rect rect = new Rect(); child.getHitRect(rect); rect.top -= padding; rect.left -= padding; rect.right += padding; rect.bottom += padding; container.setTouchDelegate(new TouchDelegate(rect, child)); } }); }
From source file:com.android.calendar.selectcalendars.SelectCalendarsSimpleAdapter.java
@Override public View getView(final int position, View convertView, ViewGroup parent) { if (position >= mRowCount) { return null; }//ww w . jav a 2 s .co m String name = mData[position].displayName; boolean selected = mData[position].selected; int color = Utils.getDisplayColorFromColor(mData[position].color); View view; if (convertView == null) { view = mInflater.inflate(mLayout, parent, false); final View delegate = view.findViewById(R.id.color); final View delegateParent = (View) delegate.getParent(); delegateParent.post(new Runnable() { @Override public void run() { final Rect r = new Rect(); delegate.getHitRect(r); r.top -= mColorViewTouchAreaIncrease; r.bottom += mColorViewTouchAreaIncrease; r.left -= mColorViewTouchAreaIncrease; r.right += mColorViewTouchAreaIncrease; delegateParent.setTouchDelegate(new TouchDelegate(r, delegate)); } }); } else { view = convertView; } TextView calendarName = (TextView) view.findViewById(R.id.calendar); calendarName.setText(name); View colorView = view.findViewById(R.id.color); colorView.setBackgroundColor(color); colorView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Purely for sanity check--view should be disabled if account has no more colors if (!hasMoreColors(position)) { return; } if (mColorPickerDialog == null) { mColorPickerDialog = CalendarColorPickerDialog.newInstance(mData[position].id, mIsTablet); } else { mColorPickerDialog.setCalendarId(mData[position].id); } mFragmentManager.executePendingTransactions(); if (!mColorPickerDialog.isAdded()) { mColorPickerDialog.show(mFragmentManager, COLOR_PICKER_DIALOG_TAG); } } }); int textColor; if (selected) { textColor = mColorCalendarVisible; } else { textColor = mColorCalendarHidden; } calendarName.setTextColor(textColor); CheckBox syncCheckBox = (CheckBox) view.findViewById(R.id.sync); if (syncCheckBox != null) { // Full screen layout syncCheckBox.setChecked(selected); colorView.setEnabled(hasMoreColors(position)); LayoutParams layoutParam = calendarName.getLayoutParams(); TextView secondaryText = (TextView) view.findViewById(R.id.status); if (!TextUtils.isEmpty(mData[position].ownerAccount) && !mData[position].ownerAccount.equals(name) && !mData[position].ownerAccount.endsWith("calendar.google.com")) { int secondaryColor; if (selected) { secondaryColor = mColorCalendarSecondaryVisible; } else { secondaryColor = mColorCalendarSecondaryHidden; } secondaryText.setText(mData[position].ownerAccount); secondaryText.setTextColor(secondaryColor); secondaryText.setVisibility(View.VISIBLE); layoutParam.height = LayoutParams.WRAP_CONTENT; } else { secondaryText.setVisibility(View.GONE); layoutParam.height = LayoutParams.MATCH_PARENT; } calendarName.setLayoutParams(layoutParam); } else { // Tablet layout view.findViewById(R.id.color).setEnabled(selected && hasMoreColors(position)); view.setBackgroundDrawable(getBackground(position, selected)); ViewGroup.LayoutParams newParams = view.getLayoutParams(); if (position == mData.length - 1) { newParams.height = BOTTOM_ITEM_HEIGHT; } else { newParams.height = NORMAL_ITEM_HEIGHT; } view.setLayoutParams(newParams); CheckBox visibleCheckBox = (CheckBox) view.findViewById(R.id.visible_check_box); if (visibleCheckBox != null) { visibleCheckBox.setChecked(selected); } } view.invalidate(); return view; }
From source file:com.sutromedia.android.core.PhotoActivity.java
private void setupTouchOnPlayButton() { View playButton = findViewById(R.image.play_slideshow); Rect expandedSize = new Rect(); playButton.getHitRect(expandedSize); expandedSize.inset(30, 30);/*from ww w . j a v a2 s. c om*/ TouchDelegate delegate = new TouchDelegate(expandedSize, playButton); View parent = (View) playButton.getParent(); parent.setTouchDelegate(delegate); }
From source file:com.android.calendar.selectcalendars.SelectSyncedCalendarsMultiAccountAdapter.java
@Override protected void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild) { final long id = cursor.getLong(ID_COLUMN); String name = cursor.getString(NAME_COLUMN); String owner = cursor.getString(OWNER_COLUMN); final String accountName = cursor.getString(ACCOUNT_COLUMN); final String accountType = cursor.getString(ACCOUNT_TYPE_COLUMN); int color = Utils.getDisplayColorFromColor(cursor.getInt(COLOR_COLUMN)); final View colorSquare = view.findViewById(R.id.color); colorSquare.setEnabled(mCache.hasColors(accountName, accountType)); colorSquare.setBackgroundColor(color); final View delegateParent = (View) colorSquare.getParent(); delegateParent.post(new Runnable() { @Override//w ww . j a v a 2 s.c o m public void run() { final Rect r = new Rect(); colorSquare.getHitRect(r); r.top -= mColorViewTouchAreaIncrease; r.bottom += mColorViewTouchAreaIncrease; r.left -= mColorViewTouchAreaIncrease; r.right += mColorViewTouchAreaIncrease; delegateParent.setTouchDelegate(new TouchDelegate(r, colorSquare)); } }); colorSquare.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!mCache.hasColors(accountName, accountType)) { return; } if (mColorPickerDialog == null) { mColorPickerDialog = CalendarColorPickerDialog.newInstance(id, mIsTablet); } else { mColorPickerDialog.setCalendarId(id); } mFragmentManager.executePendingTransactions(); if (!mColorPickerDialog.isAdded()) { mColorPickerDialog.show(mFragmentManager, COLOR_PICKER_DIALOG_TAG); } } }); if (mIsDuplicateName.containsKey(name) && mIsDuplicateName.get(name) && !name.equalsIgnoreCase(owner)) { name = new StringBuilder(name).append(Utils.OPEN_EMAIL_MARKER).append(owner) .append(Utils.CLOSE_EMAIL_MARKER).toString(); } setText(view, R.id.calendar, name); // First see if the user has already changed the state of this calendar Boolean sync = mCalendarChanges.get(id); if (sync == null) { sync = cursor.getInt(SYNCED_COLUMN) == 1; mCalendarInitialStates.put(id, sync); } CheckBox button = (CheckBox) view.findViewById(R.id.sync); button.setChecked(sync); setText(view, R.id.status, sync ? mSyncedText : mNotSyncedText); view.setTag(TAG_ID_CALENDAR_ID, id); view.setTag(TAG_ID_SYNC_CHECKBOX, button); view.setOnClickListener(this); }
From source file:com.wanderingcan.floatingactionmenu.FloatingActionMenu.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { switch (mExpandDirection) { case UP:/*from w w w.jav a 2s . co m*/ //Fall through case DOWN: boolean expandUp = mExpandDirection == UP; if (changed) { mTouchDelegateGroup.clearTouchDelegates(); } int addButtonTop = expandUp ? b - t - mMenuButton.getMeasuredHeight() - getPaddingBottom() : getPaddingTop(); // Ensure mMenuButton is centered on the line where the buttons should be int buttonsHorizontalCenter = mLabelsPosition == LABELS_LEFT ? r - l - mMaxButtonWidth / 2 - getPaddingRight() : mMaxButtonWidth / 2 + getPaddingLeft(); int addButtonLeft = buttonsHorizontalCenter - mMenuButton.getMeasuredWidth() / 2; int buttonPaddingHeight = expandUp ? (mContentPadding / 2) : (-mContentPadding / 2); int buttonPaddingWidth = mLabelsPosition == LABELS_LEFT ? (mContentPadding / 2) : (-mContentPadding / 2); mMenuButton.layout(addButtonLeft - buttonPaddingWidth, addButtonTop - buttonPaddingHeight, addButtonLeft + mMenuButton.getMeasuredWidth() - buttonPaddingWidth, addButtonTop + mMenuButton.getMeasuredHeight() - buttonPaddingHeight); int labelsOffset = mMaxButtonWidth / 2 + mLabelsMargin; int labelsXNearButton = mLabelsPosition == LABELS_LEFT ? buttonsHorizontalCenter - labelsOffset : buttonsHorizontalCenter + labelsOffset; int nextY = expandUp ? addButtonTop - mButtonMargin : addButtonTop + mMenuButton.getMeasuredHeight() + mButtonMargin; for (int i = 0; i < mButtonsCount; i++) { final View child = getChildAt(i); if (child == mMenuButton || child.getVisibility() == GONE) continue; int childX = buttonsHorizontalCenter - child.getMeasuredWidth() / 2; int childY = expandUp ? nextY - child.getMeasuredHeight() : nextY; child.layout(childX - buttonPaddingWidth, childY - buttonPaddingHeight, childX + child.getMeasuredWidth() - buttonPaddingWidth, childY + child.getMeasuredHeight() - buttonPaddingHeight); if (!isMenuOpened) { ((FloatingActionButton) child).hide(false); } LabelView label = (LabelView) child.getTag(R.id.fab_label); if (label != null) { int labelXAwayFromButton = mLabelsPosition == LABELS_LEFT ? labelsXNearButton - label.getMeasuredWidth() : labelsXNearButton + label.getMeasuredWidth(); int labelLeft = mLabelsPosition == LABELS_LEFT ? labelXAwayFromButton : labelsXNearButton; int labelRight = mLabelsPosition == LABELS_LEFT ? labelsXNearButton : labelXAwayFromButton; int labelTop = childY + (child.getMeasuredHeight() - label.getMeasuredHeight()) / 2; label.layout(labelLeft, labelTop - buttonPaddingHeight, labelRight, labelTop + label.getMeasuredHeight() - buttonPaddingHeight); Rect touchArea = new Rect(Math.min(childX, labelLeft), childY - mButtonMargin / 2, Math.max(childX + child.getMeasuredWidth(), labelRight), childY + child.getMeasuredHeight() + mButtonMargin / 2); mTouchDelegateGroup.addTouchDelegate(new TouchDelegate(touchArea, child)); if (!isMenuOpened) { label.hide(false); } } nextY = expandUp ? childY - mButtonMargin : childY + child.getMeasuredHeight() + mButtonMargin; } break; case LEFT: //Fall through case RIGHT: boolean expandLeft = mExpandDirection == LEFT; addButtonLeft = expandLeft ? r - l - mMenuButton.getMeasuredWidth() - getPaddingLeft() : getPaddingRight(); // Ensure mMenuButton is centered on the line where the buttons should be addButtonTop = b - t - mMaxButtonHeight + (mMaxButtonHeight - mMenuButton.getMeasuredHeight()) / 2; buttonPaddingHeight = (mContentPadding / 2); buttonPaddingWidth = expandLeft ? (mContentPadding / 2) : (-mContentPadding / 2); mMenuButton.layout(addButtonLeft - buttonPaddingWidth, addButtonTop - buttonPaddingHeight, addButtonLeft + mMenuButton.getMeasuredWidth() - buttonPaddingWidth, addButtonTop + mMenuButton.getMeasuredHeight() - buttonPaddingHeight); int nextX = expandLeft ? addButtonLeft - mButtonMargin : addButtonLeft + mMenuButton.getMeasuredWidth() + mButtonMargin; for (int i = 0; i < mButtonsCount; i++) { final View child = getChildAt(i); if (child == mMenuButton || child.getVisibility() == GONE) continue; int childX = expandLeft ? nextX - child.getMeasuredWidth() : nextX; int childY = addButtonTop + (mMenuButton.getMeasuredHeight() - child.getMeasuredHeight()) / 2; child.layout(childX - buttonPaddingWidth, childY - buttonPaddingHeight, childX + child.getMeasuredWidth() - buttonPaddingWidth, childY + child.getMeasuredHeight() - buttonPaddingHeight); if (!isMenuOpened) { ((FloatingActionButton) child).hide(false); } nextX = expandLeft ? childX - mButtonMargin : childX + child.getMeasuredWidth() + mButtonMargin; } break; } }