Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Tapadoo/Alerter
Browse files Browse the repository at this point in the history
  • Loading branch information
kpmmmurphy committed Feb 20, 2017
2 parents 1a7a762 + 43f46ff commit 9d87edc
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,26 @@ Alerter.create(this)

![Verbose Alert](./documentation/alert_verbose.gif)

### Visibility Callbacks

```java
Alerter.create(ExampleActivity.this)
.setTitle("Alert Title")
.setOnShownListener(new OnAlertShownListener() {
@Override
public void onAlertShown() {
Toast.makeText(ExampleActivity.this, "OnAlertShown", Toast.LENGTH_LONG).show();
}
})
.setOnHiddenListener(new OnAlertHiddenListener() {
@Override
public void onAlertHidden() {
Toast.makeText(ExampleActivity.this, "OnAlertHidden", Toast.LENGTH_LONG).show();
}
})
.show();
```

## Sample

Clone this repo and check out the `app` module.
Expand Down
22 changes: 22 additions & 0 deletions alerter/src/main/java/com/tapadoo/alerter/Alert.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class Alert extends FrameLayout implements View.OnClickListener, Animatio
private Animation slideInAnimation;
private Animation slideOutAnimation;

private OnAlertShownListener onShowListener;
private OnAlertHiddenListener onHideListener;

private long duration = DISPLAY_TIME_IN_SECONDS;

private boolean enableIconPulse = true;
Expand Down Expand Up @@ -196,6 +199,8 @@ public void onAnimationEnd(final Animation animation) {
}
}

if(onShowListener != null) onShowListener.onAlertShown();

//Start the Handler to clean up the Alert
postDelayed(new Runnable() {
@Override
Expand Down Expand Up @@ -253,6 +258,7 @@ public void run() {
} else {
try {
((ViewGroup) getParent()).removeView(Alert.this);
if(onHideListener != null) onHideListener.onAlertHidden();
} catch (Exception ex) {
Log.e(getClass().getSimpleName(), "Cannot remove from parent layout");
}
Expand Down Expand Up @@ -371,6 +377,22 @@ public void pulseIcon(final boolean shouldPulse) {
this.enableIconPulse = shouldPulse;
}

/**
* Set the alert's listener to be fired on the alert being fully shown
* @param listener Listener to be fired
*/
public void setOnShownListener(OnAlertShownListener listener) {
this.onShowListener = listener;
}

/**
* Set the alert's listener to be fired on the alert being fully hidden
* @param listener Listener to be fired
*/
public void setOnHiddenListener(OnAlertHiddenListener listener) {
this.onHideListener = listener;
}

/**
* Get the screen height in pixels
*
Expand Down
26 changes: 26 additions & 0 deletions alerter/src/main/java/com/tapadoo/alerter/Alerter.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,32 @@ public Alerter enableIconPulse(final boolean pulse) {
return this;
}

/**
* Sets the Alert Shown Listener
*
* @param listener OnAlertShownListener of Alert
* @return This Alerter
*/
public Alerter setOnShownListener(final OnAlertShownListener listener) {
if (getAlert() != null) {
getAlert().setOnShownListener(listener);
}
return this;
}

/**
* Sets the Alert Hidden Listener
*
* @param listener OnAlertHiddenListener of Alert
* @return This Alerter
*/
public Alerter setOnHiddenListener(final OnAlertHiddenListener listener) {
if (getAlert() != null) {
getAlert().setOnHiddenListener(listener);
}
return this;
}

/**
* Gets the Alert associated with the Alerter
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.tapadoo.alerter;

/**
* Created by edgeorge on 20/02/2017.
*/

public interface OnAlertHiddenListener {
void onAlertHidden();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.tapadoo.alerter;

/**
* Created by edgeorge on 20/02/2017.
*/

public interface OnAlertShownListener {
void onAlertShown();
}
28 changes: 28 additions & 0 deletions app/src/main/java/com/tapadoo/example/ExampleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import android.widget.Toast;

import com.tapadoo.alerter.Alerter;
import com.tapadoo.alerter.OnAlertHiddenListener;
import com.tapadoo.alerter.OnAlertShownListener;

public class ExampleActivity extends AppCompatActivity implements View.OnClickListener {

Expand All @@ -24,6 +26,7 @@ protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.btnAlertTextOnly).setOnClickListener(this);
findViewById(R.id.btnAlertOnClick).setOnClickListener(this);
findViewById(R.id.btnAlertVerbose).setOnClickListener(this);
findViewById(R.id.btnAlertCallback).setOnClickListener(this);
}

@Override
Expand All @@ -49,6 +52,10 @@ public void onClick(View view) {
showAlertVerbose();
break;
}
case R.id.btnAlertCallback: {
showAlertCallbacks();
break;
}
default: {
showAlertDefault();
}
Expand Down Expand Up @@ -105,4 +112,25 @@ private void showAlertVerbose() {
"The alert scales to accommodate larger bodies of text.")
.show();
}

private void showAlertCallbacks(){
Alerter.create(ExampleActivity.this)
.setTitle("Alert Title")
.setText("Alert text...")
.setDuration(10000)
.setOnShownListener(new OnAlertShownListener() {
@Override
public void onAlertShown() {
Toast.makeText(ExampleActivity.this, "OnAlertShown", Toast.LENGTH_LONG).show();
}
})
.setOnHiddenListener(new OnAlertHiddenListener() {
@Override
public void onAlertHidden() {
Toast.makeText(ExampleActivity.this, "OnAlertHidden", Toast.LENGTH_LONG).show();
}
})
.show();
}

}
7 changes: 7 additions & 0 deletions app/src/main/res/layout/content_example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,11 @@
android:layout_height="wrap_content"
android:text="@string/verbose_alert"/>

<android.support.v7.widget.AppCompatButton
style="@style/ExampleButton"
android:id="@+id/btnAlertCallback"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/callback_alert"/>

</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<string name="on_click_alert">On Click Alert</string>
<string name="verbose_alert">Verbose Alert</string>
<string name="custom_icon_alert">Custom Icon Alert</string>
<string name="callback_alert">Alert Callbacks</string>
</resources>

0 comments on commit 9d87edc

Please sign in to comment.