TakeScreenshotService.java revision fc8fa638617efb5695a1f89ea75375faebbe2a40
1/*
2 * Copyright (C) 2011 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.systemui.screenshot;
18
19import android.app.Service;
20import android.app.AlertDialog;
21import android.content.ActivityNotFoundException;
22import android.content.Context;
23import android.content.DialogInterface;
24import android.content.Intent;
25import android.net.Uri;
26import android.hardware.usb.UsbAccessory;
27import android.hardware.usb.UsbManager;
28import android.os.Bundle;
29import android.os.Handler;
30import android.os.IBinder;
31import android.os.Message;
32import android.os.Messenger;
33import android.os.RemoteException;
34import android.util.Log;
35
36import com.android.internal.app.AlertActivity;
37import com.android.internal.app.AlertController;
38
39import com.android.systemui.R;
40
41public class TakeScreenshotService extends Service {
42    private static final String TAG = "TakeScreenshotService";
43
44    private static GlobalScreenshot mScreenshot;
45
46    private Handler mHandler = new Handler() {
47        @Override
48        public void handleMessage(Message msg) {
49            switch (msg.what) {
50                case 1:
51                    final Messenger callback = msg.replyTo;
52                    if (mScreenshot == null) {
53                        mScreenshot = new GlobalScreenshot(TakeScreenshotService.this);
54                    }
55                    mScreenshot.takeScreenshot(new Runnable() {
56                        @Override public void run() {
57                            Message reply = Message.obtain(null, 1);
58                            try {
59                                callback.send(reply);
60                            } catch (RemoteException e) {
61                            }
62                        }
63                    });
64            }
65        }
66    };
67
68    @Override
69    public IBinder onBind(Intent intent) {
70        return new Messenger(mHandler).getBinder();
71    }
72}
73