List of usage examples for android.content.res Resources getDrawable
@Deprecated public Drawable getDrawable(@DrawableRes int id) throws NotFoundException
From source file:com.zia.freshdocs.widget.adapter.CMISAdapter.java
protected Drawable getDrawableForType(String contentType) { Context context = getContext(); Resources resources = context.getResources(); int resId = Constants.mimeMap.get(Constants.mimeMap.containsKey(contentType) ? contentType : null); Drawable icon = resources.getDrawable(resId); icon.setBounds(new Rect(0, 0, 44, 44)); return icon;/*from www . j a va 2 s. c o m*/ }
From source file:com.commonsware.android.EMusicDownloader.SingleBook.java
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); setContentView(R.layout.singlebook); nameTextView = (TextView) findViewById(R.id.tname); authorTextView = (TextView) findViewById(R.id.tauthor); editionTextView = (TextView) findViewById(R.id.tedition); genreTextView = (TextView) findViewById(R.id.tgenre); bioBlurb = (WebView) findViewById(R.id.blurb); ratingBar = (RatingBar) findViewById(R.id.rbar); albumArt = (ImageView) findViewById(R.id.albumart); bioBlurb.setBackgroundColor(0);// w w w . j a v a2 s .c o m authorLayout = (LinearLayout) findViewById(R.id.llauthor); Resources res = getResources(); if (version < 11) { authorLayout.setBackgroundDrawable(res.getDrawable(android.R.drawable.list_selector_background)); } else { authorLayout.setBackgroundResource(R.drawable.list_selector_holo_dark); } authorLayout.setFocusable(true); if (vLoaded) { handlerSetContent.sendEmptyMessage(0); if (vArtExists) { albumArt.setImageBitmap(albumArtBitmap); } else { albumArt.setImageResource(R.drawable.noalbum); ; } } }
From source file:com.commonsware.android.EMusicDownloader.SingleBook.java
/** Called when the activity is first created. */ @Override//from w w w . j a v a 2 s .c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.singlebook); Intent myIntent = getIntent(); albumId = myIntent.getStringExtra("keyalbumid"); emusicURL = myIntent.getStringExtra("keyexturl"); album = myIntent.getStringExtra("keyalbum"); artist = myIntent.getStringExtra("keyartist"); thisActivity = this; nameTextView = (TextView) findViewById(R.id.tname); authorTextView = (TextView) findViewById(R.id.tauthor); editionTextView = (TextView) findViewById(R.id.tedition); genreTextView = (TextView) findViewById(R.id.tgenre); bioBlurb = (WebView) findViewById(R.id.blurb); ratingBar = (RatingBar) findViewById(R.id.rbar); albumArt = (ImageView) findViewById(R.id.albumart); authorLayout = (LinearLayout) findViewById(R.id.llauthor); version = android.os.Build.VERSION.SDK_INT; Resources res = getResources(); if (version < 11) { authorLayout.setBackgroundDrawable(res.getDrawable(android.R.drawable.list_selector_background)); } else { authorLayout.setBackgroundResource(R.drawable.list_selector_holo_dark); } authorLayout.setFocusable(true); bioBlurb.setBackgroundColor(0); urlAddress = "http://api.emusic.com/book/info?" + Secrets.apikey + "&bookId=" + albumId + "&include=bookEditorial,bookRating&&imageSize=small"; Log.d("EMD - ", urlAddress); getInfoFromXML(); }
From source file:com.example.android.snake.SnakeView.java
private void initSnakeView() { setFocusable(true);//from ww w . j a v a 2s .co m Resources r = this.getContext().getResources(); resetTiles(4); loadTile(RED_STAR, r.getDrawable(R.drawable.redstar)); loadTile(YELLOW_STAR, r.getDrawable(R.drawable.yellowstar)); loadTile(GREEN_STAR, r.getDrawable(R.drawable.greenstar)); gameThread = new GameThread(this); holder = getHolder(); holder.addCallback(new SurfaceHolder.Callback() { @Override public void surfaceDestroyed(SurfaceHolder holder) { boolean retry = true; gameThread.setRunning(false); while (retry) { try { gameThread.join(); retry = false; } catch (InterruptedException e) { } } } @Override public void surfaceCreated(SurfaceHolder holder) { if (isPaused) resume(); gameThread.setRunning(true); setWillNotDraw(false); gameThread.start(); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } }); }
From source file:com.cssweb.android.quote.QHSCGridActivity.java
private void AddViewItem(int paramInt1, LinearLayout paramLinearLayout, int paramInt2, int paramInt3, int paramInt4, boolean paramBoolean) { TextView localTextView = new TextView(this); float f = this.mFontSize; localTextView.setTextSize(f);//w w w.ja va2 s.co m localTextView.setGravity(Gravity.CENTER); localTextView.setFocusable(paramBoolean); localTextView.setOnClickListener(mClickListener); localTextView.setOnLongClickListener(mLongClickListener); localTextView.setOnTouchListener(this); // touch localTextView.setTag(paramInt2); localTextView.setEnabled(paramBoolean); localTextView.setSingleLine(true); Resources localResources = getResources(); Drawable localDrawable = null; if (paramInt4 == 0 && paramInt3 >= 0) {// int i1 = this.residTitleCol; int i8 = 0; localTextView.setTextColor(paramInt1); if (paramInt3 == 0) { localDrawable = localResources.getDrawable(i1); i8 = localDrawable.getIntrinsicWidth(); } else if (paramInt3 == 100) { localDrawable = localResources.getDrawable(this.residTitleScrollCol[2]); i8 = localDrawable.getIntrinsicWidth(); i8 += 20; } else if (paramInt3 == 13) { localDrawable = localResources.getDrawable(this.residTitleScrollCol[0]); i8 = localDrawable.getIntrinsicWidth(); } else if (paramInt3 % 2 == 0) { localDrawable = localResources.getDrawable(this.residTitleScrollCol[1]); i8 = localDrawable.getIntrinsicWidth(); } else { localDrawable = localResources.getDrawable(this.residTitleScrollCol[0]); i8 = localDrawable.getIntrinsicWidth(); } localTextView.setBackgroundDrawable(localDrawable); int i6 = localDrawable.getIntrinsicHeight(); localTextView.setHeight(i6 + CssSystem.getTableTitleHeight(this)); localTextView.setWidth(i8); paramLinearLayout.addView(localTextView); return; } if (paramInt4 != 0 && paramInt3 >= 0) { int i8 = 0; localTextView.setTextColor(paramInt1); if (paramInt3 == 0) { localDrawable = localResources.getDrawable(this.residCol); i8 = localDrawable.getIntrinsicWidth(); } else if (paramInt3 == 100) { localDrawable = localResources.getDrawable(this.residScrollCol[2]); localTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); i8 = localDrawable.getIntrinsicWidth(); i8 += 20; } else if (paramInt3 == 13) { localDrawable = localResources.getDrawable(this.residScrollCol[0]); localTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); i8 = localDrawable.getIntrinsicWidth(); } else if (paramInt3 % 2 == 0) { localDrawable = localResources.getDrawable(this.residScrollCol[1]); localTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); i8 = localDrawable.getIntrinsicWidth(); } else { localDrawable = localResources.getDrawable(this.residScrollCol[0]); localTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); i8 = localDrawable.getIntrinsicWidth(); } localTextView.setBackgroundDrawable(localDrawable); int i6 = localDrawable.getIntrinsicHeight(); localTextView.setHeight(i6 + rowHeight); localTextView.setWidth(i8); paramLinearLayout.addView(localTextView); return; } }
From source file:edu.nd.darts.cimon.NDroidAdmin.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.administrator); // Toast.makeText(getBaseContext(), "This is", // Toast.LENGTH_LONG).show(); startService(new Intent(this, NDroidService.class)); Resources res = getResources(); // Resource object to get Drawables TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; // Reusable TabSpec for each tab Intent intent; // Reusable Intent for each tab // Create an Intent to launch an Activity for the tab (to be reused) // intent = new Intent().setClass(this, NDroidSystem.class); intent = new Intent().setClass(this, CimonListView.class); intent.putExtra("key", Metrics.TYPE_SYSTEM); // Initialize a TabSpec for each tab and add it to the TabHost spec = tabHost.newTabSpec("system").setIndicator("System", res.getDrawable(R.drawable.icon_system)) .setContent(intent);//from w ww . j av a2 s .co m tabHost.addTab(spec); // Do the same for the other tabs // intent = new Intent().setClass(this, NDroidSensor.class); intent = new Intent().setClass(this, CimonListView.class); intent.putExtra("key", Metrics.TYPE_SENSOR); spec = tabHost.newTabSpec("sensors").setIndicator("Sensors", res.getDrawable(R.drawable.icon_sensor)) .setContent(intent); tabHost.addTab(spec); // intent = new Intent().setClass(this, NDroidUser.class); intent = new Intent().setClass(this, CimonListView.class); intent.putExtra("key", Metrics.TYPE_USER); spec = tabHost.newTabSpec("user").setIndicator("User Activity", res.getDrawable(R.drawable.icon_user)) .setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTab(0); SharedPreferences appPrefs = getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE); int storedVersion = appPrefs.getInt(PREF_VERSION, -1); int appVersion = -1; try { appVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (DebugLog.DEBUG) Log.d(TAG, "NDroidAdmin.onCreate - appVersion:" + appVersion + " storedVersion:" + storedVersion); if (appVersion > storedVersion) { new Thread(new Runnable() { public void run() { List<MetricService<?>> serviceList; serviceList = MetricService.getServices(Metrics.TYPE_SYSTEM); for (MetricService<?> mService : serviceList) { mService.insertDatabaseEntries(); } serviceList.clear(); serviceList = MetricService.getServices(Metrics.TYPE_SENSOR); for (MetricService<?> mService : serviceList) { mService.insertDatabaseEntries(); } serviceList.clear(); serviceList = MetricService.getServices(Metrics.TYPE_USER); for (MetricService<?> mService : serviceList) { mService.insertDatabaseEntries(); } serviceList.clear(); } }).start(); SharedPreferences.Editor editor = appPrefs.edit(); editor.putInt(PREF_VERSION, appVersion); editor.commit(); } }
From source file:org.appcelerator.titanium.view.TiDrawableReference.java
private Drawable getResourceDrawable() { if (!isTypeResourceId()) { return null; }//ww w.j a v a2 s .com Drawable drawable = null; Resources resources = getResources(); if (resources != null && resourceId > 0) { try { drawable = resources.getDrawable(resourceId); } catch (Resources.NotFoundException e) { drawable = null; } } return drawable; }
From source file:com.sbgapps.scoreit.ui.ScoreItActivity.java
private void setActionButtonColor() { Resources res = getResources(); if (null == mLap) { mActionButton.setImageDrawable(res.getDrawable(R.drawable.ic_content_create)); mActionButton.setColorNormal(res.getColor(R.color.color_accent)); mActionButton.setColorPressed(res.getColor(R.color.color_accent_dark)); mActionButton.setColorRipple(res.getColor(R.color.gray_light)); } else {//from ww w. j av a 2 s . c o m mActionButton.setImageDrawable(res.getDrawable(R.drawable.ic_action_done)); mActionButton.setColorNormal(res.getColor(R.color.color_primary)); mActionButton.setColorPressed(res.getColor(R.color.color_primary_dark)); mActionButton.setColorRipple(res.getColor(R.color.gray_light)); } }
From source file:website.openeng.anki.StudyOptionsFragment.java
/** * Special method to show the context menu for the custom study options * TODO: Turn this into a DialogFragment *//*from w ww. ja v a2 s .c om*/ private void showCustomStudyContextMenu() { Resources res = getResources(); Drawable icon = res.getDrawable(R.drawable.ic_sort_black_36dp); icon.setAlpha(Themes.ALPHA_ICON_ENABLED_DARK); MaterialDialog dialog = new MaterialDialog.Builder(this.getActivity()) .title(res.getString(R.string.custom_study)).icon(icon).cancelable(true) .items(res.getStringArray(R.array.custom_study_options_labels)) .itemsCallback(new MaterialDialog.ListCallback() { @Override public void onSelection(MaterialDialog materialDialog, View view, int which, CharSequence charSequence) { DialogFragment dialogFragment; if (which == CustomStudyDialog.CUSTOM_STUDY_TAGS) { /* * This is a special Dialog for CUSTOM STUDY, where instead of only collecting a * number, it is necessary to collect a list of tags. This case handles the creation * of that Dialog. */ dialogFragment = website.openeng.anki.dialogs.TagsDialog.newInstance( TagsDialog.TYPE_CUSTOM_STUDY_TAGS, new ArrayList<String>(), new ArrayList<String>(getCol().getTags().all())); ((TagsDialog) dialogFragment).setTagsDialogListener(new TagsDialogListener() { @Override public void onPositive(List<String> selectedTags, int option) { /* * Here's the method that gathers the final selection of tags, type of cards and generates the search * screen for the custom study deck. */ StringBuilder sb = new StringBuilder(); switch (option) { case 1: sb.append("is:new "); break; case 2: sb.append("is:due "); break; default: // Logging here might be appropriate : ) break; } List<String> arr = new ArrayList<>(); if (selectedTags.size() > 0) { for (String tag : selectedTags) { arr.add(String.format("tag:'%s'", tag)); } sb.append("(" + TextUtils.join(" or ", arr) + ")"); } mSearchTerms = sb.toString(); createFilteredDeck(new JSONArray(), new Object[] { mSearchTerms, Consts.DYN_MAX_SIZE, Consts.DYN_RANDOM }, false); } }); } else { // Show CustomStudyDialog for all options other than the tags dialog dialogFragment = CustomStudyDialog.newInstance(which); // If we increase limits, refresh the interface to reflect the new counts ((CustomStudyDialog) dialogFragment).setCustomStudyDialogListener( new CustomStudyDialog.CustomStudyDialogListener() { @Override public void onPositive(int option) { if (option == CustomStudyDialog.CUSTOM_STUDY_NEW || option == CustomStudyDialog.CUSTOM_STUDY_REV) { refreshInterfaceAndDecklist(true); } } }); } // Show the DialogFragment via Activity ((AnkiActivity) getActivity()).showDialogFragment(dialogFragment); } }).build(); dialog.setOwnerActivity(getActivity()); dialog.show(); }
From source file:com.gdgdevfest.android.apps.devfestbcn.ui.tablet.TracksDropdownFragment.java
private void loadTrack(Cursor cursor, boolean triggerCallback) { final int trackColor; final Resources res = getResources(); if (cursor != null) { trackColor = cursor.getInt(TracksAdapter.TracksQuery.TRACK_COLOR); mTrackId = cursor.getString(TracksAdapter.TracksQuery.TRACK_ID); String trackName = cursor.getString(TracksAdapter.TracksQuery.TRACK_NAME); mTitle.setText(trackName);//from w w w. j a v a 2 s . co m mAbstract.setText(cursor.getString(TracksAdapter.TracksQuery.TRACK_ABSTRACT)); int iconResId = res.getIdentifier("track_" + ParserUtils.sanitizeId(trackName), "drawable", getActivity().getPackageName()); if (iconResId != 0) { BitmapDrawable sourceIconDrawable = (BitmapDrawable) res.getDrawable(iconResId); Bitmap icon = Bitmap.createBitmap(sourceIconDrawable.getIntrinsicWidth(), sourceIconDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(icon); sourceIconDrawable.setBounds(0, 0, icon.getWidth(), icon.getHeight()); sourceIconDrawable.draw(canvas); BitmapDrawable iconDrawable = new BitmapDrawable(res, icon); mIcon.setImageDrawable(iconDrawable); } else { mIcon.setImageDrawable(null); } } else { trackColor = res.getColor(R.color.all_track_color); mTrackId = ScheduleContract.Tracks.ALL_TRACK_ID; mIcon.setImageDrawable(null); switch (mViewType) { case VIEW_TYPE_SESSIONS: mTitle.setText(R.string.all_tracks_sessions); mAbstract.setText(R.string.all_tracks_subtitle_sessions); break; case VIEW_TYPE_SANDBOX: mTitle.setText(R.string.all_tracks_sandbox); mAbstract.setText(R.string.all_tracks_subtitle_sandbox); break; } } mRootView.setBackgroundColor(trackColor); mCallbacks.onTrackNameAvailable(mTrackId, mTitle.getText().toString()); if (triggerCallback) { mHandler.post(new Runnable() { @Override public void run() { mCallbacks.onTrackSelected(mTrackId); } }); } }