Android Open Source - PhoneProfiles_Eclipse Remote Export Data Activity






From Project

Back to project page PhoneProfiles_Eclipse.

License

The source code is released under:

Apache License

If you think the Android project PhoneProfiles_Eclipse 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 sk.henrichg.phoneprofiles;
/*w  w w .  ja v  a 2s .  c  o m*/
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;

public class RemoteExportDataActivity extends Activity {

  private DataWrapper dataWrapper;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Log.e("RemoteExportDataActivity.onCreate", "xxx");
    
    dataWrapper = new DataWrapper(getBaseContext(), false, false, 0);
    
  }
  
  @Override
  protected void onStart()
  {
    super.onStart();
    exportProfiles();
  }
  
  @Override
  protected void onDestroy()
  {
    super.onDestroy();

    dataWrapper.invalidateDataWrapper();
    dataWrapper = null;
  }  
  
  
  private boolean exportApplicationPreferences(File dst) {
      boolean res = false;
      ObjectOutputStream output = null;
      try {
          output = new ObjectOutputStream(new FileOutputStream(dst));
          SharedPreferences pref = getBaseContext().getSharedPreferences(GlobalData.APPLICATION_PREFS_NAME, Activity.MODE_PRIVATE);
          output.writeObject(pref.getAll());

          res = true;
      } catch (FileNotFoundException e) {
        // this is OK
          //e.printStackTrace();
        res = true;
      } catch (IOException e) {
          e.printStackTrace();
      }finally {
          try {
              if (output != null) {
                  output.flush();
                  output.close();
              }
          } catch (IOException ex) {
              ex.printStackTrace();
          }
      }
      return res;
  }
  
  private void exportProfiles()
  {
    
    // set theme and language for dialog alert ;-)
    // not working on Android 2.3.x
    GUIData.setTheme(this, true);
    GUIData.setLanguage(getBaseContext());
    
    final Activity activity = this;
    
    class ExportAsyncTask extends AsyncTask<Void, Integer, Integer> 
    {
      
      private ProgressDialog dialog;
      
      ExportAsyncTask()
      {
             this.dialog = new ProgressDialog(activity);
      }
        
      @Override
      protected void onPreExecute()
      {
        super.onPreExecute();

           this.dialog.setMessage(getResources().getString(R.string.export_profiles_alert_title));
           this.dialog.show();            
      }
      
      @Override
      protected Integer doInBackground(Void... params) {
        int ret = dataWrapper.getDatabaseHandler().exportDB();
        if (ret == 1)
        {
          File sd = Environment.getExternalStorageDirectory();
          File exportFile = new File(sd, GlobalData.EXPORT_PATH + "/" + GUIData.EXPORT_APP_PREF_FILENAME);
          if (!exportApplicationPreferences(exportFile))
            ret = 0;
        }
        return ret;
      }
      
      @Override
      protected void onPostExecute(Integer result)
      {
        super.onPostExecute(result);
        
          if (dialog.isShowing())
                dialog.dismiss();
        
        //Log.e("RemoteExportDataActivity.onPostExecute","result="+result);
          
        if (result == 1)
        {
          Intent returnIntent = new Intent();
          activity.setResult(RESULT_OK,returnIntent);
          activity.finish();
        }
        else
        {
          exportErrorDialog();
          Intent returnIntent = new Intent();
          activity.setResult(RESULT_CANCELED,returnIntent);
          activity.finish();
        }
      }
    }
    
    new ExportAsyncTask().execute();
        
  }
  
  private void exportErrorDialog()
  {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    dialogBuilder.setTitle(getResources().getString(R.string.export_profiles_alert_title));
    String resMessage;
    resMessage = getResources().getString(R.string.export_profiles_alert_error);
    dialogBuilder.setMessage(resMessage + "!");
    //dialogBuilder.setIcon(android.R.drawable.ic_dialog_alert);
    dialogBuilder.setPositiveButton(android.R.string.ok, null);
    dialogBuilder.show();
  }
  
  
  
}




Java Source Code List

