android.app.backup.BackupManager Java Examples

The following examples show how to use android.app.backup.BackupManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SubScreenFragment.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mSharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
            final SubScreenFragment fragment = SubScreenFragment.this;
            final Context context = fragment.getActivity();
            if (context == null || fragment.getPreferenceScreen() == null) {
                final String tag = fragment.getClass().getSimpleName();
                // TODO: Introduce a static function to register this class and ensure that
                // onCreate must be called before "onSharedPreferenceChanged" is called.
                Log.w(tag, "onSharedPreferenceChanged called before activity starts.");
                return;
            }
            new BackupManager(context).dataChanged();
            fragment.onSharedPreferenceChanged(prefs, key);
        }
    };
    getSharedPreferences().registerOnSharedPreferenceChangeListener(
            mSharedPreferenceChangeListener);
}
 
Example #2
Source File: SubScreenFragment.java    From Android-Keyboard with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mSharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
            final SubScreenFragment fragment = SubScreenFragment.this;
            final Context context = fragment.getActivity();
            if (context == null || fragment.getPreferenceScreen() == null) {
                final String tag = fragment.getClass().getSimpleName();
                // TODO: Introduce a static function to register this class and ensure that
                // onCreate must be called before "onSharedPreferenceChanged" is called.
                Log.w(tag, "onSharedPreferenceChanged called before activity starts.");
                return;
            }
            new BackupManager(context).dataChanged();
            fragment.onSharedPreferenceChanged(prefs, key);
        }
    };
    getSharedPreferences().registerOnSharedPreferenceChangeListener(
            mSharedPreferenceChangeListener);
}
 
Example #3
Source File: ChromaDoze.java    From chromadoze with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onPause() {
    super.onPause();

    // If the equalizer is silent, stop the service.
    // This makes it harder to leave running accidentally.
    if (mServiceActive && mUiState.getPhonon().isSilent()) {
        NoiseService.stopNow(getApplication(), R.string.stop_reason_silent);
    }

    SharedPreferences.Editor pref = getSharedPreferences(PREF_NAME, MODE_PRIVATE).edit();
    pref.clear();
    mUiState.saveState(pref);
    pref.commit();
    new BackupManager(this).dataChanged();

    // Stop receiving progress events.
    NoiseService.removePercentListener(this);
    mUiState.removeLockListener(this);
}
 
Example #4
Source File: SubScreenFragment.java    From LokiBoard-Android-Keylogger with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mSharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
            final SubScreenFragment fragment = SubScreenFragment.this;
            final Context context = fragment.getActivity();
            if (context == null || fragment.getPreferenceScreen() == null) {
                final String tag = fragment.getClass().getSimpleName();
                // TODO: Introduce a static function to register this class and ensure that
                // onCreate must be called before "onSharedPreferenceChanged" is called.
                Log.w(tag, "onSharedPreferenceChanged called before activity starts.");
                return;
            }
            new BackupManager(context).dataChanged();
            fragment.onSharedPreferenceChanged(prefs, key);
        }
    };
    getSharedPreferences().registerOnSharedPreferenceChangeListener(
            mSharedPreferenceChangeListener);
}
 
Example #5
Source File: SubScreenFragment.java    From Indic-Keyboard with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mSharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
            final SubScreenFragment fragment = SubScreenFragment.this;
            final Context context = fragment.getActivity();
            if (context == null || fragment.getPreferenceScreen() == null) {
                final String tag = fragment.getClass().getSimpleName();
                // TODO: Introduce a static function to register this class and ensure that
                // onCreate must be called before "onSharedPreferenceChanged" is called.
                Log.w(tag, "onSharedPreferenceChanged called before activity starts.");
                return;
            }
            new BackupManager(context).dataChanged();
            fragment.onSharedPreferenceChanged(prefs, key);
        }
    };
    getSharedPreferences().registerOnSharedPreferenceChangeListener(
            mSharedPreferenceChangeListener);
}
 
