[musikcube commit] r363 - Some more android stuff.

1 view
Skip to first unread message

codesite...@google.com

unread,
Jul 8, 2009, 5:55:28 PM7/8/09
to musikc...@googlegroups.com
Author: onnerby
Date: Wed Jul 8 14:54:19 2009
New Revision: 363

Added:
trunk/src/android/res/layout/track_list.xml
trunk/src/android/src/org/musikcube/TrackList.java
Removed:
trunk/src/android/res/layout/category_item.xml
Modified:
trunk/src/android/AndroidManifest.xml
trunk/src/android/src/doep/xml/Reader.java
trunk/src/android/src/doep/xml/ReaderNode.java
trunk/src/android/src/doep/xml/Writer.java
trunk/src/android/src/org/musikcube/CategoryList.java
trunk/src/android/src/org/musikcube/core/Library.java
trunk/src/android/src/org/musikcube/core/ListQuery.java
trunk/src/android/src/org/musikcube/main.java

Log:
Some more android stuff.

Modified: trunk/src/android/AndroidManifest.xml
==============================================================================
--- trunk/src/android/AndroidManifest.xml (original)
+++ trunk/src/android/AndroidManifest.xml Wed Jul 8 14:54:19 2009
@@ -13,6 +13,7 @@
</activity>
<service android:name="Service" android:enabled="false"
android:process=":remote"></service>
<activity android:name="CategoryList"></activity>
+<activity android:name="TrackList"></activity>
</application>
<uses-sdk android:minSdkVersion="3" />


Added: trunk/src/android/res/layout/track_list.xml
==============================================================================
--- (empty file)
+++ trunk/src/android/res/layout/track_list.xml Wed Jul 8 14:54:19 2009
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:paddingLeft="8dp"
+ android:paddingRight="8dp">
+
+ <ListView android:id="@id/android:list"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_weight="1"
+ android:drawSelectorOnTop="false"/>
+
+ <TextView android:id="@id/android:empty"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:text="Loading...."/>
+ </LinearLayout>
\ No newline at end of file

Modified: trunk/src/android/src/doep/xml/Reader.java
==============================================================================
--- trunk/src/android/src/doep/xml/Reader.java (original)
+++ trunk/src/android/src/doep/xml/Reader.java Wed Jul 8 14:54:19 2009
@@ -48,11 +48,11 @@

