mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
next
This commit is contained in:
@@ -1,36 +1,12 @@
|
||||
import common = require("./progress-common");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import proxy = require("ui/core/proxy");
|
||||
import style = require("ui/styling/style");
|
||||
import view = require("ui/core/view");
|
||||
import { ProgressBase, valueProperty, maxValueProperty } from "./progress-common";
|
||||
import { View, colorProperty, backgroundColorProperty, backgroundInternalProperty } from "ui/core/view";
|
||||
import { Color } from "color";
|
||||
|
||||
export * from "./progress-common";
|
||||
|
||||
const R_ATTR_PROGRESS_BAR_STYLE_HORIZONTAL = 0x01010078;
|
||||
|
||||
function onValuePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var progress = <Progress>data.object;
|
||||
if (!progress.android) {
|
||||
return;
|
||||
}
|
||||
|
||||
progress.android.setProgress(data.newValue);
|
||||
}
|
||||
|
||||
function onMaxValuePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var progress = <Progress>data.object;
|
||||
if (!progress.android) {
|
||||
return;
|
||||
}
|
||||
|
||||
progress.android.setMax(data.newValue);
|
||||
}
|
||||
|
||||
// register the setNativeValue callbacks
|
||||
(<proxy.PropertyMetadata>common.Progress.valueProperty.metadata).onSetNativeValue = onValuePropertyChanged;
|
||||
(<proxy.PropertyMetadata>common.Progress.maxValueProperty.metadata).onSetNativeValue = onMaxValuePropertyChanged;
|
||||
|
||||
global.moduleMerge(common, exports);
|
||||
|
||||
export class Progress extends common.Progress {
|
||||
export class Progress extends ProgressBase {
|
||||
private _android: android.widget.ProgressBar;
|
||||
|
||||
public _createUI() {
|
||||
@@ -40,46 +16,62 @@ export class Progress extends common.Progress {
|
||||
get android(): android.widget.ProgressBar {
|
||||
return this._android;
|
||||
}
|
||||
}
|
||||
|
||||
export class ProgressStyler implements style.Styler {
|
||||
private static setColorProperty(view: view.View, newValue: any) {
|
||||
var bar = <android.widget.ProgressBar>view._nativeView;
|
||||
bar.getProgressDrawable().setColorFilter(newValue, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
get [valueProperty.native](): number {
|
||||
return 0;
|
||||
}
|
||||
set [valueProperty.native](value: number) {
|
||||
this._android.setProgress(value);
|
||||
}
|
||||
|
||||
private static resetColorProperty(view: view.View, nativeValue: number) {
|
||||
var bar = <android.widget.ProgressBar>view._nativeView;
|
||||
bar.getProgressDrawable().clearColorFilter();
|
||||
get [maxValueProperty.native](): number {
|
||||
return 100;
|
||||
}
|
||||
set [maxValueProperty.native](value: number) {
|
||||
this._android.setMax(value);
|
||||
}
|
||||
|
||||
private static setBackgroundAndBorderProperty(view: view.View, newValue: any) {
|
||||
var bar = <android.widget.ProgressBar>view._nativeView;
|
||||
var progressDrawable = <android.graphics.drawable.LayerDrawable>bar.getProgressDrawable();
|
||||
get [colorProperty.native](): android.graphics.drawable.Drawable {
|
||||
return null;
|
||||
}
|
||||
set [colorProperty.native](value: Color) {
|
||||
let progressDrawable = this._android.getProgressDrawable();
|
||||
if (!progressDrawable) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (progressDrawable.getNumberOfLayers && progressDrawable.getNumberOfLayers() > 0) {
|
||||
var backgroundDrawable = progressDrawable.getDrawable(0);
|
||||
if (value instanceof Color) {
|
||||
progressDrawable.setColorFilter(value.android, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
} else {
|
||||
progressDrawable.clearColorFilter();
|
||||
}
|
||||
}
|
||||
|
||||
get [backgroundColorProperty.native](): UIColor {
|
||||
return null;
|
||||
}
|
||||
set [backgroundColorProperty.native](value: Color) {
|
||||
let progressDrawable = this._android.getProgressDrawable();
|
||||
if (!progressDrawable) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (progressDrawable instanceof android.graphics.drawable.LayerDrawable && progressDrawable.getNumberOfLayers() > 0) {
|
||||
let backgroundDrawable = progressDrawable.getDrawable(0);
|
||||
if (backgroundDrawable) {
|
||||
backgroundDrawable.setColorFilter(newValue, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
if (value instanceof Color) {
|
||||
backgroundDrawable.setColorFilter(value.android, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
} else {
|
||||
backgroundDrawable.clearColorFilter();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static resetBackgroundAndBorderProperty(view: view.View, nativeValue: number) {
|
||||
// Do nothing.
|
||||
get [backgroundInternalProperty.native](): UIColor {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static registerHandlers() {
|
||||
style.registerHandler(style.colorProperty, new style.StylePropertyChangedHandler(
|
||||
ProgressStyler.setColorProperty,
|
||||
ProgressStyler.resetColorProperty), "Progress");
|
||||
|
||||
style.registerHandler(style.backgroundColorProperty, new style.StylePropertyChangedHandler(
|
||||
ProgressStyler.setBackgroundAndBorderProperty,
|
||||
ProgressStyler.resetBackgroundAndBorderProperty), "Progress");
|
||||
|
||||
style.registerHandler(style.backgroundInternalProperty, style.ignorePropertyHandler, "Progress");
|
||||
set [backgroundInternalProperty.native](value: Color) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
ProgressStyler.registerHandlers();
|
||||
}
|
||||
Reference in New Issue
Block a user