use of android.view.TouchDelegate in project robolectric by robolectric.
the class ShadowTouchDelegateTest method testRealObjectIsFunctional.
@Test
public void testRealObjectIsFunctional() {
// Instantiate a TouchDelegate using the Shadow construction APIs and make sure that the
// underlying real object's constructor gets instantiated by verifying that the returned object
// behaves as expected.
Rect rect = new Rect(100, 5000, 200, 6000);
TouchDelegate td = Shadow.newInstance(TouchDelegate.class, new Class[] { Rect.class, View.class }, new Object[] { rect, view });
// Make the underlying view clickable. This ensures that if a touch event does get delegated, it
// gets reported as having been handled.
view.setClickable(true);
// Verify that a touch event in the center of the rectangle is handled.
assertThat(td.onTouchEvent(MotionEvent.obtain(1, 1, MotionEvent.ACTION_DOWN, rect.centerX(), rect.centerY(), 0))).isTrue();
// Verify that a touch event outside of the rectangle is not handled.
assertThat(td.onTouchEvent(MotionEvent.obtain(1, 1, MotionEvent.ACTION_DOWN, 5f, 10f, 0))).isFalse();
}
use of android.view.TouchDelegate in project Android-Bootstrap by Bearded-Hen.
the class BootstrapAlert method updateBootstrapState.
private void updateBootstrapState() {
TextView alertText = new TextView(getContext());
closeButton = new ImageView(getContext());
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
alertText.setId(generateViewUniqueId());
closeButton.setId(generateViewUniqueId());
} else {
alertText.setId(View.generateViewId());
closeButton.setId(View.generateViewId());
}
LayoutParams textParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
LayoutParams closeParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
textParams.addRule(RelativeLayout.LEFT_OF, closeButton.getId());
closeParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
alertText.setLayoutParams(textParams);
alertText.setTextSize(baselineFontSize);
alertText.setGravity(Gravity.START);
alertText.setTextColor(BootstrapDrawableFactory.bootstrapButtonText(getContext(), true, bootstrapBrand));
alertText.setText(Html.fromHtml(String.format("<b>%s</b>%s", strongText, (strongText.length() > 0 ? " " + messageText : messageText))));
closeButton.setLayoutParams(closeParams);
Drawable buttonBg = BootstrapDrawableFactory.bootstrapAlertCloseIcon(getContext(), (int) baselineFontSize, (int) baselineFontSize, DimenUtils.dpToPixels(6));
ViewUtils.setBackgroundDrawable(closeButton, buttonBg);
Drawable bg = BootstrapDrawableFactory.bootstrapAlert(getContext(), bootstrapBrand);
ViewUtils.setBackgroundDrawable(this, bg);
addView(alertText);
if (userDismissible) {
addView(closeButton);
((View) closeButton.getParent()).post(new Runnable() {
@Override
public void run() {
Rect bounds = new Rect();
closeButton.getHitRect(bounds);
bounds.top -= DimenUtils.dpToPixels(6);
bounds.bottom += DimenUtils.dpToPixels(6);
bounds.left -= DimenUtils.dpToPixels(6);
bounds.right += DimenUtils.dpToPixels(6);
TouchDelegate touchDelegate = new TouchDelegate(bounds, closeButton);
if (View.class.isInstance(closeButton.getParent())) {
((View) closeButton.getParent()).setTouchDelegate(touchDelegate);
}
}
});
closeButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dismiss(true);
}
});
}
int vert = (int) (baselinePadding * 1.5);
int hori = (int) (baselinePadding * 1.5);
setPadding(hori, vert, hori, vert);
}
use of android.view.TouchDelegate in project Etar-Calendar by Etar-Group.
the class SelectCalendarsSimpleAdapter 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].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);
// 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;
}
use of android.view.TouchDelegate in project PhotoNoter by yydcdut.
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 Signal-Android by WhisperSystems.
the class ContactFilterView 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