Search in sources :

Example 31 with Country

use of android.location.Country in project android_frameworks_base by AOSPA.

the class LocationBasedCountryDetector method queryCountryCode.

/**
     * Start a new thread to query the country from Geocoder.
     */
private synchronized void queryCountryCode(final Location location) {
    if (location == null) {
        notifyListener(null);
        return;
    }
    if (mQueryThread != null)
        return;
    mQueryThread = new Thread(new Runnable() {

        @Override
        public void run() {
            String countryIso = null;
            if (location != null) {
                countryIso = getCountryFromLocation(location);
            }
            if (countryIso != null) {
                mDetectedCountry = new Country(countryIso, Country.COUNTRY_SOURCE_LOCATION);
            } else {
                mDetectedCountry = null;
            }
            notifyListener(mDetectedCountry);
            mQueryThread = null;
        }
    });
    mQueryThread.start();
}
Also used : Country(android.location.Country)

Example 32 with Country

use of android.location.Country in project android_frameworks_base by crdroidandroid.

the class ComprehensiveCountryDetector method toString.

@Override
public String toString() {
    long currentTime = SystemClock.elapsedRealtime();
    long currentSessionLength = 0;
    StringBuilder sb = new StringBuilder();
    sb.append("ComprehensiveCountryDetector{");
    // The detector hasn't stopped yet --> still running
    if (mStopTime == 0) {
        currentSessionLength = currentTime - mStartTime;
        sb.append("timeRunning=" + currentSessionLength + ", ");
    } else {
        // Otherwise, it has already stopped, so take the last session
        sb.append("lastRunTimeLength=" + (mStopTime - mStartTime) + ", ");
    }
    sb.append("totalCountServiceStateChanges=" + mTotalCountServiceStateChanges + ", ");
    sb.append("currentCountServiceStateChanges=" + mCountServiceStateChanges + ", ");
    sb.append("totalTime=" + (mTotalTime + currentSessionLength) + ", ");
    sb.append("currentTime=" + currentTime + ", ");
    sb.append("countries=");
    for (Country country : mDebugLogs) {
        sb.append("\n   " + country.toString());
    }
    sb.append("}");
    return sb.toString();
}
Also used : Country(android.location.Country)

Example 33 with Country

use of android.location.Country in project android_frameworks_base by crdroidandroid.

the class ComprehensiveCountryDetector method getCountry.

/**
     * Get the country from different sources in order of the reliability.
     */
private Country getCountry() {
    Country result = null;
    result = getNetworkBasedCountry();
    if (result == null) {
        result = getLastKnownLocationBasedCountry();
    }
    if (result == null) {
        result = getSimBasedCountry();
    }
    if (result == null) {
        result = getLocaleCountry();
    }
    addToLogs(result);
    return result;
}
Also used : Country(android.location.Country)

Example 34 with Country

use of android.location.Country in project android_frameworks_base by crdroidandroid.

the class LocationBasedCountryDetector method queryCountryCode.

/**
     * Start a new thread to query the country from Geocoder.
     */
private synchronized void queryCountryCode(final Location location) {
    if (location == null) {
        notifyListener(null);
        return;
    }
    if (mQueryThread != null)
        return;
    mQueryThread = new Thread(new Runnable() {

        @Override
        public void run() {
            String countryIso = null;
            if (location != null) {
                countryIso = getCountryFromLocation(location);
            }
            if (countryIso != null) {
                mDetectedCountry = new Country(countryIso, Country.COUNTRY_SOURCE_LOCATION);
            } else {
                mDetectedCountry = null;
            }
            notifyListener(mDetectedCountry);
            mQueryThread = null;
        }
    });
    mQueryThread.start();
}
Also used : Country(android.location.Country)

Example 35 with Country

use of android.location.Country in project android_frameworks_base by crdroidandroid.

the class CallerInfo method getCurrentCountryIso.

/**
     * @return The ISO 3166-1 two letters country code of the country the user
     *         is in.
     */
private static String getCurrentCountryIso(Context context, Locale locale) {
    String countryIso = null;
    CountryDetector detector = (CountryDetector) context.getSystemService(Context.COUNTRY_DETECTOR);
    if (detector != null) {
        Country country = detector.detectCountry();
        if (country != null) {
            countryIso = country.getCountryIso();
        } else {
            Rlog.e(TAG, "CountryDetector.detectCountry() returned null.");
        }
    }
    if (countryIso == null) {
        countryIso = locale.getCountry();
        Rlog.w(TAG, "No CountryDetector; falling back to countryIso based on locale: " + countryIso);
    }
    return countryIso;
}
Also used : Country(android.location.Country) CountryDetector(android.location.CountryDetector)

Aggregations

Country (android.location.Country)71 CountryListener (android.location.CountryListener)6 ICountryListener (android.location.ICountryListener)6 ComprehensiveCountryDetector (com.android.server.location.ComprehensiveCountryDetector)6 CountryDetector (android.location.CountryDetector)4 Context (android.content.Context)1 StrictMode (android.os.StrictMode)1 LifecycleHandler (com.moez.QKSMS.common.LifecycleHandler)1 PduLoaderManager (com.moez.QKSMS.common.google.PduLoaderManager)1 ThumbnailManager (com.moez.QKSMS.common.google.ThumbnailManager)1