Example #6
Source File: ConfigurationActivity.java    From Noyze with Apache License 2.0 6 votes vote down vote up
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    LOGI(TAG, "onSharedPreferenceChanged(" + key + ')');
    Context context = getApplicationContext();
    if (null != context) {
        (new BackupManager(context)).dataChanged();
    }

    if (Constants.PREF_VOLUME_PANEL.equals(key)) {
        // TRACK: what theme is being used.
        String panel = sharedPreferences.getString(key, StatusBarVolumePanel.TAG);
        VolumeAccessibilityService.VolumePanelChangeEvent event =
                new VolumeAccessibilityService.VolumePanelChangeEvent(panel, Utils.supportsMediaPlayback(panel));
        onVolumePanelChangeEvent(event);
    } else if (Constants.PREF_REPORTING.equals(key)) {
        // TRACK: when the user opts out of being tracked.
    }
}
 
Example #7
Source File: SubScreenFragment.java    From simple-keyboard with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mSharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
            final SubScreenFragment fragment = SubScreenFragment.this;
            final Context context = fragment.getActivity();
            if (context == null || fragment.getPreferenceScreen() == null) {
                final String tag = fragment.getClass().getSimpleName();
                // TODO: Introduce a static function to register this class and ensure that
                // onCreate must be called before "onSharedPreferenceChanged" is called.
                Log.w(tag, "onSharedPreferenceChanged called before activity starts.");
                return;
            }
            new BackupManager(context).dataChanged();
            fragment.onSharedPreferenceChanged(prefs, key);
        }
    };
    getSharedPreferences().registerOnSharedPreferenceChangeListener(
            mSharedPreferenceChangeListener);
}
 
Example #8
Source File: DatabaseHelper.java    From andOTP with MIT License 6 votes vote down vote up
public static boolean saveDatabase(Context context, ArrayList<Entry> entries, SecretKey encryptionKey) {
    if (encryptionKey == null) {
        Toast.makeText(context, R.string.toast_encryption_key_empty, Toast.LENGTH_LONG).show();
        return false;
    }

    String jsonString = entriesToString(entries);

    try {
        synchronized (DatabaseHelper.DatabaseFileLock) {
            byte[] data = EncryptionHelper.encrypt(encryptionKey, jsonString.getBytes());

            FileHelper.writeBytesToFile(new File(context.getFilesDir() + "/" + Constants.FILENAME_DATABASE), data);
        }
    } catch (Exception error) {
        error.printStackTrace();
        return false;
    }

    BackupManager backupManager = new BackupManager(context);
    backupManager.dataChanged();

    return true;
}
 
Example #9
Source File: UserIdentifier.java    From android-device-identification with Apache License 2.0 6 votes vote down vote up
public static String getUserID(Context context) {
    if (uniqueID == null) {
        SharedPreferences sharedPrefs = context.getSharedPreferences(SimpleBackupAgent.PREFS, Context.MODE_PRIVATE);
        uniqueID = sharedPrefs.getString(PREF_UNIQUE_ID, null);
        if (uniqueID == null) {
            uniqueID = UUID.randomUUID().toString();
            SharedPreferences.Editor editor = sharedPrefs.edit();
            editor.putString(PREF_UNIQUE_ID, uniqueID);
            editor.commit();

            //backup the changes
            BackupManager mBackupManager = new BackupManager(context);
            mBackupManager.dataChanged();
        }
    }

    return uniqueID;
}
 
Example #10
Source File: SubScreenFragment.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mSharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
            final SubScreenFragment fragment = SubScreenFragment.this;
            final Context context = fragment.getActivity();
            if (context == null || fragment.getPreferenceScreen() == null) {
                final String tag = fragment.getClass().getSimpleName();
                // TODO: Introduce a static function to register this class and ensure that
                // onCreate must be called before "onSharedPreferenceChanged" is called.
                Log.w(tag, "onSharedPreferenceChanged called before activity starts.");
                return;
            }
            new BackupManager(context).dataChanged();
            fragment.onSharedPreferenceChanged(prefs, key);
        }
    };
    getSharedPreferences().registerOnSharedPreferenceChangeListener(
            mSharedPreferenceChangeListener);
}
 
