Here are the examples of the java api class android.graphics.drawable.ColorDrawable taken from open source projects.
1. UserActivityListItem#makeDefaultBackground()
Project: socialize-sdk-android
File: UserActivityListItem.java
File: UserActivityListItem.java
protected Drawable makeDefaultBackground() { // TODO: Make a singleton ColorDrawable shadow = makeColorDrawable(bottomColor); ColorDrawable highlight = makeColorDrawable(topColor); ColorDrawable surface = makeColorDrawable(bgColor); LayerDrawable layers = new LayerDrawable(new Drawable[] { shadow, highlight, surface }); layers.setLayerInset(0, 0, 0, 0, 0); layers.setLayerInset(1, 1, 0, 0, 1); layers.setLayerInset(2, 1, 1, 1, 1); return layers; }
2. ProfileContentView#makeButtonLayout()
Project: socialize-sdk-android
File: ProfileContentView.java
File: ProfileContentView.java
protected ViewGroup makeButtonLayout() { LinearLayout buttons = new LinearLayout(getContext()); int padding = displayUtils.getDIP(8); LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); buttons.setId(buttonLayoutViewId); buttons.setLayoutParams(buttonParams); buttons.setOrientation(LinearLayout.HORIZONTAL); buttons.setPadding(padding, padding, padding, padding); buttons.setGravity(Gravity.BOTTOM | Gravity.RIGHT); ColorDrawable background = new ColorDrawable(Color.BLACK); background.setAlpha(64); CompatUtils.setBackgroundDrawable(buttons, background); return buttons; }
3. CrossbowImageTest#testErrorDefaultFade()
Project: CrossBow
File: CrossbowImageTest.java
File: CrossbowImageTest.java
@Test public void testErrorDefaultFade() { ColorDrawable defaultDrawable = new ColorDrawable(Color.BLUE); ColorDrawable errorDrawable = new ColorDrawable(Color.BLACK); CrossbowImage.Builder builder = new CrossbowImage.Builder(RuntimeEnvironment.application, null, null); builder.placeholder(defaultDrawable); builder.error(errorDrawable); builder.fade(200); CrossbowImage crossbowImage = builder.into(imageView).load(); crossbowImage.setError(null); TransitionDrawable drawable = (TransitionDrawable) imageView.getDrawable(); assertTrue(drawable.getNumberOfLayers() == 2); }
4. GalleryAnimationActivity#showBackgroundAnimate()
Project: weiciyuan
File: GalleryAnimationActivity.java
File: GalleryAnimationActivity.java
public ObjectAnimator showBackgroundAnimate() { backgroundColor = new ColorDrawable(Color.BLACK); background.setBackground(backgroundColor); ObjectAnimator bgAnim = ObjectAnimator.ofInt(backgroundColor, "alpha", 0, 255); bgAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { background.setBackground(backgroundColor); } }); return bgAnim; }
5. CustomButton#parseAttributes()
Project: tilt-game-android
File: CustomButton.java
File: CustomButton.java
private void parseAttributes(Context context, AttributeSet attrs) { ColorDrawable drawable = (ColorDrawable) getBackground(); _baseBackgroundColor = drawable.getColor(); // Typeface if (!isInEditMode()) { TypedArray values = context.obtainStyledAttributes(attrs, R.styleable.CustomButton); int ordinal = values.getInt(R.styleable.CustomButton_typeface, 0); FontFaceType type = FontFaceType.values()[ordinal]; Typeface typeface = FontCache.get(context, type.getAssetName()); if (typeface != null) { setTypeface(typeface); } values.recycle(); } }
6. EditPage#genBackground()
Project: SuesNews
File: EditPage.java
File: EditPage.java
private void genBackground() { background = new ColorDrawable(DIM_COLOR); if (backgroundView != null) { try { Bitmap bgBm = captureView(backgroundView, backgroundView.getWidth(), backgroundView.getHeight()); bgBm = blur(bgBm, 20, 8); BitmapDrawable blurBm = new BitmapDrawable(activity.getResources(), bgBm); background = new LayerDrawable(new Drawable[] { blurBm, background }); } catch (Throwable e) { e.printStackTrace(); } } }
7. MainActivity#changeBackgroundColor()
Project: road-trip
File: MainActivity.java
File: MainActivity.java
@SuppressWarnings("PointlessBitwiseExpression") private void changeBackgroundColor(View decorView, float alpha) { float srcR = ((mAccentColor >> 16) & 0xff) / 255.0f; float srcG = ((mAccentColor >> 8) & 0xff) / 255.0f; float srcB = ((mAccentColor >> 0) & 0xff) / 255.0f; float dstR = ((mAccentColor2 >> 16) & 0xff) / 255.0f; float dstG = ((mAccentColor2 >> 8) & 0xff) / 255.0f; float dstB = ((mAccentColor2 >> 0) & 0xff) / 255.0f; int r = (int) ((srcR + ((dstR - srcR) * alpha)) * 255.0f); int g = (int) ((srcG + ((dstG - srcG) * alpha)) * 255.0f); int b = (int) ((srcB + ((dstB - srcB) * alpha)) * 255.0f); ColorDrawable background = (ColorDrawable) decorView.getBackground(); if (background != null) { background.setColor(0xff000000 | r << 16 | g << 8 | b); } }
8. GalleryAnimationActivity#showBackgroundAnimate()
Project: iBeebo
File: GalleryAnimationActivity.java
File: GalleryAnimationActivity.java
public ObjectAnimator showBackgroundAnimate() { backgroundColor = new ColorDrawable(Color.BLACK); background.setBackgroundDrawable(backgroundColor); ObjectAnimator bgAnim = ObjectAnimator.ofInt(backgroundColor, "alpha", 0, 255); bgAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { background.setBackgroundDrawable(backgroundColor); } }); return bgAnim; }
9. GenericDraweeHierarchyTest#setUp()
Project: fresco
File: GenericDraweeHierarchyTest.java
File: GenericDraweeHierarchyTest.java
@Before public void setUp() { mBuilder = new GenericDraweeHierarchyBuilder(null); mBackground1 = DrawableTestUtils.mockDrawable(); mBackground2 = DrawableTestUtils.mockDrawable(); mOverlay1 = DrawableTestUtils.mockDrawable(); mOverlay2 = DrawableTestUtils.mockDrawable(); mPlaceholderImage = DrawableTestUtils.mockBitmapDrawable(); mFailureImage = DrawableTestUtils.mockBitmapDrawable(); mRetryImage = DrawableTestUtils.mockBitmapDrawable(); mProgressBarImage = DrawableTestUtils.mockBitmapDrawable(); mActualImage1 = DrawableTestUtils.mockBitmapDrawable(); mActualImage2 = DrawableTestUtils.mockBitmapDrawable(); mWrappedLeaf = new ColorDrawable(Color.BLUE); mWrappedImage = new ForwardingDrawable(new ForwardingDrawable(mWrappedLeaf)); mActualImageMatrix = mock(Matrix.class); mFocusPoint = new PointF(0.1f, 0.4f); }
10. Utils#getSelectableBackground()
Project: FlexibleAdapter
File: Utils.java
File: Utils.java
/** * Helper to get the system default selectable background inclusive an active state. * * @param context the context * @param selectedColor the selected color * @param animate true if you want to fade over the states (only animates if API * newer than Build.VERSION_CODES.HONEYCOMB) * @return the StateListDrawable */ public static StateListDrawable getSelectableBackground(Context context, @ColorInt int selectedColor, boolean animate) { StateListDrawable states = new StateListDrawable(); ColorDrawable clrActive = new ColorDrawable(selectedColor); states.addState(new int[] { android.R.attr.state_selected }, clrActive); states.addState(new int[] { android.R.attr.state_activated }, clrActive); states.addState(new int[] {}, ContextCompat.getDrawable(context, getSelectableBackground(context))); //if possible we enable animating across states if (animate && hasHoneycomb()) { int duration = context.getResources().getInteger(android.R.integer.config_shortAnimTime); states.setEnterFadeDuration(duration); states.setExitFadeDuration(duration); } return states; }
11. FastAdapterUIUtils#getSelectableBackground()
Project: FastAdapter
File: FastAdapterUIUtils.java
File: FastAdapterUIUtils.java
/** * helper to get the system default selectable background inclusive an active state * * @param ctx the context * @param selected_color the selected color * @param animate true if you want to fade over the states (only animates if API newer than Build.VERSION_CODES.HONEYCOMB) * @return the StateListDrawable */ public static StateListDrawable getSelectableBackground(Context ctx, @ColorInt int selected_color, boolean animate) { StateListDrawable states = new StateListDrawable(); ColorDrawable clrActive = new ColorDrawable(selected_color); states.addState(new int[] { android.R.attr.state_selected }, clrActive); states.addState(new int[] {}, ContextCompat.getDrawable(ctx, getSelectableBackground(ctx))); //if possible we enable animating across states if (animate && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { int duration = ctx.getResources().getInteger(android.R.integer.config_shortAnimTime); states.setEnterFadeDuration(duration); states.setExitFadeDuration(duration); } return states; }
12. CrossbowImageTest#testDefaultErrorDrawable()
Project: CrossBow
File: CrossbowImageTest.java
File: CrossbowImageTest.java
@Test public void testDefaultErrorDrawable() { ColorDrawable defaultDrawable = new ColorDrawable(Color.BLUE); CrossbowImage.Builder builder = new CrossbowImage.Builder(RuntimeEnvironment.application, null, null); builder.placeholder(defaultDrawable); builder.placeholderScale(ImageView.ScaleType.FIT_END); CrossbowImage crossbowImage = builder.into(imageView).load(); crossbowImage.setError(null); ScaleTypeDrawable drawable = (ScaleTypeDrawable) imageView.getDrawable(); assertEquals(drawable.getScaleType(), ImageView.ScaleType.FIT_END); assertEquals(drawable.getSourceDrawable(), defaultDrawable); }
13. CrossbowImageTest#testErrorDrawable()
Project: CrossBow
File: CrossbowImageTest.java
File: CrossbowImageTest.java
@Test public void testErrorDrawable() { ColorDrawable errorDrawable = new ColorDrawable(Color.BLUE); CrossbowImage.Builder builder = new CrossbowImage.Builder(RuntimeEnvironment.application, null, null); builder.errorScale(ImageView.ScaleType.FIT_END); builder.error(errorDrawable); CrossbowImage crossbowImage = builder.into(imageView).load(); //Same method call as if the image fails crossbowImage.setError(null); ScaleTypeDrawable drawable = (ScaleTypeDrawable) imageView.getDrawable(); assertEquals(drawable.getScaleType(), ImageView.ScaleType.FIT_END); assertEquals(drawable.getSourceDrawable(), errorDrawable); }
14. CrossbowImageTest#testImageFadeDrawable()
Project: CrossBow
File: CrossbowImageTest.java
File: CrossbowImageTest.java
@Test public void testImageFadeDrawable() { ColorDrawable defaultDrawable = new ColorDrawable(Color.BLUE); CrossbowImage.Builder builder = new CrossbowImage.Builder(RuntimeEnvironment.application, null, null); builder.placeholder(defaultDrawable); builder.scale(ImageView.ScaleType.CENTER); builder.fade(200); CrossbowImage crossbowImage = builder.into(imageView).load(); Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ALPHA_8); crossbowImage.setBitmap(bitmap, false); TransitionDrawable drawable = (TransitionDrawable) imageView.getDrawable(); assertTrue(drawable.getNumberOfLayers() == 2); }
15. CustomPopupWindow#initPopupWindow()
Project: AndroidLife
File: CustomPopupWindow.java
File: CustomPopupWindow.java
private void initPopupWindow() { LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); this.contentView = inflater.inflate(R.layout.popupwindow_custom, null); this.setContentView(contentView); // ???????? this.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); // ???????? this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); // ????????? this.setTouchable(true); this.setFocusable(true); // ???????? this.setOutsideTouchable(true); //?????????? this.setAnimationStyle(R.style.PopupAnimation); //?????ColorDrawable?????? ColorDrawable background = new ColorDrawable(0x4f000000); //????????? this.setBackgroundDrawable(background); // ?? this.mandatoryDraw(); }
16. Coloring#createRippleDrawable()
Project: actual-number-picker
File: Coloring.java
File: Coloring.java
/** * Creates a new {@code RippleDrawable} used in Lollipop and later. * * @param normalColor Color for the idle ripple state * @param rippleColor Color for the clicked, pressed and focused ripple states * @param bounds Clip/mask drawable to these rectangle bounds * @return A fully colored RippleDrawable instance */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) public Drawable createRippleDrawable(int normalColor, int rippleColor, Rect bounds) { ColorDrawable maskDrawable = null; if (bounds != null) { maskDrawable = new ColorDrawable(Color.WHITE); maskDrawable.setBounds(bounds); } if (normalColor == Color.TRANSPARENT) { return new RippleDrawable(ColorStateList.valueOf(rippleColor), null, maskDrawable); } else { return new RippleDrawable(ColorStateList.valueOf(rippleColor), new ColorDrawable(normalColor), maskDrawable); } }
17. SearchViewLayout#onFinishInflate()
Project: Search-View-Layout
File: SearchViewLayout.java
File: SearchViewLayout.java
@Override protected void onFinishInflate() { mCollapsed = (ViewGroup) findViewById(R.id.search_box_collapsed); mSearchIcon = findViewById(R.id.search_magnifying_glass); mCollapsedSearchBox = findViewById(R.id.search_box_start_search); mCollapsedHintView = (TextView) findViewById(R.id.search_box_collapsed_hint); mExpanded = (ViewGroup) findViewById(R.id.search_expanded_root); mSearchEditText = (EditText) mExpanded.findViewById(R.id.search_expanded_edit_text); mBackButtonView = mExpanded.findViewById(R.id.search_expanded_back_button); mExpandedSearchIcon = findViewById(R.id.search_expanded_magnifying_glass); // Convert a long click into a click to expand the search box, and then long click on the // search view. This accelerates the long-press scenario for copy/paste. mCollapsedSearchBox.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View view) { mCollapsedSearchBox.performClick(); mSearchEditText.performLongClick(); return false; } }); mCollapsed.setOnClickListener(mSearchViewOnClickListener); mSearchIcon.setOnClickListener(mSearchViewOnClickListener); mCollapsedSearchBox.setOnClickListener(mSearchViewOnClickListener); mSearchEditText.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { Utils.showInputMethod(v); } else { Utils.hideInputMethod(v); } } }); mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { callSearchListener(); Utils.hideInputMethod(v); return true; } return false; } }); mSearchEditText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (mSearchEditText.getText().length() > 0) { if (mExpandedSearchIcon.getVisibility() != View.VISIBLE) { Utils.fadeIn(mExpandedSearchIcon, ANIMATION_DURATION); } } else { Utils.fadeOut(mExpandedSearchIcon, ANIMATION_DURATION); } if (mSearchBoxListener != null) mSearchBoxListener.onTextChanged(s, start, before, count); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { if (mSearchBoxListener != null) mSearchBoxListener.beforeTextChanged(s, start, count, after); } @Override public void afterTextChanged(Editable s) { if (mSearchBoxListener != null) mSearchBoxListener.afterTextChanged(s); } }); mBackButtonView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { collapse(); } }); mExpandedSearchIcon.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { callSearchListener(); Utils.hideInputMethod(v); } }); mCollapsedDrawable = new ColorDrawable(ContextCompat.getColor(getContext(), android.R.color.transparent)); mExpandedDrawable = new ColorDrawable(ContextCompat.getColor(getContext(), R.color.default_color_expanded)); mBackgroundTransition = new TransitionDrawable(new Drawable[] { mCollapsedDrawable, mExpandedDrawable }); mBackgroundTransition.setCrossFadeEnabled(true); setBackground(mBackgroundTransition); Utils.setPaddingAll(SearchViewLayout.this, 8); super.onFinishInflate(); }
18. MainActivity#onCreate()
Project: Search-View-Layout
File: MainActivity.java
File: MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show(); } }); final SearchViewLayout searchViewLayout = (SearchViewLayout) findViewById(R.id.search_view_container); searchViewLayout.setExpandedContentSupportFragment(this, new SearchStaticListSupportFragment()); searchViewLayout.handleToolbarAnimation(toolbar); searchViewLayout.setCollapsedHint("Collapsed Hint"); searchViewLayout.setExpandedHint("Expanded Hint"); // searchViewLayout.setHint("Global Hint"); ColorDrawable collapsed = new ColorDrawable(ContextCompat.getColor(this, R.color.colorPrimary)); ColorDrawable expanded = new ColorDrawable(ContextCompat.getColor(this, R.color.default_color_expanded)); searchViewLayout.setTransitionDrawables(collapsed, expanded); searchViewLayout.setSearchListener(new SearchViewLayout.SearchListener() { @Override public void onFinished(String searchKeyword) { searchViewLayout.collapse(); Snackbar.make(searchViewLayout, "Start Search for - " + searchKeyword, Snackbar.LENGTH_LONG).show(); } }); searchViewLayout.setOnToggleAnimationListener(new SearchViewLayout.OnToggleAnimationListener() { @Override public void onStart(boolean expanding) { if (expanding) { fab.hide(); } else { fab.show(); } } @Override public void onFinish(boolean expanded) { } }); searchViewLayout.setSearchBoxListener(new SearchViewLayout.SearchBoxListener() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { Log.d(TAG, "beforeTextChanged: " + s + "," + start + "," + count + "," + after); } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { Log.d(TAG, "onTextChanged: " + s + "," + start + "," + before + "," + count); } @Override public void afterTextChanged(Editable s) { Log.d(TAG, "afterTextChanged: " + s); } }); }
19. PToolbar#bgColor()
Project: Protocoder
File: PToolbar.java
File: PToolbar.java
@ProtoMethod(description = "Changes the title bar color", example = "") @ProtoMethodParam(params = { "r", "g", "b", "alpha" }) public PToolbar bgColor(int r, int g, int b, int alpha) { int c = Color.argb(alpha, r, g, b); ColorDrawable d = new ColorDrawable(); d.setColor(c); mToolbar.setBackgroundDrawable(d); return this; }
20. Letterbox#show()
Project: droid-comic-viewer
File: Letterbox.java
File: Letterbox.java
/** * Shows a letterbox for the given area with the given color. The area is assumed to be centered. * @param width Width of the area that the letterbox will surround. * @param height Height of the area that the letterbox wil surround. * @param color Color of the letterbox. * @param duration Duration of the animation in miliseconds. */ public void show(int width, int height, int color, long duration) { final ColorDrawable initialColor = new ColorDrawable(mColor); final ColorDrawable finalColor = new ColorDrawable(color); final TransitionDrawable backgroundTransition = new TransitionDrawable(new Drawable[] { initialColor, finalColor }); final int previousWidth = mLetterboxWidth; final int previousHeight = mLetterboxHeight; mLetterboxWidth = Math.max(1, (getWidth() - width) / 2); mLetterboxHeight = Math.max(1, (getHeight() - height) / 2); if (mLetterboxWidth <= 1 && previousWidth <= 1) { mLetterboxLeft.setBackgroundColor(Color.TRANSPARENT); mLetterboxRight.setBackgroundColor(Color.TRANSPARENT); } else { mLetterboxLeft.setBackgroundDrawable(backgroundTransition); mLetterboxRight.setBackgroundDrawable(backgroundTransition); } if (mLetterboxHeight <= 1 && previousHeight <= 1) { mLetterboxTop.setBackgroundColor(Color.TRANSPARENT); mLetterboxBottom.setBackgroundColor(Color.TRANSPARENT); } else { mLetterboxTop.setBackgroundDrawable(backgroundTransition); mLetterboxBottom.setBackgroundDrawable(backgroundTransition); } mColor = color; if (duration > 0) { animateTop(duration); animateBottom(duration); animateLeft(duration); animateRight(duration); } else { layoutTop(); layoutBottom(); layoutLeft(); layoutRight(); } }
21. DraweeSpan#createEmptyDrawable()
Project: drawee-text-view
File: DraweeSpan.java
File: DraweeSpan.java
private static Drawable createEmptyDrawable() { ColorDrawable d = new ColorDrawable(Color.TRANSPARENT); d.setBounds(0, 0, 100, 100); return d; }
22. BirdActivity#onCreate()
Project: SlidingMenu
File: BirdActivity.java
File: BirdActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int pos = 0; if (getIntent().getExtras() != null) { pos = getIntent().getExtras().getInt("pos"); } String[] birds = getResources().getStringArray(R.array.birds); TypedArray imgs = getResources().obtainTypedArray(R.array.birds_img); int resId = imgs.getResourceId(pos, -1); setTitle(birds[pos]); getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); ColorDrawable color = new ColorDrawable(Color.BLACK); color.setAlpha(128); getSupportActionBar().setBackgroundDrawable(color); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mHandler = new Handler(); ImageView imageView = new ImageView(this); imageView.setScaleType(ScaleType.CENTER_INSIDE); imageView.setImageResource(resId); imageView.setOnClickListener(new OnClickListener() { public void onClick(View v) { getSupportActionBar().show(); hideActionBarDelayed(mHandler); } }); setContentView(imageView); this.getWindow().setBackgroundDrawableResource(android.R.color.black); }
23. DrawerUIUtils#getDrawerItemBackground()
Project: YouJoin-Android
File: DrawerUIUtils.java
File: DrawerUIUtils.java
/** * helper to create a StateListDrawable for the drawer item background * * @param selected_color * @return */ public static StateListDrawable getDrawerItemBackground(int selected_color) { ColorDrawable clrActive = new ColorDrawable(selected_color); StateListDrawable states = new StateListDrawable(); states.addState(new int[] { android.R.attr.state_selected }, clrActive); return states; }
24. SearchFragment#setupBackgroundManager()
Project: Vineyard
File: SearchFragment.java
File: SearchFragment.java
private void setupBackgroundManager() { mBackgroundManager = BackgroundManager.getInstance(getActivity()); mBackgroundManager.attach(getActivity().getWindow()); mBackgroundManager.setColor(ContextCompat.getColor(getActivity(), R.color.bg_grey)); mDefaultBackground = new ColorDrawable(ContextCompat.getColor(getActivity(), R.color.bg_grey)); mMetrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(mMetrics); }
25. PostGridFragment#prepareBackgroundManager()
Project: Vineyard
File: PostGridFragment.java
File: PostGridFragment.java
private void prepareBackgroundManager() { mBackgroundManager = BackgroundManager.getInstance(getActivity()); mBackgroundManager.attach(getActivity().getWindow()); mDefaultBackground = new ColorDrawable(ContextCompat.getColor(getActivity(), R.color.bg_light_grey)); mMetrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(mMetrics); }
26. MainFragment#prepareBackgroundManager()
Project: Vineyard
File: MainFragment.java
File: MainFragment.java
private void prepareBackgroundManager() { mBackgroundManager = BackgroundManager.getInstance(getActivity()); mBackgroundManager.attach(getActivity().getWindow()); mDefaultBackground = new ColorDrawable(ContextCompat.getColor(getActivity(), R.color.bg_grey)); mBackgroundManager.setColor(ContextCompat.getColor(getActivity(), R.color.bg_grey)); mMetrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(mMetrics); }
27. MaterialRippleLayout#setRippleBackground()
Project: UltimateAndroid
File: MaterialRippleLayout.java
File: MaterialRippleLayout.java
public void setRippleBackground(int color) { rippleBackground = new ColorDrawable(color); rippleBackground.setBounds(bounds); invalidate(); }
28. DebugDrawerLayout#setStatusBarBackgroundColor()
Project: u2020
File: DebugDrawerLayout.java
File: DebugDrawerLayout.java
/** * Set a drawable to draw in the insets area for the status bar. * Note that this will only be activated if this DrawerLayout fitsSystemWindows. * * @param color Color to use as a background drawable to draw behind the status bar * in 0xAARRGGBB format. */ public void setStatusBarBackgroundColor(int color) { mStatusBarBackground = new ColorDrawable(color); invalidate(); }
29. BaseTweetView#setStyleAttributes()
Project: twitter-kit-android
File: BaseTweetView.java
File: BaseTweetView.java
/** * Parses and sets style attributes. Must be called before view inflation. Defaults style * attributes to the light style values. * @param a A TypedArray holding style-related attribute values. */ private void setStyleAttributes(TypedArray a) { // Styled via attributes containerBgColor = a.getColor(R.styleable.tw__TweetView_tw__container_bg_color, getResources().getColor(R.color.tw__tweet_light_container_bg_color)); primaryTextColor = a.getColor(R.styleable.tw__TweetView_tw__primary_text_color, getResources().getColor(R.color.tw__tweet_light_primary_text_color)); actionColor = a.getColor(R.styleable.tw__TweetView_tw__action_color, getResources().getColor(R.color.tw__tweet_action_color)); actionHighlightColor = a.getColor(R.styleable.tw__TweetView_tw__action_highlight_color, getResources().getColor(R.color.tw__tweet_action_light_highlight_color)); tweetActionsEnabled = a.getBoolean(R.styleable.tw__TweetView_tw__tweet_actions_enabled, false); // Calculated colors final boolean isLightBg = ColorUtils.isLightColor(containerBgColor); if (isLightBg) { photoErrorResId = R.drawable.tw__ic_tweet_photo_error_light; birdLogoResId = R.drawable.tw__ic_logo_blue; retweetIconResId = R.drawable.tw__ic_retweet_light; } else { photoErrorResId = R.drawable.tw__ic_tweet_photo_error_dark; birdLogoResId = R.drawable.tw__ic_logo_white; retweetIconResId = R.drawable.tw__ic_retweet_dark; } // offset from white when background is light secondaryTextColor = ColorUtils.calculateOpacityTransform(isLightBg ? SECONDARY_TEXT_COLOR_LIGHT_OPACITY : SECONDARY_TEXT_COLOR_DARK_OPACITY, isLightBg ? Color.WHITE : Color.BLACK, primaryTextColor); // offset from black when background is light mediaBgColor = ColorUtils.calculateOpacityTransform(isLightBg ? MEDIA_BG_LIGHT_OPACITY : MEDIA_BG_DARK_OPACITY, isLightBg ? Color.BLACK : Color.WHITE, containerBgColor); mediaBg = new ColorDrawable(mediaBgColor); }
30. ComposerView#init()
Project: twitter-kit-android
File: ComposerView.java
File: ComposerView.java
private void init(Context context) { imageLoader = Picasso.with(getContext()); // TODO: make color vary depending on the style mediaBg = new ColorDrawable(context.getResources().getColor(R.color.tw__composer_light_gray)); inflate(context, R.layout.tw__composer_view, this); }
31. SocializeHeader#init()
Project: socialize-sdk-android
File: SocializeHeader.java
File: SocializeHeader.java
public void init() { int four = displayUtils.getDIP(4); int eight = displayUtils.getDIP(8); int height = displayUtils.getDIP(57); LayoutParams titlePanelLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, height); titlePanelLayoutParams.gravity = Gravity.CENTER_VERTICAL; this.setLayoutParams(titlePanelLayoutParams); this.setOrientation(LinearLayout.HORIZONTAL); this.setPadding(four, four, four, four); ColorDrawable background = new ColorDrawable(Color.BLACK); Drawable headerBG = drawables.getDrawable("header.png", true, false, true); Drawable[] layers = new Drawable[] { background, headerBG }; LayerDrawable bg = newLayerDrawable(layers); bg.setLayerInset(1, 0, 0, 0, 1); CompatUtils.setBackgroundDrawable(this, bg); titleText = new TextView(getContext()); titleText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); titleText.setTextColor(colors.getColor(Colors.HEADER)); if (!StringUtils.isEmpty(headerTextKey)) { titleText.setText(localizationService.getString(headerTextKey)); } else { titleText.setText(getHeaderText()); } titleText.setPadding(0, 0, 0, displayUtils.getDIP(2)); titleText.setSingleLine(true); titleText.setEllipsize(TruncateAt.END); LayoutParams titleTextLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); titleTextLayoutParams.gravity = Gravity.CENTER_VERTICAL; titleText.setLayoutParams(titleTextLayoutParams); titleImage = new ImageView(getContext()); titleImage.setImageDrawable(drawables.getDrawable("socialize_icon_white.png")); titleImage.setPadding(0, 0, 0, 0); LayoutParams titleImageLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); titleImageLayoutParams.gravity = Gravity.CENTER_VERTICAL; titleImageLayoutParams.setMargins(eight, 0, four, 0); titleImage.setLayoutParams(titleImageLayoutParams); this.addView(titleImage); this.addView(titleText); }
32. FullScreenDialogFactory#build()
Project: socialize-sdk-android
File: FullScreenDialogFactory.java
File: FullScreenDialogFactory.java
public Dialog build(Activity context, View contentView, boolean includeCloseButton) { final Dialog dialog = new Dialog(contentView.getContext(), android.R.style.Theme_Dialog); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); if (includeCloseButton) { Drawable viewBg = drawables.getDrawable("action_bar_button.png", true, false, true); LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams master = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); layout.setLayoutParams(master); LinearLayout toolbar = new LinearLayout(context); LinearLayout.LayoutParams toolbarParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, displayUtils.getDIP(44)); toolbar.setLayoutParams(toolbarParams); toolbar.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT); CompatUtils.setBackgroundDrawable(toolbar, viewBg); SocializeButton button = buttonFactory.getBean(); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); toolbar.addView(button); layout.addView(toolbar); layout.addView(contentView); dialog.setContentView(layout); } else { dialog.setContentView(contentView); } ColorDrawable cd = new ColorDrawable(Color.BLACK); dialog.getWindow().setBackgroundDrawable(cd); dialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); // Register to prevent window leakage DialogRegistration.register(contentView.getContext(), dialog); return dialog; }
33. ViewGroupColorAdapterTest#applyColor()
Project: Scoops
File: ViewGroupColorAdapterTest.java
File: ViewGroupColorAdapterTest.java
@Test public void applyColor() throws Exception { int color = Color.GREEN; adapter.applyColor(view, color); Drawable bg = view.getBackground(); assertTrue(bg instanceof ColorDrawable); ColorDrawable cbg = (ColorDrawable) bg; assertThat(cbg.getColor(), is(color)); }
34. DefaultColorAdapterTest#applyColor()
Project: Scoops
File: DefaultColorAdapterTest.java
File: DefaultColorAdapterTest.java
@Test public void applyColor() throws Exception { int color = Color.GREEN; adapter.applyColor(view, color); Drawable bg = view.getBackground(); assertTrue(bg instanceof ColorDrawable); ColorDrawable cbg = (ColorDrawable) bg; assertThat(cbg.getColor(), is(color)); }
35. DebugDrawerLayout#setStatusBarBackgroundColor()
Project: sbt-android
File: DebugDrawerLayout.java
File: DebugDrawerLayout.java
/** * Set a drawable to draw in the insets area for the status bar. * Note that this will only be activated if this DrawerLayout fitsSystemWindows. * * @param color Color to use as a background drawable to draw behind the status bar * in 0xAARRGGBB format. */ public void setStatusBarBackgroundColor(int color) { mStatusBarBackground = new ColorDrawable(color); invalidate(); }
36. RxMenuItemTest#iconRes()
Project: RxBinding
File: RxMenuItemTest.java
File: RxMenuItemTest.java
@Test public void iconRes() { ColorDrawable drawable = (ColorDrawable) context.getResources().getDrawable(R.drawable.icon); RxMenuItem.iconRes(menuItem).call(R.drawable.icon); assertThat(((ColorDrawable) menuItem.getIcon()).getColor()).isEqualTo(drawable.getColor()); }
37. RoundedImageView#setBackgroundColor()
Project: RoundedImageView
File: RoundedImageView.java
File: RoundedImageView.java
@Override public void setBackgroundColor(int color) { mBackgroundDrawable = new ColorDrawable(color); setBackgroundDrawable(mBackgroundDrawable); }
38. BackgroundContainer#init()
Project: QuickLyric
File: BackgroundContainer.java
File: BackgroundContainer.java
private void init() { mShadowedBackground = new ColorDrawable(getContext().getResources().getColor(R.color.mdtp_red_focused)); }
39. MainActivity#setupNavDrawer()
Project: polar-dashboard
File: MainActivity.java
File: MainActivity.java
private void setupNavDrawer() { assert mNavView != null; assert mDrawer != null; mNavView.getMenu().clear(); for (PagesBuilder.Page page : mPages) page.addToMenu(mNavView.getMenu()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) getWindow().setStatusBarColor(Color.TRANSPARENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mDrawer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { //TODO: Check if NavigationView needs bottom padding WindowInsets drawerLayoutInsets = insets.replaceSystemWindowInsets(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), 0); mDrawerModeTopInset = drawerLayoutInsets.getSystemWindowInsetTop(); ((DrawerLayout) v).setChildInsets(drawerLayoutInsets, drawerLayoutInsets.getSystemWindowInsetTop() > 0); return insets; } }); } assert getSupportActionBar() != null; getSupportActionBar().setDisplayHomeAsUpEnabled(true); Drawable menuIcon = VC.get(R.drawable.ic_action_menu); menuIcon = TintUtils.createTintedDrawable(menuIcon, DialogUtils.resolveColor(this, R.attr.tab_icon_color)); getSupportActionBar().setHomeAsUpIndicator(menuIcon); mDrawer.addDrawerListener(new ActionBarDrawerToggle(this, mDrawer, mToolbar, R.string.drawer_open, R.string.drawer_close)); mDrawer.setStatusBarBackgroundColor(DialogUtils.resolveColor(this, R.attr.colorPrimaryDark)); mNavView.setNavigationItemSelectedListener(this); final ColorDrawable navBg = (ColorDrawable) mNavView.getBackground(); final int selectedIconText = DialogUtils.resolveColor(this, R.attr.colorAccent); int iconColor; int titleColor; int selectedBg; if (TintUtils.isColorLight(navBg.getColor())) { iconColor = ContextCompat.getColor(this, R.color.navigationview_normalicon_light); titleColor = ContextCompat.getColor(this, R.color.navigationview_normaltext_light); selectedBg = ContextCompat.getColor(this, R.color.navigationview_selectedbg_light); } else { iconColor = ContextCompat.getColor(this, R.color.navigationview_normalicon_dark); titleColor = ContextCompat.getColor(this, R.color.navigationview_normaltext_dark); selectedBg = ContextCompat.getColor(this, R.color.navigationview_selectedbg_dark); } final ColorStateList iconSl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_checked }, new int[] { android.R.attr.state_checked } }, new int[] { iconColor, selectedIconText }); final ColorStateList textSl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_checked }, new int[] { android.R.attr.state_checked } }, new int[] { titleColor, selectedIconText }); mNavView.setItemTextColor(textSl); mNavView.setItemIconTintList(iconSl); StateListDrawable bgDrawable = new StateListDrawable(); bgDrawable.addState(new int[] { android.R.attr.state_checked }, new ColorDrawable(selectedBg)); mNavView.setItemBackground(bgDrawable); mPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { dispatchFragmentUpdateTitle(false); invalidateNavViewSelection(position); } }); mToolbar.setContentInsetsRelative(getResources().getDimensionPixelSize(R.dimen.second_keyline), 0); }
40. PXColorUtil#getColor()
Project: pixate-freestyle-android
File: PXColorUtil.java
File: PXColorUtil.java
/** * Returns the background color value for a View that have a * {@link ColorDrawable} background, or a {@link LayerDrawable} background * that contains one. * * @param view * @return The view's background color. -1 in case the view does not have a * ColorDrawable background. */ public static int getColor(View view) { ColorDrawable colorDrawable = getColorDrawableBackground(view); if (colorDrawable != null) { return colorDrawable.getColor(); } return -1; }
41. PXColorUtil#setColor()
Project: pixate-freestyle-android
File: PXColorUtil.java
File: PXColorUtil.java
/** * Sets the color for a view with a colored background. In case the view's * background is not a {@link ColorDrawable}, or does not contain a * color-drawable in one of its layers, nothing happens. * * @param view * @param color */ public static void setColor(View view, int color) { ColorDrawable colorDrawable = getColorDrawableBackground(view); if (colorDrawable != null) { colorDrawable.setColor(color); } }
42. PXColorUtil#getHSL()
Project: pixate-freestyle-android
File: PXColorUtil.java
File: PXColorUtil.java
/** * Returns the HSL value of a view that has a colored background. In case * the view's background is not a {@link ColorDrawable}, or does not contain * a color-drawable in one of its layers, the return value is * <code>null</code> * * @param view * @return The hue value (<code>null</code> in case the background is not a * {@link ColorDrawable}) */ public static float[] getHSL(View view) { ColorDrawable colorDrawable = getColorDrawableBackground(view); if (colorDrawable != null) { int color = colorDrawable.getColor(); float[] hsl = new float[3]; PXColorUtil.colorToHsl(color, hsl); return hsl; } return null; }
43. PXColorUtil#setBrightness()
Project: pixate-freestyle-android
File: PXColorUtil.java
File: PXColorUtil.java
/** * Sets the Brightness value on a view that has a colored background. In * case the view's background is not a {@link ColorDrawable}, or does not * contain one in a {@link LayerDrawable}, nothing will be applied. * * @param view * @param brightness */ public static void setBrightness(View view, float brightness) { ColorDrawable colorDrawable = getColorDrawableBackground(view); if (colorDrawable != null) { int color = colorDrawable.getColor(); float[] hsl = new float[3]; PXColorUtil.colorToHsl(color, hsl); colorDrawable.setColor(PXColorUtil.hslToColor(Color.alpha(color), hsl[0], hsl[1], brightness)); } }
44. PXColorUtil#setSaturation()
Project: pixate-freestyle-android
File: PXColorUtil.java
File: PXColorUtil.java
/** * Sets the Saturation value on a view that has a colored background. In * case the view's background is not a {@link ColorDrawable}, or does not * contain one in a {@link LayerDrawable}, nothing will be applied. * * @param view * @param saturation */ public static void setSaturation(View view, float saturation) { ColorDrawable colorDrawable = getColorDrawableBackground(view); if (colorDrawable != null) { int color = colorDrawable.getColor(); float[] hsl = new float[3]; PXColorUtil.colorToHsl(color, hsl); colorDrawable.setColor(PXColorUtil.hslToColor(Color.alpha(color), hsl[0], saturation, hsl[2])); } }
45. PXColorUtil#setHue()
Project: pixate-freestyle-android
File: PXColorUtil.java
File: PXColorUtil.java
/** * Sets the Hue value on a view that has a colored background. In case the * view's background is not a {@link ColorDrawable}, or does not contain one * in a {@link LayerDrawable}, nothing will be applied. * * @param view * @param hue */ public static void setHue(View view, float hue) { ColorDrawable colorDrawable = getColorDrawableBackground(view); if (colorDrawable != null) { int color = colorDrawable.getColor(); float[] hsl = new float[3]; PXColorUtil.colorToHsl(color, hsl); colorDrawable.setColor(PXColorUtil.hslToColor(Color.alpha(color), hue, hsl[1], hsl[2])); } }
46. ActionBarColorSlider#setStartColor()
Project: Painter
File: ActionBarColorSlider.java
File: ActionBarColorSlider.java
public void setStartColor(Object actionBar, int color) { mStartColor = color; mDrawable = new ColorDrawable(color); setBackgroundDrawable(actionBar); }
47. ViewerActivity#initView()
Project: NewsMe
File: ViewerActivity.java
File: ViewerActivity.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void initView() { Parcelable[] pars = getIntent().getParcelableArrayExtra(INTENT_IMAGES); mImages = new Image[pars.length]; for (int i = 0; i < pars.length; i++) { mImages[i] = (Image) pars[i]; } getBinding().puller.setCallback(this); supportPostponeEnterTransition(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getWindow().getEnterTransition().addListener(new SimpleTransitionListener() { @Override @TargetApi(Build.VERSION_CODES.LOLLIPOP) public void onTransitionEnd(Transition transition) { getWindow().getEnterTransition().removeListener(this); fadeIn(); } }); } else { fadeIn(); } mBackground = new ColorDrawable(Color.BLACK); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { getBinding().getRoot().setBackground(mBackground); } else { getBinding().getRoot().setBackgroundDrawable(mBackground); } setLocImages(getIntent().getIntExtra(INTENT_INDEX, 0) + 1); }
48. GallerySettingsActivity#onCreate()
Project: muzei
File: GallerySettingsActivity.java
File: GallerySettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_settings_activity); getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); setupAppBar(); mStore = GalleryStore.getInstance(this); mChosenUris = new ArrayList<>(mStore.getChosenUris()); onDataSetChanged(); mPlaceholderDrawable = new ColorDrawable(ContextCompat.getColor(this, R.color.gallery_settings_chosen_photo_placeholder)); mPhotoGridView = (RecyclerView) findViewById(R.id.photo_grid); DefaultItemAnimator itemAnimator = new DefaultItemAnimator(); itemAnimator.setSupportsChangeAnimations(false); mPhotoGridView.setItemAnimator(itemAnimator); mPhotoGridView.setHasFixedSize(true); 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_settings_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_settings_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, false); } }); final DrawInsetsFrameLayout insetsLayout = (DrawInsetsFrameLayout) findViewById(R.id.draw_insets_frame_layout); insetsLayout.setOnInsetsCallback(new DrawInsetsFrameLayout.OnInsetsCallback() { @Override public void onInsetsChanged(Rect insets) { insetsLayout.setPadding(insets.left, insets.top, insets.right, insets.bottom); TypedValue actionBarSizeValue = new TypedValue(); getTheme().resolveAttribute(R.attr.actionBarSize, actionBarSizeValue, true); int gridSpacing = getResources().getDimensionPixelSize(R.dimen.gallery_settings_chosen_photo_grid_spacing); mPhotoGridView.setPadding(insets.left + gridSpacing, insets.top + gridSpacing + (int) actionBarSizeValue.getDimension(getResources().getDisplayMetrics()), insets.right + gridSpacing, insets.bottom + gridSpacing + getResources().getDimensionPixelSize(R.dimen.gallery_settings_fab_space)); findViewById(R.id.selection_toolbar_container).setPadding(insets.left, insets.top, insets.right, 0); } }); 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) { chooseMorePhotos(); } }); CheatSheet.setup(mAddButton); EventBus.getDefault().register(this); }
49. ViewerActivity#onCreate()
Project: mr-mantou-android
File: ViewerActivity.java
File: ViewerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); binding = DataBindingUtil.setContentView(this, R.layout.viewer_activity); setTitle(null); binding.toolbar.setNavigationOnClickListener( v -> supportFinishAfterTransition()); binding.toolbar.inflateMenu(R.menu.viewer); binding.puller.setCallback(this); supportPostponeEnterTransition(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getWindow().getEnterTransition().addListener(new SimpleTransitionListener() { @Override @TargetApi(Build.VERSION_CODES.LOLLIPOP) public void onTransitionEnd(Transition transition) { getWindow().getEnterTransition().removeListener(this); fadeIn(); } }); } else { fadeIn(); } background = new ColorDrawable(Color.BLACK); binding.getRoot().setBackground(background); adapter = new Adapter(); binding.pager.setAdapter(adapter); binding.pager.setCurrentItem(getIntent().getIntExtra("index", 0)); binding.pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageScrollStateChanged(int state) { if (state == ViewPager.SCROLL_STATE_DRAGGING) { fadeOut(); } } }); listener = new ObservableListPagerAdapterCallback(adapter); images.addOnListChangedCallback(listener); setEnterSharedElementCallback(new SharedElementCallback() { @Override public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) { Image image = images.get(binding.pager.getCurrentItem()); sharedElements.clear(); sharedElements.put(String.format("%s.image", image.getObjectId()), getCurrent().getSharedElement()); } }); menuItemClicks(R.id.share).compose(bindToLifecycle()).compose(ensurePermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)).map( avoid -> getCurrentImage()).doOnNext( image -> MobclickAgent.onEvent(this, "share", image.getObjectId())).observeOn(Schedulers.io()).flatMap(this::saveIfNeeded).observeOn(AndroidSchedulers.mainThread()).doOnNext(this::notifyMediaScanning).map(Uri::fromFile).retry().subscribe( uri -> { final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("image/jpeg"); intent.putExtra(Intent.EXTRA_STREAM, uri); startActivity(Intent.createChooser(intent, getString(R.string.share_title))); }); menuItemClicks(R.id.save).compose(bindToLifecycle()).compose(ensurePermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)).map( avoid -> getCurrentImage()).doOnNext( image -> MobclickAgent.onEvent(this, "save", image.getObjectId())).observeOn(Schedulers.io()).flatMap(this::saveIfNeeded).observeOn(AndroidSchedulers.mainThread()).doOnNext(this::notifyMediaScanning).retry().subscribe( file -> { ToastUtil.shorts(this, R.string.save_success, file.getPath()); }); final WallpaperManager wm = WallpaperManager.getInstance(this); menuItemClicks(R.id.set_wallpaper).compose(bindToLifecycle()).map( avoid -> getCurrentImage()).doOnNext( image -> MobclickAgent.onEvent(this, "set_wallpaper", image.getObjectId())).observeOn(Schedulers.io()).flatMap(this::download).observeOn(AndroidSchedulers.mainThread()).map( file -> FileProvider.getUriForFile(this, AUTHORITY_IMAGES, file)).retry().subscribe( uri -> { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { startActivity(wm.getCropAndSetWallpaperIntent(uri)); } else { try { wm.setStream(getContentResolver().openInputStream(uri)); ToastUtil.shorts(this, R.string.set_wallpaper_success); } catch (IOException e) { Log.e(TAG, "Failed to set wallpaper", e); ToastUtil.shorts(this, e.getMessage(), e); } } }); }
50. MaterialRippleLayout#setRippleBackground()
Project: MDPreference
File: MaterialRippleLayout.java
File: MaterialRippleLayout.java
public void setRippleBackground(int color) { rippleBackground = new ColorDrawable(color); rippleBackground.setBounds(bounds); invalidate(); }
51. DrawerUIUtils#getDrawerItemBackground()
Project: MaterialDrawer
File: DrawerUIUtils.java
File: DrawerUIUtils.java
/** * helper to create a StateListDrawable for the drawer item background * * @param selected_color * @return */ public static StateListDrawable getDrawerItemBackground(int selected_color) { ColorDrawable clrActive = new ColorDrawable(selected_color); StateListDrawable states = new StateListDrawable(); states.addState(new int[] { android.R.attr.state_selected }, clrActive); return states; }
52. MaterialRippleLayout#setRippleBackground()
Project: material-ripple
File: MaterialRippleLayout.java
File: MaterialRippleLayout.java
public void setRippleBackground(int color) { rippleBackground = new ColorDrawable(color); rippleBackground.setBounds(bounds); invalidate(); }
53. MaterialRippleLayout#setRippleBackground()
Project: material-cat
File: MaterialRippleLayout.java
File: MaterialRippleLayout.java
public void setRippleBackground(int color) { rippleBackground = new ColorDrawable(color); rippleBackground.setBounds(bounds); invalidate(); }
54. MaterialRippleLayout#setRippleBackground()
Project: LoyalNativeSlider
File: MaterialRippleLayout.java
File: MaterialRippleLayout.java
public void setRippleBackground(int color) { rippleBackground = new ColorDrawable(color); rippleBackground.setBounds(bounds); invalidate(); }
55. GlideUtil#loadImage()
Project: Ishusho
File: GlideUtil.java
File: GlideUtil.java
public static void loadImage(String url, ImageView imageView) { Context context = imageView.getContext(); ColorDrawable cd = new ColorDrawable(ContextCompat.getColor(context, R.color.colorPrimaryDark)); Glide.with(context).load(url).placeholder(cd).crossFade().centerCrop().into(imageView); }
56. GlideUtil#loadImage()
Project: friendlypix
File: GlideUtil.java
File: GlideUtil.java
public static void loadImage(String url, ImageView imageView) { Context context = imageView.getContext(); ColorDrawable cd = new ColorDrawable(ContextCompat.getColor(context, R.color.blue_grey_500)); Glide.with(context).load(url).placeholder(cd).crossFade().centerCrop().into(imageView); }
57. FloatingSearchView#init()
Project: Floatingsearchview-master
File: FloatingSearchView.java
File: FloatingSearchView.java
private void init(AttributeSet attrs) { mHostActivity = getHostActivity(); LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); mMainLayout = inflate(getContext(), R.layout.floating_search_layout, this); mBackgroundDrawable = new ColorDrawable(Color.BLACK); mQuerySection = (CardView) findViewById(R.id.search_query_section); mClearButton = (ImageView) findViewById(R.id.clear_btn); mSearchInput = (EditText) findViewById(R.id.search_bar_text); mSearchInputParent = findViewById(R.id.search_input_parent); mLeftAction = (ImageView) findViewById(R.id.left_action); mSearchProgress = (ProgressBar) findViewById(R.id.search_bar_search_progress); initDrawables(); mClearButton.setImageDrawable(mIconClear); mMenuView = (MenuView) findViewById(R.id.menu_view); mDivider = findViewById(R.id.divider); mSuggestionsSection = (RelativeLayout) findViewById(R.id.search_suggestions_section); mSuggestionListContainer = findViewById(R.id.suggestions_list_container); mSuggestionsList = (RecyclerView) findViewById(R.id.suggestions_list); setupViews(attrs); }
58. FloatingSearchView#init()
Project: floatingsearchview
File: FloatingSearchView.java
File: FloatingSearchView.java
private void init(AttributeSet attrs) { mHostActivity = getHostActivity(); LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); mMainLayout = inflate(getContext(), R.layout.floating_search_layout, this); mBackgroundDrawable = new ColorDrawable(Color.BLACK); mQuerySection = (CardView) findViewById(R.id.search_query_section); mClearButton = (ImageView) findViewById(R.id.clear_btn); mSearchInput = (EditText) findViewById(R.id.search_bar_text); mSearchInputParent = findViewById(R.id.search_input_parent); mLeftAction = (ImageView) findViewById(R.id.left_action); mSearchProgress = (ProgressBar) findViewById(R.id.search_bar_search_progress); initDrawables(); mClearButton.setImageDrawable(mIconClear); mMenuView = (MenuView) findViewById(R.id.menu_view); mDivider = findViewById(R.id.divider); mSuggestionsSection = (RelativeLayout) findViewById(R.id.search_suggestions_section); mSuggestionListContainer = findViewById(R.id.suggestions_list_container); mSuggestionsList = (RecyclerView) findViewById(R.id.suggestions_list); setupViews(attrs); }
59. Utils#getSelectablePressedBackground()
Project: FlexibleAdapter
File: Utils.java
File: Utils.java
/** * Helper to get the system default selectable background inclusive an active and pressed state. * <p>Useful for Image item selection.</p> * * @param context the context * @param selectedColor the selected color * @param pressedAlpha 0-255 * @param animate true if you want to fade over the states (only animates if API * newer than Build.VERSION_CODES.HONEYCOMB) * @return the StateListDrawable */ public static StateListDrawable getSelectablePressedBackground(Context context, @ColorInt int selectedColor, @IntRange(from = 0, to = 255) int pressedAlpha, boolean animate) { StateListDrawable states = getSelectableBackground(context, selectedColor, animate); ColorDrawable clrPressed = new ColorDrawable(adjustAlpha(selectedColor, pressedAlpha)); states.addState(new int[] { android.R.attr.state_pressed }, clrPressed); return states; }
60. FastAdapterUIUtils#getSelectablePressedBackground()
Project: FastAdapter
File: FastAdapterUIUtils.java
File: FastAdapterUIUtils.java
/** * helper to get the system default selectable background inclusive an active and pressed state * * @param ctx the context * @param selected_color the selected color * @param pressed_alpha 0-255 * @param animate true if you want to fade over the states (only animates if API newer than Build.VERSION_CODES.HONEYCOMB) * @return the StateListDrawable */ public static StateListDrawable getSelectablePressedBackground(Context ctx, @ColorInt int selected_color, int pressed_alpha, boolean animate) { StateListDrawable states = getSelectableBackground(ctx, selected_color, animate); ColorDrawable clrPressed = new ColorDrawable(adjustAlpha(selected_color, pressed_alpha)); states.addState(new int[] { android.R.attr.state_pressed }, clrPressed); return states; }
61. DefaultImageLoadHandler#setLoadingImageColor()
Project: cube-sdk
File: DefaultImageLoadHandler.java
File: DefaultImageLoadHandler.java
/** * set the placeholder by color * * @param color */ public void setLoadingImageColor(int color) { mLoadingColor = color; mLoadingDrawable = new ColorDrawable(color); }
62. EditDialogOkBackground#getBg()
Project: astrid
File: EditDialogOkBackground.java
File: EditDialogOkBackground.java
public static StateListDrawable getBg(int colorValue) { final Paint p = new Paint(); p.setColor(Color.GRAY); Drawable d = new Drawable() { @Override public void setColorFilter(ColorFilter cf) { // } @Override public void setAlpha(int alpha) { // } @Override public int getOpacity() { return PixelFormat.OPAQUE; } @Override public void draw(Canvas canvas) { Rect r = canvas.getClipBounds(); canvas.drawLine(r.left, r.top, r.right, r.top, p); } }; ColorDrawable color = new ColorDrawable(colorValue); StateListDrawable stld = new StateListDrawable(); stld.addState(new int[] { android.R.attr.state_pressed }, color); stld.addState(new int[] { android.R.attr.state_enabled }, d); return stld; }
63. EResources#init()
Project: appcan-android
File: EResources.java
File: EResources.java
public static boolean init(Context context) { String packg = context.getPackageName(); Resources res = context.getResources(); startup_bg_16_9 = res.getIdentifier("startup_bg_16_9", drawable, packg); startup_bg_3_2 = res.getIdentifier("startup_bg_3_2", drawable, packg); icon = res.getIdentifier("icon", drawable, packg); platform_myspace_pulltorefresh_arrow = res.getIdentifier("platform_myspace_pulltorefresh_arrow", drawable, packg); browser_init_error = res.getIdentifier("browser_init_error", string, packg); browser_exitdialog_msg = res.getIdentifier("browser_exitdialog_msg", string, packg); cancel = res.getIdentifier("cancel", string, packg); browser_exitdialog_app_text = res.getIdentifier("browser_exitdialog_app_text", string, packg); confirm = res.getIdentifier("confirm", string, packg); String release = Build.VERSION.RELEASE; windowBg = new ColorDrawable(0x00000000); if ("4.0.4".equals(release)) { windowBg = new ColorDrawable(0xFFFFFFFF); } if (startup_bg_16_9 == 0 || startup_bg_3_2 == 0 || icon == 0 || platform_myspace_pulltorefresh_arrow == 0 || browser_init_error == 0 || browser_exitdialog_msg == 0 || cancel == 0 || browser_exitdialog_app_text == 0 || confirm == 0) { return false; } return true; }
64. SearchContentFragment#setupBackgroundManager()
Project: AndroidTvBoilerplate
File: SearchContentFragment.java
File: SearchContentFragment.java
private void setupBackgroundManager() { mBackgroundManager = BackgroundManager.getInstance(getActivity()); mBackgroundManager.attach(getActivity().getWindow()); mBackgroundManager.setColor(ContextCompat.getColor(getActivity(), R.color.primary_light)); mDefaultBackground = new ColorDrawable(ContextCompat.getColor(getActivity(), R.color.primary_light)); mMetrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(mMetrics); }
65. ContentFragment#prepareBackgroundManager()
Project: AndroidTvBoilerplate
File: ContentFragment.java
File: ContentFragment.java
private void prepareBackgroundManager() { mBackgroundManager = BackgroundManager.getInstance(getActivity()); mBackgroundManager.attach(getActivity().getWindow()); mDefaultBackground = new ColorDrawable(ContextCompat.getColor(getActivity(), R.color.primary_light)); mBackgroundManager.setColor(ContextCompat.getColor(getActivity(), R.color.primary_light)); mMetrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(mMetrics); }
66. MaterialRippleLayoutNineOld#setRippleBackground()
Project: AdvancedMaterialDrawer
File: MaterialRippleLayoutNineOld.java
File: MaterialRippleLayoutNineOld.java
public void setRippleBackground(int color) { rippleBackground = new ColorDrawable(color); rippleBackground.setBounds(bounds); invalidate(); }
67. MaterialRippleLayout#setRippleBackground()
Project: AdvancedMaterialDrawer
File: MaterialRippleLayout.java
File: MaterialRippleLayout.java
public void setRippleBackground(int color) { rippleBackground = new ColorDrawable(color); rippleBackground.setBounds(bounds); invalidate(); }