Android Open Source - Smartlab Main Activity






From Project

Back to project page Smartlab.

License

The source code is released under:

Apache License

If you think the Android project Smartlab listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ir.smartlab.musicplayer;
//  w w  w  . java  2  s.co m
import java.io.File;

import com.example.musicplayer.R;

import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class MainActivity extends ListActivity {

  Cursor cursor;

  public static int STATE_SELECT_ALBUM = 0;
  public static int STATE_SELECT_SONG = 1;

  int currentState = STATE_SELECT_ALBUM;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    String[] columns = { android.provider.MediaStore.Audio.Albums._ID,
        android.provider.MediaStore.Audio.Albums.ALBUM };

    cursor = managedQuery(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
        columns, null, null, null);

    String[] displayFields = new String[] { MediaStore.Audio.Albums.ALBUM };
    int[] displayViews = new int[] { android.R.id.text1 };
    setListAdapter(new SimpleCursorAdapter(this,
        android.R.layout.simple_list_item_1, cursor, displayFields,
        displayViews));
  }

  protected void onListItemClick(ListView l, View v, int position, long id) {
    if (currentState == STATE_SELECT_ALBUM) {
      if (cursor.moveToPosition(position)) {
        String[] columns = { MediaStore.Audio.Media.DATA,
            MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.TITLE,
            MediaStore.Audio.Media.DISPLAY_NAME,
            MediaStore.Audio.Media.MIME_TYPE, };

        String where = android.provider.MediaStore.Audio.Media.ALBUM
            + "=?";
        String whereVal[] = { cursor.getString(cursor
            .getColumnIndex(MediaStore.Audio.Albums.ALBUM)) };
        String orderBy = android.provider.MediaStore.Audio.Media.TITLE;

        cursor = managedQuery(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, columns,
            where, whereVal, orderBy);

        String[] displayFields = new String[] { MediaStore.Audio.Media.DISPLAY_NAME };
        int[] displayViews = new int[] { android.R.id.text1 };
        setListAdapter(new SimpleCursorAdapter(this,
            android.R.layout.simple_list_item_1, cursor,
            displayFields, displayViews));

        currentState = STATE_SELECT_SONG;
      }
    } else if (currentState == STATE_SELECT_SONG) {
      if (cursor.moveToPosition(position)) {
        int fileColumn = cursor
            .getColumnIndex(MediaStore.Audio.Media.DATA);
        int mimeTypeColumn = cursor
            .getColumnIndex(MediaStore.Audio.Media.MIME_TYPE);
        String audioFilePath = cursor.getString(fileColumn);
        String mimeType = cursor.getString(mimeTypeColumn);
        Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
        File newFile = new File(audioFilePath);
        intent.setDataAndType(Uri.fromFile(newFile), mimeType);
        startActivity(intent);
      }
    }
  }
}




Java Source Code List

com.example.activitylifecycletest.MainActivity.java
com.example.activitylifecycletest.SecondActivity.java
com.example.analyticstest.MainActivity.java
com.example.androidgraphic.MainActivity.java
com.example.animationexample.MainActivity.java
com.example.animationexample.SecondActivity.java
com.example.compassview.CompassView.java
com.example.compassview.MainActivity.java
com.example.databasetest.BookListActivity.java
com.example.databasetest.MainActivity.java
com.example.databasetest.data.Book.java
com.example.databasetest.data.DatabaseAdapter.java
com.example.fragmentexample.BookDetailsFragment.java
com.example.fragmentexample.BookListFragment.java
com.example.fragmentexample.MainActivity.java
com.example.fragmentexample.data.BookListAdapter.java
com.example.fragmentexample.data.Book.java
com.example.fragmentexample.data.DatabaseAdapter.java
com.example.listviewexample.MainActivity.java
com.example.listviewexample.data.BookListAdapter.java
com.example.listviewexample.data.Book.java
com.example.listviewexample.data.DatabaseAdapter.java
com.example.persiandatepicker.MainActivity.java
com.example.persiandatepicker.PersianDatePicker.java
com.example.preferencesexample.MainActivity.java
com.example.sqlitetestapp.MainActivity.java
com.example.sqlitetestapp.PersonListActivity.java
com.example.sqlitetestapp.data.DatabaseAdapter.java
com.example.sqlitetestapp.data.PersonListAdapter.java
com.example.sqlitetestapp.data.model.Person.java
com.example.viewpagerexample.MainActivity.java
ir.smartlab.android.broadcast.MainActivity.java
ir.smartlab.android.broadcast.WifiStateChangeReceiver.java
ir.smartlab.android.downloadasynctask.MainActivity.java
ir.smartlab.android.helloworld.MainActivity.java
ir.smartlab.audiorecord.MainActivity.java
ir.smartlab.audiotest.MainActivity.java
ir.smartlab.camera.MainActivity.java
ir.smartlab.captureimage.MainActivity.java
ir.smartlab.customaudiorecorder.MainActivity.java
ir.smartlab.java.ch04.firstcup.FisrtCup.java
ir.smartlab.java.ch05.circlesample.Circle.java
ir.smartlab.java.ch05.circlesample.Main.java
ir.smartlab.java.ch06.simplecalculator.SimpleCalculator.java
ir.smartlab.java.ch06.variablescope.VariableScopeTest.java
ir.smartlab.java.persiancalendar.Main.java
ir.smartlab.musicplayer.MainActivity.java
ir.smartlab.musicplayerservice.MainActivity.java
ir.smartlab.musicplayerservice.PlayerService.java
ir.smartlab.personlist.MainActivity.java
ir.smartlab.personlist.PersonListActivity.java
ir.smartlab.personlist.data.DatabaseAdapter.java
ir.smartlab.personlist.data.PersonListAdapter.java
ir.smartlab.personlist.data.Person.java