switch bankMode first attempt
This commit is contained in:
parent
a3782a09b6
commit
a9a9c22899
|
@ -1,7 +1,16 @@
|
|||
package com.dspread.pos.common.adapters;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.LinearGradient;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Shader;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
@ -124,4 +133,108 @@ public class BindingAdapters {
|
|||
}
|
||||
|
||||
|
||||
@BindingAdapter("android:background")
|
||||
public static void setBackgroundResource(View view, ObservableField<Integer> backgroundResId) {
|
||||
if (backgroundResId != null && backgroundResId.get() != null) {
|
||||
view.setBackgroundResource(backgroundResId.get());
|
||||
}
|
||||
}
|
||||
|
||||
// Optional: Also add one for regular Integer for flexibility
|
||||
@BindingAdapter("android:background")
|
||||
public static void setBackgroundResource(View view, Integer resourceId) {
|
||||
if (resourceId != null) {
|
||||
view.setBackgroundResource(resourceId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@BindingAdapter({"android:src", "primaryColor", "secondaryColor", "isBankMode"})
|
||||
public static void setIconWithGradientTint(ImageView imageView, Object icon,
|
||||
String primaryColor, String secondaryColor,
|
||||
Boolean isBankMode) {
|
||||
// Set the icon first
|
||||
if (icon instanceof Integer) {
|
||||
imageView.setImageResource((Integer) icon);
|
||||
} else if (icon instanceof Bitmap) {
|
||||
imageView.setImageBitmap((Bitmap) icon);
|
||||
}
|
||||
|
||||
// Remove any previous color filter
|
||||
imageView.setColorFilter(null);
|
||||
|
||||
// Apply gradient tint or remove filter
|
||||
if (false) {
|
||||
// No tint in bank mode - already cleared above
|
||||
} else if (primaryColor != null && secondaryColor != null) {
|
||||
try {
|
||||
// Parse colors
|
||||
int startColor = Color.parseColor(primaryColor);
|
||||
int endColor = Color.parseColor(secondaryColor);
|
||||
|
||||
// Create a temporary bitmap to apply gradient
|
||||
applyGradientToImageView(imageView, startColor, endColor);
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Fallback to single color if gradient fails
|
||||
if (primaryColor != null) {
|
||||
try {
|
||||
int color = Color.parseColor(primaryColor);
|
||||
imageView.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (primaryColor != null) {
|
||||
try {
|
||||
int color = Color.parseColor(primaryColor);
|
||||
imageView.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyGradientToImageView(ImageView imageView, int startColor, int endColor) {
|
||||
Drawable drawable = imageView.getDrawable();
|
||||
if (drawable == null) return;
|
||||
|
||||
// Get drawable dimensions
|
||||
int width = drawable.getIntrinsicWidth();
|
||||
int height = drawable.getIntrinsicHeight();
|
||||
|
||||
if (width <= 0) width = 100;
|
||||
if (height <= 0) height = 100;
|
||||
|
||||
// Create gradient bitmap
|
||||
Bitmap gradientBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
Canvas gradientCanvas = new Canvas(gradientBitmap);
|
||||
|
||||
Paint gradientPaint = new Paint();
|
||||
LinearGradient gradient = new LinearGradient(
|
||||
0, 0, 0, height, // Top to bottom
|
||||
startColor, endColor,
|
||||
Shader.TileMode.CLAMP
|
||||
);
|
||||
gradientPaint.setShader(gradient);
|
||||
gradientCanvas.drawRect(0, 0, width, height, gradientPaint);
|
||||
|
||||
// Create icon bitmap
|
||||
Bitmap iconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
Canvas iconCanvas = new Canvas(iconBitmap);
|
||||
drawable.setBounds(0, 0, width, height);
|
||||
drawable.draw(iconCanvas);
|
||||
|
||||
// Combine gradient and icon using SRC_IN mode
|
||||
Paint combinePaint = new Paint();
|
||||
combinePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
||||
|
||||
Canvas resultCanvas = new Canvas(iconBitmap);
|
||||
resultCanvas.drawBitmap(gradientBitmap, 0, 0, combinePaint);
|
||||
|
||||
imageView.setImageBitmap(iconBitmap);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,7 +1,10 @@
|
|||
package com.dspread.pos.ui.mulberry;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.databinding.Observable;
|
||||
import androidx.databinding.ObservableField;
|
||||
|
||||
import com.dspread.pos.utils.PosParameters;
|
||||
|
@ -17,6 +20,11 @@ public class MulberryItemViewModel extends ItemViewModel<MulberryViewModel> {
|
|||
// Display properties
|
||||
public final ObservableField<String> title = new ObservableField<>();
|
||||
public final ObservableField<Object> icon = new ObservableField<>(); // Can be Integer(resId), Bitmap, or String(path)
|
||||
public final ObservableField<Boolean> bankMode = new ObservableField<>(false);
|
||||
public final ObservableField<Integer> textColor = new ObservableField<>(Color.WHITE);
|
||||
public final ObservableField<String> primaryColor = new ObservableField<>("#000000");
|
||||
public final ObservableField<String> secondaryColor = new ObservableField<>("#000000");
|
||||
|
||||
|
||||
|
||||
// Click handler
|
||||
|
@ -24,6 +32,8 @@ public class MulberryItemViewModel extends ItemViewModel<MulberryViewModel> {
|
|||
viewModel.onItemClick(this);
|
||||
});
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Master constructor for all navigation items
|
||||
* @param viewModel Parent ViewModel
|
||||
|
@ -42,7 +52,33 @@ public class MulberryItemViewModel extends ItemViewModel<MulberryViewModel> {
|
|||
this.activityClass = activityClass;
|
||||
this.title.set(title);
|
||||
this.icon.set(iconSource);
|
||||
this.primaryColor.set(viewModel.primaryColor.get());
|
||||
this.secondaryColor.set(viewModel.secondaryColor.get());
|
||||
|
||||
|
||||
// Initialize with parent's bankMode value
|
||||
if (viewModel != null && viewModel.bankMode != null) {
|
||||
this.bankMode.set(viewModel.bankMode.get());
|
||||
|
||||
// Listen for parent bankMode changes
|
||||
viewModel.bankMode.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
|
||||
@Override
|
||||
public void onPropertyChanged(Observable sender, int propertyId) {
|
||||
bankMode.set(viewModel.bankMode.get());
|
||||
updateTextColor();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updateTextColor();
|
||||
|
||||
}
|
||||
private void updateTextColor() {
|
||||
if (Boolean.TRUE.equals(bankMode.get())) {
|
||||
textColor.set(Color.BLACK);
|
||||
} else {
|
||||
textColor.set(Color.WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ import static com.dspread.pos.utils.PosParameters.NAV_HOME;
|
|||
import android.app.Application;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
@ -67,6 +68,9 @@ public class MulberryViewModel extends BaseAppViewModel {
|
|||
public final ObservableField<Boolean> logoVisibility = PosParameters.footerLogoVisibility;
|
||||
public final ObservableField<Boolean> logoTextVisibility = PosParameters.footerTextVisibility;
|
||||
public final ObservableField<Boolean> bankMode = PosParameters.bankmode;
|
||||
public final ObservableField<Integer> backgroundResId = new ObservableField<>();
|
||||
public final ObservableField<Integer> footerTextColor = new ObservableField<>(Color.WHITE);
|
||||
|
||||
public final ObservableField<String> greetingText = PosParameters.footerGreetingText;
|
||||
public final ObservableField<String> footerText = PosParameters.footerText;
|
||||
public final ObservableField<String> primaryColor = PosParameters.primaryColor;
|
||||
|
@ -93,6 +97,22 @@ public class MulberryViewModel extends BaseAppViewModel {
|
|||
Log.d(TAG, "MulberryViewModel constructor called");
|
||||
|
||||
|
||||
// Initialize background
|
||||
backgroundResId.set(R.drawable.wallpaper_8f25c3);
|
||||
|
||||
// Add listener to bankMode changes
|
||||
bankMode.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
|
||||
@Override
|
||||
public void onPropertyChanged(Observable sender, int propertyId) {
|
||||
if (Boolean.TRUE.equals(bankMode.get())) {
|
||||
Log.d(TAG, "background for bankmode");
|
||||
backgroundResId.set(R.drawable.keyboard_keybg_white);
|
||||
} else {
|
||||
backgroundResId.set(R.drawable.white_wallpaper);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Add this to track initialization
|
||||
Log.d(TAG, "ViewModel hash: " + this.hashCode());
|
||||
// if (Build.MODEL.equalsIgnoreCase("D70") ||
|
||||
|
@ -122,6 +142,16 @@ public class MulberryViewModel extends BaseAppViewModel {
|
|||
initialize();
|
||||
}
|
||||
|
||||
public void updateBackground() {
|
||||
if (Boolean.TRUE.equals(bankMode.get())) {
|
||||
backgroundResId.set(R.drawable.keyboard_keybg_white);
|
||||
footerTextColor.set(Color.BLACK);
|
||||
} else {
|
||||
backgroundResId.set(R.drawable.wallpaper_8f25c3);
|
||||
footerTextColor.set(Color.WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
public void adjustMulberryView(ImageView logoImageView,
|
||||
LinearLayout containerLayout,
|
||||
LinearLayout footerContainer,
|
||||
|
@ -226,8 +256,17 @@ public class MulberryViewModel extends BaseAppViewModel {
|
|||
if (fullRefresh) {
|
||||
imagesLoaded.postValue(true);
|
||||
}
|
||||
|
||||
// Your existing code...
|
||||
bankMode.set(PosParameters.bankmode.get());
|
||||
|
||||
// Add this line to update background when config changes
|
||||
updateBackground();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void updateMainConfig(boolean loadImages) {
|
||||
Log.d(TAG, "Updating main configuration");
|
||||
|
||||
|
@ -244,6 +283,8 @@ public class MulberryViewModel extends BaseAppViewModel {
|
|||
|
||||
if (Boolean.TRUE.equals(bankMode.get())){
|
||||
Log.d(TAG, "bankMode is: zzzzz " + bankMode.get());
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Load images if requested
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.4 MiB |
|
@ -17,12 +17,13 @@
|
|||
<!-- binding:onClickCommand="@{viewModel.actionCommand}"-->
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/full_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
android:padding="16dp"
|
||||
android:gravity="center"
|
||||
android:background="@drawable/wallpaper_8f25c3"
|
||||
android:background="@{viewModel.backgroundResId}"
|
||||
app:layout_constraintVertical_chainStyle="packed"
|
||||
app:layout_constraintHorizontal_chainStyle="packed">
|
||||
|
||||
|
@ -180,7 +181,7 @@
|
|||
app:layout_constraintEnd_toEndOf="parent">
|
||||
|
||||
<TextView
|
||||
android:textColor="@color/white"
|
||||
android:textColor="@{viewModel.footerTextColor}"
|
||||
android:id="@+id/footertext"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -32,11 +32,14 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="100dp"
|
||||
android:src="@{viewModel.icon}"
|
||||
app:primaryColor="@{viewModel.primaryColor}"
|
||||
app:secondaryColor="@{viewModel.secondaryColor}"
|
||||
app:isBankMode="@{viewModel.bankMode}"
|
||||
android:scaleType="fitCenter"
|
||||
tools:src="@drawable/ax_card_grey" /> <!-- Use your actual default drawable -->
|
||||
|
||||
<TextView
|
||||
android:textColor="@color/white"
|
||||
android:textColor="@{viewModel.textColor}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
|
|
Loading…
Reference in New Issue