Files
logic-puzzle/app/src/main/java/com/lumen/daily/HomeArtwork.java
T
2026-10-31 03:28:48 +01:00

55 lines
3.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.lumen.daily;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
/** Original watercolour assets with crisp native handwriting on the cover label. */
final class HomeArtwork {
private static Bitmap harbour, cover;
private static Bitmap load(Context context, int resource) {
BitmapFactory.Options options=new BitmapFactory.Options(); options.inScaled=false; options.inSampleSize=2;
return BitmapFactory.decodeResource(context.getResources(),resource,options);
}
static ImageView harbour(Context context) {
if(harbour==null)harbour=load(context,R.drawable.home_harbour);
ImageView image=new ImageView(context);image.setImageBitmap(harbour);image.setScaleType(ImageView.ScaleType.FIT_CENTER);
image.setContentDescription("Watercolour of the island at dusk, the lighthouse beam crossing the bay to Gran’s cottage.");
return image;
}
static final class Cover extends ViewGroup {
private final ImageView picture;
private final TextView label;
private int imageLeft,imageTop,imageWidth,imageHeight;
Cover(Context context) {
super(context);
if(cover==null)cover=load(context,R.drawable.home_notebook_cover);
picture=new ImageView(context);picture.setImageBitmap(cover);picture.setScaleType(ImageView.ScaleType.FIT_CENTER);
picture.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
label=new TextView(context);label.setText("Mara’s\nisland notebook");label.setTypeface(JournalArt.HAND);label.setTextSize(25);
label.setRotation(-2.5f);
label.setTextColor(JournalArt.INK);label.setGravity(Gravity.CENTER);label.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
addView(picture);addView(label);
}
@Override protected void onMeasure(int widthSpec,int heightSpec) {
int w=MeasureSpec.getSize(widthSpec),h=MeasureSpec.getSize(heightSpec);setMeasuredDimension(w,h);
float scale=Math.min(w/(float)cover.getWidth(),h/(float)cover.getHeight());
imageWidth=Math.round(cover.getWidth()*scale);imageHeight=Math.round(cover.getHeight()*scale);
imageLeft=(w-imageWidth)/2;imageTop=(h-imageHeight)/2;
picture.measure(MeasureSpec.makeMeasureSpec(w,MeasureSpec.EXACTLY),MeasureSpec.makeMeasureSpec(h,MeasureSpec.EXACTLY));
label.measure(MeasureSpec.makeMeasureSpec(Math.round(imageWidth*.49f),MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(Math.round(imageHeight*.34f),MeasureSpec.EXACTLY));
}
@Override protected void onLayout(boolean changed,int left,int top,int right,int bottom) {
picture.layout(0,0,getWidth(),getHeight());
int x=imageLeft+Math.round(imageWidth*.27f),y=imageTop+Math.round(imageHeight*.32f);
label.layout(x,y,x+label.getMeasuredWidth(),y+label.getMeasuredHeight());
}
}
private HomeArtwork(){}
}