Home | History | Annotate | Download | only in common
      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.car.settings.common;
     18 
     19 import android.os.Bundle;
     20 
     21 import androidx.car.widget.DayNightStyle;
     22 import androidx.car.widget.PagedListView;
     23 
     24 import com.android.car.list.TypedPagedListAdapter;
     25 import com.android.car.settings.R;
     26 
     27 import java.util.ArrayList;
     28 
     29 /**
     30  * Settings page that only contain a list of items.
     31  */
     32 public abstract class ListSettingsFragment extends BaseFragment {
     33 
     34     protected PagedListView mListView;
     35     protected TypedPagedListAdapter mPagedListAdapter;
     36 
     37     protected static Bundle getBundle() {
     38         Bundle bundle = BaseFragment.getBundle();
     39         bundle.putInt(EXTRA_LAYOUT, R.layout.list_fragment);
     40         return bundle;
     41     }
     42 
     43     @Override
     44     public void onActivityCreated(Bundle savedInstanceState) {
     45         super.onActivityCreated(savedInstanceState);
     46 
     47         mListView = (PagedListView) getView().findViewById(R.id.list);
     48         mListView.setDayNightStyle(DayNightStyle.AUTO);
     49         mPagedListAdapter = new TypedPagedListAdapter(getLineItems());
     50         mListView.setAdapter(mPagedListAdapter);
     51     }
     52 
     53     /**
     54      * Gets a List of LineItems to show up in this activity.
     55      */
     56     public abstract ArrayList<TypedPagedListAdapter.LineItem> getLineItems();
     57 }
     58