Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3970cfac authored by zhuw's avatar zhuw
Browse files

Fix crash when dialog is reconstructed after killed

add default constructor

Change-Id: Ifd52def49e5dc83153723d5a7d1d7bf941f1c105
CRs-Fixed: 2086123
parent da299f0a
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -38,8 +38,15 @@ import com.android.gallery3d.ui.BaseDialogFragment;
import org.codeaurora.gallery.R;

public class AlertMsgDialog extends BaseDialogFragment {
    private int mTitleId;
    private int mMessageId;
    private int mTitleId = -1;
    private int mMessageId = -1;

    public AlertMsgDialog() {
        super();
        //this constructor should only be called by FragmentActivity.
        //if called, it means dialog has been killed and is reconstructed.
        //then don't show title and message.
    }

    public AlertMsgDialog(int titleId, int msgId) {
        mTitleId = titleId;
@@ -49,8 +56,12 @@ public class AlertMsgDialog extends BaseDialogFragment {
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder ab = new AlertDialog.Builder(getActivity());
        if (-1 != mTitleId) {
            ab.setTitle(mTitleId);
        }
        if (-1 != mMessageId) {
            ab.setMessage(mMessageId);
        }
        ab.setCancelable(false);
        ab.setPositiveButton(R.string.ok, null);
        return ab.create();
+21 −8
Original line number Diff line number Diff line
@@ -45,14 +45,21 @@ import com.android.gallery3d.ui.BaseDialogFragment;
import com.android.gallery3d.util.GalleryUtils;

public class DoNotShowAgainDialog extends BaseDialogFragment {
    private int mSharedPrefKeyId;
    private int mTitleId;
    private int mMessageId;
    private int mSharedPrefKeyId = -1;
    private int mTitleId = -1;
    private int mMessageId = -1;
    private CheckBox mDoNotShowAgainChk;
    private DialogInterface.OnClickListener mButtonClickListener;
    private DialogInterface.OnDismissListener mDialogDismissListener;
    private DialogInterface.OnCancelListener mCancelListener;

    public DoNotShowAgainDialog() {
        super();
        //this constructor should only be called by FragmentActivity.
        //if called, it means dialog has been killed and is reconstructed.
        //then don't show title and message.
    }

    public DoNotShowAgainDialog(int titleId, int msgId, int sharedPrefKeyId) {
        mTitleId = titleId;
        mMessageId = msgId;
@@ -65,18 +72,24 @@ public class DoNotShowAgainDialog extends BaseDialogFragment {
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.do_not_show_again_dialog, null);
        TextView message = (TextView) view.findViewById(R.id.message);
        if (-1 != mMessageId) {
            message.setText(mMessageId);
        }
        mDoNotShowAgainChk = (CheckBox) view.findViewById(R.id.do_not_show_chk);

        AlertDialog.Builder ab = new AlertDialog.Builder(getActivity());
        if (-1 != mTitleId) {
            ab.setTitle(mTitleId);
        }
        ab.setView(view);
        ab.setCancelable(false);
        ab.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                if (-1 != mSharedPrefKeyId) {
                    Context context = getActivity();
                    GalleryUtils.setBooleanPref(context,
                            context.getString(mSharedPrefKeyId), mDoNotShowAgainChk.isChecked());
                }
                if(mButtonClickListener != null) mButtonClickListener.onClick(dialog, id);
            }
        });