Added warning icon

Some more work on settings
Configuration dialog finished
This commit is contained in:
Ziver Koc 2014-07-29 09:40:58 +02:00
parent 1aec61f810
commit ba153f5708
17 changed files with 187 additions and 77 deletions

View file

@ -26,6 +26,10 @@
android:name=".gui.EditActivity"
android:label="@string/title_activity_edit" >
</activity>
<activity
android:name=".gui.AboutActivity"
android:label="@string/title_activity_about" >
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

View file

@ -0,0 +1,14 @@
<html>
<body>
<h1>About</h1>
<hr />
This application was developed by Ziver Koc 2014 at Ericsson AB.
<br /><br />
<h3>Attributions:</h3>
<ul>
<li>GraphView (<a href="http://android-graphview.org/">http://android-graphview.org/</a>)</li>
<li>SweetiePlus Icons (<a href="http://sublink.ca/">http://sublink.ca/</a>)</li>
<li>DynamicListView (<a href="https://android.googlesource.com">https://android.googlesource.com</a>)</li>
</ul>
</body>
</html>

View file

@ -17,7 +17,12 @@ public abstract class UeBehaviour {
running = true;
if(execListener != null) execListener.executionStarted();
execute();
try {
execute();
} catch(Exception e){
if(execListener != null) execListener.exception(e);
e.printStackTrace();
}
if(execListener != null) execListener.executionStopped();
}
@ -71,7 +76,7 @@ public abstract class UeBehaviour {
/**
* Executes the behaviour, will block until behaviour has run to completion.
*/
protected abstract void execute();
protected abstract void execute() throws Exception;
/**
* @return the short name of the behaviour
@ -94,6 +99,7 @@ public abstract class UeBehaviour {
public void executionStarted();
public void progressChanged(float progress);
public void executionStopped();
public void exception(Exception e);
}
public static interface DataHandledListener {

View file

@ -22,14 +22,12 @@ public class UeBehaviourSleep extends UeBehaviour{
}
@Override
protected void execute() {
protected void execute() throws InterruptedException {
int elapsedTime = 0;
while(elapsedTime < time){
super.setProgress((float)elapsedTime/time);
if(super.stopExecution()) break;
try{
Thread.sleep(SLEEP_PERIOD);
}catch(Exception e){e.printStackTrace();};
Thread.sleep(SLEEP_PERIOD);
elapsedTime += SLEEP_PERIOD;
}
}

View file

@ -26,28 +26,26 @@ public class UeBehaviourSurfing extends UeBehaviour {
}
@Override
protected void execute() {
try {
URL url = new URL(strUrl);
if(url == null) return;
protected void execute() throws IOException {
if(!strUrl.startsWith("http://") &&
!strUrl.startsWith("ftp://"))
strUrl = "http://"+strUrl;
URL url = new URL(strUrl);
byte[] data = new byte[100];
URLConnection connection = url.openConnection();
connection.setUseCaches(false);
connection.connect();
InputStream in = connection.getInputStream();
byte[] data = new byte[100];
URLConnection connection = url.openConnection();
connection.setUseCaches(false);
connection.connect();
InputStream in = connection.getInputStream();
long total = in.available();
long progress = 0;
long read = 0;
long total = in.available();
long progress = 0;
long read = 0;
while((read = in.read(data)) != -1 && !stopExecution()){
progress += read;
super.setProgress((float)progress/total);
super.setHandledIncomingData(read);
}
} catch (IOException e) {
e.printStackTrace();
while((read = in.read(data)) != -1 && !stopExecution()){
progress += read;
super.setProgress((float)progress/total);
super.setHandledIncomingData(read);
}
}

View file

@ -0,0 +1,19 @@
package com.ericsson.uecontrol.gui;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
/**
* Created by ezivkoc on 2014-07-28.
*/
public class AboutActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView view = new WebView(this);
view.loadUrl("file://assets/www/about.html");
this.setContentView(view);
}
}

View file

@ -11,7 +11,7 @@ import android.widget.ListView;
import com.ericsson.uecontrol.R;
import com.ericsson.uecontrol.core.UeBehaviour;
import com.ericsson.uecontrol.core.UeControlExecutor;
import com.ericsson.uecontrol.gui.fragments.ConfigureBehaviourDialog;
import com.ericsson.uecontrol.gui.fragments.ConfigureDialog;
import com.ericsson.uecontrol.gui.fragments.SelectBehaviourDialog;
import com.ericsson.uecontrol.gui.util.BehaviourListAdapter;
import com.ericsson.uecontrol.gui.util.Configurator;
@ -87,7 +87,7 @@ public class EditActivity extends ListActivity implements AdapterView.OnItemClic
final UeBehaviour behaviour = executor.getBehaviourList().get(i);
Configurator confer = new Configurator(behaviour);
ConfigureBehaviourDialog dialog = new ConfigureBehaviourDialog();
ConfigureDialog dialog = new ConfigureDialog();
dialog.setConfigurator(confer);
dialog.show(getFragmentManager(), "behaviour_configurator");
}

View file

@ -5,7 +5,6 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.TextView;
@ -19,7 +18,7 @@ import java.util.ArrayList;
/**
* This fragment will show a read only list of defined UeBehaviours
*/
public class BehaviourListFragment extends Fragment implements AbsListView.OnItemClickListener {
public class BehaviourListFragment extends Fragment {
/**
* The fragment's ListView/GridView.
@ -67,9 +66,6 @@ public class BehaviourListFragment extends Fragment implements AbsListView.OnIte
listView = (AdapterView) view.findViewById(android.R.id.list);
listView.setAdapter(adapter);
// Set OnItemClickListener so we can be notified on item clicks
//listView.setOnItemClickListener(this);
setEmptyText("No Behaviours Defined");
return view;
@ -83,11 +79,6 @@ public class BehaviourListFragment extends Fragment implements AbsListView.OnIte
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
/**
* The default content for this Fragment has a TextView that is shown when
* the list is empty. If you would like to change the text, call this method

View file

@ -5,6 +5,7 @@ import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.InputType;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -13,14 +14,19 @@ import com.ericsson.uecontrol.R;
import com.ericsson.uecontrol.gui.util.Configurator;
import com.ericsson.uecontrol.gui.util.Configurator.ConfigurationParam;
import java.util.HashMap;
/**
* Created by ezivkoc on 2014-07-24.
*/
public class ConfigureBehaviourDialog extends DialogFragment {
public class ConfigureDialog extends DialogFragment {
private HashMap<String, EditText> inputs;
private Configurator confer;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
inputs = new HashMap<String, EditText>();
// Create dialog
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.configure_behaviour);
@ -30,25 +36,30 @@ public class ConfigureBehaviourDialog extends DialogFragment {
root.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
int padding = getResources().getDimensionPixelSize(R.dimen.standard_padding);
root.setPadding(padding, padding, padding, padding);
for(ConfigurationParam confParam : confer.getConfiguration()){
LinearLayout layout = new LinearLayout(getActivity());
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
LinearLayout.LayoutParams.MATCH_PARENT));
TextView label = new TextView(getActivity());
label.setText("Test: ");
label.setText(confParam.getName()+": ");
label.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
layout.addView(label);
EditText input = new EditText(getActivity());
label.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT));
input.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
input.setText(confParam.getString(), TextView.BufferType.EDITABLE);
input.setInputType(InputType.TYPE_NULL);
inputs.put(confParam.getName(), input);
layout.addView(input);
root.addView(layout);
@ -57,12 +68,15 @@ public class ConfigureBehaviourDialog extends DialogFragment {
builder.setPositiveButton(R.string.action_save, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
for(ConfigurationParam confParam : confer.getConfiguration()){
confParam.setString(inputs.get(confParam.getName()).getText().toString());
}
confer.setConfiguration();
}
});
builder.setNegativeButton(R.string.action_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
ConfigureBehaviourDialog.this.getDialog().cancel();
ConfigureDialog.this.getDialog().cancel();
}
});

