Long press back finish activity and disconnects from service

This commit is contained in:
Christopher Eby 2010-03-12 22:45:19 -06:00
parent f1e7c0d425
commit ca7fcd82c6
4 changed files with 51 additions and 4 deletions

View File

@ -21,7 +21,6 @@ package org.kreed.vanilla;
import org.kreed.vanilla.IPlaybackService;
import org.kreed.vanilla.R;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@ -47,7 +46,7 @@ import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
public class NowPlayingActivity extends Activity implements ServiceConnection, View.OnClickListener, SeekBar.OnSeekBarChangeListener, View.OnFocusChangeListener {
public class NowPlayingActivity extends PlaybackServiceActivity implements ServiceConnection, View.OnClickListener, SeekBar.OnSeekBarChangeListener, View.OnFocusChangeListener {
private IPlaybackService mService;
private ViewGroup mLayout;

View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 2010 Christopher Eby <kreed@kreed.org>
*
* This file is part of Vanilla Music Player.
*
* Vanilla Music Player is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Vanilla Music Player is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.kreed.vanilla;
import android.app.Activity;
import android.content.Intent;
import android.view.KeyEvent;
public class PlaybackServiceActivity extends Activity {
public static boolean handleKeyLongPress(Activity activity, int keyCode)
{
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
activity.stopService(new Intent(activity, PlaybackService.class));
activity.finish();
return true;
}
return false;
}
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event)
{
return handleKeyLongPress(this, keyCode);
}
}

View File

@ -21,7 +21,6 @@ package org.kreed.vanilla;
import org.kreed.vanilla.IPlaybackService;
import org.kreed.vanilla.R;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@ -36,7 +35,7 @@ import android.view.View;
import android.view.Window;
import android.widget.ImageView;
public class RemoteActivity extends Activity implements ServiceConnection, View.OnClickListener {
public class RemoteActivity extends PlaybackServiceActivity implements ServiceConnection, View.OnClickListener {
private CoverView mCoverView;
private View mOpenButton;

View File

@ -280,4 +280,10 @@ public class SongSelector extends TabActivity implements AdapterView.OnItemClick
for (int i = 3; --i != -1; )
getAdapter(i).getFilter().filter(text);
}
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event)
{
return PlaybackServiceActivity.handleKeyLongPress(this, keyCode);
}
}