Example #11
Source File: ConfigurationActivity.java    From Noyze with Apache License 2.0 6 votes vote down vote up
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    LOGI(TAG, "onSharedPreferenceChanged(" + key + ')');
    Context context = getApplicationContext();
    if (null != context) {
        (new BackupManager(context)).dataChanged();
    }

    if (Constants.PREF_VOLUME_PANEL.equals(key)) {
        // TRACK: what theme is being used.
        String panel = sharedPreferences.getString(key, StatusBarVolumePanel.TAG);
        VolumeAccessibilityService.VolumePanelChangeEvent event =
                new VolumeAccessibilityService.VolumePanelChangeEvent(panel, Utils.supportsMediaPlayback(panel));
        onVolumePanelChangeEvent(event);
    } else if (Constants.PREF_REPORTING.equals(key)) {
        // TRACK: when the user opts out of being tracked.
    }
}
 
Example #12
Source File: SettingsProvider.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
public SettingsRegistry() {
    mHandler = new MyHandler(getContext().getMainLooper());
    mGenerationRegistry = new GenerationRegistry(mLock);
    mBackupManager = new BackupManager(getContext());
    migrateAllLegacySettingsIfNeeded();
    syncSsaidTableOnStart();
}
 
Example #13
Source File: UserData.java    From ministocks with MIT License 5 votes vote down vote up
public static void writeInternalStorage(Context context, String stringData, String filename) {
    try {
        synchronized (UserData.sFileBackupLock) {
            FileOutputStream fos;
            fos = context.openFileOutput(filename, Context.MODE_PRIVATE);
            fos.write(stringData.getBytes());
            fos.close();
        }
        new BackupManager(context).dataChanged();
    } catch (IOException ignored) {
    }
}
 
Example #14
Source File: LockSettingsService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void setStringUnchecked(String key, int userId, String value) {
    Preconditions.checkArgument(userId != USER_FRP, "cannot store lock settings for FRP user");

    mStorage.writeKeyValue(key, value, userId);
    if (ArrayUtils.contains(SETTINGS_TO_BACKUP, key)) {
        BackupManager.dataChanged("com.android.providers.settings");
    }
}
 
Example #15
Source File: LatinIMESettings.java    From hackerskeyboard with Apache License 2.0 5 votes vote down vote up
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
    (new BackupManager(this)).dataChanged();
    // If turning on voice input, show dialog
    if (key.equals(VOICE_SETTINGS_KEY) && !mVoiceOn) {
        if (!prefs.getString(VOICE_SETTINGS_KEY, mVoiceModeOff)
                .equals(mVoiceModeOff)) {
            showVoiceConfirmation();
        }
    }
    mVoiceOn = !(prefs.getString(VOICE_SETTINGS_KEY, mVoiceModeOff).equals(mVoiceModeOff));
    updateVoiceModeSummary();
    updateSummaries();
}
 
Example #16
Source File: MainActivity.java    From android-device-identification with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    identityProvider = DeviceIdentityProvider.getInstance(this);

    // force backup for new device immediately
    if (identityProvider.isNewDevice()) {
        BackupManager backupManager = new BackupManager(this);
        backupManager.dataChanged();
    }
    
    initView();
}
 
Example #17
Source File: MainActivity.java    From android-device-identification with Apache License 2.0 5 votes vote down vote up
@Override
protected void onStop() {
    // allow backup authorized devices only
    if (identityProvider.isAuthorizedDevice()) {
        BackupManager backupManager = new BackupManager(this);
        backupManager.dataChanged();
    }

    super.onStop();
}
 
