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.appsettings; 17d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 18d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.app.AlertDialog; 19d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.Context; 20d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.view.LayoutInflater; 21d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.view.View; 22d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.view.View.OnClickListener; 23d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.widget.RadioButton; 24d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 25d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.R; 26d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.Assert; 27d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.BuglePrefs; 28d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 29d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/** 30d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Displays an on/off switch for group MMS setting for a given subscription. 31d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 32d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpublic class GroupMmsSettingDialog { 33d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private final Context mContext; 34d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private final int mSubId; 35d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private AlertDialog mDialog; 36d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 37d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd /** 38d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Shows a new group MMS setting dialog. 39d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 40d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static void showDialog(final Context context, final int subId) { 41d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd new GroupMmsSettingDialog(context, subId).show(); 42d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 43d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 44d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private GroupMmsSettingDialog(final Context context, final int subId) { 45d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mContext = context; 46d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mSubId = subId; 47d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 48d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 49d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private void show() { 50d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd Assert.isNull(mDialog); 51d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mDialog = new AlertDialog.Builder(mContext) 52d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .setView(createView()) 53d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .setTitle(R.string.group_mms_pref_title) 54d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .setNegativeButton(android.R.string.cancel, null) 55d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .show(); 56d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 57d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 58d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private void changeGroupMmsSettings(final boolean enable) { 59d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd Assert.notNull(mDialog); 60d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd BuglePrefs.getSubscriptionPrefs(mSubId).putBoolean( 61d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mContext.getString(R.string.group_mms_pref_key), enable); 62d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mDialog.dismiss(); 63d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 64d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 65d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private View createView() { 66d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final LayoutInflater inflater = (LayoutInflater) mContext 67d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 68d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final View rootView = inflater.inflate(R.layout.group_mms_setting_dialog, null, false); 69d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final RadioButton disableButton = (RadioButton) 70d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd rootView.findViewById(R.id.disable_group_mms_button); 71d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final RadioButton enableButton = (RadioButton) 72d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd rootView.findViewById(R.id.enable_group_mms_button); 73d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd disableButton.setOnClickListener(new OnClickListener() { 74d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 75d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void onClick(View view) { 76d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd changeGroupMmsSettings(false); 77d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 78d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd }); 79d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd enableButton.setOnClickListener(new OnClickListener() { 80d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 81d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void onClick(View view) { 82d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd changeGroupMmsSettings(true); 83d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 84d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd }); 85d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final boolean mmsEnabled = BuglePrefs.getSubscriptionPrefs(mSubId).getBoolean( 86d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mContext.getString(R.string.group_mms_pref_key), 87d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mContext.getResources().getBoolean(R.bool.group_mms_pref_default)); 88d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd enableButton.setChecked(mmsEnabled); 89d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd disableButton.setChecked(!mmsEnabled); 90d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return rootView; 91d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 92d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd} 93