Remove MiniPlaybackActivityLayout
This commit is contained in:
parent
fc3ce9f551
commit
52377a86de
@ -20,17 +20,21 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
-->
|
||||
<org.kreed.vanilla.MiniPlaybackActivityLayout
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content">
|
||||
<org.kreed.vanilla.CoverView
|
||||
android:id="@+id/cover_view"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="0px"
|
||||
android:layout_width="wrap_content" />
|
||||
<LinearLayout
|
||||
android:layout_gravity="center"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="horizontal">
|
||||
<ImageButton
|
||||
android:id="@+id/previous"
|
||||
@ -57,4 +61,4 @@ THE SOFTWARE.
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/next" />
|
||||
</LinearLayout>
|
||||
</org.kreed.vanilla.MiniPlaybackActivityLayout>
|
||||
</LinearLayout>
|
||||
|
@ -388,4 +388,25 @@ public final class CoverView extends View implements Handler.Callback {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthSpec, int heightSpec)
|
||||
{
|
||||
// This implementation only tries to handle two cases: use in the
|
||||
// FullPlaybackActivity, where we want to fill the whole screen,
|
||||
// and use in the MiniPlaybackActivity, where we want to be square.
|
||||
|
||||
int width = View.MeasureSpec.getSize(widthSpec);
|
||||
int height = View.MeasureSpec.getSize(heightSpec);
|
||||
|
||||
if (View.MeasureSpec.getMode(widthSpec) == View.MeasureSpec.EXACTLY
|
||||
&& View.MeasureSpec.getMode(heightSpec) == View.MeasureSpec.EXACTLY) {
|
||||
// FullPlaybackActivity: fill screen
|
||||
setMeasuredDimension(width, height);
|
||||
} else {
|
||||
// MiniPlaybackActivity: be square
|
||||
int size = Math.min(width, height);
|
||||
setMeasuredDimension(size, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Christopher Eby <kreed@kreed.org>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.kreed.vanilla;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
/**
|
||||
* Custom layout that acts like a very simple vertical LinearLayout with
|
||||
* special case: CoverViews will be made square at all costs.
|
||||
*/
|
||||
public 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user