Android Open Source - intelligent-lock-pattern Database Exporter Activity






From Project

Back to project page intelligent-lock-pattern.

License

The source code is released under:

GNU General Public License

If you think the Android project intelligent-lock-pattern 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

/*
 * "Copyright 2012 Lucas Andr? de Alencar"
 * /*from  w  ww.  j  a  va 2 s .  c om*/
 * This file is part of "Intelligent Lock Pattern".
 * 
 * "Intelligent Lock Pattern" is free software: you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation, either version 3 of the License, or 
 * (at your option) any later version.
 * 
 * "Intelligent Lock Pattern" is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 * GNU General Public License for more details. 
 * 
 * You should have received a copy of the GNU General Public License 
 * along with "Intelligent Lock Pattern".  If not, see <http://www.gnu.org/licenses/>.
 */

package org.unioeste.ilp;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

import org.unioeste.ilp.db.DBHelper;

import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

/**
 * Activity responsible for exporting the database
 * of the application to an external directory on the
 * sd card to data extraction.
 * 
 * @author Lucas Andr? de Alencar
 *
 */
public class DatabaseExporterActivity extends BaseActivity {

  private ExportDatabaseFileTask task;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    task = new ExportDatabaseFileTask();
  }

  @Override
  protected void onStart() {
    super.onStart();
    task.execute("");
    finish();
  }

  private class ExportDatabaseFileTask extends AsyncTask<String, Void, Boolean> {

    private final ProgressDialog dialog = new ProgressDialog(DatabaseExporterActivity.this);

    // can use UI thread here
    protected void onPreExecute() {
      this.dialog.setMessage(ilp.getText(R.string.export_db_executing));
      this.dialog.show();
    }

    // automatically done on worker thread (separate from UI thread)
    protected Boolean doInBackground(final String... args) {
      File dbFile = ilp.getDatabasePath(DBHelper.DB_NAME);
      File exportDir = ilp.getExternalFilesDir("IntelligentLockPattern");
      Log.i("ExportDatabaseFileTask", "Exporting db file to " + exportDir.getAbsolutePath());
      
      if (!exportDir.exists())
        exportDir.mkdirs();
      
      File file = new File(exportDir, dbFile.getName());

      try {
        file.createNewFile();
        this.copyFile(dbFile, file);
        return true;
      } catch (IOException e) {
        Log.e("ExportDatabaseFileTask", e.getMessage(), e);
        return false;
      }
    }

    // can use UI thread here
    protected void onPostExecute(final Boolean success) {
      if (this.dialog.isShowing())
        try {
          this.dialog.dismiss();
        } catch (IllegalArgumentException e) {
          Log.i("ExportDatabseFileTask", "Something went wrong, but I'll just ignore it! :)");
        }
        
      if (success)
        Toast.makeText(DatabaseExporterActivity.this, R.string.export_db_success, Toast.LENGTH_SHORT).show();
      else
        Toast.makeText(DatabaseExporterActivity.this, R.string.export_db_fail, Toast.LENGTH_SHORT).show();
    }

    private void copyFile(File src, File dst) throws IOException {
      FileChannel inChannel = null;
      FileChannel outChannel = null;
      try {
        inChannel = new FileInputStream(src).getChannel();
        outChannel = new FileOutputStream(dst).getChannel();
        inChannel.transferTo(0, inChannel.size(), outChannel);
      } finally {
        if (inChannel != null)
          inChannel.close();
        if (outChannel != null)
          outChannel.close();
      }
    }
  }
}




Java Source Code List

group.pals.android.lib.ui.lockpattern.LockPatternActivity.java
group.pals.android.lib.ui.lockpattern.collect.Lists.java
group.pals.android.lib.ui.lockpattern.widget.LockPatternUtils.java
group.pals.android.lib.ui.lockpattern.widget.LockPatternView.java
org.unioeste.ilp.BaseActivity.java
org.unioeste.ilp.CollectSamplesActivity.java
org.unioeste.ilp.DatabaseExporterActivity.java
org.unioeste.ilp.ILPApp.java
org.unioeste.ilp.InsertPatternActivity.java
org.unioeste.ilp.LockPatternActivity.java
org.unioeste.ilp.MainMenuActivity.java
org.unioeste.ilp.PrefsActivity.java
org.unioeste.ilp.ShowPatternsActivity.java
org.unioeste.ilp.StartExperimentActivity.java
org.unioeste.ilp.TestAuthActivity.java
org.unioeste.ilp.adapters.ExperiencesUserAdapter.java
org.unioeste.ilp.adapters.LockPatternGalleryAdapter.java
org.unioeste.ilp.db.DBHelper.java
org.unioeste.ilp.models.AttemptDao.java
org.unioeste.ilp.models.Attempt.java
org.unioeste.ilp.models.DaoMaster.java
org.unioeste.ilp.models.DaoSession.java
org.unioeste.ilp.models.ExperienceDao.java
org.unioeste.ilp.models.Experience.java
org.unioeste.ilp.models.PatternDao.java
org.unioeste.ilp.models.Pattern.java
org.unioeste.ilp.models.SampleDao.java
org.unioeste.ilp.models.Sample.java
org.unioeste.ilp.models.UserDao.java
org.unioeste.ilp.models.User.java
org.unioeste.ilp.services.SamplesCollectorService.java