add:下拉通知栏

This commit is contained in:
Barry 2019-06-15 18:07:16 +08:00
parent 3bee801fd7
commit 743b2398c9
14 changed files with 124 additions and 13 deletions

View file

@ -226,7 +226,7 @@
<string>always top</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>

View file

@ -48,7 +48,7 @@ void ControlEvent::setScrollEventData(QRect position, qint32 hScroll, qint32 vSc
m_data.scrollEvent.vScroll = vScroll;
}
void ControlEvent::setCommandEventData(qint32 action)
void ControlEvent::setCommandEventData(ControlEventCommand action)
{
m_data.commandEvent.action = action;
}

View file

@ -9,13 +9,11 @@
#include "input.h"
#include "keycodes.h"
#define CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON 0
#define TEXT_MAX_CHARACTER_LENGTH 300
// ControlEvent
class ControlEvent : public QScrcpyEvent
{
public:
public:
enum ControlEventType {
CET_KEYCODE,
CET_TEXT,
@ -23,7 +21,13 @@ public:
CET_SCROLL,
CET_COMMAND,
CET_TOUCH,
};
};
enum ControlEventCommand {
CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON = 0,
CONTROL_EVENT_COMMAND_EXPAND_NOTIFICATION_PANEL,
CONTROL_EVENT_COMMAND_COLLAPSE_NOTIFICATION_PANEL,
};
ControlEvent(ControlEventType controlEventType);
@ -35,7 +39,7 @@ public:
// position action动作对应的位置
void setTouchEventData(quint32 id, AndroidMotioneventAction action, QRect position);
void setScrollEventData(QRect position, qint32 hScroll, qint32 vScroll);
void setCommandEventData(qint32 action);
void setCommandEventData(ControlEvent::ControlEventCommand action);
QByteArray serializeData();
@ -72,7 +76,7 @@ private:
qint32 vScroll;
} scrollEvent;
struct {
qint32 action;
ControlEventCommand action;
} commandEvent;
};

View file

@ -38,6 +38,7 @@ void ToolForm::initStyle()
IconHelper::Instance()->SetIcon(ui->volumeUpBtn, QChar(0xf028), 15);
IconHelper::Instance()->SetIcon(ui->volumeDownBtn, QChar(0xf027), 15);
IconHelper::Instance()->SetIcon(ui->turnOnBtn, QChar(0xf09c), 15);
IconHelper::Instance()->SetIcon(ui->expandNotifyBtn, QChar(0xf103), 15);
}
void ToolForm::mousePressEvent(QMouseEvent *event)
@ -133,3 +134,10 @@ void ToolForm::on_turnOnBtn_clicked()
m_videoForm->postTurnOn();
}
}
void ToolForm::on_expandNotifyBtn_clicked()
{
if (m_videoForm) {
m_videoForm->expandNotificationPanel();
}
}

View file

@ -46,6 +46,8 @@ private slots:
void on_turnOnBtn_clicked();
void on_expandNotifyBtn_clicked();
private:
void initStyle();

View file

@ -43,6 +43,16 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="expandNotifyBtn">
<property name="toolTip">
<string>expand notify</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="powerBtn">
<property name="toolTip">

View file

