Java Code Examples for android.app.backup.BackupManager

The following are top voted examples for showing how to use android.app.backup.BackupManager. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: simple-keyboard   File: SubScreenFragment.java   View source code 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
Project: buildAPKsSamples   File: BackupRestoreActivity.java   View source code 6 votes vote down vote up
/** Set up the activity and populate its UI from the persistent data. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /** Establish the activity's UI */
    setContentView(R.layout.backup_restore);

    /** Once the UI has been inflated, cache the controls for later */
    mFillingGroup = (RadioGroup) findViewById(R.id.filling_group);
    mAddMayoCheckbox = (CheckBox) findViewById(R.id.mayo);
    mAddTomatoCheckbox = (CheckBox) findViewById(R.id.tomato);

    /** Set up our file bookkeeping */
    mDataFile = new File(getFilesDir(), BackupRestoreActivity.DATA_FILE_NAME);

    /** It is handy to keep a BackupManager cached */
    mBackupManager = new BackupManager(this);

    /**
     * Finally, build the UI from the persistent store
     */
    populateUI();
}
 
Example 3
Project: AOSP-Kayboard-7.1.2   File: SubScreenFragment.java   View source code 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 4
Project: dashbar   File: ExtensionManager.java   View source code 6 votes vote down vote up
/**
 * Replaces the set of active extensions with the given list.
 */
public void setInternalActiveExtensions(List<ComponentName> extensions) {
    StringBuilder sb = new StringBuilder();

    for (ComponentName extension : extensions) {
        if (sb.length() > 0) {
            sb.append(",");
        }
        sb.append(extension.flattenToString());
    }

    mDefaultPreferences.edit()
            .putString(PREF_ACTIVE_EXTENSIONS, sb.toString())
            .apply();
    new BackupManager(mApplicationContext).dataChanged();

    mInternalActiveExtensions.clear();
    mInternalActiveExtensions.addAll(extensions);
    setActiveExtensions(getActiveExtensionNames());
}
 
Example 5
Project: dashbar   File: ConfigureAdvancedFragment.java   View source code 6 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences sp, String key) {
    new BackupManager(getActivity()).dataChanged();

    // Potentially enable/disable the launcher activity if the settings button
    // preference has changed.
    if (isAdded() && AppearanceConfig.PREF_SETTINGS_BUTTON.equals(key)) {
        boolean enableLauncher = AppearanceConfig.PREF_SETTINGS_BUTTON_IN_LAUNCHER.equals(
                sp.getString(AppearanceConfig.PREF_SETTINGS_BUTTON, null));
        getActivity().getPackageManager().setComponentEnabledSetting(
                new ComponentName(
                        getActivity().getPackageName(),
                        ConfigurationActivity.LAUNCHER_ACTIVITY_NAME),
                enableLauncher
                        ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                        : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
    }
}
 
Example 6
Project: geohashdroid   File: PreferencesScreen.java   View source code 6 votes vote down vote up
@Override
public void onStop() {
    // If something changed, tell WikiService to kick back in.  Don't
    // worry; if WikiService isn't paused, this won't do anything, and
    // if it's stopped for any other reason, it'll stop again when this
    // comes in.
    if(mHasChanged) {
        mHasChanged = false;
        Intent i = new Intent(getActivity(), WikiService.class);
        i.putExtra(QueueService.COMMAND_EXTRA, QueueService.COMMAND_RESUME);
        getActivity().startService(i);
    }

    BackupManager bm = new BackupManager(getActivity());
    bm.dataChanged();

    super.onStop();
}
 
Example 7
Project: geohashdroid   File: BaseGHDThemeActivity.java   View source code 6 votes vote down vote up
/**
 * <p>
 * Sets whether or not the app is in night mode.
 * </p>
 *
 * <p>
 * <b>NOTE:</b> If the state of night mode changes, <b>the Activity WILL be
 * recreated</b>, as that's the only way you can change themes on-the-fly.
 * Make sure you've done whatever you need to BEFORE calling this, as there
 * is NO guarantee execution will meaningfully continue past this!
 * </p>
 *
 * @param night true to be night, false to be not night
 */
protected void setNightMode(boolean night) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    // Remember, ONLY act on this if this changed at all!
    if(prefs.getBoolean(GHDConstants.PREF_NIGHT_MODE, false) != night) {
        SharedPreferences.Editor edit = prefs.edit();
        edit.putBoolean(GHDConstants.PREF_NIGHT_MODE, night);
        edit.apply();

        BackupManager bm = new BackupManager(this);
        bm.dataChanged();

        recreate();
    }
}
 
