Search in sources :

Example 81 with NotFoundException

use of android.content.res.Resources.NotFoundException in project Android-Skin-Loader by fengjundev.

the class SkinInflaterFactory method parseSkinAttr.

/**
 * Collect skin able tag such as background , textColor and so on
 *
 * @param context
 * @param attrs
 * @param view
 */
private void parseSkinAttr(Context context, AttributeSet attrs, View view) {
    List<SkinAttr> viewAttrs = new ArrayList<SkinAttr>();
    for (int i = 0; i < attrs.getAttributeCount(); i++) {
        String attrName = attrs.getAttributeName(i);
        String attrValue = attrs.getAttributeValue(i);
        if (!AttrFactory.isSupportedAttr(attrName)) {
            continue;
        }
        if (attrValue.startsWith("@")) {
            try {
                int id = Integer.parseInt(attrValue.substring(1));
                String entryName = context.getResources().getResourceEntryName(id);
                String typeName = context.getResources().getResourceTypeName(id);
                SkinAttr mSkinAttr = AttrFactory.get(attrName, id, entryName, typeName);
                if (mSkinAttr != null) {
                    viewAttrs.add(mSkinAttr);
                }
            } catch (NumberFormatException e) {
                e.printStackTrace();
            } catch (NotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    if (!ListUtils.isEmpty(viewAttrs)) {
        SkinItem skinItem = new SkinItem();
        skinItem.view = view;
        skinItem.attrs = viewAttrs;
        mSkinItems.add(skinItem);
        if (SkinManager.getInstance().isExternalSkin()) {
            skinItem.apply();
        }
    }
}
Also used : SkinAttr(cn.feng.skin.manager.entity.SkinAttr) ArrayList(java.util.ArrayList) NotFoundException(android.content.res.Resources.NotFoundException) SkinItem(cn.feng.skin.manager.entity.SkinItem)

Example 82 with NotFoundException

use of android.content.res.Resources.NotFoundException in project Android-Skin-Loader by fengjundev.

the class SkinManager method getDrawable.

@SuppressLint("NewApi")
public Drawable getDrawable(int resId) {
    Drawable originDrawable = context.getResources().getDrawable(resId);
    if (mResources == null || isDefaultSkin) {
        return originDrawable;
    }
    String resName = context.getResources().getResourceEntryName(resId);
    int trueResId = mResources.getIdentifier(resName, "drawable", skinPackageName);
    Drawable trueDrawable = null;
    try {
        L.e("ttgg", "SDK_INT = " + android.os.Build.VERSION.SDK_INT);
        if (android.os.Build.VERSION.SDK_INT < 22) {
            trueDrawable = mResources.getDrawable(trueResId);
        } else {
            trueDrawable = mResources.getDrawable(trueResId, null);
        }
    } catch (NotFoundException e) {
        e.printStackTrace();
        trueDrawable = originDrawable;
    }
    return trueDrawable;
}
Also used : Drawable(android.graphics.drawable.Drawable) NotFoundException(android.content.res.Resources.NotFoundException) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 83 with NotFoundException

use of android.content.res.Resources.NotFoundException in project Android-Skin-Loader by fengjundev.

the class SkinManager method getColor.

public int getColor(int resId) {
    int originColor = context.getResources().getColor(resId);
    if (mResources == null || isDefaultSkin) {
        return originColor;
    }
    String resName = context.getResources().getResourceEntryName(resId);
    int trueResId = mResources.getIdentifier(resName, "color", skinPackageName);
    int trueColor = 0;
    try {
        trueColor = mResources.getColor(trueResId);
    } catch (NotFoundException e) {
        e.printStackTrace();
        trueColor = originColor;
    }
    return trueColor;
}
Also used : NotFoundException(android.content.res.Resources.NotFoundException) SuppressLint(android.annotation.SuppressLint)

Example 84 with NotFoundException

use of android.content.res.Resources.NotFoundException in project Anki-Android by Ramblurr.

the class DeckPicker method onPrepareDialog.

@Override
protected void onPrepareDialog(int id, Dialog dialog) {
    Resources res = getResources();
    StyledDialog ad = (StyledDialog) dialog;
    switch(id) {
        case DIALOG_DELETE_DECK:
            if (!AnkiDroidApp.colIsOpen() || mDeckList == null || mDeckList.size() == 0) {
                return;
            }
            boolean isDyn = AnkiDroidApp.getCol().getDecks().isDyn(mCurrentDid);
            if (isDyn) {
                ad.setMessage(String.format(res.getString(R.string.delete_cram_deck_message), "\'" + AnkiDroidApp.getCol().getDecks().name(mCurrentDid) + "\'"));
            } else {
                ad.setMessage(String.format(res.getString(R.string.delete_deck_message), "\'" + AnkiDroidApp.getCol().getDecks().name(mCurrentDid) + "\'"));
            }
            break;
        case DIALOG_CONTEXT_MENU:
            if (!AnkiDroidApp.colIsOpen() || mDeckList == null || mDeckList.size() == 0) {
                return;
            }
            mCurrentDid = Long.parseLong(mDeckList.get(mContextMenuPosition).get("did"));
            try {
                ad.changeListItem(CONTEXT_MENU_COLLAPSE_DECK, getResources().getString(AnkiDroidApp.getCol().getDecks().get(mCurrentDid).getBoolean("collapsed") ? R.string.contextmenu_deckpicker_inflate_deck : R.string.contextmenu_deckpicker_collapse_deck));
            } catch (NotFoundException e) {
            // do nothing
            } catch (JSONException e) {
            // do nothing
            }
            ad.setTitle(AnkiDroidApp.getCol().getDecks().name(mCurrentDid));
            break;
        case DIALOG_IMPORT_LOG:
        case DIALOG_SYNC_LOG:
        case DIALOG_SYNC_SANITY_ERROR:
            // If both have text, separate them by a new line.
            if (!TextUtils.isEmpty(mDialogMessage) && !TextUtils.isEmpty(mSyncMessage)) {
                ad.setMessage(mDialogMessage + "\n\n" + mSyncMessage);
            } else if (!TextUtils.isEmpty(mDialogMessage)) {
                ad.setMessage(mDialogMessage);
            } else {
                ad.setMessage(mSyncMessage);
            }
            break;
        case DIALOG_DB_ERROR:
            mLoadFailed = false;
            ad.getButton(Dialog.BUTTON3).setEnabled(hasErrorFiles());
            break;
        case DIALOG_LOAD_FAILED:
            mLoadFailed = true;
            if (mOpenCollectionDialog != null && mOpenCollectionDialog.isShowing()) {
                mOpenCollectionDialog.setMessage(res.getString(R.string.col_load_failed));
            }
            break;
        case DIALOG_ERROR_HANDLING:
            ArrayList<String> options = new ArrayList<String>();
            ArrayList<Integer> values = new ArrayList<Integer>();
            if (AnkiDroidApp.getCol() == null) {
                // retry
                options.add(res.getString(R.string.backup_retry_opening));
                values.add(0);
            } else {
                // fix integrity
                options.add(res.getString(R.string.check_db));
                values.add(1);
            }
            // repair db with sqlite
            options.add(res.getString(R.string.backup_error_menu_repair));
            values.add(2);
            // // restore from backup
            options.add(res.getString(R.string.backup_restore));
            values.add(3);
            // delete old collection and build new one
            options.add(res.getString(R.string.backup_full_sync_from_server));
            values.add(4);
            // delete old collection and build new one
            options.add(res.getString(R.string.backup_del_collection));
            values.add(5);
            String[] titles = new String[options.size()];
            mRepairValues = new int[options.size()];
            for (int i = 0; i < options.size(); i++) {
                titles[i] = options.get(i);
                mRepairValues[i] = values.get(i);
            }
            ad.setItems(titles, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    switch(mRepairValues[which]) {
                        case 0:
                            loadCollection();
                            return;
                        case 1:
                            integrityCheck();
                            return;
                        case 2:
                            showDialog(DIALOG_REPAIR_COLLECTION);
                            return;
                        case 3:
                            showDialog(DIALOG_RESTORE_BACKUP);
                            return;
                        case 4:
                            showDialog(DIALOG_FULL_SYNC_FROM_SERVER);
                            return;
                        case 5:
                            showDialog(DIALOG_NEW_COLLECTION);
                            return;
                    }
                }
            });
            break;
        case DIALOG_IMPORT_SELECT:
            List<File> fileList = Utils.getImportableDecks();
            if (fileList.size() == 0) {
                Themes.showThemedToast(DeckPicker.this, getResources().getString(R.string.upgrade_import_no_file_found), false);
            }
            ad.setEnabled(fileList.size() != 0);
            String[] tts = new String[fileList.size()];
            mImportValues = new String[fileList.size()];
            for (int i = 0; i < tts.length; i++) {
                tts[i] = fileList.get(i).getName().replace(".apkg", "");
                mImportValues[i] = fileList.get(i).getAbsolutePath();
            }
            ad.setItems(tts, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mImportPath = mImportValues[which];
                    switch(mImportMethod) {
                        case IMPORT_METHOD_ADD:
                            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT, mImportAddListener, new TaskData(AnkiDroidApp.getCol(), mImportPath, false));
                            mImportPath = null;
                            break;
                        case IMPORT_METHOD_REPLACE:
                            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT_REPLACE, mImportReplaceListener, new TaskData(AnkiDroidApp.getCol(), mImportPath));
                            mImportPath = null;
                            break;
                        case IMPORT_METHOD_ASK:
                        default:
                            showDialog(DIALOG_IMPORT);
                    }
                    mImportMethod = IMPORT_METHOD_ASK;
                }
            });
            break;
    }
}
Also used : DialogInterface(android.content.DialogInterface) StyledDialog(com.ichi2.themes.StyledDialog) ArrayList(java.util.ArrayList) NotFoundException(android.content.res.Resources.NotFoundException) JSONException(org.json.JSONException) TaskData(com.ichi2.async.DeckTask.TaskData) Resources(android.content.res.Resources) File(java.io.File)

