Search in sources :

Example 1 with MotionEvent

use of android.view.MotionEvent in project photo-picker-plus-android by chute.

the class RippleView method init.

private void init(final Context context, final AttributeSet attrs) {
    if (isInEditMode())
        return;
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleView);
    rippleColor = typedArray.getColor(R.styleable.RippleView_rv_color, getResources().getColor(android.R.color.white));
    rippleType = typedArray.getInt(R.styleable.RippleView_rv_type, 0);
    hasToZoom = typedArray.getBoolean(R.styleable.RippleView_rv_zoom, false);
    isCentered = typedArray.getBoolean(R.styleable.RippleView_rv_centered, false);
    DURATION = typedArray.getInteger(R.styleable.RippleView_rv_rippleDuration, DURATION);
    FRAME_RATE = typedArray.getInteger(R.styleable.RippleView_rv_framerate, FRAME_RATE);
    PAINT_ALPHA = typedArray.getInteger(R.styleable.RippleView_rv_alpha, PAINT_ALPHA);
    ripplePadding = typedArray.getDimensionPixelSize(R.styleable.RippleView_rv_ripplePadding, 0);
    canvasHandler = new Handler();
    zoomScale = typedArray.getFloat(R.styleable.RippleView_rv_zoomScale, 1.03f);
    zoomDuration = typedArray.getInt(R.styleable.RippleView_rv_zoomDuration, 200);
    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(rippleColor);
    paint.setAlpha(PAINT_ALPHA);
    this.setWillNotDraw(false);
    gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {

        @Override
        public void onLongPress(MotionEvent event) {
            super.onLongPress(event);
            animateRipple(event);
            sendClickEvent(true);
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            return true;
        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return true;
        }
    });
    this.setDrawingCacheEnabled(true);
    this.setClickable(true);
}
Also used : TypedArray(android.content.res.TypedArray) Handler(android.os.Handler) GestureDetector(android.view.GestureDetector) Paint(android.graphics.Paint) MotionEvent(android.view.MotionEvent)

Example 2 with MotionEvent

use of android.view.MotionEvent in project materialistic by hidroh.

the class ItemActivityTest method testNavButtonDrag.

@Test
public void testNavButtonDrag() {
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putString(activity.getString(R.string.pref_story_display), activity.getString(R.string.pref_story_display_value_comments)).putBoolean(activity.getString(R.string.pref_navigation), true).apply();
    startWithIntent();
    View navButton = activity.findViewById(R.id.navigation_button);
    assertThat(navButton).isVisible();
    getDetector(navButton).getListener().onLongPress(mock(MotionEvent.class));
    assertThat(ShadowToast.getTextOfLatestToast()).contains(activity.getString(R.string.hint_drag));
    MotionEvent motionEvent = mock(MotionEvent.class);
    when(motionEvent.getAction()).thenReturn(MotionEvent.ACTION_MOVE);
    when(motionEvent.getRawX()).thenReturn(1f);
    when(motionEvent.getRawY()).thenReturn(1f);
    shadowOf(navButton).getOnTouchListener().onTouch(navButton, motionEvent);
    motionEvent = mock(MotionEvent.class);
    when(motionEvent.getAction()).thenReturn(MotionEvent.ACTION_UP);
    shadowOf(navButton).getOnTouchListener().onTouch(navButton, motionEvent);
    assertThat(navButton).hasX(1f).hasY(1f);
}
Also used : View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) MotionEvent(android.view.MotionEvent) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 3 with MotionEvent

use of android.view.MotionEvent in project materialistic by hidroh.

the class AppUtilsTest method testSetTextWithLinks.

@Test
public void testSetTextWithLinks() {
    TextView textView = new TextView(RuntimeEnvironment.application);
    AppUtils.setTextWithLinks(textView, AppUtils.fromHtml("<a href=\\\"http://www.justin.tv/problems/bml\\\" rel=\\\"nofollow\\\">http://www.justin.tv/problems/bml</a>"));
    MotionEvent event = mock(MotionEvent.class);
    when(event.getAction()).thenReturn(MotionEvent.ACTION_DOWN);
    when(event.getX()).thenReturn(0f);
    when(event.getY()).thenReturn(0f);
    assertTrue(shadowOf(textView).getOnTouchListener().onTouch(textView, event));
    when(event.getAction()).thenReturn(MotionEvent.ACTION_UP);
    when(event.getX()).thenReturn(0f);
    when(event.getY()).thenReturn(0f);
    assertTrue(shadowOf(textView).getOnTouchListener().onTouch(textView, event));
    assertNotNull(ShadowApplication.getInstance().getNextStartedActivity());
}
Also used : TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent) Test(org.junit.Test)

Example 4 with MotionEvent

use of android.view.MotionEvent in project Android-Iconics by mikepenz.

the class IconsFragment method configAdapter.

