android系统自定义关机界面

本文介绍了如何在Android系统中自定义关机界面。通过创建自定义Dialog并设置特定样式,然后在PhoneWindowManager.java中替换全局操作对话框的显示方法,将默认的showGlobalActionsDialog()替换为自定义的showShutdownDialog(),从而实现个性化的关机界面。
摘要由CSDN通过智能技术生成

自定义的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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值