Android Open Source - LTM Main Activity






From Project

Back to project page LTM.

License

The source code is released under:

Apache License

If you think the Android project LTM 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.chrisplus.ltm;
//from www . j  a  v  a 2  s  . co m
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;

import android.app.Activity;
import android.content.ComponentName;
import android.content.ContextWrapper;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.chrisplus.ltm.utils.Constants;
import com.chrisplus.ltm.utils.SysUtils;

public class MainActivity extends Activity {

    private final static String TAG = MainActivity.class.getSimpleName();

    /* UI Component */
    private Button actionButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        init();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    private void init() {
        actionButton = (Button) findViewById(R.id.ActionButton);
        actionButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean isRunning = (Boolean) v.getTag();
                if (isRunning) {
                    /* stop service */
                    // TODO
                    isRunning = !stopService();
                } else {
                    /* start service */
                    // TODO
                    isRunning = startService();
                }
                /* Without Check */
                updateButtonState(isRunning);
            }
        });
    }

    private void updateButtonState(boolean isRunning) {

        boolean serviceState = isRunning;

        if (serviceState) {
            /* Set Stop */
            actionButton.setText(R.string.button_stop);
            /* Set is running */
            actionButton.setTag(true);
        } else {
            /* Set Start */
            actionButton.setText(R.string.button_start);
            /* Set is running */
            actionButton.setTag(false);
        }
    }

    private boolean startService() {
        installBinaries();

        ComponentName name = null;
        try {
            name = startService(new Intent(this, LogService.class));
        } catch (SecurityException e) {
            e.printStackTrace();
            return false;
        }

        if (name != null) {
            Log.d(TAG, "Get Component Name is " + name.getClassName());
            return true;
        } else {
            return false;
        }
    }

    private boolean stopService() {       
        return stopService(new Intent(this, LogService.class));
    }

    @Override
    protected void onResume() {
        Log.d(TAG, "Resume and Check State");
        boolean isRunning = SysUtils.isServiceRunning(this, LogService.class.getName());
        updateButtonState(isRunning);
        super.onResume();
    }

    private void installBinaries() {
        SysUtils.installBinaries(this);

        /* Write SH file */
        synchronized (Constants.EXE_SCRIPT) {
            String scriptFile = new ContextWrapper(this).getFilesDir().getAbsolutePath()
                    + File.separator + Constants.EXE_SCRIPT;
            String binaryPath = getFilesDir().getAbsolutePath() + File.separator
                    + SysUtils.getGrepBinary();

            try {
                PrintWriter script = new PrintWriter(new BufferedWriter(new FileWriter(scriptFile)));
                script.println(binaryPath + " {NL} /proc/kmsg");
                script.close();
            } catch (java.io.IOException e) {
                e.printStackTrace();
            }
        }
    }

}




Java Source Code List

com.chrisplus.ltm.LogService.java
com.chrisplus.ltm.MainActivity.java
com.chrisplus.ltm.activies.ErrorDialogActivity.java
com.chrisplus.ltm.core.CoreLogger.java
com.chrisplus.ltm.core.CoreParser.java
com.chrisplus.ltm.utils.CharArrayStringAATree.java
com.chrisplus.ltm.utils.CharArray.java
com.chrisplus.ltm.utils.Constants.java
com.chrisplus.ltm.utils.ItemNotFoundException.java
com.chrisplus.ltm.utils.MD5Sum.java
com.chrisplus.ltm.utils.NetStat.java
com.chrisplus.ltm.utils.ShellCommand.java
com.chrisplus.ltm.utils.StringPool.java
com.chrisplus.ltm.utils.SysUtils.java