Android Open Source - latrobe-datacapture-dir Remote Activity






From Project

Back to project page latrobe-datacapture-dir.

License

The source code is released under:

MIT License

If you think the Android project latrobe-datacapture-dir 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 com.example.DataCaptureApp.testing;
/*from   w ww . ja  v a2 s .co m*/
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.example.DataCaptureApp.*;
import com.example.DataCaptureApp.data.*;
import com.example.DataCaptureApp.services.RemoteConnectivityService;

/**
 * Created by Tom on 8/10/2014.
 */
public class RemoteActivity extends Activity implements IDataEventListener
{
    private static final String TAG = "RemoteActivity";

    private EditText mUrlText;
    private TextView mTextStatus;

    private RemoteConnectivityService mService;
    private Data mServiceConfig;

    private ServiceConnection mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder binder) {
            mService = (RemoteConnectivityService)((DataService.LocalBinder)binder).getService();
            Log.d(TAG, "Remote Service Connected");
            mService.setEventListener(RemoteActivity.this);
            mService.setDataListener(RemoteActivity.this);
            try
            {
                mService.start(mServiceConfig);
            }
            catch(FailedInitialisationException e)
            {
                setStatus("Failed to startSampling: " + e.getMessage());
                unbindService(this);
                return;
            }
        }

        @Override
        public void onServiceDisconnected(ComponentName name)
        {
            mService = null;
        }
    };

    @Override
    public void onCreate(Bundle savedInstance)
    {
        super.onCreate(savedInstance);
        setContentView(R.layout.remote);

        mUrlText = (EditText)findViewById(R.id.remoteUrl);
        mTextStatus = (TextView)findViewById(R.id.textStatus);
    }

    public void onInitialiseRemote(View v)
    {
        String url = mUrlText.getText().toString();
        mServiceConfig = new Data();
        mServiceConfig.set("url", url);
        mServiceConfig.set("idKey", "session");
        mServiceConfig.set("submitRoute", "session");
        mServiceConfig.set("handleType", "test");
        bindService(new Intent(this, RemoteConnectivityService.class), mServiceConn, Context.BIND_AUTO_CREATE);
    }

    @Override
    public void onData(IDataSource source, Data data)
    {
        if(source == mService)
        {
            setStatus(source + ": data received");
            String serverName = data.get("serverName");
            String version = data.get("version");
            Object[] handles = data.get("handles");
            String status = "Contacted " + serverName + " (" + version + ") [";
            for(Object obj : handles)
            {
                status += obj + " ";
            }
            status += ']';
            setStatus(status);
        }
    }

    @Override
    public void onEvent(IEventSource source, Event event, Object arg)
    {
        if(source == mService)
        {
            setStatus(source + ": " + event + " [" + (arg == null ? "no arg" : arg.toString()) + "]");
        }
    }

    private void setStatus(final String status)
    {
        this.runOnUiThread(new Runnable() {
            @Override
            public void run()
            {
                mTextStatus.append(status + '\n');
            }
        });
    }
}




Java Source Code List

com.example.DataCaptureApp.AdvConfigActivity.java
com.example.DataCaptureApp.ConfigActivity.java
com.example.DataCaptureApp.MasterActivity.java
com.example.DataCaptureApp.MasterService.java
com.example.DataCaptureApp.SlaveActivity.java
com.example.DataCaptureApp.SlaveService.java
com.example.DataCaptureApp.data.DataServiceConnection.java
com.example.DataCaptureApp.data.DataService.java
com.example.DataCaptureApp.data.DataTransform.java
com.example.DataCaptureApp.data.Data.java
com.example.DataCaptureApp.data.Event.java
com.example.DataCaptureApp.data.FailedInitialisationException.java
com.example.DataCaptureApp.data.IDataEventListener.java
com.example.DataCaptureApp.data.IDataListener.java
com.example.DataCaptureApp.data.IDataSource.java
com.example.DataCaptureApp.data.IDataTransform.java
com.example.DataCaptureApp.data.IEventListener.java
com.example.DataCaptureApp.data.IEventSource.java
com.example.DataCaptureApp.services.BluetoothConnectivityService.java
com.example.DataCaptureApp.services.BluetoothThread.java
com.example.DataCaptureApp.services.DataDbContract.java
com.example.DataCaptureApp.services.DataDbHelper.java
com.example.DataCaptureApp.services.DataStoreService.java
com.example.DataCaptureApp.services.HttpThread.java
com.example.DataCaptureApp.services.RemoteConnectivityService.java
com.example.DataCaptureApp.services.SensorSampleService.java
com.example.DataCaptureApp.services.SensorSampler.java
com.example.DataCaptureApp.testing.BluetoothActivity.java
com.example.DataCaptureApp.testing.DataStoreActivity.java
com.example.DataCaptureApp.testing.DataTester.java
com.example.DataCaptureApp.testing.IServiceListener.java
com.example.DataCaptureApp.testing.MainService.java
com.example.DataCaptureApp.testing.MasterTestActivity.java
com.example.DataCaptureApp.testing.RandomService.java
com.example.DataCaptureApp.testing.RemoteActivity.java
com.example.DataCaptureApp.testing.SensorSampleActivity.java
com.example.DataCaptureApp.testing.ServiceTestActivity.java
com.example.DataCaptureApp.testing.SlaveTestActivity.java
com.example.DataCaptureApp.testing.TestActivity.java
com.example.DataCaptureApp.transforms.AggregatorDataTransform.java
com.example.DataCaptureApp.transforms.ArithmeticDataTransform.java
com.example.DataCaptureApp.transforms.ArrayCollectDataTransform.java
com.example.DataCaptureApp.transforms.ArraySplitDataTransform.java
com.example.DataCaptureApp.transforms.DeserialiseDataTransform.java
com.example.DataCaptureApp.transforms.FieldCopyDataTransform.java
com.example.DataCaptureApp.transforms.FieldModifyDataTransform.java
com.example.DataCaptureApp.transforms.FieldRenameDataTransform.java
com.example.DataCaptureApp.transforms.IntervalAggregatorDataTransform.java
com.example.DataCaptureApp.transforms.PackDataTransform.java
com.example.DataCaptureApp.transforms.QuaternionDifferenceDataTransform.java
com.example.DataCaptureApp.transforms.RemoveDataTransform.java
com.example.DataCaptureApp.transforms.SetDataTransform.java
com.example.DataCaptureApp.transforms.UnpackDataTransform.java
com.example.DataCaptureApp.utils.BroadcastDataSource.java
com.example.DataCaptureApp.utils.ByteUtils.java
com.example.DataCaptureApp.utils.DataEventHandler.java
com.example.DataCaptureApp.utils.DataHandlerThread.java
com.example.DataCaptureApp.utils.JSONReader.java
com.example.DataCaptureApp.utils.Quaternion.java
com.example.DataCaptureApp.utils.SerialisationUtils.java