Android Open Source - BusWear Main Mobile Activity






From Project

Back to project page BusWear.

License

The source code is released under:

Apache License

If you think the Android project BusWear 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 pl.tajchert.buswear.sample;
// w  w w.  ja  v a 2 s.  co m
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.Arrays;
import java.util.List;
import java.util.Random;

import pl.tajchert.buswear.EventBus;


public class MainMobileActivity extends ActionBarActivity {
    private EditText editTextToSend;
    private Button buttonEverywhere;
    private Button buttonLocal;
    private Button buttonRemote;
    private Button buttonRemoteRandom;
    private Random rand = new Random();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EventBus.getDefault().register(this);
        editTextToSend = (EditText) findViewById(R.id.editTextToSend);
        buttonEverywhere = (Button) findViewById(R.id.buttonEverywhere);
        buttonLocal = (Button) findViewById(R.id.buttonLocal);
        buttonRemote = (Button) findViewById(R.id.buttonRemote);
        buttonRemoteRandom = (Button) findViewById(R.id.buttonRemoteRandom);

        setButtons();
    }

    private void setButtons() {
        buttonEverywhere.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Send Custom object to both local and remote EventBus
                EventBus.getDefault().post(new pl.tajchert.buswear.sample.CustomObject(editTextToSend.getText().toString()), MainMobileActivity.this);
            }
        });
        buttonLocal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Send Custom object only to local EventBus
                EventBus.getDefault().postLocal(new CustomObject(editTextToSend.getText().toString()));
            }
        });
        buttonRemote.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Send Custom object only to remote EventBus
                EventBus.getDefault().postRemote(new CustomObject(editTextToSend.getText().toString()), MainMobileActivity.this);
            }
        });

        buttonRemoteRandom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List<Object> messages = Arrays.<Object>asList(editTextToSend.getText().toString(), 1, 1L, 1.0f, 1.0, (short) 1);
                Object random = messages.get(rand.nextInt(messages.size()));
                EventBus.getDefault().post(random, MainMobileActivity.this);
            }
        });
    }

    /**
     * It receives events from event bus, also from Wear device if it send everywhere or remote.
     * @param customObject
     */
    public void onEvent(CustomObject customObject) {
        Toast.makeText(MainMobileActivity.this, "Object: " + customObject.getName(), Toast.LENGTH_SHORT).show();
    }
    public void onEvent(String stringReceived) {
        Toast.makeText(MainMobileActivity.this, "String: " + stringReceived, Toast.LENGTH_SHORT).show();
    }
}




Java Source Code List

pl.tajchert.buswear.AsyncPoster.java
pl.tajchert.buswear.BackgroundPoster.java
pl.tajchert.buswear.EventBusBuilder.java
pl.tajchert.buswear.EventBusException.java
pl.tajchert.buswear.EventBus.java
pl.tajchert.buswear.HandlerPoster.java
pl.tajchert.buswear.NoSubscriberEvent.java
pl.tajchert.buswear.PendingPostQueue.java
pl.tajchert.buswear.PendingPost.java
pl.tajchert.buswear.SubscriberExceptionEvent.java
pl.tajchert.buswear.SubscriberMethodFinder.java
pl.tajchert.buswear.SubscriberMethod.java
pl.tajchert.buswear.Subscription.java
pl.tajchert.buswear.ThreadMode.java
pl.tajchert.buswear.sample.CustomObject.java
pl.tajchert.buswear.sample.CustomObject.java
pl.tajchert.buswear.sample.MainMobileActivity.java
pl.tajchert.buswear.sample.MainWearActivity.java
pl.tajchert.buswear.util.AsyncExecutor.java
pl.tajchert.buswear.util.ErrorDialogConfig.java
pl.tajchert.buswear.util.ErrorDialogFragmentFactory.java
pl.tajchert.buswear.util.ErrorDialogFragments.java
pl.tajchert.buswear.util.ErrorDialogManager.java
pl.tajchert.buswear.util.ExceptionToResourceMapping.java
pl.tajchert.buswear.util.HasExecutionScope.java
pl.tajchert.buswear.util.ThrowableFailureEvent.java
pl.tajchert.buswear.wear.EventCatcher.java
pl.tajchert.buswear.wear.SendByteArrayToNode.java
pl.tajchert.buswear.wear.SendCommandToNode.java
pl.tajchert.buswear.wear.SendWearManager.java
pl.tajchert.buswear.wear.WearBusTools.java