List of usage examples for android.content.res Resources getDrawable
@Deprecated public Drawable getDrawable(@DrawableRes int id) throws NotFoundException
From source file:com.example.android.leanback.NewDetailsFragment.java
public void setItem(PhotoItem photoItem) { mPhotoItem = photoItem;/* ww w . ja va2 s . c om*/ mRowsAdapter.clear(); new Handler().postDelayed(new Runnable() { public void run() { if (TEST_OVERVIEW_ROW_ON_SECOND) { ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter); listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1)); listRowAdapter.add(new PhotoItem("This is a test", R.drawable.gallery_photo_2)); listRowAdapter.add(new PhotoItem("Android TV", R.drawable.gallery_photo_3)); listRowAdapter.add(new PhotoItem("Leanback", R.drawable.gallery_photo_4)); HeaderItem header = new HeaderItem(0, "Search Result"); mRowsAdapter.add(0, new ListRow(header, listRowAdapter)); } Resources res = getActivity().getResources(); DetailsOverviewRow dor = new DetailsOverviewRow(mPhotoItem.getTitle()); dor.setImageDrawable(res.getDrawable(mPhotoItem.getImageResourceId())); SparseArrayObjectAdapter adapter = new SparseArrayObjectAdapter(); adapter.set(ACTION_RENT, mActionRent); adapter.set(ACTION_BUY, mActionBuy); dor.setActionsAdapter(adapter); int indexOfOverviewRow = TEST_OVERVIEW_ROW_ON_SECOND ? 1 : 0; mRowsAdapter.add(indexOfOverviewRow, dor); setSelectedPosition(0, true); if (TEST_SHARED_ELEMENT_TRANSITION) { if (mHelper != null && !mHelper.getAutoStartSharedElementTransition()) { mHelper.startPostponedEnterTransition(); } } } }, TIME_TO_LOAD_OVERVIEW_ROW_MS); new Handler().postDelayed(new Runnable() { public void run() { for (int i = 0; i < NUM_ROWS; ++i) { ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter); listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1)); listRowAdapter.add(new PhotoItem("This is a test", R.drawable.gallery_photo_2)); listRowAdapter.add(new PhotoItem("Android TV", R.drawable.gallery_photo_3)); listRowAdapter.add(new PhotoItem("Leanback", R.drawable.gallery_photo_4)); HeaderItem header = new HeaderItem(i, "Row " + i); mRowsAdapter.add(new ListRow(header, listRowAdapter)); } if (TEST_ENTRANCE_TRANSITION) { startEntranceTransition(); } } }, TIME_TO_LOAD_RELATED_ROWS_MS); setAdapter(mRowsAdapter); }
From source file:org.smssecure.smssecure.preferences.ColorPreference.java
private static void setColorViewValue(View view, int color, boolean selected) { if (view instanceof ImageView) { ImageView imageView = (ImageView) view; Resources res = imageView.getContext().getResources(); Drawable currentDrawable = imageView.getDrawable(); GradientDrawable colorChoiceDrawable; if (currentDrawable instanceof GradientDrawable) { // Reuse drawable colorChoiceDrawable = (GradientDrawable) currentDrawable; } else {/*from www. j a v a2 s . c o m*/ colorChoiceDrawable = new GradientDrawable(); colorChoiceDrawable.setShape(GradientDrawable.OVAL); } // Set stroke to dark version of color // int darkenedColor = Color.rgb( // Color.red(color) * 192 / 256, // Color.green(color) * 192 / 256, // Color.blue(color) * 192 / 256); colorChoiceDrawable.setColor(color); // colorChoiceDrawable.setStroke((int) TypedValue.applyDimension( // TypedValue.COMPLEX_UNIT_DIP, 2, res.getDisplayMetrics()), darkenedColor); Drawable drawable = colorChoiceDrawable; if (selected) { BitmapDrawable checkmark = (BitmapDrawable) res.getDrawable(R.drawable.check); checkmark.setGravity(Gravity.CENTER); drawable = new LayerDrawable(new Drawable[] { colorChoiceDrawable, checkmark }); } imageView.setImageDrawable(drawable); } else if (view instanceof TextView) { ((TextView) view).setTextColor(color); } }
From source file:com.tingtingapps.securesms.preferences.ColorPreference.java
private static void setColorViewValue(View view, int color, boolean selected) { if (view instanceof ImageView) { ImageView imageView = (ImageView) view; Resources res = imageView.getContext().getResources(); Drawable currentDrawable = imageView.getDrawable(); GradientDrawable colorChoiceDrawable; if (currentDrawable instanceof GradientDrawable) { // Reuse drawable colorChoiceDrawable = (GradientDrawable) currentDrawable; } else {//from ww w . jav a 2 s.co m colorChoiceDrawable = new GradientDrawable(); colorChoiceDrawable.setShape(GradientDrawable.OVAL); } // Set stroke to dark version of color // int darkenedColor = Color.rgb( // Color.red(color) * 192 / 256, // Color.green(color) * 192 / 256, // Color.blue(color) * 192 / 256); colorChoiceDrawable.setColor(color); // colorChoiceDrawable.setStroke((int) TypedValue.applyDimension( // TypedValue.COMPLEX_UNIT_DIP, 2, res.getDisplayMetrics()), darkenedColor); Drawable drawable = colorChoiceDrawable; if (selected) { BitmapDrawable checkmark = (BitmapDrawable) res .getDrawable(com.tingtingapps.securesms.R.drawable.check); checkmark.setGravity(Gravity.CENTER); drawable = new LayerDrawable(new Drawable[] { colorChoiceDrawable, checkmark }); } imageView.setImageDrawable(drawable); } else if (view instanceof TextView) { ((TextView) view).setTextColor(color); } }
From source file:com.cyou.cma.clockscreen.widget.LinePageIndicator.java
public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;/*from w w w .jav a 2s . co m*/ final Resources res = getResources(); mDrawableUnselected = res.getDrawable(R.drawable.indicator_normal); mDrawableSelected = res.getDrawable(R.drawable.indicator_selected); // Load defaults from resources final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color); final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color); final float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width); final float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width); final float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width); final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered); // Retrieve styles attributes // TypedArray a = context.obtainStyledAttributes(attrs, // R.styleable.LinePageIndicator, defStyle, 0); mCentered = defaultCentered; mLineWidth = defaultLineWidth; mGapWidth = defaultGapWidth; setStrokeWidth(defaultStrokeWidth); mPaintUnselected.setColor(defaultUnselectedColor); mPaintSelected.setColor(defaultSelectedColor); // Drawable background = a // .getDrawable(R.styleable.LinePageIndicator_android_background); // if (background != null) { // setBackgroundDrawable(background); // } // a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:com.fastbootmobile.encore.app.tv.TvArtistDetailsFragment.java
private void setupDetailsOverviewRow() { final Resources res = getResources(); final DetailsOverviewRow row = new DetailsOverviewRow(mArtist); row.setImageDrawable(res.getDrawable(R.drawable.album_placeholder)); SparseArrayObjectAdapter actionsAdapter = new SparseArrayObjectAdapter(); actionsAdapter.set(ACTION_START_RADIO, mActionStartRadio); row.setActionsAdapter(actionsAdapter); mAdapter.add(row);//from w ww . jav a 2 s . c o m mArtTask = AlbumArtHelper.retrieveAlbumArt(getResources(), new AlbumArtHelper.AlbumArtListener() { @Override public void onArtLoaded(RecyclingBitmapDrawable output, BoundEntity request) { if (output != null) { row.setImageDrawable(output); updateAdapter(); } } }, mArtist, DETAIL_THUMB_WIDTH, false); }
From source file:com.android.mail.browse.SubjectAndFolderView.java
public SubjectAndFolderView(Context context, AttributeSet attrs) { super(context, attrs); final Resources res = getResources(); mNoFolderChipName = res.getString(R.string.add_label); mNoFolderBgColor = res.getColor(R.color.conv_header_add_label_background); mNoFolderFgColor = res.getColor(R.color.conv_header_add_label_text); mImportanceMarkerDrawable = res.getDrawable(R.drawable.ic_email_caret_none_important_unread); mImportanceMarkerDrawable.setBounds(0, 0, mImportanceMarkerDrawable.getIntrinsicWidth(), mImportanceMarkerDrawable.getIntrinsicHeight()); mChipVerticalOffset = res.getDimensionPixelOffset(R.dimen.folder_cv_vertical_offset); mVisibleFolders = false;/*from w w w. j a va 2 s .c o m*/ mFolderDisplayer = new ConversationFolderDisplayer(getContext()); }
From source file:ubc.cs.cpsc210.sustainabilityapp.UBCSustainabilityAppActivity.java
/** * Set up tabs//from w w w .j a v a2s .c o m * * @param res the application's resources */ private void setupTabs(Resources res) { mTabManager = new TabManager(this, mTabHost, R.id.realtabcontent); mTabManager.addTab(mTabHost.newTabSpec(POI).setIndicator("POIs", res.getDrawable(R.drawable.ic_tab_poi)), POIFragment.class, null); mTabManager.addTab( mTabHost.newTabSpec(FEATURE).setIndicator("Features", res.getDrawable(R.drawable.ic_tab_feature)), FeatureFragment.class, null); // add MapDisplayFragment to tabs only in portrait mode if (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { Fragment mapFragment = getSupportFragmentManager().findFragmentByTag(MAP); if (mapFragment != null) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.remove(mapFragment); ft.commit(); getSupportFragmentManager().executePendingTransactions(); mTabManager.addTab( mTabHost.newTabSpec(MAP).setIndicator("Map", res.getDrawable(R.drawable.ic_tab_map)), mapFragment, null); } else mTabManager.addTab( mTabHost.newTabSpec(MAP).setIndicator("Map", res.getDrawable(R.drawable.ic_tab_map)), MapDisplayFragment.class, null); } }
From source file:com.google.wolff.androidhunt.Hunt.java
/** Return value: Whether or not it needs to load from web. */ public void setClueImage(Resources res, ImageView imgView) { final Clue clue = getCurrentClue(); if (hrm.drawables.get(clue.displayImage) == null) { imgView.setImageDrawable(res.getDrawable(R.drawable.ab_icon)); } else {/*from w ww . java 2 s .co m*/ imgView.setImageDrawable(hrm.drawables.get(clue.displayImage)); } }
From source file:jp.ac.anan_nct.TabletInterphone.Fragment.VisiterInteractionFragment.java
private void changeMike(View view, boolean boo) { Resources r = getResources(); Drawable mike;/*from ww w . j ava2s . c o m*/ if (boo) { mike = r.getDrawable(R.drawable.microphone_on); } else { mike = r.getDrawable(R.drawable.microphone_off); } ImageView mikeImg = (ImageView) view.findViewById(R.id.mike); mikeImg.setImageDrawable(mike); }
From source file:net.evecom.androidecssp.gps.EventItemizedOverlayActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); /** 2.1 ***//* ww w . jav a 2 s . co m*/ // LayoutInflater inflater = LayoutInflater.from(this); // // // View mViewLayout = inflater.inflate(R.layout.itemized, null); // setContentView(mViewLayout); /** 2.1 ***/ /** 2.2 ***/ setContentView(R.layout.itemized); /** 2.2 ***/ initData(); mMapView = (MapView) findViewById(R.id.itemized_mapview); mMapView.setBuiltInZoomControls(true); // Overlay // mMapView.setDrawOverlayWhenZooming(true); mController = mMapView.getController(); mCon = this; // List<Overlay> list = mMapView.getOverlays(); myLocation = new MyLocationOverlay(this, mMapView); myLocation.enableCompass(); myLocation.enableMyLocation(); list.add(myLocation); // Resources res = getResources(); Drawable marker = res.getDrawable(R.drawable.poiresult_sel);// EventOverItem mOverlay = new EventOverItem(marker, this); eventP = new GeoPoint((int) (eventGpsPoints.getGisy() * 1E6), (int) (eventGpsPoints.getGisx() * 1E6)); mOverlay.addItem(new OverlayItem(eventP, eventGpsPoints.getName(), eventGpsPoints.getDescription())); list.add(mOverlay); mPopView = super.getLayoutInflater().inflate(R.layout.popview_event, null); mText = (TextView) mPopView.findViewById(R.id.text); mMapView.addView(mPopView, new MapView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, eventP, MapView.LayoutParams.BOTTOM_CENTER)); EventItemizedOverlayActivity.mText.setText(eventGpsPoints.getName()); mController.animateTo( new GeoPoint((int) (eventGpsPoints.getGisy() * 1E6), (int) (eventGpsPoints.getGisx() * 1E6))); // initAroundDialog(); initOtherView(); }