-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaterial_progress_view.py
More file actions
70 lines (52 loc) · 2.23 KB
/
material_progress_view.py
File metadata and controls
70 lines (52 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from abc import ABC, abstractmethod
from .utils import IS_ANDROID
from .view import ViewBase
# ========================================
# Base class
# ========================================
class MaterialProgressViewBase(ABC):
@abstractmethod
def __init__(self) -> None:
super().__init__()
@abstractmethod
def set_progress(self, progress: float) -> "MaterialProgressViewBase":
pass
@abstractmethod
def get_progress(self) -> float:
pass
if IS_ANDROID:
# ========================================
# Android class
# https://developer.android.com/reference/com/google/android/material/progressindicator/LinearProgressIndicator
# ========================================
from typing import Any
from java import jclass
class MaterialProgressView(MaterialProgressViewBase, ViewBase):
def __init__(self, context: Any) -> None:
super().__init__()
self.native_class = jclass("com.google.android.material.progressindicator.LinearProgressIndicator")
self.native_instance = self.native_class(context)
self.native_instance.setIndeterminate(False)
def set_progress(self, progress: float) -> "MaterialProgressView":
self.native_instance.setProgress(int(progress * 100))
return self
def get_progress(self) -> float:
return self.native_instance.getProgress() / 100.0
else:
# ========================================
# iOS class
# https://developer.apple.com/documentation/uikit/uiprogressview
# ========================================
from rubicon.objc import ObjCClass
class MaterialProgressView(MaterialProgressViewBase, ViewBase):
def __init__(self) -> None:
super().__init__()
self.native_class = ObjCClass("UIProgressView")
self.native_instance = self.native_class.alloc().initWithProgressViewStyle_(
0
) # 0: UIProgressViewStyleDefault
def set_progress(self, progress: float) -> "MaterialProgressView":
self.native_instance.setProgress_animated_(progress, False)
return self
def get_progress(self) -> float:
return self.native_instance.progress()