diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2013-09-15 19:38:22 +0200 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2013-09-15 19:38:22 +0200 |
commit | 4477d9ad61fcd1d84c56e5708f8125443ea318f2 (patch) | |
tree | 861a8c73164a40b3468705a138b4ec6810f4d6c3 | |
parent | af805fed5376ed931260abf684a5fabfbd830d8a (diff) | |
download | cgeo-4477d9ad61fcd1d84c56e5708f8125443ea318f2.zip cgeo-4477d9ad61fcd1d84c56e5708f8125443ea318f2.tar.gz cgeo-4477d9ad61fcd1d84c56e5708f8125443ea318f2.tar.bz2 |
make test app use auto-scroll
* on special request of Samuel :)
-rw-r--r-- | tests/res/layout/cgeo_tests_activity.xml | 4 | ||||
-rw-r--r-- | tests/src/cgeo/geocaching/test/BottomAwareScrollView.java | 36 | ||||
-rw-r--r-- | tests/src/cgeo/geocaching/test/CgeoTestsActivity.java | 7 |
3 files changed, 45 insertions, 2 deletions
diff --git a/tests/res/layout/cgeo_tests_activity.xml b/tests/res/layout/cgeo_tests_activity.xml index ba87829..43225ac 100644 --- a/tests/res/layout/cgeo_tests_activity.xml +++ b/tests/res/layout/cgeo_tests_activity.xml @@ -21,7 +21,7 @@ android:text="@string/logcat" android:textAppearance="?android:attr/textAppearanceLarge" /> - <ScrollView + <cgeo.geocaching.test.BottomAwareScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="fill_parent" @@ -35,7 +35,7 @@ android:layout_height="wrap_content" android:textSize="8sp" tools:ignore="SmallSp" /> - </ScrollView> + </cgeo.geocaching.test.BottomAwareScrollView> <Button android:id="@+id/buttonRun" diff --git a/tests/src/cgeo/geocaching/test/BottomAwareScrollView.java b/tests/src/cgeo/geocaching/test/BottomAwareScrollView.java new file mode 100644 index 0000000..5735241 --- /dev/null +++ b/tests/src/cgeo/geocaching/test/BottomAwareScrollView.java @@ -0,0 +1,36 @@ +package cgeo.geocaching.test; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.widget.ScrollView; + +public class BottomAwareScrollView extends ScrollView { + + private boolean isAtBottom = true; + + public BottomAwareScrollView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + public BottomAwareScrollView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public BottomAwareScrollView(Context context) { + super(context); + } + + @Override + protected void onScrollChanged(int l, int t, int oldl, int oldt) { + View lastChildView = getChildAt(getChildCount() - 1); + int diff = (lastChildView.getBottom() - (getHeight() + getScrollY())); + isAtBottom = diff <= 0; + super.onScrollChanged(l, t, oldl, oldt); + } + + public boolean isAtBottom() { + return isAtBottom; + } + +} diff --git a/tests/src/cgeo/geocaching/test/CgeoTestsActivity.java b/tests/src/cgeo/geocaching/test/CgeoTestsActivity.java index 8b86f35..0f41cef 100644 --- a/tests/src/cgeo/geocaching/test/CgeoTestsActivity.java +++ b/tests/src/cgeo/geocaching/test/CgeoTestsActivity.java @@ -25,6 +25,8 @@ public class CgeoTestsActivity extends Activity { private TextView logView; private LogcatAsyncTask logCatTask; + private BottomAwareScrollView scrollView; + private class LogcatAsyncTask extends AsyncTask<Integer, String, Void> { // TestRunner and silence others private static final String CMD = "logcat -v brief TestRunner:I cgeo:I *:S"; @@ -44,8 +46,12 @@ public class CgeoTestsActivity extends Activity { @Override protected void onProgressUpdate(String... values) { final String line = values[0]; + final boolean isAtBottom = scrollView.isAtBottom(); if (!TextUtils.isEmpty(line)) { logView.append(Html.fromHtml("<font color=\"" + color(line) + "\">" + line + "</font><br/>")); + if (isAtBottom) { + scrollView.scrollTo(0, logView.getBottom()); + } } } @@ -85,6 +91,7 @@ public class CgeoTestsActivity extends Activity { super.onCreate(savedInstanceState); setContentView(R.layout.cgeo_tests_activity); logView = (TextView) findViewById(R.id.logOutput); + scrollView = (BottomAwareScrollView) findViewById(R.id.scrollView); } @Override |