Example usage for android.view View getWidth

List of usage examples for android.view View getWidth

Introduction

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

Prototype

@ViewDebug.ExportedProperty(category = "layout")
public final int getWidth() 

Source Link

Document

Return the width of your view.

Usage

From source file:com.android.deskclock.alarms.AlarmActivity.java

private Animator getAlertAnimator(final View source, final int titleResId, final String infoText,
        final String accessibilityText, final int revealColor, final int backgroundColor) {
    final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content);

    final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth());
    containerView.offsetDescendantRectToMyCoords(source, sourceBounds);

    final int centerX = sourceBounds.centerX();
    final int centerY = sourceBounds.centerY();

    final int xMax = Math.max(centerX, containerView.getWidth() - centerX);
    final int yMax = Math.max(centerY, containerView.getHeight() - centerY);

    final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f;
    final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax);

    final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY)
            .setFillColor(revealColor);/*from   w  w w  .  java2 s. co  m*/
    containerView.addView(revealView);

    // TODO: Fade out source icon over the reveal (like LOLLIPOP version).

    final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius,
            endRadius);
    revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS);
    revealAnimator.setInterpolator(REVEAL_INTERPOLATOR);
    revealAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.setVisibility(View.VISIBLE);
            mAlertTitleView.setText(titleResId);

            if (infoText != null) {
                mAlertInfoView.setText(infoText);
                mAlertInfoView.setVisibility(View.VISIBLE);
            }
            mContentView.setVisibility(View.GONE);

            getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor));
        }
    });

    final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS);
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            containerView.removeView(revealView);
        }
    });

    final AnimatorSet alertAnimator = new AnimatorSet();
    alertAnimator.play(revealAnimator).before(fadeAnimator);
    alertAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.announceForAccessibility(accessibilityText);
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    finish();
                }
            }, ALERT_DISMISS_DELAY_MILLIS);
        }
    });

    return alertAnimator;
}

From source file:com.pitchedapps.primenumbercalculator.Calculator.java

License:asdf

void exitReveal(View view) {
    // previously visible view
    final View myView = view;

    // get the initial radius for the clipping circle
    int initialRadius = Math.max(myView.getWidth(), myView.getHeight());

    // create the animation (the final radius is zero)
    Animator anim = ViewAnimationUtils.createCircularReveal(myView, x, y, initialRadius, 0).setDuration(600);

    // make the view invisible when the animation is done
    anim.addListener(new AnimatorListenerAdapter() {
        @Override//from ww  w . ja v a 2  s. co m
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            myView.setVisibility(View.INVISIBLE);
        }
    });

    // start the animation
    anim.start();
}

From source file:com.example.george.sharedelementimplementation.MainActivity.java

@Override
public void onBackPressed() {
    if (mIsInFullscreen) {
        if (!mIsAnimationPlaying) {

            View view = mGridView.getViewByPosition(mPager.getCurrentItem());

            Drawable drawable = ((ImageView) view).getDrawable();

            mImage.setImageDrawable(drawable);
            mImage.setVisibility(View.VISIBLE);

            final float drawableWidth = drawable.getIntrinsicWidth();
            final float drawableHeight = drawable.getIntrinsicHeight();
            final float heightWidthRatio = drawableHeight / drawableWidth;
            final int thumbnailWidth = view.getWidth();
            final int thumbnailHeight = view.getHeight();

            int[] viewLocation = new int[2];
            int[] gridViewLocation = new int[2];
            view.getLocationOnScreen(viewLocation);
            mGridView.getLocationOnScreen(gridViewLocation);
            final int thumbnailX = viewLocation[0] + view.getWidth() / 2;
            final int thumbnailY = viewLocation[1] + view.getHeight() / 2;
            final int fullscreenX = gridViewLocation[0] + mGridView.getWidth() / 2;
            final int fullscreenY = gridViewLocation[1] + mGridView.getHeight() / 2;
            Log.d(TAG, "viewLocation=" + viewLocation[0] + ", " + "" + viewLocation[1] + "\ngridViewLocation="
                    + gridViewLocation[0] + ", " + "" + gridViewLocation[1]);
            Log.d(TAG, "thumbnailX=" + thumbnailX + ", thumbnailY=" + thumbnailY + "\nfullscreenX="
                    + fullscreenX + ", fullscreenY=" + fullscreenY);
            Log.d(TAG,/*  w w  w.  j  av a  2  s  .  c  om*/
                    "(thumbnailWidth, thumbnailHeight)=(" + thumbnailWidth + ", " + "" + thumbnailHeight + ")");
            Log.d(TAG, "drawableHeight=" + drawableHeight + "\ndrawableWidth=" + drawableWidth
                    + "\nheightWidthRatio=" + heightWidthRatio);

            // Figure out where the thumbnail and full size versions are, relative
            // to the screen and each other
            mXDelta = thumbnailX - fullscreenX;
            mYDelta = thumbnailY - fullscreenY;

            // Scale factors to make the large version
            // the same size as the thumbnail
            if (heightWidthRatio < 1) {
                mImageScale = (float) thumbnailHeight / mImage.getLayoutParams().height;
            } else {
                mImageScale = (float) thumbnailWidth / mImage.getLayoutParams().width;
            }

            if (heightWidthRatio < 1) {
                // is the original picture is in landscape
                clipRatio = 1 - heightWidthRatio;
            } else {
                // if the original picture in portrait
                clipRatio = 1 - 1 / heightWidthRatio;
            }

            Log.d(TAG, "*************************Exit Animation*************************");
            Log.d(TAG, "(mXDelta, mTopDelta)=(" + mXDelta + ", " + mYDelta + ")\nmImageScale=" + mImageScale
                    + "\nclipRatio=" + clipRatio);

            // reset image translation
            mImage.setTranslationX(0);
            mImage.setTranslationY(0);

            runExitAnimation();
        }
    } else {
        super.onBackPressed();
    }
}

