Skip to content

Commit

Permalink
Update TabsControllableDemoFragment to support small screen, landscap…
Browse files Browse the repository at this point in the history
…e and edge to edge with transparent status and navigation bars on Q.

PiperOrigin-RevId: 264210502
  • Loading branch information
leticiarossi authored and cketcham committed Aug 20, 2019
1 parent adcfec5 commit ba3d790
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.core.view.ViewCompat;
import androidx.appcompat.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -34,6 +35,7 @@
import android.widget.ArrayAdapter;
import android.widget.RadioButton;
import android.widget.Spinner;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.badge.BadgeDrawable;
import com.google.android.material.tabs.TabLayout;
Expand Down Expand Up @@ -71,6 +73,19 @@ public View onCreateDemoView(
tabLayouts = DemoUtils.findViewsWithType(view, TabLayout.class);
pager = view.findViewById(R.id.viewpager);

CoordinatorLayout coordinatorLayout = view.findViewById(R.id.coordinator_layout);
ViewCompat.setOnApplyWindowInsetsListener(
view,
(v, insetsCompat) -> {
View scrollable = coordinatorLayout.findViewById(R.id.cat_tabs_controllable_scrollview);
scrollable.setPadding(
scrollable.getPaddingLeft(),
0,
scrollable.getPaddingRight(),
scrollable.getPaddingBottom());
return insetsCompat;
});

setupViewPager();
setAllTabLayoutIcons(ICON_DRAWABLE_RES);
setAllTabLayoutText(LABEL_STRING_RES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,114 +15,126 @@
limitations under the License.
-->

<FrameLayout
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<LinearLayout
android:id="@+id/content"
<ScrollView
android:id="@+id/cat_tabs_controllable_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
android:layout_height="match_parent">

<androidx.viewpager.widget.ViewPager
android:id="@+id/viewpager"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</LinearLayout>

<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:padding="@dimen/cat_tabs_standard_spacing"
android:columnCount="2">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:labelFor="@+id/toggle_icons_switch"
android:text="@string/cat_tabs_icon_switch_label"/>
android:orientation="vertical">

<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@id/toggle_icons_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
app:showText="false"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:labelFor="@+id/toggle_labels_switch"
android:text="@string/cat_tabs_labels_switch_label"/>
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|center_horizontal"
android:orientation="vertical">

<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@id/toggle_labels_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
app:showText="false"/>
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="100dp"/>
</LinearLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:text="@string/cat_tabs_gravity_selector_label"/>

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkedButton="@+id/tabs_gravity_fill_button"
android:orientation="horizontal">
<RadioButton
android:id="@+id/tabs_gravity_fill_button"
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/cat_tabs_small_spacing"
android:layout_marginEnd="@dimen/cat_tabs_small_spacing"
android:text="@string/cat_tabs_gravity_fill"/>
<RadioButton
android:id="@+id/tabs_gravity_center_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/cat_tabs_small_spacing"
android:layout_marginEnd="@dimen/cat_tabs_small_spacing"
android:text="@string/cat_tabs_gravity_center"/>
</RadioGroup>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:labelFor="@+id/toggle_inline_switch"
android:text="@string/cat_tabs_inline_switch_label"/>

<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@id/toggle_inline_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
app:showText="false"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:labelFor="@+id/selector_spinner"
android:text="@string/cat_tabs_indicator_spinner_label"/>

<Spinner
android:id="@id/selector_spinner"
android:layout_width="wrap_content"
android:layout_height="48dp"/>

</GridLayout>

</FrameLayout>
android:layout_gravity="bottom|center_horizontal"
android:padding="@dimen/cat_tabs_standard_spacing"
android:columnCount="2">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:labelFor="@+id/toggle_icons_switch"
android:text="@string/cat_tabs_icon_switch_label"/>

<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@id/toggle_icons_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
app:showText="false"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:labelFor="@+id/toggle_labels_switch"
android:text="@string/cat_tabs_labels_switch_label"/>

<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@id/toggle_labels_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
app:showText="false"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:text="@string/cat_tabs_gravity_selector_label"/>

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkedButton="@+id/tabs_gravity_fill_button"
android:orientation="horizontal">
<RadioButton
android:id="@+id/tabs_gravity_fill_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/cat_tabs_small_spacing"
android:layout_marginEnd="@dimen/cat_tabs_small_spacing"
android:text="@string/cat_tabs_gravity_fill"/>
<RadioButton
android:id="@+id/tabs_gravity_center_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/cat_tabs_small_spacing"
android:layout_marginEnd="@dimen/cat_tabs_small_spacing"
android:text="@string/cat_tabs_gravity_center"/>
</RadioGroup>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:labelFor="@+id/toggle_inline_switch"
android:text="@string/cat_tabs_inline_switch_label"/>

<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@id/toggle_inline_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
app:showText="false"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:labelFor="@+id/selector_spinner"
android:text="@string/cat_tabs_indicator_spinner_label"/>

<Spinner
android:id="@id/selector_spinner"
android:layout_width="wrap_content"
android:layout_height="48dp"/>

</GridLayout>
</LinearLayout>
</ScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

0 comments on commit ba3d790

Please sign in to comment.