summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2014-09-05 11:39:16 +0200
committerDanny Baumann <dannybaumann@web.de>2014-11-17 14:55:48 +0100
commit315d9119f681048974e03080bca69290b73c9914 (patch)
tree1f1491d2eb3623a7f9fe4db9b77435fb4db0f6a9
parentbb88afb43b92d9d7716ad64ebdd616e95a1d43cd (diff)
downloadandroid_packages_apps_Dialer-315d9119f681048974e03080bca69290b73c9914.tar.gz
android_packages_apps_Dialer-315d9119f681048974e03080bca69290b73c9914.tar.bz2
android_packages_apps_Dialer-315d9119f681048974e03080bca69290b73c9914.zip
Rewrite speed dial feature.
Change-Id: I346bcf4552cdf2ddfd3c9b1219bc07c20332d1a2
-rw-r--r--AndroidManifest.xml4
-rwxr-xr-xres/layout/speed_dial_item.xml62
-rw-r--r--res/values-zh-rCN/strings.xml12
-rw-r--r--res/values/cm_strings.xml11
-rw-r--r--res/values/strings.xml13
-rw-r--r--res/xml/general_settings.xml14
-rwxr-xr-xsrc/com/android/dialer/SpeedDialListActivity.java439
-rw-r--r--src/com/android/dialer/SpeedDialUtils.java264
-rw-r--r--src/com/android/dialer/dialpad/DialpadFragment.java82
-rw-r--r--src/com/android/dialer/settings/GeneralSettingsFragment.java5
10 files changed, 358 insertions, 548 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index d7708b475..df2966857 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -251,8 +251,8 @@
</receiver>
<activity android:name=".SpeedDialListActivity"
- android:configChanges="orientation|screenSize|keyboardHidden|uiMode"
- android:label="@string/set_speed_dial" >
+ android:theme="@style/DialtactsTheme"
+ android:label="@string/speed_dial_settings" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
diff --git a/res/layout/speed_dial_item.xml b/res/layout/speed_dial_item.xml
new file mode 100755
index 000000000..8140fcb3a
--- /dev/null
+++ b/res/layout/speed_dial_item.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 The CyanogenMod 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="wrap_content"
+ android:paddingStart="16dip"
+ android:paddingEnd="16dip"
+ android:orientation="horizontal"
+ android:minHeight="?android:attr/listPreferredItemHeight">
+
+ <TextView
+ android:id="@+id/index"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_marginEnd="12dp"
+ android:textStyle="bold"
+ android:textAppearance="?android:attr/textAppearanceLarge" />
+
+ <LinearLayout
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_gravity="center_vertical"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/name"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <TextView
+ android:id="@+id/number"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+
+ </LinearLayout>
+
+ <QuickContactBadge
+ android:id="@+id/photo"
+ android:layout_width="@dimen/contact_photo_size"
+ android:layout_height="@dimen/contact_photo_size"
+ android:layout_gravity="center_vertical"
+ android:layout_marginStart="8dp" />
+
+</LinearLayout>
+
diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml
index 86f16bdc2..0ce652bfe 100644
--- a/res/values-zh-rCN/strings.xml
+++ b/res/values-zh-rCN/strings.xml
@@ -206,18 +206,6 @@
<string name="device_id">设备标识符</string>
- <!-- for speed dial -->
- <string name="set_speed_dial">快速拨号设置</string>
- <string name="dialog_title">提示</string>
- <string name="not_set">(未设置)</string>
- <string name="replace">替换</string>
- <string name="delete">删除</string>
- <string name="speed_call">通话</string>
- <string name="speed_sms">信息</string>
- <string name="is_set_speed">数字键<xliff:g id="number">%s</xliff:g>未设置快速拨号,是否设置?\n</string>
- <string name="dialog_speed_dial_airplane_mode_message" >"要呼叫快速拨号,请先关闭飞行模式。"</string>
- <string name="assignSpeedDialFailToast">此号码已分配了快速拨号键,请选择其它号码。</string>
-
<string name="call_log_show_all_slots">"所有卡"</string>
<string name="call_log_all_calls_header">"所有通话"</string>
<string name="calllog_search_hint">"搜索通话记录"</string>
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index f41275ed9..494d85b94 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -60,4 +60,15 @@
<string name="menu_add_to_blacklist">Add to blacklist</string>
<string name="toast_added_to_blacklist">%s added to blacklist.</string>
+
+ <!-- for speed dial -->
+ <string name="speed_dial_settings">Speed dial settings</string>
+ <string name="speed_dial_not_set">(not set)</string>
+ <string name="speed_dial_replace">Replace</string>
+ <string name="speed_dial_delete">Delete</string>
+ <string name="speed_dial_unassigned_dialog_title">Key unassigned</string>
+ <string name="speed_dial_unassigned_dialog_message">No speed dial action is assigned to number key \'<xliff:g id="number">%s</xliff:g>\'. Do you want to assign an action now?</string>
+ <string name="dialog_speed_dial_airplane_mode_message">To use speed dial, first turn off Airplane mode.</string>
+ <string name="yes">Yes</string>
+ <string name="no">No</string>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d03818f68..5424812d3 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -816,19 +816,6 @@
<string name="device_id">Device Identifier</string>
- <!-- for speed dial -->
- <string name="set_speed_dial">Speed dial settings</string>
- <string name="dialog_title">Tip</string>
- <string name="not_set">(not set)</string>
- <string name="replace">Replace</string>
- <string name="delete">Delete</string>
- <string name="speed_call">Call</string>
- <string name="speed_sms">Message</string>
- <string name="speed_item"><xliff:g id="index">%s</xliff:g>. <xliff:g id="content">%s</xliff:g></string>
- <string name="is_set_speed">Number key <xliff:g id="number">%s</xliff:g> is not set up speed dial, set now?\n</string>
- <string name="dialog_speed_dial_airplane_mode_message" >"To call Speed dial, first turn off Airplane mode."</string>
- <string name="assignSpeedDialFailToast">The number has already been assigned to a speed dial key, please select another number.</string>
-
<string name="call_log_show_all_slots">All SIMs</string>
<string name="call_log_all_calls_header">All calls</string>
<string name="calllog_search_hint">"Search call log"</string>
diff --git a/res/xml/general_settings.xml b/res/xml/general_settings.xml
index b1a78c1f2..71d95d9b7 100644
--- a/res/xml/general_settings.xml
+++ b/res/xml/general_settings.xml
@@ -78,6 +78,18 @@
</PreferenceScreen>
+ <PreferenceScreen
+ android:key="speed_dial_settings"
+ android:title="@string/speed_dial_settings"
+ android:persistent="false">
+
+ <intent
+ android:action="android.intent.action.MAIN"
+ android:targetPackage="com.android.dialer"
+ android:targetClass="com.android.dialer.SpeedDialListActivity" />
+
+ </PreferenceScreen>
+
</PreferenceCategory>
-</PreferenceScreen> \ No newline at end of file
+</PreferenceScreen>
diff --git a/src/com/android/dialer/SpeedDialListActivity.java b/src/com/android/dialer/SpeedDialListActivity.java
index 58c3e0eec..0a589cbba 100755
--- a/src/com/android/dialer/SpeedDialListActivity.java
+++ b/src/com/android/dialer/SpeedDialListActivity.java
@@ -29,60 +29,80 @@
package com.android.dialer;
-import android.app.Activity;
-import android.app.AlertDialog;
+import android.app.ActionBar;
import android.app.ListActivity;
import android.content.ActivityNotFoundException;
import android.content.ContentUris;
-import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
-import android.provider.ContactsContract.Contacts.Data;
-import android.provider.ContactsContract.RawContacts;
import android.provider.Settings;
-import android.provider.Settings.SettingNotFoundException;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
-import android.text.TextUtils;
import android.util.Log;
-import android.view.ContextMenu;
-import android.view.ContextMenu.ContextMenuInfo;
+import android.util.SparseArray;
+import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
-import android.view.View.OnCreateContextMenuListener;
+import android.view.ViewGroup;
import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemClickListener;
-import android.widget.ArrayAdapter;
+import android.widget.BaseAdapter;
import android.widget.ListView;
-import android.widget.Toast;
+import android.widget.PopupMenu;
+import android.widget.QuickContactBadge;
+import android.widget.TextView;
-import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
-
-public class SpeedDialListActivity extends ListActivity
- implements OnItemClickListener, OnCreateContextMenuListener {
+import com.android.contacts.common.ContactPhotoManager;
+import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
+import com.android.internal.telephony.PhoneConstants;
+public class SpeedDialListActivity extends ListActivity implements
+ AdapterView.OnItemClickListener, PopupMenu.OnMenuItemClickListener {
private static final String TAG = "SpeedDial";
- private static final String ACTION_ADD_VOICEMAIL
- = "com.android.phone.CallFeaturesSetting.ADD_VOICEMAIL";
+ private static final String ACTION_ADD_VOICEMAIL =
+ "com.android.phone.CallFeaturesSetting.ADD_VOICEMAIL";
+ public static final String EXTRA_INITIAL_PICK_NUMBER = "initialPickNumber";
+
+ private static final String[] LOOKUP_PROJECTION = new String[] {
+ ContactsContract.Contacts._ID,
+ ContactsContract.Contacts.DISPLAY_NAME,
+ ContactsContract.Contacts.PHOTO_ID,
+ ContactsContract.PhoneLookup.NUMBER,
+ ContactsContract.PhoneLookup.NORMALIZED_NUMBER
+ };
- private static final int PREF_NUM = 8;
- private static final int SPEED_ITEMS = 9;
- //save the speed dial number
- private static String[] mContactDataNumber = new String[PREF_NUM];
- //save the speed dial name
- private static String[] mContactDataName = new String[PREF_NUM];
- //save the speed dial sim key
- private static Boolean[] mContactSimKey = new Boolean[PREF_NUM];
- //save the speed list item content, include 1 voice mail and 2-9 speed number
- private static String[] mSpeedListItems = new String[SPEED_ITEMS];
+ private static final String[] PICK_PROJECTION = new String[] {
+ ContactsContract.Data.CONTACT_ID,
+ ContactsContract.Data.DISPLAY_NAME,
+ ContactsContract.Data.PHOTO_ID,
+ ContactsContract.CommonDataKinds.Phone.NUMBER,
+ ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER
+ };
+ private static final int COLUMN_ID = 0;
+ private static final int COLUMN_NAME = 1;
+ private static final int COLUMN_PHOTO = 2;
+ private static final int COLUMN_NUMBER = 3;
+ private static final int COLUMN_NORMALIZED = 4;
- //speeddialutils class, use to read speed number form preference and update data
- private static SpeedDialUtils mSpeedDialUtils;
+ private static class Record {
+ long contactId;
+ String name;
+ String number;
+ String normalizedNumber;
+ long photoId;
+ public Record(String number) {
+ this.number = number;
+ this.contactId = -1;
+ }
+ }
- private static int mPosition;
+ private SparseArray<Record> mRecords;
+
+ private int mPickNumber;
+ private int mInitialPickNumber;
+ private SpeedDialAdapter mAdapter;
private static final int MENU_REPLACE = 0;
private static final int MENU_DELETE = 1;
@@ -94,83 +114,97 @@ public class SpeedDialListActivity extends ListActivity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mSpeedDialUtils = new SpeedDialUtils(this);
- // the first item is the "1.voice mail", it doesn't change for ever
- mSpeedListItems[0] = getString(R.string.speed_item, String.valueOf(1),
- getString(R.string.voicemail));
+ mInitialPickNumber = getIntent().getIntExtra(EXTRA_INITIAL_PICK_NUMBER, -1);
+ mRecords = new SparseArray<Record>();
- // get number and name from share preference
- for (int i = 0; i < PREF_NUM; i++) {
- mContactDataNumber[i] = mSpeedDialUtils.getContactDataNumber(i);
- mContactDataName[i] = mSpeedDialUtils.getContactDataName(i);
- mContactSimKey[i] = mSpeedDialUtils.getContactSimKey(i);
- }
+ //the first item is the "1.voice mail", it never changes
+ mRecords.put(1, new Record(getString(R.string.voicemail)));
ListView listview = getListView();
listview.setOnItemClickListener(this);
- listview.setOnCreateContextMenuListener(this);
+
+ // compensate for action bar overlay specified in theme
+ int actionBarHeight = getResources().getDimensionPixelSize(R.dimen.action_bar_height);
+ listview.setPaddingRelative(0, actionBarHeight, 0, 0);
+
+ final ActionBar actionBar = getActionBar();
+ actionBar.setDisplayShowHomeEnabled(true);
+ actionBar.setDisplayHomeAsUpEnabled(true);
+
+ mAdapter = new SpeedDialAdapter();
+ setListAdapter(mAdapter);
}
@Override
protected void onResume() {
- // TODO Auto-generated method stub
super.onResume();
- // when every on resume, should match name from contacts, because if
- // this activity is paused, and the contacts data is changed(eg:contact
- // is edited or deleted...),after it resumes, its data also be updated.
- matchInfoFromContacts();
- setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
- mSpeedListItems));
+ // get number from shared preferences
+ for (int i = 2; i <= 9; i++) {
+ String phoneNumber = SpeedDialUtils.getNumber(this, i);
+ Record record = null;
+ if (phoneNumber != null) {
+ Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
+ Uri.encode(phoneNumber));
+ record = getRecordFromQuery(uri, LOOKUP_PROJECTION);
+ if (record == null) {
+ record = new Record(phoneNumber);
+ }
+ }
+ mRecords.put(i, record);
+ }
+
+ mAdapter.notifyDataSetChanged();
+
+ if (mInitialPickNumber >= 2 && mInitialPickNumber <= 9) {
+ pickContact(mInitialPickNumber);
+ // we only want to trigger the picker once
+ mInitialPickNumber = -1;
+ }
}
- /*
- * use to match number from contacts, if the speed number is in contacts,
- * the speed item show corresponding contact name, else show number.
- */
- private void matchInfoFromContacts() {
- // TODO Auto-generated method stub
- for (int i = 1; i < SPEED_ITEMS; i++) {
- // if there is no speed dial number for number key, show "not set", or lookup in contacts
- // according to number, if exist, show contact name, else show number.
- if (TextUtils.isEmpty(mContactDataNumber[i - 1])) {
- mContactDataName[i - 1] = "";
- mContactSimKey[i - 1] = false;
-
- mSpeedListItems[i] = getString(R.string.speed_item, String.valueOf(i + 1),
- getString(R.string.not_set));
- } else {
- mContactDataName[i - 1] = mSpeedDialUtils.getValidName(mContactDataNumber[i - 1]);
- if (TextUtils.isEmpty(mContactDataName[i - 1])) {
- mContactDataName[i - 1] = "";
- mContactSimKey[i - 1] = false;
-
- mSpeedListItems[i] = getString(R.string.speed_item, String.valueOf(i + 1),
- mContactDataNumber[i - 1]);
- } else {
- mContactSimKey[i - 1] = mSpeedDialUtils
- .isSimAccontByNumber(mContactDataNumber[i - 1]);
-
- mSpeedListItems[i] = getString(R.string.speed_item, String.valueOf(i + 1),
- mContactDataName[i - 1]);
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ finish();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ private Record getRecordFromQuery(Uri uri, String[] projection) {
+ Record record = null;
+ Cursor cursor = null;
+ try {
+ cursor = getContentResolver().query(uri, projection, null, null, null);
+ if (cursor != null && cursor.moveToFirst()) {
+ record = new Record(cursor.getString(COLUMN_NUMBER));
+ record.contactId = cursor.getLong(COLUMN_ID);
+ record.photoId = cursor.getLong(COLUMN_PHOTO);
+ record.name = cursor.getString(COLUMN_NAME);
+ record.normalizedNumber = cursor.getString(COLUMN_NORMALIZED);
+ if (record.normalizedNumber == null) {
+ record.normalizedNumber = record.number;
}
}
- mSpeedDialUtils.storeContactDataNumber(i - 1, mContactDataNumber[i - 1]);
- mSpeedDialUtils.storeContactDataName(i - 1, mContactDataName[i - 1]);
- mSpeedDialUtils.storeContactSimKey(i - 1, mContactSimKey[i - 1]);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
+ return record;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- // TODO Auto-generated method stub
if (position == 0) {
Intent intent = new Intent(ACTION_ADD_VOICEMAIL);
if (TelephonyManager.getDefault().getPhoneCount() > 1) {
long sub = SubscriptionManager.getDefaultVoiceSubId();
intent.setClassName("com.android.phone",
"com.android.phone.MSimCallFeaturesSubSetting");
- intent.putExtra(SUBSCRIPTION_KEY, sub);
+ intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, sub);
} else {
intent.setClassName("com.android.phone",
"com.android.phone.CallFeaturesSetting");
@@ -178,169 +212,130 @@ public class SpeedDialListActivity extends ListActivity
try {
startActivity(intent);
} catch(ActivityNotFoundException e) {
- Log.w(TAG, "can not find activity deal with voice mail");
+ Log.w(TAG, "Could not find voice mail setup activity");
}
- } else if (position < SPEED_ITEMS) {
- if ("".equals(mContactDataNumber[position - 1])) {
- goContactsToPick(position);
+ } else {
+ int number = position + 1;
+ final Record record = mRecords.get(number);
+ if (record == null) {
+ pickContact(number);
} else {
- final String numStr = mContactDataNumber[position - 1];
- final String nameStr = mContactDataName[position - 1];
- new AlertDialog.Builder(this)
- .setTitle(nameStr)
- .setMessage(numStr)
- .setPositiveButton(R.string.speed_call,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // TODO Auto-generated method stub
- Intent callIntent = new Intent(Intent.ACTION_CALL);
- callIntent.setData(Uri.fromParts("tel", numStr, null));
- callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(callIntent);
- }
- })
- .setNegativeButton(R.string.speed_sms,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // TODO Auto-generated method stub
- Intent smsIntent = new Intent(Intent.ACTION_SENDTO,
- Uri.fromParts("sms", numStr, null));
- startActivity(smsIntent);
- }
- })
- .show();
+ PopupMenu pm = new PopupMenu(this, view);
+ pm.getMenu().add(number, MENU_REPLACE, 0, R.string.speed_dial_replace);
+ pm.getMenu().add(number, MENU_DELETE, 0, R.string.speed_dial_delete);
+ pm.setOnMenuItemClickListener(this);
+ pm.show();
}
- } else {
- Log.w(TAG, "the invalid item");
}
}
/*
* goto contacts, used to set or replace speed number
*/
- private void goContactsToPick(int position) {
- // TODO Auto-generated method stub
- mPosition = position;
- Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds
- .Phone.CONTENT_URI);
+ private void pickContact(int number) {
+ mPickNumber = number;
+ Intent intent = new Intent(Intent.ACTION_PICK);
+ intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT_RESULT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- // TODO Auto-generated method stub
- if (requestCode == PICK_CONTACT_RESULT && resultCode == Activity.RESULT_OK
- && data != null) {
- // get phone number according to the uri
- Uri uriRet = data.getData();
- if (uriRet != null) {
- int numId = mPosition - 1;
- Cursor c = null;
- try {
- c = getContentResolver().query(uriRet, null, null, null, null);
- if (null != c && 0 != c.getCount()) {
- c.moveToFirst();
- String number = c.getString(c.getColumnIndexOrThrow(Data.DATA1));
- String name = "";
- String accountType = null;
- int rawContactId = c.getInt(c.getColumnIndexOrThrow("raw_contact_id"));
- String where = "_id = " + rawContactId;
- c = getContentResolver().query(RawContacts.CONTENT_URI, new String[] {
- "display_name", "account_type"}, where, null, null);
- if (null != c && 0 != c.getCount()) {
- c.moveToFirst();
- name = c.getString(c.getColumnIndexOrThrow("display_name"));
- accountType = c.getString(c.getColumnIndexOrThrow("account_type"));
- if (!okToSet(number)) {
- Toast.makeText(this, R.string.assignSpeedDialFailToast,
- Toast.LENGTH_LONG).show();
- return;
- } else {
- mContactDataName[numId] = name;
- mContactDataNumber[numId] = number;
- mContactSimKey[numId] = mSpeedDialUtils.isSimAccount(accountType);
- }
- }
- } else {
- mContactDataNumber[numId] = "";
- mContactDataName[numId] = "";
- }
- } catch (Exception e) {
- // exception happens
- } finally {
- if (null != c) {
- c.close();
- }
- }
- mSpeedDialUtils.storeContactDataNumber(numId, mContactDataNumber[numId]);
- mSpeedDialUtils.storeContactDataName(numId, mContactDataName[numId]);
- mSpeedDialUtils.storeContactSimKey(numId, mContactSimKey[numId]);
- }
+ if (requestCode != PICK_CONTACT_RESULT) {
+ super.onActivityResult(requestCode, resultCode, data);
+ return;
}
- super.onActivityResult(requestCode, resultCode, data);
- }
- private boolean okToSet(String number) {
- boolean isCheckOk = true;
- for (String phoneNumber: mContactDataNumber) {
- if (number.equals(phoneNumber)) {
- isCheckOk = false;
- break;
+ if (resultCode == RESULT_OK) {
+ Record record = getRecordFromQuery(data.getData(), PICK_PROJECTION);
+ if (record != null) {
+ SpeedDialUtils.saveNumber(this, mPickNumber, record.normalizedNumber);
+ mRecords.put(mPickNumber, record);
+ mAdapter.notifyDataSetChanged();
}
}
- return isCheckOk;
}
@Override
- public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
- // TODO Auto-generated method stub
- AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
- int pos = info.position;
- if (pos > 0 && pos < SPEED_ITEMS) {
- if (!("".equals(mContactDataNumber[pos - 1]))) {
- String contactNum = mContactDataNumber[pos - 1];
- String contactName = mContactDataName[pos - 1];
- String hdrTitle = !("".equals(contactName)) ? contactName : contactNum;
- menu.setHeaderTitle(hdrTitle);
- menu.add(0, MENU_REPLACE, 0, R.string.replace);
- menu.add(0, MENU_DELETE, 0, R.string.delete);
- }
- }
- super.onCreateContextMenu(menu, v, menuInfo);
- }
+ public boolean onMenuItemClick(MenuItem item) {
+ int number = item.getGroupId();
- @Override
- public boolean onContextItemSelected(MenuItem item) {
- // TODO Auto-generated method stub
- int itemId = item.getItemId();
- AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item
- .getMenuInfo();
- int pos = info.position;
-
- switch (itemId) {
+ switch (item.getItemId()) {
case MENU_REPLACE:
- goContactsToPick(pos);
- break;
+ pickContact(number);
+ return true;
case MENU_DELETE:
- // delete speed number, only need set array data to "",
- // and clear speed number in preference.
- mContactDataNumber[pos - 1] = "";
- mContactDataName[pos - 1] = "";
- mSpeedListItems[pos] = getString(R.string.speed_item, String.valueOf(pos + 1),
- getString(R.string.not_set));
- mSpeedDialUtils.storeContactDataNumber(pos - 1, "");
- mSpeedDialUtils.storeContactDataName(pos - 1, "");
- mSpeedDialUtils.storeContactSimKey(pos - 1, false);
- // update listview item
- setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
- mSpeedListItems));
- break;
- default:
- break;
+ mRecords.put(number, null);
+ SpeedDialUtils.saveNumber(this, number, null);
+ mAdapter.notifyDataSetChanged();
+ return true;
}
- return super.onContextItemSelected(item);
+ return false;
}
+ private class SpeedDialAdapter extends BaseAdapter {
+ private LayoutInflater mInflater;
+ private ContactPhotoManager mPhotoManager;
+
+ public SpeedDialAdapter() {
+ mInflater = LayoutInflater.from(SpeedDialListActivity.this);
+ mPhotoManager = (ContactPhotoManager) getApplicationContext().getSystemService(
+ ContactPhotoManager.CONTACT_PHOTO_SERVICE);
+ }
+
+ @Override
+ public int getCount() {
+ return mRecords.size();
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position + 1;
+ }
+
+ @Override
+ public Object getItem(int position) {
+ return mRecords.get(position + 1);
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ if (convertView == null) {
+ convertView = mInflater.inflate(R.layout.speed_dial_item, parent, false);
+ }
+
+ TextView index = (TextView) convertView.findViewById(R.id.index);
+ TextView name = (TextView) convertView.findViewById(R.id.name);
+ TextView number = (TextView) convertView.findViewById(R.id.number);
+ QuickContactBadge photo = (QuickContactBadge) convertView.findViewById(R.id.photo);
+ Record record = mRecords.get(position + 1);
+
+ index.setText(String.valueOf(position + 1));
+ if (record != null && record.name != null) {
+ name.setText(record.name);
+ number.setText(record.number);
+ number.setVisibility(View.VISIBLE);
+ } else {
+ name.setText(record != null ?
+ record.number : getString(R.string.speed_dial_not_set));
+ number.setVisibility(View.GONE);
+ }
+
+ if (record != null && record.contactId != -1) {
+ DefaultImageRequest request = new DefaultImageRequest(record.name,
+ record.normalizedNumber, true /* isCircular */);
+ mPhotoManager.removePhoto(photo);
+ mPhotoManager.loadThumbnail(photo, record.photoId,
+ false /* darkTheme */, true /* isCircular */, request);
+ photo.assignContactUri(ContentUris.withAppendedId(
+ ContactsContract.Contacts.CONTENT_URI, record.contactId));
+ photo.setVisibility(View.VISIBLE);
+ } else {
+ photo.setVisibility(View.GONE);
+ }
+ photo.setOverlay(null);
+
+ return convertView;
+ }
+ };
}
diff --git a/src/com/android/dialer/SpeedDialUtils.java b/src/com/android/dialer/SpeedDialUtils.java
index aacd0cbff..de8b53eff 100644
--- a/src/com/android/dialer/SpeedDialUtils.java
+++ b/src/com/android/dialer/SpeedDialUtils.java
@@ -29,263 +29,35 @@
package com.android.dialer;
-import android.app.Activity;
-import android.content.ContentUris;
import android.content.Context;
import android.content.SharedPreferences;
-import android.database.Cursor;
-import android.net.Uri;
-import android.provider.ContactsContract;
-import android.provider.ContactsContract.Contacts.Data;
-import android.provider.ContactsContract.RawContacts;
-import android.util.Log;
-/**
- * this class is used to set or get speed number in preference.
- * @author c_hluo
- *
- */
public class SpeedDialUtils {
+ private static final String NUMBER_KEY_PREFIX = "number_";
- public static final int NUM_TWO = 0;
- public static final int NUM_THREE = 1;
- public static final int NUM_FOUR = 2;
- public static final int NUM_FIVE = 3;
- public static final int NUM_SIX = 4;
- public static final int NUM_SEVEN = 5;
- public static final int NUM_EIGHT = 6;
- public static final int NUM_NINE = 7;
-
- public static final int INFO_NUMBER = 0;
- public static final int INFO_NAME = 1;
-
- public static final String ACCOUNT_TYPE_SIM = "com.android.sim";
-
- private static final String[] numKeys = new String[] {"num2_key","num3_key","num4_key",
- "num5_key","num6_key","num7_key","num8_key","num9_key"};
- private static final String[] nameKeys = new String[] {"name2_key","name3_key","name4_key",
- "name5_key","name6_key","name7_key","name8_key","name9_key"};
- private static final String[] simKeys = new String[] {"sim2_key","sim3_key","sim4_key",
- "sim5_key","sim6_key","sim7_key","sim8_key","sim9_key"};
- private SharedPreferences mPref;
-
- private Context mContext;
-
- /*
- * constructed function, in fact used to init shared preferences object.
- */
- public SpeedDialUtils(Context context) {
- mContext = context;
- mPref = mContext.getApplicationContext().getSharedPreferences("speedDial_Num",
- context.MODE_PRIVATE);
- }
-
- /*
- * set speed number to share preference
- */
- public void storeContactDataId(int numId, int keyValue) {
- SharedPreferences.Editor editor = mPref.edit();
- editor.putInt(numKeys[numId], keyValue);
- editor.commit();
- }
-
- /*
- * get raw contact id from share preference
- */
- public int getContactDataId(int numId) {
- return mPref.getInt(numKeys[numId], 0);
- }
-
- /*
- * set speed number to share preference
- */
- public void storeContactDataNumber(int numId, String keyValue) {
- SharedPreferences.Editor editor = mPref.edit();
- editor.putString(numKeys[numId], keyValue);
- editor.commit();
- }
-
- /*
- * set speed name to share preference
- */
- public void storeContactDataName(int numId, String keyValue) {
- SharedPreferences.Editor editor = mPref.edit();
- editor.putString(nameKeys[numId], keyValue);
- editor.commit();
- }
-
- /*
- * get phone number from share preference
- */
- public String getContactDataNumber(int numId) {
- return mPref.getString(numKeys[numId], "");
- }
-
- /*
- * get name from share preference
- */
- public String getContactDataName(int numId) {
- return mPref.getString(nameKeys[numId], "");
- }
-
- /*
- * set sim key to share preference
- */
- public void storeContactSimKey(int numId, boolean isSimAccount) {
- SharedPreferences.Editor editor = mPref.edit();
- editor.putBoolean(simKeys[numId], isSimAccount);
- editor.commit();
- }
-
- /*
- * get sim key from share preference
- */
- public boolean getContactSimKey(int numId) {
- return mPref.getBoolean(simKeys[numId], false);
- }
-
- /*
- * get speed dial information(name or number) according number key
- */
- public String getSpeedDialInfo(int contactDataId, int infoType) {
- Cursor c = null;
- String speedDialInfo = null;
-
- if (contactDataId == 0)
- return null;
-
- Uri lookupUri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI,
- contactDataId);
-
- try{
- c = mContext.getContentResolver().query(lookupUri, null, null, null, null);
- if ( c != null && c.moveToFirst() ) {
- if (infoType == INFO_NUMBER) {
- //data1 is the phone number, we can get it by data id.
- speedDialInfo = c.getString(c.getColumnIndexOrThrow(Data.DATA1));
- } else {
- //now we want to get phone name, first shoud get raw contact
- //id by data id, and then get phone name by raw contact id.
- int rawContactId = c.getInt(c.getColumnIndexOrThrow(Data.RAW_CONTACT_ID));
- lookupUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);;
- String querySelection = RawContacts.DELETED+"="+0;
- if (c != null) {
- c.close();
- }
- c = mContext.getContentResolver().query(lookupUri, null, querySelection,
- null, null);
- if (c != null && c.moveToFirst()) {
- speedDialInfo = c.getString(c.getColumnIndexOrThrow(
- RawContacts.DISPLAY_NAME_PRIMARY));
- }
- }
- }
- } catch(Exception e) {
- //exception happen
- } finally {
- if (c != null) {
- c.close();
- }
- }
-
- return speedDialInfo;
- }
-
- public String getValidName(String contactNumber) {
- String mContactDataName = null;
- if ("".equals(contactNumber)) {
- return null;
+ public static void saveNumber(Context context, int position, String phoneNumber) {
+ if (position < 2 || position > 9) {
+ return;
}
- Cursor rawCursor = null;
- Cursor dataCursor = null;
- try {
- dataCursor = mContext.getContentResolver().query(
- ContactsContract.Data.CONTENT_URI, null,
- Data.DATA1 + " = ? AND " + Data.MIMETYPE + " = '"
- + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "'",
- new String[] {contactNumber}, null);
- if (null == dataCursor || 0 == dataCursor.getCount()) {
- return null;
- }
- while (dataCursor.moveToNext()) {
- int rawContactId = dataCursor.getInt(
- dataCursor.getColumnIndexOrThrow(Data.RAW_CONTACT_ID));
- rawCursor = mContext.getContentResolver().query(
- RawContacts.CONTENT_URI, null,
- RawContacts._ID + " = ? AND deleted = ?",
- new String[] { String.valueOf(rawContactId), String.valueOf(0) },
- null);
- if (null == rawCursor || 0 == rawCursor.getCount()) {
- return null;
- } else {
- if (rawCursor.moveToFirst()) {
- mContactDataName = rawCursor.getString(
- rawCursor.getColumnIndexOrThrow(RawContacts
- .DISPLAY_NAME_PRIMARY));
- }
- }
- }
- } catch (Exception e) {
- // exception happens
- } finally {
- if (null != dataCursor) {
- dataCursor.close();
- }
- if (null != rawCursor) {
- rawCursor.close();
- }
+ SharedPreferences.Editor editor = getPrefs(context).edit();
+ String key = NUMBER_KEY_PREFIX + position;
+ if (phoneNumber == null) {
+ editor.remove(key);
+ } else {
+ editor.putString(key, phoneNumber);
}
- return mContactDataName;
+ editor.commit();
}
- public boolean isSimAccontByNumber(String contactNumber) {
- boolean isSimAccount = false;
- if ("".equals(contactNumber)) {
- return false;
- }
- Cursor rawCursor = null;
- Cursor dataCursor = null;
- try {
- dataCursor = mContext.getContentResolver().query(
- ContactsContract.Data.CONTENT_URI, null,
- Data.DATA1 + " = ? AND " + Data.MIMETYPE + " = '"
- + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "'",
- new String[] {contactNumber}, null);
- if (null == dataCursor || 0 == dataCursor.getCount()) {
- return false;
- }
- while (dataCursor.moveToNext()) {
- int rawContactId = dataCursor.getInt(
- dataCursor.getColumnIndexOrThrow(Data.RAW_CONTACT_ID));
- rawCursor = mContext.getContentResolver().query(
- RawContacts.CONTENT_URI, null,
- RawContacts._ID + " = ? AND deleted = ?",
- new String[] { String.valueOf(rawContactId), String.valueOf(0) },
- null);
- if (null == rawCursor || 0 == rawCursor.getCount()) {
- return false;
- } else {
- if (rawCursor.moveToFirst()) {
- String accountType = rawCursor.getString(rawCursor
- .getColumnIndexOrThrow("account_type"));
- isSimAccount = isSimAccount(accountType);
- }
- }
- }
- } catch (Exception e) {
- // exception happens
- } finally {
- if (null != dataCursor) {
- dataCursor.close();
- }
- if (null != rawCursor) {
- rawCursor.close();
- }
+ public static String getNumber(Context context, int position) {
+ if (position < 2 || position > 9) {
+ return null;
}
- return isSimAccount;
+ String key = NUMBER_KEY_PREFIX + position;
+ return getPrefs(context).getString(key, null);
}
- public boolean isSimAccount(String accountType) {
- return ACCOUNT_TYPE_SIM.equals(accountType);
+ private static SharedPreferences getPrefs(Context context) {
+ return context.getSharedPreferences("speeddial", context.MODE_PRIVATE);
}
}
diff --git a/src/com/android/dialer/dialpad/DialpadFragment.java b/src/com/android/dialer/dialpad/DialpadFragment.java
index e20f6c9de..ac86ae7ea 100644
--- a/src/com/android/dialer/dialpad/DialpadFragment.java
+++ b/src/com/android/dialer/dialpad/DialpadFragment.java
@@ -1928,67 +1928,47 @@ public class DialpadFragment extends AnalyticsFragment
}
private void callSpeedNumber(int id) {
- int numId = 0;
- SpeedDialUtils speedDialUtils = new SpeedDialUtils(getActivity());
-
- switch (id) {
- case R.id.two:
- numId = speedDialUtils.NUM_TWO;
- break;
- case R.id.three:
- numId = speedDialUtils.NUM_THREE;
- break;
- case R.id.four:
- numId = speedDialUtils.NUM_FOUR;
- break;
- case R.id.five:
- numId = speedDialUtils.NUM_FIVE;
- break;
- case R.id.six:
- numId = speedDialUtils.NUM_SIX;
- break;
- case R.id.seven:
- numId = speedDialUtils.NUM_SEVEN;
- break;
- case R.id.eight:
- numId = speedDialUtils.NUM_EIGHT;
- break;
- case R.id.nine:
- numId = speedDialUtils.NUM_NINE;
- break;
- }
-
- String speedNumber = speedDialUtils.getContactDataNumber(numId);
- if (speedNumber == null || speedNumber.length() == 0) {
- showNoSpeedNumberDialog(numId);
+ int number;
+
+ switch(id) {
+ case R.id.two: number = 2; break;
+ case R.id.three: number = 3; break;
+ case R.id.four: number = 4; break;
+ case R.id.five: number = 5; break;
+ case R.id.six: number = 6; break;
+ case R.id.seven: number = 7; break;
+ case R.id.eight: number = 8; break;
+ case R.id.nine: number = 9; break;
+ default: return;
+ }
+
+ String phoneNumber = SpeedDialUtils.getNumber(getActivity(), number);
+ if (phoneNumber == null) {
+ showNoSpeedNumberDialog(number);
} else {
- Intent intent = new Intent(Intent.ACTION_CALL);
- intent.setData(Uri.fromParts("tel", speedNumber, null));
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(intent);
+ final DialtactsActivity activity = getActivity() instanceof DialtactsActivity
+ ? (DialtactsActivity) getActivity() : null;
+ final Intent intent = CallUtil.getCallIntent(phoneNumber,
+ activity != null ? activity.getCallOrigin() : null);
+ DialerUtils.startActivityWithErrorToast(getActivity(), intent);
getActivity().finish();
}
}
- private void showNoSpeedNumberDialog(int numId) {
- // numId's range is [0,7], but numKey's range is [2,9], so need to plus two.
- int numKey = numId + 2;
- String dialogTxt = getString(R.string.is_set_speed, String.valueOf(numKey));
- final Activity thisActivity = getActivity();
- new AlertDialog.Builder(thisActivity)
- .setTitle(R.string.dialog_title)
- .setMessage(dialogTxt)
- .setPositiveButton(android.R.string.ok,
- new DialogInterface.OnClickListener() {
+ private void showNoSpeedNumberDialog(final int number) {
+ new AlertDialog.Builder(getActivity())
+ .setTitle(R.string.speed_dial_unassigned_dialog_title)
+ .setMessage(getString(R.string.speed_dial_unassigned_dialog_message, number))
+ .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- // TODO Auto-generated method stub
// go to speed dial setting screen to set speed dial number.
- Intent intent = new Intent(thisActivity, SpeedDialListActivity.class);
+ Intent intent = new Intent(getActivity(), SpeedDialListActivity.class);
+ intent.putExtra(SpeedDialListActivity.EXTRA_INITIAL_PICK_NUMBER, number);
startActivity(intent);
}
})
- .setNegativeButton(android.R.string.cancel, null)
- .show();
+ .setNegativeButton(R.string.no, null)
+ .show();
}
}
diff --git a/src/com/android/dialer/settings/GeneralSettingsFragment.java b/src/com/android/dialer/settings/GeneralSettingsFragment.java
index d04fae398..30a7b6317 100644
--- a/src/com/android/dialer/settings/GeneralSettingsFragment.java
+++ b/src/com/android/dialer/settings/GeneralSettingsFragment.java
@@ -47,6 +47,7 @@ public class GeneralSettingsFragment extends PreferenceFragment
private static final String BUTTON_VIBRATE_ON_RING = "button_vibrate_on_ring";
private static final String BUTTON_PLAY_DTMF_TONE = "button_play_dtmf_tone";
private static final String BUTTON_RESPOND_VIA_SMS_KEY = "button_respond_via_sms_key";
+ private static final String BUTTON_SPEED_DIAL_KEY = "speed_dial_settings";
private static final int MSG_UPDATE_RINGTONE_SUMMARY = 1;
@@ -56,6 +57,7 @@ public class GeneralSettingsFragment extends PreferenceFragment
private CheckBoxPreference mVibrateWhenRinging;
private CheckBoxPreference mPlayDtmfTone;
private Preference mRespondViaSms;
+ private Preference mSpeedDialSettings;
private Runnable mRingtoneLookupRunnable;
private final Handler mRingtoneLookupComplete = new Handler() {
@@ -81,6 +83,7 @@ public class GeneralSettingsFragment extends PreferenceFragment
mVibrateWhenRinging = (CheckBoxPreference) findPreference(BUTTON_VIBRATE_ON_RING);
mPlayDtmfTone = (CheckBoxPreference) findPreference(BUTTON_PLAY_DTMF_TONE);
mRespondViaSms = findPreference(BUTTON_RESPOND_VIA_SMS_KEY);
+ mSpeedDialSettings = findPreference(BUTTON_SPEED_DIAL_KEY);
PreferenceCategory soundCategory = (PreferenceCategory) findPreference(CATEGORY_SOUNDS_KEY);
if (mVibrateWhenRinging != null) {
@@ -138,7 +141,7 @@ public class GeneralSettingsFragment extends PreferenceFragment
if (preference == mPlayDtmfTone) {
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.DTMF_TONE_WHEN_DIALING, mPlayDtmfTone.isChecked() ? 1 : 0);
- } else if (preference == mRespondViaSms) {
+ } else if (preference == mRespondViaSms || preference == mSpeedDialSettings) {
// Needs to return false for the intent to launch.
return false;
}