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:eu.thecoder4.gpl.pleftdroid.HandleLinksActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TextView tv = new TextView(this);

    tv.setText("Verifying Link...");
    setContentView(tv);//from  w ww .ja  v a 2 s  .  c om

    Intent intent = getIntent();
    if (intent.getAction().equals("android.intent.action.VIEW")) {
        try {
            Uri uri = getIntent().getData();
            theurl = uri.toString();

        } catch (Exception e) {
            Toast.makeText(this, R.string.toast_couldnotopenurl, Toast.LENGTH_LONG).show();
        }
    } else if (Intent.ACTION_SEND.equals(intent.getAction())) {

        Bundle extras = intent.getExtras();
        theurl = extras.getCharSequence(Intent.EXTRA_TEXT).toString();
    } else {
        theurl = "";
    }
    //Toast.makeText(this, "The URL  =  "+theurl, Toast.LENGTH_LONG).show();

    // Parse the URL
    // VERIFICATION: verify?id=&u=&p=
    // INVITATION: a?id=&u=&p=
    if (theurl.indexOf("?") < 0 && theurl.indexOf("/verify?") < 0 && theurl.indexOf("/a?") < 0) {
        Toast.makeText(this, R.string.toast_linknotsupp, Toast.LENGTH_LONG).show();
        finish();
    } else {
        Map<String, String> arr = PleftBroker.getParamsFromURL(theurl);

        pserver = arr.get("pserver");
        if (arr.get("id") != null) {
            aid = Integer.parseInt(arr.get("id"));
        } else {
            aid = 0;
        }
        vcode = arr.get("p");
        user = arr.get("u");
        if (aid == 0 || vcode == null || user == null) {
            Toast.makeText(this, R.string.toast_shlinknotvalid, Toast.LENGTH_LONG).show();
            finish();
        } else { // we have a valid Link

            handleLnk = new Runnable() {
                @Override
                public void run() {
                    handleLink();
                }
            };
            Thread thread = new Thread(null, handleLnk, "Handlethrd");
            thread.start();
        } // End - if Link is Valid
    }
}

From source file:com.example.android.wearable.wear.wearnotifications.handlers.MessagingIntentService.java

private CharSequence getMessage(Intent intent) {
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput != null) {
        return remoteInput.getCharSequence(EXTRA_REPLY);
    }//from   w  ww.  j a  v a 2  s.  c o m
    return null;
}

From source file:com.example.android.elizachat.ResponderService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (null == intent || null == intent.getAction()) {
        return Service.START_STICKY;
    }/*from  ww  w.  j  a  va 2s  . c om*/
    String action = intent.getAction();
    if (action.equals(ACTION_RESPONSE)) {
        Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent);
        CharSequence replyMessage = "";
        if (remoteInputResults != null) {
            replyMessage = remoteInputResults.getCharSequence(EXTRA_REPLY);
        }
        processIncoming(replyMessage.toString());
    } else if (action.equals(MainActivity.ACTION_GET_CONVERSATION)) {
        broadcastMessage(mCompleteConversation.toString());
    }
    return Service.START_STICKY;
}

From source file:com.uiowa.chat.services.ReplyService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);

    Sender s = new Sender(this);
    s.sendThreadedMessage(intent.getStringExtra(EXTRA_USERNAME), intent.getLongExtra(EXTRA_THREAD_ID, -1),
            new RegistrationUtils().getMyUserId(this),
            remoteInput.getCharSequence(EXTRA_VOICE_REPLY).toString());

    NotificationManagerCompat manager = NotificationManagerCompat.from(this);
    manager.cancel(PushNotificationService.MESSAGE_NOTIFICATION_ID);
}

From source file:com.ntsync.android.sync.activities.MessageDialog.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle args = getArguments();
    textId = args.getInt(PARAM_TEXTID);//from w  w  w.ja  v  a  2  s  . c  o m
    text = args.getCharSequence(PARAM_TEXT);
    title = args.getCharSequence(PARAM_TITLE);
    positiveBtnText = args.getCharSequence(PARAM_POSITIVEBUTTONTEXT);

    closeActivity = args.getBoolean(PARAM_CLOSE, false);

}

From source file:com.tingtingapps.securesms.notifications.WearReplyReceiver.java

