Skip to content

Commit 370986e

Browse files
committed
Merge pull request #17 from dreamer0924/master
add font size support
2 parents b2ad32b + 2c8a72c commit 370986e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,19 @@ public AppMsg(Activity context) {
9292
public static AppMsg makeText(Activity context, CharSequence text, Style style) {
9393
return makeText(context, text, style, R.layout.app_msg);
9494
}
95+
96+
/**
97+
* @author mengguoqiang 扩展支持设置字体大小
98+
* Make a {@link AppMsg} that just contains a text view.
99+
*
100+
* @param context The context to use. Usually your
101+
* {@link android.app.Activity} object.
102+
* @param text The text to show. Can be formatted text.
103+
* @param style The style with a background and a duration.
104+
*/
105+
public static AppMsg makeText(Activity context, CharSequence text, Style style, float textSize) {
106+
return makeText(context, text, style, R.layout.app_msg, textSize);
107+
}
95108

96109
/**
97110
* Make a {@link AppMsg} with a custom layout. The layout must have a {@link TextView} com id {@link android.R.id.message}
@@ -108,6 +121,23 @@ public static AppMsg makeText(Activity context, CharSequence text, Style style,
108121

109122
return makeText(context, text, style, v, true);
110123
}
124+
125+
/**
126+
* @author mengguoqiang 扩展支持字体大小
127+
* Make a {@link AppMsg} with a custom layout. The layout must have a {@link TextView} com id {@link android.R.id.message}
128+
*
129+
* @param context The context to use. Usually your
130+
* {@link android.app.Activity} object.
131+
* @param text The text to show. Can be formatted text.
132+
* @param style The style with a background and a duration.
133+
*/
134+
public static AppMsg makeText(Activity context, CharSequence text, Style style, int layoutId, float textSize) {
135+
LayoutInflater inflate = (LayoutInflater)
136+
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
137+
View v = inflate.inflate(layoutId, null);
138+
139+
return makeText(context, text, style, v, true, textSize);
140+
}
111141

112142
/**
113143
* Make a non-floating {@link AppMsg} with a custom view presented inside the layout.
@@ -136,11 +166,29 @@ public static AppMsg makeText(Activity context, CharSequence text, Style style,
136166
* @param floating true if it'll float.
137167
*/
138168
private static AppMsg makeText(Activity context, CharSequence text, Style style, View view, boolean floating) {
169+
return makeText(context, text, style, view, floating, 0);
170+
}
171+
172+
/**
173+
*
174+
* @author mengguoqiang 扩展支持设置字体大小
175+
* Make a {@link AppMsg} with a custom view. It can be used to create non-floating notifications if floating is false.
176+
*
177+
* @param context The context to use. Usually your
178+
* {@link android.app.Activity} object.
179+
* @param view
180+
* View to be used.
181+
* @param text The text to show. Can be formatted text.
182+
* @param style The style with a background and a duration.
183+
* @param floating true if it'll float.
184+
*/
185+
private static AppMsg makeText(Activity context, CharSequence text, Style style, View view, boolean floating, float textSize) {
139186
AppMsg result = new AppMsg(context);
140187

141188
view.setBackgroundResource(style.background);
142189

143190
TextView tv = (TextView) view.findViewById(android.R.id.message);
191+
if(textSize > 0) tv.setTextSize(textSize);
144192
tv.setText(text);
145193

146194
result.mView = view;

0 commit comments

Comments
 (0)