old border code restored

This commit is contained in:
Vladimir Enchev
2015-06-12 10:28:56 +03:00
parent 86430bec3d
commit b1cfc37ec9
2 changed files with 21 additions and 118 deletions

View File

@@ -2,7 +2,6 @@
import proxy = require("ui/core/proxy");
import dependencyObservable = require("ui/core/dependency-observable");
import utils = require("utils/utils");
import styleModule = require("ui/styling/style");
// merge the exports of the common file with the exports of this file
declare var exports;
@@ -23,101 +22,30 @@ export class Border extends borderCommon.Border {
return;
}
var viewGroup = <android.view.ViewGroup>this._nativeView;
var nativeView = <android.view.ViewGroup>this._nativeView;
var bkg = <BorderGradientDrawable>viewGroup.getBackground();
if (!(bkg instanceof BorderGradientDrawable)) {
bkg = new BorderGradientDrawable();
viewGroup.setBackground(bkg);
var backgroundDrawable = nativeView.getBackground();
if (!(backgroundDrawable instanceof android.graphics.drawable.GradientDrawable)) {
backgroundDrawable = new android.graphics.drawable.GradientDrawable();
nativeView.setBackgroundDrawable(backgroundDrawable);
}
bkg.borderWidth = this.borderWidth;
bkg.cornerRadius = this.cornerRadius;
bkg.borderColor = this.borderColor ? this.borderColor.android : android.graphics.Color.TRANSPARENT;
bkg.backgroundColor = this.backgroundColor ? this.backgroundColor.android : android.graphics.Color.TRANSPARENT;
var gd = <android.graphics.drawable.GradientDrawable>backgroundDrawable;
var density = utils.layout.getDisplayDensity();
gd.setCornerRadius(this.cornerRadius * density);
var value = this.style._getValue(styleModule.backgroundImageSourceProperty);
bkg.bitmap = value ? value.android : undefined;
}
}
if (this.borderColor) {
gd.setStroke(this.borderWidth * density, this.borderColor.android);
}
else {
gd.setStroke(this.borderWidth * density, android.graphics.Color.TRANSPARENT);
}
class BorderGradientDrawable extends android.graphics.drawable.GradientDrawable {
private _density = utils.layout.getDisplayDensity();
constructor() {
super();
return global.__native(this);
}
private _borderWidth: number;
get borderWidth(): number {
return this._borderWidth;
}
set borderWidth(value: number) {
if (this._borderWidth !== value) {
this._borderWidth = value;
this.setStroke(this._borderWidth * this._density, this._borderColor);
if (this.backgroundColor) {
gd.setColor(this.backgroundColor.android);
}
else {
gd.setColor(android.graphics.Color.TRANSPARENT);
}
}
private _cornerRadius: number;
get cornerRadius(): number {
return this._cornerRadius;
}
set cornerRadius(value: number) {
if (this._cornerRadius !== value) {
this._cornerRadius = value;
this.setCornerRadius(this._cornerRadius);
}
}
private _borderColor: number;
get borderColor(): number {
return this._borderColor;
}
set borderColor(value: number) {
if (this._borderColor !== value) {
this._borderColor = value;
this.setStroke(this._borderWidth * this._density, this._borderColor);
}
}
private _backgroundColor: number;
get backgroundColor(): number {
return this._backgroundColor;
}
set backgroundColor(value: number) {
if (this._backgroundColor !== value) {
this._backgroundColor = value;
this.setColor(this._backgroundColor);
}
}
private _bitmap: android.graphics.Bitmap
get bitmap(): android.graphics.Bitmap {
return this._bitmap;
}
set bitmap(value: android.graphics.Bitmap) {
if (this._bitmap !== value) {
this._bitmap = value;
this.invalidateSelf();
}
}
public draw(canvas: android.graphics.Canvas): void {
if (this.bitmap) {
this.setColor(android.graphics.Color.TRANSPARENT);
var stroke = this._borderWidth * this._density;
canvas.drawBitmap(this.bitmap, stroke, stroke, undefined);
}
super.draw(canvas);
}
}
}

View File

@@ -493,35 +493,10 @@ export class BorderStyler implements definition.stylers.Styler {
border._updateAndroidBorder();
}
private static getNativeBackgroundValue(view: view.View): any {
return view.android.getBackground();
}
//Background image methods
private static setBackgroundImageSourceProperty(view: view.View, newValue: any) {
var border = <border.Border>view;
border._updateAndroidBorder();
}
private static resetBackgroundImageSourceProperty(view: view.View, nativeValue: any) {
var border = <border.Border>view;
border._updateAndroidBorder();
}
private static getNativeBackgroundImageSourceValue(view: view.View): any {
return view.android.getBackground();
}
public static registerHandlers() {
style.registerHandler(style.backgroundColorProperty, new stylersCommon.StylePropertyChangedHandler(
BorderStyler.setBackgroundProperty,
BorderStyler.resetBackgroundProperty,
BorderStyler.getNativeBackgroundValue), "Border");
style.registerHandler(style.backgroundImageSourceProperty, new stylersCommon.StylePropertyChangedHandler(
BorderStyler.setBackgroundImageSourceProperty,
BorderStyler.resetBackgroundImageSourceProperty,
BorderStyler.getNativeBackgroundImageSourceValue), "Border");
BorderStyler.resetBackgroundProperty), "Border");
}
}