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:excludeFromRecents="true"
|
||||
android:launchMode="singleInstance" />
|
||||
<activity
|
||||
android:name="SongSelector"
|
||||
android:windowSoftInputMode="adjustResize" />
|
||||
<service android:name="PlaybackService" />
|
||||
<activity android:name="PreferencesActivity" />
|
||||
</application>
|
||||
@ -41,4 +38,4 @@
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<supports-screens android:smallScreens="true" />
|
||||
</manifest>
|
||||
</manifest>
|
@ -21,6 +21,7 @@ package org.kreed.vanilla;
|
||||
import org.kreed.vanilla.IPlaybackService;
|
||||
import org.kreed.vanilla.R;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.graphics.Color;
|
||||
@ -58,6 +59,8 @@ public class NowPlayingActivity extends PlaybackServiceActivity implements View.
|
||||
private int mDuration;
|
||||
private boolean mSeekBarTracking;
|
||||
|
||||
private static final int SONG_SELECTOR = 8;
|
||||
|
||||
private static final int MENU_QUIT = 0;
|
||||
private static final int MENU_PREFS = 2;
|
||||
private static final int MENU_LIBRARY = 3;
|
||||
@ -229,7 +232,7 @@ public class NowPlayingActivity extends PlaybackServiceActivity implements View.
|
||||
startActivity(new Intent(this, PreferencesActivity.class));
|
||||
break;
|
||||
case MENU_LIBRARY:
|
||||
onSearchRequested();
|
||||
showDialog(SONG_SELECTOR);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -239,10 +242,18 @@ public class NowPlayingActivity extends PlaybackServiceActivity implements View.
|
||||
@Override
|
||||
public boolean onSearchRequested()
|
||||
{
|
||||
startActivity(new Intent(this, SongSelector.class));
|
||||
showDialog(SONG_SELECTOR);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(int id)
|
||||
{
|
||||
if (id == SONG_SELECTOR)
|
||||
return new SongSelector(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
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) {
|
||||
case KeyEvent.KEYCODE_BACK:
|
||||
quit(activity);
|
||||
quit(context);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -97,9 +97,9 @@ public abstract class PlaybackServiceActivity extends Activity implements Servic
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -22,13 +22,13 @@ import java.util.Arrays;
|
||||
|
||||
import org.kreed.vanilla.R;
|
||||
|
||||
import android.app.TabActivity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.PaintDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.Editable;
|
||||
@ -40,7 +40,6 @@ import android.view.KeyEvent;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Filter;
|
||||
import android.widget.LinearLayout;
|
||||
@ -49,7 +48,7 @@ import android.widget.TabHost;
|
||||
import android.widget.TextView;
|
||||
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 TextView mTextFilter;
|
||||
private View mClearButton;
|
||||
@ -74,24 +73,20 @@ public class SongSelector extends TabActivity implements AdapterView.OnItemClick
|
||||
ListView view = (ListView)findViewById(id);
|
||||
view.setOnItemClickListener(this);
|
||||
view.setOnCreateContextMenuListener(this);
|
||||
view.setAdapter(new MediaAdapter(this, songs, lineA, lineB, expanderListener));
|
||||
view.setAdapter(new MediaAdapter(getContext(), songs, lineA, lineB, expanderListener));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle)
|
||||
public SongSelector(Context context)
|
||||
{
|
||||
super.onCreate(icicle);
|
||||
|
||||
ContextApplication.addActivity(this);
|
||||
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
super(context, android.R.style.Theme_Black_NoTitleBar);
|
||||
|
||||
setContentView(R.layout.song_selector);
|
||||
|
||||
mTabHost = getTabHost();
|
||||
mTabHost = (TabHost)findViewById(android.R.id.tabhost);
|
||||
mTabHost.setup();
|
||||
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_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));
|
||||
@ -104,7 +99,7 @@ public class SongSelector extends TabActivity implements AdapterView.OnItemClick
|
||||
|
||||
mLimiterViews = (ViewGroup)findViewById(R.id.limiter_layout);
|
||||
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
int inputType;
|
||||
if (settings.getBoolean("phone_input", false))
|
||||
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
|
||||
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;
|
||||
String title = intent.getStringExtra("title");
|
||||
String text = getResources().getString(action, title);
|
||||
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
|
||||
String text = getContext().getResources().getString(action, title);
|
||||
Toast.makeText(getContext(), text, Toast.LENGTH_SHORT).show();
|
||||
|
||||
intent.removeExtra("title");
|
||||
startService(intent);
|
||||
getContext().startService(intent);
|
||||
}
|
||||
|
||||
private void expand(MediaAdapter.MediaView view)
|
||||
@ -228,7 +216,7 @@ public class SongSelector extends TabActivity implements AdapterView.OnItemClick
|
||||
PaintDrawable background = new PaintDrawable(Color.GRAY);
|
||||
background.setCornerRadius(5);
|
||||
|
||||
TextView view = new TextView(this);
|
||||
TextView view = new TextView(getContext());
|
||||
view.setSingleLine();
|
||||
view.setEllipsize(TextUtils.TruncateAt.MARQUEE);
|
||||
view.setText(data.getField(i) + " | X");
|
||||
@ -306,6 +294,6 @@ public class SongSelector extends TabActivity implements AdapterView.OnItemClick
|
||||
@Override
|
||||
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