Java Code Examples for android.view.View.invalidate()

The following are Jave code examples for showing how to use invalidate() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: clickable-image-view   File: EffectTouchListener.java   Source Code and License Vote up 8 votes
@Override
public boolean onTouch(View view, MotionEvent event) {
    if (view instanceof ImageView) {
        ImageView imageView = (ImageView) view;

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN: {
                rect = new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
                imageView.setColorFilter(FILTERED_GREY, PorterDuff.Mode.SRC_ATOP);
                view.invalidate();
                break;
            }
            case MotionEvent.ACTION_MOVE:
                // if move inside button do nothing, otherwise clear filter
                if(rect.contains(view.getLeft() + (int) event.getX(), view.getTop() + (int) event.getY()))
                    break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL: // Action call when button is inside scrollable view
                imageView.clearColorFilter();
                view.invalidate();
        }
    }
    return false;
}
 
Example 2
Project: appinventor-extensions   File: ButtonBase.java   Source Code and License Vote up 7 votes
/**
 * If a custom background images is specified for the button, then it will lose the pressed
 * and disabled image effects; no visual feedback.
 * The approach below is to provide a visual feedback if and only if an image is assigned
 * to the button. In this situation, we overlay a gray background when pressed and
 * release when not-pressed.
 */
@Override
public boolean onTouch(View view, MotionEvent me)
{
    //NOTE: We ALWAYS return false because we want to indicate that this listener has not
    //been consumed. Using this approach, other listeners (e.g. OnClick) can process as normal.
    if (me.getAction() == MotionEvent.ACTION_DOWN) {
        //button pressed, provide visual feedback AND return false
        if (ShowFeedback()) {
           view.getBackground().setAlpha(70); // translucent
           view.invalidate();
        }
        TouchDown();
    } else if (me.getAction() == MotionEvent.ACTION_UP ||
        me.getAction() == MotionEvent.ACTION_CANCEL) {
        //button released, set button back to normal AND return false
        if (ShowFeedback()) {
           view.getBackground().setAlpha(255); // opaque
           view.invalidate();
        }
        TouchUp();
    }

    return false;
}
 
Example 3
Project: CSipSimple   File: AnimatorProxy.java   Source Code and License Vote up 7 votes
private void invalidateAfterUpdate() {
    View view = mView.get();
    if (view == null) {
        return;
    }
    View parent = (View)view.getParent();
    if (parent == null) {
        return;
    }

    view.setAnimation(this);

    final RectF after = mAfter;
    computeRect(after, view);
    after.union(mBefore);

    parent.invalidate(
            (int) Math.floor(after.left),
            (int) Math.floor(after.top),
            (int) Math.ceil(after.right),
            (int) Math.ceil(after.bottom));
}
 
Example 4
Project: GitHub   File: ViewPortHandler.java   Source Code and License Vote up 6 votes
/**
 * call this method to refresh the graph with a given matrix
 *
 * @param newMatrix
 * @return
 */
public Matrix refresh(Matrix newMatrix, View chart, boolean invalidate) {

    mMatrixTouch.set(newMatrix);

    // make sure scale and translation are within their bounds
    limitTransAndScale(mMatrixTouch, mContentRect);

    if (invalidate)
        chart.invalidate();

    newMatrix.set(mMatrixTouch);
    return newMatrix;
}
 
Example 5
Project: boohee_v5.6   File: FilterFigureFragment.java   Source Code and License Vote up 6 votes
public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
        case 0:
            this.lastX = (int) event.getRawX();
            this.lastY = (int) event.getRawY();
            break;
        case 2:
            int dx = ((int) event.getRawX()) - this.lastX;
            int dy = ((int) event.getRawY()) - this.lastY;
            int left = v.getLeft() + dx;
            int top = v.getTop() + dy;
            int right = v.getRight() + dx;
            int bottom = v.getBottom() + dy;
            this.lastX = (int) event.getRawX();
            this.lastY = (int) event.getRawY();
            if (left < 0) {
                right = v.getWidth();
            }
            if (right > this.screenWidth) {
                right = this.screenWidth;
                left = right - v.getWidth();
            }
            if (top < 0) {
                bottom = v.getHeight();
            }
            if (bottom > this.screenHeight) {
                bottom = this.screenHeight;
                top = bottom - v.getHeight();
            }
            v.layout(left, top, right, bottom);
            v.invalidate();
            break;
    }
    return false;
}
 
