Skip to content

Commit

Permalink
various updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Anon committed Mar 30, 2012
1 parent 4aff3b2 commit c534269
Show file tree
Hide file tree
Showing 14 changed files with 343 additions and 31 deletions.
2 changes: 2 additions & 0 deletions AndroidManifest.xml
Expand Up @@ -21,6 +21,8 @@
</activity>
<activity android:name=".activity.SongLibraryActivity" >
</activity>
<activity android:name=".activity.MPDRemotePreferencesActivity" >
</activity>
</application>

</manifest>
5 changes: 5 additions & 0 deletions pom.xml
Expand Up @@ -37,6 +37,11 @@
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>

<build>
Expand Down
9 changes: 9 additions & 0 deletions res/menu/playlist_list_context_menu.xml
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/removeSongFromPlaylist"
android:icon="@android:drawable/ic_menu_delete"
android:title="Remove"/>

</menu>
9 changes: 9 additions & 0 deletions res/menu/playlist_option_menu.xml
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/preferencesOptionMenu"
android:icon="@android:drawable/ic_menu_preferences"
android:title="Preferences"/>

</menu>
9 changes: 9 additions & 0 deletions res/menu/song_library_list_context_menu.xml
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/addSongToPlaylist"
android:icon="@android:drawable/ic_menu_add"
android:title="Add"/>

</menu>
34 changes: 34 additions & 0 deletions res/xml/preferences.xml
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<!-- This is a primitive example showing the different types of preferences available. -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

<PreferenceCategory android:title="Server" >
<EditTextPreference
android:defaultValue="192.168.1.1"
android:key="mpd_host_preference"
android:summary="MPD server hostname or ip address"
android:title="Hostname" />
<EditTextPreference
android:defaultValue="6600"
android:key="mpd_port_preference"
android:summary="MPD server port"
android:title="Port" />
</PreferenceCategory>

</PreferenceScreen>
@@ -0,0 +1,14 @@
package fr.mildlyusefulsoftware.mpdremote.activity;

import android.os.Bundle;
import android.preference.PreferenceActivity;
import fr.mildlyusefulsoftware.mpdremote.R;

public class MPDRemotePreferencesActivity extends PreferenceActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
Expand Up @@ -22,19 +22,19 @@ public void onCreate(Bundle savedInstanceState) {
spec = tabHost
.newTabSpec("playlist")
.setIndicator("PlayList",
res.getDrawable(R.drawable.icon))
res.getDrawable(android.R.drawable.ic_btn_speak_now))
.setContent(intent);
tabHost.addTab(spec);

intent = new Intent().setClass(this, SongLibraryActivity.class);
spec = tabHost
.newTabSpec("library")
.setIndicator("Library",
res.getDrawable(R.drawable.icon))
res.getDrawable(android.R.drawable.ic_menu_search))
.setContent(intent);
tabHost.addTab(spec);


tabHost.setCurrentTab(1);
tabHost.setCurrentTab(0);
}
}
Expand Up @@ -3,31 +3,45 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.math.NumberUtils;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.SpannableString;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import fr.mildlyusefulsoftware.mpdremote.R;
import fr.mildlyusefulsoftware.mpdremote.bo.CurrentlyPlayingSong;
import fr.mildlyusefulsoftware.mpdremote.bo.Song;
import fr.mildlyusefulsoftware.mpdremote.service.MPDService;
import fr.mildlyusefulsoftware.mpdremote.service.MPDListener;
import fr.mildlyusefulsoftware.mpdremote.service.MPDService;

public class PlaylistActivity extends Activity implements
MPDListener {
public class PlaylistActivity extends Activity implements MPDListener,
OnSharedPreferenceChangeListener {

private Song selectedSong = null;
final List<Song> songsInPlaylist = new ArrayList<Song>();

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playlist_layout);
MPDService.getInstance().addPlaylistChangeListener(this);
MPDService.getInstance(this).addPlaylistChangeListener(this);
final ListView playlistView = (ListView) findViewById(R.id.playlistView);

registerForContextMenu(playlistView);
playlistView.setAdapter(new PlaylistAdapter(this, songsInPlaylist));
playlistView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> myAdapter, View myView,
Expand All @@ -38,12 +52,13 @@ public void onItemClick(AdapterView<?> myAdapter, View myView,
});

