Skip to content

Commit 4f138bb

Browse files
committed
2 parents ec8a927 + a38b664 commit 4f138bb

File tree

2 files changed

+146
-3
lines changed

2 files changed

+146
-3
lines changed

library/src/com/devspark/appmsg/AppMsg.java

100644100755
Lines changed: 146 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.content.res.Resources;
2222
import android.view.LayoutInflater;
2323
import android.view.View;
24+
import android.view.View.OnClickListener;
2425
import android.view.ViewGroup;
2526
import android.view.ViewGroup.LayoutParams;
2627
import android.view.animation.Animation;
@@ -132,8 +133,21 @@ public static AppMsg makeText(Activity context, CharSequence text, Style style)
132133
return makeText(context, text, style, R.layout.app_msg);
133134
}
134135

136+
137+
/**
138+
* Make a {@link AppMsg} that just contains a text view.
139+
*
140+
* @param context The context to use. Usually your
141+
* {@link android.app.Activity} object.
142+
* @param text The text to show. Can be formatted text.
143+
* @param style The style with a background and a duration.
144+
*/
145+
public static AppMsg makeText(Activity context, CharSequence text, Style style, OnClickListener clickListener) {
146+
return makeText(context, text, style, R.layout.app_msg);
147+
}
148+
135149
/**
136-
* @author mengguoqiang 扩展支持设置字体大小
150+
* @author mengguoqiang
137151
* Make a {@link AppMsg} that just contains a text view.
138152
*
139153
* @param context The context to use. Usually your
@@ -144,6 +158,20 @@ public static AppMsg makeText(Activity context, CharSequence text, Style style)
144158
public static AppMsg makeText(Activity context, CharSequence text, Style style, float textSize) {
145159
return makeText(context, text, style, R.layout.app_msg, textSize);
146160
}
161+
162+
163+
/**
164+
* @author mengguoqiang
165+
* Make a {@link AppMsg} that just contains a text view.
166+
*
167+
* @param context The context to use. Usually your
168+
* {@link android.app.Activity} object.
169+
* @param text The text to show. Can be formatted text.
170+
* @param style The style with a background and a duration.
171+
*/
172+
public static AppMsg makeText(Activity context, CharSequence text, Style style, float textSize, OnClickListener clickListener) {
173+
return makeText(context, text, style, R.layout.app_msg, textSize, clickListener);
174+
}
147175

148176
/**
149177
* Make a {@link AppMsg} with a custom layout. The layout must have a {@link TextView} com id {@link android.R.id.message}
@@ -161,8 +189,44 @@ public static AppMsg makeText(Activity context, CharSequence text, Style style,
161189
return makeText(context, text, style, v, true);
162190
}
163191

192+
164193
/**
165-
* @author mengguoqiang 扩展支持字体大小
194+
* Make a {@link AppMsg} with a custom layout. The layout must have a {@link TextView} com id {@link android.R.id.message}
195+
*
196+
* @param context The context to use. Usually your
197+
* {@link android.app.Activity} object.
198+
* @param text The text to show. Can be formatted text.
199+
* @param style The style with a background and a duration.
200+
*/
201+
public static AppMsg makeText(Activity context, CharSequence text, Style style, int layoutId, OnClickListener clickListener) {
202+
LayoutInflater inflate = (LayoutInflater)
203+
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
204+
View v = inflate.inflate(layoutId, null);
205+
206+
return makeText(context, text, style, v, true);
207+
}
208+
209+
210+
211+
/**
212+
* @author mengguoqiang
213+
* Make a {@link AppMsg} with a custom layout. The layout must have a {@link TextView} com id {@link android.R.id.message}
214+
*
215+
* @param context The context to use. Usually your
216+
* {@link android.app.Activity} object.
217+
* @param text The text to show. Can be formatted text.
218+
* @param style The style with a background and a duration.
219+
*/
220+
public static AppMsg makeText(Activity context, CharSequence text, Style style, int layoutId, float textSize, OnClickListener clickListener) {
221+
LayoutInflater inflate = (LayoutInflater)
222+
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
223+
View v = inflate.inflate(layoutId, null);
224+
225+
return makeText(context, text, style, v, true, textSize, clickListener);
226+
}
227+
228+
/**
229+
* @author mengguoqiang
166230
* Make a {@link AppMsg} with a custom layout. The layout must have a {@link TextView} com id {@link android.R.id.message}
167231
*
168232
* @param context The context to use. Usually your
@@ -177,6 +241,9 @@ public static AppMsg makeText(Activity context, CharSequence text, Style style,
177241

178242
return makeText(context, text, style, v, true, textSize);
179243
}
244+
245+
246+
180247

181248
/**
182249
* Make a non-floating {@link AppMsg} with a custom view presented inside the layout.
@@ -192,6 +259,24 @@ public static AppMsg makeText(Activity context, CharSequence text, Style style,
192259
public static AppMsg makeText(Activity context, CharSequence text, Style style, View customView) {
193260
return makeText(context, text, style, customView, false);
194261
}
262+
263+
264+
265+
/**
266+
* Make a non-floating {@link AppMsg} with a custom view presented inside the layout.
267+
* It can be used to create non-floating notifications if floating is false.
268+
*
269+
* @param context The context to use. Usually your
270+
* {@link android.app.Activity} object.
271+
* @param customView
272+
* View to be used.
273+
* @param text The text to show. Can be formatted text.
274+
* @param style The style with a background and a duration.
275+
*/
276+
public static AppMsg makeText(Activity context, CharSequence text, Style style, View customView, OnClickListener clickListener) {
277+
return makeText(context, text, style, customView, false, clickListener);
278+
}
279+
195280

