Skip to content

Commit

Permalink
Merge pull request #1 from virtualprodigy/bug-fix/xmlNameSpace_Dialog…
Browse files Browse the repository at this point in the history
…ForTTFInDemo

Bug fix/xml name space dialog for ttf in demo
  • Loading branch information
virtualprodigy committed Jun 29, 2016
2 parents d512287 + a23ffa8 commit 456ebf4
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 12 deletions.
3 changes: 2 additions & 1 deletion BetterTextViewSample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha2'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support:support-annotations:23.4.0'
compile project(':bettertextview')
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,63 @@
package com.virtualprodigy.bettertextviewsample;

import android.content.Context;
import android.graphics.Typeface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.font_license:
displayChangeLog();
return true;

default:
return super.onOptionsItemSelected(item);
}
}

/**
* Display the webview with the license for the Dancing font
*/
private void displayChangeLog() {

WebView webview = new WebView(context);
webview.loadUrl("file:///android_asset/fonts/dancing_script_license.html");

AlertDialog dialog = new AlertDialog.Builder(context)
.setTitle("Dancing Script License")
.setView(webview)
.setPositiveButton("ok",null)
.create();
dialog.show();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:bettertv="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.virtualprodigy.bettertextviewsample.MainActivity">

<com.virtualprodigy.bettertextview.BetterTextView
android:id="@+id/helloWorld"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:typefaceAsset="dancing _script.ttf"
app:scaleWithinBounds="false"
bettertv:typefaceAsset="dancing_script.ttf"
bettertv:scaleWithinBounds="false"
app:layout_constraintBottom_toBottomOf="@+id/activity_main"
app:layout_constraintLeft_toLeftOf="@+id/activity_main"
app:layout_constraintRight_toRightOf="@+id/activity_main"
Expand Down
11 changes: 11 additions & 0 deletions BetterTextViewSample/app/src/main/res/menu/menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/font_license"
app:showAsAction="never"
android:title="font license" />


</menu>
2 changes: 1 addition & 1 deletion BetterTextViewSample/bettertextview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.4.0'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.virtualprodigy.bettertextview">

<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">

</application>
<application/>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class BetterTextView extends TextView {
private boolean scaleWithinBounds;
private String typefaceAsset;
private Context context;
private final String FONT_DIRECTORY = "fonts/";

public BetterTextView(Context context) {
super(context);
Expand Down Expand Up @@ -45,7 +46,7 @@ private void init(Context context, AttributeSet attrs) {

try {
scaleWithinBounds = typedArray.getBoolean(R.styleable.betterTextViewAttrs_typefaceAsset, false);
typefaceAsset = typedArray.getString(R.styleable.betterTextViewAttrs_typefaceAsset);
typefaceAsset = FONT_DIRECTORY + typedArray.getString(R.styleable.betterTextViewAttrs_typefaceAsset);
} finally {
typedArray.recycle();
}
Expand All @@ -69,7 +70,7 @@ public void setScaleWithinBounds(boolean scaleWithinBounds) {
* @param typefaceAsset - Name of the TTF file
*/
public void setTypefaceAsset(String typefaceAsset) {
this.typefaceAsset = typefaceAsset;
this.typefaceAsset = FONT_DIRECTORY + typefaceAsset;
setTypeface();
}

Expand Down
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
# BetterTextView
A Custom Android TextView With some upgrades
A custom Android TextView with some upgrades.

#Description
This small library is a slightly upgraded version of Android's standard TextView. It currently features the ability
to set the Type Face via XML.



#Feature Features
### 1. Automatically sizing the font to fit within a TextView's bound.
### 2. Maven distribution


#Change Log
###Version 1.0
1. Users can add their typeface view xml


#License
Copyright 2016 Matthew Butler

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.

0 comments on commit 456ebf4

Please sign in to comment.