android.content.res.Resources.NotFoundException Java Examples

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: ZoomImageActivity.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_zoom_image);

    AmbientModeSupport.attach(this);

    // Check if integer was actually given.
    if (!(getIntent().hasExtra(getString(R.string.intent_extra_image)))) {
        throw new NotFoundException("Expecting extras");
    }

    // Grab the resource id from extras and set the image resource.
    int value = getIntent().getIntExtra(getString(R.string.intent_extra_image), 0);
    ImageView expandedImage = findViewById(R.id.expanded_image);
    expandedImage.setImageResource(value);
}
 
Example #2
Source File: ThemeHelper.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the color, which corresponds to a specific theme attribute, regarding the theme,
 * which is used when using a specific layout.
 *
 * @param layout
 *         The layout as a value of the enum {@link Layout}. The layout may not be null
 * @param resourceId
 *         The resource id of the theme attribute, the color should be obtained from, as an
 *         {@link Integer} value. The resource id must correspond to a valid theme attribute
 * @return The color, which has been obtained, as an {@link Integer} value
 */
@ColorInt
public int getColor(@NonNull final Layout layout, @AttrRes final int resourceId) {
    try {
        return ThemeUtil.getColor(context, resourceId);
    } catch (NotFoundException e1) {
        int themeResourceId = getThemeResourceId(layout);

        try {
            return ThemeUtil.getColor(context, themeResourceId, resourceId);
        } catch (NotFoundException e) {
            themeResourceId = obtainThemeFromThemeAttributes(layout, themeResourceId);
            return ThemeUtil.getColor(context, themeResourceId, resourceId);
        }
    }
}
 
Example #3
Source File: ThemeHelper.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the color state list, which corresponds to a specific theme attribute, regarding the
 * theme, which is used when using a specific layout.
 *
 * @param layout
 *         The layout as a value of the enum {@link Layout}. The layout may not be null
 * @param resourceId
 *         The resource id of the theme attribute, the color state list should be obtained from,
 *         as an {@link Integer} value. The resource id must correspond to a valid theme
 *         attribute
 * @return The color state list, which has been obtained, as an instance of the class {@link
 * ColorStateList}
 */
public ColorStateList getColorStateList(@NonNull final Layout layout,
                                        @AttrRes final int resourceId) {
    try {
        return ThemeUtil.getColorStateList(context, resourceId);
    } catch (NotFoundException e1) {
        int themeResourceId = getThemeResourceId(layout);

        try {
            return ThemeUtil.getColorStateList(context, themeResourceId, resourceId);
        } catch (NotFoundException e) {
            themeResourceId = obtainThemeFromThemeAttributes(layout, themeResourceId);
            return ThemeUtil.getColorStateList(context, themeResourceId, resourceId);
        }
    }
}
 
Example #4
Source File: ResourcesImpl.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@NonNull
CharSequence getQuantityText(@PluralsRes int id, int quantity) throws NotFoundException {
    PluralRules rule = getPluralRule();
    CharSequence res = mAssets.getResourceBagText(id,
            attrForQuantityCode(rule.select(quantity)));
    if (res != null) {
        return res;
    }
    res = mAssets.getResourceBagText(id, ID_OTHER);
    if (res != null) {
        return res;
    }
    throw new NotFoundException("Plural resource ID #0x" + Integer.toHexString(id)
            + " quantity=" + quantity
            + " item=" + rule.select(quantity));
}
 
Example #5
Source File: ResourcesImpl.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
String[] getTheme() {
    synchronized (mKey) {
        final int N = mKey.mCount;
        final String[] themes = new String[N * 2];
        for (int i = 0, j = N - 1; i < themes.length; i += 2, --j) {
            final int resId = mKey.mResId[j];
            final boolean forced = mKey.mForce[j];
            try {
                themes[i] = getResourceName(resId);
            } catch (NotFoundException e) {
                themes[i] = Integer.toHexString(i);
            }
            themes[i + 1] = forced ? "forced" : "not forced";
        }
        return themes;
    }
}
 
