Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit c405abe

Browse files
committed
Merge remote-tracking branch 'origin/release' into release
# Conflicts: # build.gradle # demo/src/test/java/me/angrybyte/sillyandroid/extras/ColoringTest.java # sillyandroid/src/main/java/me/angrybyte/sillyandroid/components/EasyActivity.java
2 parents 28f5ed0 + 7fc39c9 commit c405abe

File tree

8 files changed

+258
-136
lines changed

8 files changed

+258
-136
lines changed

sillyandroid/src/main/java/me/angrybyte/sillyandroid/SillyAndroid.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.lang.annotation.Retention;
4444
import java.lang.annotation.RetentionPolicy;
4545
import java.util.List;
46+
import java.util.Objects;
4647

4748
import static android.content.ContentValues.TAG;
4849

@@ -513,6 +514,23 @@ public static Bitmap drawableToBitmap(@NonNull final Drawable drawable, @Px fina
513514
return result;
514515
}
515516

517+
/**
518+
* Compares the two {@code null}able objects. For {@link Build.VERSION_CODES#KITKAT} and newer APIs this gets the result from
519+
* {@link Objects#equals(Object, Object)}; for older APIs this does the same comparison as {@link Objects#equals(Object, Object)}.
520+
*
521+
* @param first The first object to compare, can be {@code null}
522+
* @param second The second object to compare, can be {@code null}
523+
* @return {@code True} if objects are equal using {@link Object#equals(Object)}, {@code false} otherwise
524+
*/
525+
@SuppressWarnings("unused")
526+
public static boolean equal(@Nullable final Object first, @Nullable final Object second) {
527+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
528+
return Objects.equals(first, second);
529+
} else {
530+
return (first == second) || (first != null && first.equals(second));
531+
}
532+
}
533+
516534
/**
517535
* Similarly to {@link java.util.Objects#equals(Object, Object)}, this compares two {@link Drawable}s' constant states.
518536
*

sillyandroid/src/main/java/me/angrybyte/sillyandroid/components/EasyDialog.java

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
@SuppressWarnings({ "unused", "WeakerAccess" })
3636
public class EasyDialog extends Dialog implements LayoutWrapper {
3737

38+
// <editor-fold desc="Constructors">
39+
3840
/**
3941
* Creates a dialog window that uses the default dialog theme.
4042
* <p>
@@ -69,145 +71,159 @@ public EasyDialog(@NonNull final Context context, @StyleRes final int themeResId
6971
/**
7072
* {@inheritDoc}
7173
*/
72-
protected EasyDialog(@NonNull final Context context, final boolean cancelable, @Nullable final OnCancelListener cancelListener) {
74+
public EasyDialog(@NonNull final Context context, final boolean cancelable, @Nullable final OnCancelListener cancelListener) {
7375
super(context, cancelable, cancelListener);
7476
}
77+
// </editor-fold>
78+
79+
// <editor-fold desc="Internal methods">
80+
81+
/**
82+
* Returns the result from {@link SillyAndroid#equal(Object, Object)}.
83+
*/
84+
protected final boolean equal(@Nullable final Object first, @Nullable final Object second) {
85+
return SillyAndroid.equal(first, second);
86+
}
7587

7688
/**
7789
* Returns the result from {@link SillyAndroid#countIntentHandlers(Context, Intent)}.
7890
*/
7991
@IntRange(from = 0)
80-
public int countIntentHandlers(@Nullable final Intent intent) {
92+
protected final int countIntentHandlers(@Nullable final Intent intent) {
8193
return SillyAndroid.countIntentHandlers(getContext(), intent);
8294
}
8395

8496
/**
8597
* Returns the result from {@link SillyAndroid#canHandleIntent(Context, Intent)}.
8698
*/
87-
public boolean canHandleIntent(@Nullable final Intent intent) {
99+
protected final boolean canHandleIntent(@Nullable final Intent intent) {
88100
return SillyAndroid.canHandleIntent(getContext(), intent);
89101
}
90102

91103
/**
92104
* Returns the result from {@link SillyAndroid#getContentView(android.app.Activity)}.
93105
*/
94-
public <ViewType extends View> ViewType getContentView() {
106+
protected final <ViewType extends View> ViewType getContentView() {
95107
return SillyAndroid.getContentView(this);
96108
}
97109

98110
/**
99111
* Returns the result from {@link SillyAndroid#findViewById(android.support.v4.app.Fragment, int)}.
100112
*/
101-
public <ViewType extends View> ViewType findView(@IdRes final int viewId) {
113+
public final <ViewType extends View> ViewType findView(@IdRes final int viewId) {
102114
return SillyAndroid.findViewById(this, viewId);
103115
}
104116

105117
/**
106118
* Returns the result from {@link SillyAndroid#isEmpty(String)}.
107119
*/
108-
public boolean isEmpty(@Nullable final String text) {
120+
protected final boolean isEmpty(@Nullable final String text) {
109121
return SillyAndroid.isEmpty(text);
110122
}
111123

112124
/**
113125
* Returns the result from {@link SillyAndroid#dismiss(PopupMenu)}.
114126
*/
115-
public boolean dismiss(@Nullable final PopupMenu menu) {
127+
protected final boolean dismiss(@Nullable final PopupMenu menu) {
116128
return SillyAndroid.dismiss(menu);
117129
}
118130

119131
/**
120132
* Returns the result from {@link SillyAndroid#dismiss(android.app.Dialog)}.
121133
*/
122-
public boolean dismiss(@Nullable final EasyDialog dialog) {
134+
protected final boolean dismiss(@Nullable final Dialog dialog) {
123135
return SillyAndroid.dismiss(dialog);
124136
}
125137

126138
/**
127139
* Returns the result from {@link SillyAndroid#close(Closeable)}.
128140
*/
129-
public boolean close(@Nullable final Closeable closeable) {
141+
protected final boolean close(@Nullable final Closeable closeable) {
130142
return SillyAndroid.close(closeable);
131143
}
132144

133145
/**
134146
* Returns the result from {@link SillyAndroid#close(Cursor)}.
135147
*/
136148
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
137-
public boolean close(@Nullable final Cursor cursor) {
149+
protected final boolean close(@Nullable final Cursor cursor) {
138150
return SillyAndroid.close(cursor);
139151
}
140152

141153
/**
142154
* Returns the result from {@link ContextCompat#getDrawable(Context, int)}.
143155
*/
144156
@Nullable
145-
public Drawable getDrawableCompat(@DrawableRes final int drawableId) {
157+
protected final Drawable getDrawableCompat(@DrawableRes final int drawableId) {
146158
return ContextCompat.getDrawable(getContext(), drawableId);
147159
}
148160

149161
/**
150162
* Invokes {@link ViewCompat#setBackground(View, Drawable)} with the same arguments.
151163
*/
152-
public void setBackgroundCompat(@NonNull final EasyView view, @Nullable final Drawable drawable) {
164+
protected final void setBackgroundCompat(@NonNull final View view, @Nullable final Drawable drawable) {
153165
ViewCompat.setBackground(view, drawable);
154166
}
155167

156168
/**
157169
* Invokes {@link SillyAndroid#setPadding(View, int, int, int, int)} with the same arguments.
158170
*/
159-
public void setPadding(@NonNull final EasyView view, @Px final int start, @Px final int top, @Px final int end, @Px final int bottom) {
171+
protected final void setPadding(@NonNull final View view, @Px final int start, @Px final int top, @Px final int end, @Px final int bottom) {
160172
SillyAndroid.setPadding(view, start, top, end, bottom);
161173
}
162174

163175
/**
164176
* Invokes {@link SillyAndroid#setPadding(View, int)} with the same arguments.
165177
*/
166-
public void setPadding(@NonNull final EasyView view, @Px final int padding) {
178+
protected final void setPadding(@NonNull final View view, @Px final int padding) {
167179
SillyAndroid.setPadding(view, padding);
168180
}
169181

170182
/**
171183
* Returns the result from {@link SillyAndroid#isNetworkConnected(Context)}.
172184
*/
173185
@RequiresPermission(allOf = { Manifest.permission.ACCESS_WIFI_STATE, Manifest.permission.ACCESS_NETWORK_STATE })
174-
public boolean isNetworkConnected() {
186+
protected final boolean isNetworkConnected() {
175187
return SillyAndroid.isNetworkConnected(getContext());
176188
}
177189

178190
/**
179191
* Returns the result from {@link SillyAndroid#isVoiceInputAvailable(Context)}.
180192
*/
181-
public boolean isVoiceInputAvailable() {
193+
protected final boolean isVoiceInputAvailable() {
182194
return SillyAndroid.isVoiceInputAvailable(getContext());
183195
}
196+
// </editor-fold>
197+
198+
// <editor-fold desc="Toasts">
184199

185200
/**
186201
* Invokes {@link SillyAndroid#toastShort(Context, int)}.
187202
*/
188-
public void toastShort(@StringRes final int stringId) {
203+
protected final void toastShort(@StringRes final int stringId) {
189204
SillyAndroid.toastShort(getContext(), stringId);
190205
}
191206

192207
/**
193208
* Invokes {@link SillyAndroid#toastShort(Context, String)}.
194209
*/
195-
public void toastShort(@NonNull final String string) {
210+
protected final void toastShort(@NonNull final String string) {
196211
SillyAndroid.toastShort(getContext(), string);
197212
}
198213

199214
/**
200215
* Invokes {@link SillyAndroid#toastLong(Context, int)}.
201216
*/
202-
public void toastLong(@StringRes final int stringId) {
217+
protected final void toastLong(@StringRes final int stringId) {
203218
SillyAndroid.toastLong(getContext(), stringId);
204219
}
205220

206221
/**
207222
* Invokes {@link SillyAndroid#toastLong(Context, String)}.
208223
*/
209-
public void toastLong(@NonNull final String string) {
224+
protected final void toastLong(@NonNull final String string) {
210225
SillyAndroid.toastLong(getContext(), string);
211226
}
227+
// </editor-fold>
212228

213229
}

0 commit comments

Comments
 (0)