/**
   * ***************************************************
   *
   * <p>Public methods
   *
   * <p>****************************************************
   */
  public void finalizeService() {
    Logs.d(TAG, "# Service : finalize ---");

    mBluetoothAdapter = null;
    // Stop the bluetooth session
    if (mBtManager != null) mBtManager.stop();
    mBtManager = null;
    // Unregister broadcast receiver
    if (mReceiver != null) unregisterReceiver(mReceiver);
    mReceiver = null;
    if (mBatteryInfoReceiver != null) unregisterReceiver(mBatteryInfoReceiver);
    mBatteryInfoReceiver = null;

    // Stop the timer
    if (mRefreshTimer != null) {
      mRefreshTimer.cancel();
      mRefreshTimer = null;
    }
    if (mDeleteTimer != null) {
      mDeleteTimer.cancel();
      mDeleteTimer = null;
    }

    mContentManager.finalize();
  }
  /** WARNING: Remove all notifications from indicator. */
  public void sendClearAllNotificationsSignal() {
    // Send command to NotificationListenerService
    Intent i = new Intent(Constants.NOTIFICATION_LISTENER_SERVICE);
    i.putExtra("command", "clearall");
    sendBroadcast(i);

    // Clear all contents in ContentManager
    mContentManager.clearAllNotifications();
  }
  /**
   * Extract all notifications currently registered. NotificationReceiverService will send results
   * one by one using broadcast. And service send each notification to activity handler.
   */
  public void sendGetAllNotificationsSignal() {
    // Send command to NotificationService
    Intent i = new Intent(Constants.NOTIFICATION_LISTENER_SERVICE);
    i.putExtra("command", "list");
    sendBroadcast(i);

    // Clear all contents in ContentManager
    mContentManager.clearAllNotifications();

    // ----- Result will be delivered on broadcast receiver
  }
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();
          if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
            int plugType = intent.getIntExtra("plugged", 0);
            int status = intent.getIntExtra("status", BatteryManager.BATTERY_STATUS_UNKNOWN);

            int chargingStatus = EmergencyObject.BATT_STATE_UNKNOWN;
            if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
              if (plugType > 0) {
                chargingStatus =
                    ((plugType == BatteryManager.BATTERY_PLUGGED_AC)
                        ? EmergencyObject.BATT_STATE_AC_CHARGING
                        : EmergencyObject.BATT_STATE_USB_CHARGING);
              }
            } else if (status == BatteryManager.BATTERY_STATUS_DISCHARGING) {
              chargingStatus = EmergencyObject.BATT_STATE_DISCHARGING;
            } else if (status == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
              chargingStatus = EmergencyObject.BATT_STATE_NOT_CHARGING;
            } else if (status == BatteryManager.BATTERY_STATUS_FULL) {
              chargingStatus = EmergencyObject.BATT_STATE_FULL;
            } else {
              chargingStatus = EmergencyObject.BATT_STATE_UNKNOWN;
            }

            int level = intent.getIntExtra("level", 0);
            int scale = intent.getIntExtra("scale", 100);

            // WARNING: Battery service makes too many broadcast.
            // Process data only when there's change in battery level or status.
            if (mContentManager.getBatteryLevel() == level
                && mContentManager.getBatteryChargingState() == status) return;

            ContentObject co = mContentManager.setBatteryInfo(level * 100 / scale, chargingStatus);
            if (co != null) sendContentsToDevice(co);
          }
        }
  /**
   * ***************************************************
   *
   * <p>Private methods
   *
   * <p>****************************************************
   */
  private void initialize() {
    Logs.d(TAG, "# Service : initialize ---");

    // Get content manager instance
    mContentManager = ContentManager.getInstance(mContext, this);
    // Get connection info instance
    mConnectionInfo = ConnectionInfo.getInstance(mContext);

    // Set notification broadcast receiver
    mReceiver = new NotificationReceiver();
    IntentFilter filter = new IntentFilter();
    filter.addAction(Constants.NOTIFICATION_LISTENER);
    registerReceiver(mReceiver, filter);

    // Set battery broadcast receiver
    IntentFilter iFilter = new IntentFilter();
    iFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
    registerReceiver(mBatteryInfoReceiver, iFilter);

    // Set SMS listener
    IntentFilter smsFilter = new IntentFilter();
    smsFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
    registerReceiver(mSmsListener, smsFilter);

    // Set telephony listener
    TelephonyStateListener telephonyListener = new TelephonyStateListener();
    TelephonyManager telephony =
        (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    telephony.listen(telephonyListener, PhoneStateListener.LISTEN_SERVICE_STATE);
    telephony.listen(telephonyListener, PhoneStateListener.LISTEN_CALL_STATE);

    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
      Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
      return;
    }

    if (!mBluetoothAdapter.isEnabled()) {
      // BT is not on, need to turn on manually.
      // Activity will do this.
    } else {
      if (mBtManager == null) {
        setupBT();
      }
    }
  }
  @Override
  public void OnContentCallback(
      int msgType, int arg0, int arg1, String arg2, String arg3, Object arg4) {
    switch (msgType) {
      case IContentManagerListener.CALLBACK_GMAIL_UPDATED:
        if (mActivityHandler != null)
          mActivityHandler.obtainMessage(Constants.MESSAGE_GMAIL_UPDATED, arg4).sendToTarget();
        if (arg4 != null) sendContentsToDevice((ContentObject) arg4);
        break;

      case IContentManagerListener.CALLBACK_FEED_UPDATED:
        ArrayList<ContentObject> feedList = mContentManager.refreshFeedList();
        mActivityHandler.obtainMessage(Constants.MESSAGE_FEED_UPDATED, feedList).sendToTarget();
        break;

      default:
        break;
    }
  }
 public void setGmailAddress(String gmailAddr) {
   mContentManager.setGmailAddress(gmailAddr);
 }
 public int addRss(CPObject cpo) {
   if (cpo == null) return Constants.RESPONSE_ADD_RSS_FAILED;
   return mContentManager.addCPObject(cpo);
 }
 public int editFilter(FilterObject filter) {
   if (filter == null) return Constants.RESPONSE_EDIT_FILTER_FAILED;
   return mContentManager.editFilter(filter);
 }
示例#10
0
 public int deleteFilter(int filter_id) {
   if (filter_id < 0) return Constants.RESPONSE_DELETE_FILTER_FAILED;
   return mContentManager.deleteFilter(filter_id);
 }
示例#11
0
 public ArrayList<FilterObject> getFiltersAll() {
   return mContentManager.getFilterObjectList();
 }
示例#12
0
 public int addFilter(FilterObject filter) {
   if (filter == null) return Constants.RESPONSE_ADD_FILTER_FAILED;
   return mContentManager.addFilter(filter);
 }
示例#13
0
 public int deleteRss(int rss_id) {
   if (rss_id < 0) return Constants.RESPONSE_DELETE_FILTER_FAILED;
   return mContentManager.deleteCPObject(rss_id);
 }
示例#14
0
 public int editRss(CPObject cpo) {
   if (cpo == null) return Constants.RESPONSE_EDIT_RSS_FAILED;
   return mContentManager.updateCPObject(cpo);
 }
示例#15
0
 public boolean sendEveryContentsToDevice() {
   ArrayList<ContentObject> contents = mContentManager.getContentObjectList();
   sendContentsToDevice(contents);
   return true;
 }
示例#16
0
 public ArrayList<CPObject> getRssAll() {
   return mContentManager.getCPObjectList();
 }
示例#17
0
 public ArrayList<ContentObject> refreshContentObjectList() {
   return mContentManager.refreshContentObjectList();
 }