From source file:com.example.lining.mydemo.animator.MyItemAnimator.java

private void animateRemoveImpl(final ViewHolder holder) {
    final View view = holder.itemView;//ItemView
    final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);//?
    mRemoveAnimations.add(holder);//?VIew
    animation.setDuration(getRemoveDuration())//
            .translationX(view.getWidth()).setListener(new VpaListenerAdapter() {//listener??
                @Override/*  w  w w  .  j av a 2s  .c o  m*/
                public void onAnimationStart(View view) {
                    dispatchRemoveStarting(holder);
                }

                @Override
                public void onAnimationEnd(View view) {
                    animation.setListener(null);//???
                    //ViewCompat.setAlpha(view, 1);//??????
                    ViewCompat.setTranslationX(view, 0);//??????
                    dispatchRemoveFinished(holder);
                    mRemoveAnimations.remove(holder);
                    dispatchFinishedWhenDone();
                }
            }).start();
}

From source file:com.example.camera360.ui.ImageGridFragment.java

@TargetApi(16)
@Override/*from  w  ww .  j  a va 2  s .c o m*/
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    final Intent i = new Intent(activity, ImageDetailActivity.class);
    i.putExtra(ImageDetailActivity.EXTRA_IMAGE, (int) id);
    i.putExtra(ImageDetailActivity.IMAGE_URL, arrayList);
    if (Utils.hasJellyBean()) {
        // makeThumbnailScaleUpAnimation() looks kind of ugly here as the
        // loading spinner may
        // show plus the thumbnail image in GridView is cropped. so using
        // makeScaleUpAnimation() instead.
        ActivityOptions options = ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getWidth(), v.getHeight());
        activity.startActivity(i, options.toBundle());
    } else {
        startActivity(i);
    }
}

From source file:com.battlelancer.seriesguide.ui.ShowsFragment.java

@TargetApi(16)
@Override/* w w w  .  j  av a2 s .  c om*/
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    // display overview for this show

    Intent i = new Intent(getActivity(), OverviewActivity.class);
    i.putExtra(OverviewFragment.InitBundle.SHOW_TVDBID, (int) id);

    ActivityCompat.startActivity(getActivity(), i, ActivityOptionsCompat
            .makeScaleUpAnimation(view, 0, 0, view.getWidth(), view.getHeight()).toBundle());
}

From source file:com.battlelancer.seriesguide.ui.EpisodesFragment.java

/**
 * Display the episode at the given position in a detail pane or if not available in a new
 * activity.//w  w w  .j a  v a  2 s .co m
 */
private void showDetails(View view, int position) {
    if (mDualPane) {
        EpisodesActivity activity = (EpisodesActivity) getActivity();
        activity.setCurrentPage(position);
        setItemChecked(position);
    } else {
        int episodeId = (int) getListView().getItemIdAtPosition(position);

        Intent intent = new Intent();
        intent.setClass(getActivity(), EpisodesActivity.class);
        intent.putExtra(EpisodesActivity.InitBundle.EPISODE_TVDBID, episodeId);

        ActivityCompat.startActivity(getActivity(), intent, ActivityOptionsCompat
                .makeScaleUpAnimation(view, 0, 0, view.getWidth(), view.getHeight()).toBundle());
    }
}

