-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6bab4a
commit c13dc19
Showing
12 changed files
with
153 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
sample/src/main/java/android/auto/value/sample/DetailActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
sample/src/main/java/android/auto/value/sample/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
sample/src/main/java/android/auto/value/sample/Person.java
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
sample/src/main/java/android/auto/value/sample/SampleData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package model1; | ||
|
||
public enum HeightBucket { | ||
SHORT, AVERAGE, TALL | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |