phonespan added
This commit is contained in:
parent
86b468ac6a
commit
fcb0892f12
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -29,6 +29,8 @@ import android.widget.TextView;
|
|||
|
||||
import org.roboswag.components.R;
|
||||
import org.roboswag.components.views.TypefacedText;
|
||||
import org.roboswag.core.log.Lc;
|
||||
import org.roboswag.core.utils.ShouldNotHappenException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -44,6 +46,12 @@ public final class Typefaces {
|
|||
|
||||
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 */
|
||||
@NonNull
|
||||
public static Typeface getByName(@NonNull final Context context, @NonNull final String name) {
|
||||
|
|
@ -80,10 +88,14 @@ public final class Typefaces {
|
|||
typedArray.recycle();
|
||||
}
|
||||
|
||||
if (customTypeface != null && !typefacedText.isInEditMode()) {
|
||||
if (customTypeface != null) {
|
||||
if (!typefacedText.isInEditMode()) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
public static <TTypefacedText extends TextView & TypefacedText> void setTypeface(final TTypefacedText typefacedText,
|
||||
|
|
|
|||
Loading…
Reference in New Issue