Search in sources :

Example 71 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project platform_frameworks_base by android.

the class SharedElementCallback method onCreateSnapshotView.

/**
     * Reconstitutes a snapshot View from a Parcelable returned in
     * {@link #onCaptureSharedElementSnapshot(android.view.View, android.graphics.Matrix,
     * android.graphics.RectF)} to be used in {@link #onSharedElementStart(java.util.List,
     * java.util.List, java.util.List)} and {@link #onSharedElementEnd(java.util.List,
     * java.util.List, java.util.List)}. The returned View will be sized and positioned after
     * this call so that it is ready to be added to the decor View's overlay.
     *
     * <p>This is not called for Fragment Transitions.</p>
     *
     * @param context The Context used to create the snapshot View.
     * @param snapshot The Parcelable returned by {@link #onCaptureSharedElementSnapshot(
     * android.view.View, android.graphics.Matrix, android.graphics.RectF)}.
     * @return A View to be sent in {@link #onSharedElementStart(java.util.List, java.util.List,
     * java.util.List)} and {@link #onSharedElementEnd(java.util.List, java.util.List,
     * java.util.List)}. A null value will produce a null snapshot value for those two methods.
     */
public View onCreateSnapshotView(Context context, Parcelable snapshot) {
    View view = null;
    if (snapshot instanceof Bundle) {
        Bundle bundle = (Bundle) snapshot;
        Bitmap bitmap = (Bitmap) bundle.getParcelable(BUNDLE_SNAPSHOT_BITMAP);
        if (bitmap == null) {
            return null;
        }
        ImageView imageView = new ImageView(context);
        view = imageView;
        imageView.setImageBitmap(bitmap);
        imageView.setScaleType(ScaleType.valueOf(bundle.getString(BUNDLE_SNAPSHOT_IMAGE_SCALETYPE)));
        if (imageView.getScaleType() == ScaleType.MATRIX) {
            float[] values = bundle.getFloatArray(BUNDLE_SNAPSHOT_IMAGE_MATRIX);
            Matrix matrix = new Matrix();
            matrix.setValues(values);
            imageView.setImageMatrix(matrix);
        }
    } else if (snapshot instanceof Bitmap) {
        Bitmap bitmap = (Bitmap) snapshot;
        view = new View(context);
        Resources resources = context.getResources();
        view.setBackground(new BitmapDrawable(resources, bitmap));
    }
    return view;
}
Also used : Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) Resources(android.content.res.Resources) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageView(android.widget.ImageView) View(android.view.View)

Example 72 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project weiciyuan by qii.

the class WriteWeiboActivity method buildInterface.

