Example usage for android.graphics RectF RectF

List of usage examples for android.graphics RectF RectF

Introduction

In this page you can find the example usage for android.graphics RectF RectF.

Prototype

public RectF(float left, float top, float right, float bottom) 

Source Link

Document

Create a new rectangle with the specified coordinates.

Usage

From source file:com.mooc.viewpage_photoview_circleindicator.photoview.PhotoViewAttacher.java

/**
 * Calculate Matrix for FIT_CENTER/* w ww  . ja  v a 2  s.c om*/
 *
 * @param d - Drawable being displayed
 */
private void updateBaseMatrix(Drawable d, boolean isFirst) {
    ImageView imageView = getImageView();
    if (null == imageView || null == d) {
        return;
    }

    //?ImageViewdrawable
    final float viewWidth = getImageViewWidth(imageView);
    final float viewHeight = getImageViewHeight(imageView);
    final int drawableWidth = d.getIntrinsicWidth();
    final int drawableHeight = d.getIntrinsicHeight();

    mBaseMatrix.reset();

    final float widthScale = viewWidth / drawableWidth;
    final float heightScale = viewHeight / drawableHeight;

    if (mScaleType == ScaleType.CENTER) {
        mBaseMatrix.postTranslate((viewWidth - drawableWidth) / 2F, (viewHeight - drawableHeight) / 2F);

    } else if (mScaleType == ScaleType.CENTER_CROP) {
        float scale = Math.max(widthScale, heightScale);
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else if (mScaleType == ScaleType.CENTER_INSIDE) {
        float scale = Math.min(1.0f, Math.min(widthScale, heightScale));
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else {
        RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight);
        RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight);

        if ((int) mBaseRotation % 180 != 0) {
            mTempSrc = new RectF(0, 0, drawableHeight, drawableWidth);
        }

        switch (mScaleType) {

        case FIT_CENTER:
            //scaleType

            final float mutiple = (float) PhotoViewHelper.screenWidth(imageView.getContext())
                    / ((float) drawableWidth);

            mBaseMatrix.setScale(mutiple, mutiple, 0, 0);

            //                    mBaseMatrix
            //                            .setRectToRect(mTempSrc, mTempDst, ScaleToFit.CENTER);

            break;

        case FIT_START:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.START);
            break;

        case FIT_END:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.END);
            break;

        case FIT_XY:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.FILL);
            break;

        default:
            break;
        }
    }

    resetMatrix();
}

From source file:com.offsync.view.photoview.PhotoViewAttacher.java

/**
 * Calculate Matrix for FIT_CENTER/*w w  w . j av  a 2s  .  co m*/
 *
 * @param d - Drawable being displayed
 */
private void updateBaseMatrix(Drawable d) {
    ImageView imageView = getImageView();
    if (null == imageView || null == d) {
        return;
    }

    final float viewWidth = getImageViewWidth(imageView);
    final float viewHeight = getImageViewHeight(imageView);
    final int drawableWidth = d.getIntrinsicWidth();
    final int drawableHeight = d.getIntrinsicHeight();

    mBaseMatrix.reset();

    final float widthScale = viewWidth / drawableWidth;
    final float heightScale = viewHeight / drawableHeight;

    if (mScaleType == ScaleType.CENTER) {
        mBaseMatrix.postTranslate((viewWidth - drawableWidth) / 2F, (viewHeight - drawableHeight) / 2F);

    } else if (mScaleType == ScaleType.CENTER_CROP) {
        float scale = Math.max(widthScale, heightScale);
        mBaseMatrix.postScale(scale, scale);
        //Changed dy = 0 for top crop
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F, 0);

    } else if (mScaleType == ScaleType.CENTER_INSIDE) {
        float scale = Math.min(1.0f, Math.min(widthScale, heightScale));
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else {
        RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight);
        RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight);

        if ((int) mBaseRotation % 180 != 0) {
            mTempSrc = new RectF(0, 0, drawableHeight, drawableWidth);
        }

        switch (mScaleType) {
        case FIT_CENTER:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.CENTER);
            break;

        case FIT_START:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.START);
            break;

        case FIT_END:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.END);
            break;

        case FIT_XY:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.FILL);
            break;

        default:
            break;
        }
    }

    resetMatrix();
}

