diff options
Diffstat (limited to 'app/src/main/java/mygram/droid/Ui.java')
| -rw-r--r-- | app/src/main/java/mygram/droid/Ui.java | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/app/src/main/java/mygram/droid/Ui.java b/app/src/main/java/mygram/droid/Ui.java index 586aa65..ab6db38 100644 --- a/app/src/main/java/mygram/droid/Ui.java +++ b/app/src/main/java/mygram/droid/Ui.java @@ -18,9 +18,11 @@ import android.content.Context; import android.graphics.Color; import android.graphics.RenderEffect; import android.graphics.Shader; +import android.graphics.drawable.GradientDrawable; import android.text.InputType; import android.view.Gravity; import android.view.View; +import android.view.ViewGroup; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; @@ -36,6 +38,8 @@ import java.util.List; /** View helpers. The UI is built in code, there are no layout files. */ final class Ui { static final int RED = 0xFFFF3B5C; + /** Pink end of the app icon gradient. */ + static final int ACCENT = 0xFFEC4899; /** Post tiles: portrait, most media is 9:16. */ static final int POST_W = 128, POST_H = 228; @@ -97,7 +101,10 @@ final class Ui { v.animate().scaleX(in ? 1.08f : 1f).scaleY(in ? 1.08f : 1f).setDuration(120).start(); } - /** Icon-only button; its label shows under it while it has focus. Child 0 is the ImageView. */ + /** + * Icon-only button. Focus scales the icon and turns it accent pink, and + * shows the label under it. Child 1 is the current-view mark. + */ static LinearLayout iconButton(Context c, int icon, String label, View.OnClickListener click) { LinearLayout box = new LinearLayout(c); box.setOrientation(LinearLayout.VERTICAL); @@ -107,21 +114,44 @@ final class Ui { ImageView image = new ImageView(c); image.setImageResource(icon); image.setContentDescription(label); + image.setAlpha(0.7f); int s = dp(c, 36); box.addView(image, new LinearLayout.LayoutParams(s, s)); + GradientDrawable bar = new GradientDrawable(); + bar.setColor(ACCENT); + bar.setCornerRadius(dp(c, 2)); + View mark = new View(c); + mark.setBackground(bar); + mark.setVisibility(View.INVISIBLE); + LinearLayout.LayoutParams mp = new LinearLayout.LayoutParams(dp(c, 20), dp(c, 3)); + mp.topMargin = dp(c, 6); + box.addView(mark, mp); TextView t = text(c, label, 12); + t.setSingleLine(true); t.setVisibility(View.INVISIBLE); - box.addView(t); + // WRAP_CONTENT: the vertical default, MATCH_PARENT, does not widen the box, so long labels were clipped + box.addView(t, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT)); + boolean tint = icon != R.drawable.ic_launcher; // the logo keeps its colours box.setFocusable(true); - box.setBackground(c.getDrawable(R.drawable.focus_glow)); box.setOnFocusChangeListener((v, has) -> { t.setVisibility(has ? View.VISIBLE : View.INVISIBLE); - zoom(v, has); + image.setAlpha(has ? 1f : 0.7f); + if (tint && has) + image.setColorFilter(ACCENT); + else + image.clearColorFilter(); + image.animate().scaleX(has ? 1.25f : 1f).scaleY(has ? 1.25f : 1f).setDuration(120).start(); }); box.setOnClickListener(click); return box; } + /** Shows or hides the mark under an iconButton that stands for the current view. */ + static void markCurrent(LinearLayout button, boolean current) { + button.getChildAt(1).setVisibility(current ? View.VISIBLE : View.INVISIBLE); + } + static void blur(ImageView v, float radius) { v.setRenderEffect(RenderEffect.createBlurEffect(radius, radius, Shader.TileMode.CLAMP)); } |
