Skip to content

Commit

Permalink
Add is_supported function & change gradle deps to implementation (#32)
Browse files Browse the repository at this point in the history
* Change gradle deps from compile to implementation

* Try adding proguard setting to prevent crashes on old phones

* add is_supported function

* Delete extension-gpgs.pro
  • Loading branch information
SkaterDad committed Dec 8, 2020
1 parent 323402c commit c7b3a40
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 3 deletions.
19 changes: 19 additions & 0 deletions gpgs/api/gpgs.script_api
Expand Up @@ -4,6 +4,25 @@

members:

#*****************************************************************************************************

- name: is_supported
type: function
desc: Check if Google Play Services are available & ready on the device.

returns:
- name: is_supported
type: boolean
desc: Status of Google Play Services on the device.

examples:
- desc: |-
```lua
if gpgs then
local is_supported = gpgs.is_supported()
end
```

#*****************************************************************************************************

- name: login
Expand Down
6 changes: 3 additions & 3 deletions gpgs/manifests/android/build.gradle
@@ -1,6 +1,6 @@
dependencies {
// https://developers.google.com/android/guides/setup#split
compile 'com.google.android.gms:play-services-base:17.5.0'
compile 'com.google.android.gms:play-services-auth:18.1.0'
compile 'com.google.android.gms:play-services-games:20.0.1'
implementation 'com.google.android.gms:play-services-base:17.5.0'
implementation 'com.google.android.gms:play-services-auth:18.1.0'
implementation 'com.google.android.gms:play-services-games:20.0.1'
}
11 changes: 11 additions & 0 deletions gpgs/src/gpgs_extension.cpp
Expand Up @@ -28,6 +28,7 @@ struct GPGS
jmethodID m_getServerAuthCode;
jmethodID m_isLoggedIn;
jmethodID m_setGravityForPopups;
jmethodID m_isSupported;
};

struct GPGS_Disk
Expand Down Expand Up @@ -317,6 +318,11 @@ static int GpgsAuth_isLoggedIn(lua_State* L)
return CallBooleanMethod(L, g_gpgs.m_GpgsJNI, g_gpgs.m_isLoggedIn);
}

static int GpgsAuth_isSupported(lua_State* L)
{
return CallBooleanMethod(L, g_gpgs.m_GpgsJNI, g_gpgs.m_isSupported);
}

//******************************************************************************
// GPGPS misc
//******************************************************************************
Expand Down Expand Up @@ -745,6 +751,8 @@ JNIEXPORT void JNICALL Java_com_defold_gpgs_GpgsJNI_gpgsAddToQueue(JNIEnv * env,

static const luaL_reg Gpgs_methods[] =
{
//general
{"is_supported", GpgsAuth_isSupported},
//authorization
{"login", GpgsAuth_Login},
{"logout", GpgsAuth_Logout},
Expand Down Expand Up @@ -860,6 +868,9 @@ static void LuaInit(lua_State* L)

static void InitJNIMethods(JNIEnv* env, jclass cls)
{
//general
g_gpgs.m_isSupported = env->GetMethodID(cls, "isSupported", "()Z");

//authorization
g_gpgs.m_silentLogin = env->GetMethodID(cls, "silentLogin", "()V");
g_gpgs.m_login = env->GetMethodID(cls, "login", "()V");
Expand Down
9 changes: 9 additions & 0 deletions gpgs/src/java/com/defold/gpgs/GpgsJNI.java
Expand Up @@ -14,6 +14,8 @@
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.games.Games;
import com.google.android.gms.games.GamesClient;
import com.google.android.gms.games.Player;
Expand Down Expand Up @@ -98,6 +100,7 @@ public class GpgsJNI {
private String client_id;
private boolean is_request_id_token;
private boolean is_request_auth_code;
private boolean is_supported;

//--------------------------------------------------
// Authorization
Expand Down Expand Up @@ -176,6 +179,8 @@ public GpgsJNI(Activity activity, boolean is_disk_active, boolean is_request_aut
this.is_request_auth_code = is_request_auth_code;
this.is_request_id_token = is_request_id_token;

this.is_supported = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(activity) == ConnectionResult.SUCCESS;

mGoogleSignInClient = GoogleSignIn.getClient(activity, getSignInOptions());
}

Expand Down Expand Up @@ -327,6 +332,10 @@ public void setGravityForPopups(int gravity) {
mGravity = gravity;
}

public boolean isSupported() {
return is_supported;
}

//--------------------------------------------------
// GoogleDrive (Snapshots)

Expand Down
62 changes: 62 additions & 0 deletions main/menu.gui
Expand Up @@ -1141,6 +1141,68 @@ nodes {
text_leading: 1.0
text_tracking: 0.0
}
nodes {
position {
x: 977.0
y: 543.094
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 300.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: "Support Status"
font: "larryfont"
id: "support_status"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
shadow {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: true
layer: ""
inherit_alpha: true
alpha: 1.0
outline_alpha: 1.0
shadow_alpha: 1.0
template_node_child: false
text_leading: 1.0
text_tracking: 0.0
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT
max_nodes: 512
6 changes: 6 additions & 0 deletions main/menu.gui_script
Expand Up @@ -17,6 +17,12 @@ local popup_positions = {
function init(self)
msg.post(".", "acquire_input_focus")
self.popup_pos = 3

if gpgs and gpgs.is_supported() then
gui.set_text(gui.get_node("support_status"), "Is Supported")
else
gui.set_text(gui.get_node("support_status"), "Not Supported")
end
end


Expand Down

0 comments on commit c7b3a40

Please sign in to comment.