Button playButton = (Button) findViewById(R.id.playButton);
final MPDService mpd = MPDService.getInstance(this);
playButton.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
if (selectedSong != null) {
MPDService.getInstance().playSong(selectedSong);
mpd.playSong(selectedSong);
}
}
});
Expand All @@ -54,15 +69,82 @@ public void playListChanged(List<Song> playList) {
songsInPlaylist.clear();
songsInPlaylist.addAll(playList);
this.runOnUiThread(new Runnable() {

@Override
public void run() {

final ListView playlistView = (ListView) findViewById(R.id.playlistView);
((PlaylistAdapter) playlistView.getAdapter()).notifyDataSetChanged();

((PlaylistAdapter) playlistView.getAdapter())
.notifyDataSetChanged();

}
});
}

@Override
public void currentlyPlayingSongChanged(
CurrentlyPlayingSong currentlyPlayingSong) {
this.setTitle(new SpannableString(currentlyPlayingSong.getSong()
.getTitle()));

}

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.playlist_list_context_menu, menu);
}

@Override
public boolean onContextItemSelected(MenuItem item) {

switch (item.getItemId()) {
case R.id.removeSongFromPlaylist:
final ListView songLibraryView = (ListView) findViewById(R.id.playlistView);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();
Song selectedSong = (Song) (songLibraryView
.getItemAtPosition(info.position));
MPDService.getInstance(this).removeSongFromPlaylist(selectedSong);
return true;
default:
return super.onContextItemSelected(item);

}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.playlist_option_menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.preferencesOptionMenu:
Intent intent = new Intent(getApplicationContext(),
MPDRemotePreferencesActivity.class);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}

@Override
public void onSharedPreferenceChanged(SharedPreferences arg0, String arg1) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(this);
String portString = prefs.getString("mpd_port_preference", "6600");
if (!NumberUtils.isNumber(portString)) {
portString = "6600";
}
String hostname = prefs.getString("mpd_host_preference", "localhost");
MPDService.getInstance(this).connect(portString, hostname);
}

}
Expand Up @@ -2,19 +2,53 @@

import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ListView;
import fr.mildlyusefulsoftware.mpdremote.R;
import fr.mildlyusefulsoftware.mpdremote.bo.Song;
import fr.mildlyusefulsoftware.mpdremote.service.MPDService;

public class SongLibraryActivity extends Activity {


public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.song_library_layout);
final ListView songLibraryView = (ListView) findViewById(R.id.songLibraryView);
songLibraryView.setAdapter(new PlaylistAdapter(this, MPDService.getInstance().getSongsInLibrary()));
registerForContextMenu(songLibraryView);
songLibraryView.setAdapter(new PlaylistAdapter(this, MPDService
.getInstance(this).getSongsInLibrary()));

}

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.song_library_list_context_menu, menu);
}

@Override
public boolean onContextItemSelected(MenuItem item) {

switch (item.getItemId()) {
case R.id.addSongToPlaylist:
final ListView songLibraryView = (ListView) findViewById(R.id.songLibraryView);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();
Song selectedSong = (Song) (songLibraryView
.getItemAtPosition(info.position));
MPDService.getInstance(this).addSongToPlayList(selectedSong);
return true;
default:
return super.onContextItemSelected(item);

}
}

}
@@ -0,0 +1,25 @@
package fr.mildlyusefulsoftware.mpdremote.bo;

public class CurrentlyPlayingSong {

private long elapsedTime;

private Song song;

public long getElapsedTime() {
return elapsedTime;
}

public void setElapsedTime(long elapsedTime) {
this.elapsedTime = elapsedTime;
}

public Song getSong() {
return song;
}

public void setSong(Song song) {
this.song = song;
}

}
9 changes: 9 additions & 0 deletions src/main/java/fr/mildlyusefulsoftware/mpdremote/bo/Song.java
Expand Up @@ -4,6 +4,7 @@ public class Song {

private int id;
private String title;
private String filename;

public String getTitle() {
return title;
Expand All @@ -20,4 +21,12 @@ public int getId() {
public void setId(int id) {
this.id = id;
}

public String getFilename() {
return filename;
}

public void setFilename(String filename) {
this.filename = filename;
}
}
Expand Up @@ -2,9 +2,11 @@

import java.util.List;

import fr.mildlyusefulsoftware.mpdremote.bo.CurrentlyPlayingSong;
import fr.mildlyusefulsoftware.mpdremote.bo.Song;

public interface MPDListener {

void playListChanged(List<Song> playList);
void currentlyPlayingSongChanged(CurrentlyPlayingSong currentlyPlayingSong);
}

0 comments on commit c534269

Please sign in to comment.