コード例 #1
0
 @Override
 protected void onPause() {
   // TODO Cierro la BD en OnPause() cuando la Actividad no está en el foco
   dba.close();
   super.onPause();
 }
コード例 #2
0
 @Override
 protected void onResume() {
   // TODO Abro la base de datos mientras la Actividad está Activa
   dba.openREADWRITE();
   super.onResume();
 }
コード例 #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.pestanya_libre);

    // Obtengo el tipo de moneda a tulizar
    singleton_tm = SingletonTipoMoneda.getInstance();
    tipoMoneda = singleton_tm.obtenerTipoMoneda(getApplicationContext());

    animacionBotonPulsado = AnimationUtils.loadAnimation(this, R.anim.animacion_boton_pulsado);
    animacionBotonLevantado = AnimationUtils.loadAnimation(this, R.anim.animacion_boton_levantado);

    rlBarraListadoIngresos =
        (RelativeLayout) findViewById(R.id.relativeLayoutBarraListadoIngresosLibre);
    rlBarraListadoGastos =
        (RelativeLayout) findViewById(R.id.relativeLayoutBarraListadoGastosLibre);
    llListadoIngresos = (LinearLayout) findViewById(R.id.linearLayoutListadoIngresosLibre);
    llListadoGastos = (LinearLayout) findViewById(R.id.linearLayoutListadoGastosLibre);
    ivFlechaListadoIngresos = (ImageView) findViewById(R.id.imageViewListadoIngresosLibre);
    ivFlechaListadoGastos = (ImageView) findViewById(R.id.imageViewListadoGastosLibre);
    tvTotalIngresos = (TextView) findViewById(R.id.textViewTotalIngresosLibre);
    tvTotalGastos = (TextView) findViewById(R.id.textViewTotalGastosLibre);
    tvTotalBalance = (TextView) findViewById(R.id.textViewTotalBalanceLibre);
    ivSearchDate = (ImageView) findViewById(R.id.imageViewSearchFechaLibre);

    // Instancio las fechas
    tvStartDate = (TextView) findViewById(R.id.textViewPestanyaILibreFechaDe);
    tvEndDate = (TextView) findViewById(R.id.textViewPestanyaILibreFechaHasta);
    // Instancio las variables Calendar al día de hoy
    cInicio = Calendar.getInstance();
    cFin = Calendar.getInstance();

    tvStartDate.setText(obtenerFechaInicio());
    tvEndDate.setText(obtenerFechaFin());

    /*
     * Método onClick para plegar/desplegar el listado de Ingresos
     */
    rlBarraListadoIngresos.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Veo cual es el estado del listado de ingresos y luego lo
            // abro o lo cierro
            if (llListadoIngresos.getVisibility() == View.VISIBLE) {
              llListadoIngresos.setVisibility(View.GONE);
              ivFlechaListadoIngresos.setImageDrawable(
                  getResources().getDrawable(android.R.drawable.arrow_down_float));
            } else {
              llListadoIngresos.setVisibility(View.VISIBLE);
              ivFlechaListadoIngresos.setImageDrawable(
                  getResources().getDrawable(android.R.drawable.arrow_up_float));
            }
          }
        });

    /*
     * Método onClick para plegar/desplegar el listado de Gastos
     */
    rlBarraListadoGastos.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Veo cual es el estado del listado de ingresos y luego lo
            // abro o lo cierro
            if (llListadoGastos.getVisibility() == View.VISIBLE) {
              llListadoGastos.setVisibility(View.GONE);
              ivFlechaListadoGastos.setImageDrawable(
                  getResources().getDrawable(android.R.drawable.arrow_down_float));
            } else {
              llListadoGastos.setVisibility(View.VISIBLE);
              ivFlechaListadoGastos.setImageDrawable(
                  getResources().getDrawable(android.R.drawable.arrow_up_float));
            }
          }
        });

    ivSearchDate.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            // TODO Método onTouch del botón de buscar en un Rango de Fechas
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
                tiempoDePulsacionInicial = event.getEventTime();
                ivSearchDate.startAnimation(animacionBotonPulsado);
                break;
              case MotionEvent.ACTION_UP:
                if (event.getEventTime() - tiempoDePulsacionInicial <= 2000) {
                  // lanzo el dialog con la fecha a buscar por el usuario
                  ivSearchDate.startAnimation(animacionBotonLevantado);
                  Dialog dialogo;
                  dialogo = crearDialogoBuscarFecha();
                  dialogo.show();
                }
                // Si he mantenido el botón pulsado más de dos segundos
                // cancelo la operación
                ivSearchDate.startAnimation(animacionBotonLevantado);
                break;
              case MotionEvent.ACTION_CANCEL:
                ivSearchDate.startAnimation(animacionBotonLevantado);
                break;
            }

            return true;
          }
        });

    // Instancio los formateadores de números
    separadores = new DecimalFormatSymbols();
    separadores.setDecimalSeparator(',');
    separadores.setGroupingSeparator('.');
    numeroAFormatear = new DecimalFormat("###,###.##", separadores);

    // Instancio la Base de Datos
    dba = DBAdapter.getInstance(this);

    // Abro la Base de Datos solo en modo lectura
    dba.openREADWRITE();

    // Obtengo los valores de los datos de las Listas de Ingresos y Gastos
    listadoValoresIngresos =
        dba.listadoValoresIngresosPorFecha(obtenerEnteroFechaInicio(), obtenerEnteroFechaFin());
    listadoValoresGastos =
        dba.listadoValoresGastosPorFecha(obtenerEnteroFechaInicio(), obtenerEnteroFechaFin());

    /*
     * Agrupo las Lista por TRIMESTRES y luego cargo los layouts
     */
    cargarLayoutListadoIngresos();
    cargarLayoutListadoGastos();
    /*
     * Calculo los totales y la diferencia y los actualizo en sus variables
     */
    setTotalIngresos(calcularTotalIngresos());
    setTotalGastos(calcularTotalGastos());
    /*
     * Actualizo los TextView que contienen los totales
     */
    actualizarTotales();

    // Pongo los listados plegados
    llListadoIngresos.setVisibility(View.GONE);
    llListadoGastos.setVisibility(View.GONE);

    // Cierro la Base de datos
    dba.close();
  }