snapshot of https://github.com/flutter/samples.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Main Branch CI / Test Flutter beta on ubuntu-latest (push) Has been skipped
Main Branch CI / Test Flutter stable on ubuntu-latest (push) Has been skipped
Main Branch CI / Test Flutter beta on macos-latest (push) Has been cancelled
Main Branch CI / Test Flutter stable on macos-latest (push) Has been cancelled
14
add_to_app/books/android_books/.gitignore
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
/.idea/modules.xml
|
||||
/.idea/workspace.xml
|
||||
/.idea/navEditor.xml
|
||||
/.idea/assetWizardSettings.xml
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
14
add_to_app/books/android_books/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# android_books
|
||||
|
||||
An example Android application used in the Flutter add-to-app samples. For more
|
||||
information on how to use it, see the [README](../README.md) file located in the
|
||||
[/add_to_app](/add_to_app) directory of this repo.
|
||||
|
||||
## Getting Started
|
||||
|
||||
For more information about Flutter, check out
|
||||
[flutter.dev](https://flutter.dev).
|
||||
|
||||
For instructions on how to integrate Flutter modules into your existing
|
||||
applications, see Flutter's
|
||||
[add-to-app documentation](https://flutter.dev/docs/development/add-to-app).
|
||||
1
add_to_app/books/android_books/app/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
53
add_to_app/books/android_books/app/build.gradle
Normal file
@@ -0,0 +1,53 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
android {
|
||||
compileSdkVersion 31
|
||||
buildToolsVersion "29.0.3"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "dev.flutter.example.books"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
profile {
|
||||
initWith debug
|
||||
}
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
signingConfig debug.signingConfig
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation "com.squareup.okhttp3:okhttp:4.7.2"
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation 'androidx.core:core-ktx:1.3.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation "androidx.activity:activity-ktx:1.1.0"
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'com.google.android.material:material:1.1.0'
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
implementation project(path: ':flutter')
|
||||
testImplementation 'junit:junit:4.13'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
|
||||
}
|
||||
21
add_to_app/books/android_books/app/proguard-rules.pro
vendored
Normal file
@@ -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
|
||||
@@ -0,0 +1,27 @@
|
||||
package dev.flutter.example.books
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class MainActivityTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("dev.flutter.example.books", appContext.packageName)
|
||||
}
|
||||
|
||||
// The app should be hermetic (with offline books JSON) before adding
|
||||
// more tests.
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="dev.flutter.example.books">
|
||||
|
||||
<application
|
||||
android:name=".BookApplication"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".FlutterBookActivity"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize" />
|
||||
</application>
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,252 @@
|
||||
// Autogenerated from Pigeon (v1.0.1), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
|
||||
package dev.flutter.example.books;
|
||||
|
||||
import io.flutter.plugin.common.BasicMessageChannel;
|
||||
import io.flutter.plugin.common.BinaryMessenger;
|
||||
import io.flutter.plugin.common.MessageCodec;
|
||||
import io.flutter.plugin.common.StandardMessageCodec;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/** Generated class from Pigeon. */
|
||||
@SuppressWarnings(
|
||||
{"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"})
|
||||
public class Api {
|
||||
|
||||
/** Generated class from Pigeon that represents data sent in messages. */
|
||||
public static class Book {
|
||||
private String title;
|
||||
public String getTitle() { return title; }
|
||||
public void setTitle(String setterArg) { this.title = setterArg; }
|
||||
|
||||
private String subtitle;
|
||||
public String getSubtitle() { return subtitle; }
|
||||
public void setSubtitle(String setterArg) { this.subtitle = setterArg; }
|
||||
|
||||
private String author;
|
||||
public String getAuthor() { return author; }
|
||||
public void setAuthor(String setterArg) { this.author = setterArg; }
|
||||
|
||||
private String summary;
|
||||
public String getSummary() { return summary; }
|
||||
public void setSummary(String setterArg) { this.summary = setterArg; }
|
||||
|
||||
private String publishDate;
|
||||
public String getPublishDate() { return publishDate; }
|
||||
public void setPublishDate(String setterArg) {
|
||||
this.publishDate = setterArg;
|
||||
}
|
||||
|
||||
private Long pageCount;
|
||||
public Long getPageCount() { return pageCount; }
|
||||
public void setPageCount(Long setterArg) { this.pageCount = setterArg; }
|
||||
|
||||
private Thumbnail thumbnail;
|
||||
public Thumbnail getThumbnail() { return thumbnail; }
|
||||
public void setThumbnail(Thumbnail setterArg) {
|
||||
this.thumbnail = setterArg;
|
||||
}
|
||||
|
||||
Map<String, Object> toMap() {
|
||||
Map<String, Object> toMapResult = new HashMap<>();
|
||||
toMapResult.put("title", title);
|
||||
toMapResult.put("subtitle", subtitle);
|
||||
toMapResult.put("author", author);
|
||||
toMapResult.put("summary", summary);
|
||||
toMapResult.put("publishDate", publishDate);
|
||||
toMapResult.put("pageCount", pageCount);
|
||||
toMapResult.put("thumbnail",
|
||||
(thumbnail == null) ? null : thumbnail.toMap());
|
||||
return toMapResult;
|
||||
}
|
||||
static Book fromMap(Map<String, Object> map) {
|
||||
Book fromMapResult = new Book();
|
||||
Object title = map.get("title");
|
||||
fromMapResult.title = (String)title;
|
||||
Object subtitle = map.get("subtitle");
|
||||
fromMapResult.subtitle = (String)subtitle;
|
||||
Object author = map.get("author");
|
||||
fromMapResult.author = (String)author;
|
||||
Object summary = map.get("summary");
|
||||
fromMapResult.summary = (String)summary;
|
||||
Object publishDate = map.get("publishDate");
|
||||
fromMapResult.publishDate = (String)publishDate;
|
||||
Object pageCount = map.get("pageCount");
|
||||
fromMapResult.pageCount =
|
||||
(pageCount == null)
|
||||
? null
|
||||
: ((pageCount instanceof Integer) ? (Integer)pageCount
|
||||
: (Long)pageCount);
|
||||
Object thumbnail = map.get("thumbnail");
|
||||
fromMapResult.thumbnail = Thumbnail.fromMap((Map)thumbnail);
|
||||
return fromMapResult;
|
||||
}
|
||||
}
|
||||
|
||||
/** Generated class from Pigeon that represents data sent in messages. */
|
||||
public static class Thumbnail {
|
||||
private String url;
|
||||
public String getUrl() { return url; }
|
||||
public void setUrl(String setterArg) { this.url = setterArg; }
|
||||
|
||||
Map<String, Object> toMap() {
|
||||
Map<String, Object> toMapResult = new HashMap<>();
|
||||
toMapResult.put("url", url);
|
||||
return toMapResult;
|
||||
}
|
||||
static Thumbnail fromMap(Map<String, Object> map) {
|
||||
Thumbnail fromMapResult = new Thumbnail();
|
||||
Object url = map.get("url");
|
||||
fromMapResult.url = (String)url;
|
||||
return fromMapResult;
|
||||
}
|
||||
}
|
||||
private static class FlutterBookApiCodec extends StandardMessageCodec {
|
||||
public static final FlutterBookApiCodec INSTANCE =
|
||||
new FlutterBookApiCodec();
|
||||
private FlutterBookApiCodec() {}
|
||||
@Override
|
||||
protected Object readValueOfType(byte type, ByteBuffer buffer) {
|
||||
switch (type) {
|
||||
case (byte)128:
|
||||
return Book.fromMap((Map<String, Object>)readValue(buffer));
|
||||
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void writeValue(ByteArrayOutputStream stream, Object value) {
|
||||
if (value instanceof Book) {
|
||||
stream.write(128);
|
||||
writeValue(stream, ((Book)value).toMap());
|
||||
} else {
|
||||
super.writeValue(stream, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated class from Pigeon that represents Flutter messages that can be
|
||||
* called from Java.
|
||||
*/
|
||||
public static class FlutterBookApi {
|
||||
private final BinaryMessenger binaryMessenger;
|
||||
public FlutterBookApi(BinaryMessenger argBinaryMessenger) {
|
||||
this.binaryMessenger = argBinaryMessenger;
|
||||
}
|
||||
public interface Reply<T> {
|
||||
void reply(T reply);
|
||||
}
|
||||
static MessageCodec<Object> getCodec() {
|
||||
return FlutterBookApiCodec.INSTANCE;
|
||||
}
|
||||
|
||||
public void displayBookDetails(Book bookArg, Reply<Void> callback) {
|
||||
BasicMessageChannel<Object> channel = new BasicMessageChannel<>(
|
||||
binaryMessenger,
|
||||
"dev.flutter.pigeon.FlutterBookApi.displayBookDetails", getCodec());
|
||||
channel.send(new ArrayList<Object>(Arrays.asList(bookArg)),
|
||||
channelReply -> { callback.reply(null); });
|
||||
}
|
||||
}
|
||||
private static class HostBookApiCodec extends StandardMessageCodec {
|
||||
public static final HostBookApiCodec INSTANCE = new HostBookApiCodec();
|
||||
private HostBookApiCodec() {}
|
||||
@Override
|
||||
protected Object readValueOfType(byte type, ByteBuffer buffer) {
|
||||
switch (type) {
|
||||
case (byte)128:
|
||||
return Book.fromMap((Map<String, Object>)readValue(buffer));
|
||||
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void writeValue(ByteArrayOutputStream stream, Object value) {
|
||||
if (value instanceof Book) {
|
||||
stream.write(128);
|
||||
writeValue(stream, ((Book)value).toMap());
|
||||
} else {
|
||||
super.writeValue(stream, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated interface from Pigeon that represents a handler of messages from
|
||||
* Flutter.
|
||||
*/
|
||||
public interface HostBookApi {
|
||||
void cancel();
|
||||
void finishEditingBook(Book book);
|
||||
|
||||
/** The codec used by HostBookApi. */
|
||||
static MessageCodec<Object> getCodec() { return HostBookApiCodec.INSTANCE; }
|
||||
|
||||
/**
|
||||
* Sets up an instance of `HostBookApi` to handle messages through the
|
||||
* `binaryMessenger`.
|
||||
*/
|
||||
static void setup(BinaryMessenger binaryMessenger, HostBookApi api) {
|
||||
{
|
||||
BasicMessageChannel<Object> channel = new BasicMessageChannel<>(
|
||||
binaryMessenger, "dev.flutter.pigeon.HostBookApi.cancel",
|
||||
getCodec());
|
||||
if (api != null) {
|
||||
channel.setMessageHandler((message, reply) -> {
|
||||
Map<String, Object> wrapped = new HashMap<>();
|
||||
try {
|
||||
api.cancel();
|
||||
wrapped.put("result", null);
|
||||
} catch (Error | RuntimeException exception) {
|
||||
wrapped.put("error", wrapError(exception));
|
||||
}
|
||||
reply.reply(wrapped);
|
||||
});
|
||||
} else {
|
||||
channel.setMessageHandler(null);
|
||||
}
|
||||
}
|
||||
{
|
||||
BasicMessageChannel<Object> channel = new BasicMessageChannel<>(
|
||||
binaryMessenger, "dev.flutter.pigeon.HostBookApi.finishEditingBook",
|
||||
getCodec());
|
||||
if (api != null) {
|
||||
channel.setMessageHandler((message, reply) -> {
|
||||
Map<String, Object> wrapped = new HashMap<>();
|
||||
try {
|
||||
ArrayList<Object> args = (ArrayList<Object>)message;
|
||||
Book bookArg = (Book)args.get(0);
|
||||
if (bookArg == null) {
|
||||
throw new NullPointerException("bookArg unexpectedly null.");
|
||||
}
|
||||
api.finishEditingBook(bookArg);
|
||||
wrapped.put("result", null);
|
||||
} catch (Error | RuntimeException exception) {
|
||||
wrapped.put("error", wrapError(exception));
|
||||
}
|
||||
reply.reply(wrapped);
|
||||
});
|
||||
} else {
|
||||
channel.setMessageHandler(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private static Map<String, Object> wrapError(Throwable exception) {
|
||||
Map<String, Object> errorMap = new HashMap<>();
|
||||
errorMap.put("message", exception.toString());
|
||||
errorMap.put("code", exception.getClass().getSimpleName());
|
||||
errorMap.put("details", null);
|
||||
return errorMap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright 2020 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package dev.flutter.example.books
|
||||
|
||||
import android.app.Application
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.embedding.engine.FlutterEngineCache
|
||||
import io.flutter.embedding.engine.dart.DartExecutor
|
||||
|
||||
class BookApplication: Application() {
|
||||
companion object {
|
||||
const val ENGINE_ID = "book_engine"
|
||||
}
|
||||
|
||||
private lateinit var flutterEngine: FlutterEngine
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
// This application reuses a single FlutterEngine instance throughout.
|
||||
// Create the FlutterEngine on application start.
|
||||
flutterEngine = FlutterEngine(this).apply{
|
||||
dartExecutor.executeDartEntrypoint(DartExecutor.DartEntrypoint.createDefault())
|
||||
}
|
||||
FlutterEngineCache.getInstance().put(ENGINE_ID, flutterEngine)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
// Copyright 2020 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package dev.flutter.example.books
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import dev.flutter.example.books.BookApplication.Companion.ENGINE_ID
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import java.util.HashMap
|
||||
|
||||
/**
|
||||
* This {@link FlutterActivity} class repackages Kotlin-Dart interop using the Pigeon IPC mechanism.
|
||||
* It repackages Flutter/Dart-side functionalities in standard Android API style, passing
|
||||
* arguments in and out of the activity using 'startActivityForResult' intents and
|
||||
* 'onActivityResult' intents.
|
||||
*/
|
||||
class FlutterBookActivity: FlutterActivity() {
|
||||
companion object {
|
||||
const val EXTRA_BOOK = "book"
|
||||
|
||||
/**
|
||||
* Static intent factory to start {@link FlutterBookActivity} with the singleton
|
||||
* {@link FlutterEngine} the application started.
|
||||
*
|
||||
* The activity launched from this intent shows the details of the {@link Api.Book}
|
||||
* supplied.
|
||||
*/
|
||||
fun withBook(context: Context, book: Api.Book): Intent {
|
||||
// In a more realistic app, there should be some dependency injection mechanism to
|
||||
// determine which engine to use.
|
||||
return CachedEngineBookIntentBuilder(ENGINE_ID)
|
||||
.build(context)
|
||||
.putExtra(
|
||||
// The Pigeon data class is useful not only between Kotlin/Java and Dart
|
||||
// but also within Kotlin/Java where activities must communicate with
|
||||
// each other via serializable data. The Pigeon data class is a
|
||||
// serializable class by definition.
|
||||
EXTRA_BOOK,
|
||||
// TODO(gaaclarke): the Pigeon generated data class should just implement
|
||||
// Serializable so we won't need 'toMap()' here
|
||||
// https://github.com/flutter/flutter/issues/58909
|
||||
HashMap(book.toMap())
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A static helper method to parse a result intent from this activity into a {@link Book}.
|
||||
*
|
||||
* @param resultIntent an {@link Intent} that must be the data intent returned by this
|
||||
* activity's {@code onActivityResult}.
|
||||
*/
|
||||
fun getBookFromResultIntent(resultIntent: Intent): Api.Book {
|
||||
return Api.Book.fromMap((resultIntent.getSerializableExtra(FlutterBookActivity.EXTRA_BOOK) as HashMap<String, Any>));
|
||||
}
|
||||
}
|
||||
|
||||
// Intent builder class to build a FlutterBookActivity instance instead of the default FlutterActivity.
|
||||
class CachedEngineBookIntentBuilder(engineId: String): CachedEngineIntentBuilder(FlutterBookActivity::class.java, engineId) { }
|
||||
|
||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||
// Called shortly after the activity is created, when the activity is bound to a
|
||||
// FlutterEngine responsible for rendering the Flutter activity's content.
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
|
||||
// The book to give to Flutter is passed in from the MainActivity via this activity's
|
||||
// source intent getter. The intent contains the book serialized as on extra.
|
||||
val bookToShow = Api.Book.fromMap(intent.getSerializableExtra(EXTRA_BOOK) as HashMap<String, Any>)
|
||||
|
||||
// Register the HostBookApiHandler callback class to get results from Flutter.
|
||||
Api.HostBookApi.setup(flutterEngine.dartExecutor, HostBookApiHandler())
|
||||
|
||||
// Send in the book instance to Flutter.
|
||||
Api.FlutterBookApi(flutterEngine.dartExecutor).displayBookDetails(bookToShow) {
|
||||
// We don't care about the callback
|
||||
}
|
||||
}
|
||||
|
||||
// This {@link Api.HostBookApi} subclass will be called by Pigeon when the corresponding
|
||||
// APIs are invoked on the Dart side.
|
||||
inner class HostBookApiHandler: Api.HostBookApi {
|
||||
override fun cancel() {
|
||||
// Flutter called cancel. Finish the activity with a cancel result.
|
||||
setResult(Activity.RESULT_CANCELED)
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun finishEditingBook(book: Api.Book?) {
|
||||
if (book == null) {
|
||||
throw IllegalArgumentException("finishedEditingBook cannot be called with a null argument")
|
||||
}
|
||||
// Flutter returned an edited book instance. Return it to the MainActivity via the
|
||||
// standard Android Activity set result mechanism.
|
||||
setResult(Activity.RESULT_OK, Intent().putExtra(EXTRA_BOOK, HashMap(book.toMap())))
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
// Copyright 2020 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package dev.flutter.example.books
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.TextView
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.JsonParser
|
||||
import okhttp3.Call
|
||||
import okhttp3.Callback
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import java.io.IOException
|
||||
import java.lang.Exception
|
||||
import java.lang.RuntimeException
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
companion object {
|
||||
const val BOOKS_QUERY = "https://www.googleapis.com/books/v1/volumes?q=greenwood+tulsa&maxResults=15"
|
||||
}
|
||||
|
||||
private lateinit var books: MutableList<Api.Book>
|
||||
private lateinit var list: LinearLayout
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
list = findViewById<LinearLayout>(R.id.list)
|
||||
|
||||
// OkHttp is arbitrarily chosen here to represent an existing middleware constraint that's
|
||||
// already present in an existing application's infrastructure.
|
||||
val httpClient = OkHttpClient()
|
||||
val bookRequest = Request.Builder()
|
||||
// Retrieve data from Google Books API (arbitrarily chosen). This represents existing
|
||||
// data sources that an existing application is already interfacing with.
|
||||
.url(BOOKS_QUERY)
|
||||
.build()
|
||||
|
||||
httpClient.newCall(bookRequest).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
throw e
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
response.use {
|
||||
if (!response.isSuccessful) throw IOException("Unexpected code $response")
|
||||
books = parseGoogleBooksJsonToBooks(response.body!!.string())
|
||||
|
||||
val spinner = findViewById<ProgressBar>(R.id.spinner)
|
||||
|
||||
runOnUiThread {
|
||||
// Showed a spinner while network call is in progress. Remove it when
|
||||
// response is received.
|
||||
spinner.visibility = View.GONE
|
||||
populateBookCards()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Take a top level Google Books query's response JSON and create a list of Book Pigeon data
|
||||
// classes that will be used both as a model here on the Kotlin side and also in the IPCs
|
||||
// to Dart.
|
||||
private fun parseGoogleBooksJsonToBooks(jsonBody: String): MutableList<Api.Book> {
|
||||
// Here we're arbitrarily using GSON to represent another existing middleware constraint
|
||||
// that already exists in your existing application's infrastructure.
|
||||
val jsonBooks = JsonParser.parseString(jsonBody).asJsonObject.getAsJsonArray("items")
|
||||
val books = mutableListOf<Api.Book>()
|
||||
for (jsonBook in jsonBooks.map { it.asJsonObject }) {
|
||||
try {
|
||||
// Here we're using GSON to populate a Pigeon data class directly. The Pigeon data
|
||||
// class can be used not just as part of your IPC API's signature but also as a
|
||||
// normal data class in your existing application.
|
||||
//
|
||||
// We could either push the Pigeon data class usage higher into the existing GSON
|
||||
// "middleware" or lower, closer to the IPC.
|
||||
val book = Api.Book()
|
||||
val volumeInfoJson = jsonBook.getAsJsonObject("volumeInfo")
|
||||
book.title = volumeInfoJson.get("title").asString
|
||||
book.subtitle = volumeInfoJson.get("subtitle")?.asString
|
||||
// Sorry co-authors, we're trying to keep this simple.
|
||||
book.author = volumeInfoJson.getAsJsonArray("authors")[0].asString
|
||||
book.summary = volumeInfoJson.get("description").asString
|
||||
book.publishDate = volumeInfoJson.get("publishedDate").asString
|
||||
book.pageCount = volumeInfoJson.get("pageCount").asLong
|
||||
val thumbnail = Api.Thumbnail()
|
||||
thumbnail.url = volumeInfoJson.getAsJsonObject("imageLinks").get("thumbnail").asString
|
||||
book.thumbnail = thumbnail
|
||||
books.add(book)
|
||||
} catch (e: Exception) {
|
||||
println("Failed to parse book:")
|
||||
println(GsonBuilder().setPrettyPrinting().create().toJson(jsonBook))
|
||||
println("Parsing error:")
|
||||
println(e)
|
||||
}
|
||||
}
|
||||
return books
|
||||
}
|
||||
|
||||
// Given a populated books list, create a Material Design card in a scroll view for each book.
|
||||
private fun populateBookCards() {
|
||||
for ((index, book) in books.withIndex()) {
|
||||
val card = layoutInflater.inflate(R.layout.book_card, null)
|
||||
updateCardWithBook(card, book)
|
||||
card.findViewById<MaterialButton>(R.id.edit).setOnClickListener {
|
||||
// When the edit button is clicked in a book's card, launch a Flutter activity
|
||||
// showing the details of the book.
|
||||
startActivityForResult(
|
||||
// We're using our own 'FlutterActivity' subclass which wraps Pigeon API usages
|
||||
// into an idiomatic Android activity interface with intent extras as input and
|
||||
// with activity 'setResult' as output.
|
||||
//
|
||||
// This lets activity-level feature developers abstract their Flutter usage
|
||||
// and present a standard Android API to their upstream application developers.
|
||||
//
|
||||
// No Flutter-specific concepts are leaked outside the Flutter activity itself
|
||||
// into the consuming class.
|
||||
FlutterBookActivity
|
||||
// Re-read from the 'books' list rather than just capturing the iterated
|
||||
// 'book' instance since we change it when Dart updates it in onActivityResult.
|
||||
.withBook(this, books[index]),
|
||||
// The index lets us know which book we're returning the result for when we
|
||||
// return from the Flutter activity.
|
||||
index)
|
||||
}
|
||||
list.addView(card)
|
||||
}
|
||||
}
|
||||
|
||||
// Given a Material Design card and a book, update the card content to reflect the book model.
|
||||
private fun updateCardWithBook(card: View, book: Api.Book) {
|
||||
card.findViewById<TextView>(R.id.title).text = book.title
|
||||
card.findViewById<TextView>(R.id.subtitle).text = book.subtitle
|
||||
card.findViewById<TextView>(R.id.author).text = resources.getString(R.string.author_prefix, book.author)
|
||||
}
|
||||
|
||||
// Callback when the Flutter activity started with 'startActivityForResult' above returns.
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
|
||||
// The Flutter activity may cancel the edit. If so, don't update anything.
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (data == null) {
|
||||
throw RuntimeException("The FlutterBookActivity returning RESULT_OK should always have a return data intent")
|
||||
}
|
||||
|
||||
// If the book was edited in Flutter, the Flutter activity finishes and returns an
|
||||
// activity result in an intent (the 'data' argument). The intent has an extra which is
|
||||
// the edited book in serialized form.
|
||||
val returnedBook = FlutterBookActivity.getBookFromResultIntent(data)
|
||||
// Update our book model list.
|
||||
books[requestCode] = returnedBook
|
||||
|
||||
// Refresh the UI here on the Kotlin side.
|
||||
updateCardWithBook(list.getChildAt(requestCode), returnedBook)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="85.84757"
|
||||
android:endY="92.4963"
|
||||
android:startX="42.9492"
|
||||
android:startY="49.59793"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
||||
@@ -0,0 +1,170 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#3DDC84"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
</vector>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appbar"
|
||||
app:liftOnScroll="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:id="@+id/nestedScrollView"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/list"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:context=".MainActivity" />
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/spinner"
|
||||
style="?android:attr/progressBarStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true"
|
||||
app:layout_anchor="@+id/nestedScrollView"
|
||||
app:layout_anchorGravity="center" />
|
||||
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="21dp"
|
||||
android:layout_marginStart="21dp"
|
||||
android:layout_marginEnd="21dp"
|
||||
android:layout_marginBottom="2dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?attr/textAppearanceHeadline5"
|
||||
tools:text="Title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/subtitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:textAppearance="?attr/textAppearanceSubtitle1"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
tools:text="subtitle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/author"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:textAppearance="?attr/textAppearanceBody1"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
tools:text="Author" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
android:orientation="horizontal"
|
||||
android:layout_gravity="end">
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/edit"
|
||||
style="?attr/borderlessButtonStyle"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 7.3 KiB |
|
After Width: | Height: | Size: 7.7 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 16 KiB |
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#6200EE</color>
|
||||
<color name="colorPrimaryDark">#3700B3</color>
|
||||
<color name="colorAccent">#03DAC5</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,5 @@
|
||||
<resources>
|
||||
<string name="app_name">Books</string>
|
||||
<string name="edit">Edit</string>
|
||||
<string name="author_prefix">By: %1$s</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,10 @@
|
||||
<resources>
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
26
add_to_app/books/android_books/build.gradle
Normal file
@@ -0,0 +1,26 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
ext.kotlin_version = "1.6.0"
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "com.android.tools.build:gradle:7.4.2"
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
21
add_to_app/books/android_books/gradle.properties
Normal file
@@ -0,0 +1,21 @@
|
||||
# Project-wide Gradle settings.
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx2048m
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
# AndroidX package structure to make it clearer which packages are bundled with the
|
||||
# Android operating system, and which are packaged with your app"s APK
|
||||
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
||||
android.useAndroidX=true
|
||||
# Automatically convert third-party libraries to use AndroidX
|
||||
android.enableJetifier=true
|
||||
# Kotlin code style for this project: "official" or "obsolete":
|
||||
kotlin.code.style=official
|
||||
5
add_to_app/books/android_books/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
234
add_to_app/books/android_books/gradlew
vendored
Executable file
@@ -0,0 +1,234 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
89
add_to_app/books/android_books/gradlew.bat
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
7
add_to_app/books/android_books/settings.gradle
Normal file
@@ -0,0 +1,7 @@
|
||||
include ':app'
|
||||
setBinding(new Binding([gradle: this]))
|
||||
evaluate(new File(
|
||||
settingsDir,
|
||||
'../flutter_module_books/.android/include_flutter.groovy'
|
||||
))
|
||||
rootProject.name = "android_books"
|
||||