View file

@ -38,6 +38,7 @@ public class BehaviourListAdapter extends StableArrayAdapter<UeBehaviour>{
ImageView draggable = (ImageView)vi.findViewById(R.id.draggable);
TextView title = (TextView)vi.findViewById(R.id.title);
TextView description = (TextView)vi.findViewById(R.id.description);
final ImageView warning = (ImageView) vi.findViewById(R.id.warning);
final ProgressBar active = (ProgressBar)vi.findViewById(R.id.active);
final ProgressBar progress = (ProgressBar) vi.findViewById(R.id.progress);
@ -56,6 +57,7 @@ public class BehaviourListAdapter extends StableArrayAdapter<UeBehaviour>{
public void run() {
active.setVisibility(View.VISIBLE);
progress.setVisibility(View.VISIBLE);
warning.setVisibility(View.INVISIBLE);
}
});
}
@ -71,6 +73,13 @@ public class BehaviourListAdapter extends StableArrayAdapter<UeBehaviour>{
}
});
}
public void exception(Exception e){
warning.post(new Runnable() {
public void run() {
warning.setVisibility(View.VISIBLE);
}
});
}
});
return vi;
@ -79,4 +88,5 @@ public class BehaviourListAdapter extends StableArrayAdapter<UeBehaviour>{
public void setEditable(boolean b) {
editable = b;
}
}

View file