Example #6
Source File: TabSwitcherStyle.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the title of the toolbar, which is shown, when the tab switcher is shown. When using
 * the tablet layout, the title corresponds to the primary toolbar.
 *
 * @return The title of the toolbar, which is shown, when the tab switcher is shown, as an
 * instance of the type {@link CharSequence} or null, if no title is set
 */
@Nullable
public final CharSequence getToolbarTitle() {
    CharSequence title = model.getToolbarTitle();

    if (TextUtils.isEmpty(title)) {
        try {
            title = themeHelper
                    .getText(tabSwitcher.getLayout(), R.attr.tabSwitcherToolbarTitle);
        } catch (NotFoundException e) {
            title = null;
        }
    }

    return title;
}
 
Example #7
Source File: OtherUtils.java    From robotium-extensions with Apache License 2.0 6 votes vote down vote up
private String getDescriptionOrId(View view) {
    String result = view.getContentDescription() != null ? view
            .getContentDescription().toString() : null;
    if (isNullOrEmpty(result)) {
        if (view.getId() != View.NO_ID) {
            try {
                result = String.format("with id: \"%s\"", view.getContext()
                        .getResources().getResourceEntryName(view.getId()));
            } catch (NotFoundException e) {
                result = String.format(Locale.ENGLISH, "with id: \"%d\"",
                        view.getId());
            }
        }
    } else {
        result = String.format("\"%s\"", result);
    }
    return result;
}
 