From source file:com.intel.xdk.multitouch.MultiTouch.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    //get convenience reference to activity
    activity = cordova.getActivity();//from  w  w  w. ja va 2s. c  o m

    activity.runOnUiThread(new Runnable() {
        public void run() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                try {
                    Method m = WebView.class.getMethod("setWebContentsDebuggingEnabled", boolean.class);
                    m.invoke(WebView.class, true);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //WebView.setWebContentsDebuggingEnabled(true);
            }
        }
    });

    touchy = new View.OnTouchListener() {

        private SparseArray<Long> pointerId2Identifier = new SparseArray<Long>();

        @Override
        public boolean onTouch(View v, MotionEvent ev) {
            if (isMultitouchEnabled) {
                int pointerCount = ev.getPointerCount();

                //get the correct action
                int maskedAction = ev.getActionMasked();
                int idx = ev.getActionIndex();
                try {
                    String js = null;
                    if (maskedAction == MotionEvent.ACTION_POINTER_DOWN
                            || maskedAction == MotionEvent.ACTION_DOWN) {
                        int x = (int) ev.getX(idx);
                        int y = (int) ev.getY(idx);
                        int h = (int) v.getHeight();
                        int w = (int) v.getWidth();
                        int id = ev.getPointerId(idx);
                        //make a timestamp identifier and store it
                        long identifier = System.currentTimeMillis();
                        pointerId2Identifier.put(id, identifier);
                        js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchstart'},", identifier, x, y,
                                h, w);
                        queueMultitouchData(js, id, maskedAction);
                    } else if (maskedAction == MotionEvent.ACTION_POINTER_UP
                            || maskedAction == MotionEvent.ACTION_UP) {
                        int x = (int) ev.getX(idx);
                        int y = (int) ev.getY(idx);
                        int h = (int) v.getHeight();
                        int w = (int) v.getWidth();
                        int id = ev.getPointerId(idx);
                        js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchend'},",
                                pointerId2Identifier.get(id), x, y, h, w);
                        pointerId2Identifier.remove(id);
                        queueMultitouchData(js, id, maskedAction);
                    } else if (maskedAction == MotionEvent.ACTION_MOVE) {
                        //send all events if it is a move
                        for (int i = 0; i < pointerCount; i++) {
                            int x = (int) ev.getX(i);
                            int y = (int) ev.getY(i);
                            int h = (int) v.getHeight();
                            int w = (int) v.getWidth();
                            int id = ev.getPointerId(i);
                            js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchmove'},",
                                    pointerId2Identifier.get(id), x, y, h, w);
                            queueMultitouchData(js, id, maskedAction);
                        }
                    } else {
                        Log.e("[intel.xdk]", "got a MotionEvent that is not up/down/move:" + ev);
                    }
                    //Log.i("[intel.xdk]", "onTouchEvent:"+js);
                } catch (Exception e) {
                    Log.e("[intel.xdk]", "Got an exception back from WebView: ", e);
                }

                return true;
            } else {
                return false;
            }
        }
    };
    webView.setOnTouchListener(touchy);

    lock = this;
    messages = new ArrayList<String>(0);
}

From source file:com.insthub.O2OMobile.Activity.C17_ApplyFormActivity.java

/**
 * popwindow// www . j ava2  s .c o m
 *
 * @param parent
 */