From source file:com.meiqia.meiqiasdk.third.photoview.PhotoViewAttacher.java

/**
 * Calculate Matrix for FIT_CENTER/*w w w. j a v a2  s  . c  o m*/
 *
 * @param d - Drawable being displayed
 */
protected void updateBaseMatrix(Drawable d) {
    ImageView imageView = getImageView();
    if (null == imageView || null == d) {
        return;
    }

    final float viewWidth = getImageViewWidth(imageView);
    final float viewHeight = getImageViewHeight(imageView);
    final int drawableWidth = d.getIntrinsicWidth();
    final int drawableHeight = d.getIntrinsicHeight();

    mBaseMatrix.reset();

    final float widthScale = viewWidth / drawableWidth;
    final float heightScale = viewHeight / drawableHeight;

    if (mScaleType == ScaleType.CENTER) {
        mBaseMatrix.postTranslate((viewWidth - drawableWidth) / 2F, (viewHeight - drawableHeight) / 2F);

    } else if (mScaleType == ScaleType.CENTER_CROP) {
        float scale = Math.max(widthScale, heightScale);
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else if (mScaleType == ScaleType.CENTER_INSIDE) {
        float scale = Math.min(1.0f, Math.min(widthScale, heightScale));
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else {
        RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight);
        RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight);

        if ((int) mBaseRotation % 180 != 0) {
            mTempSrc = new RectF(0, 0, drawableHeight, drawableWidth);
        }

        switch (mScaleType) {
        case FIT_CENTER:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.CENTER);
            break;

        case FIT_START:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.START);
            break;

        case FIT_END:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.END);
            break;

        case FIT_XY:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.FILL);
            break;

        default:
            break;
        }
    }

    resetMatrix();
}

From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java

/**
 * Calculate Matrix for FIT_CENTER// w w w .  j  ava 2  s. c o  m
 *
 * @param d - Drawable being displayed
 */
private void updateBaseMatrix(Drawable d) {
    ImageView imageView = getImageView();
    if (null == imageView || null == d) {
        return;
    }

    final float viewWidth = getImageViewWidth(imageView);
    final float viewHeight = getImageViewHeight(imageView);
    final int drawableWidth = d.getIntrinsicWidth();
    final int drawableHeight = d.getIntrinsicHeight();

    mBaseMatrix.reset();

    final float widthScale = viewWidth / drawableWidth;
    final float heightScale = viewHeight / drawableHeight;

    if (mScaleType == ScaleType.CENTER) {
        mBaseMatrix.postTranslate((viewWidth - drawableWidth) / 2F, (viewHeight - drawableHeight) / 2F);

    } else if (mScaleType == ScaleType.CENTER_CROP) {
        float scale = Math.max(widthScale, heightScale);
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else if (mScaleType == ScaleType.CENTER_INSIDE) {
        float scale = Math.min(1.0f, Math.min(widthScale, heightScale));
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else {
        RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight);
        RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight);

        if ((int) mBaseRotation % 180 != 0) {
            mTempSrc = new RectF(0, 0, drawableHeight, drawableWidth);
        }

        switch (mScaleType) {
        case FIT_CENTER:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.CENTER);
            break;

        case FIT_START:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.START);
            break;

        case FIT_END:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.END);
            break;

        case FIT_XY:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.FILL);
            break;

        default:
            break;
        }
    }

    resetMatrix();
}

From source file:com.widgets.photoview.PhotoViewAttacher.java

/**
 * Calculate Matrix for FIT_CENTER/*  w  w w. j  a v  a 2s  .  c  o m*/
 *
 * @param d - Drawable being displayed
 */
