Add flutter_view sample (#8486)
* Add flutter_view sample * Removed platform_services files * Addressed comments * update README.md * Addressed comments.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.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:label="flutter_view" android:icon="@mipmap/ic_launcher">
|
||||
<activity android:name=".MainActivity"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/Theme.AppCompat"
|
||||
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>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.example.view;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import io.flutter.view.FlutterMain;
|
||||
import io.flutter.view.FlutterView;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
private FlutterView flutterView;
|
||||
private int counter;
|
||||
private static final String CHANNEL = "increment";
|
||||
private static final String EMPTY_MESSAGE = "";
|
||||
|
||||
private String[] getArgsFromIntent(Intent intent) {
|
||||
// Before adding more entries to this list, consider that arbitrary
|
||||
// Android applications can generate intents with extra data and that
|
||||
// there are many security-sensitive args in the binary.
|
||||
ArrayList<String> args = new ArrayList<String>();
|
||||
if (intent.getBooleanExtra("trace-startup", false)) {
|
||||
args.add("--trace-startup");
|
||||
}
|
||||
if (intent.getBooleanExtra("start-paused", false)) {
|
||||
args.add("--start-paused");
|
||||
}
|
||||
if (intent.getBooleanExtra("enable-dart-profiling", false)) {
|
||||
args.add("--enable-dart-profiling");
|
||||
}
|
||||
if (!args.isEmpty()) {
|
||||
String[] argsArray = new String[args.size()];
|
||||
return args.toArray(argsArray);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
String[] args = getArgsFromIntent(getIntent());
|
||||
FlutterMain.ensureInitializationComplete(getApplicationContext(), args);
|
||||
setContentView(R.layout.flutter_view_layout);
|
||||
getSupportActionBar().hide();
|
||||
|
||||
flutterView = (FlutterView) findViewById(R.id.flutter_view);
|
||||
flutterView.runFromBundle(FlutterMain.findAppBundlePath(getApplicationContext()), null);
|
||||
|
||||
flutterView.addOnMessageListener(CHANNEL,
|
||||
new FlutterView.OnMessageListener() {
|
||||
@Override
|
||||
public String onMessage(FlutterView view, String message) {
|
||||
return onFlutterIncrement();
|
||||
}
|
||||
});
|
||||
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.button);
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
sendAndroidIncrement();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void sendAndroidIncrement() {
|
||||
flutterView.sendToFlutter(CHANNEL, EMPTY_MESSAGE, null);
|
||||
}
|
||||
|
||||
private String onFlutterIncrement() {
|
||||
counter++;
|
||||
TextView textView = (TextView) findViewById(R.id.button_tap);
|
||||
String value = "Flutter button tapped " + counter + (counter == 1 ? " time" : " times");
|
||||
textView.setText(value);
|
||||
return EMPTY_MESSAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (flutterView != null) {
|
||||
flutterView.destroy();
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
flutterView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostResume() {
|
||||
super.onPostResume();
|
||||
flutterView.onPostResume();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true" android:color="@color/grey" />
|
||||
<item android:state_focused="true" android:color="@color/grey" />
|
||||
<item android:color="@color/white"/>
|
||||
</selector>
|
||||
@@ -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>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?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:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
>
|
||||
|
||||
<io.flutter.view.FlutterView
|
||||
android:id="@+id/flutter_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
/>
|
||||
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@color/grey"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/button_tap"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/button_tap"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:textSize="@dimen/font_size"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/android"
|
||||
android:layout_margin="@dimen/edge_margin"
|
||||
android:textSize="@dimen/platform_label_font_size"
|
||||
android:background="@color/grey"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|right"
|
||||
android:elevation="@dimen/fab_elevation_resting"
|
||||
app:pressedTranslationZ="@dimen/fab_elevation_pressed"
|
||||
android:layout_margin="@dimen/edge_margin"
|
||||
android:src="@drawable/ic_add_black_24dp"
|
||||
android:clickable="true"
|
||||
app:rippleColor="@color/grey"
|
||||
app:fabSize="normal"
|
||||
app:backgroundTint="@color/white"
|
||||
/>
|
||||
|
||||
</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 |
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<item name="grey" type="color">#9E9E9E</item>
|
||||
<item name="white" type="color">#FFFFFF</item>
|
||||
</resources>
|
||||
@@ -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>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">Flutter View</string>
|
||||
<string name="title">Flutter Application</string>
|
||||
<string name="button_tap">Flutter button tapped 0 times.</string>
|
||||
<string name="android">Android</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user