sk.henrichg.phoneprofiles.ActivateProfileActivity.java
sk.henrichg.phoneprofiles.ActivateProfileHelper.java
sk.henrichg.phoneprofiles.ActivateProfileListAdapter.java
sk.henrichg.phoneprofiles.ActivateProfileListFragment.java
sk.henrichg.phoneprofiles.ApplicationsCache.java
sk.henrichg.phoneprofiles.ApplicationsPreferenceAdapter.java
sk.henrichg.phoneprofiles.ApplicationsPreferenceDialog.java
sk.henrichg.phoneprofiles.ApplicationsPreference.java
sk.henrichg.phoneprofiles.BackgroundActivateProfileActivity.java
sk.henrichg.phoneprofiles.BitmapManipulator.java
sk.henrichg.phoneprofiles.BootUpReceiver.java
sk.henrichg.phoneprofiles.BrightnessDialogPreference.java
sk.henrichg.phoneprofiles.BrightnessView.java
sk.henrichg.phoneprofiles.DashClockBroadcastReceiver.java
sk.henrichg.phoneprofiles.DataWrapper.java
sk.henrichg.phoneprofiles.DatabaseHandler.java
sk.henrichg.phoneprofiles.EditorProfileListAdapter.java
sk.henrichg.phoneprofiles.EditorProfileListFragment.java
sk.henrichg.phoneprofiles.EditorProfilesActivity.java
sk.henrichg.phoneprofiles.ExecuteRadioProfilePrefsService.java
sk.henrichg.phoneprofiles.ExecuteVolumeProfilePrefsService.java
sk.henrichg.phoneprofiles.FirstStartService.java
sk.henrichg.phoneprofiles.GUIData.java
sk.henrichg.phoneprofiles.GlobalData.java
sk.henrichg.phoneprofiles.IconWidgetProvider.java
sk.henrichg.phoneprofiles.ImageViewPreferenceAdapter.java
sk.henrichg.phoneprofiles.ImageViewPreferenceDialog.java
sk.henrichg.phoneprofiles.ImageViewPreference.java
sk.henrichg.phoneprofiles.KeyguardService.java
sk.henrichg.phoneprofiles.Keyguard.java
sk.henrichg.phoneprofiles.LocaleChangedReceiver.java
sk.henrichg.phoneprofiles.NumberPickerPreference.java
sk.henrichg.phoneprofiles.OneRowWidgetProvider.java
sk.henrichg.phoneprofiles.PackageReplacedReceiver.java
sk.henrichg.phoneprofiles.PhoneCallBroadcastReceiver.java
sk.henrichg.phoneprofiles.PhoneCallReceiver.java
sk.henrichg.phoneprofiles.PhoneProfilesDashClockExtension.java
sk.henrichg.phoneprofiles.PhoneProfilesHelper.java
sk.henrichg.phoneprofiles.PhoneProfilesPreferencesActivity.java
sk.henrichg.phoneprofiles.PhoneProfilesPreferencesFragment.java
sk.henrichg.phoneprofiles.ProfileDurationAlarmBroadcastReceiver.java
sk.henrichg.phoneprofiles.ProfileListWidgetFactory.java
sk.henrichg.phoneprofiles.ProfileListWidgetProvider.java
sk.henrichg.phoneprofiles.ProfileListWidgetService.java
sk.henrichg.phoneprofiles.ProfilePreferenceAdapter.java
sk.henrichg.phoneprofiles.ProfilePreferenceDialog.java
sk.henrichg.phoneprofiles.ProfilePreference.java
sk.henrichg.phoneprofiles.ProfilePreferencesFragmentActivity.java
sk.henrichg.phoneprofiles.ProfilePreferencesFragment.java
sk.henrichg.phoneprofiles.ProfilePreferencesIndicator.java
sk.henrichg.phoneprofiles.Profile.java
sk.henrichg.phoneprofiles.ReceiversService.java
sk.henrichg.phoneprofiles.RefreshGUIBroadcastReceiver.java
sk.henrichg.phoneprofiles.RemoteExportDataActivity.java
sk.henrichg.phoneprofiles.RemoveBrightnessViewBroadcastReceiver.java
sk.henrichg.phoneprofiles.ScreenOnOffBroadcastReceiver.java
sk.henrichg.phoneprofiles.ShortcutCreatorActivity.java
sk.henrichg.phoneprofiles.ShortcutCreatorListFragment.java
sk.henrichg.phoneprofiles.ShortcutProfileListAdapter.java
sk.henrichg.phoneprofiles.UpgradePPHelperActivity.java
sk.henrichg.phoneprofiles.VolumeDialogPreference.java