編輯:關於Android編程
有些手機比如泛泰A820L, 泛泰A890 A900 以及Nubia Z5S 和Z5S mini具有實體按鍵(這裡所說的實體按鍵是相對於虛擬按鍵而言, 包含物理按鍵和觸摸屏上多出來的觸摸實體按鍵), 當編譯第三方ROM比如CM或者Mokee或者Omni時就會發現如果不做修改的話默認觸摸實體按鍵時是沒有振動支持的, 甚至有些patchrom的MIUI或者ColorOS等系統也可能不支持. 不知道是CM代碼的問題還是編譯的Config沒寫完全造成的, 後來經過本人修改後是可以支持按鍵振動, 不過只能作為臨時解決方案參考.
轉帖請注明出處和網址來源:
http://blog.csdn.net/syhost/article/details/32067695
java版本代碼
在本人提交的cm的review上, 沒有被通過,因為如果加進來不修改的話,會影響虛擬鍵的振動,會導致home鍵振動兩次, 不過只是作為支持實體按鍵振動的話還是可以的:
http://review.cyanogenmod.org/#/c/55274/1/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
修改的位置為android.policy.jar的源碼裡 frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index f0719e3..ca38166 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -2333,6 +2333,22 @@ public class PhoneWindowManager implements WindowManagerPolicy { WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, }; + + private void setKeyVib(WindowState win) { + WindowManager.LayoutParams attrs; + Intent service; + ContentResolver res; + + // If a system window has focus, then it doesn't make sense + // right now to interact with applications. + attrs = win != null ? win.getAttrs() : null; + service = new Intent(); + res = mContext.getContentResolver(); + if(1 == Settings.System.getInt(res, Settings.System.HAPTIC_FEEDBACK_ENABLED,0))//when setting feedback enable + { + performHapticFeedbackLw(null, HapticFeedbackConstants.KEYBOARD_TAP, true); //啟動震動 by syhost + } + } /** {@inheritDoc} */ @Override @@ -2441,7 +2457,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { ViewConfiguration.getDoubleTapTimeout()); return -1; } - + + setKeyVib(win); // Go home! launchHomeFromHotKey(); return -1; @@ -2514,6 +2531,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { } if (repeatCount == 0) { mMenuPressed = true; + setKeyVib(win); if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { Intent intent = new Intent(Intent.ACTION_BUG_REPORT); mContext.sendOrderedBroadcast(intent, null); @@ -2645,9 +2663,13 @@ public class PhoneWindowManager implements WindowManagerPolicy { } return -1; } else if (keyCode == KeyEvent.KEYCODE_BACK) { + if (down && repeatCount == 0) { + setKeyVib(win); + } if (Settings.Secure.getIntForUser(mContext.getContentResolver(), Settings.Secure.KILL_APP_LONGPRESS_BACK, 0, UserHandle.USER_CURRENT) == 1) { if (down && repeatCount == 0) { + setKeyVib(win); mHandler.postDelayed(mBackLongPress, mBackKillTimeout); } }
對應的smali版本,
在本人之前適配的泛泰A820L的cm10版本的樂蛙ROM裡可以找到, 是分幾次完成的:
patch1:
https://github.com/syhost/lewa_patchrom_ef65l/commit/18afafa2c7b770bdb593fee086c7cc07f8789e58
goto :goto_0 .end method +.method private setKeyVib(Landroid/view/WindowManagerPolicy$WindowState;)V + .locals 7 + .parameter "win" + + .prologue + const/4 v3, 0x0 + + const/4 v6, 0x1 + + .line 2110 + if-eqz p1, :cond_1 + + invoke-interface {p1}, Landroid/view/WindowManagerPolicy$WindowState;->getAttrs()Landroid/view/WindowManager$LayoutParams; + + move-result-object v0 + + .line 2111 + .local v0, attrs:Landroid/view/WindowManager$LayoutParams; + :goto_0 + new-instance v2, Landroid/content/Intent; + + invoke-direct {v2}, Landroid/content/Intent;->()V + + .line 2112 + .local v2, service:Landroid/content/Intent; + iget-object v4, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mContext:Landroid/content/Context; + + invoke-virtual {v4}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver; + + move-result-object v1 + + .line 2113 + .local v1, res:Landroid/content/ContentResolver; + const-string v4, "haptic_feedback_enabled" + + const/4 v5, 0x0 + + invoke-static {v1, v4, v5}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I + + move-result v4 + + if-ne v6, v4, :cond_0 + + .line 2115 + const/4 v4, 0x3 + + invoke-virtual {p0, v3, v4, v6}, Lcom/android/internal/policy/impl/PhoneWindowManager;->performHapticFeedbackLw(Landroid/view/WindowManagerPolicy$WindowState;IZ)Z + + .line 2117 + :cond_0 + return-void + + .end local v0 #attrs:Landroid/view/WindowManager$LayoutParams; + .end local v1 #res:Landroid/content/ContentResolver; + .end local v2 #service:Landroid/content/Intent; + :cond_1 + move-object v0, v3 + + .line 2110 + goto :goto_0 +.end method + .method private takeScreenshot()V .locals 8 @@ -8384,6 +8446,7 @@ .line 1799 .end local v11 #ex:Landroid/os/RemoteException; :cond_6 + invoke-direct/range {p0 .. p1}, Lcom/android/internal/policy/impl/PhoneWindowManager;->setKeyVib(Landroid/view/WindowManagerPolicy$WindowState;)V invoke-virtual/range {p0 .. p0}, Lcom/android/internal/policy/impl/PhoneWindowManager;->launchHomeFromHotKey()V goto :goto_4 @@ -8631,6 +8694,8 @@ if-nez v23, :cond_1c + invoke-direct/range {p0 .. p1}, Lcom/android/internal/policy/impl/PhoneWindowManager;->setKeyVib(Landroid/view/WindowManagerPolicy$WindowState;)V + .line 1853 move-object/from16 v0, p0
patch2:
https://github.com/syhost/lewa_patchrom_ef65l/commit/0e5ff497456e9428546be24bae36dfcf4544863f
move/from16 v1, v32 - if-ne v0, v1, :cond_1c + if-ne v0, v1, :cond_34 .line 1894 if-eqz v9, :cond_1a @@ -8887,7 +8887,25 @@ const-wide/16 v32, -0x1 goto/16 :goto_1 + + :cond_34 + const/16 v32, 0x4 + + move/from16 v0, v18 + + move/from16 v1, v32 + + if-ne v0, v1, :cond_1c + + if-eqz v9, :cond_1c + if-nez v23, :cond_1c + + invoke-direct/range {p0 .. p1}, Lcom/android/internal/policy/impl/PhoneWindowManager;->setKeyVib(Landroid/view/WindowManagerPolicy$WindowState;)V + + goto/16 :goto_34 + + .line 1897 :cond_19 const/16 v32, 0x1 @@ -8946,6 +8964,7 @@ goto :goto_9 .line 1920 + :goto_34 :cond_1c move-object/from16 v0, p0
上面的patch2主要是加了防止長按home鍵長振, 對應的java部分是:
+ if (down && repeatCount == 0) { + setKeyVib(win); + }
本文為大家分享了Android實現拖動選擇按鈕的具體代碼,供大家參考,具體內容如下效果圖View代碼第一步:自定義屬性 <declare-styleable nam
和大家一起分享一下學習經驗,如何實現Android文件下載進度顯示功能,希望對廣大初學者有幫助。先上效果圖: 上方的藍色進度條,會根據文件下載量的百分比進行加載,中部的
對我來說,寫自定義view是一個特麻煩但是寫完之後特有成就感的過程。寫完之後我總是喜歡拿給別人看,去炫耀(當然只是在自己熟悉和關系不錯的人群裡),盡管它們看起來會很簡陋。
什麼是View?實現View滑動的方式有哪些?1. 關於View我們需要知道的(1)什麼是View? Android中的View類是所