// Path: chronos/src/main/java/com/redmadrobot/chronos/gui/activity/ChronosActivity.java
// @SuppressWarnings("unused")
// public abstract class ChronosActivity extends Activity implements ChronosConnectorWrapper {
// 
//     /**
//      * An entry point to access Chronos functions.
//      */
//     private final ChronosConnector mConnector = new ChronosConnector();
// 
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         mConnector.onCreate(this, savedInstanceState);
//     }
// 
//     @Override
//     protected void onResume() {
//         super.onResume();
//         mConnector.onResume();
//     }
// 
//     @Override
//     protected void onSaveInstanceState(@NonNull final Bundle outState) {
//         super.onSaveInstanceState(outState);
//         mConnector.onSaveInstanceState(outState);
//     }
// 
//     @Override
//     protected void onPause() {
//         mConnector.onPause();
//         super.onPause();
//     }
// 
//     @Override
//     public final int runOperation(@NonNull final ChronosOperation operation,
//             @NonNull final String tag) {
//         return mConnector.runOperation(operation, tag, false);
//     }
// 
//     @Override
//     public final int runOperation(@NonNull final ChronosOperation operation) {
//         return mConnector.runOperation(operation, false);
//     }
// 
//     @Override
//     public final int runOperationBroadcast(@NonNull final ChronosOperation operation,
//             @NonNull final String tag) {
//         return mConnector.runOperation(operation, tag, true);
//     }
// 
//     @Override
//     public final int runOperationBroadcast(@NonNull final ChronosOperation operation) {
//         return mConnector.runOperation(operation, true);
//     }
// 
//     @Override
//     public final boolean cancelOperation(final int id) {
//         return mConnector.cancelOperation(id, true);
//     }
// 
//     @Override
//     public final boolean cancelOperation(@NonNull final String tag) {
//         return mConnector.cancelOperation(tag, true);
//     }
// 
//     @Override
//     @Contract(pure = true)
//     public final boolean isOperationRunning(final int id) {
//         return mConnector.isOperationRunning(id);
//     }
// 
//     @Override
//     @Contract(pure = true)
//     public final boolean isOperationRunning(@NonNull final String tag) {
//         return mConnector.isOperationRunning(tag);
//     }
// }
// 
// Path: app/src/main/java/com/redmadrobot/chronos_sample/operations/SimpleOperation.java
// public final class SimpleOperation extends ChronosOperation<String> {
// 
//     private final String mInput;
// 
//     public SimpleOperation(@NonNull final String input) {
//         mInput = input;
//     }
// 
//     @Nullable
//     @Override
//     //Chronos will run this method in a background thread, which means you can put
//     //any time-consuming calls here, as it will not affect UI thread performance
//     public String run() {
//         final String result = "String length is " + mInput.length();
// 
//         try {
//             Thread.sleep(3000);
//         } catch (InterruptedException e) {
//             // do nothing, thread is interrupted, which means a system wants to stop the run
//         }
// 
//         return result;
//     }
// 
//     @NonNull
//     @Override
//     // To be able to distinguish results from different operations in one Chronos client
//     // (most commonly an activity, or a fragment)
//     // you should create an 'OperationResult<>' subclass in each operation,
//     // so that it will be used as a parameter
//     // in a callback method 'onOperationFinished'
//     public Class<? extends ChronosOperationResult<String>> getResultClass() {
//         return Result.class;
//     }
// 
//     public final static class Result extends ChronosOperationResult<String> {
// 
//     }
// }


import com.redmadrobot.chronos.gui.activity.ChronosActivity;
import com.redmadrobot.chronos_sample.R;
import com.redmadrobot.chronos_sample.operations.SimpleOperation;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.widget.TextView;
package com.redmadrobot.chronos_sample.samples;



/**
 * A sample of how you can easily initiate your layout with data provided by some source, that takes
 * some time to give a response, such as remote server, or a database.
 *
 * @author maximefimov
 */
public final class DataLoad extends ChronosActivity {

    // a key by which the activity saves and restores already loaded data
    private final static String KEY_DATA = "data";

    // a tag which represents a group of operations that can't run simultaneously
    private final static String TAG_DATA_LOADING = "data_loading";

    private TextView mTextOutput;

