List of usage examples for android.support.v4.content ContextCompat getDrawable
public static final Drawable getDrawable(Context context, int i)
From source file:com.artioml.practice.MainActivity.java
private void fillSettingsPanel() { SharedPreferences sharedPreferences = getSharedPreferences(MAIN_SETTINGS, Context.MODE_PRIVATE); ((TextView) findViewById(R.id.punchTypeView)).setText( getResources().getStringArray(R.array.punch_type_list)[sharedPreferences.getInt(PUNCH_TYPE, 0)]); String hand = "ic_" + sharedPreferences.getString(HAND, "right") + "_hand"; ((ImageView) findViewById(R.id.handView)).setImageDrawable( ContextCompat.getDrawable(this, getResources().getIdentifier(hand, "drawable", getPackageName()))); String gloves = "ic_gloves_" + sharedPreferences.getString(GLOVES, "off"); ((ImageView) findViewById(R.id.glovesView)).setImageDrawable(ContextCompat.getDrawable(this, getResources().getIdentifier(gloves, "drawable", getPackageName()))); if (gloves.compareTo("ic_gloves_off") == 0) findViewById(R.id.weightView).setVisibility(View.GONE); else {/* w w w .j a v a2s . c om*/ findViewById(R.id.weightView).setVisibility(View.VISIBLE); ((TextView) findViewById(R.id.weightView)).setText(sharedPreferences.getString(GLOVES_WEIGHT, "80")); } String position = "ic_punch_" + sharedPreferences.getString(POSITION, "with") + "_step"; ((ImageView) findViewById(R.id.positionView)).setImageDrawable(ContextCompat.getDrawable(this, getResources().getIdentifier(position, "drawable", getPackageName()))); }
From source file:com.amazon.android.tv.tenfoot.ui.fragments.FullContentBrowseFragment.java
protected void setDefaultBackground(int resourceId) { mDefaultBackground = ContextCompat.getDrawable(getActivity(), resourceId); }
From source file:com.amazon.android.tv.tenfoot.ui.fragments.ContentDetailsFragment.java
private void prepareBackgroundManager() { mBackgroundManager = BackgroundManager.getInstance(getActivity()); mBackgroundManager.attach(getActivity().getWindow()); mDefaultBackground = ContextCompat.getDrawable(getActivity(), android.R.color.transparent); mMetrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(mMetrics); }
From source file:com.classiqo.nativeandroid_32bitz.ui.PlaybackControlsFragment.java
private void onPlaybackStateChanged(PlaybackStateCompat state) { LogHelper.d(TAG, "onPlaybackStateChanged ", state); if (getActivity() == null) { LogHelper.w(TAG, "onPlaybackStateChanged called when getActivity null," + "this should not happen if the callback was properly unregistered. Ignoring."); return;/*from w w w .ja v a 2 s. com*/ } if (state == null) { return; } boolean enablePlay = false; switch (state.getState()) { case PlaybackStateCompat.STATE_PAUSED: case PlaybackStateCompat.STATE_STOPPED: enablePlay = true; break; case PlaybackStateCompat.STATE_ERROR: LogHelper.e(TAG, "error playbackState: ", state.getErrorMessage()); Toast.makeText(getActivity(), state.getErrorMessage(), Toast.LENGTH_LONG).show(); break; } if (enablePlay) { mPlayPause.setImageDrawable( ContextCompat.getDrawable(getActivity(), R.drawable.ic_play_arrow_black_36dp)); } else { mPlayPause.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_pause_black_36dp)); } MediaControllerCompat controller = ((FragmentActivity) getActivity()).getSupportMediaController(); String extraInfo = null; if (controller != null && controller.getExtras() != null) { String castName = controller.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST); if (castName != null) { extraInfo = getResources().getString(R.string.casting_to_device, castName); } } setExtraInfo(extraInfo); }
From source file:com.einzig.ipst2.activities.PSDetailsActivity.java
/** * Add additional UI components for a rejected portal submission * * @param portal Portal being viewed cast to a PortalRejected for convenience *//* ww w. j a v a2s .c om*/ private void buildRejectedUI(PortalRejected portal) { buildRespondedUI(portal); portalStatusImage.setBackgroundColor(ContextCompat.getColor(this, R.color.rejected)); portalStatusImage.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_rejected)); LinearLayout rejectedLayout = (LinearLayout) LayoutInflater.from(this) .inflate(R.layout.row_psdetails_rejected, extraLayout, false); ThemeHelper.styleView(rejectedLayout.findViewById(R.id.rejectionreasonlayout_rejectedrow), this); ((TextView) rejectedLayout.findViewById(R.id.rejectionreason_rejectedrow)) .setText(portal.getRejectionReason()); extraLayout.addView(rejectedLayout); }
From source file:com.bayapps.android.robophish.ui.PlaybackControlsFragment.java
private void onPlaybackStateChanged(PlaybackStateCompat state) { LogHelper.d(TAG, "onPlaybackStateChanged ", state); if (getActivity() == null) { LogHelper.w(TAG, "onPlaybackStateChanged called when getActivity null," + "this should not happen if the callback was properly unregistered. Ignoring."); return;/*from w w w . j av a 2s .com*/ } if (state == null) { return; } boolean enablePlay = false; switch (state.getState()) { case PlaybackStateCompat.STATE_PAUSED: case PlaybackStateCompat.STATE_STOPPED: enablePlay = true; break; case PlaybackStateCompat.STATE_ERROR: LogHelper.e(TAG, "error playbackstate: ", state.getErrorMessage()); Toast.makeText(getActivity(), state.getErrorMessage(), Toast.LENGTH_LONG).show(); break; } if (enablePlay) { mPlayPause.setImageDrawable( ContextCompat.getDrawable(getActivity(), R.drawable.ic_play_arrow_black_36dp)); } else { mPlayPause.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_pause_black_36dp)); } MediaControllerCompat controller = ((FragmentActivity) getActivity()).getSupportMediaController(); String extraInfo = null; if (controller != null && controller.getExtras() != null) { String castName = controller.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST); if (castName != null) { extraInfo = getResources().getString(R.string.casting_to_device, castName); } } setExtraInfo(extraInfo); }
From source file:cl.smartcities.isci.transportinspector.fragments.ReportMapFragment.java
@Override public void currentIsOnFoot() { currentIsOnBus = false;//from www. j a v a 2 s . c om this.stateMessage.changeMessage(this.getContext().getString(R.string.on_foot_message), ContextCompat.getDrawable(getContext(), R.drawable.contexto_apie), false); }
From source file:com.example.android.mediabrowserservice.QueueFragment.java
private void onPlaybackStateChanged(PlaybackStateCompat state) { LogHelper.d(TAG, "onPlaybackStateChanged ", state); if (state == null) { return;/*from w ww .j a v a 2 s. c o m*/ } mQueueAdapter.setActiveQueueItemId(state.getActiveQueueItemId()); mQueueAdapter.notifyDataSetChanged(); boolean enablePlay = false; StringBuilder statusBuilder = new StringBuilder(); switch (state.getState()) { case PlaybackState.STATE_PLAYING: statusBuilder.append("playing"); enablePlay = false; break; case PlaybackState.STATE_PAUSED: statusBuilder.append("paused"); enablePlay = true; break; case PlaybackState.STATE_STOPPED: statusBuilder.append("ended"); enablePlay = true; break; case PlaybackState.STATE_ERROR: statusBuilder.append("error: ").append(state.getErrorMessage()); break; case PlaybackState.STATE_BUFFERING: statusBuilder.append("buffering"); break; case PlaybackState.STATE_NONE: statusBuilder.append("none"); enablePlay = false; break; case PlaybackState.STATE_CONNECTING: statusBuilder.append("connecting"); break; default: statusBuilder.append(mPlaybackState); } statusBuilder.append(" -- At position: ").append(state.getPosition()); LogHelper.d(TAG, statusBuilder.toString()); if (enablePlay) { mPlayPause.setImageDrawable( ContextCompat.getDrawable(getActivity(), R.drawable.ic_play_arrow_white_24dp)); } else { mPlayPause.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_pause_white_24dp)); } mSkipPrevious.setEnabled((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0); mSkipNext.setEnabled((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0); LogHelper.d(TAG, "Queue From MediaController *** Title " + mMediaController.getQueueTitle() + "\n: Queue: " + mMediaController.getQueue() + "\n Metadata " + mMediaController.getMetadata()); }
From source file:com.finchuk.clock2.timepickers.Utils.java
/** * Returns a tinted drawable from the given drawable resource, if {@code tintList != null}. * Otherwise, no tint will be applied./*from ww w. j a v a2 s . c om*/ */ public static Drawable getTintedDrawable(@NonNull Context context, @DrawableRes int drawableRes, @Nullable ColorStateList tintList) { Drawable d = DrawableCompat.wrap(ContextCompat.getDrawable(context, drawableRes).mutate()); DrawableCompat.setTintList(d, tintList); return d; }
From source file:com.cleveroad.audiowidget.AudioWidget.java
private Configuration prepareConfiguration(@NonNull Builder builder) { /*int darkColor = builder.darkColorSet ? builder.darkColor : ContextCompat.getColor(context, R.color.colorPrimary); int lightColor = builder.lightColorSet ? builder.lightColor : ContextCompat.getColor(context, R.color.colorAccent); int progressColor = builder.progressColorSet ? builder.progressColor : ContextCompat.getColor(context, R.color.colorPrimaryDarkTheme); int expandColor = builder.expandWidgetColorSet ? builder.expandWidgetColor : ContextCompat.getColor(context, R.color.colorPrimary); int crossColor = builder.crossColorSet ? builder.crossColor : ContextCompat.getColor(context, R.color.colorAccent); int crossOverlappedColor = builder.crossOverlappedColorSet ? builder.crossOverlappedColor : ContextCompat.getColor(context, R.color.colorPrimaryLight);*/ int shadowColor = builder.shadowColorSet ? builder.shadowColor : ContextCompat.getColor(context, R.color.shadowbg); Drawable playDrawable = builder.playDrawable != null ? builder.playDrawable : ContextCompat.getDrawable(context, R.drawable.aw_ic_play); Drawable pauseDrawable = builder.pauseDrawable != null ? builder.pauseDrawable : ContextCompat.getDrawable(context, R.drawable.aw_ic_pause); Drawable prevDrawable = builder.prevDrawable != null ? builder.prevDrawable : ContextCompat.getDrawable(context, R.drawable.aw_ic_prev); Drawable nextDrawable = builder.nextDrawable != null ? builder.nextDrawable : ContextCompat.getDrawable(context, R.drawable.aw_ic_next); Drawable playlistDrawable = builder.playlistDrawable != null ? builder.playlistDrawable : ContextCompat.getDrawable(context, R.mipmap.ic_launcher); Drawable albumDrawable = builder.defaultAlbumDrawable != null ? builder.defaultAlbumDrawable : ContextCompat.getDrawable(context, R.mipmap.ic_launcher); int buttonPadding = builder.buttonPaddingSet ? builder.buttonPadding : context.getResources().getDimensionPixelSize(R.dimen.aw_button_padding); float crossStrokeWidth = builder.crossStrokeWidthSet ? builder.crossStrokeWidth : context.getResources().getDimension(R.dimen.aw_cross_stroke_width); float progressStrokeWidth = builder.progressStrokeWidthSet ? builder.progressStrokeWidth : context.getResources().getDimension(R.dimen.aw_progress_stroke_width); float shadowRadius = builder.shadowRadiusSet ? builder.shadowRadius : context.getResources().getDimension(R.dimen.aw_shadow_radius); float shadowDx = builder.shadowDxSet ? builder.shadowDx : context.getResources().getDimension(R.dimen.aw_shadow_dx); float shadowDy = builder.shadowDySet ? builder.shadowDy : context.getResources().getDimension(R.dimen.aw_shadow_dy); float bubblesMinSize = builder.bubblesMinSizeSet ? builder.bubblesMinSize : context.getResources().getDimension(R.dimen.aw_bubbles_min_size); float bubblesMaxSize = builder.bubblesMaxSizeSet ? builder.bubblesMaxSize : context.getResources().getDimension(R.dimen.aw_bubbles_max_size); int prevNextExtraPadding = context.getResources() .getDimensionPixelSize(R.dimen.aw_prev_next_button_extra_padding); widgetHeight = context.getResources().getDimensionPixelSize(R.dimen.aw_player_height); widgetWidth = context.getResources().getDimensionPixelSize(R.dimen.aw_player_width); radius = widgetHeight / 2f;/*from w w w . j a v a 2 s.co m*/ playbackState = new PlaybackState(); ateKey = Helper.getATEKey(context); accentColor = Config.accentColor(context, ateKey); primaryColor = Config.primaryColor(context, ateKey); return new Configuration.Builder().context(context).playbackState(playbackState).random(new Random()) .accDecInterpolator(new AccelerateDecelerateInterpolator()).darkColor(primaryColor) .playColor(primaryColor).progressColor(accentColor).expandedColor(primaryColor) .widgetWidth(widgetWidth).radius(radius).playlistDrawable(playlistDrawable) .playDrawable(playDrawable).prevDrawable(prevDrawable).nextDrawable(nextDrawable) .pauseDrawable(pauseDrawable).albumDrawable(albumDrawable).buttonPadding(buttonPadding) .prevNextExtraPadding(prevNextExtraPadding).crossStrokeWidth(crossStrokeWidth) .progressStrokeWidth(progressStrokeWidth).shadowRadius(shadowRadius).shadowDx(shadowDx) .shadowDy(shadowDy).shadowColor(shadowColor).bubblesMinSize(bubblesMinSize) .bubblesMaxSize(bubblesMaxSize).crossColor(accentColor).crossOverlappedColor(accentColor).build(); }