var activity

This commit is contained in:
serso 2011-10-01 22:08:44 +04:00
parent e517686eb5
commit e46ca70a6f
11 changed files with 123 additions and 177 deletions

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:orientation="vertical"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:background="#ff000000">
<TextView
a:id="@+id/aboutTextView"
a:text="@string/c_copyright"
a:textSize="20dp"
style="@style/display_style"
a:gravity="center|top"/>
</LinearLayout>

View File

@ -1,53 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:orientation="vertical"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:background="#ff000000">
<LinearLayout
a:id="@+id/simplePad"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:orientation="vertical"
a:layout_gravity="center">
<LinearLayout a:layout_weight="1" a:layout_width="match_parent" a:layout_height="0dp">
<ImageView a:id="@+id/calibrationArrowLeft"
a:layout_gravity="left"
a:layout_width="80dp"
a:layout_height="80dp"/>
<org.solovyev.android.view.widgets.DirectionDragButton a:id="@+id/calibrationButtonLeft"
a:text=""
calc:textUp="@string/c_up"
calc:textDown="@string/c_down"
a:layout_width="80dp"
a:layout_height="80dp"
style="@style/digit_button_style"/>
<org.solovyev.android.view.widgets.DirectionDragButton a:id="@+id/calibrationButtonRight"
a:text=""
calc:textUp="@string/c_up"
calc:textDown="@string/c_down"
a:layout_width="80dp"
a:layout_height="80dp"
style="@style/digit_button_style"/>
<ImageView a:id="@+id/calibrationArrowRight"
a:layout_gravity="right"
a:layout_width="80dp"
a:layout_height="80dp"/>
</LinearLayout>
</LinearLayout>
<Button a:id="@+id/calibrationStart"
a:text="@string/c_restart"
a:layout_width="wrap_content"
a:layout_height="wrap_content"
a:onClick="restartClickHandler"
a:layout_gravity="bottom"/>
</LinearLayout>

View File

@ -1,49 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<!--
**
** Copyright 2008, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<org.solovyev.android.view.widgets.NumberPickerButton android:id="@+id/increment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/timepicker_up_btn" />
<EditText android:id="@+id/timepicker_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:singleLine="true"
style="?android:attr/textAppearanceLargeInverse"
android:textColor="@android:color/primary_text_light"
android:textSize="30sp"
android:background="@drawable/timepicker_input" />
<org.solovyev.android.view.widgets.NumberPickerButton android:id="@+id/decrement"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/timepicker_down_btn" />
</merge>

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:orientation="vertical"
a:layout_width="match_parent"
a:layout_height="match_parent">
<LinearLayout
a:orientation="horizontal"
a:layout_width="match_parent"
a:layout_height="match_parent">
<TextView a:id="@+id/var_text"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:textSize="20dp"
a:padding="5dp">
</TextView>
</LinearLayout>
</LinearLayout>

View File

@ -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">
</TextView>
</LinearLayout>

46
res/layout/var_edit.xml Normal file
View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/var_edit"
a:orientation="vertical"
a:layout_width="match_parent"
a:layout_height="match_parent">
<TextView a:layout_height="match_parent"
a:layout_width="wrap_content"
a:text="Name"/>
<EditText a:id="@+id/var_name"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:textSize="20dp">
</EditText>
<TextView a:layout_height="match_parent"
a:layout_width="wrap_content"
a:text="Value"/>
<EditText a:id="@+id/var_value"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:inputType="number"
a:textSize="20dp">
</EditText>
<TextView a:layout_height="match_parent"
a:layout_width="wrap_content"
a:text="Description"/>
<EditText a:id="@+id/var_description"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:textSize="20dp">
</EditText>
</LinearLayout>

View File

@ -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

View File

@ -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<Var> vars = new ArrayList<Var>(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<Var>(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<Var> {
private VarsArrayAdapter(Context context, int resource, int textViewResourceId, List<Var> objects) {
@ -64,13 +94,16 @@ public class CalculatorVarsActivity extends ListActivity {
public View getView(int position, View convertView, ViewGroup parent) {
final ViewGroup result = (ViewGroup)super.getView(position, convertView, parent);
if (convertView == null) {
final Var var = getItem(position);
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;
}