diff --git a/app/src/main/java/ch/blinkenlights/android/vanilla/LibraryActivity.java b/app/src/main/java/ch/blinkenlights/android/vanilla/LibraryActivity.java index 981ddbaa..4a8c4a5c 100644 --- a/app/src/main/java/ch/blinkenlights/android/vanilla/LibraryActivity.java +++ b/app/src/main/java/ch/blinkenlights/android/vanilla/LibraryActivity.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2012 Christopher Eby - * Copyright (C) 2015-2019 Adrian Ulrich + * Copyright (C) 2015-2020 Adrian Ulrich * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,6 +26,7 @@ package ch.blinkenlights.android.vanilla; import ch.blinkenlights.android.medialibrary.MediaLibrary; import ch.blinkenlights.android.vanilla.ui.FancyMenu; import ch.blinkenlights.android.vanilla.ui.FancyMenuItem; +import ch.blinkenlights.android.vanilla.ui.ArrowedText; import android.app.AlertDialog; import android.content.DialogInterface; @@ -35,7 +36,6 @@ import android.content.res.Resources; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Color; -import android.graphics.drawable.PaintDrawable; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -506,28 +506,62 @@ public class LibraryActivity Limiter limiterData = mPagerAdapter.getCurrentLimiter(); if (limiterData != null) { + final int arrowWidth = 8; String[] limiter = limiterData.names; - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); - params.leftMargin = 5; for (int i = 0; i != limiter.length; ++i) { - int color = (i+1 == limiter.length ? 0xFFA0A0A0 : 0xFFC0C0C0); - PaintDrawable background = new PaintDrawable(color); - background.setCornerRadius(0); + final boolean last = i+1 == limiter.length; + final boolean first = i == 0; + + String txt = limiter[i]; + ArrowedText view = new ArrowedText(this); + int[] colors = {0xFF606060, 0xFF707070}; + + if (i%2 == 0) { + int tmp = colors[0]; + colors[0] = colors[1]; + colors[1] = tmp; + } + + int rightPadding = 2; + if (last) { + colors[1] = 0xFF404040; + rightPadding = 0; + view.setOnClickListener(this); + } + + int leftPadding = 14; + if (first) { + leftPadding = 4; + colors[0] = colors[1]; + } - TextView view = new TextView(this); view.setSingleLine(); view.setEllipsize(TextUtils.TruncateAt.MARQUEE); - view.setText(limiter[i]); + view.setText(txt); view.setTextColor(Color.WHITE); - view.setBackgroundDrawable(background); view.setLayoutParams(params); - view.setPadding(14, 6, 14, 6); + view.setPadding(leftPadding, 6, rightPadding, 6); + view.setArrowWidth(arrowWidth); view.setTag(i); - view.setOnClickListener(this); + view.setColors(colors[0], colors[1]); mLimiterViews.addView(view); - } + if (last) { + ArrowedText end = new ArrowedText(this); + end.setOnClickListener(this); + end.setText("×"); + end.setTextColor(0xFFB0B0B0); + end.setLayoutParams(params); + end.setPadding(6, 6, 0, 6); + end.setArrowPadding(14); + end.setArrowWidth(arrowWidth); + end.setMinWidth(arrowWidth+14); + end.setTag(i); + end.setColors(colors[1], 0); + mLimiterViews.addView(end); + } + } mLimiterScroller.setVisibility(View.VISIBLE); } else { mLimiterScroller.setVisibility(View.GONE); diff --git a/app/src/main/java/ch/blinkenlights/android/vanilla/ui/ArrowedText.java b/app/src/main/java/ch/blinkenlights/android/vanilla/ui/ArrowedText.java new file mode 100644 index 00000000..3e060568 --- /dev/null +++ b/app/src/main/java/ch/blinkenlights/android/vanilla/ui/ArrowedText.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2020 Adrian Ulrich + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package ch.blinkenlights.android.vanilla.ui; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.drawable.PaintDrawable; +import android.graphics.Path; +import android.widget.TextView; + +public class ArrowedText extends TextView { + /** + * Context this view uses. + */ + Context mContext; + /** + * Color of the arrow on the left side. + */ + int mArrowColor; + /** + * Controls the width of the drawn arrow. + */ + float mArrowWidth; + /** + * 'padding' space (used left side) for the arrow to consume. + */ + int mArrowPadding; + + public ArrowedText(Context context) { + super(context); + mContext = context; + } + + /** + * Configures the width of the arrow. + */ + public void setArrowWidth(int w) { + mArrowWidth = w; + } + + /** + * Configures how much space the arrow uses on the left side. + */ + public void setArrowPadding(int p) { + mArrowPadding = p; + } + + /** + * Set arrow and background color of this view. + */ + public void setColors(int colA, int colB) { + PaintDrawable bg = new PaintDrawable(colB); + setBackgroundDrawable(bg); + mArrowColor = colA; + } + + @Override + protected void onDraw(Canvas canvas) { + Paint paint = new Paint(); + paint.setColor(mArrowColor); + paint.setAntiAlias(true); + paint.setStyle(Paint.Style.FILL_AND_STROKE); + + int h = canvas.getHeight(); + float m = h/2.0f; + Path path = new Path(); + path.moveTo(0, 0); + path.lineTo(mArrowPadding, 0); + path.lineTo(mArrowPadding + mArrowWidth, m); + path.lineTo(mArrowPadding, h); + path.lineTo(0, h); + path.lineTo(0,0); + path.close(); + canvas.drawPath(path, paint); + super.onDraw(canvas); + } +}