1d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/* 2d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Copyright (C) 2015 The Android Open Source Project 3d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 4d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Licensed under the Apache License, Version 2.0 (the "License"); 5d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * you may not use this file except in compliance with the License. 6d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * You may obtain a copy of the License at 7d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 8d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * http://www.apache.org/licenses/LICENSE-2.0 9d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 10d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Unless required by applicable law or agreed to in writing, software 11d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * distributed under the License is distributed on an "AS IS" BASIS, 12d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * See the License for the specific language governing permissions and 14d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * limitations under the License. 15d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 16d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpackage com.android.messaging.ui.conversation; 17d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 18d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.app.AlertDialog; 19d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.app.Dialog; 20d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.app.DialogFragment; 21d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.Context; 22d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.DialogInterface; 23d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.os.Bundle; 24d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.text.TextUtils; 25d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.view.LayoutInflater; 26d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.widget.EditText; 27d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 28d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.R; 29d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.ParticipantRefresh; 30d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.BuglePrefs; 31d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.UiUtils; 32d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 33d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/** 34d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * The dialog for the user to enter the phone number of their sim. 35d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 36d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpublic class EnterSelfPhoneNumberDialog extends DialogFragment { 37d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private EditText mEditText; 38d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private int mSubId; 39d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 40d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static EnterSelfPhoneNumberDialog newInstance(final int subId) { 41d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final EnterSelfPhoneNumberDialog dialog = new EnterSelfPhoneNumberDialog(); 42d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dialog.mSubId = subId; 43d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return dialog; 44d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 45d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 46d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 47d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public Dialog onCreateDialog(final Bundle savedInstanceState) { 48d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final Context context = getActivity(); 49d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final LayoutInflater inflater = LayoutInflater.from(context); 50d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mEditText = (EditText) inflater.inflate(R.layout.enter_phone_number_view, null, false); 51d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 52d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final AlertDialog.Builder builder = new AlertDialog.Builder(context); 53d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd builder.setTitle(R.string.enter_phone_number_title) 54d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .setMessage(R.string.enter_phone_number_text) 55d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .setView(mEditText) 56d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .setNegativeButton(android.R.string.cancel, 57d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd new DialogInterface.OnClickListener() { 58d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 59d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void onClick(final DialogInterface dialog, 60d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final int button) { 61d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dismiss(); 62d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 63d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd }) 64d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .setPositiveButton(android.R.string.ok, 65d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd new DialogInterface.OnClickListener() { 66d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 67d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void onClick(final DialogInterface dialog, 68d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final int button) { 69d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final String newNumber = mEditText.getText().toString(); 70d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dismiss(); 71d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (!TextUtils.isEmpty(newNumber)) { 72d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd savePhoneNumberInPrefs(newNumber); 73d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // TODO: Remove this toast and just auto-send 74d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // the message instead 75d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd UiUtils.showToast( 76d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd R.string 77d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .toast_after_setting_default_sms_app_for_message_send); 78d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 79d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 80d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd }); 81d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return builder.create(); 82d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 83d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 84d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private void savePhoneNumberInPrefs(final String newPhoneNumber) { 85d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final BuglePrefs subPrefs = BuglePrefs.getSubscriptionPrefs(mSubId); 86d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd subPrefs.putString(getString(R.string.mms_phone_number_pref_key), 87d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd newPhoneNumber); 88d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // Update the self participants so the new phone number will be reflected 89d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // everywhere in the UI. 90d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantRefresh.refreshSelfParticipants(); 91d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 92d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd} 93