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.filemanager.free.ui.views.FastScroller.java

private void setUpBarBackground() {
    InsetDrawable insetDrawable;//www  .  j  a  v  a2 s  .c  o  m
    int resolveColor = resolveColor(getContext(), R.attr.colorControlNormal);
    insetDrawable = new InsetDrawable(new ColorDrawable(resolveColor),
            getResources().getDimensionPixelSize(R.dimen.fastscroller_track_padding), 0, 0, 0);
    this.bar.setBackgroundDrawable(insetDrawable);
}

From source file:com.frankegan.sqrshare.MainActivity.java

/**
 * {@inheritDoc}//from w w w . j  ava 2s .c o m
 */
@Override
public void onColorsCalculated(Integer vib) {
    pic_fragment.setFabColor(vib);
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(vib));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        status.setBackgroundColor(vib);
}

From source file:com.hannesdorfmann.mosby3.sample.mvi.view.shoppingcartoverview.ShoppingCartOverviewFragment.java

private void setUpItemTouchHelper() {

    ///*from w  ww .  j av a2 s . co  m*/
    // Borrowed from https://github.com/nemanja-kovacevic/recycler-view-swipe-to-delete/blob/master/app/src/main/java/net/nemanjakovacevic/recyclerviewswipetodelete/MainActivity.java
    //

    ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0,
            ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {

        // we want to cache these and not allocate anything repeatedly in the onChildDraw method
        Drawable background;
        Drawable xMark;
        int xMarkMargin;
        boolean initiated;

        private void init() {
            background = new ColorDrawable(ContextCompat.getColor(getActivity(), R.color.delete_background));
            xMark = ContextCompat.getDrawable(getActivity(), R.drawable.ic_remove);
            xMarkMargin = (int) getActivity().getResources().getDimension(R.dimen.ic_clear_margin);
            initiated = true;
        }

        // not important, we don't want drag & drop
        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
                RecyclerView.ViewHolder target) {
            return false;
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
            int swipedPosition = viewHolder.getAdapterPosition();
            Product productAt = adapter.getProductAt(swipedPosition);
            removeRelay.onNext(productAt);
        }

        @Override
        public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
                float dX, float dY, int actionState, boolean isCurrentlyActive) {
            View itemView = viewHolder.itemView;

            // not sure why, but this method get's called for viewholder that are already swiped away
            if (viewHolder.getAdapterPosition() == -1) {
                // not interested in those
                return;
            }

            if (!initiated) {
                init();
            }

            // draw red background
            background.setBounds(itemView.getRight() + (int) dX, itemView.getTop(), itemView.getRight(),
                    itemView.getBottom());
            background.draw(c);

            // draw x mark
            int itemHeight = itemView.getBottom() - itemView.getTop();
            int intrinsicWidth = xMark.getIntrinsicWidth();
            int intrinsicHeight = xMark.getIntrinsicWidth();

            int xMarkLeft = itemView.getRight() - xMarkMargin - intrinsicWidth;
            int xMarkRight = itemView.getRight() - xMarkMargin;
            int xMarkTop = itemView.getTop() + (itemHeight - intrinsicHeight) / 2;
            int xMarkBottom = xMarkTop + intrinsicHeight;
            xMark.setBounds(xMarkLeft, xMarkTop, xMarkRight, xMarkBottom);

            // xMark.draw(c);

            super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
        }
    };
    ItemTouchHelper mItemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
    mItemTouchHelper.attachToRecyclerView(recyclerView);
}

From source file:augsburg.se.alltagsguide.utilities.ui.BaseActivity.java

protected void changeColor(@ColorInt int primaryColor) {
    ColorDrawable colorDrawableActivity = new ColorDrawable(primaryColor);
    ColorDrawable colorDrawableTabs = new ColorDrawable(primaryColor);
    ActionBar ab = getSupportActionBar();
    if (ab != null) {
        if (oldBackgroundActivity == null) {
            ab.setBackgroundDrawable(colorDrawableActivity);
            changeTabColor(colorDrawableTabs, primaryColor);
        } else {// ww w  . jav  a 2s .  c  o  m
            TransitionDrawable tdActivity = new TransitionDrawable(
                    new Drawable[] { oldBackgroundActivity, colorDrawableActivity });
            TransitionDrawable tdTabs = new TransitionDrawable(
                    new Drawable[] { oldBackgroundTabs, colorDrawableTabs });
            ab.setBackgroundDrawable(tdActivity);
            changeTabColor(tdTabs, primaryColor);
            tdActivity.startTransition(DURATION);
            tdTabs.startTransition(DURATION);
        }
    }
    oldBackgroundActivity = colorDrawableActivity;
    oldBackgroundTabs = colorDrawableTabs;
    mPrefUtilities.saveCurrentColor(primaryColor);
}