private void updateBaseMatrix(Drawable d) {
    ImageView imageView = getImageView();
    if (null == imageView || null == d) {
        return;
    }

    final float viewWidth = getImageViewWidth(imageView);
    final float viewHeight = getImageViewHeight(imageView);
    final int drawableWidth = d.getIntrinsicWidth();
    final int drawableHeight = d.getIntrinsicHeight();

    mBaseMatrix.reset();

    final float widthScale = viewWidth / drawableWidth;
    final float heightScale = viewHeight / drawableHeight;

    if (mScaleType == ScaleType.CENTER) {
        mBaseMatrix.postTranslate((viewWidth - drawableWidth) / 2F, (viewHeight - drawableHeight) / 2F);

    } else if (mScaleType == ScaleType.CENTER_CROP) {
        float scale = Math.max(widthScale, heightScale);
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else if (mScaleType == ScaleType.CENTER_INSIDE) {
        float scale = Math.min(1.0f, Math.min(widthScale, heightScale));
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else {
        RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight);
        RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight);

        if ((int) (mBaseRotation + this.degrees) % 180 != 0) {
            mTempSrc = new RectF(0, 0, drawableHeight, drawableWidth);
        }

        switch (mScaleType) {
        case FIT_CENTER:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.CENTER);
            break;

        case FIT_START:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.START);
            break;

        case FIT_END:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.END);
            break;

        case FIT_XY:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.FILL);
            break;

        default:
            break;
        }
    }

    resetMatrix();
}

From source file:com.tenth.space.ui.fragment.HomeFragment.java

