DialogPersoComplexCantidadModificacion.java
6.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
package com.focasoftware.deboinventario;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
/**
* Dialogo que permite mostrar una UI para modificar la cantidad de un articulo
* en las BD
* @author GuillermoR
*
*/
public class DialogPersoComplexCantidadModificacion extends Dialog implements GestionarioTecladoVirtual{
/**
* TextView para mostrar el valor incical
*/
private TextView textV_valor_inicial;
/**
* Text view para mostrar el valor previsional luego de modificar su cantidad
*/
private TextView textV_valor_previsional;
/**
* EditText para almacenar el nuevo valor a ingresar
*/
private EditText editT_nuevo_valor;
/**
* Boton para resetear la cantidad
*/
private Button boton_reset;
/**
* Variables accesorias
*/
private float VALOR_INICIO = 0;
private int TIPO_OPERACION = -1;
/**
* Constructor completo, setea las UI y carga los handlers
* <p>1 Construccin del ttulo
* <p>2 Cargamos el layout y main layout
* <p>3 Actualizacin de los textos
* <p>4 Si estamos en el modo "MODIFICAR",
* se habilita la posibilidad de reestablecer el valor a No Tomado
* <p>5 EditTexts y handlers de los mismos
* <p>6 Botones y sus handlers
*
* @param context
* @param tipo_operacion
* @param valor_inicial
* @param listenerValidar
* @param listenerCancelar
* @param listenerReset
*/
public DialogPersoComplexCantidadModificacion (Context context, int tipo_operacion, float valor_inicial,
View.OnClickListener listenerValidar,
View.OnClickListener listenerCancelar,
View.OnClickListener listenerReset) {
super(context);
System.out.println("::: Modificacion BALANZA ");
//1 Construccin del ttulo:
switch (tipo_operacion) {
case DialogPerso.OPERACION_SUMAR:
super.setTitle("Sumar");
break;
case DialogPerso.OPERACION_RESTAR:
super.setTitle("Restar");
break;
case DialogPerso.OPERACION_MODIFICAR:
super.setTitle("Nuevo valor");
break;
}
// System.out.println("::: DialogComple modificacion antes del switch");
super.setContentView(R.layout.z_dialogpersocomplexcantidad_modificacion);
//3 Actualizacin de los textos:
textV_valor_inicial = (TextView) super.findViewById(R.id.Z_DIALOG_cantidad_actual);
textV_valor_inicial.setText(String.valueOf(valor_inicial));
VALOR_INICIO = valor_inicial;
TIPO_OPERACION = tipo_operacion;
textV_valor_previsional = (TextView) super.findViewById(R.id.Z_DIALOG_cantidad_final);
textV_valor_previsional.setText(String.valueOf(valor_inicial));
//4 Si estamos en el modo "MODIFICAR", se habilita la posibilidad de reestablecer el valor a No Tomado:
if (TIPO_OPERACION == DialogPerso.OPERACION_MODIFICAR) {
boton_reset = (Button) super.findViewById(R.id.Z_DIALOG_boton_reset);
boton_reset.setVisibility(View.VISIBLE);
}
//5 EditTexts y handlers de los mismos
editT_nuevo_valor = (EditText) super.findViewById(R.id.Z_DIALOG_cantidad_nueva);
editT_nuevo_valor.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
showKeyboard(editT_nuevo_valor);
}
});
editT_nuevo_valor.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void afterTextChanged(Editable s) {
float new_val = 0;
float val_temp = 0;
try {
val_temp = Float.parseFloat(String.valueOf(s));
}
catch (Exception ex) {}
switch (TIPO_OPERACION) {
case DialogPerso.OPERACION_SUMAR:
new_val = VALOR_INICIO + val_temp;
break;
case DialogPerso.OPERACION_RESTAR:
new_val = Math.max(VALOR_INICIO - val_temp, 0);
break;
case DialogPerso.OPERACION_MODIFICAR:
new_val = val_temp;
break;
}
textV_valor_previsional.setText(String.valueOf(new_val));
}
});
TextView textV_operacion = (TextView) super.findViewById(R.id.Z_DIALOG_tipo_operacion);
String miTexto = "";
switch (tipo_operacion) {
case DialogPerso.OPERACION_SUMAR:
miTexto = "SUMAR: ";
break;
case DialogPerso.OPERACION_RESTAR:
miTexto = "RESTAR: ";
break;
case DialogPerso.OPERACION_MODIFICAR:
miTexto = "NUEVO VALOR: ";
break;
}
textV_operacion.setText(miTexto);
//6 Botones y sus handlers:
ImageView boton_validar = (ImageView) super.findViewById(R.id.Z_DIALOG_validar);
ImageView boton_cancelar = (ImageView) super.findViewById(R.id.Z_DIALOG_cancelar);
boton_validar.setOnClickListener(listenerValidar);
boton_cancelar.setOnClickListener(listenerCancelar);
if (TIPO_OPERACION == DialogPerso.OPERACION_MODIFICAR) {
boton_reset.setOnClickListener(listenerReset);
}
}
/**
* Devuleve el nuevo valor
* <p>1 Test para ver si el valor tiene formato a nombre, sino 0
* <p>2 Para provocar la excepcion si s no es del tipo Integer
* <p>3 En caso de error, devolvemos 0 si se trata de "sumar" o "restar".
* En el caso del "modificar", devolvemos "" para poder
* restablecer un "No Tomado", o valor inicial sino
*
* @return
*/
public String get_nuevo_valor() {
//1 Test para ver si el valor tiene formato a nombre, sino 0:
String s = String.valueOf(editT_nuevo_valor.getText());
try {
//2 Para provocar la excepcion si s no es del tipo Integer
Float.parseFloat(s);
return s;
}
catch (Exception ex) {
//3 En caso de error, devolvemos 0 si se trata de "sumar" o "restar".
// En el caso del "modificar", devolvemos "" para poder restablecer un "No Tomado", o valor inicial sino
if (s.length() <= 0 && TIPO_OPERACION == DialogPerso.OPERACION_MODIFICAR) {
return "";
}
else if (s.length() > 0 && TIPO_OPERACION == DialogPerso.OPERACION_MODIFICAR) {
return String.valueOf(VALOR_INICIO);
}
else {
return "0";
}
}
}
public void valor_incorrecto(Context context) {
AlertDialog show = new AlertDialog.Builder(context)
.setTitle("Debo Inventario")
.setMessage("Valor ingresado incorrecto")
.show();
}
public void showKeyboard(EditText edit_text) {
// TODO Auto-generated method stub
}
public void hideKeyboard(EditText edit_text) {
// TODO Auto-generated method stub
}
}