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

Commit ff7b2aa4 authored by Daisuke Miyakawa's avatar Daisuke Miyakawa Committed by Android Git Automerger
Browse files

am f4bd01a7: Merge "Enable Dialpad screen to prohibit some certain numbers" into ics-factoryrom

* commit 'f4bd01a7':
  Enable Dialpad screen to prohibit some certain numbers
parents a370b2d6 f4bd01a7
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -120,4 +120,8 @@
    <!-- Height of the tab carousel as a percentage of the current screen width on the
         contact detail page -->
    <item name="tab_height_screen_width_percentage" type="fraction">50%</item>

    <!-- Regular expression for prohibiting certain phone numbers in dialpad.
         Ignored if empty. -->
    <string name="config_prohibited_phone_number_regexp"></string>
</resources>
+4 −0
Original line number Diff line number Diff line
@@ -1817,4 +1817,8 @@

    <!-- Button label to prompt the user to add another account (when there are already existing accounts on the device) [CHAR LIMIT=30] -->
    <string name="add_new_account">Add new account</string>

    <!-- Dialog message which is shown when the user tries to make a phone call
         to prohibited phone numbers [CHAR LIMIT=NONE] -->
    <string name="phone_call_prohibited" msgid="4313552620858880999">Call not sent.</string>
</resources>
+54 −6
Original line number Diff line number Diff line
@@ -27,8 +27,12 @@ import com.android.phone.CallLogAsync;
import com.android.phone.HapticFeedback;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
@@ -37,7 +41,6 @@ import android.graphics.BitmapFactory;
import android.media.AudioManager;
import android.media.ToneGenerator;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -46,7 +49,6 @@ import android.provider.Contacts.People;
import android.provider.Contacts.Phones;
import android.provider.Contacts.PhonesColumns;
import android.provider.Settings;
import android.telephony.PhoneNumberFormattingTextWatcher;
import android.telephony.PhoneNumberUtils;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
@@ -61,16 +63,21 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.TextView;

import java.util.HashSet;
import java.util.Set;

/**
 * Fragment that displays a twelve-key phone dialpad.
 */
@@ -117,6 +124,11 @@ public class DialpadFragment extends Fragment
    private ListView mDialpadChooser;
    private DialpadChooserAdapter mDialpadChooserAdapter;

    /**
     * Regular expression prohibiting manual phone call. Can be empty, which means "no rule".
     */
    private String mProhibitedPhoneNumberRegexp;

    private boolean mShowOptionsMenu;

    private boolean mHasVoicemail = false;
@@ -219,6 +231,9 @@ public class DialpadFragment extends Fragment
        }

        setHasOptionsMenu(true);

        mProhibitedPhoneNumberRegexp = getResources().getString(
                R.string.config_prohibited_phone_number_regexp);
    }

    @Override
@@ -794,6 +809,26 @@ public class DialpadFragment extends Fragment
        getActivity().finish();
    }

    public static class CallProhibitedDialogFragment extends DialogFragment {
        public static CallProhibitedDialogFragment newInstance() {
            return new CallProhibitedDialogFragment();
        }

        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            return new AlertDialog.Builder(getActivity())
                    .setTitle(R.string.phone_call_prohibited)
                    .setPositiveButton(android.R.string.ok,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dismiss();
                                }
                            })
                    .create();
        }
    }

    /**
     * In most cases, when the dial button is pressed, there is a
     * number in digits area. Pack it in the intent, start the
@@ -847,11 +882,24 @@ public class DialpadFragment extends Fragment
        } else {
            final String number = mDigits.getText().toString();

            if (number != null
                    && !TextUtils.isEmpty(mProhibitedPhoneNumberRegexp)
                    && number.matches(mProhibitedPhoneNumberRegexp)) {
                Log.i(TAG, "The phone number is prohibited explicitly by a rule.");
                if (getActivity() != null) {
                    DialogFragment dialogFragment = CallProhibitedDialogFragment.newInstance();
                    dialogFragment.show(getFragmentManager(), "phone_prohibited_dialog");
                }

                // Clear the digits just in case.
                mDigits.getText().clear();
            } else {
                startActivity(newDialNumberIntent(number));
                mDigits.getText().clear();  // TODO: Fix bug 1745781
                getActivity().finish();
            }
        }
    }

    /**
     * Plays the specified tone for TONE_LENGTH_MS milliseconds.