private void showPopWindow(View parent) {
    int id = parent.getId();
    switch (id) {
    case R.id.service_type:
        if (mServiceListPopwindow == null) {
            LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            mServicePopwindowView = layoutInflater.inflate(R.layout.service_type_popwindow, null);
            mServicePopwindowListView = (ListView) mServicePopwindowView
                    .findViewById(R.id.service_type_pop_listview);
            mServiceListPopwindow = new PopupWindow(mServicePopwindowView, parent.getWidth(),
                    AbsoluteLayout.LayoutParams.WRAP_CONTENT, true);

        }
        if (mServiceTypePopAdapter == null) {
            mServiceTypePopAdapter = new ServiceTypePopAdapter(this, mServiceModel.publicServiceTypeList);
            mServicePopwindowListView.setAdapter(mServiceTypePopAdapter);
        }
        mServiceListPopwindow.setFocusable(true);
        // ?
        mServiceListPopwindow.setOutsideTouchable(true);
        mServiceTypeArrow.setImageResource(R.drawable.b4_arrow_up);
        // Back???
        mServiceListPopwindow.setBackgroundDrawable(new BitmapDrawable());
        mServiceListPopwindow.showAsDropDown(parent);
        mServiceListPopwindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                mServiceTypeArrow.setImageResource(R.drawable.b3_arrow_down);
            }
        });
        mServicePopwindowListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                SERVICE_TYPE serviceType = mServiceTypeList.get(position);
                mServiceTypeId = serviceType.id;
                mServiceTypeTitle.setText(serviceType.title);
                mServiceModel.publicIsSecondCategory = false;
                mServiceModel.getCategoryList(mServiceTypeId);
                mServiceListPopwindow.dismiss();
            }
        });
        break;
    case R.id.first_category:
        if (mFirstCategoryListPopwindow == null) {
            LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            mFirstCategoryPopWindowView = layoutInflater.inflate(R.layout.first_category_popwindow, null);
            mFirstCategoryPopWindowListView = (ListView) mFirstCategoryPopWindowView
                    .findViewById(R.id.first_category_pop_listview);
            mFirstCategoryListPopwindow = new PopupWindow(mFirstCategoryPopWindowView, parent.getWidth(),
                    AbsoluteLayout.LayoutParams.WRAP_CONTENT, true);

        }
        if (mFirstCategoryPopAdapter == null) {
            mFirstCategoryPopAdapter = new FirstCategoryPopAdapter(this, mFirstCategoryList);
            mFirstCategoryPopWindowListView.setAdapter(mFirstCategoryPopAdapter);
        } else {
            mFirstCategoryPopAdapter.publicFirstCategoryList = mFirstCategoryList;
            mFirstCategoryPopAdapter.notifyDataSetChanged();
        }
        mFirstCategoryListPopwindow.setFocusable(true);
        // ?
        mFirstCategoryListPopwindow.setOutsideTouchable(true);
        mFirstCategoryArrow.setImageResource(R.drawable.b4_arrow_up);
        // Back???
        mFirstCategoryListPopwindow.setBackgroundDrawable(new BitmapDrawable());
        mFirstCategoryListPopwindow.showAsDropDown(parent);
        mFirstCategoryListPopwindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                mFirstCategoryArrow.setImageResource(R.drawable.b3_arrow_down);
            }
        });
        mFirstCategoryPopWindowListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                SERVICE_CATEGORY service_category = mFirstCategoryList.get(position);
                mFirstClassServiceCategory = service_category.id;
                mFirstCategoryTitle.setText(service_category.title);
                mServiceModel.publicIsSecondCategory = true;
                mServiceModel.getCategoryList(mFirstClassServiceCategory);
                mFirstCategoryListPopwindow.dismiss();
            }
        });
        break;
    case R.id.second_category:
        if (mSecondCategoryListPopwindow == null) {
            LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            mSecondCategoryPopWindowView = layoutInflater.inflate(R.layout.second_category_popwindow, null);
            mSecondCategoryPopWindowListView = (ListView) mSecondCategoryPopWindowView
                    .findViewById(R.id.second_category_pop_listview);
            mSecondCategoryListPopwindow = new PopupWindow(mSecondCategoryPopWindowView, parent.getWidth(),
                    AbsoluteLayout.LayoutParams.WRAP_CONTENT, true);

        }
        if (mSecondCategoryPopAdapter == null) {
            mSecondCategoryPopAdapter = new SecondCategoryPopAdapter(this, mSecondCategoryList);
            mSecondCategoryPopWindowListView.setAdapter(mSecondCategoryPopAdapter);
        } else {
            mSecondCategoryPopAdapter.publicSecondCategoryList = mSecondCategoryList;
            mSecondCategoryPopAdapter.notifyDataSetChanged();
        }

        mSecondCategoryListPopwindow.setFocusable(true);
        // ?
        mSecondCategoryListPopwindow.setOutsideTouchable(true);
        mSecondCategoryArrow.setImageResource(R.drawable.b4_arrow_up);
        // Back???
        mSecondCategoryListPopwindow.setBackgroundDrawable(new BitmapDrawable());
        mSecondCategoryListPopwindow.showAsDropDown(parent);
        mSecondCategoryListPopwindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                mSecondCategoryArrow.setImageResource(R.drawable.b3_arrow_down);
            }
        });
        mSecondCategoryPopWindowListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                SERVICE_CATEGORY service_category = mSecondCategoryList.get(position);
                mSecondVlassServiceCategory = service_category.id;
                mSecondCategoryTitle.setText(service_category.title);
                mServiceModel.publicIsSecondCategory = true;
                mSecondCategoryListPopwindow.dismiss();
            }
        });
        break;
    }

}

From source file:com.devbrackets.android.recyclerext.decoration.ReorderDecoration.java

/**
 * Updates the stored position for the start of the view.  This will be the
 * top when Vertical and left when Horizontal.
 *
 * @param childPosition The position of the view in the RecyclerView
 * @param draggedUp True if the view has been moved up or to the left
 *///  w w w  .j  av  a  2 s .c o  m
private void updateNewViewStart(int childPosition, boolean draggedUp) {
    View view = recyclerView.getLayoutManager().getChildAt(childPosition);
    if (view == null) {
        return;
    }

    int start = orientation == LayoutOrientation.VERTICAL ? view.getTop() : view.getLeft();
    int viewDimen = orientation == LayoutOrientation.VERTICAL ? view.getHeight() : view.getWidth();
    viewDimen *= draggedUp ? -1 : 1;

    newViewStart = start + (view.getVisibility() == View.VISIBLE ? viewDimen : 0);
}