New visuals and test for QuickContact
Bug:3172860
Bug:2591163
Change-Id: I5af7bf99481c38c6b0ad62b8f1c70b04ce930d1e
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index c41ff55..e714c25 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -53,6 +53,15 @@
</intent-filter>
</activity>
+ <activity android:name=".quickcontact.QuickContactTestsActivity"
+ android:label="@string/quickContactTests"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
</application>
<instrumentation android:name="android.test.InstrumentationTestRunner"
diff --git a/tests/res/drawable/ic_contact_picture.png b/tests/res/drawable/ic_contact_picture.png
new file mode 100644
index 0000000..3a338e8
--- /dev/null
+++ b/tests/res/drawable/ic_contact_picture.png
Binary files differ
diff --git a/tests/res/layout/quick_contact_tests.xml b/tests/res/layout/quick_contact_tests.xml
new file mode 100644
index 0000000..7687713
--- /dev/null
+++ b/tests/res/layout/quick_contact_tests.xml
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:layout_marginTop="16dip">
+ <QuickContactBadge
+ android:id="@+id/small_badge1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="32dip" />
+ <QuickContactBadge
+ android:id="@+id/medium_badge1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="64dip" />
+ <QuickContactBadge
+ android:id="@+id/large_badge1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="64dip" />
+ </LinearLayout>
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="0px"
+ android:layout_weight="1" />
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+ <Button
+ android:id="@+id/pick_contact"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:padding="32dip"
+ android:text="@string/pickContact" />
+ <TextView
+ android:id="@+id/uri"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:padding="32dip" />
+ </LinearLayout>
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="0px"
+ android:layout_weight="1" />
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:layout_marginBottom="16dip">
+ <QuickContactBadge
+ android:id="@+id/small_badge2"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="32dip" />
+ <QuickContactBadge
+ android:id="@+id/medium_badge2"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="64dip" />
+ <QuickContactBadge
+ android:id="@+id/large_badge2"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="64dip" />
+ </LinearLayout>
+</LinearLayout>
+
diff --git a/tests/res/values/donottranslate_strings.xml b/tests/res/values/donottranslate_strings.xml
index 6891c2f..660bae2 100644
--- a/tests/res/values/donottranslate_strings.xml
+++ b/tests/res/values/donottranslate_strings.xml
@@ -94,6 +94,8 @@
</string-array>
<string name="pinnedHeaderList">Pinned Headers</string>
+ <string name="quickContactTests">Quick Contact modes</string>
+ <string name="pickContact">Pick contact</string>
<string-array name="pinnedHeaderUseCases">
<item>One short section - no headers</item>
diff --git a/tests/src/com/android/contacts/tests/quickcontact/QuickContactTestsActivity.java b/tests/src/com/android/contacts/tests/quickcontact/QuickContactTestsActivity.java
new file mode 100644
index 0000000..c865680
--- /dev/null
+++ b/tests/src/com/android/contacts/tests/quickcontact/QuickContactTestsActivity.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.contacts.tests.quickcontact;
+
+import com.android.contacts.tests.R;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.net.Uri;
+import android.os.Bundle;
+import android.provider.ContactsContract.Contacts;
+import android.provider.ContactsContract.QuickContact;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.Window;
+import android.widget.Button;
+import android.widget.QuickContactBadge;
+import android.widget.TextView;
+
+public class QuickContactTestsActivity extends Activity {
+ private static final int REQUEST_CODE_PICK = 1;
+ private static final String PREF_NAME = "quick_contact_prefs";
+ private static final String PREF_SETTING_URI = "uri";
+
+ private Button mPickContact;
+ private TextView mUriTextView;
+ private QuickContactBadge mSmallBadge1;
+ private QuickContactBadge mSmallBadge2;
+ private QuickContactBadge mMediumBadge1;
+ private QuickContactBadge mMediumBadge2;
+ private QuickContactBadge mLargeBadge1;
+ private QuickContactBadge mLargeBadge2;
+
+ private Uri mContactUri;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ getWindow().requestFeature(Window.FEATURE_NO_TITLE);
+ setContentView(R.layout.quick_contact_tests);
+
+ mPickContact = (Button) findViewById(R.id.pick_contact);
+ mUriTextView = (TextView) findViewById(R.id.uri);
+ mSmallBadge1 = (QuickContactBadge) findViewById(R.id.small_badge1);
+ mSmallBadge2 = (QuickContactBadge) findViewById(R.id.small_badge2);
+ mMediumBadge1 = (QuickContactBadge) findViewById(R.id.medium_badge1);
+ mMediumBadge2 = (QuickContactBadge) findViewById(R.id.medium_badge2);
+ mLargeBadge1 = (QuickContactBadge) findViewById(R.id.large_badge1);
+ mLargeBadge2 = (QuickContactBadge) findViewById(R.id.large_badge2);
+
+ mSmallBadge1.setMode(QuickContact.MODE_SMALL);
+ mSmallBadge2.setMode(QuickContact.MODE_SMALL);
+ mMediumBadge1.setMode(QuickContact.MODE_MEDIUM);
+ mMediumBadge2.setMode(QuickContact.MODE_MEDIUM);
+ mLargeBadge1.setMode(QuickContact.MODE_LARGE);
+ mLargeBadge2.setMode(QuickContact.MODE_LARGE);
+
+ mSmallBadge1.setImageResource(R.drawable.ic_contact_picture);
+ mSmallBadge2.setImageResource(R.drawable.ic_contact_picture);
+ mMediumBadge1.setImageResource(R.drawable.ic_contact_picture);
+ mMediumBadge2.setImageResource(R.drawable.ic_contact_picture);
+ mLargeBadge1.setImageResource(R.drawable.ic_contact_picture);
+ mLargeBadge2.setImageResource(R.drawable.ic_contact_picture);
+
+ mPickContact.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ final Intent intent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
+ startActivityForResult(intent , REQUEST_CODE_PICK);
+ }
+ });
+
+ // Load Uri if known
+ final SharedPreferences sharedPreferences = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
+ final String uriString = sharedPreferences.getString(PREF_SETTING_URI, null);
+ if (uriString != null) {
+ mContactUri = Uri.parse(uriString);
+ assignUri();
+ }
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (resultCode == Activity.RESULT_CANCELED) return;
+ switch (requestCode) {
+ case REQUEST_CODE_PICK: {
+ mContactUri = data.getData();
+ assignUri();
+ break;
+ }
+ }
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+
+ final SharedPreferences sharedPreferences = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
+ final Editor editor = sharedPreferences.edit();
+ editor.putString(PREF_SETTING_URI, mContactUri == null ? null : mContactUri.toString());
+ editor.apply();
+ }
+
+ private void assignUri() {
+ mUriTextView.setText(mContactUri.toString());
+ mSmallBadge1.assignContactUri(mContactUri);
+ mSmallBadge2.assignContactUri(mContactUri);
+ mMediumBadge1.assignContactUri(mContactUri);
+ mMediumBadge2.assignContactUri(mContactUri);
+ mLargeBadge1.assignContactUri(mContactUri);
+ mLargeBadge2.assignContactUri(mContactUri);
+ }
+}