Example 8
Project: geohashdroid   File: CentralMap.java   View source code 6 votes vote down vote up
private void updateLastGraticule(@NonNull Info info) {
    // This'll just stash the last Graticule away in preferences so we can
    // start with the last-used one if preferences demand it as such.
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    SharedPreferences.Editor edit = prefs.edit();

    edit.putBoolean(GHDConstants.PREF_DEFAULT_GRATICULE_GLOBALHASH, info.isGlobalHash());
    Graticule g = info.getGraticule();

    if(g != null) {
        edit.putString(GHDConstants.PREF_DEFAULT_GRATICULE_LATITUDE, g.getLatitudeString(true));
        edit.putString(GHDConstants.PREF_DEFAULT_GRATICULE_LONGITUDE, g.getLongitudeString(true));
    }

    edit.apply();

    BackupManager bm = new BackupManager(this);
    bm.dataChanged();
}
 
Example 9
Project: geohashdroid   File: KnownLocation.java   View source code 6 votes vote down vote up
/**
 * Stores a bunch of KnownLocations to preferences.  Note that this <b>replaces</b>
 * all currently-stored KnownLocations.
 *
 * @param c a Context
 * @param locations a List of KnownLocations
 */
public static void storeKnownLocations(@NonNull Context c, @NonNull List<KnownLocation> locations) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    SharedPreferences.Editor edit = prefs.edit();

    JSONArray arr = new JSONArray();

    for(KnownLocation kl : locations) {
        arr.put(kl.serialize());
    }

    // Man, that's easy.
    edit.putString(GHDConstants.PREF_KNOWN_LOCATIONS, arr.toString());
    edit.apply();

    BackupManager bm = new BackupManager(c);
    bm.dataChanged();
}
 
Example 10
Project: dashclock   File: ExtensionManager.java   View source code 6 votes vote down vote up
/**
 * Replaces the set of active extensions with the given list.
 */
public void setInternalActiveExtensions(List<ComponentName> extensions) {
    StringBuilder sb = new StringBuilder();

    for (ComponentName extension : extensions) {
        if (sb.length() > 0) {
            sb.append(",");
        }
        sb.append(extension.flattenToString());
    }

    mDefaultPreferences.edit()
            .putString(PREF_ACTIVE_EXTENSIONS, sb.toString())
            .apply();
    new BackupManager(mApplicationContext).dataChanged();

    mInternalActiveExtensions.clear();
    mInternalActiveExtensions.addAll(extensions);
    setActiveExtensions(getActiveExtensionNames());
}
 
Example 11
Project: dashclock   File: ConfigureAdvancedFragment.java   View source code 6 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences sp, String key) {
    new BackupManager(getActivity()).dataChanged();

    // Potentially enable/disable the launcher activity if the settings button
    // preference has changed.
    if (isAdded() && AppearanceConfig.PREF_SETTINGS_BUTTON.equals(key)) {
        boolean enableLauncher = AppearanceConfig.PREF_SETTINGS_BUTTON_IN_LAUNCHER.equals(
                sp.getString(AppearanceConfig.PREF_SETTINGS_BUTTON, null));
        getActivity().getPackageManager().setComponentEnabledSetting(
                new ComponentName(
                        getActivity().getPackageName(),
                        ConfigurationActivity.LAUNCHER_ACTIVITY_NAME),
                enableLauncher
                        ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                        : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
    }
}
 
Example 12
Project: MuzeiEarthView   File: SettingsFragment.java   View source code 6 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
    new BackupManager(getActivity()).dataChanged();

    // Potentially enable/disable the launcher activity if the settings button
    // preference has changed.
    final String launcherIntentKey = getString(R.string.pref_key_launcher_intent);
    if (isAdded() && launcherIntentKey.equals(s)) {

        final boolean hideLauncher = sharedPreferences.getBoolean(launcherIntentKey, false);
        getActivity().getPackageManager().setComponentEnabledSetting(
                new ComponentName(
                        getActivity().getPackageName(),
                        LAUNCHER_ACTIVITY_NAME),
                hideLauncher
                        ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
                        : PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);
    }
}
 
