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:cn.finalteam.galleryfinal.widget.FloatingActionButton.java

Drawable getIconDrawable() {
    if (mIcon != 0) {
        return ContextCompat.getDrawable(getContext(), mIcon);
    } else {/*from  w w w. j  a v  a 2  s  . c o  m*/
        return new ColorDrawable(Color.TRANSPARENT);
    }
}

From source file:com.lumisky.bluetooth_led.Interface.Bulbs.BulbsActivity.java

private void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);/*w  w  w. java 2  s  .c o m*/

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

        getActionBar().setDisplayShowTitleEnabled(false);
        getActionBar().setDisplayShowTitleEnabled(true);

    }

    currentColor = newColor;

}

From source file:android.support.design.internal.NavigationMenuItemView.java

private StateListDrawable createDefaultBackground() {
    TypedValue value = new TypedValue();
    if (getContext().getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.colorControlHighlight,
            value, true)) {/* w  w w  . ja  v a 2 s .c o m*/
        StateListDrawable drawable = new StateListDrawable();
        drawable.addState(CHECKED_STATE_SET, new ColorDrawable(value.data));
        drawable.addState(EMPTY_STATE_SET, new ColorDrawable(Color.TRANSPARENT));
        return drawable;
    }
    return null;
}

From source file:com.grepsound.activities.MainActivity.java

private void setupNavigationDrawer(boolean locked) {
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            mToolbar, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */) {

        public ColorDrawable toolbarDrawable;
        public int toolbarColor = getResources().getColor(R.color.holo_orange_light);

        public void onDrawerClosed(View view) {
            invalidateOptionsMenu(); // creates call to
            // onPrepareOptionsMenu()
            Log.i(TAG, "CLOSED");
        }//from   w ww.ja  v  a  2s.c o m

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, slideOffset);
            int ratioRed = Math.round(Color.red(toolbarColor) - Color.red(toolbarColor) * slideOffset);
            int ratioGreen = Math.round(Color.green(toolbarColor) - Color.green(toolbarColor) * slideOffset);
            int ratioBlue = Math.round(Color.blue(toolbarColor) - Color.blue(toolbarColor) * slideOffset);

            toolbarDrawable = new ColorDrawable(Math.round(0xFFFFFFFF * slideOffset));
            toolbarDrawable.setColor(Color.argb(255, ratioRed, ratioGreen, ratioBlue));

            getSupportActionBar().setBackgroundDrawable(toolbarDrawable);
        }

        public void onDrawerOpened(View drawerView) {
            invalidateOptionsMenu(); // creates call to
            Log.i(TAG, "OPEN");
            // onPrepareOptionsMenu()
        }

    };

    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i(TAG, "GOOD");
            if (getFragmentManager().getBackStackEntryCount() > 0)
                getFragmentManager().popBackStack();
            else {
                if (mDrawerLayout.isDrawerOpen(GravityCompat.START))
                    mDrawerLayout.closeDrawer(GravityCompat.START);
                else
                    mDrawerLayout.openDrawer(GravityCompat.START);
            }
        }
    });

    if (locked) {
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
        mDrawerLayout.setScrimColor(Color.TRANSPARENT);
    } else {
        mDrawerLayout.setDrawerListener(mDrawerToggle);
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    }

    mDrawerToggle.setDrawerIndicatorEnabled(!locked);
    getSupportActionBar().setHomeButtonEnabled(!locked);
}