private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();//from  w  ww  .  j  a va2 s. co m
    if (null == mTextureView || null == mPreviewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max((float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    mTextureView.setTransform(matrix);
}

From source file:info.awesomedevelopment.tvgrid.library.TVGridView.java

/**
 * Generates a bitmap according to the size and state of a view in the recycler view
 *
 * @param w width of the bitmap//ww w.j ava 2s  .  c o  m
 * @param h height of the bitmap
 * @param focused true if the view is focused
 * @param clicked true if the view is clicked
 * @return Bitmap
 */
private Bitmap generateBitmap(int w, int h, boolean focused, boolean clicked) {
    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    RectF fillRect = new RectF(mStrokeMarginLeft, mStrokeMarginTop, w - mStrokeMarginRight,
            h - mStrokeMarginBottom);
    RectF shadowRect = new RectF(mStrokeWidth + mStrokeMarginLeft, mStrokeWidth + mStrokeMarginTop,
            w - mStrokeWidth - mStrokeMarginRight, h - mStrokeWidth - mStrokeMarginBottom);
    RectF cutoutRect = new RectF(mStrokeWidth + mStrokeMarginLeft + 2, mStrokeWidth + mStrokeMarginTop + 2,
            w - mStrokeWidth - mStrokeMarginRight - 1, h - mStrokeWidth - mStrokeMarginBottom - 1);

    if (mStrokeWidth > 0.0f) {
        sStrokePaint.setColor(clicked ? mStrokeColorClicked : focused ? mStrokeColor : mStrokeColorSelected);
        paintCanvas(canvas, fillRect, sStrokePaint);

        if (!mIsFilled) {
            paintCanvas(canvas, shadowRect, sShadowPaint);
        } else {
            cutoutRect = shadowRect;
        }

        paintCanvas(canvas, cutoutRect, sCutoutPaint);
    }

    if (mIsFilled) {
        sFillPaint.setColor(clicked ? mFillColorClicked : focused ? mFillColor : mFillColorSelected);
        sFillPaint.setAlpha((int) Math
                .ceil((clicked ? mFillAlphaClicked : focused ? mFillAlpha : mFillAlphaSelected) * 255));
        paintCanvas(canvas, cutoutRect, sFillPaint);
    }

    return bitmap;
}

From source file:org.getlantern.firetweet.fragment.support.UserFragment.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final FragmentActivity activity = getActivity();
    setHasOptionsMenu(true);//from ww  w  .  j a  va 2 s . co m
    getSharedPreferences(USER_COLOR_PREFERENCES_NAME, Context.MODE_PRIVATE)
            .registerOnSharedPreferenceChangeListener(this);
    getSharedPreferences(USER_NICKNAME_PREFERENCES_NAME, Context.MODE_PRIVATE)
            .registerOnSharedPreferenceChangeListener(this);
    mLocale = getResources().getConfiguration().locale;
    mCardBackgroundColor = ThemeUtils.getCardBackgroundColor(activity);
    mProfileImageLoader = getApplication().getMediaLoaderWrapper();
    final Bundle args = getArguments();
    long accountId = -1, userId = -1;
    String screenName = null;
    if (savedInstanceState != null) {
        args.putAll(savedInstanceState);
    } else {
        accountId = args.getLong(EXTRA_ACCOUNT_ID, -1);
        userId = args.getLong(EXTRA_USER_ID, -1);
        screenName = args.getString(EXTRA_SCREEN_NAME);
    }

    Utils.setNdefPushMessageCallback(activity, new CreateNdefMessageCallback() {

        @Override
        public NdefMessage createNdefMessage(NfcEvent event) {
            final ParcelableUser user = getUser();
            if (user == null)
                return null;
            return new NdefMessage(new NdefRecord[] {
                    NdefRecord.createUri(LinkCreator.getTwitterUserLink(user.screen_name)), });
        }
    });

    activity.setEnterSharedElementCallback(new SharedElementCallback() {

        @Override
        public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements,
                List<View> sharedElementSnapshots) {
            final int idx = sharedElementNames.indexOf(TRANSITION_NAME_PROFILE_IMAGE);
            if (idx != -1) {
                final View view = sharedElements.get(idx);
                int[] location = new int[2];
                final RectF bounds = new RectF(0, 0, view.getWidth(), view.getHeight());
                view.getLocationOnScreen(location);
                bounds.offsetTo(location[0], location[1]);
                mProfileImageView.setTransitionSource(bounds);
            }
            super.onSharedElementStart(sharedElementNames, sharedElements, sharedElementSnapshots);
        }

        @Override
        public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements,
                List<View> sharedElementSnapshots) {
            int idx = sharedElementNames.indexOf(TRANSITION_NAME_PROFILE_IMAGE);
            if (idx != -1) {
                final View view = sharedElements.get(idx);
                int[] location = new int[2];
                final RectF bounds = new RectF(0, 0, view.getWidth(), view.getHeight());
                view.getLocationOnScreen(location);
                bounds.offsetTo(location[0], location[1]);
                mProfileImageView.setTransitionDestination(bounds);
            }
            super.onSharedElementEnd(sharedElementNames, sharedElements, sharedElementSnapshots);
        }

    });

    ViewCompat.setTransitionName(mProfileImageView, TRANSITION_NAME_PROFILE_IMAGE);
    ViewCompat.setTransitionName(mProfileTypeView, TRANSITION_NAME_PROFILE_TYPE);
    //        ViewCompat.setTransitionName(mCardView, TRANSITION_NAME_CARD);

    mHeaderDrawerLayout.setDrawerCallback(this);

    mPagerAdapter = new SupportTabsAdapter(activity, getChildFragmentManager());

    mViewPager.setOffscreenPageLimit(3);
    mViewPager.setAdapter(mPagerAdapter);
    mPagerIndicator.setViewPager(mViewPager);
    mPagerIndicator.setTabDisplayOption(TabPagerIndicator.LABEL);

    mFollowButton.setOnClickListener(this);
    mProfileImageView.setOnClickListener(this);
    mProfileBannerView.setOnClickListener(this);
    mListedContainer.setOnClickListener(this);
    mFollowersContainer.setOnClickListener(this);
    mFriendsContainer.setOnClickListener(this);
    mRetryButton.setOnClickListener(this);
    mProfileBannerView.setOnSizeChangedListener(this);
    mProfileBannerSpace.setOnTouchListener(this);

    mProfileNameBackground.setBackgroundColor(mCardBackgroundColor);
    mProfileDetailsContainer.setBackgroundColor(mCardBackgroundColor);
    mPagerIndicator.setBackgroundColor(mCardBackgroundColor);
    mUuckyFooter.setBackgroundColor(mCardBackgroundColor);

    getUserInfo(accountId, userId, screenName, false);

    final float actionBarElevation = ThemeUtils.getSupportActionBarElevation(activity);
    ViewCompat.setElevation(mPagerIndicator, actionBarElevation);

    setupBaseActionBar();

    setupUserPages();
}

From source file:com.android.launcher2.AsyncTaskCallback.java

