瀏覽代碼

Android Back button like home button (#212)

pull/215/head
Dan Ballard 4 月之前
父節點
當前提交
6af91b71c1
共有 4 個文件被更改,包括 41 次插入4 次删除
  1. 7
    0
      android/src/ca/openprivacy/cwtch/ui/CwtchActivity.java
  2. 19
    3
      go/gothings/android/CwtchActivity.go
  3. 1
    1
      go/gothings/gcd.go
  4. 14
    0
      qml/main.qml

+ 7
- 0
android/src/ca/openprivacy/cwtch/ui/CwtchActivity.java 查看文件

@@ -124,4 +124,11 @@ public class CwtchActivity extends org.qtproject.qt5.android.bindings.QtActivity

}
}

// handle root level back button push as a home button push: don't exit, just go to home screen
public static void rootHomeHandle() {
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
m_instance.startActivity(i);
}
}

+ 19
- 3
go/gothings/android/CwtchActivity.go 查看文件

@@ -1,6 +1,7 @@
package android

import (
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"github.com/therecipe/qt/androidextras"
"github.com/therecipe/qt/core"
)
@@ -13,10 +14,12 @@ type CwtchActivity struct {
_ string `property:"notification"`

_ func(string) `slot:"updateAndroidNotification"`

_ func() `signal:"rootHomeButtonHandle,auto"`
}

func (c *CwtchActivity) init() {
log.Debugln("CwtchActivity.init()")
c.createOngoingNotification()
c.ConnectNotificationChanged(c.updateAndroidNotification)
}
@@ -31,7 +34,7 @@ func (c *CwtchActivity) updateAndroidNotification(n string) {
)

if err != nil {
println(err.Error())
log.Errorf("Error calling Java CwtchActivity.notify(): %v\n", err.Error())
}
}

@@ -45,6 +48,19 @@ func (c *CwtchActivity) createOngoingNotification() {
)

if err != nil {
println(err.Error())
log.Errorf("Error calling Java CwtchActivity.ongoingNotify(): %v\n", err.Error())
}
}

func (c *CwtchActivity) rootHomeButtonHandle() {
log.Infoln("CwtchActivity.rootHomeButtonHandle()!")
var err = androidextras.QAndroidJniObject_CallStaticMethodVoid2Caught(
"ca/openprivacy/cwtch/ui/CwtchActivity",
"rootHomeHandle",
"()V",
)

if err != nil {
log.Errorf("Error calling Java CwtchActivity.rootHomeButtonHandle(): %v\n", err.Error())
}
}

+ 1
- 1
go/gothings/gcd.go 查看文件

@@ -75,7 +75,7 @@ type GrandCentralDispatcher struct {
_ func(onion, nick string) `signal:"savePeerSettings,auto"`
_ func(onion, groupID string) `signal:"inviteToGroup,auto"`
_ func(onion, key, nick string) `signal:"setAttribute,auto"`
_ func(onion string) `signal:"deleteContact,auto""`
_ func(onion string) `signal:"deleteContact,auto"`
_ func(locale string) `signal:"setLocale,auto"`
_ func() `signal:"allowUnknownPeers,auto"`
_ func() `signal:"blockUnknownPeers,auto"`

+ 14
- 0
qml/main.qml 查看文件

@@ -195,6 +195,20 @@ ApplicationWindow {
}
}
}

focus: true
Keys.onPressed: {
if (event.key == Qt.Key_Back) {
event.accepted = true
if (theStack.currentIndex == theStack.emptyPane) {
androidCwtchActivity.rootHomeButtonHandle()
} else if (theStack.currentIndex == theStack.userProfilePane || theStack.currentIndex == theStack.groupProfilePane) {
theStack.currentIndex = theStack.messagePane
} else {
theStack.currentIndex = theStack.emptyPane
}
}
}
}

PropertyAnimation { id: anmPopup; easing.type: Easing.InQuart; duration: 7000; target: popup; property: "opacity"; to: 0; }

Loading…
取消
儲存