Android Systemui Source code Analysis and modification
Source: Internet
Author: User
<span id="Label3"></p><p><p></p></p><p><p><span style="font-size:24px; color:rgb(0,153,0)">1. Add the volume plus minus button in the navigation bar</span><br></p></p><p><p><span style="font-size:14px">Some Android volume adjustment buttons. Or from the point of view of the protection of the entity keys, you need to add the volume plus minus adjustment button in the navigation Bar's virtual key.</span></p></p><p><p></p></p><p><p><span style="font-size:14px">Effects such as those seen in:</span></p></p><p><p><br></p></p><p><p><span style="font-size:14px">The implementation steps are as Follows:</span></p></p><p><p><span style="font-size:14px">1. First add the volume plus minus resource file to the Systemui. The path is as Follows:</span></p></p><p><p><span style="font-size:14px">frameworks/base/packages/systemui/res/</span></p></p><p><p><span style="font-size:14px">Put the picture in the appropriate drawable directory, including volume +. and Volume--see.</span></p></p><p><p><span style="font-size:14px"><br></span></p></p><p><p><span style="font-size:14px">2. Change the layout file of the navigation bar. Path:</span></p></p><p><p><span style="font-size:14px">frameworks/base/packages/systemui/res/<br></span></p></p><p><p><span style="font-size:14px">Locate the Navigation_bar.xml file in the appropriate layout directory to make Changes:</span></p></p><p><p><span style="font-size:14px">Add "volume minus" before the return key. Return the layout of the Key:</span></p></p><p><p></p></p><pre name="code" class="html"><pre name="code" class="html"><com.android.systemui.statusbar.policy.keybuttonview android:id= "@+id/back" android:layout_width= "128dp" android:paddingstart= "25dp" android:paddingend= "25dp" android:layout_height= "match_parent" android:src= "@drawable/ic_sysbar_back" systemui:keycode= "4" android:layout_weight= "0" systemui:glowbackground= "@drawable/ic_sysbar_highlight" android:contentdescription= "@string/accessibility_back" /></pre></pre>The layout of the volume minus is as Follows. This first defines visibility as gone, and then controls whether the display is displayed in the Code:<p><p></p></p><p><p></p></p><pre name="code" class="html"><pre name="code" class="html"><com.android.systemui.statusbar.policy.keybuttonview android:id= "@+id/sub" android:src= "@drawable/sub_ Normal " android:layout_width=" @dimen/navigation_key_width " android:layout_height=" match_parent " android:layout_weight= "0" systemui:keycode= "302" systemui:glowbackground= "@drawable/ic_sysbar_ Highlight " android:visibility=" Gone "/> </pre></pre><br>"volume plus" added to "recent apps", recently applied layouts:<p><p></p></p><p><p></p></p><pre name="code" class="html"><pre name="code" class="html"><com.android.systemui.statusbar.policy.keybuttonview android:id= "@+id/recent_apps" android:layout_width= "128dp" android:paddingstart= "25dp" android:paddingend= "25dp" android:layout_height= "match_parent" android:src= "@drawable/ic_sysbar_recent" android:layout_weight= "0" systemui:glowbackground= "@drawable/ Ic_sysbar_highlight " android:contentdescription=" @string/accessibility_recent " /></pre></pre><br>The volume plus layout:<p><p></p></p><p><p></p></p><pre name="code" class="html"><pre name="code" class="html"><com.android.systemui.statusbar.policy.keybuttonview android:id= "@+id/add" android:src= "@drawable/add_ Normal " android:layout_width=" @dimen/navigation_key_width " android:layout_height=" match_parent " android:layout_weight= "0" systemui:keycode= "301" systemui:glowbackground= "@drawable/ic_sysbar_ Highlight </pre></pre><br>3. Then change the code logic, file Path:<p><p></p></p><p><p><span style="font-size:14px">Frameworks/base/packages/systemui/src/com/android/systemui/statusbar/phone/phonestatusbar.java<br></span></p></p><p><p><span style="font-size:14px">In private void Preparenavigationbarview () {...} Add code that shows the volume plus minus in the function:</span></p></p><p><p></p></p><pre name="code" class="java"><pre name="code" class="java">Mnavigationbarview.getaddvolume (). setvisibility (view.visible); Mnavigationbarview.getsubvolume (). setvisibility (view.visible);</pre></pre><br>The corresponding functions Getaddvolume () and Getaddvolume () are to be<p><p></p></p><p><p><span style="font-size:14px">Frameworks/base/packages/systemui/src/com/android/systemui/statusbar/phone/navigationbarview.java<br></span></p></p><p><p><span style="font-size:14px">Implemented In:</span></p></p><p><p></p></p><pre name="code" class="java"><pre name="code" class="java">Public View getaddvolume () { return Mcurrentview.findviewbyid (r.id.add); } Public View getsubvolume () { return Mcurrentview.findviewbyid (r.id.sub); </pre></pre><br>finally, the function is Realized. In<p><p></p></p><p><p><span style="font-size:14px">Frameworks/base/packages/systemui/src/com/android/systemui/statusbar/phone/phonestatusbar.java<br></span></p></p><p><p><span style="font-size:14px">To add the listener function:</span></p></p><p><p> </p> </p><pre name="code" class="java">Private View.ontouchlistener Maddvolumeontouchlistener = new View.ontouchlistener () {public boolean onTouch (View v, Motionevent ev) {final int action = Ev.getaction (); Switch (action) {case MotionEvent.ACTION_DOWN:is_down = true; Adjust_volume (true); maddhandler.postdelayed (maddrun, Adjust_volume_delay * 2); Break Case MotionEvent.ACTION_MOVE:is_down = true; maddhandler.postdelayed (maddrun, Adjust_volume_delay * 2); Maddhandler.removecallbacks (maddrun); Break Case MotionEvent.ACTION_UP:is_down = false; Maddhandler.removecallbacks (maddrun); Break } return true; } }; Private View.ontouchlistener Msubvolumeontouchlistener = new View.ontouchlistener () {public BooleAn onTouch (View v, motionevent ev) {final int action = Ev.getaction (); int x, y; int mcode = Ev.getaction (); Switch (action) {case MotionEvent.ACTION_DOWN:is_down = true; Adjust_volume (false); msubhandler.postdelayed (msubrun, Adjust_volume_delay * 2); Break Case MotionEvent.ACTION_MOVE:is_down = true; msubhandler.postdelayed (msubrun, Adjust_volume_delay * 2); Msubhandler.removecallbacks (msubrun); Break Case MotionEvent.ACTION_UP:is_down = false; Msubhandler.removecallbacks (msubrun); Break } return true; } }; public void Adjust_volume (boolean opition) {audiomanager audiomanager = (audiomanager) Mcontext.getsystemservice (context.audio_serviCE); If (audiomanager! = Null) {////Adjust The volume in on key down since it's more Responsive to the User. If (opition) {audiomanager.adjustsuggestedstreamvolume ( audiomanager.adjust_raise, audiomanager.use_default_stream_type, audiomanager.flag_show_ui | audiomanager.flag_remove_sound_and_vibrate); }else{audiomanager.adjustsuggestedstreamvolume (audiomanager.adjust_lo WER, audiomanager.use_default_stream_type, audiomanager.flag_show_ui | audiomanager.flag_remove_sound_and_vibrate); } } }</pre><p><p><br></p></p><p><p><br></p></p><br><p><p></p></p><p><p></p></p><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px">Reprint Please specify source: <span style="color:rgb(0,153,0)">Zhou Mushi's csdn Blog</span> Http://blog.csdn.net/zhoumushui</p></p><br><br> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: Original article, Reproduced please specify the source: Http://blog.csdn.net/zhoumushui</p></p> <p><p>Android Systemui Source code Analysis and modification</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.