Android Open Source - Android-Backup Tasks Fragment






From Project

Back to project page Android-Backup.

License

The source code is released under:

GNU General Public License

If you think the Android project Android-Backup 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 com.Akkad.AndroidBackup;
/*from  ww  w  .  j  ava 2  s  .  co  m*/
import java.io.File;
import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.actionbarsherlock.app.SherlockListFragment;

public class TasksFragment extends SherlockListFragment {

  Core core = new Core();
  ArrayList<String> tasks;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    tasks = new ArrayList<String>();
    tasks.add(getString(R.string.wipe_dalvik_cache));
    tasks.add(getString(R.string.reboot_Device));
    tasks.add(getString(R.string.delete_All_Backups));

    /** Creating array adapter to set data in listview */
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity().getBaseContext(), android.R.layout.simple_list_item_1, tasks);

    /** Setting the array adapter to the listview */
    setListAdapter(adapter);

    return super.onCreateView(inflater, container, savedInstanceState);
  }

  /*
   * (non-Javadoc)
   * 
   * @see android.app.ListActivity#onListItemClick(android.widget.ListView, android.view.View, int, long)
   */
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    switch (position) {
    case 0:
      AlertDialog.Builder wipeDalvikCacheWarningDialog = new AlertDialog.Builder(getActivity());

      wipeDalvikCacheWarningDialog.setTitle(getString(R.string.wipe_dalvik_cache_warning_dialog_title));
      wipeDalvikCacheWarningDialog.setMessage(getString(R.string.wipe_dalvik_cache_warning_dialog_text));
      wipeDalvikCacheWarningDialog.setIcon(android.R.drawable.ic_dialog_alert);

      wipeDalvikCacheWarningDialog.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
          core.wipeDalvikCache();
        }
      });

      wipeDalvikCacheWarningDialog.setNegativeButton(getString(R.string.no), null);

      wipeDalvikCacheWarningDialog.show();
      break;
    case 1:
      core.rebootDevice();
      break;
    case 2:
      deleteAllBackups();
      break;
    }
  }

  public void deleteAllBackups() {

    File backupDirectory = new File(BackupStore.getBackupFolderLocation());
    boolean failed = false;
    String[] children = backupDirectory.list();
    for (int i = 0; i < children.length; i++) {
      if (!new File(backupDirectory, children[i]).delete()) {
        failed = true;
        break;
      }
    }
    if (!failed) { // If successful reload application
      Intent refresh = new Intent(getActivity(), AndroidBackupActivity.class);
      startActivity(refresh);
      getActivity().finish();
    } else {
      Toast.makeText(getActivity().getParent(), getString(R.string.delete_All_Backups_Failed_Message) + BackupStore.getBackupFolderLocation(), Toast.LENGTH_LONG).show();
    }
  }
}




Java Source Code List

com.Akkad.AndroidBackup.AndroidBackupActivity.java
com.Akkad.AndroidBackup.AppInfoAdapter.java
com.Akkad.AndroidBackup.ApplicationsFragment.java
com.Akkad.AndroidBackup.BackupListAdapter.java
com.Akkad.AndroidBackup.BackupStore.java
com.Akkad.AndroidBackup.Backup.java
com.Akkad.AndroidBackup.Core.java
com.Akkad.AndroidBackup.InformationFragment.java
com.Akkad.AndroidBackup.ScheduleFragment.java
com.Akkad.AndroidBackup.TabsPagerAdapter.java
com.Akkad.AndroidBackup.TasksFragment.java