From source file:com.example.android.uvdemo.UVFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getListView().setDivider(null);//from  w  w  w  . jav a2  s.c  o  m
    getListView().setDividerHeight(0);
    mUvItems = new ArrayList<UvItem>();
    mFeedListAdapter = new UVListAdapter(getActivity(), mUvItems);

    // Set the adapter between the ListView and its backing data.
    setListAdapter(mFeedListAdapter);

    // BEGIN_INCLUDE (setup_refreshlistener)
    /**
     * Implement {@link SwipeRefreshLayout.OnRefreshListener}. When users do the "swipe to
     * refresh" gesture, SwipeRefreshLayout invokes
     * {@link SwipeRefreshLayout.OnRefreshListener#onRefresh onRefresh()}. In
     * {@link SwipeRefreshLayout.OnRefreshListener#onRefresh onRefresh()}, call a method that
     * refreshes the content. Call the same method in response to the Refresh action from the
     * action bar.
     */
    // These two lines not needed,
    // just to get the look of facebook (changing background color & hiding the icon)
    getActivity().getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#3b5998")));
    getActivity().getActionBar()
            .setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
    setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            Log.i(LOG_TAG, "onRefresh called from SwipeRefreshLayout");
            doRequest();
            //                initiateRefresh();
        }
    });
    doRequest();

    // END_INCLUDE (setup_refreshlistener)
}

From source file:com.example.george.sharedelementimplementation.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_animations);

    mGridView = (MyGridView) findViewById(R.id.gv_photo_grid);
    PhotoGridAdapter mAdapter = new PhotoGridAdapter(this);
    pictures = mBitmapUtils.loadPhotos(getResources());
    mAdapter.updateData(pictures);/*from   w ww . ja  v a 2s.  co  m*/
    mGridView.setAdapter(mAdapter);

    // the image for pop up animation effect
    mImage = (ClippingImageView) findViewById(R.id.iv_animation);
    mImage.setVisibility(View.GONE);

    // set the background color in the fullscreen
    mTopLevelLayout = (RelativeLayout) findViewById(R.id.rl_fullscreen_bg);
    mBackground = new ColorDrawable(Color.BLACK);
    mBackground.setAlpha(0);
    mTopLevelLayout.setBackground(mBackground);

    mPager = (ClickableViewPager) findViewById(R.id.pager);
    mPager.setVisibility(View.GONE);

    // enable/disable touch event
    mGridView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (mIsInFullscreen) {
                // returning true means that this event has been consumed
                // in fullscreen the grid view is not responding any finger interaction
                return true;
            }
            return false;
        }
    });

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

            mIsInFullscreen = true;
            // set the animating image to the clicked item
            Drawable drawable = ((ImageView) view).getDrawable();
            mImage.setImageDrawable(drawable);
            mImage.setVisibility(View.VISIBLE);

            // reset image translation
            mImage.setTranslationX(0);
            mImage.setTranslationY(0);

            // reset pager's adapter every time a view in Grid view is clicked
            mPager.setAdapter(new PhotoViewAdapter(MainActivity.this, pictures));
            mPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                @Override
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                }

                @Override
                public void onPageSelected(int position) {
                }

                @Override
                public void onPageScrollStateChanged(int state) {
                    // the GirdView should follow the Pager
                    mGridView.smoothScrollToPosition(mPager.getCurrentItem());
                }
            });
            mPager.setCurrentItem(position, false);

            final float drawableWidth = drawable.getIntrinsicWidth();
            final float drawableHeight = drawable.getIntrinsicHeight();
            // calculate the clicked view's location and width/height
            final float heightWidthRatio = drawableHeight / drawableWidth;
            final int thumbnailWidth = view.getWidth();
            final int thumbnailHeight = view.getHeight();

            int[] viewLocation = new int[2];
            int[] gridViewLocation = new int[2];
            view.getLocationOnScreen(viewLocation);
            mGridView.getLocationOnScreen(gridViewLocation);
            final int thumbnailX = viewLocation[0] + thumbnailWidth / 2;
            final int thumbnailY = viewLocation[1] + thumbnailHeight / 2;
            final int fullscreenX = gridViewLocation[0] + mGridView.getWidth() / 2;
            final int fullscreenY = gridViewLocation[1] + mGridView.getHeight() / 2;

            Log.d(TAG, "viewLocation=" + viewLocation[0] + ", " + viewLocation[1] + "\ngridViewLocation="
                    + gridViewLocation[0] + ", " + gridViewLocation[1]);
            Log.d(TAG, "thumbnailX=" + thumbnailX + ", thumbnailY=" + thumbnailY + "\nfullscreenX="
                    + fullscreenX + ", fullscreenY=" + fullscreenY);

            // for image transform, we need 3 arguments to transform properly:
            // deltaX and deltaY - the translation of the image
            // scale value - the resize value
            // clip ratio - the reveal part of the image

            // figure out where the thumbnail and full size versions are, relative
            // to the screen and each other
            mXDelta = thumbnailX - fullscreenX;
            mYDelta = thumbnailY - fullscreenY;

            // Scale factors to make the large version the same size as the thumbnail
            if (heightWidthRatio < 1) {
                mImageScale = (float) thumbnailHeight / mImage.getLayoutParams().height;
            } else {
                mImageScale = (float) thumbnailWidth / mImage.getLayoutParams().width;
            }

            // clip ratio
            if (heightWidthRatio < 1) {
                // if the original picture is in landscape
                clipRatio = 1 - heightWidthRatio;
            } else {
                // if the original picture is in portrait
                clipRatio = 1 - 1 / heightWidthRatio;
            }

            Log.d(TAG, "*************************Enter Animation*************************");
            Log.d(TAG, "(mXDelta, mTopDelta)=(" + mXDelta + ", " + mYDelta + ")\nmImageScale=" + mImageScale
                    + "\nclipRatio=" + clipRatio);

            runEnterAnimation();
        }
    });
}

