本文整理汇总了Java中com.evernote.android.job.util.support.PersistableBundleCompat类的典型用法代码示例。如果您正苦于以下问题:Java PersistableBundleCompat类的具体用法?Java PersistableBundleCompat怎么用?Java PersistableBundleCompat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PersistableBundleCompat类属于com.evernote.android.job.util.support包,在下文中一共展示了PersistableBundleCompat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPeriodic
import com.evernote.android.job.util.support.PersistableBundleCompat; //导入依赖的package包/类
@Override
public void createPeriodic() {
for (int i = 0; i < 10; i++) {
JobRequest.Builder builder = new JobRequest.Builder("tag")
.setPeriodic(TimeUnit.MINUTES.toMillis(1))
.setRequiresCharging(random())
.setRequiresDeviceIdle(random())
.setRequiredNetworkType(random() ? JobRequest.NetworkType.ANY : JobRequest.NetworkType.CONNECTED)
.setRequirementsEnforced(random());
if (random()) {
PersistableBundleCompat extras = new PersistableBundleCompat();
extras.putString("key", "Hello world");
builder.setExtras(extras);
}
builder.build().schedule();
}
}
示例2: onRunJob
import com.evernote.android.job.util.support.PersistableBundleCompat; //导入依赖的package包/类
@Override
@NonNull
protected Result onRunJob(Params params) {
Log.d(TAG, "Job is running");
PersistableBundleCompat requestExtras = params.getExtras();
// Two different types of bundle so need to re-package
Bundle headlessExtras = new Bundle();
headlessExtras.putInt("timeout", requestExtras.getInt("timeout", 30));
Context context = getContext().getApplicationContext();
Intent service = new Intent(context, HeadlessTaskService.class);
service.putExtras(headlessExtras);
context.startService(service);
return Result.SUCCESS;
}
示例3: scheduleJobImmediately
import com.evernote.android.job.util.support.PersistableBundleCompat; //导入依赖的package包/类
public static void scheduleJobImmediately(boolean byUser, Calendar start, Calendar end) {
PersistableBundleCompat extras = new PersistableBundleCompat();
extras.putBoolean(ARG_INITIATED_BY_USER, byUser);
if (start != null && end != null) {
extras.putString(SyncJob.ARG_START_DATE, new SimpleDateFormat("yyyy-MM-dd", Locale.GERMANY).format(start.getTime()));
extras.putString(SyncJob.ARG_END_DATE, new SimpleDateFormat("yyyy-MM-dd", Locale.GERMANY).format(end.getTime()));
}
new JobRequest.Builder(TAG).startNow()
.setExtras(extras)
.build()
.schedule();
}
示例4: onRunJob
import com.evernote.android.job.util.support.PersistableBundleCompat; //导入依赖的package包/类
@NonNull
@Override
protected Result onRunJob(Params params) {
PersistableBundleCompat extras = params.getExtras();
long paperId = extras.getLong(ARG_PAPER_ID, -1L);
Paper paper = Paper.getPaperWithId(getContext(), paperId);
if (paper != null) {
try {
Timber.i("%s", paper);
StorageManager storageManager = StorageManager.getInstance(getContext());
currentPaperId = paperId;
currentUnzipPaper = new UnzipPaper(paper,
storageManager.getDownloadFile(paper),
storageManager.getPaperDirectory(paper),
true);
currentUnzipPaper.getUnzipFile()
.addProgressListener(this);
currentUnzipPaper.start();
savePaper(paper, null);
} catch (ParserConfigurationException | IOException | SAXException | ParseException | PropertyListFormatException | UnzipCanceledException e) {
savePaper(paper, e);
}
}
return Result.SUCCESS;
}
示例5: onRunJob
import com.evernote.android.job.util.support.PersistableBundleCompat; //导入依赖的package包/类
@NonNull
@Override
protected Result onRunJob(Params params) {
PersistableBundleCompat extras = params.getExtras();
String resourceKey = extras.getString(ARG_RESOURCE_KEY, null);
if (!TextUtils.isEmpty(resourceKey)) {
Resource resource = Resource.getWithKey(getContext(), resourceKey);
Timber.i("%s", resource);
if (resource != null && resource.isDownloading()) {
StorageManager storageManager = StorageManager.getInstance(getContext());
try {
UnzipResource unzipResource = new UnzipResource(storageManager.getDownloadFile(resource),
storageManager.getResourceDirectory(resource.getKey()),
true);
unzipResource.start();
saveResource(resource, null);
} catch (UnzipCanceledException | IOException | PropertyListFormatException | ParseException | SAXException | ParserConfigurationException e) {
saveResource(resource, e);
}
}
}
return Result.SUCCESS;
}
示例6: testPeriodic
import com.evernote.android.job.util.support.PersistableBundleCompat; //导入依赖的package包/类
@Test
public void testPeriodic() {
long interval = JobRequest.MIN_INTERVAL * 5;
JobRequest request = getBuilder()
.setPeriodic(interval)
.setExtras(new PersistableBundleCompat())
.build();
assertThat(request.getJobId()).isGreaterThan(0);
assertThat(request.getTag()).isEqualTo(DummyJobs.SuccessJob.TAG);
assertThat(request.getIntervalMs()).isEqualTo(interval);
assertThat(request.getFlexMs()).isEqualTo(interval);
assertThat(request.isPeriodic()).isTrue();
assertThat(request.isFlexSupport()).isFalse();
assertThat(request.getStartMs()).isNegative();
assertThat(request.getEndMs()).isNegative();
assertThat(request.getBackoffMs()).isEqualTo(JobRequest.DEFAULT_BACKOFF_MS);
assertThat(request.getBackoffPolicy()).isEqualTo(JobRequest.DEFAULT_BACKOFF_POLICY);
assertThat(request.getExtras()).isNotNull();
assertThat(request.isExact()).isFalse();
assertThat(request.requiredNetworkType()).isEqualTo(JobRequest.DEFAULT_NETWORK_TYPE);
assertThat(request.requirementsEnforced()).isFalse();
assertThat(request.requiresCharging()).isFalse();
assertThat(request.requiresDeviceIdle()).isFalse();
}
示例7: verifyExtraValuesAreOverwritten
import com.evernote.android.job.util.support.PersistableBundleCompat; //导入依赖的package包/类
@Test
public void verifyExtraValuesAreOverwritten() {
long start = 0;
long end = 1L;
PersistableBundleCompat extras = new PersistableBundleCompat();
extras.putLong("something", 9L); // make sure this value is not overwritten
extras.putLong(DailyJob.EXTRA_START_MS, 9L); // make sure they're overwritten
extras.putLong(DailyJob.EXTRA_END_MS, 9L);
int jobId = DailyJob.schedule(DummyJobs.createBuilder(DummyJobs.SuccessJob.class).setExtras(extras), start, end);
JobRequest request = manager().getJobRequest(jobId);
assertThat(request).isNotNull();
assertThat(request.getExtras().getLong(DailyJob.EXTRA_START_MS, -1)).isEqualTo(0L);
assertThat(request.getExtras().getLong(DailyJob.EXTRA_END_MS, -1)).isEqualTo(1L);
assertThat(request.getExtras().size()).isEqualTo(3);
}
示例8: schedule
import com.evernote.android.job.util.support.PersistableBundleCompat; //导入依赖的package包/类
/**
* Main point of interaction from JS users - allows them to specify the scheduling etc for the
* background task.
*
* Default values are specified in JS (more accessible for the average user).
*
* @param config the config options passed in from JS:
* - period (required): how frequently to carry out the task in seconds
* - timeout (required): after how many seconds should the task be auto-killed
*/
@ReactMethod
public void schedule(final ReadableMap config) {
Log.d(TAG, "@ReactMethod BackgroundTask.schedule");
// Period can't be below 15m
int period = config.getInt("period");
if (period < 900) { period = 900; }
// Flex must be between 5m and 15m
int flex = config.getInt("flex");
if (flex < 300) { flex = 300; }
if (flex > 900) { flex = 900; }
// Extra info to store with the JobRequest
PersistableBundleCompat extras = new PersistableBundleCompat();
extras.putInt("timeout", config.getInt("timeout"));
mJobRequest = new JobRequest.Builder(RNJob.JOB_TAG)
.setPeriodic(TimeUnit.SECONDS.toMillis(period), TimeUnit.SECONDS.toMillis(flex))
.setPersisted(true)
.setExtras(extras)
.build();
if (!mForeground) {
commitSchedule();
}
}
示例9: scheduleJob
import com.evernote.android.job.util.support.PersistableBundleCompat; //导入依赖的package包/类
public static void scheduleJob(Context context, long noteId, int noteTimeType, long timestamp) {
PersistableBundleCompat extras = new PersistableBundleCompat();
long snoozeTime = AppPreferences.remindersSnoozeTime(context) * 60 * 1000;
String snoozeRelativeTo = AppPreferences.remindersSnoozeRelativeTo(context);
long exactMs;
if (snoozeRelativeTo.equals("button")) {
exactMs = snoozeTime;
} else if (snoozeRelativeTo.equals("alarm")) {
timestamp += snoozeTime;
exactMs = timestamp - System.currentTimeMillis();
// keep adding snooze times until positive: handle the case where
// someone lets the alarm go off for more that one snoozeTime interval
while (exactMs <= 0) {
exactMs += snoozeTime;
timestamp += snoozeTime;
}
} else {
// should never happen
Log.e(TAG, "unhandled snoozeRelativeTo " + snoozeRelativeTo);
return;
}
if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, noteId, noteTimeType, timestamp, exactMs);
extras.putLong(AppIntent.EXTRA_NOTE_ID, noteId);
extras.putInt(AppIntent.EXTRA_NOTE_TIME_TYPE, noteTimeType);
extras.putLong(AppIntent.EXTRA_SNOOZE_TIMESTAMP, timestamp);
new JobRequest.Builder(SnoozeJob.TAG)
.setExact(exactMs)
.setExtras(extras)
.setPersisted(true)
.build()
.schedule();
}
示例10: create
import com.evernote.android.job.util.support.PersistableBundleCompat; //导入依赖的package包/类
private static JobRequest create(long taskId) {
PersistableBundleCompat bundle = new PersistableBundleCompat();
bundle.putLong(EXTRA_TASK_ID, taskId);
return new JobRequest.Builder(TAG)
.setExecutionWindow(getConfig().executionWindowStartInMilliseconds, getConfig().executionWindowEndInMilliseconds)
.setBackoffCriteria(getConfig().backoffInMilliseconds, getConfig().backoffPolicy)
.setPersisted(getConfig().persisted)
.setExtras(bundle)
.setRequiredNetworkType(JobRequest.NetworkType.CONNECTED)
.setRequirementsEnforced(true)
.build();
}
示例11: scheduleJob
import com.evernote.android.job.util.support.PersistableBundleCompat; //导入依赖的package包/类
public static void scheduleJob(@NonNull Paper paper) {
PersistableBundleCompat extras = new PersistableBundleCompat();
extras.putLong(ARG_PAPER_ID, paper.getId());
new JobRequest.Builder(TAG).setExtras(extras)
.startNow()
.build()
.schedule();
}
示例12: scheduleJob
import com.evernote.android.job.util.support.PersistableBundleCompat; //导入依赖的package包/类
public static void scheduleJob(Paper paper) {
PersistableBundleCompat extras = new PersistableBundleCompat();
extras.putLong(ARG_PAPER_ID, paper.getId());
new JobRequest.Builder(TAG).setExtras(extras)
.startNow()
.build()
.schedule();
}
示例13: scheduleJob
import com.evernote.android.job.util.support.PersistableBundleCompat; //导入依赖的package包/类
public static void scheduleJob(Resource resource) {
PersistableBundleCompat extras = new PersistableBundleCompat();
extras.putString(ARG_RESOURCE_KEY, resource.getKey());
new JobRequest.Builder(TAG).setExtras(extras)
.startNow()
.build()
.schedule();
}
示例14: getExtras
import com.evernote.android.job.util.support.PersistableBundleCompat; //导入依赖的package包/类
/**
* @return The extras for this job.
*/
public PersistableBundleCompat getExtras() {
if (mBuilder.mExtras == null && !TextUtils.isEmpty(mBuilder.mExtrasXml)) {
mBuilder.mExtras = PersistableBundleCompat.fromXml(mBuilder.mExtrasXml);
}
return mBuilder.mExtras;
}
示例15: addExtras
import com.evernote.android.job.util.support.PersistableBundleCompat; //导入依赖的package包/类
/**
* Adds optional extras. This is persisted, so only primitive types are allowed. This method overrides
* values with the same keys inside of {@code extras}, which were set before.
*
* @param extras Bundle containing extras which you can retrieve with {@link Job.Params#getExtras()}.
*/
public Builder addExtras(@NonNull PersistableBundleCompat extras) {
if (mExtras == null) {
mExtras = extras;
} else {
mExtras.putAll(extras);
}
mExtrasXml = null;
return this;
}