use of android.view.TouchDelegate in project Signal-Android by WhisperSystems.
the class ContactFilterToolbar method expandTapArea.
private void expandTapArea(final View container, final View child) {
final int padding = getResources().getDimensionPixelSize(R.dimen.contact_selection_actions_tap_area);
container.post(new Runnable() {
@Override
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));
}
});
}
use of android.view.TouchDelegate in project Etar-Calendar by Etar-Group.
the class SelectSyncedCalendarsMultiAccountAdapter method bindChildView.
@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
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);
}
use of android.view.TouchDelegate in project android_packages_apps_crDroidSettings by crdroidandroid.
the class FloatingActionsMenu method onLayout.
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
switch(mExpandDirection) {
case EXPAND_UP:
case EXPAND_DOWN:
boolean expandUp = mExpandDirection == EXPAND_UP;
if (changed) {
mTouchDelegateGroup.clearTouchDelegates();
}
int addButtonY = expandUp ? b - t - mAddButton.getMeasuredHeight() : 0;
// Ensure mAddButton is centered on the line where the buttons should be
int buttonsHorizontalCenter = mLabelsPosition == LABELS_ON_LEFT_SIDE ? r - l - mMaxButtonWidth / 2 : mMaxButtonWidth / 2;
int addButtonLeft = buttonsHorizontalCenter - mAddButton.getMeasuredWidth() / 2;
mAddButton.layout(addButtonLeft, addButtonY, addButtonLeft + mAddButton.getMeasuredWidth(), addButtonY + mAddButton.getMeasuredHeight());
int labelsOffset = mMaxButtonWidth / 2 + mLabelsMargin;
int labelsXNearButton = mLabelsPosition == LABELS_ON_LEFT_SIDE ? buttonsHorizontalCenter - labelsOffset : buttonsHorizontalCenter + labelsOffset;
int nextY = expandUp ? addButtonY - mButtonSpacing : addButtonY + mAddButton.getMeasuredHeight() + mButtonSpacing;
for (int i = mButtonsCount - 1; i >= 0; i--) {
final View child = getChildAt(i);
if (child == mAddButton || child.getVisibility() == GONE)
continue;
int childX = buttonsHorizontalCenter - child.getMeasuredWidth() / 2;
int childY = expandUp ? nextY - child.getMeasuredHeight() : nextY;
child.layout(childX, childY, childX + child.getMeasuredWidth(), childY + child.getMeasuredHeight());
float collapsedTranslation = addButtonY - childY;
float expandedTranslation = 0f;
child.setTranslationY(mExpanded ? expandedTranslation : collapsedTranslation);
child.setAlpha(mExpanded ? 1f : 0f);
LayoutParams params = (LayoutParams) child.getLayoutParams();
params.mCollapseDir.setFloatValues(expandedTranslation, collapsedTranslation);
params.mExpandDir.setFloatValues(collapsedTranslation, expandedTranslation);
params.setAnimationsTarget(child);
View label = (View) child.getTag(R.id.fab_label);
if (label != null) {
int labelXAwayFromButton = mLabelsPosition == LABELS_ON_LEFT_SIDE ? labelsXNearButton - label.getMeasuredWidth() : labelsXNearButton + label.getMeasuredWidth();
int labelLeft = mLabelsPosition == LABELS_ON_LEFT_SIDE ? labelXAwayFromButton : labelsXNearButton;
int labelRight = mLabelsPosition == LABELS_ON_LEFT_SIDE ? labelsXNearButton : labelXAwayFromButton;
int labelTop = childY - mLabelsVerticalOffset + (child.getMeasuredHeight() - label.getMeasuredHeight()) / 2;
label.layout(labelLeft, labelTop, labelRight, labelTop + label.getMeasuredHeight());
Rect touchArea = new Rect(Math.min(childX, labelLeft), childY - mButtonSpacing / 2, Math.max(childX + child.getMeasuredWidth(), labelRight), childY + child.getMeasuredHeight() + mButtonSpacing / 2);
mTouchDelegateGroup.addTouchDelegate(new TouchDelegate(touchArea, child));
label.setTranslationY(mExpanded ? expandedTranslation : collapsedTranslation);
label.setAlpha(mExpanded ? 1f : 0f);
LayoutParams labelParams = (LayoutParams) label.getLayoutParams();
labelParams.mCollapseDir.setFloatValues(expandedTranslation, collapsedTranslation);
labelParams.mExpandDir.setFloatValues(collapsedTranslation, expandedTranslation);
labelParams.setAnimationsTarget(label);
}
nextY = expandUp ? childY - mButtonSpacing : childY + child.getMeasuredHeight() + mButtonSpacing;
}
break;
case EXPAND_LEFT:
case EXPAND_RIGHT:
boolean expandLeft = mExpandDirection == EXPAND_LEFT;
int addButtonX = expandLeft ? r - l - mAddButton.getMeasuredWidth() : 0;
// Ensure mAddButton is centered on the line where the buttons should be
int addButtonTop = b - t - mMaxButtonHeight + (mMaxButtonHeight - mAddButton.getMeasuredHeight()) / 2;
mAddButton.layout(addButtonX, addButtonTop, addButtonX + mAddButton.getMeasuredWidth(), addButtonTop + mAddButton.getMeasuredHeight());
int nextX = expandLeft ? addButtonX - mButtonSpacing : addButtonX + mAddButton.getMeasuredWidth() + mButtonSpacing;
for (int i = mButtonsCount - 1; i >= 0; i--) {
final View child = getChildAt(i);
if (child == mAddButton || child.getVisibility() == GONE)
continue;
int childX = expandLeft ? nextX - child.getMeasuredWidth() : nextX;
int childY = addButtonTop + (mAddButton.getMeasuredHeight() - child.getMeasuredHeight()) / 2;
child.layout(childX, childY, childX + child.getMeasuredWidth(), childY + child.getMeasuredHeight());
float collapsedTranslation = addButtonX - childX;
float expandedTranslation = 0f;
child.setTranslationX(mExpanded ? expandedTranslation : collapsedTranslation);
child.setAlpha(mExpanded ? 1f : 0f);
LayoutParams params = (LayoutParams) child.getLayoutParams();
params.mCollapseDir.setFloatValues(expandedTranslation, collapsedTranslation);
params.mExpandDir.setFloatValues(collapsedTranslation, expandedTranslation);
params.setAnimationsTarget(child);
nextX = expandLeft ? childX - mButtonSpacing : childX + child.getMeasuredWidth() + mButtonSpacing;
}
break;
}
}
use of android.view.TouchDelegate in project android_packages_apps_crDroidSettings by crdroidandroid.
the class TouchDelegateGroup method onTouchEvent.
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
if (!mEnabled)
return false;
TouchDelegate delegate = null;
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
for (int i = 0; i < mTouchDelegates.size(); i++) {
TouchDelegate touchDelegate = mTouchDelegates.get(i);
if (touchDelegate.onTouchEvent(event)) {
mCurrentTouchDelegate = touchDelegate;
return true;
}
}
break;
case MotionEvent.ACTION_MOVE:
delegate = mCurrentTouchDelegate;
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
delegate = mCurrentTouchDelegate;
mCurrentTouchDelegate = null;
break;
}
return delegate != null && delegate.onTouchEvent(event);
}
use of android.view.TouchDelegate in project AndroidStudy by tinggengyan.
the class TouchDelegateActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_touchdelegate);
// Get the parent view
View parentView = findViewById(R.id.parent_layout);
final ImageButton myButton = (ImageButton) findViewById(R.id.touchdelegateButton);
parentView.post(new Runnable() {
// Post in the parent's message queue to make sure the parent lays out its children before you call getHitRect()
@Override
public void run() {
// The bounds for the delegate view (an ImageButton in this example)
Rect delegateArea = new Rect();
myButton.setEnabled(true);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(TouchDelegateActivity.this, "Touch occurred within ImageButton touch region.", Toast.LENGTH_SHORT).show();
}
});
// The hit rectangle for the ImageButton
myButton.getHitRect(delegateArea);
// Extend the touch area of the ImageButton beyond its bounds
// on the right and bottom.
delegateArea.right += 200;
delegateArea.bottom += 200;
// Instantiate a TouchDelegate.
// "delegateArea" is the bounds in local coordinates of
// the containing view to be mapped to the delegate view.
// "myButton" is the child view that should receive motion
// events.
TouchDelegate touchDelegate = new TouchDelegate(delegateArea, myButton);
// within the touch delegate bounds are routed to the child.
if (View.class.isInstance(myButton.getParent())) {
((View) myButton.getParent()).setTouchDelegate(touchDelegate);
}
}
});
}
Aggregations