本文整理汇总了Java中org.litepal.LitePalApplication类的典型用法代码示例。如果您正苦于以下问题:Java LitePalApplication类的具体用法?Java LitePalApplication怎么用?Java LitePalApplication使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LitePalApplication类属于org.litepal包,在下文中一共展示了LitePalApplication类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildConnection
import org.litepal.LitePalApplication; //导入依赖的package包/类
/**
* Build a connection to the database. This progress will analysis the
* litepal.xml file, and will check if the fields in LitePalAttr are valid,
* and it will open a SQLiteOpenHelper to decide to create tables or update
* tables or doing nothing depends on the version attributes.
*
* After all the stuffs above are finished. This method will return a
* LitePalHelper object.Notes this method could throw a lot of exceptions.
*
* @return LitePalHelper object.
*
* @throws org.litepal.exceptions.InvalidAttributesException
*/
private static LitePalOpenHelper buildConnection() {
LitePalAttr litePalAttr = LitePalAttr.getInstance();
litePalAttr.checkSelfValid();
if (mLitePalHelper == null) {
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())) {
// internal or empty means internal storage, neither or them means sdcard storage
String dbPath = Environment.getExternalStorageDirectory().getPath() + "/" + 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));
}
File path = new File(dbPath);
if (!path.exists()) {
path.mkdirs();
}
dbName = dbPath + "/" + dbName;
}
mLitePalHelper = new LitePalOpenHelper(dbName, litePalAttr.getVersion());
}
return mLitePalHelper;
}
示例2: isLitePalXMLExists
import org.litepal.LitePalApplication; //导入依赖的package包/类
/**
* 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;
}
示例3: onCreate
import org.litepal.LitePalApplication; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
mContext = getApplicationContext();
//初始化 Bugly
CrashReport.initCrashReport(getApplicationContext(), StaticClass.BUGLY_APP_ID, true);
//初始化 Bmob
Bmob.initialize(this, StaticClass.BMOB_APP_ID);
//初始化语音识别
SpeechUtility.createUtility(getApplicationContext(), SpeechConstant.APPID + "=" +
StaticClass.VOICE_KEY);
//初始化百度地图
SDKInitializer.initialize(getApplicationContext());
//初始化litepal
LitePalApplication.initialize(getApplicationContext());
}
示例4: getConfigInputStream
import org.litepal.LitePalApplication; //导入依赖的package包/类
/**
* 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);
}
示例5: updateVersion
import org.litepal.LitePalApplication; //导入依赖的package包/类
/**
* 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();
}
示例6: getLastVersion
import org.litepal.LitePalApplication; //导入依赖的package包/类
/**
* 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);
}
}
示例7: removeVersion
import org.litepal.LitePalApplication; //导入依赖的package包/类
/**
* 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();
}
示例8: getInputStream
import org.litepal.LitePalApplication; //导入依赖的package包/类
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);
}
示例9: onCreate
import org.litepal.LitePalApplication; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
application = this;
LitePalApplication.initialize(context);
CrashReport.initCrashReport(getApplicationContext(), "e408f695f4", false);
}
示例10: pushCmtNotify
import org.litepal.LitePalApplication; //导入依赖的package包/类
private void pushCmtNotify(CmtNotifyItem cmtNotifyItem){
Intent mainIntent = RantActivity.newIntent(LitePalApplication.getContext(), cmtNotifyItem.getRantId());
PendingIntent pi = PendingIntent.getActivity(this, 0, mainIntent, 0);
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle("Rant社区")
.setContentText(cmtNotifyItem.getUserName()+"回复你说: "+cmtNotifyItem.getCommentContent())
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_user)
.setLargeIcon(BitmapFactory.decodeResource(LitePalApplication.getContext().getResources(),R.mipmap.ic_launcher))
.setContentIntent(pi)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setAutoCancel(true)
.build();
manager.notify(0,notification);
}
示例11: pushStarNotify
import org.litepal.LitePalApplication; //导入依赖的package包/类
private void pushStarNotify(StarNotifyItem starNotifyItem){
Intent mainIntent = RantActivity.newIntent(LitePalApplication.getContext(), starNotifyItem.getRantId());
PendingIntent pi = PendingIntent.getActivity(this, 0, mainIntent, 0);
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle("Rant社区")
.setContentText(starNotifyItem.getStarValue()==1?starNotifyItem.getUserName()+"赞了你,点击这里查看":starNotifyItem.getUserName()+"朝你扔了鸡蛋,点击这里查看")
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_user)
.setLargeIcon(BitmapFactory.decodeResource(LitePalApplication.getContext().getResources(),R.mipmap.ic_launcher))
.setContentIntent(pi)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setAutoCancel(true)
.build();
manager.notify(0,notification);
}
示例12: onCreate
import org.litepal.LitePalApplication; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
this.mContext=getApplicationContext();
mHandler=new Handler();
mainThreadId=android.os.Process.myTid(); //获取主线程id
Bmob.initialize(this, "c3afc6b5c969611f04beb79125e3ec2f");
LitePalApplication.initialize(this);
ZXingLibrary.initDisplayOpinion(this);
getSharedPreferences("config",MODE_PRIVATE).edit().putBoolean("night", false).commit();
}
示例13: onCreate
import org.litepal.LitePalApplication; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
//程序崩溃错误捕捉
CrashHandler crashHandler = CrashHandler.getInstance();
crashHandler.init(context);
LitePalApplication.initialize(context);
}
示例14: onCreate
import org.litepal.LitePalApplication; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
application = this;
LitePalApplication.initialize(context);
CrashReport.initCrashReport(getApplicationContext(), "398dc6145b", false);
}
示例15: onCreate
import org.litepal.LitePalApplication; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
/***
* 初始化定位sdk,建议在Application中创建
*/
locationService = new LocationService(getApplicationContext());
mVibrator =(Vibrator)getApplicationContext().getSystemService(Service.VIBRATOR_SERVICE);
SDKInitializer.initialize(getApplicationContext());
LitePalApplication.initialize(this);
}