1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17package com.android.server.location; 18 19import android.content.Context; 20import android.location.Country; 21import android.location.CountryListener; 22import android.os.Handler; 23 24/** 25 * This class defines the methods need to be implemented by the country 26 * detector. 27 * <p> 28 * Calling {@link #detectCountry} to start detecting the country. The country 29 * could be returned immediately if it is available. 30 * 31 * @hide 32 */ 33public abstract class CountryDetectorBase { 34 protected final Handler mHandler; 35 protected final Context mContext; 36 protected CountryListener mListener; 37 protected Country mDetectedCountry; 38 39 public CountryDetectorBase(Context ctx) { 40 mContext = ctx; 41 mHandler = new Handler(); 42 } 43 44 /** 45 * Start detecting the country that the user is in. 46 * 47 * @return the country if it is available immediately, otherwise null should 48 * be returned. 49 */ 50 public abstract Country detectCountry(); 51 52 /** 53 * Register a listener to receive the notification when the country is detected or changed. 54 * <p> 55 * The previous listener will be replaced if it exists. 56 */ 57 public void setCountryListener(CountryListener listener) { 58 mListener = listener; 59 } 60 61 /** 62 * Stop detecting the country. The detector should release all system services and be ready to 63 * be freed 64 */ 65 public abstract void stop(); 66 67 protected void notifyListener(Country country) { 68 if (mListener != null) { 69 mListener.onCountryDetected(country); 70 } 71 } 72} 73