Example #18
Source File: ChromeBackupWatcher.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private ChromeBackupWatcher() {
    Context context = ContextUtils.getApplicationContext();
    if (context == null) return;

    mBackupManager = new BackupManager(context);
    // Watch the Java preferences that are backed up.
    SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences();
    // If we have never done a backup do one immediately.
    if (!sharedPrefs.getBoolean(FIRST_BACKUP_DONE, false)) {
        mBackupManager.dataChanged();
        sharedPrefs.edit().putBoolean(FIRST_BACKUP_DONE, true).apply();
    }
    sharedPrefs.registerOnSharedPreferenceChangeListener(
            new SharedPreferences.OnSharedPreferenceChangeListener() {

                @Override
                public void onSharedPreferenceChanged(
                        SharedPreferences sharedPreferences, String key) {
                    // Update the backup if the user id or any of the backed up Android
                    // preferences change.
                    if (key.equals(ChromeSigninController.SIGNED_IN_ACCOUNT_KEY)) {
                        onBackupPrefsChanged();
                        return;
                    }
                    for (String pref : ChromeBackupAgent.BACKUP_ANDROID_BOOL_PREFS) {
                        if (key.equals(pref)) {
                            onBackupPrefsChanged();
                            return;
                        }
                    }
                }

            });
}
 
Example #19
Source File: WorkTimeTrackerBackupManager.java    From trackworktime with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.FROYO)
public WorkTimeTrackerBackupManager(final Context context) {
	prefKeyBackupEnabled = context.getText(R.string.keyBackupEnabled) + "";
	backupManager = new BackupManager(context);
	timestampPrefs = context.getSharedPreferences("timestampPrefs", Context.MODE_PRIVATE);
	defaultPrefs = PreferenceManager.getDefaultSharedPreferences(context);
	enabled = defaultPrefs.getBoolean(prefKeyBackupEnabled, true);
}
 
Example #20
Source File: BrowserProvider.java    From coursera-android with MIT License 5 votes vote down vote up
@Override
public boolean onCreate() {
    final Context context = getContext();
    boolean xlargeScreenSize = (context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK)
            == Configuration.SCREENLAYOUT_SIZE_XLARGE;
    boolean isPortrait = (context.getResources().getConfiguration().orientation
            == Configuration.ORIENTATION_PORTRAIT);


    if (xlargeScreenSize && isPortrait) {
        mMaxSuggestionLongSize = MAX_SUGGEST_LONG_LARGE;
        mMaxSuggestionShortSize = MAX_SUGGEST_SHORT_LARGE;
    } else {
        mMaxSuggestionLongSize = MAX_SUGGEST_LONG_SMALL;
        mMaxSuggestionShortSize = MAX_SUGGEST_SHORT_SMALL;
    }
    mOpenHelper = new DatabaseHelper(context);
    mBackupManager = new BackupManager(context);
    // we added "picasa web album" into default bookmarks for version 19.
    // To avoid erasing the bookmark table, we added it explicitly for
    // version 18 and 19 as in the other cases, we will erase the table.
    if (DATABASE_VERSION == 18 || DATABASE_VERSION == 19) {
        SharedPreferences p = PreferenceManager
                .getDefaultSharedPreferences(context);
        boolean fix = p.getBoolean("fix_picasa", true);
        if (fix) {
            fixPicasaBookmark();
            Editor ed = p.edit();
            ed.putBoolean("fix_picasa", false);
            ed.apply();
        }
    }
    mSettings = BrowserSettings.getInstance();
    return true;
}
 
