Skip to content

Commit

Permalink
Add a decent sample application
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiesardo committed Mar 13, 2014
1 parent c6bab4a commit c13dc19
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 34 deletions.
2 changes: 2 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="android.auto.value.sample.DetailActivity"
android:label="@string/app_name" />
</application>

</manifest>
24 changes: 24 additions & 0 deletions sample/src/main/java/android/auto/value/sample/DetailActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package android.auto.value.sample;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import model3.Person;

public class DetailActivity extends Activity {

@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
Person person = getIntent().getParcelableExtra("Person");
textView(R.id.name).setText("Name:" + person.name());
textView(R.id.id).setText("Id:" + person.id());
textView(R.id.height).setText("Height:" + person.heightType());
textView(R.id.addresses).setText("Addresses:" + person.addresses());
textView(R.id.friends).setText("Friends:" + person.friends());
}

private TextView textView(int id) {
return (TextView) findViewById(id);
}
}
12 changes: 9 additions & 3 deletions sample/src/main/java/android/auto/value/sample/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package android.auto.value.sample;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import android.view.View;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Person person = Person.create("Frankie", 123);
Toast.makeText(this, person.name(), Toast.LENGTH_SHORT).show();
findViewById(R.id.click_me).setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
Intent detailIntent = new Intent(MainActivity.this, DetailActivity.class);
detailIntent.putExtra("Person", SampleData.BOB);
startActivity(detailIntent);
}
});
}
}
13 changes: 0 additions & 13 deletions sample/src/main/java/android/auto/value/sample/Person.java

This file was deleted.

22 changes: 22 additions & 0 deletions sample/src/main/java/android/auto/value/sample/SampleData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package android.auto.value.sample;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import model1.HeightBucket;
import model2.Address;
import model3.Person;

public interface SampleData {

static final Person ALICE = Person.create("Alice", 1L, HeightBucket.AVERAGE,
new HashMap<String, Address>() {{
put("home", Address.create(new double[] { 0.3, 0.7 }, "Rome"));
}}, Collections.<Person>emptyList());

static final Person BOB = Person.create("Bob", 2L, HeightBucket.TALL,
new HashMap<String, Address>() {{
put("home", Address.create(new double[] { 3.2, 143.2 }, "Turin"));
put("work", Address.create(new double[] { 5.9, 156.1 }, "Genoa"));
}}, Arrays.asList(ALICE));
}
5 changes: 5 additions & 0 deletions sample/src/main/java/model1/HeightBucket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package model1;

public enum HeightBucket {
SHORT, AVERAGE, TALL
}
14 changes: 14 additions & 0 deletions sample/src/main/java/model2/Address.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package model2;

import android.auto.value.AutoValue;
import android.os.Parcelable;

@AutoValue
public abstract class Address implements Parcelable {
public abstract double[] coordinates();
public abstract String cityName();

public static Address create(double[] coordinates, String cityName) {
return new AutoValue_Address(coordinates, cityName);
}
}
22 changes: 22 additions & 0 deletions sample/src/main/java/model3/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package model3;

import android.auto.value.AutoValue;
import android.os.Parcelable;
import java.util.List;
import java.util.Map;
import model1.HeightBucket;
import model2.Address;

@AutoValue
public abstract class Person implements Parcelable {
public static Person create(String name, long id, HeightBucket heightType, Map<String, Address> addresses,
List<Person> friends) {
return new AutoValue_Person(name, id, heightType, addresses, friends);
}

public abstract String name();
public abstract long id();
public abstract HeightBucket heightType();
public abstract Map<String, Address> addresses();
public abstract List<Person> friends();
}
49 changes: 49 additions & 0 deletions sample/src/main/res/layout/activity_detail.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:showDividers="middle"
tools:context="android.auto.value.sample.DetailActivity">

<TextView
android:text="You just sent:"
android:layout_width="wrap_content"
android:padding="8dp"
android:layout_height="?android:attr/listPreferredItemHeight"/>

<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:padding="8dp"
android:layout_height="?android:attr/listPreferredItemHeight"/>

<TextView
android:id="@+id/id"
android:layout_width="wrap_content"
android:padding="8dp"
android:layout_height="?android:attr/listPreferredItemHeight"/>

<TextView
android:id="@+id/height"
android:layout_width="wrap_content"
android:padding="8dp"
android:layout_height="?android:attr/listPreferredItemHeight"/>

<TextView
android:id="@+id/addresses"
android:layout_width="wrap_content"
android:padding="8dp"
android:layout_height="?android:attr/listPreferredItemHeight"/>

<TextView
android:id="@+id/friends"
android:layout_width="wrap_content"
android:padding="8dp"
android:layout_height="?android:attr/listPreferredItemHeight"/>

</LinearLayout>
9 changes: 5 additions & 4 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="android.auto.value.sample.MainActivity">

<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/click_me"
android:text="Send a parcelable object"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</RelativeLayout>
9 changes: 0 additions & 9 deletions sample/src/main/res/menu/main.xml

This file was deleted.

6 changes: 1 addition & 5 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">android-auto-value</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>

<string name="app_name">android-auto-value</string>
</resources>

0 comments on commit c13dc19

Please sign in to comment.