phonespan added

This commit is contained in:
Gavriil Sitnikov 2015-11-14 08:31:48 +03:00
parent 86b468ac6a
commit fcb0892f12
2 changed files with 57 additions and 3 deletions

View File

@ -0,0 +1,42 @@
package org.roboswag.components.telephony;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.text.TextPaint;
import android.text.style.URLSpan;
import android.view.View;
import org.roboswag.core.log.Lc;
/**
* Created by Gavriil Sitnikov on 14/11/2015.
* TODO: fill description
*/
public class PhoneSpan extends URLSpan {
public PhoneSpan(@NonNull final String phoneNumber) {
super(phoneNumber);
}
@SuppressWarnings("PMD.AvoidCatchingThrowable")
@Override
public void onClick(final View widget) {
super.onClick(widget);
try {
final Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse(getURL()));
widget.getContext().startActivity(intent);
// it should catch throwable to not crash in production if there are problems with startActivity()
} catch (Throwable throwable) {
Lc.fatalException(throwable);
}
}
@Override
public void updateDrawState(final TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
}

View File

@ -29,6 +29,8 @@ import android.widget.TextView;
import org.roboswag.components.R; import org.roboswag.components.R;
import org.roboswag.components.views.TypefacedText; import org.roboswag.components.views.TypefacedText;
import org.roboswag.core.log.Lc;
import org.roboswag.core.utils.ShouldNotHappenException;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
@ -44,6 +46,12 @@ public final class Typefaces {
private static final Map<String, Typeface> TYPEFACES_MAP = new HashMap<>(); private static final Map<String, Typeface> TYPEFACES_MAP = new HashMap<>();
private static boolean allowEmptyCustomTypeface = true;
public static void setAllowEmptyCustomTypeface(final boolean allowDefaultTypefacedText) {
Typefaces.allowEmptyCustomTypeface = allowDefaultTypefacedText;
}
/* Returns typeface by name from assets 'fonts' folder */ /* Returns typeface by name from assets 'fonts' folder */
@NonNull @NonNull
public static Typeface getByName(@NonNull final Context context, @NonNull final String name) { public static Typeface getByName(@NonNull final Context context, @NonNull final String name) {
@ -80,9 +88,13 @@ public final class Typefaces {
typedArray.recycle(); typedArray.recycle();
} }
if (customTypeface != null && !typefacedText.isInEditMode()) { if (customTypeface != null) {
final Typeface typeface = typefacedText.getTypeface(); if (!typefacedText.isInEditMode()) {
typefacedText.setTypeface(customTypeface, typeface == null ? Typeface.NORMAL : typeface.getStyle()); final Typeface typeface = typefacedText.getTypeface();
typefacedText.setTypeface(customTypeface, typeface == null ? Typeface.NORMAL : typeface.getStyle());
}
} else if (!allowEmptyCustomTypeface) {
Lc.fatalException(new ShouldNotHappenException("TypefacedText has no customTypeface attribute: " + typefacedText));
} }
} }