Example usage for android.view View setPressed

List of usage examples for android.view View setPressed

Introduction

In this page you can find the example usage for android.view View setPressed.

Prototype

public void setPressed(boolean pressed) 

Source Link

Document

Sets the pressed state for this view.

Usage

From source file:Main.java

public static Bitmap convertViewToBitmap(View comBitmap, int width, int height) {
    Bitmap bitmap = null;/*from  w  w  w  .j  ava2  s. c o  m*/
    if (comBitmap != null) {
        comBitmap.clearFocus();
        comBitmap.setPressed(false);

        boolean willNotCache = comBitmap.willNotCacheDrawing();
        comBitmap.setWillNotCacheDrawing(false);

        // Reset the drawing cache background color to fully transparent
        // for the duration of this operation
        int color = comBitmap.getDrawingCacheBackgroundColor();
        comBitmap.setDrawingCacheBackgroundColor(0);
        float alpha = comBitmap.getAlpha();
        comBitmap.setAlpha(1.0f);

        if (color != 0) {
            comBitmap.destroyDrawingCache();
        }

        int widthSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
        int heightSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
        comBitmap.measure(widthSpec, heightSpec);
        comBitmap.layout(0, 0, width, height);

        comBitmap.buildDrawingCache();
        Bitmap cacheBitmap = comBitmap.getDrawingCache();
        if (cacheBitmap == null) {
            Log.e("view.ProcessImageToBlur", "failed getViewBitmap(" + comBitmap + ")", new RuntimeException());
            return null;
        }
        bitmap = Bitmap.createBitmap(cacheBitmap);
        // Restore the view
        comBitmap.setAlpha(alpha);
        comBitmap.destroyDrawingCache();
        comBitmap.setWillNotCacheDrawing(willNotCache);
        comBitmap.setDrawingCacheBackgroundColor(color);
    }
    return bitmap;
}

From source file:net.soulwolf.meetrecycle.SimpleClickListener.java

@Override
public void onShowPress(MotionEvent e) {
    View view = getChildViewUnder(e);
    if (view != null) {
        view.setPressed(true);
    }/*from   w  w  w . j ava  2s .  co m*/
}

From source file:net.soulwolf.meetrecycle.SimpleClickListener.java

@Override
public boolean onSingleTapUp(MotionEvent e) {
    View view = getChildViewUnder(e);
    if (view == null)
        return false;
    view.setPressed(false);
    int position = shiftAdjustInt(mRecyclerView.getChildAdapterPosition(view));
    if (position != -1) {
        this.onItemClick(mRecyclerView, view, position);
    }//from   ww  w.  ja  va  2s .c  o  m
    return true;
}

From source file:net.soulwolf.meetrecycle.SimpleClickListener.java

@Override
public void onLongPress(MotionEvent e) {
    View view = getChildViewUnder(e);
    if (view == null)
        return;//from w w  w .ja  v a2s . c  om
    int position = shiftAdjustInt(mRecyclerView.getChildAdapterPosition(view));
    if (position != -1) {
        this.onItemLongClick(mRecyclerView, view, position);
    }
    view.setPressed(false);
}

From source file:android.support.v7.widget.DropDownListView.java

private void clearPressedItem() {
    mDrawsInPressedState = false;/*from   w  w  w .  j  a  v  a  2 s. c om*/
    setPressed(false);
    // This will call through to updateSelectorState()
    drawableStateChanged();

    final View motionView = getChildAt(mMotionPosition - getFirstVisiblePosition());
    if (motionView != null) {
        motionView.setPressed(false);
    }

    if (mClickAnimation != null) {
        mClickAnimation.cancel();
        mClickAnimation = null;
    }
}

From source file:android.support.v7.internal.view.menu.BaseMenuPresenter.java

/**
 * Reuses item views when it can//  w  ww . j ava 2 s  . c  o  m
 */
public void updateMenuView(boolean cleared) {
    final ViewGroup parent = (ViewGroup) mMenuView;
    if (parent == null)
        return;

    int childIndex = 0;
    if (mMenu != null) {
        mMenu.flagActionItems();
        ArrayList<MenuItemImpl> visibleItems = mMenu.getVisibleItems();
        final int itemCount = visibleItems.size();
        for (int i = 0; i < itemCount; i++) {
            MenuItemImpl item = visibleItems.get(i);
            if (shouldIncludeItem(childIndex, item)) {
                final View convertView = parent.getChildAt(childIndex);
                final MenuItemImpl oldItem = convertView instanceof MenuView.ItemView
                        ? ((MenuView.ItemView) convertView).getItemData()
                        : null;
                final View itemView = getItemView(item, convertView, parent);
                if (item != oldItem) {
                    // Don't let old states linger with new data.
                    itemView.setPressed(false);
                    ViewCompat.jumpDrawablesToCurrentState(itemView);
                }
                if (itemView != convertView) {
                    addItemView(itemView, childIndex);
                }
                childIndex++;
            }
        }
    }

    // Remove leftover views.
    while (childIndex < parent.getChildCount()) {
        if (!filterLeftoverView(parent, childIndex)) {
            childIndex++;
        }
    }
}

