Android Open Source - EventBus Test Setup Activity






From Project

Back to project page EventBus.

License

The source code is released under:

Apache License

If you think the Android project EventBus 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 de.greenrobot.eventperf;
//from  ww w .j  a  v a 2s .c o  m
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import de.greenrobot.event.ThreadMode;
import de.greenrobot.eventperf.testsubject.PerfTestEventBus;
import de.greenrobot.eventperf.testsubject.PerfTestOtto;

import java.util.ArrayList;

public class TestSetupActivity extends Activity {

    @SuppressWarnings("rawtypes")
    static final Class[] TEST_CLASSES_EVENTBUS = {PerfTestEventBus.Post.class,//
            PerfTestEventBus.RegisterOneByOne.class,//
            PerfTestEventBus.RegisterAll.class, //
            PerfTestEventBus.RegisterFirstTime.class};

    static final Class[] TEST_CLASSES_OTTO = {PerfTestOtto.Post.class,//
            PerfTestOtto.RegisterOneByOne.class,//
            PerfTestOtto.RegisterAll.class, //
            PerfTestOtto.RegisterFirstTime.class};

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setuptests);

        Spinner spinnerRun = (Spinner) findViewById(R.id.spinnerTestToRun);
        spinnerRun.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            public void onItemSelected(AdapterView<?> adapter, View v, int pos, long lng) {
                int eventsVisibility = pos == 0 ? View.VISIBLE : View.GONE;
                findViewById(R.id.relativeLayoutForEvents).setVisibility(eventsVisibility);
                findViewById(R.id.spinnerThread).setVisibility(eventsVisibility);
            }

            public void onNothingSelected(AdapterView<?> arg0) {
            }
        });
    }

    public void checkEventBus(View v) {
        Spinner spinnerThread = (Spinner) findViewById(R.id.spinnerThread);
        CheckBox checkBoxEventBus = (CheckBox) findViewById(R.id.checkBoxEventBus);
        int visibility = checkBoxEventBus.isChecked() ? View.VISIBLE : View.GONE;
        spinnerThread.setVisibility(visibility);
    }

    public void startClick(View v) {
        TestParams params = new TestParams();
        Spinner spinnerThread = (Spinner) findViewById(R.id.spinnerThread);
        String threadModeStr = spinnerThread.getSelectedItem().toString();
        ThreadMode threadMode = ThreadMode.valueOf(threadModeStr);
        params.setThreadMode(threadMode);

        params.setEventInheritance(((CheckBox) findViewById(R.id.checkBoxEventBusEventHierarchy)).isChecked());

        EditText editTextEvent = (EditText) findViewById(R.id.editTextEvent);
        params.setEventCount(Integer.parseInt(editTextEvent.getText().toString()));

        EditText editTextSubscriber = (EditText) findViewById(R.id.editTextSubscribe);
        params.setSubscriberCount(Integer.parseInt(editTextSubscriber.getText().toString()));

        Spinner spinnerTestToRun = (Spinner) findViewById(R.id.spinnerTestToRun);
        int testPos = spinnerTestToRun.getSelectedItemPosition();
        params.setTestNumber(testPos + 1);
        ArrayList<Class<? extends Test>> testClasses = initTestClasses(testPos);
        params.setTestClasses(testClasses);

        Intent intent = new Intent();
        intent.setClass(this, TestRunnerActivity.class);
        intent.putExtra("params", params);
        startActivity(intent);
    }

    @SuppressWarnings("unchecked")
    private ArrayList<Class<? extends Test>> initTestClasses(int testPos) {
        ArrayList<Class<? extends Test>> testClasses = new ArrayList<Class<? extends Test>>();
        // the attributes are putted in the intent (eventbus, otto, broadcast, local broadcast)
        final CheckBox checkBoxEventBus = (CheckBox) findViewById(R.id.checkBoxEventBus);
        final CheckBox checkBoxOtto = (CheckBox) findViewById(R.id.checkBoxOtto);
        final CheckBox checkBoxBroadcast = (CheckBox) findViewById(R.id.checkBoxBroadcast);
        final CheckBox checkBoxLocalBroadcast = (CheckBox) findViewById(R.id.checkBoxLocalBroadcast);
        if (checkBoxEventBus.isChecked()) {
            testClasses.add(TEST_CLASSES_EVENTBUS[testPos]);
        }
        if (checkBoxOtto.isChecked()) {
            testClasses.add(TEST_CLASSES_OTTO[testPos]);
        }
        if (checkBoxBroadcast.isChecked()) {
        }
        if (checkBoxLocalBroadcast.isChecked()) {
        }

        return testClasses;
    }
}




Java Source Code List

de.greenrobot.event.AsyncPoster.java
de.greenrobot.event.BackgroundPoster.java
de.greenrobot.event.EventBusBuilder.java
de.greenrobot.event.EventBusException.java
de.greenrobot.event.EventBus.java
de.greenrobot.event.HandlerPoster.java
de.greenrobot.event.NoSubscriberEvent.java
de.greenrobot.event.PendingPostQueue.java
de.greenrobot.event.PendingPost.java
de.greenrobot.event.SubscriberExceptionEvent.java
de.greenrobot.event.SubscriberMethodFinder.java
de.greenrobot.event.SubscriberMethod.java
de.greenrobot.event.Subscription.java
de.greenrobot.event.ThreadMode.java
de.greenrobot.event.util.AsyncExecutor.java
de.greenrobot.event.util.ErrorDialogConfig.java
de.greenrobot.event.util.ErrorDialogFragmentFactory.java
de.greenrobot.event.util.ErrorDialogFragments.java
de.greenrobot.event.util.ErrorDialogManager.java
de.greenrobot.event.util.ExceptionToResourceMapping.java
de.greenrobot.event.util.HasExecutionScope.java
de.greenrobot.event.util.ThrowableFailureEvent.java
de.greenrobot.eventperf.TestEvent.java
de.greenrobot.eventperf.TestFinishedEvent.java
de.greenrobot.eventperf.TestParams.java
de.greenrobot.eventperf.TestRunnerActivity.java
de.greenrobot.eventperf.TestRunner.java
de.greenrobot.eventperf.TestSetupActivity.java
de.greenrobot.eventperf.Test.java
de.greenrobot.eventperf.testsubject.PerfTestEventBus.java
de.greenrobot.eventperf.testsubject.PerfTestOtto.java