diff --git a/app/src/main/java/com/ericsson/uecontrol/core/UeControlExecutor.java b/app/src/main/java/com/ericsson/uecontrol/core/UeControlExecutor.java index 8f2050a..277f087 100755 --- a/app/src/main/java/com/ericsson/uecontrol/core/UeControlExecutor.java +++ b/app/src/main/java/com/ericsson/uecontrol/core/UeControlExecutor.java @@ -212,6 +212,9 @@ public class UeControlExecutor implements Runnable{ public void setDeviceBasedThroughput(boolean enable){ throughputUpdateRunnable.deviceBasedThroughput = enable; } + public void setThroughputFrequency(float throughputFrequency) { + throughputUpdateRunnable.setThroughputFrequency(throughputFrequency); + } public static interface ExecutionListener { @@ -284,5 +287,10 @@ public class UeControlExecutor implements Runnable{ previousTxBytes = currentTxBytes; return ret; } + + public void setThroughputFrequency(float throughputFrequency) { + downloadSpeed.setFrequency(throughputFrequency); + uploadSpeed.setFrequency(throughputFrequency); + } } } diff --git a/app/src/main/java/com/ericsson/uecontrol/core/util/ThroughputCalculator.java b/app/src/main/java/com/ericsson/uecontrol/core/util/ThroughputCalculator.java index 3001684..85f0507 100755 --- a/app/src/main/java/com/ericsson/uecontrol/core/util/ThroughputCalculator.java +++ b/app/src/main/java/com/ericsson/uecontrol/core/util/ThroughputCalculator.java @@ -4,19 +4,20 @@ package com.ericsson.uecontrol.core.util; * Created by ezivkoc on 2014-07-22. */ public class ThroughputCalculator { - public static final int UPDATES_PER_SEC = 2; + public static final float UPDATES_PER_SEC = 2; public static final double NANOSEC_PER_SECOND = 1000000000.0; private boolean updated; private double throughput; private long previousTimeStamp; private long data_amount; + private float frequency = UPDATES_PER_SEC; public void setHandledData(long bytes){ long currentTimeStamp = System.nanoTime(); data_amount += bytes; - if(currentTimeStamp - (NANOSEC_PER_SECOND/UPDATES_PER_SEC) > previousTimeStamp) { + if(currentTimeStamp - (NANOSEC_PER_SECOND/frequency) > previousTimeStamp) { throughput = data_amount / ((currentTimeStamp - previousTimeStamp) / NANOSEC_PER_SECOND); previousTimeStamp = currentTimeStamp; data_amount = 0; @@ -36,4 +37,11 @@ public class ThroughputCalculator { public boolean isUpdated(){ return updated; } + + public void setFrequency(float frequency) { + if(frequency < 0) + this.frequency = UPDATES_PER_SEC; + else + this.frequency = frequency; + } } diff --git a/app/src/main/java/com/ericsson/uecontrol/gui/MainActivity.java b/app/src/main/java/com/ericsson/uecontrol/gui/MainActivity.java index ba6bd1a..1a84b82 100755 --- a/app/src/main/java/com/ericsson/uecontrol/gui/MainActivity.java +++ b/app/src/main/java/com/ericsson/uecontrol/gui/MainActivity.java @@ -21,6 +21,7 @@ import com.ericsson.uecontrol.core.UeControlExecutor; import com.ericsson.uecontrol.core.UeControlExecutor.ExecutionListener; import com.ericsson.uecontrol.core.behaviour.UeBehaviourSleep; import com.ericsson.uecontrol.core.behaviour.UeBehaviourSurfing; +import com.ericsson.uecontrol.core.util.ThroughputCalculator; import com.ericsson.uecontrol.gui.fragments.BehaviourListFragment; import com.ericsson.uecontrol.gui.fragments.ExecNotification; import com.ericsson.uecontrol.gui.fragments.FileBrowserDialog; @@ -75,6 +76,7 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference log.info("Creating new instance of executor"); executor = new UeControlExecutor(); executor.setDeviceBasedThroughput(Boolean.parseBoolean(prefs.getString("throughput_type", "false"))); + executor.setThroughputFrequency(Float.parseFloat(prefs.getString("throughput_average_freq", "" + ThroughputCalculator.UPDATES_PER_SEC))); File input = new File(this.getFilesDir(), BEHAVIOUR_SAVE_FILE); if (input.exists()) { try { @@ -142,6 +144,16 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference if(executor != null) executor.setDeviceBasedThroughput(Boolean.parseBoolean(sharedPreferences.getString("throughput_type", "false"))); } + else if(key.equals("throughput_average_freq")){ + float frequency = Float.parseFloat(sharedPreferences.getString("throughput_average_freq", ""+ThroughputCalculator.UPDATES_PER_SEC)); + log.info("Device Throughput Frequency set to: "+frequency); + if(executor != null) + executor.setThroughputFrequency(frequency); + if(statusFragment != null) { + statusFragment.reset(); + statusFragment.updateGraphLength(); + } + } } @@ -305,7 +317,7 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference } @Override protected void onDestroy() { - if(executor != null){ + if(executor != null && isFinishing()){ executor.terminateNonBlock(); executor.reset(); executor = null; diff --git a/app/src/main/java/com/ericsson/uecontrol/gui/fragments/StatusFragment.java b/app/src/main/java/com/ericsson/uecontrol/gui/fragments/StatusFragment.java index cd2d9c5..6b6b796 100755 --- a/app/src/main/java/com/ericsson/uecontrol/gui/fragments/StatusFragment.java +++ b/app/src/main/java/com/ericsson/uecontrol/gui/fragments/StatusFragment.java @@ -1,9 +1,11 @@ package com.ericsson.uecontrol.gui.fragments; import android.app.Fragment; +import android.content.SharedPreferences; import android.graphics.Color; import android.os.Bundle; import android.os.Handler; +import android.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -28,15 +30,19 @@ import com.jjoe64.graphview.LineGraphView; * Created by ezivkoc on 2014-07-15. */ public class StatusFragment extends Fragment { + private static final int GRAPH_TIME_LENGTH = 60; // in seconds + private ImageView down_img; private TextView down_speed; private ImageView up_img; private TextView up_speed; private TextView rat_type; + private LineGraphView graphView; private static GraphViewSeries downGraph; private static GraphViewSeries upGraph; private static int x = 0; + private static int length = (int) (GRAPH_TIME_LENGTH * ThroughputCalculator.UPDATES_PER_SEC); private Handler handler; @@ -62,14 +68,15 @@ public class StatusFragment extends Fragment { upGraph = new GraphViewSeries("Upload Throughput", new GraphViewSeriesStyle(Color.RED, 3), new GraphViewData[]{new GraphViewData(0, 0)}); - LineGraphView graphView = new LineGraphView(this.getActivity(), "GraphView"); + graphView = new LineGraphView(this.getActivity(), "GraphView"); graphView.addSeries(downGraph); graphView.addSeries(upGraph); graphView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); graphView.getGraphViewStyle().setGridStyle(GraphViewStyle.GridStyle.BOTH); graphView.setShowVerticalLabels(false); //graphView.setDrawDataPoints(true); - graphView.setViewPort(0, 120); + updateGraphLength(); + graphView.setViewPort(0, length); graphView.setScrollable(true); graphView.setDisableTouch(true); graphView.scrollToEnd(); @@ -92,8 +99,9 @@ public class StatusFragment extends Fragment { up_speed.setText(StringUtil.getBitThroughputString(upThroughput)); rat_type.setText(CSVWriter.getRat()); - downGraph.appendData(new GraphViewData(x, downThroughput), true, 120); - upGraph.appendData(new GraphViewData(x, upThroughput), true, 120); + graphView.setViewPort(0, length); + downGraph.appendData(new GraphViewData(x, downThroughput), true, length); + upGraph.appendData(new GraphViewData(x, upThroughput), true, length); x++; ExecNotification.update(downThroughput, upThroughput); @@ -143,4 +151,11 @@ public class StatusFragment extends Fragment { }); } + public void updateGraphLength(){ + if(this.getActivity() != null) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity()); + length = (int) (GRAPH_TIME_LENGTH * Float.parseFloat(prefs.getString("throughput_average_freq", "" + ThroughputCalculator.UPDATES_PER_SEC))); + } + } + } \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index d95831f..ad86350 100755 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -25,4 +25,28 @@ false true + + + + Every 10 sec + Every 5 sec + Every 3 sec + Every 2 sec + Every second + 2 times a sec + 3 times a sec + 5 times a sec + 10 times a sec + + + 0.1 + 0.2 + 0.33 + 0.5 + 1 + 2 + 3 + 5 + 10 + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9693c80..9bbac11 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -38,6 +38,8 @@ Clear Join Beta Program Join the Google+ group to get access to the beta releases of the app. + Throughput Averaging Frequency + Frequency per second(Will also impact csv logging frequency) diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index c4e453f..aa19f2b 100755 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -22,6 +22,13 @@ android:entries="@array/throughput_types" android:entryValues="@array/throughput_type_values" android:defaultValue="false" /> +