Java tutorial
/* * Copyright (C) 2012 Jamie McDonald * * This file is part of MusicBrainz for Android. * * MusicBrainz for Android is free software: you can redistribute * it and/or modify it under the terms of the GNU General Public * License as published by the Free Software Foundation, either * version 3 of the License, or (at your option) any later version. * * MusicBrainz for Android is distributed in the hope that it * will be useful, but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MusicBrainz for Android. If not, see * <http://www.gnu.org/licenses/>. */ package org.musicbrainz.mobile.dialog; import org.musicbrainz.mobile.R; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.app.DialogFragment; /* * TODO This class is unused and should be removed unless I start * using it pretty soon. */ public class ConnectionErrorDialog extends DialogFragment { public static final String TAG = "connection_error"; private Context context; private ConnectionErrorCallbacks callbacks; public interface ConnectionErrorCallbacks { public void onConnectionRetry(); public void onConnectionCancel(); } public static ConnectionErrorDialog newInstance() { return new ConnectionErrorDialog(); } @Override public void onAttach(Activity activity) { super.onAttach(activity); context = activity.getApplicationContext(); try { callbacks = (ConnectionErrorCallbacks) activity; } catch (ClassCastException e) { throw new ClassCastException( activity.toString() + " must implement " + ConnectionErrorCallbacks.class.getSimpleName()); } } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage(context.getResources().getString(R.string.err_text)); builder.setCancelable(false); builder.setPositiveButton(getString(R.string.err_pos), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { callbacks.onConnectionRetry(); dialog.cancel(); } }); builder.setNegativeButton(getString(R.string.err_neg), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { callbacks.onConnectionCancel(); } }); return builder.create(); } }