本文整理汇总了Java中de.j4velin.pedometer.Database类的典型用法代码示例。如果您正苦于以下问题:Java Database类的具体用法?Java Database怎么用?Java Database使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Database类属于de.j4velin.pedometer包,在下文中一共展示了Database类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReceive
import de.j4velin.pedometer.Database; //导入依赖的package包/类
@Override
public void onReceive(final Context context, final Intent intent) {
if (BuildConfig.DEBUG) Logger.log("shutting down");
context.startService(new Intent(context, SensorListener.class));
// if the user used a root script for shutdown, the DEVICE_SHUTDOWN
// broadcast might not be send. Therefore, the app will check this
// setting on the next boot and displays an error message if it's not
// set to true
context.getSharedPreferences("pedometer", Context.MODE_MULTI_PROCESS).edit()
.putBoolean("correctShutdown", true).commit();
Database db = Database.getInstance(context);
db.updateSteps(Util.getToday(), db.getCurrentSteps());
// current steps will be reset on boot @see BootReceiver
db.close();
}
示例2: onSensorChanged
import de.j4velin.pedometer.Database; //导入依赖的package包/类
@Override
public void onSensorChanged(final SensorEvent event) {
steps = (int) event.values[0];
if (WAIT_FOR_VALID_STEPS && steps > 0) {
WAIT_FOR_VALID_STEPS = false;
Database db = Database.getInstance(this);
if (db.getSteps(Util.getToday()) == Integer.MIN_VALUE) {
int pauseDifference = steps -
getSharedPreferences("pedometer", Context.MODE_MULTI_PROCESS)
.getInt("pauseCount", steps);
db.insertNewDay(Util.getToday(), steps - pauseDifference);
if (pauseDifference > 0) {
// update pauseCount for the new day
getSharedPreferences("pedometer", Context.MODE_MULTI_PROCESS).edit()
.putInt("pauseCount", steps).commit();
}
reRegisterSensor();
}
db.saveCurrentSteps(steps);
db.close();
updateNotificationState();
}
}
示例3: onReceive
import de.j4velin.pedometer.Database; //导入依赖的package包/类
@Override
public void onReceive(final Context context, final Intent intent) {
SharedPreferences prefs =
context.getSharedPreferences("pedometer", Context.MODE_MULTI_PROCESS);
TimeZone oldTimeZone =
TimeZone.getTimeZone(prefs.getString("timezone", TimeZone.getDefault().getID()));
TimeZone newTimeZone = TimeZone.getTimeZone(intent.getStringExtra("time-zone"));
if (BuildConfig.DEBUG) {
Logger.log("timezone changed: new: " + newTimeZone.getRawOffset() + " old: " +
oldTimeZone.getRawOffset());
}
Database db = Database.getInstance(context);
db.timeZoneChanged(newTimeZone.getRawOffset() - oldTimeZone.getRawOffset());
db.close();
prefs.edit().putString("timezone", intent.getStringExtra("time-zone")).commit();
}
示例4: updateNotificationState
import de.j4velin.pedometer.Database; //导入依赖的package包/类
private void updateNotificationState() {
if (BuildConfig.DEBUG) Logger.log("SensorListener updateNotificationState");
SharedPreferences prefs = getSharedPreferences("pedometer", Context.MODE_MULTI_PROCESS);
NotificationManager nm =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (prefs.getBoolean("notification", true)) {
int goal = prefs.getInt("goal", 10000);
Database db = Database.getInstance(this);
int today_offset = db.getSteps(Util.getToday());
db.close();
Notification.Builder notificationBuilder = new Notification.Builder(this);
if (steps > 0) {
if (today_offset == Integer.MIN_VALUE) today_offset = -steps;
notificationBuilder.setProgress(goal, today_offset + steps, false).setContentText(
today_offset + steps >= goal ? getString(R.string.goal_reached_notification,
NumberFormat.getInstance(Locale.getDefault())
.format((today_offset + steps))) :
getString(R.string.notification_text,
NumberFormat.getInstance(Locale.getDefault())
.format((goal - today_offset - steps))));
} else {
notificationBuilder
.setContentText(getString(R.string.your_progress_will_be_shown_here_soon));
}
boolean isPaused = prefs.contains("pauseCount");
notificationBuilder.setPriority(Notification.PRIORITY_MIN).setShowWhen(false)
.setContentTitle(isPaused ? getString(R.string.ispaused) :
getString(R.string.notification_title)).setContentIntent(PendingIntent
.getActivity(this, 0, new Intent(this, Activity_Main.class),
PendingIntent.FLAG_UPDATE_CURRENT)).setSmallIcon(R.drawable.ic_launcher)
.addAction(isPaused ? R.drawable.ic_resume : R.drawable.ic_pause,
isPaused ? getString(R.string.resume) : getString(R.string.pause),
PendingIntent.getService(this, 4, new Intent(this, SensorListener.class)
.putExtra("action", ACTION_PAUSE),
PendingIntent.FLAG_UPDATE_CURRENT)).setOngoing(true);
nm.notify(1, notificationBuilder.build());
} else {
nm.cancel(1);
}
}
示例5: onStartCommand
import de.j4velin.pedometer.Database; //导入依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Database db = Database.getInstance(this);
int steps = Math.max(db.getCurrentSteps() + db.getSteps(Util.getToday()), 0);
db.close();
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(WidgetUpdateService.this);
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(WidgetUpdateService.this, Widget.class));
for (int appWidgetId : appWidgetIds) {
appWidgetManager.updateAppWidget(appWidgetId, Widget.updateWidget(appWidgetId, WidgetUpdateService.this, steps));
}
stopSelf();
return START_NOT_STICKY;
}
示例6: onUpdateData
import de.j4velin.pedometer.Database; //导入依赖的package包/类
@Override
protected void onUpdateData(int reason) {
ExtensionData data = new ExtensionData();
Database db = Database.getInstance(this);
int steps = Math.max(db.getCurrentSteps() + db.getSteps(Util.getToday()), 0);
data.visible(true).status(Fragment_Overview.formatter.format(steps)).icon(R.drawable.ic_dashclock)
.clickIntent(new Intent(DashClock.this, Activity_Main.class));
db.close();
publishUpdate(data);
}