Move several types from modules to widgets (#87)

Add setBackground method in ViewHelper
This commit is contained in:
Hristo Hristov
2017-03-07 10:35:53 +02:00
committed by GitHub
parent 80c8f65e78
commit ad11e397fe
4 changed files with 86 additions and 0 deletions

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}
}