Skip to content

Commit

Permalink
finially did 1-4
Browse files Browse the repository at this point in the history
  • Loading branch information
annalinewyork committed May 27, 2015
1 parent 2c3a418 commit adc407c
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 29 deletions.
93 changes: 69 additions & 24 deletions src/main/java/nyc/c4q/InitialActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,73 @@

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) {
Log.d(TAG, "onCreate(): counter==" + counter);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_initial);
preferences = getPreferences(Context.MODE_PRIVATE);

Button plus = (Button) findViewById(R.id.buttonPlus);
Button minus = (Button) findViewById(R.id.buttonMinus);
final TextView tvCounter = (TextView) findViewById(R.id.tvCounter);

plus.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
counter++;
Log.d(TAG, "plus:" + counter);
tvCounter.setText(String.valueOf(counter));
}
}
);

minus.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
counter--;
Log.d(TAG, "minus:" + counter);
tvCounter.setText(String.valueOf(counter));
}
}
);
}

@Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause()");
}

@Override
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop()");
}

@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy()");
}
}
56 changes: 51 additions & 5 deletions src/main/res/layout/activity_initial.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,56 @@
tools:context="nyc.c4q.InitialActivity"
android:id="@+id/activity_initial">

<TextView
android:id="@+id/text"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="InitialActivity"
/>
android:layout_height="0dp"
android:id="@+id/counterLayout"
android:orientation="horizontal"
android:layout_weight="2">

<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/counterButtonsLayout"
android:orientation="vertical"
android:layout_weight="1">

<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/buttonPlus"
android:text="+"
android:layout_weight="1"/>

<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/buttonMinus"
android:text="-"
android:layout_weight="1"/>
</LinearLayout>

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/tvCounter"
android:text="0"
android:textSize="60sp"
android:gravity="center"
android:layout_weight="1"/>
</LinearLayout>

<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/buttonTileActivity"
android:text="TileActivity"
android:layout_weight="1"/>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/buttonEmpty"
android:text="Empty"
android:layout_weight="1"/>

</LinearLayout>
1 change: 1 addition & 0 deletions src/test/java/nyc/c4q/Unit1AssessmentTestsJava.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

Expand Down

0 comments on commit adc407c

Please sign in to comment.