// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ButtonCommand.java
// public interface ButtonCommand {
// 
//     /**
//      * Perform the command.
//      */
//     public void execute();
// 
// }
// 
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ClearInputFieldsCommand.java
// public class ClearInputFieldsCommand implements ButtonCommand {
// 
//     DiagnosticActivity mContext;
// 
//     public ClearInputFieldsCommand(DiagnosticActivity context) {
//         mContext = context;
//     }
// 
//     /**
//      * Hides the keyboard and clears all displaying inputfields.
//      */
//     @Override
//     public void execute() {
//         mContext.hideKeyboard();
//         mContext.clearFields();
//     }
// 
// }
// 
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchFavoritesDialogCommand.java
// public class LaunchFavoritesDialogCommand implements ButtonCommand {
// 
//     DiagnosticActivity mContext;
// 
//     public LaunchFavoritesDialogCommand(DiagnosticActivity context) {
//         mContext = context;
//     }
// 
//     /**
//      * Hides the keyboard and launches the favorites dialog.
//      */
//     public void execute() {
//         mContext.hideKeyboard();
//         mContext.launchFavorites();
//     }
// 
// }
// 
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchSettingsDialogCommand.java
// public class LaunchSettingsDialogCommand implements ButtonCommand {
// 
//     DiagnosticActivity mContext;
// 
//     public LaunchSettingsDialogCommand(DiagnosticActivity context) {
//         mContext = context;
//     }
// 
//     /**
//      * Hides the keyboard and launches the settings dialog.
//      */
//     public void execute() {
//         mContext.hideKeyboard();
//         mContext.launchSettings();
//     }
// 
// }
// 
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/RequestSendCommand.java
// public class RequestSendCommand implements ButtonCommand {
// 
//     DiagnosticActivity mContext;
// 
//     public RequestSendCommand(DiagnosticActivity context) {
//         mContext = context;
//     }
// 
//     /**
//      * Hides the keyboard if displaying. Generates a
//      * <code>DiagnosticRequest</code> or <code>Command</code> from the input,
//      * depending on what is being displayed, and sends the generated command if
//      * successful
//      */
//     public void execute() {
//         mContext.hideKeyboard();
// 
//         VehicleMessage request;
//         if (mContext.isDisplayingCommands()) {
//             request = mContext.generateCommandFromInput();
//         } else {
//             request = mContext.generateDiagnosticRequestFromInput();
//         }
//         if (request != null) {
//             mContext.send(request);
//         }
//     }
// 
// }
// 
// Path: src/com/openxc/openxcdiagnostic/util/DialogLauncher.java
// public class DialogLauncher {
// 
//     /**
//      * Launch an alert with the given <code>title</code> and
//      * <code>message</code>. The alert will have one button that says "OK" to
//      * dismiss it.
//      * 
//      * @param context
//      * @param title
//      * @param message
//      */
//     public static void launchAlert(Activity context, String title,
//             String message) {
//         launchAlert(context, title, message, "OK");
//     }
// 
//     /**
//      * Launch an alert with the given <code>title</code> and
//      * <code>message</code>. The alert will have one button that has the value
//      * of <code>doneButton</code> to dismiss it.
//      * 
//      * @param context
//      * @param title
//      * @param message
//      */
//     public static void launchAlert(Activity context, String title,
//             String message, String doneButton) {
//         AlertDialog.Builder builder = new AlertDialog.Builder(context);
//         builder.setMessage(message);
//         builder.setTitle(title);
//         builder.setPositiveButton(doneButton, null);
//         builder.create().show();
//     }
// 
// }


import java.util.HashMap;
import java.util.Map;
import android.content.res.Resources;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.diagnostic.command.ButtonCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.ClearInputFieldsCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchFavoritesDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchSettingsDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.RequestSendCommand;
import com.openxc.openxcdiagnostic.util.DialogLauncher;
package com.openxc.openxcdiagnostic.diagnostic;




/**
 * 
 * Class for managing all of the static buttons for the diagnostic activity UI.
 * 
 */
public class ButtonManager implements DiagnosticManager {

    private DiagnosticActivity mContext;
    private boolean mDisplayCommands;
    private Resources mResources;

    public ButtonManager(DiagnosticActivity context, boolean displayCommands) {
        mContext = context;
        mResources = mContext.getResources();
        setRequestCommandState(displayCommands);
        initButtons();
    }

    @Override
    public void setRequestCommandState(boolean displayCommands) {
        mDisplayCommands = displayCommands;
        if (displayCommands) {
            initCommandInfoButton();
        } else {
            initRequestInfoButtons();
        }

        setRequestButtonText();
    }