Example 13
Project: SeriesGuideToPlex   File: SettingsFragment.java   View source code 6 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
  new BackupManager(getActivity()).dataChanged();

  // Potentially enable/disable the launcher activity if the settings button
  // preference has changed.
  final String launcherIntentKey = getString(R.string.pref_key_launcher_intent);
  if (isAdded() && launcherIntentKey.equals(s)) {

    final boolean hideLauncher = sharedPreferences.getBoolean(launcherIntentKey, false);
    packageManager.setComponentEnabledSetting(
        new ComponentName(
            getActivity().getPackageName(),
            LAUNCHER_ACTIVITY_NAME),
        hideLauncher
            ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
            : PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
        PackageManager.DONT_KILL_APP);
  }
}
 
Example 14
Project: android-device-identification   File: UserIdentifier.java   View source code 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 15
Project: Noyze   File: ConfigurationActivity.java   View source code 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 16
Project: cowbird   File: ProtocolDBContentProvider.java   View source code 6 votes vote down vote up
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    ContentConstants.ProtocolURLs vrUrl = convertURIToProtocolURL(uri);
    int count = 0;
    switch (vrUrl) {
        case URLProtocol:
            count = db.getWritableDatabase().delete(Protocol.TABLE_NAME, selection, selectionArgs);
            if (count > 0) {
                new BackupManager(getContext()).dataChanged();
            }
            break;
    }
    getContext().getContentResolver().notifyChange(uri, null);

    // Returns the number of rows deleted.
    return count;
}
 
Example 17
Project: cowbird   File: ProtocolDBContentProvider.java   View source code 6 votes vote down vote up
@Override
public Uri insert(Uri uri, ContentValues values) {
    ContentConstants.ProtocolURLs vrUrl = convertURIToProtocolURL(uri);
    long rowId = -1;
    switch (vrUrl) {
        case URLProtocol:
            rowId = db.getWritableDatabase().insert(Protocol.TABLE_NAME, null, values);
            new BackupManager(getContext()).dataChanged();
            break;
        default:
            throw new SQLiteConstraintException("Failed to switch insert protocol " + uri);

    }

    // If the insert succeeded, the row ID exists.
    if (rowId > 0) {
        // Creates a URI with the note ID pattern and the new row ID appended to it.
        Uri noteUri = ContentConstants.getUriFor(vrUrl, rowId);

        // Notifies observers registered against this provider that the data changed.
        getContext().getContentResolver().notifyChange(noteUri, null);
        return noteUri;
    } else {
        throw new SQLiteConstraintException("Failed to insert row into " + uri);
    }
}
 
Example 18
Project: cowbird   File: ProtocolDBContentProvider.java   View source code 6 votes vote down vote up
@Override
public int update(Uri uri, ContentValues values, String selection,
                  String[] selectionArgs) {
    int count = 0;
    ContentConstants.ProtocolURLs vrUrl = convertURIToProtocolURL(uri);
    switch (vrUrl) {
        case URLProtocol:
            SQLiteDatabase sql = db.getWritableDatabase();
            count = sql.update(Protocol.TABLE_NAME, values, selection, selectionArgs);
            if (count > 0) {
                new BackupManager(getContext()).dataChanged();
            }
            break;
    }

    getContext().getContentResolver().notifyChange(uri, null);
    return count;

}
 
Example 19
Project: dscautorename   File: DSCApplication.java   View source code 6 votes vote down vote up
/**
 * Called when the application is starting, before any activity, service, or
 * receiver objects (excluding content providers) have been created.
 */
@Override
public void onCreate() {
	super.onCreate();
	checkApplicationResources();
	mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
	mBackupManager = new BackupManager(this);
	initLocale();
	mSdkInt = android.os.Build.VERSION.SDK_INT;
	int serviceType = getServiceType();
	if (DSCApplication.SERVICE_TYPE_DISABLED != serviceType) {
		checkRegisteredServiceType(false);
	}
	mFolderObserverMap = new HashMap<>();
	if (SERVICE_TYPE_FILE_OBSERVER == serviceType) {
		initVolumes();
		initFolderObserverList(false);
	}
}
 
Example 20
Project: chromadoze   File: ChromaDoze.java   View source code 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 21
Project: Key-Value-Backup-API-Sample   File: MainActivity.java   View source code 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.create:
            createTestFiles();
            break;
        case R.id.restore:
            new BackupManager(this).requestRestore(new RestoreObserver() {
                @Override
                public void restoreFinished(int error) {
                    if (error == 0) {
                        Toast.makeText(MainActivity.this, R.string.files_restored, Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(MainActivity.this, getString(R.string.restore_failed, error), Toast.LENGTH_SHORT).show();
                    }
                }
            });
            break;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 22
Project: novelty   File: DbProvider.java   View source code 6 votes vote down vote up
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    SQLiteDatabase dbWritable = mOpenHelper.getWritableDatabase();

    dbWritable.beginTransaction();

    int count = dbWritable.update(getTableName(uri), values, selection, selectionArgs);

    dbWritable.setTransactionSuccessful();
    dbWritable.endTransaction();

    // Log.i(TAG, "Updated rows: " + count);
    if (count > 0) {
        BackupManager.dataChanged(getContext().getPackageName());
    }
    return count;
}
 
