android 隐藏statusbar

1:修改frameworks/base/packages/SystemUI/src/com/Android/systemui/SystemUIService.Java

      import android.content.IntentFilter;      

  1. @Override  
  2.     public void onCreate() {  
  3.         // Pick status bar or system bar.  
  4.         IWindowManager wm = IWindowManager.Stub.asInterface(  
  5.                 ServiceManager.getService(Context.WINDOW_SERVICE));  
  6.         try {  
  7.             SERVICES[0] = wm.canStatusBarHide()  
  8.                     ? R.string.config_statusBarComponent  
  9.                     : R.string.config_systemBarComponent;  
  10.         } catch (RemoteException e) {  
  11.             Slog.w(TAG, "Failing checking whether status bar can hide", e);  
  12.         }  
  13.   
  14.         final int N = SERVICES.length;  
  15.         mServices = new SystemUI[N];  
  16.         for (int i=0; i<N; i++) {  
  17.             Class cl = chooseClass(SERVICES[i]);  
  18.             Slog.d(TAG, "loading: " + cl);  
  19.             try {  
  20.                 mServices[i] = (SystemUI)cl.newInstance();  
  21.             } catch (IllegalAccessException ex) {  
  22.                 throw new RuntimeException(ex);  
  23.             } catch (InstantiationException ex) {  
  24.                 throw new RuntimeException(ex);  
  25.             }  
  26.             mServices[i].mContext = this;  
  27.             Slog.d(TAG, "running: " + mServices[i]);  
  28.             mServices[i].start();  
  29.         }  
  30.         //add by xiaoge  
  31.         IntentFilter intentFilter = new IntentFilter();  
  32.         intentFilter.addAction(Intent.ACTION_DISPLAY_STATUS_BAR);  
  33.         intentFilter.addAction(Intent.ACTION_HIDE_STATUS_BAR);  
  34.         registerReceiver(mStatusBarReceiver, intentFilter);  
  35.     }  
  36.     //add by xiaoge  
  37.     BroadcastReceiver mStatusBarReceiver = new BroadcastReceiver() {  
  38.         @Override  
  39.         public void onReceive(Context context, Intent intent) {  
  40.             if (intent != null) {  
  41.                 String action = intent.getAction();  
  42.   
  43.                 final int N = SERVICES.length;  
  44.                 for (int i = 0; i < N; i++) {  
  45.                     Slog.d(TAG, "invoke: " + mServices[i] + "'s onReceive()");  
  46.                     mServices[i].onReceive(action);  
  47.                 }  
  48.             }  
  49.         }  
  50.     };  

2:修改frameworks/base/core/java/android/content/Intent.java
  1. //add by xiaoge  
  2.     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)  
  3.     public static final String ACTION_DISPLAY_STATUS_BAR = "android.intent.action.DISPLAY_STATUS_BAR";  
  4.   
  5.     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)  
  6.     public static final String ACTION_HIDE_STATUS_BAR = "android.intent.action.HIDE_STATUS_BAR";  
  7.     //add ends  