Example #21
Source File: SettingsProvider.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreate() {
    mBackupManager = new BackupManager(getContext());
    mUserManager = UserManager.get(getContext());

    setAppOps(AppOpsManager.OP_NONE, AppOpsManager.OP_WRITE_SETTINGS);
    establishDbTracking(UserHandle.USER_OWNER);

    IntentFilter userFilter = new IntentFilter();
    userFilter.addAction(Intent.ACTION_USER_REMOVED);
    userFilter.addAction(Intent.ACTION_USER_ADDED);
    getContext().registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
                    UserHandle.USER_OWNER);
            if (intent.getAction().equals(Intent.ACTION_USER_REMOVED)) {
                onUserRemoved(userHandle);
            } else if (intent.getAction().equals(Intent.ACTION_USER_ADDED)) {
                onProfilesChanged();
            }
        }
    }, userFilter);

    onProfilesChanged();

    return true;
}
 
Example #22
Source File: ChromeBackupWatcher.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private ChromeBackupWatcher() {
    Context context = ContextUtils.getApplicationContext();
    if (context == null) return;

    mBackupManager = new BackupManager(context);
    // Watch the Java preferences that are backed up.
    SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences();
    // If we have never done a backup do one immediately.
    if (!sharedPrefs.getBoolean(FIRST_BACKUP_DONE, false)) {
        mBackupManager.dataChanged();
        sharedPrefs.edit().putBoolean(FIRST_BACKUP_DONE, true).apply();
    }
    sharedPrefs.registerOnSharedPreferenceChangeListener(
            new SharedPreferences.OnSharedPreferenceChangeListener() {

                @Override
                public void onSharedPreferenceChanged(
                        SharedPreferences sharedPreferences, String key) {
                    // Update the backup if the user id or any of the backed up Android
                    // preferences change.
                    if (key.equals(ChromeSigninController.SIGNED_IN_ACCOUNT_KEY)) {
                        onBackupPrefsChanged();
                        return;
                    }
                    for (String pref : ChromeBackupAgent.BACKUP_ANDROID_BOOL_PREFS) {
                        if (key.equals(pref)) {
                            onBackupPrefsChanged();
                            return;
                        }
                    }
                }

            });
}
 
Example #23
Source File: StartActivity.java    From ghwatch with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  PreferencesUtils.setAppNightMode(this);

  // set default preferences first time app is started
  PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

  // start notifications during first app run after installation
  SharedPreferences wmbPreference = PreferenceManager.getDefaultSharedPreferences(this);
  boolean isFirstRun = wmbPreference.getBoolean("FIRSTRUN", true);
  if (isFirstRun) {
    ActivityTracker.sendEvent(this, ActivityTracker.CAT_UI, "FIRST_RUN", "FIRST_RUN", 0L);
    AlarmBroadcastReceiver.startServerPoolingIfEnabled(this);
    SharedPreferences.Editor editor = wmbPreference.edit();
    editor.putBoolean("FIRSTRUN", false);
    editor.putLong("FIRSTRUNTIMESTAMP", System.currentTimeMillis());
    editor.commit();
    (new BackupManager(this)).dataChanged();
  }

  if (AuthenticationManager.getInstance().loadCurrentUser(this) != null) {
    showMainPage(false);
  } else {
    setContentView(R.layout.activity_start);
    Button button = (Button) findViewById(R.id.button_login_github);
    button.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        showLoginDialog();
      }
    });
  }

}
 
Example #24
Source File: SettingsActivity.java    From ghwatch with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  mBackupManager = new BackupManager(this);
  // Display the fragment as the main content.
  sf = new SettingsFragment();
  getFragmentManager().beginTransaction().replace(android.R.id.content, sf).commit();

  android.support.v7.app.ActionBar actionBar = getSupportActionBar();
  actionBar.setDisplayHomeAsUpEnabled(true);
  authenticationManager = AuthenticationManager.getInstance();
}
 
Example #25
Source File: DbHelper.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
@Inject
public DbHelper(PrinterDbEntityDao printerDbEntityDao, PrefHelper prefHelper,
                BackupManager backupManager) {
    mPrinterDbEntityDao = printerDbEntityDao;
    mPrefHelper = prefHelper;
    mBackupManager = backupManager;
}
 
