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