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

@@ -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);
}