Search in sources :

Example 31 with ColorDrawable

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

the class ActivityTransitionDetails method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setBackgroundDrawable(new ColorDrawable(Color.DKGRAY));
    setContentView(R.layout.activity_transition_details);
    ImageView titleImage = (ImageView) findViewById(R.id.titleImage);
    titleImage.setImageDrawable(getHeroDrawable());
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) ImageView(android.widget.ImageView)

Example 32 with ColorDrawable

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

the class ResourceHelper method getDrawable.

/**
     * Returns a drawable from the given value.
     * @param value The value that contains a path to a 9 patch, a bitmap or a xml based drawable,
     * or an hexadecimal color
     * @param context the current context
     * @param theme the theme to be used to inflate the drawable.
     */
public static Drawable getDrawable(ResourceValue value, BridgeContext context, Theme theme) {
    if (value == null) {
        return null;
    }
    String stringValue = value.getValue();
    if (RenderResources.REFERENCE_NULL.equals(stringValue)) {
        return null;
    }
    String lowerCaseValue = stringValue.toLowerCase();
    Density density = Density.MEDIUM;
    if (value instanceof DensityBasedResourceValue) {
        density = ((DensityBasedResourceValue) value).getResourceDensity();
    }
    if (lowerCaseValue.endsWith(NinePatch.EXTENSION_9PATCH)) {
        File file = new File(stringValue);
        if (file.isFile()) {
            try {
                return getNinePatchDrawable(new FileInputStream(file), density, value.isFramework(), stringValue, context);
            } catch (IOException e) {
                // failed to read the file, we'll return null below.
                Bridge.getLog().error(LayoutLog.TAG_RESOURCES_READ, "Failed lot load " + file.getAbsolutePath(), e, null);
            }
        }
        return null;
    } else if (lowerCaseValue.endsWith(".xml")) {
        // create a block parser for the file
        File f = new File(stringValue);
        if (f.isFile()) {
            try {
                // let the framework inflate the Drawable from the XML file.
                XmlPullParser parser = ParserFactory.create(f);
                BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(parser, context, value.isFramework());
                try {
                    return Drawable.createFromXml(context.getResources(), blockParser, theme);
                } finally {
                    blockParser.ensurePopped();
                }
            } catch (Exception e) {
                // this is an error and not warning since the file existence is checked before
                // attempting to parse it.
                Bridge.getLog().error(null, "Failed to parse file " + stringValue, e, null);
            }
        } else {
            Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("File %s does not exist (or is not a file)", stringValue), null);
        }
        return null;
    } else {
        File bmpFile = new File(stringValue);
        if (bmpFile.isFile()) {
            try {
                Bitmap bitmap = Bridge.getCachedBitmap(stringValue, value.isFramework() ? null : context.getProjectKey());
                if (bitmap == null) {
                    bitmap = Bitmap_Delegate.createBitmap(bmpFile, false, /*isMutable*/
                    density);
                    Bridge.setCachedBitmap(stringValue, bitmap, value.isFramework() ? null : context.getProjectKey());
                }
                return new BitmapDrawable(context.getResources(), bitmap);
            } catch (IOException e) {
                // we'll return null below
                Bridge.getLog().error(LayoutLog.TAG_RESOURCES_READ, "Failed lot load " + bmpFile.getAbsolutePath(), e, null);
            }
        } else {
            // attempt to get a color from the value
            try {
                int color = getColor(stringValue);
                return new ColorDrawable(color);
            } catch (NumberFormatException e) {
                // we'll return null below.
                Bridge.getLog().error(LayoutLog.TAG_RESOURCES_FORMAT, "Failed to convert " + stringValue + " into a drawable", e, null);
            }
        }
    }
    return null;
}
Also used : DensityBasedResourceValue(com.android.ide.common.rendering.api.DensityBasedResourceValue) XmlPullParser(org.xmlpull.v1.XmlPullParser) IOException(java.io.IOException) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Density(com.android.resources.Density) FileInputStream(java.io.FileInputStream) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) File(java.io.File) BridgeXmlBlockParser(com.android.layoutlib.bridge.android.BridgeXmlBlockParser)

Example 33 with ColorDrawable

use of android.graphics.drawable.ColorDrawable in project chromeview by pwnall.

the class PopupZoomer method getOverlayDrawable.

/**
     * Gets the drawable that should be used to frame the zooming popup, loading
     * it from the resource bundle if not already cached.
     */
private static Drawable getOverlayDrawable(Context context) {
    if (sOverlayDrawable == null) {
        try {
            sOverlayDrawable = context.getResources().getDrawable(R.drawable.ondemand_overlay);
        } catch (Resources.NotFoundException e) {
            Log.w(LOGTAG, "No drawable resource for PopupZoomer overlay found.");
            sOverlayDrawable = new ColorDrawable();
        }
        sOverlayPadding = new Rect();
        sOverlayDrawable.getPadding(sOverlayPadding);
    }
    return sOverlayDrawable;
}
Also used : Rect(android.graphics.Rect) ColorDrawable(android.graphics.drawable.ColorDrawable) Resources(android.content.res.Resources)

Example 34 with ColorDrawable

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

the class LocalWorker method onCancelled.

@Override
protected void onCancelled(Bitmap bitmap) {
    super.onCancelled(bitmap);
    ImageView imageView = viewWeakReference.get();
    if (!isMySelf(imageView)) {
        return;
    }
    imageView.setImageDrawable(new ColorDrawable(DebugColor.READ_CANCEL));
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) ImageView(android.widget.ImageView)

Example 35 with ColorDrawable

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

the class GalleryAnimationActivity method onBackPressed.

@Override
public void onBackPressed() {
    ContainerFragment fragment = fragmentMap.get(pager.getCurrentItem());
    if (fragment != null && fragment.canAnimateCloseActivity()) {
        backgroundColor = new ColorDrawable(Color.BLACK);
        ObjectAnimator bgAnim = ObjectAnimator.ofInt(backgroundColor, "alpha", 0);
        bgAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                background.setBackground(backgroundColor);
            }
        });
        bgAnim.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                GalleryAnimationActivity.super.finish();
                overridePendingTransition(-1, -1);
            }
        });
        fragment.animationExit(bgAnim);
    } else {
        super.onBackPressed();
    }
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) ColorDrawable(android.graphics.drawable.ColorDrawable) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator)

Aggregations

ColorDrawable (android.graphics.drawable.ColorDrawable)530 View (android.view.View)113 Drawable (android.graphics.drawable.Drawable)103 BitmapDrawable (android.graphics.drawable.BitmapDrawable)69 ImageView (android.widget.ImageView)62 TextView (android.widget.TextView)55 Bitmap (android.graphics.Bitmap)52 AdapterView (android.widget.AdapterView)32 LinearLayout (android.widget.LinearLayout)32 Test (org.junit.Test)31 Canvas (android.graphics.Canvas)30 ListView (android.widget.ListView)27 FrameLayout (android.widget.FrameLayout)23 ViewGroup (android.view.ViewGroup)22 Handler (android.os.Handler)20 Paint (android.graphics.Paint)19 StateListDrawable (android.graphics.drawable.StateListDrawable)19 TransitionDrawable (android.graphics.drawable.TransitionDrawable)19 WindowManager (android.view.WindowManager)17 Intent (android.content.Intent)16