DroidFish: Improved handling of movelist scrolling when navigation bar

is enabled/disabled and when the analysis view gets smaller/larger.
This commit is contained in:
Peter Osterlund 2015-12-31 21:30:54 +01:00
parent afcb7d2509
commit 8420e628e1
6 changed files with 86 additions and 49 deletions

View File

@ -75,10 +75,23 @@
android:fontFamily="monospace"
android:typeface="monospace"
android:textSize="12sp"/>
<RelativeLayout
<view
class="org.petero.droidfish.MyRelativeLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<view
class="org.petero.droidfish.MoveListView"
android:id="@+id/moveList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:includeFontPadding="true"
android:padding="0dp"/>
</ScrollView>
<view
class="org.petero.droidfish.MyScrollView"
android:id="@+id/scrollViewBot"
@ -94,20 +107,7 @@
android:typeface="monospace"
android:textSize="12sp"/>
</view>
<ScrollView
android:id="@+id/scrollView"
android:layout_above="@+id/scrollViewBot"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<view
class="org.petero.droidfish.MoveListView"
android:id="@+id/moveList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:includeFontPadding="true"
android:padding="0dp"/>
</ScrollView>
</RelativeLayout>
</view>
</LinearLayout>
</LinearLayout>
<include layout="@layout/left_drawer"/>

View File

@ -69,10 +69,23 @@
android:layout_height="32dp">
</ImageButton>
</LinearLayout>
<RelativeLayout
<view
class="org.petero.droidfish.MyRelativeLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<view
class="org.petero.droidfish.MoveListView"
android:id="@+id/moveList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:includeFontPadding="true"
android:padding="0dp"/>
</ScrollView>
<view
class="org.petero.droidfish.MyScrollView"
android:id="@+id/scrollViewBot"
@ -88,20 +101,7 @@
android:typeface="monospace"
android:textSize="12sp"/>
</view>
<ScrollView
android:id="@+id/scrollView"
android:layout_above="@+id/scrollViewBot"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<view
class="org.petero.droidfish.MoveListView"
android:id="@+id/moveList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:includeFontPadding="true"
android:padding="0dp"/>
</ScrollView>
</RelativeLayout>
</view>
</LinearLayout>
<include layout="@layout/left_drawer"/>
<include layout="@layout/right_drawer"/>

View File

@ -70,10 +70,23 @@
android:fontFamily="monospace"
android:typeface="monospace"
android:textSize="12sp"/>
<RelativeLayout
<view
class="org.petero.droidfish.MyRelativeLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<view
class="org.petero.droidfish.MoveListView"
android:id="@+id/moveList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:includeFontPadding="true"
android:padding="0dp"/>
</ScrollView>
<view
class="org.petero.droidfish.MyScrollView"
android:id="@+id/scrollViewBot"
@ -89,20 +102,7 @@
android:typeface="monospace"
android:textSize="12sp"/>
</view>
<ScrollView
android:id="@+id/scrollView"
android:layout_above="@+id/scrollViewBot"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<view
class="org.petero.droidfish.MoveListView"
android:id="@+id/moveList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:includeFontPadding="true"
android:padding="0dp"/>
</ScrollView>
</RelativeLayout>
</view>
</LinearLayout>
<view
class="org.petero.droidfish.ChessBoardPlay"

View File

@ -31,6 +31,7 @@ import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewParent;
/** Custom view for displaying move list.
* This is much faster than using a TextView. */
@ -125,8 +126,14 @@ public class MoveListView extends View {
createLayout(width);
int height = 0;
if (layout != null)
if (layout != null) {
height = layout.getLineCount() * getLineHeight();
ViewParent p = getParent();
if (p != null)
p = p.getParent();
if (p instanceof MyRelativeLayout)
height += -getLineHeight() + ((MyRelativeLayout)p).getNewHeight();
}
switch (MeasureSpec.getMode(heightMeasureSpec)) {
case MeasureSpec.UNSPECIFIED:
break;

View File

@ -0,0 +1,31 @@
package org.petero.droidfish;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
/** A RelativeLayout with the addition that child widgets can ask
* about the new parent size during onMeasure(). */
public class MyRelativeLayout extends RelativeLayout {
private int newWidth;
private int newHeight;
public MyRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
newWidth = MeasureSpec.getSize(widthMeasureSpec);
newHeight = MeasureSpec.getSize(heightMeasureSpec);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
public int getNewWidth() {
return newWidth;
}
public int getNewHeight() {
return newHeight;
}
}

View File

@ -20,7 +20,6 @@ package org.petero.droidfish;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ScrollView;
/** A ScrollView that uses at most 75% of the parent height. */
@ -35,8 +34,8 @@ public class MyScrollView extends ScrollView {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getMeasuredWidth();
int height = getMeasuredHeight();
if (getParent() instanceof View) {
int parentHeight = ((View)getParent()).getHeight();
if (getParent() instanceof MyRelativeLayout) {
int parentHeight = ((MyRelativeLayout)getParent()).getNewHeight();
if (parentHeight > 0)
height = Math.min(height, parentHeight * 3 / 4);
}