Example #8
Source File: ShortcutInfo.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Return the resource ID for a given resource ID.
 *
 * Basically its' a wrapper over {@link Resources#getIdentifier(String, String, String)}, except
 * if {@code resourceName} is an integer then it'll just return its value.  (Which also the
 * aforementioned method would do internally, but not documented, so doing here explicitly.)
 *
 * @param res {@link Resources} for the publisher.  Must have been loaded with
 * {@link PackageManager#getResourcesForApplicationAsUser}.
 *
 * @hide
 */
@VisibleForTesting
public static int lookUpResourceId(@NonNull Resources res, @Nullable String resourceName,
        @Nullable String resourceType, String packageName) {
    if (resourceName == null) {
        return 0;
    }
    try {
        try {
            // It the name can be parsed as an integer, just use it.
            return Integer.parseInt(resourceName);
        } catch (NumberFormatException ignore) {
        }

        return res.getIdentifier(resourceName, resourceType, packageName);
    } catch (NotFoundException e) {
        Log.e(TAG, "Resource ID for name=" + resourceName + " not found in package "
                + packageName);
        return 0;
    }
}
 
Example #9
Source File: XFlutterActivityDelegate.java    From hybrid_stack_manager with MIT License 6 votes vote down vote up
/**
 * Extracts a {@link Drawable} from the parent activity's {@code windowBackground}.
 *
 * {@code android:windowBackground} is specifically reused instead of a other attributes
 * because the Android framework can display it fast enough when launching the app as opposed
 * to anything defined in the Activity subclass.
 *
 * Returns null if no {@code windowBackground} is set for the activity.
 */
@SuppressWarnings("deprecation")
private Drawable getLaunchScreenDrawableFromActivityTheme() {
    TypedValue typedValue = new TypedValue();
    if (!activity.getTheme().resolveAttribute(
            android.R.attr.windowBackground,
            typedValue,
            true)) {;
        return null;
    }
    if (typedValue.resourceId == 0) {
        return null;
    }
    try {
        return activity.getResources().getDrawable(typedValue.resourceId);
    } catch (NotFoundException e) {
        Log.e(TAG, "Referenced launch screen windowBackground resource does not exist");
        return null;
    }
}
 
Example #10
Source File: PreferenceFragment.java    From AndroidPreferenceActivity with Apache License 2.0 6 votes vote down vote up
/**
 * Obtains the background of the button bar from the activity's current theme.
 */
private void obtainButtonBarBackground() {
    try {
        int color =
                ThemeUtil.getColor(getActivity(), R.attr.restoreDefaultsButtonBarBackground);
        setButtonBarBackgroundColor(color);
    } catch (NotFoundException e) {
        int resourceId = ThemeUtil
                .getResId(getActivity(), R.attr.restoreDefaultsButtonBarBackground, -1);

        if (resourceId != -1) {
            setButtonBarBackground(resourceId);
        } else {
            setButtonBarBackgroundColor(
                    ContextCompat.getColor(getActivity(), R.color.button_bar_background_light));
        }
    }
}
 
Example #11
Source File: TabSwitcherStyle.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Return the color state list, which should be used to tint the close button of tabs.
 *
 * @param tab
 *         The tab, the color state list should be returned for, as an instance of the class
 *         {@link Tab} or null, if the color state list should not be returned for a specific
 *         tab
 * @return The color state list, which should be used to tint the close button of tabs, as an
 * instance of the class {@link ColorStateList} or null, if the close button should not be
 * tinted
 */
@Nullable
private ColorStateList getTabCloseButtonIconTintList(@Nullable final Tab tab) {
    ColorStateList tintList = tab != null ? tab.getCloseButtonIconTintList() : null;

    if (tintList == null) {
        tintList = model.getTabCloseButtonIconTintList();

        if (tintList == null) {
            try {
                tintList = themeHelper.getColorStateList(tabSwitcher.getLayout(),
                        R.attr.tabSwitcherTabCloseButtonIconTint);
            } catch (NotFoundException e) {
                tintList = null;
            }

        }
    }

    return tintList;
}
 
Example #12
Source File: WallpaperInfo.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Return a brief summary of this wallpaper's behavior.
 */
public CharSequence loadDescription(PackageManager pm) throws NotFoundException {
    String packageName = mService.resolvePackageName;
    ApplicationInfo applicationInfo = null;
    if (packageName == null) {
        packageName = mService.serviceInfo.packageName;
        applicationInfo = mService.serviceInfo.applicationInfo;
    }
    if (mService.serviceInfo.descriptionRes != 0) {
        return pm.getText(packageName, mService.serviceInfo.descriptionRes,
                applicationInfo);
        
    }
    if (mDescriptionResource <= 0) throw new NotFoundException();
    return pm.getText(packageName, mDescriptionResource,
            mService.serviceInfo.applicationInfo);
}
 
Example #13
Source File: FolderPickerActivity.java    From Cirrus_depricated with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Updates the view associated to the activity after the finish of an operation trying
 * to create a new folder.
 *
 * @param operation     Creation operation performed.
 * @param result        Result of the creation.
 */
private void onCreateFolderOperationFinish(
        CreateFolderOperation operation, RemoteOperationResult result
) {

    if (result.isSuccess()) {
        refreshListOfFilesFragment();
    } else {
        try {
            Toast msg = Toast.makeText(FolderPickerActivity.this,
                    ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
                    Toast.LENGTH_LONG);
            msg.show();

        } catch (NotFoundException e) {
            Log_OC.e(TAG, "Error while trying to show fail message " , e);
        }
    }
}
 
Example #14
Source File: FileDisplayActivity.java    From Cirrus_depricated with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Updates the view associated to the activity after the finish of an operation trying to copy a
 * file.
 *
 * @param operation Copy operation performed.
 * @param result    Result of the copy operation.
 */
private void onCopyFileOperationFinish(CopyFileOperation operation, RemoteOperationResult result) {
    if (result.isSuccess()) {
        dismissLoadingDialog();
        refreshListOfFilesFragment();
    } else {
        dismissLoadingDialog();
        try {
            Toast msg = Toast.makeText(FileDisplayActivity.this,
                    ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
                    Toast.LENGTH_LONG);
            msg.show();

        } catch (NotFoundException e) {
            Log_OC.e(TAG, "Error while trying to show fail message ", e);
        }
    }
}
 
Example #15
Source File: SelectableRoundedImageView.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private Drawable resolveResource() {
        Resources rsrc = getResources();
        if (rsrc == null) {
            return null;
        }

        Drawable d = null;

        if (mResource != 0) {
            try {
                d = rsrc.getDrawable(mResource);
            } catch (NotFoundException e) {
//                Log.w(TAG, "Unable to find resource: " + mResource, e);
                // Don't try again.
                mResource = 0;
            }
        }
        return SelectableRoundedCornerDrawable.fromDrawable(d, getResources());
    }
 
Example #16
Source File: BasicActivity.java    From letv with Apache License 2.0 6 votes vote down vote up
public void showToast(String resId, int duration) {
    String res = null;
    if (TextUtils.empty(resId)) {
        resId = "umgr_rcode_fail";
    }
    try {
        res = L10NString.getString(resId);
    } catch (NotFoundException e) {
        LOG.e(TAG, "[resId:" + resId + "] get string failed(NotFoundException)", e);
    }
    try {
        if (!TextUtils.empty(res)) {
            ToastHelper.getInstance().shortOrLongToast((Context) this, res, duration);
        }
    } catch (NotFoundException e2) {
        LOG.e(TAG, "[resId:" + resId + "] show toast failed(NotFoundException)", e2);
    }
}
 
Example #17
Source File: SelectableRoundedImageView.java    From sealtalk-android with MIT License 6 votes vote down vote up
private Drawable resolveResource() {
        Resources rsrc = getResources();
        if (rsrc == null) {
            return null;
        }

        Drawable d = null;

        if (mResource != 0) {
            try {
                d = rsrc.getDrawable(mResource);
            } catch (NotFoundException e) {
//                Log.w(TAG, "Unable to find resource: " + mResource, e);
                // Don't try again.
                mResource = 0;
            }
        }
        return SelectableRoundedCornerDrawable.fromDrawable(d, getResources());
    }
 
Example #18
Source File: RoundedImageView.java    From AndroidMaterialDesign with Apache License 2.0 6 votes vote down vote up
private Drawable resolveResource() {
    Resources rsrc = getResources();
    if (rsrc == null) {
        return null;
    }

    Drawable d = null;

    if (mResource != 0) {
        try {
            d = rsrc.getDrawable(mResource);
        } catch (NotFoundException e) {
            Log.w(TAG, "Unable to find resource: " + mResource, e);
            // Don't try again.
            mResource = 0;
        }
    }
    return SelectableRoundedCornerDrawable.fromDrawable(d, getResources());
}
 
Example #19
Source File: TabSwitcher.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Obtains the view's background from a specific typed array.
 *
 * @param typedArray
 *         The typed array, the background should be obtained from, as an instance of the class
 *         {@link TypedArray}. The typed array may not be null
 */
private void obtainBackground(@NonNull final TypedArray typedArray) {
    Drawable background = typedArray.getDrawable(R.styleable.TabSwitcher_android_background);

    if (background == null) {
        try {
            background = themeHelper.getDrawable(getLayout(), R.attr.tabSwitcherBackground);
        } catch (NotFoundException e) {
            // There's nothing we can do
        }
    }

    if (background != null) {
        ViewUtil.setBackground(this, background);
    }
}
 
Example #20
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the elevation of the card view, which contains the currently shown preference
 * fragment, when using the split screen layout, from the activity's theme.
 */
private void obtainCardViewElevation() {
    int elevation;

    try {
        elevation = ThemeUtil.getDimensionPixelSize(this, R.attr.cardViewElevation);
    } catch (NotFoundException e) {
        elevation = getResources().getDimensionPixelSize(R.dimen.card_view_elevation);
    }

    setCardViewElevation(pixelsToDp(this, elevation));
}
 
Example #21
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the width of the navigation from the activity's theme.
 */
private void obtainNavigationWidth() {
    int navigationWidth;

    try {
        navigationWidth = ThemeUtil.getDimensionPixelSize(this, R.attr.navigationWidth);
    } catch (NotFoundException e) {
        navigationWidth = getResources().getDimensionPixelSize(R.dimen.navigation_width);
    }

    setNavigationWidth(navigationWidth);
}
 
Example #22
Source File: SeekBarPreference.java    From AndroidMaterialPreferences with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ResourceType")
@Override
public final void setSummary(@ArrayRes final int resourceId) {
    try {
        setSummaries(getContext().getResources().getStringArray(resourceId));
    } catch (NotFoundException e) {
        super.setSummary(resourceId);
    }
}
 
Example #23
Source File: ResourcesCompat.java    From letv with Apache License 2.0 5 votes vote down vote up
@Nullable
public static ColorStateList getColorStateList(@NonNull Resources res, @ColorRes int id, @Nullable Theme theme) throws NotFoundException {
    if (VERSION.SDK_INT >= 23) {
        return ResourcesCompatApi23.getColorStateList(res, id, theme);
    }
    return res.getColorStateList(id);
}
 
Example #24
Source File: ResourcesCompat.java    From Carbon with Apache License 2.0 5 votes vote down vote up
/**
 * Used by TintTypedArray.
 *
 * @hide
 */
@RestrictTo(LIBRARY_GROUP_PREFIX)
public static Typeface getFont(@NonNull Context context, @FontRes int id, TypedValue value,
                               int style, int weight, @Nullable androidx.core.content.res.ResourcesCompat.FontCallback fontCallback) throws NotFoundException {
    if (context.isRestricted()) {
        return null;
    }
    return loadFont(context, id, value, style, weight, fontCallback, null /* handler */,
            true /* isXmlRequest */);
}
 
Example #25
Source File: RoundedImageView.java    From ChatKit with Apache License 2.0 5 votes vote down vote up
private Drawable resolveResource() {
    Drawable d = null;

    if (mResource != 0) {
        try {
            d = ContextCompat.getDrawable(getContext(), mResource);
        } catch (NotFoundException e) {
            mResource = 0;
        }
    }
    return RoundedCornerDrawable.fromDrawable(d, getResources());
}
 
Example #26
Source File: ThemeHelper.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the resource id of the theme, which is used when using a specific layout.
 *
 * @param layout
 *         The layout as a value of the enum {@link Layout}. The layout may not be null
 * @return The resource id of the theme as an {@link Integer} value
 */
public final int getThemeResourceId(@NonNull final Layout layout) {
    int themeResourceId;

    try {
        themeResourceId = obtainThemeFromXmlAttributes(layout);
    } catch (NotFoundException e) {
        themeResourceId = obtainThemeFromThemeAttributes(layout, -1);
    }

    return themeResourceId;
}
 
Example #27
Source File: ThemeHelper.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the resource id of the theme, which is used when using a specific layout. The theme
 * is obtained from the tab switcher's XML attributes. If the theme is not specified, a {@link
 * NotFoundException} will be thrown.
 *
 * @param layout
 *         The layout as a value of the enum {@link Layout}. The layout may not be null
 * @return The resource id of the theme, which is used when using the given layout, as an {@link
 * Integer} value
 */
