qml: add haptic feedback for android. Also preload most used classes to reduce
lag on first use.
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
import QtQuick 2.7
|
||||||
|
import QtQuick.VirtualKeyboard 2.1
|
||||||
|
import QtQuick.VirtualKeyboard.Styles 2.1
|
||||||
|
|
||||||
|
import org.electrum 1.0
|
||||||
|
|
||||||
|
KeyPanel {
|
||||||
|
id: keyPanel
|
||||||
|
Connections {
|
||||||
|
target: keyPanel.control
|
||||||
|
function onPressedChanged() {
|
||||||
|
if (keyPanel.control.pressed)
|
||||||
|
AppController.haptic()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,7 +65,7 @@ KeyboardStyle {
|
|||||||
color: constants.colorAlpha(Material.accentColor, 0.5) //mutedForeground //'red' //"black"
|
color: constants.colorAlpha(Material.accentColor, 0.5) //mutedForeground //'red' //"black"
|
||||||
}
|
}
|
||||||
|
|
||||||
keyPanel: KeyPanel {
|
keyPanel: ElectrumKeyPanel {
|
||||||
id: keyPanel
|
id: keyPanel
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: keyBackground
|
id: keyBackground
|
||||||
@@ -135,7 +135,7 @@ KeyboardStyle {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
backspaceKeyPanel: KeyPanel {
|
backspaceKeyPanel: ElectrumKeyPanel {
|
||||||
id: backspaceKeyPanel
|
id: backspaceKeyPanel
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: backspaceKeyBackground
|
id: backspaceKeyBackground
|
||||||
@@ -180,7 +180,7 @@ KeyboardStyle {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
languageKeyPanel: KeyPanel {
|
languageKeyPanel: ElectrumKeyPanel {
|
||||||
id: languageKeyPanel
|
id: languageKeyPanel
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: languageKeyBackground
|
id: languageKeyBackground
|
||||||
@@ -225,7 +225,7 @@ KeyboardStyle {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
enterKeyPanel: KeyPanel {
|
enterKeyPanel: ElectrumKeyPanel {
|
||||||
id: enterKeyPanel
|
id: enterKeyPanel
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: enterKeyBackground
|
id: enterKeyBackground
|
||||||
@@ -322,7 +322,7 @@ KeyboardStyle {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
hideKeyPanel: KeyPanel {
|
hideKeyPanel: ElectrumKeyPanel {
|
||||||
id: hideKeyPanel
|
id: hideKeyPanel
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: hideKeyBackground
|
id: hideKeyBackground
|
||||||
@@ -367,7 +367,7 @@ KeyboardStyle {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
shiftKeyPanel: KeyPanel {
|
shiftKeyPanel: ElectrumKeyPanel {
|
||||||
id: shiftKeyPanel
|
id: shiftKeyPanel
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: shiftKeyBackground
|
id: shiftKeyBackground
|
||||||
@@ -434,7 +434,7 @@ KeyboardStyle {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
spaceKeyPanel: KeyPanel {
|
spaceKeyPanel: ElectrumKeyPanel {
|
||||||
id: spaceKeyPanel
|
id: spaceKeyPanel
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: spaceKeyBackground
|
id: spaceKeyBackground
|
||||||
@@ -475,7 +475,7 @@ KeyboardStyle {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
symbolKeyPanel: KeyPanel {
|
symbolKeyPanel: ElectrumKeyPanel {
|
||||||
id: symbolKeyPanel
|
id: symbolKeyPanel
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: symbolKeyBackground
|
id: symbolKeyBackground
|
||||||
@@ -527,7 +527,7 @@ KeyboardStyle {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
modeKeyPanel: KeyPanel {
|
modeKeyPanel: ElectrumKeyPanel {
|
||||||
id: modeKeyPanel
|
id: modeKeyPanel
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: modeKeyBackground
|
id: modeKeyBackground
|
||||||
@@ -592,7 +592,7 @@ KeyboardStyle {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
handwritingKeyPanel: KeyPanel {
|
handwritingKeyPanel: ElectrumKeyPanel {
|
||||||
id: handwritingKeyPanel
|
id: handwritingKeyPanel
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: hwrKeyBackground
|
id: hwrKeyBackground
|
||||||
|
|||||||
@@ -47,6 +47,16 @@ if TYPE_CHECKING:
|
|||||||
from electrum.daemon import Daemon
|
from electrum.daemon import Daemon
|
||||||
from electrum.plugin import Plugins
|
from electrum.plugin import Plugins
|
||||||
|
|
||||||
|
if 'ANDROID_DATA' in os.environ:
|
||||||
|
from jnius import autoclass, cast
|
||||||
|
from android import activity
|
||||||
|
|
||||||
|
jpythonActivity = autoclass('org.kivy.android.PythonActivity').mActivity
|
||||||
|
jHfc = autoclass('android.view.HapticFeedbackConstants')
|
||||||
|
jString = autoclass('java.lang.String')
|
||||||
|
jIntent = autoclass('android.content.Intent')
|
||||||
|
jview = jpythonActivity.getWindow().getDecorView()
|
||||||
|
|
||||||
notification = None
|
notification = None
|
||||||
|
|
||||||
class QEAppController(BaseCrashReporter, QObject):
|
class QEAppController(BaseCrashReporter, QObject):
|
||||||
@@ -81,9 +91,10 @@ class QEAppController(BaseCrashReporter, QObject):
|
|||||||
|
|
||||||
self._qedaemon.walletLoaded.connect(self.on_wallet_loaded)
|
self._qedaemon.walletLoaded.connect(self.on_wallet_loaded)
|
||||||
|
|
||||||
self.userNotify.connect(self.notifyAndroid)
|
self.userNotify.connect(self.doNotify)
|
||||||
|
|
||||||
self.bindIntent()
|
if self.isAndroid():
|
||||||
|
self.bindIntent()
|
||||||
|
|
||||||
def on_wallet_loaded(self):
|
def on_wallet_loaded(self):
|
||||||
qewallet = self._qedaemon.currentWallet
|
qewallet = self._qedaemon.currentWallet
|
||||||
@@ -125,7 +136,7 @@ class QEAppController(BaseCrashReporter, QObject):
|
|||||||
except queue.Empty:
|
except queue.Empty:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def notifyAndroid(self, wallet_name, message):
|
def doNotify(self, wallet_name, message):
|
||||||
try:
|
try:
|
||||||
# TODO: lazy load not in UI thread please
|
# TODO: lazy load not in UI thread please
|
||||||
global notification
|
global notification
|
||||||
@@ -143,11 +154,7 @@ class QEAppController(BaseCrashReporter, QObject):
|
|||||||
if not self.isAndroid():
|
if not self.isAndroid():
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
from android import activity
|
self.on_new_intent(jpythonActivity.getIntent())
|
||||||
from jnius import autoclass
|
|
||||||
PythonActivity = autoclass('org.kivy.android.PythonActivity')
|
|
||||||
mactivity = PythonActivity.mActivity
|
|
||||||
self.on_new_intent(mactivity.getIntent())
|
|
||||||
activity.bind(on_new_intent=self.on_new_intent)
|
activity.bind(on_new_intent=self.on_new_intent)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f'unable to bind intent: {repr(e)}')
|
self.logger.error(f'unable to bind intent: {repr(e)}')
|
||||||
@@ -170,22 +177,15 @@ class QEAppController(BaseCrashReporter, QObject):
|
|||||||
|
|
||||||
@pyqtSlot(str, str)
|
@pyqtSlot(str, str)
|
||||||
def doShare(self, data, title):
|
def doShare(self, data, title):
|
||||||
try:
|
if not self.isAndroid():
|
||||||
from jnius import autoclass, cast
|
|
||||||
except ImportError:
|
|
||||||
self.logger.error('Share: needs jnius. Platform not Android?')
|
|
||||||
return
|
return
|
||||||
|
|
||||||
JS = autoclass('java.lang.String')
|
sendIntent = jIntent()
|
||||||
Intent = autoclass('android.content.Intent')
|
sendIntent.setAction(jIntent.ACTION_SEND)
|
||||||
sendIntent = Intent()
|
|
||||||
sendIntent.setAction(Intent.ACTION_SEND)
|
|
||||||
sendIntent.setType("text/plain")
|
sendIntent.setType("text/plain")
|
||||||
sendIntent.putExtra(Intent.EXTRA_TEXT, JS(data))
|
sendIntent.putExtra(jIntent.EXTRA_TEXT, jString(data))
|
||||||
pythonActivity = autoclass('org.kivy.android.PythonActivity')
|
it = jIntent.createChooser(sendIntent, cast('java.lang.CharSequence', jString(title)))
|
||||||
currentActivity = cast('android.app.Activity', pythonActivity.mActivity)
|
jpythonActivity.startActivity(it)
|
||||||
it = Intent.createChooser(sendIntent, cast('java.lang.CharSequence', JS(title)))
|
|
||||||
currentActivity.startActivity(it)
|
|
||||||
|
|
||||||
@pyqtSlot('QString')
|
@pyqtSlot('QString')
|
||||||
def textToClipboard(self, text):
|
def textToClipboard(self, text):
|
||||||
@@ -289,6 +289,13 @@ class QEAppController(BaseCrashReporter, QObject):
|
|||||||
wallet_types = Exception_Hook._INSTANCE.wallet_types_seen
|
wallet_types = Exception_Hook._INSTANCE.wallet_types_seen
|
||||||
return ",".join(wallet_types)
|
return ",".join(wallet_types)
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def haptic(self):
|
||||||
|
if not self.isAndroid():
|
||||||
|
return
|
||||||
|
jview.performHapticFeedback(jHfc.CONFIRM)
|
||||||
|
|
||||||
|
|
||||||
class ElectrumQmlApplication(QGuiApplication):
|
class ElectrumQmlApplication(QGuiApplication):
|
||||||
|
|
||||||
_valid = True
|
_valid = True
|
||||||
|
|||||||
Reference in New Issue
Block a user