Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 package com.github.rosjava.android_remocons.robot_remocon;
00036
00037 import java.net.URI;
00038 import java.util.ArrayList;
00039
00040 import android.app.AlertDialog;
00041 import android.content.ActivityNotFoundException;
00042 import android.content.DialogInterface;
00043 import android.content.Intent;
00044 import android.net.Uri;
00045 import android.util.Log;
00046
00047 import com.github.rosjava.android_apps.application_management.AppManager;
00048 import com.github.rosjava.android_apps.application_management.RobotDescription;
00049
00050 import rocon_app_manager_msgs.PairingClient;
00051
00052 public class AppLauncher {
00053 static private final String CLIENT_TYPE = "android";
00054
00055
00057 static public boolean launch(final RobotActivity parentActivity, rocon_app_manager_msgs.App app, URI uri,RobotDescription currentRobot,boolean runningNodes) {
00058 ArrayList<ClientAppData> android_apps = new ArrayList<ClientAppData>();
00059
00060
00061 if (parentActivity instanceof RobotRemocon) {
00062 ((RobotRemocon)parentActivity).onAppClicked(app, app.getPairingClients().size() > 0);
00063 } else {
00064 Log.i("RobotRemocon", "Could not launch because parent is not an appchooser");
00065 if (app.getPairingClients().size() == 0) {
00066 Log.e("RobotRemocon", "Not launching application!!!");
00067 return false;
00068 }
00069 }
00070
00071 if (app.getPairingClients().size() == 0) {
00072 return false;
00073 }
00074
00075 Log.i("RobotRemocon", "launching robot app " + app.getName() + " -> found " + app.getPairingClients().size()
00076 + " client apps.");
00077
00078
00079 for (int i = 0; i < app.getPairingClients().size(); i++) {
00080 PairingClient client_app = app.getPairingClients().get(i);
00081 if (client_app.getClientType() != null && client_app.getClientType().equals(CLIENT_TYPE)) {
00082 ClientAppData data = new ClientAppData(client_app);
00083 android_apps.add(data);
00084 }
00085 }
00086
00087 Log.i("RobotRemocon", "launching robot app " + app.getName() + " -> found " + android_apps.size()
00088 + " compatible android apps.");
00089
00090
00091
00092
00093 ArrayList<ClientAppData> appropriateAndroidApps = android_apps;
00094
00095
00096
00097 if (appropriateAndroidApps.size() != 1) {
00098 AlertDialog.Builder dialog = new AlertDialog.Builder(parentActivity);
00099 dialog.setTitle("Wrong Number of Android Apps");
00100 dialog.setMessage("There are " + appropriateAndroidApps.size() + " valid android apps, not 1 as there should be.");
00101 dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
00102 @Override
00103 public void onClick(DialogInterface dlog, int i) {
00104 dlog.dismiss();
00105 }});
00106 dialog.show();
00107 return false;
00108 }
00109
00110
00111 String className = "";
00112
00113
00114 for (int i = 0; i < appropriateAndroidApps.size(); i++) {
00115 ClientAppData appData = appropriateAndroidApps.get(i);
00116 Intent intent = appData.createIntent();
00117 intent.putExtra(AppManager.PACKAGE + ".robot_app_name", app.getName());
00118 intent.putExtra(RobotDescription.UNIQUE_KEY, currentRobot);
00119 intent.putExtra("ChooserURI", uri.toString());
00120 intent.putExtra("runningNodes", runningNodes);
00121 intent.putExtra("PairedManagerActivity", "com.github.robotics_in_concert.rocon_android.robot_remocon.RobotRemocon");
00122 try {
00123 className = intent.getAction();
00124 Log.i("RobotRemocon", "trying to startActivity( action: " + intent.getAction() + " )");
00125 parentActivity.startActivity(intent);
00126 return true;
00127 } catch (ActivityNotFoundException e) {
00128 Log.i("RobotRemocon", "activity not found for action: " + intent.getAction());
00129 }
00130 }
00131
00132 final String installPackage = className.substring(0, className.lastIndexOf("."));
00133
00134 Log.i("RobotRemocon", "showing not-installed dialog.");
00135
00136
00137
00138
00139 AlertDialog.Builder dialog = new AlertDialog.Builder(parentActivity);
00140 dialog.setTitle("Android app not installed.");
00141 dialog
00142 .setMessage("This robot app requires a client user interface app, but none of the applicable android apps are installed. Would you like to install the app from the market place?");
00143 dialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
00144 @Override
00145 public void onClick(DialogInterface dlog, int i) {
00146 Uri uri = Uri.parse("market://details?id=" + installPackage);
00147 Intent intent = new Intent(Intent.ACTION_VIEW, uri);
00148 parentActivity.startActivity(intent);
00149 }
00150 });
00151 dialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
00152 @Override
00153 public void onClick(DialogInterface dlog, int i) {
00154 dlog.dismiss();
00155 }
00156 });
00157 dialog.show();
00158 return false;
00159 }
00160 }