Modified CategoryViews and TrackList views to use inflator.

This commit is contained in:
Daniel Önnerby 2009-08-09 22:24:12 +00:00
parent 32baa51f0d
commit 4bc6365178
7 changed files with 117 additions and 71 deletions

View File

@ -15,5 +15,5 @@
<TextView android:id="@id/android:empty" <TextView android:id="@id/android:empty"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:text="Loading...."/> android:text=""/>
</LinearLayout> </LinearLayout>

View File

@ -1,19 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent">
android:paddingLeft="8dp"
android:paddingRight="8dp">
<ListView android:id="@id/android:list" <TextView android:id="@+id/text"
android:layout_width="fill_parent" android:layout_width="0dip"
android:layout_height="fill_parent" android:layout_weight="1.0"
android:layout_weight="1" android:layout_height="wrap_content" android:textSize="24sp" android:fadingEdge="horizontal" android:maxLines="1" android:fadingEdgeLength="10sp"/>
android:drawSelectorOnTop="false"/>
<TextView android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Loading...."/>
</LinearLayout> </LinearLayout>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal">
<TextView android:id="@+id/track"
android:layout_width="24sp"
android:layout_height="wrap_content" android:textSize="24sp" android:fadingEdge="horizontal" android:maxLines="1" android:fadingEdgeLength="10sp" android:text="1."/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:textSize="24sp" android:fadingEdge="horizontal" android:maxLines="1" android:fadingEdgeLength="10sp" android:text="Track"/>
<TextView android:id="@+id/artist"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:fadingEdge="horizontal" android:maxLines="1" android:fadingEdgeLength="10sp" android:text="Track" android:textColor="#999999" android:textSize="16sp"/>
</LinearLayout>
</LinearLayout>

View File