Example 85 with NotFoundException

use of android.content.res.Resources.NotFoundException in project platform_frameworks_base by android.

the class AnimatorInflater method loadStateListAnimator.

public static StateListAnimator loadStateListAnimator(Context context, int id) throws NotFoundException {
    final Resources resources = context.getResources();
    final ConfigurationBoundResourceCache<StateListAnimator> cache = resources.getStateListAnimatorCache();
    final Theme theme = context.getTheme();
    StateListAnimator animator = cache.getInstance(id, resources, theme);
    if (animator != null) {
        return animator;
    }
    XmlResourceParser parser = null;
    try {
        parser = resources.getAnimation(id);
        animator = createStateListAnimatorFromXml(context, parser, Xml.asAttributeSet(parser));
        if (animator != null) {
            animator.appendChangingConfigurations(getChangingConfigs(resources, id));
            final ConstantState<StateListAnimator> constantState = animator.createConstantState();
            if (constantState != null) {
                cache.put(id, theme, constantState);
                // return a clone so that the animator in constant state is never used.
                animator = constantState.newInstance(resources, theme);
            }
        }
        return animator;
    } catch (XmlPullParserException ex) {
        Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load state list animator resource ID #0x" + Integer.toHexString(id));
        rnf.initCause(ex);
        throw rnf;
    } catch (IOException ex) {
        Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load state list animator resource ID #0x" + Integer.toHexString(id));
        rnf.initCause(ex);
        throw rnf;
    } finally {
        if (parser != null) {
            parser.close();
        }
    }
}
Also used : NotFoundException(android.content.res.Resources.NotFoundException) XmlResourceParser(android.content.res.XmlResourceParser) Theme(android.content.res.Resources.Theme) NotFoundException(android.content.res.Resources.NotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources) IOException(java.io.IOException)

Aggregations

NotFoundException (android.content.res.Resources.NotFoundException)165 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)49 Resources (android.content.res.Resources)47 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)45 FileNotFoundException (java.io.FileNotFoundException)34 IOException (java.io.IOException)34 ApplicationInfo (android.content.pm.ApplicationInfo)31 File (java.io.File)30 InputStream (java.io.InputStream)28 FileInputStream (java.io.FileInputStream)20 Drawable (android.graphics.drawable.Drawable)19 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)16 Nullable (android.annotation.Nullable)15 XmlResourceParser (android.content.res.XmlResourceParser)12 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)12 ArrayResourceValue (com.android.ide.common.rendering.api.ArrayResourceValue)12 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)12 NonNull (android.annotation.NonNull)10 ColorDrawable (android.graphics.drawable.ColorDrawable)10 DensityBasedResourceValue (com.android.ide.common.rendering.api.DensityBasedResourceValue)8