Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -14,5 +15,6 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,12 @@ private SuperActivityToast getSuperActivityToast() {
final Random random = new Random();

SuperActivityToast superActivityToast;
final int typeArbiter = random.nextInt(5);
final int typeArbiter = random.nextInt(6);
switch (typeArbiter) {
case 1: superActivityToast = new SuperActivityToast(Playground.this, Style.TYPE_BUTTON); break;
case 2: superActivityToast = new SuperActivityToast(Playground.this, Style.TYPE_PROGRESS_BAR); break;
case 3: superActivityToast = new SuperActivityToast(Playground.this, Style.TYPE_PROGRESS_CIRCLE); break;
case 4: superActivityToast = new SuperActivityToast(Playground.this, Style.TYPE_IMG); break;
default: superActivityToast = new SuperActivityToast(Playground.this); break;
}
superActivityToast.setText("SuperActivityToast");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void onClick(View view) {
AttributeUtils.getType(getActivity()), containerId)
.setButtonText("UNDO")
.setButtonIconResource(R.drawable.ic_undo)
.setImgResource(R.drawable.toast_warning)
.setOnButtonClickListener("good_tag_name", null, onButtonClickListener)
.setProgressBarColor(Color.WHITE)
.setText("SuperActivityToast")
Expand Down Expand Up @@ -123,7 +124,7 @@ public void onSaveInstanceState(Bundle outState) {

private final SuperActivityToast.OnButtonClickListener onButtonClickListener =
new SuperActivityToast.OnButtonClickListener() {

@Override
public void onClick(View view, Parcelable token) {
SuperToast.create(view.getContext(), "OnClick!", Style.DURATION_SHORT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* Utils class to help with saved SuperToast attributes.
*/
public class AttributeUtils {

public static int getDuration(Context context) {
switch (PreferenceManager.getDefaultSharedPreferences(context).getInt(context
.getResources().getString(R.string.duration_title), 0)) {
Expand Down Expand Up @@ -91,6 +91,7 @@ public static int getType(Context context) {
case 1: return Style.TYPE_BUTTON;
case 2: return Style.TYPE_PROGRESS_BAR;
case 3: return Style.TYPE_PROGRESS_CIRCLE;
case 4: return Style.TYPE_IMG;
default: return Style.TYPE_STANDARD;
}
}
Expand Down
1 change: 1 addition & 0 deletions demo/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@
<item>"TYPE_BUTTON"</item>
<item>"TYPE_PROGRESS_BAR"</item>
<item>"TYPE_PROGRESS_CIRCLE"</item>
<item>"TYPE_PROGRESS_IMG"</item>
</array>
</resources>
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class Style implements Parcelable {
public @interface Frame {}

@Retention(RetentionPolicy.SOURCE)
@IntDef({TYPE_STANDARD, TYPE_BUTTON, TYPE_PROGRESS_CIRCLE, TYPE_PROGRESS_BAR})
@IntDef({TYPE_STANDARD, TYPE_BUTTON, TYPE_PROGRESS_CIRCLE, TYPE_PROGRESS_BAR, TYPE_IMG})
public @interface Type {}

@Retention(RetentionPolicy.SOURCE)
Expand Down Expand Up @@ -101,6 +101,7 @@ public class Style implements Parcelable {
public static final int TYPE_BUTTON = 2;
public static final int TYPE_PROGRESS_CIRCLE = 3;
public static final int TYPE_PROGRESS_BAR = 4;
public static final int TYPE_IMG = 5;

public static final int ANIMATIONS_FADE = 1;
public static final int ANIMATIONS_FLY = 2;
Expand Down Expand Up @@ -158,6 +159,10 @@ public class Style implements Parcelable {
public boolean progressIndeterminate;
public int progressBarColor;


// SuperActivityToast Img items
public int imgResource;

/**
* Public constructor for a new {@link com.github.johnpersano.supertoasts.library.Style}.
* This constructor will assign a few default values.
Expand All @@ -167,6 +172,7 @@ public Style() {
this.duration = DURATION_MEDIUM;
this.color = PaletteUtils.getSolidColor(PaletteUtils.MATERIAL_GREY);
this.gravity = Gravity.BOTTOM | Gravity.CENTER;
this.xOffset = BackgroundUtils.convertToDIP(24);
this.yOffset = BackgroundUtils.convertToDIP(64);
this.width = FrameLayout.LayoutParams.WRAP_CONTENT;
this.height = FrameLayout.LayoutParams.WRAP_CONTENT;
Expand Down Expand Up @@ -242,6 +248,9 @@ public void writeToParcel(Parcel parcel, int flags) {
parcel.writeInt(progressMax);
parcel.writeByte((byte) (progressIndeterminate ? 1 : 0));
parcel.writeInt(progressBarColor);

// SuperActivityToast Img items
parcel.writeInt(imgResource);
}

/**
Expand Down Expand Up @@ -305,6 +314,9 @@ private Style(Parcel parcel) {
this.progressMax = parcel.readInt();
this.progressIndeterminate = parcel.readByte() != 0;
this.progressBarColor = parcel.readInt();

// SuperActivityToast Img items
this.imgResource = parcel.readInt();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.github.johnpersano.supertoasts.library.utils.BackgroundUtils;
Expand All @@ -56,7 +57,7 @@ public class SuperActivityToast extends SuperToast {
private static final String BUNDLE_KEY = "0x532e412e542e";

/**
* Listener that calls onClick() when a TYPE_BUTTON SuperActivityToast receives a Button press event.
* Listener that calls onClick() when a TYPE_BUTTON SuperActivityToast receives a Button press event.
*
* @see #setOnButtonClickListener(String, android.os.Parcelable,
* com.github.johnpersano.supertoasts.library.SuperActivityToast.OnButtonClickListener)
Expand All @@ -76,6 +77,7 @@ public interface OnButtonClickListener {
private View mView;
private ViewGroup mViewGroup;
private ProgressBar mProgressBar;
private ImageView mImg;
private Style mStyle;
private OnButtonClickListener mOnButtonClickListener;
private boolean mFromOrientationChange;
Expand Down Expand Up @@ -103,7 +105,7 @@ public SuperActivityToast(@NonNull Context context) {
* Public constructor for a SuperActivityToast.
*
* @param context An Activity Context
* @param style The desired Style
* @param style The desired Style
*/
public SuperActivityToast(@NonNull Context context, @NonNull Style style) {
super(context, style);
Expand All @@ -121,9 +123,9 @@ public SuperActivityToast(@NonNull Context context, @NonNull Style style) {

/**
* Public constructor for a SuperActivityToast.
*
*
* @param context An Activity Context
* @param type The desired SuperActivityToast type
* @param type The desired SuperActivityToast type
*/
public SuperActivityToast(@NonNull Context context, @Style.Type int type) {
super(context, type);
Expand All @@ -133,7 +135,7 @@ public SuperActivityToast(@NonNull Context context, @Style.Type int type) {
}

this.mContext = context;
this.mStyle = this.getStyle(); // Style is created in the super(context) call
this.mStyle = this.getStyle(); // Style is created in the super(context) call

// Set the default ViewGroup as the Activity's content
this.mViewGroup = (ViewGroup) ((Activity) context).findViewById(android.R.id.content);
Expand All @@ -143,8 +145,8 @@ public SuperActivityToast(@NonNull Context context, @Style.Type int type) {
* Public constructor for a SuperActivityToast.
*
* @param context An Activity Context
* @param style The desired Style
* @param type The desired SuperActivityToast type
* @param style The desired Style
* @param type The desired SuperActivityToast type
*/
public SuperActivityToast(@NonNull Context context, @NonNull Style style, @Style.Type int type) {
super(context, style, type);
Expand All @@ -154,7 +156,7 @@ public SuperActivityToast(@NonNull Context context, @NonNull Style style, @Style
}

this.mContext = context;
this.mStyle = this.getStyle(); // Style is created in the super(context) call
this.mStyle = this.getStyle(); // Style is created in the super(context) call

// Set the default ViewGroup as the Activity's content
this.mViewGroup = (ViewGroup) ((Activity) context).findViewById(android.R.id.content);
Expand All @@ -164,9 +166,9 @@ public SuperActivityToast(@NonNull Context context, @NonNull Style style, @Style
* Public constructor for a SuperActivityToast.
*
* @param context An Activity Context
* @param style The desired Style
* @param type The desired SuperActivityToast type
* @param viewGroupId The id of the ViewGroup to attach the SuperActivityToast to
* @param style The desired Style
* @param type The desired SuperActivityToast type
* @param viewGroupId The id of the ViewGroup to attach the SuperActivityToast to
*/
public SuperActivityToast(@NonNull Context context, @NonNull Style style,
@Style.Type int type, @IdRes int viewGroupId) {
Expand All @@ -177,7 +179,7 @@ public SuperActivityToast(@NonNull Context context, @NonNull Style style,
}

this.mContext = context;
this.mStyle = this.getStyle(); // Style is created in the super(context) call
this.mStyle = this.getStyle(); // Style is created in the super(context) call

// Try to find the ViewGroup id in the layout
this.mViewGroup = (ViewGroup) ((Activity) context).findViewById(viewGroupId);
Expand All @@ -192,8 +194,8 @@ public SuperActivityToast(@NonNull Context context, @NonNull Style style,
*
* @param context An Activity Context
* @param layoutInflater The LayoutInflater created from the Context
* @param type The desired SuperActivityToast type
*
* @param type The desired SuperActivityToast type
*
* @return The SuperActivityToast View
*/
@Override
Expand Down Expand Up @@ -232,6 +234,14 @@ protected View onCreateView(@NonNull Context context, LayoutInflater layoutInfla
this.mProgressBar = (ProgressBar) this.mView.findViewById(R.id.progress_bar);
break;

case Style.TYPE_IMG:
this.mView = layoutInflater.inflate(R.layout.supertoast_img,
(ViewGroup)((Activity) context)
.findViewById(android.R.id.content),
false);
this.mImg = (ImageView) this.mView.findViewById(R.id.img);
break;

default:
// Type received was erroneous so inflate the standard SuperToast layout
this.mView = layoutInflater.inflate(R.layout.supertoast,
Expand Down Expand Up @@ -304,8 +314,8 @@ public Parcelable getDismissToken() {

/**
* Protected method used by the Toaster to know when not to use the
* show animation.
*
* show animation.
*
* @return The current SuperActivityToast instance
*/
protected SuperActivityToast fromOrientationChange() {
Expand All @@ -315,8 +325,8 @@ protected SuperActivityToast fromOrientationChange() {

/**
* Protected method used by the Toaster to know when not to use the
* show animation.
*
* show animation.
*
* @return true if coming from orientation change
*/
protected boolean isFromOrientationChange() {
Expand Down Expand Up @@ -351,8 +361,8 @@ public boolean isIndeterminate() {

/**
* Set a private OnTouchListener to the SuperActivityToast which will dismiss
* it if any part is touched.
*
* it if any part is touched.
*
* @param touchToDismiss true if should touch to dismiss
* @return The current SuperActivityToast instance
*/
Expand Down Expand Up @@ -490,6 +500,17 @@ public SuperActivityToast setButtonIconResource(@DrawableRes int buttonIconResou
return this;
}

/**
* Set the Img icon resource in a TYPE_IMG SuperActivityToast.
*
* @param imgResource The desired icon resource
* @return The current SuperActivityToast instance
*/
public SuperActivityToast setImgResource(@DrawableRes int imgResource) {
this.mStyle.imgResource = imgResource;
return this;
}

/**
* Returns the Button icon resource of a TYPE_BUTTON SuperActivityToast.
*
Expand Down Expand Up @@ -629,10 +650,10 @@ public SuperActivityToast setProgressMax(int progressMax) {
public int getProgressMax() {
return this.mStyle.progressMax;
}

/**
* Set the ProgressBar to be isIndeterminate in a TYPE_PROGRESS_BAR SuperActivityToast.
*
*
* @param progressIndeterminate true if progress should be isIndeterminate
* @return The current SuperActivityToast instance
*/
Expand Down Expand Up @@ -670,11 +691,11 @@ public int getType() {
}

/**
* Modify various attributes of the SuperActivityToast before being shown.
* Modify various attributes of the SuperActivityToast before being shown.
*/
@Override
protected void onPrepareShow() {
super.onPrepareShow(); // This will take care of many modifications
super.onPrepareShow(); // This will take care of many modifications

final FrameLayout.LayoutParams layoutParams = new FrameLayout
.LayoutParams(this.mStyle.width, this.mStyle.height);
Expand All @@ -683,6 +704,9 @@ protected void onPrepareShow() {
switch (this.mStyle.type) {

case Style.TYPE_STANDARD:
this.mStyle.width = FrameLayout.LayoutParams.MATCH_PARENT;
this.mStyle.xOffset = BackgroundUtils.convertToDIP(24);
this.mStyle.yOffset = BackgroundUtils.convertToDIP(24);
break;

case Style.TYPE_BUTTON:
Expand All @@ -699,7 +723,7 @@ protected void onPrepareShow() {
>= Configuration.SCREENLAYOUT_SIZE_LARGE) {
this.mStyle.width = BackgroundUtils.convertToDIP(568);
this.mStyle.gravity = Gravity.BOTTOM | Gravity.START;
}
}

// Set up the Button attributes
final Button button = (Button) this.mView.findViewById(R.id.button);
Expand All @@ -710,7 +734,7 @@ protected void onPrepareShow() {
button.setTypeface(button.getTypeface(), this.mStyle.buttonTypefaceStyle);
button.setTextColor(this.mStyle.buttonTextColor);
button.setTextSize(this.mStyle.buttonTextSize);

if (this.mStyle.frame != Style.FRAME_LOLLIPOP) {
this.mView.findViewById(R.id.divider).setBackgroundColor(this
.mStyle.buttonDividerColor);
Expand Down Expand Up @@ -763,6 +787,17 @@ public void onClick(View view) {
this.mProgressBar.setMax(this.mStyle.progressMax);
this.mProgressBar.setIndeterminate(this.mStyle.progressIndeterminate);
break;

case Style.TYPE_IMG:
this.mStyle.width = FrameLayout.LayoutParams.MATCH_PARENT;
this.mStyle.xOffset = BackgroundUtils.convertToDIP(24);
this.mStyle.yOffset = BackgroundUtils.convertToDIP(24);

if(this.mStyle.imgResource > 0) {
this.mImg.setImageResource(this.mStyle.imgResource);
}

break;
}

layoutParams.width = this.mStyle.width;
Expand Down Expand Up @@ -800,7 +835,7 @@ public boolean onTouch(View v, MotionEvent motionEvent) {
*
* This should be called in the {@link android.app.Activity#onSaveInstanceState(android.os.Bundle)}
* method of your Activity.
*
*
* @param bundle The Bundle provided in onSaveInstanceState()
*/
@SuppressWarnings("unchecked")
Expand Down
Loading