2 * Copyright (C) 2006 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings;
19 import android.app.Activity;
20 import android.app.ActivityManager;
21 import android.app.AlertDialog;
22 import android.app.Dialog;
23 import android.util.Slog;
24 import android.content.BroadcastReceiver;
25 import android.content.DialogInterface;
26 import android.content.Intent;
27 import android.content.IntentFilter;
28 import android.os.Build;
29 import android.os.Bundle;
30 import android.preference.Preference;
31 import android.preference.PreferenceGroup;
32 import android.preference.PreferenceScreen;
33 import android.provider.Settings;
34 import android.util.Log;
35 import android.view.WindowManager;
36 import android.content.Context;
38 import java.io.BufferedReader;
39 import java.io.FileReader;
40 import java.io.IOException;
41 import java.util.List;
42 import android.os.Handler;
44 public class PowerOff extends SettingsPreferenceFragment{
45 private Context mContext;
46 public void onCreate(Bundle icicle) {
47 super.onCreate(icicle);
49 public void onStart() {
54 public void beginshutdown()
56 final CloseDialogReceiver closer = new CloseDialogReceiver(getActivity());
57 final AlertDialog dialog = new AlertDialog.Builder(getActivity())
58 .setIconAttribute(android.R.attr.alertDialogIcon)
59 .setTitle(com.android.internal.R.string.power_off)
60 .setMessage(com.android.internal.R.string.shutdown_confirm_question)
61 .setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {
62 public void onClick(DialogInterface dialog, int which) {
63 Intent shutdown = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
64 shutdown.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
65 shutdown.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
66 startActivity(shutdown);
69 .setNegativeButton(com.android.internal.R.string.no, new DialogInterface.OnClickListener() {
70 public void onClick(DialogInterface dialog, int which) {
71 Intent close = new Intent(Intent.ACTION_MAIN);
72 close.addCategory(Intent.CATEGORY_HOME);
73 close.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
79 closer.dialog = dialog;
80 dialog.setOnDismissListener(closer);
81 dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
82 if (!getActivity().getResources().getBoolean(
83 com.android.internal.R.bool.config_sf_slowBlur)) {
84 dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
89 private static class CloseDialogReceiver extends BroadcastReceiver
90 implements DialogInterface.OnDismissListener {
91 private Context mContext;
94 CloseDialogReceiver(Context context) {
96 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
97 context.registerReceiver(this, filter);
101 public void onReceive(Context context, Intent intent) {
105 public void onDismiss(DialogInterface unused) {
106 mContext.unregisterReceiver(this);
109 public void onResume() {
112 public void onPause() {
115 public void onStop() {
118 public void onDestroy() {