Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6c7ed446 authored by m0viefreak's avatar m0viefreak Committed by Danny Baumann
Browse files

Dialpad : T9 add to contact if no match found

Cherry-picked http://review.cyanogenmod.com/11212 for gingerbread.

Also included fix from http://review.cyanogenmod.com/11386

Change-Id: Idd91c732b14c35227bc89ea7c68eb249d921b80d
parent 99441450
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -18,11 +18,13 @@
		<TextView
			android:id="@+id/rowName"
			android:layout_weight="0.5"
			android:gravity="center_vertical"
			android:layout_width="match_parent"
			android:layout_height="match_parent" />
		<TextView
			android:id="@+id/rowNumber"
			android:layout_weight="0.5"
			android:gravity="center_vertical"
			android:layout_width="match_parent"
			android:layout_height="match_parent" />
	</LinearLayout>
+1 −0
Original line number Diff line number Diff line
@@ -520,6 +520,7 @@
    <string name="t9_state_summary">Aktiviert T9-artiges Suchen mit der Telefontastatur</string>
    <string name="t9_dial_click_title">Gewählten Kontakt anrufen</string>
    <string name="t9_dial_click_summary">Ausgewählten Kontakt bei T9-Suche anrufen</string>
    <string name="t9_add_to_contacts">Zu Kontakten hinzufügen</string>

    <string name="search_results_searching">Suche läuft\u2026</string>
</resources>
+1 −0
Original line number Diff line number Diff line
@@ -1306,6 +1306,7 @@
    <string name="t9_state_summary">Enable T9 searching in dialer</string>
    <string name="t9_dial_click_title">Dial selected contact</string>
    <string name="t9_dial_click_summary">Dial the selected contact for T9</string>
    <string name="t9_add_to_contacts">Add to contacts</string>
    <string name="t9_map_row_2">2abcàáâäåɑæçǽćčá</string>
    <string name="t9_map_row_3">3deféèêë</string>
    <string name="t9_map_row_4">4ghiíìïîǵ</string>
+28 −21
Original line number Diff line number Diff line
@@ -312,9 +312,15 @@ class T9Search {
            }

            ContactItem o = mItems.get(position);

            if (o.name == null) {
                holder.name.setText(mContext.getResources().getString(R.string.t9_add_to_contacts));
                holder.number.setVisibility(View.GONE);
                holder.icon.setImageResource(R.drawable.sym_action_add);
                holder.icon.assignContactFromPhone(o.number, true);
            } else {
                holder.name.setText(o.name, TextView.BufferType.SPANNABLE);
                holder.number.setText(o.normalNumber + " (" + o.groupType + ")", TextView.BufferType.SPANNABLE);
                holder.number.setVisibility(View.VISIBLE);
                if (o.nameMatchId != -1) {
                    Spannable s = (Spannable) holder.name.getText();
                    int nameStart = o.normalName.indexOf(mPrevInput);
@@ -335,6 +341,7 @@ class T9Search {
                    holder.icon.setImageResource(R.drawable.ic_contact_list_picture);

                holder.icon.assignContactFromPhone(o.number, true);
            }
            return convertView;
        }

+27 −20
Original line number Diff line number Diff line
@@ -53,11 +53,9 @@ import android.telephony.PhoneNumberUtils;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.text.Editable;
import android.text.Spannable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.DialerKeyListener;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -79,7 +77,6 @@ import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.QuickContactBadge;
import android.widget.TextView;
import android.widget.ToggleButton;
import android.widget.ViewSwitcher;
@@ -271,6 +268,7 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
        mT9ListTop = (ListView) findViewById(R.id.t9listtop);
        if (mT9ListTop != null) {
            mT9ListTop.setOnItemClickListener(this);
            mT9ListTop.setTag(new ContactItem());
        }
        mT9Toggle = (ToggleButton) findViewById(R.id.t9toggle);
        if (mT9Toggle != null) {
@@ -583,7 +581,6 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
        updateDialer();
    }


    /**
     * Hides the topresult layout
     * Needed to reclaim the space when T9 is off.
@@ -619,6 +616,12 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
        if (length > 0) {
            if (sT9Search != null) {
                T9SearchResult result = sT9Search.search(mDigits.getText().toString());
                if (mT9AdapterTop == null) {
                    mT9AdapterTop = sT9Search.new T9Adapter(this, 0, new ArrayList<ContactItem>(),getLayoutInflater());
                    mT9AdapterTop.setNotifyOnChange(true);
                } else {
                    mT9AdapterTop.clear();
                }
                if (result != null) {
                    if (mT9Adapter == null) {
                        mT9Adapter = sT9Search.new T9Adapter(this, 0, result.getResults(),getLayoutInflater());
@@ -633,28 +636,26 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
                        mT9List.setAdapter(mT9Adapter);
                    }

                    if (mT9AdapterTop == null) {
                        mT9AdapterTop = sT9Search.new T9Adapter(this, 0, new ArrayList<ContactItem>(),getLayoutInflater());
                        mT9AdapterTop.setNotifyOnChange(true);
                    } else {
                        mT9AdapterTop.clear();
                    }
                    mT9AdapterTop.add(result.getTopContact());
                    if (mT9ListTop.getAdapter() == null) {
                        mT9ListTop.setAdapter(mT9AdapterTop);
                    }

                    mT9ListTop.setVisibility(View.VISIBLE);
                    if (result.getNumResults()>  1) {
                        mT9Toggle.setVisibility(View.VISIBLE);
                    } else {
                        mT9Toggle.setVisibility(View.GONE);
                        toggleT9();
                    }
                    mT9Toggle.setTag(null);
                } else {
                    mT9ListTop.setVisibility(View.INVISIBLE);
                    mT9Toggle.setVisibility(View.INVISIBLE);
                    ContactItem contact = (ContactItem) mT9ListTop.getTag();
                    contact.number = mDigits.getText().toString();
                    mT9AdapterTop.add(contact);
                    mT9Toggle.setTag(new Boolean(true));
                    mT9Toggle.setVisibility(View.GONE);
                    toggleT9();
                }
                mT9ListTop.setVisibility(View.VISIBLE);
                if (mT9ListTop.getAdapter() == null) {
                    mT9ListTop.setAdapter(mT9AdapterTop);
                }
            }
        } else {
            mT9ListTop.setVisibility(View.INVISIBLE);
@@ -1359,10 +1360,16 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
     */
    public void onItemClick(AdapterView parent, View v, int position, long id) {
        if (parent == mT9List || parent == mT9ListTop) {
            if (parent == mT9List)
            if (parent == mT9List) {
                mDigits.setText(mT9Adapter.getItem(position).number);
            else
            } else {
                if (mT9Toggle.getTag() == null) {
                    mDigits.setText(mT9AdapterTop.getItem(position).number);
                } else {
                    addToContacts();
                    return;
                }
            }
            mDigits.setSelection(mDigits.length());
            if (dialOnTap()) {
                dialButtonPressed();