From source file:com.lesikapk.opengelplus.settings.SettingsActivity.java

public void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);//from  w  w  w. jav a  2 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.background_tab);
        LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });

        // This is actually unnecessary because the actionbar is hidden anyways, however I will leave this because of the transition.
        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.example.castCambot.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(android.R.color.transparent));

    // When the user clicks on the button, use Android voice recognition to
    // get text/*from  w  ww .  j  a  v a 2  s  .  co  m*/

    Button voiceButton = (Button) findViewById(R.id.voiceButton);
    voiceButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            startVoiceRecognitionActivity();
        }
    });

    Button buttonOK = (Button) findViewById(R.id.buttonOK);
    buttonOK.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //startVoiceRecognitionActivity();
            EditText editText1 = (EditText) findViewById(R.id.editText1);
            cambotIP = editText1.getText().toString();
            Button buttonOK = (Button) findViewById(R.id.buttonOK);
            buttonOK.setVisibility(View.INVISIBLE);

            /*
            WebView   mWebView = (WebView) findViewById(R.id.webView1);
            mWebView.getSettings().setJavaScriptEnabled(true);     
            mWebView.getSettings().setLoadWithOverviewMode(true);
            mWebView.getSettings().setUseWideViewPort(true);     
            //mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
            mWebView.loadUrl("file:///android_asset/cambot.html");
            */
        }
    });

    Button button2 = (Button) findViewById(R.id.button2);
    button2.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN)
                //System.out.println("Touch");
                myHttpPost("go_forward");
            else if (action == MotionEvent.ACTION_UP)
                //System.out.println("Release");
                myHttpPost("stop");
            return false; //  the listener has NOT consumed the event, pass it on
        }
    });

    Button button4 = (Button) findViewById(R.id.button4);
    button4.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN)
                //System.out.println("Touch");
                myHttpPost("turn_left");
            else if (action == MotionEvent.ACTION_UP)
                //System.out.println("Release");
                myHttpPost("stop");
            return false; //  the listener has NOT consumed the event, pass it on
        }
    });

    Button button6 = (Button) findViewById(R.id.button6);
    button6.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN)
                //System.out.println("Touch");
                myHttpPost("turn_right");
            else if (action == MotionEvent.ACTION_UP)
                //System.out.println("Release");
                myHttpPost("stop");
            return false; //  the listener has NOT consumed the event, pass it on
        }
    });

    Button button8 = (Button) findViewById(R.id.button8);
    button8.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN)
                //System.out.println("Touch");
                myHttpPost("go_backward");
            else if (action == MotionEvent.ACTION_UP)
                //System.out.println("Release");
                myHttpPost("stop");
            return false; //  the listener has NOT consumed the event, pass it on
        }
    });

    // Configure Cast device discovery
    mMediaRouter = MediaRouter.getInstance(getApplicationContext());
    mMediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory(
            CastMediaControlIntent.categoryForCast(getResources().getString(R.string.app_id))).build();
    mMediaRouterCallback = new MyMediaRouterCallback();
}