From source file:org.kesar.lazy.lazychat.presentation.module.chat.ChatActivity.java

@OnTouch(R.id.mBtnPressToSpeak)
boolean onTouchToSpeak(View v, MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        v.setPressed(true);
        if (mVoiceDialog == null) {
            mVoiceDialog = VoiceVolumeDialog.newInstance(toChatUserName, this);
        }/*from   www.j ava2s.  c o m*/
        mVoiceDialog.show(getSupportFragmentManager());
        break;
    case MotionEvent.ACTION_MOVE:
        if (mVoiceDialog != null && mVoiceDialog.getState() != VoiceVolumeDialog.STATE_LOADING) {
            float x = event.getX();
            float y = event.getY();
            if (x < 0 || y < 0 || y > v.getWidth()) {
                mVoiceDialog.showCancel();
            } else {
                mVoiceDialog.showVolume();
            }
        }
        break;
    default:
        v.setPressed(false);
        mVoiceDialog.dismiss();
        break;
    }
    return true;
}

From source file:com.actionbarsherlock.internal.view.menu.BaseMenuPresenter.java

/**
 * Reuses item views when it can/*from  w w w.  j ava 2s  .  c o m*/
 */
public void updateMenuView(boolean cleared) {
    final ViewGroup parent = (ViewGroup) mMenuView;
    if (parent == null)
        return;

    int childIndex = 0;
    if (mMenu != null) {
        mMenu.flagActionItems();
        ArrayList<MenuItemImpl> visibleItems = mMenu.getVisibleItems();
        final int itemCount = visibleItems.size();
        for (int i = 0; i < itemCount; i++) {
            MenuItemImpl item = visibleItems.get(i);
            if (shouldIncludeItem(childIndex, item)) {
                final View convertView = parent.getChildAt(childIndex);
                final MenuItemImpl oldItem = convertView instanceof MenuView.ItemView
                        ? ((MenuView.ItemView) convertView).getItemData()
                        : null;
                final View itemView = getItemView(item, convertView, parent);
                if (item != oldItem) {
                    // Don't let old states linger with new data.
                    itemView.setPressed(false);
                    if (IS_HONEYCOMB)
                        itemView.jumpDrawablesToCurrentState();
                }
                if (itemView != convertView) {
                    addItemView(itemView, childIndex);
                }
                childIndex++;
            }
        }
    }

    // Remove leftover views.
    while (childIndex < parent.getChildCount()) {
        if (!filterLeftoverView(parent, childIndex)) {
            childIndex++;
        }
    }
}

From source file:android.support.v7.widget.DropDownListView.java

private void setPressedItem(View child, int position, float x, float y) {
    mDrawsInPressedState = true;/*from  w w  w.  j  a v  a  2s.  c  o  m*/

    // Ordering is essential. First, update the container's pressed state.
    if (Build.VERSION.SDK_INT >= 21) {
        drawableHotspotChanged(x, y);
    }
    if (!isPressed()) {
        setPressed(true);
    }

    // Next, run layout to stabilize child positions.
    layoutChildren();

    // Manage the pressed view based on motion position. This allows us to
    // play nicely with actual touch and scroll events.
    if (mMotionPosition != INVALID_POSITION) {
        final View motionView = getChildAt(mMotionPosition - getFirstVisiblePosition());
        if (motionView != null && motionView != child && motionView.isPressed()) {
            motionView.setPressed(false);
        }
    }
    mMotionPosition = position;

    // Offset for child coordinates.
    final float childX = x - child.getLeft();
    final float childY = y - child.getTop();
    if (Build.VERSION.SDK_INT >= 21) {
        child.drawableHotspotChanged(childX, childY);
    }
    if (!child.isPressed()) {
        child.setPressed(true);
    }

    // Ensure that keyboard focus starts from the last touched position.
    positionSelectorLikeTouchCompat(position, child, x, y);

    // This needs some explanation. We need to disable the selector for this next call
    // due to the way that ListViewCompat works. Otherwise both ListView and ListViewCompat
    // will draw the selector and bad things happen.
    setSelectorEnabled(false);

    // Refresh the drawable state to reflect the new pressed state,
    // which will also update the selector state.
    refreshDrawableState();
}

From source file:com.gh4a.adapter.RootAdapter.java

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (holder instanceof FooterViewHolder) {
        if (mFooterListener != null) {
            mFooterListener.onScrolledToFooter();
        }//from  w w  w .j a  va  2 s  .  co m
    } else if (!(holder instanceof HeaderViewHolder)) {
        onBindViewHolder((VH) holder, getItemFromAdapterPosition(position));
        if (position == mHighlightPosition) {
            final View v = holder.itemView;
            v.post(new Runnable() {
                @Override
                public void run() {
                    if (v.getBackground() != null) {
                        final int centerX = v.getWidth() / 2;
                        final int centerY = v.getHeight() / 2;
                        DrawableCompat.setHotspot(v.getBackground(), centerX, centerY);
                    }
                    v.setPressed(true);
                    v.setPressed(false);
                    mHighlightPosition = -1;
                }
            });
        }
    }
}