@Override
protected void onReceive(final Context context, Intent intent, final @Nullable MasterSecret masterSecret) {
    if (!REPLY_ACTION.equals(intent.getAction()))
        return;//  w ww.  j  a  v a  2s.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_VOICE_REPLY);
    final Recipients recipients = RecipientFactory.getRecipientsForIds(context, recipientIds, false);

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

                if (recipients.isGroupRecipient()) {
                    OutgoingMediaMessage reply = new OutgoingMediaMessage(context, recipients, new PduBody(),
                            responseText.toString(), 0);
                    threadId = MessageSender.send(context, masterSecret, reply, -1, false);
                } else {
                    OutgoingTextMessage reply = new OutgoingTextMessage(recipients, responseText.toString());
                    threadId = MessageSender.send(context, masterSecret, reply, -1, false);
                }

                DatabaseFactory.getThreadDatabase(context).setRead(threadId);
                MessageNotifier.updateNotification(context, masterSecret);

                return null;
            }
        }.execute();
    }

}

From source file:edu.csh.coursebrowser.CourseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_course);
    // Show the Up button in the action bar.
    this.getActionBar().setHomeButtonEnabled(false);
    map_item = new HashMap<String, Course>();
    map = new ArrayList<String>();
    Bundle args = this.getIntent().getExtras();
    this.setTitle(args.getCharSequence("title"));
    try {//from  ww  w  .  j a  v a2 s . com
        JSONObject jso = new JSONObject(args.get("args").toString());
        JSONArray jsa = new JSONArray(jso.getString("courses"));
        ListView lv = (ListView) this.findViewById(R.id.course_list);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, map);
        for (int i = 0; i < jsa.length(); ++i) {
            String s = jsa.getString(i);
            JSONObject obj = new JSONObject(s);
            Course course = new Course(obj.getString("title"), obj.getString("department"),
                    obj.getString("course"), obj.getString("description"), obj.getString("id"));
            addItem(course);
            Log.v("Added", course.toString());
        }
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                String s = ((TextView) arg1).getText().toString();
                final Course course = map_item.get(s);
                new AsyncTask<String, String, String>() {
                    ProgressDialog p;

                    protected void onPreExecute() {
                        p = new ProgressDialog(CourseActivity.this);
                        p.setTitle("Fetching Info");
                        p.setMessage("Contacting Server...");
                        p.setCancelable(false);
                        p.show();
                    }

                    protected String doInBackground(String... dep) {
                        String params = "action=getSections&course=" + course.id;
                        Log.v("Params", params);
                        URL url;
                        String back = "";
                        try {
                            url = new URL("http://iota.csh.rit" + ".edu/schedule/js/browseAjax" + ".php");

                            URLConnection conn = url.openConnection();
                            conn.setDoOutput(true);
                            OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
                            writer.write(params);
                            writer.flush();
                            String line;
                            BufferedReader reader = new BufferedReader(
                                    new InputStreamReader(conn.getInputStream()));

                            while ((line = reader.readLine()) != null) {
                                Log.v("Back:", line);
                                back += line;
                            }
                            writer.close();
                            reader.close();
                        } catch (MalformedURLException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            return null;
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            p.dismiss();
                            return null;
                        }
                        return back;
                    }

                    protected void onPostExecute(String s) {
                        if (s == null || s == "") {
                            new AlertError(CourseActivity.this, "IO Error!").show();
                            return;
                        }
                        try {
                            JSONObject jso = new JSONObject(s);
                            JSONArray jsa = new JSONArray(jso.getString("sections"));
                        } catch (JSONException e) {
                            e.printStackTrace();
                            new AlertError(CourseActivity.this, "Invalid JSON From Server").show();
                            p.dismiss();
                            return;
                        }
                        Intent intent = new Intent(CourseActivity.this, SectionsActivity.class);
                        intent.putExtra("title", course.title);
                        intent.putExtra("id", course.id);
                        intent.putExtra("description", course.description);
                        intent.putExtra("args", s);
                        startActivity(intent);
                        p.dismiss();
                    }
                }.execute(course.id);
            }

        });

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        new AlertError(this, "Invalid JSON");
        e.printStackTrace();
    }

}

From source file:com.alchemiasoft.book.service.BookActionService.java

