|
28 | 28 | import static com.azure.reactnative.notificationhub.ReactNativeConstants.*;
|
29 | 29 |
|
30 | 30 | public class ReactNativeNotificationHubUtil {
|
31 |
| - public static final String TAG = "NotificationHubUtil"; |
| 31 | + public static final String TAG = "ReactNativeNotificationHubUtil"; |
32 | 32 |
|
33 | 33 | private static ReactNativeNotificationHubUtil sharedNotificationHubUtilInstance = null;
|
34 | 34 |
|
35 |
| - private final ExecutorService mPool = Executors.newFixedThreadPool(1); |
36 |
| - |
37 | 35 | private boolean mIsForeground;
|
38 | 36 |
|
39 | 37 | public static class IntentFactory {
|
@@ -163,194 +161,6 @@ public boolean getAppIsForeground() {
|
163 | 161 | return mIsForeground;
|
164 | 162 | }
|
165 | 163 |
|
166 |
| - public void runInWorkerThread(Runnable runnable) { |
167 |
| - mPool.execute(runnable); |
168 |
| - } |
169 |
| - |
170 |
| - public NotificationHub createNotificationHub(String hubName, String connectionString, ReactContext reactContext) { |
171 |
| - NotificationHub hub = new NotificationHub(hubName, connectionString, reactContext); |
172 |
| - return hub; |
173 |
| - } |
174 |
| - |
175 |
| - public JSONObject convertBundleToJSON(Bundle bundle) { |
176 |
| - JSONObject json = new JSONObject(); |
177 |
| - Set<String> keys = bundle.keySet(); |
178 |
| - for (String key : keys) { |
179 |
| - try { |
180 |
| - json.put(key, bundle.get(key)); |
181 |
| - } catch (JSONException e) { |
182 |
| - } |
183 |
| - } |
184 |
| - |
185 |
| - return json; |
186 |
| - } |
187 |
| - |
188 |
| - public Intent createBroadcastIntent(String action, JSONObject json) { |
189 |
| - Intent intent = IntentFactory.createIntent(action); |
190 |
| - intent.putExtra("event", DEVICE_NOTIF_EVENT); |
191 |
| - intent.putExtra("data", json.toString()); |
192 |
| - |
193 |
| - return intent; |
194 |
| - } |
195 |
| - |
196 |
| - public Class getMainActivityClass(Context context) { |
197 |
| - String packageName = context.getPackageName(); |
198 |
| - Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName); |
199 |
| - String className = launchIntent.getComponent().getClassName(); |
200 |
| - try { |
201 |
| - return Class.forName(className); |
202 |
| - } catch (ClassNotFoundException e) { |
203 |
| - Log.e(TAG, ERROR_ACTIVITY_CLASS_NOT_FOUND, e); |
204 |
| - return null; |
205 |
| - } |
206 |
| - } |
207 |
| - |
208 |
| - public int getNotificationCompatPriority(String priorityString) { |
209 |
| - int priority = NotificationCompat.PRIORITY_DEFAULT; |
210 |
| - if (priorityString != null) { |
211 |
| - switch (priorityString.toLowerCase()) { |
212 |
| - case REMOTE_NOTIFICATION_PRIORITY_MAX: |
213 |
| - priority = NotificationCompat.PRIORITY_MAX; |
214 |
| - break; |
215 |
| - case REMOTE_NOTIFICATION_PRIORITY_HIGH: |
216 |
| - priority = NotificationCompat.PRIORITY_HIGH; |
217 |
| - break; |
218 |
| - case REMOTE_NOTIFICATION_PRIORITY_LOW: |
219 |
| - priority = NotificationCompat.PRIORITY_LOW; |
220 |
| - break; |
221 |
| - case REMOTE_NOTIFICATION_PRIORITY_MIN: |
222 |
| - priority = NotificationCompat.PRIORITY_MIN; |
223 |
| - break; |
224 |
| - case REMOTE_NOTIFICATION_PRIORITY_NORMAL: |
225 |
| - priority = NotificationCompat.PRIORITY_DEFAULT; |
226 |
| - break; |
227 |
| - } |
228 |
| - } |
229 |
| - |
230 |
| - return priority; |
231 |
| - } |
232 |
| - |
233 |
| - public int getSmallIcon(Bundle bundle, Resources res, String packageName) { |
234 |
| - int smallIconResId; |
235 |
| - String smallIcon = bundle.getString(KEY_REMOTE_NOTIFICATION_SMALL_ICON); |
236 |
| - |
237 |
| - if (smallIcon != null) { |
238 |
| - smallIconResId = res.getIdentifier(smallIcon, RESOURCE_DEF_TYPE_MIPMAP, packageName); |
239 |
| - } else { |
240 |
| - smallIconResId = res.getIdentifier(RESOURCE_NAME_NOTIFICATION, RESOURCE_DEF_TYPE_MIPMAP, packageName); |
241 |
| - } |
242 |
| - |
243 |
| - if (smallIconResId == 0) { |
244 |
| - smallIconResId = res.getIdentifier(RESOURCE_NAME_LAUNCHER, RESOURCE_DEF_TYPE_MIPMAP, packageName); |
245 |
| - |
246 |
| - if (smallIconResId == 0) { |
247 |
| - smallIconResId = android.R.drawable.ic_dialog_info; |
248 |
| - } |
249 |
| - } |
250 |
| - |
251 |
| - return smallIconResId; |
252 |
| - } |
253 |
| - |
254 |
| - public int getLargeIcon(Bundle bundle, String largeIcon, Resources res, String packageName) { |
255 |
| - int largeIconResId; |
256 |
| - |
257 |
| - if (largeIcon != null) { |
258 |
| - largeIconResId = res.getIdentifier(largeIcon, RESOURCE_DEF_TYPE_MIPMAP, packageName); |
259 |
| - } else { |
260 |
| - largeIconResId = res.getIdentifier(RESOURCE_NAME_LAUNCHER, RESOURCE_DEF_TYPE_MIPMAP, packageName); |
261 |
| - } |
262 |
| - |
263 |
| - return largeIconResId; |
264 |
| - } |
265 |
| - |
266 |
| - public Uri getSoundUri(Context context, Bundle bundle) { |
267 |
| - Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); |
268 |
| - String soundName = bundle.getString(KEY_REMOTE_NOTIFICATION_SOUND_NAME); |
269 |
| - if (soundName != null) { |
270 |
| - if (!"default".equalsIgnoreCase(soundName)) { |
271 |
| - |
272 |
| - // sound name can be full filename, or just the resource name. |
273 |
| - // So the strings 'my_sound.mp3' AND 'my_sound' are accepted |
274 |
| - // The reason is to make the iOS and android javascript interfaces compatible |
275 |
| - |
276 |
| - int resId = context.getResources().getIdentifier(soundName, RESOURCE_DEF_TYPE_RAW, context.getPackageName()); |
277 |
| - if (resId == 0) { |
278 |
| - soundName = soundName.substring(0, soundName.lastIndexOf('.')); |
279 |
| - resId = context.getResources().getIdentifier(soundName, RESOURCE_DEF_TYPE_RAW, context.getPackageName()); |
280 |
| - } |
281 |
| - |
282 |
| - soundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + resId); |
283 |
| - } |
284 |
| - } |
285 |
| - |
286 |
| - return soundUri; |
287 |
| - } |
288 |
| - |
289 |
| - public Intent createNotificationIntent(Context context, Bundle bundle, Class intentClass) { |
290 |
| - Intent intent = IntentFactory.createIntent(context, intentClass); |
291 |
| - intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); |
292 |
| - bundle.putBoolean(KEY_REMOTE_NOTIFICATION_FOREGROUND, true); |
293 |
| - bundle.putBoolean(KEY_REMOTE_NOTIFICATION_USER_INTERACTION, false); |
294 |
| - bundle.putBoolean(KEY_REMOTE_NOTIFICATION_COLDSTART, false); |
295 |
| - intent.putExtra(KEY_INTENT_NOTIFICATION, bundle); |
296 |
| - |
297 |
| - return intent; |
298 |
| - } |
299 |
| - |
300 |
| - public void processNotificationActions(Context context, Bundle bundle, |
301 |
| - NotificationCompat.Builder notification, |
302 |
| - int notificationID) { |
303 |
| - JSONArray actionsArray = null; |
304 |
| - try { |
305 |
| - actionsArray = bundle.getString(KEY_REMOTE_NOTIFICATION_ACTIONS) != null ? |
306 |
| - new JSONArray(bundle.getString(KEY_REMOTE_NOTIFICATION_ACTIONS)) : null; |
307 |
| - } catch (JSONException e) { |
308 |
| - Log.e(TAG, ERROR_COVERT_ACTIONS, e); |
309 |
| - } |
310 |
| - |
311 |
| - if (actionsArray != null) { |
312 |
| - // No icon for now. The icon value of 0 shows no icon. |
313 |
| - int icon = 0; |
314 |
| - |
315 |
| - // Add button for each actions. |
316 |
| - for (int i = 0; i < actionsArray.length(); i++) { |
317 |
| - String action; |
318 |
| - try { |
319 |
| - action = actionsArray.getString(i); |
320 |
| - } catch (JSONException e) { |
321 |
| - Log.e(TAG, ERROR_GET_ACTIONS_ARRAY, e); |
322 |
| - continue; |
323 |
| - } |
324 |
| - |
325 |
| - Intent actionIntent = IntentFactory.createIntent(); |
326 |
| - actionIntent.setAction(context.getPackageName() + "." + action); |
327 |
| - // Add "action" for later identifying which button gets pressed. |
328 |
| - bundle.putString(KEY_REMOTE_NOTIFICATION_ACTION, action); |
329 |
| - actionIntent.putExtra(KEY_INTENT_NOTIFICATION, bundle); |
330 |
| - PendingIntent pendingActionIntent = PendingIntent.getBroadcast(context, notificationID, actionIntent, |
331 |
| - PendingIntent.FLAG_UPDATE_CURRENT); |
332 |
| - notification.addAction(icon, action, pendingActionIntent); |
333 |
| - } |
334 |
| - } |
335 |
| - } |
336 |
| - |
337 |
| - public NotificationCompat.Builder initNotificationCompatBuilder(Context context, |
338 |
| - String notificationChannelID, |
339 |
| - String title, |
340 |
| - CharSequence ticker, |
341 |
| - int visibility, |
342 |
| - int priority, |
343 |
| - boolean autoCancel) { |
344 |
| - NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, notificationChannelID) |
345 |
| - .setContentTitle(title) |
346 |
| - .setTicker(ticker) |
347 |
| - .setVisibility(visibility) |
348 |
| - .setPriority(priority) |
349 |
| - .setAutoCancel(autoCancel); |
350 |
| - |
351 |
| - return notificationBuilder; |
352 |
| - } |
353 |
| - |
354 | 164 | private String getPref(Context context, String key) {
|
355 | 165 | SharedPreferences prefs =
|
356 | 166 | context.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE);
|
|
0 commit comments