private int obtainThemeFromXmlAttributes(@NonNull final Layout layout) {
    int result = layout == Layout.TABLET ? tabletTheme : phoneTheme;

    if (result == 0) {
        result = globalTheme;
    }

    if (result != 0) {
        return result;
    }

    throw new NotFoundException();
}
 
Example #28
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the elevation of the button bar, which is shown when using the activity as a wizard,
 * from the activity's theme.
 */
private void obtainButtonBarElevation() {
    int elevation;

    try {
        elevation = ThemeUtil.getDimensionPixelSize(this, R.attr.buttonBarElevation);
    } catch (NotFoundException e) {
        elevation = getResources().getDimensionPixelSize(R.dimen.button_bar_elevation);
    }

    setButtonBarElevation(pixelsToDp(this, elevation));
}
 
Example #29
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the text of the finish button from the activity's theme.
 */
private void obtainFinishButtonText() {
    CharSequence text;

    try {
        text = ThemeUtil.getText(this, R.attr.finishButtonText);
    } catch (NotFoundException e) {
        text = getText(R.string.finish_button_text);
    }

    setFinishButtonText(text);
}
 
Example #30
Source File: AbstractPreferenceFragment.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the appearance of the dividers, which are shown above preference categories, from the
 * activity's theme.
 */
private void obtainDividerDecoration() {
    int dividerColor;

    try {
        dividerColor = ThemeUtil.getColor(getActivity(), R.attr.dividerColor);
    } catch (NotFoundException e) {
        dividerColor =
                ContextCompat.getColor(getActivity(), R.color.preference_divider_color_light);
    }

    this.dividerDecoration.setDividerColor(dividerColor);
    this.dividerDecoration.setDividerHeight(DisplayUtil.dpToPixels(getActivity(), 1));
}