mirror of
https://github.com/MatomoCamp/matomocamp-companion-android.git
synced 2024-09-19 16:13:46 +02:00
Added bookmark icon (un)check animation
This commit is contained in:
parent
3da0eca1fa
commit
6c6bc28ad1
11 changed files with 145 additions and 8 deletions
|
@ -5,8 +5,10 @@ import android.app.Activity;
|
|||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Animatable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.CalendarContract;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
@ -238,7 +240,7 @@ public class EventDetailsFragment extends Fragment {
|
|||
if (actionButton != null) {
|
||||
bookmarkMenuItem.setEnabled(false).setVisible(false);
|
||||
}
|
||||
updateOptionsMenu();
|
||||
updateBookmarkMenuItem(false);
|
||||
}
|
||||
|
||||
private Intent getShareChooserIntent() {
|
||||
|
@ -250,21 +252,27 @@ public class EventDetailsFragment extends Fragment {
|
|||
.createChooserIntent();
|
||||
}
|
||||
|
||||
void updateOptionsMenu() {
|
||||
void updateBookmarkMenuItem(boolean animate) {
|
||||
if (actionButton != null) {
|
||||
// Action Button is used as bookmark button
|
||||
|
||||
if (isBookmarked == null) {
|
||||
actionButton.setEnabled(false);
|
||||
} else {
|
||||
// Only animate if the button was showing a previous value
|
||||
animate = animate && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
|
||||
&& actionButton.isEnabled();
|
||||
actionButton.setEnabled(true);
|
||||
|
||||
if (isBookmarked) {
|
||||
actionButton.setContentDescription(getString(R.string.remove_bookmark));
|
||||
actionButton.setImageResource(R.drawable.ic_bookmark_white_24dp);
|
||||
actionButton.setImageResource(animate ? R.drawable.avd_fab_bookmark_add_24dp : R.drawable.ic_bookmark_white_24dp);
|
||||
} else {
|
||||
actionButton.setContentDescription(getString(R.string.add_bookmark));
|
||||
actionButton.setImageResource(R.drawable.ic_bookmark_outline_white_24dp);
|
||||
actionButton.setImageResource(animate ? R.drawable.avd_fab_bookmark_remove_24dp : R.drawable.ic_bookmark_outline_white_24dp);
|
||||
}
|
||||
if (animate) {
|
||||
((Animatable) actionButton.getDrawable()).start();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -274,14 +282,21 @@ public class EventDetailsFragment extends Fragment {
|
|||
if (isBookmarked == null) {
|
||||
bookmarkMenuItem.setEnabled(false);
|
||||
} else {
|
||||
// Only animate if the menu item was showing a previous value
|
||||
animate = animate && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
|
||||
&& bookmarkMenuItem.isEnabled();
|
||||
bookmarkMenuItem.setEnabled(true);
|
||||
|
||||
if (isBookmarked) {
|
||||
bookmarkMenuItem.setTitle(R.string.remove_bookmark);
|
||||
bookmarkMenuItem.setIcon(R.drawable.ic_bookmark_white_24dp);
|
||||
bookmarkMenuItem.setIcon(animate ? R.drawable.avd_appbar_bookmark_add_24dp : R.drawable.ic_bookmark_white_24dp);
|
||||
} else {
|
||||
bookmarkMenuItem.setTitle(R.string.add_bookmark);
|
||||
bookmarkMenuItem.setIcon(R.drawable.ic_bookmark_outline_white_24dp);
|
||||
bookmarkMenuItem.setIcon(animate ? R.drawable.avd_appbar_bookmark_remove_24dp : R.drawable.ic_bookmark_outline_white_24dp);
|
||||
}
|
||||
if (animate) {
|
||||
((Animatable) bookmarkMenuItem.getIcon()).stop();
|
||||
((Animatable) bookmarkMenuItem.getIcon()).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -369,8 +384,10 @@ public class EventDetailsFragment extends Fragment {
|
|||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Boolean> loader, Boolean data) {
|
||||
isBookmarked = data;
|
||||
updateOptionsMenu();
|
||||
if (isBookmarked != data) {
|
||||
isBookmarked = data;
|
||||
updateBookmarkMenuItem(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
16
app/src/main/res/animator-v11/bookmark_check_in.xml
Normal file
16
app/src/main/res/animator-v11/bookmark_check_in.xml
Normal file
|
@ -0,0 +1,16 @@
|
|||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:ordering="sequentially">
|
||||
<objectAnimator
|
||||
android:name="check"
|
||||
android:duration="250"
|
||||
android:propertyName="trimPathEnd"
|
||||
android:valueFrom="0"
|
||||
android:valueTo="0"/>
|
||||
<objectAnimator
|
||||
android:name="check"
|
||||
android:duration="250"
|
||||
android:interpolator="@android:anim/accelerate_interpolator"
|
||||
android:propertyName="trimPathEnd"
|
||||
android:valueFrom="0"
|
||||
android:valueTo="1"/>
|
||||
</set>
|
8
app/src/main/res/animator-v11/bookmark_check_out.xml
Normal file
8
app/src/main/res/animator-v11/bookmark_check_out.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<objectAnimator
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:name="check"
|
||||
android:duration="250"
|
||||
android:interpolator="@android:anim/decelerate_interpolator"
|
||||
android:propertyName="trimPathEnd"
|
||||
android:valueFrom="1"
|
||||
android:valueTo="0"/>
|
7
app/src/main/res/animator-v11/bookmark_fade_in.xml
Normal file
7
app/src/main/res/animator-v11/bookmark_fade_in.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<objectAnimator
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:name="filler"
|
||||
android:duration="250"
|
||||
android:propertyName="fillAlpha"
|
||||
android:valueFrom="0"
|
||||
android:valueTo="1"/>
|
15
app/src/main/res/animator-v11/bookmark_fade_out.xml
Normal file
15
app/src/main/res/animator-v11/bookmark_fade_out.xml
Normal file
|
@ -0,0 +1,15 @@
|
|||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:ordering="sequentially">
|
||||
<objectAnimator
|
||||
android:name="filler"
|
||||
android:duration="250"
|
||||
android:propertyName="fillAlpha"
|
||||
android:valueFrom="1"
|
||||
android:valueTo="1"/>
|
||||
<objectAnimator
|
||||
android:name="filler"
|
||||
android:duration="250"
|
||||
android:propertyName="fillAlpha"
|
||||
android:valueFrom="1"
|
||||
android:valueTo="0"/>
|
||||
</set>
|
|
@ -0,0 +1,9 @@
|
|||
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:drawable="@drawable/ic_avd_appbar_bookmark_24dp">
|
||||
<target
|
||||
android:name="filler"
|
||||
android:animation="@animator/bookmark_fade_in"/>
|
||||
<target
|
||||
android:name="check"
|
||||
android:animation="@animator/bookmark_check_in"/>
|
||||
</animated-vector>
|
|
@ -0,0 +1,9 @@
|
|||
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:drawable="@drawable/ic_avd_appbar_bookmark_24dp">
|
||||
<target
|
||||
android:name="filler"
|
||||
android:animation="@animator/bookmark_fade_out"/>
|
||||
<target
|
||||
android:name="check"
|
||||
android:animation="@animator/bookmark_check_out"/>
|
||||
</animated-vector>
|
9
app/src/main/res/drawable/avd_fab_bookmark_add_24dp.xml
Normal file
9
app/src/main/res/drawable/avd_fab_bookmark_add_24dp.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:drawable="@drawable/ic_avd_fab_bookmark_24dp">
|
||||
<target
|
||||
android:name="filler"
|
||||
android:animation="@animator/bookmark_fade_in"/>
|
||||
<target
|
||||
android:name="check"
|
||||
android:animation="@animator/bookmark_check_in"/>
|
||||
</animated-vector>
|
|
@ -0,0 +1,9 @@
|
|||
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:drawable="@drawable/ic_avd_fab_bookmark_24dp">
|
||||
<target
|
||||
android:name="filler"
|
||||
android:animation="@animator/bookmark_fade_out"/>
|
||||
<target
|
||||
android:name="check"
|
||||
android:animation="@animator/bookmark_check_out"/>
|
||||
</animated-vector>
|
19
app/src/main/res/drawable/ic_avd_appbar_bookmark_24dp.xml
Normal file
19
app/src/main/res/drawable/ic_avd_appbar_bookmark_24dp.xml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:name="bookmark_outline"
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M17,18V5H7V18L12,15.82L17,18M17,3A2,2 0 0,1 19,5V21L12,18L5,21V5C5,3.89 5.9,3 7,3H17M11,7H13V9H15V11H13V13H11V11H9V9H11V7Z"/>
|
||||
<path
|
||||
android:name="filler"
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M6,4h12v14h-12z"/>
|
||||
<path
|
||||
android:name="check"
|
||||
android:pathData="M7.71,9.3L11,12.59L16.55,7.05"
|
||||
android:strokeColor="?attr/colorPrimary"
|
||||
android:strokeWidth="2"/>
|
||||
</vector>
|
19
app/src/main/res/drawable/ic_avd_fab_bookmark_24dp.xml
Normal file
19
app/src/main/res/drawable/ic_avd_fab_bookmark_24dp.xml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:name="bookmark_outline"
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M17,18V5H7V18L12,15.82L17,18M17,3A2,2 0 0,1 19,5V21L12,18L5,21V5C5,3.89 5.9,3 7,3H17M11,7H13V9H15V11H13V13H11V11H9V9H11V7Z"/>
|
||||
<path
|
||||
android:name="filler"
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M6,4h12v14h-12z"/>
|
||||
<path
|
||||
android:name="check"
|
||||
android:pathData="M7.71,9.3L11,12.59L16.55,7.05"
|
||||
android:strokeColor="?attr/colorAccent"
|
||||
android:strokeWidth="2"/>
|
||||
</vector>
|
Loading…
Reference in a new issue