com.evernote.android.job.Job Java Examples

The following examples show how to use com.evernote.android.job.Job. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XDripJobCreator.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
/**
     * All new Job classes need to be included in the factory method below
     */
    @Override
    @Nullable
    public Job create(@NonNull final String tag) {
        if (D) UserError.Log.ueh("JobCreator", JoH.dateTimeText(JoH.tsl()) + " Passed: " + tag);
        switch (tag) {
/*
            case CloudSyncJob.TAG:
                return new CloudSyncJob();

*/

            case DailyJob.TAG:
                return new DailyJob();

            default:
                UserError.Log.wtf(TAG, "Failed to match Job: " + tag + " requesting cancellation");
                try {
                    JobManager.instance().cancelAllForTag(tag);
                } catch (Exception e) {
                    //
                }
                return null;
        }
    }
 
Example #2
Source File: DummyJobs.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Override
public Job create(@NonNull String tag) {
    switch (tag) {
        case SuccessJob.TAG:
            return new SuccessJob();
        case RescheduleJob.TAG:
            return new RescheduleJob();
        case FailureJob.TAG:
            return new FailureJob();
        case TwoSecondPauseJob.TAG:
            return new TwoSecondPauseJob();
        case SuccessDailyJob.TAG:
            return new SuccessDailyJob();
        default:
            return null;
    }
}
 
Example #3
Source File: PlatformGcmService.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Override
public int onRunTask(TaskParams taskParams) {
    int jobId = Integer.parseInt(taskParams.getTag());
    JobProxy.Common common = new JobProxy.Common(this, CAT, jobId);

    JobRequest request = common.getPendingRequest(true, true);
    if (request == null) {
        return GcmNetworkManager.RESULT_FAILURE;
    }

    Job.Result result = common.executeJobRequest(request, taskParams.getExtras());
    if (Job.Result.SUCCESS.equals(result)) {
        return GcmNetworkManager.RESULT_SUCCESS;
    } else {
        return GcmNetworkManager.RESULT_FAILURE;
    }
}
 
Example #4
Source File: XDripJobCreator.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
/**
     * All new Job classes need to be included in the factory method below
     */
    @Override
    @Nullable
    public Job create(@NonNull final String tag) {
        if (D) UserError.Log.ueh("JobCreator", JoH.dateTimeText(JoH.tsl()) + " Passed: " + tag);
        switch (tag) {
/*
            case CloudSyncJob.TAG:
                return new CloudSyncJob();

*/

            case DailyJob.TAG:
                return new DailyJob();

            default:
                UserError.Log.wtf(TAG, "Failed to match Job: " + tag + " requesting cancellation");
                try {
                    JobManager.instance().cancelAllForTag(tag);
                } catch (Exception e) {
                    //
                }
                return null;
        }
    }
 
Example #5
Source File: DemoJobCreator.java    From android-job with Apache License 2.0 5 votes vote down vote up
@Override
public Job create(@NonNull String tag) {
    switch (tag) {
        case DemoSyncJob.TAG:
            return new DemoSyncJob();
        default:
            return null;
    }
}
 
Example #6
Source File: RNJobCreator.java    From react-native-background-task with MIT License 5 votes vote down vote up
@Override
public Job create(String tag) {
    switch (tag) {
        case RNJob.JOB_TAG:
            return new RNJob();
        default:
            return null;
    }
}
 
Example #7
Source File: NotificationsJobCreator.java    From ForPDA with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Job create(@NonNull String tag) {
    switch (tag) {
        case NotificationsJob.TAG:
            return new NotificationsJob();
        default:
            return null;
    }
}
 
Example #8
Source File: DailyJob.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
@NonNull
protected Result onRunJob(@NonNull Job.Params params) {
    final long startTime = JoH.tsl();
    DailyIntentService.work();
    UserError.Log.uel(TAG, JoH.dateTimeText(JoH.tsl()) + " Job Ran - finished, duration: " + JoH.niceTimeScalar(JoH.msSince(startTime)));
    return Result.SUCCESS;
}
 
Example #9
Source File: DailyJob.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
@NonNull
protected Result onRunJob(@NonNull Job.Params params) {
    final long startTime = JoH.tsl();
    DailyIntentService.work();
    UserError.Log.uel(TAG, JoH.dateTimeText(JoH.tsl()) + " Job Ran - finished, duration: " + JoH.niceTimeScalar(JoH.msSince(startTime)));
    return Result.SUCCESS;
}
 