From source file:com.digium.respoke.ChatActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    Button buttonSend = (Button) findViewById(R.id.buttonSend);

    EditText chatText = (EditText) findViewById(R.id.chatText);
    chatText = (EditText) findViewById(R.id.chatText);
    chatText.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                sendChatMessage();//from  w  ww .  ja va  2 s  .com
                return true;
            }
            return false;
        }
    });
    buttonSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            sendChatMessage();
        }
    });

    String remoteEndpointID = null;
    boolean shouldStartDirectConnection = false;

    // Check whether we're recreating a previously destroyed instance
    if (savedInstanceState != null) {
        remoteEndpointID = savedInstanceState.getString(ENDPOINT_ID_KEY);
        shouldStartDirectConnection = savedInstanceState.getBoolean(DIRECT_CONNECTION_KEY, false);
    } else {
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            remoteEndpointID = extras.getString(ENDPOINT_ID_KEY);
            shouldStartDirectConnection = extras.getBoolean(DIRECT_CONNECTION_KEY, false);
        } else {
            // The activity must have been destroyed while it was hidden to save memory. Use the most recent persistent data.
            SharedPreferences prefs = getSharedPreferences(ConnectActivity.RESPOKE_SETTINGS, 0);
            remoteEndpointID = prefs.getString(ENDPOINT_ID_KEY, "");
            shouldStartDirectConnection = prefs.getBoolean(DIRECT_CONNECTION_KEY, false);
        }
    }

    conversation = ContactManager.sharedInstance().conversations.get(remoteEndpointID);
    remoteEndpoint = ContactManager.sharedInstance().sharedClient.getEndpoint(remoteEndpointID, true);
    setTitle(remoteEndpoint.getEndpointID());

    listAdapter = new ListDataAdapter();

    ListView lv = (ListView) findViewById(R.id.list); //retrieve the instance of the ListView from your main layout
    lv.setAdapter(listAdapter); //assign the Adapter to be used by the ListView

    if (shouldStartDirectConnection && (null == remoteEndpoint.directConnection())) {
        // If the direct connection has not been started yet, start it now
        remoteEndpoint.startDirectConnection();
    }

    directConnection = remoteEndpoint.directConnection();
    if (null != directConnection) {
        directConnection.setListener(this);
        RespokeCall call = directConnection.getCall();
        boolean caller = false;

        if (null != call) {
            call.setListener(this);
            caller = call.isCaller();
        }

        View answerView = findViewById(R.id.answer_view);
        View connectingView = findViewById(R.id.connecting_view);
        TextView callerNameView = (TextView) findViewById(R.id.caller_name_text);

        if (caller) {
            answerView.setVisibility(View.INVISIBLE);
            connectingView.setVisibility(View.VISIBLE);
        } else {
            answerView.setVisibility(View.VISIBLE);
            connectingView.setVisibility(View.INVISIBLE);
        }

        if (null != remoteEndpoint) {
            callerNameView.setText(remoteEndpoint.getEndpointID());
        } else {
            callerNameView.setText("Unknown Caller");
        }

        ActionBar actionBar = getActionBar();
        actionBar.setBackgroundDrawable(new ColorDrawable(R.color.incoming_connection_bg));
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowTitleEnabled(true);
    }
}

From source file:cn.njmeter.njmeter.widget.spinner.NiceSpinner.java

private void init(Context context, AttributeSet attrs) {
    Resources resources = getResources();
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NiceSpinner);
    int defaultPadding = resources.getDimensionPixelSize(R.dimen.one_and_a_half_grid_unit);

    setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
    setPadding(resources.getDimensionPixelSize(R.dimen.three_grid_unit), defaultPadding, defaultPadding,
            defaultPadding);//  www  .j  ava2s  . c  o m
    setClickable(true);

    backgroundSelector = typedArray.getResourceId(R.styleable.NiceSpinner_backgroundSelector,
            R.drawable.selector);
    setBackgroundResource(backgroundSelector);
    textColor = typedArray.getColor(R.styleable.NiceSpinner_textTint, getDefaultTextColor(context));
    setTextColor(textColor);

    listView = new ListView(context);
    // Set the spinner's id into the listview to make it pretend to be the right parent in
    // onItemClick
    listView.setId(getId());
    listView.setDivider(new ColorDrawable(Color.GRAY));
    listView.setDividerHeight(1);
    listView.setItemsCanFocus(true);
    //hide vertical and horizontal scrollbars
    listView.setVerticalScrollBarEnabled(false);
    listView.setHorizontalScrollBarEnabled(false);
    listView.setOverScrollMode(OVER_SCROLL_NEVER);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectedIndex = position;

            if (onItemClickListener != null) {
                onItemClickListener.onItemClick(parent, view, position, id);
            }

            if (onItemSelectedListener != null) {
                onItemSelectedListener.onItemSelected(parent, view, position, id);
            }

            adapter.setSelectedIndex(position);
            setTextInternal(adapter.getItemInDataset(position).toString());
            dismissDropDown();
        }
    });

    popupWindow = new PopupWindow(context);
    popupWindow.setContentView(listView);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setFocusable(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        popupWindow.setElevation(DEFAULT_ELEVATION);
        popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.spinner_drawable));
    } else {
        popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.drop_down_shadow));
    }

    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            if (!isArrowHidden) {
                animateArrow(false);
            }
        }
    });

    isArrowHidden = typedArray.getBoolean(R.styleable.NiceSpinner_hideArrow, false);
    arrowDrawableTint = typedArray.getColor(R.styleable.NiceSpinner_arrowTint, Integer.MAX_VALUE);
    arrowDrawableResId = typedArray.getResourceId(R.styleable.NiceSpinner_arrowDrawable, R.drawable.arrow);
    dropDownListPaddingBottom = typedArray
            .getDimensionPixelSize(R.styleable.NiceSpinner_dropDownListPaddingBottom, 0);
    typedArray.recycle();

    measureDisplayHeight();
}

