Android Open Source - mobilepower-android Help Dialog Fragment






From Project

Back to project page mobilepower-android.

License

The source code is released under:

Apache License

If you think the Android project mobilepower-android 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

/*
 * Copyright (C) 2013 Dario Scoppelletti, <http://www.scoppelletti.it/>.
 * // w  w  w . j  ava 2  s. com
 * 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 it.scoppelletti.mobilepower.app;

import android.app.*;
import android.content.*;
import android.os.*;
import android.text.*;
import android.view.*;
import android.widget.*;
import org.apache.commons.lang3.*;
import it.scoppelletti.mobilepower.ui.resources.R;

/**
 * Dialogo di Guida.
 * 
 * @since 1.0
 */
public final class HelpDialogFragment extends AbstractDialogFragment implements
        DialogInterface.OnClickListener {

    /**
     * Tag del frammento.
     */
    public static final String TAG = "HelpDialog";

    /**
     * Modalit&agrave; di Guida. Il valore della costante &egrave;
     * <CODE>{@value}</CODE>.
     */
    public static final int MODE_HELP = 0;
    
    /**
     * Modalit&agrave; di conferma. Il valore della costante &egrave;
     * <CODE>{@value}</CODE>.
     */    
    public static final int MODE_CONFIRM = 1;
            
    private static final String ARG_MODE = "mode";
    private static final String ARG_TITLEID = "titleId";
    private static final String ARG_TEXTID = "textId";
    private static final String ARG_PREFKEY = "prefKey";    
    
    private DialogInterface.OnClickListener myOnClickListener;
    
    /**
     * Costruttore.
     */
    public HelpDialogFragment() {        
    }
    
    /**
     * Istanzia un frammento.
     * 
     * @param  mode    Modalit&agrave;.
     * @param  titleId Identificatore della risorsa del titolo.
     * @param  textId  Identificatore della risorsa del testo.
     * @param  prefKey Chiave della preferenza che indica se la Guida &egrave;
     *                 gi&agrave; stata visualizzata.
     * @return         Frammento.
     */
    public static HelpDialogFragment newInstance(int mode, int titleId,
            int textId, String prefKey) {
        Bundle args;
        HelpDialogFragment fragment;
        
        if (StringUtils.isBlank(prefKey)) {
            throw new NullPointerException("Argument prefKey is null.");
        }
        
        args = new Bundle();
        args.putInt(HelpDialogFragment.ARG_MODE, mode);
        args.putInt(HelpDialogFragment.ARG_TITLEID, titleId);
        args.putInt(HelpDialogFragment.ARG_TEXTID, textId);
        args.putString(HelpDialogFragment.ARG_PREFKEY, prefKey);
                
        fragment = new HelpDialogFragment();
        fragment.setArguments(args);
        
        return fragment;
    }
    
    /**
     * Verifica se un&rsquo;attivit&agrave; ha gi&agrave; visualizzato una
     * Guida.
     * 
     * @param  activity Attivit&agrave;.
     * @param  prefKey  Chiave della preferenza che indica se la Guida &egrave;
     *                  gi&agrave; stata visualizzata.
     * @return          Esito della verifica.
     */
    public static boolean isShown(Activity activity, String prefKey) {
        SharedPreferences prefs;
        
        if (activity == null) {
            throw new NullPointerException("Argument activity is null.");
        }
        if (StringUtils.isBlank(prefKey)) {
            throw new NullPointerException("Argument prefKey is null.");
        }
        
        prefs = activity.getPreferences(Context.MODE_PRIVATE);
        return prefs.getBoolean(prefKey, false);
    }
    
    /**
     * Imposta il gestore della chiusura del dialogo.
     * 
     * @param obj Oggetto.
     */
    public void setOnClickListener(DialogInterface.OnClickListener obj) {
        myOnClickListener = obj;
    }

    /**
     * Crea il dialogo.
     * 
     * @param  savedInstanceState Stato dell&rsquo;istanza.
     * @return                    Dialogo.
     */
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        int mode, resId;
        View contentView;
        AlertDialog dlg;
        AlertDialog.Builder builder;
        LayoutInflater inflater;
        TextView textControl;
        Bundle args = getArguments();
        
        builder = newAlertDialogBuilder();
        
        resId = args.getInt(HelpDialogFragment.ARG_TITLEID, 0);
        if (resId > 0) {
            builder.setTitle(resId);
        }
                
        inflater = getActivity().getLayoutInflater();
        contentView = inflater.inflate(R.layout.helpdialog, null);
        builder.setView(contentView);
        
        builder.setIcon(android.R.drawable.ic_dialog_info);
        
        mode = getArguments().getInt(HelpDialogFragment.ARG_MODE,
                HelpDialogFragment.MODE_HELP);
        switch (mode) {
        case HelpDialogFragment.MODE_CONFIRM:
            setCancelable(false);
            builder.setCancelable(false);
            builder.setPositiveButton(R.string.cmd_proceed, this);        
            builder.setNegativeButton(android.R.string.cancel, this);            
            break;
            
        default: // HelpDialogFragment.MODE_HELP
            builder.setNeutralButton(R.string.cmd_close, null);
            break;
        }
        
        dlg = builder.create();
                
        textControl = (TextView) contentView.findViewById(R.id.txt_help);
        textControl.setKeyListener(null);
        
        resId = args.getInt(HelpDialogFragment.ARG_TEXTID, 0);
        if (resId > 0) {
            textControl.setText(Html.fromHtml(getResources().getString(resId)));
        }
        
        return dlg;        
    }    

    /**
     * Gestisce la chiusura del dialogo.
     * 
     * @param dialog Dialogo.
     * @param which  Identificatore del bottone.
     */    
    public void onClick(DialogInterface dialog, int which) {
        if (myOnClickListener != null) {
            myOnClickListener.onClick(dialog, which);
        }
    }
    
    /**
     * Gestisce la chiusura del dialogo.
     * 
     * @param dialog Dialogo.
     */
    @Override
    public void onDismiss(DialogInterface dialog) {
        String prefKey;
        SharedPreferences prefs;
        SharedPreferences.Editor editor;
     
        prefKey = getArguments().getString(HelpDialogFragment.ARG_PREFKEY);
        if (!StringUtils.isBlank(prefKey)) {
            prefs = getActivity().getPreferences(Context.MODE_PRIVATE);
            editor = prefs.edit();
        
            editor.putBoolean(prefKey, true);
            editor.apply();
        }
        
        super.onDismiss(dialog);
    }        
}




