Android Open Source - timestatistic Export Import Backup Activity






From Project

Back to project page timestatistic.

License

The source code is released under:

GNU General Public License

If you think the Android project timestatistic 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 maximsblog.blogspot.com.timestatistic;
/* ww  w.j  a v a  2 s.  c om*/
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.actionbarsherlock.app.SherlockPreferenceActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.widget.Toast;

public class ExportImportBackupActivity extends SherlockPreferenceActivity
    implements OnPreferenceClickListener {

  private static final int OPENDB = 1;

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.export_import_backup);
    Preference p = findPreference("export");
    p.setOnPreferenceClickListener(this);
    p = findPreference("import");
    p.setOnPreferenceClickListener(this);
    p = findPreference("google_drive");
    p.setOnPreferenceClickListener(this);
    p = findPreference("export_to_gcalendar");
    p.setOnPreferenceClickListener(this);
    p = findPreference("export_to_csv");
    p.setOnPreferenceClickListener(this);
  }

  @Override
  public boolean onPreferenceClick(Preference preference) {
    if (preference.getKey().equals("export")) {
      OpenHelper o = new OpenHelper(getApplicationContext());
      String d = "";
      SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy");
      try {
        o.exportDatabase(
            getFilesDir(),
            d = getExternalFilesDir(null).getAbsolutePath()
                + File.separator + "timestat"
                + sdf.format(new Date()) + ".db");

      } catch (IOException e) {
        e.printStackTrace();
      }
      o.close();
      if (d.length() > 0)
        d = getString(R.string.exportok) + ":\n" + d;
      else
        d = getString(R.string.exportfail);
      Toast.makeText(getApplicationContext(), d, Toast.LENGTH_LONG)
          .show();

    } else if (preference.getKey().equals("google_drive")) {
      startActivity(new Intent(this, GdriveUpload.class));
    } else if (preference.getKey().equals("export_to_gcalendar")) {
      startActivity(new Intent(this, ExportToGoogleCalendarActivity.class));
    } else if(preference.getKey().equals("export_to_csv")){
      startActivity(new Intent(this, ExportToCSVActivity.class));
    } else {
      Intent intent = new Intent(this, FileDialog.class);
      intent.putExtra(FileDialog.FORMAT_FILTER, new String[] { ".db",
          ".sqlite" });
      intent.putExtra(FileDialog.SELECTION_MODE, SelectionMode.MODE_OPEN);
      startActivityForResult(intent, OPENDB);
    }
    return false;
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (data != null && requestCode == OPENDB && resultCode == RESULT_OK) {
      String newDbOpen = data.getStringExtra(FileDialog.RESULT_PATH);
      OpenHelper o = new OpenHelper(getApplicationContext());
      try {
        o.importDatabase(getFilesDir(), newDbOpen);

      } catch (IOException e) {
        e.printStackTrace();
      }
      o.close();
      Toast.makeText(getApplicationContext(),
          getString(R.string.importok), Toast.LENGTH_LONG).show();
      getContentResolver().notifyChange(
          RecordsDbHelper.CONTENT_URI_TIMES, null);
    }
    super.onActivityResult(requestCode, resultCode, data);
  }

}




Java Source Code List

maximsblog.blogspot.com.timestatistic.AboutActivity.java
maximsblog.blogspot.com.timestatistic.AboutFragment.java
maximsblog.blogspot.com.timestatistic.AlarmManagerBroadcastReceiver.java
maximsblog.blogspot.com.timestatistic.AreYouSureResetAllDialogFragment.java
maximsblog.blogspot.com.timestatistic.AreYouSureResetAllDialog.java
maximsblog.blogspot.com.timestatistic.BootUpReceiver.java
maximsblog.blogspot.com.timestatistic.CalendarSetupDialogFragment.java
maximsblog.blogspot.com.timestatistic.ColorPickerDialogFragment.java
maximsblog.blogspot.com.timestatistic.ColorPickerDialog.java
maximsblog.blogspot.com.timestatistic.CounterEditorDialogFragment.java
maximsblog.blogspot.com.timestatistic.CountersCursorAdapter.java
maximsblog.blogspot.com.timestatistic.CountersFragment.java
maximsblog.blogspot.com.timestatistic.CountersPeriodSetupDialogFragment.java
maximsblog.blogspot.com.timestatistic.CustomDateTimePicker.java
maximsblog.blogspot.com.timestatistic.DiagramFragment.java
maximsblog.blogspot.com.timestatistic.DiaryCursorAdapter.java
maximsblog.blogspot.com.timestatistic.DiaryEditorDialogFragment.java
maximsblog.blogspot.com.timestatistic.DiaryFragment.java
maximsblog.blogspot.com.timestatistic.ExportImportBackupActivity.java
maximsblog.blogspot.com.timestatistic.ExportToCSVActivity.java
maximsblog.blogspot.com.timestatistic.ExportToCSVService.java
maximsblog.blogspot.com.timestatistic.ExportToGoogleCalendarActivity.java
maximsblog.blogspot.com.timestatistic.ExportToGoogleCalendarService.java
maximsblog.blogspot.com.timestatistic.FileDialog.java
maximsblog.blogspot.com.timestatistic.FilterDateOption.java
maximsblog.blogspot.com.timestatistic.FilterDateSetDialogFragment.java
maximsblog.blogspot.com.timestatistic.FilterDialogFragment.java
maximsblog.blogspot.com.timestatistic.GdriveUpload.java
maximsblog.blogspot.com.timestatistic.HelpActivity.java
maximsblog.blogspot.com.timestatistic.HistoryFragment.java
maximsblog.blogspot.com.timestatistic.ICustomDateTimeListener.java
maximsblog.blogspot.com.timestatistic.IRecordDialog.java
maximsblog.blogspot.com.timestatistic.IdateChange.java
maximsblog.blogspot.com.timestatistic.Item.java
maximsblog.blogspot.com.timestatistic.MainActivity.java
maximsblog.blogspot.com.timestatistic.OpenHelper.java
maximsblog.blogspot.com.timestatistic.PeriodAnalyseActivity.java
maximsblog.blogspot.com.timestatistic.PeriodAnalyseFragment.java
maximsblog.blogspot.com.timestatistic.PeriodData.java
maximsblog.blogspot.com.timestatistic.PeriodSetupDialogFragment.java
maximsblog.blogspot.com.timestatistic.RecordsDbHelper.java
maximsblog.blogspot.com.timestatistic.SelectionMode.java
maximsblog.blogspot.com.timestatistic.SettingsActivity.java
maximsblog.blogspot.com.timestatistic.SplitRecordDialogFragment.java
maximsblog.blogspot.com.timestatistic.TimeRecordsFragment.java
maximsblog.blogspot.com.timestatistic.TimesCursorAdapter.java
maximsblog.blogspot.com.timestatistic.TopicActivity.java
maximsblog.blogspot.com.timestatistic.UnionRecordDialogFragment.java
maximsblog.blogspot.com.timestatistic.XYMultipleSeriesDatasetLoader.java
maximsblog.blogspot.com.timestatistic.app.java