Merge "Add usage of BottomSheetDialogFragment" into mnc-ub-dev

This commit is contained in:
Yuichi Araki
2015-12-16 02:14:12 +00:00
committed by Android (Google) Code Review
9 changed files with 173 additions and 3 deletions

View File

@@ -235,5 +235,14 @@
</intent-filter>
</activity>
<activity android:name=".widget.BottomSheetModal"
android:label="@string/design_bottomsheet_modal"
android:theme="@style/Theme.BottomSheetModal">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.support.design.SAMPLE_CODE" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -57,7 +57,7 @@
android:elevation="@dimen/bottom_sheet_elevation"
android:minHeight="@dimen/bottom_sheet_peek_height"
android:orientation="vertical"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
app:layout_behavior="@string/bottom_sheet_behavior"
app:behavior_peekHeight="@dimen/bottom_sheet_peek_height"
app:behavior_hideable="true">

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/bottomsheet_modal"
style="@style/TextAppearance.AppCompat.Headline"/>
<Button
android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/bottomsheet_show"/>
</LinearLayout>

View File

@@ -42,7 +42,7 @@
android:elevation="@dimen/bottom_sheet_elevation"
android:minHeight="@dimen/bottom_sheet_peek_height"
android:orientation="vertical"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
app:layout_behavior="@string/bottom_sheet_behavior"
app:behavior_peekHeight="@dimen/bottom_sheet_peek_height">
<include layout="@layout/include_bottom_sheet"/>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bottom_sheet_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:clipToPadding="false"
android:scrollbars="vertical"/>

View File

@@ -24,6 +24,7 @@
<string name="design_text_input">Text Input</string>
<string name="design_bottomsheet_persistent">BottomSheet/Persistent</string>
<string name="design_bottomsheet_hideable">BottomSheet/Hideable</string>
<string name="design_bottomsheet_modal">BottomSheet/Modal</string>
<string name="fab_size_normal">Normal size</string>
<string name="fab_size_mini">Mini size</string>
@@ -88,6 +89,7 @@
<string name="bottom_sheet">Bottom sheet</string>
<string name="bottomsheet_persistent">Persistent</string>
<string name="bottomsheet_hideable">Hideable</string>
<string name="bottomsheet_modal">Modal</string>
<string name="bottomsheet_hide">Hide</string>
<string name="bottomsheet_show">Show</string>

View File

@@ -45,4 +45,18 @@
<style name="Theme.Navigation" parent="Theme.Navigation.Base"/>
<style name="Theme.BottomSheetModal" parent="Theme.Design">
<item name="bottomSheetDialogTheme">@style/Theme.BottomSheetModal.BottomSheetDialog</item>
</style>
<style name="Theme.BottomSheetModal.BottomSheetDialog" parent="Theme.Design.BottomSheetDialog">
<item name="android:colorBackground">#37474F</item>
<item name="bottomSheetStyle">@style/BottomSheetStyle</item>
</style>
<style name="BottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="android:layout_marginLeft">@dimen/bottom_sheet_horizontal_margin</item>
<item name="android:layout_marginRight">@dimen/bottom_sheet_horizontal_margin</item>
</style>
</resources>

View File

@@ -0,0 +1,84 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.support.design.widget;
import com.example.android.support.design.Cheeses;
import com.example.android.support.design.R;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetDialogFragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* This demonstrates basic usage of {@link BottomSheetDialogFragment}.
*/
public class BottomSheetModal extends AppCompatActivity {
private static final String FRAGMENT_MODAL = "modal";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.design_bottom_sheet_modal);
findViewById(R.id.show).setOnClickListener(mOnClickListener);
}
private View.OnClickListener mOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.show:
new ModalFragment().show(getSupportFragmentManager(), FRAGMENT_MODAL);
break;
}
}
};
/**
* This is the bottom sheet.
*/
public static class ModalFragment extends BottomSheetDialogFragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.design_bottom_sheet_recyclerview, container, false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
// For the scrolling content, you can use RecyclerView, NestedScrollView or any other
// View that inherits NestedScrollingChild
RecyclerView recyclerView =
(RecyclerView) view.findViewById(R.id.bottom_sheet_recyclerview);
Context context = recyclerView.getContext();
recyclerView.setLayoutManager(new LinearLayoutManager(context));
recyclerView.setAdapter(new SimpleStringRecyclerViewAdapter(context,
Cheeses.sCheeseStrings));
}
}
}

View File

@@ -20,7 +20,6 @@ import com.example.android.support.design.R;
import com.example.android.support.design.Shakespeare;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetBehavior;
import android.support.v7.app.AppCompatActivity;