Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
mathijspix committed Apr 11, 2017
2 parents 09217fc + 7ed5d52 commit 529f772
Show file tree
Hide file tree
Showing 15 changed files with 270 additions and 40 deletions.
10 changes: 8 additions & 2 deletions app/build.gradle
Expand Up @@ -6,24 +6,30 @@ android {

defaultConfig {
applicationId GROUP + '.fontview.sample'
minSdkVersion 7
minSdkVersion 9
targetSdkVersion Integer.parseInt(ANDROID_TARGET_SDK)
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 {
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile project(':library')
}
58 changes: 58 additions & 0 deletions 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);
}
}
6 changes: 6 additions & 0 deletions app/src/main/res/layout/main_activity.xml
Expand Up @@ -57,6 +57,7 @@
app:pix_font="fonts/Action_Man.ttf"/>

<com.pixplicity.fontview.FontAppCompatButton
android:id="@+id/bt_popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
Expand Down Expand Up @@ -100,6 +101,11 @@
android:layout_height="wrap_content"
android:text="FontMultiAutoCompleteTextView"/>

<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

</LinearLayout>

</ScrollView>
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/menu/menu.xml
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:id="@+id/one"
android:title="One"/>

<item
android:id="@+id/two"
android:title="Two"/>

</menu>
7 changes: 7 additions & 0 deletions app/src/main/res/values/strings.xml
@@ -1,4 +1,11 @@
<resources>
<string name="app_name">FontView Sample</string>
<string name="__leak_canary_display_activity_label">FontView Leaks Sample</string>

<string-array name="spinner_list">
<item>One</item>
<item>Two</item>
<item>Three</item>
<item>Four</item>
</string-array>
</resources>
5 changes: 4 additions & 1 deletion app/src/main/res/values/styles.xml
Expand Up @@ -3,9 +3,12 @@
<style name="FontToolbarStyle" parent="Widget.AppCompat.Toolbar">
<item name="android:background">?attr/colorPrimary</item>
<item name="android:minHeight">?attr/actionBarSize</item>
<item name="popupTheme">@style/AppTheme.ActionBar.Popup</item>
<item name="titleTextAppearance">@style/FontToolbarTitleStyle</item>
<item name="subtitleTextAppearance">@style/FontToolbarSubtitleStyle</item>
<item name="popupTheme">@style/Theme.AppCompat.NoActionBar</item>
<item name="android:textColorPrimary">@color/abc_primary_text_material_dark</item>
<item name="actionMenuTextColor">@color/abc_primary_text_material_dark</item>
<item name="android:textColorSecondary">@color/abc_primary_text_material_dark</item>
</style>

<!-- Overflow drop down style -->
Expand Down
5 changes: 0 additions & 5 deletions bintray_upload.gradle
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Expand Up @@ -5,10 +5,10 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
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.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
}

Expand All @@ -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
}
}
Expand Down
35 changes: 16 additions & 19 deletions 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_NAME=1.2
VERSION_CODE=4
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
Expand All @@ -39,13 +39,10 @@ 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

ANDROID_BUILD_TOOLS_VERSION=22.0.1
ANDROID_COMPILE_SDK_VERSION=22
ANDROID_TARGET_SDK=22
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
ANDROID_TARGET_SDK=25
4 changes: 2 additions & 2 deletions 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
8 changes: 4 additions & 4 deletions library/build.gradle
Expand Up @@ -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
Expand Down Expand Up @@ -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')
44 changes: 44 additions & 0 deletions 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);
}
}

0 comments on commit 529f772

Please sign in to comment.