/* * GeoSolutions - MapstoreMobile - GeoSpatial Framework on Android based devices * Copyright (C) 2014 GeoSolutions (www.geo-solutions.it) * * This program 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. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */ package it.geosolutions.geocollect.android.core.widgets.dialog; import android.app.Activity; import android.os.Bundle; import android.support.v4.app.DialogFragment; /** * A Dialog Fragment that retain its instance. * It contains the basic implementation of methods to extend * and fixes for some bugs in the support library * * @author Lorenzo Natali (lorenzo.natali@geo-solutions.it) * */ public class RetainedDialogFragment extends DialogFragment { protected Activity activity; /** * set the retain instance to avoid deletion on * orientation changes */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } /** * A reference to the current activity is mantained * on attach */ @Override public void onAttach(Activity activity) { // TODO Auto-generated method stub super.onAttach(activity); this.activity = activity; } /** * workaround for bug: https://code.google.com/p/android/issues/detail?id=17423 * of support library. */ @Override public void onDestroyView() { if (getDialog() != null && getRetainInstance()) getDialog().setOnDismissListener(null); super.onDestroyView(); } }