List of usage examples for android.support.v4.content ContextCompat getDrawable
public static final Drawable getDrawable(Context context, int i)
From source file:com.amazon.android.uamp.ui.PlaybackOverlayFragment.java
private void addPlaybackControlsRow() { Log.d(TAG, "Show details ? " + SHOW_DETAIL); if (SHOW_DETAIL) { mPlaybackControlsRow = new PlaybackControlsRow(mSelectedContent); } else {/*from w w w . j av a 2 s .co m*/ mPlaybackControlsRow = new PlaybackControlsRow(); } mRowsAdapter.add(mPlaybackControlsRow); updatePlaybackRow(mCurrentItem); ControlButtonPresenterSelector presenterSelector = new ControlButtonPresenterSelector(); mPrimaryActionsAdapter = new ArrayObjectAdapter(presenterSelector); mSecondaryActionsAdapter = new ArrayObjectAdapter(presenterSelector); mPlaybackControlsRow.setPrimaryActionsAdapter(mPrimaryActionsAdapter); mPlaybackControlsRow.setSecondaryActionsAdapter(mSecondaryActionsAdapter); mPlayPauseAction = new PlayPauseAction(mContext); RepeatAction mRepeatAction = new RepeatAction(mContext); ThumbsUpAction mThumbsUpAction = new ThumbsUpAction(mContext); ThumbsDownAction mThumbsDownAction = new ThumbsDownAction(mContext); ShuffleAction mShuffleAction = new ShuffleAction(mContext); mSkipNextAction = new SkipNextAction(mContext); mSkipPreviousAction = new SkipPreviousAction(mContext); mFastForwardAction = new FastForwardAction(mContext); mRewindAction = new RewindAction(mContext); mClosedCaptioningAction = new PlaybackControlsRow.ClosedCaptioningAction(mContext); mCloseCaptionOnDrawable = ContextCompat.getDrawable(getActivity(), R.drawable.ic_closed_caption_on); mCloseCaptionOffDrawable = ContextCompat.getDrawable(getActivity(), R.drawable.ic_closed_caption_off); mCloseCaptionDisabledDrawable = ContextCompat.getDrawable(getActivity(), R.drawable.ic_closed_caption_disabled); if (PRIMARY_CONTROLS > 5) { mPrimaryActionsAdapter.add(mThumbsUpAction); } else { mSecondaryActionsAdapter.add(mThumbsUpAction); } mPrimaryActionsAdapter.add(mSkipPreviousAction); if (PRIMARY_CONTROLS > 3) { mPrimaryActionsAdapter.add(new RewindAction(mContext)); } mPrimaryActionsAdapter.add(mPlayPauseAction); if (PRIMARY_CONTROLS > 3) { mPrimaryActionsAdapter.add(new FastForwardAction(mContext)); } mPrimaryActionsAdapter.add(mSkipNextAction); // Adding closed caption action button. mPrimaryActionsAdapter.add(mClosedCaptioningAction); // Disable CC button initially. updateCCButtonState(false, false); mSecondaryActionsAdapter.add(mRepeatAction); mSecondaryActionsAdapter.add(mShuffleAction); if (PRIMARY_CONTROLS > 5) { mPrimaryActionsAdapter.add(mThumbsDownAction); } else { mSecondaryActionsAdapter.add(mThumbsDownAction); } mSecondaryActionsAdapter.add(new PlaybackControlsRow.HighQualityAction(mContext)); }
From source file:com.esri.arcgis.android.samples.nearby.Nearby.java
public void updateContent(Map<String, Object> attributes) { // This is called from UI thread (MapTap listener) String title = attributes.get(getResources().getString(R.string.result_title)).toString(); mTitleTextView.setText(title);// ww w . j a va 2 s. co m String address = attributes.get(getResources().getString(R.string.result_address)).toString(); mAddressTextView.setText(address); String distance = attributes.get(getResources().getString(R.string.result_distance)).toString(); double meters = Double.parseDouble(distance); if (meters > 0) { if (mDistanceTextView.getVisibility() != View.VISIBLE) { mDistanceTextView.setVisibility(View.VISIBLE); } double miles = mMilesUnit.convertFromMeters(meters); mDistanceTextView.setText(String.format("%.2f %s", miles, getResources().getString(R.string.miles))); } else { mDistanceTextView.setVisibility(View.GONE); } String phone = attributes.get(getResources().getString(R.string.result_phone)).toString(); mPhoneTextView.setText(phone); mPhoneImageView .setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_action_call)); Float rating = Float.parseFloat(getRating()); mRatingBar.setRating(rating); mRatingBar.setVisibility(View.VISIBLE); }
From source file:com.google.android.apps.santatracker.doodles.tilt.SwimmingFragment.java
@Nullable private Drawable getShareImageDrawable(String collidedObjectType) { return ContextCompat.getDrawable(getActivity(), R.drawable.winner); }
From source file:com.appolica.interactiveinfowindow.InfoWindowManager.java
/** * Generate default {@link ContainerSpecification} for the container view. * * @param context used to work with Resources. * * @return New instance of the generated default container specs. *//*from w w w . j ava 2 s . c o m*/ public ContainerSpecification generateDefaultContainerSpecs(Context context) { final Drawable drawable = ContextCompat.getDrawable(context, R.drawable.infowindow_background); return new ContainerSpecification(drawable); }
From source file:com.android.settings.accessibility.AccessibilitySettings.java
private void updateServicePreferences() { // Since services category is auto generated we have to do a pass // to generate it since services can come and go and then based on // the global accessibility state to decided whether it is enabled. // Generate./*from www . j av a 2 s .co m*/ ArrayList<Preference> servicePreferences = new ArrayList<>( mServicePreferenceToPreferenceCategoryMap.keySet()); for (int i = 0; i < servicePreferences.size(); i++) { Preference service = servicePreferences.get(i); PreferenceCategory category = mServicePreferenceToPreferenceCategoryMap.get(service); category.removePreference(service); } initializePreBundledServicesMapFromArray(CATEGORY_SCREEN_READER, R.array.config_preinstalled_screen_reader_services); initializePreBundledServicesMapFromArray(CATEGORY_AUDIO_AND_CAPTIONS, R.array.config_preinstalled_audio_and_caption_services); initializePreBundledServicesMapFromArray(CATEGORY_DISPLAY, R.array.config_preinstalled_display_services); initializePreBundledServicesMapFromArray(CATEGORY_INTERACTION_CONTROL, R.array.config_preinstalled_interaction_control_services); AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(getActivity()); List<AccessibilityServiceInfo> installedServices = accessibilityManager .getInstalledAccessibilityServiceList(); Set<ComponentName> enabledServices = AccessibilityUtils.getEnabledServicesFromSettings(getActivity()); List<String> permittedServices = mDpm.getPermittedAccessibilityServices(UserHandle.myUserId()); final boolean accessibilityEnabled = Settings.Secure.getInt(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1; PreferenceCategory downloadedServicesCategory = mCategoryToPrefCategoryMap .get(CATEGORY_DOWNLOADED_SERVICES); // Temporarily add the downloaded services category back if it was previously removed. if (findPreference(CATEGORY_DOWNLOADED_SERVICES) == null) { getPreferenceScreen().addPreference(downloadedServicesCategory); } for (int i = 0, count = installedServices.size(); i < count; ++i) { AccessibilityServiceInfo info = installedServices.get(i); RestrictedPreference preference = new RestrictedPreference(downloadedServicesCategory.getContext()); String title = info.getResolveInfo().loadLabel(getPackageManager()).toString(); Drawable icon; if (info.getResolveInfo().getIconResource() == 0) { icon = ContextCompat.getDrawable(getContext(), R.mipmap.ic_accessibility_generic); } else { icon = info.getResolveInfo().loadIcon(getPackageManager()); } ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo; String packageName = serviceInfo.packageName; ComponentName componentName = new ComponentName(packageName, serviceInfo.name); String componentNameKey = componentName.flattenToString(); preference.setKey(componentName.flattenToString()); preference.setTitle(title); preference.setIcon(icon); final boolean serviceEnabled = accessibilityEnabled && enabledServices.contains(componentName); final String serviceState = serviceEnabled ? getString(R.string.accessibility_summary_state_enabled) : getString(R.string.accessibility_summary_state_disabled); final CharSequence serviceSummary = info.loadSummary(getPackageManager()); final String stateSummaryCombo = getString(R.string.accessibility_summary_default_combination, serviceState, serviceSummary); preference.setSummary((TextUtils.isEmpty(serviceSummary)) ? serviceState : stateSummaryCombo); // Disable all accessibility services that are not permitted. boolean serviceAllowed = permittedServices == null || permittedServices.contains(packageName); if (!serviceAllowed && !serviceEnabled) { EnforcedAdmin admin = RestrictedLockUtils.checkIfAccessibilityServiceDisallowed(getActivity(), packageName, UserHandle.myUserId()); if (admin != null) { preference.setDisabledByAdmin(admin); } else { preference.setEnabled(false); } } else { preference.setEnabled(true); } preference.setFragment(ToggleAccessibilityServicePreferenceFragment.class.getName()); preference.setPersistent(true); Bundle extras = preference.getExtras(); extras.putString(EXTRA_PREFERENCE_KEY, preference.getKey()); extras.putBoolean(EXTRA_CHECKED, serviceEnabled); extras.putString(EXTRA_TITLE, title); String description = info.loadDescription(getPackageManager()); if (TextUtils.isEmpty(description)) { description = getString(R.string.accessibility_service_default_description); } extras.putString(EXTRA_SUMMARY, description); String settingsClassName = info.getSettingsActivityName(); if (!TextUtils.isEmpty(settingsClassName)) { extras.putString(EXTRA_SETTINGS_TITLE, getString(R.string.accessibility_menu_item_settings)); extras.putString(EXTRA_SETTINGS_COMPONENT_NAME, new ComponentName(packageName, settingsClassName).flattenToString()); } extras.putParcelable(EXTRA_COMPONENT_NAME, componentName); PreferenceCategory prefCategory = downloadedServicesCategory; // Set the appropriate category if the service comes pre-installed. if (mPreBundledServiceComponentToCategoryMap.containsKey(componentName)) { prefCategory = mPreBundledServiceComponentToCategoryMap.get(componentName); } preference.setOrder(FIRST_PREFERENCE_IN_CATEGORY_INDEX); prefCategory.addPreference(preference); mServicePreferenceToPreferenceCategoryMap.put(preference, prefCategory); } // If the user has not installed any additional services, hide the category. if (downloadedServicesCategory.getPreferenceCount() == 0) { PreferenceScreen screen = getPreferenceScreen(); screen.removePreference(downloadedServicesCategory); } }
From source file:com.jaguarlandrover.hvacdemo.MainActivity.java
@Override public void onNodeConnected() { mMenu.getItem(0).setIcon(ContextCompat.getDrawable(this, R.drawable.connected_car)); Toast.makeText(MainActivity.this, "Vehicle connected", Toast.LENGTH_SHORT).show(); }
From source file:com.jaguarlandrover.hvacdemo.MainActivity.java
@Override public void onNodeDisconnected() { mMenu.getItem(0).setIcon(ContextCompat.getDrawable(this, R.drawable.disconnected_car)); Toast.makeText(MainActivity.this, "Vehicle disconnected", Toast.LENGTH_SHORT).show(); }
From source file:com.justwayward.reader.ui.activity.ReadActivity.java
private void changedMode(boolean isNight, int position) { SharedPreferencesUtil.getInstance().putBoolean(Constant.ISNIGHT, isNight); AppCompatDelegate/*from ww w.ja va2 s .c o m*/ .setDefaultNightMode(isNight ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO); if (position >= 0) { curTheme = position; } else { curTheme = SettingManager.getInstance().getReadTheme(); } gvAdapter.select(curTheme); mPageWidget.setTheme(isNight ? ThemeManager.NIGHT : curTheme); mPageWidget.setTextColor( ContextCompat.getColor(mContext, isNight ? R.color.chapter_content_night : R.color.chapter_content_day), ContextCompat.getColor(mContext, isNight ? R.color.chapter_title_night : R.color.chapter_title_day)); mTvBookReadMode.setText(getString(isNight ? R.string.book_read_mode_day_manual_setting : R.string.book_read_mode_night_manual_setting)); Drawable drawable = ContextCompat.getDrawable(this, isNight ? R.drawable.ic_menu_mode_day_manual : R.drawable.ic_menu_mode_night_manual); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); mTvBookReadMode.setCompoundDrawables(null, drawable, null, null); ThemeManager.setReaderTheme(curTheme, mRlBookReadRoot); }
From source file:com.example.view.wheel.WheelView.java
/** * Initializes resources//from w w w .j a v a 2 s.c o m */ private void initResourcesIfNecessary() { if (itemsPaint == null) { itemsPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG); //itemsPaint.density = getResources().getDisplayMetrics().density; itemsPaint.setTextSize(BaseUtil.dp2px(context, TEXT_SIZE)); } if (valuePaint == null) { valuePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG | Paint.DITHER_FLAG); //valuePaint.density = getResources().getDisplayMetrics().density; valuePaint.setTextSize(BaseUtil.dp2px(context, TEXT_SIZE)); valuePaint.setColor(Color.BLUE); // valuePaint.setShadowLayer(0.1f, 0, 0.1f, 0xFFC0C0C0); } if (linePaint == null) { linePaint = new Paint(); linePaint.setColor(Color.parseColor("#FF6D4B")); linePaint.setStrokeWidth(10.0F); } if (centerDrawable == null) { centerDrawable = ContextCompat.getDrawable(context, R.drawable.wheel_val); } if (topShadow == null) { topShadow = new GradientDrawable(Orientation.TOP_BOTTOM, SHADOWS_COLORS); } if (bottomShadow == null) { bottomShadow = new GradientDrawable(Orientation.BOTTOM_TOP, SHADOWS_COLORS); } //setBackgroundResource(R.drawable.wheel_bg); setBackgroundColor(Color.WHITE); }
From source file:android.support.v7.preference.Preference.java
/** * Binds the created View to the data for this Preference. * <p>//from w w w . j av a2 s . co m * This is a good place to grab references to custom Views in the layout and * set properties on them. * <p> * Make sure to call through to the superclass's implementation. * * @param holder The ViewHolder that provides references to the views to fill in. These views * will be recycled, so you should not hold a reference to them after this method * returns. */ public void onBindViewHolder(PreferenceViewHolder holder) { holder.itemView.setOnClickListener(mClickListener); holder.itemView.setId(mViewId); final TextView titleView = (TextView) holder.findViewById(android.R.id.title); if (titleView != null) { final CharSequence title = getTitle(); if (!TextUtils.isEmpty(title)) { titleView.setText(title); titleView.setVisibility(View.VISIBLE); } else { titleView.setVisibility(View.GONE); } } final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary); if (summaryView != null) { final CharSequence summary = getSummary(); if (!TextUtils.isEmpty(summary)) { summaryView.setText(summary); summaryView.setVisibility(View.VISIBLE); } else { summaryView.setVisibility(View.GONE); } } final ImageView imageView = (ImageView) holder.findViewById(android.R.id.icon); if (imageView != null) { if (mIconResId != 0 || mIcon != null) { if (mIcon == null) { mIcon = ContextCompat.getDrawable(getContext(), mIconResId); } if (mIcon != null) { imageView.setImageDrawable(mIcon); } } imageView.setVisibility(mIcon != null ? View.VISIBLE : View.GONE); } View imageFrame = holder.findViewById(R.id.icon_frame); if (imageFrame == null) { imageFrame = holder.findViewById(AndroidResources.ANDROID_R_ICON_FRAME); } if (imageFrame != null) { imageFrame.setVisibility(mIcon != null ? View.VISIBLE : View.GONE); } if (mShouldDisableView) { setEnabledStateOnViews(holder.itemView, isEnabled()); } else { setEnabledStateOnViews(holder.itemView, true); } final boolean selectable = isSelectable(); holder.itemView.setFocusable(selectable); holder.itemView.setClickable(selectable); holder.setDividerAllowedAbove(selectable); holder.setDividerAllowedBelow(selectable); }