diff --git a/build.gradle b/build.gradle
index 2f5b0d7..f7df259 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.2.1'
+ classpath 'com.android.tools.build:gradle:3.0.1'
}
}
@@ -14,8 +14,8 @@ allprojects {
}
ext {
- compileSdkVersion = 24
- buildToolsVersion = '24.0.3'
+ compileSdkVersion = 27
+ buildToolsVersion = '27.0.1'
// Android dependencies.
supportAppCompat = 'com.android.support:appcompat-v7:24.2.1'
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 5f2246c..5f770dc 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Fri Oct 14 13:26:25 MSK 2016
+#Wed Feb 28 00:26:16 AMT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-all.zip
\ No newline at end of file
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
diff --git a/print-sample/src/main/res/layout/activity_main.xml b/print-sample/src/main/res/layout/activity_main.xml
index c56697d..9996a18 100644
--- a/print-sample/src/main/res/layout/activity_main.xml
+++ b/print-sample/src/main/res/layout/activity_main.xml
@@ -63,6 +63,18 @@
app:print_iconSize="180dp"
app:print_iconText="@string/ic_material_adb"/>
-
+
+
+
\ 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
index 689fe59..c2e0f05 100644
--- a/print/src/main/java/com/github/johnkil/print/PrintButton.java
+++ b/print/src/main/java/com/github/johnkil/print/PrintButton.java
@@ -1,24 +1,9 @@
-/*
- * 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.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
+import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.os.Build;
import android.support.annotation.ColorRes;
@@ -26,128 +11,219 @@
import android.support.annotation.IntegerRes;
import android.support.annotation.StringRes;
import android.util.AttributeSet;
-import android.widget.ImageButton;
+import android.widget.Button;
/**
- * Button for displaying icons from iconic fonts.
- *
- * @author Evgeny Shishkin
+ * Created by orlandoleite on 2/28/18.
*/
-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 defStyleAttr) {
- super(context, attrs, defStyleAttr);
- init(context, attrs);
- }
-
- @TargetApi(Build.VERSION_CODES.LOLLIPOP)
- public PrintButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
- super(context, attrs, defStyleAttr, defStyleRes);
- 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 setIconTextRes(@StringRes int resId) {
- getIcon().setIconTextRes(resId);
- }
-
- @Override
- public void setIconCodeRes(@IntegerRes int resId) {
- getIcon().setIconCodeRes(resId);
- }
-
- @Override
- public void setIconCode(int code) {
- getIcon().setIconCode(code);
- }
-
- @Override
- public void setIconText(CharSequence text) {
- getIcon().setIconText(text);
- }
-
- @Override
- public CharSequence getIconText() {
- return getIcon().getIconText();
- }
-
- @Override
- public void setIconColorRes(@ColorRes int resId) {
- getIcon().setIconColorRes(resId);
- }
-
- @Override
- public void setIconColor(int color) {
- getIcon().setIconColor(color);
- }
-
- @Override
- public void setIconColor(ColorStateList colors) {
- getIcon().setIconColor(colors);
- }
-
- @Override
- public final ColorStateList getIconColor() {
- return getIcon().getIconColor();
- }
-
- @Override
- public void setIconSizeRes(@DimenRes int resId) {
- getIcon().setIconSizeRes(resId);
- }
-
- @Override
- public void setIconSizeDp(float size) {
- getIcon().setIconSizeDp(size);
- // 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();
- }
+public class PrintButton extends Button implements IPrintView
+{
+ PrintDrawable firstFound = null;
+
+ 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 defStyleAttr )
+ {
+ super( context, attrs, defStyleAttr );
+ init( context, attrs );
+ }
+
+ @TargetApi( Build.VERSION_CODES.LOLLIPOP )
+ public PrintButton( Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes )
+ {
+ super( context, attrs, defStyleAttr, defStyleRes );
+ init( context, attrs );
+ }
+
+ private void init( Context context, AttributeSet attrs )
+ {
+ PrintDrawable left = null, right = null, start = null, end = null, top = null, bottom = null;
+ String iconFontPath = null;
+ ColorStateList iconColor = null;
+ float iconSize;
+
+ if (attrs != null)
+ {
+ boolean inEditMode = isInEditMode();
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PrintView);
+
+ if (!inEditMode && a.hasValue(R.styleable.PrintView_print_iconFont)) {
+ iconFontPath = a.getString(R.styleable.PrintView_print_iconFont);
+ }
+
+ iconColor = a.hasValue(R.styleable.PrintView_print_iconColor) ?
+ a.getColorStateList(R.styleable.PrintView_print_iconColor) :
+ getTextColors();
+
+ iconSize = a.getDimensionPixelSize(R.styleable.PrintView_print_iconSize, 0);
+ if( iconSize == 0 ) iconSize = getTextSize();
+
+ if( a.hasValue( R.styleable.PrintView_print_iconTextLeft ) )
+ {
+ left = PrintViewUtils.buildIcon(context, a.getString( R.styleable.PrintView_print_iconTextLeft ),
+ 0, iconFontPath, iconColor, iconSize, inEditMode);
+ firstFound = left;
+ }
+
+ if( a.hasValue( R.styleable.PrintView_print_iconTextRight ) )
+ {
+ right = PrintViewUtils.buildIcon(context, a.getString( R.styleable.PrintView_print_iconTextRight ),
+ 0, iconFontPath, iconColor, iconSize, inEditMode);
+ if( firstFound == null ) firstFound = right;
+ }
+
+ if( a.hasValue( R.styleable.PrintView_print_iconTextStart ) )
+ {
+ start = PrintViewUtils.buildIcon(context, a.getString( R.styleable.PrintView_print_iconTextStart ),
+ 0, iconFontPath, iconColor, iconSize, inEditMode);
+ firstFound = start;
+ }
+
+ if( a.hasValue( R.styleable.PrintView_print_iconTextEnd ) )
+ {
+ end = PrintViewUtils.buildIcon(context, a.getString( R.styleable.PrintView_print_iconTextEnd ),
+ 0, iconFontPath, iconColor, iconSize, inEditMode);
+ if( firstFound == null ) firstFound = end;
+ }
+
+ if( a.hasValue( R.styleable.PrintView_print_iconTextTop ) )
+ {
+ top = PrintViewUtils.buildIcon(context, a.getString( R.styleable.PrintView_print_iconTextTop ),
+ 0, iconFontPath, iconColor, iconSize, inEditMode);
+ if( firstFound == null ) firstFound = top;
+ }
+
+ if( a.hasValue( R.styleable.PrintView_print_iconTextBottom ) )
+ {
+ bottom = PrintViewUtils.buildIcon(context, a.getString( R.styleable.PrintView_print_iconTextBottom ),
+ 0, iconFontPath, iconColor, iconSize, inEditMode);
+ if( firstFound == null ) firstFound = bottom;
+ }
+
+ a.recycle();
+ }
+
+ if( start != null || end != null )
+ setCompoundDrawablesRelativeWithIntrinsicBounds( start, end, top, bottom );
+ else
+ setCompoundDrawables( left, right, top, bottom );
+ }
+
+ @Override
+ public PrintDrawable getIcon()
+ {
+ return firstFound;
+ }
+
+ @Override
+ public void setIconTextRes( @StringRes int resId )
+ {
+ getIcon().setIconTextRes( resId );
+ }
+
+ @Override
+ public void setIconCodeRes( @IntegerRes int resId )
+ {
+ getIcon().setIconCodeRes( resId );
+ }
+
+ @Override
+ public void setIconCode( int code )
+ {
+ getIcon().setIconCode( code );
+ }
+
+ @Override
+ public void setIconText( CharSequence text )
+ {
+ getIcon().setIconText( text );
+ }
+
+ @Override
+ public CharSequence getIconText()
+ {
+ return getIcon().getIconText();
+ }
+
+ @Override
+ public void setIconColorRes( @ColorRes int resId )
+ {
+ getIcon().setIconColorRes( resId );
+ }
+
+ @Override
+ public void setIconColor( int color )
+ {
+ getIcon().setIconColor( color );
+ }
+
+ @Override
+ public void setIconColor( ColorStateList colors )
+ {
+ getIcon().setIconColor( colors );
+ }
+
+ @Override
+ public final ColorStateList getIconColor()
+ {
+ return getIcon().getIconColor();
+ }
+
+ @Override
+ public void setIconSizeRes( @DimenRes int resId )
+ {
+ getIcon().setIconSizeRes( resId );
+ }
+
+ @Override
+ public void setIconSizeDp( float size )
+ {
+ getIcon().setIconSizeDp( size );
+ // 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/PrintImageButton.java b/print/src/main/java/com/github/johnkil/print/PrintImageButton.java
new file mode 100644
index 0000000..54dbbab
--- /dev/null
+++ b/print/src/main/java/com/github/johnkil/print/PrintImageButton.java
@@ -0,0 +1,153 @@
+/*
+ * 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.annotation.TargetApi;
+import android.content.Context;
+import android.content.res.ColorStateList;
+import android.graphics.Typeface;
+import android.os.Build;
+import android.support.annotation.ColorRes;
+import android.support.annotation.DimenRes;
+import android.support.annotation.IntegerRes;
+import android.support.annotation.StringRes;
+import android.util.AttributeSet;
+import android.widget.ImageButton;
+
+/**
+ * Button for displaying icons from iconic fonts.
+ *
+ * @author Evgeny Shishkin
+ */
+public class PrintImageButton extends ImageButton implements IPrintView {
+
+ public PrintImageButton( Context context) {
+ super(context);
+ init(context, null);
+ }
+
+ public PrintImageButton( Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init(context, attrs);
+ }
+
+ public PrintImageButton( Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ init(context, attrs);
+ }
+
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ public PrintImageButton( Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ 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 setIconTextRes(@StringRes int resId) {
+ getIcon().setIconTextRes(resId);
+ }
+
+ @Override
+ public void setIconCodeRes(@IntegerRes int resId) {
+ getIcon().setIconCodeRes(resId);
+ }
+
+ @Override
+ public void setIconCode(int code) {
+ getIcon().setIconCode(code);
+ }
+
+ @Override
+ public void setIconText(CharSequence text) {
+ getIcon().setIconText(text);
+ }
+
+ @Override
+ public CharSequence getIconText() {
+ return getIcon().getIconText();
+ }
+
+ @Override
+ public void setIconColorRes(@ColorRes int resId) {
+ getIcon().setIconColorRes(resId);
+ }
+
+ @Override
+ public void setIconColor(int color) {
+ getIcon().setIconColor(color);
+ }
+
+ @Override
+ public void setIconColor(ColorStateList colors) {
+ getIcon().setIconColor(colors);
+ }
+
+ @Override
+ public final ColorStateList getIconColor() {
+ return getIcon().getIconColor();
+ }
+
+ @Override
+ public void setIconSizeRes(@DimenRes int resId) {
+ getIcon().setIconSizeRes(resId);
+ }
+
+ @Override
+ public void setIconSizeDp(float size) {
+ getIcon().setIconSizeDp(size);
+ // 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
index fa417ee..54b04ae 100644
--- a/print/src/main/java/com/github/johnkil/print/PrintViewUtils.java
+++ b/print/src/main/java/com/github/johnkil/print/PrintViewUtils.java
@@ -20,6 +20,7 @@
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.util.AttributeSet;
+import android.util.Log;
import android.util.TypedValue;
class PrintViewUtils {
@@ -69,6 +70,28 @@ static PrintDrawable initIcon(Context context, AttributeSet attrs, boolean inEdi
return iconBuilder.build();
}
+
+ static PrintDrawable buildIcon(Context context, String iconText, int iconCode, String iconFontPath,
+ ColorStateList iconColor, float iconSize, boolean inEditMode) {
+ PrintDrawable.Builder iconBuilder = new PrintDrawable.Builder(context);
+
+ iconBuilder.iconText(iconText);
+ if( iconCode != 0 ) iconBuilder.iconCode(iconCode);
+
+ if (!inEditMode && iconFontPath != null) {
+ iconBuilder.iconFont(TypefaceManager.load(context.getAssets(), iconFontPath));
+ }
+
+ iconBuilder.iconColor(iconColor);
+
+ iconBuilder.iconSize(TypedValue.COMPLEX_UNIT_PX, iconSize);
+
+ iconBuilder.inEditMode(inEditMode);
+
+ Log.v("PrintViewUtils", "Conteudo: " + iconText + ", " + iconFontPath + ", " +
+ iconColor + ", " + iconSize + ", " + inEditMode );
+ return iconBuilder.build();
+ }
private PrintViewUtils() {
}
diff --git a/print/src/main/res/values/attrs.xml b/print/src/main/res/values/attrs.xml
index 272747a..628d82f 100644
--- a/print/src/main/res/values/attrs.xml
+++ b/print/src/main/res/values/attrs.xml
@@ -28,6 +28,14 @@
+
+
+
+
+
+
+
+
\ No newline at end of file