@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = getActivity();
    mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    mPreferences.registerOnSharedPreferenceChangeListener(this);
    addPreferencesFromResource(R.layout.tools);

    mResidualFiles = findPreference(RESIDUAL_FILES);
    mOptimDB = findPreference(PREF_OPTIM_DB);

    long mStartTime = mPreferences.getLong(RESIDUAL_FILES, 0);
    mResidualFiles.setSummary("");
    if (mStartTime > 0) mResidualFiles.setSummary(DateUtils.getRelativeTimeSpanString(mStartTime));

    mStartTime = mPreferences.getLong(PREF_OPTIM_DB, 0);
    mOptimDB.setSummary("");
    if (mStartTime > 0) mOptimDB.setSummary(DateUtils.getRelativeTimeSpanString(mStartTime));

    if (Helpers.binExist("dd").equals(NOT_FOUND) || NO_FLASH) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("category_flash_img");
      getPreferenceScreen().removePreference(hideCat);
    }
    if (Helpers.binExist("pm").equals(NOT_FOUND)) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("category_freezer");
      getPreferenceScreen().removePreference(hideCat);
    }
    setRetainInstance(true);
    setHasOptionsMenu(true);
  }
 @Override
 protected void onPreExecute() {
   isrun = true;
   tip = 1;
   progressDialog =
       ProgressDialog.show(
           context, getString(R.string.fix_perms_title), getString(R.string.wait));
   Helpers.get_assetsScript("fix_permissions", context, "#", "");
   if (Helpers.isSystemApp(getActivity())) {
     new CMDProcessor()
         .sh.runWaitFor("busybox chmod 750 " + context.getFilesDir() + "/fix_permissions");
   } else {
     new CMDProcessor()
         .su.runWaitFor("busybox chmod 750 " + context.getFilesDir() + "/fix_permissions");
   }
 }
 @Override
 protected String doInBackground(String... params) {
   if (Helpers.isSystemApp(getActivity())) {
     new CMDProcessor().sh.runWaitFor(context.getFilesDir() + "/sql_optimize");
   } else {
     new CMDProcessor().su.runWaitFor(context.getFilesDir() + "/sql_optimize");
   }
   return null;
 }
 @Override
 protected String doInBackground(String... params) {
   final StringBuilder sb = new StringBuilder();
   sb.append("busybox rm -rf /data/dalvik-cache/*\n");
   sb.append("busybox rm -rf /cache/*\n");
   sb.append("reboot\n");
   Helpers.shExec(sb, context, true);
   return null;
 }
 @Override
 protected void onPreExecute() {
   isrun = true;
   tip = 2;
   progressDialog =
       ProgressDialog.show(
           context, getString(R.string.optim_db_title), getString(R.string.wait));
   mPreferences.edit().putLong(PREF_OPTIM_DB, System.currentTimeMillis()).commit();
   Helpers.get_assetsBinary("sqlite3", context);
   Helpers.get_assetsScript(
       "sql_optimize", context, "busybox chmod 750 " + context.getFilesDir() + "/sqlite3", "");
   if (Helpers.isSystemApp(getActivity())) {
     new CMDProcessor()
         .sh.runWaitFor("busybox chmod 750 " + context.getFilesDir() + "/sql_optimize");
   } else {
     new CMDProcessor()
         .su.runWaitFor("busybox chmod 750 " + context.getFilesDir() + "/sql_optimize");
   }
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   Helpers.removeCurItem(item, Menu.FIRST + 1, (ViewPager) getView().getParent());
   switch (item.getItemId()) {
     case R.id.app_settings:
       Intent intent = new Intent(context, PCSettings.class);
       startActivity(intent);
       break;
   }
   return true;
 }
 @Override
 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
   inflater.inflate(R.menu.tools_menu, menu);
   Helpers.addItems2Menu(
       menu, NEW_MENU_ID, getString(R.string.menu_tab), (ViewPager) getView().getParent());
 }