Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.57 KB | None | 0 0
  1. package es.paumancar.ocgases;
  2.  
  3. import com.honeywell.decodemanager.DecodeManager;
  4.  
  5. import es.paumancar.ocgases.datasync.Connectivity;
  6. import es.paumancar.ocgases.datasync.MySQLiteHelperSync;
  7. import es.paumancar.ocgases.datasync.RecuperaFichero;
  8. import android.annotation.SuppressLint;
  9. import android.app.Activity;
  10. import android.app.AlertDialog;
  11. import android.content.DialogInterface;
  12. import android.content.Intent;
  13. import android.content.SharedPreferences;
  14. import android.content.SharedPreferences.Editor;
  15. import android.database.sqlite.SQLiteDatabase;
  16. import android.graphics.drawable.GradientDrawable.Orientation;
  17. import android.os.Bundle;
  18. import android.os.Handler;
  19. import android.preference.PreferenceManager;
  20. import android.support.v7.app.AppCompatActivity;
  21. import android.text.InputType;
  22. import android.view.View;
  23. import android.view.Window;
  24. import android.view.WindowManager;
  25. import android.view.ViewGroup.LayoutParams;
  26. import android.widget.Button;
  27. import android.widget.CompoundButton;
  28. import android.widget.CompoundButton.OnCheckedChangeListener;
  29. import android.widget.EditText;
  30. import android.widget.LinearLayout;
  31. import android.widget.RadioButton;
  32. import android.widget.TextView;
  33. import android.widget.Toast;
  34. import android.view.View.OnClickListener;
  35.  
  36. @SuppressLint("NewApi")
  37. public class ActivityPreferenciasGenerales extends Activity {
  38.  
  39. SharedPreferences sharedPref;
  40.  
  41. @Override
  42. public void onCreate(Bundle savedInstanceState) {
  43.  
  44. requestWindowFeature(Window.FEATURE_NO_TITLE);
  45. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  46. WindowManager.LayoutParams.FLAG_FULLSCREEN);
  47.  
  48. super.onCreate(savedInstanceState);
  49. setContentView(R.layout.preferencias_generales);
  50.  
  51. Button botonServidores = (Button) findViewById(R.id.buttonPreferenciasServidores);
  52. Button botonRedLocal = (Button) findViewById(R.id.buttonPreferenciasRedLocal);
  53. Button botonPassword = (Button) findViewById(R.id.buttonPreferenciasPassword);
  54. Button botonPrinters = (Button) findViewById(R.id.buttonPreferenciasPrinters);
  55. Button botonRecuperaCodigos = (Button) findViewById(R.id.buttonPreferenciasRecuperaCodigos);
  56. Button botonDiasDatos = (Button) findViewById(R.id.buttonPreferenciasDiasGuardarDB);
  57. Button botonBorrarCola = (Button) findViewById(R.id.buttonPreferenciasBorrarColaEnvios);
  58. Button botonActualizaPortes = (Button) findViewById(R.id.buttonPreferenciasRecuperaReglasPortes);
  59.  
  60. RadioButton radioButtonCamara = (RadioButton) findViewById(R.id.radioPreferenciasCamara);
  61. RadioButton radioButtonLector = (RadioButton) findViewById(R.id.radioPreferenciasLector);
  62.  
  63. sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
  64.  
  65. botonServidores.setOnClickListener(new OnClickListener() {
  66.  
  67. @Override
  68. public void onClick(View v) {
  69. Intent intentPreferencias = new Intent(getApplicationContext(), ActivityPreferenciasServidores.class);
  70. startActivity(intentPreferencias);
  71.  
  72. }
  73. });
  74.  
  75. botonRecuperaCodigos.setOnClickListener(new OnClickListener() {
  76.  
  77. @Override
  78. public void onClick(View v) {
  79. Intent intentRecuperaCodigos = new Intent(getApplicationContext(),
  80. ActivityRecuperaCodigos.class);
  81. startActivity(intentRecuperaCodigos);
  82.  
  83. }
  84. });
  85.  
  86. botonRedLocal.setOnClickListener(new OnClickListener() {
  87.  
  88. @Override
  89. public void onClick(View v) {
  90. final EditText editTextRedLocal = new EditText(ActivityPreferenciasGenerales.this);
  91. LinearLayout layoutTextos = new LinearLayout(ActivityPreferenciasGenerales.this);
  92. LinearLayout.LayoutParams layoutForInner =
  93. new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
  94. LinearLayout.LayoutParams.WRAP_CONTENT);
  95. layoutTextos.setLayoutParams(layoutForInner);
  96. layoutTextos.addView(editTextRedLocal);
  97. LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1f);
  98. editTextRedLocal.setLayoutParams(params);
  99. AlertDialog.Builder dialog = new AlertDialog.Builder(ActivityPreferenciasGenerales.this);
  100.  
  101. dialog.setTitle("RED LOCAL");
  102. dialog.setView(layoutTextos);
  103. dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
  104. @Override
  105. public void onClick(DialogInterface dialog, int id) {
  106. String textoRedLocal = editTextRedLocal.getText().toString();
  107. Editor editor = sharedPref.edit();
  108. editor.putString(TagsPreferencias.RED_LOCAL, textoRedLocal);
  109. editor.commit();
  110. dialog.cancel();
  111. }
  112. });
  113. dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  114. @Override
  115. public void onClick(DialogInterface dialog, int id) {
  116. dialog.cancel();
  117. }
  118. });
  119. dialog.create();
  120. dialog.show();
  121. editTextRedLocal.setText(sharedPref.getString(TagsPreferencias.RED_LOCAL,
  122. Connectivity.RED_WIFI_PROPIA));
  123. }
  124. });
  125.  
  126. botonPassword.setOnClickListener(new OnClickListener() {
  127.  
  128. @Override
  129. public void onClick(View v) {
  130. final TextView TextPass1 = new TextView(ActivityPreferenciasGenerales.this);
  131. final TextView TextPass2 = new TextView(ActivityPreferenciasGenerales.this);
  132. final EditText editTextPass1 = new EditText(ActivityPreferenciasGenerales.this);
  133. final EditText editTextPass2 = new EditText(ActivityPreferenciasGenerales.this);
  134. TextPass1.setText("Nueva_Pass: ");
  135. TextPass2.setText("Repita_Pass: ");
  136. editTextPass1.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
  137. editTextPass2.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
  138.  
  139. LinearLayout layoutTextos = new LinearLayout(ActivityPreferenciasGenerales.this);
  140. LinearLayout.LayoutParams layoutForInner =
  141. new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
  142. LinearLayout.LayoutParams.WRAP_CONTENT);
  143. layoutTextos.setLayoutParams(layoutForInner);
  144. layoutTextos.setOrientation(LinearLayout.VERTICAL);
  145.  
  146. LayoutParams params5Weight = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 5f);
  147.  
  148. LinearLayout layoutPass1 = new LinearLayout(ActivityPreferenciasGenerales.this);
  149. layoutPass1.setLayoutParams(layoutForInner);
  150. layoutPass1.setOrientation(LinearLayout.HORIZONTAL);
  151. TextPass1.setLayoutParams(params5Weight);
  152. editTextPass1.setLayoutParams(params5Weight);
  153. layoutPass1.addView(TextPass1);
  154. layoutPass1.addView(editTextPass1);
  155.  
  156. LinearLayout layoutPass2 = new LinearLayout(ActivityPreferenciasGenerales.this);
  157. layoutPass2.setLayoutParams(layoutForInner);
  158. layoutPass2.setOrientation(LinearLayout.HORIZONTAL);
  159. TextPass2.setLayoutParams(params5Weight);
  160. editTextPass2.setLayoutParams(params5Weight);
  161. layoutPass2.addView(TextPass2);
  162. layoutPass2.addView(editTextPass2);
  163.  
  164. layoutTextos.addView(layoutPass1);
  165. layoutTextos.addView(layoutPass2);
  166.  
  167. AlertDialog.Builder dialog = new AlertDialog.Builder(ActivityPreferenciasGenerales.this);
  168.  
  169. dialog.setTitle("CAMBIO DE CONTRASEÑA");
  170. dialog.setView(layoutTextos);
  171. dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
  172. @Override
  173. public void onClick(DialogInterface dialog, int id) {
  174. String textoPass1 = editTextPass1.getText().toString();
  175. String textoPass2 = editTextPass2.getText().toString();
  176. if (textoPass1.equals(textoPass2)){
  177. MySQLiteHelper myHelper = new MySQLiteHelper(getApplicationContext());
  178. SQLiteDatabase db = myHelper.getWritableDatabase();
  179. boolean exitoAlAct = myHelper.actualizaPassword(db, textoPass1);
  180. db.close();
  181. myHelper.close();
  182. if (exitoAlAct){
  183. Toast.makeText(getApplicationContext(), "Contraseña actualizada", Toast.LENGTH_LONG).show();
  184. } else {
  185. Toast.makeText(getApplicationContext(), "Error al actualizar", Toast.LENGTH_LONG).show();
  186. }
  187. } else {
  188. editTextPass1.setText("");
  189. editTextPass2.setText("");
  190. Toast.makeText(getApplicationContext(), "Contraseñas distintas", Toast.LENGTH_LONG).show();
  191. }
  192. }
  193. });
  194. dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  195. @Override
  196. public void onClick(DialogInterface dialog, int id) {
  197. dialog.cancel();
  198. }
  199. });
  200. dialog.create();
  201. dialog.show();
  202. }
  203. });
  204.  
  205. boolean existeLectorCCD = false;
  206. try {
  207. DecodeManager mDecoderTest = new DecodeManager(this, new Handler());
  208. existeLectorCCD = true;
  209. mDecoderTest.release();
  210. mDecoderTest = null;
  211. } catch (Throwable e) {
  212. // TODO Auto-generated catch block
  213. e.printStackTrace();
  214. }
  215. String escanerDefecto = sharedPref.getString(TagsPreferencias.ESCANER, TagsPreferencias.ESCANER_VALOR_CAMARA);
  216. boolean escanearConCCD = escanerDefecto.equals(TagsPreferencias.ESCANER_VALOR_LECTOR)?true:false;
  217. if (existeLectorCCD){
  218. radioButtonLector.setChecked(escanearConCCD);
  219. radioButtonCamara.setChecked(!escanearConCCD);
  220. } else {
  221. escanearConCCD = false;
  222. radioButtonLector.setEnabled(false);
  223. radioButtonLector.setChecked(false);
  224. radioButtonCamara.setChecked(true);
  225. Editor editor = sharedPref.edit();
  226. editor.putString(TagsPreferencias.ESCANER, TagsPreferencias.ESCANER_VALOR_CAMARA);
  227. editor.commit();
  228. }
  229.  
  230. radioButtonCamara.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  231.  
  232. @Override
  233. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  234. if (isChecked){
  235. Editor editor = sharedPref.edit();
  236. editor.putString(TagsPreferencias.ESCANER, TagsPreferencias.ESCANER_VALOR_CAMARA);
  237. editor.commit();
  238. }
  239. }
  240. });
  241.  
  242.  
  243. radioButtonLector.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  244.  
  245. @Override
  246. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  247. if (isChecked){
  248. Editor editor = sharedPref.edit();
  249. editor.putString(TagsPreferencias.ESCANER, TagsPreferencias.ESCANER_VALOR_LECTOR);
  250. editor.commit();
  251. }
  252. }
  253. });
  254.  
  255. botonPrinters.setOnClickListener(new OnClickListener() {
  256. @Override
  257. public void onClick(View v) {
  258. Intent intentPreferenciasPrinters = new Intent(getApplicationContext(), ActivityPreferenciasPrinters.class);
  259. startActivity(intentPreferenciasPrinters);
  260.  
  261. }
  262. });
  263.  
  264. botonDiasDatos.setOnClickListener(new OnClickListener() {
  265.  
  266. @Override
  267. public void onClick(View v) {
  268. final EditText editTextDiasDatos = new EditText(ActivityPreferenciasGenerales.this);
  269. LinearLayout layoutTextos = new LinearLayout(ActivityPreferenciasGenerales.this);
  270. LinearLayout.LayoutParams layoutForInner =
  271. new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
  272. LinearLayout.LayoutParams.WRAP_CONTENT);
  273. layoutTextos.setLayoutParams(layoutForInner);
  274. layoutTextos.addView(editTextDiasDatos);
  275. LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1f);
  276. editTextDiasDatos.setLayoutParams(params);
  277. AlertDialog.Builder dialog = new AlertDialog.Builder(ActivityPreferenciasGenerales.this);
  278.  
  279. dialog.setTitle("DIAS GUARDADO DATOS");
  280. dialog.setView(layoutTextos);
  281. dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
  282. @Override
  283. public void onClick(DialogInterface dialog, int id) {
  284. String textoRedLocal = editTextDiasDatos.getText().toString();
  285. Editor editor = sharedPref.edit();
  286. editor.putString(TagsPreferencias.DIAS_GUARDADO_DATOS, textoRedLocal);
  287. editor.commit();
  288. dialog.cancel();
  289. }
  290. });
  291. dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  292. @Override
  293. public void onClick(DialogInterface dialog, int id) {
  294. dialog.cancel();
  295. }
  296. });
  297. dialog.create();
  298. dialog.show();
  299. editTextDiasDatos.setText(sharedPref.getString(TagsPreferencias.DIAS_GUARDADO_DATOS, "3"));
  300. }
  301. });
  302.  
  303. botonBorrarCola.setOnClickListener(new OnClickListener() {
  304. @Override
  305. public void onClick(View v) {
  306. MySQLiteHelperSync mySyncHelper = new MySQLiteHelperSync(getApplicationContext());
  307. SQLiteDatabase db = mySyncHelper.getWritableDatabase();
  308. mySyncHelper.borraTodosDatosEnviados(db);
  309. db.close();
  310. mySyncHelper.close();
  311. }
  312. });
  313.  
  314. botonActualizaPortes.setOnClickListener(new OnClickListener() {
  315.  
  316. @Override
  317. public void onClick(View v) {
  318. RecuperaFichero recuperaTablaPortes = new RecuperaFichero(ActivityPreferenciasGenerales.this);
  319. String[] datosTablaPortes = {"TablaPortes"};
  320. recuperaTablaPortes.execute(datosTablaPortes);
  321.  
  322. RecuperaFichero recuperaReglasPortes = new RecuperaFichero(ActivityPreferenciasGenerales.this);
  323. String[] datosReglasPortes = {"ReglasPortes"};
  324. recuperaReglasPortes.execute(datosReglasPortes);
  325.  
  326. }
  327. });
  328.  
  329. }
  330.  
  331. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement