Example usage for android.os Bundle getCharSequence

List of usage examples for android.os Bundle getCharSequence

Introduction

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

Prototype

@Override
@Nullable
public CharSequence getCharSequence(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:com.example.julia.popularmovies.MovieGridActivity.java

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    if (savedInstanceState != null) {
        mToolbar.setTitle(/*  w w w.j  av a 2  s .c  om*/
                getString(R.string.format_toolbar_title, savedInstanceState.getCharSequence(TOOLBAR_TITLE)));
    }
}

From source file:org.thoughtcrime.securesms.notifications.RemoteReplyReceiver.java

@Override
protected void onReceive(final Context context, Intent intent, final @Nullable MasterSecret masterSecret) {
    if (!REPLY_ACTION.equals(intent.getAction()))
        return;//  www .  j a v  a  2  s.  c om

    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);

    if (remoteInput == null)
        return;

    final long[] recipientIds = intent.getLongArrayExtra(RECIPIENT_IDS_EXTRA);
    final CharSequence responseText = remoteInput.getCharSequence(MessageNotifier.EXTRA_REMOTE_REPLY);

    if (masterSecret != null && responseText != null) {
        new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... params) {
                long threadId;

                Optional<RecipientsPreferences> preferences = DatabaseFactory
                        .getRecipientPreferenceDatabase(context).getRecipientsPreferences(recipientIds);
                int subscriptionId = preferences.isPresent()
                        ? preferences.get().getDefaultSubscriptionId().or(-1)
                        : -1;
                long expiresIn = preferences.isPresent() ? preferences.get().getExpireMessages() * 1000 : 0;

                Recipients recipients = RecipientFactory.getRecipientsForIds(context, recipientIds, false);
                if (recipients.isGroupRecipient()) {
                    OutgoingMediaMessage reply = new OutgoingMediaMessage(recipients, responseText.toString(),
                            new LinkedList<Attachment>(), System.currentTimeMillis(), subscriptionId, expiresIn,
                            0);
                    threadId = MessageSender.send(context, masterSecret, reply, -1, false);
                } else {
                    OutgoingTextMessage reply = new OutgoingTextMessage(recipients, responseText.toString(),
                            expiresIn, subscriptionId);
                    threadId = MessageSender.send(context, masterSecret, reply, -1, false);
                }

                List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context)
                        .setRead(threadId, true);

                MessageNotifier.updateNotification(context, masterSecret);
                MarkReadReceiver.process(context, messageIds);

                return null;
            }
        }.execute();
    }

}

From source file:org.smssecure.smssecure.notifications.RemoteReplyReceiver.java

@Override
protected void onReceive(final Context context, Intent intent, final @Nullable MasterSecret masterSecret) {
    if (!REPLY_ACTION.equals(intent.getAction()))
        return;/*  w w  w .  j av a2  s .  c  o m*/

    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);

    if (remoteInput == null)
        return;

    final long[] recipientIds = intent.getLongArrayExtra(RECIPIENT_IDS_EXTRA);
    final CharSequence responseText = remoteInput.getCharSequence(MessageNotifier.EXTRA_REMOTE_REPLY);

    if (masterSecret != null && responseText != null) {
        new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... params) {
                long threadId;

                Optional<RecipientsPreferences> preferences = DatabaseFactory
                        .getRecipientPreferenceDatabase(context).getRecipientsPreferences(recipientIds);
                int subscriptionId = preferences.isPresent()
                        ? preferences.get().getDefaultSubscriptionId().or(-1)
                        : -1;

                Recipients recipients = RecipientFactory.getRecipientsForIds(context, recipientIds, false);
                if (recipients.isGroupRecipient()) {
                    OutgoingMediaMessage reply = new OutgoingMediaMessage(recipients, responseText.toString(),
                            new LinkedList<Attachment>(), System.currentTimeMillis(), subscriptionId, 0);
                    threadId = MessageSender.send(context, masterSecret, reply, -1, false);
                } else {
                    boolean secure = SessionUtil.hasSession(context, masterSecret,
                            recipients.getPrimaryRecipient());

                    OutgoingTextMessage reply;
                    if (!secure) {
                        reply = new OutgoingTextMessage(recipients, responseText.toString(), subscriptionId);
                    } else {
                        reply = new OutgoingEncryptedMessage(recipients, responseText.toString(),
                                subscriptionId);
                    }

                    threadId = MessageSender.send(context, masterSecret, reply, -1, false);
                }

                DatabaseFactory.getThreadDatabase(context).setRead(threadId);
                DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId);

                MessageNotifier.updateNotification(context, masterSecret);

                return null;
            }
        }.execute();
    }

}