    private void initButtons() {

        setRequestButtonText();

        Map<Integer, ButtonCommand> buttonActions = new HashMap<>();
        buttonActions.put(R.id.sendRequestButton, new RequestSendCommand(
                mContext));
        buttonActions.put(R.id.clearButton, new ClearInputFieldsCommand(
                mContext));
        buttonActions.put(R.id.favoritesButton,
                new LaunchFavoritesDialogCommand(mContext));
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ButtonCommand.java
// public interface ButtonCommand {
// 
//     /**
//      * Perform the command.
//      */
//     public void execute();
// 
// }
// 
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ClearInputFieldsCommand.java
// public class ClearInputFieldsCommand implements ButtonCommand {
// 
//     DiagnosticActivity mContext;
// 
//     public ClearInputFieldsCommand(DiagnosticActivity context) {
//         mContext = context;
//     }
// 
//     /**
//      * Hides the keyboard and clears all displaying inputfields.
//      */
//     @Override
//     public void execute() {
//         mContext.hideKeyboard();
//         mContext.clearFields();
//     }
// 
// }
// 
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchFavoritesDialogCommand.java
// public class LaunchFavoritesDialogCommand implements ButtonCommand {
// 
//     DiagnosticActivity mContext;
// 
//     public LaunchFavoritesDialogCommand(DiagnosticActivity context) {
//         mContext = context;
//     }
// 
//     /**
//      * Hides the keyboard and launches the favorites dialog.
//      */
//     public void execute() {
//         mContext.hideKeyboard();
//         mContext.launchFavorites();
//     }
// 
// }
// 
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchSettingsDialogCommand.java
// public class LaunchSettingsDialogCommand implements ButtonCommand {
// 
//     DiagnosticActivity mContext;
// 
//     public LaunchSettingsDialogCommand(DiagnosticActivity context) {
//         mContext = context;
//     }
// 
//     /**
//      * Hides the keyboard and launches the settings dialog.
//      */
//     public void execute() {
//         mContext.hideKeyboard();
//         mContext.launchSettings();
//     }
// 
// }
// 
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/RequestSendCommand.java
// public class RequestSendCommand implements ButtonCommand {
// 
//     DiagnosticActivity mContext;
// 
//     public RequestSendCommand(DiagnosticActivity context) {
//         mContext = context;
//     }
// 
//     /**
//      * Hides the keyboard if displaying. Generates a
//      * <code>DiagnosticRequest</code> or <code>Command</code> from the input,
//      * depending on what is being displayed, and sends the generated command if
//      * successful
//      */
//     public void execute() {
//         mContext.hideKeyboard();
// 
//         VehicleMessage request;
//         if (mContext.isDisplayingCommands()) {
//             request = mContext.generateCommandFromInput();
//         } else {
//             request = mContext.generateDiagnosticRequestFromInput();
//         }
//         if (request != null) {
//             mContext.send(request);
//         }
//     }
// 
// }
// 
// Path: src/com/openxc/openxcdiagnostic/util/DialogLauncher.java
// public class DialogLauncher {
// 
//     /**
//      * Launch an alert with the given <code>title</code> and
//      * <code>message</code>. The alert will have one button that says "OK" to
//      * dismiss it.
//      * 
//      * @param context
//      * @param title
//      * @param message
//      */
//     public static void launchAlert(Activity context, String title,
//             String message) {
//         launchAlert(context, title, message, "OK");
//     }
// 
//     /**
//      * Launch an alert with the given <code>title</code> and
//      * <code>message</code>. The alert will have one button that has the value
//      * of <code>doneButton</code> to dismiss it.
//      * 
//      * @param context
//      * @param title
//      * @param message
//      */
//     public static void launchAlert(Activity context, String title,
//             String message, String doneButton) {
//         AlertDialog.Builder builder = new AlertDialog.Builder(context);
//         builder.setMessage(message);
//         builder.setTitle(title);
//         builder.setPositiveButton(doneButton, null);
//         builder.create().show();
//     }
// 
// }


// Path: src/com/openxc/openxcdiagnostic/diagnostic/ButtonManager.java
import java.util.HashMap;
import java.util.Map;
import android.content.res.Resources;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.diagnostic.command.ButtonCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.ClearInputFieldsCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchFavoritesDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchSettingsDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.RequestSendCommand;
import com.openxc.openxcdiagnostic.util.DialogLauncher;

package com.openxc.openxcdiagnostic.diagnostic;




/**
 * 
 * Class for managing all of the static buttons for the diagnostic activity UI.
 * 
 */
public class ButtonManager implements DiagnosticManager {

    private DiagnosticActivity mContext;
    private boolean mDisplayCommands;
    private Resources mResources;

    public ButtonManager(DiagnosticActivity context, boolean displayCommands) {
        mContext = context;
        mResources = mContext.getResources();
        setRequestCommandState(displayCommands);
        initButtons();
    }

    @Override
    public void setRequestCommandState(boolean displayCommands) {
        mDisplayCommands = displayCommands;
        if (displayCommands) {
            initCommandInfoButton();
        } else {
            initRequestInfoButtons();
        }

        setRequestButtonText();
    }

    private void initButtons() {

        setRequestButtonText();

        Map<Integer, ButtonCommand> buttonActions = new HashMap<>();
        buttonActions.put(R.id.sendRequestButton, new RequestSendCommand(
                mContext));
        buttonActions.put(R.id.clearButton, new ClearInputFieldsCommand(
                mContext));
        buttonActions.put(R.id.favoritesButton,
                new LaunchFavoritesDialogCommand(mContext));
        buttonActions.put(R.id.settingsButton, new LaunchSettingsDialogCommand(