Example usage for android.content Intent ACTION_SYNC

List of usage examples for android.content Intent ACTION_SYNC

Introduction

In this page you can find the example usage for android.content Intent ACTION_SYNC.

Prototype

String ACTION_SYNC

To view the source code for android.content Intent ACTION_SYNC.

Click Source Link

Document

Activity Action: Perform a data synchronization.

Usage

From source file:org.wheelmap.android.fragment.POIsMapsforgeWorkerFragment.java

public void executeSearch(Bundle extras) {
    if (!extras.containsKey(SearchManager.QUERY) && !extras.containsKey(SyncService.EXTRA_CATEGORY)
            && !extras.containsKey(SyncService.EXTRA_NODETYPE)
            && !extras.containsKey(SyncService.EXTRA_WHEELCHAIR_STATE))
        return;//w  w  w.  j  a  va  2 s.  co  m

    final Intent intent = new Intent(Intent.ACTION_SYNC, null, getActivity(), SyncService.class);

    intent.putExtras(extras);
    if (!extras.containsKey(SyncService.EXTRA_WHAT)) {
        int what;
        if (extras.containsKey(SyncService.EXTRA_CATEGORY) || extras.containsKey(SyncService.EXTRA_NODETYPE))
            what = SyncService.WHAT_RETRIEVE_NODES;
        else
            what = SyncService.WHAT_SEARCH_NODES_IN_BOX;

        intent.putExtra(SyncService.EXTRA_WHAT, what);
    }

    intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mReceiver);
    getActivity().startService(intent);
    setSearchMode(true);
    updateSearchStatus();
}

From source file:com.infine.android.devoxx.ui.HomeActivity.java

/**
 * Execute a refresh of data./*from   w w w .ja  va  2 s  .  c o  m*/
 * @param forceRefresh bypass the interval between 2 refresh
 */
private void triggerRefresh(boolean forceRefresh) {
    long now = System.currentTimeMillis();

    if (forceRefresh || now - lastRefresh > REFRESH_INTERVAL) {
        final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, RestService.class);

        intent.putExtra(RestService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiver);

        startService(intent);

        if (mTagStreamFragment != null) {
            mTagStreamFragment.refresh();
        }
    }
    lastRefresh = now;
}

From source file:com.goliathonline.android.kegbot.ui.HomeActivity.java

private void triggerRefresh() {
    final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, SyncService.class);
    intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiver);
    if (PrefsHelper.hasAPIUrl(this))
        startService(intent);// w  w w . jav  a 2s . c o  m

    if (mTagStreamFragment != null) {
        mTagStreamFragment.refresh();
    }
}

