1 /* 2 * Copyright (C) 2018 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.car.settings.system; 18 19 import static android.app.Activity.RESULT_OK; 20 21 import android.content.Intent; 22 import android.os.Bundle; 23 24 import androidx.annotation.XmlRes; 25 26 import com.android.car.settings.R; 27 import com.android.car.settings.common.SettingsFragment; 28 import com.android.car.settings.security.CheckLockActivity; 29 import com.android.car.ui.toolbar.MenuItem; 30 31 import java.util.Collections; 32 import java.util.List; 33 34 /** 35 * Presents the user with information about restoring network settings to the factory default 36 * values. If a user confirms, they will first be required to authenticate then presented with a 37 * secondary confirmation: {@link ResetNetworkConfirmFragment}. 38 */ 39 public class ResetNetworkFragment extends SettingsFragment { 40 41 // Arbitrary request code for starting CheckLockActivity when the reset button is clicked. 42 private static final int REQUEST_CODE = 123; 43 44 private MenuItem mResetButton; 45 46 @Override 47 @XmlRes getPreferenceScreenResId()48 protected int getPreferenceScreenResId() { 49 return R.xml.reset_network_fragment; 50 } 51 52 @Override getToolbarMenuItems()53 public List<MenuItem> getToolbarMenuItems() { 54 return Collections.singletonList(mResetButton); 55 } 56 57 @Override onCreate(Bundle savedInstanceState)58 public void onCreate(Bundle savedInstanceState) { 59 super.onCreate(savedInstanceState); 60 61 mResetButton = new MenuItem.Builder(getContext()) 62 .setTitle(R.string.reset_network_button_text) 63 .setOnClickListener(i -> startActivityForResult( 64 new Intent(getContext(), CheckLockActivity.class), REQUEST_CODE)) 65 .build(); 66 } 67 68 @Override onActivityResult(int requestCode, int resultCode, Intent data)69 public void onActivityResult(int requestCode, int resultCode, Intent data) { 70 super.onActivityResult(requestCode, resultCode, data); 71 if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) { 72 launchFragment(new ResetNetworkConfirmFragment()); 73 } 74 } 75 } 76