Example #10
Source File: SyncJobCreator.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Job create(@NonNull String tag) {
    try {
        if (tag.startsWith(WebTimes.SyncJob.TAG)) {
            Times t = Times.getTimes(Long.parseLong(tag.substring(WebTimes.SyncJob.TAG.length())));
            if (t instanceof WebTimes)
                return ((WebTimes) t).new SyncJob();
        }
    } catch (Exception e) {
        Crashlytics.logException(e);
    }
    return null;
}
 
Example #11
Source File: HookFetchJobCreator.java    From OneTapVideoDownload with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Job create(String tag) {
    switch (tag) {
        case HookFetchJob.TAG:
            return new HookFetchJob();
        default:
            return null;
    }
}
 
Example #12
Source File: MainActivity.java    From ETSMobile-Android2 with Apache License 2.0 5 votes vote down vote up
private void initJobManager() {
    JobManager.create(this).addJobCreator(new JobCreator() {
        @Override
        public Job create(String tag) {
            if (tag.equals(BottinSyncJob.TAG))
                return new BottinSyncJob();
            else
                return null;
        }
    });
}
 
Example #13
Source File: DonaldTrump.java    From Maying with Apache License 2.0 5 votes vote down vote up
@Override
public Job create(String tag) {
    String[] parts = tag.split(":");

    if (AclSyncJob.TAG.equals(parts[0])) {
        return new AclSyncJob(parts[1]);
    } else if (SSRSubUpdateJob.TAG.equals(parts[0])) {
        return new SSRSubUpdateJob();
    } else {
        VayLog.w(TAG, "Unknown job tag: " + tag);
        return null;
    }
}
 
Example #14
Source File: PlatformJobService.java    From android-job with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onStopJob(JobParameters params) {
    Job job = JobManager.create(this).getJob(params.getJobId());
    if (job != null) {
        job.cancel();
        CAT.d("Called onStopJob for %s", job);
    } else {
        CAT.d("Called onStopJob, job %d not found", params.getJobId());
    }

    // do not reschedule
    return false;
}
 
Example #15
Source File: PlatformWorker.java    From android-job with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public Result doWork() {
    final int jobId = getJobId();
    if (jobId < 0) {
        return Result.failure();
    }

    try {
        JobProxy.Common common = new JobProxy.Common(getApplicationContext(), CAT, jobId);

        JobRequest request = common.getPendingRequest(true, true);
        if (request == null) {
            return Result.failure();
        }

        Bundle transientBundle = null;
        if (request.isTransient()) {
            transientBundle = TransientBundleHolder.getBundle(jobId);
            if (transientBundle == null) {
                CAT.d("Transient bundle is gone for request %s", request);
                return Result.failure();
            }
        }

        Job.Result result = common.executeJobRequest(request, transientBundle);
        if (Job.Result.SUCCESS == result) {
            return Result.success();
        } else {
            return Result.failure();
        }
    } finally {
        TransientBundleHolder.cleanUpBundle(jobId);
    }
}
 
Example #16
Source File: PlatformWorker.java    From android-job with Apache License 2.0 5 votes vote down vote up
@Override
public void onStopped() {
    int jobId = getJobId();
    Job job = JobManager.create(getApplicationContext()).getJob(jobId);

    if (job != null) {
        job.cancel();
        CAT.d("Called onStopped for %s", job);
    } else {
        CAT.d("Called onStopped, job %d not found", jobId);
    }
}
 