private boolean beginDraggingWidget(View v) {
    mDraggingWidget = true;// ww w  .ja va  2  s  .  c  om
    // Get the widget preview as the drag representation
    ImageView image = (ImageView) v.findViewById(R.id.widget_preview);
    PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag();

    // If the ImageView doesn't have a drawable yet, the widget preview hasn't been loaded and
    // we abort the drag.
    if (image.getDrawable() == null) {
        mDraggingWidget = false;
        return false;
    }

    // Compose the drag image
    Bitmap preview;
    Bitmap outline;
    float scale = 1f;
    if (createItemInfo instanceof PendingAddWidgetInfo) {
        // This can happen in some weird cases involving multi-touch. We can't start dragging
        // the widget if this is null, so we break out.
        if (mCreateWidgetInfo == null) {
            return false;
        }

        PendingAddWidgetInfo createWidgetInfo = mCreateWidgetInfo;
        createItemInfo = createWidgetInfo;
        int spanX = createItemInfo.spanX;
        int spanY = createItemInfo.spanY;
        int[] size = mLauncher.getWorkspace().estimateItemSize(spanX, spanY, createWidgetInfo, true);

        FastBitmapDrawable previewDrawable = (FastBitmapDrawable) image.getDrawable();
        float minScale = 1.25f;
        int maxWidth, maxHeight;
        maxWidth = Math.min((int) (previewDrawable.getIntrinsicWidth() * minScale), size[0]);
        maxHeight = Math.min((int) (previewDrawable.getIntrinsicHeight() * minScale), size[1]);
        preview = getWidgetPreview(createWidgetInfo.componentName, createWidgetInfo.previewImage,
                createWidgetInfo.icon, spanX, spanY, maxWidth, maxHeight);

        // Determine the image view drawable scale relative to the preview
        float[] mv = new float[9];
        Matrix m = new Matrix();
        m.setRectToRect(new RectF(0f, 0f, (float) preview.getWidth(), (float) preview.getHeight()),
                new RectF(0f, 0f, (float) previewDrawable.getIntrinsicWidth(),
                        (float) previewDrawable.getIntrinsicHeight()),
                Matrix.ScaleToFit.START);
        m.getValues(mv);
        scale = (float) mv[0];
    } else {
        PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) v.getTag();
        Drawable icon = mIconCache.getFullResIcon(createShortcutInfo.shortcutActivityInfo);
        preview = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);

        mCanvas.setBitmap(preview);
        mCanvas.save();
        renderDrawableToBitmap(icon, preview, 0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
        mCanvas.restore();
        mCanvas.setBitmap(null);
        createItemInfo.spanX = createItemInfo.spanY = 1;
    }

    // Don't clip alpha values for the drag outline if we're using the default widget preview
    boolean clipAlpha = !(createItemInfo instanceof PendingAddWidgetInfo
            && (((PendingAddWidgetInfo) createItemInfo).previewImage == 0));

    // Save the preview for the outline generation, then dim the preview
    outline = Bitmap.createScaledBitmap(preview, preview.getWidth(), preview.getHeight(), false);

    // Start the drag
    mLauncher.lockScreenOrientation();
    mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, outline, clipAlpha);
    mDragController.startDrag(image, preview, this, createItemInfo, DragController.DRAG_ACTION_COPY, null,
            scale);
    outline.recycle();
    preview.recycle();
    return true;
}