From source file:com.irccloud.android.RemoteInputService.java

@Override
protected void onHandleIntent(Intent intent) {
    boolean success = false;
    String sk = getSharedPreferences("prefs", 0).getString("session_key", "");
    if (intent != null && sk != null && sk.length() > 0) {
        final String action = intent.getAction();
        if (ACTION_REPLY.equals(action)) {
            Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
            if (remoteInput != null || intent.hasExtra("reply")) {
                Crashlytics.log(Log.INFO, "IRCCloud", "Got reply from RemoteInput");
                String reply = remoteInput != null ? remoteInput.getCharSequence("extra_reply").toString()
                        : intent.getStringExtra("reply");
                if (reply.length() > 0 && !reply.contains("\n/")
                        && (!reply.startsWith("/") || reply.toLowerCase().startsWith("/me ")
                                || reply.toLowerCase().startsWith("/slap "))) {
                    try {
                        JSONObject o = NetworkConnection.getInstance().say(intent.getIntExtra("cid", -1),
                                intent.getStringExtra("to"), reply, sk);
                        success = o.getBoolean("success");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }//from  ww w  . j a  v a 2  s . c o m
                }
                NotificationManagerCompat.from(IRCCloudApplication.getInstance().getApplicationContext())
                        .cancel(intent.getIntExtra("bid", 0));
                if (intent.hasExtra("eids")) {
                    int bid = intent.getIntExtra("bid", -1);
                    long[] eids = intent.getLongArrayExtra("eids");
                    for (int j = 0; j < eids.length; j++) {
                        if (eids[j] > 0) {
                            Notifications.getInstance().dismiss(bid, eids[j]);
                        }
                    }
                }
                if (!success)
                    Notifications.getInstance().alert(intent.getIntExtra("bid", -1), "Sending Failed",
                            reply.startsWith("/") ? "Please launch the IRCCloud app to send this command"
                                    : "Your message was not sent. Please try again shortly.");
            } else {
                Crashlytics.log(Log.ERROR, "IRCCloud", "RemoteInputService received no remoteinput");
            }
        }
    }
}

From source file:org.totschnig.myexpenses.dialog.MessageDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Bundle bundle = getArguments();
    Activity ctx = getActivity();//from   w ww .  j ava2s.c om
    Context wrappedCtx = DialogUtils.wrapContext2(ctx);
    AlertDialog.Builder builder = new AlertDialog.Builder(wrappedCtx).setTitle(bundle.getInt("title"))
            .setMessage(bundle.getCharSequence("message"));
    Button positive = (Button) bundle.getSerializable("positive");
    Button neutral = (Button) bundle.getSerializable("neutral");
    Button negative = (Button) bundle.getSerializable("negative");
    if (positive != null)
        builder.setPositiveButton(positive.label, this);
    if (neutral != null)
        builder.setNeutralButton(neutral.label, this);
    if (negative != null)
        builder.setNegativeButton(negative.label, this);
    return builder.create();
}

From source file:com.commonsware.android.ab.search.ActionBarFragment.java

@Override
public void onViewCreated(View v, Bundle savedInstanceState) {
    super.onViewCreated(v, savedInstanceState);

    if (savedInstanceState == null) {
        initAdapter(null);//from  ww w. j  a  va2s .c o m
    } else {
        initAdapter(savedInstanceState.getStringArrayList(STATE_MODEL));
        initialQuery = savedInstanceState.getCharSequence(STATE_QUERY);
    }
}

