Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

Commit e644c73

Browse files
committed
Adding demo for the CardBuilder and switching to Android Studio format.
1 parent a016b56 commit e644c73

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+751
-140
lines changed

Diff for: README

-25
This file was deleted.

Diff for: app/build.gradle

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apply plugin: 'com.android.application'
2+
3+
repositories {
4+
jcenter()
5+
flatDir {
6+
dirs 'prebuilt-libs'
7+
}
8+
}
9+
10+
android {
11+
compileSdkVersion "Google Inc.:Glass Development Kit Preview:19"
12+
buildToolsVersion "20.0.0"
13+
14+
defaultConfig {
15+
minSdkVersion 19
16+
targetSdkVersion 19
17+
}
18+
buildTypes {
19+
release {
20+
runProguard false
21+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
}
25+
26+
dependencies {
27+
compile fileTree(dir: 'libs', include: ['*.jar'])
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright (C) 2014 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.android.glass.sample.apidemo;
18+
19+
import com.google.android.glass.sample.apidemo.card.CardsActivity;
20+
import com.google.android.glass.sample.apidemo.theming.ThemingActivity;
21+
import com.google.android.glass.sample.apidemo.touchpad.SelectGestureDemoActivity;
22+
23+
import android.app.Activity;
24+
import android.app.Instrumentation;
25+
import android.test.ActivityInstrumentationTestCase2;
26+
import android.test.suitebuilder.annotation.SmallTest;
27+
28+
/**
29+
* Unit tests for {@link ApiDemoActivity}.
30+
*/
31+
@SmallTest
32+
public class ApiDemoActivityTest extends ActivityInstrumentationTestCase2<ApiDemoActivity> {
33+
34+
private static final int MONITOR_TIMEOUT = 5 * 1000;
35+
private Instrumentation.ActivityMonitor mCardsActivityMonitor;
36+
private Instrumentation.ActivityMonitor mDetectorActivityMonitor;
37+
private Instrumentation.ActivityMonitor mThemingActivityMonitor;
38+
39+
public ApiDemoActivityTest() {
40+
super(ApiDemoActivity.class);
41+
}
42+
43+
@Override
44+
protected void setUp() throws Exception {
45+
super.setUp();
46+
mCardsActivityMonitor = new Instrumentation.ActivityMonitor(
47+
CardsActivity.class.getName(), null, false);
48+
mDetectorActivityMonitor = new Instrumentation.ActivityMonitor(
49+
SelectGestureDemoActivity.class.getName(), null, false);
50+
mThemingActivityMonitor = new Instrumentation.ActivityMonitor(
51+
ThemingActivity.class.getName(), null, false);
52+
getInstrumentation().addMonitor(mCardsActivityMonitor);
53+
getInstrumentation().addMonitor(mDetectorActivityMonitor);
54+
getInstrumentation().addMonitor(mThemingActivityMonitor);
55+
}
56+
57+
@Override
58+
protected void tearDown() throws Exception {
59+
super.tearDown();
60+
}
61+
62+
/**
63+
* Tests if the "Cards" API demo can be started when the card was tapped.
64+
*/
65+
public void testTapFirstCard() throws Exception {
66+
final ApiDemoActivity activity = getActivity();
67+
assertNotNull(activity);
68+
activity.runOnUiThread(new Runnable() {
69+
70+
@Override
71+
public void run() {
72+
activity.getScroller().performItemClick(null /* not used */,
73+
ApiDemoActivity.CARD_BUILDER, -1 /* not used */);
74+
}
75+
});
76+
77+
Activity cardsActivity = mCardsActivityMonitor.waitForActivityWithTimeout(MONITOR_TIMEOUT);
78+
assertNotNull("Activity was not started", cardsActivity);
79+
cardsActivity.finish();
80+
}
81+
82+
/**
83+
* Tests if the "GestureDetector" API demo can be started when the card was tapped.
84+
*/
85+
public void testTapSecondCard() throws Exception {
86+
final ApiDemoActivity activity = getActivity();
87+
assertNotNull(activity);
88+
activity.runOnUiThread(new Runnable() {
89+
90+
@Override
91+
public void run() {
92+
activity.getScroller().performItemClick(null /* not used */,
93+
ApiDemoActivity.GESTURE_DETECTOR, -1 /* not used */);
94+
}
95+
});
96+
97+
Activity touchActivity = mDetectorActivityMonitor.waitForActivityWithTimeout(MONITOR_TIMEOUT);
98+
assertNotNull("Activity was not started", touchActivity);
99+
touchActivity.finish();
100+
}
101+
102+
/**
103+
* Tests if the "Theming" API demo can be started when the card was tapped.
104+
*/
105+
public void testTapThirdCard() throws Exception {
106+
final ApiDemoActivity activity = getActivity();
107+
assertNotNull(activity);
108+
activity.runOnUiThread(new Runnable() {
109+
110+
@Override
111+
public void run() {
112+
activity.getScroller().performItemClick(null /* not used */,
113+
ApiDemoActivity.THEMING, -1 /* not used */);
114+
}
115+
});
116+
117+
Activity themeActivity = mThemingActivityMonitor.waitForActivityWithTimeout(MONITOR_TIMEOUT);
118+
assertNotNull("Activity was not started", themeActivity);
119+
themeActivity.finish();
120+
}
121+
}
File renamed without changes.

Diff for: src/com/google/android/glass/sample/apidemo/ApiDemoActivity.java renamed to app/src/main/java/com/google/android/glass/sample/apidemo/ApiDemoActivity.java

+15-10
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
package com.google.android.glass.sample.apidemo;
1818

19-
import com.google.android.glass.app.Card;
2019
import com.google.android.glass.media.Sounds;
2120
import com.google.android.glass.sample.apidemo.card.CardsActivity;
2221
import com.google.android.glass.sample.apidemo.card.CardAdapter;
2322
import com.google.android.glass.sample.apidemo.opengl.OpenGlService;
2423
import com.google.android.glass.sample.apidemo.theming.ThemingActivity;
2524
import com.google.android.glass.sample.apidemo.touchpad.SelectGestureDemoActivity;
2625
import com.google.android.glass.sample.apidemo.voicemenu.VoiceMenuActivity;
26+
import com.google.android.glass.widget.CardBuilder;
2727
import com.google.android.glass.widget.CardScrollAdapter;
2828
import com.google.android.glass.widget.CardScrollView;
2929

@@ -56,7 +56,7 @@ public class ApiDemoActivity extends Activity {
5656

5757
// Index of api demo cards.
5858
// Visible for testing.
59-
static final int CARDS = 0;
59+
static final int CARD_BUILDER = 0;
6060
static final int GESTURE_DETECTOR = 1;
6161
static final int THEMING = 2;
6262
static final int OPENGL = 3;
@@ -84,13 +84,18 @@ protected void onCreate(Bundle bundle) {
8484
/**
8585
* Create list of API demo cards.
8686
*/
87-
private List<Card> createCards(Context context) {
88-
ArrayList<Card> cards = new ArrayList<Card>();
89-
cards.add(CARDS, new Card(context).setText(R.string.text_cards));
90-
cards.add(GESTURE_DETECTOR, new Card(context).setText(R.string.text_gesture_detector));
91-
cards.add(THEMING, new Card(context).setText(R.string.text_theming));
92-
cards.add(OPENGL, new Card(context).setText(R.string.text_opengl));
93-
cards.add(VOICE_MENU, new Card(context).setText(R.string.text_voice_menu));
87+
private List<CardBuilder> createCards(Context context) {
88+
ArrayList<CardBuilder> cards = new ArrayList<CardBuilder>();
89+
cards.add(CARD_BUILDER, new CardBuilder(context, CardBuilder.Layout.TEXT)
90+
.setText(R.string.text_cards));
91+
cards.add(GESTURE_DETECTOR, new CardBuilder(context, CardBuilder.Layout.TEXT)
92+
.setText(R.string.text_gesture_detector));
93+
cards.add(THEMING, new CardBuilder(context, CardBuilder.Layout.TEXT)
94+
.setText(R.string.text_theming));
95+
cards.add(OPENGL, new CardBuilder(context, CardBuilder.Layout.TEXT)
96+
.setText(R.string.text_opengl));
97+
cards.add(VOICE_MENU, new CardBuilder(context, CardBuilder.Layout.TEXT)
98+
.setText(R.string.text_voice_menu));
9499
return cards;
95100
}
96101

@@ -117,7 +122,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
117122
Log.d(TAG, "Clicked view at position " + position + ", row-id " + id);
118123
int soundEffect = Sounds.TAP;
119124
switch (position) {
120-
case CARDS:
125+
case CARD_BUILDER:
121126
startActivity(new Intent(ApiDemoActivity.this, CardsActivity.class));
122127
break;
123128

Diff for: src/com/google/android/glass/sample/apidemo/card/CardAdapter.java renamed to app/src/main/java/com/google/android/glass/sample/apidemo/card/CardAdapter.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.android.glass.sample.apidemo.card;
1818

19-
import com.google.android.glass.app.Card;
19+
import com.google.android.glass.widget.CardBuilder;
2020
import com.google.android.glass.widget.CardScrollAdapter;
2121

2222
import android.view.View;
@@ -30,9 +30,9 @@
3030
*/
3131
public class CardAdapter extends CardScrollAdapter {
3232

33-
private final List<Card> mCards;
33+
private final List<CardBuilder> mCards;
3434

35-
public CardAdapter(List<Card> cards) {
35+
public CardAdapter(List<CardBuilder> cards) {
3636
mCards = cards;
3737
}
3838

@@ -53,7 +53,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
5353

5454
@Override
5555
public int getViewTypeCount() {
56-
return Card.getViewTypeCount();
56+
return CardBuilder.getViewTypeCount();
5757
}
5858

5959
@Override
@@ -70,4 +70,12 @@ public int getPosition(Object item) {
7070
}
7171
return AdapterView.INVALID_POSITION;
7272
}
73+
74+
/**
75+
* A non-adapter method to append a card at the end without notifying the adapter
76+
* of the data change yet ({@link #notifyDataSetChanged}).
77+
*/
78+
public void appendCardWithoutNotification(CardBuilder card) {
79+
mCards.add(card);
80+
}
7381
}

0 commit comments

Comments
 (0)