Skip to content

Import cleaned up version of components sample browser. #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# Intellij
*.iml
.idea/

# Keystore files
*.jks

# Local checkout of localization files
l10n-repo/

# Compiled python code
*.pyc

# OS X
.DS_Store

# jacoco.exec
jacoco.exec
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
103 changes: 103 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/* 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/. */

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion Config.compileSdkVersion

defaultConfig {
applicationId "org.mozilla.reference.browser"
minSdkVersion Config.minSdkVersion
targetSdkVersion Config.targetSdkVersion
versionCode Config.versionCode
versionName Config.versionName

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

flavorDimensions "engine", "abi"

productFlavors {
// GeckoView release channels (GV release is not on maven.mozilla.org yet)
geckoNightly { dimension "engine" }
geckoBeta { dimension "engine" }

// WebViewgeck
system { dimension "engine" }

// Processor architectures
arm { dimension "abi" }
x86 { dimension "abi" }
universal { dimension "abi" }
}

variantFilter { variant ->
def flavors = variant.flavors*.name.toString().toLowerCase()
if (flavors.contains("system") && !flavors.contains("universal")) {
setIgnore(true)
}

if (flavors.contains("gecko") && flavors.contains("universal")) {
setIgnore(true)
}
}
}

configurations {
systemUniversalImplementation {}

geckoNightlyArmImplementation {}
geckoNightlyX86Implementation {}

geckoBetaArmImplementation {}
geckoBetaX86Implementation {}
}

dependencies {
implementation Deps.mozilla_concept_engine
implementation Deps.mozilla_concept_tabstray
implementation Deps.mozilla_concept_toolbar

implementation Deps.mozilla_browser_search
implementation Deps.mozilla_browser_session
implementation Deps.mozilla_browser_tabstray
implementation Deps.mozilla_browser_toolbar
implementation Deps.mozilla_browser_menu

implementation Deps.mozilla_feature_intent
implementation Deps.mozilla_feature_search
implementation Deps.mozilla_feature_session
implementation Deps.mozilla_feature_toolbar
implementation Deps.mozilla_feature_tabs

implementation Deps.mozilla_ui_autocomplete

implementation Deps.mozilla_support_utils

systemUniversalImplementation Deps.mozilla_browser_engine_system

geckoNightlyImplementation Deps.mozilla_browser_engine_gecko_nightly
geckoNightlyArmImplementation Gecko.geckoview_nightly_arm
geckoNightlyX86Implementation Gecko.geckoview_nightly_x86

geckoBetaImplementation Deps.mozilla_browser_engine_gecko_beta
geckoBetaArmImplementation Gecko.geckoview_beta_arm
geckoBetaX86Implementation Gecko.geckoview_beta_x86

implementation Deps.kotlin_stdlib
implementation Deps.kotlin_coroutines

implementation Deps.support_appcompat
implementation Deps.support_constraintlayout
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.mozilla.reference.browser/* 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/. */

import android.content.Context
import mozilla.components.browser.engine.gecko.GeckoEngine
import mozilla.components.concept.engine.DefaultSettings
import mozilla.components.concept.engine.Engine
import org.mozilla.geckoview.GeckoRuntime

object EngineProvider {
fun getEngine(context: Context, defaultSettings: DefaultSettings): Engine {
val runtime = GeckoRuntime.getDefault(context)
return GeckoEngine(runtime, defaultSettings)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.mozilla.reference.browser/* 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/. */

import android.content.Context
import mozilla.components.browser.engine.gecko.GeckoEngine
import mozilla.components.concept.engine.DefaultSettings
import mozilla.components.concept.engine.Engine
import org.mozilla.geckoview.GeckoRuntime

object EngineProvider {
fun getEngine(context: Context, defaultSettings: DefaultSettings): Engine {
val runtime = GeckoRuntime.getDefault(context)
return GeckoEngine(runtime, defaultSettings)
}
}
66 changes: 66 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.mozilla.reference.browser">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:name=".BrowserApplication">
<activity android:name=".BrowserActivity"
android:launchMode="singleTask"
android:configChanges="keyboard|keyboardHidden|mcc|mnc|orientation|screenSize|locale|layoutDirection|smallestScreenSize|screenLayout">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".CustomTabActivity"
android:configChanges="keyboard|keyboardHidden|mcc|mnc|orientation|screenSize|locale|layoutDirection|smallestScreenSize|screenLayout"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden"
android:exported="false"
android:taskAffinity=""
android:persistableMode="persistNever"
android:autoRemoveFromRecents="false"
android:label="@string/app_name" />

<activity android:name=".IntentReceiverActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>

<service
android:name="mozilla.components.browser.session.tab.CustomTabsService"
android:exported="true"
tools:ignore="ExportedService">
<intent-filter>
<action android:name="android.support.customtabs.action.CustomTabsService" />
</intent-filter>
</service>

</application>

</manifest>
Binary file added app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions app/src/main/java/org/mozilla/reference/browser/BackHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* 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.reference.browser

/**
* Interface for fragments that want to handle 'back' button presses.
*/
interface BackHandler {
fun onBackPressed(): Boolean
}
54 changes: 54 additions & 0 deletions app/src/main/java/org/mozilla/reference/browser/BrowserActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* 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.reference.browser

import android.content.ComponentCallbacks2
import android.content.Context
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.AttributeSet
import android.view.View
import mozilla.components.browser.tabstray.BrowserTabsTray
import mozilla.components.concept.engine.EngineView
import mozilla.components.concept.tabstray.TabsTray
import mozilla.components.feature.intent.IntentProcessor
import mozilla.components.support.utils.SafeIntent
import org.mozilla.reference.browser.ext.components

open class BrowserActivity : AppCompatActivity(), ComponentCallbacks2 {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

if (savedInstanceState == null) {
val sessionId = SafeIntent(intent).getStringExtra(IntentProcessor.ACTIVE_SESSION_ID)
supportFragmentManager?.beginTransaction()?.apply {
replace(R.id.container, BrowserFragment.create(sessionId))
commit()
}
}
}

override fun onBackPressed() {
supportFragmentManager.fragments.forEach {
if (it is BackHandler && it.onBackPressed()) {
return
}
}

super.onBackPressed()
}

override fun onCreateView(parent: View?, name: String?, context: Context, attrs: AttributeSet?): View? =
when (name) {
EngineView::class.java.name -> components.engine.createView(context, attrs).asView()
TabsTray::class.java.name -> BrowserTabsTray(context, attrs)
else -> super.onCreateView(parent, name, context, attrs)
}

override fun onTrimMemory(level: Int) {
components.sessionManager.onLowMemory()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* 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.reference.browser

import android.app.Application

class BrowserApplication : Application() {
val components by lazy { Components(this) }
}
Loading