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.artioml.practice.activities.LicenseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_license);
    setActionBar();/*from w  w w.j a va  2 s . c  o  m*/

    Button acceptButton = (Button) findViewById(R.id.acceptButton);

    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(IS_FIRST_TIME, true)) {
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayShowHomeEnabled(false);
            actionBar.setHomeButtonEnabled(false);
            actionBar.setDisplayHomeAsUpEnabled(false);
        }
    }
    if (getSharedPreferences(PERSISTENT_STORAGE, MODE_PRIVATE).getBoolean(IS_ACCEPTED, false)) {
        acceptButton.setVisibility(View.INVISIBLE);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    acceptButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getSharedPreferences(PERSISTENT_STORAGE, MODE_PRIVATE).edit().putBoolean(IS_ACCEPTED, true).apply();
            finish();
        }
    });

    final View line = findViewById(R.id.lineView);
    line.post(new Runnable() {
        @Override
        public void run() {
            BitmapDrawable parallel = drawParallelogramLine(line.getWidth());
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                line.setBackgroundDrawable(parallel);
            } else {
                line.setBackground(parallel);
            }
        }
    });

}

From source file:com.atwal.wakeup.battery.util.Utilities.java

/**
 * ???target View //from  ww w . j av a  2 s . c  o m
 *
 * @param view
 * @param ev
 * @return
 */
public static boolean inRangeOfView(View view, MotionEvent ev) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);
    int x = location[0];
    int y = location[1];
    if (ev.getX() < x || ev.getX() > (x + view.getWidth()) || ev.getY() < y
            || ev.getY() > (y + view.getHeight())) {
        return false;
    }
    return true;
}

From source file:com.facebook.appevents.codeless.internal.ViewHierarchy.java

public static JSONObject setAppearanceOfView(View view, JSONObject json, float displayDensity) {
    try {//from  w w w  .  j  a va 2s  . c  o m
        JSONObject textStyle = new JSONObject();
        if (view instanceof TextView) {
            TextView textView = (TextView) view;
            Typeface typeface = textView.getTypeface();
            if (typeface != null) {
                textStyle.put(TEXT_SIZE, textView.getTextSize());
                textStyle.put(TEXT_IS_BOLD, typeface.isBold());
                textStyle.put(TEXT_IS_ITALIC, typeface.isItalic());
                json.put(TEXT_STYLE, textStyle);
            }
        }
        if (view instanceof ImageView) {
            Drawable drawable = ((ImageView) view).getDrawable();
            if (drawable instanceof BitmapDrawable) {
                if (view.getHeight() / displayDensity <= ICON_MAX_EDGE_LENGTH
                        && view.getWidth() / displayDensity <= ICON_MAX_EDGE_LENGTH) {
                    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
                    byte[] byteArray = byteArrayOutputStream.toByteArray();
                    String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
                    json.put(ICON_BITMAP, encoded);
                }
            }
        }
    } catch (JSONException e) {
        Utility.logd(TAG, e);
    }

    return json;
}

From source file:ameircom.keymedia.Activity.transition.FabTransform.java

private void captureValues(TransitionValues transitionValues) {
    final View view = transitionValues.view;
    if (view == null || view.getWidth() <= 0 || view.getHeight() <= 0)
        return;/*from w  w w .j ava 2 s  .  c om*/

    transitionValues.values.put(PROP_BOUNDS,
            new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom()));
}

From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java

static void setBackground(View v, Bitmap bm) {

    if (bm == null) {
        v.setBackgroundResource(0);//  w w  w.j ava2 s.  co m
        return;
    }

    int vwidth = v.getWidth();
    int vheight = v.getHeight();
    int bwidth = bm.getWidth();
    int bheight = bm.getHeight();
    float scalex = (float) vwidth / bwidth;
    float scaley = (float) vheight / bheight;
    float scale = Math.max(scalex, scaley) * 1.3f;

    Bitmap.Config config = Bitmap.Config.ARGB_8888;
    Bitmap bg = Bitmap.createBitmap(vwidth, vheight, config);
    Canvas c = new Canvas(bg);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    ColorMatrix greymatrix = new ColorMatrix();
    greymatrix.setSaturation(0);
    ColorMatrix darkmatrix = new ColorMatrix();
    darkmatrix.setScale(.3f, .3f, .3f, 1.0f);
    greymatrix.postConcat(darkmatrix);
    ColorFilter filter = new ColorMatrixColorFilter(greymatrix);
    paint.setColorFilter(filter);
    Matrix matrix = new Matrix();
    matrix.setTranslate(-bwidth / 2, -bheight / 2); // move bitmap center to origin
    matrix.postRotate(10);
    matrix.postScale(scale, scale);
    matrix.postTranslate(vwidth / 2, vheight / 2); // Move bitmap center to view center
    c.drawBitmap(bm, matrix, paint);
    v.setBackgroundDrawable(new BitmapDrawable(bg));
}

From source file:com.efithealth.app.activity.BaseActivity.java

private boolean isHideInput(View v, MotionEvent ev) {
    if (v != null && (v instanceof EditText)) {
        int[] l = { 0, 0 };
        v.getLocationInWindow(l);// w w  w.  j  av  a2 s .c  om
        int left = l[0], top = l[1], bottom = top + v.getHeight(), right = left + v.getWidth();
        if (ev.getX() > left && ev.getX() < right && ev.getY() > top && ev.getY() < bottom) {
            return false;
        } else {
            return true;
        }
    }
    return false;
}

