OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.device.time_zone_monitor; | |
6 | |
7 import android.content.BroadcastReceiver; | |
8 import android.content.Context; | |
9 import android.content.Intent; | |
10 import android.content.IntentFilter; | |
11 | |
12 import org.chromium.base.Log; | |
13 import org.chromium.base.annotations.CalledByNative; | |
14 import org.chromium.base.annotations.JNINamespace; | |
15 | |
16 /** | |
17 * Android implementation details for device::TimeZoneMonitorAndroid. | |
18 */ | |
19 @JNINamespace("device") | |
20 class TimeZoneMonitor { | |
21 private static final String TAG = "cr_TimeZoneMonitor"; | |
22 | |
23 private final Context mAppContext; | |
24 private final IntentFilter mFilter = new IntentFilter(Intent.ACTION_TIMEZONE
_CHANGED); | |
25 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver()
{ | |
26 @Override | |
27 public void onReceive(Context context, Intent intent) { | |
28 if (!intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED)) { | |
29 Log.e(TAG, "unexpected intent"); | |
30 return; | |
31 } | |
32 | |
33 nativeTimeZoneChangedFromJava(mNativePtr); | |
34 } | |
35 }; | |
36 | |
37 private long mNativePtr; | |
38 | |
39 /** | |
40 * Start listening for intents. | |
41 * @param nativePtr The native device::TimeZoneMonitorAndroid to notify of t
ime zone changes. | |
42 */ | |
43 private TimeZoneMonitor(Context context, long nativePtr) { | |
44 mAppContext = context.getApplicationContext(); | |
45 mNativePtr = nativePtr; | |
46 mAppContext.registerReceiver(mBroadcastReceiver, mFilter); | |
47 } | |
48 | |
49 @CalledByNative | |
50 static TimeZoneMonitor getInstance(Context context, long nativePtr) { | |
51 return new TimeZoneMonitor(context, nativePtr); | |
52 } | |
53 | |
54 /** | |
55 * Stop listening for intents. | |
56 */ | |
57 @CalledByNative | |
58 void stop() { | |
59 mAppContext.unregisterReceiver(mBroadcastReceiver); | |
60 mNativePtr = 0; | |
61 } | |
62 | |
63 /** | |
64 * Native JNI call to device::TimeZoneMonitorAndroid::TimeZoneChanged. | |
65 * See device/time_zone_monitor/time_zone_monitor_android.cc. | |
66 */ | |
67 private native void nativeTimeZoneChangedFromJava(long nativeTimeZoneMonitor
Android); | |
68 } | |
OLD | NEW |