Example usage for android.os Bundle EMPTY

List of usage examples for android.os Bundle EMPTY

Introduction

In this page you can find the example usage for android.os Bundle EMPTY.

Prototype

Bundle EMPTY

To view the source code for android.os Bundle EMPTY.

Click Source Link

Usage

From source file:fr.openbike.android.service.SyncService.java

@SuppressWarnings("unchecked")
@Override/* w  w w .  j  av a2 s  . c o  m*/
protected void onHandleIntent(Intent intent) {
    NetworkInfo activeNetwork = ((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();
    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);
    Bundle bundle = new Bundle();
    int status = STATUS_ERROR;
    if (activeNetwork == null || !activeNetwork.isConnectedOrConnecting()) {
        bundle = new Bundle();
        bundle.putString(Intent.EXTRA_TEXT, "No network connectivity");
        receiver.send(STATUS_ERROR, bundle);
        return;
    }
    String action = intent.getAction();
    try {
        if (ACTION_SYNC.equals(action)) {
            if (receiver != null) {
                receiver.send(STATUS_SYNC_STATIONS, Bundle.EMPTY);
            }
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
            Object result = mRemoteExecutor.executeGet(
                    mPreferences.getString(AbstractPreferencesActivity.UPDATE_SERVER_URL, "") + "/v2/stations",
                    new RemoteStationsSyncHandler(
                            prefs.getLong(AbstractPreferencesActivity.STATIONS_VERSION, 0)),
                    this);
            if (result == null) {
                // Need stations update
                action = ACTION_UPDATE;
            } else {
                String message = (String) result;
                status = STATUS_SYNC_STATIONS_FINISHED;
                if (!"".equals(message)) {
                    bundle.putString(EXTRA_RESULT, message);
                }
                prefs.edit().putLong(AbstractPreferencesActivity.LAST_UPDATE, System.currentTimeMillis())
                        .commit();
            }
        }
        if (ACTION_UPDATE.equals(action)) {
            if (receiver != null) {
                receiver.send(STATUS_UPDATE_STATIONS, Bundle.EMPTY);
            }
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
            Object result = mRemoteExecutor
                    .executeGet(mPreferences.getString(AbstractPreferencesActivity.UPDATE_SERVER_URL, "")
                            + "/v2/stations/list", new RemoteStationsUpdateHandler(), this);
            status = STATUS_UPDATE_STATIONS_FINISHED;
            if (result != null) {
                bundle.putString(EXTRA_RESULT, (String) result);
            }
            prefs.edit().putLong(AbstractPreferencesActivity.LAST_UPDATE, System.currentTimeMillis()).commit();
        }
        if (ACTION_CHOOSE_NETWORK.equals(action)) {
            if (receiver != null) {
                receiver.send(STATUS_SYNC_NETWORKS, Bundle.EMPTY);
                bundle = new Bundle();
                bundle.putParcelableArrayList(EXTRA_RESULT, (ArrayList<Network>) mRemoteExecutor
                        .executeGet(NETWORKS_URL, new RemoteNetworksHandler(), this));
                status = STATUS_SYNC_NETWORKS_FINISHED;
            }
        }
        if (receiver != null) {
            receiver.send(status, bundle);
        }
    } catch (HandlerException e) {
        if (receiver != null) {
            // Pass back error to surface listener
            bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            receiver.send(STATUS_ERROR, bundle);
        }
    } catch (Exception e) {
        if (receiver != null) {
            // Pass back error to surface listener
            e.printStackTrace();
            bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, "Une erreur est survenue. Veuillez ressayer.");
            receiver.send(STATUS_ERROR, bundle);
        }
    }
}