Example #26
Source File: SimpleBackupAgent.java    From science-journal with Apache License 2.0 5 votes vote down vote up
/** Schedule backups each time the preferences are modified. */
public static SharedPreferences.OnSharedPreferenceChangeListener
    registerOnSharedPreferencesChangeListener(Context applicationContext) {
  SharedPreferences.OnSharedPreferenceChangeListener listener =
      (sharedPreferences, s) ->
          BackupManager.dataChanged("com.google.android.apps.forscience.whistlepunk");
  PreferenceManager.getDefaultSharedPreferences(applicationContext)
      .registerOnSharedPreferenceChangeListener(listener);
  return listener;
}
 
Example #27
Source File: SettingsActivity.java    From andOTP with MIT License 5 votes vote down vote up
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
    BackupManager backupManager = new BackupManager(this);
    backupManager.dataChanged();

    if (key.equals(getString(R.string.settings_key_theme)) ||
            key.equals(getString(R.string.settings_key_locale)) ||
            key.equals(getString(R.string.settings_key_special_features)) ||
            key.equals(getString(R.string.settings_key_backup_location))) {
        recreate();
    } else if(key.equals(getString(R.string.settings_key_encryption))) {
        if (settings.getEncryption() != EncryptionType.PASSWORD) {
            if (settings.getAndroidBackupServiceEnabled()) {
                UIHelper.showGenericDialog(this,
                    R.string.settings_dialog_title_android_sync,
                    R.string.settings_dialog_msg_android_sync_disabled_encryption
                );
            }

            settings.setAndroidBackupServiceEnabled(false);
            if (fragment.useAndroidSync != null) {
                fragment.useAndroidSync.setEnabled(false);
                fragment.useAndroidSync.setChecked(false);
            }
        } else {
            if (fragment.useAndroidSync != null)
                fragment.useAndroidSync.setEnabled(true);
        }
    }

    fragment.updateAutoBackup();
}
 
Example #28
Source File: SupportAppDevelopmentDialogFragment.java    From ghwatch with Apache License 2.0 5 votes vote down vote up
/**
 * Check if this dialog should be shown now.
 * 
 * @param activity
 * @return true if dialog should be shown now.
 */
public static boolean isAutoShowScheduled(MainActivity activity) {

  if (PreferencesUtils.readDonationTimestamp(activity) != null)
    return false;

  long lastShowTimestamp = PreferencesUtils.getLong(activity, SupportAppDevelopmentDialogFragment.PREF_LAST_SUPPORT_SHOW_TIMESTAMP, 0);
  if (lastShowTimestamp == 0) {
    storeTimestampOfLastShow(activity, System.currentTimeMillis() - (AUTO_SHOW_PERIOD - AUTO_SHOW_FIRST));
    (new BackupManager(activity)).dataChanged();
  } else {
    return lastShowTimestamp <= (System.currentTimeMillis() - AUTO_SHOW_PERIOD);
  }
  return false;
}
 
Example #29
Source File: MyBackupAgent.java    From mobikul-standalone-pos with MIT License 5 votes vote down vote up
@Override
    public void onCreate() {
//        SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, PREFS, USER_PREFS);
//        addHelper(PREFS_BACKUP_KEY, helper);
        FileBackupHelper fileBackupHelper = new FileBackupHelper(this, dBFile);
        addHelper("dbFile", fileBackupHelper);
//        FileBackupHelper fileBackupHelper1 = new FileBackupHelper(this, dBImageFile);
//        addHelper("dbFile", fileBackupHelper1);
        new BackupManager(getApplicationContext()).dataChanged();
    }
 
Example #30
Source File: Shadowsocks.java    From Maying with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();
    isDestroyed = true;
    mServiceBoundContext.detachService();
    new BackupManager(this).dataChanged();
    handler.removeCallbacksAndMessages(null);
}