Android Open Source - diagnostic-tool Formatter






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.util;
/*from w w w . ja va 2  s. co m*/
import java.util.Locale;

import android.app.Activity;

import com.openxc.messages.Command;
import com.openxc.messages.CommandResponse;
import com.openxc.messages.DiagnosticMessage;
import com.openxc.messages.DiagnosticRequest;
import com.openxc.messages.DiagnosticResponse;
import com.openxc.messages.formatters.ByteAdapter;
import com.openxc.openxcdiagnostic.R;

/**
 * 
 * Class for consolidating logic and ensuring consistency of output for all of
 * the message field outputs.
 * 
 */
public class Formatter {

    private Formatter() {
    }

    /**
     * Appends a space to <code>st</code>
     * 
     * @param st
     * @return
     */
    private static String padRight(String st) {
        return st + " ";
    }

    // all these outputs are italicized so the space prevents them from being
    // cut off at the end (mostly)
    public static String getBusOutput(DiagnosticRequest req) {
        return padRight(String.valueOf(req.getBusId()));
    }

    public static String getBusOutput(DiagnosticResponse resp) {
        return padRight(String.valueOf(resp.getBusId()));
    }

    public static String getIdOutput(DiagnosticMessage msg) {
        return padRight("0x"
                + Integer.toHexString(msg.getId()).toUpperCase(Locale.US));
    }

    public static String getModeOutput(DiagnosticMessage msg) {
        return padRight("0x"
                + Integer.toHexString(msg.getMode()).toUpperCase(Locale.US));
    }

    public static String getPidOutput(DiagnosticMessage msg) {
        return msg.getPid() == null ? "" : padRight("0x"
                + Integer.toHexString(msg.getPid()).toUpperCase(Locale.US));
    }

    public static String getPayloadOutput(DiagnosticMessage msg) {
        return msg.getPayload() == null ? "" : padRight("0x"
                + ByteAdapter.byteArrayToHexString(msg.getPayload()));
    }

    public static String getSuccessOutput(DiagnosticResponse resp) {
        return padRight(String.valueOf(resp.isSuccessful()));
    }

    public static String getValueOutput(DiagnosticResponse resp) {
        return padRight(String.valueOf(resp.getValue()));
    }

    public static String getFrequencyOutput(DiagnosticRequest req) {
        return req.getFrequency() == null ? "" : padRight(String.valueOf(req
                .getFrequency()));
    }

    public static String getNameOutput(DiagnosticRequest req) {
        return req.getName() == null ? "" : padRight(String.valueOf(req
                .getName()));
    }

    public static String getMessageOutput(CommandResponse resp) {
        return resp.getMessage() == null ? "" : padRight(resp.getMessage());
    }

    public static String getCommandOutput(CommandResponse resp) {
        return getCommandOutput(new Command(resp.getCommand()));
    }

    public static String getCommandOutput(Command command) {
        return command.getCommand() == null ? "" : padRight(command
                .getCommand().toString());
    }

    public static String getResponseCodeOutput(DiagnosticResponse resp) {
        return padRight(resp.getNegativeResponseCode().hexCodeString());
    }

    public static String getOutputTableResponseCodeOutput(
            DiagnosticResponse resp) {
        return padRight(Utilities.getDocumentationError(resp) + " : "
                + getResponseCodeOutput(resp));
    }

    /**
     * 
     * @param context
     * @param resp
     * @return Light blue if resp.isSuccessful() == true, dark red otherwise
     */
    public static int getOutputColor(Activity context, DiagnosticResponse resp) {
        int color = resp.isSuccessful() ? R.color.lightBlue : R.color.darkRed;
        return context.getResources().getColor(color);
    }

}




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