Example usage for android.graphics.drawable ColorDrawable ColorDrawable

List of usage examples for android.graphics.drawable ColorDrawable ColorDrawable

Introduction

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

Prototype

public ColorDrawable(@ColorInt int color) 

Source Link

Document

Creates a new ColorDrawable with the specified color.

Usage

From source file:com.example.android.wearable.gridviewpager.SampleGridPagerAdapter.java

public SampleGridPagerAdapter(Context ctx, FragmentManager fm) {
    super(fm);//from w w  w. j av  a  2  s. c  o m
    mContext = ctx;

    mRows = new ArrayList<SampleGridPagerAdapter.Row>();

    mRows.add(new Row(cardFragment(R.string.welcome_title, R.string.welcome_text)));
    mRows.add(new Row(cardFragment(R.string.about_title, R.string.about_text)));
    mRows.add(new Row(cardFragment(R.string.cards_title, R.string.cards_text),
            cardFragment(R.string.expansion_title, R.string.expansion_text)));
    mRows.add(new Row(cardFragment(R.string.backgrounds_title, R.string.backgrounds_text),
            cardFragment(R.string.columns_title, R.string.columns_text)));
    mRows.add(new Row(new CustomFragment()));
    mRows.add(new Row(cardFragment(R.string.dismiss_title, R.string.dismiss_text)));
    mDefaultBg = new ColorDrawable(R.color.dark_grey);
    mClearBg = new ColorDrawable(android.R.color.transparent);
}

From source file:com.android.launcher3.Hotseat.java

public Hotseat(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mLauncher = Launcher.getLauncher(context);
    mHasVerticalHotseat = mLauncher.getDeviceProfile().isVerticalBarLayout();
    mBackgroundColor = ColorUtils/* ww w.j a  va2 s  .co  m*/
            .setAlphaComponent(ContextCompat.getColor(context, R.color.all_apps_container_color), 0);
    mBackground = new ColorDrawable(mBackgroundColor);

    if (Utilities.getDockBackgroundPrefEnabled(getContext()) != -1) {
        setBackgroundColor(Utilities.getDockBackgroundPrefEnabled(getContext()));
    } else {
        setBackground(mBackground);
    }
    //setBackgroundColor(ContextCompat.getColor(context, R.color.colorPrimary));
}

From source file:cn.psvmc.demo.MainActivity.java

private void changeColor(int newColor) {
    tabs.setIndicatorColor(newColor);//from   w ww  . j  av  a2  s .c  om
    ActionBar actionbar = getActionBar();
    if (actionbar == null) {
        return;
    }
    // change ActionBar color just if an ActionBar is available
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

        Drawable colorDrawable = new ColorDrawable(newColor);
        Drawable bottomDrawable = getResources().getDrawable(R.drawable.actionbar_bottom);
        LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });

        if (oldBackground == null) {

            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
                ld.setCallback(drawableCallback);
            } else {
                getActionBar().setBackgroundDrawable(ld);
            }

        } else {

            TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });

            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
                td.setCallback(drawableCallback);
            } else {
                getActionBar().setBackgroundDrawable(td);
            }

            td.startTransition(200);

        }

        oldBackground = ld;

        // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler
        getActionBar().setDisplayShowTitleEnabled(false);
        getActionBar().setDisplayShowTitleEnabled(true);

    }

    currentColor = newColor;

}

From source file:com.adithya321.sharesanalysis.fragments.SummaryFragment.java

@Nullable
@Override//  w w  w  . j  ava 2  s  .  c  om
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_summary, container, false);

    Window window = getActivity().getWindow();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        window.setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
    ((AppCompatActivity) getActivity()).getSupportActionBar()
            .setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary)));

    currentInvestmentsTV = (TickerView) root.findViewById(R.id.current_investments);
    netWorthTV = (TickerView) root.findViewById(R.id.net_worth);
    potentialProfitTV = (TickerView) root.findViewById(R.id.potential_profit);
    targetProfitTV = (TickerView) root.findViewById(R.id.target_profit);

    currentInvestmentsTV.setCharacterList(TickerUtils.getDefaultListForUSCurrency());
    netWorthTV.setCharacterList(TickerUtils.getDefaultListForUSCurrency());
    potentialProfitTV.setCharacterList(TickerUtils.getDefaultListForUSCurrency());
    targetProfitTV.setCharacterList(TickerUtils.getDefaultListForUSCurrency());

    currentInvestmentsTV.setText("0");
    netWorthTV.setText("0");
    potentialProfitTV.setText("0");
    targetProfitTV.setText("0");

    databaseHandler = new DatabaseHandler(getContext());
    sharesList = databaseHandler.getShares();
    calculateValues();

    return root;
}

