Ejemplo n.º 1
0
  private void sendNotification(NearbyPlayer nearbyPlayer) {

    Intent intent = new Intent(context, actionToNotificate);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pIntent =
        PendingIntent.getActivity(context, 2, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Builder builder = new Builder(context);

    switch (nearbyPlayer.getFaction()) {
      case blue:
        builder.setSmallIcon(R.drawable.blue_small);
        break;
      case green:
        builder.setSmallIcon(R.drawable.green_small);
        break;
    }

    builder.setContentIntent(pIntent);
    builder.setContentTitle(nearbyPlayer.getName());
    builder.setContentInfo(
        nearbyPlayer.getHumanReadableDistance()
            + " "
            + nearbyPlayer.getDirection()
            + " "
            + nearbyPlayer.getHumanReadableTime()
            + " ago on "
            + nearbyPlayer.getLocation());

    Notification noti = builder.build();
    noti.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, noti);

    this.lastNotification = nearbyPlayer;
  }
  /** Adds an onclick handler to the notification */
  private Builder setClickEvent(Builder notification) {
    Intent intent =
        new Intent(context, ReceiverActivity.class)
            .putExtra(OPTIONS, options.getJSONObject().toString())
            .setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

    int requestCode = new Random().nextInt();

    PendingIntent contentIntent =
        PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    return notification.setContentIntent(contentIntent);
  }
  @Override
  public void onCreate() {
    IntentFilter filterUsbDetached = new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED);
    registerReceiver(mUsbDetachedReceiver, filterUsbDetached);

    Intent settingsIntent = new Intent(this, SteeringWheelInterfaceActivity.class);
    settingsIntent.setAction(Intent.ACTION_EDIT);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(SteeringWheelInterfaceActivity.class);
    stackBuilder.addNextIntent(settingsIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    mNoticeBuilder.setContentIntent(resultPendingIntent);
    mNoticeBuilder.setSmallIcon(R.drawable.ic_notice);
    mNoticeBuilder.setContentTitle(getString(R.string.app_name));
    mNoticeBuilder.setContentText(getString(R.string.msg_app_starting));

    mNoticeManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNoticeManager.notify(mNoticeID, mNoticeBuilder.build());

    mCarInterface = new ElmInterface(getApplicationContext());
    mCarInterface.deviceOpenEvent_AddListener(mDeviceOpenListener);

    SharedPreferences settings =
        PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    String baudDefault = getString(R.string.scantool_baud);
    int baudValue = Integer.parseInt(settings.getString("scantool_baud", baudDefault));
    mCarInterface.setBaudRate(baudValue);

    String deviceNumDefault = getString(R.string.scantool_device_number);
    int deviceNumValue =
        Integer.parseInt(settings.getString("scantool_device_number", deviceNumDefault));
    mCarInterface.setDeviceNumber(deviceNumValue);

    String protocolCommandDefault = getString(R.string.scantool_protocol);
    String protocolCommandValue = settings.getString("scantool_protocol", protocolCommandDefault);
    mCarInterface.setProtocolCommand(protocolCommandValue);

    String monitorCommandDefault = getString(R.string.scantool_monitor_command);
    String monitorCommandValue =
        settings.getString("scantool_monitor_command", monitorCommandDefault);
    mCarInterface.setMonitorCommand(monitorCommandValue);
  }