From 037ef7c6ada1f568fe59fd55464e23e699f2f068 Mon Sep 17 00:00:00 2001 From: Mathijs Lagerberg Date: Mon, 10 Apr 2017 17:23:40 +0200 Subject: [PATCH 1/3] [mod] updated gradle and libs [mod] versionCode 3 [mod] minSdk is now 9 (because of support libs) --- app/build.gradle | 4 ++-- build.gradle | 8 ++++---- gradle.properties | 24 ++++++++++++------------ gradle/wrapper/gradle-wrapper.properties | 4 ++-- library/build.gradle | 8 ++++---- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b20785f..24aa643 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,7 +6,7 @@ android { defaultConfig { applicationId GROUP + '.fontview.sample' - minSdkVersion 7 + minSdkVersion 9 targetSdkVersion Integer.parseInt(ANDROID_TARGET_SDK) versionCode Integer.parseInt(VERSION_CODE) versionName VERSION_NAME @@ -24,6 +24,6 @@ android { } dependencies { - compile 'com.android.support:appcompat-v7:22.2.0' + compile 'com.android.support:appcompat-v7:25.3.1' compile project(':library') } diff --git a/build.gradle b/build.gradle index d2050e4..70e4b68 100644 --- a/build.gradle +++ b/build.gradle @@ -5,10 +5,10 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.2.3' + classpath 'com.android.tools.build:gradle:2.3.0' classpath 'com.noveogroup.android:check:1.1.2' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2' - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' } } @@ -26,9 +26,9 @@ project.ext.preDexLibs = !project.hasProperty('disablePreDex') subprojects { project.plugins.whenPluginAdded { plugin -> - if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) { + if ("com.android.build.gradle.AppPlugin" == plugin.class.name) { project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs - } else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) { + } else if ("com.android.build.gradle.LibraryPlugin" == plugin.class.name) { project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs } } diff --git a/gradle.properties b/gradle.properties index 5f8c71d..a513735 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,32 +1,32 @@ # Project-wide Gradle settings. - +# # IDE (e.g. Android Studio) users: # Settings specified in this file will override any Gradle settings # configured through the IDE. - +# # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html - +# # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - +# # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true - +# # Set Gradle settings which apply to all modules here. org.gradle.parallel=true org.gradle.daemon=true org.gradle.configureondemand=true - +# VERSION_NAME=1.1 -VERSION_CODE=2 +VERSION_CODE=3 GROUP=com.pixplicity.letterpress ARTIFACT_ID=letterpress - +# POM_DESCRIPTION=Custom fonts on all views POM_URL=https://github.com/Pixplicity/letterpress POM_SCM_URL=https://github.com/Pixplicity/letterpress @@ -45,7 +45,7 @@ POM_DEVELOPER_EMAIL_1=dylan@pixplicity.com POM_DEVELOPER_ID_2=mlagerberg POM_DEVELOPER_NAME_2=Mathijs Lagerberg POM_DEVELOPER_EMAIL_2=mathijs@pixplicity.com - -ANDROID_BUILD_TOOLS_VERSION=22.0.1 -ANDROID_COMPILE_SDK_VERSION=22 -ANDROID_TARGET_SDK=22 \ No newline at end of file +# +ANDROID_BUILD_TOOLS_VERSION=25.0.2 +ANDROID_COMPILE_SDK_VERSION=25 +ANDROID_TARGET_SDK=25 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d0ed79a..444a193 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Jul 07 11:06:21 CEST 2015 +#Mon Apr 10 16:55:25 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/library/build.gradle b/library/build.gradle index 98bb51b..cd31026 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -2,11 +2,11 @@ apply plugin: 'com.android.library' apply plugin: 'com.noveogroup.android.check' android { - compileSdkVersion 22 + compileSdkVersion 25 buildToolsVersion ANDROID_BUILD_TOOLS_VERSION - + defaultConfig { - minSdkVersion 7 + minSdkVersion 9 targetSdkVersion Integer.parseInt(ANDROID_TARGET_SDK) versionCode Integer.parseInt(VERSION_CODE) versionName VERSION_NAME @@ -43,7 +43,7 @@ check { } } dependencies { - compile 'com.android.support:appcompat-v7:22.2.0' + compile 'com.android.support:appcompat-v7:25.3.1' } apply from: new File('../bintray_upload.gradle') From 141d8db1f8863c752160752c071c3a4a4089abc6 Mon Sep 17 00:00:00 2001 From: Mathijs Lagerberg Date: Mon, 10 Apr 2017 18:18:51 +0200 Subject: [PATCH 2/3] [add] Support for Spinners [add] Support for overflow menus and popup menus --- .../fontview/sample/MainActivity.java | 58 +++++++++++++++++++ app/src/main/res/layout/main_activity.xml | 6 ++ app/src/main/res/menu/menu.xml | 12 ++++ app/src/main/res/values/strings.xml | 7 +++ app/src/main/res/values/styles.xml | 5 +- .../pixplicity/fontview/utils/FontSpan.java | 44 ++++++++++++++ .../fontview/utils/FontSpinnerAdapter.java | 50 ++++++++++++++++ .../pixplicity/fontview/utils/FontUtil.java | 48 ++++++++++++++- library/src/main/res/layout/li_spinner.xml | 10 ++++ 9 files changed, 236 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/menu/menu.xml create mode 100644 library/src/main/java/com/pixplicity/fontview/utils/FontSpan.java create mode 100644 library/src/main/java/com/pixplicity/fontview/utils/FontSpinnerAdapter.java create mode 100644 library/src/main/res/layout/li_spinner.xml diff --git a/app/src/main/java/com/pixplicity/fontview/sample/MainActivity.java b/app/src/main/java/com/pixplicity/fontview/sample/MainActivity.java index 16b6234..f9286d6 100644 --- a/app/src/main/java/com/pixplicity/fontview/sample/MainActivity.java +++ b/app/src/main/java/com/pixplicity/fontview/sample/MainActivity.java @@ -1,23 +1,81 @@ package com.pixplicity.fontview.sample; +import android.graphics.Typeface; import android.os.Bundle; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.PopupMenu; import android.support.v7.widget.Toolbar; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.widget.Spinner; + +import com.pixplicity.fontview.utils.FontSpinnerAdapter; +import com.pixplicity.fontview.utils.FontUtil; public class MainActivity extends AppCompatActivity { + private Typeface mTypeface; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); + // Configure toolbar final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); final ActionBar supportActionBar = getSupportActionBar(); if (supportActionBar != null) { supportActionBar.setDisplayShowTitleEnabled(false); } + + // Load font manually + mTypeface = FontUtil.getTypeface(this, "fonts/Action_Man.ttf"); + + // Apply font to popup menu + findViewById(R.id.bt_popup).setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + showPopupMenu(v); + } + }); + + // Apply font to Spinner + final Spinner spinner = (Spinner) findViewById(R.id.spinner); + spinner.setAdapter(new FontSpinnerAdapter(this, mTypeface, R.array.spinner_list)); } + private void showPopupMenu(View anchorView) { + PopupMenu popup = new PopupMenu(MainActivity.this, anchorView); + popup.getMenuInflater().inflate(R.menu.menu, popup.getMenu()); + popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + public boolean onMenuItemClick(MenuItem item) { + // ... + return true; + } + }); + + // Apply custom font to popup menu + FontUtil.applyTypeface(popup.getMenu(), mTypeface); + popup.show(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.menu, menu); + return true; + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + + // Apply custom font to overflow menu + FontUtil.applyTypeface(menu, mTypeface); + return super.onPrepareOptionsMenu(menu); + } } diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index 07af80d..8ca2465 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -57,6 +57,7 @@ app:pix_font="fonts/Action_Man.ttf"/> + + diff --git a/app/src/main/res/menu/menu.xml b/app/src/main/res/menu/menu.xml new file mode 100644 index 0000000..ad9845f --- /dev/null +++ b/app/src/main/res/menu/menu.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e4f762d..dff8af5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,4 +1,11 @@ FontView Sample FontView Leaks Sample + + + One + Two + Three + Four + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index dc3d7bf..a473452 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -3,9 +3,12 @@ diff --git a/library/src/main/java/com/pixplicity/fontview/utils/FontSpan.java b/library/src/main/java/com/pixplicity/fontview/utils/FontSpan.java new file mode 100644 index 0000000..577f501 --- /dev/null +++ b/library/src/main/java/com/pixplicity/fontview/utils/FontSpan.java @@ -0,0 +1,44 @@ +package com.pixplicity.fontview.utils; + +import android.graphics.Paint; +import android.graphics.Typeface; +import android.text.TextPaint; +import android.text.style.MetricAffectingSpan; + +/** + * Span that applies a Typeface to a String + */ +public class FontSpan extends MetricAffectingSpan { + + private final Typeface typeface; + + public FontSpan(final Typeface typeface) { + this.typeface = typeface; + } + + @Override + public void updateDrawState(final TextPaint drawState) { + apply(drawState); + } + + @Override + public void updateMeasureState(final TextPaint paint) { + apply(paint); + } + + private void apply(final Paint paint) { + final Typeface oldTypeface = paint.getTypeface(); + final int oldStyle = oldTypeface != null ? oldTypeface.getStyle() : 0; + final int fakeStyle = oldStyle & ~typeface.getStyle(); + + if ((fakeStyle & Typeface.BOLD) != 0) { + paint.setFakeBoldText(true); + } + + if ((fakeStyle & Typeface.ITALIC) != 0) { + paint.setTextSkewX(-0.25f); + } + + paint.setTypeface(typeface); + } +} \ No newline at end of file diff --git a/library/src/main/java/com/pixplicity/fontview/utils/FontSpinnerAdapter.java b/library/src/main/java/com/pixplicity/fontview/utils/FontSpinnerAdapter.java new file mode 100644 index 0000000..841be28 --- /dev/null +++ b/library/src/main/java/com/pixplicity/fontview/utils/FontSpinnerAdapter.java @@ -0,0 +1,50 @@ +package com.pixplicity.fontview.utils; + +import android.content.Context; +import android.graphics.Typeface; +import android.support.annotation.ArrayRes; +import android.support.annotation.LayoutRes; +import android.support.annotation.NonNull; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import com.pixplicity.fontview.R; + +/** + * A simple ArrayAdapter meant to apply the default typeface to Spinners + */ +public class FontSpinnerAdapter extends ArrayAdapter { + + private final Typeface mTypeface; + + public FontSpinnerAdapter(@NonNull Context context, @NonNull Typeface typeface, + @ArrayRes int strArray) { + this(context, typeface, R.layout.li_spinner, strArray); + } + + public FontSpinnerAdapter(@NonNull Context context, @NonNull Typeface typeface, + @LayoutRes int listItem, @ArrayRes int strArray) { + super(context, listItem, context.getResources().getStringArray(strArray)); + mTypeface = typeface; + } + + // Affects default (closed) state of the spinner + @NonNull + @Override + public View getView(int position, View convertView, @NonNull ViewGroup parent) { + TextView view = (TextView) super.getView(position, convertView, parent); + FontUtil.applyTypeface(view, mTypeface); + return view; + } + + // Affects opened state of the spinner + @NonNull + @Override + public View getDropDownView(int position, View convertView, @NonNull ViewGroup parent) { + TextView view = (TextView) super.getDropDownView(position, convertView, parent); + FontUtil.applyTypeface(view, mTypeface); + return view; + } +} \ No newline at end of file diff --git a/library/src/main/java/com/pixplicity/fontview/utils/FontUtil.java b/library/src/main/java/com/pixplicity/fontview/utils/FontUtil.java index 85838d6..692bf24 100644 --- a/library/src/main/java/com/pixplicity/fontview/utils/FontUtil.java +++ b/library/src/main/java/com/pixplicity/fontview/utils/FontUtil.java @@ -4,11 +4,17 @@ import android.content.res.TypedArray; import android.graphics.Typeface; import android.support.annotation.NonNull; +import android.text.Spannable; +import android.text.SpannableString; import android.text.TextUtils; import android.util.AttributeSet; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.TextView; import com.pixplicity.fontview.R; +import java.security.InvalidParameterException; import java.util.Hashtable; public final class FontUtil { @@ -49,14 +55,12 @@ private static String getFontFromAttributes(@NonNull Context context, @NonNull A && (fontStyle & Typeface.ITALIC) == 0)) { fontName = a.getString(attr); } - } else if (attr == R.styleable.FontTextView_pix_fontItalic) { if (TextUtils.isEmpty(fontName) || ((fontStyle & Typeface.BOLD) == 0 && (fontStyle & Typeface.ITALIC) != 0)) { fontName = a.getString(attr); } - } else if (attr == R.styleable.FontTextView_pix_fontBoldItalic) { if (TextUtils.isEmpty(fontName) || ((fontStyle & Typeface.BOLD) != 0 @@ -84,11 +88,49 @@ public static Typeface getTypeface(@NonNull Context context, @NonNull String fon TYPEFACES.put(fontName, tf); } return tf; + } + + public static void applyTypeface(@NonNull TextView view, @NonNull Typeface typeface) { + view.setTypeface(typeface); + } + + public static void applyTypeface(@NonNull TextView view, @NonNull String fontName) { + final Typeface typeface = getTypeface(view.getContext(), fontName); + view.setTypeface(typeface); + } + @NonNull + public static SpannableString applyTypeface(@NonNull String text, @NonNull Context + context, @NonNull String fontName) { + final Typeface typeface = getTypeface(context, fontName); + if (typeface == null) { + throw new InvalidParameterException("Font '" + fontName + "' not found"); + } + return applyTypeface(text, typeface); + } + + @NonNull + public static SpannableString applyTypeface(final @NonNull String text, final @NonNull Typeface + typeface) { + SpannableString spannableString = new SpannableString(text); + FontSpan span = new FontSpan(typeface); + spannableString.setSpan(span, 0, spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + return spannableString; + } + + /** + * Applies a Typeface onto an overflow or popup menu + * + * @param menu The menu to typefacesize + */ + public static void applyTypeface(@NonNull Menu menu, final @NonNull Typeface typeface) { + for (int i = 0; i < menu.size(); i++) { + MenuItem item = menu.getItem(i); + item.setTitle(applyTypeface(item.getTitle().toString(), typeface)); + } } private FontUtil() { // Forbid class creation } - } diff --git a/library/src/main/res/layout/li_spinner.xml b/library/src/main/res/layout/li_spinner.xml new file mode 100644 index 0000000..d224c69 --- /dev/null +++ b/library/src/main/res/layout/li_spinner.xml @@ -0,0 +1,10 @@ + + \ No newline at end of file From 7ed5d52032a65d51ef633ee3c4c4d3cd621a950b Mon Sep 17 00:00:00 2001 From: Mathijs Lagerberg Date: Tue, 11 Apr 2017 18:57:02 +0200 Subject: [PATCH 3/3] [mod] version 1.2(4) [mod] disabled lint abortOnError [mod] pom details --- app/build.gradle | 6 ++++++ bintray_upload.gradle | 5 ----- build.gradle | 2 +- gradle.properties | 13 +++++-------- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 24aa643..f4a900a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,16 +11,22 @@ android { versionCode Integer.parseInt(VERSION_CODE) versionName VERSION_NAME } + buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } + + lintOptions { + abortOnError false + } } dependencies { diff --git a/bintray_upload.gradle b/bintray_upload.gradle index a3c480a..3bd5d1b 100644 --- a/bintray_upload.gradle +++ b/bintray_upload.gradle @@ -50,11 +50,6 @@ install { name POM_DEVELOPER_NAME_1 email POM_DEVELOPER_EMAIL_1 } - developer { - id POM_DEVELOPER_ID_2 - name POM_DEVELOPER_NAME_2 - email POM_DEVELOPER_EMAIL_2 - } } scm { connection POM_SCM_CONNECTION diff --git a/build.gradle b/build.gradle index 70e4b68..7e1ad0e 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.android.tools.build:gradle:2.3.1' classpath 'com.noveogroup.android:check:1.1.2' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' diff --git a/gradle.properties b/gradle.properties index a513735..08902a9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,8 +22,8 @@ org.gradle.parallel=true org.gradle.daemon=true org.gradle.configureondemand=true # -VERSION_NAME=1.1 -VERSION_CODE=3 +VERSION_NAME=1.2 +VERSION_CODE=4 GROUP=com.pixplicity.letterpress ARTIFACT_ID=letterpress # @@ -39,12 +39,9 @@ POM_LICENCE_DIST=repo POM_DEVELOPER_ID_0=pflammertsma POM_DEVELOPER_NAME_0=Paul Lammerstma POM_DEVELOPER_EMAIL_0=paul@pixplicity.com -POM_DEVELOPER_ID_1=aegis123 -POM_DEVELOPER_NAME_1=Dylan Drost -POM_DEVELOPER_EMAIL_1=dylan@pixplicity.com -POM_DEVELOPER_ID_2=mlagerberg -POM_DEVELOPER_NAME_2=Mathijs Lagerberg -POM_DEVELOPER_EMAIL_2=mathijs@pixplicity.com +POM_DEVELOPER_ID_1=mlagerberg +POM_DEVELOPER_NAME_1=Mathijs Lagerberg +POM_DEVELOPER_EMAIL_1=mathijs@pixplicity.com # ANDROID_BUILD_TOOLS_VERSION=25.0.2 ANDROID_COMPILE_SDK_VERSION=25