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.auth0.android.lock.views.ActionButton.java

private Drawable generateStateBackground(Theme lockTheme) {
    int normalColor = lockTheme.getPrimaryColor(getContext());
    int pressedColor = lockTheme.getDarkPrimaryColor(getContext());
    int disabledColor = ContextCompat.getColor(getContext(), R.color.com_auth0_lock_submit_disabled);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        return new RippleDrawable(ColorStateList.valueOf(pressedColor), new ColorDrawable(normalColor), null);
    } else {//from  w  w  w  .  java 2 s  . c  o  m
        StateListDrawable states = new StateListDrawable();
        states.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_pressed },
                new ColorDrawable(pressedColor));
        states.addState(new int[] { android.R.attr.state_enabled }, new ColorDrawable(normalColor));
        states.addState(new int[] {}, new ColorDrawable(disabledColor));
        return states;
    }
}

From source file:it.scoppelletti.mobilepower.preference.ColorPreference.java

/**
 * Imposta il colore./*w  ww  .jav a2  s.  com*/
 * 
 * @param value     Valore.
 * @param component Codice del componente.
 */
private void setColor(int value, int component) {
    int red, green, blue;

    switch (component) {
    case Color.RED:
        red = value;
        green = Color.green(myEditingValue);
        blue = Color.blue(myEditingValue);
        myEditingValue = Color.rgb(red, green, blue);
        break;

    case Color.GREEN:
        red = Color.red(myEditingValue);
        green = value;
        blue = Color.blue(myEditingValue);
        myEditingValue = Color.rgb(red, green, blue);
        break;

    case Color.BLUE:
        red = Color.red(myEditingValue);
        green = Color.green(myEditingValue);
        blue = value;
        myEditingValue = Color.rgb(red, green, blue);
        break;

    default:
        myEditingValue = value;
        break;
    }

    myEditingPreview.setImageDrawable(new ColorDrawable(myEditingValue));
}

From source file:com.massivcode.androidmusicplayer.fragments.AddPlaylistFragment.java

@Nullable
@Override/*from  w w w.  j  a v a 2s.  c o  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_add_playlist, container, false);

    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE));

    setCancelable(false);

    initViews(view);

    return view;
}

From source file:com.flowzr.activity.RecurActivity.java

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

    // Setup ActionBar      
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    //@see: http://stackoverflow.com/questions/16539251/get-rid-of-blue-line, 
    //only way found to remove on various devices 2.3x, 3.0, ...
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#000000")));

    setContentView(R.layout.recur);/*from  ww  w.  j a  v a 2  s .  c  o  m*/

    df = DateUtils.getLongDateFormat(this);

    stopsOnDate.add(Calendar.YEAR, 1);

    sInterval = (Spinner) findViewById(R.id.intervalSpinner);
    sPeriod = (Spinner) findViewById(R.id.recurSpinner);
    layoutInterval = (LinearLayout) findViewById(R.id.layoutInterval);
    layoutRecur = (LinearLayout) findViewById(R.id.recurInterval);

    bStartDate = (Button) findViewById(R.id.bStartDate);
    bStartDate.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            final Calendar c = startDate;
            DatePickerDialog d = new DatePickerDialog(RecurActivity.this,
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                            c.set(Calendar.YEAR, year);
                            c.set(Calendar.MONTH, monthOfYear);
                            c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                            DateUtils.startOfDay(c);
                            editStartDate(c.getTimeInMillis());
                        }
                    }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
            d.show();
        }
    });

    addSpinnerItems(sInterval,
            new RecurInterval[] { RecurInterval.NO_RECUR, RecurInterval.WEEKLY, RecurInterval.MONTHLY });
    addSpinnerItems(sPeriod, periods);

    LayoutInflater inflater = getLayoutInflater();
    //addLayouts(inflater, layoutInterval, intervals);
    addLayouts(inflater, layoutRecur, periods);

    Recur recur = RecurUtils.createDefaultRecur();
    Intent intent = getIntent();
    if (intent != null) {
        String extra = intent.getStringExtra(EXTRA_RECUR);
        if (extra != null) {
            recur = RecurUtils.createFromExtraString(extra);
        }
    }
    editRecur(recur);

    sInterval.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            RecurInterval interval = getRecurInterval(sInterval.getSelectedItem());
            selectInterval(interval);
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }

    });

    sPeriod.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            RecurPeriod period = periods[position];
            selectPeriod(period);
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }

    });

}

From source file:beihua.example.com.kouding_app.MainActivity.java

private void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);//from   www. j av  a2 s  .  c  om

    // 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 });

            // workaround for broken ActionBarContainer drawable handling on
            // pre-API 17 builds
            // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4
            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.chenenyu.areapicker.AreaPicker.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = super.onCreateDialog(savedInstanceState);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    return dialog;
}

From source file:arun.com.popularmovies.MovieDetailActivity.java

