Search in sources :

Example 11 with SafeIntent

use of mozilla.components.utils.SafeIntent in project focus-android by mozilla-mobile.

the class SessionManagerTest method testShareIntentWithTextViaNewIntent.

public void testShareIntentWithTextViaNewIntent() {
    final SessionManager sessionManager = SessionManager.getInstance();
    final Intent unsafeIntent = new Intent(Intent.ACTION_SEND);
    unsafeIntent.putExtra(Intent.EXTRA_TEXT, "Hello World Focus");
    sessionManager.handleNewIntent(RuntimeEnvironment.application, new SafeIntent(unsafeIntent));
    final List<Session> sessions = sessionManager.getSessions().getValue();
    assertNotNull(sessions);
    assertEquals(1, sessions.size());
    final Session session = sessions.get(0);
    assertTrue(session.isSearch());
    assertEquals("Hello World Focus", session.getSearchTerms());
    assertEquals(TEST_URL, session.getUrl().getValue());
    assertFalse(session.isCustomTab());
    assertNull(session.getCustomTabConfig());
    assertTrue(sessionManager.hasSession());
}
Also used : SafeIntent(mozilla.components.utils.SafeIntent) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) SafeIntent(mozilla.components.utils.SafeIntent)

Example 12 with SafeIntent

use of mozilla.components.utils.SafeIntent in project focus-android by mozilla-mobile.

the class SessionManagerTest method testCustomTabIntent.

@Test
public void testCustomTabIntent() {
    final SessionManager sessionManager = SessionManager.getInstance();
    final SafeIntent intent = new SafeIntent(new CustomTabsIntent.Builder().setToolbarColor(Color.GREEN).addDefaultShareMenuItem().build().intent.setData(Uri.parse(TEST_URL)).putExtra(CustomTabConfig.EXTRA_CUSTOM_TAB_ID, UUID.randomUUID().toString()));
    sessionManager.handleIntent(RuntimeEnvironment.application, intent, null);
    final List<Session> sessions = sessionManager.getSessions().getValue();
    assertNotNull(sessions);
    assertEquals(0, sessions.size());
    final List<Session> customTabSessions = sessionManager.getCustomTabSessions().getValue();
    assertNotNull(customTabSessions);
    assertEquals(1, customTabSessions.size());
    final Session session = customTabSessions.get(0);
    assertEquals(TEST_URL, session.getUrl().getValue());
    assertTrue(session.isCustomTab());
    assertNotNull(session.getCustomTabConfig());
    final CustomTabConfig config = session.getCustomTabConfig();
    assertNotNull(config.toolbarColor);
    assertEquals(Color.GREEN, config.toolbarColor.intValue());
    assertTrue(config.showShareMenuItem);
    assertFalse(sessionManager.hasSession());
}
Also used : CustomTabsIntent(android.support.customtabs.CustomTabsIntent) CustomTabConfig(org.mozilla.focus.customtabs.CustomTabConfig) SafeIntent(mozilla.components.utils.SafeIntent) Test(org.junit.Test)

Example 13 with SafeIntent

use of mozilla.components.utils.SafeIntent in project focus-android by mozilla-mobile.

the class TextActionActivity method onCreate.

@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final SafeIntent intent = new SafeIntent(getIntent());
    final CharSequence searchTextCharSequence = intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT);
    final String searchText;
    if (searchTextCharSequence != null) {
        searchText = searchTextCharSequence.toString();
    } else {
        searchText = "";
    }
    final String searchUrl = UrlUtils.createSearchUrl(this, searchText);
    final Intent searchIntent = new Intent(this, MainActivity.class);
    searchIntent.setAction(Intent.ACTION_VIEW);
    searchIntent.putExtra(MainActivity.EXTRA_TEXT_SELECTION, true);
    searchIntent.setData(Uri.parse(searchUrl));
    startActivity(searchIntent);
    finish();
}
Also used : SafeIntent(mozilla.components.utils.SafeIntent) SafeIntent(mozilla.components.utils.SafeIntent) Intent(android.content.Intent) RequiresApi(android.support.annotation.RequiresApi)

Example 14 with SafeIntent

use of mozilla.components.utils.SafeIntent in project focus-android by mozilla-mobile.

the class CustomTabConfigTest method malformedCloseButton.

// Tests that a non-Bitmap is ignored
@Test
public void malformedCloseButton() throws Exception {
    final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    final CustomTabsIntent customTabsIntent = builder.build();
    // Intent is a parcelable but not a Bitmap
    customTabsIntent.intent.putExtra(CustomTabsIntent.EXTRA_CLOSE_BUTTON_ICON, new Intent());
    final Bitmap bitmap = CustomTabConfig.getCloseButtonIcon(RuntimeEnvironment.application, new SafeIntent(customTabsIntent.intent));
    assertNull(bitmap);
}
Also used : CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Bitmap(android.graphics.Bitmap) SafeIntent(mozilla.components.utils.SafeIntent) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SafeIntent(mozilla.components.utils.SafeIntent) Test(org.junit.Test)

Example 15 with SafeIntent

use of mozilla.components.utils.SafeIntent in project focus-android by mozilla-mobile.

the class CustomTabConfigTest method maxSizeCloseButton.

// Tests that a max-size bitmap is OK:
@Test
public void maxSizeCloseButton() throws Exception {
    final int maxSize = RuntimeEnvironment.application.getResources().getDimensionPixelSize(R.dimen.customtabs_toolbar_icon_size);
    final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    {
        final Bitmap bitmap = Bitmap.createBitmap(new int[maxSize * maxSize], maxSize, maxSize, Bitmap.Config.ARGB_8888);
        builder.setCloseButtonIcon(bitmap);
    }
    final CustomTabsIntent customTabsIntent = builder.build();
    final Bitmap bitmap = CustomTabConfig.getCloseButtonIcon(RuntimeEnvironment.application, new SafeIntent(customTabsIntent.intent));
    // An arbitrary icon
    assertNotNull(bitmap);
    assertEquals(maxSize, bitmap.getWidth());
    assertEquals(maxSize, bitmap.getHeight());
}
Also used : CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Bitmap(android.graphics.Bitmap) SafeIntent(mozilla.components.utils.SafeIntent) Test(org.junit.Test)

Aggregations

SafeIntent (mozilla.components.utils.SafeIntent)23 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)20 Test (org.junit.Test)19 Intent (android.content.Intent)10 Bitmap (android.graphics.Bitmap)5 PendingIntent (android.app.PendingIntent)3 Bundle (android.os.Bundle)3 CustomTabConfig (org.mozilla.focus.customtabs.CustomTabConfig)2 Parcel (android.os.Parcel)1 RequiresApi (android.support.annotation.RequiresApi)1 Field (java.lang.reflect.Field)1