のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

CyanogenMod Theme

    private Typeface loadTypeface(Family family, int style) {
        AssetManager assets = mThemeContext.getAssets();
        String path = FONTS_DIR + family.fileset.get(style);
        return Typeface.createFromAsset(assets, path);
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPkgName = getArguments().getString(PKG_EXTRA);

        ThemedTypefaceHelper helper = new ThemedTypefaceHelper();
        helper.load(getActivity(), mPkgName);
        mTypefaceNormal = helper.getTypeface(Typeface.NORMAL);
        mTypefaceBold = helper.getTypeface(Typeface.BOLD);
        mTypefaceItalic = helper.getTypeface(Typeface.ITALIC);
        mTypefaceBoldItalic = helper.getTypeface(Typeface.BOLD_ITALIC);
    }
      public void bindFontView(View view, Context context, String pkgName) {
            FontItemHolder item = (FontItemHolder) view.getTag();
            ThemedTypefaceHelper helper = new ThemedTypefaceHelper();
            helper.load(mContext, pkgName);
            Typeface typefaceNormal = helper.getTypeface(Typeface.NORMAL);
            Typeface typefaceBold = helper.getTypeface(Typeface.BOLD);
            item.textView.setTypeface(typefaceNormal);
            item.textViewBold.setTypeface(typefaceBold);
        }
    private static final String TAG = NotificationHijackingService.class.getName();
    private static final String GOOGLE_PLAY_PACKAGE_NAME = "com.android.vending";
    private static final String ACTION_INSTALLED =
            "com.android.vending.SUCCESSFULLY_INSTALLED_CLICKED";
    private static final String EXTRA_PACKAGE_NAME = "package_name";
  private boolean updateFonts() {
        //Clear the font dir
        ThemeUtils.deleteFilesInDir(ThemeUtils.SYSTEM_THEME_FONT_PATH);

        if (!mPkgName.equals(HOLO_DEFAULT)) {
            //Get Font Assets
            Context themeCtx;
            String[] assetList;
            try {
                themeCtx = mContext.createPackageContext(mPkgName, Context.CONTEXT_IGNORE_SECURITY);
                AssetManager assetManager = themeCtx.getAssets();
                assetList = assetManager.list("fonts");
            } catch (Exception e) {
                Log.e(TAG, "There was an error getting assets  for pkg " + mPkgName, e);
                return false;
            }
            if (assetList == null || assetList.length == 0) {
                Log.e(TAG, "Could not find any font assets");
                return false;
            }

            //Copy font assets to font dir
            for(String asset : assetList) {
                InputStream is = null;
                OutputStream os = null;
                try {
                    is = ThemeUtils.getInputStreamFromAsset(themeCtx, "file:///android_asset/fonts/" + asset);
                    File outFile = new File(ThemeUtils.SYSTEM_THEME_FONT_PATH, asset);
                    FileUtils.copyToFile(is, outFile);
                    FileUtils.setPermissions(outFile, FileUtils.S_IRWXU|FileUtils.S_IRGRP|FileUtils.S_IRWXO, -1, -1);
                } catch (Exception e) {
                    Log.e(TAG, "There was an error installing the new fonts for pkg " + mPkgName, e);
                    return false;
                } finally {
                    ThemeUtils.closeQuietly(is);
                    ThemeUtils.closeQuietly(os);
                }
            }
        }

        //Notify zygote that themes need a refresh
        SystemProperties.set("sys.refresh_theme", "1");
        return true;
    }
 // path to external theme resources, i.e. bootanimation.zip
    public static final String SYSTEM_THEME_PATH = "/data/system/theme";
    public static final String SYSTEM_THEME_FONT_PATH = SYSTEM_THEME_PATH + File.separator + "fonts";