Java Code Examples for android.content.res.Resources#NotFoundException
The following examples show how to use
android.content.res.Resources#NotFoundException .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseIndicatorBanner.java From BaseProject with Apache License 2.0 | 6 votes |
/** 设置显示器选中以及未选中资源(for STYLE_DRAWABLE_RESOURCE) */ public I setIndicatorSelectorRes(@DrawableRes int unselectRes, @DrawableRes int selectRes) { try { if (mIndicatorStyle == STYLE_DRAWABLE_RESOURCE) { if (selectRes != 0) { this.mSelectDrawable = getResources().getDrawable(selectRes); } if (unselectRes != 0) { this.mUnSelectDrawable = getResources().getDrawable(unselectRes); } } } catch (Resources.NotFoundException e) { e.printStackTrace(); } return self(); }
Example 2
Source File: Launcher.java From TurboLauncher with Apache License 2.0 | 6 votes |
private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) { try { PackageManager packageManager = getPackageManager(); // Look for the toolbar icon specified in the activity meta-data Bundle metaData = packageManager.getActivityInfo(activityName, PackageManager.GET_META_DATA).metaData; if (metaData != null) { int iconResId = metaData.getInt(resourceName); if (iconResId != 0) { Resources res = packageManager .getResourcesForActivity(activityName); return res.getDrawable(iconResId); } } } catch (NameNotFoundException e) { } catch (Resources.NotFoundException nfe) { } return null; }
Example 3
Source File: SubtypeLocaleUtils.java From LokiBoard-Android-Keylogger with Apache License 2.0 | 6 votes |
private static String getSubtypeDisplayNameInternal(final InputMethodSubtype subtype, final Locale displayLocale) { final String replacementString = getReplacementString(subtype, displayLocale); // TODO: rework this for multi-lingual subtypes final int nameResId = subtype.getNameResId(); final RunInLocale<String> getSubtypeName = new RunInLocale<String>() { @Override protected String job(final Resources res) { try { return res.getString(nameResId, replacementString); } catch (Resources.NotFoundException e) { // TODO: Remove this catch when InputMethodManager.getCurrentInputMethodSubtype // is fixed. Log.w(TAG, "Unknown subtype: mode=" + subtype.getMode() + " nameResId=" + subtype.getNameResId() + " locale=" + subtype.getLocale() + " extra=" + subtype.getExtraValue() + "\n" + DebugLogUtils.getStackTrace()); return ""; } } }; return StringUtils.capitalizeFirstCodePoint( getSubtypeName.runInLocale(sResources, displayLocale), displayLocale); }
Example 4
Source File: ListBuddiesLayout.java From UltimateAndroid with Apache License 2.0 | 6 votes |
private void setListBuddiesAttributes(Context context, AttributeSet attrs) { try { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListBuddiesOptions, 0, 0); mGap = a.getDimensionPixelSize(R.styleable.ListBuddiesOptions_gap, 12); mSpeed = a.getInteger(R.styleable.ListBuddiesOptions_speed, DEFAULT_SPEED); int configOptionFasterList = a.getInteger(R.styleable.ListBuddiesOptions_autoScrollFaster, ScrollConfigOptions.LEFT.getConfigValue()); isAutoScrollLeftListFaster = configOptionFasterList == ScrollConfigOptions.LEFT.getConfigValue(); isManualScrollLeftListFaster = a.getInteger(R.styleable.ListBuddiesOptions_scrollFaster, configOptionFasterList) == ScrollConfigOptions.LEFT.getConfigValue(); mDivider = a.getDrawable(R.styleable.ListBuddiesOptions_listsDivider); mDividerHeight = a.getDimensionPixelSize(R.styleable.ListBuddiesOptions_listsDividerHeight, ATTR_NOT_SET); mGapColor = a.getColor(R.styleable.ListBuddiesOptions_gapColor, ATTR_NOT_SET); a.recycle(); } catch (Resources.NotFoundException e) { e.printStackTrace(); Logs.e(e, ""); } }
Example 5
Source File: PermissionAspect.java From android_permission_aspectjx with Apache License 2.0 | 6 votes |
private static String chooseContent(Context context, String strContent, int resId) { if (context == null) { return null; } if (TextUtils.isEmpty(strContent)) { if (resId <= 0) { return strContent; } try { return context.getString(resId); } catch (Resources.NotFoundException e) { return strContent; } } return strContent; }
Example 6
Source File: RouteDirectionsFragment.java From nearby-android with Apache License 2.0 | 5 votes |
private Drawable getRoutingIcon(final DirectionManeuverType maneuver) { try { Integer id = getResourceIdForManeuverType(maneuver); return ResourcesCompat.getDrawable(getActivity().getResources(),id,null); } catch (final Resources.NotFoundException e) { Log.w(RouteDirectionsFragment.TAG, "No drawable found for" + maneuver.name()); return null; } }
Example 7
Source File: BottomSheetNumberPadTimePickerDialog.java From NumberPadTimePicker with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Override the dialog's width if we're running in an eligible layout qualifier. try { getWindow().setLayout(getContext().getResources().getDimensionPixelSize( R.dimen.nptp_bottom_sheet_dialog_width), ViewGroup.LayoutParams.MATCH_PARENT); } catch (Resources.NotFoundException nfe) { // Do nothing. } }
Example 8
Source File: Matchers.java From zulip-android with Apache License 2.0 | 5 votes |
public static Matcher<View> withFirstId(final int id) { return new TypeSafeMatcher<View>() { Resources resources = null; boolean found = false; @Override public void describeTo(Description description) { String idDescription = Integer.toString(id); if (resources != null) { try { idDescription = resources.getResourceName(id); } catch (Resources.NotFoundException e) { // No big deal, will just use the int value. idDescription = String.format("%s (resource name not found)", id); } } description.appendText("with id: " + idDescription); } @Override public boolean matchesSafely(View view) { if (found) return false; resources = view.getResources(); if (id == view.getId()) { found = true; return true; } return false; } }; }
Example 9
Source File: HomeRepositoryDiskImpl.java From Material-Design-Example with Apache License 2.0 | 5 votes |
@Override public void recoverTitleTabs() { try { List<String> listTitleTabs = Arrays.asList(MaterialDesignApplication.getApplicationCtx().getResources().getStringArray(R.array.fragment_home_sections_tabs_title)); BusProvider.getInstance().post(new LoadTitleTabsDisk(listTitleTabs)); } catch (Resources.NotFoundException notFoundExcepetion) { Log.e(TAG, "Error Getting The Array", notFoundExcepetion); } }
Example 10
Source File: ResourcesManager.java From Sunshine with Apache License 2.0 | 5 votes |
public Drawable getMipmapByName(String name) { try { return resources.getDrawable(identifier(name, RES_TYPE_MIPMAP)); } catch (Resources.NotFoundException e) { Log.e(TAG, "获取mipmap资源" + name + "失败"); e.printStackTrace(); return null; } }
Example 11
Source File: Resource.java From proteus with Apache License 2.0 | 5 votes |
@Nullable public static ColorStateList getColorStateList(int resId, Context context) { try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return context.getColorStateList(resId); } else { //noinspection deprecation return context.getResources().getColorStateList(resId); } } catch (Resources.NotFoundException nfe) { return null; } }
Example 12
Source File: PathAnimatorInflater.java From ElasticProgressBar with Apache License 2.0 | 5 votes |
private static ObjectAnimator loadObjectAnimator(Context c, Resources res, Resources.Theme theme, AttributeSet attrs, float pathErrorScale) throws Resources.NotFoundException { ObjectAnimator anim = new ObjectAnimator(); loadAnimator(c, res, theme, attrs, anim, pathErrorScale); return anim; }
Example 13
Source File: TetheringConfiguration.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static String getProvisioningAppNoUi(Context ctx) { try { return ctx.getResources().getString(config_mobile_hotspot_provision_app_no_ui); } catch (Resources.NotFoundException e) { return ""; } }
Example 14
Source File: GlowPadView.java From CSipSimple with GNU General Public License v3.0 | 5 votes |
/** * Searches the given package for a resource to use to replace the Drawable on the * target with the given resource id * @param component of the .apk that contains the resource * @param name of the metadata in the .apk * @param existingResId the resource id of the target to search for * @return true if found in the given package and replaced at least one target Drawables */ public boolean replaceTargetDrawablesIfPresent(ComponentName component, String name, int existingResId) { if (existingResId == 0) return false; boolean replaced = false; if (component != null) { try { PackageManager packageManager = getContext().getPackageManager(); // Look for the search icon specified in the activity meta-data Bundle metaData = packageManager.getActivityInfo( component, PackageManager.GET_META_DATA).metaData; if (metaData != null) { int iconResId = metaData.getInt(name); if (iconResId != 0) { Resources res = packageManager.getResourcesForActivity(component); replaced = replaceTargetDrawables(res, existingResId, iconResId); } } } catch (NameNotFoundException e) { Log.w(THIS_FILE, "Failed to swap drawable; " + component.flattenToShortString() + " not found", e); } catch (Resources.NotFoundException nfe) { Log.w(THIS_FILE, "Failed to swap drawable from " + component.flattenToShortString(), nfe); } } if (!replaced) { // Restore the original drawable replaceTargetDrawables(getContext().getResources(), existingResId, existingResId); } return replaced; }
Example 15
Source File: AbstractMaterialDialogBuilder.java From AndroidMaterialDialog with Apache License 2.0 | 5 votes |
/** * Obtains the height from a specific theme. * * @param themeResourceId * The resource id of the theme, the height should be obtained from, as an {@link * Integer} value */ private void obtainHeight(@StyleRes final int themeResourceId) { TypedArray typedArray = getContext().getTheme() .obtainStyledAttributes(themeResourceId, new int[]{R.attr.materialDialogHeight}); int defaultValue = Dialog.WRAP_CONTENT; try { setHeight(typedArray.getDimensionPixelSize(0, defaultValue)); } catch (Resources.NotFoundException | UnsupportedOperationException e) { setHeight(typedArray.getInteger(0, defaultValue)); } }
Example 16
Source File: ToastUtils.java From ToastUtils with Apache License 2.0 | 5 votes |
/** * 显示一个吐司 * * @param id 如果传入的是正确的 string id 就显示对应字符串 * 如果不是则显示一个整数的string */ public static void show(int id) { checkToastState(); try { // 如果这是一个资源 id show(getContext().getResources().getText(id)); } catch (Resources.NotFoundException ignored) { // 如果这是一个 int 整数 show(String.valueOf(id)); } }
Example 17
Source File: PulseView.java From PulseView with Apache License 2.0 | 4 votes |
public PulseView(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); // Always draw and improve speed setWillNotDraw(false); setLayerType(LAYER_TYPE_HARDWARE, null); // Get attrs final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.PulseView); try { setIconRes(typedArray.getResourceId(R.styleable.PulseView_pv_icon, 0)); setIconWidth((int) typedArray.getDimension(R.styleable.PulseView_pv_icon_width, 0)); setIconHeight((int) typedArray.getDimension(R.styleable.PulseView_pv_icon_height, 0)); setPulseCount( typedArray.getInteger(R.styleable.PulseView_pv_count, DEFAULT_PULSE_COUNT) ); setPulseSpawnPeriod( typedArray.getInteger( R.styleable.PulseView_pv_spawn_period, DEFAULT_PULSE_SPAWN_PERIOD ) ); setPulseAlpha(typedArray.getInteger(R.styleable.PulseView_pv_alpha, DEFAULT_PULSE_ALPHA)); setPulseColor(typedArray.getColor(R.styleable.PulseView_pv_color, DEFAULT_PULSE_COLOR)); setPulseMeasure( typedArray.getInt(R.styleable.PulseView_pv_measure, DEFAULT_PULSE_MEASURE) ); // Retrieve interpolator Interpolator interpolator = null; try { final int interpolatorId = typedArray.getResourceId( R.styleable.PulseView_pv_interpolator, 0 ); interpolator = interpolatorId == 0 ? null : AnimationUtils.loadInterpolator(context, interpolatorId); } catch (Resources.NotFoundException exception) { interpolator = null; exception.printStackTrace(); } finally { setInterpolator(interpolator); } } finally { typedArray.recycle(); } }
Example 18
Source File: ToastEx.java From FairEmail with GNU General Public License v3.0 | 4 votes |
public static ToastEx makeText(Context context, int resId, int duration) throws Resources.NotFoundException { return makeText(context, context.getText(resId), duration); }
Example 19
Source File: Boast.java From RetailStore with Apache License 2.0 | 2 votes |
/** * Show a standard {@link Boast} that just contains a text view with the * text from a resource. * * @param context The context to use. Usually your {@link android.app.Application} * or {@link android.app.Activity} object. * @param resId The resource id of the string resource to use. Can be formatted * text. * @param duration How long to display the message. Either {@link //LENGTH_SHORT} or * {@link //LENGTH_LONG} * @throws Resources.NotFoundException if the resource can't be found. */ public static void showText(Context context, int resId, int duration) throws Resources.NotFoundException { Boast.makeText(context, resId, duration).show(); }
Example 20
Source File: Toast.java From android_9.0.0_r45 with Apache License 2.0 | 2 votes |
/** * Make a standard toast that just contains a text view with the text from a resource. * * @param context The context to use. Usually your {@link android.app.Application} * or {@link android.app.Activity} object. * @param resId The resource id of the string resource to use. Can be formatted text. * @param duration How long to display the message. Either {@link #LENGTH_SHORT} or * {@link #LENGTH_LONG} * * @throws Resources.NotFoundException if the resource can't be found. */ public static Toast makeText(Context context, @StringRes int resId, @Duration int duration) throws Resources.NotFoundException { return makeText(context, context.getResources().getText(resId), duration); }