Time Zone data loader
- Use CountryZonesFinder to provide time zone id and region-to-timezone mapping, where the underlying data is updatable through an unbundled time zone data app in some devices. Bug: 73952488 Bug: 72144448 Test: m RunSettingsRoboTests Change-Id: I2e01e167c48987ebb98d4881a1a528d16dd82944
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.datetime.timezone.model;
|
||||
|
||||
import android.app.LoaderManager;
|
||||
import android.content.Context;
|
||||
import android.content.Loader;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.settingslib.utils.AsyncLoader;
|
||||
|
||||
public class TimeZoneDataLoader extends AsyncLoader<TimeZoneData> {
|
||||
|
||||
public TimeZoneDataLoader(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeZoneData loadInBackground() {
|
||||
// Heavy operation due to reading the underlying file
|
||||
return new TimeZoneData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDiscardResult(TimeZoneData result) {
|
||||
// This class doesn't hold resource of the result.
|
||||
}
|
||||
|
||||
public interface OnDataReadyCallback {
|
||||
void onTimeZoneDataReady(TimeZoneData data);
|
||||
}
|
||||
|
||||
public static class LoaderCreator implements LoaderManager.LoaderCallbacks<TimeZoneData> {
|
||||
|
||||
private final Context mContext;
|
||||
private final OnDataReadyCallback mCallback;
|
||||
|
||||
public LoaderCreator(Context context, OnDataReadyCallback callback) {
|
||||
mContext = context;
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader onCreateLoader(int id, Bundle args) {
|
||||
return new TimeZoneDataLoader(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<TimeZoneData> loader, TimeZoneData data) {
|
||||
if (mCallback != null) {
|
||||
mCallback.onTimeZoneDataReady(data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<TimeZoneData> loader) {
|
||||
//It's okay to keep the time zone data when loader is reset
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user