use of android.view.TouchDelegate in project Resurrection_packages_apps_Settings by ResurrectionRemix.
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 AndroidUtilCode by Blankj.
the class ClickUtils method expandClickArea.
public static void expandClickArea(@NonNull final View view, final int expandSizeTop, final int expandSizeLeft, final int expandSizeRight, final int expandSizeBottom) {
final View parentView = (View) view.getParent();
if (parentView == null) {
Log.e("ClickUtils", "expandClickArea must have parent view.");
return;
}
parentView.post(new Runnable() {
@Override
public void run() {
final Rect rect = new Rect();
view.getHitRect(rect);
rect.top -= expandSizeTop;
rect.bottom += expandSizeBottom;
rect.left -= expandSizeLeft;
rect.right += expandSizeRight;
parentView.setTouchDelegate(new TouchDelegate(rect, view));
}
});
}
use of android.view.TouchDelegate in project Etar-Calendar by Etar-Group.
the class SelectCalendarsSyncAdapter method getView.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (position >= mRowCount) {
return null;
}
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;
}
use of android.view.TouchDelegate in project Signal-Android by signalapp.
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 Signal-Android by signalapp.
the class GiphyActivityToolbar 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));
}
});
}
Aggregations