@Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    // Dialog doesn't allow us to wait for a result, so we need to store
    // the info we need for when the dialog posts its result
    mQueryCursor.moveToPosition(position);
    if (mQueryCursor.isBeforeFirst() || mQueryCursor.isAfterLast()) {
      return;
    }
    String selectedType =
        mQueryCursor.getString(
            mQueryCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE));

    if ("artist".equals(selectedType)) {
      Intent intent = new Intent(Intent.ACTION_PICK);
      intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album");
      intent.putExtra("artist", Long.valueOf(id).toString());
      startActivity(intent);
    } else if ("album".equals(selectedType)) {
      Intent intent = new Intent(Intent.ACTION_PICK);
      intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
      intent.putExtra("album", Long.valueOf(id).toString());
      startActivity(intent);
    } else if (position >= 0 && id >= 0) {
      int[] list = new int[] {(int) id};
      MusicUtils.playAll(this, list, 0);
    } else {
      Log.e("QueryBrowser", "invalid position/id: " + position + "/" + id);
    }
  }
  public void init(Cursor c) {

    if (mAdapterDestroyed) return;
    mAdapter.changeCursor(c);

    if (mQueryCursor == null) {
      MusicUtils.displayDatabaseError(this);
      setListAdapter(null);
      mReScanHandler.sendEmptyMessageDelayed(0, 1000);
      return;
    }
    MusicUtils.hideDatabaseError(this);
  }
  private Cursor getQueryCursor(AsyncQueryHandler async, String filter) {
    if (filter == null) {
      filter = "";
    }
    String[] ccols =
        new String[] {
          BaseColumns._ID, // this will be the artist, album or track ID
          MediaStore.Audio.Media.MIME_TYPE, // mimetype of audio file, or "artist" or "album"
          MediaStore.Audio.Artists.ARTIST,
          MediaStore.Audio.Albums.ALBUM,
          MediaStore.Audio.Media.TITLE,
          "data1",
          "data2"
        };

    Uri search = Uri.parse("content://media/external/audio/search/fancy/" + Uri.encode(filter));

    Cursor ret = null;
    if (async != null) {
      async.startQuery(0, null, search, ccols, null, null, null);
    } else {
      ret = MusicUtils.query(this, search, ccols, null, null, null);
    }
    return ret;
  }
 public static Drawable getCachedArtwork(
     Context context, long artIndex, BitmapDrawable defaultArtwork) {
   Drawable d = null;
   synchronized (sArtCache) {
     d = sArtCache.get(artIndex);
   }
   if (d == null) {
     d = defaultArtwork;
     final Bitmap icon = defaultArtwork.getBitmap();
     int w = icon.getWidth();
     int h = icon.getHeight();
     Bitmap b = MusicUtils.getArtworkQuick(context, artIndex, w, h);
     if (b != null) {
       d = new FastBitmapDrawable(b);
       synchronized (sArtCache) {
         // the cache may have changed since we checked
         Drawable value = sArtCache.get(artIndex);
         if (value == null) {
           sArtCache.put(artIndex, d);
         } else {
           d = value;
         }
       }
     }
   }
   return d;
 }
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle icicle) {
   super.onCreate(icicle);
   setVolumeControlStream(AudioManager.STREAM_MUSIC);
   mAdapter = (QueryListAdapter) getLastNonConfigurationInstance();
   MusicUtils.bindToService(this, this);
   // defer the real work until we're bound to the service
 }
示例#6
0
    @Override
    protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
      if (cursor != null) {
        if (!isFinishing()) {
          /// M: when media file be empty,show the empty view
          MusicUtils.emptyShow(getListView(), MusicPicker.this);

          /// M: Only when there exist audio and has one selected by user, we need to enable ok
          // button.
          /// if user delete the last select audio, we need to check whether it exist.
          mOkayButton.setEnabled(
              cursor.getCount() > 0
                  && RingtoneManager.isRingtoneExist(getApplicationContext(), mSelectedUri));

          // Update the adapter: we are no longer loading, and have
          // a new cursor for it.
          mAdapter.setLoading(false);
          mAdapter.changeCursor(cursor);
          /// M: when listview has item showed ,let the ProgressBar@{
          if (getListView().getCount() != 0) {
            setProgressBarIndeterminateVisibility(false);
          }
          /// @}
          // Now that the cursor is populated again, it's possible to
          // restore the list state
          if (mListState != null) {
            getListView().onRestoreInstanceState(mListState);
            if (mListHasFocus) {
              getListView().requestFocus();
            }
            mListHasFocus = false;
            mListState = null;
          }
          /// M: when query out audios, hide error ui.
          MusicUtils.hideDatabaseError(MusicPicker.this);
          MusicPicker.this.setTitle(R.string.music_picker_title);
        } else {
          cursor.close();
        }
      } else {
        /// M: When can not query out result, show error to notify user.
        mOkayButton.setEnabled(false);
        MusicUtils.resetSdStatus();
        MusicUtils.displayDatabaseError(MusicPicker.this, false);
      }
    }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case USE_AS_RINGTONE:
       {
         // Set the system setting to make this the current ringtone
         MusicUtils.setRingtone(this, mTrackList.getSelectedItemId());
         return true;
       }
   }
   return super.onOptionsItemSelected(item);
 }
