android.content.res.Resources#NotFoundException()源码实例Demo

下面列出了android.content.res.Resources#NotFoundException() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: BaseProject   文件: BaseIndicatorBanner.java
/** 设置显示器选中以及未选中资源(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();
}
 
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;
}
 
源代码3 项目: UltimateAndroid   文件: ListBuddiesLayout.java
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, "");
    }
}
 
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);
}
 
源代码5 项目: TurboLauncher   文件: Launcher.java
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;
}
 
源代码6 项目: ToastUtils   文件: ToastUtils.java
/**
 * 显示一个吐司
 *
 * @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));
    }
}
 
源代码7 项目: proteus   文件: Resource.java
@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;
  }
}
 
源代码8 项目: Sunshine   文件: ResourcesManager.java
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;
    }
}
 
源代码9 项目: nearby-android   文件: RouteDirectionsFragment.java
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;
      }
    }
 
@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.
    }
}
 
源代码11 项目: zulip-android   文件: Matchers.java
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;
        }
    };
}
 
@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);
    }
}
 
源代码13 项目: ElasticProgressBar   文件: PathAnimatorInflater.java
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;
}
 
源代码14 项目: android_9.0.0_r45   文件: TetheringConfiguration.java
private static String getProvisioningAppNoUi(Context ctx) {
    try {
        return ctx.getResources().getString(config_mobile_hotspot_provision_app_no_ui);
    } catch (Resources.NotFoundException e) {
        return "";
    }
}
 
源代码15 项目: CSipSimple   文件: GlowPadView.java
/**
 * 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;
}
 
/**
 * 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));
    }
}
 
源代码17 项目: PulseView   文件: PulseView.java
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();
    }
}
 
源代码18 项目: FairEmail   文件: ToastEx.java
public static ToastEx makeText(Context context, int resId, int duration) throws Resources.NotFoundException {
    return makeText(context, context.getText(resId), duration);
}
 
源代码19 项目: RetailStore   文件: Boast.java
/**
 * 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();
}
 
源代码20 项目: android_9.0.0_r45   文件: Toast.java
/**
 * 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);
}