From source file:com.hamzahrmalik.calculator2.Calculator.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_calculator);

    mDisplayView = findViewById(R.id.display);
    mFormulaEditText = (CalculatorEditText) findViewById(R.id.formula);
    mResultEditText = (CalculatorEditText) findViewById(R.id.result);
    mPadViewPager = (ViewPager) findViewById(R.id.pad_pager);
    mDeleteButton = findViewById(R.id.del);
    mClearButton = findViewById(R.id.clr);

    mEqualButton = findViewById(R.id.pad_numeric).findViewById(R.id.eq);
    if (mEqualButton == null || mEqualButton.getVisibility() != View.VISIBLE) {
        mEqualButton = findViewById(R.id.pad_operator).findViewById(R.id.eq);
    }//from   w  w  w. j  a va2s  .c o  m

    mTokenizer = new CalculatorExpressionTokenizer(this);
    mEvaluator = new CalculatorExpressionEvaluator(mTokenizer);

    savedInstanceState = savedInstanceState == null ? Bundle.EMPTY : savedInstanceState;
    setState(CalculatorState.values()[savedInstanceState.getInt(KEY_CURRENT_STATE,
            CalculatorState.INPUT.ordinal())]);
    mFormulaEditText.setText(
            mTokenizer.getLocalizedExpression(savedInstanceState.getString(KEY_CURRENT_EXPRESSION, "")));
    mEvaluator.evaluate(mFormulaEditText.getText(), this);

    mFormulaEditText.setEditableFactory(mFormulaEditableFactory);
    mFormulaEditText.addTextChangedListener(mFormulaTextWatcher);
    mFormulaEditText.setOnKeyListener(mFormulaOnKeyListener);
    mFormulaEditText.setOnTextSizeChangeListener(this);
    mDeleteButton.setOnLongClickListener(this);
}

From source file:com.android.mail.browse.MessageFooterView.java

public void bind(MessageHeaderItem headerItem, boolean measureOnly) {
    mMessageHeaderItem = headerItem;//from w  ww  .  j av a 2 s .  c  o  m

    final Integer attachmentLoaderId = getAttachmentLoaderId();

    // Destroy the loader if we are attempting to load a different attachment
    if (mOldAttachmentLoaderId != null && !Objects.equal(mOldAttachmentLoaderId, attachmentLoaderId)) {
        mLoaderManager.destroyLoader(mOldAttachmentLoaderId);

        // Resets the footer view. This step is only done if the
        // attachmentsListUri changes so that we don't
        // repeat the work of layout and measure when
        // we're only updating the attachments.
        mAttachmentGrid.removeAllViewsInLayout();
        mAttachmentBarList.removeAllViewsInLayout();
        mViewEntireMessagePrompt.setVisibility(View.GONE);
        mAttachmentGrid.setVisibility(View.GONE);
        mAttachmentBarList.setVisibility(View.GONE);
    }
    mOldAttachmentLoaderId = attachmentLoaderId;

    // kick off load of Attachment objects in background thread
    // but don't do any Loader work if we're only measuring
    if (!measureOnly && attachmentLoaderId != null) {
        LogUtils.i(LOG_TAG, "binding footer view, calling initLoader for message %d", attachmentLoaderId);
        mLoaderManager.initLoader(attachmentLoaderId, Bundle.EMPTY, this);
    }

    // Do an initial render if initLoader didn't already do one
    if (mAttachmentGrid.getChildCount() == 0 && mAttachmentBarList.getChildCount() == 0) {
        renderAttachments(false);
    }

    final ConversationMessage message = mMessageHeaderItem.getMessage();
    mViewEntireMessagePrompt
            .setVisibility(message.clipped && !TextUtils.isEmpty(message.permalink) ? VISIBLE : GONE);
    setVisibility(mMessageHeaderItem.isExpanded() ? VISIBLE : GONE);
}