@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
private CharSequence getExtraNotes(Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        final Bundle result = RemoteInput.getResultsFromIntent(intent);
        if (result != null) {
            return result.getCharSequence(EXTRA_ADD_NOTE);
        }/*ww w  . j  av  a  2  s .  c om*/
    }
    return null;
}

From source file:edu.csh.coursebrowser.DepartmentActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_departments);
    // Show the Up button in the action bar.
    // getActionBar().setDisplayHomeAsUpEnabled(false);
    this.getActionBar().setHomeButtonEnabled(true);
    final Bundle b = this.getIntent().getExtras();
    map_item = new HashMap<String, Department>();
    map = new ArrayList<String>();
    Bundle args = this.getIntent().getExtras();
    this.setTitle(args.getCharSequence("from"));
    try {//from  w w w.  j a  va2s.c om
        JSONObject jso = new JSONObject(args.get("args").toString());
        JSONArray jsa = new JSONArray(jso.getString("departments"));
        ListView lv = (ListView) this.findViewById(R.id.department_list);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, map);
        for (int i = 0; i < jsa.length(); ++i) {
            String s = jsa.getString(i);
            JSONObject obj = new JSONObject(s);
            Department dept = new Department(obj.getString("title"), obj.getString("id"),
                    obj.getString("code"));
            addItem(dept);
            Log.v("Added", dept.toString());
        }
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                String s = ((TextView) arg1).getText().toString();
                final Department department = map_item.get(s);
                new AsyncTask<String, String, String>() {
                    ProgressDialog p;

                    protected void onPreExecute() {
                        p = new ProgressDialog(DepartmentActivity.this);
                        p.setTitle("Fetching Info");
                        p.setMessage("Contacting Server...");
                        p.setCancelable(false);
                        p.show();
                    }

                    protected String doInBackground(String... dep) {
                        String params = "action=getCourses&department=" + dep[0] + "&quarter="
                                + b.getString("qCode");
                        Log.v("Params", params);
                        URL url;
                        String back = "";
                        try {
                            url = new URL("http://iota.csh.rit" + ".edu/schedule/js/browseAjax" + ".php");

                            URLConnection conn = url.openConnection();
                            conn.setDoOutput(true);
                            OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
                            writer.write(params);
                            writer.flush();
                            String line;
                            BufferedReader reader = new BufferedReader(
                                    new InputStreamReader(conn.getInputStream()));

                            while ((line = reader.readLine()) != null) {
                                Log.v("Back:", line);
                                back += line;
                            }
                            writer.close();
                            reader.close();
                        } catch (MalformedURLException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            return null;
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            p.dismiss();
                            return null;
                        }
                        return back;
                    }

                    protected void onPostExecute(String s) {
                        if (s == null || s == "") {
                            new AlertError(DepartmentActivity.this, "IO Error!").show();
                            return;
                        }

                        try {
                            JSONObject jso = new JSONObject(s);
                            JSONArray jsa = new JSONArray(jso.getString("courses"));
                        } catch (JSONException e) {
                            e.printStackTrace();
                            new AlertError(DepartmentActivity.this, "Invalid JSON From Server").show();
                            p.dismiss();
                            return;
                        }
                        Intent intent = new Intent(DepartmentActivity.this, CourseActivity.class);
                        intent.putExtra("title", department.title);
                        intent.putExtra("id", department.id);
                        intent.putExtra("code", department.code);
                        intent.putExtra("args", s);
                        startActivity(intent);
                        p.dismiss();
                    }
                }.execute(department.id);
            }

        });

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        new AlertError(this, "Invalid JSON");
        e.printStackTrace();
    }

}

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

@Override
protected void onReceive(final Context context, Intent intent, final @Nullable MasterSecret masterSecret) {
    if (!REPLY_ACTION.equals(intent.getAction()))
        return;//  ww w. j av  a 2 s .co  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_VOICE_REPLY);
    final Recipients recipients = RecipientFactory.getRecipientsForIds(context, recipientIds, false);

    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;

                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 {
                    OutgoingTextMessage reply = new OutgoingTextMessage(recipients, responseText.toString(),
                            subscriptionId);
                    threadId = MessageSender.send(context, masterSecret, reply, -1, false);
                }

                DatabaseFactory.getThreadDatabase(context).setRead(threadId);
                MessageNotifier.updateNotification(context, masterSecret);

                return null;
            }
        }.execute();
    }

}