From source file:com.fenlisproject.elf.core.widget.ExtendedEditText.java

@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
    switch (action) {
    case AccessibilityNodeInfo.ACTION_SET_TEXT: {
        CharSequence text = (arguments != null)
                ? arguments.getCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE)
                : null;/*from   w  ww . j  a v  a  2  s .co m*/
        setText(text);
        if (text != null && text.length() > 0) {
            setSelection(text.length());
        }
        return true;
    }
    default: {
        return super.performAccessibilityAction(action, arguments);
    }
    }
}

From source file:de.uni.stuttgart.informatik.ToureNPlaner.UI.Dialogs.TextDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    input = new EditText(getActivity());
    String message = getArguments().getString("title");
    CharSequence content;//from ww w . ja v  a 2 s  . c om
    if (savedInstanceState == null) {
        content = getArguments().getCharSequence("content");
    } else {
        content = savedInstanceState.getCharSequence("content");
    }
    input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    input.setText(content, TextView.BufferType.SPANNABLE);
    return new AlertDialog.Builder(getActivity()).setTitle(message).setView(input)
            .setPositiveButton(getResources().getText(android.R.string.ok),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            doPositiveClick();
                        }
                    })
            .setNegativeButton(getResources().getText(android.R.string.cancel),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            doNegativeClick();
                        }
                    })
            .setOnKeyListener(new DialogInterface.OnKeyListener() {

                @Override
                public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                    if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) && (i == KeyEvent.KEYCODE_ENTER)) {
                        dialogInterface.dismiss();
                        doPositiveClick();
                        return true;
                    }
                    return false;
                }
            }).create();
}

From source file:com.example.julia.popularmovies.MovieGridActivity.java

private void setupToolbar(Bundle savedInstanceState) {
    setSupportActionBar(mToolbar);/*w w w .j av a2 s  . com*/
    if (getSupportActionBar() != null) {
        if (savedInstanceState != null) {
            getSupportActionBar().setTitle(getString(R.string.format_toolbar_title,
                    savedInstanceState.getCharSequence(TOOLBAR_TITLE)));
        } else {
            getSupportActionBar().setTitle(getString(R.string.format_toolbar_title, FRAGMENT_NAME[0]));
        }
    }
}

From source file:com.silentcircle.silenttext.activity.AccountCreationActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment);/*  www . j  ava  2  s  .c  om*/
    findViewById(R.id.error).setVisibility(View.GONE);

    handler = new Handler();
    hideError = new ViewAnimator(this, R.id.error, R.anim.slide_up);

    Fragment fragment = getFragmentManager().findFragmentById(R.id.content);

    if (fragment == null) {
        Bundle bundle = toBundle(getIntent());

        CharSequence licenseCode = bundle.getCharSequence(AccountCreationFragment.EXTRA_LICENSE_CODE);
        if (StringUtils.isEmpty(licenseCode)) {
            // check for application level license code
            LicenseCodeProvider provider = new ApplicationLicenseCodeProvider();
            licenseCode = provider.provideLicenseCode(this);

            if (StringUtils.isEmpty(licenseCode)) {
                // check for auto-generated partner license codes
                provider = new EligibleLicenseCodeProvider(DeviceUtils.getPartnerEligibility(this),
                        new DeviceIDLicenseCodeProvider());
                licenseCode = provider.provideLicenseCode(this);
            }

            bundle.putCharSequence(AccountCreationFragment.EXTRA_LICENSE_CODE, licenseCode);
        }

        fragment = AccountCreationWelcomeFragment.create(bundle);
        getFragmentManager().beginTransaction().add(R.id.content, fragment).commit();
    }

    if (fragment instanceof HasFlow) {
        ((HasFlow) fragment).setFlowListener(this);
    }

    getFragmentManager().addOnBackStackChangedListener(new OnBackStackChangedListener() {

        @Override
        public void onBackStackChanged() {
            Fragment f = getFragmentManager().findFragmentById(R.id.content);
            if (f instanceof HasFlow) {
                ((HasFlow) f).setFlowListener(AccountCreationActivity.this);
            }
        }
    });

}