diff --git a/example/src/main/java/com/cocosw/bottomsheet/example/ListAcitivty.java b/example/src/main/java/com/cocosw/bottomsheet/example/ListAcitivty.java index 484f1ee..f828a75 100644 --- a/example/src/main/java/com/cocosw/bottomsheet/example/ListAcitivty.java +++ b/example/src/main/java/com/cocosw/bottomsheet/example/ListAcitivty.java @@ -84,53 +84,22 @@ private Drawable getRoundedBitmap(int imageId) { protected Dialog onCreateDialog(final int position, Bundle args) { switch (action) { case 0: - sheet = new BottomSheet.Builder(this).icon(getRoundedBitmap(R.drawable.icon)).title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ListAcitivty.this.onClick(adapter.getItem(position), which); - } - }).build(); + casePositionZero(position); break; case 1: - sheet = new BottomSheet.Builder(this).sheet(R.menu.noicon).listener(new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ListAcitivty.this.onClick(adapter.getItem(position), which); - } - }).build(); + casePositionOne(position); break; - case 2: - sheet = new BottomSheet.Builder(this).darkTheme().title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ListAcitivty.this.onClick(adapter.getItem(position), which); - } - }).build(); + casePositionTwo(position); break; case 3: - sheet = new BottomSheet.Builder(this).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ListAcitivty.this.onClick(adapter.getItem(position), which); - } - }).grid().build(); + casePositionThree(position); break; case 4: - sheet = new BottomSheet.Builder(this, R.style.BottomSheet_StyleDialog).title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ListAcitivty.this.onClick(adapter.getItem(position), which); - } - }).build(); + casePositionFour(position); break; case 5: - sheet = new BottomSheet.Builder(this).title("To " + adapter.getItem(position)).sheet(R.menu.longlist).listener(new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ListAcitivty.this.onClick(adapter.getItem(position), which); - } - }).limit(R.integer.bs_initial_list_row).build(); + casePositionFive(position); break; case 6: sheet = getShareActions("Hello " + adapter.getItem(position)).title("Share To " + adapter.getItem(position)).limit(R.integer.no_limit).build(); @@ -139,59 +108,121 @@ public void onClick(DialogInterface dialog, int which) { sheet = getShareActions("Hello " + adapter.getItem(position)).title("Share To " + adapter.getItem(position)).build(); break; case 8: - sheet = new BottomSheet.Builder(this).icon(getRoundedBitmap(R.drawable.icon)).title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ListAcitivty.this.onClick(adapter.getItem(position), which); - } - }).build(); - final Menu menu = sheet.getMenu(); - menu.getItem(0).setTitle("MenuClickListener"); - menu.getItem(0).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - q.alert("OnMenuItemClickListener", "You can set OnMenuItemClickListener for each item"); - return true; - } - }); - menu.getItem(1).setVisible(false); - menu.getItem(2).setEnabled(false); - menu.add(Menu.NONE, 23, Menu.NONE, "Fresh meal!"); - menu.findItem(23).setIcon(R.drawable.perm_group_user_dictionary); - menu.findItem(23).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - q.toast("Hello"); - return true; - } - }); - menu.setGroupVisible(android.R.id.empty,false); + casePositionEight(position); break; case 9: - sheet = new BottomSheet.Builder(this, R.style.BottomSheet_CustomizedDialog).grid().title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ListAcitivty.this.onClick(adapter.getItem(position), which); - } - }).build(); - sheet.setOnShowListener(new DialogInterface.OnShowListener() { - @Override - public void onShow(DialogInterface dialog) { - q.toast("I'm showing"); - } - }); - sheet.setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - q.toast("I'm dismissing"); - } - }); + casePositionNine(position); break; } return sheet; } + private void casePositionNine(final int position) { + sheet = new BottomSheet.Builder(this, R.style.BottomSheet_CustomizedDialog).grid().title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + ListAcitivty.this.onClick(adapter.getItem(position), which); + } + }).build(); + sheet.setOnShowListener(new DialogInterface.OnShowListener() { + @Override + public void onShow(DialogInterface dialog) { + q.toast("I'm showing"); + } + }); + sheet.setOnDismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + q.toast("I'm dismissing"); + } + }); + } + + private void casePositionEight(final int position) { + sheet = new BottomSheet.Builder(this).icon(getRoundedBitmap(R.drawable.icon)).title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + ListAcitivty.this.onClick(adapter.getItem(position), which); + } + }).build(); + final Menu menu = sheet.getMenu(); + menu.getItem(0).setTitle("MenuClickListener"); + menu.getItem(0).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + q.alert("OnMenuItemClickListener", "You can set OnMenuItemClickListener for each item"); + return true; + } + }); + menu.getItem(1).setVisible(false); + menu.getItem(2).setEnabled(false); + menu.add(Menu.NONE, 23, Menu.NONE, "Fresh meal!"); + menu.findItem(23).setIcon(R.drawable.perm_group_user_dictionary); + menu.findItem(23).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + q.toast("Hello"); + return true; + } + }); + menu.setGroupVisible(android.R.id.empty,false); + } + + private void casePositionFive(final int position) { + sheet = new BottomSheet.Builder(this).title("To " + adapter.getItem(position)).sheet(R.menu.longlist).listener(new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + ListAcitivty.this.onClick(adapter.getItem(position), which); + } + }).limit(R.integer.bs_initial_list_row).build(); + } + + private void casePositionFour(final int position) { + sheet = new BottomSheet.Builder(this, R.style.BottomSheet_StyleDialog).title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + ListAcitivty.this.onClick(adapter.getItem(position), which); + } + }).build(); + } + + private void casePositionThree(final int position) { + sheet = new BottomSheet.Builder(this).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + ListAcitivty.this.onClick(adapter.getItem(position), which); + } + }).grid().build(); + } + + private void casePositionTwo(final int position) { + sheet = new BottomSheet.Builder(this).darkTheme().title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + ListAcitivty.this.onClick(adapter.getItem(position), which); + } + }).build(); + } + + private void casePositionOne(final int position) { + sheet = new BottomSheet.Builder(this).sheet(R.menu.noicon).listener(new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + ListAcitivty.this.onClick(adapter.getItem(position), which); + } + }).build(); + } + + private void casePositionZero(final int position) { + sheet = new BottomSheet.Builder(this).icon(getRoundedBitmap(R.drawable.icon)).title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + ListAcitivty.this.onClick(adapter.getItem(position), which); + } + }).build(); + } + private BottomSheet.Builder getShareActions(String text) { final Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); diff --git a/library/src/main/java/com/cocosw/bottomsheet/SimpleSectionedGridAdapter.java b/library/src/main/java/com/cocosw/bottomsheet/SimpleSectionedGridAdapter.java index df5f6ed..c57d177 100644 --- a/library/src/main/java/com/cocosw/bottomsheet/SimpleSectionedGridAdapter.java +++ b/library/src/main/java/com/cocosw/bottomsheet/SimpleSectionedGridAdapter.java @@ -119,13 +119,7 @@ private int getHeaderSize(){ break; case GridView.STRETCH_SPACING: - mColumnWidth = requestedColumnWidth; - if (mNumColumns > 1) { - mHorizontalSpacing = requestedHorizontalSpacing + - spaceLeftOver / (mNumColumns - 1); - } else { - mHorizontalSpacing = requestedHorizontalSpacing + spaceLeftOver; - } + caseGridViewStretchSpacing(spaceLeftOver); break; case GridView.STRETCH_SPACING_UNIFORM: @@ -138,6 +132,16 @@ private int getHeaderSize(){ return mHeaderWidth; } + private void caseGridViewStretchSpacing(int spaceLeftOver) { + mColumnWidth = requestedColumnWidth; + if (mNumColumns > 1) { + mHorizontalSpacing = requestedHorizontalSpacing + + spaceLeftOver / (mNumColumns - 1); + } else { + mHorizontalSpacing = requestedHorizontalSpacing + spaceLeftOver; + } + } + public void setSections(Section... sections) { mInitialSections = sections;