コード例 #1
0
 public static int getFontPreviewCount(ThemePackage tp) {
   List<String> list = tp.getPreviewNames();
   int count = 0;
   if (list != null) {
     for (String str : list) {
       if ((str != null) && (str.contains("preview_font"))) {
         count++;
       }
     }
   }
   return count;
 }
コード例 #2
0
  public static int useTheme(
      ThemePackage tp, Context context, MultiTheme mixTheme, String type, boolean isFontChanged) {
    if (tp == null) return RESULT_FAIL;
    try {
      MultiTheme multiTheme = mixTheme;
      String font = null, lockscreen = null;
      String fontPackage = null, lockPackage = null;
      String thirdLockPackageName = null;
      String lockwallpaper = null;
      if (tp != null && tp.isDefault()) {
        multiTheme = null;
        lockscreen = AuiThemeConstant.DEFAULT_LOCK_STYLE;
        lockPackage = tp.getThemePackage();
      }
      MultiTheme currentTheme = MultiThemeManagerProxy.getInstance().getCurrentAuiTheme();

      if (multiTheme == null && tp != null && !tp.isDefault()) {
        multiTheme = new MultiTheme(tp);
      }
      if (multiTheme != null) {
        font = multiTheme.getFont();
        lockscreen = multiTheme.getLockScreenStyle();
        fontPackage = multiTheme.getFontPackage();
        lockPackage = multiTheme.getStylePackage();
        thirdLockPackageName = multiTheme.getThirdLockPackageName();
        lockwallpaper = multiTheme.getLockScreenWallpaper();
      }
      if (!TextUtils.isEmpty(thirdLockPackageName)
          && !ThemePackageUtils.isThirdLockNeeded(thirdLockPackageName, context, true)) {
        return RESULT_CANCEL;
      }
      if (ThemeDetailHelper.THEME_TYPE_FONT.equals(type)) {
        multiTheme = new MultiTheme(currentTheme);
        multiTheme.setFont(font);
        multiTheme.setFontPackage(fontPackage);
        multiTheme.setWallpaper(null); // won't set wallpaper fix bug:43359
      } else if (ThemeDetailHelper.THEME_TYPE_LOCK_STYLE.equals(type)) {
        multiTheme = new MultiTheme(currentTheme);
        multiTheme.setLockScreenStyle(lockscreen);
        multiTheme.setStylePackage(lockPackage);
        multiTheme.setLockScreenWallpaper(lockwallpaper);
        UserSettingsSharPre.getInstance()
            .backupLockWallpaperAndType(lockwallpaper, UserSettingsSharPre.TYPE_THME);
        multiTheme.setThirdLockPackageName(thirdLockPackageName);
        multiTheme.setWallpaper(null); // won't set wallpaper fix bug:43359
      } else {
        UserSettingsSharPre.getInstance()
            .backupWallpaperAndType(
                multiTheme == null ? "" : multiTheme.getWallpaper(), UserSettingsSharPre.TYPE_THME);
      }
      isFontChanged = isFontChanged && font != null;

      if (!isFontChanged && multiTheme != null) {
        multiTheme.setFont(null);
        multiTheme.setFontPackage(null);
      }
      if (multiTheme != null) {
        multiTheme.setGoHome(true);
      }
      if (MultiThemeManagerProxy.getInstance()
          .updateAuiThemeConfig(SystemGlobal.instance().getApplicationContext(), multiTheme)) {
        if (!TextUtils.isEmpty(thirdLockPackageName)) {
          if (!thirdLockPackageName.equals(Utils.getSetThirdLockPkg(context))) {
            setThirdLock(thirdLockPackageName, context);
            Settings.Secure.putString(
                context.getContentResolver(), _3RD_PARTY_LOCKSCREEN, thirdLockPackageName);
          } else {
            openLock(thirdLockPackageName, context);
          }
        } else if (!TextUtils.isEmpty(lockscreen)) {
          // set yunos lockstyle, stop the Third lock
          closeLock(context);
          Settings.Secure.putString(context.getContentResolver(), _3RD_PARTY_LOCKSCREEN, null);
        }

        // YUNOS BEGIN PB
        // ##modules(AliTheme): ##author:[email protected]
        // ##BugID:(166388) ##date:2014/10/26
        // ##decrpition: Added support for HomeShell editmode
        DBManager.getInstance(context).updateThemeChecked(tp);
        // YUNOS END PB
        return RESULT_OK;
      }
    } catch (Exception e) {
      e.printStackTrace();
      return RESULT_FAIL;
    }
    return RESULT_FAIL;
  }