From source file:com.doctoror.fuckoffmusicplayer.presentation.queue.QueueItemViewHolder.java

@NonNull
private Drawable getSelectedBackground(@NonNull final Context context) {
    if (mSelectedBackground != null) {
        return mSelectedBackground;
    }//from  w  w  w .j a  va  2s  .  co m

    mSelectedBackground = new LayerDrawable(new Drawable[] {
            new ColorDrawable(ThemeUtils.getColor(context.getTheme(), android.R.attr.windowBackground)),
            new ColorDrawable(ContextCompat.getColor(context, R.color.dividerBackground)) });

    return mSelectedBackground;
}

From source file:android.content.res.VectorResources.java

@Override
Drawable loadDrawable(TypedValue value, int id) throws NotFoundException {
    boolean isColorDrawable = false;
    if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        isColorDrawable = true;/*w  w w.  j  av  a 2  s. c  o m*/
    }
    final long key = isColorDrawable ? value.data : (((long) value.assetCookie) << 32) | value.data;

    Drawable dr = getCachedDrawable(isColorDrawable ? mColorDrawableCache : mDrawableCache, key);

    if (dr != null) {
        return dr;
    }

    if (isColorDrawable) {
        dr = new ColorDrawable(value.data);
    }

    if (dr == null) {
        if (value.string == null) {
            throw new NotFoundException("Resource is not a Drawable (color or path): " + value);
        }

        String file = value.string.toString();

        if (file.endsWith(".xml")) {
            // Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, file);
            try {
                XmlResourceParser rp = getXml(id);
                // XmlResourceParser rp = loadXmlResourceParser(
                //         file, id, value.assetCookie, "drawable");
                dr = createDrawableFromXml(rp);
                rp.close();
            } catch (Exception e) {
                // Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
                NotFoundException rnf = new NotFoundException(
                        "File " + file + " from drawable resource ID #0x" + Integer.toHexString(id));
                rnf.initCause(e);
                throw rnf;
            }
            // Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);

        } else {
            // Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, file);
            try {
                InputStream is = openRawResource(id, value);
                //InputStream is = mAssets.openNonAsset(
                //        value.assetCookie, file, AssetManager.ACCESS_STREAMING);
                //                System.out.println("Opened file " + file + ": " + is);
                dr = Drawable.createFromResourceStream(this, value, is, file, null);
                is.close();
                //                System.out.println("Created stream: " + dr);
            } catch (Exception e) {
                // Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
                NotFoundException rnf = new NotFoundException(
                        "File " + file + " from drawable resource ID #0x" + Integer.toHexString(id));
                rnf.initCause(e);
                throw rnf;
            }
            // Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
        }
    }
    Drawable.ConstantState cs;
    if (dr != null) {
        dr.setChangingConfigurations(value.changingConfigurations);
        cs = dr.getConstantState();
        if (cs != null) {
            synchronized (mAccessLock) {
                //Log.i(TAG, "Saving cached drawable @ #" +
                //        Integer.toHexString(key.intValue())
                //        + " in " + this + ": " + cs);
                if (isColorDrawable) {
                    mColorDrawableCache.put(key, new WeakReference<Drawable.ConstantState>(cs));
                } else {
                    mDrawableCache.put(key, new WeakReference<Drawable.ConstantState>(cs));
                }
            }
        }
    }

    return dr;
}

