Rename the main activities to be more consitent

NowPlayingActivity -> FullPlaybackActivity
RemoteActivity -> MiniPlaybackActivity

Also renamed referenced layouts and move the MiniPlaybackActivity layout inside
the main activity file
This commit is contained in:
Christopher Eby 2010-03-21 16:43:52 -05:00
parent 4a24644485
commit 8b9e7a63b7
11 changed files with 93 additions and 112 deletions

View File

@ -7,7 +7,7 @@
android:label="@string/app_name"
android:name="ContextApplication">
<activity
android:name="NowPlayingActivity"
android:name="FullPlaybackActivity"
android:theme="@style/NoBackground"
android:launchMode="singleTop" >
<intent-filter>
@ -15,6 +15,11 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="MiniPlaybackActivity"
android:theme="@android:style/Theme.Dialog"
android:excludeFromRecents="true"
android:launchMode="singleInstance" />
<receiver
android:name=".OneCellWidget"
android:label="Vanilla Music 1x1">
@ -26,11 +31,6 @@
android:name="android.appwidget.provider"
android:resource="@xml/one_cell_widget" />
</receiver>
<activity
android:name="RemoteActivity"
android:theme="@android:style/Theme.Dialog"
android:excludeFromRecents="true"
android:launchMode="singleInstance" />
<service android:name="PlaybackService" />
<activity android:name="PreferencesActivity" />
</application>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<org.kreed.vanilla.RemoteLayout
<org.kreed.vanilla.MiniPlaybackActivityLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
@ -31,4 +31,4 @@
android:layout_marginRight="15px"
android:src="@drawable/kill" />
</LinearLayout>
</org.kreed.vanilla.RemoteLayout>
</org.kreed.vanilla.MiniPlaybackActivityLayout>

View File

