/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.focus.activity;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.util.AttributeSet;
import android.view.View;

import org.mozilla.focus.R;
import org.mozilla.focus.fragment.HomeFragment;
import org.mozilla.focus.web.IWebView;
import org.mozilla.focus.web.WebViewProvider;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        getWindow().setStatusBarColor(Color.TRANSPARENT);

        setContentView(R.layout.activity_main);

        // We add the home fragment to the layout if it doesn't exist yet. I tried adding the fragment
        // to the layout directly but then I wasn't able to remove it later. It was still visible but
        // without an activity attached. So let's do it manually.
        final FragmentManager fragmentManager = getSupportFragmentManager();
        if (fragmentManager.findFragmentByTag(HomeFragment.FRAGMENT_TAG) == null) {
            fragmentManager
                    .beginTransaction()
                    .add(R.id.container, HomeFragment.create(), HomeFragment.FRAGMENT_TAG)
                    .commit();
        }
    }

    @Override
    public View onCreateView(String name, Context context, AttributeSet attrs) {
        if (name.equals(IWebView.class.getName())) {
            return WebViewProvider.create(this, attrs);
        }

        return super.onCreateView(name, context, attrs);
    }
}

@@ -334,22 +334,93 @@
 oid.
-content.Contex
+annotation.SuppressLint;%0Aimport android.content.Context;%0Aimport android.content.Inten
 t;%0Ai
@@ -660,16 +660,67 @@
 ocus.R;%0A
+import org.mozilla.focus.fragment.BrowserFragment;%0A
 import o
@@ -898,16 +898,47 @@
 tivity %7B
+%0A    private String pendingUrl;
 %0A%0A    @O
@@ -1301,24 +1301,929 @@
 ity_main);%0A%0A
+        if (Intent.ACTION_VIEW.equals(getIntent().getAction())) %7B%0A            showBrowserScreen(getIntent().getDataString());%0A        %7D else %7B%0A            showHomeScreen();%0A        %7D%0A    %7D%0A%0A    @Override%0A    @SuppressLint(%22CommitTransaction%22)%0A    protected void onNewIntent(Intent intent) %7B%0A        if (Intent.ACTION_VIEW.equals(intent.getAction())) %7B%0A            // We can't update our fragment right now because we need to wait until the activity is%0A            // resumed. So just remember this URL and load it in onResume().%0A            pendingUrl = intent.getDataString();%0A        %7D%0A    %7D%0A%0A    @Override%0A    protected void onResume() %7B%0A        super.onResume();%0A%0A        if (pendingUrl != null) %7B%0A            // We have received an URL in onNewIntent(). Let's load it now.%0A            showBrowserScreen(pendingUrl);%0A            pendingUrl = null;%0A        %7D%0A    %7D%0A%0A    private void showHomeScreen() %7B%0A
         // W
@@ -2731,19 +2731,23 @@
        .
-add
+replace
 (R.id.co
@@ -2845,32 +2845,311 @@
        %7D%0A    %7D%0A%0A
+    private void showBrowserScreen(String url) %7B%0A        getSupportFragmentManager()%0A                .beginTransaction()%0A                .replace(R.id.container,%0A                        BrowserFragment.create(url), BrowserFragment.FRAGMENT_TAG)%0A                .commit();%0A    %7D%0A%0A
     @Override%0A  

Add support for VIEW intents from other apps. (#10)