@ -25,20 +25,6 @@ public class Configurator {
STRING, INT
}
public static class ConfigurationParam{
protected Field field;
protected ConfigType type;
protected Object value;
public ConfigType getType(){return type;}
public int getInt (){return (Integer) value;}
public String setString(){return (String) value;}
public void setInt (int v) {value = v;}
public void setString(String v){value = v;}
}
private Object obj;
private ConfigurationParam[] params;
@ -52,30 +38,72 @@ public class Configurator {
return params;
}
protected static ConfigurationParam[] getConfiguration(Object obj){
protected ConfigurationParam[] getConfiguration(Object obj){
Class c = obj.getClass();
ArrayList<ConfigurationParam> conf = new ArrayList<ConfigurationParam>();
Field[] all = c.getDeclaredFields();
for(Field f : all){
if(f.isAnnotationPresent(Configurable.class) && !Modifier.isStatic(f.getModifiers())) {
ConfigurationParam confParam = new ConfigurationParam();
confParam.field = f;
conf.add(confParam);
try {
conf.add(new ConfigurationParam(f));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
return conf.toArray(new ConfigurationParam[conf.size()]);
}
protected static void setConfiguration(ConfigurationParam[] params, Object obj){
public void setConfiguration(){
for(ConfigurationParam param : params){
try {
param.field.setAccessible(true);
param.field.set(obj, param.value);
param.set();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
public class ConfigurationParam{
protected Field field;
protected String name;
protected String niceName;
protected ConfigType type;
protected Object value;
protected ConfigurationParam(Field f) throws IllegalAccessException {
field = f;
field.setAccessible(true);
name = field.getName();
niceName = field.getAnnotation(Configurable.class).value();
value = field.get(obj);
if (f.getType() == String.class) type = ConfigType.STRING;
else if(f.getType() == int.class) type = ConfigType.INT;
}
public String getName(){return name;}
public String getNiceName(){return niceName;}
public ConfigType getType(){return type;}
public String getString(){return (String) value;}
public void setString(String v){
switch(type){
case STRING:
value = v; break;
case INT:
value = Integer.parseInt(v); break;
}
}
protected void set() throws IllegalAccessException {
field.set(obj, value);
}
}
}

View file

@ -1,5 +1,7 @@
/*
* Copyright (C) 2013 The Android Open Source Project
* https://android.googlesource.com/platform/development/+/master/samples/devbytes/animation/ListViewDraggingAnimation/src/com/example/android/listviewdragginganimation/DynamicListView.java
* Modified by Ziver Koc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -57,6 +59,7 @@ import android.widget.ListView;
* <p/>
* When the hover cell is either above or below the bounds of the listview, this
* listview also scrolls on its own so as to reveal additional content.
*
*/
public class DynamicListView extends ListView {
private static final int INVALID_POINTER_ID = -1;

Binary file not shown.

After

Width:  |  Height:  |  Size: 954 B

View file

@ -44,7 +44,7 @@
android:layout_toEndOf="@+id/draggable"/>
<!-- Rightend Arrow -->
<!-- Rightend -->
<ProgressBar
android:id="@+id/active"
style="?android:attr/progressBarStyleSmall"
@ -55,6 +55,17 @@
android:layout_marginRight="10dp"
android:visibility="invisible" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/warning"
android:layout_alignParentTop="true"
android:src="@drawable/warning"
android:layout_marginRight="5dp"
android:layout_centerVertical="true"
android:visibility="invisible"
android:layout_toLeftOf="@id/active"/>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"

View file

@ -6,4 +6,6 @@
<!-- Per the design guidelines, navigation drawers should be between 240dp and 320dp:
https://developer.android.com/design/patterns/navigation-drawer.html -->
<dimen name="navigation_drawer_width">240dp</dimen>
<dimen name="standard_padding">10dp</dimen>
</resources>

View file

@ -13,8 +13,6 @@
<string name="action_export">Export</string>
<string name="action_settings">Settings</string>
<string name="pref_exec_title">Execution Settings</string>
<string name="pref_simulate">Simulate</string>
<string name="pref_simulate_summ">The execution will be simulated, no actual data will be transferred.</string>
<string name="pref_other_title">Other Settings</string>
<string name="title_activity_edit">Edit</string>
<string name="action_add">Add</string>
@ -22,4 +20,11 @@
<string name="configure_behaviour">Configure Behaviour</string>
<string name="action_save">Save</string>
<string name="action_cancel">Cancel</string>
<string name="pref_about">About</string>
<string name="pref_logging">Logging</string>
<string name="pref_logging_summ">Enable logging of throughput and other attributes to a csv file</string>
<string name="pref_logging_path">Log Path</string>
<string name="pref_logging_path_summ">Folder where log file will be stored</string>
<string name="title_activity_about">About</string>
</resources>

View file

@ -5,20 +5,27 @@
android:key="pref_key_storage_settings">
<CheckBoxPreference
android:key="simulation"
android:title="@string/pref_simulate"
android:summary="@string/pref_simulate_summ"
android:key="logging"
android:title="@string/pref_logging"
android:summary="@string/pref_logging_summ"
android:defaultValue="false" />
<EditTextPreference
android:key="logging_path"
android:title="@string/pref_logging_path"
android:summary="@string/pref_logging_path_summ"
android:defaultValue="/sdcard/uecontrol" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_other_title"
android:key="pref_key_storage_settings">
<CheckBoxPreference
android:key="simulation"
android:title="@string/pref_simulate"
android:summary="@string/pref_simulate_summ"
android:defaultValue="false" />
<PreferenceScreen
android:key="about"
android:title="@string/pref_about"
android:defaultValue="false">
<intent android:targetClass="com.ericsson.uecontrol.gui.AboutActivity" />
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>