@ -10,10 +10,12 @@ import org.musikcube.core.ListQuery;
import org.musikcube.core.IQuery.OnQueryResultListener; import org.musikcube.core.IQuery.OnQueryResultListener;
import android.app.ListActivity; import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
@ -36,6 +38,7 @@ public class CategoryList extends ListActivity implements OnQueryResultListener
private ArrayList<String> selectedCategory; private ArrayList<String> selectedCategory;
private ArrayList<Integer> selectedCategoryIds; private ArrayList<Integer> selectedCategoryIds;
private ProgressDialog loadingDialog;
// Need handler for callbacks to the UI thread // Need handler for callbacks to the UI thread
final Handler callbackHandler = new Handler(); final Handler callbackHandler = new Handler();
@ -50,10 +53,12 @@ public class CategoryList extends ListActivity implements OnQueryResultListener
public class ResultAdapter extends BaseAdapter{ public class ResultAdapter extends BaseAdapter{
protected ListQuery query; protected ListQuery query;
protected Context context; protected ListActivity context;
private LayoutInflater inflator;
public ResultAdapter(Context context){ public ResultAdapter(ListActivity context){
this.context = context; this.context = context;
this.inflator = context.getLayoutInflater();
} }
public int getCount() { public int getCount() {
@ -69,20 +74,17 @@ public class CategoryList extends ListActivity implements OnQueryResultListener
} }
public View getView(int position, View view, ViewGroup parent) { public View getView(int position, View view, ViewGroup parent) {
CategoryItemView item;
if(view==null){ if(view==null){
item = new CategoryItemView(this.context,this.query.resultsStrings.get(position)); view = inflator.inflate(R.layout.category_list_item, null);
}else{
item = (CategoryItemView)view;
item.SetTitle(this.query.resultsStrings.get(position));
} }
return item;
((TextView) view.findViewById(R.id.text)).setText(this.query.resultsStrings.get(position));
return view;
} }
} }
private class CategoryItemView extends LinearLayout { /* private class CategoryItemView extends LinearLayout {
public CategoryItemView(Context context, String title) { public CategoryItemView(Context context, String title) {
super(context); super(context);
this.setOrientation(VERTICAL); this.setOrientation(VERTICAL);
@ -95,16 +97,13 @@ public class CategoryList extends ListActivity implements OnQueryResultListener
} }
/**
* Convenience method to set the title of a CategoryItemView
*/
public void SetTitle(String title) { public void SetTitle(String title) {
mTitle.setText(title); mTitle.setText(title);
} }
private TextView mTitle; private TextView mTitle;
} }
*/
private ResultAdapter listAdapter; private ResultAdapter listAdapter;
@Override @Override
@ -154,7 +153,8 @@ public class CategoryList extends ListActivity implements OnQueryResultListener
org.musikcube.core.Library library = org.musikcube.core.Library.GetInstance(); org.musikcube.core.Library library = org.musikcube.core.Library.GetInstance();
library.AddQuery(this.query); this.loadingDialog = ProgressDialog.show(this, "", "Loading "+this.category+"...", true);
library.AddQuery(this.query);
}else{ }else{
//Log.v("musikcube.CategoryList", "category=null"); //Log.v("musikcube.CategoryList", "category=null");
@ -167,6 +167,10 @@ public class CategoryList extends ListActivity implements OnQueryResultListener
public void OnResults(){ public void OnResults(){
//Log.i("CategoryList::OnResults","In right thread "+this.query.resultsStrings.size()); //Log.i("CategoryList::OnResults","In right thread "+this.query.resultsStrings.size());
if(this.loadingDialog!=null){
this.loadingDialog.dismiss();
this.loadingDialog = null;
}
this.listAdapter.notifyDataSetChanged(); this.listAdapter.notifyDataSetChanged();
} }

View File

@ -18,6 +18,7 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
@ -29,8 +30,10 @@ import android.widget.TextView;
* @author doy * @author doy
* *
*/ */
public class TrackList extends ListActivity implements OnQueryResultListener { public class TrackList extends ListActivity implements OnQueryResultListener {
private ListQuery query = new ListQuery(); private ListQuery query = new ListQuery();
public java.util.ArrayList<Integer> trackList = new java.util.ArrayList<Integer>(); public java.util.ArrayList<Integer> trackList = new java.util.ArrayList<Integer>();
public java.util.TreeMap<Integer, Track> trackCache = new java.util.TreeMap<Integer,Track>(); public java.util.TreeMap<Integer, Track> trackCache = new java.util.TreeMap<Integer,Track>();
@ -48,13 +51,21 @@ public class TrackList extends ListActivity implements OnQueryResultListener {
} }
}; };
static class TrackViewHolder{
TextView track;
TextView title;
TextView artist;
}
public class ResultAdapter extends BaseAdapter{ public class ResultAdapter extends BaseAdapter{
protected TrackList trackList; protected TrackList trackList;
protected Context context; protected ListActivity context;
private LayoutInflater inflator;
public ResultAdapter(Context context){ public ResultAdapter(ListActivity context){
this.context = context; this.context = context;
this.inflator = context.getLayoutInflater();
} }
public int getCount() { public int getCount() {
@ -69,20 +80,54 @@ public class TrackList extends ListActivity implements OnQueryResultListener {
return this.trackList.trackList.get(position); return this.trackList.trackList.get(position);
} }
public View getView(int position, View view, ViewGroup parent) { public View getView(int position, View view, ViewGroup parent) {
TrackItemView item; TrackViewHolder holder;
if(view==null){ if(view==null){
item = new TrackItemView(this.context,this.trackList.GetTrack(position)); view = inflator.inflate(R.layout.track_list_item, null);
}else{
item = (TrackItemView)view;
item.SetTitles(this.trackList.GetTrack(position));
holder = new TrackViewHolder();
holder.title = (TextView) view.findViewById(R.id.title);
holder.track = (TextView) view.findViewById(R.id.track);
holder.artist = (TextView) view.findViewById(R.id.artist);
view.setTag(holder);
}else{
holder = (TrackViewHolder)view.getTag();
} }
return item;
Track track = this.trackList.GetTrack(position);
if(track==null){
holder.track.setText("");
holder.title.setText("....");
holder.artist.setText("");
return view;
}
String trackNumber = track.metadata.get("track");
String title = track.metadata.get("title");
String artist = track.metadata.get("visual_artist");
if(trackNumber!=null){
holder.track.setText(trackNumber);
}else{
holder.track.setText("");
}
if(title!=null){
holder.title.setText(title);
}else{
holder.title.setText("");
}
if(artist!=null){
holder.artist.setText(artist);
}else{
holder.artist.setText("");
}
return view;
} }
} }
/*
private class TrackItemView extends LinearLayout { private class TrackItemView extends LinearLayout {
public TrackItemView(Context context, Track track) { public TrackItemView(Context context, Track track) {
super(context); super(context);
@ -96,9 +141,6 @@ public class TrackList extends ListActivity implements OnQueryResultListener {
} }
/**
* Convenience method to set the title of a CategoryItemView
*/
public void SetTitles(Track track) { public void SetTitles(Track track) {
if(track!=null){ if(track!=null){
String text = ""; String text = "";
@ -121,14 +163,14 @@ public class TrackList extends ListActivity implements OnQueryResultListener {
} }
private TextView mTitle; private TextView mTitle;
} }*/
private ResultAdapter listAdapter; private ResultAdapter listAdapter;
@Override @Override
protected void onCreate(Bundle savedInstanceState){ protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Log.v("musikcube.TrackList", "start"); //Log.v("musikcube.TrackList", "start");
this.setContentView(R.layout.track_list); this.setContentView(R.layout.track_list);
Intent intent = this.getIntent(); Intent intent = this.getIntent();

View File

@ -10,10 +10,8 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.*;
import doep.xml.*; import doep.xml.*;
import org.musikcube.R;
import org.musikcube.core.IQuery; import org.musikcube.core.IQuery;
/** /**
@ -181,7 +179,7 @@ public class Library implements Runnable{
} }
public void WaitForAuthroization(){ public void WaitForAuthroization(){
Log.v("Library::WaitForAuthroization","start"); // Log.v("Library::WaitForAuthroization","start");
synchronized (notifier) { synchronized (notifier) {
if(this.authorization.equals("")){ if(this.authorization.equals("")){
try { try {
@ -190,7 +188,7 @@ public class Library implements Runnable{
} }
} }
} }
Log.v("Library::WaitForAuthroization","end"); // Log.v("Library::WaitForAuthroization","end");
} }
public void run(){ public void run(){
@ -224,11 +222,11 @@ public class Library implements Runnable{
authNode.End(); authNode.End();
synchronized (notifier) { synchronized (notifier) {
Log.v("Library::run","Authtag end"); //Log.v("Library::run","Authtag end");
this.authorization = authNode.content; this.authorization = authNode.content;
Log.v("Library::run","Authorization="+this.authorization); //Log.v("Library::run","Authorization="+this.authorization);
this.notifier.notifyAll(); this.notifier.notifyAll();
Log.v("Library::run","Authorization notify"); //Log.v("Library::run","Authorization notify");
} }
} }
} }
@ -272,10 +270,10 @@ public class Library implements Runnable{
//Log.v("Library::socket","NOT Waiting for query results"); //Log.v("Library::socket","NOT Waiting for query results");
} }
catch(IOException x){ catch(IOException x){
Log.e("Library::socket","IOE "+x.getMessage()); //Log.e("Library::socket","IOE "+x.getMessage());
} }
catch(Exception x){ catch(Exception x){
Log.e("Library::socket","E "+x.getMessage()); //Log.e("Library::socket","E "+x.getMessage());
} }
synchronized (notifier) { synchronized (notifier) {
@ -326,7 +324,7 @@ public class Library implements Runnable{
} }
}*/ }*/
Log.i("musikcube::LIB","exit? "+this.exit); //Log.i("musikcube::LIB","exit? "+this.exit);
if(this.exit){ if(this.exit){
Intent intent = new Intent(this.context, org.musikcube.Service.class); Intent intent = new Intent(this.context, org.musikcube.Service.class);
@ -402,10 +400,10 @@ public class Library implements Runnable{
} }
catch(IOException x){ catch(IOException x){
Log.e("Library::WriteThread","IOException error"); //Log.e("Library::WriteThread","IOException error");
} }
catch(Exception x){ catch(Exception x){
Log.e("Library::WriteThread","E "+x.getMessage()); //Log.e("Library::WriteThread","E "+x.getMessage());
} }
this.SetStatus(STATUS_SHUTDOWN); this.SetStatus(STATUS_SHUTDOWN);
@ -414,7 +412,7 @@ public class Library implements Runnable{
try { try {
this.socket.close(); this.socket.close();
} catch (Exception x) { } catch (Exception x) {
Log.e("Library::WriteThread","E "+x.getMessage()); //Log.e("Library::WriteThread","E "+x.getMessage());
} }
//Log.v("Library::WriteThread","Ended"); //Log.v("Library::WriteThread","Ended");
@ -435,13 +433,13 @@ public class Library implements Runnable{
this.socket.close(); this.socket.close();
} }
catch(Exception x){ catch(Exception x){
Log.e("Library::Disconnect","Exception error "+x.getMessage()); //Log.e("Library::Disconnect","Exception error "+x.getMessage());
} }
try{ try{
this.thread.join(); this.thread.join();
} }
catch(Exception x){ catch(Exception x){
Log.e("Library::Disconnect","Exception error "+x.getMessage()); //Log.e("Library::Disconnect","Exception error "+x.getMessage());
} }
} }

View File

@ -31,17 +31,6 @@ public class Player implements TrackPlayer.OnTrackStatusListener{
} }
return Player.player; return Player.player;
} }
/*
private synchronized void StartThread(){
synchronized(lock){
if(this.running==false){
this.thread = new Thread(this);
this.running = true;
this.thread.start();
}
}
}
*/
public void Play(java.util.ArrayList<Integer> playlist,int position){ public void Play(java.util.ArrayList<Integer> playlist,int position){