本文整理汇总了Java中com.firebase.jobdispatcher.Constraint类的典型用法代码示例。如果您正苦于以下问题:Java Constraint类的具体用法?Java Constraint怎么用?Java Constraint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Constraint类属于com.firebase.jobdispatcher包,在下文中一共展示了Constraint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scheduleJob
import com.firebase.jobdispatcher.Constraint; //导入依赖的package包/类
private static boolean scheduleJob(Context context) {
FirebaseJobDispatcher dispatcher = getDispatcher(context);
Job job = dispatcher.newJobBuilder()
.setService(UploadService.class)
.setTag(context.getPackageName() + ".uploadqueue")
.setConstraints(Constraint.ON_ANY_NETWORK)
.setTrigger(Trigger.NOW)
.setLifetime(Lifetime.FOREVER)
.setRecurring(false)
.setReplaceCurrent(true)
.build();
int result = dispatcher.schedule(job);
if (result == FirebaseJobDispatcher.SCHEDULE_RESULT_SUCCESS) {
Logger.v("Job scheduled");
return true;
} else {
Logger.v("Job not scheduled");
return false;
}
}
示例2: syncImmediately
import com.firebase.jobdispatcher.Constraint; //导入依赖的package包/类
synchronized public static void syncImmediately(Context context, String tag) {
Timber.d("Scheduling a immediate sync");
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver
(context));
Bundle bundle = new Bundle();
Job myJob = dispatcher.newJobBuilder()
.setService(QuoteJobService.class)
.setTag(tag)
.setExtras(bundle)
.setRecurring(false)
.setTrigger(Trigger.executionWindow(0, 0))
.setLifetime(Lifetime.UNTIL_NEXT_BOOT)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
.setReplaceCurrent(true)
.build();
dispatcher.mustSchedule(myJob);
}
示例3: onSetupComplete
import com.firebase.jobdispatcher.Constraint; //导入依赖的package包/类
@SuppressLint("ApplySharedPref")
private void onSetupComplete() {
//download whole leaderboards data asynchronously
new FetchLeaderBoardDataAsync(this).execute();
//schedule daily sync at 3:00 am local time
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
DateTime now = new DateTime();
DateTime tomorrow = now.plusDays(1).withTimeAtStartOfDay().plusHours(3);
int windowStart = Hours.hoursBetween(now, tomorrow).getHours() * 60 * 60;
Job synJob = dispatcher.newJobBuilder()
.setService(SyncScheduler.class)
.setTag(Constants.PERIODIC_SYNC_SCHEDULE_KEY)
.setReplaceCurrent(true)
.setTrigger(Trigger.executionWindow(windowStart, windowStart + 10))
.setConstraints(Constraint.ON_ANY_NETWORK)
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.build();
dispatcher.mustSchedule(synJob);
sharedPreferences.edit().putBoolean(Constants.PREF_FIREBASE_SETUP, true).commit();
startActivity(new Intent(this, PreChecksActivity.class));
finish();
}
示例4: scheduleFirebaseJobDispatcherSync
import com.firebase.jobdispatcher.Constraint; //导入依赖的package包/类
static void scheduleFirebaseJobDispatcherSync(@NonNull final Context context) {
Driver driver = new GooglePlayDriver(context);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
/* Create the Job to periodically sync Sunshine */
Job syncSunshineJob = dispatcher.newJobBuilder()
.setService(NewsFirebaseJobService.class)
.setTag(NEWS_SYNC_TAG)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setLifetime(Lifetime.FOREVER)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(
REMINDER_INTERVAL_SECONDS,
REMINDER_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS))
.setReplaceCurrent(true)
.build();
dispatcher.schedule(syncSunshineJob);
}
示例5: scheduleJob
import com.firebase.jobdispatcher.Constraint; //导入依赖的package包/类
public static void scheduleJob(Context context, Message message) {
try {
Bundle bundle = new Bundle();
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
bundle.putString(MobiComKitConstants.AL_MESSAGE_KEY, message.getKeyString());
Class pushNotificationJobServiceClass = Class.forName("com.applozic.mobicomkit.uiwidgets.notification.PushNotificationJobService");
Job myJob = dispatcher.newJobBuilder()
.setService(pushNotificationJobServiceClass) // the JobService that will be called
.setTag(MobiComKitConstants.PUSH_NOTIFICATION_DISPATCHER) // uniquely identifies the job
.setRecurring(false)
.setTrigger(Trigger.executionWindow(0, 0))
.setReplaceCurrent(true)
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setExtras(bundle)
.build();
dispatcher.mustSchedule(myJob);
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: scheduleImageService
import com.firebase.jobdispatcher.Constraint; //导入依赖的package包/类
@Override
public void scheduleImageService(FirebaseJobDispatcher dispatcher) {
dispatcher
.newJobBuilder()
.setService(DownloadImageService.class)
.setTag(Configuration.JOB_ID_DOWNLOAD_IMAGE_SERVICE)
.setRecurring(false)
.setLifetime(Lifetime.FOREVER)
.setTrigger(Trigger.executionWindow(0, 3600))
.setReplaceCurrent(true)
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.setConstraints(
Constraint.ON_UNMETERED_NETWORK,
Constraint.DEVICE_CHARGING
)
.build();
}
示例7: queuePostCore
import com.firebase.jobdispatcher.Constraint; //导入依赖的package包/类
public void queuePostCore(@NonNull FirebaseJobDispatcher dispatcher, @NonNull PostRequest postRequest) {
Bundle extras = new Bundle(2);
extras.putString(GenericJobService.JOB_TYPE, GenericJobService.POST);
extras.putParcelable(GenericJobService.PAYLOAD, postRequest);
dispatcher.mustSchedule(dispatcher.newJobBuilder()
.setService(GenericJobService.class)
.setTag(GenericJobService.POST)
.setRecurring(false)
.setLifetime(Lifetime.UNTIL_NEXT_BOOT)
.setTrigger(Trigger.executionWindow(0, 60))
.setReplaceCurrent(false)
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
.setConstraints(Constraint.ON_ANY_NETWORK, Constraint.DEVICE_CHARGING)
.setExtras(extras)
.build());
Log.d("FBJD", postRequest.getMethod() + " request is queued successfully!");
}
示例8: queueFileIOCore
import com.firebase.jobdispatcher.Constraint; //导入依赖的package包/类
public void queueFileIOCore(@NonNull FirebaseJobDispatcher dispatcher, boolean isDownload,
@NonNull FileIORequest fileIORequest) {
Bundle extras = new Bundle(2);
extras.putString(GenericJobService.JOB_TYPE, isDownload ?
GenericJobService.DOWNLOAD_FILE : GenericJobService.UPLOAD_FILE);
extras.putParcelable(GenericJobService.PAYLOAD, fileIORequest);
dispatcher.mustSchedule(dispatcher.newJobBuilder()
.setService(GenericJobService.class)
.setTag(isDownload ? GenericJobService.DOWNLOAD_FILE : GenericJobService.UPLOAD_FILE)
.setRecurring(false)
.setLifetime(Lifetime.FOREVER)
.setReplaceCurrent(false)
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
.setConstraints(fileIORequest.onWifi() ? Constraint.ON_UNMETERED_NETWORK : Constraint.ON_ANY_NETWORK,
fileIORequest.isWhileCharging() ? Constraint.DEVICE_CHARGING : 0)
.setExtras(extras)
.build());
Log.d("FBJD", String.format("%s file request is queued successfully!", isDownload ?
"Download" : "Upload"));
}
示例9: schedulePeriodic
import com.firebase.jobdispatcher.Constraint; //导入依赖的package包/类
public static void schedulePeriodic(Context context, String tag, int period) {
Timber.d("Scheduling a periodic sync every " + period + " seconds");
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job myJob = dispatcher.newJobBuilder()
.setService(QuoteJobService.class)
.setTag(tag)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(period, period))
.setLifetime(Lifetime.UNTIL_NEXT_BOOT)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
.setReplaceCurrent(true)
.build();
dispatcher.mustSchedule(myJob);
}
示例10: startSignInSocial
import com.firebase.jobdispatcher.Constraint; //导入依赖的package包/类
public static void startSignInSocial(Context context, Bundle bundle){
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job myJob = dispatcher.newJobBuilder()
// the JobService that will be called
.setService(SessionJobService.class)
// uniquely identifies the job
.setTag(SIGN_IN_SOCIAL_ACTION)
// one-off job
.setRecurring(false)
// start between 0 and 60 seconds from now
.setTrigger(Trigger.executionWindow(0, 60))
// don't overwrite an existing job with the same tag
.setReplaceCurrent(false)
// constraints that need to be satisfied for the job to run
.setConstraints(
// only run on an unmetered network
Constraint.ON_UNMETERED_NETWORK
)
.setExtras(bundle)
.build();
dispatcher.mustSchedule(myJob);
}
示例11: onStartJob
import com.firebase.jobdispatcher.Constraint; //导入依赖的package包/类
@Override
public boolean onStartJob(JobParameters job) {
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
/* Schedule the job once now*/
Job oneTimeJob = dispatcher.newJobBuilder()
.setService(WakatimeDataSyncJob.class)
.setTag("OneTimeJob")
.setTrigger(Trigger.executionWindow(0, 60))
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.build();
dispatcher.mustSchedule(oneTimeJob);
/* Schedule a recurring job everyday */
Job synJob = dispatcher.newJobBuilder()
.setService(WakatimeDataSyncJob.class)
.setTag(Constants.WAKATIME_DATA_SYNC_JOB_TAG)
.setReplaceCurrent(true)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(Constants.SYNC_PERIOD, Constants.SYNC_TOLERANCE))
.setConstraints(Constraint.ON_ANY_NETWORK)
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.build();
dispatcher.mustSchedule(synJob);
return false;
}
示例12: scheduleUpdateProgressReminder
import com.firebase.jobdispatcher.Constraint; //导入依赖的package包/类
synchronized public static void scheduleUpdateProgressReminder(@NonNull final Context context) {
if (sInitialized) {
return;
}
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
calendar.add(Calendar.MINUTE, 3);
//could have done add(Calender.Date,1). I have trust issues
Intent intentAlarm = new Intent(context, UpdateDayAlarmReciever.class);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, PendingIntent.getBroadcast(context, 1, intentAlarm, PendingIntent.FLAG_CANCEL_CURRENT));
Driver driver = new GooglePlayDriver(context);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
Job constraintReminderJob = dispatcher.newJobBuilder()
.setService(UpdateProgressFirebaseJobService.class)
.setTag(UPDATE_PROGRESS_JOB_TAG)
.setLifetime(Lifetime.FOREVER)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(
0,
UPDATE_INTERVAL_SECONDS))
.setReplaceCurrent(true)
.setConstraints(Constraint.ON_ANY_NETWORK)
.build();
/* Schedule the Job with the dispatcher */
dispatcher.schedule(constraintReminderJob);
/* The job has been initialized */
sInitialized = true;
}
示例13: scheduleJob
import com.firebase.jobdispatcher.Constraint; //导入依赖的package包/类
static void scheduleJob(Context context, String tag) {
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
dispatcher.cancel(tag);
Job myJob = dispatcher.newJobBuilder()
.setService(SyncJobService.class) // the JobService that will be called
.setTag(tag) // uniquely identifies the job
.setRecurring(false)
.setLifetime(Lifetime.FOREVER)
.setTrigger(Trigger.NOW)
.setConstraints(Constraint.ON_ANY_NETWORK)
.build();
dispatcher.mustSchedule(myJob);
}
示例14: scheduleChargingReminder
import com.firebase.jobdispatcher.Constraint; //导入依赖的package包/类
synchronized public static void scheduleChargingReminder(@NonNull final Context context) {
// COMPLETED (17) If the job has already been initialized, return
if (sInitialized) return;
// COMPLETED (18) Create a new GooglePlayDriver
Driver driver = new GooglePlayDriver(context);
// COMPLETED (19) Create a new FirebaseJobDispatcher with the driver
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
// COMPLETED (20) Use FirebaseJobDispatcher's newJobBuilder method to build a job which:
// - has WaterReminderFirebaseJobService as it's service
// - has the tag REMINDER_JOB_TAG
// - only triggers if the device is charging
// - has the lifetime of the job as forever
// - has the job recur
// - occurs every 15 minutes with a window of 15 minutes. You can do this using a
// setTrigger, passing in a Trigger.executionWindow
// - replaces the current job if it's already running
// Finally, you should build the job.
Job constraintReminderJob = dispatcher.newJobBuilder()
.setService(WaterReminderFirebaseJobService.class)
.setTag(REMINDER_JOB_TAG)
.setConstraints(Constraint.DEVICE_CHARGING)
.setLifetime(Lifetime.FOREVER)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(
REMINDER_INTERVAL_SECONDS,
REMINDER_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS))
.setReplaceCurrent(true)
.build();
// COMPLETED (21) Use dispatcher's schedule method to schedule the job
dispatcher.schedule(constraintReminderJob);
// COMPLETED (22) Set sInitialized to true to mark that we're done setting up the job
sInitialized = true;
}
示例15: createJob
import com.firebase.jobdispatcher.Constraint; //导入依赖的package包/类
@Override
protected Job createJob(FirebaseJobDispatcher dispatcher) {
return dispatcher.newJobBuilder()
.setLifetime(Lifetime.FOREVER)
.setService(SyncService.class)
.setTag(UNIQUE_TAG)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(DEFAULT_INTERVAL_START, DEFAULT_INTERVAL_END))
.setConstraints(Constraint.ON_ANY_NETWORK)
.setReplaceCurrent(false)
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
.build();
}