1 /* 2 * Copyright 2021 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 androidx.appsearch.debugview.view; 18 19 import android.os.Bundle; 20 import android.view.LayoutInflater; 21 import android.view.View; 22 import android.view.ViewGroup; 23 import android.widget.Button; 24 25 import androidx.annotation.RestrictTo; 26 import androidx.appsearch.debugview.R; 27 import androidx.fragment.app.Fragment; 28 29 import org.jspecify.annotations.NonNull; 30 import org.jspecify.annotations.Nullable; 31 32 /** 33 * A fragment for displaying page navigation shortcuts of the debug view. 34 * 35 * @exportToFramework:hide 36 */ 37 @RestrictTo(RestrictTo.Scope.LIBRARY) 38 public class MenuFragment extends Fragment { 39 40 @Override onCreateView(@onNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)41 public @Nullable View onCreateView(@NonNull LayoutInflater inflater, 42 @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 43 // Inflate the layout for this fragment 44 return inflater.inflate(R.layout.fragment_menu, container, /*attachToRoot=*/false); 45 } 46 47 @Override onViewCreated(@onNull View view, @Nullable Bundle savedInstanceState)48 public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { 49 super.onViewCreated(view, savedInstanceState); 50 51 Button documentListButton = getView().findViewById(R.id.view_documents_button); 52 documentListButton.setOnClickListener( 53 unusedView -> { 54 DocumentListFragment documentListFragment = new DocumentListFragment(); 55 navigateToFragment(documentListFragment); 56 }); 57 58 Button schemaTypeListButton = getView().findViewById(R.id.view_schema_types_button); 59 schemaTypeListButton.setOnClickListener( 60 unusedView -> { 61 SchemaTypeListFragment schemaTypeListFragment = new SchemaTypeListFragment(); 62 navigateToFragment(schemaTypeListFragment); 63 }); 64 } 65 navigateToFragment(Fragment fragment)66 private void navigateToFragment(Fragment fragment) { 67 getActivity().getSupportFragmentManager() 68 .beginTransaction() 69 .replace(R.id.fragment_container, fragment) 70 .addToBackStack(/*name=*/null) 71 .commit(); 72 } 73 } 74