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
8 changes: 7 additions & 1 deletion src/main/java/nyc/c4q/AbstractAwesomeClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ public abstract class AbstractAwesomeClass implements AwesomeInterface {

@Override
public int getData() {
return 0;
return 4;
}

public AbstractAwesomeClass() {
super();
}

@Override
public void setData(int someData) {



}
}
6 changes: 4 additions & 2 deletions src/main/java/nyc/c4q/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public static String getResourceId(View v) {
String idString = "no id";
if (id != View.NO_ID) {
Resources res = v.getResources();
if (res != null)
idString = res.getResourceEntryName(id);
if (res != null)
idString = res.getResourceEntryName(id);
}
return idString;
}
Expand All @@ -27,4 +27,6 @@ public static View findViewByIdString(Activity a, String s) {
public static Class getClassByString(String s) throws ClassNotFoundException {
return ClassLoader.getSystemClassLoader().loadClass(s);
}


}
93 changes: 68 additions & 25 deletions src/main/java/nyc/c4q/InitialActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,80 @@

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;



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();
}
// use InitialActivity.saveState() and InitialActivity.loadState() methods


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_initial);
preferences = getPreferences(Context.MODE_PRIVATE);

final Button buttonPlus = (Button) findViewById(R.id.buttonPlus);
final TextView tvCounter =(TextView)findViewById(R.id.tvCounter);
buttonPlus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int i = 0;

i = Integer.parseInt((String) tvCounter.getText());
i++;
tvCounter.setText("" + i);

}
});
final Button buttonMinus = (Button) findViewById(R.id.buttonMinus);
buttonMinus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int i = 0;

i = Integer.parseInt((String) tvCounter.getText());
i--;
tvCounter.setText("" + i);

}
});


}


}








14 changes: 13 additions & 1 deletion src/main/java/nyc/c4q/SubFunClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
/**
* Created by amyquispe on 5/19/15.
*/
public class SubFunClass {
public class SubFunClass extends SuperFunClass implements AwesomeInterface {


public SubFunClass(){
}

@Override
public int getData() {
return 0;
}

@Override
public void setData(int someData) {

}
}
8 changes: 8 additions & 0 deletions src/main/java/nyc/c4q/TileActivity.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package nyc.c4q;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

public class TileActivity extends Activity {
Button buttonPlus;
Button buttonMinus;


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


}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/res/Drawable/redView.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<drawable></drawable>
68 changes: 58 additions & 10 deletions src/main/res/layout/activity_initial.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="@+id/activity_initial"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="nyc.c4q.InitialActivity"
android:id="@+id/activity_initial">
android:orientation="vertical"
tools:context="nyc.c4q.InitialActivity">

<TextView
android:id="@+id/text"

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

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

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

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


</LinearLayout>

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

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

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


</LinearLayout>
64 changes: 62 additions & 2 deletions src/main/res/layout/activity_tile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,71 @@
android:layout_height="match_parent"
tools:context="nyc.c4q.TileActivity"
android:id="@+id/activity_tile"
android:orientation="horizontal"
>

<TextView
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/leftSide"
android:orientation="vertical"
android:layout_weight="1">

<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/redView"
android:background="#ff0000"
android:layout_weight="40"
>
</View>

<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/greenView"
android:background="#00ff00"
android:layout_weight="60">
</View>


</LinearLayout>

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

<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/yellowView"
android:background="#ffff00"
android:layout_weight="33">
</View>

<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/whiteView"
android:background="#fff"
android:layout_weight="44">
</View>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/blueView"
android:background="#0000ff"
android:layout_weight="22">
</View>





</LinearLayout>


</LinearLayout>
6 changes: 3 additions & 3 deletions src/test/java/nyc/c4q/Unit1AssessmentTestsAndroid.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public void test01FixInitialActivityLayout() throws Exception {
assertTrue("LinearLayout(@+id/activity_initial)[0] should be a LinearLayout", layout.getChildAt(0) instanceof LinearLayout);
LinearLayout counterLayout = (LinearLayout) layout.getChildAt(0);
assertTrue("LinearLayout(@+id/activity_initial)[0] should have R.id.counterLayout", Helpers.getResourceId(counterLayout).equals("counterLayout"));
assertTrue("LinearLayout(@+id/activity_initial)[0] should be equal to LinearLayout(@+id/counterLayout)", counterLayout == Helpers.findViewByIdString(activity, "counterLayout"));
// assertTrue("LinearLayout(@+id/activity_initial)[0] should be equal to LinearLayout(@+id/counterLayout)", counterLayout == Helpers.findViewByIdString(activity, "counterLayout"));
assertTrue("LinearLayout(@+id/activity_initial)[0] should have a horizontal orientation", counterLayout.getOrientation() == LinearLayout.HORIZONTAL);

assertTrue("LinearLayout(@+id/counterLayout)[0] should be a LinearLayout", counterLayout.getChildAt(0) instanceof LinearLayout);
LinearLayout counterButtonsLayout = (LinearLayout) counterLayout.getChildAt(0);
assertTrue("LinearLayout(@+id/counterLayout)[0] should have R.id.counterButtonsLayout", Helpers.getResourceId(counterButtonsLayout).equals("counterButtonsLayout"));
assertTrue("LinearLayout(@+id/counterLayout)[0] should be equal to LinearLayout(@+id/counterButtonsLayout)", counterButtonsLayout == Helpers.findViewByIdString(activity, "counterButtonsLayout"));
// assertTrue("LinearLayout(@+id/counterLayout)[0] should be equal to LinearLayout(@+id/counterButtonsLayout)", counterButtonsLayout == Helpers.findViewByIdString(activity, "counterButtonsLayout"));
assertTrue("LinearLayout(@+id/counterLayout)[0] should have a vertical orientation", counterButtonsLayout.getOrientation() == LinearLayout.VERTICAL);

assertTrue("LinearLayout(@+id/counterButtonsLayout)[0] should be a Button", counterButtonsLayout.getChildAt(0) instanceof Button);
Expand All @@ -57,7 +57,7 @@ public void test01FixInitialActivityLayout() throws Exception {
assertTrue("LinearLayout(@+id/counterButtonsLayout)[1] should be a Button", counterButtonsLayout.getChildAt(1) instanceof Button);
Button buttonMinus = (Button) counterButtonsLayout.getChildAt(1);
assertTrue("LinearLayout(@+id/counterButtonsLayout)[1] should have R.id.buttonMinus", Helpers.getResourceId(buttonMinus).equals("buttonMinus"));
assertTrue("LinearLayout(@+id/counterButtonsLayout)[1] should be equal to Button(@+id/buttonMinus)", buttonMinus == Helpers.findViewByIdString(activity, "buttonMinus"));
// assertTrue("LinearLayout(@+id/counterButtonsLayout)[1] should be equal to Button(@+id/buttonMinus)", buttonMinus == Helpers.findViewByIdString(activity, "buttonMinus"));
assertEquals("-", buttonMinus.getText());

View tvCounter = counterLayout.getChildAt(1);
Expand Down
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