From source file:com.lithidsw.wallbox.app.colorwall.ColorWallFrag.java

@Override
public void onClick(View view) {
    switch (view.getId()) {
    case R.id.color_black:
        mColor = getResources().getColor(R.color.black);
        mColorCode.setText(R.color.black);
        break;/*from   w  w  w .j  ava  2s  .  com*/
    case R.id.color_white:
        mColor = getResources().getColor(R.color.white);
        mColorCode.setText(R.color.white);
        break;
    case R.id.color_blue:
        mColor = getResources().getColor(R.color.blue);
        mColorCode.setText(R.color.blue);
        break;
    case R.id.color_purple:
        mColor = getResources().getColor(R.color.purple);
        mColorCode.setText(R.color.purple);
        break;
    case R.id.color_green:
        mColor = getResources().getColor(R.color.green);
        mColorCode.setText(R.color.green);
        break;
    case R.id.color_yellow:
        mColor = getResources().getColor(R.color.yellow);
        mColorCode.setText(R.color.yellow);
        break;
    case R.id.color_red:
        mColor = getResources().getColor(R.color.red);
        mColorCode.setText(R.color.red);
        break;
    }

    mPicker.setImageDrawable(new ColorDrawable(mColor));
}

From source file:com.insthub.O2OMobile.Activity.F0_ProfileActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.f0_profile);
    mUserId = getIntent().getIntExtra(USER_ID, 0);
    mServiceType = (SERVICE_TYPE) getIntent().getSerializableExtra(O2OMobileAppConst.SERVICE_TYPE);
    mListview = (ListView) findViewById(R.id.profile_listview);
    mHelp = (Button) findViewById(R.id.btn_help);
    LayoutInflater layoutInflater = LayoutInflater.from(this);
    mHeaderView = layoutInflater.inflate(R.layout.f0_profile_header, null);
    mBack = (ImageView) mHeaderView.findViewById(R.id.top_view_back);
    mSetting = (ImageView) mHeaderView.findViewById(R.id.top_view_setting);
    mAvatar = (RoundedWebImageView) mHeaderView.findViewById(R.id.iv_avarta);
    mName = (TextView) mHeaderView.findViewById(R.id.tv_name);
    mBalance = (TextView) mHeaderView.findViewById(R.id.tv_balance);
    mSignature = (TextView) mHeaderView.findViewById(R.id.tv_signature);
    mBrief = (TextView) mHeaderView.findViewById(R.id.tv_brief);
    mBrief_detail = (TextView) mHeaderView.findViewById(R.id.brief_detail);
    //        mMyCash = (RelativeLayout) mHeaderView.findViewById(R.id.my_cash);
    mComment = (RelativeLayout) mHeaderView.findViewById(R.id.comment);
    mCommentCount = (TextView) mHeaderView.findViewById(R.id.tv_comment_count);
    mCommentGoodrate = (TextView) mHeaderView.findViewById(R.id.tv_comment_goodrate);
    mComplain = (TextView) mHeaderView.findViewById(R.id.complain);
    mGridviewServiceList = (MyGridView) mHeaderView.findViewById(R.id.grid_view_service_list);
    mGridview = (LinearLayout) mHeaderView.findViewById(R.id.gridview);
    mBirefLayout = (LinearLayout) mHeaderView.findViewById(R.id.ll_brief);
    mRefresh = (ImageView) mHeaderView.findViewById(R.id.refresh);
    mGridviewServiceList.setSelector(new ColorDrawable(Color.TRANSPARENT));
    mListview.addHeaderView(mHeaderView);
    mListview.setAdapter(null);/*  w  w w  . j a  va2  s  .c  o m*/
    mUserBalance = new UserBalanceModel(this);
    mUserBalance.addResponseListener(this);
    mUserBalance.getProfile(mUserId);
    mBack.setOnClickListener(this);
    mSetting.setOnClickListener(this);
    mBrief_detail.setOnClickListener(this);
    mHelp.setOnClickListener(this);
    mComment.setOnClickListener(this);
    mComplain.setOnClickListener(this);
    mAvatar.setOnClickListener(this);
    mRefresh.setOnClickListener(this);
    if (mUserId != SESSION.getInstance().uid) {
        mSetting.setVisibility(View.GONE);
        mComplain.setVisibility(View.VISIBLE);
    } else {
        mUserBalance.get();
    }
    EventBus.getDefault().register(this);
}

