Commit 41cfad21 authored by Sergey Galin's avatar Sergey Galin

Added QAndroidToast with showToast() function.

parent b112ab7c
......@@ -60,6 +60,7 @@ QAndroidDialog::QAndroidDialog(QObject * parent)
, delete_self_on_close_(false)
, result_button_(0)
{
preloadJavaClasses();
dialog_helper_.reset(new QJniObject(c_full_class_name_, "J", (jlong)this));
if (!dialog_helper_->jObject())
{
......
/*
Lightweight access to various Android APIs for Qt
Author:
Sergey A. Galin <sergey.galin@gmail.com>
Distrbuted under The BSD License
Copyright (c) 2014, DoubleGIS, LLC.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the DoubleGIS, LLC nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <QAndroidQPAPluginGap.h>
#include "QAndroidToast.h"
static const char * const c_full_class_name_ = "ru/dublgis/androidhelpers/ToastHelper";
namespace QAndroidToast {
void showToast(const QString & text, bool length_long)
{
QJniClass(c_full_class_name_).callStaticParamVoid(
"showToast",
"Landroid/app/Activity;Ljava/lang/String;I",
QJniObject(QAndroidQPAPluginGap::getActivity(), true).jObject(),
QJniLocalRef(text).jObject(),
jint((length_long)? ANDROID_TOAST_LENGTH_LONG: ANDROID_TOAST_LENGTH_SHORT));
}
void preloadJavaClasses()
{
static bool s_preloaded = false;
if (!s_preloaded)
{
QAndroidQPAPluginGap::preloadJavaClass(c_full_class_name_);
s_preloaded = true;
}
}
} // namespace QAndroidToast
/*
Lightweight access to various Android APIs for Qt
Author:
Sergey A. Galin <sergey.galin@gmail.com>
Distrbuted under The BSD License
Copyright (c) 2014, DoubleGIS, LLC.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the DoubleGIS, LLC nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <QtCore/QString>
#include <QJniHelpers.h>
namespace QAndroidToast {
const jint
ANDROID_TOAST_LENGTH_SHORT = 0,
ANDROID_TOAST_LENGTH_LONG = 1;
void showToast(const QString & text, bool length_long = false);
void preloadJavaClasses();
} // namespace QAndroidToast
......@@ -5,7 +5,8 @@ HEADERS += \
QAndroidDisplayMetrics.h \
QAndroidFilePaths.h \
QAndroidScreenOrientation.h \
QAndroidScreenLayoutHandler.h
QAndroidScreenLayoutHandler.h \
QAndroidToast.h
SOURCES += \
QAndroidConfiguration.cpp \
......@@ -13,4 +14,5 @@ SOURCES += \
QAndroidDisplayMetrics.cpp \
QAndroidFilePaths.cpp \
QAndroidScreenOrientation.cpp \
QAndroidScreenLayoutHandler.cpp
QAndroidScreenLayoutHandler.cpp \
QAndroidToast.cpp
/*
Offscreen Android Views library for Qt
Author:
Sergey A. Galin <sergey.galin@gmail.com>
Distrbuted under The BSD License
Copyright (c) 2014, DoubleGIS, LLC.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the DoubleGIS, LLC nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/
package ru.dublgis.androidhelpers;
import java.lang.Thread;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
public class ToastHelper
{
public static final String TAG = "Grym/ToastHelper";
public static void showToast(final Activity a, final String text, final int duration)
{
try
{
a.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast toast = Toast.makeText(a, text, duration);
toast.show();
}
});
}
catch(Exception e)
{
Log.e(TAG, "showToast: exception: "+e);
}
}
}
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