Java Source Code List

it.scoppelletti.mobilepower.app.AboutActivity.java
it.scoppelletti.mobilepower.app.AbstractActivity.java
it.scoppelletti.mobilepower.app.AbstractDialogFragment.java
it.scoppelletti.mobilepower.app.AbstractFragment.java
it.scoppelletti.mobilepower.app.AbstractPreferenceActivity.java
it.scoppelletti.mobilepower.app.ActionBarCompat.java
it.scoppelletti.mobilepower.app.ActionBarSupport.java
it.scoppelletti.mobilepower.app.ActivitySupport.java
it.scoppelletti.mobilepower.app.AppUtils.java
it.scoppelletti.mobilepower.app.CommonMenuFragment.java
it.scoppelletti.mobilepower.app.ConfirmDialogFragment.java
it.scoppelletti.mobilepower.app.DatePickerDialogFragment.java
it.scoppelletti.mobilepower.app.FragmentLayoutController.java
it.scoppelletti.mobilepower.app.FragmentSupport.java
it.scoppelletti.mobilepower.app.HelpActivity.java
it.scoppelletti.mobilepower.app.HelpDialogFragment.java
it.scoppelletti.mobilepower.app.MarketTagHandler.java
it.scoppelletti.mobilepower.app.ProgressDialogFragment.java
it.scoppelletti.mobilepower.app.ReleaseNoteActivity.java
it.scoppelletti.mobilepower.app.bluetooth.ActivityBTManager.java
it.scoppelletti.mobilepower.app.data.DatabaseConnectionManager.java
it.scoppelletti.mobilepower.app.data.DatabaseUpgradeTask.java
it.scoppelletti.mobilepower.app.security.ActivityLicenseClient.java
it.scoppelletti.mobilepower.app.security.LicenseBuyDialogFragment.java
it.scoppelletti.mobilepower.app.security.LicenseDemoDialogFragment.java
it.scoppelletti.mobilepower.app.security.LicenseRetryDialogFragment.java
it.scoppelletti.mobilepower.bluetooth.BTManager.java
it.scoppelletti.mobilepower.bluetooth.BTTask.java
it.scoppelletti.mobilepower.bluetooth.OnBTListener.java
it.scoppelletti.mobilepower.data.DatabaseUpgrader.java
it.scoppelletti.mobilepower.data.OnDatabaseConnectionListener.java
it.scoppelletti.mobilepower.graphics.GraphicTools.java
it.scoppelletti.mobilepower.graphics.SizeF.java
it.scoppelletti.mobilepower.io.IOTools.java
it.scoppelletti.mobilepower.media.DefaultOnScanCompletedListener.java
it.scoppelletti.mobilepower.os.AbstractAsyncTask.java
it.scoppelletti.mobilepower.os.AsyncTaskController.java
it.scoppelletti.mobilepower.os.AsyncTaskHost.java
it.scoppelletti.mobilepower.os.BuildCompat.java
it.scoppelletti.mobilepower.preference.AbstractDialogPreference.java
it.scoppelletti.mobilepower.preference.BTDevicePreference.java
it.scoppelletti.mobilepower.preference.ColorPreference.java
it.scoppelletti.mobilepower.preference.EditTextPreferenceEx.java
it.scoppelletti.mobilepower.preference.IntegerSpinnerPreference.java
it.scoppelletti.mobilepower.preference.PreferenceSavedState.java
it.scoppelletti.mobilepower.preference.SeekBarPreference.java
it.scoppelletti.mobilepower.provider.ContactsContractCompat.java
it.scoppelletti.mobilepower.reflect.MemberCache.java
it.scoppelletti.mobilepower.security.LicenseClient.java
it.scoppelletti.mobilepower.types.SimpleDate.java
it.scoppelletti.mobilepower.types.StringTools.java
it.scoppelletti.mobilepower.types.TimeTools.java
it.scoppelletti.mobilepower.types.ValueTools.java
it.scoppelletti.mobilepower.types.ValueType.java
it.scoppelletti.mobilepower.view.ViewSavedState.java
it.scoppelletti.mobilepower.widget.CompoundControl.java
it.scoppelletti.mobilepower.widget.DateControl.java
it.scoppelletti.mobilepower.widget.ImageButtonCompat.java
it.scoppelletti.mobilepower.widget.IntegerSpinner.java
it.scoppelletti.mobilepower.widget.IntegerTextWatcher.java
it.scoppelletti.mobilepower.widget.WidgetTools.java