Skip to content

Commit

Permalink
Revert back to original enter & exit animations. Removed unneeded code
Browse files Browse the repository at this point in the history
  • Loading branch information
kpmmmurphy committed Feb 21, 2017
1 parent 4c7b672 commit 6e0f307
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 46 deletions.
2 changes: 1 addition & 1 deletion alerter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
minSdkVersion 9
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion

versionCode 1
Expand Down
12 changes: 11 additions & 1 deletion alerter/src/androidTest/java/com/tapadoo/alerter/AlertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.support.v4.content.ContextCompat;
import android.view.View;

import com.tapadoo.android.R;

import junit.framework.Assert;

import org.junit.Before;
Expand Down Expand Up @@ -124,7 +127,10 @@ public void testBackgroundColour() {
alert.setAlertBackgroundColor(ContextCompat.getColor(mockActivity, android.R.color.darker_gray));

Assert.assertNotNull(alert.getAlertBackground().getBackground());
Assert.assertEquals(((ColorDrawable) alert.getAlertBackground().getBackground()).getColor(), ContextCompat.getColor(mockActivity, android.R.color.darker_gray));

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
Assert.assertEquals(((ColorDrawable) alert.getAlertBackground().getBackground()).getColor(), ContextCompat.getColor(mockActivity, android.R.color.darker_gray));
}
}

@Test
Expand All @@ -140,6 +146,10 @@ public void testIcon() {

@Test
public void testOnClickListener() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
return;
}

//Check default onClickListener
Assert.assertTrue(alert.getAlertBackground().hasOnClickListeners());

Expand Down
21 changes: 13 additions & 8 deletions alerter/src/androidTest/java/com/tapadoo/alerter/AlerterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import com.tapadoo.android.R;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.ClassRule;
Expand Down Expand Up @@ -112,27 +115,29 @@ public void testBuilderBackground() {
.show();

Assert.assertNotNull(alert.getAlertBackground().getBackground());
Assert.assertEquals(((ColorDrawable) alert.getAlertBackground().getBackground()).getColor(), ContextCompat.getColor(mockActivity, android.R.color.darker_gray));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
Assert.assertEquals(((ColorDrawable) alert.getAlertBackground().getBackground()).getColor(), ContextCompat.getColor(mockActivity, android.R.color.darker_gray));
}
}

@Test
public void testBuilderOnClickListener() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
return;
}

//Test default hide listener
final Alert alert1 = Alerter.create(mockActivity)
.show();
final Alert alert1 = Alerter.create(mockActivity).show();

Assert.assertTrue(alert1.getAlertBackground().hasOnClickListeners());

//Test nullifying listener
final Alert alert2 = Alerter.create(mockActivity)
.setOnClickListener(null)
.show();
final Alert alert2 = Alerter.create(mockActivity).setOnClickListener(null).show();

Assert.assertFalse(alert2.getAlertBackground().hasOnClickListeners());

