/PTTextView

Implementation of TextView with support for Google & Paratype PT font family

Primary LanguageJavaOtherNOASSERTION

Android-PTTextView

Deprecated - use new TextView android:font attribute instead

Android Arsenal

image

An implementation of a TextView with support of Paratype & Google PT font family

A project was inspired by RobotoTextView

####List of supported fonts:

image

###List of supported widgets:

  • PTTextView
  • PTEditText
  • PTButton
  • PTCheckBox
  • PTAutocompleteTextView
  • PTCheckedTextView
  • PTCompoundButton
  • PTExtractEditText
  • PTMultiAutoCompleteTextView
  • PTRadioButton
  • PTSwitch
  • PTToggleButton
  • PTChronometer
  • PTDigitalClock
  • PTTextClock

image

Get it on Google Play

Download

Download the latest JAR or grab via Maven:

<dependency>
  <groupId>com.github.olegosipenko</groupId>
  <artifactId>PTTextView</artifactId>
  <version>1.0.0</version>
</dependency>

or Gradle:

repositories {
    jcenter()
}

dependencies {
    compile 'com.github.olegosipenko:pttextview:1.0.0'
}

Usage

In XML

To setup a typeface you must specify the parameter typeface:

<pttextview.widget.PTTextView
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:typeface="pt_serif_bold_italic"/>

or specify a set of parameters fontFamily, textWeight and textStyle:

<pttextview.widget.PTTextView
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:fontFamily="pt_mono"
            app:textWeight="bold"
            app:textStyle="regular"/>

Setup typeface in code:

In Code

Using parameter typeface:

PTTextView textView = new PTTextView(context);
Typeface typeface = PTTypefaceManager.getTypeface(
        context, PTTypefaceManager.Typefaces.PT_SERIF_CAPTION_ITALIC);
PTTextViewUtils.setTypeface(textView, typeface);

Using parameters fontFamily, textWeight and textStyle:

PTTextViewUtils textView = new PTTextViewUtils(context);
Typeface typeface = PTTypefaceManager.getTypeface(
        context,
        PTTypefaceManager.FontFamilies.PT_SANS_NARROW,
        PTTypefaceManager.TextWeights.BOLD,
        PTTypefaceManager.TextStyles.REGULAR);
PTTextViewUtils.setTypeface(textView, typeface);

With Span

Using parameter typeface:

PTTypefaceSpan span = new PTTypefaceSpan(
        context,
        PTTypefaceManager.Typefaces.PT_SERIF_CAPTION_ITALIC);
Spannable spannable = new SpannableString("text");
spannable.setSpan(span, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

Using parameters fontFamily, textWeight and textStyle:

PTTypefaceSpan span = new PTTypefaceSpan(
        context,
        PTTypefaceManager.FontFamilies.PT_SERIF,
        PTTypefaceManager.TextWeights.BOLD,
        PTTypefaceManager.TextStyles.ITALIC);
Spannable spannable = new SpannableString("text");
spannable.setSpan(span, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

Gradle

If you intend to use is not all fonts, the extra fonts can be removed.

android.applicationVariants.all{ variant ->
    variant.mergeAssets.doFirst {
        File fonts = file("${projectDir}/build/intermediates/exploded-aar/pttextview/pttextview/1.0.0/assets/fonts")
        if (fonts.exists()) {
            for (File file : fonts.listFiles()) {
                if (file.getName().contains("PT Sans")) {
                    println("delete " + file.getName() + " font")
                    file.delete()
                };
            }
        }
    }
}

Compatibility

The widget supports API down to Android 2.1 (API >= 7)

Credits

The idea of this library was inspired by [Android-RobotoTextView] (https://github.com/johnkil/Android-RobotoTextView) by Evgeny Shishkin

License

Copyright (C) 2015 Oleg Osipenko

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.