Example 6
Project: FlickLauncher   File: BubbleTextView.java   Source Code and License Vote up 6 votes
/**
 * Applies the item info if it is same as what the view is pointing to currently.
 */
public void reapplyItemInfo(final ItemInfo info) {
    if (getTag() == info) {
        FastBitmapDrawable.State prevState = FastBitmapDrawable.State.NORMAL;
        if (mIcon instanceof FastBitmapDrawable) {
            prevState = ((FastBitmapDrawable) mIcon).getCurrentState();
        }
        mIconLoadRequest = null;
        mDisableRelayout = true;

        if (info instanceof AppInfo) {
            applyFromApplicationInfo((AppInfo) info);
        } else if (info instanceof ShortcutInfo) {
            applyFromShortcutInfo((ShortcutInfo) info,
                    LauncherAppState.getInstance().getIconCache());
            if ((info.rank < FolderIcon.NUM_ITEMS_IN_PREVIEW) && (info.container >= 0)) {
                View folderIcon =
                        mLauncher.getWorkspace().getHomescreenIconByItemId(info.container);
                if (folderIcon != null) {
                    folderIcon.invalidate();
                }
            }
        } else if (info instanceof PackageItemInfo) {
            applyFromPackageItemInfo((PackageItemInfo) info);
        }

        // If we are reapplying over an old icon, then we should update the new icon to the same
        // state as the old icon
        if (mIcon instanceof FastBitmapDrawable) {
            ((FastBitmapDrawable) mIcon).setState(prevState);
        }

        mDisableRelayout = false;
    }
}
 
Example 7
Project: chromium-for-android-56-debug-video   File: ViewUtils.java   Source Code and License Vote up 6 votes
/**
 * Invalidates a view and all of its descendants.
 */
private static void recursiveInvalidate(View view) {
    view.invalidate();
    if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;
        int childCount = group.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View child = group.getChildAt(i);
            if (child.getVisibility() == View.VISIBLE) {
                recursiveInvalidate(child);
            }
        }
    }
}
 
Example 8
Project: Blockly   File: BlockGroup.java   Source Code and License Vote up 6 votes
/**
 * Force every {@link BlockView} in this group to recalculate the locations of its
 * connections; used to return the views and models to a consistent state after a drag.
 */
public void updateAllConnectorLocations() {
    int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = getChildAt(i);
        BlockView childBlockView = (BlockView) child;
        childBlockView.updateConnectorLocations();
        child.invalidate();
    }
}
 
Example 9
Project: exciting-app   File: AnimatorProxy.java   Source Code and License Vote up 6 votes
public void setAlpha(float alpha) {
    if (mAlpha != alpha) {
        mAlpha = alpha;
        View view = mView.get();
        if (view != null) {
            view.invalidate();
        }
    }
}
 
Example 10
Project: WavesView   File: DoubleWavesShaderView.java   Source Code and License Vote up 6 votes
public void setWavePos(int pos) {
    boolean changed = (offset != pos);
    offset = pos;
    View v = viewRef.get();
    if (v != null && changed)
        v.invalidate();
}
 
Example 11
Project: LuaViewPlayground   File: ForegroundDelegate.java   Source Code and License Vote up 6 votes
/**
 * Supply a Drawable that is to be rendered on top of all of the child
 * views in the frame layout.  Any padding in the Drawable will be taken
 * into account by ensuring that the children are inset to be placed
 * inside of the padding area.
 *
 * @param drawable The Drawable to be drawn on top of the children.
 */
public void setForeground(View view, Drawable drawable) {
    if (view != null) {
        if (mForeground != drawable) {
            if (mForeground != null) {
                mForeground.setCallback(null);
                view.unscheduleDrawable(mForeground);
            }

            mForeground = drawable;

            if (drawable != null) {
                view.setWillNotDraw(false);
                drawable.setCallback(view);
                if (drawable.isStateful()) {
                    drawable.setState(view.getDrawableState());
                }
                if (mForegroundGravity == Gravity.FILL) {
                    Rect padding = new Rect();
                    drawable.getPadding(padding);
                }

                //update bounds
                updateBounds(view, drawable);//added by song
            } else {
                view.setWillNotDraw(true);
            }
            view.requestLayout();
            view.invalidate();
        }
    }
}
 