Example 23
Project: novelty   File: BaseActivity.java   View source code 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplication());
    sharedPrefs.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
            BackupManager.dataChanged(getPackageName());
        }
    });

    Utils.setStrictMode(true);

    setContentView(getLayoutResource());
    initUI();
}
 
Example 24
Project: Advanced-Settings-for-Android-Wear   File: MainActivity.java   View source code 6 votes vote down vote up
/**
 * Requests the system to update the system locale. Note that the system looks halted
 * for a while during the Locale migration, so the caller need to take care of it.
 * <p/>
 * Requires android.permission.CHANGE_CONFIGURATION
 */
public static void updateLocale(Locale locale) {
    try {
        IActivityManager am = ActivityManagerNative.getDefault();

        Configuration config = am.getConfiguration();

        // Will set userSetLocale to indicate this isn't some passing default - the user
        // wants this remembered
        config.setLocale(locale);

        am.updateConfiguration(config);
        // Trigger the dirty bit for the Settings Provider.
        BackupManager.dataChanged("com.android.providers.settings");
    } catch (RemoteException e) {
        // Intentionally left blank
    }
}
 
Example 25
Project: Noyze   File: ConfigurationActivity.java   View source code 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 26
Project: geoPingProject   File: GeoPingPrefActivity.java   View source code 6 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    // Ask Backup
    BackupManager.dataChanged(getPackageName());
    // Recompute Change Sumaries
    Log.d(TAG, "### onSharedPreferenceChanged key : " + key);
     Preference pref = findPreference(key);
    Log.d(TAG, "### onSharedPreferenceChanged findPreference : " + pref);
    setSummary(this, pref);
    // Tracker
    // GeoPingApplication.getInstance().tracker().trackPageView("/Pref/" +
    // key);
    Tracker tracker = tracker = GeoPingApplication.getGeoPingApplication(this).getTracker();
    tracker.send(new HitBuilders.EventBuilder()//
            .setCategory("ui_pref") // Category
            .setAction("changed") // Action
            .setLabel(key) // Label
            .build());
}
 
Example 27
Project: geoPingProject   File: GeoPingPrefActivity.java   View source code 6 votes vote down vote up
/**
 * Click handler, designated in the layout, that runs a restore of the app's
 * most recent data when the button is pressed.
 */
public void onRestoreButtonClick(View v) {
    Log.v(TAG, "Requesting restore of our most recent data");
    BackupManager mBackupManager = new BackupManager(this);
    mBackupManager.requestRestore(new RestoreObserver() {
        public void restoreFinished(int error) {
            /** Done with the restore! Now draw the new state of our data */
            if (error == 0) {
                Log.v(TAG, "Restore finished, error = " + error);
                NotifToasts.showBackupRestored(GeoPingPrefActivity.this);
            } else {
                Log.e(TAG, "Restore finished with error = " + error);
            }
        }
    });
}
 
Example 28
Project: geoPingProject   File: PersonProvider.java   View source code 6 votes vote down vote up
@Override
public Uri insert(Uri uri, ContentValues values) {
    switch (sURIMatcher.match(uri)) {
    case PERSONS:
        long personId = personDatabase.insertEntity(values);
        Uri personUri = null;
        if (personId > -1) {
            personUri = Uri.withAppendedPath(Constants.CONTENT_URI, String.valueOf(personId));
            getContext().getContentResolver().notifyChange(uri, null);
            // Backup
            BackupManager.dataChanged(getContext().getPackageName());
        }
        return personUri;
    default:
        throw new IllegalArgumentException("Unknown Uri: " + uri);
    }
}
 
Example 29
Project: geoPingProject   File: PersonProvider.java   View source code 6 votes vote down vote up
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    int count = 0;
    switch (sURIMatcher.match(uri)) {
    case PERSON_ID:
        String entityId = uri.getLastPathSegment();
        String[] args = new String[] { entityId };
        count = personDatabase.deleteEntity(PersonColumns.SELECT_BY_ENTITY_ID, args);
        break;
    case PERSONS:
        count = personDatabase.deleteEntity(selection, selectionArgs);
        break;
    default:
        throw new IllegalArgumentException("Unknown Uri: " + uri);
    }
    if (count > 0) {
        getContext().getContentResolver().notifyChange(uri, null);
        // Backup
       BackupManager.dataChanged(getContext().getPackageName());
     }
    return count;
}
 
