Example usage for android.os PersistableBundle putDoubleArray

List of usage examples for android.os PersistableBundle putDoubleArray

Introduction

In this page you can find the example usage for android.os PersistableBundle putDoubleArray.

Prototype

public void putDoubleArray(@Nullable String key, @Nullable double[] value) 

Source Link

Document

Inserts a double array value into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:nuclei.task.TaskScheduler.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void onScheduleJobL(Context context) {
    JobInfo.Builder builder = new JobInfo.Builder(mBuilder.mTask.getTaskId(),
            new ComponentName(context, TaskJobService.class));

    ArrayMap<String, Object> map = new ArrayMap<>();
    mBuilder.mTask.serialize(map);//  ww  w .  j  ava2s.c om
    PersistableBundle extras = new PersistableBundle();
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        Object v = entry.getValue();
        if (v == null)
            continue;
        if (v instanceof Integer)
            extras.putInt(entry.getKey(), (int) v);
        else if (v instanceof Double)
            extras.putDouble(entry.getKey(), (double) v);
        else if (v instanceof Long)
            extras.putLong(entry.getKey(), (long) v);
        else if (v instanceof String)
            extras.putString(entry.getKey(), (String) v);
        else if (v instanceof String[])
            extras.putStringArray(entry.getKey(), (String[]) v);
        else if (v instanceof boolean[] && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1)
            extras.putBooleanArray(entry.getKey(), (boolean[]) v);
        else if (v instanceof double[])
            extras.putDoubleArray(entry.getKey(), (double[]) v);
        else if (v instanceof long[])
            extras.putLongArray(entry.getKey(), (long[]) v);
        else if (v instanceof int[])
            extras.putIntArray(entry.getKey(), (int[]) v);
        else
            throw new IllegalArgumentException("Invalid Type: " + entry.getKey());
    }
    extras.putString(TASK_NAME, mBuilder.mTask.getClass().getName());

    switch (mBuilder.mTaskType) {
    case TASK_ONE_OFF:
        if (mBuilder.mWindowStartDelaySecondsSet)
            builder.setMinimumLatency(mBuilder.mWindowStartDelaySeconds * 1000);
        if (mBuilder.mWindowEndDelaySecondsSet)
            builder.setOverrideDeadline(mBuilder.mWindowEndDelaySeconds * 1000);
        break;
    case TASK_PERIODIC:
        builder.setPeriodic(mBuilder.mPeriodInSeconds * 1000);
        break;
    default:
        throw new IllegalArgumentException();
    }

    builder.setExtras(extras).setPersisted(mBuilder.mPersisted).setRequiresCharging(mBuilder.mRequiresCharging)
            .setRequiresDeviceIdle(mBuilder.mRequiresDeviceIdle);

    switch (mBuilder.mNetworkState) {
    case NETWORK_STATE_ANY:
        builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_NONE);
        break;
    case NETWORK_STATE_CONNECTED:
        builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
        break;
    case NETWORK_STATE_UNMETERED:
        builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED);
        break;
    }

    switch (mBuilder.mBackoffPolicy) {
    case BACKOFF_POLICY_EXPONENTIAL:
        builder.setBackoffCriteria(mBuilder.mInitialBackoffMillis, JobInfo.BACKOFF_POLICY_EXPONENTIAL);
        break;
    case BACKOFF_POLICY_LINEAR:
        builder.setBackoffCriteria(mBuilder.mInitialBackoffMillis, JobInfo.BACKOFF_POLICY_LINEAR);
        break;
    }

    JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    jobScheduler.schedule(builder.build());
}