@ -40,7 +40,7 @@ import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
public class NowPlayingActivity extends PlaybackServiceActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, View.OnFocusChangeListener {
public class FullPlaybackActivity extends PlaybackActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, View.OnFocusChangeListener {
private IPlaybackService mService;
private ViewGroup mLayout;
@ -69,7 +69,7 @@ public class NowPlayingActivity extends PlaybackServiceActivity implements View.
{
super.onCreate(icicle);
setContentView(R.layout.now_playing);
setContentView(R.layout.full_playback);
mCoverView = (CoverView)findViewById(R.id.cover_view);
mCoverView.setOnClickListener(this);

View File

@ -21,15 +21,18 @@ package org.kreed.vanilla;
import org.kreed.vanilla.IPlaybackService;
import org.kreed.vanilla.R;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;
public class RemoteActivity extends PlaybackServiceActivity implements View.OnClickListener {
public class MiniPlaybackActivity extends PlaybackActivity implements View.OnClickListener {
private View mOpenButton;
private View mKillButton;
private View mPreviousButton;
@ -42,7 +45,7 @@ public class RemoteActivity extends PlaybackServiceActivity implements View.OnCl
super.onCreate(state);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.remote_dialog);
setContentView(R.layout.mini_playback);
mCoverView = (CoverView)findViewById(R.id.cover_view);
@ -86,7 +89,7 @@ public class RemoteActivity extends PlaybackServiceActivity implements View.OnCl
if (view == mKillButton) {
ContextApplication.quit(this);
} else if (view == mOpenButton) {
startActivity(new Intent(this, NowPlayingActivity.class));
startActivity(new Intent(this, FullPlaybackActivity.class));
finish();
} else {
try {
@ -102,4 +105,76 @@ public class RemoteActivity extends PlaybackServiceActivity implements View.OnCl
}
}
}
}
/*
* Custom layout that acts like a very simple vertical LinearLayout with
* special case: CoverViews will be made square at all costs.
*
* I would prefer this to be a nested class, but it does not seem like
* Android's layout inflater supports referencing nested classes in XML.
*/
class MiniPlaybackActivityLayout extends ViewGroup {
private int mCoverSize;
public MiniPlaybackActivityLayout(Context context, AttributeSet attrs)
{
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
int maxHeight = MeasureSpec.getSize(heightMeasureSpec);
int measuredHeight = 0;
int measuredWidth = 0;
View coverView = null;
for (int i = getChildCount(); --i != -1; ) {
View view = getChildAt(i);
if (view instanceof CoverView) {
coverView = view;
} else {
int spec = MeasureSpec.makeMeasureSpec(maxHeight - measuredHeight, MeasureSpec.AT_MOST);
view.measure(widthMeasureSpec, spec);
measuredHeight += view.getMeasuredHeight();
if (view.getMeasuredWidth() > measuredWidth)
measuredWidth = view.getMeasuredWidth();
}
}
if (coverView != null) {
if (measuredHeight + measuredWidth > maxHeight) {
mCoverSize = maxHeight - measuredHeight;
measuredHeight = maxHeight;
} else {
mCoverSize = measuredWidth;
measuredHeight += measuredWidth;
}
}
setMeasuredDimension(measuredWidth, measuredHeight);
}
@Override
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4)
{
int layoutWidth = getMeasuredWidth();
int top = 0;
for (int i = 0, end = getChildCount(); i != end; ++i) {
View view = getChildAt(i);
if (view instanceof CoverView) {
view.layout(0, top, layoutWidth, top + mCoverSize);
top += mCoverSize;
} else {
int height = view.getMeasuredHeight();
int width = view.getMeasuredWidth();
int left = (layoutWidth - width) / 2;
view.layout(left, top, layoutWidth - left, top + height);
top += height;
}
}
}
}

View File

@ -29,7 +29,7 @@ import android.os.Bundle;
import android.os.IBinder;
import android.view.KeyEvent;
public abstract class PlaybackServiceActivity extends Activity implements ServiceConnection {
public abstract class PlaybackActivity extends Activity implements ServiceConnection {
protected CoverView mCoverView;
@Override

View File

@ -145,7 +145,7 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
if (mHandler.hasMessages(GO)) {
mHandler.removeMessages(GO);
Intent launcher = new Intent(this, NowPlayingActivity.class);
Intent launcher = new Intent(this, FullPlaybackActivity.class);
launcher.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(launcher);
} else {

View File

@ -43,6 +43,6 @@ public class PreferencesActivity extends PreferenceActivity {
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event)
{
return PlaybackServiceActivity.handleKeyLongPress(this, keyCode);
return PlaybackActivity.handleKeyLongPress(this, keyCode);
}
}

View File

@ -1,94 +0,0 @@
/*
* 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.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
/*
* RemoteLayout acts like a very simple vertical LinearLayout with special
* case: all CoverViews placed will be made square at all costs.
*/
public class RemoteLayout extends ViewGroup {
private int mCoverSize;
public RemoteLayout(Context context, AttributeSet attrs)
{
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
int maxHeight = MeasureSpec.getSize(heightMeasureSpec);
int measuredHeight = 0;
int measuredWidth = 0;
View coverView = null;
for (int i = getChildCount(); --i != -1; ) {
View view = getChildAt(i);
if (view instanceof CoverView) {
coverView = view;
} else {
int spec = MeasureSpec.makeMeasureSpec(maxHeight - measuredHeight, MeasureSpec.AT_MOST);
view.measure(widthMeasureSpec, spec);
measuredHeight += view.getMeasuredHeight();
if (view.getMeasuredWidth() > measuredWidth)
measuredWidth = view.getMeasuredWidth();
}
}
if (coverView != null) {
if (measuredHeight + measuredWidth > maxHeight) {
mCoverSize = maxHeight - measuredHeight;
measuredHeight = maxHeight;
} else {
mCoverSize = measuredWidth;
measuredHeight += measuredWidth;
}
}
setMeasuredDimension(measuredWidth, measuredHeight);
}
@Override
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4)
{
int layoutWidth = getMeasuredWidth();
int top = 0;
for (int i = 0, end = getChildCount(); i != end; ++i) {
View view = getChildAt(i);
if (view instanceof CoverView) {
view.layout(0, top, layoutWidth, top + mCoverSize);
top += mCoverSize;
} else {
int height = view.getMeasuredHeight();
int width = view.getMeasuredWidth();
int left = (layoutWidth - width) / 2;
view.layout(left, top, layoutWidth - left, top + height);
top += height;
}
}
}
}

View File

@ -42,7 +42,7 @@ public class SongNotification extends Notification {
contentView = views;
icon = statusIcon;
flags |= Notification.FLAG_ONGOING_EVENT;
Intent intent = new Intent(context, remoteView ? RemoteActivity.class : NowPlayingActivity.class);
Intent intent = new Intent(context, remoteView ? MiniPlaybackActivity.class : FullPlaybackActivity.class);
contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
}
}

View File

@ -294,6 +294,6 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event)
{
return PlaybackServiceActivity.handleKeyLongPress(getContext(), keyCode);
return PlaybackActivity.handleKeyLongPress(getContext(), keyCode);
}
}