Search in sources :

Example 76 with Drawable

use of android.graphics.drawable.Drawable in project android_frameworks_base by ParanoidAndroid.

the class ProgressBar method doRefreshProgress.

private synchronized void doRefreshProgress(int id, int progress, boolean fromUser, boolean callBackToApp) {
    float scale = mMax > 0 ? (float) progress / (float) mMax : 0;
    final Drawable d = mCurrentDrawable;
    if (d != null) {
        Drawable progressDrawable = null;
        if (d instanceof LayerDrawable) {
            progressDrawable = ((LayerDrawable) d).findDrawableByLayerId(id);
            if (progressDrawable != null && canResolveLayoutDirection()) {
                progressDrawable.setLayoutDirection(getLayoutDirection());
            }
        }
        final int level = (int) (scale * MAX_LEVEL);
        (progressDrawable != null ? progressDrawable : d).setLevel(level);
    } else {
        invalidate();
    }
    if (callBackToApp && id == R.id.progress) {
        onProgressRefresh(scale, fromUser);
    }
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 77 with Drawable

use of android.graphics.drawable.Drawable in project android_frameworks_base by ParanoidAndroid.

the class ProgressBar method tileifyIndeterminate.

/**
     * Convert a AnimationDrawable for use as a barberpole animation.
     * Each frame of the animation is wrapped in a ClipDrawable and
     * given a tiling BitmapShader.
     */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());
        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}
Also used : AnimationDrawable(android.graphics.drawable.AnimationDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 78 with Drawable

use of android.graphics.drawable.Drawable in project android_frameworks_base by ParanoidAndroid.

the class ProgressBar method onDraw.

@Override
protected synchronized void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    Drawable d = mCurrentDrawable;
    if (d != null) {
        // Translate canvas so a indeterminate circular progress bar with padding
        // rotates properly in its animation
        canvas.save();
        if (isLayoutRtl() && mMirrorForRtl) {
            canvas.translate(getWidth() - mPaddingRight, mPaddingTop);
            canvas.scale(-1.0f, 1.0f);
        } else {
            canvas.translate(mPaddingLeft, mPaddingTop);
        }
        long time = getDrawingTime();
        if (mHasAnimation) {
            mAnimation.getTransformation(time, mTransformation);
            float scale = mTransformation.getAlpha();
            try {
                mInDrawing = true;
                d.setLevel((int) (scale * MAX_LEVEL));
            } finally {
                mInDrawing = false;
            }
            postInvalidateOnAnimation();
        }
        d.draw(canvas);
        canvas.restore();
        if (mShouldStartAnimationDrawable && d instanceof Animatable) {
            ((Animatable) d).start();
            mShouldStartAnimationDrawable = false;
        }
    }
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Animatable(android.graphics.drawable.Animatable)

Example 79 with Drawable

use of android.graphics.drawable.Drawable in project android_frameworks_base by ParanoidAndroid.

the class ImageView method resolveUri.

private void resolveUri() {
    if (mDrawable != null) {
        return;
    }
    Resources rsrc = getResources();
    if (rsrc == null) {
        return;
    }
    Drawable d = null;
    if (mResource != 0) {
        try {
            d = rsrc.getDrawable(mResource);
        } catch (Exception e) {
            Log.w("ImageView", "Unable to find resource: " + mResource, e);
            // Don't try again.
            mUri = null;
        }
    } else if (mUri != null) {
        String scheme = mUri.getScheme();
        if (ContentResolver.SCHEME_ANDROID_RESOURCE.equals(scheme)) {
            try {
                // Load drawable through Resources, to get the source density information
                ContentResolver.OpenResourceIdResult r = mContext.getContentResolver().getResourceId(mUri);
                d = r.r.getDrawable(r.id);
            } catch (Exception e) {
                Log.w("ImageView", "Unable to open content: " + mUri, e);
            }
        } else if (ContentResolver.SCHEME_CONTENT.equals(scheme) || ContentResolver.SCHEME_FILE.equals(scheme)) {
            InputStream stream = null;
            try {
                stream = mContext.getContentResolver().openInputStream(mUri);
                d = Drawable.createFromStream(stream, null);
            } catch (Exception e) {
                Log.w("ImageView", "Unable to open content: " + mUri, e);
            } finally {
                if (stream != null) {
                    try {
                        stream.close();
                    } catch (IOException e) {
                        Log.w("ImageView", "Unable to close content: " + mUri, e);
                    }
                }
            }
        } else {
            d = Drawable.createFromPath(mUri.toString());
        }
        if (d == null) {
            System.out.println("resolveUri failed on bad bitmap uri: " + mUri);
            // Don't try again.
            mUri = null;
        }
    } else {
        return;
    }
    updateDrawable(d);
}
Also used : InputStream(java.io.InputStream) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Resources(android.content.res.Resources) IOException(java.io.IOException) IOException(java.io.IOException)

Example 80 with Drawable

use of android.graphics.drawable.Drawable in project android_frameworks_base by ParanoidAndroid.

the class HeavyWeightSwitcherActivity method setIconAndText.

void setIconAndText(int iconId, int actionId, int descriptionId, String packageName, int actionStr, int descriptionStr) {
    CharSequence appName = "";
    Drawable appIcon = null;
    if (mCurApp != null) {
        try {
            ApplicationInfo info = getPackageManager().getApplicationInfo(packageName, 0);
            appName = info.loadLabel(getPackageManager());
            appIcon = info.loadIcon(getPackageManager());
        } catch (PackageManager.NameNotFoundException e) {
        }
    }
    setDrawable(iconId, appIcon);
    setText(actionId, getString(actionStr, appName));
    setText(descriptionId, getText(descriptionStr));
}
Also used : PackageManager(android.content.pm.PackageManager) Drawable(android.graphics.drawable.Drawable) ApplicationInfo(android.content.pm.ApplicationInfo)

Aggregations

Drawable (android.graphics.drawable.Drawable)2687 BitmapDrawable (android.graphics.drawable.BitmapDrawable)522 View (android.view.View)311 ColorDrawable (android.graphics.drawable.ColorDrawable)275 Bitmap (android.graphics.Bitmap)242 ImageView (android.widget.ImageView)226 TextView (android.widget.TextView)215 Paint (android.graphics.Paint)213 LayerDrawable (android.graphics.drawable.LayerDrawable)209 Rect (android.graphics.Rect)203 StateListDrawable (android.graphics.drawable.StateListDrawable)152 Resources (android.content.res.Resources)140 AnimationDrawable (android.graphics.drawable.AnimationDrawable)137 PackageManager (android.content.pm.PackageManager)126 Context (android.content.Context)122 TypedArray (android.content.res.TypedArray)113 ClipDrawable (android.graphics.drawable.ClipDrawable)108 Test (org.junit.Test)100 ViewGroup (android.view.ViewGroup)99 ShapeDrawable (android.graphics.drawable.ShapeDrawable)94