Android Open Source - diagnostic-tool Dump Activity






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.dump;
/*www.  java2s  .c o m*/
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.openxc.VehicleManager;
import com.openxc.messages.KeyMatcher;
import com.openxc.messages.VehicleMessage;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.util.ActivityLauncher;

public class DumpActivity extends Activity {

    private static String TAG = "DumpActivity";

    private VehicleManager mVehicleManager;
    private boolean mIsBound;
    private final Handler mHandler = new Handler();
    private LinearLayout mDumpLayout;
    private SettingsManager mSettingsManager;
    private boolean isPaused = false;

    VehicleMessage.Listener mDumpListener = new VehicleMessage.Listener() {
        @Override
        public void receive(final VehicleMessage response) {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (!isPaused) {
                        TextView newRow = new TextView(DumpActivity.this);
                        newRow.setText(response.toString());
                        newRow.setTextColor(DumpActivity.this.getResources()
                                .getColor(R.color.lightBlue));
                        newRow.setTextSize(18f);
                        mDumpLayout.addView(newRow, 0);
                        limitMessageCount(mSettingsManager.getNumMessages());
                    }
                }
            });
        }
    };

    private ServiceConnection mConnection = new ServiceConnection() {
        @Override
        public void
                onServiceConnected(ComponentName className, IBinder service) {
            Log.i(TAG, "Bound to VehicleManager");
            mVehicleManager = ((VehicleManager.VehicleBinder) service)
                    .getService();
            mIsBound = true;
            mVehicleManager.addListener(KeyMatcher.getWildcardMatcher(),
                    mDumpListener);
        }

        @Override
        public void onServiceDisconnected(ComponentName className) {
            Log.w(TAG, "VehicleService disconnected unexpectedly");
            mVehicleManager = null;
            mIsBound = false;
        }
    };

    public void limitMessageCount(int numMessages) {
        while (mDumpLayout.getChildCount() > numMessages) {
            mDumpLayout.removeViewAt(numMessages);
        }
    }

    private void initButtons() {

        ((Button) findViewById(R.id.dumpClearButton))
                .setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mDumpLayout.removeAllViews();
                    }
                });

        final Button pauseButton = (Button) findViewById(R.id.dumpPauseButton);
        pauseButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                isPaused = !isPaused;
                setPauseButtonSelector();
            }
        });
        setPauseButtonSelector();

        ((Button) findViewById(R.id.dumpSettingsButton))
                .setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mSettingsManager.showAlert();
                    }
                });

    }

    /**
     * Set the background of the pause button depending on if the activity is
     * "paused"
     */
    private void setPauseButtonSelector() {

        int drawable;

        if (isPaused) {
            drawable = R.drawable.play_button_selector;
        } else {
            drawable = R.drawable.pause_button_selector;
        }
        ((Button) findViewById(R.id.dumpPauseButton))
                .setBackground(getResources().getDrawable(drawable));
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dump);
        mDumpLayout = (LinearLayout) findViewById(R.id.dumpOutput);
        mSettingsManager = new SettingsManager(this);
        initButtons();
        Log.i(TAG, "Vehicle Dump Created");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mVehicleManager != null) {
            mVehicleManager.removeListener(KeyMatcher.getWildcardMatcher(),
                    mDumpListener);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        bindService(new Intent(this, VehicleManager.class), mConnection,
                Context.BIND_AUTO_CREATE);
    }

    @Override
    public void onPause() {
        super.onPause();
        if (mIsBound) {
            Log.i(TAG, "Unbinding from vehicle service");
            unbindService(mConnection);
            mIsBound = false;
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        ActivityLauncher.launchActivity(this, item.getItemId());
        return super.onOptionsItemSelected(item);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.options, menu);
        return true;
    }
}




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