package com.edufound.mobile.xxt.util; import android.app.Activity; import android.app.Dialog; import android.graphics.Color; import android.os.Handler; import android.os.Handler.Callback; import android.os.Message; import android.view.Display; import android.view.Gravity; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.TextView; import com.edufound.mobile.xxt.R; public final class ShowDevice implements Callback { private static final int MSG_SHOW_EFKEY = Integer.MIN_VALUE; private Handler mHandlerUi = new Handler(this); private Handler mHandlerBackground = new Handler(this); private static final int[] EFKEY = {KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_RIGHT, KeyEvent.KEYCODE_DPAD_DOWN, KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_RIGHT, KeyEvent.KEYCODE_DPAD_DOWN, KeyEvent.KEYCODE_DPAD_LEFT}; private static final int EFKEY_LENGTH = EFKEY.length; private static final long INPUT_INTERVAL = 10 * 1000L; private long mLastInputTime; private int mIndex; private static Activity mContext; private DeviceUtil dUtil = new DeviceUtil(); private void input(int keyCode) { if (System.currentTimeMillis() - mLastInputTime > INPUT_INTERVAL) { mIndex = 0; } if (mIndex >= EFKEY_LENGTH || mIndex < 0) { mIndex = 0; } if (EFKEY[mIndex] == keyCode) { mLastInputTime = System.currentTimeMillis(); mIndex++; if (mIndex == EFKEY_LENGTH) { mHandlerUi.sendEmptyMessage(MSG_SHOW_EFKEY); } } else { mLastInputTime = System.currentTimeMillis(); mIndex = 0; } } public void show(Activity act) { mContext = act; Logger.e("show EfKey Dialog"); StringBuffer buffer = new StringBuffer(); buffer.append("\n\tSerialNumber:\t" + "\t" + dUtil.SerialNumber() + "\n"); buffer.append("\t自定义SerialNumber:\t" + "\t" + dUtil.getSerial() + "\n"); buffer.append("\tUUID:\t" + "\t" + DeviceUuidFactory.getUuid() + "\n"); buffer.append("\t厂商:\t" + "\t" + dUtil.getDeviceBrand() + "\n"); buffer.append("\t型号:\t" + "\t" + dUtil.getSystemModel() + "\n"); buffer.append("\t系统版本号:\t" + "\t" + dUtil.getSystemVersion() + "\n"); buffer.append("\t应用版本号:\t" + "\t" + dUtil.getVersionCode(mContext) + "\n"); buffer.append("\t应用版本号名称:\t" + "\t" + dUtil.getVersionName(mContext) + "\n"); buffer.append("\t屏幕宽度:\t\t" + dUtil.getWidth(mContext) + "\n"); buffer.append("\t屏幕高度:\t\t" + dUtil.getHeight(mContext) + "\n"); buffer.append("\t屏幕密度:\t\t" + dUtil.getDensity(mContext) + "\n"); buffer.append("\t屏幕DPI:\t\t" + dUtil.getDensityDpi(mContext) + "\n"); String playerName = ""; switch (SPutil.getPrefInt(mContext, SPutil.videoType, 0)) { case SPutil.VIDEO_IJKPLAYER: playerName = "IJKPlayer播放器"; break; case SPutil.VIDEO_VIDEOVIEW: playerName = "默认VideoView播放器"; break; } buffer.append("\t播放器类型:\t\t" + playerName + "\n"); String message = buffer.toString(); Dialog dialog = new Dialog(mContext); dialog.setContentView(createView(message)); Window dialogWindow = dialog.getWindow(); dialogWindow.setGravity(Gravity.CENTER); WindowManager m = mContext.getWindowManager(); Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用 WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值 p.height = (int) (d.getHeight() * 0.6); p.width = (int) (d.getWidth() * 0.8); dialogWindow.setAttributes(p); dialog.setTitle("Device信息"); dialog.show(); } private View createView(String message) { View infoView = LayoutInflater.from(mContext).inflate(R.layout.window_deviceinfo, null); TextView text = (TextView) infoView.findViewById(R.id.deviceinfo); text.setText(message); text.setTextSize(20); text.setTextColor(Color.RED); return infoView; } private static final ShowDevice INSTANCE = new ShowDevice(); public static void dispatchKeyEvent(KeyEvent e, Activity context) { try { mContext = context; getInstance().dispathInput(e); } catch (final Exception ex) { ex.printStackTrace(); } } public static ShowDevice getInstance() { return INSTANCE; } private void dispathInput(final KeyEvent e) { mHandlerBackground.sendEmptyMessage(e.getKeyCode()); } @Override public boolean handleMessage(Message msg) { try { switch (msg.what) { case MSG_SHOW_EFKEY: // show(); break; default: input(msg.what); break; } } catch (final Exception ex) { ex.printStackTrace(); } return true; } }