From source file:org.quantumbadger.redreader.activities.AlbumListingActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    PrefsUtility.applyTheme(this);

    OptionsMenuUtility.fixActionBar(AlbumListingActivity.this, getString(R.string.imgur_album));

    if (getActionBar() != null) {
        getActionBar().setHomeButtonEnabled(true);
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }//  w w w  . jav a2  s.  c o m

    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    final boolean solidblack = PrefsUtility.appearance_solidblack(this, sharedPreferences)
            && PrefsUtility.appearance_theme(this, sharedPreferences) == PrefsUtility.AppearanceTheme.NIGHT;

    if (solidblack)
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK));

    final Intent intent = getIntent();

    mUrl = intent.getDataString();

    if (mUrl == null) {
        finish();
        return;
    }

    final Matcher matchImgur = LinkHandler.imgurAlbumPattern.matcher(mUrl);
    final String albumId;

    if (matchImgur.find()) {
        albumId = matchImgur.group(2);
    } else {
        Log.e("AlbumListingActivity", "URL match failed");
        revertToWeb();
        return;
    }

    Log.i("AlbumListingActivity", "Loading URL " + mUrl + ", album id " + albumId);

    final ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
    progressBar.setIndeterminate(true);

    final LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(progressBar);

    ImgurAPI.getAlbumInfo(this, albumId, Constants.Priority.IMAGE_VIEW, 0, new GetAlbumInfoListener() {

        @Override
        public void onFailure(final RequestFailureType type, final Throwable t, final StatusLine status,
                final String readableMessage) {
            Log.e("AlbumListingActivity", "getAlbumInfo call failed: " + type);

            if (status != null)
                Log.e("AlbumListingActivity", "status was: " + status.toString());
            if (t != null)
                Log.e("AlbumListingActivity", "exception was: ", t);

            // It might be a single image, not an album

            if (status == null) {
                revertToWeb();
                return;
            }

            ImgurAPI.getImageInfo(AlbumListingActivity.this, albumId, Constants.Priority.IMAGE_VIEW, 0,
                    new GetImageInfoListener() {
                        @Override
                        public void onFailure(final RequestFailureType type, final Throwable t,
                                final StatusLine status, final String readableMessage) {
                            Log.e("AlbumListingActivity", "Image info request also failed: " + type);
                            revertToWeb();
                        }

                        @Override
                        public void onSuccess(final ImageInfo info) {
                            Log.i("AlbumListingActivity", "Link was actually an image.");
                            LinkHandler.onLinkClicked(AlbumListingActivity.this, info.urlOriginal);
                            finish();
                        }

                        @Override
                        public void onNotAnImage() {
                            Log.i("AlbumListingActivity", "Not an image either");
                            revertToWeb();
                        }
                    });
        }

        @Override
        public void onSuccess(final ImgurAPI.AlbumInfo info) {
            Log.i("AlbumListingActivity", "Got album, " + info.images.size() + " image(s)");

            AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                @Override
                public void run() {

                    if (info.title != null && !info.title.trim().isEmpty()) {
                        OptionsMenuUtility.fixActionBar(AlbumListingActivity.this,
                                getString(R.string.imgur_album) + ": " + info.title);
                    }

                    layout.removeAllViews();

                    final ListView listView = new ListView(AlbumListingActivity.this);
                    listView.setAdapter(new AlbumAdapter(info));
                    layout.addView(listView);

                    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(final AdapterView<?> parent, final View view,
                                final int position, final long id) {

                            LinkHandler.onLinkClicked(AlbumListingActivity.this,
                                    info.images.get(position).urlOriginal, false, null, info, position);
                        }
                    });
                }
            });
        }
    });

    setContentView(layout);
}

From source file:com.carlrice.reader.utils.UiUtils.java

static public void setActionBarColors(ActionBar supportActionBar, Palette palette) {
    int color = Application.color(R.color.light_theme_color_primary);
    int darkColor = Application.color(R.color.light_theme_color_primary_dark);
    if (palette != null) {
        color = palette.getVibrantColor(color);
        darkColor = palette.getDarkVibrantColor(darkColor);
    }/*from w ww . j a  v a  2 s . c o m*/
    supportActionBar.setBackgroundDrawable(new ColorDrawable(color));
}

From source file:com.anadoluuniversity.tinyreader.OcrCaptureActivity.java

/**
 * Initializes the UI and creates the detector pipeline.
 *//*from ww w.  j  a v  a  2  s .  c  o m*/
@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.ocr_capture_activity);

    DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.string.drawer_open, /* "open drawer" description */
            R.string.drawer_close /* "close drawer" description */
    );
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();

    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
    }

    getSupportActionBar()
            .setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary)));
    getWindow().setStatusBarColor(getResources().getColor(R.color.status_bar_color));

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    Fragment fragment = FragmentCamera.newInstance(true);
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.content_frame, fragment, "FragmentCamera");
    ft.commit();

    fillDB();

}

From source file:com.google.android.apps.santatracker.games.common.GameActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setHomeButtonEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setBackgroundDrawable(
                new ColorDrawable(ContextCompat.getColor(this, android.R.color.transparent)));
    }// w w w  .j a v  a  2  s  . c  o m

    mGamesFragment = PlayGamesFragment.getInstance(this, this);

    mApiClient = new GoogleApiClient.Builder(this).addApi(AppIndex.APP_INDEX_API).build();
    // add App Indexing API
    BASE_APP_URI = Uri.parse("android-app://" + getApplicationContext().getPackageName() + "/"
            + getResources().getString(R.string.santa_tracker_deep_link_prefix));

    if (Utils.hasKitKat()) {
        ImmersiveModeHelper.setImmersiveSticky(getWindow());
        ImmersiveModeHelper.installSystemUiVisibilityChangeListener(getWindow());
    }
}