Commit 93f0a445 authored by Yusuke Iwaki's avatar Yusuke Iwaki Committed by GitHub

Merge pull request #201 from RocketChat/ext_fontawesome

Use external library for FontAwesome widgets
parents 1a8ebdf1 97961cbd
...@@ -82,13 +82,6 @@ play { ...@@ -82,13 +82,6 @@ play {
track = "${track}" track = "${track}"
} }
repositories {
mavenCentral()
maven { url 'https://github.com/lijingle1/stetho-realm/raw/master/maven-repo' }
maven { url 'http://dl.bintray.com/amulyakhare/maven' }
maven { url "https://clojars.org/repo/" } //for icepick.
}
dependencies { dependencies {
compile project(':log-wrapper') compile project(':log-wrapper')
compile project(':android-ddp') compile project(':android-ddp')
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<chat.rocket.android.widget.FontAwesomeButton <io.github.yusukeiwaki.android.widget.FontAwesomeButton
android:id="@+id/btn_login_with_twitter" android:id="@+id/btn_login_with_twitter"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
android:textSize="16dp" android:textSize="16dp"
android:layout_marginRight="@dimen/margin_8" /> android:layout_marginRight="@dimen/margin_8" />
<chat.rocket.android.widget.FontAwesomeButton <io.github.yusukeiwaki.android.widget.FontAwesomeButton
android:id="@+id/btn_login_with_facebook" android:id="@+id/btn_login_with_facebook"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
android:textSize="16dp" android:textSize="16dp"
android:layout_marginRight="@dimen/margin_8" /> android:layout_marginRight="@dimen/margin_8" />
<chat.rocket.android.widget.FontAwesomeButton <io.github.yusukeiwaki.android.widget.FontAwesomeButton
android:id="@+id/btn_login_with_github" android:id="@+id/btn_login_with_github"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
android:textSize="16dp" android:textSize="16dp"
android:layout_marginRight="@dimen/margin_8" /> android:layout_marginRight="@dimen/margin_8" />
<chat.rocket.android.widget.FontAwesomeButton <io.github.yusukeiwaki.android.widget.FontAwesomeButton
android:id="@+id/btn_login_with_google" android:id="@+id/btn_login_with_google"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
......
...@@ -101,7 +101,7 @@ ...@@ -101,7 +101,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Body2" android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textStyle="bold" /> android:textStyle="bold" />
<chat.rocket.android.widget.FontAwesomeButton <io.github.yusukeiwaki.android.widget.FontAwesomeButton
android:id="@+id/btn_add_channel" android:id="@+id/btn_add_channel"
style="@style/Widget.AppCompat.Button.Borderless" style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="48dp" android:layout_width="48dp"
...@@ -134,7 +134,7 @@ ...@@ -134,7 +134,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Body2" android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textStyle="bold" /> android:textStyle="bold" />
<chat.rocket.android.widget.FontAwesomeButton <io.github.yusukeiwaki.android.widget.FontAwesomeButton
android:id="@+id/btn_add_direct_message" android:id="@+id/btn_add_direct_message"
style="@style/Widget.AppCompat.Button.Borderless" style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="48dp" android:layout_width="48dp"
...@@ -221,7 +221,7 @@ ...@@ -221,7 +221,7 @@
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="match_parent"> android:layout_height="match_parent">
<chat.rocket.android.widget.FontAwesomeTextView <io.github.yusukeiwaki.android.widget.FontAwesomeTextView
android:layout_width="16dp" android:layout_width="16dp"
android:layout_height="16dp" android:layout_height="16dp"
android:layout_gravity="center" android:layout_gravity="center"
......
...@@ -6,21 +6,21 @@ ...@@ -6,21 +6,21 @@
android:layout_gravity="end" android:layout_gravity="end"
android:orientation="vertical"> android:orientation="vertical">
<chat.rocket.android.widget.FontAwesomeButton <io.github.yusukeiwaki.android.widget.FontAwesomeButton
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:enabled="false" android:enabled="false"
android:text="@string/fa_search" android:text="@string/fa_search"
android:textSize="24dp" /> android:textSize="24dp" />
<chat.rocket.android.widget.FontAwesomeButton <io.github.yusukeiwaki.android.widget.FontAwesomeButton
android:id="@+id/btn_users" android:id="@+id/btn_users"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:text="@string/fa_users" android:text="@string/fa_users"
android:textSize="24dp" /> android:textSize="24dp" />
<chat.rocket.android.widget.FontAwesomeButton <io.github.yusukeiwaki.android.widget.FontAwesomeButton
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:enabled="false" android:enabled="false"
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
android:layout_margin="@dimen/margin_8" android:layout_margin="@dimen/margin_8"
android:src="@mipmap/ic_launcher" /> android:src="@mipmap/ic_launcher" />
<chat.rocket.android.widget.FontAwesomeButton <io.github.yusukeiwaki.android.widget.FontAwesomeButton
style="@style/Base.Widget.AppCompat.Button.Borderless" style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="80dp" android:layout_width="80dp"
android:layout_height="80dp" android:layout_height="80dp"
......
...@@ -4,6 +4,11 @@ apply from: rootProject.file('dependencies.gradle') ...@@ -4,6 +4,11 @@ apply from: rootProject.file('dependencies.gradle')
allprojects { allprojects {
repositories { repositories {
jcenter() jcenter()
mavenCentral()
maven { url 'https://github.com/lijingle1/stetho-realm/raw/master/maven-repo' }
maven { url 'http://dl.bintray.com/amulyakhare/maven' } //for TextDrawable.
maven { url "https://clojars.org/repo/" } //for icepick.
maven { url 'https://jitpack.io' } //for widget-fontawesome.
} }
} }
......
...@@ -40,6 +40,8 @@ dependencies { ...@@ -40,6 +40,8 @@ dependencies {
compile rootProject.ext.okhttp3 compile rootProject.ext.okhttp3
compile rootProject.ext.boltsTask compile rootProject.ext.boltsTask
compile 'com.github.yusukeiwaki.android-widget:widget-fontawesome:0.0.1'
compile rootProject.ext.frescoBase compile rootProject.ext.frescoBase
compile rootProject.ext.frescoAnimatedGif compile rootProject.ext.frescoAnimatedGif
compile rootProject.ext.frescoAnimatedWebp compile rootProject.ext.frescoAnimatedWebp
......
package chat.rocket.android.widget;
import android.content.Context;
import android.graphics.Typeface;
import android.support.v7.widget.AppCompatButton;
import android.util.AttributeSet;
import android.view.Gravity;
abstract class AbstractCustomFontButton extends AppCompatButton {
public AbstractCustomFontButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public AbstractCustomFontButton(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public AbstractCustomFontButton(Context context) {
super(context);
init();
}
protected abstract String getFont();
private void init() {
String font = getFont();
if (font != null) {
Typeface typeface = TypefaceHelper.getTypeface(getContext(), font);
if (typeface != null) {
setTypeface(typeface);
}
}
setMinWidth(0);
setMinHeight(0);
setGravity(Gravity.CENTER);
}
}
package chat.rocket.android.widget;
import android.content.Context;
import android.graphics.Typeface;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
abstract class AbstractCustomFontTextView extends AppCompatTextView {
public AbstractCustomFontTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public AbstractCustomFontTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public AbstractCustomFontTextView(Context context) {
super(context);
init();
}
protected abstract String getFont();
private void init() {
String font = getFont();
if (font != null) {
Typeface typeface = TypefaceHelper.getTypeface(getContext(), font);
if (typeface != null) {
setTypeface(typeface);
}
}
}
}
package chat.rocket.android.widget;
import android.content.Context;
import android.util.AttributeSet;
/**
* Button with font-awesome text.
*/
public class FontAwesomeButton extends AbstractCustomFontButton {
public FontAwesomeButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public FontAwesomeButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FontAwesomeButton(Context context) {
super(context);
}
@Override
protected String getFont() {
return "fontawesome-webfont.ttf";
}
}
package chat.rocket.android.widget;
import android.content.Context;
import android.util.AttributeSet;
/**
* TextView with font-awesome.
*/
public class FontAwesomeTextView extends AbstractCustomFontTextView {
public FontAwesomeTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public FontAwesomeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FontAwesomeTextView(Context context) {
super(context);
}
@Override
protected String getFont() {
return "fontawesome-webfont.ttf";
}
}
package chat.rocket.android.widget;
import android.content.Context;
import android.util.AttributeSet;
/**
* TextView with fontello.
*/
public class FontelloTextView extends AbstractCustomFontTextView {
public FontelloTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public FontelloTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FontelloTextView(Context context) {
super(context);
}
@Override
protected String getFont() {
return "fontello.ttf";
}
}
package chat.rocket.android.widget;
import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import java.util.Hashtable;
/**
* Helper for reading typeface. ref:https://code.google.com/p/android/issues/detail?id=9904#c7
*/
class TypefaceHelper {
private static final String TAG = TypefaceHelper.class.getName();
private static final Hashtable<String, Typeface> CACHE = new Hashtable<String, Typeface>();
/**
* read font in assets directory.
*/
public static Typeface getTypeface(Context context, String assetPath) {
synchronized (CACHE) {
if (!CACHE.containsKey(assetPath)) {
try {
Typeface typeface = Typeface.createFromAsset(context.getAssets(), assetPath);
CACHE.put(assetPath, typeface);
} catch (Exception exception) {
Log.e(TAG,
"Could not get typeface '" + assetPath + "' because " + exception.getMessage());
return null;
}
}
return CACHE.get(assetPath);
}
}
}
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"> android:layout_marginRight="16dp">
<chat.rocket.android.widget.FontAwesomeTextView <io.github.yusukeiwaki.android.widget.FontAwesomeTextView
android:id="@+id/icon" android:id="@+id/icon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string translatable="false" name="fa_hashtag">&#xf292;</string> <!-- for public rooms -->
<string translatable="false" name="fa_lock">&#xf023;</string> <!-- for private rooms -->
<string translatable="false" name="fa_at">&#xf1fa;</string> <!-- for direct message -->
</resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment