Android Open Source - timesync Random Sync






From Project

Back to project page timesync.

License

The source code is released under:

Apache License

If you think the Android project timesync listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package me.tatarka.timesync.app;
/*w  w w . j  av  a  2  s .  c  om*/
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;

import java.util.Random;

import me.tatarka.timesync.lib.TimeSync;

public class RandomSync extends TimeSync {
    public static final String BROADCAST = RandomSync.class.getName();
    public static final String EXTRA_RESULT = "result";

    private Random random = new Random();

    @Override
    public void onSync(Context context) throws Exception {
        long result = random.nextLong();

//        if (random.nextInt(5) < 2) {
//            Log.d("TimeSync", "sync failed: " + System.currentTimeMillis());
//            throw new Exception();
//        }

        // Normally you would save to a database or file. For this example, it's just easier to
        // broadcast the result.
        Intent intent = new Intent(BROADCAST);
        intent.putExtra(EXTRA_RESULT, result);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }
}




Java Source Code List

me.tatarka.timesync.app.MainActivity.java
me.tatarka.timesync.app.MyApplication.java
me.tatarka.timesync.app.RandomSync.java
me.tatarka.timesync.lib.BooleanFormatException.java
me.tatarka.timesync.lib.EventCalculator.java
me.tatarka.timesync.lib.MathUtil.java
me.tatarka.timesync.lib.ReceiverUtils.java
me.tatarka.timesync.lib.SuperNotCalledException.java
me.tatarka.timesync.lib.TimeSyncBootReceiver.java
me.tatarka.timesync.lib.TimeSyncNetworkReceiver.java
me.tatarka.timesync.lib.TimeSyncParser.java
me.tatarka.timesync.lib.TimeSyncPowerReceiver.java
me.tatarka.timesync.lib.TimeSyncPreferences.java
me.tatarka.timesync.lib.TimeSyncProxy.java
me.tatarka.timesync.lib.TimeSyncService.java
me.tatarka.timesync.lib.TimeSync.java