// while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_DOCUMENT) {
- Log.v("doep::Reader::Parse","Start document");
+ //Log.v("doep::Reader::Parse","Start document");
// Start document
} else if(eventType == XmlPullParser.END_DOCUMENT) {
// End document
- Log.v("doep::Reader::Parse","End document");
+ //Log.v("doep::Reader::Parse","End document");

java.util.ListIterator<ReaderNode> it=this.nodeLevels.listIterator();
while(it.hasNext()){
@@ -60,7 +60,7 @@
}

} else if(eventType == XmlPullParser.START_TAG) {
- Log.v("doep::Reader::Parse","Start tag "+this.parser.getName());
+ //Log.v("doep::Reader::Parse","Start tag "+this.parser.getName());
//System.out.println("Start tag "+xpp.getName());
// Start a new node
ReaderNode node = new
ReaderNode(this.parser.getName(),this.nodeLevels.getLast());
@@ -78,7 +78,7 @@
this.currentNode = node;

} else if(eventType == XmlPullParser.END_TAG) {
- Log.v("doep::Reader::Parse","End tag "+this.parser.getName());
+ //Log.v("doep::Reader::Parse","End tag "+this.parser.getName());
//System.out.println("End tag "+xpp.getName());
if(this.parser.getName().equals(this.currentNode.name)){
// End the node, and remove from levels
@@ -90,7 +90,7 @@
throw new Exception("Wrong end tag..
expecting "+this.currentNode.name);
}
} else if(eventType == XmlPullParser.TEXT) {
- Log.v("doep::Reader::Parse","Text "+this.parser.getText());
+ //Log.v("doep::Reader::Parse","Text "+this.parser.getText());
//System.out.println("Text "+xpp.getText());
this.currentNode.content += this.parser.getText();
}

Modified: trunk/src/android/src/doep/xml/ReaderNode.java
==============================================================================
--- trunk/src/android/src/doep/xml/ReaderNode.java (original)
+++ trunk/src/android/src/doep/xml/ReaderNode.java Wed Jul 8 14:54:19 2009
@@ -38,16 +38,16 @@
public ReaderNode ChildNode(String name)
throws Exception
{
- Log.v("doep::ReaderNode::ChildNode","Node: "+name+" ended: "+this.ended);
+ //Log.v("doep::ReaderNode::ChildNode","Node: "+name+"
ended: "+this.ended);
// Check if this is the current node, if not - lets wait for it to bee
while(!this.ended){
this.reader.Parse();
-
Log.v("doep::ReaderNode::ChildNode1","Node: "+this.reader.currentNode.level+" "+this.level);
+
//Log.v("doep::ReaderNode::ChildNode1","Node: "+this.reader.currentNode.level+" "+this.level);
if(this.reader.currentNode.level==this.level+1){
// We have a childnode
-
Log.v("doep::ReaderNode::ChildNode2",""+this.reader.currentNode.name+"=="+name);
+
//Log.v("doep::ReaderNode::ChildNode2",""+this.reader.currentNode.name+"=="+name);
if(this.reader.currentNode.name.equals(name)){
-
Log.v("doep::ReaderNode::ChildNode3","FOUND "+this.reader.currentNode.name);
+
//Log.v("doep::ReaderNode::ChildNode3","FOUND "+this.reader.currentNode.name);
return this.reader.currentNode;
}else{
this.reader.currentNode.End();
@@ -56,7 +56,7 @@
this.reader.currentNode.End();
}
}
- Log.v("doep::ReaderNode::ChildNode4","NOT FOUND "+name);
+ //Log.v("doep::ReaderNode::ChildNode4","NOT FOUND "+name);
return null;
}

Modified: trunk/src/android/src/doep/xml/Writer.java
==============================================================================
--- trunk/src/android/src/doep/xml/Writer.java (original)
+++ trunk/src/android/src/doep/xml/Writer.java Wed Jul 8 14:54:19 2009
@@ -19,7 +19,7 @@
public void Write(String content)
throws java.io.IOException
{
- Log.v("doep.xml.Writer","Write "+content);
+ //Log.v("doep.xml.Writer","Write "+content);
this.stream.write(content.getBytes());
// this.buffer += content;
}
@@ -33,7 +33,7 @@
public void Flush(boolean writeNull)
throws java.io.IOException
{
- Log.v("doep.xml.Writer","Flush "+writeNull);
+ //Log.v("doep.xml.Writer","Flush "+writeNull);
if(writeNull){
this.stream.write(0);
}

Modified: trunk/src/android/src/org/musikcube/CategoryList.java
==============================================================================
--- trunk/src/android/src/org/musikcube/CategoryList.java (original)
+++ trunk/src/android/src/org/musikcube/CategoryList.java Wed Jul 8
14:54:19 2009
@@ -3,6 +3,8 @@
*/
package org.musikcube;

+import java.util.ArrayList;
+
import org.musikcube.core.ListQuery;
import org.musikcube.core.IQuery.OnQueryResultListener;

@@ -16,6 +18,7 @@
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
+import android.widget.ListView;
import android.widget.TextView;

/**
@@ -24,9 +27,13 @@
*/
public class CategoryList extends ListActivity implements
OnQueryResultListener {

- private String category = "";
+ private String category = null;
+ private String nextCategoryList = "";
private ListQuery query = new ListQuery();

+ private ArrayList<String> selectedCategory;
+ private ArrayList<Integer> selectedCategoryIds;
+
// Need handler for callbacks to the UI thread
final Handler callbackHandler = new Handler();

@@ -111,12 +118,37 @@
this.listAdapter.query = this.query;
setListAdapter(this.listAdapter);

- this.category =
intent.getStringExtra("org.musikcube.CategoryList.listCategory");
+
+ // Extract the category order
+ String categoryString =
intent.getStringExtra("org.musikcube.CategoryList.listCategory");
+ String[] categories = categoryString.split(",");
+ this.category = categories[0];
+
+ // Save the next category lists
+ for(int i=1;i<categories.length;i++){
+ if(i>1){
+ this.nextCategoryList += ",";
+ }
+ this.nextCategoryList += categories[i];
+ }
+
+ this.setTitle("musikCube: "+this.category);
+
+
if(this.category!=null){
Log.v("musikcube.CategoryList", "category="+this.category);
// Query for data
this.query.category = this.category;

+ // check for selection
+ this.selectedCategory =
intent.getStringArrayListExtra("org.musikcube.CategoryList.selectedCategory");
+ this.selectedCategoryIds =
intent.getIntegerArrayListExtra("org.musikcube.CategoryList.selectedCategoryId");
+ if(this.selectedCategory!=null){
+ for(int i=0;i<this.selectedCategory.size();i++){
+ this.query.SelectData(this.selectedCategory.get(i),
this.selectedCategoryIds.get(i));
+ }
+ }
+
org.musikcube.core.Library library =
org.musikcube.core.Library.GetInstance();

library.AddQuery(this.query);
@@ -132,19 +164,45 @@

public void OnResults(){
Log.i("CategoryList::OnResults","In right
thread "+this.query.resultsStrings.size());
-// this.get
this.listAdapter.notifyDataSetChanged();
-/*
- int first =
this.getListView().getPositionForView(this.getListView().getChildAt(0));
- int last = first + this.getListView().getChildCount();
-
- Log.i("CategoryList::OnResults","VISIBLE "+first+" "+last);
- */
}

public void OnQueryResults() {
// Call in right thread
this.callbackHandler.post(this.callbackRunnable);
+ }
+
+ @Override
+ protected void onListItemClick(ListView l, View v, int position, long id){
+ Log.i("CategoryList::onListItemClick","clicked on "+position+" "+id);
+
+ // List category
+ if(this.selectedCategory==null){
+ this.selectedCategory = new ArrayList<String>();
+ }
+ if(this.selectedCategoryIds==null){
+ this.selectedCategoryIds = new ArrayList<Integer>();
+ }
+ ArrayList<String> selectedCategory =
(ArrayList<String>)this.selectedCategory.clone();
+ ArrayList<Integer> selectedCategoryIds =
(ArrayList<Integer>)this.selectedCategoryIds.clone();
+
+ selectedCategory.add(this.category);
+ selectedCategoryIds.add((int)id);
+
+ if(this.nextCategoryList.equals("")){
+ // List tracks
+ Intent intent = new Intent(this, TrackList.class);
+ intent.putExtra("org.musikcube.CategoryList.listCategory",
this.nextCategoryList);
+ intent.putExtra("org.musikcube.CategoryList.selectedCategory",
selectedCategory);
+ intent.putExtra("org.musikcube.CategoryList.selectedCategoryId",
selectedCategoryIds);
+ startActivity(intent);
+ }else{
+ Intent intent = new Intent(this, CategoryList.class);
+ intent.putExtra("org.musikcube.CategoryList.listCategory",
this.nextCategoryList);
+ intent.putExtra("org.musikcube.CategoryList.selectedCategory",
selectedCategory);
+ intent.putExtra("org.musikcube.CategoryList.selectedCategoryId",
selectedCategoryIds);
+ startActivity(intent);
+ }
}

}

Added: trunk/src/android/src/org/musikcube/TrackList.java
==============================================================================
--- (empty file)
+++ trunk/src/android/src/org/musikcube/TrackList.java Wed Jul 8 14:54:19
2009
@@ -0,0 +1,160 @@
+/**
+ *
+ */
+package org.musikcube;
+
+import java.util.ArrayList;
+
+import org.musikcube.core.ListQuery;
+import org.musikcube.core.IQuery.OnQueryResultListener;
+
+import android.app.ListActivity;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.util.Log;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.LinearLayout;
+import android.widget.ListView;
+import android.widget.TextView;
+
+/**
+ * @author doy
+ *
+ */
+public class TrackList extends ListActivity implements
OnQueryResultListener {
+
+ private ListQuery query = new ListQuery();
+
+ // Need handler for callbacks to the UI thread
+ final Handler callbackHandler = new Handler();
+
+ // Create runnable for posting
+ final Runnable callbackRunnable = new Runnable() {
+ public void run() {
+ OnResults();
+ }
+ };
+
+ public class ResultAdapter extends BaseAdapter{
+
+ protected ListQuery query;
+ protected Context context;
+
+ public ResultAdapter(Context context){
+ this.context = context;
+ }
+
+ public int getCount() {
+ return this.query.trackList.size();
+ }
+
+ public Object getItem(int position) {
+ return this.query.trackList.get(position);
+ }
+
+ public long getItemId(int position) {
+ return this.query.trackList.get(position);
+ }
+
+ public View getView(int position, View view, ViewGroup parent) {
+ TrackItemView item;
+ if(view==null){
+ item = new
TrackItemView(this.context,this.query.trackList.get(position));
+ }else{
+ item = (TrackItemView)view;
+ item.SetTitle(this.query.trackList.get(position));
+
+ }
+ return item;
+ }
+
+ }
+
+ private class TrackItemView extends LinearLayout {
+ public TrackItemView(Context context, Integer title) {
+ super(context);
+ this.setOrientation(VERTICAL);
+
+ mTitle = new TextView(context);
+ mTitle.setTextSize(18);
+ mTitle.setText(title.toString());
+ addView(mTitle, new LinearLayout.LayoutParams(
+ LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
+
+ }
+
+ /**
+ * Convenience method to set the title of a CategoryItemView
+ */
+ public void SetTitle(Integer title) {
+ mTitle.setText(title.toString());
+ }
+
+ private TextView mTitle;
+ }
+
+ private ResultAdapter listAdapter;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState){
+ super.onCreate(savedInstanceState);
+ Log.v("musikcube.TrackList", "start");
+ this.setContentView(R.layout.track_list);
+
+ Intent intent = this.getIntent();
+
+ this.query.SetResultListener(this);
+
+ this.listAdapter = new ResultAdapter(this);
+ this.listAdapter.query = this.query;
+ setListAdapter(this.listAdapter);
+
+ this.setTitle("musikCube: Tracks");
+
+ // Query for data
+
+ // check for selection
+ ArrayList<String> selectedCategory =
intent.getStringArrayListExtra("org.musikcube.CategoryList.selectedCategory");
+ ArrayList<Integer> selectedCategoryIds =
intent.getIntegerArrayListExtra("org.musikcube.CategoryList.selectedCategoryId");
+ if(selectedCategory!=null){
+ for(int i=0;i<selectedCategory.size();i++){
+ this.query.SelectData(selectedCategory.get(i),
selectedCategoryIds.get(i));
+ }
+ }
+
+ org.musikcube.core.Library library =
org.musikcube.core.Library.GetInstance();
+
+ this.query.listTracks = true;
+ library.AddQuery(this.query);
+
+ }
+
+ public void OnResults(){
+ Log.i("TrackList::OnResults","In right
thread "+this.query.trackList.size());
+ this.listAdapter.notifyDataSetChanged();
+ }
+
+ public void OnQueryResults() {
+ // Call in right thread
+ this.callbackHandler.post(this.callbackRunnable);
+ }
+
+ @Override
+ protected void onListItemClick(ListView l, View v, int position, long id){
+/* Log.i("CategoryList::onListItemClick","clicked on "+position+" "+id);
+ if(this.nextCategoryList.equals("")){
+ // List tracks
+ }else{
+ Intent intent = new Intent(this, CategoryList.class);
+ intent.putExtra("org.musikcube.CategoryList.listCategory",
this.nextCategoryList);
+ intent.putExtra("org.musikcube.CategoryList.selectedCategory",
this.category);
+ intent.putExtra("org.musikcube.CategoryList.selectedCategoryId",
(int)id);
+ startActivity(intent);
+ }*/
+ }
+
+}

Modified: trunk/src/android/src/org/musikcube/core/Library.java
==============================================================================
--- trunk/src/android/src/org/musikcube/core/Library.java (original)
+++ trunk/src/android/src/org/musikcube/core/Library.java Wed Jul 8
14:54:19 2009
@@ -64,7 +64,7 @@
}

public boolean Connect(String host,String username,String password,int
queryPort,int httpPort){
- Log.i("Library","starting "+host+":"+queryPort);
+ //Log.i("Library","starting "+host+":"+queryPort);
if(!running){
this.host = host;
this.username = username;
@@ -86,7 +86,7 @@
// First try to connect
try{
this.socket = new java.net.Socket(this.host,this.queryPort);
- Log.v("Library::socket","Successfully connected
to "+this.host+":"+this.queryPort);
+ //Log.v("Library::socket","Successfully connected
to "+this.host+":"+this.queryPort);

doep.xml.Reader reader = new
doep.xml.Reader(this.socket.getInputStream());
//Log.v("Library::run","Reader started");
@@ -107,11 +107,11 @@
this.writerThreadHelper = new WriterThreadHelper(this);

// Lets start waiting for query-results
- Log.v("Library::socket","Waiting for query results");
+ //Log.v("Library::socket","Waiting for query results");

doep.xml.ReaderNode queryNode = null;
while((queryNode=reader.ChildNode("queryresults"))!=null){
- Log.v("NODE","We have a "+queryNode.name);
+ //Log.v("NODE","We have a "+queryNode.name);
// Find the right query
IQuery query = null;

@@ -131,7 +131,7 @@
}

if(query!=null){
- Log.v("Library::socket","Parse query results");
+ //Log.v("Library::socket","Parse query results");
// Parse the results
query.ReceiveQueryResult(queryNode);
}
@@ -139,7 +139,7 @@

}

- Log.v("Library::socket","NOT Waiting for query results");
+ //Log.v("Library::socket","NOT Waiting for query results");
}
catch(IOException x){
Log.e("Library::socket","IOE "+x.getMessage());
@@ -151,7 +151,7 @@
}

public void WriteThread(WriterThreadHelper thread){
- Log.v("Library::WriteThread","Started");
+ //Log.v("Library::WriteThread","Started");
try{
doep.xml.Writer writer = new
doep.xml.Writer(this.socket.getOutputStream());
{
@@ -169,7 +169,7 @@
synchronized(this.sendQueryQueue){
if(this.sendQueryQueue.isEmpty()){
this.sendQueryQueue.wait(2000);
- Log.v("Library::WriteThread","wait over");
+ //Log.v("Library::WriteThread","wait over");
}else{
// Get the first query
query = this.sendQueryQueue.removeFirst();
@@ -177,7 +177,7 @@
}
}
catch(InterruptedException x){
- Log.v("Library::WriteThread","Thread Notified");
+ //Log.v("Library::WriteThread","Thread Notified");
}

if(query!=null){
@@ -200,7 +200,7 @@
Log.e("Library::WriteThread","E "+x.getMessage());
}

- Log.v("Library::WriteThread","Ended");
+ //Log.v("Library::WriteThread","Ended");
}

public void Disconnect(){

Modified: trunk/src/android/src/org/musikcube/core/ListQuery.java
==============================================================================
--- trunk/src/android/src/org/musikcube/core/ListQuery.java (original)
+++ trunk/src/android/src/org/musikcube/core/ListQuery.java Wed Jul 8
14:54:19 2009
@@ -13,7 +13,7 @@
public java.util.ArrayList<String> resultsStrings = new
java.util.ArrayList<String>();
public java.util.ArrayList<Integer> resultsInts = new
java.util.ArrayList<Integer>();
public java.util.ArrayList<Integer> trackList = new
java.util.ArrayList<Integer>();
-
+ public boolean listTracks = false;

public ListQuery() {
@@ -40,6 +40,12 @@
WriterNode listenersNode = queryNode.ChildNode("listeners");
listenersNode.content = this.category;

+ // List tracks?
+ if(this.listTracks){
+ WriterNode listtracksNode = queryNode.ChildNode("listtracks");
+ listtracksNode.content = "true";
+ }
+
queryNode.End();
}

@@ -61,7 +67,16 @@
}
}
}else if(childNode.name.equals("tracklist")){
- // TODO: get tracklist
+ // Get tracks
+ ReaderNode trackNode = null;
+ while( (trackNode=childNode.ChildNode("tracks"))!=null ){
+ trackNode.End();
+ String[] tracks = trackNode.content.split(",");
+ int nofTracks = tracks.length;
+ for(int i=0;i<nofTracks;i++){
+ this.trackList.add(Integer.parseInt(tracks[i]));
+ }
+ }
}
childNode.End();
}

Modified: trunk/src/android/src/org/musikcube/main.java
==============================================================================
--- trunk/src/android/src/org/musikcube/main.java (original)
+++ trunk/src/android/src/org/musikcube/main.java Wed Jul 8 14:54:19 2009
@@ -29,7 +29,7 @@

public void onClick(View v){
Intent intent = new Intent(main.this, CategoryList.class);
- intent.putExtra("org.musikcube.CategoryList.listCategory", "genre");
+
intent.putExtra("org.musikcube.CategoryList.listCategory", "genre,artist,album");
startActivity(intent);

}
@@ -40,7 +40,7 @@

public void onClick(View v){
Intent intent = new Intent(main.this, CategoryList.class);
- intent.putExtra("org.musikcube.CategoryList.listCategory", "artist");
+
intent.putExtra("org.musikcube.CategoryList.listCategory", "artist,album");
startActivity(intent);

}

Reply all
Reply to author
Forward
0 new messages