From source file:ca.mudar.snoozy.receiver.PowerConnectionReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    final Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);

    // Get user preferences
    final SharedPreferences sharedPrefs = context.getSharedPreferences(Const.APP_PREFS_NAME,
            Context.MODE_PRIVATE);
    final SharedPreferences.Editor sharedPrefsEditor = sharedPrefs.edit();
    final boolean hasNotifications = sharedPrefs.getBoolean(Const.PrefsNames.HAS_NOTIFICATIONS, false);
    final boolean hasVibration = (sharedPrefs.getBoolean(Const.PrefsNames.HAS_VIBRATION, false)
            && vibrator.hasVibrator());
    final boolean hasSound = sharedPrefs.getBoolean(Const.PrefsNames.HAS_SOUND, false);
    final boolean onScreenLock = sharedPrefs.getBoolean(Const.PrefsNames.ON_SCREEN_LOCK, true);
    final boolean onPowerLoss = sharedPrefs.getBoolean(Const.PrefsNames.ON_POWER_LOSS, false);
    final int delayToLock = Integer.parseInt(
            sharedPrefs.getString(Const.PrefsNames.DELAY_TO_LOCK, Const.PrefsValues.DELAY_FAST)) * 1000;
    final int notifyCount = sharedPrefs.getInt(Const.PrefsNames.NOTIFY_COUNT, 1);
    final int notifyGroup = sharedPrefs.getInt(Const.PrefsNames.NOTIFY_GROUP, 1);

    final String action = intent.getAction();
    if (action == null)
        return;/*ww w . j a v  a2  s.  c om*/

    if (action.equals(Const.IntentActions.NOTIFY_DELETE)) {
        if (hasNotifications) {
            // Reset the notification counter (and group) on NOTIFY_DELETE
            sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_COUNT, 1);
            sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_GROUP, notifyGroup + 1);
            sharedPrefsEditor.apply();
        }
    } else if (action.equals(Intent.ACTION_POWER_CONNECTED)
            || action.equals(Intent.ACTION_POWER_DISCONNECTED)) {
        final boolean isConnectedPower = action.equals(Intent.ACTION_POWER_CONNECTED);

        // Lock the screen, following the user preferences
        if (delayToLock == 0) {
            LockScreenHelper.lockScreen(context, onScreenLock, onPowerLoss, isConnectedPower);
        } else {
            Intent intentService = new Intent(Intent.ACTION_SYNC, null, context, DelayedLockService.class);
            Bundle extras = new Bundle();
            extras.putBoolean(Const.IntentExtras.ON_SCREEN_LOCK, onScreenLock);
            extras.putBoolean(Const.IntentExtras.ON_POWER_LOSS, onPowerLoss);
            extras.putBoolean(Const.IntentExtras.IS_CONNECTED, isConnectedPower);
            extras.putInt(Const.IntentExtras.DELAY_TO_LOCK, delayToLock);
            intentService.putExtras(extras);
            context.startService(intentService);
        }

        // Save in database
        saveHistoryItem(context.getApplicationContext(), isConnectedPower, notifyGroup);

        if (hasNotifications) {
            // Send notification, with sound and vibration
            notify(context, isConnectedPower, hasVibration, hasSound, notifyCount);

            // Increment the notification counter
            sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_COUNT, notifyCount + 1);
            sharedPrefsEditor.apply();
        } else {
            // Native Vibration or Sound, without Notifications
            nativeVibrate(context, hasVibration);

            nativeRingtone(context, hasSound);
        }
    }
}

From source file:ca.mudar.mtlaucasou.MainActivity.java

@Override
public void onResume() {
    super.onResume();

    /**// w w  w. j a  va 2s.  co m
     * Update the interface language
     */
    getSupportActionBar().setTitle(R.string.app_name);
    if (!lang.equals(mAppHelper.getLanguage())) {
        lang = mAppHelper.getLanguage();
        this.onConfigurationChanged();
    }

    /**
     * Starting the sync service is done onResume() for
     * SyncStatusUpdaterFragment to be ready. Otherwise, we send an empty
     * receiver to the service.
     */
    // TODO Move this to a sync service listener.
    if (!hasLoadedData && (mSyncStatusUpdaterFragment != null)) {
        Intent intent = new Intent(Intent.ACTION_SYNC, null, getApplicationContext(), SyncService.class);
        intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiver);
        startService(intent);

    }
}

From source file:org.wheelmap.android.fragment.POIsMapsforgeWorkerFragment.java

protected void requestUpdate(Bundle extras) {
    if (isSearchMode)
        return;/* w  w  w. j  ava  2s  .  c  o  m*/

    // trigger off background sync
    final Intent intent = new Intent(Intent.ACTION_SYNC, null, getActivity(), SyncService.class);
    intent.putExtras(extras);
    intent.putExtra(SyncService.EXTRA_WHAT, SyncService.WHAT_RETRIEVE_NODES);
    intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mReceiver);
    getActivity().startService(intent);
}

From source file:com.savvywits.wethepeople.MainActivity.java