private void populateUI() {
    if (getSupportActionBar() != null)
        getSupportActionBar().setTitle(mMovie.getTitle());

    // load the backdrop image
    String backdropPath = new PosterSize(this).getFormattedBackdropPath(mMovie.getBackdrop_path());

    Glide.with(this).load(backdropPath).crossFade()
            .listener(GlidePalette.with(backdropPath).intoCallBack(new BitmapPalette.CallBack() {
                @Override/*ww w.j ava2 s . co  m*/
                public void onPaletteLoaded(Palette palette) {
                    int fabColor = Utility.getDarkColorFromPalette(palette,
                            ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
                    updateFAB(fabColor);
                }
            })).placeholder(new ColorDrawable(ContextCompat.getColor(this, R.color.colorPrimaryDark)))
            .into(mBackdrop);

    ((ImageView) findViewById(R.id.movie_poster_detail))
            .setImageDrawable(MovieGridFragment.mPosterCache.get(1));

    String movieName = mMovie.getOriginal_title() != null ? mMovie.getOriginal_title() : mMovie.getTitle();

    ((TextView) findViewById(R.id.movie_title)).setText(movieName);

    ((TextView) findViewById(R.id.movie_summary)).setText(mMovie.getOverview());

    ((TextView) findViewById(R.id.movie_release)).setText(Utility.getReleaseDate(mMovie.getRelease_date()));

    ((TextView) findViewById(R.id.movie_rating)).setText(mMovie.getVote_average() + " / 10");
}

From source file:com.filemanager.free.activities.Preferences.java

@Override
public void onCreate(Bundle savedInstanceState) {
    SharedPreferences Sp = PreferenceManager.getDefaultSharedPreferences(this);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.prefsfrag);//from w  w w  .  j  av a 2  s .  co  m
    mHandler = new Handler();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    skin = PreferenceUtils.getSkinColor(Sp.getInt("skin_color_position", 9));
    if (Build.VERSION.SDK_INT >= 21) {
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("File Manager",
                ((BitmapDrawable) ContextCompat.getDrawable(getBaseContext(), R.mipmap.ic_launcher))
                        .getBitmap(),
                Color.parseColor(skin));
        setTaskDescription(taskDescription);
    }
    skinStatusBar = PreferenceUtils.getStatusColor(skin);
    setSupportActionBar(toolbar);
    assert (getSupportActionBar()) != null;
    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE);
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(skin)));
    int sdk = Build.VERSION.SDK_INT;

    if (sdk == 20 || sdk == 19) {
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setStatusBarTintColor(Color.parseColor(skin));

        FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.preferences)
                .getLayoutParams();
        SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
        p.setMargins(0, config.getStatusBarHeight(), 0, 0);
    } else if (Build.VERSION.SDK_INT >= 21) {
        boolean colourednavigation = Sp.getBoolean("colorednavigation", true);
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor((PreferenceUtils.getStatusColor(skin)));
        if (colourednavigation)
            window.setNavigationBarColor((PreferenceUtils.getStatusColor(skin)));

    }
    selectItem(0);
}

From source file:com.calgen.udacity.lego.ui.ArticleDetailActivity.java

private void setUpPager() {
    mPagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
    pager.setAdapter(mPagerAdapter);/* ww  w. j  av a2 s  . com*/
    pager.setPageMargin(Utils.dpToPx(1));
    pager.setPageMarginDrawable(new ColorDrawable(0x22000000));
    pager.setOnPageChangeListener(this);
}

From source file:com.emotiona.study.listviewpage.SwipeMenuListViewFragment.java

private void initData() {
    mAppList = getActivity().getPackageManager().getInstalledApplications(0);
    mAdapter = new AppAdapter();
    mListView.setAdapter(mAdapter);//  w  w w.  j a va2  s. com

    // step 1. create a MenuCreator
    SwipeMenuCreator creator = new SwipeMenuCreator() {

        @Override
        public void create(SwipeMenu menu) {
            // create "open" item
            SwipeMenuItem openItem = new SwipeMenuItem(getActivity());
            // set item background
            openItem.setBackground(new ColorDrawable(Color.rgb(0xC9, 0xC9, 0xCE)));
            // set item width
            openItem.setWidth(dp2px(90));
            // set item title
            openItem.setTitle("Open");
            // set item title fontsize
            openItem.setTitleSize(18);
            // set item title font color
            openItem.setTitleColor(Color.WHITE);
            openItem.setIcon(android.R.drawable.ic_menu_add);
            // add to menu
            menu.addMenuItem(openItem);

            // create "delete" item
            SwipeMenuItem deleteItem = new SwipeMenuItem(getActivity());
            // set item background
            deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9, 0x3F, 0x25)));
            // set item width
            deleteItem.setWidth(dp2px(90));
            // set a icon
            deleteItem.setIcon(android.R.drawable.ic_delete);
            // add to menu
            menu.addMenuItem(deleteItem);
        }
    };
    // set creator
    mListView.setMenuCreator(creator);

    // step 2. listener item click event
    mListView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
            ApplicationInfo item = mAppList.get(position);
            switch (index) {
            case 0:
                // open
                open(item);
                break;
            case 1:
                // delete
                //               delete(item);
                mAppList.remove(position);
                mAdapter.notifyDataSetChanged();
                break;
            }
            return false;
        }
    });

    // set SwipeListener
    mListView.setOnSwipeListener(new SwipeMenuListView.OnSwipeListener() {

        @Override
        public void onSwipeStart(int position) {
            // swipe start
        }

        @Override
        public void onSwipeEnd(int position) {
            // swipe end
        }
    });

    // set MenuStateChangeListener
    mListView.setOnMenuStateChangeListener(new SwipeMenuListView.OnMenuStateChangeListener() {
        @Override
        public void onMenuOpen(int position) {

        }

        @Override
        public void onMenuClose(int position) {

        }
    });
    // other setting
    //      listView.setCloseInterpolator(new BounceInterpolator());

    // test item long click
    mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(getActivity(), position + " long click", Toast.LENGTH_SHORT).show();
            return false;
        }
    });
}