diff --git a/examples/hello_services/.gitignore b/examples/hello_services/.gitignore deleted file mode 100644 index 9b3426eff3..0000000000 --- a/examples/hello_services/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.DS_Store -.atom/ -.idea -.packages -.pub/ -build/ -packages/ -pubspec.lock diff --git a/examples/hello_services/.idea/modules.xml b/examples/hello_services/.idea/modules.xml deleted file mode 100644 index 06d5e0a75a..0000000000 --- a/examples/hello_services/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/examples/hello_services/.idea/runConfigurations/hello_services.xml b/examples/hello_services/.idea/runConfigurations/hello_services.xml deleted file mode 100644 index 4fe7890ac5..0000000000 --- a/examples/hello_services/.idea/runConfigurations/hello_services.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - diff --git a/examples/hello_services/README.md b/examples/hello_services/README.md deleted file mode 100644 index 3bdd61856f..0000000000 --- a/examples/hello_services/README.md +++ /dev/null @@ -1,69 +0,0 @@ -# Example of embedding Flutter using FlutterView - -This project demonstrates how to embed Flutter within an iOS or Android -application. On iOS, the iOS and Flutter components are built with Xcode. On -Android, the Android and Flutter components are built with Android Studio or -gradle. - -You can read more about -[accessing platform and third-party services in Flutter](https://flutter.io/platform-services/). - -## iOS - -### Configure - -Create an `ios/Flutter/Generated.xcconfig` file with this entry: - - * `FLUTTER_ROOT=[absolute path to the Flutter SDK]` - -There are a number of other parameters you can control with this file: - - * `FLUTTER_APPLICATION_PATH`: The path to the directory that contains your - `pubspec.yaml` file relative to your `xcodeproj` file. - * `FLUTTER_BUILD_MODE`: Whether to build for `debug`, `profile`, or `release`. - Defaults to `release`. - * `FLUTTER_TARGET`: The path to your `main.dart` relative to your - `pubspec.yaml`. Defaults to `lib/main.dart`. - * `FLUTTER_FRAMEWORK_DIR`: The absolute path to the directory that contains - `Flutter.framework`. Defaults to the `ios-release` version of - `Flutter.framework` in the `bin/cache` directory of the Flutter SDK. - -### Build - -Once you've configured your project, you can open `ios/HelloServices.xcodeproj` -in Xcode and build the project as usual. - -## Android - -### Configure - -Create an `android/local.properties` file with these entries: - - * `sdk.dir=[path to the Android SDK]` - * `flutter.sdk=[path to the Flutter SDK]` - -There are a number of other parameters you can control with this file: - - * `flutter.buildMode`: Whether to build for `debug`, `profile`, or `release`. - Defaults to `release`. - * `flutter.jar`: The path to `flutter.jar`. Defaults to the - `android-arm-release` version of `flutter.jar` in the `bin/cache` directory - of the Flutter SDK. - -See `android/app/build.gradle` for project specific settings, including: - - * `source`: The path to the directory that contains your `pubspec.yaml` file - relative to your `build.gradle` file. - * `target`: The path to your `main.dart` relative to your `pubspec.yaml`. - Defaults to `lib/main.dart`. - -### Build - -To build directly with `gradle`, use the following commands: - - * `cd android` - * `gradle wrapper` - * `./gradlew build` - -To build with Android Studio, open the `android` folder in Android Studio and -build the project as usual. diff --git a/examples/hello_services/android/.gitignore b/examples/hello_services/android/.gitignore deleted file mode 100644 index 5c4ef82869..0000000000 --- a/examples/hello_services/android/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -*.iml -.gradle -/local.properties -/.idea/workspace.xml -/.idea/libraries -.DS_Store -/build -/captures - -/gradle -/gradlew -/gradlew.bat diff --git a/examples/hello_services/android/app/.gitignore b/examples/hello_services/android/app/.gitignore deleted file mode 100644 index 796b96d1c4..0000000000 --- a/examples/hello_services/android/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/examples/hello_services/android/app/build.gradle b/examples/hello_services/android/app/build.gradle deleted file mode 100644 index 4e2e46b56c..0000000000 --- a/examples/hello_services/android/app/build.gradle +++ /dev/null @@ -1,46 +0,0 @@ -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.2' - - lintOptions { - disable 'InvalidPackage' - } - - defaultConfig { - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - - 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' -} diff --git a/examples/hello_services/android/app/src/androidTest/java/com/example/flutter/ExampleInstrumentedTest.java b/examples/hello_services/android/app/src/androidTest/java/com/example/flutter/ExampleInstrumentedTest.java deleted file mode 100644 index 5b66006e9b..0000000000 --- a/examples/hello_services/android/app/src/androidTest/java/com/example/flutter/ExampleInstrumentedTest.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.example.flutter; - -import android.app.Instrumentation; -import android.graphics.Bitmap; -import android.support.test.InstrumentationRegistry; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.util.Arrays; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -import io.flutter.plugin.common.FlutterMethodChannel; -import io.flutter.view.FlutterView; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Rule - public ActivityTestRule activityRule = - new ActivityTestRule<>(ExampleActivity.class); - - @Test - public void testFlutterMessage() { - final Instrumentation instr = InstrumentationRegistry.getInstrumentation(); - - final int RANDOM_MIN = 1; - final int RANDOM_MAX = 1000; - - final CountDownLatch latch = new CountDownLatch(1); - final AtomicInteger random = new AtomicInteger(); - - instr.runOnMainSync(new Runnable() { - public void run() { - final FlutterView flutterView = (FlutterView) activityRule.getActivity().findViewById( - R.id.flutter_view); - final FlutterMethodChannel randomChannel = new FlutterMethodChannel(flutterView, "random"); - randomChannel.invokeMethod("getRandom", Arrays.asList(RANDOM_MIN, RANDOM_MAX), new FlutterMethodChannel.Response() { - @Override - public void success(Object o) { - random.set(((Number) o).intValue()); - latch.countDown(); - } - - @Override - public void error(String code, String message, Object details) { - - } - }); - } - }); - - try { - assertTrue(latch.await(2, TimeUnit.SECONDS)); - } catch (InterruptedException e) { - fail(e.getMessage()); - } - assertTrue(random.get() >= RANDOM_MIN); - assertTrue(random.get() < RANDOM_MAX); - } - - @Test - public void testBitmap() { - final Instrumentation instr = InstrumentationRegistry.getInstrumentation(); - final BitmapPoller poller = new BitmapPoller(5); - instr.runOnMainSync(new Runnable() { - public void run() { - final FlutterView flutterView = (FlutterView) activityRule.getActivity().findViewById( - R.id.flutter_view); - - // Call onPostResume to start the engine's renderer even if the activity - // is paused in the test environment. - flutterView.onPostResume(); - - poller.start(flutterView); - } - }); - - Bitmap bitmap = null; - try { - bitmap = poller.waitForBitmap(); - } catch (InterruptedException e) { - fail(e.getMessage()); - } - - assertNotNull(bitmap); - assertTrue(bitmap.getWidth() > 0); - assertTrue(bitmap.getHeight() > 0); - - // Check that a pixel matches the default Material background color. - assertTrue(bitmap.getPixel(bitmap.getWidth() - 1, bitmap.getHeight() - 1) == 0xFFFAFAFA); - } - - // Waits on a FlutterView until it is able to produce a bitmap. - private class BitmapPoller { - private final int delayMsec = 1000; - private int triesPending; - private int waitMsec; - private FlutterView flutterView; - private Bitmap bitmap; - private CountDownLatch latch = new CountDownLatch(1); - private Runnable checkBitmap = new Runnable() { - public void run() { - bitmap = flutterView.getBitmap(); - triesPending--; - if (bitmap != null || triesPending == 0) { - latch.countDown(); - } else { - flutterView.postDelayed(checkBitmap, delayMsec); - } - } - }; - - BitmapPoller(int tries) { - triesPending = tries; - waitMsec = delayMsec * tries + 100; - } - - void start(FlutterView flutterView) { - this.flutterView = flutterView; - flutterView.postDelayed(checkBitmap, delayMsec); - } - - Bitmap waitForBitmap() throws InterruptedException { - latch.await(waitMsec, TimeUnit.MILLISECONDS); - return bitmap; - } - } -} diff --git a/examples/hello_services/android/app/src/main/AndroidManifest.xml b/examples/hello_services/android/app/src/main/AndroidManifest.xml deleted file mode 100644 index 772377e0e8..0000000000 --- a/examples/hello_services/android/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/examples/hello_services/android/app/src/main/java/com/example/flutter/ExampleActivity.java b/examples/hello_services/android/app/src/main/java/com/example/flutter/ExampleActivity.java deleted file mode 100644 index e9518aa4b1..0000000000 --- a/examples/hello_services/android/app/src/main/java/com/example/flutter/ExampleActivity.java +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package com.example.flutter; - -import android.app.Activity; -import android.content.Context; -import android.content.pm.PackageManager; -import android.location.Location; -import android.location.LocationManager; -import android.os.Bundle; -import android.view.View; -import android.widget.Button; -import android.widget.TextView; - -import io.flutter.plugin.common.FlutterMethodChannel; -import io.flutter.plugin.common.MethodCall; -import io.flutter.view.FlutterMain; -import io.flutter.view.FlutterView; - -import java.util.Arrays; - -public class ExampleActivity extends Activity { - private static final String TAG = "ExampleActivity"; - - private FlutterView flutterView; - private FlutterMethodChannel randomChannel; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - FlutterMain.ensureInitializationComplete(getApplicationContext(), null); - setContentView(R.layout.hello_services_layout); - - flutterView = (FlutterView) findViewById(R.id.flutter_view); - flutterView.runFromBundle(FlutterMain.findAppBundlePath(getApplicationContext()), null); - - FlutterMethodChannel locationChannel = new FlutterMethodChannel(flutterView, "location"); - randomChannel = new FlutterMethodChannel(flutterView, "random"); - - locationChannel.setMethodCallHandler(new FlutterMethodChannel.MethodCallHandler() { - @Override - public void onMethodCall(MethodCall methodCall, FlutterMethodChannel.Response response) { - if (methodCall.method.equals("getLocation")) { - getLocation((String) methodCall.arguments, response); - } else { - response.error("unknown method", "Unknown method: " + methodCall.method, null); - } - } - }); - - Button getRandom = (Button) findViewById(R.id.get_random); - getRandom.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { getRandom(); } - }); - } - - @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(); - } - - private void getRandom() { - randomChannel.invokeMethod("getRandom", Arrays.asList(1, 1000), new FlutterMethodChannel.Response() { - TextView textView = (TextView) findViewById(R.id.random_value); - - @Override - public void success(Object result) { - textView.setText(result.toString()); - } - - @Override - public void error(String code, String message, Object details) { - textView.setText("Error: " + message); - } - }); - } - - private void getLocation(String provider, FlutterMethodChannel.Response response) { - String locationProvider; - if (provider.equals("network")) { - locationProvider = LocationManager.NETWORK_PROVIDER; - } else if (provider.equals("gps")) { - locationProvider = LocationManager.GPS_PROVIDER; - } else { - response.error("unknown provider", "Unknown location provider: " + provider, null); - return; - } - - String permission = "android.permission.ACCESS_FINE_LOCATION"; - if (checkCallingOrSelfPermission(permission) == PackageManager.PERMISSION_GRANTED) { - LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); - Location location = locationManager.getLastKnownLocation(locationProvider); - if (location != null) { - response.success(Arrays.asList(location.getLatitude(), location.getLongitude())); - } else { - response.error("location unavailable", "Location is not available", null); - } - } else { - response.error("access error", "Location permissions not granted", null); - } - } -} diff --git a/examples/hello_services/android/app/src/main/res/layout/hello_services_layout.xml b/examples/hello_services/android/app/src/main/res/layout/hello_services_layout.xml deleted file mode 100644 index da1a2eccd0..0000000000 --- a/examples/hello_services/android/app/src/main/res/layout/hello_services_layout.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - -