Java tutorial
/* * Copyright 2013 Andrii Iasynetskyi * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package org.yasik.android.utils.conditions; import org.yasik.android.utils.rateapp.R; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.text.Html; import android.text.method.LinkMovementMethod; import android.view.LayoutInflater; import android.widget.LinearLayout; import android.widget.TextView; /** * A default dialog fragment used by the framework. * * @author yasinecky@gmail.com (Andrii Iasynetskyi) */ public class RateAppDialogFragment extends DialogFragment { public interface RateAppDialogListener { public void onDialogRateNowClick(DialogFragment dialog); public void onDialogRemindClick(DialogFragment dialog); public void onDialogCancelClick(DialogFragment dialog); } /** * Use this instance of the interface to deliver action events. */ private static RateAppDialogListener mListener; public static RateAppDialogFragment newInstance(RateAppDialogListener listener) { mListener = listener; RateAppDialogFragment dialogFragment = new RateAppDialogFragment(); return dialogFragment; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { setCancelable(true); // Inflate and build the dialog view. LayoutInflater inflater = getActivity().getLayoutInflater(); LinearLayout dialogLayout = (LinearLayout) inflater.inflate(R.layout.rateapp_dialog_fragment, null); TextView textView = (TextView) dialogLayout.findViewById(R.id.rateapp_dialog_text); textView.setText(Html.fromHtml(getString(R.string.rateapp_dialog_text))); textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setSingleLine(false); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setView(dialogLayout).setTitle(R.string.rateapp_dialog_title) .setPositiveButton(R.string.rateapp_btn_title_rateme, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mListener.onDialogRateNowClick(RateAppDialogFragment.this); } }).setNeutralButton(R.string.rateapp_btn_title_remind, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mListener.onDialogRemindClick(RateAppDialogFragment.this); } }).setNegativeButton(R.string.rateapp_btn_title_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mListener.onDialogCancelClick(RateAppDialogFragment.this); } }).setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { mListener.onDialogCancelClick(RateAppDialogFragment.this); } }); return builder.create(); } }