Example usage for android.content SyncStatusObserver SyncStatusObserver

List of usage examples for android.content SyncStatusObserver SyncStatusObserver

Introduction

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

Prototype

SyncStatusObserver

Source Link

Usage

From source file:edu.mit.mobile.android.locast.ver2.browser.BrowserHome.java

@Override
protected void onResume() {
    super.onResume();
    mSyncHandle = ContentResolver.addStatusChangeListener(0xff, new SyncStatusObserver() {

        @Override//from  w w w .j  ava 2  s.co  m
        public void onStatusChanged(int which) {
            Account a = Authenticator.getFirstAccount(BrowserHome.this);
            if (!ContentResolver.isSyncActive(a, MediaProvider.AUTHORITY)
                    && !ContentResolver.isSyncPending(a, MediaProvider.AUTHORITY)) {
                Log.d(TAG, "Sync finished, should refresh naw!!");
                mHandler.sendEmptyMessage(MSG_SET_NOT_REFRESHING);

            } else {
                Log.d(TAG, "Sync Active or Pending!!");
                mHandler.sendEmptyMessage(MSG_SET_REFRESHING);
            }
        }
    });
    //check if synch is in progress 
    Account a = Authenticator.getFirstAccount(BrowserHome.this);
    if (!ContentResolver.isSyncActive(a, MediaProvider.AUTHORITY)
            && !ContentResolver.isSyncPending(a, MediaProvider.AUTHORITY)) {
        Log.d(TAG, "Sync finished, should refresh naw!!");
        mHandler.sendEmptyMessage(MSG_SET_NOT_REFRESHING);
    } else {
        Log.d(TAG, "Sync Active or Pending!!");
        mHandler.sendEmptyMessage(MSG_SET_REFRESHING);
    }

    if (shouldRefresh) {
        refresh(false);
    }

}

From source file:edu.mit.mobile.android.locast.ver2.itineraries.ItineraryList.java

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

    mSyncWhenLoaded = true;//from  w  w w. j  ava  2 s  . co  m
    mSyncHandle = ContentResolver.addStatusChangeListener(0xff, new SyncStatusObserver() {

        @Override
        public void onStatusChanged(int which) {
            Account a = Authenticator.getFirstAccount(ItineraryList.this);
            if (!ContentResolver.isSyncActive(a, MediaProvider.AUTHORITY)
                    && !ContentResolver.isSyncPending(a, MediaProvider.AUTHORITY)) {
                Log.d(TAG, "Sync finished, should refresh naw!!");
                mHandler.sendEmptyMessage(MSG_SET_NOT_REFRESHING);

            } else {
                Log.d(TAG, "Sync Active or Pending!!");
                mHandler.sendEmptyMessage(MSG_SET_REFRESHING);
            }
        }
    });
    //check if synch is in progress 
    Account a = Authenticator.getFirstAccount(ItineraryList.this);
    if (!ContentResolver.isSyncActive(a, MediaProvider.AUTHORITY)
            && !ContentResolver.isSyncPending(a, MediaProvider.AUTHORITY)) {
        Log.d(TAG, "Sync finished, should refresh naw!!");
        mHandler.sendEmptyMessage(MSG_SET_NOT_REFRESHING);
    } else {
        Log.d(TAG, "Sync Active or Pending!!");
        mHandler.sendEmptyMessage(MSG_SET_REFRESHING);
    }
}

From source file:edu.mit.mobile.android.locast.ver2.itineraries.ItineraryDetail.java

@Override
protected void onResume() {
    mFirstLoadSync = true;/*from  w w  w.j  a v a2s  .c o  m*/
    super.onResume();
    mSyncHandle = ContentResolver.addStatusChangeListener(0xff, new SyncStatusObserver() {

        @Override
        public void onStatusChanged(int which) {
            final Account a = Authenticator.getFirstAccount(ItineraryDetail.this);
            if (!ContentResolver.isSyncActive(a, MediaProvider.AUTHORITY)
                    && !ContentResolver.isSyncPending(a, MediaProvider.AUTHORITY)) {
                Log.d(TAG, "Sync finished, should refresh naw!!");
                mHandler.sendEmptyMessage(MSG_SET_NOT_REFRESHING);

            } else {
                Log.d(TAG, "Sync Active or Pending!!");
                mHandler.sendEmptyMessage(MSG_SET_REFRESHING);
            }
        }
    });
    //check if synch is in progress
    final Account a = Authenticator.getFirstAccount(ItineraryDetail.this);
    if (!ContentResolver.isSyncActive(a, MediaProvider.AUTHORITY)
            && !ContentResolver.isSyncPending(a, MediaProvider.AUTHORITY)) {
        Log.d(TAG, "Sync finished, should refresh naw!!");
        mHandler.sendEmptyMessage(MSG_SET_NOT_REFRESHING);
    } else {
        Log.d(TAG, "Sync Active or Pending!!");
        mHandler.sendEmptyMessage(MSG_SET_REFRESHING);
    }
}

