Commit 4908b5f5 authored by Nicolas Fella's avatar Nicolas Fella

Make double tap on barcode toggle the brightness

parent ae43b249
......@@ -32,7 +32,7 @@ Rectangle {
MouseArea {
anchors.fill: parent
onDoubleClicked: _brightnessManager.maxBrightness();
onDoubleClicked: _brightnessManager.toggleBrightness();
}
ColumnLayout {
......
......@@ -68,7 +68,7 @@ ColumnLayout {
MouseArea {
anchors.fill: parent
onDoubleClicked: _brightnessManager.maxBrightness();
onDoubleClicked: _brightnessManager.toggleBrightness();
}
Prison.Barcode {
......
......@@ -30,10 +30,23 @@ AndroidBrightnessBackend::~AndroidBrightnessBackend()
{
}
void AndroidBrightnessBackend::maxBrightness()
float AndroidBrightnessBackend::brightness() const
{
float brightness = QtAndroid::androidActivity().callMethod<jfloat>("getBrightness", "()F");
return brightness;
}
void AndroidBrightnessBackend::setBrightness(float brightness)
{
const auto activity = QtAndroid::androidActivity();
if (activity.isValid()) {
activity.callMethod<void>("maxBrightness");
activity.callMethod<void>("setBrightness", "(F)V", brightness);
}
}
float AndroidBrightnessBackend::maxBrightness() const
{
return 1;
}
......@@ -29,8 +29,9 @@ public:
explicit AndroidBrightnessBackend(QObject *parent = nullptr);
virtual ~AndroidBrightnessBackend();
virtual void maxBrightness();
void setBrightness(float brightness) override;
float brightness() const override;
float maxBrightness() const override;
};
#endif // ANDROIDBRIGHTNESSBACKEND_H
......@@ -37,9 +37,22 @@ BrightnessManager::BrightnessManager(QObject *parent)
BrightnessManager::~BrightnessManager() = default;
void BrightnessManager::maxBrightness()
void BrightnessManager::toggleBrightness()
{
if (m_backend) {
m_backend->maxBrightness();
if (!m_backend)
return;
m_backend->toggleBrightness();
}
void BrightnessBackend::toggleBrightness()
{
if (m_maximized) {
setBrightness(m_previousValue);
} else {
m_previousValue = brightness();
setBrightness(maxBrightness());
}
m_maximized = !m_maximized;
}
......@@ -23,11 +23,23 @@
class BrightnessBackend : public QObject
{
public:
explicit BrightnessBackend(QObject *parent = nullptr) : QObject(parent) {}
explicit BrightnessBackend(QObject *parent = nullptr) : QObject(parent)
, m_maximized()
, m_previousValue()
{}
virtual ~BrightnessBackend() = default;
public:
virtual void maxBrightness() = 0;
virtual void toggleBrightness();
protected:
virtual void setBrightness(float brightness) = 0;
virtual float brightness() const = 0;
virtual float maxBrightness() const = 0;
private:
bool m_maximized;
int m_previousValue;
};
class BrightnessManager : public QObject
......@@ -39,7 +51,7 @@ public:
~BrightnessManager();
public Q_SLOTS:
void maxBrightness();
void toggleBrightness();
private:
BrightnessBackend *m_backend;
......
......@@ -34,7 +34,17 @@ SolidBrightnessBackend::~SolidBrightnessBackend()
{
}
void SolidBrightnessBackend::maxBrightness()
float SolidBrightnessBackend::brightness() const
{
m_iface->setBrightnessSilent(m_iface->brightnessMax());
return m_iface->brightness();
}
void SolidBrightnessBackend::setBrightness(float brightness)
{
m_iface->setBrightnessSilent(brightness);
}
float SolidBrightnessBackend::maxBrightness() const
{
return m_iface->brightnessMax();
}
......@@ -30,7 +30,9 @@ public:
explicit SolidBrightnessBackend(QObject *parent = nullptr);
~SolidBrightnessBackend() override;
void maxBrightness() override;
void setBrightness(float brightness) override;
float brightness() const override;
float maxBrightness() const override;
private:
OrgKdeSolidPowerManagementActionsBrightnessControlInterface *m_iface;
......
......@@ -91,17 +91,21 @@ public class Activity extends QtActivity
}
}
public void maxBrightness() {
public void setBrightness(final float brightness) {
runOnUiThread(new Runnable() {
@Override
public void run() {
WindowManager.LayoutParams layout = getWindow().getAttributes();
layout.screenBrightness = 1F;
layout.screenBrightness = brightness;
getWindow().setAttributes(layout);
}
});
}
public float getBrightness() {
return getWindow().getAttributes().screenBrightness;
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment