本文整理匯總了Java中android.content.res.Resources.NotFoundException方法的典型用法代碼示例。如果您正苦於以下問題:Java Resources.NotFoundException方法的具體用法?Java Resources.NotFoundException怎麽用?Java Resources.NotFoundException使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.res.Resources
的用法示例。
在下文中一共展示了Resources.NotFoundException方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTintedDrawable
import android.content.res.Resources; //導入方法依賴的package包/類
@UiThread // Implicit synchronization for use of shared resource VALUE.
public static Drawable getTintedDrawable(Context context,
@DrawableRes int id, @AttrRes int tintAttrId) {
boolean attributeFound = context.getTheme().resolveAttribute(tintAttrId, VALUE, true);
if (!attributeFound) {
throw new Resources.NotFoundException("Required tint color attribute with name "
+ context.getResources().getResourceEntryName(tintAttrId)
+ " and attribute ID "
+ tintAttrId
+ " was not found.");
}
Drawable drawable = ContextCompat.getDrawable(context, id);
drawable = DrawableCompat.wrap(drawable.mutate());
int color = ContextCompat.getColor(context, VALUE.resourceId);
DrawableCompat.setTint(drawable, color);
return drawable;
}
示例2: requestRobotSetup
import android.content.res.Resources; //導入方法依賴的package包/類
private void requestRobotSetup() {
if (controllerService == null) return;
HardwareFactory factory;
RobotConfigFile file = cfgFileMgr.getActiveConfigAndUpdateUI();
HardwareFactory hardwareFactory = new HardwareFactory(context);
try {
hardwareFactory.setXmlPullParser(file.getXml());
} catch (Resources.NotFoundException e) {
file = RobotConfigFile.noConfig(cfgFileMgr);
hardwareFactory.setXmlPullParser(file.getXml());
cfgFileMgr.setActiveConfigAndUpdateUI(false, file);
}
factory = hardwareFactory;
eventLoop = new FtcEventLoop(factory, createOpModeRegister(), callback, this, programmingModeController);
FtcEventLoopIdle idleLoop = new FtcEventLoopIdle(factory, callback, this, programmingModeController);
controllerService.setCallback(callback);
controllerService.setupRobot(eventLoop, idleLoop);
passReceivedUsbAttachmentsToEventLoop();
}
示例3: getLength
import android.content.res.Resources; //導入方法依賴的package包/類
private int getLength(ImageRequest imageRequest) {
AssetFileDescriptor fd = null;
try {
fd = mResources.openRawResourceFd(getResourceId(imageRequest));
return (int) fd.getLength();
} catch (Resources.NotFoundException e) {
return -1;
} finally {
try {
if (fd != null) {
fd.close();
}
} catch (IOException ignored) {
// There's nothing we can do with the exception when closing descriptor.
}
}
}
示例4: testNotMatchingPasswords
import android.content.res.Resources; //導入方法依賴的package包/類
@Test
public void testNotMatchingPasswords() throws Resources.NotFoundException {
Editable mockEditable = mock(Editable.class);
Editable mockEditable2 = mock(Editable.class);
int color = 50;
String text = "message";
when(mPasswordInput.getText()).thenReturn(mockEditable);
when(mockEditable.toString()).thenReturn("validPassw0rd");
when(mockEditable2.toString()).thenReturn("validpassword");
when(mResources.getColor(R.color.red)).thenReturn(color);
when(mContext.getString(R.string.not_matching_passwords)).thenReturn(text);
mPasswordMatchTextWatcher.afterTextChanged(mockEditable2);
verify(mIcon).setImageResource(R.drawable.ic_cancel);
verify(mText).setText(text);
verify(mText).setTextColor(color);
}
示例5: addChildView
import android.content.res.Resources; //導入方法依賴的package包/類
/**
*
* @param parentResolver
* @param childResolver
* @throws Resources.NotFoundException
*/
protected void addChildView(T parentResolver, T childResolver) throws Resources.NotFoundException {
ExpandableViewBinder<T, View> parentBinder = getBinderForResolver(parentResolver);
if(parentBinder != null && parentBinder.isParent()){
ExpandableViewBinder<T, View> childViewBinder = new ExpandableViewBinder<>(childResolver);
parentBinder.getChildList().add(childViewBinder);
if(parentBinder.isExpanded()){
int position;
position = getViewBinderList().indexOf(parentBinder) + parentBinder.getChildList().size();
getViewBinderList().add(position, childViewBinder);
childViewBinder.setParentViewBinder(parentBinder);
childViewBinder.bindParentPosition(getParentPosition(parentBinder));
childViewBinder.bindChildPosition(getChildPosition(parentBinder, childViewBinder));
notifyItemInserted(position);
}
}
}
示例6: getSubtypeDisplayNameInternal
import android.content.res.Resources; //導入方法依賴的package包/類
@NonNull
private static String getSubtypeDisplayNameInternal(@NonNull final InputMethodSubtype subtype,
@NonNull 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);
}
示例7: getFloat
import android.content.res.Resources; //導入方法依賴的package包/類
@UiThread // Implicit synchronization for use of shared resource VALUE.
public static float getFloat(Context context, @DimenRes int id) {
TypedValue value = VALUE;
context.getResources().getValue(id, value, true);
if (value.type == TypedValue.TYPE_FLOAT) {
return value.getFloat();
}
throw new Resources.NotFoundException("Resource ID #0x" + Integer.toHexString(id)
+ " type #0x" + Integer.toHexString(value.type) + " is not valid");
}
示例8: onCreate
import android.content.res.Resources; //導入方法依賴的package包/類
@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.
}
}
示例9: getReadmeText
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* Returns contents of `custom_ca.txt` file from assets as CharSequence.
*
* @return contents of custom_ca.txt file
*/
private CharSequence getReadmeText() {
String rtn = "";
try {
InputStream stream = getResources().openRawResource(R.raw.custom_ca);
java.util.Scanner s = new java.util.Scanner(stream)
.useDelimiter("\\A");
rtn = s.hasNext() ? s.next() : "";
} catch (Resources.NotFoundException e) {
Log.e(LOG_TAG, "License couldn't be retrieved", e);
}
return rtn;
}
示例10: getResourceUri
import android.content.res.Resources; //導入方法依賴的package包/類
@Nullable
private Uri getResourceUri(Integer model) {
try {
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
+ resources.getResourcePackageName(model) + '/'
+ resources.getResourceTypeName(model) + '/'
+ resources.getResourceEntryName(model));
} catch (Resources.NotFoundException e) {
if (Log.isLoggable(TAG, Log.WARN)) {
Log.w(TAG, "Received invalid resource id: " + model, e);
}
return null;
}
}
示例11: get
import android.content.res.Resources; //導入方法依賴的package包/類
public static int get(Context context, int res) {
try {
return ContextCompat.getColor(context, res);
} catch (Resources.NotFoundException e) {
return res;
}
}
示例12: replaceTargetDrawablesIfPresent
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* 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;
}
示例13: applyInvariantDeviceProfileOverrides
import android.content.res.Resources; //導入方法依賴的package包/類
public void applyInvariantDeviceProfileOverrides(InvariantDeviceProfile inv, DisplayMetrics dm) {
int numRows = -1;
int numColumns = -1;
float iconSize = -1;
try {
int resId = getResources().getIdentifier(RES_GRID_NUM_ROWS,
"integer", getPackageName());
if (resId > 0) {
numRows = getResources().getInteger(resId);
}
resId = getResources().getIdentifier(RES_GRID_NUM_COLUMNS,
"integer", getPackageName());
if (resId > 0) {
numColumns = getResources().getInteger(resId);
}
resId = getResources().getIdentifier(RES_GRID_ICON_SIZE_DP,
"dimen", getPackageName());
if (resId > 0) {
int px = getResources().getDimensionPixelSize(resId);
iconSize = Utilities.dpiFromPx(px, dm);
}
} catch (Resources.NotFoundException ex) {
Log.e(TAG, "Invalid Partner grid resource!", ex);
return;
}
if (numRows > 0 && numColumns > 0) {
inv.numRows = numRows;
inv.numColumns = numColumns;
}
if (iconSize > 0) {
inv.iconSize = iconSize;
}
}
示例14: getIcon
import android.content.res.Resources; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
Drawable getIcon(Resources res, int resId) {
Drawable result;
try {
result = res.getDrawableForDensity(resId, mIconDpi);
} catch (Resources.NotFoundException e) {
result = null;
}
return result;
}
示例15: atPositionOnView
import android.content.res.Resources; //導入方法依賴的package包/類
private Matcher<View> atPositionOnView(final int position, final int targetViewId) {
return new TypeSafeMatcher<View>() {
Resources resources = null;
View childView;
public void describeTo(Description description) {
String idDescription = Integer.toString(recyclerViewId);
if (this.resources != null) {
try {
idDescription = this.resources.getResourceName(recyclerViewId);
} catch (Resources.NotFoundException var4) {
idDescription = String.format("%s (resource name not found)", recyclerViewId);
}
}
description.appendText("RecyclerView with id: " + idDescription + " at position: " + position);
}
public boolean matchesSafely(View view) {
this.resources = view.getResources();
if (childView == null) {
RecyclerView recyclerView =
(RecyclerView) view.getRootView().findViewById(recyclerViewId);
if (recyclerView != null && recyclerView.getId() == recyclerViewId) {
RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(position);
if (viewHolder != null) {
childView = viewHolder.itemView;
}
} else {
return false;
}
}
if (targetViewId == -1) {
return view == childView;
} else {
View targetView = childView.findViewById(targetViewId);
return view == targetView;
}
}
};
}