Skip to content

Commit c3c7e6b

Browse files
author
Pascal Schwenke
committed
initial commit
0 parents  commit c3c7e6b

File tree

19 files changed

+328
-0
lines changed

19 files changed

+328
-0
lines changed

.gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
.idea/
16+
gradle/wrapper/gradle-wrapper.jar
17+
gradle/wrapper/gradle-wrapper.properties
18+
gradlew.bat
19+
gradlew
20+
godot-lib.3.2.3.stable.release/build/

GodotReviewPlugin/.gitignore

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

GodotReviewPlugin/build.gradle

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 29
5+
buildToolsVersion "30.0.0"
6+
7+
defaultConfig {
8+
minSdkVersion 21
9+
targetSdkVersion 29
10+
versionCode 1
11+
versionName "1.0"
12+
13+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14+
consumerProguardFiles "consumer-rules.pro"
15+
}
16+
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
compileOptions {
24+
sourceCompatibility JavaVersion.VERSION_1_8
25+
targetCompatibility JavaVersion.VERSION_1_8
26+
}
27+
}
28+
29+
dependencies {
30+
implementation fileTree(dir: "libs", include: ["*.jar"])
31+
implementation 'androidx.appcompat:appcompat:1.2.0'
32+
testImplementation 'junit:junit:4.12'
33+
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
34+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
35+
implementation 'com.google.android.play:core:1.8.0'
36+
compileOnly project(":godot-lib.3.2.3.stable.release")
37+
}

GodotReviewPlugin/consumer-rules.pro

Whitespace-only changes.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[config]
2+
3+
name="ReviewPlugin"
4+
binary_type="local"
5+
binary="ReviewPlugin.debug.aar"
6+
7+
[dependencies]
8+
remote=["com.google.android.play:core:1.8.0"]

