Android Open Source - EventBus Error Dialog Fragments






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.event.util;
//  w  w w .  j a  v  a 2 s  . c o  m
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import de.greenrobot.event.EventBus;

public class ErrorDialogFragments {
    /** TODO Use config:  Icon res ID to use for all error dialogs. May be configured by each app (optional). */
    public static int ERROR_DIALOG_ICON = 0;

    /** TODO Use config:  Event class to be fired on dismissing the dialog by the user. May be configured by each app. */
    public static Class<?> EVENT_TYPE_ON_CLICK;

    public static Dialog createDialog(Context context, Bundle arguments, OnClickListener onClickListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(arguments.getString(ErrorDialogManager.KEY_TITLE));
        builder.setMessage(arguments.getString(ErrorDialogManager.KEY_MESSAGE));
        if (ERROR_DIALOG_ICON != 0) {
            builder.setIcon(ERROR_DIALOG_ICON);
        }
        builder.setPositiveButton(android.R.string.ok, onClickListener);
        return builder.create();
    }

    public static void handleOnClick(DialogInterface dialog, int which, Activity activity, Bundle arguments) {
        if (EVENT_TYPE_ON_CLICK != null) {
            Object event;
            try {
                event = EVENT_TYPE_ON_CLICK.newInstance();
            } catch (Exception e) {
                throw new RuntimeException("Event cannot be constructed", e);
            }
            EventBus eventBus = ErrorDialogManager.factory.config.getEventBus();
            eventBus.post(event);
        }
        boolean finish = arguments.getBoolean(ErrorDialogManager.KEY_FINISH_AFTER_DIALOG, false);
        if (finish && activity != null) {
            activity.finish();
        }
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static class Honeycomb extends android.app.DialogFragment implements OnClickListener {
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            return createDialog(getActivity(), getArguments(), this);
        }

        @Override
        public void onClick(DialogInterface dialog, int which) {
            handleOnClick(dialog, which, getActivity(), getArguments());
        }
    }

    public static class Support extends DialogFragment implements OnClickListener {
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            return createDialog(getActivity(), getArguments(), this);
        }

        @Override
        public void onClick(DialogInterface dialog, int which) {
            handleOnClick(dialog, which, getActivity(), getArguments());
        }
    }
}




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