From source file:org.peterbaldwin.vlcremote.fragment.BrowseFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_refresh_directory:
        getLoaderManager().restartLoader(Data.DIRECTORY, Bundle.EMPTY, this);
        return true;
    case R.id.menu_parent:
        openParentDirectory();//ww  w.  java  2  s . c  o  m
        return true;
    case R.id.menu_home:
        mDirectory = mPreferences.getHomeDirectory();
        getLoaderManager().restartLoader(Data.DIRECTORY, Bundle.EMPTY, this);
        return true;
    case R.id.menu_set_home:
        mPreferences.setHomeDirectory(mDirectory);
        showSetHomeToast();
        return true;
    case R.id.menu_size_large:
        mPreferences.setTextSize(Preferences.TEXT_LARGE);
        mAdapter.notifyDataSetChanged();
        return true;
    case R.id.menu_size_medium:
        mPreferences.setTextSize(Preferences.TEXT_MEDIUM);
        mAdapter.notifyDataSetChanged();
        return true;
    case R.id.menu_size_small:
        mPreferences.setTextSize(Preferences.TEXT_SMALL);
        mAdapter.notifyDataSetChanged();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:se.leap.bitmaskclient.Dashboard.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) {
        if (resultCode == RESULT_OK && data.hasExtra(Provider.KEY)) {
            provider = data.getParcelableExtra(Provider.KEY);
            providerToPreferences(provider);

            buildDashboard(false);//w  ww  .  ja  v a 2s.co m
            invalidateOptionsMenuOnUiThread();
            if (data.hasExtra(SessionDialog.TAG)) {
                sessionDialog(Bundle.EMPTY);
            }

        } else if (resultCode == RESULT_CANCELED && data != null && data.hasExtra(ACTION_QUIT)) {
            finish();
        } else
            configErrorDialog();
    } else if (requestCode == EIP.DISCONNECT) {
        EipStatus.getInstance().setConnectedOrDisconnected();
    }
}