From source file:com.nextgis.ngm_clink_monitoring.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getIntent().getBooleanExtra(FoclConstants.NO_SDCARD, false)) {

        YesNoDialog dialog = new YesNoDialog();
        dialog.setCancelable(false);//from ww w.  j av  a 2  s.co m
        dialog.setKeepInstance(true).setIcon(R.drawable.ic_action_warning).setTitle(R.string.warning)
                .setMessage(getString(R.string.no_sdcard_exit_app)).setPositiveText(R.string.ok)
                .setOnPositiveClickedListener(new YesNoDialog.OnPositiveClickedListener() {
                    @Override
                    public void onPositiveClicked() {
                        // show Home screen
                        Intent intent = new Intent(Intent.ACTION_MAIN);
                        intent.addCategory(Intent.CATEGORY_HOME);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);

                        System.exit(0);
                    }
                }).show(getSupportFragmentManager(), FoclConstants.FRAGMENT_YES_NO_DIALOG + "NoSdCard");
        return;
    }

    final GISApplication app = (GISApplication) getApplication();

    mGpsEventSource = app.getGpsEventSource();
    if (null != mGpsEventSource) {
        mGpsEventSource.addListener(this);
    }

    // initialize the default settings
    PreferenceManager.setDefaultValues(this, R.xml.preferences_general, false);

    mSyncStatusObserver = new SyncStatusObserver() {
        @Override
        public void onStatusChanged(int which) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Account account = app.getAccount();

                    if (null != account) {
                        mIsSyncing = AccountUtil.isSyncActive(account, FoclSettingsConstantsUI.AUTHORITY);
                        switchMenuView();
                    }
                }
            });
        }
    };

    setContentView(R.layout.activity_main);

    mMainToolbar = (Toolbar) findViewById(R.id.main_toolbar_cl);
    mMainToolbar.setTitle(""); // needed for screen rotation
    mMainToolbar.getBackground().setAlpha(255);
    setSupportActionBar(mMainToolbar);

    mBottomToolbar = (Toolbar) findViewById(R.id.bottom_toolbar_cl);
    mBottomToolbar.setContentInsetsAbsolute(0, 0);
    mBottomToolbar.getBackground().setAlpha(255);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        // Inflate a custom action bar that contains the "done" button
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View customActionBarView = inflater.inflate(R.layout.editor_custom_action_bar, null);

        mCustomToolbarTitle = (TextView) customActionBarView.findViewById(R.id.custom_toolbar_title);
        mCustomToolbarButton = (TextView) customActionBarView.findViewById(R.id.custom_toolbar_button);
        mCustomToolbarImage = (ImageView) customActionBarView.findViewById(R.id.custom_toolbar_image);

        actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setCustomView(customActionBarView);
    }

    // TODO: remove it
    //        FragmentManager fm = getSupportFragmentManager();
    //        mStatusBarFragment =
    //                (StatusBarFragment) fm.findFragmentByTag(FoclConstants.FRAGMENT_STATUS_BAR);
    //        if (null == mStatusBarFragment) {
    //            mStatusBarFragment = new StatusBarFragment();
    //            FragmentTransaction ft = fm.beginTransaction();
    //            ft.replace(
    //                    R.id.status_bar_fragment, mStatusBarFragment,
    //                    FoclConstants.FRAGMENT_STATUS_BAR);
    //            ft.hide(mStatusBarFragment);
    //            ft.commit();
    //        }

    if (null == savedInstanceState) {
        if (!app.hasAccount()) {
            mViewState = VIEW_STATE_LOGIN;
        } else if (null == app.getFoclProject()) {
            mViewState = VIEW_STATE_1ST_SYNC;
        } else {
            mViewState = VIEW_STATE_OBJECTS;
        }
    } else {
        if (savedInstanceState.containsKey(FoclConstants.VIEW_STATE)) {
            mViewState = savedInstanceState.getInt(FoclConstants.VIEW_STATE);
        }
    }

    setActivityView();

    // workaround for YesNoDialog destroying by the screen rotation
    FragmentManager fm = getSupportFragmentManager();
    Fragment fr = fm.findFragmentByTag(FoclConstants.FRAGMENT_YES_NO_DIALOG + "CancelObjectCreating");
    if (null != fr) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.remove(fr);
        ft.commit();
    }
}

From source file:edu.mit.mobile.android.locast.ver2.casts.LocatableListWithMap.java

@Override
protected void onResume() {
    super.onResume();
    mMyLocationOverlay.enableMyLocation();
    mExpeditedSync = true;/*from  ww  w  .  j  av  a 2s . c o  m*/
    mSyncHandle = ContentResolver.addStatusChangeListener(0xff, new SyncStatusObserver() {

        @Override
        public void onStatusChanged(int which) {
            Account a = Authenticator.getFirstAccount(LocatableListWithMap.this);
            if (!ContentResolver.isSyncActive(a, MediaProvider.AUTHORITY)
                    && !ContentResolver.isSyncPending(a, MediaProvider.AUTHORITY)) {
                Log.d(TAG, "Sync finished, should refresh naw!!");
                mHandler.sendEmptyMessage(MSG_SET_NOT_REFRESHING);

            } else {
                Log.d(TAG, "Sync Active or Pending!!");
                mHandler.sendEmptyMessage(MSG_SET_REFRESHING);
            }
        }
    });
    //check if synch is in progress 
    Account a = Authenticator.getFirstAccount(LocatableListWithMap.this);
    if (!ContentResolver.isSyncActive(a, MediaProvider.AUTHORITY)
            && !ContentResolver.isSyncPending(a, MediaProvider.AUTHORITY)) {
        Log.d(TAG, "Sync finished, should refresh naw!!");
        mHandler.sendEmptyMessage(MSG_SET_NOT_REFRESHING);
    } else {
        Log.d(TAG, "Sync Active or Pending!!");
        mHandler.sendEmptyMessage(MSG_SET_REFRESHING);
    }
}