Skip to content

Commit 1f55123

Browse files
committed
Import cleaned up version of components sample browser.
1 parent d6824cd commit 1f55123

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1775
-0
lines changed

.gitignore

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Built application files
2+
*.apk
3+
*.ap_
4+
5+
# Files for the ART/Dalvik VM
6+
*.dex
7+
8+
# Java class files
9+
*.class
10+
11+
# Generated files
12+
bin/
13+
gen/
14+
out/
15+
16+
# Gradle files
17+
.gradle/
18+
build/
19+
20+
# Local configuration file (sdk path, etc)
21+
local.properties
22+
23+
# Proguard folder generated by Eclipse
24+
proguard/
25+
26+
# Log Files
27+
*.log
28+
29+
# Android Studio Navigation editor temp files
30+
.navigation/
31+
32+
# Android Studio captures folder
33+
captures/
34+
35+
# Intellij
36+
*.iml
37+
.idea/
38+
39+
# Keystore files
40+
*.jks
41+
42+
# Local checkout of localization files
43+
l10n-repo/
44+
45+
# Compiled python code
46+
*.pyc
47+
48+
# OS X
49+
.DS_Store
50+
51+
# jacoco.exec
52+
jacoco.exec

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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/. */
4+
5+
apply plugin: 'com.android.application'
6+
apply plugin: 'kotlin-android'
7+
apply plugin: 'kotlin-android-extensions'
8+
9+
android {
10+
compileSdkVersion Config.compileSdkVersion
11+
12+
defaultConfig {
13+
applicationId "org.mozilla.reference.browser"
14+
minSdkVersion Config.minSdkVersion
15+
targetSdkVersion Config.targetSdkVersion
16+
versionCode Config.versionCode
17+
versionName Config.versionName
18+
19+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
20+
}
21+
22+
buildTypes {
23+
release {
24+
minifyEnabled false
25+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26+
}
27+
}
28+
29+
flavorDimensions "engine", "abi"
30+
31+
productFlavors {
32+
// GeckoView release channels (GV release is not on maven.mozilla.org yet)
33+
geckoNightly { dimension "engine" }
34+
geckoBeta { dimension "engine" }
35+
36+
// WebViewgeck
37+
system { dimension "engine" }
38+
39+
// Processor architectures
40+
arm { dimension "abi" }
41+
x86 { dimension "abi" }
42+
universal { dimension "abi" }
43+
}
44+
45+
variantFilter { variant ->
46+
def flavors = variant.flavors*.name.toString().toLowerCase()
47+
if (flavors.contains("system") && !flavors.contains("universal")) {
48+
setIgnore(true)
49+
}
50+
51+
if (flavors.contains("gecko") && flavors.contains("universal")) {
52+
setIgnore(true)
53+
}
54+
}
55+
}
56+
57+
configurations {
58+
systemUniversalImplementation {}
59+
60+
geckoNightlyArmImplementation {}
61+
geckoNightlyX86Implementation {}
62+
63+
geckoBetaArmImplementation {}
64+
geckoBetaX86Implementation {}
65+
}
66+
67+
dependencies {
68+
implementation Deps.mozilla_concept_engine
69+
implementation Deps.mozilla_concept_tabstray
70+
implementation Deps.mozilla_concept_toolbar
71+
72+
implementation Deps.mozilla_browser_search
73+
implementation Deps.mozilla_browser_session
74+
implementation Deps.mozilla_browser_tabstray
75+
implementation Deps.mozilla_browser_toolbar
76+
implementation Deps.mozilla_browser_menu
77+
78+
implementation Deps.mozilla_feature_intent
79+
implementation Deps.mozilla_feature_search
80+
implementation Deps.mozilla_feature_session
81+
implementation Deps.mozilla_feature_toolbar
82+
implementation Deps.mozilla_feature_tabs
83+
84+
implementation Deps.mozilla_ui_autocomplete
85+
86+
implementation Deps.mozilla_support_utils
87+
88+
systemUniversalImplementation Deps.mozilla_browser_engine_system
89+
90+
geckoNightlyImplementation Deps.mozilla_browser_engine_gecko_nightly
91+
geckoNightlyArmImplementation Gecko.geckoview_nightly_arm
92+
geckoNightlyX86Implementation Gecko.geckoview_nightly_x86
93+
94+
geckoBetaImplementation Deps.mozilla_browser_engine_gecko_beta
95+
geckoBetaArmImplementation Gecko.geckoview_beta_arm
96+
geckoBetaX86Implementation Gecko.geckoview_beta_x86
97+
98+
implementation Deps.kotlin_stdlib
99+
implementation Deps.kotlin_coroutines
100+
101+
implementation Deps.support_appcompat
102+
implementation Deps.support_constraintlayout
103+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.mozilla.reference.browser/* 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/. */
4+
5+
import android.content.Context
6+
import mozilla.components.browser.engine.gecko.GeckoEngine
7+
import mozilla.components.concept.engine.DefaultSettings
8+
import mozilla.components.concept.engine.Engine
9+
import org.mozilla.geckoview.GeckoRuntime
10+
11+
object EngineProvider {
12+
fun getEngine(context: Context, defaultSettings: DefaultSettings): Engine {
13+
val runtime = GeckoRuntime.getDefault(context)
14+
return GeckoEngine(runtime, defaultSettings)
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.mozilla.reference.browser/* 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/. */
4+
5+
import android.content.Context
6+
import mozilla.components.browser.engine.gecko.GeckoEngine
7+
import mozilla.components.concept.engine.DefaultSettings
8+
import mozilla.components.concept.engine.Engine
9+
import org.mozilla.geckoview.GeckoRuntime
10+
11+
object EngineProvider {
12+
fun getEngine(context: Context, defaultSettings: DefaultSettings): Engine {
13+
val runtime = GeckoRuntime.getDefault(context)
14+
return GeckoEngine(runtime, defaultSettings)
15+
}
16+
}

app/src/main/AndroidManifest.xml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- This Source Code Form is subject to the terms of the Mozilla Public
3+
- License, v. 2.0. If a copy of the MPL was not distributed with this
4+
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
5+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
6+
xmlns:tools="http://schemas.android.com/tools"
7+
package="org.mozilla.reference.browser">
8+
9+
<uses-permission android:name="android.permission.INTERNET" />
10+
11+
<application
12+
android:allowBackup="true"
13+
android:fullBackupContent="@xml/backup_rules"
14+
android:icon="@mipmap/ic_launcher"
15+
android:roundIcon="@mipmap/ic_launcher_round"
16+
android:label="@string/app_name"
17+
android:supportsRtl="true"
18+
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
19+
android:name=".BrowserApplication">
20+
<activity android:name=".BrowserActivity"
21+
android:launchMode="singleTask"
22+
android:configChanges="keyboard|keyboardHidden|mcc|mnc|orientation|screenSize|locale|layoutDirection|smallestScreenSize|screenLayout">
23+
<intent-filter>
24+
<action android:name="android.intent.action.MAIN" />
25+
26+
<category android:name="android.intent.category.LAUNCHER" />
27+
</intent-filter>
28+
</activity>
29+
30+
<activity android:name=".CustomTabActivity"
31+
android:configChanges="keyboard|keyboardHidden|mcc|mnc|orientation|screenSize|locale|layoutDirection|smallestScreenSize|screenLayout"
32+
android:windowSoftInputMode="adjustResize|stateAlwaysHidden"
33+
android:exported="false"
34+
android:taskAffinity=""
35+
android:persistableMode="persistNever"
36+
android:autoRemoveFromRecents="false"
37+
android:label="@string/app_name" />
38+
39+
<activity android:name=".IntentReceiverActivity">
40+
<intent-filter>
41+
<action android:name="android.intent.action.VIEW" />
42+
<category android:name="android.intent.category.DEFAULT" />
43+
<category android:name="android.intent.category.BROWSABLE" />
44+
<data android:scheme="http" />
45+
<data android:scheme="https" />
46+
</intent-filter>
47+
48+
<intent-filter>
49+
<action android:name="android.intent.action.SEND" />
50+
<category android:name="android.intent.category.DEFAULT" />
51+
<data android:mimeType="text/plain" />
52+
</intent-filter>
53+
</activity>
54+
55+
<service
56+
android:name="mozilla.components.browser.session.tab.CustomTabsService"
57+
android:exported="true"
58+
tools:ignore="ExportedService">
59+
<intent-filter>
60+
<action android:name="android.support.customtabs.action.CustomTabsService" />
61+
</intent-filter>
62+
</service>
63+
64+
</application>
65+
66+
</manifest>

app/src/main/ic_launcher-web.png

51.2 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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/. */
4+
5+
package org.mozilla.reference.browser
6+
7+
/**
8+
* Interface for fragments that want to handle 'back' button presses.
9+
*/
10+
interface BackHandler {
11+
fun onBackPressed(): Boolean
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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/. */
4+
5+
package org.mozilla.reference.browser
6+
7+
import android.content.ComponentCallbacks2
8+
import android.content.Context
9+
import android.os.Bundle
10+
import android.support.v7.app.AppCompatActivity
11+
import android.util.AttributeSet
12+
import android.view.View
13+
import mozilla.components.browser.tabstray.BrowserTabsTray
14+
import mozilla.components.concept.engine.EngineView
15+
import mozilla.components.concept.tabstray.TabsTray
16+
import mozilla.components.feature.intent.IntentProcessor
17+
import mozilla.components.support.utils.SafeIntent
18+
import org.mozilla.reference.browser.ext.components
19+
20+
open class BrowserActivity : AppCompatActivity(), ComponentCallbacks2 {
21+
override fun onCreate(savedInstanceState: Bundle?) {
22+
super.onCreate(savedInstanceState)
23+
setContentView(R.layout.activity_main)
24+
25+
if (savedInstanceState == null) {
26+
val sessionId = SafeIntent(intent).getStringExtra(IntentProcessor.ACTIVE_SESSION_ID)
27+
supportFragmentManager?.beginTransaction()?.apply {
28+
replace(R.id.container, BrowserFragment.create(sessionId))
29+
commit()
30+
}
31+
}
32+
}
33+
34+
override fun onBackPressed() {
35+
supportFragmentManager.fragments.forEach {
36+
if (it is BackHandler && it.onBackPressed()) {
37+
return
38+
}
39+
}
40+
41+
super.onBackPressed()
42+
}
43+
44+
override fun onCreateView(parent: View?, name: String?, context: Context, attrs: AttributeSet?): View? =
45+
when (name) {
46+
EngineView::class.java.name -> components.engine.createView(context, attrs).asView()
47+
TabsTray::class.java.name -> BrowserTabsTray(context, attrs)
48+
else -> super.onCreateView(parent, name, context, attrs)
49+
}
50+
51+
override fun onTrimMemory(level: Int) {
52+
components.sessionManager.onLowMemory()
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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/. */
4+
5+
package org.mozilla.reference.browser
6+
7+
import android.app.Application
8+
9+
class BrowserApplication : Application() {
10+
val components by lazy { Components(this) }
11+
}

0 commit comments

Comments
 (0)