From 5d823d73a8e55e43d7a5a4218c92678e3d3f657a Mon Sep 17 00:00:00 2001 From: Gavriil Sitnikov Date: Thu, 12 Nov 2015 03:10:48 +0300 Subject: [PATCH] edittext added --- .../components/views/TypefacedEditText.java | 76 +++++++++++++++++++ .../components/views/TypefacedTextView.java | 1 + 2 files changed, 77 insertions(+) create mode 100644 src/main/java/org/roboswag/components/views/TypefacedEditText.java diff --git a/src/main/java/org/roboswag/components/views/TypefacedEditText.java b/src/main/java/org/roboswag/components/views/TypefacedEditText.java new file mode 100644 index 0000000..e0a1ca6 --- /dev/null +++ b/src/main/java/org/roboswag/components/views/TypefacedEditText.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2015 RoboSwag (Gavriil Sitnikov, Vsevolod Ivanov) + * + * This file is part of RoboSwag library. + * + * 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 org.roboswag.components.views; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Typeface; +import android.util.AttributeSet; +import android.widget.EditText; + +import org.roboswag.components.R; + +import org.roboswag.components.utils.Typefaces; + +/** + * Created by Gavriil Sitnikov on 18/07/2014. + * TextView that supports fonts from Typefaces class + */ +public class TypefacedEditText extends EditText { + + public TypefacedEditText(Context context) { + super(context); + initialize(context, null); + } + + public TypefacedEditText(Context context, AttributeSet attrs) { + super(context, attrs); + initialize(context, attrs); + } + + public TypefacedEditText(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + initialize(context, attrs); + } + + public void setTypeface(String name, int style) { + setTypeface(Typefaces.getByName(getContext(), name), style); + } + + public void setTypeface(String name) { + setTypeface(name, Typeface.NORMAL); + } + + private void initialize(Context context, AttributeSet attrs) { + setIncludeFontPadding(false); + String customTypeface = null; + if (attrs != null) { + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TypefacedTextView); + customTypeface = a.getString(R.styleable.TypefacedTextView_customTypeface); + a.recycle(); + } + + if (customTypeface != null && !isInEditMode()) { + Typeface typeface = getTypeface(); + setTypeface(customTypeface, typeface != null ? typeface.getStyle() : Typeface.NORMAL); + } + } + +} diff --git a/src/main/java/org/roboswag/components/views/TypefacedTextView.java b/src/main/java/org/roboswag/components/views/TypefacedTextView.java index 43b6587..61755ea 100644 --- a/src/main/java/org/roboswag/components/views/TypefacedTextView.java +++ b/src/main/java/org/roboswag/components/views/TypefacedTextView.java @@ -59,6 +59,7 @@ public class TypefacedTextView extends TextView { } private void initialize(Context context, AttributeSet attrs) { + setIncludeFontPadding(false); String customTypeface = null; if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TypefacedTextView);