    // a data that has to be loaded
    private String mData = null;

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_data_load);

        mTextOutput = (TextView) findViewById(R.id.text_output);

        if (savedInstanceState != null) {
            //first of all, the activity tries to restored already loaded data
            mData = savedInstanceState.getString(KEY_DATA);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        //after this point all pending OperationResults are delivered, so that you may be sure,
        // that all proper 'onOperationFinished' calls are done

        if (mData == null) {// if it is still no data
            // The activity launches a loading operations with a tag
            // so that if it comes to this point once again and the data is not loaded yet,
            // the next launch will be ignored.
            // That means, no matter now often user rotates the device,
            // only one operation with a given tag may be pending in a single moment of time.
// Path: chronos/src/main/java/com/redmadrobot/chronos/gui/activity/ChronosActivity.java
// @SuppressWarnings("unused")
// public abstract class ChronosActivity extends Activity implements ChronosConnectorWrapper {
// 
//     /**
//      * An entry point to access Chronos functions.
//      */
//     private final ChronosConnector mConnector = new ChronosConnector();
// 
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         mConnector.onCreate(this, savedInstanceState);
//     }
// 
//     @Override
//     protected void onResume() {
//         super.onResume();
//         mConnector.onResume();
//     }
// 
//     @Override
//     protected void onSaveInstanceState(@NonNull final Bundle outState) {
//         super.onSaveInstanceState(outState);
//         mConnector.onSaveInstanceState(outState);
//     }
// 
//     @Override
//     protected void onPause() {
//         mConnector.onPause();
//         super.onPause();
//     }
// 
//     @Override
//     public final int runOperation(@NonNull final ChronosOperation operation,
//             @NonNull final String tag) {
//         return mConnector.runOperation(operation, tag, false);
//     }
// 
//     @Override
//     public final int runOperation(@NonNull final ChronosOperation operation) {
//         return mConnector.runOperation(operation, false);
//     }
// 
//     @Override
//     public final int runOperationBroadcast(@NonNull final ChronosOperation operation,
//             @NonNull final String tag) {
//         return mConnector.runOperation(operation, tag, true);
//     }
// 
//     @Override
//     public final int runOperationBroadcast(@NonNull final ChronosOperation operation) {
//         return mConnector.runOperation(operation, true);
//     }
// 
//     @Override
//     public final boolean cancelOperation(final int id) {
//         return mConnector.cancelOperation(id, true);
//     }
// 
//     @Override
//     public final boolean cancelOperation(@NonNull final String tag) {
//         return mConnector.cancelOperation(tag, true);
//     }
// 
//     @Override
//     @Contract(pure = true)
//     public final boolean isOperationRunning(final int id) {
//         return mConnector.isOperationRunning(id);
//     }
// 
//     @Override
//     @Contract(pure = true)
//     public final boolean isOperationRunning(@NonNull final String tag) {
//         return mConnector.isOperationRunning(tag);
//     }
// }
// 
// Path: app/src/main/java/com/redmadrobot/chronos_sample/operations/SimpleOperation.java
// public final class SimpleOperation extends ChronosOperation<String> {
// 
//     private final String mInput;
// 
//     public SimpleOperation(@NonNull final String input) {
//         mInput = input;
//     }
// 
//     @Nullable
//     @Override
//     //Chronos will run this method in a background thread, which means you can put
//     //any time-consuming calls here, as it will not affect UI thread performance
//     public String run() {
//         final String result = "String length is " + mInput.length();
// 
//         try {
//             Thread.sleep(3000);
//         } catch (InterruptedException e) {
//             // do nothing, thread is interrupted, which means a system wants to stop the run
//         }
// 
//         return result;
//     }
// 
//     @NonNull
//     @Override
//     // To be able to distinguish results from different operations in one Chronos client
//     // (most commonly an activity, or a fragment)
//     // you should create an 'OperationResult<>' subclass in each operation,
//     // so that it will be used as a parameter
//     // in a callback method 'onOperationFinished'
//     public Class<? extends ChronosOperationResult<String>> getResultClass() {
//         return Result.class;
//     }
// 
//     public final static class Result extends ChronosOperationResult<String> {
// 
//     }
// }


// Path: app/src/main/java/com/redmadrobot/chronos_sample/samples/DataLoad.java
import com.redmadrobot.chronos.gui.activity.ChronosActivity;
import com.redmadrobot.chronos_sample.R;
import com.redmadrobot.chronos_sample.operations.SimpleOperation;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.widget.TextView;

package com.redmadrobot.chronos_sample.samples;



/**
 * A sample of how you can easily initiate your layout with data provided by some source, that takes
 * some time to give a response, such as remote server, or a database.
 *
 * @author maximefimov
 */
public final class DataLoad extends ChronosActivity {

    // a key by which the activity saves and restores already loaded data
    private final static String KEY_DATA = "data";

    // a tag which represents a group of operations that can't run simultaneously
    private final static String TAG_DATA_LOADING = "data_loading";

    private TextView mTextOutput;

    // a data that has to be loaded
    private String mData = null;

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_data_load);

        mTextOutput = (TextView) findViewById(R.id.text_output);

        if (savedInstanceState != null) {
            //first of all, the activity tries to restored already loaded data
            mData = savedInstanceState.getString(KEY_DATA);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        //after this point all pending OperationResults are delivered, so that you may be sure,
        // that all proper 'onOperationFinished' calls are done

        if (mData == null) {// if it is still no data
            // The activity launches a loading operations with a tag
            // so that if it comes to this point once again and the data is not loaded yet,
            // the next launch will be ignored.
            // That means, no matter now often user rotates the device,
            // only one operation with a given tag may be pending in a single moment of time.
            runOperation(new SimpleOperation(""), TAG_DATA_LOADING);