From source file:com.amazonaws.cognito.sync.demo.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    Log.i(TAG, "onCreate");

    /**//from  w  w w .  jav  a2 s  . c o  m
     * Initialize Facebook SDK
     */
    FacebookSdk.sdkInitialize(getApplicationContext());
    callbackManager = CallbackManager.Factory.create();

    //Twitter
    if (mOauthConsumer == null) {
        mOauthProvider = new DefaultOAuthProvider("https://api.twitter.com/oauth/request_token",
                "https://api.twitter.com/oauth/access_token", "https://api.twitter.com/oauth/authorize");
        mOauthConsumer = new DefaultOAuthConsumer(getString(R.string.twitter_consumer_key),
                getString(R.string.twitter_consumer_secret));
    }
    retrieveTwitterCredentials(getIntent());

    //If access token is already here, set fb session
    final AccessToken fbAccessToken = AccessToken.getCurrentAccessToken();
    if (fbAccessToken != null) {
        setFacebookSession(fbAccessToken);
        btnLoginFacebook.setVisibility(View.GONE);
    }

    /**
     * Initializes the sync client. This must be call before you can use it.
     */
    CognitoSyncClientManager.init(this);

    btnLoginFacebook = (Button) findViewById(R.id.btnLoginFacebook);
    btnLoginFacebook.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // start Facebook Login
            LoginManager.getInstance().logInWithReadPermissions(MainActivity.this,
                    Arrays.asList("public_profile"));
            LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {
                    btnLoginFacebook.setVisibility(View.GONE);
                    new GetFbName(loginResult).execute();
                    setFacebookSession(loginResult.getAccessToken());
                }

                @Override
                public void onCancel() {
                    Toast.makeText(MainActivity.this, "Facebook login cancelled", Toast.LENGTH_LONG).show();
                }

                @Override
                public void onError(FacebookException error) {
                    Toast.makeText(MainActivity.this, "Error in Facebook login " + error.getMessage(),
                            Toast.LENGTH_LONG).show();
                }
            });
        }
    });
    btnLoginFacebook.setEnabled(getString(R.string.facebook_app_id) != "facebook_app_id");

    try {
        mAuthManager = new AmazonAuthorizationManager(this, Bundle.EMPTY);
    } catch (IllegalArgumentException e) {
        Log.d(TAG, "Login with Amazon isn't configured correctly. " + "Thus it's disabled in this demo.");
    }
    btnLoginLWA = (Button) findViewById(R.id.btnLoginLWA);
    btnLoginLWA.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mAuthManager.authorize(APP_SCOPES, Bundle.EMPTY, new AuthorizeListener());
        }
    });
    btnLoginLWA.setEnabled(mAuthManager != null);

    Button btnWipedata = (Button) findViewById(R.id.btnWipedata);
    btnWipedata.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(MainActivity.this).setTitle("Wipe data?")
                    .setMessage("This will log off your current session and wipe all user data. "
                            + "Any data not synchronized will be lost.")
                    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // clear login status
                            if (fbAccessToken != null) {
                                LoginManager.getInstance().logOut();
                            }
                            btnLoginFacebook.setVisibility(View.VISIBLE);
                            if (mAuthManager != null) {
                                mAuthManager.clearAuthorizationState(null);
                            }
                            btnLoginLWA.setVisibility(View.VISIBLE);
                            // wipe data
                            CognitoSyncClientManager.getInstance().wipeData();

                            // Wipe shared preferences
                            AmazonSharedPreferencesWrapper
                                    .wipe(PreferenceManager.getDefaultSharedPreferences(MainActivity.this));
                        }

                    }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    }).show();
        }
    });

    findViewById(R.id.btnListDatasets).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, ListDatasetsActivity.class);
            startActivity(intent);
        }
    });

    btnLoginDevAuth = (Button) findViewById(R.id.btnLoginDevAuth);
    if ((CognitoSyncClientManager.credentialsProvider
            .getIdentityProvider()) instanceof DeveloperAuthenticationProvider) {
        btnLoginDevAuth.setEnabled(true);
        Log.w(TAG, "Developer authentication feature configured correctly. ");
    } else {
        btnLoginDevAuth.setEnabled(false);
        Log.w(TAG, "Developer authentication feature configured incorrectly. "
                + "Thus it's disabled in this demo.");
    }
    btnLoginDevAuth.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // username and password dialog
            final Dialog login = new Dialog(MainActivity.this);
            login.setContentView(R.layout.login_dialog);
            login.setTitle("Sample developer login");
            final TextView txtUsername = (TextView) login.findViewById(R.id.txtUsername);
            txtUsername.setHint("Username");
            final TextView txtPassword = (TextView) login.findViewById(R.id.txtPassword);
            txtPassword.setHint("Password");
            Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
            Button btnCancel = (Button) login.findViewById(R.id.btnCancel);

            btnCancel.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    login.dismiss();
                }
            });

            btnLogin.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    // Validate the username and password
                    if (txtUsername.getText().toString().isEmpty()
                            || txtPassword.getText().toString().isEmpty()) {
                        new AlertDialog.Builder(MainActivity.this).setTitle("Login error")
                                .setMessage("Username or password cannot be empty!!").show();
                    } else {
                        // Clear the existing credentials
                        CognitoSyncClientManager.credentialsProvider.clearCredentials();
                        // Initiate user authentication against the
                        // developer backend in this case the sample Cognito
                        // developer authentication application.
                        ((DeveloperAuthenticationProvider) CognitoSyncClientManager.credentialsProvider
                                .getIdentityProvider()).login(txtUsername.getText().toString(),
                                        txtPassword.getText().toString(), MainActivity.this);
                    }
                    login.dismiss();
                }
            });
            login.show();
        }
    });

    /**
     * Button that leaves the app and launches the Twitter site to get an authorization.
     * If the user grants permissions to our app, it will be redirected to us again through
     * a callback.
     */
    Button btnLoginTwitter = (Button) findViewById(R.id.btnLoginTwitter);
    btnLoginTwitter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        String callbackUrl = "callback://" + getString(R.string.twitter_callback_url);
                        String authUrl = mOauthProvider.retrieveRequestToken(mOauthConsumer, callbackUrl);
                        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl));
                        startActivity(intent);
                    } catch (Exception e) {
                        Log.w("oauth fail", e);
                    }
                }
            }).start();
        }
    });
    btnLoginTwitter.setEnabled(getString(R.string.twitter_consumer_secret) != "twitter_consumer_secret");

}

From source file:com.nextgis.woody.activity.MainActivity.java

@Override
public void onAddAccount(Account account, String token, boolean accountAdded) {
    Log.d(Constants.WTAG, "No account. " + Constants.ACCOUNT_NAME + " created. Run first step.");

    if (accountAdded) {
        // TODO: final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

        final MainApplication app = (MainApplication) getApplication();
        app.setUserData(account.name, Constants.KEY_IS_AUTHORIZED, token);

        //set sync with server
        ContentResolver.setSyncAutomatically(account, app.getAuthority(), true);
        ContentResolver.addPeriodicSync(account, app.getAuthority(), Bundle.EMPTY,
                com.nextgis.maplib.util.Constants.DEFAULT_SYNC_PERIOD);

        // goto step 2
        refreshActivityView();/*from ww w  .j  a va  2 s  .  com*/
    } else
        Toast.makeText(this, R.string.error_init, Toast.LENGTH_SHORT).show();
}

