diff --git a/res/layout-port/about.xml b/res/layout-port/about.xml
deleted file mode 100644
index 28933ac3..00000000
--- a/res/layout-port/about.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/res/layout-port/drag_button_calibration.xml b/res/layout-port/drag_button_calibration.xml
deleted file mode 100644
index 47179e82..00000000
--- a/res/layout-port/drag_button_calibration.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/res/layout-port/number_picker.xml b/res/layout-port/number_picker.xml
deleted file mode 100644
index 6919a09c..00000000
--- a/res/layout-port/number_picker.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/res/layout-port/var.xml b/res/layout-port/var.xml
deleted file mode 100644
index 3fddfcbb..00000000
--- a/res/layout-port/var.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/res/layout-land/about.xml b/res/layout/about.xml
similarity index 100%
rename from res/layout-land/about.xml
rename to res/layout/about.xml
diff --git a/res/layout-land/drag_button_calibration.xml b/res/layout/drag_button_calibration.xml
similarity index 100%
rename from res/layout-land/drag_button_calibration.xml
rename to res/layout/drag_button_calibration.xml
diff --git a/res/layout-land/number_picker.xml b/res/layout/number_picker.xml
similarity index 100%
rename from res/layout-land/number_picker.xml
rename to res/layout/number_picker.xml
diff --git a/res/layout-land/var.xml b/res/layout/var.xml
similarity index 83%
rename from res/layout-land/var.xml
rename to res/layout/var.xml
index 3fddfcbb..cba3dbf8 100644
--- a/res/layout-land/var.xml
+++ b/res/layout/var.xml
@@ -20,7 +20,11 @@
a:layout_width="match_parent"
a:layout_height="match_parent"
a:textSize="20dp"
- a:padding="5dp">
+ a:paddingBottom="3dp"
+ a:paddingLeft="6dp"
+ a:paddingRight="6dp"
+ a:paddingTop="6dp"
+ a:textStyle="bold">
diff --git a/res/layout/var_edit.xml b/res/layout/var_edit.xml
new file mode 100644
index 00000000..5bf580ab
--- /dev/null
+++ b/res/layout/var_edit.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java
index 52ed45ec..46d0581f 100644
--- a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java
+++ b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java
@@ -47,6 +47,8 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
@NotNull
private BroadcastReceiver insertTextReceiver;
+ private volatile boolean initialized;
+
/**
* Called when the activity is first created.
*/
@@ -55,17 +57,11 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
- try {
- if (!CalculatorModel.isLoaded()) {
- CalculatorModel.init(this);
- }
- this.calculatorModel = CalculatorModel.getInstance();
- } catch (EvalError evalError) {
- // todo serso: create serso runtime exception
- throw new RuntimeException("Could not initialize interpreter!");
- }
+ firstTimeInit();
- this.calculatorView = new CalculatorView(this, this.calculatorModel);
+ init();
+
+ dpclRegister.clear();
final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(this);
@@ -99,7 +95,13 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
((DragButton) findViewById(R.id.leftButton)).setOnDragListener(toPositionOnDragListener);
dpclRegister.addListener(toPositionOnDragListener);
+ final SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+ defaultSharedPreferences.registerOnSharedPreferenceChangeListener(this);
+ this.onSharedPreferenceChanged(defaultSharedPreferences, null);
+ }
+
+ private void init() {
insertTextReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -118,11 +120,24 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
};
registerReceiver(insertTextReceiver, new IntentFilter(INSERT_TEXT_INTENT));
+ }
- final SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
- defaultSharedPreferences.registerOnSharedPreferenceChangeListener(this);
+ private synchronized void firstTimeInit() {
+ if (!initialized) {
+ try {
+ if (!CalculatorModel.isLoaded()) {
+ CalculatorModel.init(this);
+ }
+ this.calculatorModel = CalculatorModel.getInstance();
+ } catch (EvalError evalError) {
+ // todo serso: create serso runtime exception
+ throw new RuntimeException("Could not initialize interpreter!");
+ }
- this.onSharedPreferenceChanged(defaultSharedPreferences, null);
+ this.calculatorView = new CalculatorView(this, this.calculatorModel);
+
+ initialized = true;
+ }
}
@Override
diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorVarsActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorVarsActivity.java
index 1461fbff..c2fe7b61 100644
--- a/src/main/java/org/solovyev/android/calculator/CalculatorVarsActivity.java
+++ b/src/main/java/org/solovyev/android/calculator/CalculatorVarsActivity.java
@@ -6,10 +6,13 @@
package org.solovyev.android.calculator;
+import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
+import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
@@ -23,25 +26,47 @@ import java.util.List;
* Date: 9/28/11
* Time: 10:55 PM
*/
-public class CalculatorVarsActivity extends ListActivity {
+public class CalculatorVarsActivity extends ListActivity implements DialogInterface.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setTheme(android.R.style.Theme_Dialog);
-
- final List vars = new ArrayList(CalculatorModel.getInstance().getVarsRegister().getVars());
- setListAdapter(new VarsArrayAdapter(this, R.layout.var, R.id.var_text, vars));
+ setListAdapter(new VarsArrayAdapter(this, R.layout.var, R.id.var_text, new ArrayList(CalculatorModel.getInstance().getVarsRegister().getVars())));
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
+
+ lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
+ @Override
+ public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
+ final LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
+ final View editView = layoutInflater.inflate(R.layout.var_edit, null);
+
+ final Var var = (Var)parent.getItemAtPosition(position);
+
+ final EditText editName = (EditText)editView.findViewById(R.id.var_name);
+ editName.setText(var.getName());
+ final EditText editValue = (EditText)editView.findViewById(R.id.var_value);
+ editValue.setText(var.getValue());
+ final EditText editDescription = (EditText)editView.findViewById(R.id.var_description);
+ editDescription.setText(var.getDescription());
+
+
+ new AlertDialog.Builder(CalculatorVarsActivity.this)
+ .setCancelable(true)
+ .setPositiveButton("Save", CalculatorVarsActivity.this)
+ .setView(editView).create().show();
+ return true;
+ }
+ });
+
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView> parent, View view,
int position, long id) {
final Intent intent = new Intent(CalculatorActivity.INSERT_TEXT_INTENT);
- intent.putExtra(CalculatorActivity.INSERT_TEXT_INTENT_EXTRA_STRING, vars.get(position).getName());
+ intent.putExtra(CalculatorActivity.INSERT_TEXT_INTENT_EXTRA_STRING, ((Var) parent.getItemAtPosition(position)).getName());
sendOrderedBroadcast(intent, null);
CalculatorVarsActivity.this.finish();
@@ -50,6 +75,11 @@ public class CalculatorVarsActivity extends ListActivity {
}
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
private class VarsArrayAdapter extends ArrayAdapter {
private VarsArrayAdapter(Context context, int resource, int textViewResourceId, List objects) {
@@ -64,12 +94,15 @@ public class CalculatorVarsActivity extends ListActivity {
public View getView(int position, View convertView, ViewGroup parent) {
final ViewGroup result = (ViewGroup)super.getView(position, convertView, parent);
- final Var var = getItem(position);
+ if (convertView == null) {
+ final Var var = getItem(position);
- if (!StringUtils.isEmpty(var.getDescription())) {
- final TextView description = new TextView(getContext());
- description.setText(var.getDescription());
- result.addView(description, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ if (!StringUtils.isEmpty(var.getDescription())) {
+ final TextView description = new TextView(getContext());
+ description.setText(var.getDescription());
+ description.setPadding(6, 0, 6, 6);
+ result.addView(description, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ }
}
return result;