private void createDialog(final NavBarButton button) {
    final DialogInterface.OnClickListener l =
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int item) {
            onDialogClick(button, item);
            dialog.dismiss();
          }
        };

    String action = mResources.getString(R.string.navbar_actiontitle_menu);
    action = String.format(action, button.getClickName());
    String longpress = mResources.getString(R.string.navbar_longpress_menu);
    longpress = String.format(longpress, button.getLongName());
    String[] items = {
      action,
      longpress,
      mResources.getString(R.string.navbar_icon_menu),
      mResources.getString(R.string.navbar_delete_menu)
    };
    final AlertDialog dialog =
        new AlertDialog.Builder(mContext)
            .setTitle(mResources.getString(R.string.navbar_title_menu))
            .setItems(items, l)
            .create();

    dialog.show();
  }
 private void onDialogClick(NavBarButton button, int command) {
   switch (command) {
     case 0: // Set Click Action
       button.setPickLongPress(false);
       createActionDialog(button);
       break;
     case 1: // Set Long Press Action
       button.setPickLongPress(true);
       createActionDialog(button);
       break;
     case 2: // set Custom Icon
       int width = 100;
       int height = width;
       Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
       intent.setType("image/*");
       intent.putExtra("crop", "true");
       intent.putExtra("aspectX", width);
       intent.putExtra("aspectY", height);
       intent.putExtra("outputX", width);
       intent.putExtra("outputY", height);
       intent.putExtra("scale", true);
       intent.putExtra(MediaStore.EXTRA_OUTPUT, getTempFileUri());
       intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.toString());
       Log.i(TAG, "started for result, should output to: " + getTempFileUri());
       startActivityForResult(intent, REQUEST_PICK_CUSTOM_ICON);
       break;
     case 3: // Delete Button
       mButtons.remove(mPendingButton);
       mNumberofButtons--;
       break;
   }
   refreshButtons();
 }
 private void onActionDialogClick(NavBarButton button, int command) {
   if (command == mActions.length - 1) {
     // This is the last action - should be **app**
     mPicker.pickShortcut();
   } else { // This should be any other defined action.
     if (button.getPickLongPress()) {
       button.setLongPress(mActionCodes[command]);
     } else {
       button.setClickAction(mActionCodes[command]);
     }
   }
   refreshButtons();
 }
 private void saveButtons() {
   Settings.System.putInt(
       mContentRes, Settings.System.NAVIGATION_BAR_BUTTONS_QTY, mNumberofButtons);
   for (int i = 0; i < mNumberofButtons; i++) {
     NavBarButton button = mButtons.get(i);
     Settings.System.putString(
         mContentRes, Settings.System.NAVIGATION_CUSTOM_ACTIVITIES[i], button.getClickAction());
     Settings.System.putString(
         mContentRes, Settings.System.NAVIGATION_LONGPRESS_ACTIVITIES[i], button.getLongAction());
     Settings.System.putString(
         mContentRes, Settings.System.NAVIGATION_CUSTOM_APP_ICONS[i], button.getIconURI());
   }
 }
  @Override
  public void shortcutPicked(String uri, String friendlyName, Bitmap bmp, boolean isApplication) {
    NavBarButton button = mButtons.get(mPendingButton);
    boolean longpress = button.getPickLongPress();

    if (!longpress) {
      button.setClickAction(uri);
      if (bmp == null) {
        button.setIconURI("");
      } else {
        String iconName = getIconFileName(mPendingButton);
        FileOutputStream iconStream = null;
        try {
          iconStream = mContext.openFileOutput(iconName, Context.MODE_WORLD_READABLE);
        } catch (FileNotFoundException e) {
          return; // NOOOOO
        }
        bmp.compress(Bitmap.CompressFormat.PNG, 100, iconStream);
        button.setIconURI(Uri.fromFile(mContext.getFileStreamPath(iconName)).toString());
      }
    } else {
      button.setLongPress(uri);
    }
    refreshButtons();
  }