/** * A simple constructor for SQLiteOpenHelper with null for CursorFactory as * default. * * @param dbName * The database file. * @param version * (SQLiteDatabase, int, int) will be used to upgrade the * database; if the database is newer, * onDowngrade(SQLiteDatabase, int, int) will be used to * downgrade the database */ LitePalOpenHelper(String dbName, int version) { this(LitePalApplication.getContext(), dbName, null, version); }
@Override public void onCreate() { super.onCreate(); applicationContext = getApplicationContext(); LitePalApplication.initialize(this); Config.createConfig(this); PageFactory.createPageFactory(this); }
@Override public void onCreate() { super.onCreate(); //滑动返回注册 registerActivityLifecycleCallbacks(ActivityLifecycleHelper.build()); } }
@Override public void onCreate() { super.onCreate(); //**************************************相关第三方SDK的初始化等操作************************************************* KLog.init(BuildConfig.DEBUG);//初始化KLog LitePalApplication.initialize(getApplicationContext());//初始化litePal registerActivityLifecycleCallbacks(ParallaxHelper.getInstance()); } }
@Override public void onTerminate() { super.onTerminate(); }
@Override public void onCreate() { super.onCreate(); Resources resources = getResources(); DisplayMetrics dm = resources.getDisplayMetrics(); Configuration config = resources.getConfiguration(); // 应用用户选择语言 String language = SPUtil.getInstance(this).getLanguage(); if ("".equals(language)){ language =Locale.getDefault().getLanguage(); } if (language.equals(SPUtil.LANGUAGE_CHINESE)) { config.setLocale(Locale.getDefault()); } else { config.setLocale(Locale.ENGLISH); } resources.updateConfiguration(config, dm); mContext=getApplicationContext(); }
@Override public void onCreate() { super.onCreate(); context = getApplicationContext(); LitePalApplication.initialize(context); requestQueue = Volley.newRequestQueue(context); }
/** * Get the last database version. * @param extraKeyName * Pass the name of the using database usually. Pass null if it's default database. * @return the last database version */ public static int getLastVersion(String extraKeyName) { SharedPreferences sPref = LitePalApplication.getContext().getSharedPreferences( LITEPAL_PREPS, Context.MODE_PRIVATE); if (TextUtils.isEmpty(extraKeyName)) { return sPref.getInt(VERSION, 0); } else { if (extraKeyName.endsWith(Const.Config.DB_NAME_SUFFIX)) { extraKeyName = extraKeyName.replace(Const.Config.DB_NAME_SUFFIX, ""); } return sPref.getInt(VERSION + "_" + extraKeyName, 0); } }
@Override public void onCreate() { super.onCreate();
/** * Remove the version with specified extra key name. * @param extraKeyName * Pass the name of the using database usually. Pass null if it's default database. */ public static void removeVersion(String extraKeyName) { SharedPreferences.Editor sEditor = LitePalApplication.getContext() .getSharedPreferences(LITEPAL_PREPS, Context.MODE_PRIVATE).edit(); if (TextUtils.isEmpty(extraKeyName)) { sEditor.remove(VERSION); } else { if (extraKeyName.endsWith(Const.Config.DB_NAME_SUFFIX)) { extraKeyName = extraKeyName.replace(Const.Config.DB_NAME_SUFFIX, ""); } sEditor.remove(VERSION + "_" + extraKeyName); } sEditor.apply(); }
/** * Each time database upgrade, the version of database stored in shared * preference will update. * @param extraKeyName * Pass the name of the using database usually. Pass null if it's default database. * @param newVersion * new version of database */ public static void updateVersion(String extraKeyName, int newVersion) { SharedPreferences.Editor sEditor = LitePalApplication.getContext() .getSharedPreferences(LITEPAL_PREPS, Context.MODE_PRIVATE).edit(); if (TextUtils.isEmpty(extraKeyName)) { sEditor.putInt(VERSION, newVersion); } else { if (extraKeyName.endsWith(Const.Config.DB_NAME_SUFFIX)) { extraKeyName = extraKeyName.replace(Const.Config.DB_NAME_SUFFIX, ""); } sEditor.putInt(VERSION + "_" + extraKeyName, newVersion); } sEditor.apply(); }
private InputStream getInputStream() throws IOException { AssetManager assetManager = LitePalApplication.getContext().getAssets(); String[] fileNames = assetManager.list(""); if (fileNames != null && fileNames.length > 0) { for (String fileName : fileNames) { if (Const.Config.CONFIGURATION_FILE_NAME.equalsIgnoreCase(fileName)) { return assetManager.open(fileName, AssetManager.ACCESS_BUFFER); } } } throw new ParseConfigurationFileException( ParseConfigurationFileException.CAN_NOT_FIND_LITEPAL_FILE); }
/** * If the litepal.xml configuration file exists. * @return True if exists, false otherwise. */ public static boolean isLitePalXMLExists() { try { AssetManager assetManager = LitePalApplication.getContext().getAssets(); String[] fileNames = assetManager.list(""); if (fileNames != null && fileNames.length > 0) { for (String fileName : fileNames) { if (Const.Config.CONFIGURATION_FILE_NAME.equalsIgnoreCase(fileName)) { return true; } } } } catch (IOException e) { } return false; }
/** * Iterates all files in the root of assets folder. If find litepal.xml, * open this file and return the input stream. Or throw * ParseConfigurationFileException. * * @return The input stream of litepal.xml. * @throws java.io.IOException */ private InputStream getConfigInputStream() throws IOException { AssetManager assetManager = LitePalApplication.getContext().getAssets(); String[] fileNames = assetManager.list(""); if (fileNames != null && fileNames.length > 0) { for (String fileName : fileNames) { if (Const.Config.CONFIGURATION_FILE_NAME.equalsIgnoreCase(fileName)) { return assetManager.open(fileName, AssetManager.ACCESS_BUFFER); } } } throw new ParseConfigurationFileException( ParseConfigurationFileException.CAN_NOT_FIND_LITEPAL_FILE); } }
dbName = dbName + Const.Config.DB_NAME_SUFFIX; File dbFile = LitePalApplication.getContext().getDatabasePath(dbName); if (dbFile.exists()) { boolean result = dbFile.delete(); String path = LitePalApplication.getContext().getExternalFilesDir("") + "/databases/"; dbFile = new File(path + dbName); boolean result = dbFile.delete();
String dbName = litePalAttr.getDbName(); if ("external".equalsIgnoreCase(litePalAttr.getStorage())) { dbName = LitePalApplication.getContext().getExternalFilesDir("") + "/databases/" + dbName; } else if (!"internal".equalsIgnoreCase(litePalAttr.getStorage()) && !TextUtils.isEmpty(litePalAttr.getStorage())) { dbPath = dbPath.replace("//", "/"); if (BaseUtility.isClassAndMethodExist("android.support.v4.content.ContextCompat", "checkSelfPermission") && ContextCompat.checkSelfPermission(LitePalApplication.getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { throw new DatabaseGenerateException(String.format(DatabaseGenerateException.EXTERNAL_STORAGE_PERMISSION_DENIED, dbPath));
/** * A simple constructor for SQLiteOpenHelper with null for CursorFactory as * default. * * @param dbName * The database file. * @param version * (SQLiteDatabase, int, int) will be used to upgrade the * database; if the database is newer, * onDowngrade(SQLiteDatabase, int, int) will be used to * downgrade the database */ LitePalOpenHelper(String dbName, int version) { this(LitePalApplication.getContext(), dbName, null, version); }
/** * Get the last database version. * * @return the last database version */ public static int getLastVersion() { SharedPreferences sPref = LitePalApplication.getContext().getSharedPreferences( LITEPAL_PREPS, Context.MODE_PRIVATE); int version = sPref.getInt(VERSION, 0); return version; }
/** * Each time database upgrade, the version of database stored in shared * preference will update. * * @param newVersion */ public static void updateVersion(int newVersion) { SharedPreferences.Editor sEditor = LitePalApplication.getContext() .getSharedPreferences(LITEPAL_PREPS, Context.MODE_PRIVATE).edit(); sEditor.putInt(VERSION, newVersion); sEditor.commit(); }
/** * Iterates all files in the root of assets folder. If find litepal.xml, * open this file and return the input stream. Or throw * ParseConfigurationFileException. * * @return The input stream of litepal.xml. * @throws java.io.IOException */ private InputStream getConfigInputStream() throws IOException { AssetManager assetManager = LitePalApplication.getContext().getAssets(); String[] fileNames = assetManager.list(""); if (fileNames != null && fileNames.length > 0) { for (String fileName : fileNames) { if (Const.LitePal.CONFIGURATION_FILE_NAME.equalsIgnoreCase(fileName)) { return assetManager.open(fileName, AssetManager.ACCESS_BUFFER); } } } throw new ParseConfigurationFileException( ParseConfigurationFileException.CAN_NOT_FIND_LITEPAL_FILE); } }