Skip to content

Commit

Permalink
added default font parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
smdi committed Jun 27, 2022
1 parent eb08c2d commit 0809ccf
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 830 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class FullRainbowToast {
private static final int STOP_AFTER4K = 3500;
public static final int LENGTH_SHORT = 0;
public static final int LENGTH_LONG = 1;
public static final int DEFAULT_FONT = 0;

public static void showToast(Activity activity, String titleData, String messageData,
int duration, int titleFont, int messageFont) {
Expand All @@ -42,15 +43,7 @@ public static void showToast(Activity activity, String titleData, String message
TextView title = view.findViewById(R.id.rainbowTitle);
TextView message = view.findViewById(R.id.rainbowMessage);

Typeface fontTitle = ResourcesCompat.getFont(activity, titleFont);
Typeface fontMessage = ResourcesCompat.getFont(activity, messageFont);

title.setTypeface(fontTitle);
message.setTypeface(fontMessage);

title.setText(titleData);
message.setText(messageData);

setFontByCheckingDefault(activity, titleFont, messageFont, title, message);

if(duration == LENGTH_LONG){
stopAfter = STOP_AFTER4K;
Expand All @@ -68,6 +61,21 @@ public static void showToast(Activity activity, String titleData, String message
toast.show();
}

private static void setFontByCheckingDefault(Activity activity, int titleFont, int messageFont, TextView title, TextView message) {
if(titleFont != DEFAULT_FONT) setFontForTitle(activity, titleFont, title);
if(messageFont != DEFAULT_FONT) setFontForMessage(activity, messageFont, message);
}

private static void setFontForMessage(Activity activity, int messageFont, TextView message) {
Typeface fontMessage = ResourcesCompat.getFont(activity, messageFont);
message.setTypeface(fontMessage);
}

private static void setFontForTitle(Activity activity, int titleFont, TextView title) {
Typeface fontTitle = ResourcesCompat.getFont(activity, titleFont);
title.setTypeface(fontTitle);
}

private static void setColorToText(Activity activity, TextView title, TextView message, MaterialCardView materialCardView) {

title.setTextColor(activity.getResources().getColor(R.color.fr_custom_title_text_color_lite));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class RainbowToast {
public static final String DARK = "DARK";
public static final int LENGTH_SHORT = 0;
public static final int LENGTH_LONG = 1;
public static final int DEFAULT_FONT = 0;

public static void showToast(Activity activity, String titleData, String messageData,
int duration, String type, String mode, int titleFont, int messageFont) {
Expand All @@ -46,14 +47,7 @@ public static void showToast(Activity activity, String titleData, String message
TextView title = view.findViewById(R.id.rainbowTitle);
TextView message = view.findViewById(R.id.rainbowMessage);

Typeface fontTitle = ResourcesCompat.getFont(activity, titleFont);
Typeface fontMessage = ResourcesCompat.getFont(activity, messageFont);

title.setTypeface(fontTitle);
message.setTypeface(fontMessage);

title.setText(titleData);
message.setText(messageData);
setFontByCheckingDefault(activity, titleFont, messageFont, title, message);

if(duration == LENGTH_LONG){
stopAfter = STOP_AFTER4K;
Expand All @@ -71,6 +65,21 @@ public static void showToast(Activity activity, String titleData, String message
toast.show();
}

private static void setFontByCheckingDefault(Activity activity, int titleFont, int messageFont, TextView title, TextView message) {
if(titleFont != DEFAULT_FONT) setFontForTitle(activity, titleFont, title);
if(messageFont != DEFAULT_FONT) setFontForMessage(activity, messageFont, message);
}

private static void setFontForMessage(Activity activity, int messageFont, TextView message) {
Typeface fontMessage = ResourcesCompat.getFont(activity, messageFont);
message.setTypeface(fontMessage);
}

private static void setFontForTitle(Activity activity, int titleFont, TextView title) {
Typeface fontTitle = ResourcesCompat.getFont(activity, titleFont);
title.setTypeface(fontTitle);
}

private static void setColorToCard(MaterialCardView materialCardView, Activity activity, int colorBackground, int colorStroke, TextView title, int titleColor){
title.setTextColor(activity.getResources().getColor(titleColor));
materialCardView.setCardBackgroundColor(activity.getResources().getColor(colorBackground));
Expand Down
12 changes: 1 addition & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.RainbowToast"
tools:targetApi="31" >
<activity
android:name=".MainActivity"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
tools:targetApi="31" ></application>

</manifest>
120 changes: 0 additions & 120 deletions app/src/main/java/com/rainbowtoast/FullRainbowToast.java

This file was deleted.

15 changes: 0 additions & 15 deletions app/src/main/java/com/rainbowtoast/MainActivity.java

This file was deleted.

Loading

0 comments on commit 0809ccf

Please sign in to comment.