@Override
  public View getView(int position, View convertView, ViewGroup parent) {

    // Get the data item for this position
    TrackItem trackItem = getItem(position);

    // Check if an existing view is being reused, otherwise inflate the view
    if (convertView == null) {
      convertView = LayoutInflater.from(getContext()).inflate(R.layout.track, parent, false);
    }

    // Get views to set
    TextView tvName = (TextView) convertView.findViewById(R.id.textView);
    TextView tvAlbumName = (TextView) convertView.findViewById(R.id.albumTextView);
    ImageView ivUrl = (ImageView) convertView.findViewById(R.id.url);

    // Populate the data into the template view using the data object
    tvName.setText(trackItem.getName());
    tvAlbumName.setText(trackItem.getAlbum());

    // Populate the image view with the artist image using picasso.
    if (!TextUtils.isEmpty(trackItem.getImageUrl())) {
      Picasso.with(this.getContext()).load(trackItem.getImageUrl()).into(ivUrl);
    }

    return convertView;
  }
 private void uploadToDropbox() {
   Toast.makeText(
           ActivityTracksListView.this,
           "Uploading " + selected.getTrackName() + " to Dropbox",
           Toast.LENGTH_SHORT)
       .show();
   UploadFileToDropbox upload =
       new UploadFileToDropbox(
           ActivityTracksListView.this,
           dropbox,
           selected.getAlbumName() + "/" + selected.getTrackName() + ".wav",
           selected.getTrackPath());
   upload.execute();
 }
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   if (item.getTitle() == "Move") {
     moveDialog();
   }
   if (item.getTitle() == "Rename") {
     renameDialog();
   }
   if (item.getTitle() == "Set Description") {
     descriptionDialog();
   }
   if (item.getTitle() == "Upload Track to Dropbox") {
     Toast.makeText(
             ActivityTracksListView.this,
             "Upload " + selected.getTrackName() + " to Dropbox",
             Toast.LENGTH_SHORT)
         .show();
     if (dropboxAuthentication()) {
       uploadToDropbox();
     }
   }
   if (item.getTitle() == "Delete") {
     deleteDialog();
   }
   return false;
 }
  private void startPlayer(TrackItem currentTrack) {
    Uri uri = Uri.fromFile(currentTrack.getTrackPath()); // Load track location
    final double duration;

    mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

    try {
      // mediaPlayer.reset();
      mediaPlayer.setDataSource(getApplicationContext(), uri);
      mediaPlayer.prepare();
      mediaPlayer.start();
      mediaPlayer.seekTo(progressValue);
      duration = mediaPlayer.getDuration();
      track_duration.setText(
          String.format(
              "%02d:%02d",
              TimeUnit.MILLISECONDS.toMinutes((long) duration),
              TimeUnit.MILLISECONDS.toSeconds((long) duration)
                  - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) duration))));

      trackSeekBar.setMax((int) duration);
      // trackSeekBar.setProgress(mediaPlayer.getCurrentPosition());
      myHandler.postDelayed(UpdateSongTime, 10);

      mediaPlayer.setOnCompletionListener(
          new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
              mediaPlayer.release();
              mediaPlayer = null;
              trackSeekBar.setProgress(trackSeekBar.getMax());
              current_duration.setText(
                  String.format(
                      "%02d:%02d",
                      TimeUnit.MILLISECONDS.toMinutes((long) duration),
                      TimeUnit.MILLISECONDS.toSeconds((long) duration)
                          - TimeUnit.MINUTES.toSeconds(
                              TimeUnit.MILLISECONDS.toMinutes((long) duration))));
              progressValue = 0;
            }
          });

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  private void descriptionDialog() {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    final EditText textInput = new EditText(this);

    textInput.setText(selected.getTrackDescription());
    textInput.setSelectAllOnFocus(true);

    textInput.requestFocus();
    textInput.postDelayed(
        new Runnable() {
          @Override
          public void run() {
            InputMethodManager keyboard =
                (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            keyboard.showSoftInput(textInput, 0);
          }
        },
        100);

    dialogBuilder.setTitle("Set Description (max 3 lines)");
    dialogBuilder.setView(textInput);
    dialogBuilder.setNegativeButton(
        "Confirm",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            String description = textInput.getText().toString();
            data.setTrackDescription(selected, description);
            Toast.makeText(ActivityTracksListView.this, "Description changed!", Toast.LENGTH_SHORT)
                .show();
            populateListView();
          }
        });
    dialogBuilder.setPositiveButton(
        "Cancel",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
          }
        });

    AlertDialog dialogRename = dialogBuilder.create();
    dialogRename.show();
  }