Example #17
Source File: DummyJobs.java    From android-job with Apache License 2.0 5 votes vote down vote up
public static JobRequest.Builder createBuilder(Class<? extends Job> jobClass) {
    try {
        String tag = (String) jobClass.getDeclaredField("TAG").get(null);
        return new JobRequest.Builder(tag);
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
 
Example #18
Source File: SyncJobCreator.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Job create(@NonNull String tag) {
    try {
        if (tag.startsWith(WebTimes.SyncJob.TAG)) {
            Times t = Times.getTimes(Long.parseLong(tag.substring(WebTimes.SyncJob.TAG.length())));
            if (t instanceof WebTimes)
                return ((WebTimes) t).new SyncJob();
        }
    } catch (Exception e) {
        Crashlytics.logException(e);
    }
    return null;
}
 
Example #19
Source File: AndroidJobStrategy.java    From cloudinary_android with MIT License 5 votes vote down vote up
@NonNull
private static Job.Result adaptResult(UploadStatus res) {
    switch (res) {
        case FAILURE:
            return Job.Result.FAILURE;
        case SUCCESS:
            return Job.Result.SUCCESS;
        case RESCHEDULE:
            return Job.Result.RESCHEDULE;
    }

    // unexpected result, we don't want to retry because we have no idea why it failed.
    return Job.Result.FAILURE;
}
 
Example #20
Source File: AndroidJobStrategy.java    From cloudinary_android with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int getRunningJobsCount() {
    int running = 0;
    for (Job job : JobManager.instance().getAllJobs()) {
        if (!job.isFinished()) {
            running++;
        }
    }

    return running;
}
 
Example #21
Source File: BackupTestJobCreator.java    From fingen with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public Job create(@NonNull String tag) {
    switch (tag) {
        case BackupTestJob.TAG:
            return new BackupTestJob();
        default:
            return null;
    }
}
 
Example #22
Source File: DonaldTrump.java    From ShadowsocksRR with Apache License 2.0 5 votes vote down vote up
@Override
public Job create(String tag) {
    String[] parts = tag.split(":");

    if (AclSyncJob.TAG.equals(parts[0])) {
        return new AclSyncJob(parts[1]);
    } else if (SSRSubUpdateJob.TAG.equals(parts[0])) {
        return new SSRSubUpdateJob();
    } else {
        VayLog.w(TAG, "Unknown job tag: " + tag);
        return null;
    }
}
 
Example #23
Source File: AppJobCreator.java    From Building-Professional-Android-Applications with MIT License 5 votes vote down vote up
@Override
@Nullable
public Job create(@NonNull String tag) {
    switch (tag) {
        case PortfolioSyncJob.TAG:
            return new PortfolioSyncJob(portfolioRepository, stockUpdatesService);
        default:
            return null;
    }
}
 
Example #24
Source File: AppJobCreator.java    From Building-Professional-Android-Applications with MIT License 5 votes vote down vote up
@Override
@Nullable
public Job create(@NonNull String tag) {
    switch (tag) {
        case PortfolioSyncJob.TAG:
            return new PortfolioSyncJob(portfolioRepository, stockUpdatesService);
        default:
            return null;
    }
}
 
Example #25
Source File: AppJobCreator.java    From Building-Professional-Android-Applications with MIT License 5 votes vote down vote up
@Override
@Nullable
public Job create(@NonNull String tag) {
    switch (tag) {
        case PortfolioSyncJob.TAG:
            return new PortfolioSyncJob(portfolioRepository, stockUpdatesService);
        default:
            return null;
    }
}
 
Example #26
Source File: AppJobCreator.java    From Building-Professional-Android-Applications with MIT License 5 votes vote down vote up
@Override
@Nullable
public Job create(@NonNull String tag) {
    switch (tag) {
        case PortfolioSyncJob.TAG:
            return new PortfolioSyncJob(portfolioRepository, stockUpdatesService);
        default:
            return null;
    }
}
 
Example #27
Source File: AppJobCreator.java    From Building-Professional-Android-Applications with MIT License 5 votes vote down vote up
@Override
@Nullable
public Job create(@NonNull String tag) {
    switch (tag) {
        case PortfolioSyncJob.TAG:
            return new PortfolioSyncJob(portfolioRepository, stockUpdatesService);
        default:
            return null;
    }
}
 
Example #28
Source File: AppJobCreator.java    From Building-Professional-Android-Applications with MIT License 5 votes vote down vote up
@Override
@Nullable
public Job create(@NonNull String tag) {
    switch (tag) {
        case PortfolioSyncJob.TAG:
            return new PortfolioSyncJob(portfolioRepository, stockUpdatesService);
        default:
            return null;
    }
}
 
Example #29
Source File: AppJobCreator.java    From Building-Professional-Android-Applications with MIT License 5 votes vote down vote up
@Override
@Nullable
public Job create(@NonNull String tag) {
    switch (tag) {
        case PortfolioSyncJob.TAG:
            return new PortfolioSyncJob(portfolioRepository, stockUpdatesService);
        default:
            return null;
    }
}
 
Example #30
Source File: AppJobCreator.java    From Building-Professional-Android-Applications with MIT License 5 votes vote down vote up
@Override
@Nullable
public Job create(@NonNull String tag) {
    switch (tag) {
        case PortfolioSyncJob.TAG:
            return new PortfolioSyncJob(portfolioRepository, stockUpdatesService);
        default:
            return null;
    }
}