196281
/**
197282
* Make a {@link AppMsg} with a custom view. It can be used to create non-floating notifications if floating is false.
@@ -208,9 +293,26 @@ private static AppMsg makeText(Activity context, CharSequence text, Style style,
208293
return makeText(context, text, style, view, floating, 0);
209294
}
210295

296+
297+
298+
/**
299+
* Make a {@link AppMsg} with a custom view. It can be used to create non-floating notifications if floating is false.
300+
*
301+
* @param context The context to use. Usually your
302+
* {@link android.app.Activity} object.
303+
* @param view
304+
* View to be used.
305+
* @param text The text to show. Can be formatted text.
306+
* @param style The style with a background and a duration.
307+
* @param floating true if it'll float.
308+
*/
309+
private static AppMsg makeText(Activity context, CharSequence text, Style style, View view, boolean floating, OnClickListener clickListener) {
310+
return makeText(context, text, style, view, floating, 0, clickListener);
311+
}
312+
211313
/**
212314
*
213-
* @author mengguoqiang 扩展支持设置字体大小
315+
* @author mengguoqiang
214316
* Make a {@link AppMsg} with a custom view. It can be used to create non-floating notifications if floating is false.
215317
*
216318
* @param context The context to use. Usually your
@@ -236,6 +338,47 @@ private static AppMsg makeText(Activity context, CharSequence text, Style style,
236338

237339
return result;
238340
}
341+
342+
343+
344+
/**
345+
*
346+
347+
* Make a {@link AppMsg} with a custom view. It can be used to create non-floating notifications if floating is false.
348+
*
349+
* @param context The context to use. Usually your
350+
* {@link android.app.Activity} object.
351+
* @param view
352+
* View to be used.
353+
* @param text The text to show. Can be formatted text.
354+
* @param style The style with a background and a duration.
355+
* @param floating true if it'll float.
356+
* @param clickListener Clicklistener
357+
*/
358+
private static AppMsg makeText(Activity context, CharSequence text, Style style, View view, boolean floating,
359+
float textSize, OnClickListener clickListener) {
360+
AppMsg result = new AppMsg(context);
361+
362+
view.setBackgroundResource(style.background);
363+
view.setClickable(true);
364+
365+
TextView tv = (TextView) view.findViewById(android.R.id.message);
366+
if(textSize > 0) tv.setTextSize(textSize);
367+
tv.setText(text);
368+
369+
result.mView = view;
370+
result.mDuration = style.duration;
371+
result.mFloating = floating;
372+
373+
view.setOnClickListener(clickListener);
374+
375+
return result;
376+
}
377+
378+
379+
380+
381+
239382

240383
/**
241384
* Make a {@link AppMsg} with a custom view. It can be used to create non-floating notifications if floating is false.

library/src/com/devspark/appmsg/MsgManager.java

100644100755
File mode changed.

0 commit comments

Comments
 (0)