Add an Activity that shows the log fragment
[strongswan.git] / src / frontends / android / src / org / strongswan / android / ui / LogScrollView.java
1 /*
2 * Copyright (C) 2012 Tobias Brunner
3 * Copyright (C) 2012 Giuliano Grassi
4 * Copyright (C) 2012 Ralf Sager
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 package org.strongswan.android.ui;
19
20 import android.content.Context;
21 import android.util.AttributeSet;
22 import android.view.MotionEvent;
23 import android.view.View;
24 import android.widget.ScrollView;
25
26 public class LogScrollView extends ScrollView
27 {
28 private boolean mAutoScroll = true;
29
30 public LogScrollView(Context context)
31 {
32 super(context);
33 }
34
35 public LogScrollView(Context context, AttributeSet attrs)
36 {
37 super(context, attrs);
38 }
39
40 public LogScrollView(Context context, AttributeSet attrs, int defStyle)
41 {
42 super(context, attrs, defStyle);
43 }
44
45 @Override
46 public boolean onTouchEvent(MotionEvent ev)
47 {
48 /* disable auto-scrolling when the user starts scrolling around */
49 if (ev.getActionMasked() == MotionEvent.ACTION_DOWN)
50 {
51 mAutoScroll = false;
52 }
53 return super.onTouchEvent(ev);
54 }
55
56 /**
57 * Call this to move newly added content into view by scrolling to the bottom.
58 * Nothing happens if auto-scrolling is disabled.
59 */
60 public void autoScroll()
61 {
62 if (mAutoScroll)
63 {
64 fullScroll(View.FOCUS_DOWN);
65 }
66 }
67
68 @Override
69 protected void onScrollChanged(int l, int t, int oldl, int oldt)
70 {
71 super.onScrollChanged(l, t, oldl, oldt);
72 /* if the user scrolls to the bottom we enable auto-scrolling again */
73 if (t == getChildAt(getChildCount() - 1).getHeight() - getHeight())
74 {
75 mAutoScroll = true;
76 }
77 }
78 }