summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2014-09-05 11:39:16 +0200
committerDanny Baumann <dannybaumann@web.de>2014-09-09 10:12:30 +0200
commit77a52dc9b556b295187aadd63a080c85cc38da7b (patch)
tree08d441aee450fbd4d885f93dfb8c0f4e9ed33b60
parent5c85fa75715d1861efeb780126b953fec6121653 (diff)
downloadandroid_packages_apps_Dialer-77a52dc9b556b295187aadd63a080c85cc38da7b.tar.gz
android_packages_apps_Dialer-77a52dc9b556b295187aadd63a080c85cc38da7b.tar.bz2
android_packages_apps_Dialer-77a52dc9b556b295187aadd63a080c85cc38da7b.zip
Rewrite speed dial feature.
Change-Id: I346bcf4552cdf2ddfd3c9b1219bc07c20332d1a2
-rwxr-xr-xAndroidManifest.xml4
-rwxr-xr-xres/layout/speed_dial_item.xml63
-rw-r--r--res/menu/dialpad_options.xml5
-rw-r--r--res/values/cm_strings.xml8
-rw-r--r--res/values/dimens.xml2
-rwxr-xr-xsrc/com/android/dialer/SpeedDialListActivity.java434
-rwxr-xr-xsrc/com/android/dialer/SpeedDialUtils.java264
-rw-r--r--src/com/android/dialer/dialpad/DialpadFragment.java88
8 files changed, 340 insertions, 528 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 8e0a6e679..0be343bec 100755
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -292,8 +292,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..53807db14
--- /dev/null
+++ b/res/layout/speed_dial_item.xml
@@ -0,0 +1,63 @@
+<?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="8dip"
+ android:paddingEnd="8dip"
+ 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_marginStart="4dp"
+ 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/speed_dial_list_contact_photo_size"
+ android:layout_height="@dimen/speed_dial_list_contact_photo_size"
+ android:layout_gravity="center_vertical"
+ android:layout_marginEnd="8dp" />
+
+</LinearLayout>
+
diff --git a/res/menu/dialpad_options.xml b/res/menu/dialpad_options.xml
index 0bbcecbd2..1ac7998d5 100644
--- a/res/menu/dialpad_options.xml
+++ b/res/menu/dialpad_options.xml
@@ -49,4 +49,9 @@
android:showAsAction="withText"
android:orderInCategory="1" />
<!-- add for CSVT -->
+ <item
+ android:id="@+id/speed_dial"
+ android:title="@string/speed_dial_settings"
+ android:showAsAction="withText"
+ android:orderInCategory="1" />
</menu>
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index 2ed5b7225..84625e956 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -73,18 +73,16 @@
<string name="description_videocall">Video call <xliff:g id="name">%1$s</xliff:g></string>
<!-- for speed dial -->
- <string name="set_speed_dial">Speed dial settings</string>
+ <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_call">Call</string>
- <string name="speed_sms">Message</string>
- <string name="speed_item" translatable="false">&lt;b&gt;<xliff:g id="index">%s</xliff:g>&lt;/b&gt; <xliff:g id="content">%s</xliff:g></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="speed_dial_assign_failure_toast">The number \'<xliff:g id="number">%s</xliff:g>\' is already assigned to different speed dial key</string>
<string name="msim_ime_dialog_title">Device identifier</string>
<string name="multi_sim_slot_name">SIM <xliff:g id="index">%d</xliff:g></string>
<string name="call_log_show_all_slots">All SIMs</string>
+ <string name="yes">Yes</string>
+ <string name="no">No</string>
</resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index fe7658a72..35ff8694e 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -133,4 +133,6 @@
<!-- Size of the pie chart in the call stats detail activity -->
<dimen name="call_stats_details_chart_size">140dip</dimen>
+
+ <dimen name="speed_dial_list_contact_photo_size">40dp</dimen>
</resources>
diff --git a/src/com/android/dialer/SpeedDialListActivity.java b/src/com/android/dialer/SpeedDialListActivity.java
index 656ad676f..76869f7e2 100755
--- a/src/com/android/dialer/SpeedDialListActivity.java
+++ b/src/com/android/dialer/SpeedDialListActivity.java
@@ -29,59 +29,79 @@
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.MSimTelephonyManager;
-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.MSimConstants.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.MSimConstants;
+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;
@@ -93,78 +113,86 @@ public class SpeedDialListActivity extends ListActivity implements OnItemClickLi
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);
+
+ 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.speed_dial_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 (MSimTelephonyManager.getDefault().isMultiSimEnabled()) {
@@ -173,173 +201,135 @@ public class SpeedDialListActivity extends ListActivity implements OnItemClickLi
Settings.Global.MULTI_SIM_VOICE_CALL_SUBSCRIPTION, 0);
intent.setClassName("com.android.phone",
"com.android.phone.MSimCallFeaturesSubSetting");
- intent.putExtra(SUBSCRIPTION_KEY, sub);
+ intent.putExtra(MSimConstants.SUBSCRIPTION_KEY, sub);
} else {
intent.setClassName("com.android.phone", "com.android.phone.CallFeaturesSetting");
}
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_PRIVILEGED);
- 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)) {
- String text = getString(R.string.speed_dial_assign_failure_toast,
- number);
- Toast.makeText(this, text, 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;
+ 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.speed_dial_replace);
- menu.add(0, MENU_DELETE, 0, R.string.speed_dial_delete);
- }
+ public boolean onMenuItemClick(MenuItem item) {
+ int number = item.getGroupId();
+
+ switch (item.getItemId()) {
+ case MENU_REPLACE:
+ pickContact(number);
+ return true;
+ case MENU_DELETE:
+ mRecords.put(number, null);
+ SpeedDialUtils.saveNumber(this, number, null);
+ mAdapter.notifyDataSetChanged();
+ return true;
}
- super.onCreateContextMenu(menu, v, menuInfo);
+ return false;
}
- @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) {
- case MENU_REPLACE:
- goContactsToPick(pos);
- break;
- 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.speed_dial_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;
+ 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;
}
- return super.onContextItemSelected(item);
- }
+ @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);
+ mPhotoManager.removePhoto(photo);
+ mPhotoManager.loadThumbnail(photo, record.photoId, false, request);
+ photo.assignContactUri(ContentUris.withAppendedId(
+ ContactsContract.Contacts.CONTENT_URI, record.contactId));
+ photo.setVisibility(View.VISIBLE);
+ } else {
+ photo.setVisibility(View.GONE);
+ }
+
+ return convertView;
+ }
+ };
}
diff --git a/src/com/android/dialer/SpeedDialUtils.java b/src/com/android/dialer/SpeedDialUtils.java
index 08793ce1e..c20ca7b05 100755
--- 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 0ab28780c..30113f737 100644
--- a/src/com/android/dialer/dialpad/DialpadFragment.java
+++ b/src/com/android/dialer/dialpad/DialpadFragment.java
@@ -1677,6 +1677,9 @@ public class DialpadFragment extends Fragment
case R.id.menu_ip_call_by_slot2:
ipCallBySlot(MSimConstants.SUB2);
return true;
+ case R.id.speed_dial:
+ startActivity(new Intent(getActivity(), SpeedDialListActivity.class));
+ return true;
default:
return false;
}
@@ -1959,67 +1962,46 @@ public class DialpadFragment extends Fragment
}
private void callSpeedNumber(int id) {
- SpeedDialUtils speedDialUtils = new SpeedDialUtils(getActivity());
- int numId = 0;
- String speedNumber;
- String speedName;
+ int number;
+
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;
- }
- speedNumber = speedDialUtils.getContactDataNumber(numId);
- speedName = speedDialUtils.getContactDataName(numId);
- if (speedNumber == null || speedNumber.length() == 0) {
- showNoSpeedNumberDialog(numId);
+ 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_PRIVILEGED);
- intent.setData(Uri.fromParts("tel", speedNumber, null));
+ intent.setData(Uri.fromParts("tel", phoneNumber, null));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
getActivity().finish();
}
}
- private void showNoSpeedNumberDialog(int numId) {
- //because numId start from 0, but numKey from 2 that represent num 2-9, so here add two
- int numKey = numId + 2;
- String dialogTxt = getString(R.string.speed_dial_unassigned_dialog_message,
- String.valueOf(numKey));
- final Activity thisActivity = getActivity();
- new AlertDialog.Builder(thisActivity)
- .setTitle(R.string.speed_dial_unassigned_dialog_title)
- .setMessage(dialogTxt)
- .setPositiveButton(android.R.string.ok,
- 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);
- startActivity(intent);
- }
- }).setNegativeButton(android.R.string.cancel,null)
+
+ 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) {
+ // go to speed dial setting screen to set speed dial number.
+ Intent intent = new Intent(getActivity(), SpeedDialListActivity.class);
+ intent.putExtra(SpeedDialListActivity.EXTRA_INITIAL_PICK_NUMBER, number);
+ startActivity(intent);
+ }
+ })
+ .setNegativeButton(R.string.no, null)
.show();
}
}