//Test setting listener
final Alert alert3 = Alerter.create(mockActivity)
.setOnClickListener(new View.OnClickListener() {
final Alert alert3 = Alerter.create(mockActivity).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
//Ignore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.tapadoo.alerter;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.tapadoo.android.R;

/**
* Mock Activity for Testing
Expand Down
2 changes: 1 addition & 1 deletion alerter/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.tapadoo.alerter"
<manifest package="com.tapadoo.android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

Expand Down
28 changes: 21 additions & 7 deletions alerter/src/main/java/com/tapadoo/alerter/Alert.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.tapadoo.alerter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
Expand All @@ -23,6 +21,8 @@
import android.widget.ImageView;
import android.widget.TextView;

import com.tapadoo.android.R;

/**
* Custom Alert View
*
Expand Down Expand Up @@ -54,6 +54,11 @@ public class Alert extends FrameLayout implements View.OnClickListener, Animatio

private boolean enableIconPulse = true;

/**
* Flag to ensure we only set the margins once
*/
private boolean marginSet;

/**
* This is the default view constructor. It requires a Context, and holds a reference to it.
* If not cleaned up properly, memory will leak.
Expand Down Expand Up @@ -101,10 +106,6 @@ private void initView() {

flBackground.setOnClickListener(this);

setIcon(R.drawable.ic_notifications);

setAlertBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.darker_gray));

//Setup Enter & Exit Animations
slideInAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.alerter_slide_in_from_top);
slideOutAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.alerter_slide_out_to_top);
Expand All @@ -114,6 +115,20 @@ private void initView() {
setAnimation(slideInAnimation);
}

@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

if (!marginSet) {
marginSet = true;

// Add a negative top margin to compensate for overshoot enter animation
final ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) getLayoutParams();
params.topMargin = getContext().getResources().getDimensionPixelSize(R.dimen.alerter_alert_negative_margin_top);
requestLayout();
}
}

// Release resources once view is detached.
@Override
protected void onDetachedFromWindow() {
Expand Down Expand Up @@ -320,7 +335,6 @@ public ImageView getIcon() {
*/
public void setIcon(@DrawableRes final int iconId) {
final Drawable iconDrawable = ContextCompat.getDrawable(getContext(), iconId);
iconDrawable.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
ivIcon.setImageDrawable(iconDrawable);
}

Expand Down
2 changes: 2 additions & 0 deletions alerter/src/main/java/com/tapadoo/alerter/Alerter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import android.view.View;
import android.view.ViewGroup;

import com.tapadoo.android.R;

import java.lang.ref.WeakReference;

/**
Expand Down
16 changes: 5 additions & 11 deletions alerter/src/main/res/anim/alerter_slide_in_from_top.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fillAfter="true"
android:fillBefore="true"
android:interpolator="@android:anim/overshoot_interpolator">
android:duration="700"
android:interpolator="@anim/interpolator_slight_overshoot">

<scale
android:fromXScale="1.0"
android:fromYScale="0"
android:pivotX="50%"
android:pivotY="0%"
android:toXScale="1.0"
android:toYScale="1.0"/>
<translate
android:fromYDelta="-100%"
android:toYDelta="0%"/>

</set>
15 changes: 5 additions & 10 deletions alerter/src/main/res/anim/alerter_slide_out_to_top.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime"
android:duration="@android:integer/config_longAnimTime"
android:fillAfter="true"
android:fillBefore="true"
android:interpolator="@android:anim/anticipate_interpolator">
android:interpolator="@anim/interpolator_slight_anticipate">

<scale
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="0%"
android:toXScale="1.0"
android:toYScale="0.0"/>
<translate
android:fromYDelta="0%"
android:toYDelta="-100%"/>

</set>
11 changes: 7 additions & 4 deletions alerter/src/main/res/layout/alerter_alert_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
style="@style/AlertStyle"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@android:color/darker_gray"
android:clickable="true"
android:foreground="?attr/selectableItemBackground"
tools:background="@android:color/black"
tools:visibility="visible">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:padding="@dimen/alerter_activity_horizontal_margin"
android:layout_marginTop="@dimen/alerter_padding_half"
android:background="@null"
android:clipChildren="false"
android:clipToPadding="false"
android:paddingBottom="@dimen/alerter_padding_small">
android:padding="@dimen/alerter_activity_horizontal_margin">

<android.support.v7.widget.AppCompatImageView
android:id="@+id/ivIcon"
Expand All @@ -27,7 +28,8 @@
android:layout_centerVertical="true"
android:maxHeight="@dimen/alerter_alert_icn_size"
android:maxWidth="@dimen/alerter_alert_icn_size"
tools:src="@android:drawable/ic_menu_info_details"/>
android:src="@drawable/ic_notifications"
android:tint="@android:color/white"/>

<LinearLayout
android:id="@+id/llAlertTextContainer"
Expand All @@ -40,6 +42,7 @@
android:layout_marginStart="@dimen/alerter_activity_horizontal_margin"
android:layout_toEndOf="@id/ivIcon"
android:layout_toRightOf="@id/ivIcon"
android:background="@null"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical">
Expand Down
4 changes: 3 additions & 1 deletion alerter/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
<dimen name="alerter_activity_vertical_margin">16dp</dimen>

<dimen name="alerter_padding_small">4dp</dimen>
<dimen name="alerter_padding_half">8dp</dimen>
<dimen name="alerter_padding_default">16dp</dimen>
<dimen name="alerter_alert_padding">26dp</dimen>
<dimen name="alerter_alert_padding">28dp</dimen>
<dimen name="alerter_alert_negative_margin_top">-24dp</dimen>

<!--Alerts-->
<dimen name="alerter_alert_min_height">64dp</dimen>
Expand Down
1 change: 1 addition & 0 deletions alerter/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
<style name="AlertTextAppearance.Text">
<item name="android:textSize">@dimen/alerter_text_small</item>
</style>

</resources>
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
defaultConfig {
applicationId "com.tapadoo.example"

minSdkVersion 9
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion

versionCode 1
Expand Down

0 comments on commit 6e0f307

Please sign in to comment.