Android Open Source - diagnostic-tool Button Manager






From Project

Back to project page diagnostic-tool.

License

The source code is released under:

Copyright (c) 2014 Ford Motor Company All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are me...

If you think the Android project diagnostic-tool 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

package com.openxc.openxcdiagnostic.diagnostic;
/*w w  w.j  a  va 2 s  .  co m*/
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;

/**
 * 
 * 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(
                mContext));

        for (final Map.Entry<Integer, ButtonCommand> entry : buttonActions
                .entrySet()) {
            ((Button) mContext.findViewById(entry.getKey()))
                    .setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            entry.getValue().execute();
                        }
                    });
        }
    }

    private void initCommandInfoButton() {
        Button commandInfoButton = (Button) mContext
                .findViewById(R.id.commandQuestionButton);
        commandInfoButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogLauncher.launchAlert(mContext,
                        mResources.getString(R.string.command_label),
                        mResources.getString(R.string.command_info), "OK");
            }
        });
    }

    private void initRequestInfoButtons() {

        final Map<Integer, Integer> infoLabels = new HashMap<>();
        final Map<Integer, Integer> buttonInfo = new HashMap<>();

        buttonInfo.put(R.id.frequencyQuestionButton, R.string.frequency_info);
        infoLabels.put(R.string.frequency_info, R.string.frequency_label);

        buttonInfo.put(R.id.busQuestionButton, R.string.bus_info);
        infoLabels.put(R.string.bus_info, R.string.bus_label);

        buttonInfo.put(R.id.idQuestionButton, R.string.id_info);
        infoLabels.put(R.string.id_info, R.string.id_label);

        buttonInfo.put(R.id.modeQuestionButton, R.string.mode_info);
        infoLabels.put(R.string.mode_info, R.string.mode_label);

        buttonInfo.put(R.id.pidQuestionButton, R.string.pid_info);
        infoLabels.put(R.string.pid_info, R.string.pid_label);

        buttonInfo.put(R.id.payloadQuestionButton, R.string.payload_info);
        infoLabels.put(R.string.payload_info, R.string.payload_label);

        buttonInfo.put(R.id.nameQuestionButton, R.string.name_info);
        infoLabels.put(R.string.name_info, R.string.name_label);

        for (final Integer buttonId : buttonInfo.keySet()) {
            ((Button) mContext.findViewById(buttonId))
                    .setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            int infoId = buttonInfo.get(buttonId);
                            DialogLauncher.launchAlert(mContext, mResources
                                    .getString(infoLabels.get(infoId)),
                                    mResources.getString(infoId), "OK");
                        }
                    });
        }
    }

    private void setRequestButtonText() {
        String label;
        if (mDisplayCommands) {
            label = "Send Command";
        } else {
            label = "Send Request";
        }

        ((Button) mContext.findViewById(R.id.sendRequestButton)).setText(label);
    }

}




Java Source Code List

com.openxc.openxcdiagnostic.dash.DashboardActivity.java
com.openxc.openxcdiagnostic.dash.package-info.java
com.openxc.openxcdiagnostic.diagnostic.ButtonManager.java
com.openxc.openxcdiagnostic.diagnostic.DiagnosticActivity.java
com.openxc.openxcdiagnostic.diagnostic.DiagnosticManager.java
com.openxc.openxcdiagnostic.diagnostic.FavoritesAlertManager.java
com.openxc.openxcdiagnostic.diagnostic.FavoritesManager.java
com.openxc.openxcdiagnostic.diagnostic.InputManager.java
com.openxc.openxcdiagnostic.diagnostic.ResponseDetailsAlertManager.java
com.openxc.openxcdiagnostic.diagnostic.SettingsManager.java
com.openxc.openxcdiagnostic.diagnostic.command.ButtonCommand.java
com.openxc.openxcdiagnostic.diagnostic.command.ClearInputFieldsCommand.java
com.openxc.openxcdiagnostic.diagnostic.command.LaunchFavoritesDialogCommand.java
com.openxc.openxcdiagnostic.diagnostic.command.LaunchSettingsDialogCommand.java
com.openxc.openxcdiagnostic.diagnostic.command.RequestSendCommand.java
com.openxc.openxcdiagnostic.diagnostic.command.package-info.java
com.openxc.openxcdiagnostic.diagnostic.output.OutputRow.java
com.openxc.openxcdiagnostic.diagnostic.output.OutputTableManager.java
com.openxc.openxcdiagnostic.diagnostic.output.TableAdapter.java
com.openxc.openxcdiagnostic.diagnostic.output.TableSaver.java
com.openxc.openxcdiagnostic.diagnostic.output.package-info.java
com.openxc.openxcdiagnostic.diagnostic.pair.CommandPair.java
com.openxc.openxcdiagnostic.diagnostic.pair.DiagnosticPair.java
com.openxc.openxcdiagnostic.diagnostic.pair.Pair.java
com.openxc.openxcdiagnostic.diagnostic.pair.package-info.java
com.openxc.openxcdiagnostic.diagnostic.package-info.java
com.openxc.openxcdiagnostic.dump.DumpActivity.java
com.openxc.openxcdiagnostic.dump.SettingsManager.java
com.openxc.openxcdiagnostic.dump.package-info.java
com.openxc.openxcdiagnostic.menu.GraphDataRetrieveTask.java
com.openxc.openxcdiagnostic.menu.GrapherActivity.java
com.openxc.openxcdiagnostic.menu.GridImageAdapter.java
com.openxc.openxcdiagnostic.menu.GridManager.java
com.openxc.openxcdiagnostic.menu.MenuActivity.java
com.openxc.openxcdiagnostic.menu.package-info.java
com.openxc.openxcdiagnostic.util.ActivityLauncher.java
com.openxc.openxcdiagnostic.util.DialogLauncher.java
com.openxc.openxcdiagnostic.util.Formatter.java
com.openxc.openxcdiagnostic.util.MessageAnalyzer.java
com.openxc.openxcdiagnostic.util.RecurringResponseGenerator.java
com.openxc.openxcdiagnostic.util.ResponseEmulator.java
com.openxc.openxcdiagnostic.util.Toaster.java
com.openxc.openxcdiagnostic.util.Utilities.java
com.openxc.openxcdiagnostic.util.package-info.java