示例#8
0
        @Override
        public void onReceive(Context context, Intent intent) {

          String action = intent.getAction();
          String status = Environment.getExternalStorageState();

          MusicLogUtils.d(TAG, "mScanListener.onReceive:" + action + ", status = " + status);
          if (Intent.ACTION_MEDIA_SCANNER_STARTED.equals(action)
              || Intent.ACTION_MEDIA_SCANNER_FINISHED.equals(action)) {
            MusicUtils.setSpinnerState(MusicPicker.this);
          }
          doQuery(false, null);
        }
 public static void setPartyShuffleMenuIcon(Menu menu) {
   MenuItem item = menu.findItem(Defs.PARTY_SHUFFLE);
   if (item != null) {
     int shuffle = MusicUtils.getCurrentShuffleMode();
     if (shuffle == MediaPlaybackService.SHUFFLE_AUTO) {
       item.setIcon(R.drawable.ic_menu_party_shuffle);
       item.setTitle(R.string.party_shuffle_off);
     } else {
       item.setIcon(R.drawable.ic_menu_party_shuffle);
       item.setTitle(R.string.party_shuffle);
     }
   }
 }
示例#10
0
 public void onClick(View v) {
   String name = mPlaylist.getText().toString();
   if (name != null && name.length() > 0) {
     ContentResolver resolver = getContentResolver();
     int id = idForplaylist(name);
     Uri uri;
     if (id >= 0) {
       uri = ContentUris.withAppendedId(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, id);
       MusicUtils.clearPlaylist(CreatePlaylist.this, id);
     } else {
       ContentValues values = new ContentValues(1);
       values.put(MediaStore.Audio.Playlists.NAME, name);
       uri = resolver.insert(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values);
     }
     setResult(RESULT_OK, (new Intent()).setData(uri));
     finish();
   }
 }
示例#11
0
 @Override
 public void onDestroy() {
   MusicUtils.unbindFromService(this);
   unregisterReceiver(mScanListener);
   super.onDestroy();
   if (!mAdapterSent && mAdapter != null) {
     Cursor c = mAdapter.getCursor();
     if (c != null) {
       c.close();
     }
   }
   // Because we pass the adapter to the next activity, we need to make
   // sure it doesn't keep a reference to this activity. We can do this
   // by clearing its DatasetObservers, which setListAdapter(null) does.
   setListAdapter(null);
   mAdapter = null;
   mAdapterDestroyed = true;
 }
示例#12
0
 private int idForplaylist(String name) {
   Cursor c =
       MusicUtils.query(
           this,
           MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
           new String[] {MediaStore.Audio.Playlists._ID},
           MediaStore.Audio.Playlists.NAME + "=?",
           new String[] {name},
           MediaStore.Audio.Playlists.NAME);
   int id = -1;
   if (c != null) {
     c.moveToFirst();
     if (!c.isAfterLast()) {
       id = c.getInt(0);
     }
     c.close();
   }
   return id;
 }
