|
1 | 1 | package com.dvinfosys.WidgetsExample; |
2 | 2 |
|
3 | 3 | import android.content.Context; |
| 4 | +import android.graphics.Typeface; |
| 5 | +import android.graphics.drawable.Drawable; |
4 | 6 | import android.net.Uri; |
5 | 7 | import android.os.Bundle; |
6 | 8 | import android.support.v7.app.AppCompatActivity; |
| 9 | +import android.text.Spannable; |
| 10 | +import android.text.SpannableStringBuilder; |
| 11 | +import android.text.style.StyleSpan; |
7 | 12 | import android.view.View; |
8 | 13 | import android.widget.Button; |
9 | 14 |
|
10 | 15 | import com.dvinfosys.widgets.ToastView.ToastView; |
11 | 16 | import com.dvinfosys.widgets.VideoPlayer.VPVideoPlayer; |
12 | 17 | import com.dvinfosys.widgets.VideoPlayer.VPVideoPlayerStandard; |
13 | 18 |
|
| 19 | +import static android.graphics.Typeface.BOLD_ITALIC; |
| 20 | + |
14 | 21 | public class MainActivity extends AppCompatActivity { |
15 | 22 |
|
16 | 23 | private Context context; |
@@ -55,6 +62,49 @@ public void onClick(View v) { |
55 | 62 | ToastView.success(context,"This is success ToastView",ToastView.LENGTH_SHORT).show(); |
56 | 63 | } |
57 | 64 | }); |
| 65 | + |
| 66 | + findViewById(R.id.button_normal_toast_wo_icon).setOnClickListener(new View.OnClickListener() { |
| 67 | + @Override |
| 68 | + public void onClick(View view) { |
| 69 | + ToastView.normal(MainActivity.this, "normal message without icon").show(); |
| 70 | + } |
| 71 | + }); |
| 72 | + findViewById(R.id.button_normal_toast_w_icon).setOnClickListener(new View.OnClickListener() { |
| 73 | + @Override |
| 74 | + public void onClick(View view) { |
| 75 | + Drawable icon = getResources().getDrawable(R.drawable.menu); |
| 76 | + ToastView.normal(MainActivity.this, "normal message with icon", icon).show(); |
| 77 | + } |
| 78 | + }); |
| 79 | + findViewById(R.id.button_info_toast_with_formatting).setOnClickListener(new View.OnClickListener() { |
| 80 | + @Override |
| 81 | + public void onClick(View view) { |
| 82 | + ToastView.info(MainActivity.this, getFormattedMessage()).show(); |
| 83 | + } |
| 84 | + }); |
| 85 | + findViewById(R.id.button_custom_config).setOnClickListener(new View.OnClickListener() { |
| 86 | + @Override |
| 87 | + public void onClick(View view) { |
| 88 | + ToastView.Config.getInstance() |
| 89 | + .setToastTypeface(Typeface.createFromAsset(getAssets(), "fonts/Smoothy.otf")) |
| 90 | + .allowQueue(false) |
| 91 | + .apply(); |
| 92 | + ToastView.custom(MainActivity.this, R.string.custom_message, getResources().getDrawable(R.drawable.menu), |
| 93 | + android.R.color.black, android.R.color.holo_green_light, ToastView.LENGTH_SHORT, true, true).show(); |
| 94 | + ToastView.Config.reset(); // Use this if you want to use the configuration above only once |
| 95 | + } |
| 96 | + }); |
| 97 | + } |
| 98 | + |
| 99 | + private CharSequence getFormattedMessage() { |
| 100 | + final String prefix = "Formatted "; |
| 101 | + final String highlight = "bold italic"; |
| 102 | + final String suffix = " text"; |
| 103 | + SpannableStringBuilder ssb = new SpannableStringBuilder(prefix).append(highlight).append(suffix); |
| 104 | + int prefixLen = prefix.length(); |
| 105 | + ssb.setSpan(new StyleSpan(BOLD_ITALIC), |
| 106 | + prefixLen, prefixLen + highlight.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); |
| 107 | + return ssb; |
58 | 108 | } |
59 | 109 |
|
60 | 110 | @Override |
|
0 commit comments