Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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