private void buildInterface() {
    setContentView(R.layout.writeweiboactivity_layout);
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setTitle(R.string.write_weibo);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    int avatarWidth = getResources().getDimensionPixelSize(R.dimen.timeline_avatar_width);
    int avatarHeight = getResources().getDimensionPixelSize(R.dimen.timeline_avatar_height);
    Bitmap bitmap = ImageUtility.getWriteWeiboRoundedCornerPic(GlobalContext.getInstance().getAccountBean().getInfo().getAvatar_large(), avatarWidth, avatarHeight, FileLocationMethod.avatar_large);
    if (bitmap == null) {
        bitmap = ImageUtility.getWriteWeiboRoundedCornerPic(GlobalContext.getInstance().getAccountBean().getInfo().getProfile_image_url(), avatarWidth, avatarHeight, FileLocationMethod.avatar_small);
    }
    if (bitmap != null) {
        actionBar.setIcon(new BitmapDrawable(getResources(), bitmap));
    }
    View title = getLayoutInflater().inflate(R.layout.writeweiboactivity_title_layout, null);
    TextView contentNumber = (TextView) title.findViewById(R.id.content_number);
    contentNumber.setVisibility(View.GONE);
    haveGPS = (ImageView) title.findViewById(R.id.have_gps);
    final PopupMenu popupMenu = new PopupMenu(this, haveGPS);
    popupMenu.inflate(R.menu.popmenu_gps);
    haveGPS.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            popupMenu.show();
        }
    });
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch(item.getItemId()) {
                case R.id.menu_view:
                    StringBuilder geoUriString = new StringBuilder().append("geo:" + geoBean.getLat() + "," + geoBean.getLon());
                    if (!TextUtils.isEmpty(location)) {
                        geoUriString.append("?q=").append(location);
                    }
                    Uri geoUri = Uri.parse(geoUriString.toString());
                    Intent mapCall = new Intent(Intent.ACTION_VIEW, geoUri);
                    if (Utility.isIntentSafe(WriteWeiboActivity.this, mapCall)) {
                        startActivity(mapCall);
                    } else {
                        Toast.makeText(WriteWeiboActivity.this, R.string.your_device_dont_have_any_map_app_to_open_gps_info, Toast.LENGTH_SHORT).show();
                    }
                    break;
                case R.id.menu_delete:
                    haveGPS.setVisibility(View.GONE);
                    geoBean = null;
                    break;
            }
            return true;
        }
    });
    actionBar.setCustomView(title, new ActionBar.LayoutParams(Gravity.RIGHT));
    actionBar.setDisplayShowCustomEnabled(true);
    content = ((KeyboardControlEditText) findViewById(R.id.status_new_content));
    content.addTextChangedListener(new TextNumLimitWatcher((TextView) findViewById(R.id.menu_send), content, this));
    content.setDrawingCacheEnabled(true);
    AutoCompleteAdapter adapter = new AutoCompleteAdapter(this, content, (ProgressBar) title.findViewById(R.id.have_suggest_progressbar));
    content.setAdapter(adapter);
    preview = ViewUtility.findViewById(this, R.id.status_image_preview);
    View.OnClickListener onClickListener = new BottomButtonClickListener();
    findViewById(R.id.menu_at).setOnClickListener(onClickListener);
    findViewById(R.id.menu_emoticon).setOnClickListener(onClickListener);
    findViewById(R.id.menu_add_pic).setOnClickListener(onClickListener);
    findViewById(R.id.menu_send).setOnClickListener(onClickListener);
    CheatSheet.setup(WriteWeiboActivity.this, findViewById(R.id.menu_at), R.string.at_other);
    CheatSheet.setup(WriteWeiboActivity.this, findViewById(R.id.menu_emoticon), R.string.add_emoticon);
    CheatSheet.setup(WriteWeiboActivity.this, findViewById(R.id.menu_add_pic), R.string.add_pic);
    CheatSheet.setup(WriteWeiboActivity.this, findViewById(R.id.menu_send), R.string.send);
    smiley = (SmileyPicker) findViewById(R.id.smiley_picker);
    smiley.setEditText(WriteWeiboActivity.this, ((LinearLayout) findViewById(R.id.root_layout)), content);
    container = (RelativeLayout) findViewById(R.id.container);
    content.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            hideSmileyPicker(true);
        }
    });
}
Also used : MenuItem(android.view.MenuItem) Intent(android.content.Intent) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Uri(android.net.Uri) Bitmap(android.graphics.Bitmap) KeyboardControlEditText(org.qii.weiciyuan.support.lib.KeyboardControlEditText) TextView(android.widget.TextView) ActionBar(android.app.ActionBar) LinearLayout(android.widget.LinearLayout) PopupMenu(android.widget.PopupMenu)

Example 73 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project weiciyuan by qii.

