use of android.app.LoaderManager in project android_packages_apps_Settings by DirtyUnicorns.
the class SearchFragment method onIndexingFinished.
/**
* Gets called when Indexing is completed.
*/
@Override
public void onIndexingFinished() {
if (getActivity() == null) {
return;
}
if (mShowingSavedQuery) {
mSavedQueryController.loadSavedQueries();
} else {
final LoaderManager loaderManager = getLoaderManager();
loaderManager.initLoader(SearchLoaderId.DATABASE, null, /* args */
this);
loaderManager.initLoader(SearchLoaderId.INSTALLED_APPS, null, /* args */
this);
loaderManager.initLoader(SearchLoaderId.ACCESSIBILITY_SERVICES, null, /* args */
this);
loaderManager.initLoader(SearchLoaderId.INPUT_DEVICES, null, /* args */
this);
}
requery();
}
use of android.app.LoaderManager in project android_packages_apps_Settings by DirtyUnicorns.
the class InstalledAppDetails method onResume.
@Override
public void onResume() {
super.onResume();
if (mFinishing) {
return;
}
AppItem app = new AppItem(mAppEntry.info.uid);
app.addUid(mAppEntry.info.uid);
if (mStatsSession != null) {
LoaderManager loaderManager = getLoaderManager();
loaderManager.restartLoader(LOADER_CHART_DATA, ChartDataLoader.buildArgs(getTemplate(getContext()), app), mDataCallbacks);
loaderManager.restartLoader(LOADER_STORAGE, Bundle.EMPTY, this);
}
restartBatteryStatsLoader();
if (mDevelopmentSettingsEnabler.getLastEnabledState()) {
new MemoryUpdater().execute();
}
updateDynamicPrefs();
}
use of android.app.LoaderManager in project android_packages_apps_Settings by DirtyUnicorns.
the class SearchFragmentTest method onIndexingFinished_notShowingSavedQuery_initLoaders.
@Test
public void onIndexingFinished_notShowingSavedQuery_initLoaders() {
ActivityController<SearchActivity> activityController = Robolectric.buildActivity(SearchActivity.class);
activityController.setup();
SearchFragment fragment = (SearchFragment) spy(activityController.get().getFragmentManager().findFragmentById(R.id.main_content));
final LoaderManager loaderManager = mock(LoaderManager.class);
when(fragment.getLoaderManager()).thenReturn(loaderManager);
fragment.mShowingSavedQuery = false;
fragment.mQuery = null;
fragment.onIndexingFinished();
verify(loaderManager).initLoader(eq(SearchFragment.SearchLoaderId.DATABASE), eq(null), any(LoaderManager.LoaderCallbacks.class));
verify(loaderManager).initLoader(eq(SearchFragment.SearchLoaderId.INSTALLED_APPS), eq(null), any(LoaderManager.LoaderCallbacks.class));
}
use of android.app.LoaderManager in project Collar by CodeZsx.
the class ImageScan method startScanImg.
protected void startScanImg(final Context context, LoaderManager loaderManager) {
mFolderList = new ArrayList<>();
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
T.s(context, "暂无外部存储");
return;
}
LoaderManager.LoaderCallbacks<Cursor> loaderCallbacks = new LoaderManager.LoaderCallbacks<Cursor>() {
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
CursorLoader imageCursorLoader = new CursorLoader(context, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, IMAGE_PROJECTION, null, null, MediaStore.Images.Media.DEFAULT_SORT_ORDER);
return imageCursorLoader;
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
if (data.getCount() == 0) {
T.s(context, "没有扫描到图片");
} else {
// 获取属性列的索引位置
int dataColumnIndex = data.getColumnIndex(MediaStore.Images.Media.DATA);
// 图片目录arraylist
ArrayList<File> albumList = new ArrayList<>();
// 图片目录的hashmap,防止扫描同一目录下的图片,图片目录重复出现
// <相册的绝对路径,相册底下的所有图片>
HashMap<String, ArrayList<File>> albumImageListMap = new HashMap<>();
while (data.moveToNext()) {
// 图片文件
File imageFile = new File(data.getString(dataColumnIndex));
// 图片的父文件夹
File albumFolder = imageFile.getParentFile();
// 图片目录arraylist中没有这个目录,就加入到里面
if (!albumList.contains(albumFolder)) {
albumList.add(albumFolder);
}
// 获取绝对路径
String albumPath = albumFolder.getAbsolutePath();
// 获取该相册下的所有图片
ArrayList<File> albumImageFiles = albumImageListMap.get(albumPath);
// 检查此目录是否存在hashmap中,如果没有就添加进去
if (albumImageFiles == null) {
albumImageFiles = new ArrayList<>();
albumImageListMap.put(albumPath, albumImageFiles);
}
// 把当前的图片添加到相册目录下
albumImageFiles.add(imageFile);
}
// 对相册目录进行排序
sortByFileLastModified(albumList);
// 对图片目录下所有的图片文件进行排序
// 取出key列表,即目录列表
Set<String> keySet = albumImageListMap.keySet();
for (String key : keySet) {
ArrayList<File> albumImageList = albumImageListMap.get(key);
sortByFileLastModified(albumImageList);
}
if (albumList != null && albumList.size() > 0 && albumImageListMap != null) {
ArrayList<AlbumFolder> folders = new ArrayList<>();
// 生成一个包含全部的名为"全部"的目录
AlbumFolder allFolder = createAllImageAlbum(context, albumImageListMap);
if (allFolder != null) {
folders.add(allFolder);
}
int albumFolerSize = albumList.size();
for (int pos = 0; pos < albumFolerSize; pos++) {
File album = albumList.get(pos);
AlbumFolder folder = new AlbumFolder();
// 设置目录名
folder.setFolderName(album.getName());
// 获取当前目录下的图片list
List<File> curList = albumImageListMap.get(album.getAbsolutePath());
// 设置cover
folder.setCover(curList.get(0));
// 设置目录下的图片list
folder.setImageList(curList);
// 把当前目录的图片list添加到"全部"目录下
allFolder.getImageList().addAll(curList);
// 把设置完的folder添加到list中
folders.add(folder);
}
mFolderList = folders;
}
onScanFinish(mFolderList);
}
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
}
};
// 初始化指定id的loader
loaderManager.initLoader(IMAGE_LOADER_ID, null, loaderCallbacks);
}
use of android.app.LoaderManager in project android_packages_apps_Settings by crdroidandroid.
the class SearchFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
long startTime = System.currentTimeMillis();
setHasOptionsMenu(true);
final LoaderManager loaderManager = getLoaderManager();
mSearchAdapter = new SearchResultsAdapter(this, mSearchFeatureProvider);
mSavedQueryController = new SavedQueryController(getContext(), loaderManager, mSearchAdapter);
mSearchFeatureProvider.initFeedbackButton();
if (savedInstanceState != null) {
mQuery = savedInstanceState.getString(STATE_QUERY);
mNeverEnteredQuery = savedInstanceState.getBoolean(STATE_NEVER_ENTERED_QUERY);
mResultClickCount = savedInstanceState.getInt(STATE_RESULT_CLICK_COUNT);
mShowingSavedQuery = savedInstanceState.getBoolean(STATE_SHOWING_SAVED_QUERY);
} else {
mShowingSavedQuery = true;
}
final Activity activity = getActivity();
// Run the Index update only if we have some space
if (!Utils.isLowStorage(activity)) {
mSearchFeatureProvider.updateIndexAsync(activity, this);
} else {
Log.w(TAG, "Cannot update the Indexer as we are running low on storage space!");
}
if (SettingsSearchIndexablesProvider.DEBUG) {
Log.d(TAG, "onCreate spent " + (System.currentTimeMillis() - startTime) + " ms");
}
}
Aggregations