List of usage examples for android.content.res Resources getDrawable
@Deprecated public Drawable getDrawable(@DrawableRes int id) throws NotFoundException
From source file:com.wanikani.androidnotifier.WebReviewActivity.java
/** * Called when the action is initially displayed. It initializes the objects * and starts loading the review page./*from w w w . j a v a 2s . c om*/ * @param bundle the saved bundle */ @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); Resources res; CookieSyncManager.createInstance(this); setVolumeControlStream(AudioManager.STREAM_MUSIC); mh = new MenuHandler(this, new MenuListener()); if (SettingsActivity.getFullscreen(this)) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE); } setContentView(R.layout.web_review); res = getResources(); selectedColor = res.getColor(R.color.selected); unselectedColor = res.getColor(R.color.unselected); muteDrawable = res.getDrawable(R.drawable.ic_mute); notMutedDrawable = res.getDrawable(R.drawable.ic_not_muted); kbstatus = KeyboardStatus.INVISIBLE; bar = (ProgressBar) findViewById(R.id.pb_reviews); dbar = (ProgressBar) findViewById(R.id.pb_download); ignbtn = (ImageButton) findViewById(R.id.btn_ignore); ignbtn.setOnClickListener(new IgnoreButtonListener()); /* First of all get references to views we'll need in the near future */ splashView = findViewById(R.id.wv_splash); contentView = findViewById(R.id.wv_content); msgw = (TextView) findViewById(R.id.tv_message); wv = (FocusWebView) findViewById(R.id.wv_reviews); wv.getSettings().setJavaScriptEnabled(true); wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); wv.getSettings().setSupportMultipleWindows(false); wv.getSettings().setUseWideViewPort(false); wv.getSettings().setDatabaseEnabled(true); wv.getSettings().setDomStorageEnabled(true); wv.getSettings().setDatabasePath(getFilesDir().getPath() + "/wv"); wv.addJavascriptInterface(new WKNKeyboard(), "wknKeyboard"); wv.setScrollBarStyle(ScrollView.SCROLLBARS_OUTSIDE_OVERLAY); wv.setWebViewClient(new WebViewClientImpl()); wv.setWebChromeClient(new WebChromeClientImpl()); download = getIntent().getAction().equals(DOWNLOAD_ACTION); if (download) { downloadPrefix = getIntent().getStringExtra(EXTRA_DOWNLOAD_PREFIX); wv.setDownloadListener(fda = new FileDownloader()); } wv.loadUrl(getIntent().getData().toString()); nativeKeyboard = new NativeKeyboard(this, wv); localIMEKeyboard = new LocalIMEKeyboard(this, wv); muteH = (ImageButton) findViewById(R.id.kb_mute_h); muteH.setOnClickListener(new MuteListener()); singleb = (Button) findViewById(R.id.kb_single); singleb.setOnClickListener(new SingleListener()); if (SettingsActivity.getTimerReaper(this)) { reaper = new TimerThreadsReaper(); rtask = reaper.createTask(new Handler(), 2, 7000); rtask.setListener(new ReaperTaskListener()); } }
From source file:com.android.gallery3d.filtershow.FilterShowActivity.java
private void setDefaultValues() { Resources res = getResources(); // TODO: get those values from XML. FramedTextButton.setTextSize((int) getPixelsFromDip(14)); FramedTextButton.setTrianglePadding((int) getPixelsFromDip(4)); FramedTextButton.setTriangleSize((int) getPixelsFromDip(10)); Drawable curveHandle = res.getDrawable(R.drawable.camera_crop); int curveHandleSize = (int) res.getDimension(R.dimen.crop_indicator_size); Spline.setCurveHandle(curveHandle, curveHandleSize); Spline.setCurveWidth((int) getPixelsFromDip(3)); mOriginalImageUri = null;// www . j a v a2 s . c o m }
From source file:com.actionbarsherlock.internal.view.menu.MenuBuilder.java
private void setHeaderInternal(final int titleRes, final CharSequence title, final int iconRes, final Drawable icon, final View view) { final Resources r = getResources(); if (view != null) { mHeaderView = view;/*from www. j a v a 2 s . c o m*/ // If using a custom view, then the title and icon aren't used mHeaderTitle = null; mHeaderIcon = null; } else { if (titleRes > 0) { mHeaderTitle = r.getText(titleRes); } else if (title != null) { mHeaderTitle = title; } if (iconRes > 0) { mHeaderIcon = r.getDrawable(iconRes); } else if (icon != null) { mHeaderIcon = icon; } // If using the title or icon, then a custom view isn't used mHeaderView = null; } // Notify of change onItemsChanged(false); }
From source file:cm.aptoide.com.actionbarsherlock.widget.SuggestionsAdapter.java
public Drawable getTheDrawable(Uri uri) throws FileNotFoundException { String authority = uri.getAuthority(); Resources r; if (TextUtils.isEmpty(authority)) { throw new FileNotFoundException("No authority: " + uri); } else {//from ww w. jav a 2s.c o m try { r = mContext.getPackageManager().getResourcesForApplication(authority); } catch (NameNotFoundException ex) { throw new FileNotFoundException("No package found for authority: " + uri); } } List<String> path = uri.getPathSegments(); if (path == null) { throw new FileNotFoundException("No path: " + uri); } int len = path.size(); int id; if (len == 1) { try { id = Integer.parseInt(path.get(0)); } catch (NumberFormatException e) { throw new FileNotFoundException("Single path segment is not a resource ID: " + uri); } } else if (len == 2) { id = r.getIdentifier(path.get(1), path.get(0), authority); } else { throw new FileNotFoundException("More than two path segments: " + uri); } if (id == 0) { throw new FileNotFoundException("No resource found for: " + uri); } return r.getDrawable(id); }
From source file:com.granita.tasks.TaskListFragment.java
@Override public void onFlingStart(ListView listView, View listElement, int position, int direction) { // control the visibility of the views that reveal behind a flinging element regarding the fling direction int rightFlingViewId = mGroupDescriptor.getElementViewDescriptor().getFlingRevealRightViewId(); int leftFlingViewId = mGroupDescriptor.getElementViewDescriptor().getFlingRevealLeftViewId(); TextView rightFlingView = null;/* w w w . j a v a 2 s .c o m*/ TextView leftFlingView = null; if (rightFlingViewId != -1) { rightFlingView = (TextView) listElement.findViewById(rightFlingViewId); } if (leftFlingViewId != -1) { leftFlingView = (TextView) listElement.findViewById(leftFlingViewId); } Resources resources = getActivity().getResources(); // change title and icon regarding the task status long packedPos = mExpandableListView.getExpandableListPosition(position); if (ExpandableListView.getPackedPositionType(packedPos) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { ExpandableListAdapter listAdapter = mExpandableListView.getExpandableListAdapter(); Cursor cursor = (Cursor) listAdapter.getChild(ExpandableListView.getPackedPositionGroup(packedPos), ExpandableListView.getPackedPositionChild(packedPos)); if (cursor != null) { int taskStatus = cursor.getInt(cursor.getColumnIndex(Instances.STATUS)); if (leftFlingView != null && rightFlingView != null) { if (taskStatus == Instances.STATUS_COMPLETED) { leftFlingView.setText(R.string.fling_task_delete); leftFlingView.setCompoundDrawablesWithIntrinsicBounds( resources.getDrawable(R.drawable.content_discard), null, null, null); rightFlingView.setText(R.string.fling_task_uncomplete); rightFlingView.setCompoundDrawablesWithIntrinsicBounds(null, null, resources.getDrawable(R.drawable.content_remove_light), null); } else { leftFlingView.setText(R.string.fling_task_complete); leftFlingView.setCompoundDrawablesWithIntrinsicBounds( resources.getDrawable(R.drawable.ic_action_complete), null, null, null); rightFlingView.setText(R.string.fling_task_edit); rightFlingView.setCompoundDrawablesWithIntrinsicBounds(null, null, resources.getDrawable(R.drawable.content_edit), null); } } } } if (rightFlingView != null) { rightFlingView.setVisibility(direction != FlingDetector.LEFT_FLING ? View.GONE : View.VISIBLE); } if (leftFlingView != null) { leftFlingView.setVisibility(direction != FlingDetector.RIGHT_FLING ? View.GONE : View.VISIBLE); } }
From source file:android.support.v7.widget.SuggestionsAdapter.java
/** * Import of hidden method: ContentResolver.getResourceId(Uri). * Modified to return a drawable, rather than a hidden type. *//*w ww.java2 s . co m*/ Drawable getDrawableFromResourceUri(Uri uri) throws FileNotFoundException { String authority = uri.getAuthority(); Resources r; if (TextUtils.isEmpty(authority)) { throw new FileNotFoundException("No authority: " + uri); } else { try { r = mContext.getPackageManager().getResourcesForApplication(authority); } catch (NameNotFoundException ex) { throw new FileNotFoundException("No package found for authority: " + uri); } } List<String> path = uri.getPathSegments(); if (path == null) { throw new FileNotFoundException("No path: " + uri); } int len = path.size(); int id; if (len == 1) { try { id = Integer.parseInt(path.get(0)); } catch (NumberFormatException e) { throw new FileNotFoundException("Single path segment is not a resource ID: " + uri); } } else if (len == 2) { id = r.getIdentifier(path.get(1), path.get(0), authority); } else { throw new FileNotFoundException("More than two path segments: " + uri); } if (id == 0) { throw new FileNotFoundException("No resource found for: " + uri); } return r.getDrawable(id); }
From source file:com.android.mail.browse.ConversationItemView.java
private static synchronized void getItemViewResources(Context context) { if (sConfigurationChangedReceiver == null) { sConfigurationChangedReceiver = new BroadcastReceiver() { @Override// w w w .j a va2s.com public void onReceive(Context context, Intent intent) { STAR_OFF = null; getItemViewResources(context); } }; context.registerReceiver(sConfigurationChangedReceiver, new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED)); } if (STAR_OFF == null) { final Resources res = context.getResources(); // Initialize static bitmaps. STAR_OFF = BitmapFactory.decodeResource(res, R.drawable.ic_star_outline_20dp); STAR_ON = BitmapFactory.decodeResource(res, R.drawable.ic_star_20dp); ATTACHMENT = BitmapFactory.decodeResource(res, R.drawable.ic_attach_file_18dp); ONLY_TO_ME = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_double); TO_ME_AND_OTHERS = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_single); IMPORTANT_ONLY_TO_ME = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_double_important_unread); IMPORTANT_TO_ME_AND_OTHERS = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_single_important_unread); IMPORTANT = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_none_important_unread); STATE_REPLIED = BitmapFactory.decodeResource(res, R.drawable.ic_badge_reply_holo_light); STATE_FORWARDED = BitmapFactory.decodeResource(res, R.drawable.ic_badge_forward_holo_light); STATE_REPLIED_AND_FORWARDED = BitmapFactory.decodeResource(res, R.drawable.ic_badge_reply_forward_holo_light); STATE_CALENDAR_INVITE = BitmapFactory.decodeResource(res, R.drawable.ic_badge_invite_holo_light); FOCUSED_CONVERSATION_HIGHLIGHT = res.getDrawable(R.drawable.visible_conversation_highlight); // Initialize colors. sActivatedTextSpan = CharacterStyle .wrap(new ForegroundColorSpan(res.getColor(R.color.senders_text_color))); sSendersTextColor = res.getColor(R.color.senders_text_color); sSubjectTextUnreadSpan = new TextAppearanceSpan(context, R.style.SubjectAppearanceUnreadStyle); sSubjectTextReadSpan = new TextAppearanceSpan(context, R.style.SubjectAppearanceReadStyle); sBadgeTextSpan = new TextAppearanceSpan(context, R.style.BadgeTextStyle); sBadgeBackgroundSpan = new BackgroundColorSpan(res.getColor(R.color.badge_background_color)); sDateTextColorRead = res.getColor(R.color.date_text_color_read); sDateTextColorUnread = res.getColor(R.color.date_text_color_unread); sStarTouchSlop = res.getDimensionPixelSize(R.dimen.star_touch_slop); sSenderImageTouchSlop = res.getDimensionPixelSize(R.dimen.sender_image_touch_slop); sShrinkAnimationDuration = res.getInteger(R.integer.shrink_animation_duration); sSlideAnimationDuration = res.getInteger(R.integer.slide_animation_duration); // Initialize static color. sSendersSplitToken = res.getString(R.string.senders_split_token); sElidedPaddingToken = res.getString(R.string.elided_padding_token); sScrollSlop = res.getInteger(R.integer.swipeScrollSlop); sFoldersMaxCount = res.getInteger(R.integer.conversation_list_max_folder_count); sCabAnimationDuration = res.getInteger(R.integer.conv_item_view_cab_anim_duration); sBadgePaddingExtraWidth = res.getDimensionPixelSize(R.dimen.badge_padding_extra_width); sBadgeRoundedCornerRadius = res.getDimensionPixelSize(R.dimen.badge_rounded_corner_radius); sDividerPaint.setColor(res.getColor(R.color.divider_color)); sDividerHeight = res.getDimensionPixelSize(R.dimen.divider_height); } }
From source file:org.mythdroid.activities.Guide.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.guide);//from www.j a v a 2 s . c om hScroll = (HorizontalScrollView) findViewById(R.id.guidehscroll); vScroll = (ScrollView) findViewById(R.id.guidevscroll); Resources res = getResources(); scale = res.getDisplayMetrics().density; gDetector = new GestureDetector(this, new GuideGestureListener()); if (getWindowManager().getDefaultDisplay().getWidth() > 1000 || getWindowManager().getDefaultDisplay().getHeight() > 1000) numHours *= 2; numTimes = numHours * 60 / colMins; times = new long[numTimes + 1]; hdrTimes = new String[numTimes / hdrSpan]; colWidth = (int) (40 * scale + 0.5f); rowHeight = (int) (60 * scale + 0.5f); chanWidth = (int) (100 * scale + 0.5f); tbl = (TableLayout) findViewById(R.id.table); rowLayout.topMargin = rowLayout.bottomMargin = chanLayout.topMargin = chanLayout.bottomMargin = chanLayout.leftMargin = chanLayout.rightMargin = hdrDateLayout.leftMargin = hdrDateLayout.rightMargin = hdrTimeLayout.leftMargin = hdrTimeLayout.rightMargin = 1; rowLayout.height = chanLayout.height = rowHeight; chanLayout.column = hdrDateLayout.column = 0; chanLayout.span = hdrDateLayout.span = 1; chanLayout.width = hdrDateLayout.width = chanWidth; hdrTimeLayout.width = colWidth * hdrSpan; hdrTimeLayout.span = hdrSpan; spacerLayout.height = 1; spacerLayout.width = colWidth; spacerLayout.span = 1; recordedIcon = res.getDrawable(R.drawable.recorded); willRecordIcon = res.getDrawable(R.drawable.willrecord); failedIcon = res.getDrawable(R.drawable.failed); conflictIcon = res.getDrawable(R.drawable.conflict); otherIcon = res.getDrawable(R.drawable.other); date.setTimeZone(TimeZone.getDefault()); time.setTimeZone(TimeZone.getDefault()); if (Globals.haveServices()) try { guideService = new GuideService(Globals.getBackend().addr); } catch (IOException e) { ErrUtil.err(this, e); finish(); return; } }
From source file:com.dwdesign.tweetings.util.Utils.java
public static Drawable getTabIconDrawable(final Context context, final Object icon_obj) { if (context == null) return null; final Resources res = context.getResources(); if (icon_obj instanceof Integer) { try {// w ww .jav a2s . c om return res.getDrawable((Integer) icon_obj); } catch (final Resources.NotFoundException e) { // Ignore. } } else if (icon_obj instanceof Bitmap) return new BitmapDrawable(res, (Bitmap) icon_obj); else if (icon_obj instanceof Drawable) return (Drawable) icon_obj; else if (icon_obj instanceof File) { final Bitmap b = getTabIconFromFile((File) icon_obj, res); if (b != null) return new BitmapDrawable(res, b); } return res.getDrawable(R.drawable.ic_tab_list); }
From source file:com.klinker.deskclock.widget.multiwaveview.GlowPadView.java
public GlowPadView(Context context, AttributeSet attrs) { super(context, attrs); Resources res = context.getResources(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GlowPadView); mInnerRadius = a.getDimension(R.styleable.GlowPadView_innerRadius, mInnerRadius); mOuterRadius = a.getDimension(R.styleable.GlowPadView_outerRadius, mOuterRadius); mSnapMargin = a.getDimension(R.styleable.GlowPadView_snapMargin, mSnapMargin); mVibrationDuration = a.getInt(R.styleable.GlowPadView_vibrationDuration, mVibrationDuration); mFeedbackCount = a.getInt(R.styleable.GlowPadView_feedbackCount, mFeedbackCount); TypedValue handle = a.peekValue(R.styleable.GlowPadView_handleDrawable); mHandleDrawable = new TargetDrawable(res, handle != null ? handle.resourceId : 0, 2); mHandleDrawable.setState(TargetDrawable.STATE_INACTIVE); mOuterRing = new TargetDrawable(res, getResourceId(a, R.styleable.GlowPadView_outerRingDrawable), 1); mAlwaysTrackFinger = a.getBoolean(R.styleable.GlowPadView_alwaysTrackFinger, false); int pointId = getResourceId(a, R.styleable.GlowPadView_pointDrawable); Drawable pointDrawable = pointId != 0 ? res.getDrawable(pointId) : null; mGlowRadius = a.getDimension(R.styleable.GlowPadView_glowRadius, 0.0f); TypedValue outValue = new TypedValue(); // Read array of target drawables if (a.getValue(R.styleable.GlowPadView_targetDrawables, outValue)) { internalSetTargetResources(outValue.resourceId); }//from ww w . ja v a2 s . c o m if (mTargetDrawables == null || mTargetDrawables.size() == 0) { throw new IllegalStateException("Must specify at least one target drawable"); } // Read array of target descriptions if (a.getValue(R.styleable.GlowPadView_targetDescriptions, outValue)) { final int resourceId = outValue.resourceId; if (resourceId == 0) { throw new IllegalStateException("Must specify target descriptions"); } setTargetDescriptionsResourceId(resourceId); } // Read array of direction descriptions if (a.getValue(R.styleable.GlowPadView_directionDescriptions, outValue)) { final int resourceId = outValue.resourceId; if (resourceId == 0) { throw new IllegalStateException("Must specify direction descriptions"); } setDirectionDescriptionsResourceId(resourceId); } a.recycle(); // Use gravity attribute from LinearLayout //a = context.obtainStyledAttributes(attrs, R.styleable.LinearLayout); mGravity = a.getInt(R.styleable.GlowPadView_android_gravity, Gravity.TOP); a.recycle(); setVibrateEnabled(mVibrationDuration > 0); assignDefaultsIfNeeded(); mPointCloud = new PointCloud(pointDrawable); mPointCloud.makePointCloud(mInnerRadius, mOuterRadius); mPointCloud.glowManager.setRadius(mGlowRadius); }