Skip to content

Commit

Permalink
Add description field to font selection
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantner committed Nov 20, 2017
1 parent b2787e4 commit 48a92a6
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,15 @@ 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;

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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -32,6 +42,7 @@ public FontItemAdapter(Context context, int resource, List<MemeData.Font> fontLi
}

@Override
@NonNull
public View getView(int position, View convertView, ViewGroup parent) {
View v = getTheView(position, convertView, parent);
if (_showCustomSelectedText) {
Expand All @@ -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) {
Expand Down

0 comments on commit 48a92a6

Please sign in to comment.