Skip to content

Commit

Permalink
add bottom sheet layout
Browse files Browse the repository at this point in the history
  • Loading branch information
bowyer-app committed Aug 6, 2015
1 parent 317ebf6 commit 00f3a63
Show file tree
Hide file tree
Showing 28 changed files with 332 additions and 30 deletions.
12 changes: 6 additions & 6 deletions demo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
compileSdkVersion COMPILE_SDK_VERSION as int
buildToolsVersion BUILD_TOOLS_VERSION

defaultConfig {
applicationId "com.bowyer.fabtransitionlayout.demo"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
minSdkVersion MIN_SDK_VERSION
targetSdkVersion TARGET_SDK_VERSION as int
versionCode VERSION_CODE as int
versionName VERSION_NAME
}
buildTypes {
release {
Expand Down
19 changes: 10 additions & 9 deletions demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bowyer.fabtransitionlayout.demo" >
package="com.bowyer.fabtransitionlayout.demo">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".BottomSheetDemoActivity"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.bowyer.fabtransitionlayout.demo;

import com.bowyer.app.fabtransitionlayout.BottomSheetLayout;
import com.bowyer.fabtransitionlayout.demo.adapter.BottomSheetAdapter;
import com.bowyer.fabtransitionlayout.demo.model.BottomSheet;
import com.github.ksoichiro.android.observablescrollview.ObservableListView;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.ActionBarActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
* Created by Bowyer on 15/08/07.
*/
public class BottomSheetDemoActivity extends ActionBarActivity {

@InjectView(R.id.list_view)
ObservableListView mObservableListView;

@InjectView(R.id.bottom_sheet)
BottomSheetLayout mBottomSheetLayout;

@InjectView(R.id.list_menu)
ListView mMenuList;

@InjectView(R.id.fab)
FloatingActionButton mFab;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bottom_sheet);
ButterKnife.inject(this);
initListView();
initListMenu();
mBottomSheetLayout.setFab(mFab);
}

private void initListView() {
List<String> list = new ArrayList<String>(100);
for (int i = 0; i < 100; i++) {
list.add("Item " + i);
}

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, list);
mObservableListView.setAdapter(adapter);
}

private void initListMenu() {
ArrayList<BottomSheet> bottomSheets = new ArrayList<>();
bottomSheets.add(
BottomSheet.to().setBottomSheetMenuType(BottomSheet.BottomSheetMenuType.EMAIL));
bottomSheets.add(
BottomSheet.to().setBottomSheetMenuType(BottomSheet.BottomSheetMenuType.ACCOUNT));
bottomSheets.add(
BottomSheet.to().setBottomSheetMenuType(BottomSheet.BottomSheetMenuType.SETTING));
BottomSheetAdapter adapter = new BottomSheetAdapter(this, bottomSheets);
mMenuList.setAdapter(adapter);

}

