Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 package org.mozilla.gecko.sync.setup.activities;
7 import java.util.Arrays;
8 import java.util.List;
10 import android.content.Intent;
11 import android.os.Bundle;
13 /**
14 * A static factory that extracts (title, uri) pairs suitable for send tab from
15 * Android intent instances.
16 * <p>
17 * Takes some care to extract likely "Web URLs" in preference to general URIs.
18 */
19 public class SendTabData {
20 public final String title;
21 public final String uri;
23 public SendTabData(String title, String uri) {
24 this.title = title;
25 this.uri = uri;
26 }
28 public static SendTabData fromIntent(Intent intent) {
29 if (intent == null) {
30 throw new IllegalArgumentException("intent must not be null");
31 }
33 return fromBundle(intent.getExtras());
34 }
36 protected static SendTabData fromBundle(Bundle bundle) {
37 if (bundle == null) {
38 throw new IllegalArgumentException("bundle must not be null");
39 }
41 String text = bundle.getString(Intent.EXTRA_TEXT);
42 String subject = bundle.getString(Intent.EXTRA_SUBJECT);
43 String title = bundle.getString(Intent.EXTRA_TITLE);
45 // For title, prefer EXTRA_SUBJECT but accept EXTRA_TITLE.
46 String theTitle = subject;
47 if (theTitle == null) {
48 theTitle = title;
49 }
51 // For URL, take first URL from EXTRA_TEXT, EXTRA_SUBJECT, and EXTRA_TITLE
52 // (in that order).
53 List<String> strings = Arrays.asList(text, subject, title);
54 String theUri = new WebURLFinder(strings).bestWebURL();
56 return new SendTabData(theTitle, theUri);
57 }
58 }