var activity
This commit is contained in:
parent
55c6cbcc20
commit
d4fb589c77
@ -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>
|
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
|
@ -20,7 +20,11 @@
|
|||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="match_parent"
|
a:layout_height="match_parent"
|
||||||
a:textSize="20dp"
|
a:textSize="20dp"
|
||||||
a:padding="5dp">
|
a:paddingBottom="3dp"
|
||||||
|
a:paddingLeft="6dp"
|
||||||
|
a:paddingRight="6dp"
|
||||||
|
a:paddingTop="6dp"
|
||||||
|
a:textStyle="bold">
|
||||||
</TextView>
|
</TextView>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
46
res/layout/var_edit.xml
Normal file
46
res/layout/var_edit.xml
Normal 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>
|
@ -47,6 +47,8 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
@NotNull
|
@NotNull
|
||||||
private BroadcastReceiver insertTextReceiver;
|
private BroadcastReceiver insertTextReceiver;
|
||||||
|
|
||||||
|
private volatile boolean initialized;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the activity is first created.
|
* Called when the activity is first created.
|
||||||
*/
|
*/
|
||||||
@ -55,17 +57,11 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
|
|
||||||
try {
|
firstTimeInit();
|
||||||
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.calculatorView = new CalculatorView(this, this.calculatorModel);
|
init();
|
||||||
|
|
||||||
|
dpclRegister.clear();
|
||||||
|
|
||||||
final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(this);
|
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);
|
((DragButton) findViewById(R.id.leftButton)).setOnDragListener(toPositionOnDragListener);
|
||||||
dpclRegister.addListener(toPositionOnDragListener);
|
dpclRegister.addListener(toPositionOnDragListener);
|
||||||
|
|
||||||
|
final SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
this.onSharedPreferenceChanged(defaultSharedPreferences, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
insertTextReceiver = new BroadcastReceiver() {
|
insertTextReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
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));
|
registerReceiver(insertTextReceiver, new IntentFilter(INSERT_TEXT_INTENT));
|
||||||
|
}
|
||||||
|
|
||||||
final SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
private synchronized void firstTimeInit() {
|
||||||
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
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
|
@Override
|
||||||
|
@ -6,10 +6,13 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
@ -23,25 +26,47 @@ import java.util.List;
|
|||||||
* Date: 9/28/11
|
* Date: 9/28/11
|
||||||
* Time: 10:55 PM
|
* Time: 10:55 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorVarsActivity extends ListActivity {
|
public class CalculatorVarsActivity extends ListActivity implements DialogInterface.OnClickListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
setTheme(android.R.style.Theme_Dialog);
|
setListAdapter(new VarsArrayAdapter(this, R.layout.var, R.id.var_text, new ArrayList<Var>(CalculatorModel.getInstance().getVarsRegister().getVars())));
|
||||||
|
|
||||||
final List<Var> vars = new ArrayList<Var>(CalculatorModel.getInstance().getVarsRegister().getVars());
|
|
||||||
setListAdapter(new VarsArrayAdapter(this, R.layout.var, R.id.var_text, vars));
|
|
||||||
|
|
||||||
final ListView lv = getListView();
|
final ListView lv = getListView();
|
||||||
lv.setTextFilterEnabled(true);
|
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() {
|
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
public void onItemClick(AdapterView<?> parent, View view,
|
public void onItemClick(AdapterView<?> parent, View view,
|
||||||
int position, long id) {
|
int position, long id) {
|
||||||
final Intent intent = new Intent(CalculatorActivity.INSERT_TEXT_INTENT);
|
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);
|
sendOrderedBroadcast(intent, null);
|
||||||
|
|
||||||
CalculatorVarsActivity.this.finish();
|
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 class VarsArrayAdapter extends ArrayAdapter<Var> {
|
||||||
|
|
||||||
private VarsArrayAdapter(Context context, int resource, int textViewResourceId, List<Var> objects) {
|
private VarsArrayAdapter(Context context, int resource, int textViewResourceId, List<Var> objects) {
|
||||||
@ -64,12 +94,15 @@ public class CalculatorVarsActivity extends ListActivity {
|
|||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
final ViewGroup result = (ViewGroup)super.getView(position, convertView, 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())) {
|
if (!StringUtils.isEmpty(var.getDescription())) {
|
||||||
final TextView description = new TextView(getContext());
|
final TextView description = new TextView(getContext());
|
||||||
description.setText(var.getDescription());
|
description.setText(var.getDescription());
|
||||||
result.addView(description, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
description.setPadding(6, 0, 6, 6);
|
||||||
|
result.addView(description, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user