示例#13
0
    @Override
    public void bindView(View view, Context context, Cursor cursor) {
      ViewHolder vh = (ViewHolder) view.getTag();

      cursor.copyStringToBuffer(mTitleIdx, vh.buffer1);
      vh.line1.setText(vh.buffer1.data, 0, vh.buffer1.sizeCopied);

      final int secondUnit = 1000;
      int secs = cursor.getInt(mDurationIdx) / secondUnit;
      if (secs == 0) {
        vh.duration.setText("");
      } else {
        vh.duration.setText(MusicUtils.makeTimeString(context, secs));
      }

      final StringBuilder builder = mBuilder;
      builder.delete(0, builder.length());

      String name = cursor.getString(mAlbumIdx);
      if (name == null || name.equals("<unknown>")) {
        builder.append(mUnknownAlbum);
      } else {
        builder.append(name);
      }
      builder.append('\n');
      name = cursor.getString(mArtistIdx);
      if (name == null || name.equals("<unknown>")) {
        builder.append(mUnknownArtist);
      } else {
        builder.append(name);
      }
      int len = builder.length();
      if (vh.buffer2.length < len) {
        vh.buffer2 = new char[len];
      }
      builder.getChars(0, len, vh.buffer2, 0);
      vh.line2.setText(vh.buffer2, 0, len);

      // Update the checkbox of the item, based on which the user last
      // selected.  Note that doing it this way means we must have the
      // list view update all of its items when the selected item
      // changes.
      final long id = cursor.getLong(mIdIdx);
      vh.radio.setChecked(id == mSelectedId);
      MusicLogUtils.v(
          TAG,
          "Binding id="
              + id
              + " sel="
              + mSelectedId
              + " playing="
              + mPlayingId
              + " cursor="
              + cursor);

      // Likewise, display the "now playing" icon if this item is
      // currently being previewed for the user.
      ImageView iv = vh.play_indicator;
      if (id == mPlayingId) {
        iv.setVisibility(View.VISIBLE);
      } else {
        /// M: if current song is not playing , we don't need the ImageView of play_indicator
        // visible.
        iv.setVisibility(View.GONE);
      }

      /// M:  Show drm lock when necessary @{
      updateDrmLockIcon(vh.drmLock, cursor, id);
    }
    @Override
    public void bindView(View view, Context context, Cursor cursor) {
      ViewHolder vh = (ViewHolder) view.getTag();

      cursor.copyStringToBuffer(mTitleIdx, vh.buffer1);
      vh.line1.setText(vh.buffer1.data, 0, vh.buffer1.sizeCopied);

      int secs = cursor.getInt(mDurationIdx) / 1000;
      if (secs == 0) {
        vh.duration.setText("");
      } else {
        vh.duration.setText(MusicUtils.makeTimeString(context, secs));
      }

      final StringBuilder builder = mBuilder;
      builder.delete(0, builder.length());

      String name = cursor.getString(mAlbumIdx);
      if (name == null || name.equals("<unknown>")) {
        builder.append(mUnknownAlbum);
      } else {
        builder.append(name);
      }
      builder.append('\n');
      name = cursor.getString(mArtistIdx);
      if (name == null || name.equals("<unknown>")) {
        builder.append(mUnknownArtist);
      } else {
        builder.append(name);
      }
      int len = builder.length();
      if (vh.buffer2.length < len) {
        vh.buffer2 = new char[len];
      }
      builder.getChars(0, len, vh.buffer2, 0);
      vh.line2.setText(vh.buffer2, 0, len);

      // Update the checkbox of the item, based on which the user last
      // selected.  Note that doing it this way means we must have the
      // list view update all of its items when the selected item
      // changes.
      final long id = cursor.getLong(mIdIdx);
      vh.radio.setChecked(id == mSelectedId);
      MusicLogUtils.v(
          TAG,
          "Binding id="
              + id
              + " sel="
              + mSelectedId
              + " playing="
              + mPlayingId
              + " cursor="
              + cursor);

      // Likewise, display the "now playing" icon if this item is
      // currently being previewed for the user.
      ImageView iv = vh.play_indicator;
      if (id == mPlayingId) {
        iv.setImageResource(R.drawable.indicator_ic_mp_playing_list);
        iv.setVisibility(View.VISIBLE);
      } else {
        iv.setVisibility(View.GONE);
      }

      // Show drm lock when necessary
      iv = vh.drm_lock;
      if (FeatureOption.MTK_DRM_APP) {
        int isDRM = cursor.getInt(mIsDrmIdx);
        int drmMethod = cursor.getInt(mDrmMethodIdx);
        MusicLogUtils.d(TAG, "bindView(" + view + "): isDRM=" + isDRM + ", drmMethod=" + drmMethod);
        try {
          if (isDRM == 1 && drmMethod != DrmStore.DrmMethod.METHOD_FL) {
            if (mDrmClient.checkRightsStatus(
                    ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id),
                    DrmStore.Action.PLAY)
                == DrmStore.RightsStatus.RIGHTS_VALID) {
              iv.setImageResource(com.mediatek.internal.R.drawable.drm_green_lock);
            } else {
              iv.setImageResource(com.mediatek.internal.R.drawable.drm_red_lock);
            }
            iv.setVisibility(View.VISIBLE);
          } else {
            iv.setVisibility(View.GONE);
          }
        } catch (Exception ex) {
          MusicLogUtils.e(TAG, "bindView: ", ex);
          iv.setVisibility(View.GONE);
        }
      } else {
        iv.setVisibility(View.GONE);
      }
    }
