Android Open Source - Archeology Main Activity






From Project

Back to project page Archeology.

License

The source code is released under:

GNU General Public License

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

/*
 *  Chipotle Software(c) 2013   GPLv3 /*from  w  w  w .  j  av  a  2 s . c  o m*/
 */

package com.chipotle.archeology;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.content.Intent;
import android.widget.EditText;
import android.widget.TextView;
import android.support.v4.app.NavUtils;
import android.annotation.SuppressLint; 
import android.os.Build;
import android.util.Log;

// life cicle
import com.chipotle.archeology.util.StatusTracker;
import com.chipotle.archeology.util.Utils;

public class MainActivity extends Activity
{
    public final static String EXTRA_MESSAGE = "com.chipotle.archeology.MESSAGE";
    static final String STATE_SCORE = "playerScore";
    static final String STATE_LEVEL = "playerLevel";

    private String mActivityName;
    private Integer mCurrentScore;
    private Integer mCurrentLevel;
    private TextView mStatusView;
    private TextView mStatusAllView;
    private StatusTracker mStatusTracker = StatusTracker.getInstance();
    private TextView mTextView; // Member variable for text view in the layout

    /** Called when the activity is first created. */
    // TextView mTextView; // Member variable for text view in the layout

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        // super.onCreate(savedInstanceState);

        // Set the user interface layout for this Activity
        // The layout file is defined in the project res/layout/main_activity.xml file
        // setContentView(R.layout.main);
        
        // Initialize member TextView so we can manipulate it later
        // mTextView = (TextView) findViewById(R.id.text_message);
    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mActivityName = getString(R.string.activity_main);
        mStatusView = (TextView)findViewById(R.id.status_view_a);
        mStatusAllView = (TextView)findViewById(R.id.status_view_all_a);
        mStatusTracker.setStatus(mActivityName, getString(R.string.on_create));
        Utils.printStatus(mStatusView, mStatusAllView);
        // Make sure we're running on Honeycomb or higher to use ActionBar APIs
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) 
        {
            // For the main activity, make sure the app icon in the action bar
            // does not behave as a button
            ActionBar actionBar = getActionBar();
            actionBar.setHomeButtonEnabled(false);
        }

        // Check whether we're recreating a previously destroyed instance
        if (savedInstanceState != null) {
            // Restore value of members from saved state
            mCurrentScore = savedInstanceState.getInt(STATE_SCORE);
            mCurrentLevel = savedInstanceState.getInt(STATE_LEVEL);
        } else {
            // Probably initialize members with default values for a new instance
            Log.v("bundle", "Saved");
            mCurrentScore = 0;
            mCurrentLevel = 0;
        }
    }

    /** Called when the user clicks the Send button */
    public void sendMessage(View view)
    {
        // Do something in response to button
      Intent intent = new Intent(this, DisplayMessageActivity.class);
        EditText editText = (EditText) findViewById(R.id.edit_message);
        String message = editText.getText().toString();  // to_s
        intent.putExtra(EXTRA_MESSAGE, message);
    }

    @Override
    protected void onStart() {
        super.onStart();
        mStatusTracker.setStatus(mActivityName, getString(R.string.on_start));
        Utils.printStatus(mStatusView, mStatusAllView);
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        mStatusTracker.setStatus(mActivityName, getString(R.string.on_restart));
        Utils.printStatus(mStatusView, mStatusAllView);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mStatusTracker.setStatus(mActivityName, getString(R.string.on_resume));
        Utils.printStatus(mStatusView, mStatusAllView);
    }

    @Override
    protected void onPause() {
        super.onPause();
        mStatusTracker.setStatus(mActivityName, getString(R.string.on_pause));
        Utils.printStatus(mStatusView, mStatusAllView);
    }

    @Override
    protected void onStop() {
        super.onStop();
        mStatusTracker.setStatus(mActivityName, getString(R.string.on_stop));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mStatusTracker.setStatus(mActivityName, getString(R.string.on_destroy));
        mStatusTracker.clear();
    }

    public void startDialog(View v) {
        Intent intent = new Intent(MainActivity.this, DialogActivity.class);
        startActivity(intent);
    }

    public void startActivityB(View v) {
        Intent intent = new Intent(MainActivity.this, ActivityB.class);
        startActivity(intent);
    }

    public void startActivityC(View v) {
        Intent intent = new Intent(MainActivity.this, ActivityC.class);
        startActivity(intent);
    }

    public void finishMainActivity(View v) {
        MainActivity.this.finish();
    }

   /*
   *  Save 
   *   void
   */
   @Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
        // Save the user's current game state
        savedInstanceState.putInt(STATE_SCORE, mCurrentScore);
        savedInstanceState.putInt(STATE_LEVEL, mCurrentLevel);
    
        // Always call the superclass so it can save the view hierarchy state
        super.onSaveInstanceState(savedInstanceState);
    }
}




Java Source Code List

com.chipotle.archeology.ActivityB.java
com.chipotle.archeology.ActivityC.java
com.chipotle.archeology.DialogActivity.java
com.chipotle.archeology.DisplayMessageActivity.java
com.chipotle.archeology.MainActivity.java
com.chipotle.archeology.util.StatusTracker.java
com.chipotle.archeology.util.Utils.java