mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
chore: format
This commit is contained in:
@@ -1,146 +1,167 @@
|
||||
import { Background } from "../styling/background";
|
||||
import {
|
||||
SliderBase, valueProperty, minValueProperty, maxValueProperty
|
||||
SliderBase,
|
||||
valueProperty,
|
||||
minValueProperty,
|
||||
maxValueProperty,
|
||||
} from "./slider-common";
|
||||
import { colorProperty, backgroundColorProperty, backgroundInternalProperty } from "../styling/style-properties";
|
||||
import {
|
||||
colorProperty,
|
||||
backgroundColorProperty,
|
||||
backgroundInternalProperty,
|
||||
} from "../styling/style-properties";
|
||||
import { Color } from "../../color";
|
||||
|
||||
export * from "./slider-common";
|
||||
|
||||
interface OwnerSeekBar extends android.widget.SeekBar {
|
||||
owner: Slider;
|
||||
owner: Slider;
|
||||
}
|
||||
|
||||
let SeekBar: typeof android.widget.SeekBar;
|
||||
let SeekBarChangeListener: android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
|
||||
function initializeListenerClass(): void {
|
||||
if (!SeekBarChangeListener) {
|
||||
@Interfaces([android.widget.SeekBar.OnSeekBarChangeListener])
|
||||
class SeekBarChangeListenerImpl extends java.lang.Object
|
||||
implements android.widget.SeekBar.OnSeekBarChangeListener {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
if (!SeekBarChangeListener) {
|
||||
@Interfaces([android.widget.SeekBar.OnSeekBarChangeListener])
|
||||
class SeekBarChangeListenerImpl extends java.lang.Object implements android.widget.SeekBar.OnSeekBarChangeListener {
|
||||
constructor() {
|
||||
super();
|
||||
return global.__native(this);
|
||||
}
|
||||
|
||||
return global.__native(this);
|
||||
}
|
||||
onProgressChanged(
|
||||
seekBar: OwnerSeekBar,
|
||||
progress: number,
|
||||
fromUser: boolean
|
||||
): void {
|
||||
const owner = seekBar.owner;
|
||||
if (owner && !owner._supressNativeValue) {
|
||||
const newValue = progress + owner.minValue;
|
||||
valueProperty.nativeValueChange(owner, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
onProgressChanged(seekBar: OwnerSeekBar, progress: number, fromUser: boolean): void {
|
||||
const owner = seekBar.owner;
|
||||
if (owner && !owner._supressNativeValue) {
|
||||
const newValue = progress + owner.minValue;
|
||||
valueProperty.nativeValueChange(owner, newValue);
|
||||
}
|
||||
}
|
||||
onStartTrackingTouch(seekBar: OwnerSeekBar): void {
|
||||
//
|
||||
}
|
||||
|
||||
onStartTrackingTouch(seekBar: OwnerSeekBar): void {
|
||||
//
|
||||
}
|
||||
onStopTrackingTouch(seekBar: OwnerSeekBar): void {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
onStopTrackingTouch(seekBar: OwnerSeekBar): void {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
SeekBarChangeListener = new SeekBarChangeListenerImpl();
|
||||
}
|
||||
SeekBarChangeListener = new SeekBarChangeListenerImpl();
|
||||
}
|
||||
}
|
||||
|
||||
function getListener(): android.widget.SeekBar.OnSeekBarChangeListener {
|
||||
return SeekBarChangeListener;
|
||||
return SeekBarChangeListener;
|
||||
}
|
||||
|
||||
export class Slider extends SliderBase {
|
||||
_supressNativeValue: boolean;
|
||||
nativeViewProtected: OwnerSeekBar;
|
||||
_supressNativeValue: boolean;
|
||||
nativeViewProtected: OwnerSeekBar;
|
||||
|
||||
public createNativeView() {
|
||||
if (!SeekBar) {
|
||||
SeekBar = android.widget.SeekBar;
|
||||
}
|
||||
public createNativeView() {
|
||||
if (!SeekBar) {
|
||||
SeekBar = android.widget.SeekBar;
|
||||
}
|
||||
|
||||
return new SeekBar(this._context);
|
||||
}
|
||||
return new SeekBar(this._context);
|
||||
}
|
||||
|
||||
public initNativeView(): void {
|
||||
super.initNativeView();
|
||||
const nativeView = this.nativeViewProtected;
|
||||
nativeView.owner = this;
|
||||
initializeListenerClass();
|
||||
const listener = getListener();
|
||||
nativeView.setOnSeekBarChangeListener(listener);
|
||||
}
|
||||
public initNativeView(): void {
|
||||
super.initNativeView();
|
||||
const nativeView = this.nativeViewProtected;
|
||||
nativeView.owner = this;
|
||||
initializeListenerClass();
|
||||
const listener = getListener();
|
||||
nativeView.setOnSeekBarChangeListener(listener);
|
||||
}
|
||||
|
||||
public disposeNativeView() {
|
||||
this.nativeViewProtected.owner = null;
|
||||
super.disposeNativeView();
|
||||
}
|
||||
public disposeNativeView() {
|
||||
this.nativeViewProtected.owner = null;
|
||||
super.disposeNativeView();
|
||||
}
|
||||
|
||||
public resetNativeView(): void {
|
||||
super.resetNativeView();
|
||||
const nativeView = this.nativeViewProtected;
|
||||
nativeView.setMax(100);
|
||||
nativeView.setProgress(0);
|
||||
nativeView.setKeyProgressIncrement(1);
|
||||
}
|
||||
public resetNativeView(): void {
|
||||
super.resetNativeView();
|
||||
const nativeView = this.nativeViewProtected;
|
||||
nativeView.setMax(100);
|
||||
nativeView.setProgress(0);
|
||||
nativeView.setKeyProgressIncrement(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* There is no minValue in Android. We simulate this by subtracting the minValue from the native value and maxValue.
|
||||
* We need this method to call native setMax and setProgress methods when minValue property is changed,
|
||||
* without handling the native value changed callback.
|
||||
*/
|
||||
private setNativeValuesSilently() {
|
||||
this._supressNativeValue = true;
|
||||
const nativeView = this.nativeViewProtected;
|
||||
try {
|
||||
nativeView.setMax(this.maxValue - this.minValue);
|
||||
nativeView.setProgress(this.value - this.minValue);
|
||||
} finally {
|
||||
this._supressNativeValue = false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* There is no minValue in Android. We simulate this by subtracting the minValue from the native value and maxValue.
|
||||
* We need this method to call native setMax and setProgress methods when minValue property is changed,
|
||||
* without handling the native value changed callback.
|
||||
*/
|
||||
private setNativeValuesSilently() {
|
||||
this._supressNativeValue = true;
|
||||
const nativeView = this.nativeViewProtected;
|
||||
try {
|
||||
nativeView.setMax(this.maxValue - this.minValue);
|
||||
nativeView.setProgress(this.value - this.minValue);
|
||||
} finally {
|
||||
this._supressNativeValue = false;
|
||||
}
|
||||
}
|
||||
|
||||
[valueProperty.setNative](value: number) {
|
||||
this.setNativeValuesSilently();
|
||||
}
|
||||
[valueProperty.setNative](value: number) {
|
||||
this.setNativeValuesSilently();
|
||||
}
|
||||
|
||||
[minValueProperty.setNative](value: number) {
|
||||
this.setNativeValuesSilently();
|
||||
}
|
||||
[minValueProperty.setNative](value: number) {
|
||||
this.setNativeValuesSilently();
|
||||
}
|
||||
|
||||
[maxValueProperty.getDefault](): number {
|
||||
return 100;
|
||||
}
|
||||
[maxValueProperty.setNative](value: number) {
|
||||
this.setNativeValuesSilently();
|
||||
}
|
||||
[maxValueProperty.getDefault](): number {
|
||||
return 100;
|
||||
}
|
||||
[maxValueProperty.setNative](value: number) {
|
||||
this.setNativeValuesSilently();
|
||||
}
|
||||
|
||||
[colorProperty.getDefault](): number {
|
||||
return -1;
|
||||
}
|
||||
[colorProperty.setNative](value: number | Color) {
|
||||
if (value instanceof Color) {
|
||||
this.nativeViewProtected.getThumb().setColorFilter(value.android, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
} else {
|
||||
this.nativeViewProtected.getThumb().clearColorFilter();
|
||||
}
|
||||
}
|
||||
[colorProperty.getDefault](): number {
|
||||
return -1;
|
||||
}
|
||||
[colorProperty.setNative](value: number | Color) {
|
||||
if (value instanceof Color) {
|
||||
this.nativeViewProtected
|
||||
.getThumb()
|
||||
.setColorFilter(
|
||||
value.android,
|
||||
android.graphics.PorterDuff.Mode.SRC_IN
|
||||
);
|
||||
} else {
|
||||
this.nativeViewProtected.getThumb().clearColorFilter();
|
||||
}
|
||||
}
|
||||
|
||||
[backgroundColorProperty.getDefault](): number {
|
||||
return -1;
|
||||
}
|
||||
[backgroundColorProperty.setNative](value: number | Color) {
|
||||
if (value instanceof Color) {
|
||||
this.nativeViewProtected.getProgressDrawable().setColorFilter(value.android, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
} else {
|
||||
this.nativeViewProtected.getProgressDrawable().clearColorFilter();
|
||||
}
|
||||
}
|
||||
[backgroundColorProperty.getDefault](): number {
|
||||
return -1;
|
||||
}
|
||||
[backgroundColorProperty.setNative](value: number | Color) {
|
||||
if (value instanceof Color) {
|
||||
this.nativeViewProtected
|
||||
.getProgressDrawable()
|
||||
.setColorFilter(
|
||||
value.android,
|
||||
android.graphics.PorterDuff.Mode.SRC_IN
|
||||
);
|
||||
} else {
|
||||
this.nativeViewProtected.getProgressDrawable().clearColorFilter();
|
||||
}
|
||||
}
|
||||
|
||||
[backgroundInternalProperty.getDefault](): Background {
|
||||
return null;
|
||||
}
|
||||
[backgroundInternalProperty.setNative](value: Background) {
|
||||
//
|
||||
}
|
||||
[backgroundInternalProperty.getDefault](): Background {
|
||||
return null;
|
||||
}
|
||||
[backgroundInternalProperty.setNative](value: Background) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user