示例#15
0
  public void onServiceConnected(ComponentName name, IBinder service) {
    IntentFilter f = new IntentFilter();
    f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
    f.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    f.addDataScheme("file");
    registerReceiver(mScanListener, f);

    Intent intent = getIntent();

    if (intent.getAction().equals(Intent.ACTION_VIEW)) {
      // this is something we got from the search bar
      Uri uri = intent.getData();
      String path = uri.toString();
      if (path.startsWith("content://media/external/audio/media/")) {
        // This is a specific file
        String id = uri.getLastPathSegment();
        int[] list = new int[] {Integer.valueOf(id)};
        MusicUtils.playAll(this, list, 0);
        finish();
        return;
      } else if (path.startsWith("content://media/external/audio/albums/")) {
        // This is an album, show the songs on it
        Intent i = new Intent(Intent.ACTION_PICK);
        i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
        i.putExtra("album", uri.getLastPathSegment());
        startActivity(i);
        finish();
        return;
      } else if (path.startsWith("content://media/external/audio/artists/")) {
        // This is an artist, show the albums for that artist
        Intent i = new Intent(Intent.ACTION_PICK);
        i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album");
        i.putExtra("artist", uri.getLastPathSegment());
        startActivity(i);
        finish();
        return;
      }
    }
    mFilterString = intent.getStringExtra(SearchManager.QUERY);

    setContentView(R.layout.query_activity);
    mTrackList = getListView();
    mTrackList.setTextFilterEnabled(true);
    if (mAdapter == null) {
      mAdapter =
          new QueryListAdapter(
              getApplication(),
              this,
              R.layout.track_list_item,
              null, // cursor
              new String[] {},
              new int[] {});
      setListAdapter(mAdapter);
      if (TextUtils.isEmpty(mFilterString)) {
        getQueryCursor(mAdapter.getQueryHandler(), null);
      } else {
        mTrackList.setFilterText(mFilterString);
        mFilterString = null;
      }
    } else {
      mAdapter.setActivity(this);
      setListAdapter(mAdapter);
      mQueryCursor = mAdapter.getCursor();
      if (mQueryCursor != null) {
        init(mQueryCursor);
      } else {
        getQueryCursor(mAdapter.getQueryHandler(), mFilterString);
      }
    }
  }
示例#16
0
    @Override
    public void bindView(View view, Context context, Cursor cursor) {

      TextView tv1 = (TextView) view.findViewById(R.id.line1);
      TextView tv2 = (TextView) view.findViewById(R.id.line2);
      ImageView iv = (ImageView) view.findViewById(R.id.icon);
      ViewGroup.LayoutParams p = iv.getLayoutParams();
      if (p == null) {
        // seen this happen, not sure why
        DatabaseUtils.dumpCursor(cursor);
        return;
      }
      p.width = ViewGroup.LayoutParams.WRAP_CONTENT;
      p.height = ViewGroup.LayoutParams.WRAP_CONTENT;

      String mimetype =
          cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE));

      if (mimetype == null) {
        mimetype = "audio/";
      }
      if (mimetype.equals("artist")) {
        iv.setImageResource(R.drawable.ic_mp_artist_list);
        String name =
            cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST));
        String displayname = name;
        boolean isunknown = false;
        if (name == null || name.equals(MediaFile.UNKNOWN_STRING)) {
          displayname = context.getString(R.string.unknown_artist_name);
          isunknown = true;
        }
        tv1.setText(displayname);

        int numalbums = cursor.getInt(cursor.getColumnIndexOrThrow("data1"));
        int numsongs = cursor.getInt(cursor.getColumnIndexOrThrow("data2"));

        String songs_albums =
            MusicUtils.makeAlbumsSongsLabel(context, numalbums, numsongs, isunknown);

        tv2.setText(songs_albums);

      } else if (mimetype.equals("album")) {
        iv.setImageResource(R.drawable.albumart_mp_unknown_list);
        String name = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM));
        String displayname = name;
        if (name == null || name.equals(MediaFile.UNKNOWN_STRING)) {
          displayname = context.getString(R.string.unknown_album_name);
        }
        tv1.setText(displayname);

        name = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST));
        displayname = name;
        if (name == null || name.equals(MediaFile.UNKNOWN_STRING)) {
          displayname = context.getString(R.string.unknown_artist_name);
        }
        tv2.setText(displayname);

      } else if (mimetype.startsWith("audio/")
          || mimetype.equals("application/ogg")
          || mimetype.equals("application/x-ogg")) {
        iv.setImageResource(R.drawable.ic_mp_song_list);
        String name = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
        tv1.setText(name);

        String displayname =
            cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST));
        if (displayname == null || displayname.equals(MediaFile.UNKNOWN_STRING)) {
          displayname = context.getString(R.string.unknown_artist_name);
        }
        name = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM));
        if (name == null || name.equals(MediaFile.UNKNOWN_STRING)) {
          name = context.getString(R.string.unknown_album_name);
        }
        tv2.setText(displayname + " - " + name);
      }
    }
示例#17
0
 @Override
 public void onReceive(Context context, Intent intent) {
   MusicUtils.setSpinnerState(QueryBrowserActivity.this);
   mReScanHandler.sendEmptyMessage(0);
 }