diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2019-11-21 02:10:26 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2019-11-21 02:10:26 +0000 |
commit | 846cf730fceaefd927a1d2fbbe0af18bfb739ee8 (patch) | |
tree | f1225c36792ebf211f4f90937fa4092dfd0fd3db /tests/src/com/android/wallpaper/testing/TestCategoryProvider.java | |
parent | d6b718de5f6bd24410087482a7687bb1fd09536b (diff) | |
parent | 9734f7414149c6fc9f0a704576ad17e4c09ec2d8 (diff) | |
download | android_packages_apps_WallpaperPicker2-846cf730fceaefd927a1d2fbbe0af18bfb739ee8.tar.gz android_packages_apps_WallpaperPicker2-846cf730fceaefd927a1d2fbbe0af18bfb739ee8.tar.bz2 android_packages_apps_WallpaperPicker2-846cf730fceaefd927a1d2fbbe0af18bfb739ee8.zip |
Snap for 6021960 from 9734f7414149c6fc9f0a704576ad17e4c09ec2d8 to qt-qpr2-release
Change-Id: I4e7faba13af7127727057361073631ba16328b73
Diffstat (limited to 'tests/src/com/android/wallpaper/testing/TestCategoryProvider.java')
-rw-r--r-- | tests/src/com/android/wallpaper/testing/TestCategoryProvider.java | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/src/com/android/wallpaper/testing/TestCategoryProvider.java b/tests/src/com/android/wallpaper/testing/TestCategoryProvider.java new file mode 100644 index 0000000..310840c --- /dev/null +++ b/tests/src/com/android/wallpaper/testing/TestCategoryProvider.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2019 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.wallpaper.testing; + +import android.os.Handler; + +import com.android.wallpaper.model.Category; +import com.android.wallpaper.model.CategoryProvider; +import com.android.wallpaper.model.CategoryReceiver; +import com.android.wallpaper.model.ImageCategory; +import com.android.wallpaper.model.WallpaperInfo; + +import java.util.ArrayList; +import java.util.List; + +/** + * Test implementation of {@link CategoryProvider}. + */ +public class TestCategoryProvider implements CategoryProvider { + private final List<Category> mCategories; + + public TestCategoryProvider() { + Category category1 = new ImageCategory( + "My photos" /* title */, + "image_wallpapers" /* collection */, + 0 /* priority */); + + ArrayList<WallpaperInfo> wallpapers = new ArrayList<>(); + WallpaperInfo wallpaperInfo = new com.android.wallpaper.testing.TestWallpaperInfo(0); + wallpapers.add(wallpaperInfo); + Category category2 = new com.android.wallpaper.testing.TestWallpaperCategory( + "Test category", "init_collection", wallpapers, + 1 /* priority */); + + mCategories = new ArrayList<>(); + mCategories.add(category1); + mCategories.add(category2); + } + + @Override + public void fetchCategories(CategoryReceiver receiver, boolean forceRefresh) { + // Mimic real behavior by fetching asynchronously. + new Handler().post(new Runnable() { + @Override + public void run() { + List<Category> categories = getTestCategories(); + for (Category category : categories) { + receiver.onCategoryReceived(category); + } + receiver.doneFetchingCategories(); + } + }); + } + + @Override + public int getSize() { + return mCategories == null ? 0 : mCategories.size(); + } + + @Override + public Category getCategory(int index) { + return mCategories == null ? null : mCategories.get(index); + } + + @Override + public Category getCategory(String collectionId) { + Category category; + for (int i = 0; i < mCategories.size(); i++) { + category = mCategories.get(i); + if (category.getCollectionId().equals(collectionId)) { + return category; + } + } + return null; + } + + /** Returns a list of test Category objects used by this TestCategoryProvider. */ + public List<Category> getTestCategories() { + return mCategories; + } +} |