From 48a92a60f61bd85273aa10abb610608b328a8412 Mon Sep 17 00:00:00 2001 From: Gregor Santner Date: Mon, 20 Nov 2017 13:39:35 +0100 Subject: [PATCH] Add description field to font selection --- README.md | 2 +- .../memetastic/activity/MainActivity.java | 2 - .../activity/MemeCreateActivity.java | 2 - .../gsantner/memetastic/data/MemeConfig.java | 13 +++++ .../memetastic/ui/FontItemAdapter.java | 51 +++++++++++++++---- 5 files changed, 56 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d40265e25..c849cff5f 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Meme templates will only get added if there are no existing watermarks (of e.g. and if they are in a good image quality (do a quick search before). You can maybe find something suitable here: -* Fonts: [1001fonts](http://www.1001fonts.com) | [Font Squirell](https://www.fontsquirrel.com/fonts/list/find_fonts?filter%5Blicense%5D%5B0%5D=app&filter%5Blicense%5D%5B1%5D=open&sort=hot) | [fontspace](http://www.fontspace.com/) | [Google Fonts](https://fonts.google.com) | [Identify font](https://www.fontsquirrel.com/matcherator) +* Fonts: [1001fonts](http://www.1001fonts.com) | [Font Squirell](https://www.fontsquirrel.com/fonts/list/find_fonts?filter%5Blicense%5D%5B0%5D=app&filter%5Blicense%5D%5B1%5D=open&sort=hot) | [fontspace](http://www.fontspace.com/) | [Google Fonts](https://fonts.google.com) | [FontMeme](https://fontmeme.com/) | [Identify font](https://www.fontsquirrel.com/matcherator) * Memes: [knowyourmeme.com](http://knowyourmeme.com) | [/r/MemeTemplatesOfficial](https://www.reddit.com/r/MemeTemplatesOfficial) | [memes.at](http://www.memes.at/) diff --git a/app/src/main/java/io/github/gsantner/memetastic/activity/MainActivity.java b/app/src/main/java/io/github/gsantner/memetastic/activity/MainActivity.java index a8b706b33..fb4c2ba60 100644 --- a/app/src/main/java/io/github/gsantner/memetastic/activity/MainActivity.java +++ b/app/src/main/java/io/github/gsantner/memetastic/activity/MainActivity.java @@ -501,8 +501,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { onImageTemplateWasChosen(picturePath); } } - } else { - ActivityUtils.get(this).showSnackBar(R.string.main__error_no_picture_selected, false); } if (requestCode == REQUEST_TAKE_CAMERA_PICTURE) { diff --git a/app/src/main/java/io/github/gsantner/memetastic/activity/MemeCreateActivity.java b/app/src/main/java/io/github/gsantner/memetastic/activity/MemeCreateActivity.java index 98661cf9c..277aa8088 100644 --- a/app/src/main/java/io/github/gsantner/memetastic/activity/MemeCreateActivity.java +++ b/app/src/main/java/io/github/gsantner/memetastic/activity/MemeCreateActivity.java @@ -19,10 +19,8 @@ import android.support.annotation.NonNull; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; -import android.support.v4.content.ContextCompat; import android.support.v4.content.LocalBroadcastManager; import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.AppCompatImageButton; import android.support.v7.widget.Toolbar; import android.text.Layout; import android.text.StaticLayout; diff --git a/app/src/main/java/io/github/gsantner/memetastic/data/MemeConfig.java b/app/src/main/java/io/github/gsantner/memetastic/data/MemeConfig.java index c4a6db805..5fd0a5881 100644 --- a/app/src/main/java/io/github/gsantner/memetastic/data/MemeConfig.java +++ b/app/src/main/java/io/github/gsantner/memetastic/data/MemeConfig.java @@ -255,6 +255,7 @@ public static class Font implements Serializable { public static final int FONT_TYPE__COMIC = 1; private String _title; + private String _description; private String _filename; private int _fontType; @@ -262,6 +263,7 @@ public Font fromJson(JSONObject json) throws JSONException { setTitle(json.getString("title")); setFilename(json.getString("filename")); setFontType(json.optInt("font_type", 0)); + setDescription(json.optString("description", "")); return this; } @@ -272,6 +274,9 @@ public JSONObject toJson() throws JSONException { if (getFontType() != 0) { root.put("font_type", getFontType()); } + if (!TextUtils.isEmpty(getDescription())) { + root.put("description", getDescription()); + } return root; } @@ -301,6 +306,14 @@ public int getFontType() { public void setFontType(int fontType) { _fontType = fontType; } + + public String getDescription() { + return _description; + } + + public void setDescription(String description) { + _description = description; + } } // For interoperability with PointF use public members diff --git a/app/src/main/java/io/github/gsantner/memetastic/ui/FontItemAdapter.java b/app/src/main/java/io/github/gsantner/memetastic/ui/FontItemAdapter.java index 53a940731..2eab9af59 100644 --- a/app/src/main/java/io/github/gsantner/memetastic/ui/FontItemAdapter.java +++ b/app/src/main/java/io/github/gsantner/memetastic/ui/FontItemAdapter.java @@ -1,6 +1,16 @@ package io.github.gsantner.memetastic.ui; import android.content.Context; +import android.graphics.Color; +import android.graphics.Typeface; +import android.support.annotation.NonNull; +import android.text.ParcelableSpan; +import android.text.SpannableString; +import android.text.TextUtils; +import android.text.style.ForegroundColorSpan; +import android.text.style.RelativeSizeSpan; +import android.text.style.StyleSpan; +import android.text.style.TypefaceSpan; import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; @@ -32,6 +42,7 @@ public FontItemAdapter(Context context, int resource, List fontLi } @Override + @NonNull public View getView(int position, View convertView, ViewGroup parent) { View v = getTheView(position, convertView, parent); if (_showCustomSelectedText) { @@ -41,21 +52,43 @@ public View getView(int position, View convertView, ViewGroup parent) { } @Override - public View getDropDownView(int position, View convertView, ViewGroup parent) { + public View getDropDownView(int position, View convertView, @NonNull ViewGroup parent) { return getTheView(position, convertView, parent); } // set how the item should look like (rendered in own conf) private View getTheView(int position, View convertView, ViewGroup parent) { - String fontName = getItem(position).conf.getTitle(); - if (fontName.contains("_") && !fontName.endsWith("_")) ; - fontName = fontName.substring(fontName.indexOf('_') + 1); + MemeData.Font item = getItem(position); + TextView textview = (TextView) super.getDropDownView(position, convertView, parent); + if (item != null && item.conf != null) { + String fontName = item.conf.getTitle(); + String fontDescription = item.conf.getDescription(); - TextView view = (TextView) super.getDropDownView(position, convertView, parent); - view.setTypeface(getItem(position).typeFace); - view.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); - view.setText(fontName); - return view; + if (fontName.contains("_") && !fontName.endsWith("_")) ; + fontName = fontName.substring(fontName.indexOf('_') + 1); + + textview.setTypeface(item.typeFace); + textview.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); + + SpannableString spannedText = null; + if (TextUtils.isEmpty(fontDescription)) { + spannedText = new SpannableString(fontName); + } else { + fontName += "\n" + fontDescription; + spannedText = new SpannableString(fontName); + ParcelableSpan[] spanMods = new ParcelableSpan[]{ + new RelativeSizeSpan(0.7f), + new ForegroundColorSpan(Color.GRAY), + new StyleSpan(Typeface.NORMAL), + new TypefaceSpan("sans-serif") + }; + for (ParcelableSpan spanMod : spanMods) { + spannedText.setSpan(spanMod, fontName.indexOf("\n"), fontName.length(), 0); + } + } + textview.setText(spannedText); + } + return textview; } public void setSelectedFont(Spinner spinner, MemeData.Font font) {