private void configAdapter() {
    //our popup on touch
    mAdapter.withOnTouchListener(new FastAdapter.OnTouchListener<IconItem>() {

        @Override
        public boolean onTouch(View v, MotionEvent motionEvent, IAdapter<IconItem> adapter, IconItem item, int position) {
            int a = motionEvent.getAction();
            if (a == MotionEvent.ACTION_DOWN) {
                if (popup != null && popup.isShowing()) {
                    popup.dismiss();
                }
                IconicsDrawable icon = new IconicsDrawable(v.getContext()).icon(item.getIcon()).sizeDp(144).paddingDp(8).backgroundColor(Color.parseColor("#DDFFFFFF")).roundedCornersDp(12);
                ImageView imageView = new ImageView(v.getContext());
                imageView.setImageDrawable(icon);
                int size = (int) UIUtils.convertDpToPixel(144, v.getContext());
                popup = new PopupWindow(imageView, size, size);
                popup.showAsDropDown(v);
                //copy to clipboard
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
                    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) v.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
                    clipboard.setText(icon.getIcon().getFormattedName());
                } else {
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) v.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText("Android-Iconics icon", icon.getIcon().getFormattedName());
                    clipboard.setPrimaryClip(clip);
                }
            } else if (a == MotionEvent.ACTION_UP || a == MotionEvent.ACTION_CANCEL || a == MotionEvent.ACTION_OUTSIDE) {
                if (popup != null && popup.isShowing()) {
                    popup.dismiss();
                }
            }
            return false;
        }
    });
    mAdapter.withOnBindViewHolderListener(new FastAdapter.OnBindViewHolderListener() {

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position, List payloads) {
            IconItem.ViewHolder holder = (IconItem.ViewHolder) viewHolder;
            //as we overwrite the default listener
            mAdapter.getItem(position).bindView(holder, payloads);
            if (randomize) {
                holder.image.setColorRes(getRandomColor(position));
                holder.image.setPaddingDp(random.nextInt(12));
                holder.image.setContourWidthDp(random.nextInt(2));
                holder.image.setContourColor(getRandomColor(position - 2));
                int y = random.nextInt(10);
                if (y % 4 == 0) {
                    holder.image.setBackgroundColorRes(getRandomColor(position - 4));
                    holder.image.setRoundedCornersDp(2 + random.nextInt(10));
                }
            }
        }

        @Override
        public void unBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
            IconItem item = mAdapter.getItem(position);
            if (item != null) {
                item.unbindView((IconItem.ViewHolder) viewHolder);
            }
        }
    });
}
Also used : PopupWindow(android.widget.PopupWindow) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) MotionEvent(android.view.MotionEvent) IconItem(com.mikepenz.iconics.sample.item.IconItem) RecyclerView(android.support.v7.widget.RecyclerView) AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList) List(java.util.List) FastAdapter(com.mikepenz.fastadapter.FastAdapter) ImageView(android.widget.ImageView) Context(android.content.Context) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable)

Example 5 with MotionEvent

use of android.view.MotionEvent in project nmid-headline by miao1007.

the class PlatformListPage method initPageView.

private void initPageView() {
    flPage = new FrameLayout(getContext());
    flPage.setOnClickListener(this);
    flPage.setBackgroundDrawable(new ColorDrawable(0x55000000));
    // container of the platform gridview
    llPage = new LinearLayout(getContext()) {

        public boolean onTouchEvent(MotionEvent event) {
            return true;
        }
    };
    llPage.setOrientation(LinearLayout.VERTICAL);
    llPage.setBackgroundDrawable(new ColorDrawable(0xffffffff));
    FrameLayout.LayoutParams lpLl = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
    lpLl.gravity = Gravity.BOTTOM;
    llPage.setLayoutParams(lpLl);
    flPage.addView(llPage);
    // gridview
    grid = new PlatformGridView(getContext());
    grid.setEditPageBackground(getBackgroundView());
    LinearLayout.LayoutParams lpWg = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    grid.setLayoutParams(lpWg);
    llPage.addView(grid);
    // cancel button
    btnCancel = new Button(getContext());
    btnCancel.setTextColor(0xff3a65ff);
    btnCancel.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    int resId = getStringRes(getContext(), "cancel");
    if (resId > 0) {
        btnCancel.setText(resId);
    }
    btnCancel.setPadding(0, 0, 0, com.mob.tools.utils.R.dipToPx(getContext(), 5));
    resId = getBitmapRes(getContext(), "classic_platform_corners_bg");
    if (resId > 0) {
        btnCancel.setBackgroundResource(resId);
    } else {
        btnCancel.setBackgroundDrawable(new ColorDrawable(0xffffffff));
    }
    LinearLayout.LayoutParams lpBtn = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, com.mob.tools.utils.R.dipToPx(getContext(), 45));
    int dp_10 = com.mob.tools.utils.R.dipToPx(getContext(), 10);
    lpBtn.setMargins(dp_10, dp_10, dp_10, dp_10);
    btnCancel.setLayoutParams(lpBtn);
    llPage.addView(btnCancel);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) Button(android.widget.Button) FrameLayout(android.widget.FrameLayout) LinearLayout(android.widget.LinearLayout) MotionEvent(android.view.MotionEvent)

Aggregations

MotionEvent (android.view.MotionEvent)1088 View (android.view.View)497 TextView (android.widget.TextView)264 ImageView (android.widget.ImageView)190 GestureDetector (android.view.GestureDetector)95 Point (android.graphics.Point)81 AdapterView (android.widget.AdapterView)80 ViewGroup (android.view.ViewGroup)75 Paint (android.graphics.Paint)72 ListView (android.widget.ListView)70 SuppressLint (android.annotation.SuppressLint)69 OnTouchListener (android.view.View.OnTouchListener)69 Intent (android.content.Intent)68 RecyclerView (android.support.v7.widget.RecyclerView)53 Test (org.junit.Test)47 ScrollView (android.widget.ScrollView)46 Handler (android.os.Handler)43 AbsListView (android.widget.AbsListView)42 WindowManager (android.view.WindowManager)41 LinearLayout (android.widget.LinearLayout)40