Example 12
Project: appinventor-extensions   File: ViewUtil.java   Source Code and License Vote up 5 votes
public static void setBackgroundDrawable(View view, Drawable drawable) {
  view.setBackgroundDrawable(drawable);
  view.invalidate();
}
 
Example 13
Project: Hotspot-master-devp   File: CoverFlowView.java   Source Code and License Vote up 5 votes
/**
     * 对 bitmap 进行伪 3d 变换
     *
     * @param child
     * @param position
     * @param offset
     */
    private void makeChildTransfromer(View child, int position, float offset) {
        child.layout(0, 0, child.getMeasuredWidth(), child.getMeasuredHeight());

        float scale = 0;
        float scaleX = 0;
        scale = 1 - Math.abs(offset) * 0.25f;
        scaleX = 1 - Math.abs(offset) * 0.15f;

        // 延x轴移动的距离应该根据center图片决定
        float translateY = 0;

        final int originalChildHeight = (int) (mChildHeight - mChildHeight
                * reflectHeightFraction - reflectGap);

        final float originalChildHeightScale = (float) originalChildHeight / child.getHeight();

        final float childHeightScale = originalChildHeightScale * scale;
        final float childWidthScale = originalChildHeightScale * scaleX;


        final int centerChildHeight = (int) (child.getHeight() * originalChildHeightScale);

        topSpace = (mHeight-centerChildHeight)/2;
//        float baseDis = dip2px(getContext(),24);
        baseDis = centerChildHeight/4.9f;

        translateY = (mHeight-centerChildHeight)/2- baseDis *offset*-1;

        //根据offset 算出透明度
        float alpha = 254 - Math.abs(offset) * STANDARD_ALPHA;

        child.setAlpha(0);
        if (alpha < 0) {
            alpha = 0;
        } else if (alpha > 254) {
            alpha = 254;
        }
        child.setAlpha(alpha / 254.0f);

        ObjectAnimator anim1 = ObjectAnimator.ofFloat(child, "scaleX", 1.0f, childWidthScale);
        ObjectAnimator anim2 = ObjectAnimator.ofFloat(child, "scaleY", 1.0f, childHeightScale);
        AnimatorSet animSet = new AnimatorSet();
        animSet.setDuration(0);
        //两个动画同时执行
        animSet.playTogether(anim1, anim2);
        child.setPivotX(child.getWidth()/2);
        child.setPivotY(child.getHeight() / 2);
        //显示的调用invalidate
        child.invalidate();
        animSet.setTarget(child);
        animSet.start();

        child.setTranslationX(mChildTranslateX);
        child.setTranslationY(translateY);

    }
 
Example 14
Project: labelview   File: LabelViewHelper.java   Source Code and License Vote up 5 votes
public void setLabelVisual(View view, boolean visual) {
    if (this.visual != visual) {
        this.visual = visual;
        view.invalidate();
    }
}
 
Example 15
Project: labelview   File: LabelViewHelper.java   Source Code and License Vote up 5 votes
public void setLabelTextColor(View view, int textColor) {
    if (this.textColor != textColor) {
        this.textColor = textColor;
        view.invalidate();
    }
}
 
Example 16
Project: boohee_v5.6   File: ViewCompat.java   Source Code and License Vote up 5 votes
public void postInvalidateOnAnimation(View view) {
    view.invalidate();
}
 
Example 17
Project: labelview   File: LabelViewHelper.java   Source Code and License Vote up 5 votes
public void setLabelTextSize(View view, int textSize) {
    if (this.textSize != textSize) {
        this.textSize = textSize;
        view.invalidate();
    }
}
 
Example 18
Project: labelview   File: LabelViewHelper.java   Source Code and License Vote up 5 votes
public void setLabelTextStyle(View view, int textStyle){
    if(this.textStyle == textStyle) return;
    this.textStyle = textStyle;
    view.invalidate();
}
 
Example 19
Project: letv   File: ViewCompat.java   Source Code and License Vote up 5 votes
public void postInvalidateOnAnimation(View view, int left, int top, int right, int bottom) {
    view.invalidate(left, top, right, bottom);
}
 
Example 20
Project: DrinkHubGames   File: MainActivity.java   Source Code and License Vote up 5 votes
protected void setActivityBackground(Drawable drawable) {
    View view = this.getWindow().getDecorView();
    view.setBackground(drawable);
    view.invalidate();
}