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.settings.wifi.dpp; 18 19 import android.app.settings.SettingsEnums; 20 import android.content.Intent; 21 import android.os.Bundle; 22 import android.view.LayoutInflater; 23 import android.view.View; 24 import android.view.ViewGroup; 25 26 import androidx.fragment.app.FragmentManager; 27 import androidx.fragment.app.FragmentTransaction; 28 29 import com.android.settings.R; 30 31 /** 32 * After a camera APP scanned a Wi-Fi DPP QR code, it can trigger 33 * {@code WifiDppConfiguratorActivity} to start with this fragment to choose a saved Wi-Fi network. 34 */ 35 public class WifiDppChooseSavedWifiNetworkFragment extends WifiDppQrCodeBaseFragment { 36 private static final String TAG_FRAGMENT_WIFI_NETWORK_LIST = "wifi_network_list_fragment"; 37 38 @Override getMetricsCategory()39 public int getMetricsCategory() { 40 return SettingsEnums.SETTINGS_WIFI_DPP_CONFIGURATOR; 41 } 42 43 @Override onActivityCreated(Bundle savedInstanceState)44 public void onActivityCreated(Bundle savedInstanceState) { 45 super.onActivityCreated(savedInstanceState); 46 47 // Embedded WifiNetworkListFragment as child fragment within 48 // WifiDppChooseSavedWifiNetworkFragment. 49 final FragmentManager fragmentManager = getChildFragmentManager(); 50 final WifiNetworkListFragment fragment = new WifiNetworkListFragment(); 51 final Bundle args = getArguments(); 52 if (args != null) { 53 fragment.setArguments(args); 54 } 55 final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 56 fragmentTransaction.replace(R.id.wifi_network_list_container, fragment, 57 TAG_FRAGMENT_WIFI_NETWORK_LIST); 58 fragmentTransaction.commit(); 59 } 60 61 @Override onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)62 public final View onCreateView(LayoutInflater inflater, ViewGroup container, 63 Bundle savedInstanceState) { 64 return inflater.inflate(R.layout.wifi_dpp_choose_saved_wifi_network_fragment, container, 65 /* attachToRoot */ false); 66 } 67 68 @Override onViewCreated(View view, Bundle savedInstanceState)69 public void onViewCreated(View view, Bundle savedInstanceState) { 70 super.onViewCreated(view, savedInstanceState); 71 72 setHeaderTitle(R.string.wifi_dpp_choose_network); 73 mSummary.setText(R.string.wifi_dpp_choose_network_to_connect_device); 74 75 mLeftButton.setText(getContext(), R.string.cancel); 76 mLeftButton.setOnClickListener(v -> { 77 String action = null; 78 final Intent intent = getActivity().getIntent(); 79 if (intent != null) { 80 action = intent.getAction(); 81 } 82 if (WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_SCANNER.equals(action) || 83 WifiDppConfiguratorActivity 84 .ACTION_CONFIGURATOR_QR_CODE_GENERATOR.equals(action)) { 85 getFragmentManager().popBackStack(); 86 } else { 87 getActivity().finish(); 88 } 89 }); 90 91 mRightButton.setVisibility(View.GONE); 92 } 93 94 @Override isFooterAvailable()95 protected boolean isFooterAvailable() { 96 return true; 97 } 98 } 99