需求:
客戶要求從後天獲取霸屏 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);