summaryrefslogtreecommitdiff
path: root/src/de/blinkt/openvpn
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2013-10-13 17:07:30 +0200
committerArne Schwabe <arne@rfc2549.org>2013-10-13 17:07:30 +0200
commitd2dc6fa6fc12ca876bb3dcf099ec6694dc7ef061 (patch)
treefc253400a74c2ce9c74f710d85bd1deeb5abdf7e /src/de/blinkt/openvpn
parent7997868109c0831f2c6d97f342a7e6c6226bf54d (diff)
Add Seekbar with ticks, make a better layout for large screens of the log screen
--HG-- rename : res/layout/logwindow.xml => res/layout-w720dp/logwindow.xml
Diffstat (limited to 'src/de/blinkt/openvpn')
-rw-r--r--src/de/blinkt/openvpn/LogWindow.java51
-rw-r--r--src/de/blinkt/openvpn/fragments/SeekbarTicks.java63
2 files changed, 107 insertions, 7 deletions
diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java
index 11becf9c..1c38705c 100644
--- a/src/de/blinkt/openvpn/LogWindow.java
+++ b/src/de/blinkt/openvpn/LogWindow.java
@@ -23,6 +23,7 @@ import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.*;
import android.widget.AdapterView.OnItemLongClickListener;
+import de.blinkt.openvpn.core.OpenVPNManagement;
import de.blinkt.openvpn.core.VpnStatus;
import de.blinkt.openvpn.core.VpnStatus.ConnectionStatus;
import de.blinkt.openvpn.core.VpnStatus.LogItem;
@@ -38,7 +39,9 @@ import java.util.Date;
import java.util.Locale;
import java.util.Vector;
-public class LogWindow extends ListActivity implements StateListener, SeekBar.OnSeekBarChangeListener, RadioGroup.OnCheckedChangeListener {
+import static de.blinkt.openvpn.core.OpenVpnService.humanReadableByteCount;
+
+public class LogWindow extends ListActivity implements StateListener, SeekBar.OnSeekBarChangeListener, RadioGroup.OnCheckedChangeListener, VpnStatus.ByteCountListener {
private static final String LOGTIMEFORMAT = "logtimeformat";
private static final int START_VPN_CONFIG = 0;
private static final String VERBOSITYLEVEL = "verbositylevel";
@@ -63,11 +66,13 @@ public class LogWindow extends ListActivity implements StateListener, SeekBar.On
private SeekBar mLogLevelSlider;
private LinearLayout mOptionsLayout;
private RadioGroup mTimeRadioGroup;
+ private TextView mUpStatus;
+ private TextView mDownStatus;
+ private TextView mConnectStatus;
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
ladapter.setLogLevel(progress+1);
- Toast.makeText(this,"Loglevel set to " + ladapter.mLogLevel,Toast.LENGTH_SHORT).show();
}
@Override
@@ -96,6 +101,24 @@ public class LogWindow extends ListActivity implements StateListener, SeekBar.On
}
}
+ @Override
+ public void updateByteCount(long in, long out, long diffin, long diffout) {
+ //%2$s/s %1$s - ↑%4$s/s %3$s
+ final String down = String.format("%s/s %s", humanReadableByteCount(in, false), humanReadableByteCount(diffin / OpenVPNManagement.mBytecountInterval, true));
+ final String up = String.format("%s/s %s", humanReadableByteCount(out, false), humanReadableByteCount(diffout / OpenVPNManagement.mBytecountInterval, true));
+
+ if(mUpStatus!=null && mDownStatus!=null) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mUpStatus.setText(up);
+ mDownStatus.setText(down);
+ }
+ });
+ }
+
+ }
+
class LogWindowListAdapter implements ListAdapter, LogListener, Callback {
@@ -179,7 +202,7 @@ public class LogWindow extends ListActivity implements StateListener, SeekBar.On
@Override
public long getItemId(int position) {
- return currentLevelEntries.get(position).hashCode();
+ return ((Object)currentLevelEntries.get(position)).hashCode();
}
@Override
@@ -457,6 +480,9 @@ public class LogWindow extends ListActivity implements StateListener, SeekBar.On
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.logmenu, menu);
+ if (getResources().getBoolean(R.bool.logSildersAlwaysVisible))
+ menu.removeItem(R.id.toggle_time);
+
return true;
}
@@ -465,6 +491,7 @@ public class LogWindow extends ListActivity implements StateListener, SeekBar.On
protected void onResume() {
super.onResume();
VpnStatus.addStateListener(this);
+ VpnStatus.addByteCountListener(this);
Intent intent = new Intent(this, OpenVpnService.class);
intent.setAction(OpenVpnService.START_SERVICE);
@@ -520,6 +547,7 @@ public class LogWindow extends ListActivity implements StateListener, SeekBar.On
protected void onStop() {
super.onStop();
VpnStatus.removeStateListener(this);
+ VpnStatus.removeByteCountListener(this);
unbindService(mConnection);
getPreferences(0).edit().putInt(LOGTIMEFORMAT, ladapter.mTimeFormat)
.putInt(VERBOSITYLEVEL, ladapter.mLogLevel).apply();
@@ -578,22 +606,31 @@ public class LogWindow extends ListActivity implements StateListener, SeekBar.On
mLogLevelSlider.setOnSeekBarChangeListener(this);
+ if(getResources().getBoolean(R.bool.logSildersAlwaysVisible))
+ mOptionsLayout.setVisibility(View.VISIBLE);
+ mUpStatus = (TextView) findViewById(R.id.speedUp);
+ mDownStatus = (TextView) findViewById(R.id.speedDown);
+ mConnectStatus = (TextView) findViewById(R.id.speedStatus);
}
@Override
- public void updateState(final String status,final String logmessage, final int resid, final ConnectionStatus level) {
+ public void updateState(final String status,final String logMessage, final int resId, final ConnectionStatus level) {
runOnUiThread(new Runnable() {
@Override
public void run() {
- String prefix=getString(resid) + ":";
+ String prefix=getString(resId) + ":";
if (status.equals("BYTECOUNT") || status.equals("NOPROCESS") )
prefix="";
- if (resid==R.string.unknown_state)
+ if (resId==R.string.unknown_state)
prefix+=status;
- mSpeedView.setText(prefix + logmessage);
+ if(mSpeedView!=null)
+ mSpeedView.setText(prefix + logMessage);
+
+ if(mConnectStatus!=null)
+ mConnectStatus.setText(getString(resId));
}
});
diff --git a/src/de/blinkt/openvpn/fragments/SeekbarTicks.java b/src/de/blinkt/openvpn/fragments/SeekbarTicks.java
new file mode 100644
index 00000000..1e289529
--- /dev/null
+++ b/src/de/blinkt/openvpn/fragments/SeekbarTicks.java
@@ -0,0 +1,63 @@
+package de.blinkt.openvpn.fragments;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.util.TypedValue;
+import android.view.ViewConfiguration;
+import android.widget.SeekBar;
+
+public class SeekBarTicks extends SeekBar {
+ private Paint mTickPaint;
+ private float mTickHeight;
+
+
+ public SeekBarTicks(Context context, AttributeSet attrs) {
+ super (context, attrs);
+
+ initTicks (context, attrs, android.R.attr.seekBarStyle);
+ }
+
+
+ public SeekBarTicks(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+
+ initTicks (context, attrs, defStyle);
+
+ /*mTickHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
+ tickHeightDP,
+ ctx.getResources().getDisplayMetrics()); */
+ }
+
+ private void initTicks(Context context, AttributeSet attrs, int defStyle) {
+ TypedArray a = context.obtainStyledAttributes(attrs,
+ new int[] { android.R.attr.secondaryProgress }, defStyle, 0);
+
+
+ int tickColor = a.getColor(0, android.R.color.white);
+ mTickPaint = new Paint();
+ mTickPaint.setColor( context.getResources().getColor(tickColor));
+ a.recycle();
+ }
+
+
+ @Override
+ protected synchronized void onDraw(Canvas canvas) {
+ drawTicks(canvas);
+ super.onDraw(canvas);
+ }
+
+ private void drawTicks(Canvas canvas) {
+
+ final int available = getWidth() - getPaddingLeft() - getPaddingRight();
+ int tickSpacing = available / (getMax() );
+
+ for (int i = 1; i < getMax(); i++) {
+ final float x = getPaddingLeft() + i * tickSpacing;
+ canvas.drawLine(x, getPaddingTop(), x, getHeight()-getPaddingBottom(), mTickPaint);
+ }
+ }
+}