All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gh.bmd.jrt.android.runner.MainRunner Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.gh.bmd.jrt.android.runner;

import android.os.Looper;

import com.gh.bmd.jrt.runner.Execution;
import com.gh.bmd.jrt.runner.Runner;
import com.gh.bmd.jrt.runner.Runners;

import java.util.concurrent.TimeUnit;

import javax.annotation.Nonnull;

/**
 * Implementation of a runner employing the main UI thread looper.
* Note that, when the invocation runs in the main thread, the executions with a delay of 0 will be * performed synchronously, while the ones with a positive delay will be posted on the UI thread. *

* Created by davide on 12/17/14. */ public class MainRunner extends LooperRunner { private static final Runner sSameThreadRunner = new Runner() { private final Runner mMain = new LooperRunner(Looper.getMainLooper(), null); private final Runner mQueued = Runners.queuedRunner(); public void run(@Nonnull final Execution execution, final long delay, @Nonnull final TimeUnit timeUnit) { if (delay == 0) { mQueued.run(execution, delay, timeUnit); } else { mMain.run(execution, delay, timeUnit); } } }; /** * Constructor. */ public MainRunner() { super(Looper.getMainLooper(), sSameThreadRunner); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy