2016-01-07 11:21:22 -05:00
|
|
|
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
|
2014-03-14 14:13:41 -04:00
|
|
|
//This file needs to be here so the "ant" build step doesnt fail when looking for a /src folder.
|
|
|
|
|
|
|
|
|
|
package com.epicgames.ue4;
|
|
|
|
|
|
2014-09-09 12:20:07 -04:00
|
|
|
import java.io.File;
|
|
|
|
|
|
2014-04-23 20:22:19 -04:00
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.HashMap;
|
2014-07-22 18:03:47 -04:00
|
|
|
import java.util.ArrayList;
|
2014-04-23 20:22:19 -04:00
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
import android.app.NativeActivity;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
2014-09-16 17:32:10 -04:00
|
|
|
import android.os.Vibrator;
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
import android.app.AlertDialog;
|
2014-04-23 19:40:10 -04:00
|
|
|
import android.app.Dialog;
|
2014-03-14 14:13:41 -04:00
|
|
|
import android.widget.EditText;
|
2014-07-22 18:03:47 -04:00
|
|
|
import android.text.InputType;
|
2014-09-12 11:37:24 -04:00
|
|
|
import android.content.Context;
|
2014-03-14 14:13:41 -04:00
|
|
|
import android.content.DialogInterface;
|
|
|
|
|
import android.content.Intent;
|
2015-08-24 05:01:41 -04:00
|
|
|
import android.content.IntentFilter;
|
2014-05-13 11:40:41 -04:00
|
|
|
import android.content.res.AssetManager;
|
2014-03-14 14:13:41 -04:00
|
|
|
import android.content.res.Configuration;
|
2014-04-23 19:40:10 -04:00
|
|
|
import android.content.IntentSender.SendIntentException;
|
2014-06-27 17:59:00 -04:00
|
|
|
import android.content.pm.ApplicationInfo;
|
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
import android.content.pm.PackageManager.NameNotFoundException;
|
2014-04-23 19:40:10 -04:00
|
|
|
|
2014-04-28 17:46:38 -04:00
|
|
|
import android.media.AudioManager;
|
2014-05-22 09:08:10 -04:00
|
|
|
import android.util.DisplayMetrics;
|
2014-04-28 17:46:38 -04:00
|
|
|
|
2015-09-24 21:03:00 -04:00
|
|
|
import android.view.InputDevice;
|
2014-04-28 12:19:40 -04:00
|
|
|
import android.view.Gravity;
|
2014-07-22 18:03:47 -04:00
|
|
|
import android.view.MotionEvent;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.View.OnTouchListener;
|
|
|
|
|
import android.view.ViewConfiguration;
|
2014-04-28 12:19:40 -04:00
|
|
|
import android.view.ViewGroup.LayoutParams;
|
|
|
|
|
import android.view.ViewGroup.MarginLayoutParams;
|
2015-12-10 16:56:55 -05:00
|
|
|
import android.view.SurfaceHolder;
|
|
|
|
|
import android.view.SurfaceView;
|
2014-04-28 12:19:40 -04:00
|
|
|
import android.view.WindowManager;
|
2015-01-05 08:49:14 -05:00
|
|
|
import android.view.Window;
|
2014-04-28 12:19:40 -04:00
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
import android.widget.PopupWindow;
|
|
|
|
|
|
2014-09-12 11:37:24 -04:00
|
|
|
import android.media.AudioManager;
|
|
|
|
|
|
2014-07-28 12:50:02 -04:00
|
|
|
import com.google.android.gms.auth.GoogleAuthUtil;
|
2014-04-23 19:40:10 -04:00
|
|
|
import com.google.android.gms.common.api.GoogleApiClient;
|
|
|
|
|
import com.google.android.gms.common.GooglePlayServicesUtil;
|
2014-04-23 20:22:19 -04:00
|
|
|
|
2014-04-28 12:19:40 -04:00
|
|
|
import com.google.android.gms.ads.AdRequest;
|
|
|
|
|
import com.google.android.gms.ads.AdView;
|
|
|
|
|
import com.google.android.gms.ads.AdSize;
|
2014-05-22 09:08:10 -04:00
|
|
|
import com.google.android.gms.ads.AdListener;
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-07-28 12:50:02 -04:00
|
|
|
import com.google.android.gms.plus.Plus;
|
|
|
|
|
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
|
|
2014-10-30 17:06:50 -04:00
|
|
|
import com.epicgames.ue4.GooglePlayStoreHelper;
|
|
|
|
|
import com.epicgames.ue4.GooglePlayLicensing;
|
|
|
|
|
|
2015-08-24 05:01:41 -04:00
|
|
|
// Console commands listener, only for debug builds
|
|
|
|
|
import com.epicgames.ue4.ConsoleCmdReceiver;
|
2014-10-30 17:06:50 -04:00
|
|
|
|
2015-12-10 16:56:55 -05:00
|
|
|
import android.os.Build;
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
// TODO: use the resources from the UE4 lib project once we've got the packager up and running
|
|
|
|
|
//import com.epicgames.ue4.R;
|
|
|
|
|
|
2015-04-22 11:14:29 -04:00
|
|
|
import com.epicgames.ue4.DownloadShim;
|
|
|
|
|
|
2015-12-10 16:56:55 -05:00
|
|
|
//$${gameActivityImportAdditions}$$
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
//Extending NativeActivity so that this Java class is instantiated
|
|
|
|
|
//from the beginning of the program. This will allow the user
|
|
|
|
|
//to instantiate other Java libraries from here, that the user
|
|
|
|
|
//can then use the functions from C++
|
|
|
|
|
//NOTE -- This class is not necessary for the UnrealEngine C++ code
|
|
|
|
|
// to startup, as this is handled through the base NativeActivity class.
|
|
|
|
|
// This class's functionality is to provide a way to instantiate other
|
|
|
|
|
// Java libraries at the startup of the program and store references
|
|
|
|
|
// to them in this class.
|
|
|
|
|
|
2015-12-10 16:56:55 -05:00
|
|
|
public class GameActivity extends NativeActivity implements SurfaceHolder.Callback2
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
public static Logger Log = new Logger("UE4");
|
|
|
|
|
|
2015-04-22 11:14:29 -04:00
|
|
|
public static final int DOWNLOAD_ACTIVITY_ID = 80001; // so we can identify the activity later
|
|
|
|
|
public static final int DOWNLOAD_NO_RETURN_CODE = 0; // we didn't get a return code - will need to log and debug as this shouldn't happen
|
|
|
|
|
public static final int DOWNLOAD_FILES_PRESENT = 1; // we already had the files we needed
|
|
|
|
|
public static final int DOWNLOAD_COMPLETED_OK = 2; // downloaded ok (practically the same as above)
|
|
|
|
|
public static final int DOWNLOAD_USER_QUIT = 3; // user aborted the download
|
|
|
|
|
public static final int DOWNLOAD_FAILED = 4;
|
|
|
|
|
public static final int DOWNLOAD_INVALID = 5;
|
2015-05-12 06:11:38 -04:00
|
|
|
public static final int DOWNLOAD_NO_PLAY_KEY = 6;
|
2015-04-22 11:14:29 -04:00
|
|
|
public static final String DOWNLOAD_RETURN_NAME = "Result";
|
|
|
|
|
|
2014-11-17 11:31:49 -05:00
|
|
|
static GameActivity _activity;
|
2016-01-07 11:21:22 -05:00
|
|
|
static Bundle _bundle;
|
2014-07-21 16:20:58 -04:00
|
|
|
|
2015-08-28 19:34:42 -04:00
|
|
|
protected Dialog mSplashDialog;
|
|
|
|
|
private int noActionAnimID = -1;
|
|
|
|
|
|
2014-07-21 16:20:58 -04:00
|
|
|
// Console
|
|
|
|
|
AlertDialog consoleAlert;
|
|
|
|
|
EditText consoleInputBox;
|
2014-07-22 18:03:47 -04:00
|
|
|
ArrayList<String> consoleHistoryList;
|
|
|
|
|
int consoleHistoryIndex;
|
|
|
|
|
float consoleDistance;
|
|
|
|
|
float consoleVelocity;
|
2014-07-21 16:20:58 -04:00
|
|
|
|
|
|
|
|
// Virtual keyboard
|
|
|
|
|
AlertDialog virtualKeyboardAlert;
|
|
|
|
|
EditText virtualKeyboardInputBox;
|
2014-05-13 11:40:41 -04:00
|
|
|
|
2015-08-24 05:01:41 -04:00
|
|
|
// Console commands receiver
|
|
|
|
|
ConsoleCmdReceiver consoleCmdReceiver;
|
|
|
|
|
|
2015-01-27 13:05:32 -05:00
|
|
|
// default the PackageDataInsideApk to an invalid value to make sure we don't get it too early
|
|
|
|
|
private static int PackageDataInsideApkValue = -1;
|
2015-04-22 11:14:29 -04:00
|
|
|
private static int HasOBBFiles = -1;
|
2015-01-27 13:05:32 -05:00
|
|
|
|
2015-05-20 20:32:30 -04:00
|
|
|
// depthbuffer preference from manifest
|
|
|
|
|
int DepthBufferPreference = 0;
|
|
|
|
|
|
2014-05-13 11:40:41 -04:00
|
|
|
/** AssetManger reference - populated on start up and used when the OBB is packed into the APK */
|
|
|
|
|
private AssetManager AssetManagerReference;
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-04-23 19:40:10 -04:00
|
|
|
private GoogleApiClient googleClient;
|
2014-04-29 21:51:48 -04:00
|
|
|
|
2014-04-28 12:19:40 -04:00
|
|
|
/** AdMob support */
|
|
|
|
|
private PopupWindow adPopupWindow;
|
|
|
|
|
private AdView adView;
|
|
|
|
|
private boolean adInit = false;
|
|
|
|
|
private LinearLayout adLayout;
|
2014-05-22 09:08:10 -04:00
|
|
|
private int adGravity = Gravity.TOP;
|
|
|
|
|
|
2015-10-01 10:39:13 -04:00
|
|
|
// layout required by popups, e.g ads, native controls
|
|
|
|
|
LinearLayout activityLayout;
|
|
|
|
|
|
2014-05-22 09:08:10 -04:00
|
|
|
/** true when the application has requested that an ad be displayed */
|
|
|
|
|
private boolean adWantsToBeShown = false;
|
|
|
|
|
|
|
|
|
|
/** true when an ad is available to be displayed */
|
|
|
|
|
private boolean adIsAvailable = false;
|
|
|
|
|
|
|
|
|
|
/** true when an ad request is in flight */
|
|
|
|
|
private boolean adIsRequested = false;
|
2014-04-28 12:19:40 -04:00
|
|
|
|
2014-04-23 19:40:10 -04:00
|
|
|
/** Request code to use when launching the Google Services resolution activity */
|
|
|
|
|
private static final int GOOGLE_SERVICES_REQUEST_RESOLVE_ERROR = 1001;
|
|
|
|
|
|
|
|
|
|
/** Unique tag for the error dialog fragment */
|
|
|
|
|
private static final String DIALOG_ERROR = "dialog_error";
|
|
|
|
|
|
|
|
|
|
/** Unique ID to identify Google Play Services error dialog */
|
|
|
|
|
private static final int PLAY_SERVICES_DIALOG_ID = 1;
|
|
|
|
|
|
2015-04-22 11:14:29 -04:00
|
|
|
/** Check to see if we have all the files */
|
|
|
|
|
private boolean HasAllFiles = false;
|
|
|
|
|
|
|
|
|
|
/** Check to see if we should be verifying the files once we have them */
|
|
|
|
|
public boolean VerifyOBBOnStartUp = false;
|
2015-05-15 16:22:16 -04:00
|
|
|
|
2015-04-22 11:14:29 -04:00
|
|
|
/** Flag to ensure we have finished startup before allowing nativeOnActivityResult to get called */
|
|
|
|
|
private boolean InitCompletedOK = false;
|
|
|
|
|
|
2015-04-24 10:31:00 -04:00
|
|
|
private boolean ShouldHideUI = false;
|
2015-08-24 05:01:41 -04:00
|
|
|
|
|
|
|
|
/** Whether this application is for distribution */
|
|
|
|
|
private boolean IsForDistribution = false;
|
2015-12-10 16:56:55 -05:00
|
|
|
|
|
|
|
|
/** Used for SurfaceHolder.setFixedSize buffer scaling workaround on early Amazon devices and some others */
|
|
|
|
|
private boolean bUseSurfaceView = false;
|
|
|
|
|
private SurfaceView MySurfaceView;
|
|
|
|
|
private int DesiredHolderWidth = 0;
|
|
|
|
|
private int DesiredHolderHeight = 0;
|
2015-04-22 11:14:29 -04:00
|
|
|
|
2014-11-17 11:31:49 -05:00
|
|
|
/** Access singleton activity for game. **/
|
|
|
|
|
public static GameActivity Get()
|
|
|
|
|
{
|
|
|
|
|
return _activity;
|
|
|
|
|
}
|
2014-12-03 14:34:22 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Get the SDK level of the OS we are running in.
|
|
|
|
|
We do this instead of accessing the SDK_INT
|
|
|
|
|
with JNI from C++ as the new ART runtime seems to have
|
|
|
|
|
problems dynamically finding/loading static inner classes.
|
|
|
|
|
*/
|
|
|
|
|
public static final int ANDROID_BUILD_VERSION = android.os.Build.VERSION.SDK_INT;
|
|
|
|
|
|
2014-10-30 17:06:50 -04:00
|
|
|
private StoreHelper IapStoreHelper;
|
|
|
|
|
|
2015-12-10 16:56:55 -05:00
|
|
|
//$${gameActivityClassAdditions}$$
|
|
|
|
|
|
2014-04-23 19:40:10 -04:00
|
|
|
@Override
|
2014-03-14 14:13:41 -04:00
|
|
|
public void onStart()
|
|
|
|
|
{
|
|
|
|
|
super.onStart();
|
|
|
|
|
|
2015-08-24 05:01:41 -04:00
|
|
|
if (IsForDistribution == false)
|
|
|
|
|
{
|
|
|
|
|
// Create console command broadcast listener
|
|
|
|
|
consoleCmdReceiver = new ConsoleCmdReceiver(this);
|
|
|
|
|
registerReceiver(consoleCmdReceiver, new IntentFilter(Intent.ACTION_RUN));
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-10 16:56:55 -05:00
|
|
|
//$${gameActivityOnStartAdditions}$$
|
2014-03-14 14:13:41 -04:00
|
|
|
Log.debug("==================================> Inside onStart function in GameActivity");
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-01 11:23:41 -04:00
|
|
|
public int getDeviceDefaultOrientation()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
|
|
|
|
|
WindowManager windowManager = getWindowManager();
|
|
|
|
|
|
|
|
|
|
Configuration config = getResources().getConfiguration();
|
|
|
|
|
|
|
|
|
|
int rotation = windowManager.getDefaultDisplay().getRotation();
|
|
|
|
|
|
|
|
|
|
if ( ((rotation == android.view.Surface.ROTATION_0 || rotation == android.view.Surface.ROTATION_180) &&
|
|
|
|
|
config.orientation == Configuration.ORIENTATION_LANDSCAPE)
|
|
|
|
|
|| ((rotation == android.view.Surface.ROTATION_90 || rotation == android.view.Surface.ROTATION_270) &&
|
|
|
|
|
config.orientation == Configuration.ORIENTATION_PORTRAIT))
|
|
|
|
|
{
|
|
|
|
|
return Configuration.ORIENTATION_LANDSCAPE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Configuration.ORIENTATION_PORTRAIT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-28 19:34:42 -04:00
|
|
|
private int getResourceId(String VariableName, String ResourceName, String PackageName)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return getResources().getIdentifier(VariableName, ResourceName, PackageName);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 19:40:10 -04:00
|
|
|
@Override
|
2014-03-14 14:13:41 -04:00
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
|
|
{
|
|
|
|
|
super.onCreate(savedInstanceState);
|
2015-08-28 19:34:42 -04:00
|
|
|
|
|
|
|
|
// create splashscreen dialog (if launched by SplashActivity)
|
|
|
|
|
Bundle intentBundle = getIntent().getExtras();
|
2015-12-10 16:56:55 -05:00
|
|
|
if (intentBundle != null)
|
2015-08-28 19:34:42 -04:00
|
|
|
{
|
2015-12-10 16:56:55 -05:00
|
|
|
ShouldHideUI = intentBundle.getString("ShouldHideUI") != null;
|
|
|
|
|
if (intentBundle.getString("UseSplashScreen") != null)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
// try to get the splash theme (can't use R.style.UE4SplashTheme since we don't know the package name until runtime)
|
|
|
|
|
int SplashThemeId = getResources().getIdentifier("UE4SplashTheme", "style", getPackageName());
|
|
|
|
|
mSplashDialog = new Dialog(this, SplashThemeId);
|
|
|
|
|
mSplashDialog.setCancelable(false);
|
|
|
|
|
if (ShouldHideUI)
|
|
|
|
|
{
|
|
|
|
|
View decorView = mSplashDialog.getWindow().getDecorView();
|
|
|
|
|
// only do this on KitKat and above
|
|
|
|
|
if(android.os.Build.VERSION.SDK_INT >= 19) {
|
|
|
|
|
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
|
|
|
|
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
|
|
|
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
|
|
|
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
|
|
|
|
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
|
|
|
|
| View.SYSTEM_UI_FLAG_IMMERSIVE); // NOT sticky.. will be set to sticky later!
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mSplashDialog.show();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
noActionAnimID = getResources().getIdentifier("noaction", "anim", getPackageName());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
2015-08-28 19:34:42 -04:00
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
noActionAnimID = getResources().getIdentifier("noaction", "anim", getPackageName());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
// Suppress java logs in Shipping builds
|
|
|
|
|
if (nativeIsShippingBuild())
|
|
|
|
|
{
|
|
|
|
|
Logger.SuppressLogs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_activity = this;
|
2015-10-01 10:39:13 -04:00
|
|
|
|
|
|
|
|
// layout required by popups, e.g ads, native controls
|
|
|
|
|
MarginLayoutParams params = new MarginLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
|
|
|
|
params.setMargins(0, 0, 0, 0);
|
|
|
|
|
activityLayout = new LinearLayout(_activity);
|
|
|
|
|
_activity.setContentView(activityLayout, params);
|
|
|
|
|
|
2015-01-19 18:26:22 -05:00
|
|
|
/*
|
2015-01-05 08:49:14 -05:00
|
|
|
// Turn on and unlock screen.. Assumption is that this
|
|
|
|
|
// will only really have an effect when for debug launching
|
|
|
|
|
// as otherwise the screen is already unlocked.
|
2015-01-06 12:16:41 -05:00
|
|
|
this.getWindow().addFlags(
|
|
|
|
|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
|
2015-01-19 18:26:22 -05:00
|
|
|
// WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
|
2015-01-06 12:16:41 -05:00
|
|
|
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
|
2015-01-05 08:49:14 -05:00
|
|
|
// On some devices we can also unlock a key-locked screen by disabling the
|
2015-01-06 12:16:41 -05:00
|
|
|
// keylock guard. To be safe we only do this on < Android 3.2. As the API
|
|
|
|
|
// is deprecated from 3.2 onward.
|
|
|
|
|
if (ANDROID_BUILD_VERSION < 13)
|
|
|
|
|
{
|
|
|
|
|
android.app.KeyguardManager keyman = (android.app.KeyguardManager)getSystemService(KEYGUARD_SERVICE);
|
|
|
|
|
android.app.KeyguardManager.KeyguardLock keylock = keyman.newKeyguardLock("Unlock");
|
|
|
|
|
keylock.disableKeyguard();
|
|
|
|
|
}
|
2015-01-19 18:26:22 -05:00
|
|
|
*/
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2015-09-24 21:03:00 -04:00
|
|
|
/*
|
|
|
|
|
// log a list of input devices for debugging
|
|
|
|
|
{
|
|
|
|
|
int[] deviceIds = InputDevice.getDeviceIds();
|
|
|
|
|
for (int deviceIndex=0; deviceIndex < deviceIds.length; deviceIndex++)
|
|
|
|
|
{
|
|
|
|
|
InputDevice inputDevice = InputDevice.getDevice(deviceIds[deviceIndex]);
|
|
|
|
|
Log.debug("Device index " + deviceIndex + ": (deviceId=" + inputDevice.getId() +
|
|
|
|
|
", controllerNumber=" + inputDevice.getControllerNumber() + ", sources=" + String.format("%08x", inputDevice.getSources()) +
|
|
|
|
|
", vendorId=" + String.format("%04x", inputDevice.getVendorId()) + ", productId=" + String.format("%04x", inputDevice.getProductId()) +
|
|
|
|
|
", descriptor=" + inputDevice.getDescriptor() + ", deviceName=" + inputDevice.getName() + ")");
|
|
|
|
|
|
|
|
|
|
// is it a joystick?
|
|
|
|
|
if ((inputDevice.getSources() & InputDevice.SOURCE_JOYSTICK) != 0)
|
|
|
|
|
{
|
|
|
|
|
Log.debug("Gamepad detected: (deviceIndex=" + deviceIndex + ", deviceId=" + inputDevice.getId() + ", deviceName=" + inputDevice.getName() + ")");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
2014-04-28 17:46:38 -04:00
|
|
|
// tell Android that we want volume controls to change the media volume, aka music
|
|
|
|
|
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
2014-05-01 11:23:41 -04:00
|
|
|
|
2014-06-19 18:32:18 -04:00
|
|
|
// is this a native landscape device (tablet, tv)?
|
2014-05-01 11:23:41 -04:00
|
|
|
if ( getDeviceDefaultOrientation() == Configuration.ORIENTATION_LANDSCAPE )
|
|
|
|
|
{
|
2014-06-19 18:32:18 -04:00
|
|
|
boolean bForceLandscape = false;
|
|
|
|
|
|
|
|
|
|
// check for a Google TV by checking system feature support
|
|
|
|
|
if (getPackageManager().hasSystemFeature("com.google.android.tv"))
|
|
|
|
|
{
|
|
|
|
|
Log.debug( "Detected Google TV, will default to landscape" );
|
|
|
|
|
bForceLandscape = true;
|
|
|
|
|
} else
|
|
|
|
|
|
|
|
|
|
// check NVidia devices
|
|
|
|
|
if (android.os.Build.MANUFACTURER.equals("NVIDIA"))
|
|
|
|
|
{
|
|
|
|
|
// is it a Shield? (checking exact model)
|
|
|
|
|
if (android.os.Build.MODEL.equals("SHIELD"))
|
|
|
|
|
{
|
|
|
|
|
Log.debug( "Detected NVidia Shield, will default to landscape" );
|
|
|
|
|
bForceLandscape = true;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
|
|
|
|
|
// check Ouya
|
|
|
|
|
if (android.os.Build.MANUFACTURER.equals("OUYA"))
|
|
|
|
|
{
|
|
|
|
|
// only one so far (ouya_1_1) but check prefix anyway
|
|
|
|
|
if (android.os.Build.MODEL.toLowerCase().startsWith("ouya_"))
|
|
|
|
|
{
|
|
|
|
|
Log.debug( "Detected Ouya console (" + android.os.Build.MODEL + "), will default to landscape" );
|
|
|
|
|
bForceLandscape = true;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
|
|
|
|
|
// check Amazon devices
|
|
|
|
|
if (android.os.Build.MANUFACTURER.equals("Amazon"))
|
|
|
|
|
{
|
|
|
|
|
// is it a Kindle Fire TV? (Fire TV FAQ says AFTB, but to check for AFT)
|
|
|
|
|
if (android.os.Build.MODEL.startsWith("AFT"))
|
|
|
|
|
{
|
|
|
|
|
Log.debug( "Detected Kindle Fire TV (" + android.os.Build.MODEL + "), will default to landscape" );
|
|
|
|
|
bForceLandscape = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// apply the force request if we found a device above
|
|
|
|
|
if (bForceLandscape)
|
|
|
|
|
{
|
|
|
|
|
Log.debug( "Setting screen orientation to landscape because we have detected landscape device" );
|
|
|
|
|
_activity.setRequestedOrientation( android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE );
|
|
|
|
|
}
|
2014-05-01 11:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-05-13 11:40:41 -04:00
|
|
|
// Grab a reference to the asset manager
|
|
|
|
|
AssetManagerReference = this.getAssets();
|
|
|
|
|
|
2015-03-11 14:09:11 -04:00
|
|
|
// Read metadata from AndroidManifest.xml
|
|
|
|
|
String ProjectName = getPackageName();
|
|
|
|
|
ProjectName = ProjectName.substring(ProjectName.lastIndexOf('.') + 1);
|
2014-06-27 17:59:00 -04:00
|
|
|
try {
|
|
|
|
|
ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
|
|
|
|
|
Bundle bundle = ai.metaData;
|
2016-01-07 11:21:22 -05:00
|
|
|
_bundle = bundle;
|
2015-03-11 14:09:11 -04:00
|
|
|
|
2015-08-24 05:01:41 -04:00
|
|
|
if ((ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) == 0)
|
|
|
|
|
{
|
|
|
|
|
IsForDistribution = true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-11 14:09:11 -04:00
|
|
|
// Get the preferred depth buffer size from AndroidManifest.xml
|
2014-06-27 17:59:00 -04:00
|
|
|
if (bundle.containsKey("com.epicgames.ue4.GameActivity.DepthBufferPreference"))
|
|
|
|
|
{
|
|
|
|
|
DepthBufferPreference = bundle.getInt("com.epicgames.ue4.GameActivity.DepthBufferPreference");
|
|
|
|
|
Log.debug( "Found DepthBufferPreference = " + DepthBufferPreference);
|
2015-01-27 13:05:32 -05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-06-27 17:59:00 -04:00
|
|
|
Log.debug( "Did not find DepthBufferPreference, using default.");
|
|
|
|
|
}
|
2015-01-27 13:05:32 -05:00
|
|
|
|
2015-03-11 14:09:11 -04:00
|
|
|
// Determine if data is embedded in APK from AndroidManifest.xml
|
2015-01-27 13:05:32 -05:00
|
|
|
if (bundle.containsKey("com.epicgames.ue4.GameActivity.bPackageDataInsideApk"))
|
|
|
|
|
{
|
|
|
|
|
PackageDataInsideApkValue = bundle.getBoolean("com.epicgames.ue4.GameActivity.bPackageDataInsideApk") ? 1 : 0;
|
|
|
|
|
Log.debug( "Found bPackageDataInsideApk = " + PackageDataInsideApkValue);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PackageDataInsideApkValue = 0;
|
|
|
|
|
Log.debug( "Did not find bPackageDataInsideApk, using default.");
|
|
|
|
|
}
|
2015-03-11 14:09:11 -04:00
|
|
|
|
|
|
|
|
// Get the project name from AndroidManifest.xml
|
|
|
|
|
if (bundle.containsKey("com.epicgames.ue4.GameActivity.ProjectName"))
|
|
|
|
|
{
|
|
|
|
|
ProjectName = bundle.getString("com.epicgames.ue4.GameActivity.ProjectName");
|
|
|
|
|
Log.debug( "Found ProjectName = " + ProjectName);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.debug( "Did not find ProjectName, using package name = " + ProjectName);
|
|
|
|
|
}
|
2015-04-22 11:14:29 -04:00
|
|
|
|
|
|
|
|
if (bundle.containsKey("com.epicgames.ue4.GameActivity.bHasOBBFiles"))
|
|
|
|
|
{
|
|
|
|
|
HasOBBFiles = bundle.getBoolean("com.epicgames.ue4.GameActivity.bHasOBBFiles") ? 1 : 0;
|
|
|
|
|
Log.debug( "Found bHasOBBFiles = " + HasOBBFiles);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
HasOBBFiles = 0;
|
|
|
|
|
Log.debug( "Did not find bHasOBBFiles, using default.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bundle.containsKey("com.epicgames.ue4.GameActivity.bVerifyOBBOnStartUp"))
|
|
|
|
|
{
|
|
|
|
|
VerifyOBBOnStartUp = bundle.getBoolean("com.epicgames.ue4.GameActivity.bVerifyOBBOnStartUp");
|
|
|
|
|
Log.debug( "Found bVerifyOBBOnStartUp = " + VerifyOBBOnStartUp);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
VerifyOBBOnStartUp = false;
|
|
|
|
|
Log.debug( "Did not find bVerifyOBBOnStartUp, using default.");
|
|
|
|
|
}
|
2015-04-24 10:31:00 -04:00
|
|
|
|
2015-04-22 11:14:29 -04:00
|
|
|
if(bundle.containsKey("com.epicgames.ue4.GameActivity.bShouldHideUI"))
|
|
|
|
|
{
|
|
|
|
|
ShouldHideUI = bundle.getBoolean("com.epicgames.ue4.GameActivity.bShouldHideUI");
|
|
|
|
|
Log.debug( "UI hiding set to " + ShouldHideUI);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.debug( "UI hiding not found. Leaving as " + ShouldHideUI);
|
|
|
|
|
}
|
2015-08-03 20:13:23 -04:00
|
|
|
|
2015-12-10 16:56:55 -05:00
|
|
|
//$${gameActivityReadMetadataAdditions}$$
|
2015-01-27 13:05:32 -05:00
|
|
|
}
|
|
|
|
|
catch (NameNotFoundException e)
|
|
|
|
|
{
|
2014-06-27 17:59:00 -04:00
|
|
|
Log.debug( "Failed to load meta-data: NameNotFound: " + e.getMessage());
|
2015-01-27 13:05:32 -05:00
|
|
|
}
|
|
|
|
|
catch (NullPointerException e)
|
|
|
|
|
{
|
2014-06-27 17:59:00 -04:00
|
|
|
Log.debug( "Failed to load meta-data: NullPointer: " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
// tell the engine if this is a portrait app
|
|
|
|
|
nativeSetGlobalActivity();
|
2014-06-27 17:59:00 -04:00
|
|
|
nativeSetWindowInfo(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT, DepthBufferPreference);
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-08-22 10:24:13 -04:00
|
|
|
// get the full language code, like en-US
|
|
|
|
|
// note: this may need to be Locale.getDefault().getLanguage()
|
|
|
|
|
String Language = java.util.Locale.getDefault().toString();
|
2014-05-22 09:08:10 -04:00
|
|
|
|
|
|
|
|
Log.debug( "Android version is " + android.os.Build.VERSION.RELEASE );
|
2014-07-23 11:46:00 -04:00
|
|
|
Log.debug( "Android manufacturer is " + android.os.Build.MANUFACTURER );
|
2014-05-22 09:08:10 -04:00
|
|
|
Log.debug( "Android model is " + android.os.Build.MODEL );
|
2014-08-22 10:24:13 -04:00
|
|
|
Log.debug( "OS language is set to " + Language );
|
2014-05-22 09:08:10 -04:00
|
|
|
|
2014-08-22 10:24:13 -04:00
|
|
|
nativeSetAndroidVersionInformation( android.os.Build.VERSION.RELEASE, android.os.Build.MANUFACTURER, android.os.Build.MODEL, Language );
|
2014-05-22 09:08:10 -04:00
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int Version = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
|
|
|
|
|
int PatchVersion = 0;
|
2015-03-11 14:09:11 -04:00
|
|
|
nativeSetObbInfo(ProjectName, getApplicationContext().getPackageName(), Version, PatchVersion);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
// if the above failed, then, we can't use obbs
|
|
|
|
|
Log.debug("==================================> PackageInfo failure getting .obb info: " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-22 09:08:10 -04:00
|
|
|
// enable the physical volume controls to the game
|
|
|
|
|
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
|
|
|
|
|
2014-07-21 16:20:58 -04:00
|
|
|
AlertDialog.Builder builder;
|
|
|
|
|
|
|
|
|
|
consoleInputBox = new EditText(this);
|
2014-07-22 18:03:47 -04:00
|
|
|
consoleInputBox.setInputType(0x00080001); // TYPE_CLASS_TEXT | TYPE_TEXT_FLAG_NO_SUGGESTIONS);
|
|
|
|
|
consoleHistoryList = new ArrayList<String>();
|
|
|
|
|
consoleHistoryIndex = 0;
|
|
|
|
|
|
|
|
|
|
final ViewConfiguration vc = ViewConfiguration.get(this);
|
|
|
|
|
DisplayMetrics dm = getResources().getDisplayMetrics();
|
|
|
|
|
consoleDistance = vc.getScaledPagingTouchSlop() * dm.density;
|
|
|
|
|
consoleVelocity = vc.getScaledMinimumFlingVelocity() / 1000.0f;
|
|
|
|
|
|
|
|
|
|
consoleInputBox.setOnTouchListener(new OnTouchListener() {
|
|
|
|
|
private long downTime;
|
|
|
|
|
private float downX;
|
|
|
|
|
|
|
|
|
|
public void swipeLeft() {
|
|
|
|
|
if (!consoleHistoryList.isEmpty() && consoleHistoryIndex + 1 < consoleHistoryList.size()) {
|
|
|
|
|
consoleInputBox.setText(consoleHistoryList.get(++consoleHistoryIndex));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void swipeRight() {
|
|
|
|
|
if (!consoleHistoryList.isEmpty() && consoleHistoryIndex > 0) {
|
|
|
|
|
consoleInputBox.setText(consoleHistoryList.get(--consoleHistoryIndex));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
|
switch (event.getAction()) {
|
|
|
|
|
case MotionEvent.ACTION_DOWN: {
|
|
|
|
|
// remember down time and position
|
|
|
|
|
downTime = System.currentTimeMillis();
|
|
|
|
|
downX = event.getX();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case MotionEvent.ACTION_UP: {
|
|
|
|
|
long deltaTime = System.currentTimeMillis() - downTime;
|
|
|
|
|
float delta = event.getX() - downX;
|
|
|
|
|
float absDelta = Math.abs(delta);
|
|
|
|
|
|
|
|
|
|
if (absDelta > consoleDistance && absDelta > deltaTime * consoleVelocity)
|
|
|
|
|
{
|
|
|
|
|
if (delta < 0)
|
|
|
|
|
this.swipeLeft();
|
|
|
|
|
else
|
|
|
|
|
this.swipeRight();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-07-21 16:20:58 -04:00
|
|
|
|
|
|
|
|
builder = new AlertDialog.Builder(this);
|
|
|
|
|
builder.setTitle("Console Window - Enter Command")
|
|
|
|
|
.setMessage("")
|
|
|
|
|
.setView(consoleInputBox)
|
|
|
|
|
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
|
|
|
|
public void onClick(DialogInterface dialog, int id) {
|
2014-03-14 14:13:41 -04:00
|
|
|
String message = consoleInputBox.getText().toString().trim();
|
2014-07-22 18:03:47 -04:00
|
|
|
|
|
|
|
|
// remove it if already in history
|
|
|
|
|
int index = consoleHistoryList.indexOf(message);
|
|
|
|
|
if (index >= 0)
|
|
|
|
|
consoleHistoryList.remove(index);
|
|
|
|
|
|
|
|
|
|
// add it to the end
|
|
|
|
|
consoleHistoryList.add(message);
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
nativeConsoleCommand(message);
|
|
|
|
|
consoleInputBox.setText(" ");
|
|
|
|
|
dialog.dismiss();
|
|
|
|
|
}
|
2014-07-21 16:20:58 -04:00
|
|
|
})
|
|
|
|
|
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
|
|
|
|
public void onClick(DialogInterface dialog, int id) {
|
2014-03-14 14:13:41 -04:00
|
|
|
consoleInputBox.setText(" ");
|
|
|
|
|
dialog.dismiss();
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-07-21 16:20:58 -04:00
|
|
|
consoleAlert = builder.create();
|
|
|
|
|
|
|
|
|
|
virtualKeyboardInputBox = new EditText(this);
|
|
|
|
|
|
|
|
|
|
builder = new AlertDialog.Builder(this);
|
|
|
|
|
builder.setTitle("")
|
|
|
|
|
.setView(virtualKeyboardInputBox)
|
|
|
|
|
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
|
|
|
|
public void onClick(DialogInterface dialog, int id) {
|
|
|
|
|
String message = virtualKeyboardInputBox.getText().toString();
|
|
|
|
|
nativeVirtualKeyboardResult(true, message);
|
|
|
|
|
virtualKeyboardInputBox.setText(" ");
|
|
|
|
|
dialog.dismiss();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
|
|
|
|
public void onClick(DialogInterface dialog, int id) {
|
|
|
|
|
nativeVirtualKeyboardResult(false, " ");
|
|
|
|
|
virtualKeyboardInputBox.setText(" ");
|
|
|
|
|
dialog.dismiss();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
virtualKeyboardAlert = builder.create();
|
2014-04-23 19:40:10 -04:00
|
|
|
|
2014-10-30 17:06:50 -04:00
|
|
|
GooglePlayLicensing.GoogleLicensing = new GooglePlayLicensing();
|
|
|
|
|
GooglePlayLicensing.GoogleLicensing.Init(this, Log);
|
2015-04-22 11:14:29 -04:00
|
|
|
|
2014-07-10 14:41:00 -04:00
|
|
|
// Now okay for event handler to be set up on native side
|
2015-04-22 11:14:29 -04:00
|
|
|
// nativeResumeMainInit();
|
|
|
|
|
|
2014-06-27 11:22:12 -04:00
|
|
|
// Try to establish a connection to Google Play
|
2014-07-31 12:34:53 -04:00
|
|
|
// AndroidThunkJava_GooglePlayConnect();
|
2014-07-21 16:20:58 -04:00
|
|
|
|
2015-04-22 11:14:29 -04:00
|
|
|
// If we have data in the apk or just loose then carry on init as normal
|
|
|
|
|
/*Log.debug(this.getObbDir().getAbsolutePath());
|
|
|
|
|
String path = this.getObbDir().getAbsolutePath() + "/main.1.com.epicgames.StrategyGame.obb";
|
|
|
|
|
File obb = new File(path);
|
|
|
|
|
Log.debug("=+=+=+=+=+=+=> File exists: " + (obb.exists() ? "True" : "False"));
|
|
|
|
|
*/
|
|
|
|
|
if(PackageDataInsideApkValue == 1 || HasOBBFiles == 0)
|
|
|
|
|
{
|
|
|
|
|
HasAllFiles = true;
|
|
|
|
|
}
|
2015-12-10 16:56:55 -05:00
|
|
|
|
|
|
|
|
// Need to create our surface view here regardless of if we are going to end up using it
|
|
|
|
|
getWindow().takeSurface(null);
|
|
|
|
|
MySurfaceView = new SurfaceView(this);
|
|
|
|
|
MySurfaceView.getHolder().addCallback(this);
|
|
|
|
|
setContentView(MySurfaceView);
|
2016-05-19 19:35:35 -04:00
|
|
|
|
|
|
|
|
//$${gameActivityOnCreateAdditions}$$
|
2015-04-22 11:14:29 -04:00
|
|
|
|
2014-07-21 16:20:58 -04:00
|
|
|
Log.debug("==============> GameActive.onCreate complete!");
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
2015-04-22 11:14:29 -04:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onResume()
|
|
|
|
|
{
|
|
|
|
|
super.onResume();
|
2015-05-20 20:32:30 -04:00
|
|
|
|
|
|
|
|
// invalidate window cache
|
|
|
|
|
nativeSetWindowInfo(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT, DepthBufferPreference);
|
2015-04-22 11:14:29 -04:00
|
|
|
|
|
|
|
|
// only do this on KitKat and above
|
2015-05-22 11:09:51 -04:00
|
|
|
if (ShouldHideUI)
|
2015-04-22 11:14:29 -04:00
|
|
|
{
|
2015-05-22 11:09:51 -04:00
|
|
|
|
2015-04-22 11:14:29 -04:00
|
|
|
View decorView = getWindow().getDecorView();
|
2015-05-22 11:09:51 -04:00
|
|
|
if(android.os.Build.VERSION.SDK_INT >= 19) {
|
|
|
|
|
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
|
|
|
|
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
|
|
|
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
|
|
|
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
|
|
|
|
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
|
|
|
|
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
|
|
|
|
|
} /*else {
|
|
|
|
|
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
|
|
|
|
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
|
|
|
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
|
|
|
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
|
|
|
|
| View.SYSTEM_UI_FLAG_FULLSCREEN);
|
|
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
|
|
|
|
|
@Override public void onSystemUiVisibilityChange(int visibility) {
|
|
|
|
|
View decorView = getWindow().getDecorView();
|
|
|
|
|
if(android.os.Build.VERSION.SDK_INT >= 19) {
|
|
|
|
|
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
|
|
|
|
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
|
|
|
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
|
|
|
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
|
|
|
|
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
|
|
|
|
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
|
|
|
|
|
} /*else {
|
|
|
|
|
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
|
|
|
|
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
|
|
|
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
|
|
|
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
|
|
|
|
| View.SYSTEM_UI_FLAG_FULLSCREEN);
|
|
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-04-22 11:14:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(HasAllFiles)
|
|
|
|
|
{
|
|
|
|
|
Log.debug("==============> Resuming main init");
|
|
|
|
|
nativeResumeMainInit();
|
|
|
|
|
InitCompletedOK = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Start the check activity here
|
2015-08-28 19:34:42 -04:00
|
|
|
Log.debug("==============> Starting activity to check files and download if required");
|
2015-04-22 11:14:29 -04:00
|
|
|
Intent intent = new Intent(this, DownloadShim.GetDownloaderType());
|
2015-08-28 19:34:42 -04:00
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
2015-04-22 11:14:29 -04:00
|
|
|
startActivityForResult(intent, DOWNLOAD_ACTIVITY_ID);
|
2015-08-28 19:34:42 -04:00
|
|
|
if (noActionAnimID != -1)
|
|
|
|
|
{
|
|
|
|
|
overridePendingTransition(noActionAnimID, noActionAnimID);
|
|
|
|
|
}
|
2015-04-22 11:14:29 -04:00
|
|
|
}
|
2015-08-28 19:34:42 -04:00
|
|
|
|
2015-12-10 16:56:55 -05:00
|
|
|
//$${gameActivityOnResumeAdditions}$$
|
2015-04-22 11:14:29 -04:00
|
|
|
Log.debug("==============> GameActive.onResume complete!");
|
|
|
|
|
}
|
2014-04-23 19:40:10 -04:00
|
|
|
|
2015-12-10 16:56:55 -05:00
|
|
|
@Override
|
|
|
|
|
protected void onPause()
|
|
|
|
|
{
|
|
|
|
|
super.onPause();
|
|
|
|
|
//$${gameActivityOnPauseAdditions}$$
|
|
|
|
|
Log.debug("==============> GameActive.onPause complete!");
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 19:40:10 -04:00
|
|
|
@Override
|
|
|
|
|
public void onStop()
|
|
|
|
|
{
|
|
|
|
|
super.onStop();
|
2015-08-24 05:01:41 -04:00
|
|
|
|
|
|
|
|
if (consoleCmdReceiver != null)
|
|
|
|
|
{
|
|
|
|
|
unregisterReceiver(consoleCmdReceiver);
|
|
|
|
|
}
|
2015-12-10 16:56:55 -05:00
|
|
|
|
|
|
|
|
//$${gameActivityOnStopAdditions}$$
|
|
|
|
|
Log.debug("==============> GameActive.onStop complete!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDestroy()
|
|
|
|
|
{
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
if( IapStoreHelper != null )
|
|
|
|
|
{
|
|
|
|
|
IapStoreHelper.onDestroy();
|
|
|
|
|
}
|
|
|
|
|
//$${gameActivityOnDestroyAdditions}$$
|
|
|
|
|
Log.debug("==============> GameActive.onDestroy complete!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
if(bUseSurfaceView)
|
|
|
|
|
{
|
|
|
|
|
int newWidth = (DesiredHolderWidth > 0) ? DesiredHolderWidth : width;
|
|
|
|
|
int newHeight = (DesiredHolderHeight > 0) ? DesiredHolderHeight : height;
|
|
|
|
|
|
|
|
|
|
super.surfaceChanged(holder, format, newWidth, newHeight);
|
|
|
|
|
|
|
|
|
|
holder.setFixedSize(newWidth, newHeight);
|
|
|
|
|
|
|
|
|
|
nativeSetSurfaceViewInfo(holder.getSurfaceFrame().width(), holder.getSurfaceFrame().height());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
super.surfaceChanged(holder, format, width, height);
|
|
|
|
|
}
|
2014-04-23 19:40:10 -04:00
|
|
|
}
|
|
|
|
|
|
2014-05-22 09:08:10 -04:00
|
|
|
// handle ad popup visibility and requests
|
|
|
|
|
private void updateAdVisibility(boolean loadIfNeeded)
|
|
|
|
|
{
|
|
|
|
|
if (!adInit || (adPopupWindow == null))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// request an ad if we don't have one available or requested, but would like one
|
|
|
|
|
if (adWantsToBeShown && !adIsAvailable && !adIsRequested && loadIfNeeded)
|
|
|
|
|
{
|
|
|
|
|
AdRequest adRequest = new AdRequest.Builder().build(); // add test devices here
|
|
|
|
|
_activity.adView.loadAd(adRequest);
|
|
|
|
|
|
|
|
|
|
adIsRequested = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (adIsAvailable && adWantsToBeShown)
|
|
|
|
|
{
|
|
|
|
|
if (adPopupWindow.isShowing())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
adPopupWindow.showAtLocation(activityLayout, adGravity, 0, 0);
|
|
|
|
|
adPopupWindow.update();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!adPopupWindow.isShowing())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
adPopupWindow.dismiss();
|
|
|
|
|
adPopupWindow.update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-18 17:09:29 -04:00
|
|
|
public void AndroidThunkJava_KeepScreenOn(boolean Enable)
|
|
|
|
|
{
|
|
|
|
|
if (Enable)
|
|
|
|
|
{
|
|
|
|
|
_activity.runOnUiThread(new Runnable()
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void run()
|
|
|
|
|
{
|
|
|
|
|
_activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_activity.runOnUiThread(new Runnable()
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void run()
|
|
|
|
|
{
|
|
|
|
|
_activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-06 17:57:32 -05:00
|
|
|
private class VibrateRunnable implements Runnable {
|
|
|
|
|
private int duration;
|
|
|
|
|
private Vibrator vibrator;
|
|
|
|
|
|
|
|
|
|
VibrateRunnable(final int Duration, final Vibrator vibrator)
|
|
|
|
|
{
|
|
|
|
|
this.duration = Duration;
|
|
|
|
|
this.vibrator = vibrator;
|
|
|
|
|
}
|
|
|
|
|
public void run ()
|
|
|
|
|
{
|
|
|
|
|
if (duration < 1)
|
|
|
|
|
{
|
|
|
|
|
vibrator.cancel();
|
|
|
|
|
} else {
|
|
|
|
|
vibrator.vibrate(duration);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AndroidThunkJava_Vibrate(int Duration)
|
2014-09-16 17:32:10 -04:00
|
|
|
{
|
|
|
|
|
Vibrator vibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE);
|
2015-02-06 17:57:32 -05:00
|
|
|
if (vibrator != null)
|
2014-09-16 17:32:10 -04:00
|
|
|
{
|
2015-02-06 17:57:32 -05:00
|
|
|
_activity.runOnUiThread(new VibrateRunnable(Duration, vibrator));
|
2014-09-16 17:32:10 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
// Called from event thread in NativeActivity
|
|
|
|
|
public void AndroidThunkJava_ShowConsoleWindow(String Formats)
|
|
|
|
|
{
|
2014-07-21 16:20:58 -04:00
|
|
|
if (consoleAlert.isShowing() == true)
|
2014-04-23 18:34:35 -04:00
|
|
|
{
|
|
|
|
|
Log.debug("Console already showing.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 18:03:47 -04:00
|
|
|
// start at end of console history
|
|
|
|
|
consoleHistoryIndex = consoleHistoryList.size();
|
|
|
|
|
|
2014-07-21 16:20:58 -04:00
|
|
|
consoleAlert.setMessage("[Available texture formats: " + Formats + "]");
|
2014-03-14 14:13:41 -04:00
|
|
|
_activity.runOnUiThread(new Runnable()
|
|
|
|
|
{
|
|
|
|
|
public void run()
|
|
|
|
|
{
|
2014-07-21 16:20:58 -04:00
|
|
|
if (consoleAlert.isShowing() == false)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
Log.debug("Console not showing yet");
|
2014-07-21 16:20:58 -04:00
|
|
|
consoleAlert.show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AndroidThunkJava_ShowVirtualKeyboardInput(int InputType, String Label, String Contents)
|
|
|
|
|
{
|
|
|
|
|
if (virtualKeyboardAlert.isShowing() == true)
|
|
|
|
|
{
|
|
|
|
|
Log.debug("Virtual keyboard already showing.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set label and starting contents
|
|
|
|
|
virtualKeyboardAlert.setTitle(Label);
|
2015-09-08 18:43:53 -04:00
|
|
|
virtualKeyboardInputBox.setText("");
|
|
|
|
|
virtualKeyboardInputBox.append(Contents);
|
2014-07-21 16:20:58 -04:00
|
|
|
|
|
|
|
|
// configure for type of input
|
|
|
|
|
virtualKeyboardInputBox.setInputType(InputType);
|
|
|
|
|
|
|
|
|
|
_activity.runOnUiThread(new Runnable()
|
|
|
|
|
{
|
|
|
|
|
public void run()
|
|
|
|
|
{
|
|
|
|
|
if (virtualKeyboardAlert.isShowing() == false)
|
|
|
|
|
{
|
|
|
|
|
Log.debug("Virtual keyboard not showing yet");
|
|
|
|
|
virtualKeyboardAlert.show();
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AndroidThunkJava_LaunchURL(String URL)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Intent BrowserIntent = new Intent(Intent.ACTION_VIEW, android.net.Uri.parse(URL));
|
|
|
|
|
startActivity(BrowserIntent);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.debug("LaunchURL failed with exception " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-28 12:50:02 -04:00
|
|
|
public void AndroidThunkJava_ResetAchievements()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
String email = Plus.AccountApi.getAccountName(googleClient);
|
|
|
|
|
Log.debug("AndroidThunkJava_ResetAchievements: using email " + email);
|
|
|
|
|
|
|
|
|
|
String accesstoken = GoogleAuthUtil.getToken(this, email, "oauth2:https://www.googleapis.com/auth/games");
|
|
|
|
|
|
|
|
|
|
String ResetURL = "https://www.googleapis.com/games/v1management/achievements/reset?access_token=" + accesstoken;
|
|
|
|
|
Log.debug("AndroidThunkJava_ResetAchievements: using URL " + ResetURL);
|
|
|
|
|
|
|
|
|
|
URL url = new URL(ResetURL);
|
|
|
|
|
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
urlConnection.setRequestMethod("POST");
|
|
|
|
|
int status = urlConnection.getResponseCode();
|
|
|
|
|
Log.debug("AndroidThunkJava_ResetAchievements: HTTP response is " + status);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
urlConnection.disconnect();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.debug("AndroidThunkJava_ResetAchievements failed: " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-28 12:19:40 -04:00
|
|
|
public void AndroidThunkJava_ShowAdBanner(String AdMobAdUnitID, boolean bShowOnBottonOfScreen)
|
|
|
|
|
{
|
|
|
|
|
Log.debug("In AndroidThunkJava_ShowAdBanner");
|
|
|
|
|
Log.debug("AdID: " + AdMobAdUnitID);
|
|
|
|
|
|
2014-05-22 09:08:10 -04:00
|
|
|
adGravity = bShowOnBottonOfScreen ? Gravity.BOTTOM : Gravity.TOP;
|
2014-04-28 12:19:40 -04:00
|
|
|
|
|
|
|
|
if (adInit)
|
|
|
|
|
{
|
|
|
|
|
// already created, make it visible
|
|
|
|
|
_activity.runOnUiThread(new Runnable()
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void run()
|
|
|
|
|
{
|
|
|
|
|
if ((adPopupWindow == null) || adPopupWindow.isShowing())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-22 09:08:10 -04:00
|
|
|
adWantsToBeShown = true;
|
|
|
|
|
updateAdVisibility(true);
|
2014-04-28 12:19:40 -04:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// init our AdMob window
|
|
|
|
|
adView = new AdView(this);
|
|
|
|
|
adView.setAdUnitId(AdMobAdUnitID);
|
|
|
|
|
adView.setAdSize(AdSize.BANNER);
|
|
|
|
|
|
|
|
|
|
if (adView != null)
|
|
|
|
|
{
|
|
|
|
|
_activity.runOnUiThread(new Runnable()
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void run()
|
|
|
|
|
{
|
|
|
|
|
adInit = true;
|
|
|
|
|
|
2014-05-22 09:08:10 -04:00
|
|
|
final DisplayMetrics dm = getResources().getDisplayMetrics();
|
|
|
|
|
final float scale = dm.density;
|
2014-04-28 12:19:40 -04:00
|
|
|
adPopupWindow = new PopupWindow(_activity);
|
2014-05-22 09:08:10 -04:00
|
|
|
adPopupWindow.setWidth((int)(320*scale));
|
|
|
|
|
adPopupWindow.setHeight((int)(50*scale));
|
2014-04-28 12:19:40 -04:00
|
|
|
adPopupWindow.setWindowLayoutMode(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
|
|
|
|
adPopupWindow.setClippingEnabled(false);
|
|
|
|
|
|
|
|
|
|
adLayout = new LinearLayout(_activity);
|
|
|
|
|
|
2014-05-22 09:08:10 -04:00
|
|
|
final int padding = (int)(-5*scale);
|
|
|
|
|
adLayout.setPadding(padding,padding,padding,padding);
|
2014-04-28 12:19:40 -04:00
|
|
|
|
|
|
|
|
MarginLayoutParams params = new MarginLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);;
|
|
|
|
|
|
|
|
|
|
params.setMargins(0,0,0,0);
|
|
|
|
|
|
|
|
|
|
adLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
adLayout.addView(adView, params);
|
|
|
|
|
adPopupWindow.setContentView(adLayout);
|
|
|
|
|
|
2014-05-22 09:08:10 -04:00
|
|
|
// set up our ad callbacks
|
|
|
|
|
_activity.adView.setAdListener(new AdListener()
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void onAdLoaded()
|
|
|
|
|
{
|
|
|
|
|
adIsAvailable = true;
|
|
|
|
|
adIsRequested = false;
|
2014-04-28 12:19:40 -04:00
|
|
|
|
2014-05-22 09:08:10 -04:00
|
|
|
updateAdVisibility(true);
|
|
|
|
|
}
|
2014-04-28 12:19:40 -04:00
|
|
|
|
2014-05-22 09:08:10 -04:00
|
|
|
@Override
|
|
|
|
|
public void onAdFailedToLoad(int errorCode)
|
|
|
|
|
{
|
|
|
|
|
adIsAvailable = false;
|
|
|
|
|
adIsRequested = false;
|
|
|
|
|
|
|
|
|
|
// don't immediately request a new ad on failure, wait until the next show
|
|
|
|
|
updateAdVisibility(false);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
adWantsToBeShown = true;
|
|
|
|
|
updateAdVisibility(true);
|
2014-04-28 12:19:40 -04:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AndroidThunkJava_HideAdBanner()
|
|
|
|
|
{
|
|
|
|
|
Log.debug("In AndroidThunkJava_HideAdBanner");
|
|
|
|
|
|
|
|
|
|
if (!adInit)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_activity.runOnUiThread(new Runnable()
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void run()
|
|
|
|
|
{
|
2014-05-22 09:08:10 -04:00
|
|
|
adWantsToBeShown = false;
|
|
|
|
|
updateAdVisibility(true);
|
2014-04-28 12:19:40 -04:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AndroidThunkJava_CloseAdBanner()
|
|
|
|
|
{
|
|
|
|
|
Log.debug("In AndroidThunkJava_CloseAdBanner");
|
|
|
|
|
|
|
|
|
|
if (!adInit)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// currently the same as hide. should we do a full teardown?
|
|
|
|
|
_activity.runOnUiThread(new Runnable()
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void run()
|
|
|
|
|
{
|
2014-05-22 09:08:10 -04:00
|
|
|
adWantsToBeShown = false;
|
|
|
|
|
updateAdVisibility(true);
|
2014-04-28 12:19:40 -04:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-13 11:40:41 -04:00
|
|
|
public AssetManager AndroidThunkJava_GetAssetManager()
|
|
|
|
|
{
|
|
|
|
|
if(AssetManagerReference == null)
|
|
|
|
|
{
|
|
|
|
|
Log.debug("No reference to asset manager found!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return AssetManagerReference;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean isOBBInAPK()
|
|
|
|
|
{
|
2015-01-27 13:05:32 -05:00
|
|
|
Log.debug("Asking if osOBBInAPK? " + (PackageDataInsideApkValue == 1));
|
|
|
|
|
return PackageDataInsideApkValue == 1;
|
2014-05-13 11:40:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-08-04 20:46:25 -04:00
|
|
|
public void AndroidThunkJava_Minimize()
|
|
|
|
|
{
|
|
|
|
|
Intent startMain = new Intent(Intent.ACTION_MAIN);
|
|
|
|
|
startMain.addCategory(Intent.CATEGORY_HOME);
|
|
|
|
|
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
startActivity(startMain);
|
|
|
|
|
}
|
2014-05-13 11:40:41 -04:00
|
|
|
|
2014-08-04 20:46:25 -04:00
|
|
|
public void AndroidThunkJava_ForceQuit()
|
|
|
|
|
{
|
|
|
|
|
System.exit(0);
|
|
|
|
|
// finish();
|
|
|
|
|
}
|
2014-05-13 11:40:41 -04:00
|
|
|
|
2014-10-20 19:15:50 -04:00
|
|
|
// call back into native code from the Java UI thread, initializing any available VR HMD modules
|
|
|
|
|
public void AndroidThunkJava_InitHMDs()
|
|
|
|
|
{
|
|
|
|
|
_activity.runOnUiThread(new Runnable()
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void run()
|
|
|
|
|
{
|
|
|
|
|
nativeInitHMDs();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-09 12:20:07 -04:00
|
|
|
public static String AndroidThunkJava_GetFontDirectory()
|
|
|
|
|
{
|
|
|
|
|
// Parse and find the first known fonts directory on the device
|
|
|
|
|
String[] fontdirs = { "/system/fonts", "/system/font", "/data/fonts" };
|
|
|
|
|
|
|
|
|
|
String targetDir = null;
|
|
|
|
|
|
|
|
|
|
for ( String fontdir : fontdirs )
|
|
|
|
|
{
|
|
|
|
|
File dir = new File( fontdir );
|
|
|
|
|
|
|
|
|
|
if(dir.exists())
|
|
|
|
|
{
|
|
|
|
|
targetDir = fontdir;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return targetDir + "/";
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-12 11:37:24 -04:00
|
|
|
public boolean AndroidThunkJava_IsMusicActive()
|
|
|
|
|
{
|
|
|
|
|
AudioManager audioManager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
|
|
|
|
|
return audioManager.isMusicActive();
|
|
|
|
|
}
|
2014-10-30 17:06:50 -04:00
|
|
|
|
|
|
|
|
// In app purchase functionality
|
|
|
|
|
public void AndroidThunkJava_IapSetupService(String InProductKey)
|
|
|
|
|
{
|
2015-12-10 16:56:55 -05:00
|
|
|
if (getPackageManager().checkPermission("com.android.vending.BILLING", getPackageName()) == getPackageManager().PERMISSION_GRANTED)
|
2014-10-30 17:06:50 -04:00
|
|
|
{
|
2015-12-10 16:56:55 -05:00
|
|
|
IapStoreHelper = new GooglePlayStoreHelper(InProductKey, this, Log);
|
|
|
|
|
if (IapStoreHelper != null)
|
|
|
|
|
{
|
|
|
|
|
Log.debug("[JAVA] - AndroidThunkJava_IapSetupService - Failed to setup IAP service");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.debug("[JAVA] - AndroidThunkJava_IapSetupService - You do not have the appropriate permission setup.");
|
|
|
|
|
Log.debug("[JAVA] - AndroidThunkJava_IapSetupService - Please ensure com.android.vending.BILLING is added to the manifest.");
|
2014-10-30 17:06:50 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String[] CachedQueryProductIDs;
|
|
|
|
|
private boolean[] CachedQueryConsumables;
|
|
|
|
|
public boolean AndroidThunkJava_IapQueryInAppPurchases(String[] ProductIDs, boolean[] bConsumable)
|
|
|
|
|
{
|
|
|
|
|
Log.debug("[JAVA] - AndroidThunkJava_IapQueryInAppPurchases");
|
|
|
|
|
CachedQueryProductIDs = ProductIDs;
|
|
|
|
|
CachedQueryConsumables = bConsumable;
|
|
|
|
|
|
|
|
|
|
boolean bTriggeredQuery = false;
|
|
|
|
|
if( IapStoreHelper != null )
|
|
|
|
|
{
|
|
|
|
|
bTriggeredQuery = true;
|
|
|
|
|
|
|
|
|
|
_activity.runOnUiThread(new Runnable()
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void run()
|
|
|
|
|
{
|
|
|
|
|
IapStoreHelper.QueryInAppPurchases(CachedQueryProductIDs, CachedQueryConsumables);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.debug("[JAVA] - Store Helper is invalid");
|
|
|
|
|
}
|
|
|
|
|
return bTriggeredQuery;
|
|
|
|
|
}
|
2014-11-19 05:18:19 -05:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
|
|
|
|
{
|
2015-04-22 11:14:29 -04:00
|
|
|
if( requestCode == DOWNLOAD_ACTIVITY_ID)
|
|
|
|
|
{
|
2015-06-09 06:34:08 -04:00
|
|
|
int errorCode = 0;
|
|
|
|
|
if(resultCode == RESULT_OK)
|
2015-04-22 11:14:29 -04:00
|
|
|
{
|
2015-06-09 06:34:08 -04:00
|
|
|
|
|
|
|
|
errorCode = data.getIntExtra(DOWNLOAD_RETURN_NAME, DOWNLOAD_NO_RETURN_CODE);
|
|
|
|
|
|
|
|
|
|
String logMsg = "DownloadActivity Returned with ";
|
|
|
|
|
switch(errorCode)
|
|
|
|
|
{
|
|
|
|
|
case DOWNLOAD_FILES_PRESENT:
|
|
|
|
|
logMsg += "Download Files Present";
|
|
|
|
|
break;
|
|
|
|
|
case DOWNLOAD_COMPLETED_OK:
|
|
|
|
|
logMsg += "Download Completed OK";
|
|
|
|
|
break;
|
|
|
|
|
case DOWNLOAD_NO_RETURN_CODE:
|
|
|
|
|
logMsg += "Download No Return Code";
|
|
|
|
|
break;
|
|
|
|
|
case DOWNLOAD_USER_QUIT:
|
|
|
|
|
logMsg += "Download User Quit";
|
|
|
|
|
break;
|
|
|
|
|
case DOWNLOAD_FAILED:
|
|
|
|
|
logMsg += "Download Failed";
|
|
|
|
|
break;
|
|
|
|
|
case DOWNLOAD_INVALID:
|
|
|
|
|
logMsg += "Download Invalid";
|
|
|
|
|
break;
|
|
|
|
|
case DOWNLOAD_NO_PLAY_KEY:
|
|
|
|
|
logMsg +="Download No Play Key";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
logMsg += "Unknown message!";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.debug(logMsg);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.debug("Download activity cancelled by user.");
|
|
|
|
|
errorCode = DOWNLOAD_USER_QUIT;
|
2015-04-22 11:14:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HasAllFiles = (errorCode == DOWNLOAD_FILES_PRESENT || errorCode == DOWNLOAD_COMPLETED_OK);
|
|
|
|
|
|
|
|
|
|
if(errorCode == DOWNLOAD_NO_RETURN_CODE
|
|
|
|
|
|| errorCode == DOWNLOAD_USER_QUIT
|
|
|
|
|
|| errorCode == DOWNLOAD_FAILED
|
2015-05-12 06:11:38 -04:00
|
|
|
|| errorCode == DOWNLOAD_INVALID
|
|
|
|
|
|| errorCode == DOWNLOAD_NO_PLAY_KEY)
|
2015-08-28 19:34:42 -04:00
|
|
|
{
|
2015-04-22 11:14:29 -04:00
|
|
|
finish();
|
2015-08-28 19:34:42 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2015-04-22 11:14:29 -04:00
|
|
|
}
|
|
|
|
|
else if( IapStoreHelper != null )
|
2014-11-19 05:18:19 -05:00
|
|
|
{
|
2015-01-07 16:20:04 -05:00
|
|
|
if(!IapStoreHelper.onActivityResult(requestCode, resultCode, data))
|
|
|
|
|
{
|
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.debug("[JAVA] - Store Helper handled onActivityResult");
|
|
|
|
|
}
|
2014-11-19 05:18:19 -05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-01-07 16:20:04 -05:00
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
2014-11-19 05:18:19 -05:00
|
|
|
}
|
2015-12-10 16:56:55 -05:00
|
|
|
|
|
|
|
|
//$${gameActivityOnActivityResultAdditions}$$
|
2015-04-22 11:14:29 -04:00
|
|
|
|
|
|
|
|
if(InitCompletedOK)
|
|
|
|
|
{
|
|
|
|
|
nativeOnActivityResult(this, requestCode, resultCode, data);
|
|
|
|
|
}
|
2014-11-19 05:18:19 -05:00
|
|
|
}
|
2014-10-30 17:06:50 -04:00
|
|
|
|
|
|
|
|
public boolean AndroidThunkJava_IapBeginPurchase(String ProductId, boolean bConsumable)
|
|
|
|
|
{
|
|
|
|
|
Log.debug("[JAVA] - AndroidThunkJava_IapBeginPurchase");
|
|
|
|
|
boolean bTriggeredPurchase = false;
|
|
|
|
|
if( IapStoreHelper != null )
|
|
|
|
|
{
|
|
|
|
|
bTriggeredPurchase = IapStoreHelper.BeginPurchase(ProductId, bConsumable);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.debug("[JAVA] - Store Helper is invalid");
|
|
|
|
|
}
|
|
|
|
|
return bTriggeredPurchase;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean AndroidThunkJava_IapIsAllowedToMakePurchases()
|
|
|
|
|
{
|
|
|
|
|
Log.debug("[JAVA] - AndroidThunkJava_IapIsAllowedToMakePurchases");
|
|
|
|
|
boolean bIsAllowedToMakePurchase = false;
|
|
|
|
|
if( IapStoreHelper != null )
|
|
|
|
|
{
|
|
|
|
|
bIsAllowedToMakePurchase = IapStoreHelper.IsAllowedToMakePurchases();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.debug("[JAVA] - Store Helper is invalid");
|
|
|
|
|
}
|
|
|
|
|
return bIsAllowedToMakePurchase;
|
|
|
|
|
}
|
2014-09-12 11:37:24 -04:00
|
|
|
|
2015-12-10 16:56:55 -05:00
|
|
|
public boolean AndroidThunkJava_IapRestorePurchases()
|
|
|
|
|
{
|
|
|
|
|
Log.debug("[JAVA] - AndroidThunkJava_IapRestorePurchases");
|
|
|
|
|
boolean bTriggeredRestore = false;
|
|
|
|
|
if( IapStoreHelper != null )
|
|
|
|
|
{
|
|
|
|
|
Log.debug("[JAVA] - AndroidThunkJava_IapRestorePurchases - Kick off logic here!");
|
|
|
|
|
bTriggeredRestore = IapStoreHelper.RestorePurchases();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.debug("[JAVA] - Store Helper is invalid");
|
|
|
|
|
}
|
|
|
|
|
return bTriggeredRestore;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-28 19:34:42 -04:00
|
|
|
public void AndroidThunkJava_DismissSplashScreen()
|
|
|
|
|
{
|
|
|
|
|
if (mSplashDialog != null)
|
|
|
|
|
{
|
|
|
|
|
mSplashDialog.dismiss();
|
|
|
|
|
mSplashDialog = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-24 21:03:00 -04:00
|
|
|
private static class DeviceInfoData {
|
|
|
|
|
public final int vendorId;
|
|
|
|
|
public final int productId;
|
|
|
|
|
public final String name;
|
|
|
|
|
|
|
|
|
|
DeviceInfoData(int vid, int pid, String inName)
|
|
|
|
|
{
|
|
|
|
|
vendorId = vid;
|
|
|
|
|
productId = pid;
|
|
|
|
|
name = inName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean IsMatch(int vid, int pid)
|
|
|
|
|
{
|
|
|
|
|
return (vendorId == vid && productId == pid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// List of vendor/product ids
|
|
|
|
|
private static final DeviceInfoData[] DeviceInfoList = {
|
|
|
|
|
new DeviceInfoData(0x04e8, 0xa000, "Samsung Game Pad EI-GP20"),
|
|
|
|
|
new DeviceInfoData(0x0955, 0x7203, "NVIDIA Corporation NVIDIA Controller v01.01"),
|
|
|
|
|
new DeviceInfoData(0x0955, 0x7210, "NVIDIA Corporation NVIDIA Controller v01.03"),
|
|
|
|
|
new DeviceInfoData(0x1949, 0x0404, "Amazon Fire TV Remote"),
|
|
|
|
|
new DeviceInfoData(0x1949, 0x0406, "Amazon Fire Game Controller")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public class InputDeviceInfo {
|
|
|
|
|
public int deviceId;
|
|
|
|
|
public int vendorId;
|
|
|
|
|
public int productId;
|
|
|
|
|
public int controllerId;
|
|
|
|
|
public String name;
|
|
|
|
|
public String descriptor;
|
|
|
|
|
|
|
|
|
|
InputDeviceInfo(int did, int vid, int pid, int cid, String inName, String inDescriptor)
|
|
|
|
|
{
|
|
|
|
|
deviceId = did;
|
|
|
|
|
vendorId = vid;
|
|
|
|
|
productId = pid;
|
|
|
|
|
controllerId = cid;
|
|
|
|
|
name = inName;
|
|
|
|
|
descriptor = inDescriptor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public InputDeviceInfo AndroidThunkJava_GetInputDeviceInfo(int deviceId)
|
|
|
|
|
{
|
|
|
|
|
int[] deviceIds = InputDevice.getDeviceIds();
|
|
|
|
|
for (int deviceIndex=0; deviceIndex < deviceIds.length; deviceIndex++)
|
|
|
|
|
{
|
|
|
|
|
InputDevice inputDevice = InputDevice.getDevice(deviceIds[deviceIndex]);
|
|
|
|
|
if (inputDevice.getId() == deviceId)
|
|
|
|
|
{
|
2016-05-19 19:35:35 -04:00
|
|
|
int vendorId = 0;
|
|
|
|
|
int productId = 0;
|
|
|
|
|
int controllerNumber = 0;
|
|
|
|
|
|
|
|
|
|
// requires 4.1 (Jellybean)
|
|
|
|
|
String descriptor = ANDROID_BUILD_VERSION >= 16 ? inputDevice.getDescriptor() : Integer.toString(deviceId);
|
|
|
|
|
|
|
|
|
|
// supported on 4.4 (KitKat) onward
|
|
|
|
|
if (ANDROID_BUILD_VERSION >= 19)
|
2015-09-24 21:03:00 -04:00
|
|
|
{
|
2016-05-19 19:35:35 -04:00
|
|
|
vendorId = inputDevice.getVendorId();
|
|
|
|
|
productId = inputDevice.getProductId();
|
|
|
|
|
controllerNumber = inputDevice.getControllerNumber();
|
|
|
|
|
|
|
|
|
|
// note: inputDevice.getName may not return a proper name so check vendor and product id first
|
|
|
|
|
for (DeviceInfoData deviceInfo : DeviceInfoList)
|
2015-09-24 21:03:00 -04:00
|
|
|
{
|
2016-05-19 19:35:35 -04:00
|
|
|
if (deviceInfo.IsMatch(vendorId, productId))
|
|
|
|
|
{
|
|
|
|
|
return new InputDeviceInfo(deviceId, vendorId, productId, controllerNumber, deviceInfo.name, descriptor);
|
|
|
|
|
}
|
2015-09-24 21:03:00 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// use device name as fallback (may be generic like "Bluetooth HID" so not always useful)
|
2016-05-19 19:35:35 -04:00
|
|
|
return new InputDeviceInfo(deviceId, vendorId, productId, controllerNumber, inputDevice.getName(), descriptor);
|
2015-09-24 21:03:00 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new InputDeviceInfo(deviceId, 0, 0, -1, "Unknown", "Unknown");
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-10 16:56:55 -05:00
|
|
|
public void AndroidThunkJava_UseSurfaceViewWorkaround()
|
|
|
|
|
{
|
|
|
|
|
// We only need apply a change to the SurfaceHolder on the first call
|
|
|
|
|
// Once bUseSurfaceView is true, it is never changed back
|
|
|
|
|
if(bUseSurfaceView)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bUseSurfaceView = true;
|
|
|
|
|
Log.debug("[JAVA] Using SurfaceView sizing workaround for this device");
|
|
|
|
|
|
|
|
|
|
if(DesiredHolderWidth > 0 &&
|
|
|
|
|
DesiredHolderHeight > 0 &&
|
|
|
|
|
MySurfaceView != null)
|
|
|
|
|
{
|
|
|
|
|
_activity.runOnUiThread(new Runnable()
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void run()
|
|
|
|
|
{
|
|
|
|
|
MySurfaceView.getHolder().setFixedSize(DesiredHolderWidth, DesiredHolderHeight);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AndroidThunkJava_SetDesiredViewSize(int width, int height)
|
|
|
|
|
{
|
|
|
|
|
if (width == DesiredHolderWidth && height == DesiredHolderHeight)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.debug("[JAVA] - SetDesiredViewSize width=" + width + " and height=" + height);
|
|
|
|
|
DesiredHolderWidth = width;
|
|
|
|
|
DesiredHolderHeight = height;
|
|
|
|
|
|
|
|
|
|
if(bUseSurfaceView && MySurfaceView != null)
|
|
|
|
|
{
|
|
|
|
|
_activity.runOnUiThread(new Runnable()
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void run()
|
|
|
|
|
{
|
|
|
|
|
MySurfaceView.getHolder().setFixedSize(DesiredHolderWidth, DesiredHolderHeight);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-07 11:21:22 -05:00
|
|
|
public boolean AndroidThunkJava_HasMetaDataKey(String key)
|
|
|
|
|
{
|
|
|
|
|
if (_bundle == null || key == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return _bundle.containsKey(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean AndroidThunkJava_GetMetaDataBoolean(String key)
|
|
|
|
|
{
|
|
|
|
|
if (_bundle == null || key == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return _bundle.getBoolean(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int AndroidThunkJava_GetMetaDataInt(String key)
|
|
|
|
|
{
|
|
|
|
|
if (_bundle == null || key == null)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return _bundle.getInt(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String AndroidThunkJava_GetMetaDataString(String key)
|
|
|
|
|
{
|
|
|
|
|
if (_bundle == null || key == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return _bundle.getString(key);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
public native boolean nativeIsShippingBuild();
|
|
|
|
|
public native void nativeSetGlobalActivity();
|
2014-06-27 17:59:00 -04:00
|
|
|
public native void nativeSetWindowInfo(boolean bIsPortrait, int DepthBufferPreference);
|
2015-03-11 14:09:11 -04:00
|
|
|
public native void nativeSetObbInfo(String ProjectName, String PackageName, int Version, int PatchVersion);
|
2014-08-22 10:24:13 -04:00
|
|
|
public native void nativeSetAndroidVersionInformation( String AndroidVersion, String PhoneMake, String PhoneModel, String OSLanguage );
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2015-12-10 16:56:55 -05:00
|
|
|
public native void nativeSetSurfaceViewInfo(int width, int height);
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
public native void nativeConsoleCommand(String commandString);
|
2014-07-21 16:20:58 -04:00
|
|
|
public native void nativeVirtualKeyboardResult(boolean update, String contents);
|
2014-07-10 14:41:00 -04:00
|
|
|
|
2014-10-20 19:15:50 -04:00
|
|
|
public native void nativeInitHMDs();
|
|
|
|
|
|
2014-07-10 14:41:00 -04:00
|
|
|
public native void nativeResumeMainInit();
|
2015-01-27 18:30:20 -05:00
|
|
|
|
|
|
|
|
public native void nativeOnActivityResult(GameActivity activity, int requestCode, int resultCode, Intent data);
|
2015-04-22 11:14:29 -04:00
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
static
|
|
|
|
|
{
|
2014-08-18 15:45:13 -04:00
|
|
|
System.loadLibrary("gnustl_shared");
|
2015-12-10 16:56:55 -05:00
|
|
|
//$${soLoadLibrary}$$
|
2014-03-14 14:13:41 -04:00
|
|
|
System.loadLibrary("UE4");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|