自定义的dialog
package com.android.internal.policy.impl;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.os.Message;
import android.os.UserHandle;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.content.Context;
import android.content.Intent;
import android.app.Dialog;
import android.os.Bundle;
import android.os.IPowerManager;
import android.os.ServiceManager;
import android.os.RemoteException;
import android.graphics.Color;
import android.graphics.Paint.Style;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RoundRectShape;
import android.text.TextUtils;
import android.view.MotionEvent;
import com.android.internal.R;
import android.view.WindowManagerPolicy.WindowManagerFuncs;
public class ShutdownDialog extends Dialog implements OnClickListener {
private View mDayIcon;
private ImageView mNightIcon;
private ImageView mTshIcon;
private ImageView mPowerIcon;
private ImageView mShDIcon;
private ImageView mLightyIcon;
private ImageView mLightsIcon;
private ImageView mLighteIcon;
private TextView mRemindTv;
private Context mContext;
private AudioManager aduioManager;
private static final String OPEN_FLIP_BRIGHT_SCREEN = "com.android.open.flipbrightscreen";
private static final String CLOSE_FLIP_BRIGHT_SCREEN = "com.android.close.flipbrightscreen";
private WindowManagerFuncs mWindowManagerFuncs;
private boolean mCancelOnUp;
private int mLastMotionY;
private Dialog mDialog = null;
private static final int CLOSE_DIALOG = 1001;
private MyHandler mHandler;
private boolean isDownPower = false;
ShutdownDialog(Context context){
this(context,R.style.shutdown_dialog);
mContext = context;
}
ShutdownDialog(Context context,WindowManagerFuncs windowManagerFuncs){
this(context,R.style.shutdown_dialog);
mContext = context;
mWindowManagerFuncs = windowManagerFuncs;
}
ShutdownDialog(Context context,int style){
super(context,style);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.shutdown_dialog);
WindowManager m = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
Display d = m.getDefaultDisplay();
LayoutParams params = getWindow().getAttributes();
params.height = (int) (d.getHeight() * 1.005);
params.width = (int) (d.getWidth() * 1.005);
this.getWindow().setAttributes(params);
mHandler = new MyHandler();
initData();
init();
}
private void initData() {
aduioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
}
private void init() {
mDayIcon = (ImageView)findViewById(R.id.normal_mode);
mDayIcon.setOnClickListener(this);
mNightIcon = (ImageView)findViewById(R.id.mute_mode);
mNightIcon.setOnClickListener(this);
mTshIcon = (ImageView)findViewById(R.id.conspire_bright_screen);
mTshIcon.setOnClickListener(this);
mPowerIcon = (ImageView)findViewById(R.id.powr_icon);
mPowerIcon.setOnClickListener(this);
mShDIcon = (ImageView)findViewById(R.id.shd_icon);
mShDIcon.setOnClickListener(this);
mLightyIcon = (ImageView)findViewById(R.id.lighty_icon);
mLightyIcon.setOnClickListener(this);
mLighteIcon = (ImageView)findViewById(R.id.lighte_icon);
mLighteIcon.setOnClickListener(this);
mLightsIcon = (ImageView)findViewById(R.id.lights_icon);
mLightsIcon.setOnClickListener(this);
mRemindTv = (TextView)findViewById(R.id.remind_tv);
refreshStatus();
}
private void refreshStatus() {
if(getModeStyle()){
mNightIcon.setBackgroundResource(R.drawable.ic_mute_mode_on);
}else {
mDayIcon.setBackgroundResource(R.drawable.ic_normal_mode_on);
}
boolean isFlipBrightScreen = (Settings.System.getInt(mContext.getContentResolver(),Settings.System.FLIP_BRIGHT_SCREEN, 0) != 0);
if (isFlipBrightScreen) {
mTshIcon.setBackgroundResource(R.drawable.ic_conspire_on);
} else {
mTsh