Home | History | Annotate | Download | only in network
      1 /*
      2  * Copyright (C) 2017 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.network;
     18 
     19 import android.content.Context;
     20 import android.view.Menu;
     21 import android.view.MenuItem;
     22 
     23 import com.android.internal.logging.nano.MetricsProto;
     24 import com.android.settings.R;
     25 import com.android.settings.ResetNetwork;
     26 import com.android.settings.Utils;
     27 
     28 public class NetworkResetActionMenuController {
     29 
     30     private static final int MENU_NETWORK_RESET = Menu.FIRST + 200;
     31     private final Context mContext;
     32     private final NetworkResetRestrictionChecker mRestrictionChecker;
     33 
     34     public NetworkResetActionMenuController(Context context) {
     35         mContext = context;
     36         mRestrictionChecker = new NetworkResetRestrictionChecker(context);
     37     }
     38 
     39     public void buildMenuItem(Menu menu) {
     40         MenuItem item = null;
     41         if (isAvailable() && menu != null) {
     42             item = menu.add(0, MENU_NETWORK_RESET, 0, R.string.reset_network_title);
     43         }
     44         if (item != null) {
     45             item.setOnMenuItemClickListener(target -> {
     46                 Utils.startWithFragment(mContext, ResetNetwork.class.getName(), null, null,
     47                         0, R.string.reset_network_title, null,
     48                         MetricsProto.MetricsEvent.SETTINGS_NETWORK_CATEGORY);
     49                 return true;
     50             });
     51         }
     52     }
     53 
     54 
     55     boolean isAvailable() {
     56         return !mRestrictionChecker.hasRestriction();
     57     }
     58 }
     59