Files
edc-monitoring-android-app/app/src/main/java/com/example/bdkipoc/StyleHelper.java
2025-06-10 12:10:35 +07:00

106 lines
4.8 KiB
Java

package com.example.bdkipoc;
import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.core.content.ContextCompat;
public class StyleHelper {
/**
* Create rounded rectangle drawable programmatically
*/
public static GradientDrawable createRoundedDrawable(int color, int strokeColor, int strokeWidth, int radius) {
GradientDrawable drawable = new GradientDrawable();
drawable.setShape(GradientDrawable.RECTANGLE);
drawable.setColor(color);
drawable.setStroke(strokeWidth, strokeColor);
drawable.setCornerRadius(radius);
return drawable;
}
/**
* Apply search input styling
*/
public static void applySearchInputStyle(View view, Context context) {
int white = ContextCompat.getColor(context, android.R.color.white);
int lightGrey = ContextCompat.getColor(context, android.R.color.darker_gray);
// ✅ IMPROVED: Larger corner radius and lighter border like in the image
GradientDrawable drawable = createRoundedDrawable(white, lightGrey, 1, 75); // 25dp radius, thinner border
view.setBackground(drawable);
}
/**
* Apply filter button styling
*/
public static void applyFilterButtonStyle(View view, Context context) {
int white = ContextCompat.getColor(context, android.R.color.white);
int lightGrey = ContextCompat.getColor(context, android.R.color.darker_gray);
// ✅ IMPROVED: Larger corner radius like in the image
GradientDrawable drawable = createRoundedDrawable(white, lightGrey, 1, 75); // 25dp radius, thinner border
view.setBackground(drawable);
}
/**
* Apply pagination button styling (simple version)
*/
public static void applyPaginationButtonStyle(View view, Context context, boolean isActive) {
int backgroundColor, strokeColor;
if (isActive) {
backgroundColor = ContextCompat.getColor(context, android.R.color.holo_red_dark);
strokeColor = ContextCompat.getColor(context, android.R.color.holo_red_dark);
} else {
backgroundColor = ContextCompat.getColor(context, android.R.color.white);
strokeColor = ContextCompat.getColor(context, android.R.color.transparent);
}
// ✅ IMPROVED: Larger corner radius for modern look (like in the image)
GradientDrawable drawable = createRoundedDrawable(backgroundColor, strokeColor, 0, 48); // 16dp radius
view.setBackground(drawable);
// Set text color if it's a TextView
if (view instanceof TextView) {
int textColor = isActive ?
ContextCompat.getColor(context, android.R.color.white) :
ContextCompat.getColor(context, android.R.color.black);
((TextView) view).setTextColor(textColor);
}
}
/**
* Apply status text color only (no background badge)
*/
public static void applyStatusTextColor(TextView textView, Context context, String status) {
String statusLower = status != null ? status.toLowerCase() : "";
int textColor;
if (statusLower.equals("failed") || statusLower.equals("failure") ||
statusLower.equals("error") || statusLower.equals("declined") ||
statusLower.equals("expire") || statusLower.equals("cancel")) {
// Red text for failed/error statuses
textColor = ContextCompat.getColor(context, android.R.color.holo_red_dark);
} else if (statusLower.equals("success") || statusLower.equals("paid") ||
statusLower.equals("settlement") || statusLower.equals("completed") ||
statusLower.equals("capture")) {
// Green text for successful statuses
textColor = ContextCompat.getColor(context, android.R.color.holo_green_dark);
} else if (statusLower.equals("pending") || statusLower.equals("processing") ||
statusLower.equals("waiting") || statusLower.equals("checking...") ||
statusLower.equals("checking")) {
// Orange text for pending/processing statuses
textColor = ContextCompat.getColor(context, android.R.color.holo_orange_dark);
} else if (statusLower.equals("init")) {
// Blue text for init status
textColor = ContextCompat.getColor(context, android.R.color.holo_blue_dark);
} else {
// Default gray text for unknown statuses
textColor = ContextCompat.getColor(context, android.R.color.darker_gray);
}
textView.setTextColor(textColor);
textView.setBackground(null); // Remove any background
}
}