1/* 2 * Copyright (C) 2015 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 17package com.example.android.supportv7.widget; 18 19import androidx.recyclerview.widget.StaggeredGridLayoutManager; 20 21import com.example.android.supportv7.R; 22import com.example.android.supportv7.widget.util.ConfigToggle; 23 24public class StaggeredGridLayoutManagerActivity 25 extends BaseLayoutManagerActivity<StaggeredGridLayoutManager> { 26 27 private boolean mVertical = true; 28 29 @Override 30 protected StaggeredGridLayoutManager createLayoutManager() { 31 if (mVertical) { 32 return new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL); 33 } else { 34 return new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.HORIZONTAL); 35 } 36 } 37 38 @Override 39 protected ConfigToggle[] createConfigToggles() { 40 return new ConfigToggle[] { 41 new ConfigToggle(this, R.string.vertical) { 42 @Override 43 public boolean isChecked() { 44 return mVertical; 45 } 46 47 @Override 48 public void onChange(boolean newValue) { 49 if (mVertical == newValue) { 50 return; 51 } 52 mVertical = newValue; 53 mRecyclerView.setLayoutManager(createLayoutManager()); 54 } 55 } 56 }; 57 } 58} 59