From 8b5ccc9f97f62fbed86349dc382cef6074ba35f6 Mon Sep 17 00:00:00 2001 From: MadelynTav Date: Tue, 19 May 2015 21:56:26 -0400 Subject: [PATCH 1/6] submitting exam --- src/main/java/nyc/c4q/InitialActivity.java | 98 ++++++++++++++++------ src/main/res/layout/activity_initial.xml | 61 ++++++++++++++ src/main/res/layout/activity_tile.xml | 62 +++++++++++++- src/main/res/values/colors.xml | 11 +++ 4 files changed, 205 insertions(+), 27 deletions(-) create mode 100644 src/main/res/values/colors.xml diff --git a/src/main/java/nyc/c4q/InitialActivity.java b/src/main/java/nyc/c4q/InitialActivity.java index 2213b83..5b55807 100644 --- a/src/main/java/nyc/c4q/InitialActivity.java +++ b/src/main/java/nyc/c4q/InitialActivity.java @@ -2,6 +2,7 @@ import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; @@ -9,30 +10,77 @@ import android.widget.Button; import android.widget.TextView; +import org.w3c.dom.Text; + public class InitialActivity extends Activity { - public int counter = 0; - public SharedPreferences preferences = null; - public final static String TAG = "C4QTAG"; - - public void loadState(){ - Log.d(TAG, "loadState()"); - counter = preferences.getInt("counter", 0); - Log.d(TAG, "loadState(): counter=="+counter); - } - - public void saveState(){ - Log.d(TAG, "saveState()"); - Log.d(TAG, "saveState(): counter=="+counter); - SharedPreferences.Editor editor = preferences.edit(); - editor.putInt("counter", counter); - editor.commit(); - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_initial); - preferences = getPreferences(Context.MODE_PRIVATE); - } -} + public int counter = 0; + public SharedPreferences preferences = null; + public final static String TAG = "C4QTAG"; + + public void loadState() { + Log.d(TAG, "loadState()"); + counter = preferences.getInt("counter", 0); + Log.d(TAG, "loadState(): counter==" + counter); + } + + public void saveState() { + Log.d(TAG, "saveState()"); + Log.d(TAG, "saveState(): counter==" + counter); + SharedPreferences.Editor editor = preferences.edit(); + editor.putInt("counter", counter); + editor.commit(); + } + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_initial); + preferences = getPreferences(Context.MODE_PRIVATE); + + final Button button = (Button) findViewById(R.id.buttonPlus); + final TextView countertv = (TextView) findViewById(R.id.tvCounter); + + if(savedInstanceState!=null){ + counter= Integer.parseInt(savedInstanceState.get("click_count").toString()); + countertv.setText(counter); + } + + button.setOnClickListener(new View.OnClickListener() { + @Override + + public void onClick(View view) { + counter++; + countertv.setText(String.valueOf(counter)); + } + + }); + + Button buttonMin = (Button) findViewById(R.id.buttonMinus); + buttonMin.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + counter--; + countertv.setText(String.valueOf(counter)); + } + }); + + Button buttonTile = (Button) findViewById(R.id.buttonTileActivity); + buttonTile.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(InitialActivity.this, TileActivity.class); + startActivity(intent); + } + }); + } + + @Override + public void onSaveInstanceState(Bundle outState){ + super.onSaveInstanceState(outState); + outState.putInt("click_count", counter); + + //base.OnSaveInstanceState (outState); + } +} \ No newline at end of file diff --git a/src/main/res/layout/activity_initial.xml b/src/main/res/layout/activity_initial.xml index 49e22b0..d44ef51 100644 --- a/src/main/res/layout/activity_initial.xml +++ b/src/main/res/layout/activity_initial.xml @@ -9,6 +9,67 @@ tools:context="nyc.c4q.InitialActivity" android:id="@+id/activity_initial"> + + + + + + +