GodotReviewPlugin/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package magicnut.android.godotreviewplugin;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("magicnut.android.godotreviewplugin.test", appContext.getPackageName());
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="magicnut.android.godotreviewplugin">
3+
4+
<application>
5+
<meta-data
6+
android:name="org.godotengine.plugin.v1.ReviewPlugin"
7+
android:value="magicnut.android.godotreviewplugin.ReviewPlugin" />
8+
</application>
9+
/
10+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package magicnut.android.godotreviewplugin;
2+
3+
import android.app.Activity;
4+
import android.util.Log;
5+
6+
import com.google.android.play.core.review.ReviewInfo;
7+
import com.google.android.play.core.review.ReviewManager;
8+
import com.google.android.play.core.review.ReviewManagerFactory;
9+
import com.google.android.play.core.tasks.Task;
10+
11+
import org.godotengine.godot.Godot;
12+
import org.godotengine.godot.plugin.GodotPlugin;
13+
import org.godotengine.godot.plugin.SignalInfo;
14+
15+
import java.util.Arrays;
16+
import java.util.List;
17+
import java.util.Set;
18+
19+
import androidx.annotation.NonNull;
20+
import androidx.collection.ArraySet;
21+
22+
public class ReviewPlugin extends GodotPlugin {
23+
public static final String PLUGIN_NAME = "ReviewPlugin";
24+
Activity activity;
25+
26+
/**
27+
* Constructor calling super and setting the activity.
28+
*
29+
* @param godot The godot app that instantiates the plugin.
30+
*/
31+
public ReviewPlugin(Godot godot) {
32+
super(godot);
33+
activity = godot;
34+
}
35+
36+
@NonNull
37+
@Override
38+
public String getPluginName() {
39+
return PLUGIN_NAME;
40+
}
41+
42+
/**
43+
* Return all the method names as list that can be called from godot side.
44+
*
45+
* @return
46+
*/
47+
@NonNull
48+
@Override
49+
public List<String> getPluginMethods() {
50+
return Arrays.asList("startInAppReview");
51+
}
52+
53+
/**
54+
* A set of all signals the plugin can emit.
55+
*
56+
* @return
57+
*/
58+
@NonNull
59+
@Override
60+
public Set<SignalInfo> getPluginSignals() {
61+
Set<SignalInfo> signals = new ArraySet<>();
62+
63+
signals.add(new SignalInfo("review_flow_finished"));
64+
signals.add(new SignalInfo("review_flow_started"));
65+
signals.add(new SignalInfo("review_info_request_unsuccessful"));
66+
67+
return signals;
68+
}
69+
70+
public void startInAppReview() {
71+
activity.runOnUiThread(() -> {
72+
ReviewManager manager = ReviewManagerFactory.create(activity);
73+
Task<ReviewInfo> request = manager.requestReviewFlow();
74+
request.addOnCompleteListener(requestTask -> {
75+
if (requestTask.isSuccessful()) {
76+
Log.d(PLUGIN_NAME, "The review flow has started.");
77+
emitSignal("review_flow_started");
78+
// We can get the ReviewInfo object
79+
ReviewInfo reviewInfo = requestTask.getResult();
80+
Task<Void> flow = manager.launchReviewFlow(activity, reviewInfo);
81+
flow.addOnCompleteListener(task -> {
82+
// The flow has finished. The API does not indicate whether the user
83+
// reviewed or not, or even whether the review dialog was shown. Thus, no
84+
// matter the result, we continue our app flow.
85+
Log.d(PLUGIN_NAME, "The review flow has finished.");
86+
emitSignal("review_flow_finished");
87+
});
88+
} else {
89+
// There was some problem, continue regardless of the result.
90+
Log.d(PLUGIN_NAME, "There was some problem, continue regardless of the result.");
91+
emitSignal("review_info_request_unsuccessful");
92+
}
93+
});
94+
});
95+
}
96+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package magicnut.android.godotreviewplugin;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.*;
6+
7+
/**
8+
* Example local unit test, which will execute on the development machine (host).
9+
*
10+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
11+
*/
12+
public class ExampleUnitTest {
13+
@Test
14+
public void addition_isCorrect() {
15+
assertEquals(4, 2 + 2);
16+
}
17+
}

README.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
Support my work:
3+
**Follow me on [Twitter](https://twitter.com/pascalschwenke) and add me on [LinkedIn](https://www.linkedin.com/in/pascal-schwenke-537a8a169/)!**
4+
5+
6+
# In-App Review plugin for Godot 3.2.3
7+
8+
This plugin implements the [Google Play In-App Review API](https://developer.android.com/guide/playcore/in-app-review/) for [Godot 3.2.3](https://godotengine.org/).
9+
10+
See the plugin in action:\
11+
[![Demo video](https://github.com/pschw/GodotConsentPlugin/blob/master/thumbnail_mini.jpg?raw=true)](https://youtu.be/PJ2H8ZK8O_w "Demo video")
12+
13+
## Adding the plugin to Godot 3.2.3
14+
1. Follow the [official documentation](https://docs.godotengine.org/en/latest/getting_started/workflow/export/android_custom_build.html) to configure, install and enable an Android Custom Build.
15+
2. Download the In-App Review plugin from the release tab.
16+
3. Extract the contents of InAppReviewPlugin.7z to `res://android/plugins`
17+
4. Call the plugin from a godot script (see chapter below).
18+
5. When exporting your game via a preset in `Project>Export...` make sure that `Use Custom Build` and `Review Plugin` is checked.
19+
20+
## Using the plugin in a godot script
21+
Check if the singleton instance of `ReviewPlugin` is available. Then connect the signals of the plugin.
22+
```javascript
23+
func check_consent():
24+
if Engine.has_singleton("ReviewPlugin"):
25+
review = Engine.get_singleton("ReviewPlugin")
26+
# connect signals
27+
review.connect("consent_info_updated",self,"consent_info_updated")
28+
review.connect("failed_to_update_consent_information",self,"failed_to_update_consent_information")
29+
review.connect("consent_form_loaded",self,"consent_form_loaded")
30+
review.start()
31+
```
32+
33+
### Remarks
34+
Make sure to read through the official documentation of [Google Play In-App Review API](https://developer.android.com/guide/playcore/in-app-review/) to learn about quotas or what to expect of the API in general, specifically how it can be tested.
35+
The Plugin is very simple but can be debugged by using the Android Debug Bridge and the tag filter `ReviewPlugin`.
36+
Required min SDK?

build.gradle

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
buildscript {
3+
repositories {
4+
google()
5+
jcenter()
6+
}
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:4.0.1'
9+
10+
// NOTE: Do not place your application dependencies here; they belong
11+
// in the individual module build.gradle files
12+
}
13+
}
14+
15+
allprojects {
16+
repositories {
17+
google()
18+
jcenter()
19+
}
20+
}
21+
22+
task clean(type: Delete) {
23+
delete rootProject.buildDir
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
configurations.maybeCreate("default")
2+
artifacts.add("default", file('godot-lib.3.2.3.stable.release.aar'))
Binary file not shown.

gradle.properties

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Project-wide Gradle settings.
2+
# IDE (e.g. Android Studio) users:
3+
# Gradle settings configured through the IDE *will override*
4+
# any settings specified in this file.
5+
# For more details on how to configure your build environment visit
6+
# http://www.gradle.org/docs/current/userguide/build_environment.html
7+
# Specifies the JVM arguments used for the daemon process.
8+
# The setting is particularly useful for tweaking memory settings.
9+
org.gradle.jvmargs=-Xmx2048m
10+
# When configured, Gradle will run in incubating parallel mode.
11+
# This option should only be used with decoupled projects. More details, visit
12+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13+
# org.gradle.parallel=true
14+
# AndroidX package structure to make it clearer which packages are bundled with the
15+
# Android operating system, and which are packaged with your app"s APK
16+
# https://developer.android.com/topic/libraries/support-library/androidx-rn
17+
android.useAndroidX=true
18+
# Automatically convert third-party libraries to use AndroidX
19+
android.enableJetifier=true

plugin/ReviewPlugin.gdap

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[config]
2+
3+
name="ReviewPlugin"
4+
binary_type="local"
5+
binary="ReviewPlugin.release.aar"
6+
7+
[dependencies]
8+
remote=["com.google.android.play:core:1.8.0"]

settings.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include ':godot-lib.3.2.3.stable.release'
2+
include ':GodotReviewPlugin'
3+
rootProject.name = "GodotInAppReviewPlugin"

thumbnail_mini.png

45.8 KB
Loading

0 commit comments

Comments
 (0)