diff options
author | qqzhou <qqzhou@codeaurora.org> | 2014-07-24 16:07:02 +0800 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-03-21 15:28:01 -0700 |
commit | 88663a6d1826ad662dfbaa26f33d714a18cb22d7 (patch) | |
tree | 211a19e2acc5f7e67fe858bd459f6e02c9ba360b | |
parent | c56a503b4c528c0643fcefcbd235e5aa4e0abbb3 (diff) | |
download | android_packages_apps_Dialer-88663a6d1826ad662dfbaa26f33d714a18cb22d7.tar.gz android_packages_apps_Dialer-88663a6d1826ad662dfbaa26f33d714a18cb22d7.tar.bz2 android_packages_apps_Dialer-88663a6d1826ad662dfbaa26f33d714a18cb22d7.zip |
Dialer: add to support speed number dial
allow user to set speed dial number from 2~9, when long click
these numbers, it will pop up a screen to set speed number
or dial out directly if you have set it before.
Change-Id: Iaab841933ad0e63dee70e7f4dc7f078507c425b3
-rw-r--r-- | AndroidManifest.xml | 8 | ||||
-rw-r--r-- | res/values-zh-rCN/strings.xml | 13 | ||||
-rw-r--r-- | res/values/strings.xml | 14 | ||||
-rw-r--r-- | src/com/android/dialer/SpeedDialListActivity.java | 333 | ||||
-rw-r--r-- | src/com/android/dialer/SpeedDialUtils.java | 291 | ||||
-rw-r--r-- | src/com/android/dialer/dialpad/DialpadFragment.java | 96 |
6 files changed, 755 insertions, 0 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 56089fa66..497dad113 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -239,6 +239,14 @@ </intent-filter> </receiver> + <activity android:name=".SpeedDialListActivity" + android:configChanges="orientation|screenSize|keyboardHidden|uiMode" + android:label="@string/set_speed_dial" > + <intent-filter> + <action android:name="android.intent.action.MAIN"/> + </intent-filter> + </activity> + <receiver android:name=".interactions.UndemoteOutgoingCallReceiver"> <intent-filter> <action android:name="android.intent.action.NEW_OUTGOING_CALL" /> diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml index e36b594ad..cc18830e4 100644 --- a/res/values-zh-rCN/strings.xml +++ b/res/values-zh-rCN/strings.xml @@ -205,4 +205,17 @@ <string name="call_log_show_all_slots">"所有卡"</string> <string name="call_log_all_calls_header">"所有通话"</string> <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> + </resources> diff --git a/res/values/strings.xml b/res/values/strings.xml index 0d9c0dc68..4c9cd5a61 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -813,4 +813,18 @@ <string name="call_log_show_all_slots">All SIMs</string> <string name="call_log_all_calls_header">All calls</string> <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> + </resources> diff --git a/src/com/android/dialer/SpeedDialListActivity.java b/src/com/android/dialer/SpeedDialListActivity.java new file mode 100644 index 000000000..83c9852ae --- /dev/null +++ b/src/com/android/dialer/SpeedDialListActivity.java @@ -0,0 +1,333 @@ +/* + * Copyright (C) 2013-2014, The Linux Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation, Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.android.dialer; + +import android.app.Activity; +import android.app.AlertDialog; +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.text.TextUtils; +import android.util.Log; +import android.view.ContextMenu; +import android.view.ContextMenu.ContextMenuInfo; +import android.view.MenuItem; +import android.view.View; +import android.view.View.OnCreateContextMenuListener; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.Toast; + +public class SpeedDialListActivity extends ListActivity + implements OnItemClickListener, OnCreateContextMenuListener { + + private static final String TAG = "SpeedDial"; + private static final String ACTION_ADD_VOICEMAIL + = "com.android.phone.CallFeaturesSetting.ADD_VOICEMAIL"; + + 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]; + + //speeddialutils class, use to read speed number form preference and update data + private static SpeedDialUtils mSpeedDialUtils; + + private static int mPosition; + + private static final int MENU_REPLACE = 0; + private static final int MENU_DELETE = 1; + + private static final int PICK_CONTACT_RESULT = 0; + + /** Called when the activity is first created. */ + @Override + 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)); + + // 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); + } + + ListView listview = getListView(); + listview.setOnItemClickListener(this); + listview.setOnCreateContextMenuListener(this); + } + + @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)); + } + + /* + * 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]); + } + } + mSpeedDialUtils.storeContactDataNumber(i - 1, mContactDataNumber[i - 1]); + mSpeedDialUtils.storeContactDataName(i - 1, mContactDataName[i - 1]); + mSpeedDialUtils.storeContactSimKey(i - 1, mContactSimKey[i - 1]); + } + } + + @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); + try { + startActivity(intent); + } catch(ActivityNotFoundException e) { + Log.w(TAG, "can not find activity deal with voice mail"); + } + } else if (position < SPEED_ITEMS) { + if ("".equals(mContactDataNumber[position - 1])) { + goContactsToPick(position); + } 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(); + } + } 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); + 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]); + } + } + super.onActivityResult(requestCode, resultCode, data); + } + + private boolean okToSet(String number) { + boolean isCheckOk = true; + for (String phoneNumber: mContactDataNumber) { + if (number.equals(phoneNumber)) { + isCheckOk = false; + break; + } + } + 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); + } + + @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.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; + } + return super.onContextItemSelected(item); + } + +} diff --git a/src/com/android/dialer/SpeedDialUtils.java b/src/com/android/dialer/SpeedDialUtils.java new file mode 100644 index 000000000..aacd0cbff --- /dev/null +++ b/src/com/android/dialer/SpeedDialUtils.java @@ -0,0 +1,291 @@ +/* + * Copyright (C) 2013-2014, The Linux Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +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 { + + 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; + } + 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(); + } + } + return mContactDataName; + } + + 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(); + } + } + return isSimAccount; + } + + public boolean isSimAccount(String accountType) { + return ACCOUNT_TYPE_SIM.equals(accountType); + } +} diff --git a/src/com/android/dialer/dialpad/DialpadFragment.java b/src/com/android/dialer/dialpad/DialpadFragment.java index 875880a2c..1f0b38143 100644 --- a/src/com/android/dialer/dialpad/DialpadFragment.java +++ b/src/com/android/dialer/dialpad/DialpadFragment.java @@ -77,6 +77,8 @@ import com.android.dialer.DialtactsActivity; import com.android.dialer.NeededForReflection; import com.android.dialer.R; import com.android.dialer.SpecialCharSequenceMgr; +import com.android.dialer.SpeedDialListActivity; +import com.android.dialer.SpeedDialUtils; import com.android.dialer.util.DialerUtils; import com.android.dialerbind.analytics.AnalyticsFragment; import com.android.internal.telephony.TelephonyProperties; @@ -592,6 +594,10 @@ public class DialpadFragment extends AnalyticsFragment for (int i = 0; i < buttonIds.length; i++) { dialpadKey = (DialpadKeyButton) fragmentView.findViewById(buttonIds[i]); dialpadKey.setOnPressedListener(this); + // Long-pressing button from two to nine will set up speed key dial. + if (i > 0 && i < buttonIds.length - 3) { + dialpadKey.setOnLongClickListener(this); + } } // Long-pressing one button will initiate Voicemail. @@ -1079,6 +1085,31 @@ public class DialpadFragment extends AnalyticsFragment mDigits.setCursorVisible(true); return false; } + case R.id.two: + case R.id.three: + case R.id.four: + case R.id.five: + case R.id.six: + case R.id.seven: + case R.id.eight: + case R.id.nine: { + if (mDigits.length() == 1) { + removePreviousDigitIfPossible(); + final boolean isAirplaneModeOn = + Settings.System.getInt(getActivity().getContentResolver(), + Settings.System.AIRPLANE_MODE_ON, 0) != 0; + if (isAirplaneModeOn) { + DialogFragment dialogFragment = ErrorDialogFragment.newInstance( + R.string.dialog_speed_dial_airplane_mode_message); + dialogFragment.show(getFragmentManager(), + "speed_dial_request_during_airplane_mode"); + } else { + callSpeedNumber(id); + } + return true; + } + return false; + } } return false; } @@ -1800,4 +1831,69 @@ public class DialpadFragment extends AnalyticsFragment public void setYFraction(float yFraction) { ((DialpadSlidingRelativeLayout) getView()).setYFraction(yFraction); } + + 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); + } else { + Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED); + intent.setData(Uri.fromParts("tel", speedNumber, null)); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(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() { + @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) + .show(); + } } |