From source file:com.amaze.filemanager.activities.DatabaseViewerActivity.java

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

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);

    if (getAppTheme().equals(AppTheme.DARK)) {
        setTheme(R.style.appCompatDark);
        getWindow().getDecorView().setBackgroundColor(Utils.getColor(this, R.color.holo_dark_background));
    } else if (getAppTheme().equals(AppTheme.BLACK)) {
        setTheme(R.style.appCompatBlack);
        getWindow().getDecorView().setBackgroundColor(Utils.getColor(this, android.R.color.black));
    }/*from w w  w .  j  a  v  a 2 s . c om*/
    setContentView(R.layout.activity_db_viewer);
    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    @ColorInt
    int primaryColor = ColorPreferenceHelper.getPrimary(getCurrentColorPreference(), MainActivity.currentTab);

    if (SDK_INT >= 21) {
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("Amaze",
                ((BitmapDrawable) ContextCompat.getDrawable(this, R.mipmap.ic_launcher)).getBitmap(),
                primaryColor);
        setTaskDescription(taskDescription);
    }

    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(primaryColor));

    boolean useNewStack = sharedPref.getBoolean(PreferencesConstants.PREFERENCE_TEXTEDITOR_NEWSTACK, false);

    getSupportActionBar().setDisplayHomeAsUpEnabled(!useNewStack);

    if (SDK_INT == 20 || SDK_INT == 19) {
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setStatusBarTintColor(
                ColorPreferenceHelper.getPrimary(getCurrentColorPreference(), MainActivity.currentTab));
        FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.parentdb)
                .getLayoutParams();
        SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
        p.setMargins(0, config.getStatusBarHeight(), 0, 0);
    } else if (SDK_INT >= 21) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor(PreferenceUtils.getStatusColor(primaryColor));
        if (getBoolean(PREFERENCE_COLORED_NAVIGATION))
            window.setNavigationBarColor(PreferenceUtils.getStatusColor(primaryColor));

    }

    path = getIntent().getStringExtra("path");
    pathFile = new File(path);
    listView = findViewById(R.id.listView);

    load(pathFile);
    listView.setOnItemClickListener((parent, view, position, id) -> {
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        DbViewerFragment fragment = new DbViewerFragment();
        Bundle bundle = new Bundle();
        bundle.putString("table", arrayList.get(position));
        fragment.setArguments(bundle);
        fragmentTransaction.add(R.id.content_frame, fragment);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();
    });

}

From source file:com.daking.sports.view.banner.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*from  w w  w  .  ja  v a 2s. co  m*/

    //Load defaults from resources
    final int defaultPageColor = Color.parseColor("#00000000");
    final int defaultFillColor = Color.parseColor("#FFFFFFFF");
    final int defaultOrientation = 0;
    final int defaultStrokeColor = Color.parseColor("#FFDDDDDD");
    final float defaultStrokeWidth = 2;
    final float defaultRadius = 6;
    final boolean defaultCentered = true;
    final boolean defaultSnap = false;

    //Retrieve styles attributes
    //        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle, 0);

    mCentered = defaultCentered;
    mOrientation = defaultOrientation;
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(defaultPageColor);
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(defaultStrokeColor);
    mPaintStroke.setStrokeWidth(defaultStrokeWidth);
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(defaultFillColor);
    mRadius = defaultRadius;
    mSelectedRadius = defaultRadius;
    mSnap = defaultSnap;

    Drawable background = new ColorDrawable(Color.parseColor("#FFFFFF"));
    setBackgroundDrawable(background);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}