From source file:com.dk.animation.effect.out.HingeOut.java

@Override
public void startAnimation(final ViewHolder holder, long duration, final BaseItemAnimator animator) {
    ViewCompat.animate(holder.itemView).cancel();
    AnimatorSet set = new AnimatorSet();
    View target = holder.itemView;
    int abs = Math.random() > 0.5 ? -1 : 1;
    float x, y;//from   www.j a  v a2s. com
    if (abs > 0) {
        x = target.getPaddingLeft();
        y = target.getPaddingTop();
    } else {
        x = target.getWidth();
        y = target.getPaddingTop();
    }
    set.setDuration(animator.getRemoveDuration());
    set.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            animator.dispatchAddFinished(holder);
            animator.mAddAnimations.remove(holder);
            animator.dispatchFinishedWhenDone();
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }
    });

    set.playTogether(
            ObjectAnimator.ofFloat(target, "rotation", 0, abs * 80, abs * 60, abs * 80, abs * 60, abs * 60),
            ObjectAnimator.ofFloat(target, "translationY", 0, 0, 0, 0, 0, 700),
            ObjectAnimator.ofFloat(target, "alpha", 1, 1, 1, 1, 1, 0),
            ObjectAnimator.ofFloat(target, "pivotX", x, x, x, x, x, x),
            ObjectAnimator.ofFloat(target, "pivotY", y, y, y, y, y, y));
    set.setStartDelay(mDelay * mDelayCount);
    set.setDuration(animator.getAddDuration());
    set.start();

    animator.mAddAnimations.add(holder);
}

From source file:com.actionbarsherlock.internal.nineoldandroids.view.animation.AnimatorProxy.java

private void computeRect(final RectF r, View view) {
    // compute current rectangle according to matrix transformation
    final float w = view.getWidth();
    final float h = view.getHeight();

    // use a rectangle at 0,0 to make sure we don't run into issues with scaling
    r.set(0, 0, w, h);//  w w  w .  ja v  a2  s.c  o  m

    final Matrix m = mTempMatrix;
    m.reset();
    transformMatrix(m, view);
    mTempMatrix.mapRect(r);

    r.offset(view.getLeft(), view.getTop());

    // Straighten coords if rotations flipped them
    if (r.right < r.left) {
        final float f = r.right;
        r.right = r.left;
        r.left = f;
    }
    if (r.bottom < r.top) {
        final float f = r.top;
        r.top = r.bottom;
        r.bottom = f;
    }
}

From source file:com.albedinsky.android.ui.widget.CubicPageTransformer.java

/**
 *//*from   w ww. ja va 2  s  .c  om*/
@Override
public void transformPage(View page, float position) {
    final float factor = Math.abs(position);
    final int pageWidth = page.getWidth();
    final int pageHeight = page.getHeight();

    /**
     * This page is way off-screen to the start.
     * [-Infinity,-1)
     */
    if (position < -1) {
        ViewCompat.setAlpha(page, 0);
    }
    /**
     * Moving page from/to the start.
     * [-1,0]
     */
    else if (position <= 0) {
        // Fade in/out the page.
        ViewCompat.setAlpha(page, Math.max(1 - factor, mMinAlpha));

        // Rotate the page along its y axis.
        ViewCompat.setPivotX(page, pageWidth * mCameraPosition.destPivotXFactor);
        ViewCompat.setPivotX(page, pageHeight * 0.5f);
        ViewCompat.setRotationY(page, factor * mCameraPosition.destDegrees);
    }
    /**
     * Moving page from/to the end.
     * (0,1]
     */
    else if (position <= 1) {
        // Fade in/out the page.
        ViewCompat.setAlpha(page, Math.max(1 - factor, mMinAlpha));

        // Rotate the page along its y axis.
        ViewCompat.setPivotX(page, pageWidth * mCameraPosition.originPivotXFactor);
        ViewCompat.setPivotX(page, pageHeight * 0.5f);
        ViewCompat.setRotationY(page, factor * mCameraPosition.destDegrees);
    }
    /**
     * This page is way off-screen to the end.
     * (1,+Infinity]
     */
    else {
        ViewCompat.setAlpha(page, 0);
    }
}

From source file:com.example.kent_zheng.sdk_fragmenttransition.FragmentTransitionFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Meat meat = mAdapter.getItem(position);
    Log.i(TAG, meat.title + " clicked. Replacing fragment.");

    Log.d(TAG, "onItemClick: view.getX() = " + view.getX() + ", view.getY() = " + view.getY()
            + ", view.getWidth() = " + view.getWidth() + ", view.getHeight() = " + view.getHeight());

    // We start the fragment transaction here. It is just an ordinary fragment transaction.
    getActivity().getSupportFragmentManager().beginTransaction()
            .replace(R.id.sample_content_fragment,
                    DetailFragment.newInstance(meat.resourceId, meat.title, (int) view.getX(),
                            (int) view.getY(), view.getWidth(), view.getHeight()))
            // We push the fragment transaction to back stack. User can go back to the
            // previous fragment by pressing back button.
            .addToBackStack("detail").commit();
}