Exemplo n.º 6
0
  /**
   * This method is called from within the constructor to initialize the form. WARNING: Do NOT
   * modify this code. The content of this method is always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jPanel1 = new javax.swing.JPanel();
    itemIdLabel = new javax.swing.JLabel();
    ItemIdText = new javax.swing.JTextField();
    itemBarCodeLabel = new javax.swing.JLabel();
    ItemBarCodeText = new javax.swing.JTextField();
    ItemNameLabel = new javax.swing.JLabel();
    ItemNameText = new javax.swing.JTextField();
    ItemPriceLabel = new javax.swing.JLabel();
    ItemPriceText = new javax.swing.JTextField();
    ItemQtyLabel = new javax.swing.JLabel();
    ItemQtyText = new javax.swing.JTextField();
    CatLabel = new javax.swing.JLabel();
    CatComboBox = new javax.swing.JComboBox();
    statusLabel = new javax.swing.JLabel();
    jComboBox2 = new javax.swing.JComboBox();
    itemConversionLabel = new javax.swing.JLabel();
    itemConversionCombo = new javax.swing.JComboBox();
    jPanel2 = new javax.swing.JPanel();
    sizeLabel = new javax.swing.JLabel();
    SizeText = new javax.swing.JTextField();
    ColorLabel = new javax.swing.JLabel();
    ColorText = new javax.swing.JTextField();
    MakeLabel = new javax.swing.JLabel();
    MakeText = new javax.swing.JTextField();
    QualityLabel = new javax.swing.JLabel();
    QualityComboBox = new javax.swing.JComboBox();
    WeigthLabel = new javax.swing.JLabel();
    WeightText = new javax.swing.JTextField();
    descLabel = new javax.swing.JLabel();
    jScrollPane1 = new javax.swing.JScrollPane();
    DescTextArea = new javax.swing.JTextArea();
    ManufLabel = new javax.swing.JLabel();
    ManufText = new javax.swing.JTextField();
    picPanel = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    jPanel3 = new javax.swing.JPanel();
    SaveUpdate = new javax.swing.JButton();
    prev = new javax.swing.JButton();
    next = new javax.swing.JButton();
    TrackItem = new javax.swing.JButton();
    Close = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    jPanel1.setBorder(
        javax.swing.BorderFactory.createTitledBorder(
            null,
            "General description",
            javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
            javax.swing.border.TitledBorder.DEFAULT_POSITION,
            new java.awt.Font("Tahoma", 0, 12),
            new java.awt.Color(0, 0, 51))); // NOI18N

    itemIdLabel.setText("Item Id");

    itemBarCodeLabel.setText("Item bar code");

    ItemBarCodeText.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            ItemBarCodeTextActionPerformed(evt);
          }
        });

    ItemNameLabel.setText("Item name");

    ItemPriceLabel.setText("Item price");

    ItemQtyLabel.setText("Item qty");

    CatLabel.setText("Category");

    CatComboBox.setModel(
        new javax.swing.DefaultComboBoxModel(
            new String[] {"Item 1", "Item 2", "Item 3", "Item 4"}));

    statusLabel.setText("Item status");

    jComboBox2.setModel(
        new javax.swing.DefaultComboBoxModel(
            new String[] {"Item 1", "Item 2", "Item 3", "Item 4"}));

    itemConversionLabel.setText("Item Conversion qty");

    itemConversionCombo.setModel(
        new javax.swing.DefaultComboBoxModel(
            new String[] {"Item 1", "Item 2", "Item 3", "Item 4"}));

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jPanel1Layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(
                                javax.swing.GroupLayout.Alignment.LEADING,
                                jPanel1Layout
                                    .createSequentialGroup()
                                    .addComponent(itemConversionLabel)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(
                                        itemConversionCombo,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        106,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(statusLabel)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(
                                        jComboBox2,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        112,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(
                                jPanel1Layout
                                    .createSequentialGroup()
                                    .addGroup(
                                        jPanel1Layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addGroup(
                                                jPanel1Layout
                                                    .createSequentialGroup()
                                                    .addComponent(itemIdLabel)
                                                    .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement
                                                            .RELATED)
                                                    .addComponent(
                                                        ItemIdText,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        102,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement
                                                            .UNRELATED)
                                                    .addComponent(itemBarCodeLabel)
                                                    .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement
                                                            .UNRELATED)
                                                    .addComponent(ItemBarCodeText))
                                            .addGroup(
                                                jPanel1Layout
                                                    .createSequentialGroup()
                                                    .addComponent(ItemPriceLabel)
                                                    .addGap(2, 2, 2)
                                                    .addComponent(
                                                        ItemPriceText,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        113,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addGap(18, 18, 18)
                                                    .addComponent(ItemQtyLabel)
                                                    .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement
                                                            .RELATED)
                                                    .addComponent(
                                                        ItemQtyText,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        146,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGap(24, 24, 24)
                                    .addGroup(
                                        jPanel1Layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(
                                                CatLabel,
                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(
                                                ItemNameLabel,
                                                javax.swing.GroupLayout.Alignment.TRAILING))))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(CatComboBox, 0, 154, Short.MAX_VALUE)
                            .addComponent(ItemNameText))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jPanel1Layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(
                                ItemIdText,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                29,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(itemIdLabel)
                            .addComponent(itemBarCodeLabel)
                            .addComponent(
                                ItemBarCodeText,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                29,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ItemNameLabel)
                            .addComponent(
                                ItemNameText,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                29,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ItemPriceLabel)
                            .addComponent(
                                ItemPriceText,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                29,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ItemQtyLabel)
                            .addComponent(
                                ItemQtyText,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                29,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(CatLabel)
                            .addComponent(
                                CatComboBox,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                29,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(
                                itemConversionCombo,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                32,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(
                                jComboBox2,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                28,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(itemConversionLabel)
                            .addComponent(statusLabel))
                    .addContainerGap()));

    jPanel2.setBorder(
        javax.swing.BorderFactory.createTitledBorder(
            null,
            "Other descriptions",
            javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
            javax.swing.border.TitledBorder.DEFAULT_POSITION,
            new java.awt.Font("Tahoma", 0, 12))); // NOI18N

    sizeLabel.setText("Item size");

    ColorLabel.setText("Item color");

    MakeLabel.setText("Origin/Make");

    QualityLabel.setText("Item quality");

    QualityComboBox.setModel(
        new javax.swing.DefaultComboBoxModel(
            new String[] {"Item 1", "Item 2", "Item 3", "Item 4"}));

    WeigthLabel.setText("Item weight");

    descLabel.setText("Item description");

    DescTextArea.setColumns(20);
    DescTextArea.setRows(5);
    jScrollPane1.setViewportView(DescTextArea);

    ManufLabel.setText("Manufacturer");

    picPanel.setBorder(
        javax.swing.BorderFactory.createEtchedBorder(
            javax.swing.border.EtchedBorder.RAISED, java.awt.Color.gray, java.awt.Color.lightGray));

    javax.swing.GroupLayout picPanelLayout = new javax.swing.GroupLayout(picPanel);
    picPanel.setLayout(picPanelLayout);
    picPanelLayout.setHorizontalGroup(
        picPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE));
    picPanelLayout.setVerticalGroup(
        picPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE));

    jLabel1.setText("Item pic");

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
        jPanel2Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jPanel2Layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        jPanel2Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(
                                jPanel2Layout
                                    .createSequentialGroup()
                                    .addGroup(
                                        jPanel2Layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addGroup(
                                                jPanel2Layout
                                                    .createSequentialGroup()
                                                    .addComponent(sizeLabel)
                                                    .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement
                                                            .RELATED)
                                                    .addComponent(
                                                        SizeText,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        133,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(
                                                jPanel2Layout
                                                    .createSequentialGroup()
                                                    .addComponent(QualityLabel)
                                                    .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement
                                                            .RELATED)
                                                    .addComponent(
                                                        QualityComboBox,
                                                        0,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        Short.MAX_VALUE)))
                                    .addGroup(
                                        jPanel2Layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(
                                                jPanel2Layout
                                                    .createSequentialGroup()
                                                    .addGap(16, 16, 16)
                                                    .addComponent(
                                                        ColorLabel,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        56,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(
                                                jPanel2Layout
                                                    .createSequentialGroup()
                                                    .addGap(18, 18, 18)
                                                    .addComponent(WeigthLabel)))
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(
                                        jPanel2Layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(
                                                jPanel2Layout
                                                    .createSequentialGroup()
                                                    .addComponent(
                                                        WeightText,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        90,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addGap(26, 26, 26)
                                                    .addComponent(ManufLabel)
                                                    .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement
                                                            .UNRELATED)
                                                    .addComponent(ManufText))
                                            .addGroup(
                                                jPanel2Layout
                                                    .createSequentialGroup()
                                                    .addComponent(ColorText)
                                                    .addGap(18, 18, 18)
                                                    .addComponent(MakeLabel)
                                                    .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement
                                                            .UNRELATED)
                                                    .addComponent(
                                                        MakeText,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        140,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(
                                jPanel2Layout
                                    .createSequentialGroup()
                                    .addComponent(descLabel)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(
                                        jScrollPane1,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        235,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(47, 47, 47)
                                    .addComponent(
                                        jLabel1,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        63,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(
                                        picPanel,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)))
                    .addGap(40, 40, 40)));
    jPanel2Layout.setVerticalGroup(
        jPanel2Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jPanel2Layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        jPanel2Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(sizeLabel)
                            .addComponent(
                                SizeText,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                28,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ColorLabel)
                            .addComponent(
                                ColorText,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                28,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(MakeLabel)
                            .addComponent(
                                MakeText,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                28,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(
                        jPanel2Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(QualityLabel)
                            .addComponent(
                                QualityComboBox,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                28,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(WeigthLabel)
                            .addComponent(
                                WeightText,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                28,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ManufLabel)
                            .addComponent(
                                ManufText,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                28,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(
                        jPanel2Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(
                                picPanel,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                            .addGroup(
                                jPanel2Layout
                                    .createSequentialGroup()
                                    .addGroup(
                                        jPanel2Layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(
                                                jScrollPane1,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGroup(
                                                jPanel2Layout
                                                    .createSequentialGroup()
                                                    .addGap(48, 48, 48)
                                                    .addComponent(jLabel1))
                                            .addGroup(
                                                jPanel2Layout
                                                    .createSequentialGroup()
                                                    .addGap(29, 29, 29)
                                                    .addComponent(descLabel)))
                                    .addGap(0, 33, Short.MAX_VALUE)))
                    .addContainerGap()));

    SaveUpdate.setText("Save");

    prev.setText("<< Previous");
    prev.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            prevActionPerformed(evt);
          }
        });

    next.setText("Next >>");

    TrackItem.setText("Track item");

    Close.setText("Close");

    javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
        jPanel3Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jPanel3Layout
                    .createSequentialGroup()
                    .addGap(8, 8, 8)
                    .addComponent(
                        SaveUpdate,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        96,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(
                        prev,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        116,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(
                        next,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        99,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(
                        TrackItem,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        104,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(
                        Close,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        101,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 41, Short.MAX_VALUE)));
    jPanel3Layout.setVerticalGroup(
        jPanel3Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jPanel3Layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        jPanel3Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(
                                SaveUpdate,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                34,
                                Short.MAX_VALUE)
                            .addComponent(
                                prev,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                            .addComponent(
                                next,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                            .addComponent(
                                TrackItem,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                            .addComponent(
                                Close,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE))));

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(
                                jPanel1,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                            .addComponent(
                                jPanel2,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                            .addComponent(
                                jPanel3,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE))
                    .addContainerGap()));
    layout.setVerticalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addComponent(
                        jPanel1,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        171,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(
                        jPanel2,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(
                        jPanel3,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(21, Short.MAX_VALUE)));

    pack();
  } // </editor-fold>//GEN-END:initComponents
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      View itemView = convertView;
      if (itemView == null) {
        itemView = getLayoutInflater().inflate(R.layout.tracks_item_view, parent, false);
      }

      // Find the album to work with
      final TrackItem currentTrack = data.getCurrentAlbum().getTracksList().get(position);

      // Make
      final TextView sizeText = (TextView) itemView.findViewById(R.id.size);
      sizeText.setText(currentTrack.getTrackSize());
      final TextView makeText = (TextView) itemView.findViewById(R.id.trackTextView);
      final TextView makeDescription = (TextView) itemView.findViewById(R.id.track_description);
      final ImageView makeimage = (ImageView) itemView.findViewById(R.id.imageView);
      makeText.setText(currentTrack.getTrackName());
      makeText.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              stopPlayer();
              selected = currentTrack;
              track_text.setText(currentTrack.getTrackName());
              startPlayer(selected);
            }
          });
      makeText.setOnLongClickListener(
          new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
              selected = currentTrack;
              return false;
            }
          });

      // Make Description

      makeDescription.setText(currentTrack.getTrackDescription());
      makeDescription.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              stopPlayer();
              selected = currentTrack;
              track_text.setText(currentTrack.getTrackName());
              startPlayer(selected);
            }
          });
      makeDescription.setOnLongClickListener(
          new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
              selected = currentTrack;
              return false;
            }
          });

      makeDescription.setText(currentTrack.getTrackDescription());
      makeimage.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              stopPlayer();
              selected = currentTrack;
              track_text.setText(currentTrack.getTrackName());
              startPlayer(selected);
            }
          });
      makeimage.setOnLongClickListener(
          new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
              selected = currentTrack;
              return false;
            }
          });

      play_button.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              if (mediaPlayer != null) mediaPlayer.start();
              else if (selected != null) startPlayer(selected);
            }
          });

      pause_button.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              if (mediaPlayer != null) {
                mediaPlayer.pause();
              }
            }
          });

      stop_button.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              stopPlayer();
              trackSeekBar.setProgress(0);
              current_duration.setText("00:00");
            }
          });

      trackSeekBar.setOnSeekBarChangeListener(
          new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

              if (fromUser && seekBar.isInTouchMode()) {
                progressValue = progress;
              }
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {}

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
              if (mediaPlayer != null) {
                mediaPlayer.seekTo(progressValue);
              } else {
                trackSeekBar.setProgress(progressValue);
              }
            }
          });

      return itemView;
    }
  private void renameDialog() {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    final EditText textInput = new EditText(this);
    textInput.setText(selected.getTrackName());
    textInput.setSelectAllOnFocus(true);

    textInput.requestFocus();
    textInput.postDelayed(
        new Runnable() {
          @Override
          public void run() {
            InputMethodManager keyboard =
                (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            keyboard.showSoftInput(textInput, 0);
          }
        },
        100);

    dialogBuilder.setTitle("Rename track");
    dialogBuilder.setView(textInput);
    dialogBuilder.setNegativeButton(
        "Confirm",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            String rename = textInput.getText().toString();

            File file =
                new File(
                    Environment.getExternalStorageDirectory()
                        + "/Audava/"
                        + data.getCurrentAlbum().getName()
                        + "/"
                        + rename
                        + ".wav");
            if (!file.exists()) {
              data.renameTrack(selected, rename);
              Toast.makeText(
                      ActivityTracksListView.this, "Name changed to " + rename, Toast.LENGTH_SHORT)
                  .show();
            } else {
              Toast.makeText(
                      ActivityTracksListView.this,
                      "File with the same name exists",
                      Toast.LENGTH_SHORT)
                  .show();
            }
            populateListView();
          }
        });
    dialogBuilder.setPositiveButton(
        "Cancel",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
          }
        });

    AlertDialog dialogRename = dialogBuilder.create();
    dialogRename.show();
  }