Example 30
Project: geoPingProject   File: PersonProvider.java   View source code 6 votes vote down vote up
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    int count = 0;
    switch (sURIMatcher.match(uri)) {
    case PERSON_ID:
        String entityId = uri.getLastPathSegment();
        String[] args = new String[] { entityId };
        count = personDatabase.updateEntity(values, PersonColumns.SELECT_BY_ENTITY_ID, args);
        break;
    case PERSONS:
        count = personDatabase.updateEntity(values, selection, selectionArgs);
        break;
    default:
        throw new IllegalArgumentException("Unknown Uri: " + uri);
    }
    if (count > 0) {
        getContext().getContentResolver().notifyChange(uri, null);
        // Backup
        BackupManager.dataChanged(getContext().getPackageName());
    }
    return count;
}
 
Example 31
Project: geoPingProject   File: PairingProvider.java   View source code 6 votes vote down vote up
@Override
public Uri insert(Uri uri, ContentValues values) {
    switch (sURIMatcher.match(uri)) {
    case PAIRINGS:

        long pairingId = pairingDatabase.insertEntity(values);
        Uri pairingUri = null;
        if (pairingId > -1) {
            pairingUri = Uri.withAppendedPath(Constants.CONTENT_URI, String.valueOf(pairingId));
            getContext().getContentResolver().notifyChange(uri, null);
            Log.i(TAG, String.format("Insert Pairing %s : %s", pairingUri, values));
            // Backup
            BackupManager.dataChanged(getContext().getPackageName());
        }
        return pairingUri;
    default:
        throw new IllegalArgumentException("Unknown Uri: " + uri);
    }
}
 
Example 32
Project: geoPingProject   File: PairingProvider.java   View source code 6 votes vote down vote up
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    int count = 0;
    switch (sURIMatcher.match(uri)) {
    case PAIRING_ID:
        String entityId = uri.getLastPathSegment();
        String[] args = new String[] { entityId };
        count = pairingDatabase.deleteEntity(PairingColumns.SELECT_BY_ENTITY_ID, args);
        break;
    case PAIRINGS:
        count = pairingDatabase.deleteEntity(selection, selectionArgs);
        break;
    default:
        throw new IllegalArgumentException("Unknown Uri: " + uri);
    }
    if (count > 0) {
        getContext().getContentResolver().notifyChange(uri, null);
        // Backup
       BackupManager.dataChanged(getContext().getPackageName());
    }
    return count;
}
 
Example 33
Project: geoPingProject   File: PairingProvider.java   View source code 6 votes vote down vote up
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    int count = 0;
    switch (sURIMatcher.match(uri)) {
    case PAIRING_ID:
        String entityId = uri.getLastPathSegment();
        String[] args = new String[] { entityId };
        count = pairingDatabase.updateEntity(values, PairingColumns.SELECT_BY_ENTITY_ID, args);
        break;
    case PAIRINGS:
        count = pairingDatabase.updateEntity(values, selection, selectionArgs);
        break;
    default:
        throw new IllegalArgumentException("Unknown Uri: " + uri);
    }
    if (count > 0) {
        getContext().getContentResolver().notifyChange(uri, null);
        // Backup
       BackupManager.dataChanged(getContext().getPackageName());
    }
    return count;
}
 
Example 34
Project: geoPingProject   File: GeoFenceProvider.java   View source code 6 votes vote down vote up
@Override
public Uri insert(Uri uri, ContentValues values) {
    switch (sURIMatcher.match(uri)) {
        case GEOFENCES:
            long geofenceId = geofenceDatabase.insertEntity(values);
            Uri geofenceUri = null;
            if (geofenceId > -1) {
                geofenceUri = Constants.getContentUri(geofenceId);
                getContext().getContentResolver().notifyChange(uri, null);
                Log.i(TAG, String.format("Insert GeoFence %s : %s", geofenceUri, values));
                // Backup
                BackupManager.dataChanged(getContext().getPackageName());
            }
            return geofenceUri;
        default:
            throw new IllegalArgumentException("Unknown insert Uri: " + uri);
    }
}
 
