mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-04-04 07:41:40 -04:00
using icon on card view headers
This commit is contained in:
committed by
Katharine Chui
parent
74157b2fe5
commit
cb5a98edad
@@ -23,6 +23,7 @@ import android.view.WindowManager;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
@@ -71,6 +72,10 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
|
||||
ImageButton minimizeButton;
|
||||
View collapsingToolbarLayout;
|
||||
AppBarLayout appBarLayout;
|
||||
ImageView iconImage;
|
||||
RelativeLayout relativeLayout;
|
||||
Toolbar landscapeToolbar;
|
||||
|
||||
int loyaltyCardId;
|
||||
LoyaltyCard loyaltyCard;
|
||||
boolean rotationEnabled;
|
||||
@@ -101,6 +106,8 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
|
||||
static final String STATE_IMAGEINDEX = "imageIndex";
|
||||
static final String STATE_FULLSCREEN = "isFullscreen";
|
||||
|
||||
private final int HEADER_FILTER_ALPHA = 70;
|
||||
|
||||
final private TaskHandler mTasks = new TaskHandler();
|
||||
|
||||
@Override
|
||||
@@ -259,6 +266,9 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
|
||||
minimizeButton = findViewById(R.id.minimizeButton);
|
||||
collapsingToolbarLayout = findViewById(R.id.collapsingToolbarLayout);
|
||||
appBarLayout = findViewById(R.id.app_bar_layout);
|
||||
iconImage = findViewById(R.id.icon_image);
|
||||
relativeLayout = findViewById(R.id.relative_layout);
|
||||
landscapeToolbar = findViewById(R.id.toolbar_landscape);
|
||||
|
||||
centerGuideline = findViewById(R.id.centerGuideline);
|
||||
barcodeScaler = findViewById(R.id.barcodeScaler);
|
||||
@@ -366,6 +376,34 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
|
||||
}
|
||||
});
|
||||
|
||||
// synchronizing iconImage size with it's layer above
|
||||
collapsingToolbarLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
Log.d("onLayoutChange", "collapsing toolbar change, height: " + v.getHeight());
|
||||
// on android 11, setAdjustViewBounds on the imageView triggers this callback again to my horror, so adding an if to block it
|
||||
if(iconImage.getHeight() != v.getHeight()) {
|
||||
// setAdjustViewBounds and scale type breaks when an image is set, then the following has to be execute in this order
|
||||
iconImage.setAdjustViewBounds(true);
|
||||
iconImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
iconImage.setMaxHeight(v.getHeight());
|
||||
iconImage.setMaxWidth(v.getWidth());
|
||||
}
|
||||
}
|
||||
});
|
||||
landscapeToolbar.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
Log.d("onLayoutChange", "landscape toolbar change, height: " + v.getHeight());
|
||||
if(iconImage.getHeight() != v.getHeight()) {
|
||||
iconImage.setAdjustViewBounds(true);
|
||||
iconImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
iconImage.setMaxHeight(v.getHeight());
|
||||
iconImage.setMaxWidth(v.getWidth());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mGestureDetector = new GestureDetector(this, this);
|
||||
View.OnTouchListener gestureTouchListener = (v, event) -> mGestureDetector.onTouchEvent(event);
|
||||
mainImage.setOnTouchListener(gestureTouchListener);
|
||||
@@ -501,7 +539,6 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
|
||||
backgroundHeaderColor = LetterBitmap.getDefaultColor(this, loyaltyCard.store);
|
||||
}
|
||||
|
||||
collapsingToolbarLayout.setBackgroundColor(backgroundHeaderColor);
|
||||
appBarLayout.setBackgroundColor(backgroundHeaderColor);
|
||||
|
||||
int textColor;
|
||||
@@ -513,6 +550,24 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
|
||||
storeName.setTextColor(textColor);
|
||||
((Toolbar) findViewById(R.id.toolbar_landscape)).setTitleTextColor(textColor);
|
||||
|
||||
Bitmap icon = Utils.retrieveCardImage(this, loyaltyCard.id, ImageLocationType.icon);
|
||||
if (icon != null){
|
||||
int backgroundAlphaColor = Utils.needsDarkForeground(backgroundHeaderColor) ? Color.WHITE : Color.BLACK;
|
||||
Log.d("onResume", "setting icon image");
|
||||
iconImage.setImageBitmap(icon);
|
||||
int backgroundWithAlpha = Color.argb(HEADER_FILTER_ALPHA, Color.red(backgroundAlphaColor), Color.green(backgroundAlphaColor), Color.blue(backgroundAlphaColor));
|
||||
collapsingToolbarLayout.setBackgroundColor(backgroundWithAlpha);
|
||||
landscapeToolbar.setBackgroundColor(backgroundWithAlpha);
|
||||
// for images that has alpha
|
||||
iconImage.setBackgroundColor(backgroundWithAlpha);
|
||||
}else{
|
||||
Bitmap plain = Bitmap.createBitmap(new int[]{backgroundHeaderColor}, 1, 1, Bitmap.Config.ARGB_8888);
|
||||
iconImage.setImageBitmap(plain);
|
||||
collapsingToolbarLayout.setBackgroundColor(Color.TRANSPARENT);
|
||||
landscapeToolbar.setBackgroundColor(Color.TRANSPARENT);
|
||||
iconImage.setBackgroundColor(Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
// If the background is very bright, we should use dark icons
|
||||
backgroundNeedsDarkIcons = Utils.needsDarkForeground(backgroundHeaderColor);
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
@@ -820,6 +875,8 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
|
||||
actionBar.hide();
|
||||
}
|
||||
|
||||
iconImage.setVisibility(View.GONE);
|
||||
|
||||
// Hide toolbars
|
||||
//
|
||||
// Appbar needs to be invisible and have padding removed
|
||||
@@ -860,6 +917,8 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
|
||||
actionBar.show();
|
||||
}
|
||||
|
||||
iconImage.setVisibility(View.VISIBLE);
|
||||
|
||||
// Show appropriate toolbar
|
||||
// And restore 24dp paddingTop for appBarLayout
|
||||
appBarLayout.setVisibility(View.VISIBLE);
|
||||
|
||||
@@ -61,8 +61,8 @@ public class Utils {
|
||||
|
||||
static final double LUMINANCE_MIDPOINT = 0.5;
|
||||
|
||||
static final int BITMAP_SIZE_SMALL = 64;
|
||||
static final int BITMAP_SIZE_BIG = 512;
|
||||
static final int BITMAP_SIZE_SMALL = 512;
|
||||
static final int BITMAP_SIZE_BIG = 2045;
|
||||
|
||||
static public LetterBitmap generateIcon(Context context, LoyaltyCard loyaltyCard, boolean forShortcut) {
|
||||
return generateIcon(context, loyaltyCard.store, loyaltyCard.headerColor, forShortcut);
|
||||
|
||||
@@ -244,50 +244,73 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:weightSum="1.0"
|
||||
android:fitsSystemWindows="true">
|
||||
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
android:id="@+id/collapsingToolbarLayout"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:layout_width="fill_parent"
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/relative_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="56.0dip"
|
||||
android:layout_weight="1.0"
|
||||
app:expandedTitleMarginStart="48dp"
|
||||
app:expandedTitleMarginEnd="64dp"
|
||||
app:contentScrim="?colorPrimary"
|
||||
app:expandedTitleGravity="top">
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/storeName"
|
||||
android:layout_weight="1.0">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="40sp"
|
||||
android:textAlignment="center"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="?actionBarSize"
|
||||
android:layout_marginBottom="?actionBarSize"
|
||||
app:layout_collapseMode="parallax"
|
||||
android:fitsSystemWindows="true"/>
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentTop="true"
|
||||
android:scaleType="centerCrop"
|
||||
app:srcCompat="@drawable/ic_launcher_foreground"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@id/toolbar"
|
||||
android:background="@android:color/transparent"
|
||||
android:theme="@style/CardView.ActionBarTheme"
|
||||
android:id="@+id/toolbar_landscape"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="?actionBarSize"
|
||||
android:layout_alignParentTop="true"
|
||||
android:background="@android:color/transparent"
|
||||
android:paddingTop="6dp"
|
||||
android:theme="@style/CardView.ActionBarTheme"
|
||||
android:visibility="gone"
|
||||
app:contentInsetStart="72.0dip"
|
||||
app:layout_collapseMode="pin" />
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar_landscape"
|
||||
android:visibility="gone"
|
||||
android:background="@android:color/transparent"
|
||||
android:theme="@style/CardView.ActionBarTheme"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="?actionBarSize"
|
||||
app:contentInsetStart="72.0dip"
|
||||
app:layout_collapseMode="pin"
|
||||
android:paddingTop="6dp" />
|
||||
|
||||
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
android:id="@+id/collapsingToolbarLayout"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:minHeight="56.0dip"
|
||||
app:contentScrim="?colorPrimary"
|
||||
app:expandedTitleGravity="top"
|
||||
app:expandedTitleMarginEnd="64dp"
|
||||
app:expandedTitleMarginStart="48dp">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/storeName"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="?actionBarSize"
|
||||
android:layout_marginBottom="?actionBarSize"
|
||||
android:ellipsize="end"
|
||||
android:fitsSystemWindows="true"
|
||||
android:maxLines="1"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="40sp"
|
||||
app:layout_collapseMode="parallax" />
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@id/toolbar"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="?actionBarSize"
|
||||
android:background="@android:color/transparent"
|
||||
android:theme="@style/CardView.ActionBarTheme"
|
||||
app:contentInsetStart="72.0dip"
|
||||
app:layout_collapseMode="pin" />
|
||||
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
Reference in New Issue
Block a user