From 8b9e7a63b735d3fa5126689e784a9dc8769fe0dd Mon Sep 17 00:00:00 2001 From: Christopher Eby Date: Sun, 21 Mar 2010 16:43:52 -0500 Subject: [PATCH] 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 --- AndroidManifest.xml | 12 +-- .../{now_playing.xml => full_playback.xml} | 0 .../{remote_dialog.xml => mini_playback.xml} | 4 +- ...ctivity.java => FullPlaybackActivity.java} | 4 +- ...ctivity.java => MiniPlaybackActivity.java} | 81 +++++++++++++++- ...iceActivity.java => PlaybackActivity.java} | 2 +- src/org/kreed/vanilla/PlaybackService.java | 2 +- .../kreed/vanilla/PreferencesActivity.java | 2 +- src/org/kreed/vanilla/RemoteLayout.java | 94 ------------------- src/org/kreed/vanilla/SongNotification.java | 2 +- src/org/kreed/vanilla/SongSelector.java | 2 +- 11 files changed, 93 insertions(+), 112 deletions(-) rename res/layout/{now_playing.xml => full_playback.xml} (100%) rename res/layout/{remote_dialog.xml => mini_playback.xml} (92%) rename src/org/kreed/vanilla/{NowPlayingActivity.java => FullPlaybackActivity.java} (97%) rename src/org/kreed/vanilla/{RemoteActivity.java => MiniPlaybackActivity.java} (54%) rename src/org/kreed/vanilla/{PlaybackServiceActivity.java => PlaybackActivity.java} (97%) delete mode 100644 src/org/kreed/vanilla/RemoteLayout.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index b0516933..e680643a 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -7,7 +7,7 @@ android:label="@string/app_name" android:name="ContextApplication"> @@ -15,6 +15,11 @@ + @@ -26,11 +31,6 @@ android:name="android.appwidget.provider" android:resource="@xml/one_cell_widget" /> - diff --git a/res/layout/now_playing.xml b/res/layout/full_playback.xml similarity index 100% rename from res/layout/now_playing.xml rename to res/layout/full_playback.xml diff --git a/res/layout/remote_dialog.xml b/res/layout/mini_playback.xml similarity index 92% rename from res/layout/remote_dialog.xml rename to res/layout/mini_playback.xml index ffb9c9f9..9b2afea1 100644 --- a/res/layout/remote_dialog.xml +++ b/res/layout/mini_playback.xml @@ -1,5 +1,5 @@ - @@ -31,4 +31,4 @@ android:layout_marginRight="15px" android:src="@drawable/kill" /> - \ No newline at end of file + \ No newline at end of file diff --git a/src/org/kreed/vanilla/NowPlayingActivity.java b/src/org/kreed/vanilla/FullPlaybackActivity.java similarity index 97% rename from src/org/kreed/vanilla/NowPlayingActivity.java rename to src/org/kreed/vanilla/FullPlaybackActivity.java index c4a7fc1a..3e551863 100644 --- a/src/org/kreed/vanilla/NowPlayingActivity.java +++ b/src/org/kreed/vanilla/FullPlaybackActivity.java @@ -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); diff --git a/src/org/kreed/vanilla/RemoteActivity.java b/src/org/kreed/vanilla/MiniPlaybackActivity.java similarity index 54% rename from src/org/kreed/vanilla/RemoteActivity.java rename to src/org/kreed/vanilla/MiniPlaybackActivity.java index 2d433afa..a7b5a80a 100644 --- a/src/org/kreed/vanilla/RemoteActivity.java +++ b/src/org/kreed/vanilla/MiniPlaybackActivity.java @@ -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; + } + } + } } \ No newline at end of file diff --git a/src/org/kreed/vanilla/PlaybackServiceActivity.java b/src/org/kreed/vanilla/PlaybackActivity.java similarity index 97% rename from src/org/kreed/vanilla/PlaybackServiceActivity.java rename to src/org/kreed/vanilla/PlaybackActivity.java index b5e1efce..63d5c153 100644 --- a/src/org/kreed/vanilla/PlaybackServiceActivity.java +++ b/src/org/kreed/vanilla/PlaybackActivity.java @@ -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 diff --git a/src/org/kreed/vanilla/PlaybackService.java b/src/org/kreed/vanilla/PlaybackService.java index b87af60e..c48cde13 100644 --- a/src/org/kreed/vanilla/PlaybackService.java +++ b/src/org/kreed/vanilla/PlaybackService.java @@ -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 { diff --git a/src/org/kreed/vanilla/PreferencesActivity.java b/src/org/kreed/vanilla/PreferencesActivity.java index 68e9ba26..d0f2a5e0 100644 --- a/src/org/kreed/vanilla/PreferencesActivity.java +++ b/src/org/kreed/vanilla/PreferencesActivity.java @@ -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); } } \ No newline at end of file diff --git a/src/org/kreed/vanilla/RemoteLayout.java b/src/org/kreed/vanilla/RemoteLayout.java deleted file mode 100644 index 298d5930..00000000 --- a/src/org/kreed/vanilla/RemoteLayout.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2010 Christopher Eby - * - * 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 . - */ - -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; - } - } - } -} \ No newline at end of file diff --git a/src/org/kreed/vanilla/SongNotification.java b/src/org/kreed/vanilla/SongNotification.java index 8863c1c4..2567b0b6 100644 --- a/src/org/kreed/vanilla/SongNotification.java +++ b/src/org/kreed/vanilla/SongNotification.java @@ -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); } } \ No newline at end of file diff --git a/src/org/kreed/vanilla/SongSelector.java b/src/org/kreed/vanilla/SongSelector.java index cb2fe400..a560d63c 100644 --- a/src/org/kreed/vanilla/SongSelector.java +++ b/src/org/kreed/vanilla/SongSelector.java @@ -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); } } \ No newline at end of file