Example #1
0
  public static void updateNotification(Context context, String description, String boardToLaunch) {

    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.notification);
    views.setImageViewResource(R.id.play_pause, R.drawable.play_pause);
    views.setTextViewText(R.id.description, " " + description);

    File icon = new File(mSbDir, boardToLaunch + "/icon.png");
    if (icon.exists()) {
      Bitmap bitmap = IconUtils.decodeIcon(context, icon);
      views.setImageViewBitmap(R.id.icon, bitmap);
    } else {
      views.setImageViewResource(R.id.icon, R.drawable.board_icon);
    }

    Intent pauseIntent = new Intent(context, TogglePlayPauseService.class);
    PendingIntent pausePendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0);
    views.setOnClickPendingIntent(R.id.play_pause, pausePendingIntent);

    final Intent notificationIntent = new Intent(context, SoundboardMenu.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

    if (boardToLaunch != null) {
      notificationIntent.putExtra(SoundboardMenu.EXTRA_LAUNCH_BAORD_KEY, boardToLaunch);
    }

    PendingIntent pendingIntent =
        PendingIntent.getActivity(
            context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    Notification.Builder builder =
        new Notification.Builder(context)
            .setOngoing(true)
            .setSmallIcon(R.drawable.icon)
            .setAutoCancel(false)
            .setTicker("Boarder")
            .setContentText(description)
            .setContentIntent(pendingIntent)
            .setContent(views);

    final NotificationManager notificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(SoundboardMenu.TAG, mNotificationId, builder.getNotification());
  }
Example #2
0
  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    Cursor selection = mDbHelper.fetchBoard(id);
    startManagingCursor(selection);
    final String boardName =
        selection.getString(selection.getColumnIndexOrThrow(MenuDbAdapter.KEY_TITLE));
    int boardLocal = selection.getInt(selection.getColumnIndexOrThrow(MenuDbAdapter.KEY_LOCAL));
    File boardDir = new File(mSbDir, boardName);

    if (Intent.ACTION_CREATE_SHORTCUT.equals(mAction)) {

      Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
      shortcutIntent.setClassName(this, this.getClass().getName());
      shortcutIntent.putExtra(EXTRA_LAUNCH_BAORD_KEY, boardName);
      shortcutIntent.putExtra(EXTRA_HIDE_SOUNDBOARDMENU, true);
      shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

      Intent intent = new Intent();
      intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
      intent.putExtra(
          Intent.EXTRA_SHORTCUT_NAME,
          selection.getString(selection.getColumnIndexOrThrow(MenuDbAdapter.KEY_TITLE)));

      File icon = new File(mSbDir, boardName + "/icon.png");
      if (icon.exists()) {
        Bitmap bitmap = IconUtils.decodeIcon(super.mContext, icon);
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, IconUtils.resizeIcon(this, bitmap, (40 / 12)));
      } else {
        Parcelable iconResource =
            Intent.ShortcutIconResource.fromContext(this, R.drawable.board_icon);
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
      }

      setResult(RESULT_OK, intent);

      finish();
      return;

    } else if (mMoveBoard > -1) {

      Cursor moveFrom = mDbHelper.fetchBoard(mMoveBoard);
      startManagingCursor(moveFrom);

      String moveSourceTitle =
          moveFrom.getString(moveFrom.getColumnIndexOrThrow(MenuDbAdapter.KEY_TITLE));
      int moveSourceLocal =
          moveFrom.getInt(moveFrom.getColumnIndexOrThrow(MenuDbAdapter.KEY_LOCAL));

      mDbHelper.updateBoard((int) id, moveSourceTitle, moveSourceLocal);
      mDbHelper.updateBoard(mMoveBoard, boardName, boardLocal);

      mMoveBoard = -1;

      initializeBoardUpdateThread();

    } else {

      try {
        boolean boardFileFound = false;
        for (File boardDirContent : boardDir.listFiles()) {
          if (boardDirContent.getName().equals("graphicalBoard")) {
            Intent i = new Intent(this, BoardEditor.class);
            i.putExtra(MenuDbAdapter.KEY_TITLE, boardName);
            startActivity(i);
            boardFileFound = true;
            break;
          }
        }
        if (!boardFileFound) {
          Intent i = new Intent(this, BoardEditor.class);
          i.putExtra(MenuDbAdapter.KEY_TITLE, boardName);
          startActivity(i);
        }
      } catch (NullPointerException npe) {
        Log.e(SoundboardMenu.TAG, "Unable to list boards", npe);
      }
    }
  }