mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-02-04 10:36:50 +00:00
Move RetroActivity based classes into their own package. Keeps them localized.
This commit is contained in:
parent
b2be996e67
commit
4b86d80408
@ -31,11 +31,11 @@
|
||||
<activity android:name="com.retroarch.browser.preferences.PreferenceActivity" android:theme="@style/Theme.AppCompat" />
|
||||
<activity android:name="com.retroarch.browser.coremanager.CoreManagerActivity" android:theme="@style/Theme.AppCompat"/>
|
||||
|
||||
<activity android:name="com.retroarch.browser.RetroActivityFuture" android:exported="true" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:launchMode="singleInstance">
|
||||
<activity android:name="com.retroarch.browser.retroactivity.RetroActivityFuture" android:exported="true" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:launchMode="singleInstance">
|
||||
<meta-data android:name="android.app.lib_name" android:value="retroarch-activity" />
|
||||
<meta-data android:name="android.app.func_name" android:value="ANativeActivity_onCreate" />
|
||||
</activity>
|
||||
<activity android:name="com.retroarch.browser.RetroActivityPast" android:exported="true" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:launchMode="singleInstance">
|
||||
<activity android:name="com.retroarch.browser.retroactivity.RetroActivityPast" android:exported="true" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:launchMode="singleInstance">
|
||||
<meta-data android:name="android.app.lib_name" android:value="retroarch-activity" />
|
||||
<meta-data android:name="android.app.func_name" android:value="ANativeActivity_onCreate" />
|
||||
</activity>
|
||||
|
@ -9,6 +9,8 @@ import java.io.InputStreamReader;
|
||||
import com.retroarch.R;
|
||||
import com.retroarch.browser.mainmenu.MainMenuActivity;
|
||||
import com.retroarch.browser.preferences.util.UserPreferences;
|
||||
import com.retroarch.browser.retroactivity.RetroActivityFuture;
|
||||
import com.retroarch.browser.retroactivity.RetroActivityPast;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
|
@ -1,255 +0,0 @@
|
||||
package com.retroarch.browser;
|
||||
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
import com.google.android.gms.common.GooglePlayServicesClient;
|
||||
import com.google.android.gms.location.LocationClient;
|
||||
import com.google.android.gms.location.LocationRequest;
|
||||
import com.retroarch.browser.preferences.util.UserPreferences;
|
||||
|
||||
import android.app.NativeActivity;
|
||||
import android.content.IntentSender;
|
||||
import android.content.SharedPreferences;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class RetroActivityLocation extends NativeActivity
|
||||
implements GooglePlayServicesClient.ConnectionCallbacks,
|
||||
GooglePlayServicesClient.OnConnectionFailedListener,
|
||||
LocationListener
|
||||
{
|
||||
/* LOCATION VARIABLES */
|
||||
private static int CONNECTION_FAILURE_RESOLUTION_REQUEST = 0;
|
||||
private LocationClient mLocationClient = null;
|
||||
private Location mCurrentLocation;
|
||||
//TODO - FIXME: We will want to make most of this configurable
|
||||
// Milliseconds per second
|
||||
private static final int MILLISECONDS_PER_SECOND = 1000;
|
||||
// Update frequency in seconds
|
||||
public static final int UPDATE_INTERVAL_IN_SECONDS = 5;
|
||||
// Update frequency in milliseconds
|
||||
private static final long UPDATE_INTERVAL =
|
||||
MILLISECONDS_PER_SECOND * UPDATE_INTERVAL_IN_SECONDS;
|
||||
// The fastest update frequency, in seconds
|
||||
private static final int FASTEST_INTERVAL_IN_SECONDS = 1;
|
||||
// A fast frequency ceiling in milliseconds
|
||||
private static final long FASTEST_INTERVAL =
|
||||
MILLISECONDS_PER_SECOND * FASTEST_INTERVAL_IN_SECONDS;
|
||||
// Define an object that holds accuracy and frequency parameters
|
||||
LocationRequest mLocationRequest = null;
|
||||
boolean mUpdatesRequested = false;
|
||||
boolean location_service_running = false;
|
||||
|
||||
/*
|
||||
* Called by Location Services when the request to connect the
|
||||
* client finishes successfully. At this point, you can
|
||||
* request the current location or start periodic updates
|
||||
*/
|
||||
@Override
|
||||
public void onConnected(Bundle dataBundle)
|
||||
{
|
||||
// Display the connection status
|
||||
Toast.makeText(this, "Connected", Toast.LENGTH_SHORT).show();
|
||||
// If already requested, start periodic updates
|
||||
if (mUpdatesRequested)
|
||||
{
|
||||
mLocationClient.requestLocationUpdates(mLocationRequest,
|
||||
(com.google.android.gms.location.LocationListener) this);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called by Location Services if the connection to the
|
||||
* location client drops because of an error.
|
||||
*/
|
||||
@Override
|
||||
public void onDisconnected()
|
||||
{
|
||||
// Display the connection status
|
||||
Toast.makeText(this, "Disconnected. Please re-connect.",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
/*
|
||||
* Called by Location Services if the attempt to
|
||||
* Location Services fails.
|
||||
*/
|
||||
@Override
|
||||
public void onConnectionFailed(ConnectionResult connectionResult)
|
||||
{
|
||||
/*
|
||||
* Google Play services can resolve some errors it detects.
|
||||
* If the error has a resolution, try sending an Intent to
|
||||
* start a Google Play services activity that can resolve
|
||||
* error.
|
||||
*/
|
||||
if (connectionResult.hasResolution())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Start an Activity that tries to resolve the error
|
||||
connectionResult.startResolutionForResult(
|
||||
this,
|
||||
CONNECTION_FAILURE_RESOLUTION_REQUEST);
|
||||
/*
|
||||
* Thrown if Google Play services cancelled the original
|
||||
* PendingIntent
|
||||
*/
|
||||
}
|
||||
catch (IntentSender.SendIntentException e)
|
||||
{
|
||||
// Log the error
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* If no resolution is available, display a dialog to the
|
||||
* user with the error.
|
||||
*/
|
||||
//showErrorDialog(connectionResult.getErrorCode());
|
||||
}
|
||||
}
|
||||
|
||||
public void onLocationInit()
|
||||
{
|
||||
/*
|
||||
* Create a new location client, using the enclosing class to
|
||||
* handle callbacks.
|
||||
*/
|
||||
if (mLocationClient == null)
|
||||
mLocationClient = new LocationClient(this, this, this);
|
||||
// Start with updates turned off
|
||||
mUpdatesRequested = false;
|
||||
|
||||
//TODO - FIXME
|
||||
/* Split this logic up into a separate function
|
||||
* and make it configurable - callback parameters
|
||||
* should be configurable
|
||||
*/
|
||||
|
||||
// Create the LocationRequest object
|
||||
if (mLocationRequest == null)
|
||||
mLocationRequest = LocationRequest.create();
|
||||
// Use high accuracy
|
||||
mLocationRequest.setPriority(
|
||||
LocationRequest.PRIORITY_HIGH_ACCURACY);
|
||||
// Set the update interval to 5 seconds
|
||||
mLocationRequest.setInterval(UPDATE_INTERVAL);
|
||||
// Set the fastest update interval to 1 second
|
||||
mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
|
||||
|
||||
}
|
||||
|
||||
public void onLocationStart()
|
||||
{
|
||||
if (location_service_running)
|
||||
return;
|
||||
|
||||
// Connect the client.
|
||||
mLocationClient.connect();
|
||||
|
||||
// Get last known location
|
||||
mCurrentLocation = mLocationClient.getLastLocation();
|
||||
location_service_running = true;
|
||||
}
|
||||
|
||||
public void onLocationStop()
|
||||
{
|
||||
if (!location_service_running)
|
||||
return;
|
||||
|
||||
// If the client is connected
|
||||
if (mLocationClient.isConnected())
|
||||
{
|
||||
/*
|
||||
* Remove location updates for a listener.
|
||||
* The current Activity is the listener, so
|
||||
* the argument is "this".
|
||||
*/
|
||||
mLocationClient.removeLocationUpdates((com.google.android.gms.location.LocationListener) this);
|
||||
}
|
||||
|
||||
if (location_service_running)
|
||||
{
|
||||
// Disconnecting the client invalidates it.
|
||||
mLocationClient.disconnect();
|
||||
}
|
||||
location_service_running = false;
|
||||
}
|
||||
|
||||
public double onLocationGetLatitude()
|
||||
{
|
||||
return mCurrentLocation.getLatitude();
|
||||
}
|
||||
|
||||
public double onLocationGetLongitude()
|
||||
{
|
||||
return mCurrentLocation.getLongitude();
|
||||
}
|
||||
|
||||
// Define the callback method that receives location updates
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
mCurrentLocation = location;
|
||||
// Report to the UI that the location was updated
|
||||
String msg = "Updated Location: " +
|
||||
Double.toString(location.getLatitude()) + "," +
|
||||
Double.toString(location.getLongitude());
|
||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
public void onStatusChanged(String provider, int status, Bundle extras) {}
|
||||
|
||||
public void onProviderEnabled(String provider) {}
|
||||
|
||||
public void onProviderDisabled(String provider) {}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
// Save the current setting for updates
|
||||
SharedPreferences prefs = UserPreferences.getPreferences(this);
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
edit.putBoolean("LOCATION_UPDATES_ON", mUpdatesRequested);
|
||||
edit.commit();
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
SharedPreferences prefs = UserPreferences.getPreferences(this);
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
|
||||
/*
|
||||
* Get any previous setting for location updates
|
||||
* Gets "false" if an error occurs
|
||||
*/
|
||||
if (prefs.contains("LOCATION_UPDATES_ON"))
|
||||
{
|
||||
mUpdatesRequested = prefs.getBoolean("LOCATION_UPDATES_ON", false);
|
||||
if (mUpdatesRequested)
|
||||
location_service_running = true;
|
||||
// Otherwise, turn off location updates
|
||||
}
|
||||
else
|
||||
{
|
||||
edit.putBoolean("LOCATION_UPDATES_ON", false);
|
||||
edit.commit();
|
||||
location_service_running = false;
|
||||
}
|
||||
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
onLocationStop();
|
||||
super.onStop();
|
||||
}
|
||||
}
|
@ -28,13 +28,13 @@ import com.retroarch.R;
|
||||
import com.retroarch.browser.CoreSelection;
|
||||
import com.retroarch.browser.HistorySelection;
|
||||
import com.retroarch.browser.NativeInterface;
|
||||
import com.retroarch.browser.RetroActivityFuture;
|
||||
import com.retroarch.browser.RetroActivityPast;
|
||||
import com.retroarch.browser.dirfragment.DirectoryFragment;
|
||||
import com.retroarch.browser.dirfragment.DirectoryFragment.OnDirectoryFragmentClosedListener;
|
||||
import com.retroarch.browser.mainmenu.gplwaiver.GPLWaiverDialogFragment;
|
||||
import com.retroarch.browser.preferences.fragments.util.PreferenceListFragment;
|
||||
import com.retroarch.browser.preferences.util.UserPreferences;
|
||||
import com.retroarch.browser.retroactivity.RetroActivityFuture;
|
||||
import com.retroarch.browser.retroactivity.RetroActivityPast;
|
||||
|
||||
/**
|
||||
* Represents the fragment that handles the layout of the main menu.
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.retroarch.browser;
|
||||
package com.retroarch.browser.retroactivity;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -15,14 +15,23 @@ import android.util.Log;
|
||||
|
||||
//For Android 3.0 and up
|
||||
|
||||
/**
|
||||
* Class which provides {@link Camera} functionality
|
||||
* to {@link RetroActivityFuture}.
|
||||
*/
|
||||
@SuppressLint("NewApi")
|
||||
public class RetroActivityCamera extends RetroActivityCommon {
|
||||
public class RetroActivityCamera extends RetroActivityCommon
|
||||
{
|
||||
private Camera mCamera = null;
|
||||
private long lastTimestamp = 0;
|
||||
private SurfaceTexture texture;
|
||||
private boolean updateSurface = true;
|
||||
private boolean camera_service_running = false;
|
||||
|
||||
/**
|
||||
* Executed when the {@link Camera}
|
||||
* is staring to capture.
|
||||
*/
|
||||
public void onCameraStart()
|
||||
{
|
||||
if (camera_service_running)
|
||||
@ -32,6 +41,13 @@ public class RetroActivityCamera extends RetroActivityCommon {
|
||||
camera_service_running = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executed when the {@link Camera} is done capturing.
|
||||
* <p>
|
||||
* Note that this does not release the currently held
|
||||
* {@link Camera} instance and must be freed by calling
|
||||
* {@link #onCameraFree}
|
||||
*/
|
||||
public void onCameraStop()
|
||||
{
|
||||
if (!camera_service_running)
|
||||
@ -40,13 +56,19 @@ public class RetroActivityCamera extends RetroActivityCommon {
|
||||
mCamera.stopPreview();
|
||||
camera_service_running = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Releases the currently held {@link Camera} instance.
|
||||
*/
|
||||
public void onCameraFree()
|
||||
{
|
||||
onCameraStop();
|
||||
mCamera.release();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the camera for use.
|
||||
*/
|
||||
public void onCameraInit()
|
||||
{
|
||||
if (mCamera != null)
|
||||
@ -55,6 +77,11 @@ public class RetroActivityCamera extends RetroActivityCommon {
|
||||
mCamera = Camera.open();
|
||||
}
|
||||
|
||||
/**
|
||||
* Polls the camera for updates to the {@link SurfaceTexture}.
|
||||
*
|
||||
* @return true if polling was successful, false otherwise.
|
||||
*/
|
||||
public boolean onCameraPoll()
|
||||
{
|
||||
if (!camera_service_running)
|
||||
@ -85,82 +112,35 @@ public class RetroActivityCamera extends RetroActivityCommon {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
// Save the current setting for updates
|
||||
SharedPreferences prefs = UserPreferences.getPreferences(this);
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
edit.putBoolean("CAMERA_UPDATES_ON", false);
|
||||
edit.commit();
|
||||
|
||||
camera_service_running = false;
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
// Save the current setting for updates
|
||||
SharedPreferences prefs = UserPreferences.getPreferences(this);
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
edit.putBoolean("CAMERA_UPDATES_ON", camera_service_running);
|
||||
edit.commit();
|
||||
|
||||
onCameraStop();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
SharedPreferences prefs = UserPreferences.getPreferences(this);
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
|
||||
/*
|
||||
* Get any previous setting for camera updates
|
||||
* Gets "false" if an error occurs
|
||||
*/
|
||||
if (prefs.contains("CAMERA_UPDATES_ON"))
|
||||
{
|
||||
camera_service_running = prefs.getBoolean("CAMERA_UPDATES_ON", false);
|
||||
if (camera_service_running)
|
||||
{
|
||||
onCameraStart();
|
||||
}
|
||||
// Otherwise, turn off camera updates
|
||||
}
|
||||
else
|
||||
{
|
||||
edit.putBoolean("CAMERA_UPDATES_ON", false);
|
||||
edit.commit();
|
||||
camera_service_running = false;
|
||||
}
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy()
|
||||
{
|
||||
onCameraFree();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
onCameraStop();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the {@link SurfaceTexture} used by the
|
||||
* {@link Camera} with a given OpenGL texure ID.
|
||||
*
|
||||
* @param gl_texid texture ID to initialize the
|
||||
* {@link SurfaceTexture} with.
|
||||
*/
|
||||
public void onCameraTextureInit(int gl_texid)
|
||||
{
|
||||
texture = new SurfaceTexture(gl_texid);
|
||||
texture.setOnFrameAvailableListener(onCameraFrameAvailableListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link Camera} texture with the texture represented
|
||||
* by the given OpenGL texture ID.
|
||||
*
|
||||
* @param gl_texid The texture ID representing the texture to set the camera to.
|
||||
* @throws IOException If setting the texture fails.
|
||||
*/
|
||||
public void onCameraSetTexture(int gl_texid) throws IOException
|
||||
{
|
||||
if (texture == null)
|
||||
onCameraTextureInit(gl_texid);
|
||||
|
||||
mCamera.setPreviewTexture(texture);
|
||||
}
|
||||
|
||||
private final OnFrameAvailableListener onCameraFrameAvailableListener = new OnFrameAvailableListener()
|
||||
{
|
||||
@Override
|
||||
@ -170,11 +150,71 @@ public class RetroActivityCamera extends RetroActivityCommon {
|
||||
}
|
||||
};
|
||||
|
||||
public void onCameraSetTexture(int gl_texid) throws IOException
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
if (texture == null)
|
||||
onCameraTextureInit(gl_texid);
|
||||
// Save the current setting for updates
|
||||
SharedPreferences prefs = UserPreferences.getPreferences(this);
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
edit.putBoolean("CAMERA_UPDATES_ON", false);
|
||||
edit.commit();
|
||||
|
||||
mCamera.setPreviewTexture(texture);
|
||||
camera_service_running = false;
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
// Save the current setting for updates
|
||||
SharedPreferences prefs = UserPreferences.getPreferences(this);
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
edit.putBoolean("CAMERA_UPDATES_ON", camera_service_running);
|
||||
edit.commit();
|
||||
|
||||
onCameraStop();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
SharedPreferences prefs = UserPreferences.getPreferences(this);
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
|
||||
/*
|
||||
* Get any previous setting for camera updates
|
||||
* Gets "false" if an error occurs
|
||||
*/
|
||||
if (prefs.contains("CAMERA_UPDATES_ON"))
|
||||
{
|
||||
camera_service_running = prefs.getBoolean("CAMERA_UPDATES_ON", false);
|
||||
if (camera_service_running)
|
||||
{
|
||||
onCameraStart();
|
||||
}
|
||||
}
|
||||
else // Otherwise, turn off camera updates
|
||||
{
|
||||
edit.putBoolean("CAMERA_UPDATES_ON", false);
|
||||
edit.commit();
|
||||
camera_service_running = false;
|
||||
}
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy()
|
||||
{
|
||||
onCameraFree();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
onCameraStop();
|
||||
super.onStop();
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.retroarch.browser;
|
||||
package com.retroarch.browser.retroactivity;
|
||||
|
||||
import com.retroarch.browser.mainmenu.MainMenuActivity;
|
||||
import com.retroarch.browser.preferences.util.UserPreferences;
|
||||
@ -6,6 +6,9 @@ import com.retroarch.browser.preferences.util.UserPreferences;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Class which provides common methods for RetroActivity related classes.
|
||||
*/
|
||||
public class RetroActivityCommon extends RetroActivityLocation
|
||||
{
|
||||
private Intent pendingIntent = null;
|
||||
@ -19,42 +22,73 @@ public class RetroActivityCommon extends RetroActivityLocation
|
||||
pendingIntent = intent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ROM file specified in the pending intent.
|
||||
*
|
||||
* @return the ROM file specified in the pending intent.
|
||||
*/
|
||||
public String getPendingIntentFullPath()
|
||||
{
|
||||
return pendingIntent.getStringExtra("ROM");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the specified path to the libretro core in the pending intent.
|
||||
*
|
||||
* @return the specified path to the libretro core in the pending intent.
|
||||
*/
|
||||
public String getPendingIntentLibretroPath()
|
||||
{
|
||||
return pendingIntent.getStringExtra("LIBRETRO");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path specified in the pending intent to the retroarch cfg file.
|
||||
*
|
||||
* @return the path specified in the pending intent to the retroarch cfg file.
|
||||
*/
|
||||
public String getPendingIntentConfigPath()
|
||||
{
|
||||
return pendingIntent.getStringExtra("CONFIGFILE");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the specified IME in the pending intent.
|
||||
*
|
||||
* @return the specified IME in the pending intent.
|
||||
*/
|
||||
public String getPendingIntentIME()
|
||||
{
|
||||
return pendingIntent.getStringExtra("IME");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not a pending intent exists.
|
||||
*
|
||||
* @return true if a pending intent exists, false otherwise.
|
||||
*/
|
||||
public boolean hasPendingIntent()
|
||||
{
|
||||
if (pendingIntent == null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the current pending intent.
|
||||
*/
|
||||
public void clearPendingIntent()
|
||||
{
|
||||
pendingIntent = null;
|
||||
}
|
||||
|
||||
|
||||
/* MISC
|
||||
* Other RetroArch functions */
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* MISC
|
||||
* Other RetroArch functions
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onDestroy()
|
||||
{
|
||||
@ -79,7 +113,12 @@ public class RetroActivityCommon extends RetroActivityLocation
|
||||
retro.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
startActivity(retro);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the current Android version being used on a device.
|
||||
*
|
||||
* @return the current Android version.
|
||||
*/
|
||||
public int getAndroidOSVersion()
|
||||
{
|
||||
return android.os.Build.VERSION.SDK_INT;
|
@ -1,4 +1,4 @@
|
||||
package com.retroarch.browser;
|
||||
package com.retroarch.browser.retroactivity;
|
||||
|
||||
public final class RetroActivityFuture extends RetroActivityCamera
|
||||
{
|
@ -0,0 +1,288 @@
|
||||
package com.retroarch.browser.retroactivity;
|
||||
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
import com.google.android.gms.common.GooglePlayServicesClient;
|
||||
import com.google.android.gms.location.LocationClient;
|
||||
import com.google.android.gms.location.LocationRequest;
|
||||
import com.retroarch.browser.preferences.util.UserPreferences;
|
||||
|
||||
import android.app.NativeActivity;
|
||||
import android.content.IntentSender;
|
||||
import android.content.SharedPreferences;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* Class that implements location-based functionality for
|
||||
* the {@link RetroActivityFuture} and {@link RetroActivityPast}
|
||||
* activities.
|
||||
*/
|
||||
public class RetroActivityLocation extends NativeActivity
|
||||
implements GooglePlayServicesClient.ConnectionCallbacks,
|
||||
GooglePlayServicesClient.OnConnectionFailedListener,
|
||||
LocationListener
|
||||
{
|
||||
/* LOCATION VARIABLES */
|
||||
private static int CONNECTION_FAILURE_RESOLUTION_REQUEST = 0;
|
||||
private LocationClient mLocationClient = null;
|
||||
private Location mCurrentLocation;
|
||||
|
||||
//TODO - FIXME: We will want to make most of this configurable
|
||||
// Milliseconds per second
|
||||
private static final int MILLISECONDS_PER_SECOND = 1000;
|
||||
// Update frequency in seconds */
|
||||
private static final int UPDATE_INTERVAL_IN_SECONDS = 5;
|
||||
// Update frequency in milliseconds
|
||||
private static final long UPDATE_INTERVAL = (MILLISECONDS_PER_SECOND * UPDATE_INTERVAL_IN_SECONDS);
|
||||
// The fastest update frequency, in seconds
|
||||
private static final int FASTEST_INTERVAL_IN_SECONDS = 1;
|
||||
// A fast frequency ceiling in milliseconds
|
||||
private static final long FASTEST_INTERVAL = (MILLISECONDS_PER_SECOND * FASTEST_INTERVAL_IN_SECONDS);
|
||||
// Define an object that holds accuracy and frequency parameters
|
||||
LocationRequest mLocationRequest = null;
|
||||
boolean mUpdatesRequested = false;
|
||||
boolean location_service_running = false;
|
||||
|
||||
/*
|
||||
* Called by Location Services when the request to connect the
|
||||
* client finishes successfully. At this point, you can
|
||||
* request the current location or start periodic updates
|
||||
*/
|
||||
@Override
|
||||
public void onConnected(Bundle dataBundle)
|
||||
{
|
||||
// Display the connection status
|
||||
Toast.makeText(this, "Connected", Toast.LENGTH_SHORT).show();
|
||||
// If already requested, start periodic updates
|
||||
if (mUpdatesRequested)
|
||||
{
|
||||
mLocationClient.requestLocationUpdates(mLocationRequest,
|
||||
(com.google.android.gms.location.LocationListener) this);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called by Location Services if the connection to the
|
||||
* location client drops because of an error.
|
||||
*/
|
||||
@Override
|
||||
public void onDisconnected()
|
||||
{
|
||||
// Display the connection status
|
||||
Toast.makeText(this, "Disconnected. Please re-connect.",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
/*
|
||||
* Called by Location Services if the attempt to
|
||||
* Location Services fails.
|
||||
*/
|
||||
@Override
|
||||
public void onConnectionFailed(ConnectionResult connectionResult)
|
||||
{
|
||||
/*
|
||||
* Google Play services can resolve some errors it detects.
|
||||
* If the error has a resolution, try sending an Intent to
|
||||
* start a Google Play services activity that can resolve
|
||||
* error.
|
||||
*/
|
||||
if (connectionResult.hasResolution())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Start an Activity that tries to resolve the error
|
||||
connectionResult.startResolutionForResult(
|
||||
this,
|
||||
CONNECTION_FAILURE_RESOLUTION_REQUEST);
|
||||
/*
|
||||
* Thrown if Google Play services cancelled the original
|
||||
* PendingIntent
|
||||
*/
|
||||
}
|
||||
catch (IntentSender.SendIntentException e)
|
||||
{
|
||||
// Log the error
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* If no resolution is available, display a dialog to the
|
||||
* user with the error.
|
||||
*/
|
||||
//showErrorDialog(connectionResult.getErrorCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializing methods for location based functionality.
|
||||
*/
|
||||
public void onLocationInit()
|
||||
{
|
||||
/*
|
||||
* Create a new location client, using the enclosing class to
|
||||
* handle callbacks.
|
||||
*/
|
||||
if (mLocationClient == null)
|
||||
mLocationClient = new LocationClient(this, this, this);
|
||||
// Start with updates turned off
|
||||
mUpdatesRequested = false;
|
||||
|
||||
//TODO - FIXME
|
||||
/* Split this logic up into a separate function
|
||||
* and make it configurable - callback parameters
|
||||
* should be configurable
|
||||
*/
|
||||
|
||||
// Create the LocationRequest object
|
||||
if (mLocationRequest == null)
|
||||
mLocationRequest = LocationRequest.create();
|
||||
|
||||
// Use high accuracy
|
||||
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
|
||||
// Set the update interval to 5 seconds
|
||||
mLocationRequest.setInterval(UPDATE_INTERVAL);
|
||||
// Set the fastest update interval to 1 second
|
||||
mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Executed upon starting the {@link LocationClient}.
|
||||
*/
|
||||
public void onLocationStart()
|
||||
{
|
||||
if (location_service_running)
|
||||
return;
|
||||
|
||||
// Connect the client.
|
||||
mLocationClient.connect();
|
||||
|
||||
// Get last known location
|
||||
mCurrentLocation = mLocationClient.getLastLocation();
|
||||
location_service_running = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executed upon stopping the location client.
|
||||
* Does nothing if called when the client is not started.
|
||||
*/
|
||||
public void onLocationStop()
|
||||
{
|
||||
if (!location_service_running)
|
||||
return;
|
||||
|
||||
// If the client is connected
|
||||
if (mLocationClient.isConnected())
|
||||
{
|
||||
/*
|
||||
* Remove location updates for a listener.
|
||||
* The current Activity is the listener, so
|
||||
* the argument is "this".
|
||||
*/
|
||||
mLocationClient.removeLocationUpdates((com.google.android.gms.location.LocationListener) this);
|
||||
}
|
||||
|
||||
if (location_service_running)
|
||||
{
|
||||
// Disconnecting the client invalidates it.
|
||||
mLocationClient.disconnect();
|
||||
}
|
||||
|
||||
location_service_running = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the latitude at the current location in degrees.
|
||||
*
|
||||
* @return the latitude at the current location.
|
||||
*/
|
||||
public double onLocationGetLatitude()
|
||||
{
|
||||
return mCurrentLocation.getLatitude();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the longtude at the current location in degrees.
|
||||
*
|
||||
* @return the longitude at the current location.
|
||||
*/
|
||||
public double onLocationGetLongitude()
|
||||
{
|
||||
return mCurrentLocation.getLongitude();
|
||||
}
|
||||
|
||||
// Define the callback method that receives location updates
|
||||
@Override
|
||||
public void onLocationChanged(Location location)
|
||||
{
|
||||
mCurrentLocation = location;
|
||||
|
||||
// Report to the UI that the location was updated
|
||||
String msg = "Updated Location: " + location.getLatitude() + ", " + location.getLongitude();
|
||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(String provider, int status, Bundle extras)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String provider)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderDisabled(String provider)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
// Save the current setting for updates
|
||||
SharedPreferences prefs = UserPreferences.getPreferences(this);
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
edit.putBoolean("LOCATION_UPDATES_ON", mUpdatesRequested);
|
||||
edit.commit();
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
SharedPreferences prefs = UserPreferences.getPreferences(this);
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
|
||||
/*
|
||||
* Get any previous setting for location updates
|
||||
* Gets "false" if an error occurs
|
||||
*/
|
||||
if (prefs.contains("LOCATION_UPDATES_ON"))
|
||||
{
|
||||
mUpdatesRequested = prefs.getBoolean("LOCATION_UPDATES_ON", false);
|
||||
if (mUpdatesRequested)
|
||||
location_service_running = true;
|
||||
}
|
||||
else // Otherwise, turn off location updates
|
||||
{
|
||||
edit.putBoolean("LOCATION_UPDATES_ON", false);
|
||||
edit.commit();
|
||||
location_service_running = false;
|
||||
}
|
||||
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
onLocationStop();
|
||||
super.onStop();
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.retroarch.browser;
|
||||
package com.retroarch.browser.retroactivity;
|
||||
|
||||
// For Android 2.3.x
|
||||
|
Loading…
x
Reference in New Issue
Block a user