Skip to content

Commit

Permalink
Handle home key press
Browse files Browse the repository at this point in the history
Since it is not possible to know when the
home key is pressed, close drawer when a new
intent is received.
  • Loading branch information
Iktwo committed Aug 25, 2016
1 parent 9e67777 commit aa47cba
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iktwo.qutelauncher"
android:installLocation="auto"
android:versionCode="4"
android:versionName="0.04">
android:versionCode="5"
android:versionName="0.05">

<application
android:name="org.qtproject.qt5.android.bindings.QtApplication"
Expand Down
9 changes: 8 additions & 1 deletion src/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,18 @@ android {
abortOnError false
}

assembleRelease.doLast {

}

applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
APK_NAME + "_" + variant.productFlavors[0].name + "_"+ BUILDTYPE + ".apk")
"android-build-release-unsigned.apk")

// TODO: figure out how to fix this
// APK_NAME + "_" + variant.productFlavors[0].name + "_"+ BUILDTYPE + ".apk")
}

variant.assemble.doLast {
Expand Down
13 changes: 13 additions & 0 deletions src/android/src/com/iktwo/qutelauncher/QuteLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class QuteLauncher extends org.qtproject.qt5.android.bindings.QtActivity
private static WallpaperManager wm;
private static int mIconDpi;
private static PackageManager mPm;
private static long qtObject = 0;

public QuteLauncher() {
m_instance = this;
Expand Down Expand Up @@ -141,6 +142,12 @@ public static void openApplicationInfo(String packageName) {
m_instance.startActivity(intent);
}

public static void setQtObject(long qtObject) {
QuteLauncher.qtObject = qtObject;
}

private static native void jnewIntent(long qtObject);

@Override
public void onCreate(Bundle savedInstanceState) {
this.QT_ANDROID_DEFAULT_THEME = "AppTheme";
Expand All @@ -164,6 +171,12 @@ protected void onStart() {
mPm = (PackageManager) m_instance.getPackageManager();
}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
jnewIntent(qtObject);
}

@Override
protected void onDestroy() {
super.onDestroy();
Expand Down
6 changes: 3 additions & 3 deletions src/qml/ApplicationGrid.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ScrollView {

property int highlightedItem

maximumFlickVelocity: height * 2.5
maximumFlickVelocity: height * 5

header: Item {
width: parent.width
Expand Down Expand Up @@ -72,11 +72,11 @@ ScrollView {
text: model.name

onClicked: PackageManager.launchApplication(model.packageName)
onPressAndHold: root.pressAndHold(model)
// onPressAndHold: root.pressAndHold(model)
}

onHeightChanged: {
if (cacheBuffer !== 0)
if (height !== 0)
cacheBuffer = Math.max(1080, height * 5)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/qml/ApplicationTile.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ Item {

asynchronous: true

Layout.preferredHeight: Math.round(59 * ScreenValues.dp)
Layout.preferredWidth: Math.round(59 * ScreenValues.dp)
Layout.preferredHeight: Math.round(48 * ScreenValues.dp)
Layout.preferredWidth: Math.round(48 * ScreenValues.dp)

fillMode: Image.PreserveAspectFit
}
Expand Down
6 changes: 3 additions & 3 deletions src/qml/ExpandableItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Item {
property int minimizedWidth: Math.round(48 * ScreenValues.dp)

property int targetWidth: Math.round(parent.width - (getSideMargin() * ScreenValues.dp))
property int targetHeight: Math.round(parent.height - (44 * ScreenValues.dp))
property int targetHeight: Math.round(parent.height - 8 * ScreenValues.dp)

property point minimizedPoint: Qt.point(Math.round(parent.width / 2), Math.round(parent.height - rectangleMinizedIndicator.height - (4 * ScreenValues.dp)))
property point centerPoint: Qt.point(Math.round(parent.width / 2), Math.round(parent.height / 2))
Expand Down Expand Up @@ -92,6 +92,8 @@ Item {
to: "opened"
reversible: true
ParallelAnimation {
PropertyAnimation { property: "y"; duration: 350; easing.type: Easing.InOutCubic }

SequentialAnimation {
PauseAnimation { duration: 250 }
ParallelAnimation {
Expand All @@ -104,8 +106,6 @@ Item {
}
}
}

PropertyAnimation { property: "y"; duration: 450; easing.type: Easing.InOutCubic }
}
}
]
Expand Down
10 changes: 9 additions & 1 deletion src/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ ApplicationWindow {
interval: 550
running: true

onTriggered: PackageManager.registerBroadcast()
onTriggered: {
Launcher.registerMethods()
PackageManager.registerBroadcast()
}
}

BorderImage {
Expand Down Expand Up @@ -220,4 +223,9 @@ ApplicationWindow {

dragTarget: applicationTile
}

Connections {
target: Launcher
onNewIntentReceived: explandableItem.close()
}
}
49 changes: 48 additions & 1 deletion src/src/launcher.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
#include "launcher.h"

#ifdef Q_OS_ANDROID
#include <QAndroidJniObject>
#include <QAndroidJniEnvironment>

static void newIntent(JNIEnv *env, jobject thiz, jlong qtObject)
{
Q_UNUSED(env)
Q_UNUSED(thiz)
reinterpret_cast<Launcher*>(qtObject)->emitNewIntent();
}
#endif

Launcher::Launcher(QObject *parent) : QObject(parent)
{
#ifdef Q_OS_ANDROID
mActivity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");

#endif
}

void Launcher::pickWallpaper()
Expand All @@ -17,3 +27,40 @@ void Launcher::pickWallpaper()
"()V");
#endif
}

void Launcher::emitNewIntent()
{
emit newIntentReceived();
}

void Launcher::registerMethods()
{
registerNativeMethods();
}

void Launcher::registerNativeMethods()
{
#ifdef Q_OS_ANDROID
JNINativeMethod methods[] {{"jnewIntent", "(J)V", reinterpret_cast<void *>(newIntent)}};

QAndroidJniObject::callStaticMethod<void>("com/iktwo/qutelauncher/QuteLauncherFlavored",
"setQtObject", "(J)V",
"(J)V", reinterpret_cast<long>(this));

QAndroidJniEnvironment env;
jclass objectClass = env->GetObjectClass(mActivity.object<jobject>());

if (env->ExceptionCheck())
env->ExceptionClear();

env->RegisterNatives(objectClass, methods, sizeof(methods) / sizeof(methods[0]));

if (env->ExceptionCheck())
env->ExceptionClear();

env->DeleteLocalRef(objectClass);

if (env->ExceptionCheck())
env->ExceptionClear();
#endif
}
16 changes: 16 additions & 0 deletions src/src/launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,29 @@

#include <QObject>

#ifdef Q_OS_ANDROID
#include <QAndroidJniObject>
#endif

class Launcher : public QObject
{
Q_OBJECT
public:
explicit Launcher(QObject *parent = 0);

Q_INVOKABLE void pickWallpaper();
Q_INVOKABLE void emitNewIntent();
Q_INVOKABLE void registerMethods();

signals:
void newIntentReceived();

private:
void registerNativeMethods();

#ifdef Q_OS_ANDROID
QAndroidJniObject mActivity;
#endif
};

#endif // LAUNCHER_H
54 changes: 54 additions & 0 deletions src/src/screenvalues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ ScreenValues::ScreenValues(QObject *parent) :
{
m_dpi = retrieveDpi();

m_density = retrieveDensity();

m_dp = (float) m_dpi / 160;

setStatusBarHeight(getResourceSize("status_bar_height"));
Expand Down Expand Up @@ -105,6 +107,20 @@ bool ScreenValues::navBarVisible() const
return m_navBarVisible;
}

float ScreenValues::density() const
{
return m_density;
}

void ScreenValues::setDensity(float density)
{
if (m_density == density)
return;

m_density = density;
emit densityChanged(density);
}

int ScreenValues::statusBarHeight() const
{
return m_statusBarHeight;
Expand Down Expand Up @@ -218,6 +234,44 @@ int ScreenValues::retrieveDpi()
#endif
}

float ScreenValues::retrieveDensity()
{
#ifdef Q_OS_ANDROID
QAndroidJniEnvironment env;
env->PushLocalFrame(9);

QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative",
"activity",
"()Landroid/app/Activity;");
jclass activityClass = env->GetObjectClass(activity.object<jobject>());

jmethodID mIDGetResources = env->GetMethodID(activityClass,
"getResources",
"()Landroid/content/res/Resources;");

jobject resources = env->CallObjectMethod(activity.object<jobject>(), mIDGetResources);
jclass resourcesClass = env->GetObjectClass(resources);

jmethodID mIDGetDisplayMetrics = env->GetMethodID(resourcesClass,
"getDisplayMetrics",
"()Landroid/util/DisplayMetrics;");

jobject displayMetrics = env->CallObjectMethod(resources, mIDGetDisplayMetrics);
jclass displayMetricsClass = env->GetObjectClass(displayMetrics);

jfieldID fIDDensityDpi = env->GetFieldID(displayMetricsClass, "density", "F");
jfloat densityDpi = env->GetFloatField(displayMetrics, fIDDensityDpi);

float result = (float)densityDpi;

env->PopLocalFrame(NULL);

return result;
#else
return QGuiApplication::primaryScreen()->physicalDotsPerInch();
#endif
}

int ScreenValues::getResourceSize(const QString &resource)
{
#ifdef Q_OS_ANDROID
Expand Down
8 changes: 8 additions & 0 deletions src/src/screenvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ScreenValues : public QObject
Q_PROPERTY(int navigationBarHeightLandscape READ navigationBarHeightLandscape NOTIFY navigationBarHeightLandscapeChanged)
Q_PROPERTY(int dpi READ dpi WRITE setDpi NOTIFY dpiChanged)
Q_PROPERTY(float dp READ dp WRITE setDp NOTIFY dpChanged)
Q_PROPERTY(float density READ density NOTIFY densityChanged)
Q_PROPERTY(bool isTablet READ isTablet NOTIFY isTabletChanged)
Q_PROPERTY(bool navBarVisible READ navBarVisible NOTIFY navBarVisibleChanged)

Expand All @@ -24,6 +25,9 @@ class ScreenValues : public QObject
float dp() const;
void setDp(float dp);

float density() const;
void setDensity(float density);

int dpi() const;
void setDpi(int dpi);

Expand All @@ -47,16 +51,20 @@ class ScreenValues : public QObject
void isTabletChanged();
void navBarVisibleChanged();

void densityChanged(float density);

private:
System m_system;
float m_dp;
float m_density;
int m_dpi;
int m_statusBarHeight;
int m_navigationBarHeight;
int m_navigationBarHeightLandscape;
bool m_isTablet;
bool m_navBarVisible;

float retrieveDensity();
int retrieveDpi();
int getResourceSize(const QString &resource);

Expand Down

0 comments on commit aa47cba

Please sign in to comment.