Search in sources :

Example 21 with TouchDelegate

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();
}
Also used : Rect(android.graphics.Rect) TouchDelegate(android.view.TouchDelegate) Test(org.junit.Test)

Example 22 with TouchDelegate

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 ? "&nbsp;" + 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);
}
Also used : Rect(android.graphics.Rect) Drawable(android.graphics.drawable.Drawable) TextView(android.widget.TextView) TouchDelegate(android.view.TouchDelegate) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Example 23 with TouchDelegate

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;
}
Also used : Rect(android.graphics.Rect) ViewGroup(android.view.ViewGroup) TouchDelegate(android.view.TouchDelegate) TextView(android.widget.TextView) View(android.view.View) CheckBox(android.widget.CheckBox) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView)

Example 24 with TouchDelegate

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);
}
Also used : TouchDelegate(android.view.TouchDelegate)

Example 25 with TouchDelegate

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));
        }
    });
}
Also used : Rect(android.graphics.Rect) TouchDelegate(android.view.TouchDelegate)

Aggregations

TouchDelegate (android.view.TouchDelegate)28 Rect (android.graphics.Rect)21 View (android.view.View)12 TextView (android.widget.TextView)9 CheckBox (android.widget.CheckBox)4 OnClickListener (android.view.View.OnClickListener)3 ViewGroup (android.view.ViewGroup)2 SuppressLint (android.annotation.SuppressLint)1 Drawable (android.graphics.drawable.Drawable)1 RecyclerView (android.support.v7.widget.RecyclerView)1 AdapterView (android.widget.AdapterView)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 Before (org.junit.Before)1 Test (org.junit.Test)1