From source file:com.moubry.worthwatching.ui.BaseActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        Toast.makeText(this, "Tapped home", Toast.LENGTH_SHORT).show();
        break;/*from  www.  jav a  2 s  .co  m*/

    case R.id.menu_refresh:
        Toast.makeText(this, "Fake refreshing...", Toast.LENGTH_SHORT).show();
        getActionBarHelper().setRefreshActionItemState(true);
        getWindow().getDecorView().postDelayed(new Runnable() {
            @Override
            public void run() {
                getActionBarHelper().setRefreshActionItemState(false);
            }
        }, 1000);
        break;

    case R.id.menu_search:
        startSearch(null, false, Bundle.EMPTY, false);
        break;

    case R.id.menu_settings:
        startActivity(new Intent(this, SettingsActivity.class));
        break;

    case R.id.menu_home:
        startActivity(new Intent(this, HomeActivity.class));
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:dev.drsoran.moloko.fragments.NoteEditFragment.java

private void registerForNoteDeletedByBackgroundSync() {
    noteChangesObserver = new ContentObserver(MolokoApp.getHandler()) {
        @Override/*from  w  ww. j  av a2  s .c  o  m*/
        public void onChange(boolean selfChange) {
            getSherlockActivity().getSupportLoaderManager().initLoader(RtmTaskNoteLoader.ID, Bundle.EMPTY,
                    NoteEditFragment.this);
        }
    };

    getSherlockActivity().getContentResolver().registerContentObserver(
            Queries.contentUriWithId(Notes.CONTENT_URI, getNoteAssertNotNull().getId()), false,
            noteChangesObserver);
}

From source file:com.tct.mail.browse.MessageFooterView.java

public void bind(MessageHeaderItem headerItem, boolean measureOnly) {
    mMessageHeaderItem = headerItem;/*from   w ww .j av  a 2  s.  c o  m*/

    //TS: zhaotianyong 2014-12-31 EMAIL BUGFIX_869494 ADD
    if (!getResources().getBoolean(R.bool.feature_email_show_attachments_on_top)) {
        final Integer attachmentLoaderId = getAttachmentLoaderId();

        // Destroy the loader if we are attempting to load a different attachment
        if (mOldAttachmentLoaderId != null && !Objects.equal(mOldAttachmentLoaderId, attachmentLoaderId)) {
            mLoaderManager.destroyLoader(mOldAttachmentLoaderId);

            // Resets the footer view. This step is only done if the
            // attachmentsListUri changes so that we don't
            // repeat the work of layout and measure when
            // we're only updating the attachments.
            mAttachmentGrid.removeAllViewsInLayout();
            mAttachmentBarList.removeAllViewsInLayout();
            mViewEntireMessagePrompt.setVisibility(View.GONE);
            mAttachmentGrid.setVisibility(View.GONE);
            mAttachmentBarList.setVisibility(View.GONE);
        }
        mOldAttachmentLoaderId = attachmentLoaderId;

        // kick off load of Attachment objects in background thread
        // but don't do any Loader work if we're only measuring
        if (!measureOnly && attachmentLoaderId != null) {
            LogUtils.i(LOG_TAG, "binding footer view, calling initLoader for message %d", attachmentLoaderId);
            mLoaderManager.initLoader(attachmentLoaderId, Bundle.EMPTY, this);
        }

        // Do an initial render if initLoader didn't already do one
        if (mAttachmentGrid.getChildCount() == 0 && mAttachmentBarList.getChildCount() == 0) {
            renderAttachments(false);
        }
    }

    final ConversationMessage message = mMessageHeaderItem.getMessage();
    mViewEntireMessagePrompt
            .setVisibility(message.clipped && !TextUtils.isEmpty(message.permalink) ? VISIBLE : GONE);
    setVisibility(mMessageHeaderItem.isExpanded() ? VISIBLE : GONE);
}