Android Open Source - jpdroid Exportacoes Activity






From Project

Back to project page jpdroid.

License

The source code is released under:

GNU General Public License

If you think the Android project jpdroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package br.com.rafael.pedidojpdroid;
//www  . j  ava2  s .c  om
import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.ImageButton;
import android.widget.Toast;
import br.com.rafael.jpdroid.core.Jpdroid;
import br.com.rafael.jpdroid.util.JpdroidCsvFile;
import br.com.rafael.jpdroid.util.JpdroidJsonFile;
import br.com.rafael.jpdroid.util.JpdroidXmlFile;
import br.com.rafael.pedidojpdroid.entity.Pedido;
import br.com.rafael.pedidojpdroid.entity.Pessoa;
import br.com.rafael.pedidojpdroid.entity.Produto;

public class ExportacoesActivity extends Activity {

  private static final int EXPORT_PESSOA = 3;
  private static final int EXPORT_PRODUTO = 2;
  private static final int EXPORT_PEDIDO = 1;
  private ImageButton btExportPedido;
  private ImageButton btExportProduto;
  private ImageButton btExportPessoa;
  private int buttonClick;
  private DatePicker dataInicial;
  private DatePicker dataFim;
  private CheckBox chkPeriodo;

  Jpdroid jpdroid = null;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_exportacoes);

    jpdroid = Jpdroid.getInstance();

    btExportPedido = (ImageButton) findViewById(R.id.btExportPedido);
    registerForContextMenu(btExportPedido);

    btExportProduto = (ImageButton) findViewById(R.id.btExportProduto);
    registerForContextMenu(btExportProduto);

    btExportPessoa = (ImageButton) findViewById(R.id.btExportPessoa);

    dataInicial = (DatePicker) findViewById(R.id.datePicker1);
    dataFim = (DatePicker) findViewById(R.id.datePicker2);

    chkPeriodo = (CheckBox) findViewById(R.id.checkBox1);

    registerForContextMenu(btExportPessoa);
  }

  public static java.util.Date getDateFromDatePicket(DatePicker datePicker) {
    int day = datePicker.getDayOfMonth();
    int month = datePicker.getMonth();
    int year = datePicker.getYear();

    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month, day);

    return calendar.getTime();
  }

  @SuppressLint("SimpleDateFormat")
  public static String getDataFormat(DatePicker datePicker) {
    return new SimpleDateFormat("yyyy-MM-dd").format(getDateFromDatePicket(datePicker));
  }

  public void onClickExportPedido(View v) {
    buttonClick = EXPORT_PEDIDO;
    openContextMenu(v);
  }

  public void onClickExportProduto(View v) {
    buttonClick = EXPORT_PRODUTO;
    openContextMenu(v);
  }

  public void onClickExportPessoa(View v) {
    buttonClick = EXPORT_PESSOA;
    openContextMenu(v);
  }

  @Override
  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_exportacao, menu);
  }

  @Override
  public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.exportCSV:
        exportCSV();
        break;
      case R.id.exportJSON:
        exportJSON();
        break;
      case R.id.exportXML:
        exportXML();
        break;
      default:
        return super.onContextItemSelected(item);
    }
    return super.onContextItemSelected(item);
  }

  private void exportCSV() {
    switch (buttonClick) {
      case EXPORT_PEDIDO:
        if (chkPeriodo.isChecked()) {
          JpdroidCsvFile.export(
              jpdroid.retrieve(Pedido.class, " date(data) BETWEEN '" + getDataFormat(dataInicial) + "' AND '"
                  + getDataFormat(dataFim) + "' ", true), "PedidoExport.csv");
        } else {
          JpdroidCsvFile.export(jpdroid.retrieve(Pedido.class, true), "PedidoExport.csv");
        }
        break;
      case EXPORT_PRODUTO:
        JpdroidCsvFile.export(jpdroid.retrieve(Produto.class, true), "ProdutoExport.csv");
        break;
      case EXPORT_PESSOA:
        JpdroidCsvFile.export(jpdroid.retrieve(Pessoa.class, true), "PessoaExport.csv");
        break;
      default:
    }
    Toast.makeText(getBaseContext(), "Exporta??o realizada!", Toast.LENGTH_SHORT).show();
  }

  private void exportJSON() {
    switch (buttonClick) {
      case EXPORT_PEDIDO:
        if (chkPeriodo.isChecked()) {
          JpdroidJsonFile.export(
              jpdroid.retrieve(Pedido.class, " date(data) BETWEEN '" + getDataFormat(dataInicial) + "' AND '"
                  + getDataFormat(dataFim) + "' ", true), "PedidoExport.json");
        } else {
          JpdroidJsonFile.export(jpdroid.retrieve(Pedido.class, true), "PedidoExport.json");
        }
        break;
      case EXPORT_PRODUTO:
        JpdroidJsonFile.export(jpdroid.retrieve(Produto.class, true), "ProdutoExport.json");
        break;
      case EXPORT_PESSOA:
        JpdroidJsonFile.export(jpdroid.retrieve(Pessoa.class, true), "PessoaExport.json");
        break;
      default:
    }
    Toast.makeText(getBaseContext(), "Exporta??o realizada!", Toast.LENGTH_SHORT).show();
  }

  private void exportXML() {
    switch (buttonClick) {
      case EXPORT_PEDIDO:
        if (chkPeriodo.isChecked()) {
          JpdroidXmlFile.export(
              jpdroid.retrieve(Pedido.class, " date(data) BETWEEN '" + getDataFormat(dataInicial) + "' AND '"
                  + getDataFormat(dataFim) + "' ", true), "PedidoExport.xml");
        } else {
          JpdroidXmlFile.export(jpdroid.retrieve(Pedido.class, true), "PedidoExport.xml");
        }
        break;
      case EXPORT_PRODUTO:
        JpdroidXmlFile.export(jpdroid.retrieve(Produto.class, true), "ProdutoExport.xml");
        break;
      case EXPORT_PESSOA:
        JpdroidXmlFile.export(jpdroid.retrieve(Pessoa.class, true), "PessoaExport.xml");
        break;
      default:
    }
    Toast.makeText(getBaseContext(), "Exporta??o realizada!", Toast.LENGTH_SHORT).show();
  }

}




