mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Move several types from modules to widgets (#87)
Add setBackground method in ViewHelper
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package org.nativescript.widgets;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Typeface;
|
||||
import android.text.TextPaint;
|
||||
import android.text.style.TypefaceSpan;
|
||||
|
||||
/**
|
||||
* Created by hhristov on 2/27/17.
|
||||
*/
|
||||
|
||||
@SuppressLint("ParcelCreator")
|
||||
public class CustomTypefaceSpan extends TypefaceSpan {
|
||||
private Typeface typeface;
|
||||
|
||||
public CustomTypefaceSpan(String family, Typeface typeface) {
|
||||
super(family);
|
||||
this.typeface = typeface;
|
||||
}
|
||||
|
||||
public void updateDrawState(TextPaint ds) {
|
||||
this.applyCustomTypeFace(ds);
|
||||
}
|
||||
|
||||
public void updateMeasureState(TextPaint paint) {
|
||||
this.applyCustomTypeFace(paint);
|
||||
}
|
||||
|
||||
private void applyCustomTypeFace(TextPaint paint) {
|
||||
final Typeface old = paint.getTypeface();
|
||||
final int oldStyle = (old == null) ? 0 : old.getStyle();
|
||||
|
||||
Typeface typeface = this.typeface;
|
||||
int fake = oldStyle & ~typeface.getStyle();
|
||||
if ((fake & android.graphics.Typeface.BOLD) != 0) {
|
||||
paint.setFakeBoldText(true);
|
||||
}
|
||||
|
||||
if ((fake & android.graphics.Typeface.ITALIC) != 0) {
|
||||
paint.setTextSkewX(-0.25f);
|
||||
}
|
||||
|
||||
paint.setTypeface(typeface);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.nativescript.widgets;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Created by hhristov on 2/22/17.
|
||||
*/
|
||||
|
||||
public final class DisableUserInteractionListener extends Object implements View.OnTouchListener {
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.nativescript.widgets;
|
||||
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
|
||||
/**
|
||||
* Created by hhristov on 2/23/17.
|
||||
*/
|
||||
|
||||
public class SegmentedBarColorDrawable extends ColorDrawable {
|
||||
public void draw(android.graphics.Canvas canvas) {
|
||||
Paint p = new Paint();
|
||||
p.setColor(this.getColor());
|
||||
p.setStyle(android.graphics.Paint.Style.FILL);
|
||||
canvas.drawRect(0, this.getBounds().height() - 15, this.getBounds().width(), this.getBounds().height(), p);
|
||||
}
|
||||
}
|
||||
@@ -528,5 +528,13 @@ public class ViewHelper {
|
||||
textView.setLetterSpacing(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setBackground(android.view.View view, android.graphics.drawable.Drawable background) {
|
||||
if (version >= 16) {
|
||||
view.setBackground(background);
|
||||
} else {
|
||||
view.setBackgroundDrawable(background);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user