Added double back button press for exit

This commit is contained in:
Ziver Koc 2014-08-01 10:58:55 +02:00
parent ff7138bf9d
commit e5ca4aea34
3 changed files with 26 additions and 14 deletions

View file

@ -1,18 +1,18 @@
package com.ericsson.uecontrol.gui;
import android.app.ActionBar;
import android.app.FragmentManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import com.ericsson.uecontrol.R;
import com.ericsson.uecontrol.core.UeControlExecutor;
import com.ericsson.uecontrol.core.behaviour.UeBehaviourFtp;
import com.ericsson.uecontrol.core.behaviour.UeBehaviourSleep;
import com.ericsson.uecontrol.core.behaviour.UeBehaviourSurfing;
import com.ericsson.uecontrol.gui.fragments.BehaviourListFragment;
@ -28,6 +28,7 @@ public class MainActivity extends FragmentActivity {
*/
private NavigationDrawerFragment navigationDrawerFragment;
private StatusFragment statusFragment;
private boolean backButtonPressed = false;
private static UeControlExecutor currentExecutor;
private static CSVWriter logger;
@ -86,6 +87,7 @@ public class MainActivity extends FragmentActivity {
if(currentExecutor.isRunning()){
currentExecutor.terminate();
item.setTitle(R.string.action_run);
logger = null;
}
else {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
@ -120,4 +122,22 @@ public class MainActivity extends FragmentActivity {
logger.write(currentExecutor.getRunningBehaviour().getName(), downThroughput, upThroughput);
}
@Override
public void onBackPressed() {
if (backButtonPressed) {
super.onBackPressed();
return;
}
this.backButtonPressed = true;
Toast.makeText(this, "Press BACK again to Exit", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
backButtonPressed = false;
}
}, 2000);
}
}

View file

@ -61,16 +61,6 @@ public class CSVWriter {
}
public void write(String behaviour){
StringBuilder line = new StringBuilder();
line.append(getTime()).append(DELIMITER);
line.append(behaviour).append(DELIMITER);
line.append(DELIMITER);
line.append(DELIMITER);
line.append(getRat()).append(DELIMITER);
writeLine(line.toString());
}
public void write(String behaviour, double down, double up){
StringBuilder line = new StringBuilder();
line.append(getTime()).append(DELIMITER);

View file

@ -30,7 +30,8 @@
android:id="@+id/down_speed"
android:textColor="#ffffffff"
android:typeface="sans"
android:layout_weight="0" />
android:layout_weight="0"
android:layout_marginLeft="3dp" />
<Space
android:layout_width="wrap_content"
@ -51,7 +52,8 @@
android:id="@+id/up_speed"
android:textColor="#ffffffff"
android:typeface="sans"
android:layout_weight="0.45" />
android:layout_weight="0.45"
android:layout_marginLeft="3dp" />
</LinearLayout>