Home | History | Annotate | Download | only in appsettings
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.messaging.ui.appsettings;
     17 
     18 import android.app.AlertDialog;
     19 import android.content.Context;
     20 import android.view.LayoutInflater;
     21 import android.view.View;
     22 import android.view.View.OnClickListener;
     23 import android.widget.RadioButton;
     24 
     25 import com.android.messaging.R;
     26 import com.android.messaging.util.Assert;
     27 import com.android.messaging.util.BuglePrefs;
     28 
     29 /**
     30  * Displays an on/off switch for group MMS setting for a given subscription.
     31  */
     32 public class GroupMmsSettingDialog {
     33     private final Context mContext;
     34     private final int mSubId;
     35     private AlertDialog mDialog;
     36 
     37     /**
     38      * Shows a new group MMS setting dialog.
     39      */
     40     public static void showDialog(final Context context, final int subId) {
     41         new GroupMmsSettingDialog(context, subId).show();
     42     }
     43 
     44     private GroupMmsSettingDialog(final Context context, final int subId) {
     45         mContext = context;
     46         mSubId = subId;
     47     }
     48 
     49     private void show() {
     50         Assert.isNull(mDialog);
     51         mDialog = new AlertDialog.Builder(mContext)
     52                 .setView(createView())
     53                 .setTitle(R.string.group_mms_pref_title)
     54                 .setNegativeButton(android.R.string.cancel, null)
     55                 .show();
     56     }
     57 
     58     private void changeGroupMmsSettings(final boolean enable) {
     59         Assert.notNull(mDialog);
     60         BuglePrefs.getSubscriptionPrefs(mSubId).putBoolean(
     61                 mContext.getString(R.string.group_mms_pref_key), enable);
     62         mDialog.dismiss();
     63     }
     64 
     65     private View createView() {
     66         final LayoutInflater inflater = (LayoutInflater) mContext
     67                 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     68         final View rootView = inflater.inflate(R.layout.group_mms_setting_dialog, null, false);
     69         final RadioButton disableButton = (RadioButton)
     70                 rootView.findViewById(R.id.disable_group_mms_button);
     71         final RadioButton enableButton = (RadioButton)
     72                 rootView.findViewById(R.id.enable_group_mms_button);
     73         disableButton.setOnClickListener(new OnClickListener() {
     74             @Override
     75             public void onClick(View view) {
     76                 changeGroupMmsSettings(false);
     77             }
     78         });
     79         enableButton.setOnClickListener(new OnClickListener() {
     80             @Override
     81             public void onClick(View view) {
     82                 changeGroupMmsSettings(true);
     83             }
     84         });
     85         final boolean mmsEnabled = BuglePrefs.getSubscriptionPrefs(mSubId).getBoolean(
     86                 mContext.getString(R.string.group_mms_pref_key),
     87                 mContext.getResources().getBoolean(R.bool.group_mms_pref_default));
     88         enableButton.setChecked(mmsEnabled);
     89         disableButton.setChecked(!mmsEnabled);
     90         return rootView;
     91     }
     92 }
     93