diff options
Diffstat (limited to 'src/com/android/providers/contacts/CountryMonitor.java')
-rw-r--r-- | src/com/android/providers/contacts/CountryMonitor.java | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/com/android/providers/contacts/CountryMonitor.java b/src/com/android/providers/contacts/CountryMonitor.java index 7796849c..134a4ef7 100644 --- a/src/com/android/providers/contacts/CountryMonitor.java +++ b/src/com/android/providers/contacts/CountryMonitor.java @@ -16,6 +16,8 @@ package com.android.providers.contacts; +import android.annotation.NonNull; +import android.annotation.Nullable; import android.content.Context; import android.location.Country; import android.location.CountryDetector; @@ -32,10 +34,20 @@ import java.util.Locale; */ public class CountryMonitor { private String mCurrentCountryIso; - private Context mContext; - public CountryMonitor(Context context) { + @NonNull + private final Context mContext; + + @Nullable + private final Runnable mUpdateCallback; + + public CountryMonitor(@NonNull Context context) { + this(context, null); + } + + public CountryMonitor(@NonNull Context context, @Nullable Runnable updateCallback) { mContext = context; + mUpdateCallback = updateCallback; } /** @@ -56,11 +68,14 @@ public class CountryMonitor { } mCurrentCountryIso = country.getCountryIso(); - countryDetector.addCountryListener(new CountryListener() { - public void onCountryDetected(Country country) { - mCurrentCountryIso = country.getCountryIso(); + countryDetector.addCountryListener(new CountryListener() { + public void onCountryDetected(Country country) { + mCurrentCountryIso = country.getCountryIso(); + if (mUpdateCallback != null) { + mUpdateCallback.run(); } - }, Looper.getMainLooper()); + } + }, Looper.getMainLooper()); } return mCurrentCountryIso; } |