1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.gallery3d.ui;
18
19import android.app.Activity;
20import android.content.Context;
21import android.os.PowerManager;
22
23import com.android.gallery3d.app.AbstractGalleryActivity;
24
25public class WakeLockHoldingProgressListener implements MenuExecutor.ProgressListener {
26    static private final String DEFAULT_WAKE_LOCK_LABEL = "Gallery Progress Listener";
27    private AbstractGalleryActivity mActivity;
28    private PowerManager.WakeLock mWakeLock;
29
30    public WakeLockHoldingProgressListener(AbstractGalleryActivity galleryActivity) {
31        this(galleryActivity, DEFAULT_WAKE_LOCK_LABEL);
32    }
33
34    public WakeLockHoldingProgressListener(AbstractGalleryActivity galleryActivity, String label) {
35        mActivity = galleryActivity;
36        PowerManager pm =
37                (PowerManager) ((Activity) mActivity).getSystemService(Context.POWER_SERVICE);
38        mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, label);
39    }
40
41    @Override
42    public void onProgressComplete(int result) {
43        mWakeLock.release();
44    }
45
46    @Override
47    public void onProgressStart() {
48        mWakeLock.acquire();
49    }
50
51    protected AbstractGalleryActivity getActivity() {
52        return mActivity;
53    }
54
55    @Override
56    public void onProgressUpdate(int index) {
57    }
58
59    @Override
60    public void onConfirmDialogDismissed(boolean confirmed) {
61    }
62
63    @Override
64    public void onConfirmDialogShown() {
65    }
66}
67