Make SongSelector a dialog
This prevents the NowPlayingActivity from being stopped, so the covers will update in the background when a song is selected in the song selector.
This commit is contained in:
parent
adfbe7f78e
commit
41e63e331f
@ -31,9 +31,6 @@
|
|||||||
android:theme="@android:style/Theme.Dialog"
|
android:theme="@android:style/Theme.Dialog"
|
||||||
android:excludeFromRecents="true"
|
android:excludeFromRecents="true"
|
||||||
android:launchMode="singleInstance" />
|
android:launchMode="singleInstance" />
|
||||||
<activity
|
|
||||||
android:name="SongSelector"
|
|
||||||
android:windowSoftInputMode="adjustResize" />
|
|
||||||
<service android:name="PlaybackService" />
|
<service android:name="PlaybackService" />
|
||||||
<activity android:name="PreferencesActivity" />
|
<activity android:name="PreferencesActivity" />
|
||||||
</application>
|
</application>
|
||||||
|
@ -21,6 +21,7 @@ package org.kreed.vanilla;
|
|||||||
import org.kreed.vanilla.IPlaybackService;
|
import org.kreed.vanilla.IPlaybackService;
|
||||||
import org.kreed.vanilla.R;
|
import org.kreed.vanilla.R;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
@ -58,6 +59,8 @@ public class NowPlayingActivity extends PlaybackServiceActivity implements View.
|
|||||||
private int mDuration;
|
private int mDuration;
|
||||||
private boolean mSeekBarTracking;
|
private boolean mSeekBarTracking;
|
||||||
|
|
||||||
|
private static final int SONG_SELECTOR = 8;
|
||||||
|
|
||||||
private static final int MENU_QUIT = 0;
|
private static final int MENU_QUIT = 0;
|
||||||
private static final int MENU_PREFS = 2;
|
private static final int MENU_PREFS = 2;
|
||||||
private static final int MENU_LIBRARY = 3;
|
private static final int MENU_LIBRARY = 3;
|
||||||
@ -229,7 +232,7 @@ public class NowPlayingActivity extends PlaybackServiceActivity implements View.
|
|||||||
startActivity(new Intent(this, PreferencesActivity.class));
|
startActivity(new Intent(this, PreferencesActivity.class));
|
||||||
break;
|
break;
|
||||||
case MENU_LIBRARY:
|
case MENU_LIBRARY:
|
||||||
onSearchRequested();
|
showDialog(SONG_SELECTOR);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,10 +242,18 @@ public class NowPlayingActivity extends PlaybackServiceActivity implements View.
|
|||||||
@Override
|
@Override
|
||||||
public boolean onSearchRequested()
|
public boolean onSearchRequested()
|
||||||
{
|
{
|
||||||
startActivity(new Intent(this, SongSelector.class));
|
showDialog(SONG_SELECTOR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(int id)
|
||||||
|
{
|
||||||
|
if (id == SONG_SELECTOR)
|
||||||
|
return new SongSelector(this);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyUp(int keyCode, KeyEvent event)
|
public boolean onKeyUp(int keyCode, KeyEvent event)
|
||||||
{
|
{
|
||||||
|
@ -80,11 +80,11 @@ public abstract class PlaybackServiceActivity extends Activity implements Servic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean handleKeyLongPress(Activity activity, int keyCode)
|
public static boolean handleKeyLongPress(Context context, int keyCode)
|
||||||
{
|
{
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
case KeyEvent.KEYCODE_BACK:
|
case KeyEvent.KEYCODE_BACK:
|
||||||
quit(activity);
|
quit(context);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,9 +97,9 @@ public abstract class PlaybackServiceActivity extends Activity implements Servic
|
|||||||
return handleKeyLongPress(this, keyCode);
|
return handleKeyLongPress(this, keyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void quit(Activity activity)
|
protected static void quit(Context context)
|
||||||
{
|
{
|
||||||
activity.stopService(new Intent(activity, PlaybackService.class));
|
context.stopService(new Intent(context, PlaybackService.class));
|
||||||
ContextApplication.finishAllActivities();
|
ContextApplication.finishAllActivities();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,13 +22,13 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
import org.kreed.vanilla.R;
|
import org.kreed.vanilla.R;
|
||||||
|
|
||||||
import android.app.TabActivity;
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.PaintDrawable;
|
import android.graphics.drawable.PaintDrawable;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
@ -40,7 +40,6 @@ import android.view.KeyEvent;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.Filter;
|
import android.widget.Filter;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
@ -49,7 +48,7 @@ import android.widget.TabHost;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class SongSelector extends TabActivity implements AdapterView.OnItemClickListener, TextWatcher, View.OnClickListener, TabHost.OnTabChangeListener, Filter.FilterListener {
|
public class SongSelector extends Dialog implements AdapterView.OnItemClickListener, TextWatcher, View.OnClickListener, TabHost.OnTabChangeListener, Filter.FilterListener {
|
||||||
private TabHost mTabHost;
|
private TabHost mTabHost;
|
||||||
private TextView mTextFilter;
|
private TextView mTextFilter;
|
||||||
private View mClearButton;
|
private View mClearButton;
|
||||||
@ -74,24 +73,20 @@ public class SongSelector extends TabActivity implements AdapterView.OnItemClick
|
|||||||
ListView view = (ListView)findViewById(id);
|
ListView view = (ListView)findViewById(id);
|
||||||
view.setOnItemClickListener(this);
|
view.setOnItemClickListener(this);
|
||||||
view.setOnCreateContextMenuListener(this);
|
view.setOnCreateContextMenuListener(this);
|
||||||
view.setAdapter(new MediaAdapter(this, songs, lineA, lineB, expanderListener));
|
view.setAdapter(new MediaAdapter(getContext(), songs, lineA, lineB, expanderListener));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public SongSelector(Context context)
|
||||||
public void onCreate(Bundle icicle)
|
|
||||||
{
|
{
|
||||||
super.onCreate(icicle);
|
super(context, android.R.style.Theme_Black_NoTitleBar);
|
||||||
|
|
||||||
ContextApplication.addActivity(this);
|
|
||||||
|
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
||||||
|
|
||||||
setContentView(R.layout.song_selector);
|
setContentView(R.layout.song_selector);
|
||||||
|
|
||||||
mTabHost = getTabHost();
|
mTabHost = (TabHost)findViewById(android.R.id.tabhost);
|
||||||
|
mTabHost.setup();
|
||||||
mTabHost.setOnTabChangedListener(this);
|
mTabHost.setOnTabChangedListener(this);
|
||||||
|
|
||||||
Resources res = getResources();
|
Resources res = context.getResources();
|
||||||
mTabHost.addTab(mTabHost.newTabSpec("tab_artists").setIndicator(res.getText(R.string.artists), res.getDrawable(R.drawable.tab_artists)).setContent(R.id.artist_list));
|
mTabHost.addTab(mTabHost.newTabSpec("tab_artists").setIndicator(res.getText(R.string.artists), res.getDrawable(R.drawable.tab_artists)).setContent(R.id.artist_list));
|
||||||
mTabHost.addTab(mTabHost.newTabSpec("tab_albums").setIndicator(res.getText(R.string.albums), res.getDrawable(R.drawable.tab_albums)).setContent(R.id.album_list));
|
mTabHost.addTab(mTabHost.newTabSpec("tab_albums").setIndicator(res.getText(R.string.albums), res.getDrawable(R.drawable.tab_albums)).setContent(R.id.album_list));
|
||||||
mTabHost.addTab(mTabHost.newTabSpec("tab_songs").setIndicator(res.getText(R.string.songs), res.getDrawable(R.drawable.tab_songs)).setContent(R.id.song_list));
|
mTabHost.addTab(mTabHost.newTabSpec("tab_songs").setIndicator(res.getText(R.string.songs), res.getDrawable(R.drawable.tab_songs)).setContent(R.id.song_list));
|
||||||
@ -104,7 +99,7 @@ public class SongSelector extends TabActivity implements AdapterView.OnItemClick
|
|||||||
|
|
||||||
mLimiterViews = (ViewGroup)findViewById(R.id.limiter_layout);
|
mLimiterViews = (ViewGroup)findViewById(R.id.limiter_layout);
|
||||||
|
|
||||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
int inputType;
|
int inputType;
|
||||||
if (settings.getBoolean("phone_input", false))
|
if (settings.getBoolean("phone_input", false))
|
||||||
inputType = InputType.TYPE_CLASS_PHONE;
|
inputType = InputType.TYPE_CLASS_PHONE;
|
||||||
@ -137,13 +132,6 @@ public class SongSelector extends TabActivity implements AdapterView.OnItemClick
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy()
|
|
||||||
{
|
|
||||||
super.onDestroy();
|
|
||||||
ContextApplication.removeActivity(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||||
{
|
{
|
||||||
@ -158,11 +146,11 @@ public class SongSelector extends TabActivity implements AdapterView.OnItemClick
|
|||||||
{
|
{
|
||||||
int action = intent.getIntExtra("action", PlaybackService.ACTION_PLAY) == PlaybackService.ACTION_PLAY ? R.string.playing : R.string.enqueued;
|
int action = intent.getIntExtra("action", PlaybackService.ACTION_PLAY) == PlaybackService.ACTION_PLAY ? R.string.playing : R.string.enqueued;
|
||||||
String title = intent.getStringExtra("title");
|
String title = intent.getStringExtra("title");
|
||||||
String text = getResources().getString(action, title);
|
String text = getContext().getResources().getString(action, title);
|
||||||
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), text, Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
intent.removeExtra("title");
|
intent.removeExtra("title");
|
||||||
startService(intent);
|
getContext().startService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expand(MediaAdapter.MediaView view)
|
private void expand(MediaAdapter.MediaView view)
|
||||||
@ -228,7 +216,7 @@ public class SongSelector extends TabActivity implements AdapterView.OnItemClick
|
|||||||
PaintDrawable background = new PaintDrawable(Color.GRAY);
|
PaintDrawable background = new PaintDrawable(Color.GRAY);
|
||||||
background.setCornerRadius(5);
|
background.setCornerRadius(5);
|
||||||
|
|
||||||
TextView view = new TextView(this);
|
TextView view = new TextView(getContext());
|
||||||
view.setSingleLine();
|
view.setSingleLine();
|
||||||
view.setEllipsize(TextUtils.TruncateAt.MARQUEE);
|
view.setEllipsize(TextUtils.TruncateAt.MARQUEE);
|
||||||
view.setText(data.getField(i) + " | X");
|
view.setText(data.getField(i) + " | X");
|
||||||
@ -306,6 +294,6 @@ public class SongSelector extends TabActivity implements AdapterView.OnItemClick
|
|||||||
@Override
|
@Override
|
||||||
public boolean onKeyLongPress(int keyCode, KeyEvent event)
|
public boolean onKeyLongPress(int keyCode, KeyEvent event)
|
||||||
{
|
{
|
||||||
return PlaybackServiceActivity.handleKeyLongPress(this, keyCode);
|
return PlaybackServiceActivity.handleKeyLongPress(getContext(), keyCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user