3:修改frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/StatusBar.java

  1. /* 
  2.  * Copyright (C) 2010 The Android Open Source Project 
  3.  * 
  4.  * Licensed under the Apache License, Version 2.0 (the "License"); 
  5.  * you may not use this file except in compliance with the License. 
  6.  * You may obtain a copy of the License at 
  7.  * 
  8.  *      http://www.apache.org/licenses/LICENSE-2.0 
  9.  * 
  10.  * Unless required by applicable law or agreed to in writing, software 
  11.  * distributed under the License is distributed on an "AS IS" BASIS, 
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  13.  * See the License for the specific language governing permissions and 
  14.  * limitations under the License. 
  15.  */  
  16.   
  17. package com.android.systemui.statusbar;  
  18.   
  19. import com.android.systemui.statusbar.SeviceSocket;  
  20. import android.content.ComponentName;  
  21. import android.app.Notification;  
  22. import android.app.NotificationManager;  
  23. import android.app.PendingIntent;  
  24. import java.io.File;  
  25. import java.io.FileReader;  
  26. import java.util.Timer;  
  27. import java.util.TimerTask;  
  28. import android.os.Handler;  
  29. import android.os.Message;  
  30. import android.os.ServiceManager;  
  31. import android.app.Notification;  
  32. import android.app.PendingIntent;  
  33.   
  34. import android.app.ActivityManager;  
  35. import android.app.Service;  
  36. import android.content.Context;  
  37. import android.content.Intent;  
  38. import android.content.res.Resources;  
  39. import android.graphics.PixelFormat;  
  40. import android.os.IBinder;  
  41. import android.os.RemoteException;  
  42. import android.os.ServiceManager;  
  43. import android.util.Slog;  
  44. import android.util.Log;  
  45. import android.view.Display;  
  46. import android.view.Gravity;  
  47. import android.view.View;  
  48. import android.view.ViewGroup;  
  49. import android.view.WindowManager;  
  50. import android.view.WindowManagerImpl;  
  51.   
  52. import java.util.ArrayList;  
  53.   
  54. import com.android.internal.statusbar.IStatusBarService;  
  55. import com.android.internal.statusbar.StatusBarIcon;  
  56. import com.android.internal.statusbar.StatusBarIconList;  
  57. import com.android.internal.statusbar.StatusBarNotification;  
  58.   
  59. import com.android.systemui.SystemUI;  
  60. import com.android.systemui.R;  
  61.   
  62. public abstract class StatusBar extends SystemUI implements CommandQueue.Callbacks {  
  63.     static final String TAG = "StatusBar";  
  64.     private static final boolean SPEW = false;  
  65.     //add by xiaoge  
  66.     private View mStatusBarView;  
  67.     private int mStatusBarHeight;  
  68.     private WindowManager.LayoutParams mStatusBarLayoutParams;  
  69.   
  70.     protected CommandQueue mCommandQueue;  
  71.     protected IStatusBarService mBarService;  
  72.   
  73.     //F/r/i/e/n/d/l/y/A/R/M  
  74.     private static SeviceSocket seviceSocket = null;  
  75.     private NotificationManager myNotiManager;  
  76.   
  77.     // Up-call methods  
  78.     protected abstract View makeStatusBarView();  
  79.     protected abstract int getStatusBarGravity();  
  80.     public abstract int getStatusBarHeight();  
  81.     public abstract void animateCollapse();  
  82.   
  83.     private DoNotDisturb mDoNotDisturb;  
  84.   
  85.    
  86.     //{{F-r-i-e-n-d-l-y-A-R-M  
  87.     private void setStatusIcon(int iconId, String text) {  
  88.         Intent notifyIntent=new Intent();  
  89.         notifyIntent.setComponent(new ComponentName("com.friendlyarm.net3gdialup""com.friendlyarm.net3gdialup.ActivityMain"));  
  90.         notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  91.         PendingIntent appIntent = PendingIntent.getActivity(mContext, 0,  
  92.             notifyIntent, 0);  
  93.         Notification myNoti = new Notification();  
  94.         myNoti.icon = iconId;  
  95.         myNoti.tickerText = text;  
  96.         myNoti.defaults = Notification.DEFAULT_LIGHTS;  
  97.         myNoti.setLatestEventInfo(mContext, "3G Network Status",text, appIntent);  
  98.         myNotiManager.notify(0, myNoti);  
  99.     }  
  100.   
  101.     private void removeStatusIcon() {  
  102.         myNotiManager.cancelAll();  
  103.     }  
  104.   
  105.     private int lastNetworkStatus = -1;  
  106.     private boolean isConnectService = false;  
  107.   
  108.     private final int CONNECT_TO_SERVICE_MSG = 100;  
  109.     private final int REQUEST_NETSTATUS_MSG = 101;  
  110.   
  111.     private Timer timerToConnService = new Timer();  
  112.     private Timer timerToRequestStatus = new Timer();  
  113.   
  114.     private Handler handler = new Handler() {  
  115.         public void handleMessage(Message msg) {  
  116.             switch (msg.what) {  
  117.             case CONNECT_TO_SERVICE_MSG:  
  118.                 timerToConnService.cancel();  
  119.                 seviceSocket.connectToService();  
  120.                 break;  
  121.             case REQUEST_NETSTATUS_MSG:  
  122.                 seviceSocket.sendRequest("REQUEST NETSTATUS\n");  
  123.                 seviceSocket.recvResponse();  
  124.                 break;  
  125.             }  
  126.             super.handleMessage(msg);  
  127.         }  
  128.     };  
  129.   
  130.     private TimerTask taskConnectService = new TimerTask() {  
  131.         public void run() {  
  132.             Message message = new Message();  
  133.             message.what = CONNECT_TO_SERVICE_MSG;  
  134.             handler.sendMessage(message);  
  135.         }  
  136.     };  
  137.   
  138.     private TimerTask taskRequestNetStatus = new TimerTask() {  
  139.         public void run() {  
  140.             Message message = new Message();  
  141.             message.what = REQUEST_NETSTATUS_MSG;  
  142.             handler.sendMessage(message);  
  143.         }  
  144.     };  
  145.   
  146.     private void processNETStatusResponse(String response) {  
  147.         String[] results = response.split(" ");  
  148.   
  149.         if (response.startsWith("RESPONSE CONNECT OK")) {  
  150.              seviceSocket.sendRequest("REQUEST 3GAUTOCONNECT GETSTATUS");  
  151.              seviceSocket.recvResponse();  
  152.         } else if (response.startsWith(new String("RESPONSE 3GAUTOCONNECT")) && results.length == 6) {  
  153.             if (Integer.parseInt(results[2]) == 1 && results[3].startsWith(new String("3GNET"))) {  
  154.                 timerToRequestStatus.schedule(taskRequestNetStatus,1,3000);  
  155.             } else {  
  156.                 seviceSocket.disconnect();  
  157.             }  
  158.         } else if (response.startsWith(new String("RESPONSE NETSTATUS"))  
  159.             && results.length >= 5) {  
  160.             if (results[2].startsWith(new String("DOWN"))) {  
  161.                 if (lastNetworkStatus != 0) {  
  162.                     removeStatusIcon();  
  163.                 }  
  164.                 lastNetworkStatus = 0;  
  165.             } else if (results[2].startsWith(new String("UP"))  
  166.                 && results.length == 8) {  
  167.                 if (lastNetworkStatus != 1) {  
  168.                     setStatusIcon(com.android.internal.R.drawable.net3g, "Connected. (FriendlyARM-3G)");  
  169.                 }  
  170.                 lastNetworkStatus = 1;  
  171.             }  
  172.         }  
  173.     }  
  174.     //}}  
  175.   
  176.   
  177.   
  178.    public void start() {  
  179.         // First set up our views and stuff.  
  180.   
  181.   
  182.        View sb = makeStatusBarView();  
  183.   
  184.         //F/r/i/e/n/d/l/y/A/R/M  
  185.         myNotiManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);  
  186.         seviceSocket = new SeviceSocket(new SeviceSocket.RecvCallBack() {  
  187.             public void responseIncoming(String response) {  
  188.             processNETStatusResponse(response);  
  189.             }  
  190.             });  
  191.   
  192.   
  193.         // Connect in to the status bar manager service  
  194.         StatusBarIconList iconList = new StatusBarIconList();  
  195.         ArrayList<IBinder> notificationKeys = new ArrayList<IBinder>();  
  196.         ArrayList<StatusBarNotification> notifications = new ArrayList<StatusBarNotification>();  
  197.         mCommandQueue = new CommandQueue(this, iconList);  
  198.         mBarService = IStatusBarService.Stub.asInterface(  
  199.                 ServiceManager.getService(Context.STATUS_BAR_SERVICE));  
  200.         int[] switches = new int[7];  
  201.         ArrayList<IBinder> binders = new ArrayList<IBinder>();  
  202.         try {  
  203.             mBarService.registerStatusBar(mCommandQueue, iconList, notificationKeys, notifications,  
  204.                     switches, binders);  
  205.         } catch (RemoteException ex) {  
  206.             // If the system process isn't there we're doomed anyway.  
  207.         }  
  208.   
  209.         disable(switches[0]);  
  210.         setSystemUiVisibility(switches[1]);  
  211.         topAppWindowChanged(switches[2] != 0);  
  212.         // StatusBarManagerService has a back up of IME token and it's restored here.  
  213.         setImeWindowStatus(binders.get(0), switches[3], switches[4]);  
  214.         setHardKeyboardStatus(switches[5] != 0, switches[6] != 0);  
  215.   
  216.         // Set up the initial icon state  
  217.         int N = iconList.size();  
  218.         int viewIndex = 0;  
  219.         for (int i=0; i<N; i++) {  
  220.             StatusBarIcon icon = iconList.getIcon(i);  
  221.             if (icon != null) {  
  222.                 addIcon(iconList.getSlot(i), i, viewIndex, icon);  
  223.                 viewIndex++;  
  224.             }  
  225.         }  
  226.   
  227.         // Set up the initial notification state  
  228.         N = notificationKeys.size();  
  229.         if (N == notifications.size()) {  
  230.             for (int i=0; i<N; i++) {  
  231.                 addNotification(notificationKeys.get(i), notifications.get(i));  
  232.             }  
  233.         } else {  
  234.             Log.wtf(TAG, "Notification list length mismatch: keys=" + N  
  235.                     + " notifications=" + notifications.size());  
  236.         }  
  237.   
  238.         // Put up the view  
  239.         final int height = getStatusBarHeight();  
  240.         mStatusBarHeight = height;//add by xiaoge  
  241.         final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(  
  242.                 ViewGroup.LayoutParams.MATCH_PARENT,  
  243.                 height,  
  244.                 WindowManager.LayoutParams.TYPE_STATUS_BAR,  
  245.                 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE  
  246.                     | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING  
  247.                     | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,  
  248.                 // We use a pixel format of RGB565 for the status bar to save memory bandwidth and  
  249.                 // to ensure that the layer can be handled by HWComposer.  On some devices the  
  250.                 // HWComposer is unable to handle SW-rendered RGBX_8888 layers.  
  251.                 PixelFormat.RGB_565);  
  252.           
  253.         // the status bar should be in an overlay if possible  
  254.         final Display defaultDisplay   
  255.             = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))  
  256.                 .getDefaultDisplay();  
  257.   
  258.         // We explicitly leave FLAG_HARDWARE_ACCELERATED out of the flags.  The status bar occupies  
  259.         // very little screen real-estate and is updated fairly frequently.  By using CPU rendering  
  260.         // for the status bar, we prevent the GPU from having to wake up just to do these small  
  261.         // updates, which should help keep power consumption down.  
  262.   
  263.         lp.gravity = getStatusBarGravity();  
  264.         lp.setTitle("StatusBar");  
  265.         lp.packageName = mContext.getPackageName();  
  266.         lp.windowAnimations = R.style.Animation_StatusBar;  
  267.         //add by xiaoge  
  268.         mStatusBarLayoutParams = lp;  
  269.         mStatusBarView = sb;  
  270.   
  271.         WindowManagerImpl.getDefault().addView(sb, lp);  
  272.   
  273.         if (SPEW) {  
  274.             Slog.d(TAG, "Added status bar view: gravity=0x" + Integer.toHexString(lp.gravity)   
  275.                    + " icons=" + iconList.size()  
  276.                    + " disabled=0x" + Integer.toHexString(switches[0])  
  277.                    + " lights=" + switches[1]  
  278.                    + " menu=" + switches[2]  
  279.                    + " imeButton=" + switches[3]  
  280.                    );  
  281.         }  
  282.   
  283.         mDoNotDisturb = new DoNotDisturb(mContext);  
  284.     }  
  285.   
  286.     protected View updateNotificationVetoButton(View row, StatusBarNotification n) {  
  287.         View vetoButton = row.findViewById(R.id.veto);  
  288.         if (n.isClearable()) {  
  289.             final String _pkg = n.pkg;  
  290.             final String _tag = n.tag;  
  291.             final int _id = n.id;  
  292.             vetoButton.setOnClickListener(new View.OnClickListener() {  
  293.                     public void onClick(View v) {  
  294.                         try {  
  295.                             mBarService.onNotificationClear(_pkg, _tag, _id);  
  296.                         } catch (RemoteException ex) {  
  297.                             // system process is dead if we're here.  
  298.                         }  
  299.                     }  
  300.                 });  
  301.             vetoButton.setVisibility(View.VISIBLE);  
  302.         } else {  
  303.             vetoButton.setVisibility(View.GONE);  
  304.         }  
  305.         return vetoButton;  
  306.     }  
  307.     //add by xiaoge  
  308.     public void onReceive(String action) {  
  309.         Log.d(TAG, "*** onReceive(), action = " + action + " ***");  
  310.         if (Intent.ACTION_DISPLAY_STATUS_BAR.equals(action)) {  
  311.                 mStatusBarLayoutParams.height = mStatusBarHeight;  
  312.                 WindowManagerImpl.getDefault().updateViewLayout(mStatusBarView,  
  313.                                 mStatusBarLayoutParams);  
  314.         } else if (Intent.ACTION_HIDE_STATUS_BAR.equals(action)) {  
  315.                 mStatusBarLayoutParams.height = 0;  
  316.                 WindowManagerImpl.getDefault().updateViewLayout(mStatusBarView,  
  317.                                 mStatusBarLayoutParams);  
  318.         }  
  319.     }  
  320. }  

4:修改frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUI.java
  1. package com.android.systemui;  
  2.   
  3. import java.io.FileDescriptor;  
  4. import java.io.PrintWriter;  
  5.   
  6. import android.content.Context;  
  7. import android.content.res.Configuration;  
  8.   
  9. public abstract class SystemUI {  
  10.     public Context mContext;  
  11.   
  12.     public abstract void start();  
  13.     public abstract void onReceive(String action);//add by xiaoge  
  14.     protected void onConfigurationChanged(Configuration newConfig) {  
  15.     }  
  16.   
  17.     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {  
  18.     }  
  19. }  

5:修改frameworks/base/packages/SystemUI/src/com/android/systemui/power/PowerUI.java,添加函数
  1. //add by xiaoge  
  2. public void onReceive(String action) {  
  3.          
  4.    }  

6:显示statusbar方法:sendBroadcast(new Intent(Intent.ACTION_DISPLAY_STATUS_BAR));

      或者sendBroadcast(new Intent("android.intent.action.DISPLAY_STATUS_BAR"));


7:隐藏statusbar:sendBroadcast(new Intent(Intent.ACTION_HIDE_STATUS_BAR));

     或者sendBroadcast(new Intent("android.intent.action.HIDE_STATUS_BAR"));
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值