From source file:org.mariotaku.twidere.fragment.support.UserFragment.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final FragmentActivity activity = getActivity();
    setHasOptionsMenu(true);// ww w. j a v a2  s  .  c  o  m
    getSharedPreferences(USER_COLOR_PREFERENCES_NAME, Context.MODE_PRIVATE)
            .registerOnSharedPreferenceChangeListener(this);
    getSharedPreferences(USER_NICKNAME_PREFERENCES_NAME, Context.MODE_PRIVATE)
            .registerOnSharedPreferenceChangeListener(this);
    mUserColorNameManager = UserColorNameManager.getInstance(activity);
    mPreferences = SharedPreferencesWrapper.getInstance(activity, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE,
            SharedPreferenceConstants.class);
    mNameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
    mLocale = getResources().getConfiguration().locale;
    mCardBackgroundColor = ThemeUtils.getCardBackgroundColor(activity,
            ThemeUtils.getThemeBackgroundOption(activity), ThemeUtils.getUserThemeBackgroundAlpha(activity));
    mActionBarShadowColor = 0xA0000000;
    final TwidereApplication app = TwidereApplication.getInstance(activity);
    mProfileImageLoader = app.getMediaLoaderWrapper();
    final Bundle args = getArguments();
    long accountId = -1, userId = -1;
    String screenName = null;
    if (savedInstanceState != null) {
        args.putAll(savedInstanceState);
    } else {
        accountId = args.getLong(EXTRA_ACCOUNT_ID, -1);
        userId = args.getLong(EXTRA_USER_ID, -1);
        screenName = args.getString(EXTRA_SCREEN_NAME);
    }

    Utils.setNdefPushMessageCallback(activity, new CreateNdefMessageCallback() {

        @Override
        public NdefMessage createNdefMessage(NfcEvent event) {
            final ParcelableUser user = getUser();
            if (user == null)
                return null;
            return new NdefMessage(new NdefRecord[] {
                    NdefRecord.createUri(LinkCreator.getTwitterUserLink(user.screen_name)), });
        }
    });

    activity.setEnterSharedElementCallback(new SharedElementCallback() {

        @Override
        public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements,
                List<View> sharedElementSnapshots) {
            final int idx = sharedElementNames.indexOf(TRANSITION_NAME_PROFILE_IMAGE);
            if (idx != -1) {
                final View view = sharedElements.get(idx);
                int[] location = new int[2];
                final RectF bounds = new RectF(0, 0, view.getWidth(), view.getHeight());
                view.getLocationOnScreen(location);
                bounds.offsetTo(location[0], location[1]);
                mProfileImageView.setTransitionSource(bounds);
            }
            super.onSharedElementStart(sharedElementNames, sharedElements, sharedElementSnapshots);
        }

        @Override
        public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements,
                List<View> sharedElementSnapshots) {
            int idx = sharedElementNames.indexOf(TRANSITION_NAME_PROFILE_IMAGE);
            if (idx != -1) {
                final View view = sharedElements.get(idx);
                int[] location = new int[2];
                final RectF bounds = new RectF(0, 0, view.getWidth(), view.getHeight());
                view.getLocationOnScreen(location);
                bounds.offsetTo(location[0], location[1]);
                mProfileImageView.setTransitionDestination(bounds);
            }
            super.onSharedElementEnd(sharedElementNames, sharedElements, sharedElementSnapshots);
        }

    });

    ViewCompat.setTransitionName(mProfileImageView, TRANSITION_NAME_PROFILE_IMAGE);
    ViewCompat.setTransitionName(mProfileTypeView, TRANSITION_NAME_PROFILE_TYPE);
    //        ViewCompat.setTransitionName(mCardView, TRANSITION_NAME_CARD);

    mHeaderDrawerLayout.setDrawerCallback(this);

    mPagerAdapter = new SupportTabsAdapter(activity, getChildFragmentManager());

    mViewPager.setOffscreenPageLimit(3);
    mViewPager.setAdapter(mPagerAdapter);
    mPagerIndicator.setViewPager(mViewPager);
    mPagerIndicator.setTabDisplayOption(TabPagerIndicator.LABEL);
    mPagerIndicator.setOnPageChangeListener(this);

    mFollowButton.setOnClickListener(this);
    mProfileImageView.setOnClickListener(this);
    mProfileBannerView.setOnClickListener(this);
    mListedContainer.setOnClickListener(this);
    mFollowersContainer.setOnClickListener(this);
    mFriendsContainer.setOnClickListener(this);
    mHeaderErrorIcon.setOnClickListener(this);
    mProfileBannerView.setOnSizeChangedListener(this);
    mProfileBannerSpace.setOnTouchListener(this);

    mProfileNameBackground.setBackgroundColor(mCardBackgroundColor);
    mProfileDetailsContainer.setBackgroundColor(mCardBackgroundColor);
    mPagerIndicator.setBackgroundColor(mCardBackgroundColor);
    mUuckyFooter.setBackgroundColor(mCardBackgroundColor);

    final float actionBarElevation = ThemeUtils.getSupportActionBarElevation(activity);
    ViewCompat.setElevation(mPagerIndicator, actionBarElevation);

    if (activity instanceof IThemedActivity) {
        ViewSupport.setBackground(mPagerOverlay, ThemeUtils.getNormalWindowContentOverlay(activity,
                ((IThemedActivity) activity).getCurrentThemeResourceId()));
        ViewSupport.setBackground(mErrorOverlay, ThemeUtils.getNormalWindowContentOverlay(activity,
                ((IThemedActivity) activity).getCurrentThemeResourceId()));
    }

    setupBaseActionBar();
    setupUserPages();
    if (activity instanceof IThemedActivity) {
        setUiColor(((IThemedActivity) activity).getCurrentThemeColor());
    }

    getUserInfo(accountId, userId, screenName, false);
}