Add example showing full-screen iOS/Android view from Flutter (#10386)

This commit is contained in:
Sarah Zakarias
2017-05-30 13:28:30 +02:00
committed by GitHub
parent 178f446d71
commit d14bb2cdfc
62 changed files with 1770 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
GeneratedPluginRegistrant.java
/gradle
/gradlew
/gradlew.bat

View File

@@ -0,0 +1,51 @@
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withInputStream { stream ->
localProperties.load(stream)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "io.flutter.examples.platform_view"
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
androidTestCompile 'com.android.support:support-annotations:25.0.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
}

View File

@@ -0,0 +1,43 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.flutter.examples.platform_view"
android:versionCode="1"
android:versionName="0.0.1">
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />
<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET" />
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:icon="@mipmap/ic_launcher"
android:label="platform_view">
<activity
android:name="io.flutter.examples.platform_view.MainActivity"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="io.flutter.examples.platform_view.CountActivity"
android:parentActivityName="io.flutter.examples.platform_view.MainActivity"
android:theme="@style/Theme.AppCompat.NoActionBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"></activity>
</application>
</manifest>

View File

@@ -0,0 +1,66 @@
// Copyright 2017, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package io.flutter.examples.platform_view;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class CountActivity extends AppCompatActivity {
public static final String EXTRA_COUNTER = "counter";
private int counter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.android_full_screen_layout);
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
myToolbar.setTitle("Platform View");
setSupportActionBar(myToolbar);
counter = getIntent().getIntExtra(EXTRA_COUNTER, 0);
updateText();
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
counter++;
updateText();
}
});
Button switchViewButton = (Button) findViewById(R.id.button);
switchViewButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
returnToFlutterView();
}
});
}
private void updateText() {
TextView textView = (TextView) findViewById(R.id.button_tap);
String value = "Button tapped " + counter + (counter == 1 ? " time" : " times");
textView.setText(value);
}
private void returnToFlutterView() {
Intent returnIntent = new Intent();
returnIntent.putExtra(EXTRA_COUNTER, counter);
setResult(Activity.RESULT_OK, returnIntent);
finish();
}
public void onBackPressed() {
returnToFlutterView();
}
}

View File

@@ -0,0 +1,60 @@
// Copyright 2017, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package io.flutter.examples.platform_view;
import android.content.Intent;
import android.os.Bundle;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
public class MainActivity extends FlutterActivity {
private static final String CHANNEL = "samples.flutter.io/platform_view";
private static final String METHOD_SWITCH_VIEW = "switchView";
private static final int COUNT_REQUEST = 1;
private MethodChannel.Result result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(
new MethodChannel.MethodCallHandler() {
@Override
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
MainActivity.this.result = result;
int count = methodCall.arguments();
if (methodCall.method.equals(METHOD_SWITCH_VIEW)) {
onlaunchFullScreen(count);
} else {
result.notImplemented();
}
}
}
);
}
private void onlaunchFullScreen(int count) {
Intent fullScreenIntent = new Intent(this, CountActivity.class);
fullScreenIntent.putExtra(CountActivity.EXTRA_COUNTER, count);
startActivityForResult(fullScreenIntent, COUNT_REQUEST);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == COUNT_REQUEST) {
if (resultCode == RESULT_OK) {
result.success(data.getIntExtra(CountActivity.EXTRA_COUNTER, 0));
} else {
result.error("ACTIVITY_FAILURE", "Failed while launching activity", null);
}
}
}
}

View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:theme="@style/Theme.AppCompat">
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="@+id/button_tap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_tap"
android:padding="18dp"
android:textSize="@dimen/font_size" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/MyButton"
android:text="@string/switch_view"
android:textAllCaps="false" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/edge_margin"
android:background="@color/grey"
android:text="@string/android"
android:textSize="@dimen/platform_label_font_size" />
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="@dimen/edge_margin"
android:clickable="true"
android:elevation="@dimen/fab_elevation_resting"
android:src="@drawable/ic_add_black_24dp"
app:backgroundTint="@color/white"
app:fabSize="normal"
app:pressedTranslationZ="@dimen/fab_elevation_pressed"
app:rippleColor="@color/grey" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 442 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 721 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="grey" type="color">#9E9E9E</item>
<item name="white" type="color">#FFFFFF</item>
<item name="black" type="color">#000000</item>
</resources>

View File

@@ -0,0 +1,7 @@
<resources>
<dimen name="edge_margin">16dp</dimen>
<dimen name="fab_elevation_resting">6dp</dimen>
<dimen name="fab_elevation_pressed">12dp</dimen>
<dimen name="font_size">17sp</dimen>
<dimen name="platform_label_font_size">30sp</dimen>
</resources>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Platform View</string>
<string name="title">Flutter Application</string>
<string name="button_tap">Button tapped 0 times. </string>
<string name="switch_view">"Continue in Flutter view"</string>
<string name="android">Android</string>
</resources>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyButton" parent="Widget.AppCompat.Button.Borderless">
<item name="colorControlHighlight">@color/grey</item>
<item name="colorButtonNormal">@color/white</item>
<item name="android:textColor">@color/black</item>
</style>
</resources>

View File

@@ -0,0 +1,29 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
task wrapper(type: Wrapper) {
gradleVersion = '2.14.1'
}

View File

@@ -0,0 +1 @@
org.gradle.jvmargs=-Xmx1536M

View File

@@ -0,0 +1,15 @@
include ':app'
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
pluginsFile.withInputStream { stream -> plugins.load(stream) }
}
plugins.each { name, path ->
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
}