赞
踩
需求:
客户要求从后天获取霸屏 app list,在打开apk的时候,apk要进入霸屏模式,即隐藏虚拟按键和状态栏,下拉状态栏。 并且在3s内连续点击屏幕8下弹出退出霸屏模式选择界面。
分析:
其实解决方法也很简单,刚开始做的是隐藏虚拟按键和状态栏;但是这样apk不能全屏显示,所以还是需要动态控制状态栏和导航栏的height;
修改的代码比较多,只简单说下关键的地方
代码分析:
1、PhoneWindowManager.java 主要是获取屏幕点击操作,计算点击次数
frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
public void onDown() {
+ System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
+ mHits[mHits.length - 1] = SystemClock.uptimeMillis();
+ if (mHits[0] >= (SystemClock.uptimeMillis() - DURATIONS)) {
+ mHits = new long[5];//重新初始化数组
+ SystemProperties.set("persist.neo.isbaping","false");
+ Settings.System.putInt(mContext.getContentResolver(), PHONE_STATUS_
+ }
}
2、需要从后台获取 霸屏模式 的app 列表;这个需要和后台对接;将设备SN传给后台,等待返回的数据,中间会有网络延迟,需要做下处理。获取到的数据存储在SharedPreferences。
public static int getInstallAuthority() { try { String sn = android.os.Build.SERIAL; Log.i("InstallController---SN", sn); JSONObject body = new JSONObject(); body.put("sn", sn); URL url = new URL(urlPath); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5000); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); DataOutputStream os = new DataOutputStream(conn.getOutputStream()); String content = String.valueOf(body); os.writeBytes(content); os.flush(); os.close(); int responseCode = conn.getResponseCode(); Log.i("InstallController", String.valueOf(responseCode)); if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { InputStreamReader in = new InputStreamReader(conn.getInputStream()); BufferedReader bf = new BufferedReader(in); String inputLine; StringBuilder response = new StringBuilder(); while ((inputLine = bf.readLine()) != null) { response.append(inputLine); } applist = response.toString(); JSONObject jsonResponse = new JSONObject(response.toString()); JSONObject dataJsonObject = jsonResponse.getJSONObject("data"); int installAuthority = dataJsonObject.getInt("installAuthority"); Log.i("InstallController", "installAuthority --" + installAuthority); in.close(); conn.disconnect(); return installAuthority; } } catch (Exception e) { Log.e("InstallController", "InstallController --Exception--" + e.toString()); } return NOT_GET_NET_AUTHORITY; }
3、动态隐藏导航栏状态栏的高度,这个比较简单
frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
status_bar_height
navigation_bar_height
navigation_bar_height_landscape
navigation_bar_width
另外如果要单独只是动态隐藏导航栏,状态栏。需要另外操作,不详细列举。
二 双指触摸退出霸屏模式
主要是在getPointerCount() 中加逻辑判断
frameworks/base/core/java/android/view/MotionEvent.java public final int getPointerCount() { + + + if("true".equals(SystemProperties.get("persist.neo.isbaping")) + && nativeGetPointerCount(mNativePtr) == 2 + && "true".equals(SystemProperties.get("persist.neo.pointerCount")) + && "false".equals(SystemProperties.get("persist.neo.openBaping"))){ + System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1); + mHits[mHits.length - 1] = SystemClock.uptimeMillis(); + SystemProperties.set("persist.neo.pointerCount","false"); + Log.e("lyl","mHits[mHits.length - 1]" +mHits[mHits.length - 1]); + Log.e("lyl"," mHits[0] " +mHits[0]+ " " + SystemClock.uptimeMillis() ); + if (mHits[0] >= (SystemClock.uptimeMillis() - DURATIONS)) { + //if (SystemClock.uptimeMillis() - mHits[0] <= DURATIONS) { + Log.e("lyl","getPointerCount33333" ); + mHits = new long[7]; + SystemProperties.set("persist.neo.openBaping","true"); + + } + } return nativeGetPointerCount(mNativePtr);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。