summaryrefslogtreecommitdiffstats
path: root/WallpaperPicker/src/com/android/launcher3/wallpapertileinfo/FileWallpaperInfo.java
blob: f6a46fc48e771a46aa382270c05f6619c6bc16f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.android.launcher3.wallpapertileinfo;

import android.graphics.drawable.Drawable;
import android.net.Uri;

import com.android.launcher3.WallpaperPickerActivity;
import com.android.photos.BitmapRegionTileSource;
import com.android.photos.BitmapRegionTileSource.BitmapSource;

import java.io.File;

public class FileWallpaperInfo extends DrawableThumbWallpaperInfo {

    private final File mFile;

    public FileWallpaperInfo(File target, Drawable thumb) {
        super(thumb);
        mFile = target;
    }

    @Override
    public void onClick(final WallpaperPickerActivity a) {
        a.setWallpaperButtonEnabled(false);
        final BitmapRegionTileSource.FilePathBitmapSource bitmapSource =
                new BitmapRegionTileSource.FilePathBitmapSource(mFile.getAbsolutePath());
        a.setCropViewTileSource(bitmapSource, false, true, null, new Runnable() {

            @Override
            public void run() {
                if (bitmapSource.getLoadingState() == BitmapSource.State.LOADED) {
                    a.setWallpaperButtonEnabled(true);
                }
            }
        });
    }

    @Override
    public void onSave(WallpaperPickerActivity a) {
        boolean shouldFadeOutOnFinish = a.getWallpaperParallaxOffset() == 0f;
        a.setWallpaper(Uri.fromFile(mFile), shouldFadeOutOnFinish);
    }

    @Override
    public boolean isSelectable() {
        return true;
    }

    @Override
    public boolean isNamelessWallpaper() {
        return true;
    }
}