@OnClick(R.id.fab)
void onFabClick() {
mBottomSheetLayout.expandFab();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import com.bowyer.app.fabtransitionlayout.BottomSheetLayout;
import com.bowyer.app.fabtransitionlayout.FooterLayout;
import com.bowyer.fabtransitionlayout.demo.adapter.BottomSheetAdapter;
import com.bowyer.fabtransitionlayout.demo.model.BottomSheet;
import com.github.ksoichiro.android.observablescrollview.ObservableListView;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks;
import com.github.ksoichiro.android.observablescrollview.ScrollState;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.ActionBarActivity;
Expand All @@ -29,22 +32,28 @@ public class MainActivity extends ActionBarActivity implements ObservableScrollV

@InjectView(R.id.list_view)
ObservableListView mObservableListView;

@InjectView(R.id.fabtoolbar)
FooterLayout mFabToolbar;

@InjectView(R.id.fablist)
BottomSheetLayout mFooterLayout;

@InjectView(R.id.list_menu)
ListView mListView;

@InjectView(R.id.fab)
FloatingActionButton mFab;

@InjectView(R.id.fab_left)
FloatingActionButton mFabLeft;

@InjectView(R.id.ic_call)
ImageView mIcCall;

@InjectView(R.id.ic_email)
ImageView mIcEmail;

@InjectView(R.id.ic_forum)
ImageView mIcForum;

Expand All @@ -59,16 +68,24 @@ protected void onCreate(Bundle savedInstanceState) {
mFooterLayout.setFab(mFabLeft);
}

private void initListMenu(){
List<String> menu = new ArrayList<>();
menu.add("Share");
menu.add("Upload");
menu.add("Fav");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, menu);
private void callBottomSheetActivity() {
Intent intet = new Intent(this, BottomSheetDemoActivity.class);
startActivity(intet);
}

private void initListMenu() {
ArrayList<BottomSheet> bottomSheets = new ArrayList<>();
bottomSheets.add(
BottomSheet.to().setBottomSheetMenuType(BottomSheet.BottomSheetMenuType.EMAIL));
bottomSheets.add(
BottomSheet.to().setBottomSheetMenuType(BottomSheet.BottomSheetMenuType.ACCOUNT));
bottomSheets.add(
BottomSheet.to().setBottomSheetMenuType(BottomSheet.BottomSheetMenuType.SETTING));
BottomSheetAdapter adapter = new BottomSheetAdapter(this, bottomSheets);
mListView.setAdapter(adapter);

}

private void initListView() {
List<String> list = new ArrayList<String>(100);
for (int i = 0; i < 100; i++) {
Expand Down Expand Up @@ -108,8 +125,9 @@ void onFabClick() {
}

@OnClick(R.id.fab_left)
void onFabLeftClick(){
mFooterLayout.expandFab();
void onFabLeftClick() {
callBottomSheetActivity();
// mFooterLayout.expandFab();
}

@OnClick(R.id.call)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.bowyer.fabtransitionlayout.demo.adapter;

import com.bowyer.fabtransitionlayout.demo.R;
import com.bowyer.fabtransitionlayout.demo.model.BottomSheet;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
* Created by Bowyer on 15/08/06.
*/
public class BottomSheetAdapter extends BaseAdapter {

Context mContext;

LayoutInflater mLayoutInflater = null;

ArrayList<BottomSheet> mBottomSheets;

public BottomSheetAdapter(Context context, ArrayList<BottomSheet> bottomSheets) {
mContext = context;
mBottomSheets = bottomSheets;
mLayoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getCount() {
return mBottomSheets.size();
}

@Override
public Object getItem(int position) {
return mBottomSheets.get(position);
}

@Override
public long getItemId(int position) {
return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = mLayoutInflater.inflate(R.layout.row_item_bottom_sheet, parent, false);
viewHolder = new ViewHolder(convertView);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}

BottomSheet sheet = (BottomSheet) getItem(position);
viewHolder.mMenuIcon
.setBackground(mContext.getDrawable(sheet.getBottomSheetMenuType().getResId()));
viewHolder.mMenuTitle.setText(sheet.getBottomSheetMenuType().getName());
return convertView;
}

static class ViewHolder {

@InjectView(R.id.menu_icon)
ImageView mMenuIcon;

@InjectView(R.id.menu_title)
TextView mMenuTitle;

public ViewHolder(View view) {
ButterKnife.inject(this, view);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.bowyer.fabtransitionlayout.demo.model;

import com.bowyer.fabtransitionlayout.demo.R;

/**
* Created by Bowyer on 15/08/06.
*/
public class BottomSheet {


public enum BottomSheetMenuType {
EMAIL(R.drawable.ic_drafts_white_24dp, "Mail"), ACCOUNT(
R.drawable.ic_account_circle_white_24dp, "Acount"), SETTING(R.drawable.ic_build_white_24dp,
"Setitng");

int resId;

String name;

BottomSheetMenuType(int resId, String name) {
this.resId = resId;
this.name = name;
}


public int getResId() {
return resId;
}

public String getName() {
return name;
}
}

BottomSheetMenuType bottomSheetMenuType;

public static BottomSheet to() {
return new BottomSheet();
}

public BottomSheetMenuType getBottomSheetMenuType() {
return bottomSheetMenuType;
}

public BottomSheet setBottomSheetMenuType(BottomSheetMenuType bottomSheetMenuType) {
this.bottomSheetMenuType = bottomSheetMenuType;
return this;
}

}
Binary file removed demo/src/main/res/drawable-hdpi/ic_add_white_24dp.png
Binary file not shown.
Binary file removed demo/src/main/res/drawable-hdpi/ic_call_white_36dp.png
Binary file not shown.
Binary file removed demo/src/main/res/drawable-hdpi/ic_email_white_36dp.png
Binary file not shown.
Binary file removed demo/src/main/res/drawable-hdpi/ic_forum_white_36dp.png
Binary file not shown.
Binary file removed demo/src/main/res/drawable-mdpi/ic_add_white_24dp.png
Binary file not shown.
Binary file removed demo/src/main/res/drawable-mdpi/ic_call_white_36dp.png
Binary file not shown.
Binary file removed demo/src/main/res/drawable-mdpi/ic_email_white_36dp.png
Binary file not shown.
Binary file removed demo/src/main/res/drawable-mdpi/ic_forum_white_36dp.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions demo/src/main/res/layout/activity_bottom_sheet.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<com.github.ksoichiro.android.observablescrollview.ObservableListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="32dp"
android:layout_marginRight="32dp"
android:src="@drawable/ic_add_white_24dp"
app:borderWidth="0dp"
app:fabSize="normal"
app:rippleColor="@color/primary"
/>

<com.bowyer.app.fabtransitionlayout.BottomSheetLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
app:ft_container_gravity="end"
app:ft_color="@color/primary">

<ListView
android:id="@+id/list_menu"
android:background="@color/primary"
android:divider="@null"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.bowyer.app.fabtransitionlayout.BottomSheetLayout>

</FrameLayout>
Loading

0 comments on commit 00f3a63

Please sign in to comment.