Example 35
Project: geoPingProject   File: GeoFenceProvider.java   View source code 6 votes vote down vote up
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    int count = 0;
    switch (sURIMatcher.match(uri)) {
        case GEOFENCE_ID:
            String entityId = uri.getLastPathSegment();
            String[] args = new String[]{entityId};
            count = geofenceDatabase.updateEntity(values, GeoFenceColumns.SELECT_BY_ENTITY_ID, args);
            break;
        case GEOFENCES:
            count = geofenceDatabase.updateEntity(values, selection, selectionArgs);
            break;
        default:
            throw new IllegalArgumentException("Unknown update Uri: " + uri);
    }
    if (count > 0) {
        getContext().getContentResolver().notifyChange(uri, null);
        // Backup
        BackupManager.dataChanged(getContext().getPackageName());
    }
    return count;
}
 
Example 36
Project: Calendar_lunar   File: GeneralPreferences.java   View source code 6 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
        String key) {
    Activity a = getActivity();
    if (key.equals(KEY_ALERTS)) {
        updateChildPreferences();
        if (a != null) {
            Intent intent = new Intent();
            intent.setClass(a, AlertReceiver.class);
            if (mAlert.isChecked()) {
                intent.setAction(AlertReceiver.ACTION_DISMISS_OLD_REMINDERS);
            } else {
                intent.setAction(CalendarContract.ACTION_EVENT_REMINDER);
            }
            a.sendBroadcast(intent);
        }
    }
    if (a != null) {
        BackupManager.dataChanged(a.getPackageName());
    }
}
 
Example 37
Project: Dash   File: ExtensionManager.java   View source code 6 votes vote down vote up
private void saveActiveExtensionList() {
    StringBuilder sb = new StringBuilder();

    synchronized (mActiveExtensions) {
        for (ExtensionWithData ci : mActiveExtensions) {
            if (sb.length() > 0) {
                sb.append(",");
            }
            sb.append(ci.listing.componentName.flattenToString());
        }
    }

    mDefaultPreferences.edit()
            .putString(PREF_ACTIVE_EXTENSIONS, sb.toString())
            .commit();
    new BackupManager(mApplicationContext).dataChanged();
}
 
Example 38
Project: Dash   File: ConfigureAdvancedFragment.java   View source code 6 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences sp, String key) {
    new BackupManager(getActivity()).dataChanged();

    // Potentially enable/disable the launcher activity if the settings button
    // preference has changed.
    if (isAdded() && AppearanceConfig.PREF_SETTINGS_BUTTON.equals(key)) {
        boolean enableLauncher = AppearanceConfig.PREF_SETTINGS_BUTTON_IN_LAUNCHER.equals(
                sp.getString(AppearanceConfig.PREF_SETTINGS_BUTTON, null));
        getActivity().getPackageManager().setComponentEnabledSetting(
                new ComponentName(
                        getActivity().getPackageName(),
                        ConfigurationActivity.LAUNCHER_ACTIVITY_NAME),
                enableLauncher
                        ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                        : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
    }
}
 
Example 39
Project: android-kioskime   File: SettingsFragment.java   View source code 6 votes vote down vote up
@Override
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
    (new BackupManager(getActivity())).dataChanged();
    final Resources res = getResources();
    if (key.equals(Settings.PREF_POPUP_ON)) {
        setPreferenceEnabled(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY,
                Settings.readKeyPreviewPopupEnabled(prefs, res));
    } else if (key.equals(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY)) {
        setPreferenceEnabled(Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST,
                Settings.readShowsLanguageSwitchKey(prefs));
    } else if (key.equals(Settings.PREF_SHOW_SETUP_WIZARD_ICON)) {
        LauncherIconVisibilityManager.updateSetupWizardIconVisibility(getActivity());
    }
    ensureConsistencyOfAutoCorrectionSettings();
    updateVoiceModeSummary();
    updateShowCorrectionSuggestionsSummary();
    updateKeyPreviewPopupDelaySummary();
    refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources());
}
 
Example 40
Project: CineTime   File: DBHelper.java   View source code 6 votes vote down vote up
/**
 * Insert new item into favorites
 *
 * @param context
 */
@SuppressLint("NewApi")
public static void insertFavorite(Context context, String code, String title, String location) {
    synchronized (DBHelper.sDataLock) {
        SQLiteDatabase db = getDatabase(context);

        ContentValues values = new ContentValues();
        values.put("code", code);
        values.put("title", title);
        values.put("location", location);
        db.insert("favorites", null, values);
        db.close();
    }
    favCodes.add(code);
    new BackupManager(context).dataChanged();
}