android4.0.3隐藏statusbar

1:修改frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIService.java

      import android.content.IntentFilter;      

@Override
    public void onCreate() {
        // Pick status bar or system bar.
        IWindowManager wm = IWindowManager.Stub.asInterface(
                ServiceManager.getService(Context.WINDOW_SERVICE));
        try {
            SERVICES[0] = wm.canStatusBarHide()
                    ? R.string.config_statusBarComponent
                    : R.string.config_systemBarComponent;
        } catch (RemoteException e) {
            Slog.w(TAG, "Failing checking whether status bar can hide", e);
        }

        final int N = SERVICES.length;
        mServices = new SystemUI[N];
        for (int i=0; i

2:修改frameworks/base/core/java/android/content/Intent.java

//add by xiaoge
	@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
	public static final String ACTION_DISPLAY_STATUS_BAR = "android.intent.action.DISPLAY_STATUS_BAR";

	@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
	public static final String ACTION_HIDE_STATUS_BAR = "android.intent.action.HIDE_STATUS_BAR";
	//add ends

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

/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar;

import com.android.systemui.statusbar.SeviceSocket;
import android.content.ComponentName;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import java.io.File;
import java.io.FileReader;
import java.util.Timer;
import java.util.TimerTask;
import android.os.Handler;
import android.os.Message;
import android.os.ServiceManager;
import android.app.Notification;
import android.app.PendingIntent;

import android.app.ActivityManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Slog;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.WindowManagerImpl;

import java.util.ArrayList;

import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.StatusBarIcon;
import com.android.internal.statusbar.StatusBarIconList;
import com.android.internal.statusbar.StatusBarNotification;

import com.android.systemui.SystemUI;
import com.android.systemui.R;

public abstract class StatusBar extends SystemUI implements CommandQueue.Callbacks {
    static final String TAG = "StatusBar";
    private static final boolean SPEW = false;
	//add by xiaoge
	private View mStatusBarView;
    private int mStatusBarHeight;
    private WindowManager.LayoutParams mStatusBarLayoutParams;

    protected CommandQueue mCommandQueue;
    protected IStatusBarService mBarService;

    //F/r/i/e/n/d/l/y/A/R/M
    private static SeviceSocket seviceSocket = null;
    private NotificationManager myNotiManager;

    // Up-call methods
    protected abstract View makeStatusBarView();
    protected abstract int getStatusBarGravity();
    public abstract int getStatusBarHeight();
    public abstract void animateCollapse();

    private DoNotDisturb mDoNotDisturb;

 
    //{{F-r-i-e-n-d-l-y-A-R-M
    private void setStatusIcon(int iconId, String text) {
        Intent notifyIntent=new Intent();
        notifyIntent.setComponent(new ComponentName("com.friendlyarm.net3gdialup", "com.friendlyarm.net3gdialup.ActivityMain"));
        notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent appIntent = PendingIntent.getActivity(mContext, 0,
            notifyIntent, 0);
        Notification myNoti = new Notification();
        myNoti.icon = iconId;
        myNoti.tickerText = text;
        myNoti.defaults = Notification.DEFAULT_LIGHTS;
        myNoti.setLatestEventInfo(mContext, "3G Network Status",text, appIntent);
        myNotiManager.notify(0, myNoti);
    }

    private void removeStatusIcon() {
        myNotiManager.cancelAll();
    }

    private int lastNetworkStatus = -1;
    private boolean isConnectService = false;

    private final int CONNECT_TO_SERVICE_MSG = 100;
    private final int REQUEST_NETSTATUS_MSG = 101;

    private Timer timerToConnService = new Timer();
    private Timer timerToRequestStatus = new Timer();

    private Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case CONNECT_TO_SERVICE_MSG:
                timerToConnService.cancel();
                seviceSocket.connectToService();
                break;
            case REQUEST_NETSTATUS_MSG:
                seviceSocket.sendRequest("REQUEST NETSTATUS\n");
                seviceSocket.recvResponse();
                break;
            }
            super.handleMessage(msg);
        }
    };

    private TimerTask taskConnectService = new TimerTask() {
        public void run() {
            Message message = new Message();
            message.what = CONNECT_TO_SERVICE_MSG;
            handler.sendMessage(message);
        }
    };

    private TimerTask taskRequestNetStatus = new TimerTask() {
        public void run() {
            Message message = new Message();
            message.what = REQUEST_NETSTATUS_MSG;
            handler.sendMessage(message);
        }
    };

    private void processNETStatusResponse(String response) {
        String[] results = response.split(" ");

        if (response.startsWith("RESPONSE CONNECT OK")) {
             seviceSocket.sendRequest("REQUEST 3GAUTOCONNECT GETSTATUS");
             seviceSocket.recvResponse();
        } else if (response.startsWith(new String("RESPONSE 3GAUTOCONNECT")) && results.length == 6) {
            if (Integer.parseInt(results[2]) == 1 && results[3].startsWith(new String("3GNET"))) {
                timerToRequestStatus.schedule(taskRequestNetStatus,1,3000);
            } else {
                seviceSocket.disconnect();
            }
        } else if (response.startsWith(new String("RESPONSE NETSTATUS"))
            && results.length >= 5) {
            if (results[2].startsWith(new String("DOWN"))) {
                if (lastNetworkStatus != 0) {
                    removeStatusIcon();
                }
                lastNetworkStatus = 0;
            } else if (results[2].startsWith(new String("UP"))
                && results.length == 8) {
                if (lastNetworkStatus != 1) {
                    setStatusIcon(com.android.internal.R.drawable.net3g, "Connected. (FriendlyARM-3G)");
                }
                lastNetworkStatus = 1;
            }
        }
    }
    //}}



   public void start() {
        // First set up our views and stuff.


       View sb = makeStatusBarView();

        //F/r/i/e/n/d/l/y/A/R/M
        myNotiManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        seviceSocket = new SeviceSocket(new SeviceSocket.RecvCallBack() {
            public void responseIncoming(String response) {
            processNETStatusResponse(response);
            }
            });


        // Connect in to the status bar manager service
        StatusBarIconList iconList = new StatusBarIconList();
        ArrayList notificationKeys = new ArrayList();
        ArrayList notifications = new ArrayList();
        mCommandQueue = new CommandQueue(this, iconList);
        mBarService = IStatusBarService.Stub.asInterface(
                ServiceManager.getService(Context.STATUS_BAR_SERVICE));
        int[] switches = new int[7];
        ArrayList binders = new ArrayList();
        try {
            mBarService.registerStatusBar(mCommandQueue, iconList, notificationKeys, notifications,
                    switches, binders);
        } catch (RemoteException ex) {
            // If the system process isn't there we're doomed anyway.
        }

        disable(switches[0]);
        setSystemUiVisibility(switches[1]);
        topAppWindowChanged(switches[2] != 0);
        // StatusBarManagerService has a back up of IME token and it's restored here.
        setImeWindowStatus(binders.get(0), switches[3], switches[4]);
        setHardKeyboardStatus(switches[5] != 0, switches[6] != 0);

        // Set up the initial icon state
        int N = iconList.size();
        int viewIndex = 0;
        for (int i=0; i

4:修改frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUI.java

package com.android.systemui;

import java.io.FileDescriptor;
import java.io.PrintWriter;

import android.content.Context;
import android.content.res.Configuration;

public abstract class SystemUI {
    public Context mContext;

    public abstract void start();
    public abstract void onReceive(String action);//add by xiaoge
    protected void onConfigurationChanged(Configuration newConfig) {
    }

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    }
}

5:修改frameworks/base/packages/SystemUI/src/com/android/systemui/power/PowerUI.java,添加函数

	//add by xiaoge
	public void onReceive(String action) {
        
    }

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"));





你可能感兴趣的:(android4.0.3隐藏statusbar)