From 55e4cd83bc0741b26c4fbba8def4763a4e038050 Mon Sep 17 00:00:00 2001 From: Evgeny Shishkin Date: Tue, 21 Oct 2014 13:21:18 +0400 Subject: [PATCH] This fixes #2, resolves #3 and closes #4 --- CHANGELOG.md | 8 + README.md | 44 +- .../print-sample.png | Bin build.gradle | 2 +- gradle.properties | 4 +- print-sample/build.gradle | 12 +- .../src/main/assets/fonts/holo-icon-font.ttf | Bin 0 -> 20100 bytes .../johnkil/print/sample/MainActivity.java | 25 +- .../print/sample/PrintApplication.java | 9 +- print-sample/src/main/res/color/icon.xml | 15 + .../src/main/res/layout/activity_main.xml | 21 +- print-sample/src/main/res/menu/main.xml | 17 + print-sample/src/main/res/values/colors.xml | 17 + print-sample/src/main/res/values/dimens.xml | 18 + print-sample/src/main/res/values/icons.xml | 438 ----------------- .../src/main/res/values/icons_holo.xml | 165 +++++++ .../src/main/res/values/icons_material.xml | 454 ++++++++++++++++++ print-sample/src/main/res/values/strings.xml | 18 +- print-sample/src/main/res/values/styles.xml | 17 + print/build.gradle | 10 +- print/gradle.properties | 2 +- print/src/main/AndroidManifest.xml | 2 +- .../java/com/github/johnkil/print/IPrint.java | 136 ++++++ .../com/github/johnkil/print/IPrintView.java | 26 + .../java/com/github/johnkil/print/Print.java | 87 ---- .../com/github/johnkil/print/PrintButton.java | 122 +++++ .../com/github/johnkil/print/PrintConfig.java | 81 ++++ .../github/johnkil/print/PrintDrawable.java | 277 +++++++++++ .../com/github/johnkil/print/PrintView.java | 121 +++++ .../github/johnkil/print/PrintViewUtils.java | 69 +++ .../github/johnkil/print/TypefaceManager.java | 58 +++ .../johnkil/print/drawable/PrintDrawable.java | 132 ----- .../johnkil/print/widget/PrintButton.java | 225 --------- .../johnkil/print/widget/PrintView.java | 225 --------- print/src/main/res/values/attrs.xml | 32 +- print/src/main/res/values/colors.xml | 22 - print/src/main/res/values/dimens.xml | 22 - 37 files changed, 1712 insertions(+), 1221 deletions(-) rename print-sample/web_hi_res_512.png => art/print-sample.png (100%) create mode 100644 print-sample/src/main/assets/fonts/holo-icon-font.ttf delete mode 100644 print-sample/src/main/res/values/icons.xml create mode 100644 print-sample/src/main/res/values/icons_holo.xml create mode 100644 print-sample/src/main/res/values/icons_material.xml create mode 100644 print/src/main/java/com/github/johnkil/print/IPrint.java create mode 100644 print/src/main/java/com/github/johnkil/print/IPrintView.java delete mode 100644 print/src/main/java/com/github/johnkil/print/Print.java create mode 100644 print/src/main/java/com/github/johnkil/print/PrintButton.java create mode 100644 print/src/main/java/com/github/johnkil/print/PrintConfig.java create mode 100644 print/src/main/java/com/github/johnkil/print/PrintDrawable.java create mode 100644 print/src/main/java/com/github/johnkil/print/PrintView.java create mode 100644 print/src/main/java/com/github/johnkil/print/PrintViewUtils.java create mode 100644 print/src/main/java/com/github/johnkil/print/TypefaceManager.java delete mode 100644 print/src/main/java/com/github/johnkil/print/drawable/PrintDrawable.java delete mode 100644 print/src/main/java/com/github/johnkil/print/widget/PrintButton.java delete mode 100644 print/src/main/java/com/github/johnkil/print/widget/PrintView.java delete mode 100644 print/src/main/res/values/colors.xml delete mode 100644 print/src/main/res/values/dimens.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index fd53672..305848b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ Change Log ========== +Version 1.2.0 *(2014-10-21)* +---------------------------- + +* Support multiple iconic fonts. +* Support for displaying the preview in edit mode. +* Fix: Font size too large to fit in cache. + + Version 1.1.0 *(2014-10-06)* ---------------------------- diff --git a/README.md b/README.md index e33b67d..1c18b8f 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Download Gradle: ```groovy -compile 'com.github.johnkil.print:print:1.1.0' +compile 'com.github.johnkil.print:print:1.2.0' ``` Maven: @@ -27,14 +27,15 @@ Maven: com.github.johnkil.print print - 1.1.0 + 1.2.0 ``` Usage ----- -First, you need to initialize the iconic font in [Application.onCreate()][1] method. +First, you need to initialize the default iconic font in [Application.onCreate()][1] method. If +the font is not specified, then the font is used by default. ```java public class MyApplication extends Application { @@ -42,7 +43,7 @@ public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); - Print.initFont(getAssets(), "fonts/iconic-font.ttf"); + PrintConfig.initDefault(getAssets(), "fonts/iconic-font.ttf"); } } @@ -53,11 +54,12 @@ public class MyApplication extends Application { Use `PrintView` as single icon in your layout. ```xml - ``` @@ -67,11 +69,12 @@ Use `PrintView` as single icon in your layout. Use `PrintButton` to create a button with an icon. ```xml - ``` @@ -83,10 +86,14 @@ If you need an icon in `ImageView` or in `ActionBar`, then you should use `Print ```java ImageView imageView = (ImageView) findViewById(R.id.image); // Set an icon in the ImageView -imageView.setImageDrawable(new PrintDrawable() - .iconText(getResources().getString(R.string.ic_info)) - .iconColor(getResources().getColor(R.color.icon_color)) - .iconSize(getResources().getDimensionPixelSize(R.dimen.icon_size))); +imageView.setImageDrawable( + new PrintDrawable.Builder(context) + .iconText(R.string.ic_info) + .iconColor(R.color.icon_color) + .iconSize(R.dimen.icon_size) + .iconFont("fonts/iconic-font.ttf") + .build() +); ``` ```java @@ -95,10 +102,12 @@ public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); // Set an icon in the ActionBar menu.findItem(R.id.action_info).setIcon( - new PrintDrawable() - .iconText(getResources().getString(R.string.ic_info)) - .iconColor(getResources().getColor(R.color.ab_icon_color)) - .iconSize(getResources().getDimensionPixelSize(R.dimen.ab_icon_size)) + new PrintDrawable.Builder(context) + .iconText(R.string.ic_info) + .iconColor(R.color.ab_icon_color) + .iconSize(R.dimen.ab_icon_size) + .iconFont("fonts/iconic-font.ttf") + .build() ); return true; } @@ -129,4 +138,9 @@ License [1]: http://developer.android.com/reference/android/app/Application.html#onCreate%28%29 -[2]: https://github.com/johnkil/Android-Icon-Fonts \ No newline at end of file +[2]: https://github.com/johnkil/Android-Icon-Fonts + +[0]: https://github.com/shamanland/fonticon +[0]: https://github.com/atermenji/IconicDroid +[0]: https://github.com/JoanZapata/android-iconify +[0]: https://github.com/chrisjenx/Calligraphy \ No newline at end of file diff --git a/print-sample/web_hi_res_512.png b/art/print-sample.png similarity index 100% rename from print-sample/web_hi_res_512.png rename to art/print-sample.png diff --git a/build.gradle b/build.gradle index 58fa5a2..582829a 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:0.13.2' + classpath 'com.android.tools.build:gradle:0.13.3' } } diff --git a/gradle.properties b/gradle.properties index b14898e..ec4601f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ -VERSION_NAME=1.1.0-SNAPSHOT -VERSION_CODE=2 +VERSION_NAME=1.2.0-SNAPSHOT +VERSION_CODE=3 GROUP=com.github.johnkil.print POM_DESCRIPTION=A lightweight Android library for use iconic fonts. diff --git a/print-sample/build.gradle b/print-sample/build.gradle index e16a031..fc27872 100644 --- a/print-sample/build.gradle +++ b/print-sample/build.gradle @@ -1,19 +1,19 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 20 - buildToolsVersion "20.0.0" + compileSdkVersion 21 + buildToolsVersion "21.0.1" defaultConfig { applicationId "com.github.johnkil.print.sample" minSdkVersion 8 - targetSdkVersion 20 - versionCode 2 - versionName "1.1.0" + targetSdkVersion 21 + versionCode 3 + versionName "1.2.0" } } dependencies { - compile 'com.android.support:appcompat-v7:20.0.0' + compile 'com.android.support:appcompat-v7:21.0.0' compile project(':print') } \ No newline at end of file diff --git a/print-sample/src/main/assets/fonts/holo-icon-font.ttf b/print-sample/src/main/assets/fonts/holo-icon-font.ttf new file mode 100644 index 0000000000000000000000000000000000000000..0ac18c7b1eaa49d09dddb519469ad2ed8e1613c8 GIT binary patch literal 20100 zcmd^ndAuA|m4BUDd#~!Hx_Vz6@n~65ZRF> zN{ET<7*HG#2Q%UiK^?_Wkx@tUQ^s*-oY9{%&Nx43n&0i$ZMQ&_j!Pq!=l9O>giR;u^D|(7O z4=nly$I%*Guim)hg54*NWMAS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&b$(YaJN^DhO=8GFKC@N{>B_H`IKsp7% zS|JKkgrbCz!q(;_rLdPILs@EpzMcm|wNe|kQwMcYmuax|QXduJKP)3cqY8;rr+yls zL7Id3XSV5cl;+YrnokR8jK*mKAzxFpkfwnrEv6-O7A>V^w47GZN?Jv$>1_C~*5ZGn zoJ;HIJX%lZ(+pie8)zeKq6=v=_C#-`ZFCWBr;BL^?SwyRH|?Rlw2$`FCD39nMFipH zbOmBcuA&do)!1uukglZ<({<4FZ$N~`M-ahsGyEyHKohtXsMT$BJKdpNvUA&5Z*Q-a z_E~AsN=sH+w$h4~R;{#VrFARqx6-**I?qbyTj>HT9kbH$X4+@b@3ZLlS@ioX`h6Dt zK8t>zMZeFY-)GV9v*`C(^!qIOeHQ&bi+-O)zt5sywCEQt`bCR=(V}0p=oc;eMT>sX zqF=P=7cKfli+<6fU$p2KE&4@^e$k>|vgnsA`X!4#Y)*50N)~;9iOp+^KK4sAuPyo| zi+;(XU$W?zEczvje#xR=vgnsB`eloL*`i;z=$9?}Ws82Pj=;qF=G-S1kG!i+;tTU$N*{ zEcz9TKH~n&da4$E#0WL7E&AB?*1WdpS1tNgi+Y^MA1YKOGm$K>z>% literal 0 HcmV?d00001 diff --git a/print-sample/src/main/java/com/github/johnkil/print/sample/MainActivity.java b/print-sample/src/main/java/com/github/johnkil/print/sample/MainActivity.java index 006d99b..70f8ce7 100644 --- a/print-sample/src/main/java/com/github/johnkil/print/sample/MainActivity.java +++ b/print-sample/src/main/java/com/github/johnkil/print/sample/MainActivity.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 Evgeny Shishkin + * Copyright (C) 2014 Evgeny Shishkin * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,13 +25,9 @@ import android.widget.SeekBar; import android.widget.TextView; -import com.github.johnkil.print.drawable.PrintDrawable; -import com.github.johnkil.print.widget.PrintView; +import com.github.johnkil.print.PrintDrawable; +import com.github.johnkil.print.PrintView; - -/** - * @author Evgeny Shishkin - */ public class MainActivity extends ActionBarActivity { @Override @@ -46,9 +42,7 @@ protected void onCreate(Bundle savedInstanceState) { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { sizeValue.setText(getString(R.string.size_format, progress)); - int iconSize = (int) TypedValue.applyDimension( - TypedValue.COMPLEX_UNIT_DIP, progress, getResources().getDisplayMetrics()); - iconView.setIconSize(iconSize); + iconView.setIconSize(TypedValue.COMPLEX_UNIT_DIP, progress); } @Override @@ -70,16 +64,19 @@ public void onClick(View v) { // on click process } }); + } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); menu.findItem(R.id.action_info).setIcon( - new PrintDrawable() - .iconText(getResources().getString(R.string.ic_info)) - .iconColor(getResources().getColor(R.color.ab_icon_color)) - .iconSize(getResources().getDimensionPixelSize(R.dimen.ab_icon_size)) + new PrintDrawable.Builder(this) + .iconText(R.string.ic_holo_about) + .iconColor(R.color.ab_icon_color) + .iconFont("fonts/holo-icon-font.ttf") + .iconSize(R.dimen.ab_icon_size) + .build() ); return true; } diff --git a/print-sample/src/main/java/com/github/johnkil/print/sample/PrintApplication.java b/print-sample/src/main/java/com/github/johnkil/print/sample/PrintApplication.java index 4ba29ed..4424069 100644 --- a/print-sample/src/main/java/com/github/johnkil/print/sample/PrintApplication.java +++ b/print-sample/src/main/java/com/github/johnkil/print/sample/PrintApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 Evgeny Shishkin + * Copyright (C) 2014 Evgeny Shishkin * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,17 +18,14 @@ import android.app.Application; -import com.github.johnkil.print.Print; +import com.github.johnkil.print.PrintConfig; -/** - * @author Evgeny Shishkin - */ public class PrintApplication extends Application { @Override public void onCreate() { super.onCreate(); - Print.initFont(getAssets(), "fonts/material-icon-font.ttf"); + PrintConfig.initDefault(getAssets(), "fonts/material-icon-font.ttf"); } } \ No newline at end of file diff --git a/print-sample/src/main/res/color/icon.xml b/print-sample/src/main/res/color/icon.xml index 24cf2bd..24795d1 100644 --- a/print-sample/src/main/res/color/icon.xml +++ b/print-sample/src/main/res/color/icon.xml @@ -1,4 +1,19 @@ + + + - diff --git a/print-sample/src/main/res/menu/main.xml b/print-sample/src/main/res/menu/main.xml index d951c89..a4a7517 100644 --- a/print-sample/src/main/res/menu/main.xml +++ b/print-sample/src/main/res/menu/main.xml @@ -1,3 +1,20 @@ + + + + + @@ -6,6 +22,7 @@ #8a000000 + #ffffff \ No newline at end of file diff --git a/print-sample/src/main/res/values/dimens.xml b/print-sample/src/main/res/values/dimens.xml index 908b63a..9369545 100644 --- a/print-sample/src/main/res/values/dimens.xml +++ b/print-sample/src/main/res/values/dimens.xml @@ -1,5 +1,23 @@ + + + + 32dp \ No newline at end of file diff --git a/print-sample/src/main/res/values/icons.xml b/print-sample/src/main/res/values/icons.xml deleted file mode 100644 index 7dd71e7..0000000 --- a/print-sample/src/main/res/values/icons.xml +++ /dev/null @@ -1,438 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/print-sample/src/main/res/values/icons_holo.xml b/print-sample/src/main/res/values/icons_holo.xml new file mode 100644 index 0000000..a6b356d --- /dev/null +++ b/print-sample/src/main/res/values/icons_holo.xml @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/print-sample/src/main/res/values/icons_material.xml b/print-sample/src/main/res/values/icons_material.xml new file mode 100644 index 0000000..0f3940f --- /dev/null +++ b/print-sample/src/main/res/values/icons_material.xml @@ -0,0 +1,454 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/print-sample/src/main/res/values/strings.xml b/print-sample/src/main/res/values/strings.xml index ef4ae30..0effc85 100644 --- a/print-sample/src/main/res/values/strings.xml +++ b/print-sample/src/main/res/values/strings.xml @@ -1,13 +1,27 @@ + + Print Info - Size: %ddp - ADB \ No newline at end of file diff --git a/print-sample/src/main/res/values/styles.xml b/print-sample/src/main/res/values/styles.xml index f2cc7bb..c238c5b 100644 --- a/print-sample/src/main/res/values/styles.xml +++ b/print-sample/src/main/res/values/styles.xml @@ -1,3 +1,20 @@ + + + diff --git a/print/build.gradle b/print/build.gradle index 9c4ca2f..112eae6 100644 --- a/print/build.gradle +++ b/print/build.gradle @@ -1,15 +1,15 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 20 - buildToolsVersion "20.0.0" + compileSdkVersion 21 + buildToolsVersion "21.0.1" defaultConfig { applicationId "com.github.johnkil.print" minSdkVersion 8 - targetSdkVersion 20 - versionCode 2 - versionName "1.1.0" + targetSdkVersion 21 + versionCode 3 + versionName "1.2.0" } } diff --git a/print/gradle.properties b/print/gradle.properties index 466b9e2..b60bb44 100644 --- a/print/gradle.properties +++ b/print/gradle.properties @@ -1,3 +1,3 @@ -POM_NAME=Print Library +POM_NAME=Print POM_ARTIFACT_ID=print POM_PACKAGING=aar \ No newline at end of file diff --git a/print/src/main/AndroidManifest.xml b/print/src/main/AndroidManifest.xml index 952e19c..31a67af 100644 --- a/print/src/main/AndroidManifest.xml +++ b/print/src/main/AndroidManifest.xml @@ -2,4 +2,4 @@ - + \ No newline at end of file diff --git a/print/src/main/java/com/github/johnkil/print/IPrint.java b/print/src/main/java/com/github/johnkil/print/IPrint.java new file mode 100644 index 0000000..c04cf1b --- /dev/null +++ b/print/src/main/java/com/github/johnkil/print/IPrint.java @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2014 Evgeny Shishkin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.github.johnkil.print; + +import android.content.res.ColorStateList; +import android.graphics.Typeface; + +interface IPrint { + + /** + * Sets the icon text from resources. + * + * @attr ref R.styleable#PrintView_iconText + * @see #setIconText(CharSequence) + * @see #getIconText() + */ + void setIconText(int resId); + + /** + * Sets the icon text. + * + * @attr ref R.styleable#PrintView_iconText + * @see #setIconText(int) + * @see #getIconText() + */ + void setIconText(CharSequence text); + + /** + * Return the icon text, or null if icon text is not set. + * + * @attr ref R.styleable#PrintView_iconText + * @see #setIconText(int) + * @see #setIconText(CharSequence) + */ + CharSequence getIconText(); + + /** + * Sets the icon color from resources. + * + * @attr ref R.styleable#PrintView_iconColor + * @see #setIconColor(android.content.res.ColorStateList) + * @see #getIconColor() + */ + void setIconColor(int resId); + + /** + * Sets the icon color. + * + * @attr ref R.styleable#PrintView_iconColor + * @see #setIconColor(int) + * @see #getIconColor() + */ + void setIconColor(ColorStateList colors); + + /** + * Return the icon colors for the different states (normal, selected, focused). + * + * @attr ref R.styleable#PrintView_iconColor + * @see #setIconColor(ColorStateList) + * @see #setIconColor(int) + */ + ColorStateList getIconColor(); + + /** + * Sets the icon size from resources. + * + * @attr ref R.styleable#PrintView_iconSize + * @see #setIconSize(int, float) + * @see #getIconSize() + */ + void setIconSize(int resId); + + /** + * Sets the icon size to a given unit and value. See {@link android.util.TypedValue} + * for the possible dimension units. + * + * @param unit The desired dimension unit. + * @param size The desired size in the given units. + * @attr ref R.styleable#PrintView_iconSize + * @see #setIconSize(int) + * @see #getIconSize() + */ + void setIconSize(int unit, float size); + + /** + * Return the icon size (in pixels). + * + * @attr ref R.styleable#PrintView_iconSize + * @see #setIconSize(int) + * @see #setIconSize(int, float) + */ + int getIconSize(); + + /** + * Sets the iconic font from assets. + * + * @param path The file name of the font in the assets directory, e.g. "fonts/iconic-font.ttf". + * @attr ref R.styleable#PrintView_iconFont + * @see #setIconFont(android.graphics.Typeface) + * @see #getIconFont() + */ + void setIconFont(String path); + + /** + * Sets the iconic font. + * + * @attr ref R.styleable#PrintView_iconFont + * @see #setIconFont(String) + * @see #getIconFont() + */ + void setIconFont(Typeface font); + + /** + * Return the iconic font. + * + * @attr ref R.styleable#PrintView_iconFont + * @see #setIconFont(String) + * @see #setIconFont(android.graphics.Typeface) + */ + Typeface getIconFont(); + +} \ No newline at end of file diff --git a/print/src/main/java/com/github/johnkil/print/IPrintView.java b/print/src/main/java/com/github/johnkil/print/IPrintView.java new file mode 100644 index 0000000..4c47503 --- /dev/null +++ b/print/src/main/java/com/github/johnkil/print/IPrintView.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2014 Evgeny Shishkin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.github.johnkil.print; + +interface IPrintView extends IPrint { + + /** + * Return the icon, or null if no icon has been assigned. + */ + PrintDrawable getIcon(); + +} \ No newline at end of file diff --git a/print/src/main/java/com/github/johnkil/print/Print.java b/print/src/main/java/com/github/johnkil/print/Print.java deleted file mode 100644 index a4cad62..0000000 --- a/print/src/main/java/com/github/johnkil/print/Print.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2014 Evgeny Shishkin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.github.johnkil.print; - -import android.content.res.AssetManager; -import android.graphics.Paint; -import android.graphics.Typeface; -import android.widget.TextView; - -/** - * @author Evgeny Shishkin - */ -public class Print { - - private static Typeface sTypeface; - - /** - * Initialize the iconic font. - * - * @param assets The application's asset manager. - * @param fontAssetPath The file name of the font data in the assets directory. - */ - public static void initFont(AssetManager assets, String fontAssetPath) { - sTypeface = Typeface.createFromAsset(assets, fontAssetPath); - if (sTypeface == null) { - throw new IllegalArgumentException("Error font initializing"); - } - } - - /** - * @return true if iconic font is initialized. - */ - public static boolean isFontInit() { - return sTypeface != null; - } - - /** - * @return iconic font. - */ - public static Typeface getFont() { - return sTypeface; - } - - /** - * Apply iconic font for TextView. - * - * @param view TextView. - */ - public static void applyFont(TextView view) { - if (isFontInit()) { - view.setPaintFlags(view.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); - view.setTypeface(sTypeface); - } else { - throw new IllegalStateException("Font is not initialized"); - } - } - - /** - * Apply iconic font for Paint. - * - * @param paint Paint. - */ - public static void applyFont(Paint paint) { - if (isFontInit()) { - paint.setSubpixelText(true); - paint.setAntiAlias(true); - paint.setTypeface(sTypeface); - } else { - throw new IllegalStateException("Font is not initialized"); - } - } - -} \ No newline at end of file diff --git a/print/src/main/java/com/github/johnkil/print/PrintButton.java b/print/src/main/java/com/github/johnkil/print/PrintButton.java new file mode 100644 index 0000000..2f76fa1 --- /dev/null +++ b/print/src/main/java/com/github/johnkil/print/PrintButton.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2014 Evgeny Shishkin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.github.johnkil.print; + +import android.content.Context; +import android.content.res.ColorStateList; +import android.graphics.Typeface; +import android.util.AttributeSet; +import android.util.TypedValue; +import android.widget.ImageButton; + +/** + * Button for displaying icons from iconic fonts. + * + * @author Evgeny Shishkin + */ +public class PrintButton extends ImageButton implements IPrintView { + + public PrintButton(Context context) { + super(context); + init(context, null); + } + + public PrintButton(Context context, AttributeSet attrs) { + super(context, attrs); + init(context, attrs); + } + + public PrintButton(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + init(context, attrs); + } + + private void init(Context context, AttributeSet attrs) { + PrintDrawable icon = PrintViewUtils.initIcon(context, attrs, isInEditMode()); + setImageDrawable(icon); + } + + @Override + public PrintDrawable getIcon() { + return (PrintDrawable) getDrawable(); + } + + @Override + public void setIconText(int resId) { + getIcon().setIconText(resId); + } + + @Override + public void setIconText(CharSequence text) { + getIcon().setIconText(text); + } + + @Override + public CharSequence getIconText() { + return getIcon().getIconText(); + } + + @Override + public void setIconColor(int resId) { + getIcon().setIconColor(resId); + } + + @Override + public void setIconColor(ColorStateList colors) { + getIcon().setIconColor(colors); + } + + @Override + public final ColorStateList getIconColor() { + return getIcon().getIconColor(); + } + + @Override + public void setIconSize(int resId) { + getIcon().setIconSize(resId); + // hack for calling resizeFromDrawable() + setSelected(isSelected()); + } + + @Override + public void setIconSize(int unit, float size) { + getIcon().setIconSize(unit, size); + // hack for calling resizeFromDrawable() + setSelected(isSelected()); + } + + @Override + public int getIconSize() { + return getIcon().getIconSize(); + } + + @Override + public void setIconFont(String path) { + getIcon().setIconFont(path); + } + + @Override + public void setIconFont(Typeface font) { + getIcon().setIconFont(font); + } + + @Override + public Typeface getIconFont() { + return getIcon().getIconFont(); + } + +} \ No newline at end of file diff --git a/print/src/main/java/com/github/johnkil/print/PrintConfig.java b/print/src/main/java/com/github/johnkil/print/PrintConfig.java new file mode 100644 index 0000000..906fad8 --- /dev/null +++ b/print/src/main/java/com/github/johnkil/print/PrintConfig.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2014 Evgeny Shishkin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.github.johnkil.print; + +import android.content.res.AssetManager; +import android.graphics.Typeface; + +public class PrintConfig { + + private static PrintConfig sInstance; + + /** + * Define the default iconic font. + * + * @param assets The application's asset manager. + * @param defaultFontPath The file name of the font in the assets directory, + * e.g. "fonts/iconic-font.ttf". + * @see #initDefault(Typeface) + */ + public static void initDefault(AssetManager assets, String defaultFontPath) { + Typeface defaultFont = TypefaceManager.load(assets, defaultFontPath); + initDefault(defaultFont); + } + + /** + * Define the default iconic font. + * + * @see #initDefault(AssetManager, String) + */ + public static void initDefault(Typeface defaultFont) { + sInstance = new PrintConfig(defaultFont); + } + + static PrintConfig get() { + if (sInstance == null) + sInstance = new PrintConfig(); + return sInstance; + } + + + private final Typeface mFont; + private final boolean mIsFontSet; + + private PrintConfig() { + this(null); + } + + private PrintConfig(Typeface defaultFont) { + mFont = defaultFont; + mIsFontSet = defaultFont != null; + } + + /** + * @return the default font. + */ + Typeface getFont() { + return mFont; + } + + /** + * @return true if default font is set. + */ + boolean isFontSet() { + return mIsFontSet; + } + +} \ No newline at end of file diff --git a/print/src/main/java/com/github/johnkil/print/PrintDrawable.java b/print/src/main/java/com/github/johnkil/print/PrintDrawable.java new file mode 100644 index 0000000..08fd2f9 --- /dev/null +++ b/print/src/main/java/com/github/johnkil/print/PrintDrawable.java @@ -0,0 +1,277 @@ +/* + * Copyright (C) 2014 Evgeny Shishkin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.github.johnkil.print; + +import android.content.Context; +import android.content.res.ColorStateList; +import android.graphics.Canvas; +import android.graphics.ColorFilter; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.PixelFormat; +import android.graphics.Typeface; +import android.graphics.drawable.Drawable; +import android.util.Log; +import android.util.TypedValue; + +/** + * Drawable for displaying icons from iconic fonts. + * + * @author Evgeny Shishkin + */ +public class PrintDrawable extends Drawable implements IPrint { + + /** + * Fluent API for creating {@link PrintDrawable} instances. + */ + public static class Builder { + private final Context context; + + private CharSequence iconText; + private ColorStateList iconColor; + private Typeface iconFont; + private int iconSize; + + /** + * Start building a new {@link PrintDrawable} instance. + */ + public Builder(Context context) { + this.context = context; + } + + public Builder iconText(int resId) { + return iconText(context.getString(resId)); + } + + public Builder iconText(CharSequence text) { + iconText = text; + return this; + } + + public Builder iconColor(int resId) { + return iconColor(context.getResources().getColorStateList(resId)); + } + + public Builder iconColor(ColorStateList colors) { + if (colors == null) { + throw new IllegalArgumentException("Color must not be null."); + } + iconColor = colors; + return this; + } + + public Builder iconFont(String fontAssetPath) { + return iconFont(TypefaceManager.load(context.getAssets(), fontAssetPath)); + } + + public Builder iconFont(Typeface font) { + if (font == null) { + throw new IllegalArgumentException("Font must not be null."); + } + iconFont = font; + return this; + } + + public Builder iconSize(int resId) { + iconSize = context.getResources().getDimensionPixelSize(resId); + return this; + } + + public Builder iconSize(int unit, float size) { + iconSize = (int) TypedValue.applyDimension(unit, size, context.getResources().getDisplayMetrics()); + return this; + } + + /** + * Create the {@link PrintDrawable} instance. + */ + public PrintDrawable build() { + if (iconFont == null) { + PrintConfig config = PrintConfig.get(); + if (config.isFontSet()) { + iconFont = config.getFont(); + } else { + Log.w("Print", "The iconic font is not set."); + } + } + + return new PrintDrawable(context, iconText, iconColor, iconFont, iconSize); + } + } + + private final Context mContext; + private final Paint mPaint; + private Path mPath; + + private CharSequence mIconText; + private ColorStateList mIconColor; + private Typeface mIconFont; + private int mIconSize; + + private int mCurIconColor; + + private PrintDrawable(Context context, CharSequence iconText, + ColorStateList iconColor, Typeface iconFont, int iconSize) { + mContext = context; + mPaint = new Paint(); + mPaint.setFlags(mPaint.getFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); + mPath = new Path(); + + mIconText = iconText; + mIconColor = iconColor; + mIconFont = iconFont; + mIconSize = iconSize; + + mPaint.setTextSize(mIconSize); + mPaint.setTypeface(mIconFont); + updateIconColors(); + } + + @Override + public void setIconText(int resId) { + setIconText(mContext.getText(resId)); + } + + @Override + public void setIconText(CharSequence iconText) { + mIconText = iconText; + invalidateSelf(); + } + + @Override + public CharSequence getIconText() { + return mIconText; + } + + @Override + public void setIconColor(int resId) { + setIconColor(mContext.getResources().getColorStateList(resId)); + } + + @Override + public void setIconColor(ColorStateList colors) { + if (colors == null) { + throw new IllegalArgumentException("Color must not be null."); + } + mIconColor = colors; + updateIconColors(); + invalidateSelf(); + } + + @Override + public ColorStateList getIconColor() { + return mIconColor; + } + + @Override + public void setIconFont(String path) { + setIconFont(TypefaceManager.load(mContext.getAssets(), path)); + } + + @Override + public void setIconFont(Typeface font) { + if (font == null) { + throw new IllegalArgumentException("Font must not be null."); + } + mIconFont = font; + mPaint.setTypeface(mIconFont); + invalidateSelf(); + } + + @Override + public Typeface getIconFont() { + return mIconFont; + } + + @Override + public void setIconSize(int resId) { + setIconSize(TypedValue.COMPLEX_UNIT_PX, + mContext.getResources().getDimensionPixelSize(resId)); + } + + @Override + public void setIconSize(int unit, float size) { + int sizeInPx = (int) TypedValue.applyDimension(unit, size, mContext.getResources().getDisplayMetrics()); + mIconSize = sizeInPx; + mPaint.setTextSize(mIconSize); + invalidateSelf(); + } + + @Override + public int getIconSize() { + return mIconSize; + } + + private void updateIconColors() { + int color = mIconColor.getColorForState(getState(), 0); + if (color != mCurIconColor) { + mCurIconColor = color; + mPaint.setColor(mCurIconColor); + } + } + + @Override + public boolean isStateful() { + return true; + } + + @Override + protected boolean onStateChange(int[] state) { + if (mIconColor != null && mIconColor.isStateful()) { + updateIconColors(); + invalidateSelf(); + } + return super.onStateChange(state); + } + + @Override + public int getIntrinsicHeight() { + return mIconSize; + } + + @Override + public int getIntrinsicWidth() { + return mIconSize; + } + + @Override + public void draw(Canvas canvas) { + if (mIconText != null) { + float x = 0; + float y = getBounds().height(); + mPaint.getTextPath((String) mIconText, 0, mIconText.length(), x, y, mPath); + mPath.close(); + canvas.drawPath(mPath, mPaint); + } + } + + @Override + public void setAlpha(int alpha) { + mPaint.setAlpha(alpha); + } + + @Override + public void setColorFilter(ColorFilter cf) { + mPaint.setColorFilter(cf); + } + + @Override + public int getOpacity() { + return PixelFormat.TRANSLUCENT; + } + +} \ No newline at end of file diff --git a/print/src/main/java/com/github/johnkil/print/PrintView.java b/print/src/main/java/com/github/johnkil/print/PrintView.java new file mode 100644 index 0000000..d629e1f --- /dev/null +++ b/print/src/main/java/com/github/johnkil/print/PrintView.java @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2014 Evgeny Shishkin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.github.johnkil.print; + +import android.content.Context; +import android.content.res.ColorStateList; +import android.graphics.Typeface; +import android.util.AttributeSet; +import android.widget.ImageView; + +/** + * View for displaying icons from iconic fonts. + * + * @author Evgeny Shishkin + */ +public class PrintView extends ImageView implements IPrintView { + + public PrintView(Context context) { + super(context); + init(context, null); + } + + public PrintView(Context context, AttributeSet attrs) { + super(context, attrs); + init(context, attrs); + } + + public PrintView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + init(context, attrs); + } + + private void init(Context context, AttributeSet attrs) { + PrintDrawable icon = PrintViewUtils.initIcon(context, attrs, isInEditMode()); + setImageDrawable(icon); + } + + @Override + public PrintDrawable getIcon() { + return (PrintDrawable) getDrawable(); + } + + @Override + public void setIconText(int resId) { + getIcon().setIconText(resId); + } + + @Override + public void setIconText(CharSequence text) { + getIcon().setIconText(text); + } + + @Override + public CharSequence getIconText() { + return getIcon().getIconText(); + } + + @Override + public void setIconColor(int resId) { + getIcon().setIconColor(resId); + } + + @Override + public void setIconColor(ColorStateList colors) { + getIcon().setIconColor(colors); + } + + @Override + public final ColorStateList getIconColor() { + return getIcon().getIconColor(); + } + + @Override + public void setIconSize(int resId) { + getIcon().setIconSize(resId); + // hack for calling resizeFromDrawable() + setSelected(isSelected()); + } + + @Override + public void setIconSize(int unit, float size) { + getIcon().setIconSize(unit, size); + // hack for calling resizeFromDrawable() + setSelected(isSelected()); + } + + @Override + public int getIconSize() { + return getIcon().getIconSize(); + } + + @Override + public void setIconFont(String path) { + getIcon().setIconFont(path); + } + + @Override + public void setIconFont(Typeface font) { + getIcon().setIconFont(font); + } + + @Override + public Typeface getIconFont() { + return getIcon().getIconFont(); + } + +} \ No newline at end of file diff --git a/print/src/main/java/com/github/johnkil/print/PrintViewUtils.java b/print/src/main/java/com/github/johnkil/print/PrintViewUtils.java new file mode 100644 index 0000000..33db2b9 --- /dev/null +++ b/print/src/main/java/com/github/johnkil/print/PrintViewUtils.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2014 Evgeny Shishkin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.github.johnkil.print; + +import android.content.Context; +import android.content.res.ColorStateList; +import android.content.res.TypedArray; +import android.util.AttributeSet; +import android.util.TypedValue; + +class PrintViewUtils { + + /** + * Initialization of icon for print views. + * + * @param context The Context the view is running in, through which it can access the current + * theme, resources, etc. + * @param attrs The attributes of the XML tag that is inflating the view. + * @param inEditMode Indicates whether this View is currently in edit mode. + * @return The icon to display. + */ + static PrintDrawable initIcon(Context context, AttributeSet attrs, boolean inEditMode) { + PrintDrawable.Builder iconBuilder = new PrintDrawable.Builder(context); + + if (attrs != null) { + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PrintView); + + if (a.hasValue(R.styleable.PrintView_iconText)) { + String iconText = a.getString(R.styleable.PrintView_iconText); + iconBuilder.iconText(iconText); + } + + if (!inEditMode && a.hasValue(R.styleable.PrintView_iconFont)) { + String iconFontPath = a.getString(R.styleable.PrintView_iconFont); + iconBuilder.iconFont(TypefaceManager.load(context.getAssets(), iconFontPath)); + } + + if (a.hasValue(R.styleable.PrintView_iconColor)) { + ColorStateList iconColor = a.getColorStateList(R.styleable.PrintView_iconColor); + iconBuilder.iconColor(iconColor); + } + + int iconSize = a.getDimensionPixelSize(R.styleable.PrintView_iconSize, 0); + iconBuilder.iconSize(TypedValue.COMPLEX_UNIT_PX, iconSize); + + a.recycle(); + } + + return iconBuilder.build(); + } + + private PrintViewUtils() { + } + +} \ No newline at end of file diff --git a/print/src/main/java/com/github/johnkil/print/TypefaceManager.java b/print/src/main/java/com/github/johnkil/print/TypefaceManager.java new file mode 100644 index 0000000..9da40b2 --- /dev/null +++ b/print/src/main/java/com/github/johnkil/print/TypefaceManager.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2014 Evgeny Shishkin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.github.johnkil.print; + +import android.content.res.AssetManager; +import android.graphics.Typeface; + +import java.util.HashMap; + +/** + * A helper loading {@link android.graphics.Typeface} avoiding the leak of the font when loaded + * by multiple calls to {@link android.graphics.Typeface#createFromAsset(android.content.res.AssetManager, String)} + * on pre-ICS versions. + */ +class TypefaceManager { + + /** + * The cached typefaces. + */ + private static final HashMap sTypefaces = new HashMap(); + + /** + * Load a typeface from the specified font data. + * + * @param assets The application's asset manager. + * @param path The file name of the font data in the assets directory. + */ + static Typeface load(AssetManager assets, String path) { + synchronized (sTypefaces) { + Typeface typeface; + if (sTypefaces.containsKey(path)) { + typeface = sTypefaces.get(path); + } else { + typeface = Typeface.createFromAsset(assets, path); + sTypefaces.put(path, typeface); + } + return typeface; + } + } + + private TypefaceManager() { + } + +} \ No newline at end of file diff --git a/print/src/main/java/com/github/johnkil/print/drawable/PrintDrawable.java b/print/src/main/java/com/github/johnkil/print/drawable/PrintDrawable.java deleted file mode 100644 index dc34321..0000000 --- a/print/src/main/java/com/github/johnkil/print/drawable/PrintDrawable.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2014 Evgeny Shishkin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.github.johnkil.print.drawable; - -import android.graphics.Canvas; -import android.graphics.ColorFilter; -import android.graphics.Paint; -import android.graphics.PixelFormat; -import android.graphics.drawable.Drawable; - -import com.github.johnkil.print.Print; - -/** - * Drawable for displaying icons from iconic fonts. - * - * @author Evgeny Shishkin - */ -public class PrintDrawable extends Drawable { - - private final Paint mPaint; - - private CharSequence mIconText; - private int mIconSize; - private int mIconColor; - private int mPadding; - - public PrintDrawable() { - mPaint = new Paint(); - Print.applyFont(mPaint); - } - - /** - * Set the icon. - * - * @param iconText The string representation of icon. - * @return The current PrintDrawable instance. - */ - public PrintDrawable iconText(CharSequence iconText) { - mIconText = iconText; - invalidateSelf(); - return this; - } - - /** - * Set a color of icon. - * - * @param color The color, usually from android.graphics.Color or 0xFF012345. - * @return The current PrintDrawable instance. - */ - public PrintDrawable iconColor(int color) { - mIconColor = color; - mPaint.setColor(color); - invalidateSelf(); - return this; - } - - /** - * Set a size of icon. - * - * @param size The size in pixels (px). - * @return The current PrintDrawable instance. - */ - public PrintDrawable iconSize(int size) { - mIconSize = size; - mPaint.setTextSize(size); - invalidateSelf(); - return this; - } - - /** - * Set a padding of the drawable. - * - * @param padding the padding in pixels - * @return The current PrintDrawable instance. - */ - public PrintDrawable padding(int padding) { - mPadding = padding; - return this; - } - - @Override - public int getIntrinsicHeight() { - int height = mIconSize + 2 * mPadding; - return height; - } - - @Override - public int getIntrinsicWidth() { - int width = mIconSize + 2 * mPadding; - return width; - } - - @Override - public void draw(Canvas canvas) { - float x = mPadding; - float y = getBounds().height() - mPadding; - - if (mIconText != null) { - canvas.drawText(mIconText.toString(), x, y, mPaint); - } - } - - @Override - public void setAlpha(int alpha) { - mPaint.setAlpha(alpha); - } - - @Override - public void setColorFilter(ColorFilter cf) { - mPaint.setColorFilter(cf); - } - - @Override - public int getOpacity() { - return PixelFormat.TRANSLUCENT; - } - -} \ No newline at end of file diff --git a/print/src/main/java/com/github/johnkil/print/widget/PrintButton.java b/print/src/main/java/com/github/johnkil/print/widget/PrintButton.java deleted file mode 100644 index e0ecb8d..0000000 --- a/print/src/main/java/com/github/johnkil/print/widget/PrintButton.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright 2014 Evgeny Shishkin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.github.johnkil.print.widget; - -import android.content.Context; -import android.content.res.ColorStateList; -import android.content.res.TypedArray; -import android.util.AttributeSet; -import android.widget.ImageButton; - -import com.github.johnkil.print.R; -import com.github.johnkil.print.drawable.PrintDrawable; - -/** - * Button for displaying icons from iconic fonts. - * - * @author Evgeny Shishkin - */ -public class PrintButton extends ImageButton { - - private PrintDrawable mIcon; - private CharSequence mIconText; - private ColorStateList mIconColor; - private int mIconSize; - - private int mCurIconColor; - - public PrintButton(Context context) { - super(context); - init(context, null); - } - - public PrintButton(Context context, AttributeSet attrs) { - super(context, attrs); - init(context, attrs); - } - - public PrintButton(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - init(context, attrs); - } - - private void init(Context context, AttributeSet attrs) { - if (!isInEditMode()) { - - // setup default values - CharSequence iconText = null; - ColorStateList iconColor = getResources().getColorStateList(R.color.icon_color); - int iconSize = getResources().getDimensionPixelSize(R.dimen.icon_size); - - if (attrs != null) { - - TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PrintView); - - if (a.hasValue(R.styleable.PrintView_iconText)) { - iconText = a.getString(R.styleable.PrintView_iconText); - } - - if (a.hasValue(R.styleable.PrintView_iconColor)) { - iconColor = a.getColorStateList(R.styleable.PrintView_iconColor); - } - - iconSize = a.getDimensionPixelSize(R.styleable.PrintView_iconSize, iconSize); - - a.recycle(); - } - - setIconSize(iconSize); - setIconText(iconText); - setIconColor(iconColor); - - invalidateIcon(); - } - } - - /** - * Invalidates the icon drawable. - */ - protected void invalidateIcon() { - mIcon = new PrintDrawable() - .iconText(mIconText) - .iconColor(mCurIconColor) - .iconSize(mIconSize); - setImageDrawable(mIcon); - } - - private void updateIconColors() { - int color = mIconColor.getColorForState(getDrawableState(), 0); - if (color != mCurIconColor) { - mCurIconColor = color; - if (mIcon != null) { - mIcon.iconColor(mCurIconColor); - } - } - } - - /** - * Return the icon, or null if no icon has been assigned. - */ - public PrintDrawable getIcon() { - return mIcon; - } - - /** - * Set icon text. - * - * @attr ref R.styleable#PrintView_iconText - * @see #setIconText(CharSequence) - * @see #getIconText() - */ - public void setIconText(int resId) { - setIconText(getContext().getResources().getText(resId)); - } - - /** - * Set icon text. - * - * @attr ref R.styleable#PrintView_iconText - * @see #setIconText(int) - * @see #getIconText() - */ - public void setIconText(CharSequence text) { - mIconText = text; - if (mIcon != null) { - mIcon.iconText(mIconText); - } - } - - /** - * Return the icon text the PrintButton is displaying - * - * @attr ref R.styleable#PrintView_iconText - * @see #setIconText(int) - * @see #setIconText(CharSequence) - */ - public CharSequence getIconText() { - return mIconText; - } - - /** - * Sets the icon color for all the states (normal, selected, focused) to be this color. - * - * @attr ref R.styleable#PrintView_iconColor - * @see #setIconColor(ColorStateList) - * @see #getIconColors() - */ - public void setIconColor(int color) { - setIconColor(ColorStateList.valueOf(color)); - } - - /** - * Sets the icon color. - * - * @attr ref R.styleable#PrintView_iconColor - * @see #setIconColor(int) - * @see #getIconColors() - */ - public void setIconColor(ColorStateList colors) { - if (colors == null) { - throw new NullPointerException(); - } - mIconColor = colors; - updateIconColors(); - } - - /** - * Gets the icon colors for the different states (normal, selected, focused) of the PrintView. - * - * @attr ref R.styleable#PrintView_iconColor - * @see #setIconColor(ColorStateList) - * @see #setIconColor(int) - */ - public final ColorStateList getIconColors() { - return mIconColor; - } - - /** - * Set the icon size in pixels. - * - * @attr ref R.styleable#PrintView_iconSize - * @see #getIconSize() - */ - public void setIconSize(int size) { - mIconSize = size; - if (mIcon != null) { - mIcon.iconSize(mIconSize); - // hack for calling resizeFromDrawable() - setSelected(isSelected()); - } - } - - /** - * Get the size (in pixels) of the icon in this PrintButton. - * - * @attr ref R.styleable#PrintView_iconSize - * @see #setIconSize(int) - */ - public int getIconSize() { - return mIconSize; - } - - @Override - protected void drawableStateChanged() { - super.drawableStateChanged(); - - if (mIconColor != null && mIconColor.isStateful()) { - updateIconColors(); - } - } - -} \ No newline at end of file diff --git a/print/src/main/java/com/github/johnkil/print/widget/PrintView.java b/print/src/main/java/com/github/johnkil/print/widget/PrintView.java deleted file mode 100644 index cfd3772..0000000 --- a/print/src/main/java/com/github/johnkil/print/widget/PrintView.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright 2014 Evgeny Shishkin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.github.johnkil.print.widget; - -import android.content.Context; -import android.content.res.ColorStateList; -import android.content.res.TypedArray; -import android.util.AttributeSet; -import android.widget.ImageView; - -import com.github.johnkil.print.R; -import com.github.johnkil.print.drawable.PrintDrawable; - -/** - * View for displaying icons from iconic fonts. - * - * @author Evgeny Shishkin - */ -public class PrintView extends ImageView { - - private PrintDrawable mIcon; - private CharSequence mIconText; - private ColorStateList mIconColor; - private int mIconSize; - - private int mCurIconColor; - - public PrintView(Context context) { - super(context); - init(context, null); - } - - public PrintView(Context context, AttributeSet attrs) { - super(context, attrs); - init(context, attrs); - } - - public PrintView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - init(context, attrs); - } - - private void init(Context context, AttributeSet attrs) { - if (!isInEditMode()) { - - // setup default values - CharSequence iconText = null; - ColorStateList iconColor = getResources().getColorStateList(R.color.icon_color); - int iconSize = getResources().getDimensionPixelSize(R.dimen.icon_size); - - if (attrs != null) { - - TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PrintView); - - if (a.hasValue(R.styleable.PrintView_iconText)) { - iconText = a.getString(R.styleable.PrintView_iconText); - } - - if (a.hasValue(R.styleable.PrintView_iconColor)) { - iconColor = a.getColorStateList(R.styleable.PrintView_iconColor); - } - - iconSize = a.getDimensionPixelSize(R.styleable.PrintView_iconSize, iconSize); - - a.recycle(); - } - - setIconSize(iconSize); - setIconText(iconText); - setIconColor(iconColor); - - invalidateIcon(); - } - } - - /** - * Invalidates the icon drawable. - */ - protected void invalidateIcon() { - mIcon = new PrintDrawable() - .iconText(mIconText) - .iconColor(mCurIconColor) - .iconSize(mIconSize); - setImageDrawable(mIcon); - } - - private void updateIconColors() { - int color = mIconColor.getColorForState(getDrawableState(), 0); - if (color != mCurIconColor) { - mCurIconColor = color; - if (mIcon != null) { - mIcon.iconColor(mCurIconColor); - } - } - } - - /** - * Return the icon, or null if no icon has been assigned. - */ - public PrintDrawable getIcon() { - return mIcon; - } - - /** - * Set icon text. - * - * @attr ref R.styleable#PrintView_iconText - * @see #setIconText(CharSequence) - * @see #getIconText() - */ - public void setIconText(int resId) { - setIconText(getContext().getResources().getText(resId)); - } - - /** - * Set icon text. - * - * @attr ref R.styleable#PrintView_iconText - * @see #setIconText(int) - * @see #getIconText() - */ - public void setIconText(CharSequence text) { - mIconText = text; - if (mIcon != null) { - mIcon.iconText(mIconText); - } - } - - /** - * Return the icon text the PrintView is displaying - * - * @attr ref R.styleable#PrintView_iconText - * @see #setIconText(int) - * @see #setIconText(CharSequence) - */ - public CharSequence getIconText() { - return mIconText; - } - - /** - * Sets the icon color for all the states (normal, selected, focused) to be this color. - * - * @attr ref R.styleable#PrintView_iconColor - * @see #setIconColor(ColorStateList) - * @see #getIconColors() - */ - public void setIconColor(int color) { - setIconColor(ColorStateList.valueOf(color)); - } - - /** - * Sets the icon color. - * - * @attr ref R.styleable#PrintView_iconColor - * @see #setIconColor(int) - * @see #getIconColors() - */ - public void setIconColor(ColorStateList colors) { - if (colors == null) { - throw new NullPointerException(); - } - mIconColor = colors; - updateIconColors(); - } - - /** - * Gets the icon colors for the different states (normal, selected, focused) of the PrintView. - * - * @attr ref R.styleable#PrintView_iconColor - * @see #setIconColor(ColorStateList) - * @see #setIconColor(int) - */ - public final ColorStateList getIconColors() { - return mIconColor; - } - - /** - * Set the icon size in pixels. - * - * @attr ref R.styleable#PrintView_iconSize - * @see #getIconSize() - */ - public void setIconSize(int size) { - mIconSize = size; - if (mIcon != null) { - mIcon.iconSize(mIconSize); - // hack for calling resizeFromDrawable() - setSelected(isSelected()); - } - } - - /** - * Get the size (in pixels) of the icon in this PrintView. - * - * @attr ref R.styleable#PrintView_iconSize - * @see #setIconSize(int) - */ - public int getIconSize() { - return mIconSize; - } - - @Override - protected void drawableStateChanged() { - super.drawableStateChanged(); - - if (mIconColor != null && mIconColor.isStateful()) { - updateIconColors(); - } - } - -} \ No newline at end of file diff --git a/print/src/main/res/values/attrs.xml b/print/src/main/res/values/attrs.xml index f2a0a77..11db765 100644 --- a/print/src/main/res/values/attrs.xml +++ b/print/src/main/res/values/attrs.xml @@ -1,20 +1,20 @@ + ~ Copyright (C) 2014 Evgeny Shishkin + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + @@ -24,6 +24,8 @@ + + \ No newline at end of file diff --git a/print/src/main/res/values/colors.xml b/print/src/main/res/values/colors.xml deleted file mode 100644 index c641c14..0000000 --- a/print/src/main/res/values/colors.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - #333 - - \ No newline at end of file diff --git a/print/src/main/res/values/dimens.xml b/print/src/main/res/values/dimens.xml deleted file mode 100644 index 88697e8..0000000 --- a/print/src/main/res/values/dimens.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - 32dp - - \ No newline at end of file