the class AbstractWriteActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.abstractwriteactivity_layout);
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayShowCustomEnabled(true);
    int avatarWidth = getResources().getDimensionPixelSize(R.dimen.timeline_avatar_width);
    int avatarHeight = getResources().getDimensionPixelSize(R.dimen.timeline_avatar_height);
    Bitmap bitmap = ImageUtility.getWriteWeiboRoundedCornerPic(getCurrentAccountBean().getInfo().getAvatar_large(), avatarWidth, avatarHeight, FileLocationMethod.avatar_large);
    if (bitmap == null) {
        bitmap = ImageUtility.getWriteWeiboRoundedCornerPic(getCurrentAccountBean().getInfo().getProfile_image_url(), avatarWidth, avatarHeight, FileLocationMethod.avatar_small);
    }
    if (bitmap != null) {
        actionBar.setIcon(new BitmapDrawable(getResources(), bitmap));
    }
    token = getIntent().getStringExtra("token");
    View title = getLayoutInflater().inflate(R.layout.writeweiboactivity_title_layout, null);
    actionBar.setCustomView(title, new ActionBar.LayoutParams(Gravity.RIGHT));
    et = ((AutoCompleteTextView) findViewById(R.id.status_new_content));
    et.addTextChangedListener(new TextNumLimitWatcher((TextView) findViewById(R.id.menu_send), et, this));
    AutoCompleteAdapter adapter = new AutoCompleteAdapter(this, et, (ProgressBar) title.findViewById(R.id.have_suggest_progressbar));
    et.setAdapter(adapter);
    findViewById(R.id.menu_topic).setOnClickListener(this);
    findViewById(R.id.menu_at).setOnClickListener(this);
    findViewById(R.id.menu_emoticon).setOnClickListener(this);
    findViewById(R.id.menu_send).setOnClickListener(this);
    CheatSheet.setup(AbstractWriteActivity.this, findViewById(R.id.menu_at), R.string.at_other);
    CheatSheet.setup(AbstractWriteActivity.this, findViewById(R.id.menu_emoticon), R.string.add_emoticon);
    CheatSheet.setup(AbstractWriteActivity.this, findViewById(R.id.menu_topic), R.string.add_topic);
    CheatSheet.setup(AbstractWriteActivity.this, findViewById(R.id.menu_send), R.string.send);
    smiley = (SmileyPicker) findViewById(R.id.smiley_picker);
    smiley.setEditText(AbstractWriteActivity.this, ((LinearLayout) findViewById(R.id.root_layout)), et);
    container = (RelativeLayout) findViewById(R.id.container);
    et.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            hideSmileyPicker(true);
        }
    });
}
Also used : BitmapDrawable(android.graphics.drawable.BitmapDrawable) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) Bitmap(android.graphics.Bitmap) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) ActionBar(android.app.ActionBar) LinearLayout(android.widget.LinearLayout) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 74 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project material by rey5137.

the class ContactView method setAvatarDrawable.

public void setAvatarDrawable(Drawable drawable) {
    if (drawable == null)
        return;
    if (drawable instanceof BitmapDrawable)
        setAvatarBitmap(((BitmapDrawable) drawable).getBitmap());
    else {
        Bitmap bm = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bm);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        setAvatarBitmap(bm);
    }
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 75 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project mobile-android by photo.

the class ImageWorker method recycleBitmapIfNecessary.

public void recycleBitmapIfNecessary(ImageView imageView) {
    if (imageView.getTag() == null) {
        CommonUtils.debug(TAG, "recycleBitmapIfNecessary: skipping, tag is null");
        return;
    }
    Drawable drawable = imageView.getDrawable();
    if (drawable != null) {
        if (drawable instanceof BitmapDrawable && !(drawable instanceof AsyncDrawable)) {
            CommonUtils.debug(TAG, "recycleBitmapIfNecessary: drawable is instance of BitmapDrawable");
            Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
            if (mImageCache.hasInMemoryCache(bitmap)) {
                CommonUtils.debug(TAG, "recycleBitmapIfNecessary: bitmap is in cache");
            } else {
                CommonUtils.debug(TAG, "recycleBitmapIfNecessary: bitmap is not in cache.");
                imageView.setImageDrawable(null);
                if (!bitmap.isRecycled()) {
                    CommonUtils.debug(TAG, "recycleBitmapIfNecessary: bitmap is not yet recycled. Recycling...");
                    bitmap.recycle();
                } else {
                    CommonUtils.debug(TAG, "recycleBitmapIfNecessary: bitmap is already recycled.");
                }
            }
        } else {
            CommonUtils.debug(TAG, "recycleBitmapIfNecessary: drawable is not instance of BitmapDrawable or it is AsyncDrawable");
        }
    } else {
        CommonUtils.debug(TAG, "recycleBitmapIfNecessary: drawable is null");
    }
}
Also used : Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Aggregations

BitmapDrawable (android.graphics.drawable.BitmapDrawable)640 Bitmap (android.graphics.Bitmap)426 Drawable (android.graphics.drawable.Drawable)187 Canvas (android.graphics.Canvas)182 Paint (android.graphics.Paint)110 Rect (android.graphics.Rect)77 View (android.view.View)77 ImageView (android.widget.ImageView)63 ColorDrawable (android.graphics.drawable.ColorDrawable)59 TextView (android.widget.TextView)51 IOException (java.io.IOException)40 Resources (android.content.res.Resources)35 LayerDrawable (android.graphics.drawable.LayerDrawable)33 AnimationDrawable (android.graphics.drawable.AnimationDrawable)30 File (java.io.File)27 Test (org.junit.Test)24 Matrix (android.graphics.Matrix)23 Intent (android.content.Intent)22 StateListDrawable (android.graphics.drawable.StateListDrawable)22 InputStream (java.io.InputStream)22