LocationController.java revision e40451a89dc91dfd636af7cb32a23b4a4cc93fdc
1/* 2 * Copyright (C) 2008 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 17package com.android.systemui.statusbar.policy; 18 19import java.util.ArrayList; 20 21import android.app.Notification; 22import android.app.NotificationManager; 23import android.content.BroadcastReceiver; 24import android.content.Context; 25import android.content.Intent; 26import android.content.IntentFilter; 27import android.location.LocationManager; 28import android.util.Slog; 29import android.view.View; 30import android.widget.ImageView; 31 32// private NM API 33import android.app.INotificationManager; 34import com.android.internal.statusbar.StatusBarNotification; 35 36import com.android.systemui.R; 37 38public class LocationController extends BroadcastReceiver { 39 private static final String TAG = "StatusBar.LocationController"; 40 41 private static final int GPS_NOTIFICATION_ID = 374203-122084; 42 43 private Context mContext; 44 45 private INotificationManager mNotificationService; 46 47 public LocationController(Context context) { 48 mContext = context; 49 50 IntentFilter filter = new IntentFilter(); 51 filter.addAction(LocationManager.GPS_ENABLED_CHANGE_ACTION); 52 filter.addAction(LocationManager.GPS_FIX_CHANGE_ACTION); 53 context.registerReceiver(this, filter); 54 55 NotificationManager nm = (NotificationManager)context.getSystemService( 56 Context.NOTIFICATION_SERVICE); 57 mNotificationService = nm.getService(); 58 } 59 60 @Override 61 public void onReceive(Context context, Intent intent) { 62 final String action = intent.getAction(); 63 final boolean enabled = intent.getBooleanExtra(LocationManager.EXTRA_GPS_ENABLED, false); 64 65 boolean visible; 66 int iconId, textResId; 67 68 if (action.equals(LocationManager.GPS_FIX_CHANGE_ACTION) && enabled) { 69 // GPS is getting fixes 70 iconId = com.android.internal.R.drawable.stat_sys_gps_on; 71 textResId = R.string.gps_notification_found_text; 72 visible = true; 73 } else if (action.equals(LocationManager.GPS_ENABLED_CHANGE_ACTION) && !enabled) { 74 // GPS is off 75 visible = false; 76 iconId = textResId = 0; 77 } else { 78 // GPS is on, but not receiving fixes 79 iconId = R.drawable.stat_sys_gps_acquiring_anim; 80 textResId = R.string.gps_notification_searching_text; 81 visible = true; 82 } 83 84 try { 85 if (visible) { 86 Notification n = new Notification.Builder(mContext) 87 .setSmallIcon(iconId) 88 .setContentTitle(mContext.getText(textResId)) 89 .setOngoing(true) 90 .getNotification(); 91 92 // Notification.Builder will helpfully fill these out for you no matter what you do 93 n.tickerView = null; 94 n.tickerText = null; 95 96 int[] idOut = new int[1]; 97 mNotificationService.enqueueNotificationWithTagPriority( 98 mContext.getPackageName(), 99 null, 100 GPS_NOTIFICATION_ID, 101 StatusBarNotification.PRIORITY_SYSTEM, // !!!1!one!!! 102 n, 103 idOut); 104 } else { 105 mNotificationService.cancelNotification( 106 mContext.getPackageName(), 107 GPS_NOTIFICATION_ID); 108 } 109 } catch (android.os.RemoteException ex) { 110 // well, it was worth a shot 111 } 112 } 113} 114 115