@ -340,7 +340,27 @@ void VideoForm::postTurnOn()
if (!controlEvent) {
return;
}
controlEvent->setCommandEventData(CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON);
controlEvent->setCommandEventData(ControlEvent::CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON);
m_inputConvert.sendControlEvent(controlEvent);
}
void VideoForm::expandNotificationPanel()
{
ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_COMMAND);
if (!controlEvent) {
return;
}
controlEvent->setCommandEventData(ControlEvent::CONTROL_EVENT_COMMAND_EXPAND_NOTIFICATION_PANEL);
m_inputConvert.sendControlEvent(controlEvent);
}
void VideoForm::collapseNotificationPanel()
{
ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_COMMAND);
if (!controlEvent) {
return;
}
controlEvent->setCommandEventData(ControlEvent::CONTROL_EVENT_COMMAND_COLLAPSE_NOTIFICATION_PANEL);
m_inputConvert.sendControlEvent(controlEvent);
}
@ -360,10 +380,9 @@ void VideoForm::staysOnTop(bool top)
if (isVisible()) {
needShow = true;
}
if (top) {
setWindowFlag(Qt::WindowStaysOnTopHint);
} else {
setWindowFlag(Qt::WindowStaysOnTopHint, false);
setWindowFlag(Qt::WindowStaysOnTopHint, top);
if (m_toolForm) {
m_toolForm->setWindowFlag(Qt::WindowStaysOnTopHint, top);
}
if (needShow) {
show();

View file

@ -36,6 +36,8 @@ public:
void postVolumeDown();
// turn the screen on if it was off, press BACK otherwise
void postTurnOn();
void expandNotificationPanel();
void collapseNotificationPanel();
void postTextInput(const QString& text);
void staysOnTop(bool top = true);

View file

@ -13,6 +13,8 @@ public final class ControlEvent {
public static final int TYPE_TOUCH = 5;
public static final int COMMAND_BACK_OR_SCREEN_ON = 0;
public static final int COMMAND_EXPAND_NOTIFICATION_PANEL = 1;
public static final int COMMAND_COLLAPSE_NOTIFICATION_PANEL = 2;
private int type;
private String text;

View file

@ -172,6 +172,14 @@ public final class Device {
this.rotationListener = rotationListener;
}
public void expandNotificationPanel() {
serviceManager.getStatusBarManager().expandNotificationsPanel();
}
public void collapsePanels() {
serviceManager.getStatusBarManager().collapsePanels();
}
static Rect flipRect(Rect crop) {
return new Rect(crop.top, crop.left, crop.bottom, crop.right);
}

View file

@ -1,6 +1,7 @@
package com.genymobile.scrcpy;
import com.genymobile.scrcpy.wrappers.InputManager;
import com.genymobile.scrcpy.wrappers.ServiceManager;
import android.graphics.Point;
import android.os.SystemClock;
@ -301,6 +302,12 @@ public class EventController {
switch (action) {
case ControlEvent.COMMAND_BACK_OR_SCREEN_ON:
return pressBackOrTurnScreenOn();
case ControlEvent.COMMAND_EXPAND_NOTIFICATION_PANEL:
device.expandNotificationPanel();
return true;
case ControlEvent.COMMAND_COLLAPSE_NOTIFICATION_PANEL:
device.collapsePanels();
return true;
default:
Ln.w("Unsupported command: " + action);
}

View file

@ -14,6 +14,7 @@ public final class ServiceManager {
private DisplayManager displayManager;
private InputManager inputManager;
private PowerManager powerManager;
private StatusBarManager statusBarManager;
public ServiceManager() {
try {
@ -60,4 +61,11 @@ public final class ServiceManager {
}
return powerManager;
}
public StatusBarManager getStatusBarManager() {
if (statusBarManager == null) {
statusBarManager = new StatusBarManager(getService("statusbar", "com.android.internal.statusbar.IStatusBarService"));
}
return statusBarManager;
}
}

View file

@ -0,0 +1,41 @@
package com.genymobile.scrcpy.wrappers;
//import android.annotation.SuppressLint;
import android.os.IInterface;
//import android.view.InputEvent;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class StatusBarManager {
private final IInterface manager;
private final Method expandNotificationsPanelMethod;
private final Method collapsePanelsMethod;
public StatusBarManager(IInterface manager) {
this.manager = manager;
try {
expandNotificationsPanelMethod = manager.getClass().getMethod("expandNotificationsPanel");
collapsePanelsMethod = manager.getClass().getMethod("collapsePanels");
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
}
}
public void expandNotificationsPanel() {
try {
expandNotificationsPanelMethod.invoke(manager);
} catch (InvocationTargetException | IllegalAccessException e) {
throw new AssertionError(e);
}
}
public void collapsePanels() {
try {
collapsePanelsMethod.invoke(manager);
} catch (InvocationTargetException | IllegalAccessException e) {
throw new AssertionError(e);
}
}
}

Binary file not shown.