From source file:com.list.helper.view.listviewhelper.SwipeListViewHelper.java

@Override
public void setDivider(int ColorId) {
    mListView.setDivider(new ColorDrawable(ColorId));
}

From source file:com.google.android.apps.muzei.gallery.GallerySettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gallery_activity);
    Toolbar appBar = (Toolbar) findViewById(R.id.app_bar);
    setSupportActionBar(appBar);//w w  w  .j  a va 2 s  .  co m

    getSupportLoaderManager().initLoader(0, null, this);

    bindService(new Intent(this, GalleryArtSource.class).setAction(GalleryArtSource.ACTION_BIND_GALLERY),
            mServiceConnection, BIND_AUTO_CREATE);

    mPlaceholderDrawable = new ColorDrawable(
            ContextCompat.getColor(this, R.color.gallery_chosen_photo_placeholder));

    mPhotoGridView = (RecyclerView) findViewById(R.id.photo_grid);
    DefaultItemAnimator itemAnimator = new DefaultItemAnimator();
    itemAnimator.setSupportsChangeAnimations(false);
    mPhotoGridView.setItemAnimator(itemAnimator);
    setupMultiSelect();

    final GridLayoutManager gridLayoutManager = new GridLayoutManager(GallerySettingsActivity.this, 1);
    mPhotoGridView.setLayoutManager(gridLayoutManager);

    final ViewTreeObserver vto = mPhotoGridView.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            int width = mPhotoGridView.getWidth() - mPhotoGridView.getPaddingStart()
                    - mPhotoGridView.getPaddingEnd();
            if (width <= 0) {
                return;
            }

            // Compute number of columns
            int maxItemWidth = getResources()
                    .getDimensionPixelSize(R.dimen.gallery_chosen_photo_grid_max_item_size);
            int numColumns = 1;
            while (true) {
                if (width / numColumns > maxItemWidth) {
                    ++numColumns;
                } else {
                    break;
                }
            }

            int spacing = getResources().getDimensionPixelSize(R.dimen.gallery_chosen_photo_grid_spacing);
            mItemSize = (width - spacing * (numColumns - 1)) / numColumns;

            // Complete setup
            gridLayoutManager.setSpanCount(numColumns);
            mChosenPhotosAdapter.setHasStableIds(true);
            mPhotoGridView.setAdapter(mChosenPhotosAdapter);

            mPhotoGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            tryUpdateSelection(false);
        }
    });

    ViewCompat.setOnApplyWindowInsetsListener(mPhotoGridView, new OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(final View v, final WindowInsetsCompat insets) {
            int gridSpacing = getResources().getDimensionPixelSize(R.dimen.gallery_chosen_photo_grid_spacing);
            ViewCompat.onApplyWindowInsets(v,
                    insets.replaceSystemWindowInsets(insets.getSystemWindowInsetLeft() + gridSpacing,
                            gridSpacing, insets.getSystemWindowInsetRight() + gridSpacing,
                            insets.getSystemWindowInsetBottom() + insets.getSystemWindowInsetTop() + gridSpacing
                                    + getResources().getDimensionPixelSize(R.dimen.gallery_fab_space)));

            return insets;
        }
    });

    Button enableRandomImages = (Button) findViewById(R.id.gallery_enable_random);
    enableRandomImages.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View view) {
            ActivityCompat.requestPermissions(GallerySettingsActivity.this,
                    new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, REQUEST_STORAGE_PERMISSION);
        }
    });
    Button permissionSettings = (Button) findViewById(R.id.gallery_edit_permission_settings);
    permissionSettings.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View view) {
            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
                    Uri.fromParts("package", getPackageName(), null));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    });
    mAddButton = findViewById(R.id.add_photos_button);
    mAddButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Use ACTION_OPEN_DOCUMENT by default for adding photos.
            // This allows us to use persistent URI permissions to access the underlying photos
            // meaning we don't need to use additional storage space and will pull in edits automatically
            // in addition to syncing deletions.
            // (There's a separate 'Import photos' option which uses ACTION_GET_CONTENT to support legacy apps)
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            intent.setType("image/*");
            intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
            startActivityForResult(intent, REQUEST_CHOOSE_PHOTOS);
        }
    });
}