public void onClick(View view) {
    mZipCode = mData.getText().toString();
    if (validZipCode(mZipCode)) {
        Fragment fragment = mFragmentManager.findFragmentByTag("results_list");
        if (fragment != null) {
            FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
            fragmentTransaction.remove(fragment);
            fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            fragmentTransaction.commit();
        }/*from   w  ww.  j  a v  a  2  s  .com*/
        RESTResultFragment emptyList = RESTResultFragment.newInstance(null);
        FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
        fragmentTransaction.add(R.id.overlay, emptyList, "results_list");
        fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        fragmentTransaction.commit();

        Intent intent = new Intent(Intent.ACTION_SYNC, null, this, RESTService.class);
        intent.putExtra("receiver", mReceiver);
        intent.putExtra("zipcode", mZipCode);
        startService(intent);

    } else {
        Fragment errorFragment = mFragmentManager.findFragmentByTag("zip_error");
        if (errorFragment == null) {
            DialogFragment error = ErrorDialogFragment.newInstance(null);
            error.show(mFragmentManager, "zip_error");
        }
    }

}

From source file:ca.mudar.parkcatcher.ui.activities.MainActivity.java

@SuppressWarnings("deprecation")
@Override/*from  w  w w. j a v a 2  s  .  c  o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (!Const.IS_DEBUG) {
        Crittercism.init(getApplicationContext(), Const.CRITTERCISM_APP_ID);
    }

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    activityHelper = ActivityHelper.createInstance(this);

    parkingApp = (ParkingApp) getApplicationContext();
    parkingApp.updateUiLanguage();

    /**
     * Display the GPLv3 licence
     */
    if (!EulaHelper.hasAcceptedEula(this)) {

        if (ConnectionHelper.hasConnection(this)) {
            EulaHelper.showEula(false, this);
        } else {
            setContentView(R.layout.activity_no_connection);
            setSupportProgressBarIndeterminateVisibility(Boolean.FALSE);
            return;
        }
    }

    hasLoadedData = parkingApp.hasLoadedData();

    if (!hasLoadedData) {
        hasLoadedData = true;

        // The service runs in the background with no listener
        Intent intent = new Intent(Intent.ACTION_SYNC, null, getApplicationContext(), SyncService.class);
        intent.putExtra(Const.INTENT_EXTRA_SERVICE_LOCAL, false);
        intent.putExtra(Const.INTENT_EXTRA_SERVICE_REMOTE, true);
        startService(intent);
    }

    isPlayservicesOutdated = (GooglePlayServicesUtil
            .isGooglePlayServicesAvailable(getApplicationContext()) != ConnectionResult.SUCCESS);

    if (isPlayservicesOutdated) {
        disableLocationUpdates();
        isCenterOnMyLocation = false;

        setContentView(R.layout.activity_playservices_update);
        setSupportProgressBarIndeterminateVisibility(Boolean.FALSE);

        return;
    } else {
        setContentView(R.layout.activity_main);
        setSupportProgressBarIndeterminateVisibility(Boolean.FALSE);
    }

    // Set the layout containing the two fragments

    // Get the fragments
    FragmentManager fm = getSupportFragmentManager();
    mMapFragment = (MapFragment) fm.findFragmentByTag(Const.TAG_FRAGMENT_MAP);
    mFavoritesFragment = (FavoritesFragment) fm.findFragmentByTag(Const.TAG_FRAGMENT_FAVORITES);

    // Create the actionbar tabs
    final ActionBar ab = getSupportActionBar();

    ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    ab.addTab(ab.newTab().setText(R.string.tab_map).setTabListener(this).setTag(Const.TAG_TABS_MAP));
    ab.addTab(
            ab.newTab().setText(R.string.tab_favorites).setTabListener(this).setTag(Const.TAG_TABS_FAVORITES));

    initLocation = null;

    double latitude = getIntent().getDoubleExtra(Const.INTENT_EXTRA_GEO_LAT, Double.MIN_VALUE);
    double longitude = getIntent().getDoubleExtra(Const.INTENT_EXTRA_GEO_LNG, Double.MIN_VALUE);

    if (Double.compare(latitude, Double.MIN_VALUE) != 0 && Double.compare(latitude, Double.MIN_VALUE) != 0) {
        initLocation = new Location(Const.LOCATION_PROVIDER_INTENT);

        initLocation.setLatitude(latitude);
        initLocation.setLongitude(longitude);

        isCenterOnMyLocation = false;
    } else {
        isCenterOnMyLocation = true;

        // Initialize the displayed values. This is not done when
        // MainActivity is called from Details activity, to keep the same
        // Calendar.
        parkingApp.resetParkingCalendar();
    }

    updateParkingTimeTitle();
    updateParkingDateButton();
    updateParkingTimeButton();
    updateParkingDurationButton();
    mFavoritesFragment.refreshList();

    mDrawer = (SlidingDrawer) findViewById(R.id.drawer_time);
    mDrawer.animateOpen();
}

