Show abstract art behind categories without predefined images.

In the process refactored the FeatureImage class to not be dependant on
an instance of Palette for its colours.
This commit is contained in:
Peter Serwylo 2017-03-17 09:15:47 +11:00
parent 1776b1e2c3
commit bc1ff7d8c8
5 changed files with 23 additions and 18 deletions

View File

@ -10,6 +10,7 @@ import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout;
@ -108,7 +109,7 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
new Palette.Builder(loadedImage).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
featureImage.setPalette(palette);
featureImage.setColour(palette.getDominantColor(Color.LTGRAY));
}
});
}

View File

@ -8,7 +8,9 @@ import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.os.Build;
import android.support.annotation.ColorInt;
import android.support.annotation.Nullable;
import android.support.v7.graphics.Palette;
import android.support.v7.widget.AppCompatImageView;
@ -71,8 +73,8 @@ public class FeatureImage extends AppCompatImageView {
* then creates a second variation that is slightly dimmer still. These two colours are then
* randomly allocated to each triangle which is expected to be rendered.
*/
public void setPalette(@Nullable Palette palette) {
if (palette == null) {
public void setColour(@ColorInt int colour) {
if (colour == 0) {
trianglePaints = null;
return;
}
@ -80,7 +82,7 @@ public class FeatureImage extends AppCompatImageView {
// It is easier to dull al colour in the HSV space, so convert to that then adjust the
// saturation down and the colour value down.
float[] hsv = new float[3];
Color.colorToHSV(palette.getDominantColor(Color.LTGRAY), hsv);
Color.colorToHSV(colour, hsv);
hsv[1] *= 0.5f;
hsv[2] *= 0.7f;
int colourOne = Color.HSVToColor(hsv);
@ -187,9 +189,8 @@ public class FeatureImage extends AppCompatImageView {
/**
* First try to draw whatever image was given to this view. If that doesn't exist, try to draw
* a geometric pattern based on the palette that was given to us. If we haven't had a palette
* assigned to us (using {@link FeatureImage#setPalette(Palette)}) then clear the
* view by filling it with white.
* a geometric pattern based on the palette that was given to us. If we haven't had a colour
* assigned to us (using {@link #setColour(int)}) then clear the view by filling it with white.
*/
@Override
protected void onDraw(Canvas canvas) {
@ -200,12 +201,11 @@ public class FeatureImage extends AppCompatImageView {
paint.setAlpha(currentAlpha);
}
canvas.drawRect(0, 0, getWidth(), getHeight(), WHITE_PAINT);
for (int i = 0; i < triangles.length; i++) {
canvas.drawPath(triangles[i], trianglePaints[i]);
}
} else {
canvas.drawRect(0, 0, getWidth(), getHeight(), WHITE_PAINT);
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
}
}

View File

@ -3,6 +3,7 @@ package org.fdroid.fdroid.views.categories;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.IdRes;
@ -111,7 +112,7 @@ public class AppCardController extends RecyclerView.ViewHolder implements ImageL
}
if (featuredImage != null) {
featuredImage.setPalette(null);
featuredImage.setColour(0);
featuredImage.setImageDrawable(null);
}
@ -154,7 +155,7 @@ public class AppCardController extends RecyclerView.ViewHolder implements ImageL
new Palette.Builder(loadedImage).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
featuredImage.setPalette(palette);
featuredImage.setColour(palette.getDominantColor(Color.LTGRAY));
}
});
}

View File

@ -8,6 +8,7 @@ import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.ContextCompat;
@ -18,7 +19,6 @@ import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
@ -30,13 +30,14 @@ import org.fdroid.fdroid.R;
import org.fdroid.fdroid.data.AppProvider;
import org.fdroid.fdroid.data.Schema;
import org.fdroid.fdroid.views.apps.AppListActivity;
import org.fdroid.fdroid.views.apps.FeatureImage;
import java.util.Random;
public class CategoryController extends RecyclerView.ViewHolder implements LoaderManager.LoaderCallbacks<Cursor> {
private final Button viewAll;
private final TextView heading;
private final ImageView image;
private final FeatureImage image;
private final AppPreviewAdapter appCardsAdapter;
private final FrameLayout background;
@ -58,7 +59,7 @@ public class CategoryController extends RecyclerView.ViewHolder implements Loade
viewAll.setOnClickListener(onViewAll);
heading = (TextView) itemView.findViewById(R.id.name);
image = (ImageView) itemView.findViewById(R.id.category_image);
image = (FeatureImage) itemView.findViewById(R.id.category_image);
background = (FrameLayout) itemView.findViewById(R.id.category_background);
RecyclerView appCards = (RecyclerView) itemView.findViewById(R.id.app_cards);
@ -85,13 +86,15 @@ public class CategoryController extends RecyclerView.ViewHolder implements Loade
loaderManager.initLoader(currentCategory.hashCode(), null, this);
loaderManager.initLoader(currentCategory.hashCode() + 1, null, this);
background.setBackgroundColor(getBackgroundColour(activity, categoryName));
@ColorInt int backgroundColour = getBackgroundColour(activity, categoryName);
background.setBackgroundColor(backgroundColour);
int categoryImageId = getCategoryResource(activity, categoryName, "drawable", true);
if (categoryImageId == 0) {
image.setVisibility(View.GONE);
image.setColour(backgroundColour);
image.setImageDrawable(null);
} else {
image.setVisibility(View.VISIBLE);
image.setColour(0);
ImageLoader.getInstance().displayImage("drawable://" + categoryImageId, image, displayImageOptions);
}
}

View File

@ -52,7 +52,7 @@
app:layout_constraintEnd_toEndOf="parent"
tools:background="#ffffbbbb" />
<ImageView
<org.fdroid.fdroid.views.apps.FeatureImage
android:id="@+id/category_image"
app:layout_constraintStart_toStartOf="@+id/category_background"
app:layout_constraintEnd_toEndOf="@+id/category_background"