List of usage examples for android.graphics.drawable ColorDrawable ColorDrawable
public ColorDrawable(@ColorInt int color)
From source file:com.collcloud.frame.viewpager.main.PagerTabMainActivity.java
private void changeColor(int newColor) { tabs.setIndicatorColor(newColor);/*from ww w .j a v a 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.tab_pagertab_actionbar_bottom); LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable }); if (oldBackground == null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { ld.setCallback(drawableCallback); } else { //getActionBar().setBackgroundDrawable(ld); } } else { TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld }); // workaround for broken ActionBarContainer drawable handling on // pre-API 17 builds // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { td.setCallback(drawableCallback); } else { //getActionBar().setBackgroundDrawable(td); } td.startTransition(200); } oldBackground = ld; // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler // getActionBar().setDisplayShowTitleEnabled(false); // getActionBar().setDisplayShowTitleEnabled(true); } currentColor = newColor; }
From source file:com.eccyan.widget.sample.MainActivity.java
private void changeColor(int newColor) { tabs.setBackgroundColor(newColor);/* ww w . j a v a 2 s .c o m*/ mTintManager.setTintColor(newColor); // change ActionBar color just if an ActionBar is available Drawable colorDrawable = new ColorDrawable(newColor); Drawable bottomDrawable = new ColorDrawable(getResources().getColor(android.R.color.transparent)); LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable }); if (oldBackground == null) { getSupportActionBar().setBackgroundDrawable(ld); } else { TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld }); getSupportActionBar().setBackgroundDrawable(td); td.startTransition(200); } oldBackground = ld; currentColor = newColor; }
From source file:com.tony.casthelloworld.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)); //Current Card Text currentCard = (TextView) findViewById(R.id.currentCard); //Remaining Cards Text remainingCards = (TextView) findViewById(R.id.cardsRemaining); //Start/Reset Game Button startGame = (Button) findViewById(R.id.startGame); startGame.setOnClickListener(new View.OnClickListener() { @Override/*from ww w . j a v a 2s . c om*/ public void onClick(View v) { initializeGame(); updateCast(); } }); //Next Card Button nextCard = (Button) findViewById(R.id.nextCard); nextCard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //pop the card off //Update the current card getNextCard(); updateCast(); } }); //Show Card Button showCard = (Button) findViewById(R.id.showCard); showCard.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: //Make the card visible if (deck.peek() != null) { currentCard.setText(prettyPrintCard(deck.peek())); } else { currentCard.setText("No more Cards!"); } return true; case MotionEvent.ACTION_UP: // No longer down if (deck.peek() != null) { currentCard.setText(CARD_HIDDEN_TEXT); } else { currentCard.setText("No more Cards!"); } return true; } return false; } }); // 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.agenmate.lollipop.util.ViewUtils.java
public static RippleDrawable createRipple(@NonNull Palette palette, @FloatRange(from = 0f, to = 1f) float darkAlpha, @FloatRange(from = 0f, to = 1f) float lightAlpha, @ColorInt int fallbackColor, boolean bounded) { int rippleColor = fallbackColor; if (palette != null) { // try the named swatches in preference order if (palette.getVibrantSwatch() != null) { rippleColor = ColorUtils.modifyAlpha(palette.getVibrantSwatch().getRgb(), darkAlpha); } else if (palette.getLightVibrantSwatch() != null) { rippleColor = ColorUtils.modifyAlpha(palette.getLightVibrantSwatch().getRgb(), lightAlpha); } else if (palette.getDarkVibrantSwatch() != null) { rippleColor = ColorUtils.modifyAlpha(palette.getDarkVibrantSwatch().getRgb(), darkAlpha); } else if (palette.getMutedSwatch() != null) { rippleColor = ColorUtils.modifyAlpha(palette.getMutedSwatch().getRgb(), darkAlpha); } else if (palette.getLightMutedSwatch() != null) { rippleColor = ColorUtils.modifyAlpha(palette.getLightMutedSwatch().getRgb(), lightAlpha); } else if (palette.getDarkMutedSwatch() != null) { rippleColor = ColorUtils.modifyAlpha(palette.getDarkMutedSwatch().getRgb(), darkAlpha); }/* w ww. j a va 2s .com*/ } return new RippleDrawable(ColorStateList.valueOf(rippleColor), null, bounded ? new ColorDrawable(Color.WHITE) : null); }
From source file:org.lol.reddit.activities.ImageViewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); final boolean solidblack = PrefsUtility.appearance_solidblack(this, sharedPreferences); if (solidblack) getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK)); final Intent intent = getIntent(); mUrl = General.uriFromString(intent.getDataString()); final RedditPost src_post = intent.getParcelableExtra("post"); if (mUrl == null) { General.quickToast(this, "Invalid URL. Trying web browser."); revertToWeb();// www . j av a 2 s .c o m return; } Log.i("ImageViewActivity", "Loading URL " + mUrl.toString()); final ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal); final LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(progressBar); CacheManager.getInstance(this) .makeRequest(new CacheRequest(mUrl, RedditAccountManager.getAnon(), null, Constants.Priority.IMAGE_VIEW, 0, CacheRequest.DownloadType.IF_NECESSARY, Constants.FileType.IMAGE, false, false, false, this) { private void setContentView(View v) { layout.removeAllViews(); layout.addView(v); v.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT; v.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT; } @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(context.getApplicationContext(), new RRError(null, null, t)); } @Override protected void onDownloadNecessary() { General.UI_THREAD_HANDLER.post(new Runnable() { @Override public void run() { progressBar.setVisibility(View.VISIBLE); progressBar.setIndeterminate(true); } }); } @Override protected void onDownloadStarted() { } @Override protected void onFailure(final RequestFailureType type, Throwable t, StatusLine status, final String readableMessage) { final RRError error = General.getGeneralErrorForFailure(context, type, t, status, url.toString()); General.UI_THREAD_HANDLER.post(new Runnable() { public void run() { // TODO handle properly progressBar.setVisibility(View.GONE); layout.addView(new ErrorView(ImageViewActivity.this, error)); } }); } @Override protected void onProgress(final long bytesRead, final long totalBytes) { General.UI_THREAD_HANDLER.post(new Runnable() { @Override public void run() { progressBar.setVisibility(View.VISIBLE); progressBar.setIndeterminate(false); progressBar.setProgress((int) ((100 * bytesRead) / totalBytes)); } }); } @Override protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, long timestamp, UUID session, boolean fromCache, final String mimetype) { if (mimetype == null || !Constants.Mime.isImage(mimetype)) { revertToWeb(); return; } final InputStream cacheFileInputStream; try { cacheFileInputStream = cacheFile.getInputStream(); } catch (IOException e) { notifyFailure(RequestFailureType.PARSE, e, null, "Could not read existing cached image."); return; } if (cacheFileInputStream == null) { notifyFailure(RequestFailureType.CACHE_MISS, null, null, "Could not find cached image"); return; } if (Constants.Mime.isImageGif(mimetype)) { if (AndroidApi.isIceCreamSandwichOrLater()) { General.UI_THREAD_HANDLER.post(new Runnable() { public void run() { try { final GIFView gifView = new GIFView(ImageViewActivity.this, cacheFileInputStream); setContentView(gifView); gifView.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { finish(); } }); } catch (OutOfMemoryError e) { General.quickToast(context, R.string.imageview_oom); revertToWeb(); } catch (Throwable e) { General.quickToast(context, R.string.imageview_invalid_gif); revertToWeb(); } } }); } else { gifThread = new GifDecoderThread(cacheFileInputStream, new GifDecoderThread.OnGifLoadedListener() { public void onGifLoaded() { General.UI_THREAD_HANDLER.post(new Runnable() { public void run() { imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); setContentView(imageView); gifThread.setView(imageView); imageView.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { finish(); } }); } }); } public void onOutOfMemory() { General.quickToast(context, R.string.imageview_oom); revertToWeb(); } public void onGifInvalid() { General.quickToast(context, R.string.imageview_invalid_gif); revertToWeb(); } }); gifThread.start(); } } else { final long bytes = cacheFile.getSize(); final byte[] buf = new byte[(int) bytes]; try { new DataInputStream(cacheFileInputStream).readFully(buf); } catch (IOException e) { throw new RuntimeException(e); } final ImageTileSource imageTileSource; try { imageTileSource = new ImageTileSourceWholeBitmap(buf); } catch (OutOfMemoryError e) { General.quickToast(context, R.string.imageview_oom); revertToWeb(); return; } catch (Throwable t) { Log.e("ImageViewActivity", "Exception when creating ImageTileSource", t); General.quickToast(context, R.string.imageview_decode_failed); revertToWeb(); return; } General.UI_THREAD_HANDLER.post(new Runnable() { public void run() { surfaceView = new RRGLSurfaceView(ImageViewActivity.this, new ImageViewDisplayListManager(imageTileSource, ImageViewActivity.this)); setContentView(surfaceView); surfaceView.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { finish(); } }); if (mIsPaused) { surfaceView.onPause(); } else { surfaceView.onResume(); } } }); } } }); final RedditPreparedPost post = src_post == null ? null : new RedditPreparedPost(this, CacheManager.getInstance(this), 0, src_post, -1, false, false, false, false, RedditAccountManager.getInstance(this).getDefaultAccount(), false); final FrameLayout outerFrame = new FrameLayout(this); outerFrame.addView(layout); if (post != null) { final SideToolbarOverlay toolbarOverlay = new SideToolbarOverlay(this); final BezelSwipeOverlay bezelOverlay = new BezelSwipeOverlay(this, new BezelSwipeOverlay.BezelSwipeListener() { public boolean onSwipe(BezelSwipeOverlay.SwipeEdge edge) { toolbarOverlay.setContents( post.generateToolbar(ImageViewActivity.this, false, toolbarOverlay)); toolbarOverlay.show(edge == BezelSwipeOverlay.SwipeEdge.LEFT ? SideToolbarOverlay.SideToolbarPosition.LEFT : SideToolbarOverlay.SideToolbarPosition.RIGHT); return true; } public boolean onTap() { if (toolbarOverlay.isShown()) { toolbarOverlay.hide(); return true; } return false; } }); outerFrame.addView(bezelOverlay); outerFrame.addView(toolbarOverlay); bezelOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT; bezelOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT; toolbarOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT; toolbarOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT; } setContentView(outerFrame); }
From source file:com.LMO.capstone.KnoWITHerbalMain.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override//from w w w. j a va 2s .c o m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_layout); title = ""; navTitles = getResources().getStringArray(R.array.navigationMenus); drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout); drawerList = (ListView) findViewById(R.id.nav_list); drawer = (LinearLayout) findViewById(R.id.drawer_view); util = new Utilities(this); drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); drawerList.setAdapter(new MenuListAdapter(this, navTitles)); drawerList.setOnItemClickListener(new DrawerItemClickListener()); drawerList.setSelector(R.drawable.listitem_selector); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#6AD600"))); //light green = 6ad600, dark = 00cc00 getSupportActionBar().setIcon(getResources().getDrawable(R.drawable.ic_launcher_2)); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { public void onDrawerClosed(View view) { getSupportActionBar().setTitle(title); supportInvalidateOptionsMenu(); } public void onDrawerOpened(View view) { getSupportActionBar().setDisplayShowTitleEnabled(true); getSupportActionBar().setTitle("Menu"); supportInvalidateOptionsMenu(); } }; drawerLayout.setDrawerListener(drawerToggle); if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } //FIRST RUN OF THE APPLICATION============================================ if (savedInstanceState == null) { FragmentTransaction fTransac = getSupportFragmentManager().beginTransaction(); fTransac.replace(R.id.frame_content, new Welcome()).commit(); try { resolver(); } catch (XmlPullParserException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //END OF FIRST RUN OF THE APPLICATION============================================ /*try { ViewConfiguration config = ViewConfiguration.get(this); Field menuKeyField = ViewConfiguration.class .getDeclaredField("sHasPermanentMenuKey"); if (menuKeyField != null) { menuKeyField.setAccessible(true); menuKeyField.setBoolean(config, false); } } catch (Exception e) { e.printStackTrace(); }*/ }
From source file:com.lee.sdk.widget.viewpager.DrawablePageIndicator.java
@SuppressWarnings("deprecation") public DrawablePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;/*from w w w .ja v a 2 s . c o m*/ //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DrawablePageIndicator, defStyle, 0); Drawable background = a.getDrawable(R.styleable.DrawablePageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } mShadowLeft = a.getDimension(R.styleable.DrawablePageIndicator_shadow_left, 0.0f); mShadowRight = a.getDimension(R.styleable.DrawablePageIndicator_shadow_right, 0.0f); mDrawable = a.getDrawable(R.styleable.DrawablePageIndicator_android_src); if (mDrawable == null) { mDrawable = new ColorDrawable(Color.WHITE); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:com.example.ies_sms_demo.EquipementSlideActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_equipement_slide); sharedPref = getSharedPreferences("share_data", Context.MODE_PRIVATE); String projectListStr = sharedPref.getString(getString(R.string.project_list), ""); projects = EquipmentHelper.getProjectList(projectListStr); getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent))); pIndex = getIntent().getIntExtra("pIndex", 0); //Remove notification bar // this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); if (projects.size() > 0) { setTitle(projects.get(0).name_en); equipements = (ArrayList<Equipment>) projects.get(pIndex).equipments; eIndex = getIntent().getIntExtra("eIndex", 0); // Instantiate a ViewPager and a PagerAdapter. setTitle(equipements.get(eIndex).refNo); getActionBar().setDisplayHomeAsUpEnabled(true); mPager = (ViewPager) findViewById(R.id.pager); next = (ImageView) findViewById(R.id.next); previous = (ImageView) findViewById(R.id.previous); mPagerAdapter = new ScreenSlidePagerAdapter(getFragmentManager()); if (previous != null) { previous.setVisibility(getVisibility(eIndex > 0)); previous.setOnClickListener(new OnClickListener() { @Override/* w w w . j a va 2s . c o m*/ public void onClick(View v) { mPager.setCurrentItem(mPager.getCurrentItem() - 1); } }); } if (next != null) { next.setVisibility(getVisibility(eIndex < mPagerAdapter.getCount() - 1)); next.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mPager.setCurrentItem(mPager.getCurrentItem() + 1); } }); } mPager.setAdapter(mPagerAdapter); mPager.setCurrentItem(eIndex); mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When changing pages, reset the action bar actions since they are dependent // on which page is currently active. An alternative approach is to have each // fragment expose actions itself (rather than the activity exposing actions), // but for simplicity, the activity provides the actions in this sample. setTitle(equipements.get(position).refNo); if (previous != null) previous.setVisibility(getVisibility(mPager.getCurrentItem() > 0)); if (next != null) next.setVisibility(getVisibility(mPager.getCurrentItem() < mPagerAdapter.getCount() - 1)); invalidateOptionsMenu(); } }); } }
From source file:bander.notepad.PrefsFragmentAppCompat.java
private void showCustomColorChooser() { new ColorChooserDialog().show(getActivity(), selectedColorIndex, new ColorChooserDialog.Callback() { @Override//from ww w . j a va 2s . c o m public void onColorSelection(int index, int color, int darker) { selectedColorIndex = index; ActionBarActivity aba = (ActionBarActivity) getActivity(); aba.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color)); ThemeSingleton.get().positiveColor = color; ThemeSingleton.get().neutralColor = color; ThemeSingleton.get().negativeColor = color; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) aba.getWindow().setStatusBarColor(darker); } }); }
From source file:app.philm.in.view.InsetFrameLayout.java
void setInsetBackgroundColorRaw(int color) { setInsetBackground(new ColorDrawable(color)); }