diff --git a/src/app/PkPassBarcode.qml b/src/app/PkPassBarcode.qml index 0c524e3..2e11565 100644 --- a/src/app/PkPassBarcode.qml +++ b/src/app/PkPassBarcode.qml @@ -1,57 +1,57 @@ /* Copyright (C) 2018 Volker Krause This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ import QtQuick 2.5 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.1 as QQC2 import org.kde.pkpass 1.0 as KPkPass import org.kde.prison 1.0 as Prison Rectangle { property var pass implicitHeight: barcodeLayout.implicitHeight implicitWidth: barcodeLayout.implicitWidth color: "white" radius: 6 Layout.alignment: Qt.AlignCenter MouseArea { anchors.fill: parent - onDoubleClicked: _brightnessManager.maxBrightness(); + onDoubleClicked: _brightnessManager.toggleBrightness(); } ColumnLayout { id: barcodeLayout anchors.fill: parent Prison.Barcode { Layout.alignment: Qt.AlignCenter Layout.margins: 4 Layout.preferredWidth: Math.max(implicitWidth, 0.8 * bodyBackground.width) Layout.preferredHeight: Layout.preferredWidth barcodeType: pass.barcodes[0].format == KPkPass.Barcode.QR ? Prison.Barcode.QRCode : Prison.Barcode.Aztec content: pass.barcodes[0].message } QQC2.Label { Layout.alignment: Qt.AlignCenter text: pass.barcodes[0].alternativeText color: "black" visible: text.length > 0 } } } diff --git a/src/app/TicketTokenDelegate.qml b/src/app/TicketTokenDelegate.qml index 44e6acc..dd01c1c 100644 --- a/src/app/TicketTokenDelegate.qml +++ b/src/app/TicketTokenDelegate.qml @@ -1,98 +1,98 @@ /* Copyright (C) 2018 Volker Krause This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ import QtQuick 2.5 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.1 as QQC2 import org.kde.kirigami 2.0 as Kirigami import org.kde.prison 1.0 as Prison import org.kde.kitinerary 1.0 import org.kde.itinerary 1.0 import "." as App ColumnLayout { id: root property var resIds readonly property var currentReservationId: ticketModel.reservationIdAt(travelerBox.currentIndex) readonly property var currentTicket: ticketModel.reservationAt(travelerBox.currentIndex).reservedTicket Layout.fillWidth: true TicketTokenModel { id: ticketModel reservationManager: _reservationManager reservationIds: resIds } QQC2.ComboBox { id: travelerBox Layout.alignment: Qt.AlignCenter model: ticketModel textRole: "display" Layout.fillWidth: true // ugly, but rowCount does not trigger binding changes Component.onCompleted: visible = ticketModel.rowCount() >= 1 && root.resIds.length > 1 } Item { id: barcodeContainer Layout.alignment: Qt.AlignCenter Layout.fillWidth: true implicitHeight: childrenRect.height Rectangle { id: background anchors.centerIn: barcodeContainer anchors.top: barcodeContainer.top anchors.bottom: barcodeContainer.bottom color: "white" implicitWidth: Math.max(root.width * 0.8, barcode.implicitWidth + barcode.anchors.margins * 2) // ### we assume aspect ratio 1:1 here, which is correct for QR and Aztec only implicitHeight: visible ? implicitWidth : 0 visible: barcode.implicitHeight > 0 MouseArea { anchors.fill: parent - onDoubleClicked: _brightnessManager.maxBrightness(); + onDoubleClicked: _brightnessManager.toggleBrightness(); } Prison.Barcode { id: barcode anchors.fill: background anchors.margins: 4 barcodeType: { if (currentTicket == undefined) return Prison.Barcode.Null; switch (currentTicket.ticketTokenType) { case Ticket.QRCode: return Prison.Barcode.QRCode; case Ticket.AztecCode: return Prison.Barcode.Aztec; case Ticket.Code128: return Prison.Barcode.Code128; } return Prison.Barcode.Null; } content: { if (barcodeType == Prison.Barcode.Null || currentTicket == undefined) return ""; return currentTicket.ticketTokenData; } } } } } diff --git a/src/app/androidbrightnessbackend.cpp b/src/app/androidbrightnessbackend.cpp index 3b5584a..cba9319 100644 --- a/src/app/androidbrightnessbackend.cpp +++ b/src/app/androidbrightnessbackend.cpp @@ -1,39 +1,52 @@ /* Copyright (C) 2018 Nicolas Fella This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "androidbrightnessbackend.h" #include #include #include AndroidBrightnessBackend::AndroidBrightnessBackend(QObject *parent) : BrightnessBackend(parent) { } AndroidBrightnessBackend::~AndroidBrightnessBackend() { } -void AndroidBrightnessBackend::maxBrightness() +float AndroidBrightnessBackend::brightness() const +{ + + float brightness = QtAndroid::androidActivity().callMethod("getBrightness", "()F"); + + return brightness; +} + +void AndroidBrightnessBackend::setBrightness(float brightness) { const auto activity = QtAndroid::androidActivity(); if (activity.isValid()) { - activity.callMethod("maxBrightness"); + activity.callMethod("setBrightness", "(F)V", brightness); } } + +float AndroidBrightnessBackend::maxBrightness() const +{ + return 1; +} diff --git a/src/app/androidbrightnessbackend.h b/src/app/androidbrightnessbackend.h index 9fc5ecc..db01289 100644 --- a/src/app/androidbrightnessbackend.h +++ b/src/app/androidbrightnessbackend.h @@ -1,36 +1,37 @@ /* Copyright (C) 2018 Nicolas Fella This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef ANDROIDBRIGHTNESSBACKEND_H #define ANDROIDBRIGHTNESSBACKEND_H #include #include "brightnessmanager.h" class AndroidBrightnessBackend : public BrightnessBackend { 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 diff --git a/src/app/brightnessmanager.cpp b/src/app/brightnessmanager.cpp index fbf4918..850d42b 100644 --- a/src/app/brightnessmanager.cpp +++ b/src/app/brightnessmanager.cpp @@ -1,45 +1,58 @@ /* Copyright (C) 2018 Nicolas Fella This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "brightnessmanager.h" #include #if defined(Q_OS_ANDROID) #include "androidbrightnessbackend.h" #elif defined(Q_OS_LINUX) #include "solidbrightnessbackend.h" #endif BrightnessManager::BrightnessManager(QObject *parent) : QObject(parent) { #if defined(Q_OS_ANDROID) m_backend = new AndroidBrightnessBackend(this); #elif defined(Q_OS_LINUX) m_backend = new SolidBrightnessBackend(this); #endif } 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; } diff --git a/src/app/brightnessmanager.h b/src/app/brightnessmanager.h index 0cbb664..b45a1aa 100644 --- a/src/app/brightnessmanager.h +++ b/src/app/brightnessmanager.h @@ -1,49 +1,61 @@ /* Copyright (C) 2018 Nicolas Fella This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef BRIGHTNESSMANAGER_H #define BRIGHTNESSMANAGER_H #include 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 { Q_OBJECT public: explicit BrightnessManager(QObject *parent = nullptr); ~BrightnessManager(); public Q_SLOTS: - void maxBrightness(); + void toggleBrightness(); private: BrightnessBackend *m_backend; }; #endif // BRIGHTNESSMANAGER_H diff --git a/src/app/solidbrightnessbackend.cpp b/src/app/solidbrightnessbackend.cpp index 4328088..7f4f6a0 100644 --- a/src/app/solidbrightnessbackend.cpp +++ b/src/app/solidbrightnessbackend.cpp @@ -1,40 +1,50 @@ /* Copyright (C) 2018 Nicolas Fella This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "solidbrightnessbackend.h" #include #include #include SolidBrightnessBackend::SolidBrightnessBackend(QObject *parent) : BrightnessBackend(parent) { m_iface = new OrgKdeSolidPowerManagementActionsBrightnessControlInterface( QStringLiteral("org.kde.Solid.PowerManagement"), QStringLiteral("/org/kde/Solid/PowerManagement/Actions/BrightnessControl"), QDBusConnection::sessionBus(), this); } 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(); } diff --git a/src/app/solidbrightnessbackend.h b/src/app/solidbrightnessbackend.h index 5189a27..44a9420 100644 --- a/src/app/solidbrightnessbackend.h +++ b/src/app/solidbrightnessbackend.h @@ -1,39 +1,41 @@ /* Copyright (C) 2018 Nicolas Fella This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef SOLIDBRIGHTNESSBACKEND_H #define SOLIDBRIGHTNESSBACKEND_H #include #include "brightnessmanager.h" class OrgKdeSolidPowerManagementActionsBrightnessControlInterface; class SolidBrightnessBackend : public BrightnessBackend { 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; }; #endif // SOLIDBRIGHTNESSBACKEND_H diff --git a/src/app/src/org/kde/itinerary/Activity.java b/src/app/src/org/kde/itinerary/Activity.java index e31b685..837658e 100644 --- a/src/app/src/org/kde/itinerary/Activity.java +++ b/src/app/src/org/kde/itinerary/Activity.java @@ -1,110 +1,114 @@ /* Copyright (C) 2018 Volker Krause This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package org.kde.itinerary; import org.qtproject.qt5.android.bindings.QtActivity; import net.fortuna.ical4j.model.property.XProperty; import android.content.ContentResolver; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.provider.CalendarContract; import android.util.Log; import android.view.WindowManager; import java.io.*; import java.util.*; public class Activity extends QtActivity { private static final String TAG = "org.kde.itinerary"; public void launchViewIntentFromUri(String uri) { Uri mapIntentUri = Uri.parse(uri); Intent mapIntent = new Intent(Intent.ACTION_VIEW, mapIntentUri); startActivity(mapIntent); } public native void importReservation(String data); public native void importFromIntent(Intent data); /** Check the calendar for with JSON-LD data. * This assumes the custom property serialization format used by DavDroid. */ public void checkCalendar() { Calendar startTime = Calendar.getInstance(); startTime.add(Calendar.DAY_OF_YEAR, -5); Calendar endTime = Calendar.getInstance(); endTime.add(Calendar.MONTH, 6); String[] eventColumns = new String[] { "uid2445", "title", "_id" }; String[] propColumns = new String[] { "name", "value" }; String eventSelection = "(( " + CalendarContract.Events.DTSTART + " >= " + startTime.getTimeInMillis() + " ) AND ( " + CalendarContract.Events.DTSTART + " <= " + endTime.getTimeInMillis() + " ))"; Cursor cursor = getContentResolver().query(CalendarContract.Events.CONTENT_URI, eventColumns, eventSelection, null, null); while (cursor.moveToNext()) { if (cursor.getString(0) == null || !cursor.getString(0).startsWith("KIT-")) { continue; } Log.i(TAG, cursor.getString(1)); String propSelection = "(event_id == " + cursor.getInt(2) + ")"; Cursor propCursor = getContentResolver().query(CalendarContract.ExtendedProperties.CONTENT_URI, propColumns, propSelection, null, null); while (propCursor.moveToNext()) { if (propCursor.getString(0) == null || !propCursor.getString(0).equals("unknown-property") || propCursor.getString(1) == null) { continue; } ByteArrayInputStream bis = new ByteArrayInputStream(android.util.Base64.decode(propCursor.getString(1), android.util.Base64.NO_WRAP)); try { ObjectInputStream ois = new ObjectInputStream(bis); Object prop = ois.readObject(); if (prop instanceof XProperty) { importReservation(((XProperty)prop).getValue()); } } catch (Exception e) { Log.i(TAG, e.toString()); continue; } } } } - 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); importFromIntent(intent); } }