• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 
17 package com.android.settings.sim;
18 
19 import android.content.Context;
20 import android.content.DialogInterface;
21 import android.os.Bundle;
22 
23 import androidx.annotation.NonNull;
24 
25 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
26 import com.android.settings.network.SubscriptionsChangeListener;
27 
28 /** Common functionality for showing a dialog in SimDialogActivity. */
29 public abstract class SimDialogFragment extends InstrumentedDialogFragment implements
30         SubscriptionsChangeListener.SubscriptionsChangeListenerClient {
31     private static final String TAG = "SimDialogFragment";
32 
33     private static final String KEY_TITLE_ID = "title_id";
34     private static final String KEY_DIALOG_TYPE = "dialog_type";
35 
36     private SubscriptionsChangeListener mChangeListener;
37 
initArguments(int dialogType, int titleResId)38     protected static Bundle initArguments(int dialogType, int titleResId) {
39         final Bundle args = new Bundle();
40         args.putInt(KEY_DIALOG_TYPE, dialogType);
41         args.putInt(KEY_TITLE_ID, titleResId);
42         return args;
43     }
44 
getDialogType()45     public int getDialogType() {
46         return getArguments().getInt(KEY_DIALOG_TYPE);
47     }
48 
getTitleResId()49     public int getTitleResId() {
50         return getArguments().getInt(KEY_TITLE_ID);
51     }
52 
53     @Override
onAttach(Context context)54     public void onAttach(Context context) {
55         super.onAttach(context);
56         mChangeListener = new SubscriptionsChangeListener(context, this);
57     }
58 
59     @Override
onPause()60     public void onPause() {
61         super.onPause();
62         mChangeListener.stop();
63     }
64 
65     @Override
onResume()66     public void onResume() {
67         super.onResume();
68         mChangeListener.start();
69     }
70 
71     @Override
onDismiss(@onNull DialogInterface dialog)72     public void onDismiss(@NonNull DialogInterface dialog) {
73         super.onDismiss(dialog);
74         final SimDialogActivity activity = (SimDialogActivity) getActivity();
75         if (activity != null && !activity.isFinishing()) {
76             activity.onFragmentDismissed(this);
77         }
78     }
79 
updateDialog()80     public abstract void updateDialog();
81 
82     @Override
onAirplaneModeChanged(boolean airplaneModeEnabled)83     public void onAirplaneModeChanged(boolean airplaneModeEnabled) {
84     }
85 
86     @Override
onSubscriptionsChanged()87     public void onSubscriptionsChanged() {
88         updateDialog();
89     }
90 }
91