summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTyler Gunn <tgunn@google.com>2015-08-13 15:19:54 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-08-13 15:19:54 +0000
commit7acc74a431abf2fe2dea0e82775110fc4ed0cd2f (patch)
tree5ebe91e4136d32be5620e5e7514857bb8990bcac
parente62a5be8ca8f2dc1d51e54628597af00c6f29805 (diff)
parent4325af9b87d8d48cb9443e8ad5bf0a3658622887 (diff)
downloadandroid_packages_apps_ContactsCommon-7acc74a431abf2fe2dea0e82775110fc4ed0cd2f.tar.gz
android_packages_apps_ContactsCommon-7acc74a431abf2fe2dea0e82775110fc4ed0cd2f.tar.bz2
android_packages_apps_ContactsCommon-7acc74a431abf2fe2dea0e82775110fc4ed0cd2f.zip
am 4325af9b: Merge "Consolidate CallSubject history and dialog." into mnc-dr-dev
* commit '4325af9b87d8d48cb9443e8ad5bf0a3658622887': Consolidate CallSubject history and dialog.
-rw-r--r--res/drawable/dialog_background_material.xml23
-rw-r--r--res/layout/call_subject_history_list_item.xml29
-rw-r--r--res/layout/dialog_call_subject.xml210
-rw-r--r--res/values/dimens.xml2
-rw-r--r--res/values/integers.xml3
-rw-r--r--res/values/styles.xml19
-rw-r--r--src/com/android/contacts/common/dialog/CallSubjectDialog.java273
-rw-r--r--src/com/android/contacts/common/dialog/CallSubjectHistory.java106
8 files changed, 371 insertions, 294 deletions
diff --git a/res/drawable/dialog_background_material.xml b/res/drawable/dialog_background_material.xml
new file mode 100644
index 00000000..fb586a08
--- /dev/null
+++ b/res/drawable/dialog_background_material.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+
+<inset xmlns:android="http://schemas.android.com/apk/res/android"
+ android:inset="16dp">
+ <shape android:shape="rectangle">
+ <corners android:radius="2dp" />
+ <solid android:color="@color/call_subject_history_background" />
+ </shape>
+</inset>
diff --git a/res/layout/call_subject_history_list_item.xml b/res/layout/call_subject_history_list_item.xml
new file mode 100644
index 00000000..b8cce475
--- /dev/null
+++ b/res/layout/call_subject_history_list_item.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2015 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
+ -->
+
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/text1"
+ android:gravity="center_vertical"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingStart="@dimen/call_subject_dialog_margin"
+ android:paddingEnd="@dimen/call_subject_dialog_margin"
+ android:paddingTop="@dimen/call_subject_history_item_padding"
+ android:paddingBottom="@dimen/call_subject_history_item_padding"
+ android:singleLine="true"
+ android:textColor="@color/dialtacts_primary_text_color"
+ android:textSize="@dimen/call_subject_dialog_primary_text_size" />
diff --git a/res/layout/dialog_call_subject.xml b/res/layout/dialog_call_subject.xml
index 005f4402..d6365c24 100644
--- a/res/layout/dialog_call_subject.xml
+++ b/res/layout/dialog_call_subject.xml
@@ -17,113 +17,143 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
android:layout_width="match_parent"
- android:layout_height="wrap_content" >
+ android:layout_height="match_parent"
+ android:background="@android:color/transparent"
+ android:id="@+id/call_subject_dialog"
+ android:orientation="vertical">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:layout_marginStart="@dimen/call_subject_dialog_margin"
- android:layout_marginEnd="@dimen/call_subject_dialog_margin"
- android:layout_marginTop="@dimen/call_subject_dialog_margin">
-
- <QuickContactBadge
- android:id="@+id/contact_photo"
- android:layout_width="@dimen/call_subject_dialog_contact_photo_size"
- android:layout_height="@dimen/call_subject_dialog_contact_photo_size"
- android:layout_gravity="top"
- android:focusable="true"
- android:layout_marginEnd="@dimen/call_subject_dialog_margin" />
+ <RelativeLayout
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:layout_width="match_parent">
+ <!-- The call subject dialog will be centered in the space above the subject list. -->
<LinearLayout
+ android:id="@+id/dialog_view"
+ android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:orientation="vertical"
- android:gravity="center_vertical">
+ android:clickable="true"
+ android:theme="@android:style/Theme.Material.Light.Dialog"
+ android:elevation="16dp"
+ android:layout_centerInParent="true"
+ android:background="@drawable/dialog_background_material">
- <TextView
- android:id="@+id/name"
- android:layout_width="wrap_content"
+ <LinearLayout
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:textColor="@color/dialtacts_primary_text_color"
+ android:orientation="horizontal"
+ android:layout_marginStart="@dimen/call_subject_dialog_margin"
+ android:layout_marginEnd="@dimen/call_subject_dialog_margin"
+ android:layout_marginTop="@dimen/call_subject_dialog_margin">
+
+ <QuickContactBadge
+ android:id="@+id/contact_photo"
+ android:layout_width="@dimen/call_subject_dialog_contact_photo_size"
+ android:layout_height="@dimen/call_subject_dialog_contact_photo_size"
+ android:layout_gravity="top"
+ android:focusable="true"
+ android:layout_marginEnd="@dimen/call_subject_dialog_margin" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:gravity="center_vertical">
+
+ <TextView
+ android:id="@+id/name"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textColor="@color/dialtacts_primary_text_color"
+ android:textSize="@dimen/call_subject_dialog_secondary_text_size"
+ android:singleLine="true" />
+
+ <TextView
+ android:id="@+id/number"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_marginTop="@dimen/call_subject_dialog_between_line_margin"
+ android:textColor="@color/dialtacts_secondary_text_color"
+ android:textSize="@dimen/call_subject_dialog_secondary_text_size"
+ android:singleLine="true" />
+ </LinearLayout>
+ </LinearLayout>
+
+ <EditText
+ android:id="@+id/call_subject"
+ android:hint="@string/call_subject_hint"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:layout_gravity="top"
+ android:textColor="@color/dialtacts_secondary_text_color"
android:textSize="@dimen/call_subject_dialog_secondary_text_size"
- android:singleLine="true" />
+ android:gravity="top"
+ android:background="@null"
+ android:layout_marginTop="@dimen/call_subject_dialog_edit_spacing"
+ android:layout_marginStart="@dimen/call_subject_dialog_margin"
+ android:layout_marginEnd="@dimen/call_subject_dialog_margin"
+ />
<TextView
- android:id="@+id/number"
+ android:id="@+id/character_limit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:layout_marginTop="@dimen/call_subject_dialog_between_line_margin"
android:textColor="@color/dialtacts_secondary_text_color"
android:textSize="@dimen/call_subject_dialog_secondary_text_size"
- android:singleLine="true" />
- </LinearLayout>
- </LinearLayout>
+ android:singleLine="true"
+ android:layout_marginStart="@dimen/call_subject_dialog_margin"
+ android:layout_marginEnd="@dimen/call_subject_dialog_margin"
+ android:layout_marginTop="@dimen/call_subject_dialog_margin"
+ android:layout_marginBottom="@dimen/call_subject_dialog_margin"/>
- <EditText
- android:id="@+id/call_subject"
- android:hint="@string/call_subject_hint"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="1"
- android:layout_gravity="top"
- android:textColor="@color/dialtacts_secondary_text_color"
- android:textSize="@dimen/call_subject_dialog_secondary_text_size"
- android:gravity="top"
- android:background="@null"
- android:layout_marginTop="@dimen/call_subject_dialog_edit_spacing"
- android:layout_marginStart="@dimen/call_subject_dialog_margin"
- android:layout_marginEnd="@dimen/call_subject_dialog_margin"
- />
-
- <TextView
- android:id="@+id/character_limit"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textColor="@color/dialtacts_secondary_text_color"
- android:textSize="@dimen/call_subject_dialog_secondary_text_size"
- android:singleLine="true"
- android:layout_marginStart="@dimen/call_subject_dialog_margin"
- android:layout_marginEnd="@dimen/call_subject_dialog_margin"
- android:layout_marginTop="@dimen/call_subject_dialog_margin"
- android:layout_marginBottom="@dimen/call_subject_dialog_margin"/>
-
- <View
- android:layout_width="fill_parent"
- android:layout_height="1dp"
- android:background="@color/call_subject_divider"/>
+ <View
+ android:layout_width="fill_parent"
+ android:layout_height="1dp"
+ android:background="@color/call_subject_divider"/>
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:layout_marginStart="@dimen/call_subject_dialog_margin"
- android:layout_marginEnd="@dimen/call_subject_dialog_margin"
- android:layout_marginTop="@dimen/call_subject_dialog_margin"
- android:layout_marginBottom="@dimen/call_subject_dialog_margin">
-
- <ImageView
- android:id="@+id/history_button"
- android:layout_width="25dp"
- android:layout_height="25dp"
- android:src="@drawable/ic_history_white_drawable_24dp"
- android:tint="@color/call_subject_history_icon"
- android:layout_alignParentStart="true"
- android:layout_centerVertical="true" />
-
- <TextView
- android:id="@+id/send_and_call_button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/send_and_call_button"
- android:textColor="@color/call_subject_button"
- android:textSize="@dimen/call_subject_dialog_secondary_text_size"
- android:singleLine="true"
- android:layout_alignParentEnd="true"
- android:layout_centerVertical="true" />
+ <RelativeLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="@dimen/call_subject_dialog_margin"
+ android:layout_marginEnd="@dimen/call_subject_dialog_margin"
+ android:layout_marginTop="@dimen/call_subject_dialog_margin"
+ android:layout_marginBottom="@dimen/call_subject_dialog_margin">
+
+ <ImageView
+ android:id="@+id/history_button"
+ android:layout_width="25dp"
+ android:layout_height="25dp"
+ android:src="@drawable/ic_history_white_drawable_24dp"
+ android:tint="@color/call_subject_history_icon"
+ android:layout_alignParentStart="true"
+ android:layout_centerVertical="true" />
+ <TextView
+ android:id="@+id/send_and_call_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/send_and_call_button"
+ android:textColor="@color/call_subject_button"
+ android:textSize="@dimen/call_subject_dialog_secondary_text_size"
+ android:singleLine="true"
+ android:layout_alignParentEnd="true"
+ android:layout_centerVertical="true" />
+
+ </RelativeLayout>
+ </LinearLayout>
</RelativeLayout>
+ <!-- The subject list is pinned to the bottom of the screen. -->
+ <ListView
+ android:id="@+id/subject_list"
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:layout_below="@id/dialog_view"
+ android:background="@color/call_subject_history_background"
+ android:divider="@null"
+ android:elevation="8dp" />
+
</LinearLayout> \ No newline at end of file
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index fd380243..8d612ff1 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -159,4 +159,6 @@
<dimen name="call_subject_dialog_primary_text_size">16sp</dimen>
<!-- Size of secondary text in the call subject dialog. -->
<dimen name="call_subject_dialog_secondary_text_size">14sp</dimen>
+ <!-- Row padding for call subject history items. -->
+ <dimen name="call_subject_history_item_padding">15dp</dimen>
</resources>
diff --git a/res/values/integers.xml b/res/values/integers.xml
index fc1209fa..f3d1e748 100644
--- a/res/values/integers.xml
+++ b/res/values/integers.xml
@@ -30,4 +30,7 @@
<!-- Layout weight of card in contact list view.
Default to 0 to indicate no padding -->
<integer name="contact_list_card_layout_weight">0</integer>
+
+ <!-- Duration of the animations on the call subject dialog. -->
+ <integer name="call_subject_animation_duration">250</integer>
</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 6ab07d3e..77c4677c 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -89,25 +89,18 @@ background and text color. See also android:style/Widget.Holo.TextView.ListSepar
<item name="android:windowIsFloating">true</item>
</style>
- <style name="CallSubjectDialogTheme" parent="android:Theme.Material.Light.Dialog">
- <item name="android:layout_width">fill_parent</item>
- <item name="android:layout_height">fill_parent</item>
+ <style name="Theme.CallSubjectDialogTheme" parent="@android:style/Theme.Material.Light.Dialog">
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">match_parent</item>
<!-- No backgrounds, titles or window float -->
- <item name="android:windowNoTitle">true</item>
- <item name="android:windowFullscreen">true</item>
- <item name="android:windowIsFloating">true</item>
- </style>
-
- <!-- Theme used for the call subjection history selection activity. -->
- <style name="Theme.CallSubjectSelector" parent="android:Theme.Material.Light">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
+ <item name="android:windowFullscreen">false</item>
+ <item name="android:windowIsFloating">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
- <item name="android:backgroundDimEnabled">false</item>
- <item name="android:windowTranslucentStatus">false</item>
- <item name="android:windowTranslucentNavigation">false</item>
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:windowContentOverlay">@null</item>
+ <item name="android:windowElevation">0dp</item>
</style>
</resources>
diff --git a/src/com/android/contacts/common/dialog/CallSubjectDialog.java b/src/com/android/contacts/common/dialog/CallSubjectDialog.java
index 622be601..fd041dd9 100644
--- a/src/com/android/contacts/common/dialog/CallSubjectDialog.java
+++ b/src/com/android/contacts/common/dialog/CallSubjectDialog.java
@@ -16,16 +16,18 @@
package com.android.contacts.common.dialog;
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.app.DialogFragment;
-import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.os.ResultReceiver;
import android.preference.PreferenceManager;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
@@ -34,14 +36,15 @@ import android.text.InputFilter;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
-import android.view.Gravity;
-import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.view.Window;
+import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
import android.widget.EditText;
+import android.widget.ListView;
import android.widget.QuickContactBadge;
import android.widget.TextView;
@@ -49,16 +52,17 @@ import com.android.contacts.common.CallUtil;
import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.R;
import com.android.contacts.common.util.UriUtils;
+import com.android.phone.common.animation.AnimUtils;
import java.util.ArrayList;
import java.util.List;
/**
- * Implements a dialog which prompts for a call subject for an outgoing call.
+ * Implements a dialog which prompts for a call subject for an outgoing call. The dialog includes
+ * a pop up list of historical call subjects.
*/
-public class CallSubjectDialog extends DialogFragment {
+public class CallSubjectDialog extends Activity {
private static final String TAG = "CallSubjectDialog";
- private static final String FRAGMENT_TAG = "callSubject";
private static final int CALL_SUBJECT_LIMIT = 16;
private static final int CALL_SUBJECT_HISTORY_SIZE = 5;
@@ -68,7 +72,7 @@ public class CallSubjectDialog extends DialogFragment {
public static final String PREF_KEY_SUBJECT_HISTORY_ITEM = "subject_history_item";
/**
- * Fragment argument bundle keys:
+ * Activity intent argument bundle keys:
*/
public static final String ARG_PHOTO_ID = "PHOTO_ID";
public static final String ARG_PHOTO_URI = "PHOTO_URI";
@@ -80,7 +84,9 @@ public class CallSubjectDialog extends DialogFragment {
public static final String ARG_NUMBER_LABEL = "NUMBER_LABEL";
public static final String ARG_PHONE_ACCOUNT_HANDLE = "PHONE_ACCOUNT_HANDLE";
- private Context mContext;
+ private int mAnimationDuration;
+ private View mBackgroundView;
+ private View mDialogView;
private QuickContactBadge mContactPhoto;
private TextView mNameView;
private TextView mNumberView;
@@ -88,6 +94,7 @@ public class CallSubjectDialog extends DialogFragment {
private TextView mCharacterLimitView;
private View mHistoryButton;
private View mSendAndCallButton;
+ private ListView mSubjectList;
private int mLimit = CALL_SUBJECT_LIMIT;
private int mPhotoSize;
@@ -125,15 +132,23 @@ public class CallSubjectDialog extends DialogFragment {
};
/**
+ * Click listener which handles user clicks outside of the dialog.
+ */
+ private View.OnClickListener mBackgroundListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ finish();
+ }
+ };
+
+ /**
* Handles displaying the list of past call subjects.
*/
private final View.OnClickListener mHistoryOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
- hideSoftKeyboard(mContext, mCallSubjectView);
- Intent intent = new Intent(mContext, CallSubjectHistory.class);
- setTargetFragment(CallSubjectDialog.this, REQUEST_SUBJECT);
- startActivityForResult(intent, REQUEST_SUBJECT);
+ hideSoftKeyboard(CallSubjectDialog.this, mCallSubjectView);
+ showCallHistory(mSubjectList.getVisibility() == View.GONE);
}
};
@@ -143,22 +158,48 @@ public class CallSubjectDialog extends DialogFragment {
private final View.OnClickListener mSendAndCallOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
- hideSoftKeyboard(mContext, mCallSubjectView);
String subject = mCallSubjectView.getText().toString();
Intent intent = CallUtil.getCallWithSubjectIntent(mNumber, mPhoneAccountHandle,
subject);
final TelecomManager tm =
- (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
+ (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
tm.placeCall(intent.getData(), intent.getExtras());
mSubjectHistory.add(subject);
saveSubjectHistory(mSubjectHistory);
- getDialog().dismiss();
+ finish();
}
};
/**
+ * Handles auto-hiding the call history when user clicks in the call subject field to give it
+ * focus.
+ */
+ private final View.OnClickListener mCallSubjectClickListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mSubjectList.getVisibility() == View.VISIBLE) {
+ showCallHistory(false);
+ }
+ }
+ };
+
+ /**
+ * Item click listener which handles user clicks on the items in the list view. Dismisses
+ * the activity, returning the subject to the caller and closing the activity with the
+ * {@link Activity#RESULT_OK} result code.
+ */
+ private AdapterView.OnItemClickListener mItemClickListener =
+ new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
+ mCallSubjectView.setText(mSubjectHistory.get(position));
+ showCallHistory(false);
+ }
+ };
+
+ /**
* Show the call subhect dialog given a phone number to dial (e.g. from the dialpad).
*
* @param activity The activity.
@@ -215,10 +256,9 @@ public class CallSubjectDialog extends DialogFragment {
* @param arguments The arguments bundle.
*/
public static void start(Activity activity, Bundle arguments) {
- final FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
- final CallSubjectDialog fragment = new CallSubjectDialog();
- fragment.setArguments(arguments);
- fragment.show(ft, FRAGMENT_TAG);
+ Intent intent = new Intent(activity, CallSubjectDialog.class);
+ intent.putExtras(arguments);
+ activity.startActivity(intent);
}
/**
@@ -230,40 +270,42 @@ public class CallSubjectDialog extends DialogFragment {
* @return Dialog instance.
*/
@Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- mContext = getActivity();
- mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
- mPhotoSize = mContext.getResources().getDimensionPixelSize(
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mAnimationDuration = getResources().getInteger(R.integer.call_subject_animation_duration);
+ mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
+ mPhotoSize = getResources().getDimensionPixelSize(
R.dimen.call_subject_dialog_contact_photo_size);
readArguments();
mSubjectHistory = loadSubjectHistory(mPrefs);
- LayoutInflater inflater = getActivity().getLayoutInflater();
- View view = inflater.inflate(R.layout.dialog_call_subject, null);
-
- mContactPhoto = (QuickContactBadge) view.findViewById(R.id.contact_photo);
- mNameView = (TextView) view.findViewById(R.id.name);
- mNumberView = (TextView) view.findViewById(R.id.number);
- mCallSubjectView = (EditText) view.findViewById(R.id.call_subject);
+ setContentView(R.layout.dialog_call_subject);
+ getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mBackgroundView = findViewById(R.id.call_subject_dialog);
+ mBackgroundView.setOnClickListener(mBackgroundListener);
+ mDialogView = findViewById(R.id.dialog_view);
+ mContactPhoto = (QuickContactBadge) findViewById(R.id.contact_photo);
+ mNameView = (TextView) findViewById(R.id.name);
+ mNumberView = (TextView) findViewById(R.id.number);
+ mCallSubjectView = (EditText) findViewById(R.id.call_subject);
mCallSubjectView.addTextChangedListener(mTextWatcher);
+ mCallSubjectView.setOnClickListener(mCallSubjectClickListener);
InputFilter[] filters = new InputFilter[1];
filters[0] = new InputFilter.LengthFilter(mLimit);
mCallSubjectView.setFilters(filters);
-
- mCharacterLimitView = (TextView) view.findViewById(R.id.character_limit);
- mHistoryButton = view.findViewById(R.id.history_button);
+ mCharacterLimitView = (TextView) findViewById(R.id.character_limit);
+ mHistoryButton = findViewById(R.id.history_button);
mHistoryButton.setOnClickListener(mHistoryOnClickListener);
mHistoryButton.setVisibility(mSubjectHistory.isEmpty() ? View.GONE : View.VISIBLE);
- mSendAndCallButton = view.findViewById(R.id.send_and_call_button);
+ mSendAndCallButton = findViewById(R.id.send_and_call_button);
mSendAndCallButton.setOnClickListener(mSendAndCallOnClickListener);
+ mSubjectList = (ListView) findViewById(R.id.subject_list);
+ mSubjectList.setOnItemClickListener(mItemClickListener);
+ mSubjectList.setVisibility(View.GONE);
- showSoftKeyboard(mContext, mCallSubjectView);
updateContactInfo();
updateCharacterLimit();
-
- AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
- dialogBuilder.setView(view);
- return dialogBuilder.create();
}
/**
@@ -278,8 +320,8 @@ public class CallSubjectDialog extends DialogFragment {
mNameView.setText(mNameOrNumber);
if (!TextUtils.isEmpty(mNumberLabel) && !TextUtils.isEmpty(mDisplayNumber)) {
mNumberView.setVisibility(View.VISIBLE);
- mNumberView.setText(mContext.getString(R.string.call_subject_type_and_number, mNumberLabel,
- mDisplayNumber));
+ mNumberView.setText(getString(R.string.call_subject_type_and_number,
+ mNumberLabel, mDisplayNumber));
} else {
mNumberView.setVisibility(View.GONE);
mNumberView.setText(null);
@@ -290,7 +332,7 @@ public class CallSubjectDialog extends DialogFragment {
* Reads arguments from the fragment arguments and populates the necessary instance variables.
*/
private void readArguments() {
- Bundle arguments = getArguments();
+ Bundle arguments = getIntent().getExtras();
if (arguments == null) {
Log.e(TAG, "Arguments cannot be null.");
return;
@@ -313,12 +355,12 @@ public class CallSubjectDialog extends DialogFragment {
private void updateCharacterLimit() {
int length = mCallSubjectView.length();
mCharacterLimitView.setText(
- mContext.getString(R.string.call_subject_limit, length, mLimit));
+ getString(R.string.call_subject_limit, length, mLimit));
if (length >= mLimit) {
- mCharacterLimitView.setTextColor(mContext.getResources().getColor(
+ mCharacterLimitView.setTextColor(getResources().getColor(
R.color.call_subject_limit_exceeded));
} else {
- mCharacterLimitView.setTextColor(mContext.getResources().getColor(
+ mCharacterLimitView.setTextColor(getResources().getColor(
R.color.dialtacts_secondary_text_color));
}
}
@@ -354,10 +396,10 @@ public class CallSubjectDialog extends DialogFragment {
displayName, lookupKey, contactType, true /* isCircular */);
if (photoId == 0 && photoUri != null) {
- ContactPhotoManager.getInstance(mContext).loadPhoto(mContactPhoto, photoUri,
+ ContactPhotoManager.getInstance(this).loadPhoto(mContactPhoto, photoUri,
mPhotoSize, false /* darkTheme */, true /* isCircular */, request);
} else {
- ContactPhotoManager.getInstance(mContext).loadThumbnail(mContactPhoto, photoId,
+ ContactPhotoManager.getInstance(this).loadThumbnail(mContactPhoto, photoId,
false /* darkTheme */, true /* isCircular */, request);
}
}
@@ -408,51 +450,112 @@ public class CallSubjectDialog extends DialogFragment {
}
/**
- * Handles results from the CallSubjectHistory activity.
- *
- * @param requestCode The integer request code originally supplied to
- * startActivityForResult(), allowing you to identify who this
- * result came from.
- * @param resultCode The integer result code returned by the child activity
- * through its setResult().
- * @param data An Intent, which can return result data to the caller
- */
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (requestCode != REQUEST_SUBJECT || data == null) {
- return;
- }
-
- if (resultCode != Activity.RESULT_OK) {
- return;
- }
-
- String chosenSubject = data.getStringExtra(CallSubjectHistory.EXTRA_CHOSEN_SUBJECT);
- mCallSubjectView.setText(chosenSubject);
- super.onActivityResult(requestCode, resultCode, data);
- }
-
- /**
* Hide software keyboard for the given {@link View}.
*/
public void hideSoftKeyboard(Context context, View view) {
InputMethodManager imm = (InputMethodManager) context.getSystemService(
Context.INPUT_METHOD_SERVICE);
if (imm != null) {
- imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
+ imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
/**
- * Show software keyboard for the given {@link View}.
+ * Hides or shows the call history list.
+ *
+ * @param show {@code true} if the call history should be shown, {@code false} otherwise.
*/
- public void showSoftKeyboard(Context context, View view) {
- view.requestFocus();
- InputMethodManager imm = (InputMethodManager) context.getSystemService(
- Context.INPUT_METHOD_SERVICE);
- if (imm != null) {
- imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
- InputMethodManager.HIDE_IMPLICIT_ONLY);
+ private void showCallHistory(final boolean show) {
+ // Bail early if the visibility has not changed.
+ if ((show && mSubjectList.getVisibility() == View.VISIBLE) ||
+ (!show && mSubjectList.getVisibility() == View.GONE)) {
+ return;
}
+
+ final int dialogStartingBottom = mDialogView.getBottom();
+ if (show) {
+ // Showing the subject list; bind the list of history items to the list and show it.
+ ArrayAdapter<String> adapter = new ArrayAdapter<String>(CallSubjectDialog.this,
+ R.layout.call_subject_history_list_item, mSubjectHistory);
+ mSubjectList.setAdapter(adapter);
+ mSubjectList.setVisibility(View.VISIBLE);
+ } else {
+ // Hiding the subject list.
+ mSubjectList.setVisibility(View.GONE);
+ }
+
+ // Use a ViewTreeObserver so that we can animate between the pre-layout and post-layout
+ // states.
+ final ViewTreeObserver observer = mBackgroundView.getViewTreeObserver();
+ observer.addOnPreDrawListener(
+ new ViewTreeObserver.OnPreDrawListener() {
+ @Override
+ public boolean onPreDraw() {
+ // We don't want to continue getting called.
+ if (observer.isAlive()) {
+ observer.removeOnPreDrawListener(this);
+ }
+
+ // Determine the amount the dialog has shifted due to the relayout.
+ int shiftAmount = dialogStartingBottom - mDialogView.getBottom();
+
+ // If the dialog needs to be shifted, do that now.
+ if (shiftAmount != 0) {
+ // Start animation in translated state and animate to translationY 0.
+ mDialogView.setTranslationY(shiftAmount);
+ mDialogView.animate()
+ .translationY(0)
+ .setInterpolator(AnimUtils.EASE_OUT_EASE_IN)
+ .setDuration(mAnimationDuration)
+ .start();
+ }
+
+ if (show) {
+ // Show the subhect list.
+ mSubjectList.setTranslationY(mSubjectList.getHeight());
+
+ mSubjectList.animate()
+ .translationY(0)
+ .setInterpolator(AnimUtils.EASE_OUT_EASE_IN)
+ .setDuration(mAnimationDuration)
+ .setListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ super.onAnimationEnd(animation);
+ }
+
+ @Override
+ public void onAnimationStart(Animator animation) {
+ super.onAnimationStart(animation);
+ mSubjectList.setVisibility(View.VISIBLE);
+ }
+ })
+ .start();
+ } else {
+ // Hide the subject list.
+ mSubjectList.setTranslationY(0);
+
+ mSubjectList.animate()
+ .translationY(mSubjectList.getHeight())
+ .setInterpolator(AnimUtils.EASE_OUT_EASE_IN)
+ .setDuration(mAnimationDuration)
+ .setListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ super.onAnimationEnd(animation);
+ mSubjectList.setVisibility(View.GONE);
+ }
+
+ @Override
+ public void onAnimationStart(Animator animation) {
+ super.onAnimationStart(animation);
+ }
+ })
+ .start();
+ }
+ return true;
+ }
+ }
+ );
}
}
diff --git a/src/com/android/contacts/common/dialog/CallSubjectHistory.java b/src/com/android/contacts/common/dialog/CallSubjectHistory.java
deleted file mode 100644
index 1e983e60..00000000
--- a/src/com/android/contacts/common/dialog/CallSubjectHistory.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (C) 2015 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.common.dialog;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.os.Bundle;
-import android.preference.PreferenceManager;
-import android.text.TextUtils;
-import android.view.View;
-import android.view.ViewTreeObserver;
-import android.view.Window;
-import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
-
-import com.android.contacts.common.R;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * List activity which displays the call subject history. Shows at the bottom of the screen,
- * on top of existing content.
- */
-public class CallSubjectHistory extends Activity {
- public static final String EXTRA_CHOSEN_SUBJECT =
- "com.android.contracts.common.dialog.extra.CHOSEN_SUBJECT";
-
- private View mBackground;
- private ListView mSubjectList;
- private SharedPreferences mSharedPreferences;
- private List<String> mSubjects;
-
- /**
- * Click listener which handles user clicks outside of the list view. Dismisses the activity
- * and returns a {@link Activity#RESULT_CANCELED} result code.
- */
- private View.OnClickListener mBackgroundListner = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- setResult(RESULT_CANCELED);
- finish();
- }
- };
-
- /**
- * Item click listener which handles user clicks on the items in the list view. Dismisses
- * the activity, returning the subject to the caller and closing the activity with the
- * {@link Activity#RESULT_OK} result code.
- */
- private AdapterView.OnItemClickListener mItemClickListener =
- new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
- returnSubject(mSubjects.get(position));
- }
- };
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
- mSubjects = CallSubjectDialog.loadSubjectHistory(mSharedPreferences);
-
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.call_subject_history);
-
- mBackground = findViewById(R.id.background);
- mBackground.setOnClickListener(mBackgroundListner);
-
- mSubjectList = (ListView) findViewById(R.id.subject_list);
- mSubjectList.setOnItemClickListener(mItemClickListener);
-
- ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
- android.R.layout.simple_list_item_1, mSubjects);
- mSubjectList.setAdapter(adapter);
- }
-
- /**
- * Closes the activity and returns the subject chosen by the user to the caller.
- *
- * @param chosenSubject The chosen subject.
- */
- private void returnSubject(String chosenSubject) {
- Intent intent = getIntent();
- intent.putExtra(EXTRA_CHOSEN_SUBJECT, chosenSubject);
- setResult(RESULT_OK, intent);
- finish();
- }
-}