From source file:net.peterkuterna.android.apps.devoxxfrsched.service.CfpSyncService.java

@Override
protected void doSync(Intent intent) throws Exception {
    Log.d(TAG, "Start sync");

    final Context context = this;

    final SharedPreferences settings = Prefs.get(context);
    final int localVersion = settings.getInt(DevoxxPrefs.CFP_LOCAL_VERSION, VERSION_NONE);

    final long startLocal = System.currentTimeMillis();
    final boolean localParse = localVersion < VERSION_CURRENT;
    Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_CURRENT=" + VERSION_CURRENT);
    if (localParse) {
        // Parse values from local cache first
        mLocalExecutor.execute(R.xml.search_suggest, new SearchSuggestHandler());
        mLocalExecutor.execute(R.xml.rooms, new RoomsHandler());
        mLocalExecutor.execute(R.xml.tracks, new TracksHandler());
        mLocalExecutor.execute(R.xml.presentationtypes, new SessionTypesHandler());
        mLocalExecutor.execute(context, "cache-speakers.json", new SpeakersHandler());
        mLocalExecutor.execute(context, "cache-presentations.json", new SessionsHandler());
        mLocalExecutor.execute(context, "cache-schedule.json", new ScheduleHandler());

        // Save local parsed version
        settings.edit().putInt(DevoxxPrefs.CFP_LOCAL_VERSION, VERSION_CURRENT).commit();

        final ContentValues values = new ContentValues();
        values.put(Sessions.SESSION_NEW, 0);
        getContentResolver().update(Sessions.CONTENT_NEW_URI, values, null, null);
    }/* ww  w .  ja  va2 s  .  co  m*/
    Log.d(TAG, "Local sync took " + (System.currentTimeMillis() - startLocal) + "ms");

    final CfpSyncManager syncManager = new CfpSyncManager(context);
    if (syncManager.shouldPerformRemoteSync(Intent.ACTION_SYNC.equals(intent.getAction()))) {
        Log.d(TAG, "Should perform remote sync");
        final long startRemote = System.currentTimeMillis();
        Editor prefsEditor = syncManager.hasRemoteContentChanged(mHttpClient);
        if (prefsEditor != null) {
            Log.d(TAG, "Remote content was changed");
            mRemoteExecutor.executeGet(SPEAKERS_URL, new SpeakersHandler());
            mRemoteExecutor.executeGet(PRESENTATIONS_URL, new SessionsHandler());
            mRemoteExecutor.executeGet(SCHEDULE_URL, new ScheduleHandler());
            prefsEditor.commit();
        }
        Log.d(TAG, "Remote sync took " + (System.currentTimeMillis() - startRemote) + "ms");
    } else {
        Log.d(TAG, "Should not perform remote sync");
    }

    final CfpDatabase database = new CfpDatabase(this);
    database.cleanupLinkTables();

    if (!localParse) {
        final NotifierManager notifierManager = new NotifierManager(this);
        notifierManager.notifyNewSessions();
    }

    Log.d(TAG, "Sync finished");
}

From source file:net.peterkuterna.android.apps.devoxxfrsched.ui.TwitterSearchFragment.java

private void triggerRefresh() {
    final Intent intent = new Intent(Intent.ACTION_SYNC, null, getActivity(), TwitterSearchService.class);
    intent.putExtra(AbstractSyncService.EXTRA_STATUS_RECEIVER, mState.mReceiver);
    getActivity().startService(intent);/*from   w  ww. ja v  a  2  s  .  c  o  m*/
}