Java Source Code List

br.com.rafael.jpdroid.annotations.Column.java
br.com.rafael.jpdroid.annotations.DefaultOrder.java
br.com.rafael.jpdroid.annotations.DtoField.java
br.com.rafael.jpdroid.annotations.Dto.java
br.com.rafael.jpdroid.annotations.Entity.java
br.com.rafael.jpdroid.annotations.ForeignKey.java
br.com.rafael.jpdroid.annotations.Ignorable.java
br.com.rafael.jpdroid.annotations.PrimaryKey.java
br.com.rafael.jpdroid.annotations.RelationClass.java
br.com.rafael.jpdroid.annotations.ViewColumn.java
br.com.rafael.jpdroid.converters.JpdroidCsvConverter.java
br.com.rafael.jpdroid.converters.JpdroidDateUtil.java
br.com.rafael.jpdroid.converters.JpdroidDtoConverter.java
br.com.rafael.jpdroid.converters.JpdroidJsonConverter.java
br.com.rafael.jpdroid.converters.JpdroidMatrixCursorConverter.java
br.com.rafael.jpdroid.converters.JpdroidXmlConverter.java
br.com.rafael.jpdroid.core.JpdroidAbout.java
br.com.rafael.jpdroid.core.JpdroidDbHelper.java
br.com.rafael.jpdroid.core.JpdroidEntityValidation.java
br.com.rafael.jpdroid.core.JpdroidObjectMap.java
br.com.rafael.jpdroid.core.JpdroidTransaction.java
br.com.rafael.jpdroid.core.JpdroidWriteFile.java
br.com.rafael.jpdroid.core.Jpdroid.java
br.com.rafael.jpdroid.enums.Order.java
br.com.rafael.jpdroid.enums.RelationType.java
br.com.rafael.jpdroid.enums.ScriptPath.java
br.com.rafael.jpdroid.exceptions.JpdroidException.java
br.com.rafael.jpdroid.interfaces.ITransaction.java
br.com.rafael.jpdroid.util.JpdroidConverter.java
br.com.rafael.jpdroid.util.JpdroidCsvFile.java
br.com.rafael.jpdroid.util.JpdroidJsonFile.java
br.com.rafael.jpdroid.util.JpdroidXmlFile.java
br.com.rafael.pedidojpdroid.ContatoActivity.java
br.com.rafael.pedidojpdroid.EnderecoActivity.java
br.com.rafael.pedidojpdroid.ExportacoesActivity.java
br.com.rafael.pedidojpdroid.ImportacoesActivity.java
br.com.rafael.pedidojpdroid.ItensPedidoActivity.java
br.com.rafael.pedidojpdroid.ListaCidadesActivity.java
br.com.rafael.pedidojpdroid.ListaContatoActivity.java
br.com.rafael.pedidojpdroid.ListaEnderecoActivity.java
br.com.rafael.pedidojpdroid.ListaItensPedidoActivity.java
br.com.rafael.pedidojpdroid.ListaPedidoActivity.java
br.com.rafael.pedidojpdroid.ListaPessoaActivity.java
br.com.rafael.pedidojpdroid.ListaProdutoActivity.java
br.com.rafael.pedidojpdroid.ListagemPedidoActivity.java
br.com.rafael.pedidojpdroid.ListagemPessoaActivity.java
br.com.rafael.pedidojpdroid.ListagemProdutoActivity.java
br.com.rafael.pedidojpdroid.PedidoActivity.java
br.com.rafael.pedidojpdroid.PesquisaDialogActivity.java
br.com.rafael.pedidojpdroid.PessoaActivity.java
br.com.rafael.pedidojpdroid.PrincipalActivity.java
br.com.rafael.pedidojpdroid.ProdutoActivity.java
br.com.rafael.pedidojpdroid.SobreActivity.java
br.com.rafael.pedidojpdroid.dto.ContatoDTO.java
br.com.rafael.pedidojpdroid.dto.PessoaDTO.java
br.com.rafael.pedidojpdroid.entity.Cidade.java
br.com.rafael.pedidojpdroid.entity.Contato.java
br.com.rafael.pedidojpdroid.entity.Endereco.java
br.com.rafael.pedidojpdroid.entity.Estado.java
br.com.rafael.pedidojpdroid.entity.ItensPedido.java
br.com.rafael.pedidojpdroid.entity.Pedido.java
br.com.rafael.pedidojpdroid.entity.Pessoa.java
br.com.rafael.pedidojpdroid.entity.Produto.java
com.rafael.androidcomjpdroid.ContatoActivity.java
com.rafael.androidcomjpdroid.MainActivity.java
com.rafael.androidcomjpdroid.PessoaActivity.java
com.rafael.androidcomjpdroid.entity.Contato.java
com.rafael.androidcomjpdroid.entity.Pessoa.java
com.rafael.androidcomjpdroid.entity.TipoContato.java