add:下拉通知栏

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -340,7 +340,27 @@ void VideoForm::postTurnOn()
if (!controlEvent) { if (!controlEvent) {
return; 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); m_inputConvert.sendControlEvent(controlEvent);
} }
@ -360,10 +380,9 @@ void VideoForm::staysOnTop(bool top)
if (isVisible()) { if (isVisible()) {
needShow = true; needShow = true;
} }
if (top) { setWindowFlag(Qt::WindowStaysOnTopHint, top);
setWindowFlag(Qt::WindowStaysOnTopHint); if (m_toolForm) {
} else { m_toolForm->setWindowFlag(Qt::WindowStaysOnTopHint, top);
setWindowFlag(Qt::WindowStaysOnTopHint, false);
} }
if (needShow) { if (needShow) {
show(); show();

View file

@ -36,6 +36,8 @@ public:
void postVolumeDown(); void postVolumeDown();
// turn the screen on if it was off, press BACK otherwise // turn the screen on if it was off, press BACK otherwise
void postTurnOn(); void postTurnOn();
void expandNotificationPanel();
void collapseNotificationPanel();
void postTextInput(const QString& text); void postTextInput(const QString& text);
void staysOnTop(bool top = true); 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 TYPE_TOUCH = 5;
public static final int COMMAND_BACK_OR_SCREEN_ON = 0; 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 int type;
private String text; private String text;

View file

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

View file

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

View file

@ -14,6 +14,7 @@ public final class ServiceManager {
private DisplayManager displayManager; private DisplayManager displayManager;
private InputManager inputManager; private InputManager inputManager;
private PowerManager powerManager; private PowerManager powerManager;
private StatusBarManager statusBarManager;
public ServiceManager() { public ServiceManager() {
try { try {
@ -60,4 +61,11 @@ public final class ServiceManager {
} }
return powerManager; 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.