diff --git a/README.md b/README.md index ea632c0..8dc9263 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,12 @@ This library tries to mimic the activity chooser version you can see on Android ## Download (from JCenter) ```groovy -compile 'com.github.zawadz88:material-activity-chooser:0.1.1' +compile 'com.github.zawadz88:material-activity-chooser:0.2.0' ``` ## Supported features - showing the activity chooser as a bottom sheet dialog on all OS versions starting from Jelly Bean (API 16)+ + - a smooth animation when the items appear in the bottom sheet - setting custom bottom sheet titles - setting different intents per activity, e.g. to have different messages for different applications when sharing - use custom styles for the bottom sheet @@ -152,7 +153,16 @@ You can inflate an entirely custom empty view as well, e.g. ## Styling the dialog to your own needs You can override the default styling of the Activity Chooser to your own needs. -The easiest way is to override the +The easiest way is to override the ```MACTheme``` and replace the styles in the custom attributes. For more info see the sample app. + +## Disabling the item animation +By default there is a layout animation on the RecyclerView which animates the items as they show up. +It can be however disabled by extending the ```MACTheme``` and overriding ```mac_bottomSheetRecyclerViewStyle``` with a style with this animation disabled, e.g. +```java + +``` ## Tracking when an activity was clicked You might want to track/log when an activity has been selected to handle your intent. To do so you can extend the default MaterialActivityChooserActivity. diff --git a/gradle.properties b/gradle.properties index fa38122..686f97c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,4 +18,4 @@ org.gradle.jvmargs=-Xmx1536m POM_GROUP_ID=com.github.zawadz88 POM_ARTIFACT_ID=material-activity-chooser -POM_VERSION=0.1.1 +POM_VERSION=0.2.0 diff --git a/material-activity-chooser/src/main/java/com/github/zawadz88/activitychooser/widget/GridRecyclerView.java b/material-activity-chooser/src/main/java/com/github/zawadz88/activitychooser/widget/GridRecyclerView.java new file mode 100644 index 0000000..8d68c1c --- /dev/null +++ b/material-activity-chooser/src/main/java/com/github/zawadz88/activitychooser/widget/GridRecyclerView.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2014 Freddie (Musenkishi) Lust-Hed + * + * 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.github.zawadz88.activitychooser.widget; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.v7.widget.GridLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewGroup; +import android.view.animation.GridLayoutAnimationController; + +/** + * An extension of RecyclerView, focused more on resembling a GridView. + * Unlike {@link android.support.v7.widget.RecyclerView}, this view can handle + * {@code } as long as you provide it a + * {@link android.support.v7.widget.GridLayoutManager} in + * {@code setLayoutManager(LayoutManager layout)}.
+ * + * Created by Freddie (Musenkishi) Lust-Hed.
+ * + * animationParams.column and animationParams.row values were corrected.
+ * + * Source: GitHub + */ +public class GridRecyclerView extends RecyclerView { + + public GridRecyclerView(Context context) { + super(context); + } + + public GridRecyclerView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public GridRecyclerView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + public void setLayoutManager(LayoutManager layout) { + if (layout instanceof GridLayoutManager) { + super.setLayoutManager(layout); + } else { + throw new ClassCastException("You should only use a GridLayoutManager with GridRecyclerView."); + } + } + + @Override + protected void attachLayoutAnimationParameters(View child, @NonNull ViewGroup.LayoutParams params, int index, int count) { + + if (getAdapter() != null && getLayoutManager() instanceof GridLayoutManager) { + + GridLayoutAnimationController.AnimationParameters animationParams = + (GridLayoutAnimationController.AnimationParameters) params.layoutAnimationParameters; + + if (animationParams == null) { + animationParams = new GridLayoutAnimationController.AnimationParameters(); + params.layoutAnimationParameters = animationParams; + } + + int columns = ((GridLayoutManager) getLayoutManager()).getSpanCount(); + + + animationParams.count = count; + animationParams.index = index; + animationParams.columnsCount = columns; + animationParams.rowsCount = count / columns + 1; + + animationParams.column = index % columns; + animationParams.row = index % columns + index / columns; + + } else { + super.attachLayoutAnimationParameters(child, params, index, count); + } + } +} \ No newline at end of file diff --git a/material-activity-chooser/src/main/res-public/values/public.xml b/material-activity-chooser/src/main/res-public/values/public.xml index 88c7b5b..698872d 100644 --- a/material-activity-chooser/src/main/res-public/values/public.xml +++ b/material-activity-chooser/src/main/res-public/values/public.xml @@ -3,6 +3,7 @@ + diff --git a/material-activity-chooser/src/main/res/anim/mac_grid_layout_animation.xml b/material-activity-chooser/src/main/res/anim/mac_grid_layout_animation.xml new file mode 100644 index 0000000..a52d6d8 --- /dev/null +++ b/material-activity-chooser/src/main/res/anim/mac_grid_layout_animation.xml @@ -0,0 +1,7 @@ + + \ No newline at end of file diff --git a/material-activity-chooser/src/main/res/anim/mac_slide_up_with_fade_in.xml b/material-activity-chooser/src/main/res/anim/mac_slide_up_with_fade_in.xml new file mode 100644 index 0000000..4834ac3 --- /dev/null +++ b/material-activity-chooser/src/main/res/anim/mac_slide_up_with_fade_in.xml @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file diff --git a/material-activity-chooser/src/main/res/layout/activity_material_activity_chooser.xml b/material-activity-chooser/src/main/res/layout/activity_material_activity_chooser.xml index 43b69b0..308f50b 100644 --- a/material-activity-chooser/src/main/res/layout/activity_material_activity_chooser.xml +++ b/material-activity-chooser/src/main/res/layout/activity_material_activity_chooser.xml @@ -25,35 +25,34 @@ style="?attr/mac_bottomSheetTitleStyle" android:layout_width="match_parent" android:layout_height="wrap_content" - android:clickable="true"/> + android:clickable="true" /> - + android:layout_height="wrap_content" /> + android:clickable="true" + android:visibility="gone"> + android:text="@string/mac_default_no_activities_found_message" />