Commit 818ab3a7 authored by Paweł Wegner's avatar Paweł Wegner

cloudbrowser: refactored native methods.

parent 0940f327
...@@ -26,8 +26,6 @@ public class CloudBrowser extends QtActivity { ...@@ -26,8 +26,6 @@ public class CloudBrowser extends QtActivity {
private RelativeLayout m_ad_view; private RelativeLayout m_ad_view;
private boolean m_ad_view_visible = false; private boolean m_ad_view_visible = false;
private native void onRequestResult(int request, int result, Intent data);
private void updateAdView() { private void updateAdView() {
if (m_ad_view != null && m_view_group != null) if (m_ad_view != null && m_view_group != null)
m_view_group.removeView(m_ad_view); m_view_group.removeView(m_ad_view);
...@@ -57,14 +55,14 @@ public class CloudBrowser extends QtActivity { ...@@ -57,14 +55,14 @@ public class CloudBrowser extends QtActivity {
public void onAdLoaded() { public void onAdLoaded() {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
NotificationHelper.callback("SHOW_AD"); Utility.onActionRequested("SHOW_AD");
attach(); attach();
} }
}); });
} }
public void onAdFailedToLoad(int error) { public void onAdFailedToLoad(int error) {
NotificationHelper.callback("HIDE_AD"); Utility.onActionRequested("HIDE_AD");
} }
}); });
ad.loadAd(new AdRequest.Builder().build()); ad.loadAd(new AdRequest.Builder().build());
...@@ -93,7 +91,7 @@ public class CloudBrowser extends QtActivity { ...@@ -93,7 +91,7 @@ public class CloudBrowser extends QtActivity {
@Override @Override
public void onActivityResult(int request, int result, Intent data) { public void onActivityResult(int request, int result, Intent data) {
super.onActivityResult(request, result, data); super.onActivityResult(request, result, data);
onRequestResult(request, result, data); Utility.onRequestResult(request, result, data);
} }
@Override @Override
......
...@@ -22,12 +22,10 @@ public class NotificationHelper { ...@@ -22,12 +22,10 @@ public class NotificationHelper {
private static class Receiver extends BroadcastReceiver { private static class Receiver extends BroadcastReceiver {
public void onReceive(Context ctx, Intent intent) { public void onReceive(Context ctx, Intent intent) {
callback(intent.getAction()); Utility.onActionRequested(intent.getAction());
} }
} }
public static native void callback(String action);
public NotificationHelper(Context context) { public NotificationHelper(Context context) {
m_context = context; m_context = context;
m_notification_manager = m_notification_manager =
......
...@@ -4,6 +4,9 @@ import android.net.Uri; ...@@ -4,6 +4,9 @@ import android.net.Uri;
import android.content.Intent; import android.content.Intent;
public class Utility { public class Utility {
public static native void onActionRequested(String action);
public static native void onRequestResult(int request, int result, Intent data);
public static Uri stringToUri(String uri) { public static Uri stringToUri(String uri) {
String basename = uri.substring(0, uri.lastIndexOf('/') + 1); String basename = uri.substring(0, uri.lastIndexOf('/') + 1);
String filename = uri.substring(uri.lastIndexOf('/') + 1); String filename = uri.substring(uri.lastIndexOf('/') + 1);
......
...@@ -24,20 +24,15 @@ std::unordered_map<int, std::unordered_set<AndroidUtility::IResultListener *>> ...@@ -24,20 +24,15 @@ std::unordered_map<int, std::unordered_set<AndroidUtility::IResultListener *>>
} // namespace } // namespace
extern "C" { extern "C" {
JNIEXPORT void JNICALL JNIEXPORT void JNICALL Java_org_videolan_cloudbrowser_Utility_onActionRequested(
Java_org_videolan_cloudbrowser_NotificationHelper_callback(JNIEnv *env, JNIEnv *env, jclass *, jstring action) {
jclass *,
jstring action) {
const char *str = env->GetStringUTFChars(action, nullptr); const char *str = env->GetStringUTFChars(action, nullptr);
emit android->notify(str); emit android->notify(str);
env->ReleaseStringUTFChars(action, str); env->ReleaseStringUTFChars(action, str);
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL Java_org_videolan_cloudbrowser_Utility_onRequestResult(
Java_org_videolan_cloudbrowser_CloudBrowser_onRequestResult(JNIEnv *, jobject *, JNIEnv *, jclass *, jint request, jint result, jobject data) {
jint request,
jint result,
jobject data) {
std::unique_lock<std::mutex> lock(mutex); std::unique_lock<std::mutex> lock(mutex);
auto cb = result_listener.find(request); auto cb = result_listener.find(request);
if (cb != result_listener.end()) { if (cb != result_listener.end()) {
......
...@@ -57,7 +57,7 @@ class FileDialog : public IFileDialog { ...@@ -57,7 +57,7 @@ class FileDialog : public IFileDialog {
public: public:
ActivityReceiver(FileDialog*); ActivityReceiver(FileDialog*);
void done(int request_code, int result_code, void done(int request_code, int result_code,
const QAndroidJniObject& data) override; const QAndroidJniObject& data) override;
private: private:
FileDialog* file_dialog_; FileDialog* file_dialog_;
......
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