Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: jni/JniNotification.cpp

Issue 5327480814567424: Issue 1108 - Support notifications (Closed)
Patch Set: Removed markAsShown() Created Feb. 18, 2015, 2:46 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <AdblockPlus.h>
19 #include "Utils.h"
20 #include "JniJsValue.h"
21
22 static AdblockPlus::Notification* GetNotificationPtr(jlong ptr)
23 {
24 return JniLongToTypePtr<AdblockPlus::NotificationPtr>(ptr)->get();
25 }
26
27 static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr)
28 {
29 AdblockPlus::NotificationType type;
30 try
31 {
32 type = GetNotificationPtr(ptr)->GetType();
33 }
34 CATCH_THROW_AND_RETURN(env, 0)
35
36 const char* enumName = 0;
37
38 switch (type)
39 {
40 case AdblockPlus::NotificationType::NOTIFICATION_TYPE_CRITICAL:
41 enumName = "CRITICAL";
42 break;
43 case AdblockPlus::NotificationType::NOTIFICATION_TYPE_INFORMATION:
44 enumName = "INFORMATION";
45 break;
46 case AdblockPlus::NotificationType::NOTIFICATION_TYPE_QUESTION:
47 enumName = "QUESTION";
48 break;
49 default:
50 enumName = "INVALID";
51 break;
52 }
53
54 JniLocalReference<jclass> enumClass(
55 env,
56 env->FindClass(PKG("Notification$Type")));
57
58 jfieldID enumField = env->GetStaticFieldID(
59 *enumClass,
60 enumName,
61 TYP("Notification$Type"));
62
63 return env->GetStaticObjectField(*enumClass, enumField);
64 }
65
66 static jstring JniGetTitle(JNIEnv* env, jclass clazz, jlong ptr)
67 {
68 try
69 {
70 return env->NewStringUTF(GetNotificationPtr(ptr)->GetTitle().c_str());
71 }
72 CATCH_THROW_AND_RETURN(env, 0)
73 }
74
75 static jstring JniGetMessageString(JNIEnv* env, jclass clazz, jlong ptr)
76 {
77 try
78 {
79 return env->NewStringUTF(GetNotificationPtr(ptr)->GetMessageString().c_str() );
80 }
81 CATCH_THROW_AND_RETURN(env, 0)
82 }
83
84 static void JniMarkAsShown(JNIEnv* env, jclass clazz, jlong ptr)
85 {
86 try
87 {
88 GetNotificationPtr(ptr)->MarkAsShown();
89 }
90 CATCH_AND_THROW(env)
91 }
92
93 static JNINativeMethod methods[] =
94 {
95 { (char*) "markAsShown", (char*) "(J)V", (void*) JniMarkAsShown },
96 { (char*) "getMessageString", (char*) "(J)Ljava/lang/String;", (void*) JniGetM essageString },
97 { (char*) "getTitle", (char*) "(J)Ljava/lang/String;", (void*) JniGetTitle },
98 { (char*) "getType", (char*) "(J)" TYP("Notification$Type"), (void*) JniGetTyp e }
99 };
100
101 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Notificati on_registerNatives(
102 JNIEnv *env, jclass clazz)
103 {
104 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
105 }
106
OLDNEW

Powered by Google App Engine
This is Rietveld