diff --git a/FtcRobotController/.idea/gradle.xml b/FtcRobotController/.idea/gradle.xml index c49011e..4bd6cc3 100644 --- a/FtcRobotController/.idea/gradle.xml +++ b/FtcRobotController/.idea/gradle.xml @@ -5,12 +5,19 @@ diff --git a/FtcRobotController/.idea/modules.xml b/FtcRobotController/.idea/modules.xml index 31c8126..77165fc 100644 --- a/FtcRobotController/.idea/modules.xml +++ b/FtcRobotController/.idea/modules.xml @@ -2,8 +2,15 @@ + + + + + + + \ No newline at end of file diff --git a/FtcRobotController/Analytics/.gitignore b/FtcRobotController/Analytics/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/FtcRobotController/Analytics/.gitignore @@ -0,0 +1 @@ +/build diff --git a/FtcRobotController/Analytics/Analytics.iml b/FtcRobotController/Analytics/Analytics.iml new file mode 100644 index 0000000..0b669eb --- /dev/null +++ b/FtcRobotController/Analytics/Analytics.iml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/FtcRobotController/Analytics/build.gradle b/FtcRobotController/Analytics/build.gradle new file mode 100644 index 0000000..f8bc75c --- /dev/null +++ b/FtcRobotController/Analytics/build.gradle @@ -0,0 +1,29 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 22 + buildToolsVersion '22.0.1' + + defaultConfig { + minSdkVersion 19 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } +} + +dependencies { + compile fileTree(include: ['*.jar'], dir: 'libs') + testCompile 'junit:junit:4.12' + compile project(':robotcore') +} diff --git a/FtcRobotController/Analytics/proguard-rules.pro b/FtcRobotController/Analytics/proguard-rules.pro new file mode 100644 index 0000000..db73af4 --- /dev/null +++ b/FtcRobotController/Analytics/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\Public\Android\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/FtcRobotController/Analytics/src/androidTest/java/com/qualcomm/analytics/ApplicationTest.java b/FtcRobotController/Analytics/src/androidTest/java/com/qualcomm/analytics/ApplicationTest.java new file mode 100644 index 0000000..fd7fd3d --- /dev/null +++ b/FtcRobotController/Analytics/src/androidTest/java/com/qualcomm/analytics/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.qualcomm.analytics; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/FtcRobotController/Analytics/src/main/AndroidManifest.xml b/FtcRobotController/Analytics/src/main/AndroidManifest.xml new file mode 100644 index 0000000..b67db6f --- /dev/null +++ b/FtcRobotController/Analytics/src/main/AndroidManifest.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/analytics/Analytics.java b/FtcRobotController/Analytics/src/main/java/com/qualcomm/analytics/Analytics.java similarity index 87% rename from FtcRobotController/app/src/main/java/com/qualcomm/analytics/Analytics.java rename to FtcRobotController/Analytics/src/main/java/com/qualcomm/analytics/Analytics.java index 30c34a7..08e39fe 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/analytics/Analytics.java +++ b/FtcRobotController/Analytics/src/main/java/com/qualcomm/analytics/Analytics.java @@ -1,568 +1,568 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package com.qualcomm.analytics; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.SharedPreferences; -import android.content.SharedPreferences.Editor; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.net.NetworkInfo.State; -import android.os.AsyncTask; -import android.os.Build; -import android.os.Bundle; -import android.os.Environment; -import android.preference.PreferenceManager; -import com.qualcomm.robotcore.hardware.DcMotorController; -import com.qualcomm.robotcore.hardware.HardwareMap; -import com.qualcomm.robotcore.hardware.ServoController; -import com.qualcomm.robotcore.util.RobotLog; -import com.qualcomm.robotcore.util.Version; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.EOFException; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.OutputStreamWriter; -import java.io.Serializable; -import java.io.UnsupportedEncodingException; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLEncoder; -import java.nio.charset.Charset; -import java.security.SecureRandom; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Locale; -import java.util.UUID; -import java.util.regex.Pattern; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.KeyManager; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; - -public class Analytics extends BroadcastReceiver { - public static final String UUID_PATH = ".analytics_id"; - public static final String DATA_COLLECTION_PATH = ".ftcdc"; - static String a = "https://ftcdc.qualcomm.com/DataApi"; - public static final String RC_COMMAND_STRING = "update_rc"; - public static final String DS_COMMAND_STRING = "update_ds"; - public static final String EXTERNAL_STORAGE_DIRECTORY_PATH = Environment.getExternalStorageDirectory() + "/"; - public static final String LAST_UPLOAD_DATE = "last_upload_date"; - public static final String MAX_DEVICES = "max_usb_devices"; - public static int MAX_ENTRIES_SIZE = 100; - public static int TRIMMED_SIZE = 90; - private static final Charset m = Charset.forName("UTF-8"); - static long b; - static UUID c = null; - static String d; - String e; - static String f = ""; - Context g; - SharedPreferences h; - boolean i = false; - long j = 0L; - int k = 0; - static final HostnameVerifier l = new HostnameVerifier() { - public boolean verify(String hostname, SSLSession session) { - return true; - } - }; - - public void onReceive(Context context, Intent intent) { - Bundle var3 = intent.getExtras(); - if(var3 != null && var3.containsKey("networkInfo")) { - NetworkInfo var4 = (NetworkInfo)var3.get("networkInfo"); - State var5 = var4.getState(); - if(var5.equals(State.CONNECTED)) { - RobotLog.i("Analytics detected NetworkInfo.State.CONNECTED"); - this.communicateWithServer(); - } - } - - } - - public void unregister() { - this.g.unregisterReceiver(this); - } - - public void register() { - this.g.registerReceiver(this, new IntentFilter("android.net.wifi.STATE_CHANGE")); - } - - public Analytics(Context context, String commandString, HardwareMap map) { - this.g = context; - this.e = commandString; - - try { - try { - this.h = PreferenceManager.getDefaultSharedPreferences(context); - b = System.currentTimeMillis(); - f = Version.getLibraryVersion(); - this.handleUUID(".analytics_id"); - int var4 = this.calculateUsbDevices(map); - int var5 = this.h.getInt("max_usb_devices", this.k); - if(var5 < var4) { - Editor var6 = this.h.edit(); - var6.putInt("max_usb_devices", var4); - var6.apply(); - } - - setApplicationName(context.getApplicationInfo().loadLabel(context.getPackageManager()).toString()); - this.handleData(); - this.register(); - RobotLog.i("Analytics has completed initialization."); - } catch (Exception var7) { - this.i = true; - } - - if(this.i) { - this.a(); - this.i = false; - } - } catch (Exception var8) { - RobotLog.i("Analytics encountered a problem during initialization"); - RobotLog.logStacktrace(var8); - } - - } - - protected int calculateUsbDevices(HardwareMap map) { - byte var2 = 0; - int var7 = var2 + map.legacyModule.size(); - var7 += map.deviceInterfaceModule.size(); - Iterator var3 = map.servoController.iterator(); - - String var5; - Pattern var6; - while(var3.hasNext()) { - ServoController var4 = (ServoController)var3.next(); - var5 = var4.getDeviceName(); - var6 = Pattern.compile("(?i)usb"); - if(var6.matcher(var5).matches()) { - ++var7; - } - } - - var3 = map.dcMotorController.iterator(); - - while(var3.hasNext()) { - DcMotorController var8 = (DcMotorController)var3.next(); - var5 = var8.getDeviceName(); - var6 = Pattern.compile("(?i)usb"); - if(var6.matcher(var5).matches()) { - ++var7; - } - } - - return var7; - } - - protected void handleData() throws IOException, ClassNotFoundException { - String var1 = EXTERNAL_STORAGE_DIRECTORY_PATH + ".ftcdc"; - File var2 = new File(var1); - if(!var2.exists()) { - this.createInitialFile(var1); - } else { - ArrayList var3 = this.updateExistingFile(var1, getDateFromTime(b)); - if(var3.size() >= MAX_ENTRIES_SIZE) { - this.trimEntries(var3); - } - - this.writeObjectsToFile(var1, var3); - } - - } - - protected void trimEntries(ArrayList dataInfoArrayList) { - dataInfoArrayList.subList(TRIMMED_SIZE, dataInfoArrayList.size()).clear(); - } - - protected ArrayList updateExistingFile(String filepath, String date) throws ClassNotFoundException, IOException { - ArrayList var3 = this.readObjectsFromFile(filepath); - Analytics.DataInfo var4 = (Analytics.DataInfo)var3.get(var3.size() - 1); - if(var4.a.equalsIgnoreCase(date)) { - ++var4.numUsages; - } else { - Analytics.DataInfo var5 = new Analytics.DataInfo(date, 1); - var3.add(var5); - } - - return var3; - } - - protected ArrayList readObjectsFromFile(String filepath) throws IOException, ClassNotFoundException { - FileInputStream var2 = new FileInputStream(new File(filepath)); - ObjectInputStream var3 = new ObjectInputStream(var2); - ArrayList var4 = new ArrayList(); - boolean var5 = true; - - while(var5) { - try { - Analytics.DataInfo var6 = (Analytics.DataInfo)var3.readObject(); - var4.add(var6); - } catch (EOFException var7) { - var5 = false; - } - } - - var3.close(); - return var4; - } - - protected void createInitialFile(String filepath) throws IOException { - Analytics.DataInfo var2 = new Analytics.DataInfo(getDateFromTime(b), 1); - ArrayList var3 = new ArrayList(); - var3.add(var2); - this.writeObjectsToFile(filepath, var3); - } - - private void a() { - RobotLog.i("Analytics is starting with a clean slate."); - Editor var1 = this.h.edit(); - var1.putLong("last_upload_date", this.j); - var1.apply(); - var1.putInt("max_usb_devices", 0); - var1.apply(); - File var2 = new File(EXTERNAL_STORAGE_DIRECTORY_PATH + ".ftcdc"); - var2.delete(); - File var3 = new File(EXTERNAL_STORAGE_DIRECTORY_PATH + ".analytics_id"); - var3.delete(); - this.i = false; - } - - public void communicateWithServer() { - String[] var1 = new String[]{a}; - (new Analytics.a(null)).execute((Object[])var1); - } - - public static void setApplicationName(String name) { - d = name; - } - - public void handleUUID(String filename) { - File var2 = new File(EXTERNAL_STORAGE_DIRECTORY_PATH + filename); - if(!var2.exists()) { - c = UUID.randomUUID(); - this.handleCreateNewFile(EXTERNAL_STORAGE_DIRECTORY_PATH + filename, c.toString()); - } - - String var3 = this.readFromFile(var2); - - try { - c = UUID.fromString(var3); - } catch (IllegalArgumentException var5) { - RobotLog.i("Analytics encountered an IllegalArgumentException"); - c = UUID.randomUUID(); - this.handleCreateNewFile(EXTERNAL_STORAGE_DIRECTORY_PATH + filename, c.toString()); - } - - } - - protected String readFromFile(File file) { - try { - char[] var2 = new char[4096]; - FileReader var3 = new FileReader(file); - int var4 = var3.read(var2); - var3.close(); - String var5 = new String(var2, 0, var4); - return var5.trim(); - } catch (FileNotFoundException var6) { - RobotLog.i("Analytics encountered a FileNotFoundException while trying to read a file."); - } catch (IOException var7) { - RobotLog.i("Analytics encountered an IOException while trying to read."); - } - - return ""; - } - - protected void writeObjectsToFile(String filepath, ArrayList info) throws IOException { - ObjectOutputStream var3 = new ObjectOutputStream(new FileOutputStream(filepath)); - Iterator var4 = info.iterator(); - - while(var4.hasNext()) { - Analytics.DataInfo var5 = (Analytics.DataInfo)var4.next(); - var3.writeObject(var5); - } - - var3.close(); - } - - protected void handleCreateNewFile(String filepath, String data) { - BufferedWriter var3 = null; - - try { - File var4 = new File(filepath); - FileOutputStream var5 = new FileOutputStream(var4); - var3 = new BufferedWriter(new OutputStreamWriter(var5, "utf-8")); - var3.write(data); - } catch (IOException var14) { - RobotLog.i("Analytics encountered an IOException: " + var14.toString()); - } finally { - if(var3 != null) { - try { - var3.close(); - } catch (IOException var13) { - ; - } - } - - } - - } - - public static String getDateFromTime(long time) { - SimpleDateFormat var2 = new SimpleDateFormat("yyyy-MM-dd", Locale.US); - String var3 = var2.format(new Date(time)); - return var3; - } - - protected static UUID getUuid() { - return c; - } - - public String updateStats(String user, ArrayList dateInfo, String commandString) { - int var4 = this.h.getInt("max_usb_devices", this.k); - String var5 = this.a("cmd", "=", commandString) + "&" + this.a("uuid", "=", user) + "&" + this.a("device_hw", "=", Build.MANUFACTURER) + "&" + this.a("device_ver", "=", Build.MODEL) + "&" + this.a("chip_type", "=", this.b()) + "&" + this.a("sw_ver", "=", f) + "&" + this.a("max_dev", "=", String.valueOf(var4)) + "&"; - String var6 = ""; - - for(int var7 = 0; var7 < dateInfo.size(); ++var7) { - if(var7 > 0) { - var6 = var6 + ","; - } - - var6 = var6 + this.a(((Analytics.DataInfo)dateInfo.get(var7)).date(), ",", String.valueOf(((Analytics.DataInfo)dateInfo.get(var7)).numUsages())); - } - - var5 = var5 + this.a("dc", "=", ""); - var5 = var5 + var6; - return var5; - } - - private String a(String var1, String var2, String var3) { - String var4 = ""; - - try { - var4 = URLEncoder.encode(var1, m.name()) + var2 + URLEncoder.encode(var3, m.name()); - } catch (UnsupportedEncodingException var6) { - RobotLog.i("Analytics caught an UnsupportedEncodingException"); - } - - return var4; - } - - private String b() { - String var1 = "UNKNOWN"; - String var2 = "/proc/cpuinfo"; - String[] var3 = new String[]{"CPU implementer", "Hardware"}; - HashMap var4 = new HashMap(); - - try { - BufferedReader var5 = new BufferedReader(new FileReader("/proc/cpuinfo")); - - for(String var6 = var5.readLine(); var6 != null; var6 = var5.readLine()) { - var6 = var6.toLowerCase(); - String[] var7 = var6.split(":"); - if(var7.length >= 2) { - var4.put(var7[0].trim(), var7[1].trim()); - } - } - - var5.close(); - String var14 = ""; - String[] var8 = var3; - int var9 = var3.length; - - for(int var10 = 0; var10 < var9; ++var10) { - String var11 = var8[var10]; - var14 = var14 + (String)var4.get(var11.toLowerCase()) + " "; - } - - var14 = var14.trim(); - if(var14.isEmpty()) { - return var1; - } - - return var14; - } catch (FileNotFoundException var12) { - RobotLog.i("Analytics encountered a FileNotFoundException while looking for CPU info"); - } catch (IOException var13) { - RobotLog.i("Analytics encountered an IOException while looking for CPU info"); - } - - return var1; - } - - public boolean isConnected() { - ConnectivityManager var1 = (ConnectivityManager)this.g.getSystemService("connectivity"); - NetworkInfo var2 = var1.getActiveNetworkInfo(); - return var2 != null && var2.isConnected(); - } - - public static String ping(URL baseUrl, String data) { - String var2 = call(baseUrl, data); - return var2; - } - - public static String call(URL url, String data) { - String var4 = null; - if(url != null && data != null) { - try { - long var2 = System.currentTimeMillis(); - Object var5 = null; - if(url.getProtocol().toLowerCase().equals("https")) { - c(); - HttpsURLConnection var6 = (HttpsURLConnection)url.openConnection(); - var6.setHostnameVerifier(l); - var5 = var6; - } else { - var5 = (HttpURLConnection)url.openConnection(); - } - - ((HttpURLConnection)var5).setDoOutput(true); - OutputStreamWriter var7 = new OutputStreamWriter(((HttpURLConnection)var5).getOutputStream()); - var7.write(data); - var7.flush(); - var7.close(); - BufferedReader var10 = new BufferedReader(new InputStreamReader(((HttpURLConnection)var5).getInputStream())); - - String var8; - for(var4 = new String(); (var8 = var10.readLine()) != null; var4 = var4 + var8) { - ; - } - - var10.close(); - RobotLog.i("Analytics took: " + (System.currentTimeMillis() - var2) + "ms"); - } catch (IOException var9) { - RobotLog.i("Analytics Failed to process command."); - } - } - - return var4; - } - - private static void c() { - TrustManager[] var0 = new TrustManager[]{new X509TrustManager() { - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } - - public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { - } - - public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { - } - }}; - - try { - SSLContext var1 = SSLContext.getInstance("TLS"); - var1.init((KeyManager[])null, var0, new SecureRandom()); - HttpsURLConnection.setDefaultSSLSocketFactory(var1.getSocketFactory()); - } catch (Exception var2) { - var2.printStackTrace(); - } - - } - - private class a extends AsyncTask { - private a() { - } - - protected Object doInBackground(Object[] params) { - if(Analytics.this.isConnected()) { - try { - URL var2 = null; - var2 = new URL(Analytics.a); - long var3 = Analytics.this.h.getLong("last_upload_date", Analytics.this.j); - if(!Analytics.getDateFromTime(Analytics.b).equals(Analytics.getDateFromTime(var3))) { - label53: { - String var5 = Analytics.this.a("cmd", "=", "ping"); - String var6 = Analytics.ping(var2, var5); - String var7 = "\"rc\": \"OK\""; - if(var6 != null && var6.contains(var7)) { - RobotLog.i("Analytics ping succeeded."); - String var8 = Analytics.EXTERNAL_STORAGE_DIRECTORY_PATH + ".ftcdc"; - ArrayList var9 = Analytics.this.readObjectsFromFile(var8); - if(var9.size() >= Analytics.MAX_ENTRIES_SIZE) { - Analytics.this.trimEntries(var9); - } - - String var10 = Analytics.this.updateStats(Analytics.c.toString(), var9, Analytics.this.e); - String var11 = Analytics.call(var2, var10); - if(var11 != null && var11.contains(var7)) { - RobotLog.i("Analytics: Upload succeeded."); - Editor var12 = Analytics.this.h.edit(); - var12.putLong("last_upload_date", Analytics.b); - var12.apply(); - var12.putInt("max_usb_devices", 0); - var12.apply(); - File var13 = new File(var8); - boolean var14 = var13.delete(); - break label53; - } - - RobotLog.e("Analytics: Upload failed."); - return null; - } - - RobotLog.e("Analytics: Ping failed."); - return null; - } - } - } catch (MalformedURLException var15) { - RobotLog.e("Analytics encountered a malformed URL exception"); - } catch (Exception var16) { - Analytics.this.i = true; - } - - if(Analytics.this.i) { - RobotLog.i("Analytics encountered a problem during communication"); - Analytics.this.a(); - Analytics.this.i = false; - } - } - - return null; - } - } - - public static class DataInfo implements Serializable { - private final String a; - protected int numUsages; - - public DataInfo(String adate, int numUsages) { - this.a = adate; - this.numUsages = numUsages; - } - - public String date() { - return this.a; - } - - public int numUsages() { - return this.numUsages; - } - } -} +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package com.qualcomm.analytics; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.NetworkInfo.State; +import android.os.AsyncTask; +import android.os.Build; +import android.os.Bundle; +import android.os.Environment; +import android.preference.PreferenceManager; + +import com.qualcomm.robotcore.hardware.DcMotorController; +import com.qualcomm.robotcore.hardware.HardwareMap; +import com.qualcomm.robotcore.hardware.ServoController; +import com.qualcomm.robotcore.util.RobotLog; +import com.qualcomm.robotcore.util.Version; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.EOFException; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.OutputStreamWriter; +import java.io.Serializable; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLEncoder; +import java.nio.charset.Charset; +import java.security.SecureRandom; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.UUID; +import java.util.regex.Pattern; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + +public class Analytics extends BroadcastReceiver { + public static final String UUID_PATH = ".analytics_id"; + public static final String DATA_COLLECTION_PATH = ".ftcdc"; + public static final String RC_COMMAND_STRING = "update_rc"; + public static final String DS_COMMAND_STRING = "update_ds"; + public static final String EXTERNAL_STORAGE_DIRECTORY_PATH = Environment.getExternalStorageDirectory() + "/"; + public static final String LAST_UPLOAD_DATE = "last_upload_date"; + public static final String MAX_DEVICES = "max_usb_devices"; + static final HostnameVerifier l = new HostnameVerifier() { + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + private static final Charset m = Charset.forName("UTF-8"); + public static int MAX_ENTRIES_SIZE = 100; + public static int TRIMMED_SIZE = 90; + static String a = "https://ftcdc.qualcomm.com/DataApi"; + static long b; + static UUID c = null; + static String d; + static String f = ""; + String e; + Context g; + SharedPreferences h; + boolean i = false; + long j = 0L; + int k = 0; + + public Analytics(Context context, String commandString, HardwareMap map) { + this.g = context; + this.e = commandString; + + try { + try { + this.h = PreferenceManager.getDefaultSharedPreferences(context); + b = System.currentTimeMillis(); + f = Version.getLibraryVersion(); + this.handleUUID(".analytics_id"); + int var4 = this.calculateUsbDevices(map); + int var5 = this.h.getInt("max_usb_devices", this.k); + if(var5 < var4) { + Editor var6 = this.h.edit(); + var6.putInt("max_usb_devices", var4); + var6.apply(); + } + + setApplicationName(context.getApplicationInfo().loadLabel(context.getPackageManager()).toString()); + this.handleData(); + this.register(); + RobotLog.i("Analytics has completed initialization."); + } catch (Exception var7) { + this.i = true; + } + + if(this.i) { + this.a(); + this.i = false; + } + } catch (Exception var8) { + RobotLog.i("Analytics encountered a problem during initialization"); + RobotLog.logStacktrace(var8); + } + + } + + public static void setApplicationName(String name) { + d = name; + } + + public static String getDateFromTime(long time) { + SimpleDateFormat var2 = new SimpleDateFormat("yyyy-MM-dd", Locale.US); + String var3 = var2.format(new Date(time)); + return var3; + } + + protected static UUID getUuid() { + return c; + } + + public static String ping(URL baseUrl, String data) { + String var2 = call(baseUrl, data); + return var2; + } + + public static String call(URL url, String data) { + String var4 = null; + if (url != null && data != null) { + try { + long var2 = System.currentTimeMillis(); + Object var5 = null; + if (url.getProtocol().toLowerCase().equals("https")) { + c(); + HttpsURLConnection var6 = (HttpsURLConnection) url.openConnection(); + var6.setHostnameVerifier(l); + var5 = var6; + } else { + var5 = url.openConnection(); + } + + ((HttpURLConnection) var5).setDoOutput(true); + OutputStreamWriter var7 = new OutputStreamWriter(((HttpURLConnection) var5).getOutputStream()); + var7.write(data); + var7.flush(); + var7.close(); + BufferedReader var10 = new BufferedReader(new InputStreamReader(((HttpURLConnection) var5).getInputStream())); + + String var8; + for (var4 = new String(); (var8 = var10.readLine()) != null; var4 = var4 + var8) { + } + + var10.close(); + RobotLog.i("Analytics took: " + (System.currentTimeMillis() - var2) + "ms"); + } catch (IOException var9) { + RobotLog.i("Analytics Failed to process command."); + } + } + + return var4; + } + + private static void c() { + TrustManager[] var0 = new TrustManager[]{new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[0]; + } + + public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { + } + + public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { + } + }}; + + try { + SSLContext var1 = SSLContext.getInstance("TLS"); + var1.init(null, var0, new SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(var1.getSocketFactory()); + } catch (Exception var2) { + var2.printStackTrace(); + } + + } + + public void onReceive(Context context, Intent intent) { + Bundle var3 = intent.getExtras(); + if (var3 != null && var3.containsKey("networkInfo")) { + NetworkInfo var4 = (NetworkInfo) var3.get("networkInfo"); + State var5 = var4.getState(); + if (var5.equals(State.CONNECTED)) { + RobotLog.i("Analytics detected NetworkInfo.State.CONNECTED"); + this.communicateWithServer(); + } + } + + } + + public void unregister() { + this.g.unregisterReceiver(this); + } + + public void register() { + this.g.registerReceiver(this, new IntentFilter("android.net.wifi.STATE_CHANGE")); + } + + protected int calculateUsbDevices(HardwareMap map) { + byte var2 = 0; + int var7 = var2 + map.legacyModule.size(); + var7 += map.deviceInterfaceModule.size(); + Iterator var3 = map.servoController.iterator(); + + String var5; + Pattern var6; + while(var3.hasNext()) { + ServoController var4 = (ServoController)var3.next(); + var5 = var4.getDeviceName(); + var6 = Pattern.compile("(?i)usb"); + if(var6.matcher(var5).matches()) { + ++var7; + } + } + + var3 = map.dcMotorController.iterator(); + + while(var3.hasNext()) { + DcMotorController var8 = (DcMotorController)var3.next(); + var5 = var8.getDeviceName(); + var6 = Pattern.compile("(?i)usb"); + if(var6.matcher(var5).matches()) { + ++var7; + } + } + + return var7; + } + + protected void handleData() throws IOException, ClassNotFoundException { + String var1 = EXTERNAL_STORAGE_DIRECTORY_PATH + ".ftcdc"; + File var2 = new File(var1); + if(!var2.exists()) { + this.createInitialFile(var1); + } else { + ArrayList var3 = this.updateExistingFile(var1, getDateFromTime(b)); + if(var3.size() >= MAX_ENTRIES_SIZE) { + this.trimEntries(var3); + } + + this.writeObjectsToFile(var1, var3); + } + + } + + protected void trimEntries(ArrayList dataInfoArrayList) { + dataInfoArrayList.subList(TRIMMED_SIZE, dataInfoArrayList.size()).clear(); + } + + protected ArrayList updateExistingFile(String filepath, String date) throws ClassNotFoundException, IOException { + ArrayList var3 = this.readObjectsFromFile(filepath); + DataInfo var4 = (DataInfo)var3.get(var3.size() - 1); + if(var4.a.equalsIgnoreCase(date)) { + ++var4.numUsages; + } else { + DataInfo var5 = new DataInfo(date, 1); + var3.add(var5); + } + + return var3; + } + + protected ArrayList readObjectsFromFile(String filepath) throws IOException, ClassNotFoundException { + FileInputStream var2 = new FileInputStream(new File(filepath)); + ObjectInputStream var3 = new ObjectInputStream(var2); + ArrayList var4 = new ArrayList(); + boolean var5 = true; + + while(var5) { + try { + DataInfo var6 = (DataInfo)var3.readObject(); + var4.add(var6); + } catch (EOFException var7) { + var5 = false; + } + } + + var3.close(); + return var4; + } + + protected void createInitialFile(String filepath) throws IOException { + DataInfo var2 = new DataInfo(getDateFromTime(b), 1); + ArrayList var3 = new ArrayList(); + var3.add(var2); + this.writeObjectsToFile(filepath, var3); + } + + private void a() { + RobotLog.i("Analytics is starting with a clean slate."); + Editor var1 = this.h.edit(); + var1.putLong("last_upload_date", this.j); + var1.apply(); + var1.putInt("max_usb_devices", 0); + var1.apply(); + File var2 = new File(EXTERNAL_STORAGE_DIRECTORY_PATH + ".ftcdc"); + var2.delete(); + File var3 = new File(EXTERNAL_STORAGE_DIRECTORY_PATH + ".analytics_id"); + var3.delete(); + this.i = false; + } + + public void communicateWithServer() { + String[] var1 = new String[]{a}; + (new a()).execute((Object[]) var1); + } + + public void handleUUID(String filename) { + File var2 = new File(EXTERNAL_STORAGE_DIRECTORY_PATH + filename); + if(!var2.exists()) { + c = UUID.randomUUID(); + this.handleCreateNewFile(EXTERNAL_STORAGE_DIRECTORY_PATH + filename, c.toString()); + } + + String var3 = this.readFromFile(var2); + + try { + c = UUID.fromString(var3); + } catch (IllegalArgumentException var5) { + RobotLog.i("Analytics encountered an IllegalArgumentException"); + c = UUID.randomUUID(); + this.handleCreateNewFile(EXTERNAL_STORAGE_DIRECTORY_PATH + filename, c.toString()); + } + + } + + protected String readFromFile(File file) { + try { + char[] var2 = new char[4096]; + FileReader var3 = new FileReader(file); + int var4 = var3.read(var2); + var3.close(); + String var5 = new String(var2, 0, var4); + return var5.trim(); + } catch (FileNotFoundException var6) { + RobotLog.i("Analytics encountered a FileNotFoundException while trying to read a file."); + } catch (IOException var7) { + RobotLog.i("Analytics encountered an IOException while trying to read."); + } + + return ""; + } + + protected void writeObjectsToFile(String filepath, ArrayList info) throws IOException { + ObjectOutputStream var3 = new ObjectOutputStream(new FileOutputStream(filepath)); + Iterator var4 = info.iterator(); + + while(var4.hasNext()) { + DataInfo var5 = (DataInfo)var4.next(); + var3.writeObject(var5); + } + + var3.close(); + } + + protected void handleCreateNewFile(String filepath, String data) { + BufferedWriter var3 = null; + + try { + File var4 = new File(filepath); + FileOutputStream var5 = new FileOutputStream(var4); + var3 = new BufferedWriter(new OutputStreamWriter(var5, "utf-8")); + var3.write(data); + } catch (IOException var14) { + RobotLog.i("Analytics encountered an IOException: " + var14.toString()); + } finally { + if(var3 != null) { + try { + var3.close(); + } catch (IOException var13) { + } + } + + } + + } + + public String updateStats(String user, ArrayList dateInfo, String commandString) { + int var4 = this.h.getInt("max_usb_devices", this.k); + String var5 = this.a("cmd", "=", commandString) + "&" + this.a("uuid", "=", user) + "&" + this.a("device_hw", "=", Build.MANUFACTURER) + "&" + this.a("device_ver", "=", Build.MODEL) + "&" + this.a("chip_type", "=", this.b()) + "&" + this.a("sw_ver", "=", f) + "&" + this.a("max_dev", "=", String.valueOf(var4)) + "&"; + String var6 = ""; + + for(int var7 = 0; var7 < dateInfo.size(); ++var7) { + if(var7 > 0) { + var6 = var6 + ","; + } + + var6 = var6 + this.a(dateInfo.get(var7).date(), ",", String.valueOf(dateInfo.get(var7).numUsages())); + } + + var5 = var5 + this.a("dc", "=", ""); + var5 = var5 + var6; + return var5; + } + + private String a(String var1, String var2, String var3) { + String var4 = ""; + + try { + var4 = URLEncoder.encode(var1, m.name()) + var2 + URLEncoder.encode(var3, m.name()); + } catch (UnsupportedEncodingException var6) { + RobotLog.i("Analytics caught an UnsupportedEncodingException"); + } + + return var4; + } + + private String b() { + String var1 = "UNKNOWN"; + String var2 = "/proc/cpuinfo"; + String[] var3 = new String[]{"CPU implementer", "Hardware"}; + HashMap var4 = new HashMap(); + + try { + BufferedReader var5 = new BufferedReader(new FileReader("/proc/cpuinfo")); + + for(String var6 = var5.readLine(); var6 != null; var6 = var5.readLine()) { + var6 = var6.toLowerCase(); + String[] var7 = var6.split(":"); + if(var7.length >= 2) { + var4.put(var7[0].trim(), var7[1].trim()); + } + } + + var5.close(); + String var14 = ""; + String[] var8 = var3; + int var9 = var3.length; + + for(int var10 = 0; var10 < var9; ++var10) { + String var11 = var8[var10]; + var14 = var14 + var4.get(var11.toLowerCase()) + " "; + } + + var14 = var14.trim(); + if(var14.isEmpty()) { + return var1; + } + + return var14; + } catch (FileNotFoundException var12) { + RobotLog.i("Analytics encountered a FileNotFoundException while looking for CPU info"); + } catch (IOException var13) { + RobotLog.i("Analytics encountered an IOException while looking for CPU info"); + } + + return var1; + } + + public boolean isConnected() { + ConnectivityManager var1 = (ConnectivityManager)this.g.getSystemService("connectivity"); + NetworkInfo var2 = var1.getActiveNetworkInfo(); + return var2 != null && var2.isConnected(); + } + + public static class DataInfo implements Serializable { + private final String a; + protected int numUsages; + + public DataInfo(String adate, int numUsages) { + this.a = adate; + this.numUsages = numUsages; + } + + public String date() { + return this.a; + } + + public int numUsages() { + return this.numUsages; + } + } + + private class a extends AsyncTask { + private a() { + } + + protected Object doInBackground(Object[] params) { + if(Analytics.this.isConnected()) { + try { + URL var2 = null; + var2 = new URL(Analytics.a); + long var3 = Analytics.this.h.getLong("last_upload_date", Analytics.this.j); + if(!Analytics.getDateFromTime(Analytics.b).equals(Analytics.getDateFromTime(var3))) { + label53: { + String var5 = Analytics.this.a("cmd", "=", "ping"); + String var6 = Analytics.ping(var2, var5); + String var7 = "\"rc\": \"OK\""; + if(var6 != null && var6.contains(var7)) { + RobotLog.i("Analytics ping succeeded."); + String var8 = Analytics.EXTERNAL_STORAGE_DIRECTORY_PATH + ".ftcdc"; + ArrayList var9 = Analytics.this.readObjectsFromFile(var8); + if(var9.size() >= Analytics.MAX_ENTRIES_SIZE) { + Analytics.this.trimEntries(var9); + } + + String var10 = Analytics.this.updateStats(Analytics.c.toString(), var9, Analytics.this.e); + String var11 = Analytics.call(var2, var10); + if(var11 != null && var11.contains(var7)) { + RobotLog.i("Analytics: Upload succeeded."); + Editor var12 = Analytics.this.h.edit(); + var12.putLong("last_upload_date", Analytics.b); + var12.apply(); + var12.putInt("max_usb_devices", 0); + var12.apply(); + File var13 = new File(var8); + boolean var14 = var13.delete(); + break label53; + } + + RobotLog.e("Analytics: Upload failed."); + return null; + } + + RobotLog.e("Analytics: Ping failed."); + return null; + } + } + } catch (MalformedURLException var15) { + RobotLog.e("Analytics encountered a malformed URL exception"); + } catch (Exception var16) { + Analytics.this.i = true; + } + + if(Analytics.this.i) { + RobotLog.i("Analytics encountered a problem during communication"); + Analytics.this.a(); + Analytics.this.i = false; + } + } + + return null; + } + } +} diff --git a/FtcRobotController/Analytics/src/main/res/values/strings.xml b/FtcRobotController/Analytics/src/main/res/values/strings.xml new file mode 100644 index 0000000..eb97911 --- /dev/null +++ b/FtcRobotController/Analytics/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Analytics + diff --git a/FtcRobotController/Analytics/src/test/java/com/qualcomm/analytics/ExampleUnitTest.java b/FtcRobotController/Analytics/src/test/java/com/qualcomm/analytics/ExampleUnitTest.java new file mode 100644 index 0000000..564a41e --- /dev/null +++ b/FtcRobotController/Analytics/src/test/java/com/qualcomm/analytics/ExampleUnitTest.java @@ -0,0 +1,15 @@ +package com.qualcomm.analytics; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * To work on unit tests, switch the Test Artifact in the Build Variants view. + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/FtcRobotController/FtcCommon/.gitignore b/FtcRobotController/FtcCommon/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/FtcRobotController/FtcCommon/.gitignore @@ -0,0 +1 @@ +/build diff --git a/FtcRobotController/FtcCommon/FtcCommon.iml b/FtcRobotController/FtcCommon/FtcCommon.iml new file mode 100644 index 0000000..90c3a72 --- /dev/null +++ b/FtcRobotController/FtcCommon/FtcCommon.iml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/FtcRobotController/FtcCommon/build.gradle b/FtcRobotController/FtcCommon/build.gradle new file mode 100644 index 0000000..984af3d --- /dev/null +++ b/FtcRobotController/FtcCommon/build.gradle @@ -0,0 +1,32 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 22 + buildToolsVersion '22.0.1' + + defaultConfig { + minSdkVersion 19 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } +} + +dependencies { + compile fileTree(include: ['*.jar'], dir: 'libs') + testCompile 'junit:junit:4.12' + compile project(':robotcore') + compile project(':ModernRobotics') + compile project(':WirelessP2p') + compile project(':Hardware') +} diff --git a/FtcRobotController/FtcCommon/proguard-rules.pro b/FtcRobotController/FtcCommon/proguard-rules.pro new file mode 100644 index 0000000..db73af4 --- /dev/null +++ b/FtcRobotController/FtcCommon/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\Public\Android\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/FtcRobotController/FtcCommon/src/androidTest/java/com/qualcomm/ftccommon/ApplicationTest.java b/FtcRobotController/FtcCommon/src/androidTest/java/com/qualcomm/ftccommon/ApplicationTest.java new file mode 100644 index 0000000..91c1c09 --- /dev/null +++ b/FtcRobotController/FtcCommon/src/androidTest/java/com/qualcomm/ftccommon/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.qualcomm.ftccommon; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/FtcRobotController/FtcCommon/src/main/AndroidManifest.xml b/FtcRobotController/FtcCommon/src/main/AndroidManifest.xml new file mode 100644 index 0000000..649e4cd --- /dev/null +++ b/FtcRobotController/FtcCommon/src/main/AndroidManifest.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/AboutActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/AboutActivity.java similarity index 76% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/AboutActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/AboutActivity.java index 91c1df3..f51c7bb 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/AboutActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/AboutActivity.java @@ -1,123 +1,123 @@ -package com.qualcomm.ftccommon; - -import android.app.Activity; -import android.content.Context; -import android.content.pm.PackageManager.NameNotFoundException; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.ListView; -import android.widget.TextView; -import com.qualcomm.ftccommon.R; -import com.qualcomm.robotcore.util.RobotLog; -import com.qualcomm.robotcore.util.Version; -import com.qualcomm.robotcore.wifi.WifiDirectAssistant; - -public class AboutActivity extends Activity { - WifiDirectAssistant a = null; - - protected void onStart() { - super.onStart(); - this.setContentView(R.layout.activity_about); - ListView var1 = (ListView)this.findViewById(R.id.aboutList); - - try { - this.a = WifiDirectAssistant.getWifiDirectAssistant((Context)null); - this.a.enable(); - } catch (NullPointerException var3) { - RobotLog.i("Cannot start Wifi Direct Assistant"); - this.a = null; - } - - var1.setAdapter(new ArrayAdapter(this, 17367044, 16908308) { - private AboutActivity.Item a() { - AboutActivity.Item var1 = new AboutActivity.Item(); - var1.title = "App Version"; - - try { - var1.info = AboutActivity.this.getPackageManager().getPackageInfo(AboutActivity.this.getPackageName(), 0).versionName; - return var1; - } catch (NameNotFoundException var3) { - var1.info = var3.getMessage(); - return var1; - } - } - - private AboutActivity.Item b() { - AboutActivity.Item var1 = new AboutActivity.Item(); - var1.title = "Library Version"; - var1.info = Version.getLibraryVersion(); - return var1; - } - - private AboutActivity.Item c() { - AboutActivity.Item var1 = new AboutActivity.Item(); - var1.title = "Wifi Direct Information"; - var1.info = "unavailable"; - StringBuilder var2 = new StringBuilder(); - if(AboutActivity.this.a != null && AboutActivity.this.a.isEnabled()) { - var2.append("Name: ").append(AboutActivity.this.a.getDeviceName()); - if(AboutActivity.this.a.isGroupOwner()) { - var2.append("\nIP Address").append(AboutActivity.this.a.getGroupOwnerAddress().getHostAddress()); - var2.append("\nPassphrase: ").append(AboutActivity.this.a.getPassphrase()); - var2.append("\nGroup Owner"); - } else if(AboutActivity.this.a.isConnected()) { - var2.append("\nGroup Owner: ").append(AboutActivity.this.a.getGroupOwnerName()); - var2.append("\nConnected"); - } else { - var2.append("\nNo connection information"); - } - - var1.info = var2.toString(); - } - - return var1; - } - - public AboutActivity.Item a(int var1) { - switch(var1) { - case 0: - return this.a(); - case 1: - return this.b(); - case 2: - return this.c(); - default: - return new AboutActivity.Item(); - } - } - - public int getCount() { - return 3; - } - - // $FF: synthetic method - public Object getItem(int var1) { - return this.a(var1); - } - - public View getView(int var1, View var2, ViewGroup var3) { - View var4 = super.getView(var1, var2, var3); - TextView var5 = (TextView)var4.findViewById(16908308); - TextView var6 = (TextView)var4.findViewById(16908309); - AboutActivity.Item var7 = this.a(var1); - var5.setText(var7.title); - var6.setText(var7.info); - return var4; - } - }); - } - - protected void onStop() { - super.onStop(); - if(this.a != null) { - this.a.disable(); - } - - } - - public static class Item { - public String info = ""; - public String title = ""; - } -} +package com.qualcomm.ftccommon; + +import android.app.Activity; +import android.content.pm.PackageManager.NameNotFoundException; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.TextView; + +import com.qualcomm.robotcore.util.RobotLog; +import com.qualcomm.robotcore.util.Version; +import com.qualcomm.robotcore.wifi.WifiDirectAssistant; + +public class AboutActivity extends Activity { + WifiDirectAssistant a = null; + + protected void onStart() { + super.onStart(); + this.setContentView(R.layout.about); + ListView var1 = (ListView)this.findViewById(R.id.aboutList); + + try { + this.a = WifiDirectAssistant.getWifiDirectAssistant(null); + this.a.enable(); + } catch (NullPointerException var3) { + RobotLog.i("Cannot start Wifi Direct Assistant"); + this.a = null; + } + + var1.setAdapter(new ArrayAdapter(this, R.layout.about, R.id.aboutList) { + private Item a() { + Item var1 = new Item(); + var1.title = "App Version"; + + try { + var1.info = AboutActivity.this.getPackageManager().getPackageInfo(AboutActivity.this.getPackageName(), 0).versionName; + return var1; + } catch (NameNotFoundException var3) { + var1.info = var3.getMessage(); + return var1; + } + } + + private Item b() { + Item var1 = new Item(); + var1.title = "Library Version"; + var1.info = Version.getLibraryVersion(); + return var1; + } + + private Item c() { + Item var1 = new Item(); + var1.title = "Wifi Direct Information"; + var1.info = "unavailable"; + StringBuilder var2 = new StringBuilder(); + if(AboutActivity.this.a != null && AboutActivity.this.a.isEnabled()) { + var2.append("Name: ").append(AboutActivity.this.a.getDeviceName()); + if(AboutActivity.this.a.isGroupOwner()) { + var2.append("\nIP Address").append(AboutActivity.this.a.getGroupOwnerAddress().getHostAddress()); + var2.append("\nPassphrase: ").append(AboutActivity.this.a.getPassphrase()); + var2.append("\nGroup Owner"); + } else if(AboutActivity.this.a.isConnected()) { + var2.append("\nGroup Owner: ").append(AboutActivity.this.a.getGroupOwnerName()); + var2.append("\nConnected"); + } else { + var2.append("\nNo connection information"); + } + + var1.info = var2.toString(); + } + + return var1; + } + + public Item a(int var1) { + switch(var1) { + case 0: + return this.a(); + case 1: + return this.b(); + case 2: + return this.c(); + default: + return new Item(); + } + } + + public int getCount() { + return 3; + } + + // $FF: synthetic method + public Object getItem(int var1) { + return this.a(var1); + } + + public View getView(int var1, View var2, ViewGroup var3) { + View var4 = super.getView(var1, var2, var3); + // todo: figure out what this actually is + TextView var5 = (TextView) var4.findViewById(R.id.textView); + TextView var6 = (TextView) var4.findViewById(R.id.textView1); + Item var7 = this.a(var1); + var5.setText(var7.title); + var6.setText(var7.info); + return var4; + } + }); + } + + protected void onStop() { + super.onStop(); + if(this.a != null) { + this.a.disable(); + } + + } + + public static class Item { + public String info = ""; + public String title = ""; + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/CommandList.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/CommandList.java similarity index 98% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/CommandList.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/CommandList.java index bd8d650..7e06bd8 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/CommandList.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/CommandList.java @@ -1,11 +1,11 @@ -package com.qualcomm.ftccommon; - -public class CommandList { - public static final String CMD_INIT_OP_MODE = "CMD_INIT_OP_MODE"; - public static final String CMD_INIT_OP_MODE_RESP = "CMD_INIT_OP_MODE_RESP"; - public static final String CMD_REQUEST_OP_MODE_LIST = "CMD_REQUEST_OP_MODE_LIST"; - public static final String CMD_REQUEST_OP_MODE_LIST_RESP = "CMD_REQUEST_OP_MODE_LIST_RESP"; - public static final String CMD_RESTART_ROBOT = "CMD_RESTART_ROBOT"; - public static final String CMD_RUN_OP_MODE = "CMD_RUN_OP_MODE"; - public static final String CMD_RUN_OP_MODE_RESP = "CMD_RUN_OP_MODE_RESP"; -} +package com.qualcomm.ftccommon; + +public class CommandList { + public static final String CMD_INIT_OP_MODE = "CMD_INIT_OP_MODE"; + public static final String CMD_INIT_OP_MODE_RESP = "CMD_INIT_OP_MODE_RESP"; + public static final String CMD_REQUEST_OP_MODE_LIST = "CMD_REQUEST_OP_MODE_LIST"; + public static final String CMD_REQUEST_OP_MODE_LIST_RESP = "CMD_REQUEST_OP_MODE_LIST_RESP"; + public static final String CMD_RESTART_ROBOT = "CMD_RESTART_ROBOT"; + public static final String CMD_RUN_OP_MODE = "CMD_RUN_OP_MODE"; + public static final String CMD_RUN_OP_MODE_RESP = "CMD_RUN_OP_MODE_RESP"; +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/ConfigWifiDirectActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/ConfigWifiDirectActivity.java similarity index 92% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/ConfigWifiDirectActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/ConfigWifiDirectActivity.java index 387f814..547c233 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/ConfigWifiDirectActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/ConfigWifiDirectActivity.java @@ -1,63 +1,63 @@ -package com.qualcomm.ftccommon; - -import android.app.Activity; -import android.app.ProgressDialog; -import android.content.Context; -import android.net.wifi.WifiManager; -import android.os.Bundle; -import com.qualcomm.ftccommon.DbgLog; -import com.qualcomm.ftccommon.R; -import com.qualcomm.robotcore.wifi.FixWifiDirectSetup; - -public class ConfigWifiDirectActivity extends Activity { - private ProgressDialog a; - private Context b; - - protected void onCreate(Bundle var1) { - super.onCreate(var1); - this.setContentView(R.layout.activity_config_wifi_direct); - this.b = this; - } - - protected void onResume() { - super.onResume(); - (new Thread(new ConfigWifiDirectActivity.a(null))).start(); - } - - private class a implements Runnable { - private a() { - } - - // $FF: synthetic method - a(Object var2) { - this(); - } - - public void run() { - DbgLog.msg("attempting to reconfigure Wifi Direct"); - ConfigWifiDirectActivity.this.runOnUiThread(new Runnable() { - public void run() { - ConfigWifiDirectActivity.this.a = new ProgressDialog(ConfigWifiDirectActivity.this.b, R.style.CustomAlertDialog); - ConfigWifiDirectActivity.this.a.setMessage("Please wait"); - ConfigWifiDirectActivity.this.a.setTitle("Configuring Wifi Direct"); - ConfigWifiDirectActivity.this.a.setIndeterminate(true); - ConfigWifiDirectActivity.this.a.show(); - } - }); - WifiManager var1 = (WifiManager)ConfigWifiDirectActivity.this.getSystemService("wifi"); - - try { - FixWifiDirectSetup.fixWifiDirectSetup(var1); - } catch (InterruptedException var3) { - DbgLog.msg("Cannot fix wifi setup - interrupted"); - } - - ConfigWifiDirectActivity.this.runOnUiThread(new Runnable() { - public void run() { - ConfigWifiDirectActivity.this.a.dismiss(); - ConfigWifiDirectActivity.this.finish(); - } - }); - } - } -} +package com.qualcomm.ftccommon; + +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.Context; +import android.net.wifi.WifiManager; +import android.os.Bundle; + +import com.qualcomm.ftccommon.R; +import com.qualcomm.robotcore.wifi.FixWifiDirectSetup; + +public class ConfigWifiDirectActivity extends Activity { + private ProgressDialog a; + private Context b; + + protected void onCreate(Bundle var1) { + super.onCreate(var1); + this.setContentView(R.layout.activity_config_wifi_direct); + this.b = this; + } + + protected void onResume() { + super.onResume(); + (new Thread(new a(null))).start(); + } + + private class a implements Runnable { + private a() { + } + + // $FF: synthetic method + a(Object var2) { + this(); + } + + public void run() { + DbgLog.msg("attempting to reconfigure Wifi Direct"); + ConfigWifiDirectActivity.this.runOnUiThread(new Runnable() { + public void run() { + ConfigWifiDirectActivity.this.a = new ProgressDialog(ConfigWifiDirectActivity.this.b, R.style.CustomAlertDialog); + ConfigWifiDirectActivity.this.a.setMessage("Please wait"); + ConfigWifiDirectActivity.this.a.setTitle("Configuring Wifi Direct"); + ConfigWifiDirectActivity.this.a.setIndeterminate(true); + ConfigWifiDirectActivity.this.a.show(); + } + }); + WifiManager var1 = (WifiManager)ConfigWifiDirectActivity.this.getSystemService("wifi"); + + try { + FixWifiDirectSetup.fixWifiDirectSetup(var1); + } catch (InterruptedException var3) { + DbgLog.msg("Cannot fix wifi setup - interrupted"); + } + + ConfigWifiDirectActivity.this.runOnUiThread(new Runnable() { + public void run() { + ConfigWifiDirectActivity.this.a.dismiss(); + ConfigWifiDirectActivity.this.finish(); + } + }); + } + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/DbgLog.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/DbgLog.java similarity index 95% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/DbgLog.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/DbgLog.java index 0ea9744..81d2bb7 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/DbgLog.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/DbgLog.java @@ -1,27 +1,27 @@ -package com.qualcomm.ftccommon; - -import android.util.Log; - -public class DbgLog { - public static final String ERROR_PREPEND = "### ERROR: "; - public static final String TAG = "FIRST"; - - public static void error(String var0) { - Log.e("FIRST", "### ERROR: " + var0); - } - - public static void logStacktrace(Exception var0) { - msg(var0.toString()); - StackTraceElement[] var1 = var0.getStackTrace(); - int var2 = var1.length; - - for(int var3 = 0; var3 < var2; ++var3) { - msg(var1[var3].toString()); - } - - } - - public static void msg(String var0) { - Log.i("FIRST", var0); - } -} +package com.qualcomm.ftccommon; + +import android.util.Log; + +public class DbgLog { + public static final String ERROR_PREPEND = "### ERROR: "; + public static final String TAG = "FIRST"; + + public static void error(String var0) { + Log.e("FIRST", "### ERROR: " + var0); + } + + public static void logStacktrace(Exception var0) { + msg(var0.toString()); + StackTraceElement[] var1 = var0.getStackTrace(); + int var2 = var1.length; + + for(int var3 = 0; var3 < var2; ++var3) { + msg(var1[var3].toString()); + } + + } + + public static void msg(String var0) { + Log.i("FIRST", var0); + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/Device.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/Device.java similarity index 97% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/Device.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/Device.java index 83553e8..6290b00 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/Device.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/Device.java @@ -1,7 +1,7 @@ -package com.qualcomm.ftccommon; - -public class Device { - public static final String MANUFACTURER_ZTE = "zte"; - public static final String MODEL_FOXDA_FL7007 = "FL7007"; - public static final String MODEL_ZTE_SPEED = "N9130"; -} +package com.qualcomm.ftccommon; + +public class Device { + public static final String MANUFACTURER_ZTE = "zte"; + public static final String MODEL_FOXDA_FL7007 = "FL7007"; + public static final String MODEL_ZTE_SPEED = "N9130"; +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/FtcEventLoop.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/FtcEventLoop.java similarity index 93% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/FtcEventLoop.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/FtcEventLoop.java index e229d4c..42ade36 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/FtcEventLoop.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/FtcEventLoop.java @@ -1,112 +1,111 @@ -package com.qualcomm.ftccommon; - -import android.content.Context; -import com.qualcomm.ftccommon.DbgLog; -import com.qualcomm.ftccommon.FtcEventLoopHandler; -import com.qualcomm.ftccommon.UpdateUI; -import com.qualcomm.modernrobotics.ModernRoboticsUsbUtil; -import com.qualcomm.robotcore.eventloop.EventLoop; -import com.qualcomm.robotcore.eventloop.EventLoopManager; -import com.qualcomm.robotcore.eventloop.opmode.OpModeManager; -import com.qualcomm.robotcore.eventloop.opmode.OpModeRegister; -import com.qualcomm.robotcore.exception.RobotCoreException; -import com.qualcomm.robotcore.hardware.Gamepad; -import com.qualcomm.robotcore.hardware.HardwareFactory; -import com.qualcomm.robotcore.hardware.HardwareMap; -import com.qualcomm.robotcore.robocol.Command; -import com.qualcomm.robotcore.util.Util; -import java.util.Iterator; - -public class FtcEventLoop implements EventLoop { - FtcEventLoopHandler a; - OpModeManager b = new OpModeManager(new HardwareMap()); - OpModeRegister c; - - public FtcEventLoop(HardwareFactory var1, OpModeRegister var2, UpdateUI.Callback var3, Context var4) { - this.a = new FtcEventLoopHandler(var1, var3, var4); - this.c = var2; - } - - private void a() { - this.a.restartRobot(); - } - - private void a(String var1) { - String var2 = this.a.getOpMode(var1); - this.b.initActiveOpMode(var2); - this.a.sendCommand(new Command("CMD_INIT_OP_MODE_RESP", var2)); - } - - private void b() { - String var1 = ""; - Iterator var2 = this.b.getOpModes().iterator(); - - while(var2.hasNext()) { - String var3 = (String)var2.next(); - if(!var3.equals("Stop Robot")) { - if(!var1.isEmpty()) { - var1 = var1 + Util.ASCII_RECORD_SEPARATOR; - } - - var1 = var1 + var3; - } - } - - this.a.sendCommand(new Command("CMD_REQUEST_OP_MODE_LIST_RESP", var1)); - } - - private void c() { - this.b.startActiveOpMode(); - this.a.sendCommand(new Command("CMD_RUN_OP_MODE_RESP", this.b.getActiveOpModeName())); - } - - public OpModeManager getOpModeManager() { - return this.b; - } - - public void init(EventLoopManager var1) throws RobotCoreException, InterruptedException { - DbgLog.msg("======= INIT START ======="); - this.b.registerOpModes(this.c); - this.a.init(var1); - HardwareMap var2 = this.a.getHardwareMap(); - ModernRoboticsUsbUtil.init(var2.appContext, var2); - this.b.setHardwareMap(var2); - var2.logDevices(); - DbgLog.msg("======= INIT FINISH ======="); - } - - public void loop() throws RobotCoreException { - this.a.displayGamePadInfo(this.b.getActiveOpModeName()); - Gamepad[] var1 = this.a.getGamepads(); - this.b.runActiveOpMode(var1); - this.a.sendTelemetryData(this.b.getActiveOpMode().telemetry); - } - - public void processCommand(Command var1) { - DbgLog.msg("Processing Command: " + var1.getName() + " " + var1.getExtra()); - this.a.sendBatteryInfo(); - String var2 = var1.getName(); - String var3 = var1.getExtra(); - if(var2.equals("CMD_RESTART_ROBOT")) { - this.a(); - } else if(var2.equals("CMD_REQUEST_OP_MODE_LIST")) { - this.b(); - } else if(var2.equals("CMD_INIT_OP_MODE")) { - this.a(var3); - } else if(var2.equals("CMD_RUN_OP_MODE")) { - this.c(); - } else { - DbgLog.msg("Unknown command: " + var2); - } - } - - public void teardown() throws RobotCoreException { - DbgLog.msg("======= TEARDOWN ======="); - this.b.stopActiveOpMode(); - this.a.shutdownMotorControllers(); - this.a.shutdownServoControllers(); - this.a.shutdownLegacyModules(); - this.a.shutdownCoreInterfaceDeviceModules(); - DbgLog.msg("======= TEARDOWN COMPLETE ======="); - } -} +package com.qualcomm.ftccommon; + +import android.content.Context; + +import com.qualcomm.modernrobotics.ModernRoboticsUsbUtil; +import com.qualcomm.robotcore.eventloop.EventLoop; +import com.qualcomm.robotcore.eventloop.EventLoopManager; +import com.qualcomm.robotcore.eventloop.opmode.OpModeManager; +import com.qualcomm.robotcore.eventloop.opmode.OpModeRegister; +import com.qualcomm.robotcore.exception.RobotCoreException; +import com.qualcomm.robotcore.hardware.Gamepad; +import com.qualcomm.robotcore.hardware.HardwareFactory; +import com.qualcomm.robotcore.hardware.HardwareMap; +import com.qualcomm.robotcore.robocol.Command; +import com.qualcomm.robotcore.util.Util; + +import java.util.Iterator; + +public class FtcEventLoop implements EventLoop { + FtcEventLoopHandler a; + OpModeManager b = new OpModeManager(new HardwareMap()); + OpModeRegister c; + + public FtcEventLoop(HardwareFactory var1, OpModeRegister var2, UpdateUI.Callback var3, Context var4) { + this.a = new FtcEventLoopHandler(var1, var3, var4); + this.c = var2; + } + + private void a() { + this.a.restartRobot(); + } + + private void a(String var1) { + String var2 = this.a.getOpMode(var1); + this.b.initActiveOpMode(var2); + this.a.sendCommand(new Command("CMD_INIT_OP_MODE_RESP", var2)); + } + + private void b() { + String var1 = ""; + Iterator var2 = this.b.getOpModes().iterator(); + + while(var2.hasNext()) { + String var3 = (String)var2.next(); + if(!var3.equals("Stop Robot")) { + if(!var1.isEmpty()) { + var1 = var1 + Util.ASCII_RECORD_SEPARATOR; + } + + var1 = var1 + var3; + } + } + + this.a.sendCommand(new Command("CMD_REQUEST_OP_MODE_LIST_RESP", var1)); + } + + private void c() { + this.b.startActiveOpMode(); + this.a.sendCommand(new Command("CMD_RUN_OP_MODE_RESP", this.b.getActiveOpModeName())); + } + + public OpModeManager getOpModeManager() { + return this.b; + } + + public void init(EventLoopManager var1) throws RobotCoreException, InterruptedException { + DbgLog.msg("======= INIT START ======="); + this.b.registerOpModes(this.c); + this.a.init(var1); + HardwareMap var2 = this.a.getHardwareMap(); + ModernRoboticsUsbUtil.init(var2.appContext, var2); + this.b.setHardwareMap(var2); + var2.logDevices(); + DbgLog.msg("======= INIT FINISH ======="); + } + + public void loop() throws RobotCoreException { + this.a.displayGamePadInfo(this.b.getActiveOpModeName()); + Gamepad[] var1 = this.a.getGamepads(); + this.b.runActiveOpMode(var1); + this.a.sendTelemetryData(this.b.getActiveOpMode().telemetry); + } + + public void processCommand(Command var1) { + DbgLog.msg("Processing Command: " + var1.getName() + " " + var1.getExtra()); + this.a.sendBatteryInfo(); + String var2 = var1.getName(); + String var3 = var1.getExtra(); + if(var2.equals("CMD_RESTART_ROBOT")) { + this.a(); + } else if(var2.equals("CMD_REQUEST_OP_MODE_LIST")) { + this.b(); + } else if(var2.equals("CMD_INIT_OP_MODE")) { + this.a(var3); + } else if(var2.equals("CMD_RUN_OP_MODE")) { + this.c(); + } else { + DbgLog.msg("Unknown command: " + var2); + } + } + + public void teardown() throws RobotCoreException { + DbgLog.msg("======= TEARDOWN ======="); + this.b.stopActiveOpMode(); + this.a.shutdownMotorControllers(); + this.a.shutdownServoControllers(); + this.a.shutdownLegacyModules(); + this.a.shutdownCoreInterfaceDeviceModules(); + DbgLog.msg("======= TEARDOWN COMPLETE ======="); + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/FtcEventLoopHandler.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/FtcEventLoopHandler.java similarity index 95% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/FtcEventLoopHandler.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/FtcEventLoopHandler.java index 6dce199..d0d5a1e 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/FtcEventLoopHandler.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/FtcEventLoopHandler.java @@ -1,191 +1,191 @@ -package com.qualcomm.ftccommon; - -import android.content.Context; -import com.qualcomm.ftccommon.DbgLog; -import com.qualcomm.ftccommon.UpdateUI; -import com.qualcomm.robotcore.eventloop.EventLoopManager; -import com.qualcomm.robotcore.exception.RobotCoreException; -import com.qualcomm.robotcore.hardware.DcMotorController; -import com.qualcomm.robotcore.hardware.DeviceInterfaceModule; -import com.qualcomm.robotcore.hardware.Gamepad; -import com.qualcomm.robotcore.hardware.HardwareFactory; -import com.qualcomm.robotcore.hardware.HardwareMap; -import com.qualcomm.robotcore.hardware.LegacyModule; -import com.qualcomm.robotcore.hardware.ServoController; -import com.qualcomm.robotcore.hardware.VoltageSensor; -import com.qualcomm.robotcore.robocol.Command; -import com.qualcomm.robotcore.robocol.Telemetry; -import com.qualcomm.robotcore.robot.RobotState; -import com.qualcomm.robotcore.util.BatteryChecker; -import com.qualcomm.robotcore.util.ElapsedTime; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.util.Iterator; -import java.util.Map.Entry; - -public class FtcEventLoopHandler implements BatteryChecker.BatteryWatcher { - public static final String NO_VOLTAGE_SENSOR = "no voltage sensor found"; - EventLoopManager a; - BatteryChecker b; - Context c; - ElapsedTime d = new ElapsedTime(); - double e = 0.25D; - UpdateUI.Callback f; - HardwareFactory g; - HardwareMap h = new HardwareMap(); - - public FtcEventLoopHandler(HardwareFactory var1, UpdateUI.Callback var2, Context var3) { - this.g = var1; - this.f = var2; - this.c = var3; - this.b = new BatteryChecker(var3, this, 180000L); - this.b.startBatteryMonitoring(); - } - - private void a() { - this.sendTelemetry("RobotController Battery Level", String.valueOf(this.b.getBatteryLevel())); - } - - private void b() { - Iterator var1 = this.h.voltageSensor.iterator(); - - double var2; - double var6; - for(var2 = Double.MAX_VALUE; var1.hasNext(); var2 = var6) { - VoltageSensor var5 = (VoltageSensor)var1.next(); - if(var5.getVoltage() < var2) { - var6 = var5.getVoltage(); - } else { - var6 = var2; - } - } - - String var4; - if(this.h.voltageSensor.size() == 0) { - var4 = "no voltage sensor found"; - } else { - var4 = String.valueOf((new BigDecimal(var2)).setScale(2, RoundingMode.HALF_UP).doubleValue()); - } - - this.sendTelemetry("Robot Battery Level", var4); - } - - public void displayGamePadInfo(String var1) { - Gamepad[] var2 = this.a.getGamepads(); - this.f.updateUi(var1, var2); - } - - public Gamepad[] getGamepads() { - return this.a.getGamepads(); - } - - public HardwareMap getHardwareMap() throws RobotCoreException, InterruptedException { - this.h = this.g.createHardwareMap(this.a); - return this.h; - } - - public String getOpMode(String var1) { - if(this.a.state != RobotState.RUNNING) { - var1 = "Stop Robot"; - } - - return var1; - } - - public void init(EventLoopManager var1) { - this.a = var1; - } - - public void restartRobot() { - this.b.endBatteryMonitoring(); - this.f.restartRobot(); - } - - public void sendBatteryInfo() { - this.a(); - this.b(); - } - - public void sendCommand(Command var1) { - this.a.sendCommand(var1); - } - - public void sendTelemetry(String var1, String var2) { - Telemetry var3 = new Telemetry(); - var3.setTag(var1); - var3.addData(var1, var2); - if(this.a != null) { - this.a.sendTelemetryData(var3); - var3.clearData(); - } - - } - - public void sendTelemetryData(Telemetry var1) { - if(this.d.time() > this.e) { - this.d.reset(); - if(var1.hasData()) { - this.a.sendTelemetryData(var1); - } - - var1.clearData(); - } - - } - - public void shutdownCoreInterfaceDeviceModules() { - Iterator var1 = this.h.deviceInterfaceModule.entrySet().iterator(); - - while(var1.hasNext()) { - Entry var2 = (Entry)var1.next(); - String var3 = (String)var2.getKey(); - DeviceInterfaceModule var4 = (DeviceInterfaceModule)var2.getValue(); - DbgLog.msg("Stopping Core Interface Device Module " + var3); - var4.close(); - } - - } - - public void shutdownLegacyModules() { - Iterator var1 = this.h.legacyModule.entrySet().iterator(); - - while(var1.hasNext()) { - Entry var2 = (Entry)var1.next(); - String var3 = (String)var2.getKey(); - LegacyModule var4 = (LegacyModule)var2.getValue(); - DbgLog.msg("Stopping Legacy Module " + var3); - var4.close(); - } - - } - - public void shutdownMotorControllers() { - Iterator var1 = this.h.dcMotorController.entrySet().iterator(); - - while(var1.hasNext()) { - Entry var2 = (Entry)var1.next(); - String var3 = (String)var2.getKey(); - DcMotorController var4 = (DcMotorController)var2.getValue(); - DbgLog.msg("Stopping DC Motor Controller " + var3); - var4.close(); - } - - } - - public void shutdownServoControllers() { - Iterator var1 = this.h.servoController.entrySet().iterator(); - - while(var1.hasNext()) { - Entry var2 = (Entry)var1.next(); - String var3 = (String)var2.getKey(); - ServoController var4 = (ServoController)var2.getValue(); - DbgLog.msg("Stopping Servo Controller " + var3); - var4.close(); - } - - } - - public void updateBatteryLevel(float var1) { - this.sendTelemetry("RobotController Battery Level", String.valueOf(var1)); - } -} +package com.qualcomm.ftccommon; + +import android.content.Context; + +import com.qualcomm.robotcore.eventloop.EventLoopManager; +import com.qualcomm.robotcore.exception.RobotCoreException; +import com.qualcomm.robotcore.hardware.DcMotorController; +import com.qualcomm.robotcore.hardware.DeviceInterfaceModule; +import com.qualcomm.robotcore.hardware.Gamepad; +import com.qualcomm.robotcore.hardware.HardwareFactory; +import com.qualcomm.robotcore.hardware.HardwareMap; +import com.qualcomm.robotcore.hardware.LegacyModule; +import com.qualcomm.robotcore.hardware.ServoController; +import com.qualcomm.robotcore.hardware.VoltageSensor; +import com.qualcomm.robotcore.robocol.Command; +import com.qualcomm.robotcore.robocol.Telemetry; +import com.qualcomm.robotcore.robot.RobotState; +import com.qualcomm.robotcore.util.BatteryChecker; +import com.qualcomm.robotcore.util.ElapsedTime; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.Iterator; +import java.util.Map.Entry; + +public class FtcEventLoopHandler implements BatteryChecker.BatteryWatcher { + public static final String NO_VOLTAGE_SENSOR = "no voltage sensor found"; + EventLoopManager a; + BatteryChecker b; + Context c; + ElapsedTime d = new ElapsedTime(); + double e = 0.25D; + UpdateUI.Callback f; + HardwareFactory g; + HardwareMap h = new HardwareMap(); + + public FtcEventLoopHandler(HardwareFactory var1, UpdateUI.Callback var2, Context var3) { + this.g = var1; + this.f = var2; + this.c = var3; + this.b = new BatteryChecker(var3, this, 180000L); + this.b.startBatteryMonitoring(); + } + + private void a() { + this.sendTelemetry("RobotController Battery Level", String.valueOf(this.b.getBatteryLevel())); + } + + private void b() { + Iterator var1 = this.h.voltageSensor.iterator(); + + double var2; + double var6; + for(var2 = Double.MAX_VALUE; var1.hasNext(); var2 = var6) { + VoltageSensor var5 = (VoltageSensor)var1.next(); + if(var5.getVoltage() < var2) { + var6 = var5.getVoltage(); + } else { + var6 = var2; + } + } + + String var4; + if(this.h.voltageSensor.size() == 0) { + var4 = "no voltage sensor found"; + } else { + var4 = String.valueOf((new BigDecimal(var2)).setScale(2, RoundingMode.HALF_UP).doubleValue()); + } + + this.sendTelemetry("Robot Battery Level", var4); + } + + public void displayGamePadInfo(String var1) { + Gamepad[] var2 = this.a.getGamepads(); + this.f.updateUi(var1, var2); + } + + public Gamepad[] getGamepads() { + return this.a.getGamepads(); + } + + public HardwareMap getHardwareMap() throws RobotCoreException, InterruptedException { + this.h = this.g.createHardwareMap(this.a); + return this.h; + } + + public String getOpMode(String var1) { + if(this.a.state != RobotState.RUNNING) { + var1 = "Stop Robot"; + } + + return var1; + } + + public void init(EventLoopManager var1) { + this.a = var1; + } + + public void restartRobot() { + this.b.endBatteryMonitoring(); + this.f.restartRobot(); + } + + public void sendBatteryInfo() { + this.a(); + this.b(); + } + + public void sendCommand(Command var1) { + this.a.sendCommand(var1); + } + + public void sendTelemetry(String var1, String var2) { + Telemetry var3 = new Telemetry(); + var3.setTag(var1); + var3.addData(var1, var2); + if(this.a != null) { + this.a.sendTelemetryData(var3); + var3.clearData(); + } + + } + + public void sendTelemetryData(Telemetry var1) { + if(this.d.time() > this.e) { + this.d.reset(); + if(var1.hasData()) { + this.a.sendTelemetryData(var1); + } + + var1.clearData(); + } + + } + + public void shutdownCoreInterfaceDeviceModules() { + Iterator var1 = this.h.deviceInterfaceModule.entrySet().iterator(); + + while(var1.hasNext()) { + Entry var2 = (Entry)var1.next(); + String var3 = (String)var2.getKey(); + DeviceInterfaceModule var4 = (DeviceInterfaceModule)var2.getValue(); + DbgLog.msg("Stopping Core Interface Device Module " + var3); + var4.close(); + } + + } + + public void shutdownLegacyModules() { + Iterator var1 = this.h.legacyModule.entrySet().iterator(); + + while(var1.hasNext()) { + Entry var2 = (Entry)var1.next(); + String var3 = (String)var2.getKey(); + LegacyModule var4 = (LegacyModule)var2.getValue(); + DbgLog.msg("Stopping Legacy Module " + var3); + var4.close(); + } + + } + + public void shutdownMotorControllers() { + Iterator var1 = this.h.dcMotorController.entrySet().iterator(); + + while(var1.hasNext()) { + Entry var2 = (Entry)var1.next(); + String var3 = (String)var2.getKey(); + DcMotorController var4 = (DcMotorController)var2.getValue(); + DbgLog.msg("Stopping DC Motor Controller " + var3); + var4.close(); + } + + } + + public void shutdownServoControllers() { + Iterator var1 = this.h.servoController.entrySet().iterator(); + + while(var1.hasNext()) { + Entry var2 = (Entry)var1.next(); + String var3 = (String)var2.getKey(); + ServoController var4 = (ServoController)var2.getValue(); + DbgLog.msg("Stopping Servo Controller " + var3); + var4.close(); + } + + } + + public void updateBatteryLevel(float var1) { + this.sendTelemetry("RobotController Battery Level", String.valueOf(var1)); + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/FtcRobotControllerService.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/FtcRobotControllerService.java similarity index 91% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/FtcRobotControllerService.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/FtcRobotControllerService.java index 9491498..93c5ad3 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/FtcRobotControllerService.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/FtcRobotControllerService.java @@ -1,253 +1,254 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package com.qualcomm.ftccommon; - -import android.app.Service; -import android.content.Intent; -import android.os.Binder; -import android.os.Build; -import android.os.IBinder; -import com.qualcomm.ftccommon.DbgLog; -import com.qualcomm.ftccommon.UpdateUI.Callback; -import com.qualcomm.robotcore.eventloop.EventLoop; -import com.qualcomm.robotcore.eventloop.EventLoopManager.EventLoopMonitor; -import com.qualcomm.robotcore.exception.RobotCoreException; -import com.qualcomm.robotcore.factory.RobotFactory; -import com.qualcomm.robotcore.robot.Robot; -import com.qualcomm.robotcore.robot.RobotState; -import com.qualcomm.robotcore.util.ElapsedTime; -import com.qualcomm.robotcore.util.RobotLog; -import com.qualcomm.robotcore.wifi.WifiDirectAssistant; -import com.qualcomm.robotcore.wifi.WifiDirectAssistant.Event; -import com.qualcomm.robotcore.wifi.WifiDirectAssistant.WifiDirectAssistantCallback; -import java.lang.Thread.State; -import java.net.InetAddress; - -public class FtcRobotControllerService extends Service implements WifiDirectAssistantCallback { - private final IBinder a = new FtcRobotControllerService.FtcRobotControllerBinder(); - private WifiDirectAssistant b; - private Robot c; - private EventLoop d; - private Event e; - private String f; - private Callback g; - private final FtcRobotControllerService.a h; - private final ElapsedTime i; - private Thread j; - - public FtcRobotControllerService() { - this.e = Event.DISCONNECTED; - this.f = "Robot Status: null"; - this.g = null; - this.h = new FtcRobotControllerService.a((FtcRobotControllerService.SyntheticClass_1)null); - this.i = new ElapsedTime(); - this.j = null; - } - - public WifiDirectAssistant getWifiDirectAssistant() { - return this.b; - } - - public Event getWifiDirectStatus() { - return this.e; - } - - public String getRobotStatus() { - return this.f; - } - - public IBinder onBind(Intent intent) { - DbgLog.msg("Starting FTC Controller Service"); - DbgLog.msg("Android device is " + Build.MANUFACTURER + ", " + Build.MODEL); - this.b = WifiDirectAssistant.getWifiDirectAssistant(this); - this.b.setCallback(this); - this.b.enable(); - if(Build.MODEL.equals("FL7007")) { - this.b.discoverPeers(); - } else { - this.b.createGroup(); - } - - return this.a; - } - - public boolean onUnbind(Intent intent) { - DbgLog.msg("Stopping FTC Controller Service"); - this.b.disable(); - this.shutdownRobot(); - return false; - } - - public synchronized void setCallback(Callback callback) { - this.g = callback; - } - - public synchronized void setupRobot(EventLoop eventLoop) { - if(this.j != null && this.j.isAlive()) { - DbgLog.msg("FtcRobotControllerService.setupRobot() is currently running, stopping old setup"); - this.j.interrupt(); - - while(this.j.isAlive()) { - Thread.yield(); - } - - DbgLog.msg("Old setup stopped; restarting setup"); - } - - RobotLog.clearGlobalErrorMsg(); - DbgLog.msg("Processing robot setup"); - this.d = eventLoop; - this.j = new Thread(new FtcRobotControllerService.b((FtcRobotControllerService.SyntheticClass_1)null), "Robot Setup"); - this.j.start(); - - while(this.j.getState() == State.NEW) { - Thread.yield(); - } - - } - - public synchronized void shutdownRobot() { - if(this.j != null && this.j.isAlive()) { - this.j.interrupt(); - } - - if(this.c != null) { - this.c.shutdown(); - } - - this.c = null; - this.a("Robot Status: null"); - } - - public void onWifiDirectEvent(Event event) { - switch(FtcRobotControllerService.SyntheticClass_1.b[event.ordinal()]) { - case 1: - DbgLog.msg("Wifi Direct - Group Owner"); - this.b.cancelDiscoverPeers(); - break; - case 2: - DbgLog.error("Wifi Direct - connected as peer, was expecting Group Owner"); - break; - case 3: - DbgLog.msg("Wifi Direct Passphrase: " + this.b.getPassphrase()); - break; - case 4: - DbgLog.error("Wifi Direct Error: " + this.b.getFailureReason()); - } - - this.a(event); - } - - private void a(Event var1) { - this.e = var1; - if(this.g != null) { - this.g.wifiDirectUpdate(this.e); - } - - } - - private void a(String var1) { - this.f = var1; - if(this.g != null) { - this.g.robotUpdate(var1); - } - - } - - private class b implements Runnable { - private b() { - } - - public void run() { - try { - if(FtcRobotControllerService.this.c != null) { - FtcRobotControllerService.this.c.shutdown(); - FtcRobotControllerService.this.c = null; - } - - FtcRobotControllerService.this.a("Robot Status: scanning for USB devices"); - - try { - Thread.sleep(2000L); - } catch (InterruptedException var4) { - FtcRobotControllerService.this.a("Robot Status: abort due to interrupt"); - return; - } - - FtcRobotControllerService.this.c = RobotFactory.createRobot(); - FtcRobotControllerService.this.a("Robot Status: waiting on network"); - FtcRobotControllerService.this.i.reset(); - - while(!FtcRobotControllerService.this.b.isConnected()) { - try { - Thread.sleep(1000L); - if(FtcRobotControllerService.this.i.time() > 120.0D) { - FtcRobotControllerService.this.a("Robot Status: network timed out"); - return; - } - } catch (InterruptedException var3) { - DbgLog.msg("interrupt waiting for network; aborting setup"); - return; - } - } - - FtcRobotControllerService.this.a("Robot Status: starting robot"); - - try { - FtcRobotControllerService.this.c.eventLoopManager.setMonitor(FtcRobotControllerService.this.h); - InetAddress var1 = FtcRobotControllerService.this.b.getGroupOwnerAddress(); - FtcRobotControllerService.this.c.start(var1, FtcRobotControllerService.this.d); - } catch (RobotCoreException var2) { - FtcRobotControllerService.this.a("Robot Status: failed to start robot"); - RobotLog.setGlobalErrorMsg(var2.getMessage()); - } - } catch (RobotCoreException var5) { - FtcRobotControllerService.this.a("Robot Status: Unable to create robot!"); - RobotLog.setGlobalErrorMsg(var5.getMessage()); - } - - } - } - - private class a implements EventLoopMonitor { - private a() { - } - - public void onStateChange(RobotState state) { - if(FtcRobotControllerService.this.g != null) { - switch(FtcRobotControllerService.SyntheticClass_1.a[state.ordinal()]) { - case 1: - FtcRobotControllerService.this.g.robotUpdate("Robot Status: init"); - break; - case 2: - FtcRobotControllerService.this.g.robotUpdate("Robot Status: not started"); - break; - case 3: - FtcRobotControllerService.this.g.robotUpdate("Robot Status: running"); - break; - case 4: - FtcRobotControllerService.this.g.robotUpdate("Robot Status: stopped"); - break; - case 5: - FtcRobotControllerService.this.g.robotUpdate("Robot Status: EMERGENCY STOP"); - break; - case 6: - FtcRobotControllerService.this.g.robotUpdate("Robot Status: dropped connection"); - } - - } - } - } - - public class FtcRobotControllerBinder extends Binder { - public FtcRobotControllerBinder() { - } - - public FtcRobotControllerService getService() { - return FtcRobotControllerService.this; - } - } -} +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package com.qualcomm.ftccommon; + +import android.app.Service; +import android.content.Intent; +import android.os.Binder; +import android.os.Build; +import android.os.IBinder; + +import com.qualcomm.ftccommon.UpdateUI.Callback; +import com.qualcomm.robotcore.eventloop.EventLoop; +import com.qualcomm.robotcore.eventloop.EventLoopManager.EventLoopMonitor; +import com.qualcomm.robotcore.exception.RobotCoreException; +import com.qualcomm.robotcore.factory.RobotFactory; +import com.qualcomm.robotcore.robot.Robot; +import com.qualcomm.robotcore.robot.RobotState; +import com.qualcomm.robotcore.util.ElapsedTime; +import com.qualcomm.robotcore.util.RobotLog; +import com.qualcomm.robotcore.wifi.WifiDirectAssistant; +import com.qualcomm.robotcore.wifi.WifiDirectAssistant.Event; +import com.qualcomm.robotcore.wifi.WifiDirectAssistant.WifiDirectAssistantCallback; + +import java.lang.Thread.State; +import java.net.InetAddress; + +public class FtcRobotControllerService extends Service implements WifiDirectAssistantCallback { + private final IBinder a = new FtcRobotControllerBinder(); + private final FtcRobotControllerService.a h; + private final ElapsedTime i; + private WifiDirectAssistant b; + private Robot c; + private EventLoop d; + private Event e; + private String f; + private Callback g; + private Thread j; + + public FtcRobotControllerService() { + this.e = Event.DISCONNECTED; + this.f = "Robot Status: null"; + this.g = null; + this.h = new a(); + this.i = new ElapsedTime(); + this.j = null; + } + + public WifiDirectAssistant getWifiDirectAssistant() { + return this.b; + } + + public Event getWifiDirectStatus() { + return this.e; + } + + public String getRobotStatus() { + return this.f; + } + + public IBinder onBind(Intent intent) { + DbgLog.msg("Starting FTC Controller Service"); + DbgLog.msg("Android device is " + Build.MANUFACTURER + ", " + Build.MODEL); + this.b = WifiDirectAssistant.getWifiDirectAssistant(this); + this.b.setCallback(this); + this.b.enable(); + if(Build.MODEL.equals("FL7007")) { + this.b.discoverPeers(); + } else { + this.b.createGroup(); + } + + return this.a; + } + + public boolean onUnbind(Intent intent) { + DbgLog.msg("Stopping FTC Controller Service"); + this.b.disable(); + this.shutdownRobot(); + return false; + } + + public synchronized void setCallback(Callback callback) { + this.g = callback; + } + + public synchronized void setupRobot(EventLoop eventLoop) { + if(this.j != null && this.j.isAlive()) { + DbgLog.msg("FtcRobotControllerService.setupRobot() is currently running, stopping old setup"); + this.j.interrupt(); + + while(this.j.isAlive()) { + Thread.yield(); + } + + DbgLog.msg("Old setup stopped; restarting setup"); + } + + RobotLog.clearGlobalErrorMsg(); + DbgLog.msg("Processing robot setup"); + this.d = eventLoop; + this.j = new Thread(new b(), "Robot Setup"); + this.j.start(); + + while(this.j.getState() == State.NEW) { + Thread.yield(); + } + + } + + public synchronized void shutdownRobot() { + if(this.j != null && this.j.isAlive()) { + this.j.interrupt(); + } + + if(this.c != null) { + this.c.shutdown(); + } + + this.c = null; + this.a("Robot Status: null"); + } + + public void onWifiDirectEvent(Event event) { + switch (event.ordinal()) { + case 1: + DbgLog.msg("Wifi Direct - Group Owner"); + this.b.cancelDiscoverPeers(); + break; + case 2: + DbgLog.error("Wifi Direct - connected as peer, was expecting Group Owner"); + break; + case 3: + DbgLog.msg("Wifi Direct Passphrase: " + this.b.getPassphrase()); + break; + case 4: + DbgLog.error("Wifi Direct Error: " + this.b.getFailureReason()); + } + + this.a(event); + } + + private void a(Event var1) { + this.e = var1; + if(this.g != null) { + this.g.wifiDirectUpdate(this.e); + } + + } + + private void a(String var1) { + this.f = var1; + if(this.g != null) { + this.g.robotUpdate(var1); + } + + } + + private class b implements Runnable { + private b() { + } + + public void run() { + try { + if(FtcRobotControllerService.this.c != null) { + FtcRobotControllerService.this.c.shutdown(); + FtcRobotControllerService.this.c = null; + } + + FtcRobotControllerService.this.a("Robot Status: scanning for USB devices"); + + try { + Thread.sleep(2000L); + } catch (InterruptedException var4) { + FtcRobotControllerService.this.a("Robot Status: abort due to interrupt"); + return; + } + + FtcRobotControllerService.this.c = RobotFactory.createRobot(); + FtcRobotControllerService.this.a("Robot Status: waiting on network"); + FtcRobotControllerService.this.i.reset(); + + while(!FtcRobotControllerService.this.b.isConnected()) { + try { + Thread.sleep(1000L); + if(FtcRobotControllerService.this.i.time() > 120.0D) { + FtcRobotControllerService.this.a("Robot Status: network timed out"); + return; + } + } catch (InterruptedException var3) { + DbgLog.msg("interrupt waiting for network; aborting setup"); + return; + } + } + + FtcRobotControllerService.this.a("Robot Status: starting robot"); + + try { + FtcRobotControllerService.this.c.eventLoopManager.setMonitor(FtcRobotControllerService.this.h); + InetAddress var1 = FtcRobotControllerService.this.b.getGroupOwnerAddress(); + FtcRobotControllerService.this.c.start(var1, FtcRobotControllerService.this.d); + } catch (RobotCoreException var2) { + FtcRobotControllerService.this.a("Robot Status: failed to start robot"); + RobotLog.setGlobalErrorMsg(var2.getMessage()); + } + } catch (RobotCoreException var5) { + FtcRobotControllerService.this.a("Robot Status: Unable to create robot!"); + RobotLog.setGlobalErrorMsg(var5.getMessage()); + } + + } + } + + private class a implements EventLoopMonitor { + private a() { + } + + public void onStateChange(RobotState state) { + if(FtcRobotControllerService.this.g != null) { + switch (state.ordinal()) { + case 1: + FtcRobotControllerService.this.g.robotUpdate("Robot Status: init"); + break; + case 2: + FtcRobotControllerService.this.g.robotUpdate("Robot Status: not started"); + break; + case 3: + FtcRobotControllerService.this.g.robotUpdate("Robot Status: running"); + break; + case 4: + FtcRobotControllerService.this.g.robotUpdate("Robot Status: stopped"); + break; + case 5: + FtcRobotControllerService.this.g.robotUpdate("Robot Status: EMERGENCY STOP"); + break; + case 6: + FtcRobotControllerService.this.g.robotUpdate("Robot Status: dropped connection"); + } + + } + } + } + + public class FtcRobotControllerBinder extends Binder { + public FtcRobotControllerBinder() { + } + + public FtcRobotControllerService getService() { + return FtcRobotControllerService.this; + } + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/FtcRobotControllerSettingsActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/FtcRobotControllerSettingsActivity.java similarity index 94% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/FtcRobotControllerSettingsActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/FtcRobotControllerSettingsActivity.java index 80d305e..1af9fb9 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/FtcRobotControllerSettingsActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/FtcRobotControllerSettingsActivity.java @@ -1,76 +1,75 @@ -package com.qualcomm.ftccommon; - -import android.app.Activity; -import android.content.Intent; -import android.os.Build; -import android.os.Bundle; -import android.preference.Preference; -import android.preference.PreferenceFragment; -import android.preference.Preference.OnPreferenceClickListener; -import android.widget.Toast; -import com.qualcomm.ftccommon.R; - -public class FtcRobotControllerSettingsActivity extends Activity { - protected void onCreate(Bundle var1) { - super.onCreate(var1); - this.getFragmentManager().beginTransaction().replace(16908290, new FtcRobotControllerSettingsActivity.SettingsFragment()).commit(); - } - - public static class SettingsFragment extends PreferenceFragment { - OnPreferenceClickListener a = new OnPreferenceClickListener() { - public boolean onPreferenceClick(Preference var1) { - Intent var2 = new Intent(var1.getIntent().getAction()); - SettingsFragment.this.startActivityForResult(var2, 3); - return true; - } - }; - - public void onActivityResult(int var1, int var2, Intent var3) { - if(var1 == 3 && var2 == -1) { - this.getActivity().setResult(-1, var3); - } - - } - - public void onCreate(Bundle var1) { - super.onCreate(var1); - this.addPreferencesFromResource(R.xml.preferences); - this.findPreference(this.getString(R.string.pref_launch_configure)).setOnPreferenceClickListener(this.a); - this.findPreference(this.getString(R.string.pref_launch_autoconfigure)).setOnPreferenceClickListener(this.a); - if(Build.MANUFACTURER.equalsIgnoreCase("zte") && Build.MODEL.equalsIgnoreCase("N9130")) { - this.findPreference(this.getString(R.string.pref_launch_settings)).setOnPreferenceClickListener(new OnPreferenceClickListener() { - public boolean onPreferenceClick(Preference var1) { - Intent var2 = SettingsFragment.this.getActivity().getPackageManager().getLaunchIntentForPackage("com.zte.wifichanneleditor"); - - try { - SettingsFragment.this.startActivity(var2); - } catch (NullPointerException var4) { - Toast.makeText(SettingsFragment.this.getActivity(), "Unable to launch ZTE WifiChannelEditor", 0).show(); - } - - return true; - } - }); - } else { - this.findPreference(this.getString(R.string.pref_launch_settings)).setOnPreferenceClickListener(new OnPreferenceClickListener() { - public boolean onPreferenceClick(Preference var1) { - Intent var2 = new Intent(var1.getIntent().getAction()); - SettingsFragment.this.startActivity(var2); - return true; - } - }); - } - - if(Build.MODEL.equals("FL7007")) { - this.findPreference(this.getString(R.string.pref_launch_settings)).setOnPreferenceClickListener(new OnPreferenceClickListener() { - public boolean onPreferenceClick(Preference var1) { - Intent var2 = new Intent("android.settings.SETTINGS"); - SettingsFragment.this.startActivity(var2); - return true; - } - }); - } - - } - } -} +package com.qualcomm.ftccommon; + +import android.app.Activity; +import android.content.Intent; +import android.os.Build; +import android.os.Bundle; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceClickListener; +import android.preference.PreferenceFragment; +import android.widget.Toast; + +public class FtcRobotControllerSettingsActivity extends Activity { + protected void onCreate(Bundle var1) { + super.onCreate(var1); + this.getFragmentManager().beginTransaction().replace(16908290, new SettingsFragment()).commit(); + } + + public static class SettingsFragment extends PreferenceFragment { + OnPreferenceClickListener a = new OnPreferenceClickListener() { + public boolean onPreferenceClick(Preference var1) { + Intent var2 = new Intent(var1.getIntent().getAction()); + SettingsFragment.this.startActivityForResult(var2, 3); + return true; + } + }; + + public void onActivityResult(int var1, int var2, Intent var3) { + if(var1 == 3 && var2 == -1) { + this.getActivity().setResult(-1, var3); + } + + } + + public void onCreate(Bundle var1) { + super.onCreate(var1); + this.addPreferencesFromResource(R.xml.preferences); + this.findPreference(this.getString(R.string.pref_launch_configure)).setOnPreferenceClickListener(this.a); + this.findPreference(this.getString(R.string.pref_launch_autoconfigure)).setOnPreferenceClickListener(this.a); + if(Build.MANUFACTURER.equalsIgnoreCase("zte") && Build.MODEL.equalsIgnoreCase("N9130")) { + this.findPreference(this.getString(R.string.pref_launch_settings)).setOnPreferenceClickListener(new OnPreferenceClickListener() { + public boolean onPreferenceClick(Preference var1) { + Intent var2 = SettingsFragment.this.getActivity().getPackageManager().getLaunchIntentForPackage("com.zte.wifichanneleditor"); + + try { + SettingsFragment.this.startActivity(var2); + } catch (NullPointerException var4) { + Toast.makeText(SettingsFragment.this.getActivity(), "Unable to launch ZTE WifiChannelEditor", 0).show(); + } + + return true; + } + }); + } else { + this.findPreference(this.getString(R.string.pref_launch_settings)).setOnPreferenceClickListener(new OnPreferenceClickListener() { + public boolean onPreferenceClick(Preference var1) { + Intent var2 = new Intent(var1.getIntent().getAction()); + SettingsFragment.this.startActivity(var2); + return true; + } + }); + } + + if(Build.MODEL.equals("FL7007")) { + this.findPreference(this.getString(R.string.pref_launch_settings)).setOnPreferenceClickListener(new OnPreferenceClickListener() { + public boolean onPreferenceClick(Preference var1) { + Intent var2 = new Intent("android.settings.SETTINGS"); + SettingsFragment.this.startActivity(var2); + return true; + } + }); + } + + } + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/FtcWifiChannelSelectorActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/FtcWifiChannelSelectorActivity.java similarity index 90% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/FtcWifiChannelSelectorActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/FtcWifiChannelSelectorActivity.java index e39af09..537cf34 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/FtcWifiChannelSelectorActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/FtcWifiChannelSelectorActivity.java @@ -1,144 +1,143 @@ -package com.qualcomm.ftccommon; - -import android.app.Activity; -import android.app.ProgressDialog; -import android.content.Context; -import android.content.Intent; -import android.net.wifi.WifiManager; -import android.os.Bundle; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.Spinner; -import android.widget.Toast; -import android.widget.AdapterView.OnItemSelectedListener; -import com.qualcomm.ftccommon.DbgLog; -import com.qualcomm.ftccommon.R; -import com.qualcomm.wirelessp2p.WifiDirectChannelSelection; -import java.io.IOException; - -public class FtcWifiChannelSelectorActivity extends Activity implements OnClickListener, OnItemSelectedListener { - private static int a = 0; - private Button b; - private Button c; - private Spinner d; - private ProgressDialog e; - private WifiDirectChannelSelection f; - private int g = -1; - private int h = -1; - private Context i; - - private void a() { - Object[] var1 = new Object[]{Integer.valueOf(this.g), Integer.valueOf(this.h)}; - DbgLog.msg(String.format("configure p2p channel - class %d channel %d", var1)); - - try { - this.e = ProgressDialog.show(this, "Configuring Channel", "Please Wait", true); - this.f.config(this.g, this.h); - (new Thread(new Runnable() { - public void run() { - try { - Thread.sleep(5000L); - } catch (InterruptedException var2) { - ; - } - - FtcWifiChannelSelectorActivity.this.runOnUiThread(new Runnable() { - public void run() { - FtcWifiChannelSelectorActivity.this.setResult(-1); - FtcWifiChannelSelectorActivity.this.e.dismiss(); - FtcWifiChannelSelectorActivity.this.finish(); - } - }); - } - })).start(); - } catch (IOException var3) { - this.a("Failed - root is required", 0); - var3.printStackTrace(); - } - } - - private void a(final String var1, final int var2) { - this.runOnUiThread(new Runnable() { - public void run() { - Toast.makeText(FtcWifiChannelSelectorActivity.this.i, var1, var2).show(); - } - }); - } - - public void onClick(View var1) { - if(var1.getId() == R.id.buttonConfigure) { - a = this.d.getSelectedItemPosition(); - this.a(); - } else if(var1.getId() == R.id.buttonWifiSettings) { - DbgLog.msg("launch wifi settings"); - this.startActivity(new Intent("android.net.wifi.PICK_WIFI_NETWORK")); - return; - } - - } - - protected void onCreate(Bundle var1) { - super.onCreate(var1); - this.setContentView(R.layout.activity_ftc_wifi_channel_selector); - this.i = this; - this.d = (Spinner)this.findViewById(R.id.spinnerChannelSelect); - ArrayAdapter var2 = ArrayAdapter.createFromResource(this, R.array.wifi_direct_channels, 17367048); - var2.setDropDownViewResource(17367049); - this.d.setAdapter(var2); - this.d.setOnItemSelectedListener(this); - this.b = (Button)this.findViewById(R.id.buttonConfigure); - this.b.setOnClickListener(this); - this.c = (Button)this.findViewById(R.id.buttonWifiSettings); - this.c.setOnClickListener(this); - this.f = new WifiDirectChannelSelection(this, (WifiManager)this.getSystemService("wifi")); - } - - public void onItemSelected(AdapterView var1, View var2, int var3, long var4) { - switch(var3) { - case 0: - this.g = -1; - this.h = -1; - return; - case 1: - this.g = 81; - this.h = 1; - return; - case 2: - this.g = 81; - this.h = 6; - return; - case 3: - this.g = 81; - this.h = 11; - return; - case 4: - this.g = 124; - this.h = 149; - return; - case 5: - this.g = 124; - this.h = 153; - return; - case 6: - this.g = 124; - this.h = 157; - return; - case 7: - this.g = 124; - this.h = 161; - return; - default: - } - } - - public void onNothingSelected(AdapterView var1) { - } - - protected void onStart() { - super.onStart(); - this.d.setSelection(a); - } -} +package com.qualcomm.ftccommon; + +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.Context; +import android.content.Intent; +import android.net.wifi.WifiManager; +import android.os.Bundle; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.Spinner; +import android.widget.Toast; + +import com.qualcomm.wirelessP2p.WifiDirectChannelSelection; + +import java.io.IOException; + +public class FtcWifiChannelSelectorActivity extends Activity implements OnClickListener, OnItemSelectedListener { + private static int a = 0; + private Button b; + private Button c; + private Spinner d; + private ProgressDialog e; + private WifiDirectChannelSelection f; + private int g = -1; + private int h = -1; + private Context i; + + private void a() { + Object[] var1 = new Object[]{Integer.valueOf(this.g), Integer.valueOf(this.h)}; + DbgLog.msg(String.format("configure p2p channel - class %d channel %d", var1)); + + try { + this.e = ProgressDialog.show(this, "Configuring Channel", "Please Wait", true); + this.f.config(this.g, this.h); + (new Thread(new Runnable() { + public void run() { + try { + Thread.sleep(5000L); + } catch (InterruptedException var2) { + } + + FtcWifiChannelSelectorActivity.this.runOnUiThread(new Runnable() { + public void run() { + FtcWifiChannelSelectorActivity.this.setResult(-1); + FtcWifiChannelSelectorActivity.this.e.dismiss(); + FtcWifiChannelSelectorActivity.this.finish(); + } + }); + } + })).start(); + } catch (IOException var3) { + this.a("Failed - root is required", 0); + var3.printStackTrace(); + } + } + + private void a(final String var1, final int var2) { + this.runOnUiThread(new Runnable() { + public void run() { + Toast.makeText(FtcWifiChannelSelectorActivity.this.i, var1, var2).show(); + } + }); + } + + public void onClick(View var1) { + if(var1.getId() == R.id.buttonConfigure) { + a = this.d.getSelectedItemPosition(); + this.a(); + } else if(var1.getId() == R.id.buttonWifiSettings) { + DbgLog.msg("launch wifi settings"); + this.startActivity(new Intent("android.net.wifi.PICK_WIFI_NETWORK")); + return; + } + + } + + protected void onCreate(Bundle var1) { + super.onCreate(var1); + this.setContentView(R.layout.activity_ftc_wifi_channel_selector); + this.i = this; + this.d = (Spinner)this.findViewById(R.id.spinnerChannelSelect); + ArrayAdapter var2 = ArrayAdapter.createFromResource(this, R.array.wifi_direct_channels, R.layout.activity_ftc_wifi_channel_selector); + var2.setDropDownViewResource(/* 17367049 */ R.layout.activity_ftc_wifi_channel_selector); + this.d.setAdapter(var2); + this.d.setOnItemSelectedListener(this); + this.b = (Button)this.findViewById(R.id.buttonConfigure); + this.b.setOnClickListener(this); + this.c = (Button)this.findViewById(R.id.buttonWifiSettings); + this.c.setOnClickListener(this); + this.f = new WifiDirectChannelSelection(this, (WifiManager) this.getSystemService(WIFI_SERVICE)); + } + + public void onItemSelected(AdapterView var1, View var2, int var3, long var4) { + switch(var3) { + case 0: + this.g = -1; + this.h = -1; + return; + case 1: + this.g = 81; + this.h = 1; + return; + case 2: + this.g = 81; + this.h = 6; + return; + case 3: + this.g = 81; + this.h = 11; + return; + case 4: + this.g = 124; + this.h = 149; + return; + case 5: + this.g = 124; + this.h = 153; + return; + case 6: + this.g = 124; + this.h = 157; + return; + case 7: + this.g = 124; + this.h = 161; + return; + default: + } + } + + public void onNothingSelected(AdapterView var1) { + } + + protected void onStart() { + super.onStart(); + this.d.setSelection(a); + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/LaunchActivityConstantsList.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/LaunchActivityConstantsList.java similarity index 97% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/LaunchActivityConstantsList.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/LaunchActivityConstantsList.java index 76f74c8..288d5fb 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/LaunchActivityConstantsList.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/LaunchActivityConstantsList.java @@ -1,7 +1,7 @@ -package com.qualcomm.ftccommon; - -public class LaunchActivityConstantsList { - public static final int FTC_ROBOT_CONTROLLER_ACTIVITY_CONFIGURE_ROBOT = 3; - public static final String VIEW_LOGS_ACTIVITY_FILENAME = "Filename"; - public static final String ZTE_WIFI_CHANNEL_EDITOR_PACKAGE = "com.zte.wifichanneleditor"; -} +package com.qualcomm.ftccommon; + +public class LaunchActivityConstantsList { + public static final int FTC_ROBOT_CONTROLLER_ACTIVITY_CONFIGURE_ROBOT = 3; + public static final String VIEW_LOGS_ACTIVITY_FILENAME = "Filename"; + public static final String ZTE_WIFI_CHANNEL_EDITOR_PACKAGE = "com.zte.wifichanneleditor"; +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/Restarter.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/Restarter.java similarity index 94% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/Restarter.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/Restarter.java index 15d348b..4638688 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/Restarter.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/Restarter.java @@ -1,5 +1,5 @@ -package com.qualcomm.ftccommon; - -public interface Restarter { - void requestRestart(); -} +package com.qualcomm.ftccommon; + +public interface Restarter { + void requestRestart(); +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/UpdateUI.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/UpdateUI.java similarity index 92% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/UpdateUI.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/UpdateUI.java index a46a3c4..6c54824 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/UpdateUI.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/UpdateUI.java @@ -1,143 +1,140 @@ -package com.qualcomm.ftccommon; - -import android.app.Activity; -import android.widget.TextView; -import android.widget.Toast; -import com.qualcomm.ftccommon.DbgLog; -import com.qualcomm.ftccommon.FtcRobotControllerService; -import com.qualcomm.ftccommon.Restarter; -import com.qualcomm.robotcore.hardware.Gamepad; -import com.qualcomm.robotcore.util.Dimmer; -import com.qualcomm.robotcore.util.RobotLog; -import com.qualcomm.robotcore.wifi.WifiDirectAssistant; - -public class UpdateUI { - Restarter a; - FtcRobotControllerService b; - Activity c; - Dimmer d; - protected TextView textDeviceName; - protected TextView textErrorMessage; - protected TextView[] textGamepad = new TextView[2]; - protected TextView textOpMode; - protected TextView textRobotStatus; - protected TextView textWifiDirectStatus; - - public UpdateUI(Activity var1, Dimmer var2) { - this.c = var1; - this.d = var2; - } - - private void a() { - this.a.requestRestart(); - } - - private void a(final String var1) { - DbgLog.msg(var1); - this.c.runOnUiThread(new Runnable() { - public void run() { - UpdateUI.this.textWifiDirectStatus.setText(var1); - } - }); - } - - private void b(final String var1) { - this.c.runOnUiThread(new Runnable() { - public void run() { - UpdateUI.this.textDeviceName.setText(var1); - } - }); - } - - public void setControllerService(FtcRobotControllerService var1) { - this.b = var1; - } - - public void setRestarter(Restarter var1) { - this.a = var1; - } - - public void setTextViews(TextView var1, TextView var2, TextView[] var3, TextView var4, TextView var5, TextView var6) { - this.textWifiDirectStatus = var1; - this.textRobotStatus = var2; - this.textGamepad = var3; - this.textOpMode = var4; - this.textErrorMessage = var5; - this.textDeviceName = var6; - } - - public class Callback { - public void restartRobot() { - UpdateUI.this.c.runOnUiThread(new Runnable() { - public void run() { - Toast.makeText(UpdateUI.this.c, "Restarting Robot", 0).show(); - } - }); - (new Thread() { - public void run() { - try { - Thread.sleep(1500L); - } catch (InterruptedException var2) { - ; - } - - UpdateUI.this.c.runOnUiThread(new Runnable() { - public void run() { - UpdateUI.this.a(); - } - }); - } - }).start(); - } - - public void robotUpdate(final String var1) { - DbgLog.msg(var1); - UpdateUI.this.c.runOnUiThread(new Runnable() { - public void run() { - UpdateUI.this.textRobotStatus.setText(var1); - UpdateUI.this.textErrorMessage.setText(RobotLog.getGlobalErrorMsg()); - if(RobotLog.hasGlobalErrorMsg()) { - UpdateUI.this.d.longBright(); - } - - } - }); - } - - public void updateUi(final String var1, final Gamepad[] var2) { - UpdateUI.this.c.runOnUiThread(new Runnable() { - public void run() { - for(int var1x = 0; var1x < UpdateUI.this.textGamepad.length && var1x < var2.length; ++var1x) { - if(var2[var1x].id == -1) { - UpdateUI.this.textGamepad[var1x].setText(" "); - } else { - UpdateUI.this.textGamepad[var1x].setText(var2[var1x].toString()); - } - } - - UpdateUI.this.textOpMode.setText("Op Mode: " + var1); - UpdateUI.this.textErrorMessage.setText(RobotLog.getGlobalErrorMsg()); - } - }); - } - - public void wifiDirectUpdate(WifiDirectAssistant.Event var1) { - switch(null.a[var1.ordinal()]) { - case 1: - UpdateUI.this.a("Wifi Direct - disconnected"); - return; - case 2: - UpdateUI.this.a("Wifi Direct - enabled"); - return; - case 3: - UpdateUI.this.a("Wifi Direct - ERROR"); - return; - case 4: - WifiDirectAssistant var2 = UpdateUI.this.b.getWifiDirectAssistant(); - UpdateUI.this.b(var2.getDeviceName()); - return; - default: - } - } - } -} +package com.qualcomm.ftccommon; + +import android.app.Activity; +import android.widget.TextView; +import android.widget.Toast; + +import com.qualcomm.robotcore.hardware.Gamepad; +import com.qualcomm.robotcore.util.Dimmer; +import com.qualcomm.robotcore.util.RobotLog; +import com.qualcomm.robotcore.wifi.WifiDirectAssistant; + +public class UpdateUI { + protected TextView textDeviceName; + protected TextView textErrorMessage; + protected TextView[] textGamepad = new TextView[2]; + protected TextView textOpMode; + protected TextView textRobotStatus; + protected TextView textWifiDirectStatus; + Restarter a; + FtcRobotControllerService b; + Activity c; + Dimmer d; + + public UpdateUI(Activity var1, Dimmer var2) { + this.c = var1; + this.d = var2; + } + + private void a() { + this.a.requestRestart(); + } + + private void a(final String var1) { + DbgLog.msg(var1); + this.c.runOnUiThread(new Runnable() { + public void run() { + UpdateUI.this.textWifiDirectStatus.setText(var1); + } + }); + } + + private void b(final String var1) { + this.c.runOnUiThread(new Runnable() { + public void run() { + UpdateUI.this.textDeviceName.setText(var1); + } + }); + } + + public void setControllerService(FtcRobotControllerService var1) { + this.b = var1; + } + + public void setRestarter(Restarter var1) { + this.a = var1; + } + + public void setTextViews(TextView var1, TextView var2, TextView[] var3, TextView var4, TextView var5, TextView var6) { + this.textWifiDirectStatus = var1; + this.textRobotStatus = var2; + this.textGamepad = var3; + this.textOpMode = var4; + this.textErrorMessage = var5; + this.textDeviceName = var6; + } + + public class Callback { + public void restartRobot() { + UpdateUI.this.c.runOnUiThread(new Runnable() { + public void run() { + Toast.makeText(UpdateUI.this.c, "Restarting Robot", 0).show(); + } + }); + (new Thread() { + public void run() { + try { + Thread.sleep(1500L); + } catch (InterruptedException var2) { + } + + UpdateUI.this.c.runOnUiThread(new Runnable() { + public void run() { + UpdateUI.this.a(); + } + }); + } + }).start(); + } + + public void robotUpdate(final String var1) { + DbgLog.msg(var1); + UpdateUI.this.c.runOnUiThread(new Runnable() { + public void run() { + UpdateUI.this.textRobotStatus.setText(var1); + UpdateUI.this.textErrorMessage.setText(RobotLog.getGlobalErrorMsg()); + if(RobotLog.hasGlobalErrorMsg()) { + UpdateUI.this.d.longBright(); + } + + } + }); + } + + public void updateUi(final String var1, final Gamepad[] var2) { + UpdateUI.this.c.runOnUiThread(new Runnable() { + public void run() { + for(int var1x = 0; var1x < UpdateUI.this.textGamepad.length && var1x < var2.length; ++var1x) { + if(var2[var1x].id == -1) { + UpdateUI.this.textGamepad[var1x].setText(" "); + } else { + UpdateUI.this.textGamepad[var1x].setText(var2[var1x].toString()); + } + } + + UpdateUI.this.textOpMode.setText("Op Mode: " + var1); + UpdateUI.this.textErrorMessage.setText(RobotLog.getGlobalErrorMsg()); + } + }); + } + + public void wifiDirectUpdate(WifiDirectAssistant.Event var1) { + switch (var1.ordinal()) { + case 1: + UpdateUI.this.a("Wifi Direct - disconnected"); + return; + case 2: + UpdateUI.this.a("Wifi Direct - enabled"); + return; + case 3: + UpdateUI.this.a("Wifi Direct - ERROR"); + return; + case 4: + WifiDirectAssistant var2 = UpdateUI.this.b.getWifiDirectAssistant(); + UpdateUI.this.b(var2.getDeviceName()); + return; + default: + } + } + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/ViewLogsActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/ViewLogsActivity.java similarity index 96% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/ViewLogsActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/ViewLogsActivity.java index 24f8f7c..7d8040d 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/ViewLogsActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/ViewLogsActivity.java @@ -1,108 +1,110 @@ -package com.qualcomm.ftccommon; - -import android.app.Activity; -import android.os.Bundle; -import android.os.Environment; -import android.text.Spannable; -import android.text.SpannableString; -import android.text.style.ForegroundColorSpan; -import android.widget.ScrollView; -import android.widget.TextView; -import com.qualcomm.ftccommon.R; -import com.qualcomm.robotcore.util.RobotLog; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.Serializable; - -public class ViewLogsActivity extends Activity { - public static final String FILENAME = "Filename"; - TextView a; - int b = 300; - String c = " "; - - private Spannable a(String var1) { - int var2 = 0; - SpannableString var3 = new SpannableString(var1); - String[] var4 = var1.split("\\n"); - int var5 = var4.length; - - for(int var6 = 0; var2 < var5; ++var2) { - String var7 = var4[var2]; - if(var7.contains("E/RobotCore") || var7.contains("### ERROR: ")) { - var3.setSpan(new ForegroundColorSpan(-65536), var6, var6 + var7.length(), 33); - } - - var6 = 1 + var6 + var7.length(); - } - - return var3; - } - - protected void onCreate(Bundle var1) { - super.onCreate(var1); - this.setContentView(R.layout.activity_view_logs); - this.a = (TextView)this.findViewById(R.id.textAdbLogs); - final ScrollView var2 = (ScrollView)this.findViewById(R.id.scrollView); - var2.post(new Runnable() { - public void run() { - var2.fullScroll(130); - } - }); - } - - protected void onStart() { - super.onStart(); - Serializable var1 = this.getIntent().getSerializableExtra("Filename"); - if(var1 != null) { - this.c = (String)var1; - } - - this.runOnUiThread(new Runnable() { - public void run() { - try { - String var2 = ViewLogsActivity.this.readNLines(ViewLogsActivity.this.b); - Spannable var3 = ViewLogsActivity.this.a(var2); - ViewLogsActivity.this.a.setText(var3); - } catch (IOException var4) { - RobotLog.e(var4.toString()); - ViewLogsActivity.this.a.setText("File not found: " + ViewLogsActivity.this.c); - } - } - }); - } - - public String readNLines(int var1) throws IOException { - Environment.getExternalStorageDirectory(); - BufferedReader var3 = new BufferedReader(new FileReader(new File(this.c))); - String[] var4 = new String[var1]; - int var5 = 0; - - while(true) { - String var6 = var3.readLine(); - if(var6 == null) { - int var7 = var5 - var1; - int var8 = 0; - if(var7 >= 0) { - var8 = var7; - } - - String var10 = ""; - - String var14; - for(int var11 = var8; var11 < var5; var10 = var14) { - String var13 = var4[var11 % var4.length]; - var14 = var10 + var13 + "\n"; - ++var11; - } - - int var12 = var10.lastIndexOf("--------- beginning"); - return var12 < 0?var10:var10.substring(var12); - } - - var4[var5 % var4.length] = var6; - ++var5; - } - } -} +package com.qualcomm.ftccommon; + +import android.app.Activity; +import android.os.Bundle; +import android.os.Environment; +import android.text.Spannable; +import android.text.SpannableString; +import android.text.style.ForegroundColorSpan; +import android.widget.ScrollView; +import android.widget.TextView; + +import com.qualcomm.ftccommon.R; +import com.qualcomm.robotcore.util.RobotLog; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.Serializable; + +public class ViewLogsActivity extends Activity { + public static final String FILENAME = "Filename"; + TextView a; + int b = 300; + String c = " "; + + private Spannable a(String var1) { + int var2 = 0; + SpannableString var3 = new SpannableString(var1); + String[] var4 = var1.split("\\n"); + int var5 = var4.length; + + for(int var6 = 0; var2 < var5; ++var2) { + String var7 = var4[var2]; + if(var7.contains("E/RobotCore") || var7.contains("### ERROR: ")) { + var3.setSpan(new ForegroundColorSpan(-65536), var6, var6 + var7.length(), 33); + } + + var6 = 1 + var6 + var7.length(); + } + + return var3; + } + + protected void onCreate(Bundle var1) { + super.onCreate(var1); + this.setContentView(R.layout.activity_view_logs); + this.a = (TextView)this.findViewById(R.id.textAdbLogs); + final ScrollView var2 = (ScrollView)this.findViewById(R.id.scrollView); + var2.post(new Runnable() { + public void run() { + var2.fullScroll(130); + } + }); + } + + protected void onStart() { + super.onStart(); + Serializable var1 = this.getIntent().getSerializableExtra("Filename"); + if(var1 != null) { + this.c = (String)var1; + } + + this.runOnUiThread(new Runnable() { + public void run() { + try { + String var2 = ViewLogsActivity.this.readNLines(ViewLogsActivity.this.b); + Spannable var3 = ViewLogsActivity.this.a(var2); + ViewLogsActivity.this.a.setText(var3); + } catch (IOException var4) { + RobotLog.e(var4.toString()); + ViewLogsActivity.this.a.setText("File not found: " + ViewLogsActivity.this.c); + } + } + }); + } + + public String readNLines(int var1) throws IOException { + Environment.getExternalStorageDirectory(); + BufferedReader var3 = new BufferedReader(new FileReader(new File(this.c))); + String[] var4 = new String[var1]; + int var5 = 0; + + while(true) { + String var6 = var3.readLine(); + if(var6 == null) { + int var7 = var5 - var1; + int var8 = 0; + if(var7 >= 0) { + var8 = var7; + } + + String var10 = ""; + + String var14; + for(int var11 = var8; var11 < var5; var10 = var14) { + String var13 = var4[var11 % var4.length]; + var14 = var10 + var13 + "\n"; + ++var11; + } + + int var12 = var10.lastIndexOf("--------- beginning"); + return var12 < 0?var10:var10.substring(var12); + } + + var4[var5 % var4.length] = var6; + ++var5; + } + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/AutoConfigureActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/AutoConfigureActivity.java similarity index 97% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/AutoConfigureActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/AutoConfigureActivity.java index 81ef5da..bfd3a7c 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/AutoConfigureActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/AutoConfigureActivity.java @@ -1,356 +1,358 @@ -package com.qualcomm.ftccommon.configuration; - -import android.app.Activity; -import android.content.Context; -import android.os.Bundle; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.Toast; -import com.qualcomm.ftccommon.DbgLog; -import com.qualcomm.ftccommon.R; -import com.qualcomm.hardware.ModernRoboticsDeviceManager; -import com.qualcomm.robotcore.eventloop.EventLoopManager; -import com.qualcomm.robotcore.exception.RobotCoreException; -import com.qualcomm.robotcore.hardware.DeviceManager; -import com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration; -import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; -import com.qualcomm.robotcore.hardware.configuration.LegacyModuleControllerConfiguration; -import com.qualcomm.robotcore.hardware.configuration.MotorConfiguration; -import com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration; -import com.qualcomm.robotcore.hardware.configuration.ServoConfiguration; -import com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration; -import com.qualcomm.robotcore.hardware.configuration.Utility; -import com.qualcomm.robotcore.util.SerialNumber; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.Map.Entry; - -public class AutoConfigureActivity extends Activity { - private Context a; - private Button b; - private Button c; - private DeviceManager d; - private Map e = new HashMap(); - protected Set> entries = new HashSet(); - private Thread f; - private Utility g; - protected Map scannedDevices = new HashMap(); - - private DeviceConfiguration a(DeviceConfiguration.ConfigurationType var1, String var2, int var3) { - return new DeviceConfiguration(var3, var1, var2, true); - } - - private MotorControllerConfiguration a(SerialNumber var1, String var2, String var3, String var4) { - MotorControllerConfiguration var5; - if(!var1.equals(ControllerConfiguration.NO_SERIAL_NUMBER)) { - var5 = (MotorControllerConfiguration)this.e.get(var1); - } else { - var5 = new MotorControllerConfiguration(); - } - - var5.setName(var4); - ArrayList var6 = new ArrayList(); - MotorConfiguration var7 = new MotorConfiguration(1, var2, true); - MotorConfiguration var8 = new MotorConfiguration(2, var3, true); - var6.add(var7); - var6.add(var8); - var5.addMotors(var6); - return var5; - } - - private ServoControllerConfiguration a(SerialNumber var1, ArrayList var2, String var3) { - ServoControllerConfiguration var4; - if(!var1.equals(ControllerConfiguration.NO_SERIAL_NUMBER)) { - var4 = (ServoControllerConfiguration)this.e.get(var1); - } else { - var4 = new ServoControllerConfiguration(); - } - - var4.setName(var3); - ArrayList var5 = new ArrayList(); - - for(int var6 = 1; var6 <= 6; ++var6) { - String var7 = (String)var2.get(var6 - 1); - boolean var8; - if(var7.equals("NO DEVICE ATTACHED")) { - var8 = false; - } else { - var8 = true; - } - - var5.add(new ServoConfiguration(var6, var7, var8)); - } - - var4.addServos(var5); - return var4; - } - - private void a() { - this.g.setOrangeText("No devices found!", "To configure K9LegacyBot, please: \n 1. Attach a LegacyModuleController, \n with \n a. MotorController in port 0, with a \n motor in port 1 and port 2 \n b. ServoController in port 1, with a \n servo in port 1 and port 6 \n c. IR seeker in port 2\n d. Light sensor in port 3 \n 2. Press the K9LegacyBot button\n \nTo configure K9USBBot, please: \n 1. Attach a USBMotorController, with a \n motor in port 1 and port 2 \n 2. USBServoController in port 1, with a \n servo in port 1 and port 6 \n 3. LegacyModule, with \n a. IR seeker in port 2\n b. Light sensor in port 3 \n 4. Press the K9USBBot button", R.id.autoconfigure_info, R.layout.orange_warning, R.id.orangetext0, R.id.orangetext1); - } - - private void a(SerialNumber var1, String var2) { - LegacyModuleControllerConfiguration var3 = (LegacyModuleControllerConfiguration)this.e.get(var1); - var3.setName(var2); - DeviceConfiguration var4 = this.a(DeviceConfiguration.ConfigurationType.IR_SEEKER, "ir_seeker", 2); - DeviceConfiguration var5 = this.a(DeviceConfiguration.ConfigurationType.LIGHT_SENSOR, "light_sensor", 3); - ArrayList var6 = new ArrayList(); - - for(int var7 = 0; var7 < 6; ++var7) { - if(var7 == 2) { - var6.add(var4); - } - - if(var7 == 3) { - var6.add(var5); - } else { - var6.add(new DeviceConfiguration(var7)); - } - } - - var3.addDevices(var6); - } - - private void a(String var1) { - this.g.writeXML(this.e); - - try { - this.g.writeToFile(var1 + ".xml"); - this.g.saveToPreferences(var1, R.string.pref_hardware_config_filename); - this.g.updateHeader(var1, R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - Toast.makeText(this.a, "AutoConfigure " + var1 + " Successful", 0).show(); - } catch (RobotCoreException var5) { - this.g.complainToast(var5.getMessage(), this.a); - DbgLog.error(var5.getMessage()); - } catch (IOException var6) { - this.g.complainToast("Found " + var6.getMessage() + "\n Please fix and re-save", this.a); - DbgLog.error(var6.getMessage()); - } - } - - private void b() { - String var1 = "Found: \n" + this.scannedDevices.values() + "\n" + "Required: \n" + " 1. LegacyModuleController, with \n " + " a. MotorController in port 0, with a \n" + " motor in port 1 and port 2 \n " + " b. ServoController in port 1, with a \n" + " servo in port 1 and port 6 \n" + " c. IR seeker in port 2\n" + " d. Light sensor in port 3 "; - this.g.setOrangeText("Wrong devices found!", var1, R.id.autoconfigure_info, R.layout.orange_warning, R.id.orangetext0, R.id.orangetext1); - } - - private void b(SerialNumber var1, String var2) { - LegacyModuleControllerConfiguration var3 = (LegacyModuleControllerConfiguration)this.e.get(var1); - var3.setName(var2); - MotorControllerConfiguration var4 = this.a(ControllerConfiguration.NO_SERIAL_NUMBER, "motor_1", "motor_2", "wheels"); - var4.setPort(0); - ArrayList var5 = this.f(); - ServoControllerConfiguration var6 = this.a(ControllerConfiguration.NO_SERIAL_NUMBER, var5, "servos"); - var6.setPort(1); - DeviceConfiguration var7 = this.a(DeviceConfiguration.ConfigurationType.IR_SEEKER, "ir_seeker", 2); - DeviceConfiguration var8 = this.a(DeviceConfiguration.ConfigurationType.LIGHT_SENSOR, "light_sensor", 3); - ArrayList var9 = new ArrayList(); - var9.add(var4); - var9.add(var6); - var9.add(var7); - var9.add(var8); - - for(int var14 = 4; var14 < 6; ++var14) { - var9.add(new DeviceConfiguration(var14)); - } - - var3.addDevices(var9); - } - - private void c() { - String var1 = "Found: \n" + this.scannedDevices.values() + "\n" + "Required: \n" + " 1. USBMotorController with a \n" + " motor in port 1 and port 2 \n " + " 2. USBServoController with a \n" + " servo in port 1 and port 6 \n" + " 3. LegacyModuleController, with \n " + " a. IR seeker in port 2\n" + " b. Light sensor in port 3 "; - this.g.setOrangeText("Wrong devices found!", var1, R.id.autoconfigure_info, R.layout.orange_warning, R.id.orangetext0, R.id.orangetext1); - } - - private void d() { - this.g.setOrangeText("Already configured!", "", R.id.autoconfigure_info, R.layout.orange_warning, R.id.orangetext0, R.id.orangetext1); - } - - private boolean e() { - Iterator var1 = this.entries.iterator(); - boolean var2 = true; - boolean var3 = true; - - boolean var4; - boolean var7; - for(var4 = true; var1.hasNext(); var4 = var7) { - Entry var5 = (Entry)var1.next(); - DeviceManager.DeviceType var6 = (DeviceManager.DeviceType)var5.getValue(); - if(var6 == DeviceManager.DeviceType.MODERN_ROBOTICS_USB_LEGACY_MODULE && var4) { - this.a((SerialNumber)var5.getKey(), "sensors"); - var7 = false; - } else { - var7 = var4; - } - - boolean var8; - if(var6 == DeviceManager.DeviceType.MODERN_ROBOTICS_USB_DC_MOTOR_CONTROLLER && var3) { - this.a((SerialNumber)var5.getKey(), "motor_1", "motor_2", "wheels"); - var8 = false; - } else { - var8 = var3; - } - - boolean var9; - if(var6 == DeviceManager.DeviceType.MODERN_ROBOTICS_USB_SERVO_CONTROLLER && var2) { - this.a((SerialNumber)var5.getKey(), this.f(), "servos"); - var9 = false; - } else { - var9 = var2; - } - - var2 = var9; - var3 = var8; - } - - if(!var4 && !var3 && !var2) { - ((LinearLayout)this.findViewById(R.id.autoconfigure_info)).removeAllViews(); - return true; - } else { - return false; - } - } - - private ArrayList f() { - ArrayList var1 = new ArrayList(); - var1.add("servo_1"); - var1.add("NO DEVICE ATTACHED"); - var1.add("NO DEVICE ATTACHED"); - var1.add("NO DEVICE ATTACHED"); - var1.add("NO DEVICE ATTACHED"); - var1.add("servo_6"); - return var1; - } - - private boolean g() { - Iterator var1 = this.entries.iterator(); - - boolean var2; - boolean var4; - for(var2 = true; var1.hasNext(); var2 = var4) { - Entry var3 = (Entry)var1.next(); - if((DeviceManager.DeviceType)var3.getValue() == DeviceManager.DeviceType.MODERN_ROBOTICS_USB_LEGACY_MODULE && var2) { - this.b((SerialNumber)var3.getKey(), "devices"); - var4 = false; - } else { - var4 = var2; - } - } - - if(var2) { - return false; - } else { - ((LinearLayout)this.findViewById(R.id.autoconfigure_info)).removeAllViews(); - return true; - } - } - - protected void onCreate(Bundle var1) { - super.onCreate(var1); - this.a = this; - this.setContentView(R.layout.activity_autoconfigure); - this.g = new Utility(this); - this.b = (Button)this.findViewById(R.id.configureLegacy); - this.c = (Button)this.findViewById(R.id.configureUSB); - - try { - this.d = new ModernRoboticsDeviceManager(this.a, (EventLoopManager)null); - } catch (RobotCoreException var3) { - this.g.complainToast("Failed to open the Device Manager", this.a); - DbgLog.error("Failed to open deviceManager: " + var3.toString()); - DbgLog.logStacktrace(var3); - } - } - - protected void onStart() { - super.onStart(); - this.g.updateHeader("K9LegacyBot", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - String var1 = this.g.getFilenameFromPrefs(R.string.pref_hardware_config_filename, "No current file!"); - if(!var1.equals("K9LegacyBot") && !var1.equals("K9USBBot")) { - this.a(); - } else { - this.d(); - } - - this.b.setOnClickListener(new OnClickListener() { - public void onClick(View var1) { - AutoConfigureActivity.this.f = new Thread(new Runnable() { - public void run() { - try { - DbgLog.msg("Scanning USB bus"); - AutoConfigureActivity.this.scannedDevices = AutoConfigureActivity.this.d.scanForUsbDevices(); - } catch (RobotCoreException var2) { - DbgLog.error("Device scan failed"); - } - - AutoConfigureActivity.this.runOnUiThread(new Runnable() { - public void run() { - AutoConfigureActivity.this.g.resetCount(); - if(AutoConfigureActivity.this.scannedDevices.size() == 0) { - AutoConfigureActivity.this.g.saveToPreferences("No current file!", R.string.pref_hardware_config_filename); - AutoConfigureActivity.this.g.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - AutoConfigureActivity.this.a(); - } - - AutoConfigureActivity.this.entries = AutoConfigureActivity.this.scannedDevices.entrySet(); - AutoConfigureActivity.this.e = new HashMap(); - AutoConfigureActivity.this.g.createLists(AutoConfigureActivity.this.entries, AutoConfigureActivity.this.e); - if(AutoConfigureActivity.this.g()) { - AutoConfigureActivity.this.a("K9LegacyBot"); - } else { - AutoConfigureActivity.this.g.saveToPreferences("No current file!", R.string.pref_hardware_config_filename); - AutoConfigureActivity.this.g.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - AutoConfigureActivity.this.b(); - } - } - }); - } - }); - AutoConfigureActivity.this.f.start(); - } - }); - this.c.setOnClickListener(new OnClickListener() { - public void onClick(View var1) { - AutoConfigureActivity.this.f = new Thread(new Runnable() { - public void run() { - try { - DbgLog.msg("Scanning USB bus"); - AutoConfigureActivity.this.scannedDevices = AutoConfigureActivity.this.d.scanForUsbDevices(); - } catch (RobotCoreException var2) { - DbgLog.error("Device scan failed"); - } - - AutoConfigureActivity.this.runOnUiThread(new Runnable() { - public void run() { - AutoConfigureActivity.this.g.resetCount(); - if(AutoConfigureActivity.this.scannedDevices.size() == 0) { - AutoConfigureActivity.this.g.saveToPreferences("No current file!", R.string.pref_hardware_config_filename); - AutoConfigureActivity.this.g.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - AutoConfigureActivity.this.a(); - } - - AutoConfigureActivity.this.entries = AutoConfigureActivity.this.scannedDevices.entrySet(); - AutoConfigureActivity.this.e = new HashMap(); - AutoConfigureActivity.this.g.createLists(AutoConfigureActivity.this.entries, AutoConfigureActivity.this.e); - if(AutoConfigureActivity.this.e()) { - AutoConfigureActivity.this.a("K9USBBot"); - } else { - AutoConfigureActivity.this.g.saveToPreferences("No current file!", R.string.pref_hardware_config_filename); - AutoConfigureActivity.this.g.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - AutoConfigureActivity.this.c(); - } - } - }); - } - }); - AutoConfigureActivity.this.f.start(); - } - }); - } -} +package com.qualcomm.ftccommon.configuration; + +import android.app.Activity; +import android.content.Context; +import android.os.Bundle; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.Toast; + +import com.qualcomm.ftccommon.DbgLog; +import com.qualcomm.ftccommon.R; +import com.qualcomm.hardware.ModernRoboticsDeviceManager; +import com.qualcomm.robotcore.eventloop.EventLoopManager; +import com.qualcomm.robotcore.exception.RobotCoreException; +import com.qualcomm.robotcore.hardware.DeviceManager; +import com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration; +import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; +import com.qualcomm.robotcore.hardware.configuration.LegacyModuleControllerConfiguration; +import com.qualcomm.robotcore.hardware.configuration.MotorConfiguration; +import com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration; +import com.qualcomm.robotcore.hardware.configuration.ServoConfiguration; +import com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration; +import com.qualcomm.robotcore.hardware.configuration.Utility; +import com.qualcomm.robotcore.util.SerialNumber; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +public class AutoConfigureActivity extends Activity { + private Context a; + private Button b; + private Button c; + private DeviceManager d; + private Map e = new HashMap(); + protected Set> entries = new HashSet(); + private Thread f; + private Utility g; + protected Map scannedDevices = new HashMap(); + + private DeviceConfiguration a(DeviceConfiguration.ConfigurationType var1, String var2, int var3) { + return new DeviceConfiguration(var3, var1, var2, true); + } + + private MotorControllerConfiguration a(SerialNumber var1, String var2, String var3, String var4) { + MotorControllerConfiguration var5; + if(!var1.equals(ControllerConfiguration.NO_SERIAL_NUMBER)) { + var5 = (MotorControllerConfiguration)this.e.get(var1); + } else { + var5 = new MotorControllerConfiguration(); + } + + var5.setName(var4); + ArrayList var6 = new ArrayList(); + MotorConfiguration var7 = new MotorConfiguration(1, var2, true); + MotorConfiguration var8 = new MotorConfiguration(2, var3, true); + var6.add(var7); + var6.add(var8); + var5.addMotors(var6); + return var5; + } + + private ServoControllerConfiguration a(SerialNumber var1, ArrayList var2, String var3) { + ServoControllerConfiguration var4; + if(!var1.equals(ControllerConfiguration.NO_SERIAL_NUMBER)) { + var4 = (ServoControllerConfiguration)this.e.get(var1); + } else { + var4 = new ServoControllerConfiguration(); + } + + var4.setName(var3); + ArrayList var5 = new ArrayList(); + + for(int var6 = 1; var6 <= 6; ++var6) { + String var7 = (String)var2.get(var6 - 1); + boolean var8; + if(var7.equals("NO DEVICE ATTACHED")) { + var8 = false; + } else { + var8 = true; + } + + var5.add(new ServoConfiguration(var6, var7, var8)); + } + + var4.addServos(var5); + return var4; + } + + private void a() { + this.g.setOrangeText("No devices found!", "To configure K9LegacyBot, please: \n 1. Attach a LegacyModuleController, \n with \n a. MotorController in port 0, with a \n motor in port 1 and port 2 \n b. ServoController in port 1, with a \n servo in port 1 and port 6 \n c. IR seeker in port 2\n d. Light sensor in port 3 \n 2. Press the K9LegacyBot button\n \nTo configure K9USBBot, please: \n 1. Attach a USBMotorController, with a \n motor in port 1 and port 2 \n 2. USBServoController in port 1, with a \n servo in port 1 and port 6 \n 3. LegacyModule, with \n a. IR seeker in port 2\n b. Light sensor in port 3 \n 4. Press the K9USBBot button", R.id.autoconfigure_info, R.layout.orange_warning, R.id.orangetext0, R.id.orangetext1); + } + + private void a(SerialNumber var1, String var2) { + LegacyModuleControllerConfiguration var3 = (LegacyModuleControllerConfiguration)this.e.get(var1); + var3.setName(var2); + DeviceConfiguration var4 = this.a(DeviceConfiguration.ConfigurationType.IR_SEEKER, "ir_seeker", 2); + DeviceConfiguration var5 = this.a(DeviceConfiguration.ConfigurationType.LIGHT_SENSOR, "light_sensor", 3); + ArrayList var6 = new ArrayList(); + + for(int var7 = 0; var7 < 6; ++var7) { + if(var7 == 2) { + var6.add(var4); + } + + if(var7 == 3) { + var6.add(var5); + } else { + var6.add(new DeviceConfiguration(var7)); + } + } + + var3.addDevices(var6); + } + + private void a(String var1) { + this.g.writeXML(this.e); + + try { + this.g.writeToFile(var1 + ".xml"); + this.g.saveToPreferences(var1, R.string.pref_hardware_config_filename); + this.g.updateHeader(var1, R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + Toast.makeText(this.a, "AutoConfigure " + var1 + " Successful", 0).show(); + } catch (RobotCoreException var5) { + this.g.complainToast(var5.getMessage(), this.a); + DbgLog.error(var5.getMessage()); + } catch (IOException var6) { + this.g.complainToast("Found " + var6.getMessage() + "\n Please fix and re-save", this.a); + DbgLog.error(var6.getMessage()); + } + } + + private void b() { + String var1 = "Found: \n" + this.scannedDevices.values() + "\n" + "Required: \n" + " 1. LegacyModuleController, with \n " + " a. MotorController in port 0, with a \n" + " motor in port 1 and port 2 \n " + " b. ServoController in port 1, with a \n" + " servo in port 1 and port 6 \n" + " c. IR seeker in port 2\n" + " d. Light sensor in port 3 "; + this.g.setOrangeText("Wrong devices found!", var1, R.id.autoconfigure_info, R.layout.orange_warning, R.id.orangetext0, R.id.orangetext1); + } + + private void b(SerialNumber var1, String var2) { + LegacyModuleControllerConfiguration var3 = (LegacyModuleControllerConfiguration)this.e.get(var1); + var3.setName(var2); + MotorControllerConfiguration var4 = this.a(ControllerConfiguration.NO_SERIAL_NUMBER, "motor_1", "motor_2", "wheels"); + var4.setPort(0); + ArrayList var5 = this.f(); + ServoControllerConfiguration var6 = this.a(ControllerConfiguration.NO_SERIAL_NUMBER, var5, "servos"); + var6.setPort(1); + DeviceConfiguration var7 = this.a(DeviceConfiguration.ConfigurationType.IR_SEEKER, "ir_seeker", 2); + DeviceConfiguration var8 = this.a(DeviceConfiguration.ConfigurationType.LIGHT_SENSOR, "light_sensor", 3); + ArrayList var9 = new ArrayList(); + var9.add(var4); + var9.add(var6); + var9.add(var7); + var9.add(var8); + + for(int var14 = 4; var14 < 6; ++var14) { + var9.add(new DeviceConfiguration(var14)); + } + + var3.addDevices(var9); + } + + private void c() { + String var1 = "Found: \n" + this.scannedDevices.values() + "\n" + "Required: \n" + " 1. USBMotorController with a \n" + " motor in port 1 and port 2 \n " + " 2. USBServoController with a \n" + " servo in port 1 and port 6 \n" + " 3. LegacyModuleController, with \n " + " a. IR seeker in port 2\n" + " b. Light sensor in port 3 "; + this.g.setOrangeText("Wrong devices found!", var1, R.id.autoconfigure_info, R.layout.orange_warning, R.id.orangetext0, R.id.orangetext1); + } + + private void d() { + this.g.setOrangeText("Already configured!", "", R.id.autoconfigure_info, R.layout.orange_warning, R.id.orangetext0, R.id.orangetext1); + } + + private boolean e() { + Iterator var1 = this.entries.iterator(); + boolean var2 = true; + boolean var3 = true; + + boolean var4; + boolean var7; + for(var4 = true; var1.hasNext(); var4 = var7) { + Entry var5 = (Entry)var1.next(); + DeviceManager.DeviceType var6 = (DeviceManager.DeviceType)var5.getValue(); + if(var6 == DeviceManager.DeviceType.MODERN_ROBOTICS_USB_LEGACY_MODULE && var4) { + this.a((SerialNumber)var5.getKey(), "sensors"); + var7 = false; + } else { + var7 = var4; + } + + boolean var8; + if(var6 == DeviceManager.DeviceType.MODERN_ROBOTICS_USB_DC_MOTOR_CONTROLLER && var3) { + this.a((SerialNumber)var5.getKey(), "motor_1", "motor_2", "wheels"); + var8 = false; + } else { + var8 = var3; + } + + boolean var9; + if(var6 == DeviceManager.DeviceType.MODERN_ROBOTICS_USB_SERVO_CONTROLLER && var2) { + this.a((SerialNumber)var5.getKey(), this.f(), "servos"); + var9 = false; + } else { + var9 = var2; + } + + var2 = var9; + var3 = var8; + } + + if(!var4 && !var3 && !var2) { + ((LinearLayout)this.findViewById(R.id.autoconfigure_info)).removeAllViews(); + return true; + } else { + return false; + } + } + + private ArrayList f() { + ArrayList var1 = new ArrayList(); + var1.add("servo_1"); + var1.add("NO DEVICE ATTACHED"); + var1.add("NO DEVICE ATTACHED"); + var1.add("NO DEVICE ATTACHED"); + var1.add("NO DEVICE ATTACHED"); + var1.add("servo_6"); + return var1; + } + + private boolean g() { + Iterator var1 = this.entries.iterator(); + + boolean var2; + boolean var4; + for(var2 = true; var1.hasNext(); var2 = var4) { + Entry var3 = (Entry)var1.next(); + if((DeviceManager.DeviceType)var3.getValue() == DeviceManager.DeviceType.MODERN_ROBOTICS_USB_LEGACY_MODULE && var2) { + this.b((SerialNumber)var3.getKey(), "devices"); + var4 = false; + } else { + var4 = var2; + } + } + + if(var2) { + return false; + } else { + ((LinearLayout)this.findViewById(R.id.autoconfigure_info)).removeAllViews(); + return true; + } + } + + protected void onCreate(Bundle var1) { + super.onCreate(var1); + this.a = this; + this.setContentView(R.layout.activity_autoconfigure); + this.g = new Utility(this); + this.b = (Button)this.findViewById(R.id.configureLegacy); + this.c = (Button)this.findViewById(R.id.configureUSB); + + try { + this.d = new ModernRoboticsDeviceManager(this.a, (EventLoopManager)null); + } catch (RobotCoreException var3) { + this.g.complainToast("Failed to open the Device Manager", this.a); + DbgLog.error("Failed to open deviceManager: " + var3.toString()); + DbgLog.logStacktrace(var3); + } + } + + protected void onStart() { + super.onStart(); + this.g.updateHeader("K9LegacyBot", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + String var1 = this.g.getFilenameFromPrefs(R.string.pref_hardware_config_filename, "No current file!"); + if(!var1.equals("K9LegacyBot") && !var1.equals("K9USBBot")) { + this.a(); + } else { + this.d(); + } + + this.b.setOnClickListener(new OnClickListener() { + public void onClick(View var1) { + AutoConfigureActivity.this.f = new Thread(new Runnable() { + public void run() { + try { + DbgLog.msg("Scanning USB bus"); + AutoConfigureActivity.this.scannedDevices = AutoConfigureActivity.this.d.scanForUsbDevices(); + } catch (RobotCoreException var2) { + DbgLog.error("Device scan failed"); + } + + AutoConfigureActivity.this.runOnUiThread(new Runnable() { + public void run() { + AutoConfigureActivity.this.g.resetCount(); + if(AutoConfigureActivity.this.scannedDevices.size() == 0) { + AutoConfigureActivity.this.g.saveToPreferences("No current file!", R.string.pref_hardware_config_filename); + AutoConfigureActivity.this.g.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + AutoConfigureActivity.this.a(); + } + + AutoConfigureActivity.this.entries = AutoConfigureActivity.this.scannedDevices.entrySet(); + AutoConfigureActivity.this.e = new HashMap(); + AutoConfigureActivity.this.g.createLists(AutoConfigureActivity.this.entries, AutoConfigureActivity.this.e); + if(AutoConfigureActivity.this.g()) { + AutoConfigureActivity.this.a("K9LegacyBot"); + } else { + AutoConfigureActivity.this.g.saveToPreferences("No current file!", R.string.pref_hardware_config_filename); + AutoConfigureActivity.this.g.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + AutoConfigureActivity.this.b(); + } + } + }); + } + }); + AutoConfigureActivity.this.f.start(); + } + }); + this.c.setOnClickListener(new OnClickListener() { + public void onClick(View var1) { + AutoConfigureActivity.this.f = new Thread(new Runnable() { + public void run() { + try { + DbgLog.msg("Scanning USB bus"); + AutoConfigureActivity.this.scannedDevices = AutoConfigureActivity.this.d.scanForUsbDevices(); + } catch (RobotCoreException var2) { + DbgLog.error("Device scan failed"); + } + + AutoConfigureActivity.this.runOnUiThread(new Runnable() { + public void run() { + AutoConfigureActivity.this.g.resetCount(); + if(AutoConfigureActivity.this.scannedDevices.size() == 0) { + AutoConfigureActivity.this.g.saveToPreferences("No current file!", R.string.pref_hardware_config_filename); + AutoConfigureActivity.this.g.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + AutoConfigureActivity.this.a(); + } + + AutoConfigureActivity.this.entries = AutoConfigureActivity.this.scannedDevices.entrySet(); + AutoConfigureActivity.this.e = new HashMap(); + AutoConfigureActivity.this.g.createLists(AutoConfigureActivity.this.entries, AutoConfigureActivity.this.e); + if(AutoConfigureActivity.this.e()) { + AutoConfigureActivity.this.a("K9USBBot"); + } else { + AutoConfigureActivity.this.g.saveToPreferences("No current file!", R.string.pref_hardware_config_filename); + AutoConfigureActivity.this.g.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + AutoConfigureActivity.this.c(); + } + } + }); + } + }); + AutoConfigureActivity.this.f.start(); + } + }); + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditAnalogInputDevicesActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditAnalogInputDevicesActivity.java similarity index 91% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditAnalogInputDevicesActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditAnalogInputDevicesActivity.java index 92ded0f..51b682a 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditAnalogInputDevicesActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditAnalogInputDevicesActivity.java @@ -1,229 +1,230 @@ -package com.qualcomm.ftccommon.configuration; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.Spinner; -import android.widget.TextView; -import android.widget.AdapterView.OnItemSelectedListener; -import com.qualcomm.ftccommon.R; -import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; -import com.qualcomm.robotcore.hardware.configuration.Utility; -import com.qualcomm.robotcore.util.RobotLog; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Iterator; - -public class EditAnalogInputDevicesActivity extends Activity { - private Utility a; - private View b; - private View c; - private View d; - private View e; - private View f; - private View g; - private View h; - private View i; - private ArrayList j = new ArrayList(); - private OnItemSelectedListener k = new OnItemSelectedListener() { - public void onItemSelected(AdapterView var1, View var2, int var3, long var4) { - String var6 = var1.getItemAtPosition(var3).toString(); - LinearLayout var7 = (LinearLayout)var2.getParent().getParent().getParent(); - if(var6.equalsIgnoreCase(DeviceConfiguration.ConfigurationType.NOTHING.toString())) { - EditAnalogInputDevicesActivity.this.a(var7); - } else { - EditAnalogInputDevicesActivity.this.a(var7, var6); - } - } - - public void onNothingSelected(AdapterView var1) { - } - }; - - private View a(int var1) { - switch(var1) { - case 0: - return this.b; - case 1: - return this.c; - case 2: - return this.d; - case 3: - return this.e; - case 4: - return this.f; - case 5: - return this.g; - case 6: - return this.h; - case 7: - return this.i; - default: - return null; - } - } - - private void a() { - Bundle var1 = new Bundle(); - - for(int var2 = 0; var2 < this.j.size(); ++var2) { - var1.putSerializable(String.valueOf(var2), (Serializable)this.j.get(var2)); - } - - Intent var3 = new Intent(); - var3.putExtras(var1); - var3.putExtras(var1); - this.setResult(-1, var3); - this.finish(); - } - - private void a(View var1) { - ((EditText)var1.findViewById(R.id.editTextResult_analogInput)).addTextChangedListener(new EditAnalogInputDevicesActivity.a(var1, null)); - } - - private void a(View var1, DeviceConfiguration var2) { - Spinner var3 = (Spinner)var1.findViewById(R.id.choiceSpinner_analogInput); - ArrayAdapter var4 = (ArrayAdapter)var3.getAdapter(); - if(var2.isEnabled()) { - var3.setSelection(var4.getPosition(var2.getType().toString())); - } else { - var3.setSelection(0); - } - - var3.setOnItemSelectedListener(this.k); - } - - private void a(EditText var1, DeviceConfiguration var2) { - if(var1.getText().toString().equalsIgnoreCase("NO DEVICE ATTACHED")) { - var1.setText(""); - var2.setName(""); - } else { - var1.setText(var2.getName()); - } - } - - private void a(LinearLayout var1) { - int var2 = Integer.parseInt(((TextView)var1.findViewById(R.id.port_number_analogInput)).getText().toString()); - EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_analogInput); - var3.setEnabled(false); - var3.setText("NO DEVICE ATTACHED"); - ((DeviceConfiguration)this.j.get(var2)).setEnabled(false); - } - - private void a(LinearLayout var1, String var2) { - int var3 = Integer.parseInt(((TextView)var1.findViewById(R.id.port_number_analogInput)).getText().toString()); - EditText var4 = (EditText)var1.findViewById(R.id.editTextResult_analogInput); - var4.setEnabled(true); - DeviceConfiguration var5 = (DeviceConfiguration)this.j.get(var3); - var5.setType(var5.typeFromString(var2)); - var5.setEnabled(true); - this.a(var4, var5); - } - - private void b(View var1, DeviceConfiguration var2) { - EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_analogInput); - if(var2.isEnabled()) { - var3.setText(var2.getName()); - var3.setEnabled(true); - } else { - var3.setText("NO DEVICE ATTACHED"); - var3.setEnabled(false); - } - } - - public void cancelAnalogInputDevices(View var1) { - this.setResult(0, new Intent()); - this.finish(); - } - - protected void onCreate(Bundle var1) { - super.onCreate(var1); - this.setContentView(R.layout.analog_inputs); - PreferenceManager.setDefaultValues(this, R.xml.preferences, false); - this.a = new Utility(this); - RobotLog.writeLogcatToDisk(this, 1024); - LinearLayout var2 = (LinearLayout)this.findViewById(R.id.linearLayout_analogInput0); - this.b = this.getLayoutInflater().inflate(R.layout.analog_input_device, var2, true); - ((TextView)this.b.findViewById(R.id.port_number_analogInput)).setText("0"); - LinearLayout var3 = (LinearLayout)this.findViewById(R.id.linearLayout_analogInput1); - this.c = this.getLayoutInflater().inflate(R.layout.analog_input_device, var3, true); - ((TextView)this.c.findViewById(R.id.port_number_analogInput)).setText("1"); - LinearLayout var4 = (LinearLayout)this.findViewById(R.id.linearLayout_analogInput2); - this.d = this.getLayoutInflater().inflate(R.layout.analog_input_device, var4, true); - ((TextView)this.d.findViewById(R.id.port_number_analogInput)).setText("2"); - LinearLayout var5 = (LinearLayout)this.findViewById(R.id.linearLayout_analogInput3); - this.e = this.getLayoutInflater().inflate(R.layout.analog_input_device, var5, true); - ((TextView)this.e.findViewById(R.id.port_number_analogInput)).setText("3"); - LinearLayout var6 = (LinearLayout)this.findViewById(R.id.linearLayout_analogInput4); - this.f = this.getLayoutInflater().inflate(R.layout.analog_input_device, var6, true); - ((TextView)this.f.findViewById(R.id.port_number_analogInput)).setText("4"); - LinearLayout var7 = (LinearLayout)this.findViewById(R.id.linearLayout_analogInput5); - this.g = this.getLayoutInflater().inflate(R.layout.analog_input_device, var7, true); - ((TextView)this.g.findViewById(R.id.port_number_analogInput)).setText("5"); - LinearLayout var8 = (LinearLayout)this.findViewById(R.id.linearLayout_analogInput6); - this.h = this.getLayoutInflater().inflate(R.layout.analog_input_device, var8, true); - ((TextView)this.h.findViewById(R.id.port_number_analogInput)).setText("6"); - LinearLayout var9 = (LinearLayout)this.findViewById(R.id.linearLayout_analogInput7); - this.i = this.getLayoutInflater().inflate(R.layout.analog_input_device, var9, true); - ((TextView)this.i.findViewById(R.id.port_number_analogInput)).setText("7"); - } - - protected void onStart() { - super.onStart(); - this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - Bundle var1 = this.getIntent().getExtras(); - if(var1 != null) { - Iterator var2 = var1.keySet().iterator(); - - while(var2.hasNext()) { - String var6 = (String)var2.next(); - DeviceConfiguration var7 = (DeviceConfiguration)var1.getSerializable(var6); - this.j.add(Integer.parseInt(var6), var7); - } - - for(int var3 = 0; var3 < this.j.size(); ++var3) { - View var4 = this.a(var3); - DeviceConfiguration var5 = (DeviceConfiguration)this.j.get(var3); - this.a(var4); - this.b(var4, var5); - this.a(var4, var5); - } - } - - } - - public void saveAnalogInputDevices(View var1) { - this.a(); - } - - private class a implements TextWatcher { - private int b; - - private a(View var2) { - this.b = Integer.parseInt(((TextView)var2.findViewById(R.id.port_number_analogInput)).getText().toString()); - } - - // $FF: synthetic method - a(View var2, Object var3) { - this(); - } - - public void afterTextChanged(Editable var1) { - ((DeviceConfiguration)EditAnalogInputDevicesActivity.this.j.get(this.b)).setName(var1.toString()); - } - - public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - - public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - } -} +package com.qualcomm.ftccommon.configuration; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.Spinner; +import android.widget.TextView; + +import com.qualcomm.ftccommon.R; +import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; +import com.qualcomm.robotcore.hardware.configuration.Utility; +import com.qualcomm.robotcore.util.RobotLog; + +import java.util.ArrayList; +import java.util.Iterator; + +public class EditAnalogInputDevicesActivity extends Activity { + private Utility a; + private View b; + private View c; + private View d; + private View e; + private View f; + private View g; + private View h; + private View i; + private ArrayList j = new ArrayList(); + private OnItemSelectedListener k = new OnItemSelectedListener() { + public void onItemSelected(AdapterView var1, View var2, int var3, long var4) { + String var6 = var1.getItemAtPosition(var3).toString(); + LinearLayout var7 = (LinearLayout)var2.getParent().getParent().getParent(); + if(var6.equalsIgnoreCase(DeviceConfiguration.ConfigurationType.NOTHING.toString())) { + EditAnalogInputDevicesActivity.this.a(var7); + } else { + EditAnalogInputDevicesActivity.this.a(var7, var6); + } + } + + public void onNothingSelected(AdapterView var1) { + } + }; + + private View a(int var1) { + switch(var1) { + case 0: + return this.b; + case 1: + return this.c; + case 2: + return this.d; + case 3: + return this.e; + case 4: + return this.f; + case 5: + return this.g; + case 6: + return this.h; + case 7: + return this.i; + default: + return null; + } + } + + private void a() { + Bundle var1 = new Bundle(); + + for(int var2 = 0; var2 < this.j.size(); ++var2) { + var1.putSerializable(String.valueOf(var2), this.j.get(var2)); + } + + Intent var3 = new Intent(); + var3.putExtras(var1); + var3.putExtras(var1); + this.setResult(-1, var3); + this.finish(); + } + + private void a(View var1) { + ((EditText)var1.findViewById(R.id.editTextResult_analogInput)).addTextChangedListener(new a(var1, null)); + } + + private void a(View var1, DeviceConfiguration var2) { + Spinner var3 = (Spinner)var1.findViewById(R.id.choiceSpinner_analogInput); + ArrayAdapter var4 = (ArrayAdapter)var3.getAdapter(); + if(var2.isEnabled()) { + var3.setSelection(var4.getPosition(var2.getType().toString())); + } else { + var3.setSelection(0); + } + + var3.setOnItemSelectedListener(this.k); + } + + private void a(EditText var1, DeviceConfiguration var2) { + if(var1.getText().toString().equalsIgnoreCase("NO DEVICE ATTACHED")) { + var1.setText(""); + var2.setName(""); + } else { + var1.setText(var2.getName()); + } + } + + private void a(LinearLayout var1) { + int var2 = Integer.parseInt(((TextView)var1.findViewById(R.id.port_number_analogInput)).getText().toString()); + EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_analogInput); + var3.setEnabled(false); + var3.setText("NO DEVICE ATTACHED"); + this.j.get(var2).setEnabled(false); + } + + private void a(LinearLayout var1, String var2) { + int var3 = Integer.parseInt(((TextView)var1.findViewById(R.id.port_number_analogInput)).getText().toString()); + EditText var4 = (EditText)var1.findViewById(R.id.editTextResult_analogInput); + var4.setEnabled(true); + DeviceConfiguration var5 = this.j.get(var3); + var5.setType(var5.typeFromString(var2)); + var5.setEnabled(true); + this.a(var4, var5); + } + + private void b(View var1, DeviceConfiguration var2) { + EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_analogInput); + if(var2.isEnabled()) { + var3.setText(var2.getName()); + var3.setEnabled(true); + } else { + var3.setText("NO DEVICE ATTACHED"); + var3.setEnabled(false); + } + } + + public void cancelAnalogInputDevices(View var1) { + this.setResult(0, new Intent()); + this.finish(); + } + + protected void onCreate(Bundle var1) { + super.onCreate(var1); + this.setContentView(R.layout.analog_inputs); + PreferenceManager.setDefaultValues(this, R.xml.preferences, false); + this.a = new Utility(this); + RobotLog.writeLogcatToDisk(this, 1024); + LinearLayout var2 = (LinearLayout)this.findViewById(R.id.linearLayout_analogInput0); + this.b = this.getLayoutInflater().inflate(R.layout.analog_input_device, var2, true); + ((TextView)this.b.findViewById(R.id.port_number_analogInput)).setText("0"); + LinearLayout var3 = (LinearLayout)this.findViewById(R.id.linearLayout_analogInput1); + this.c = this.getLayoutInflater().inflate(R.layout.analog_input_device, var3, true); + ((TextView)this.c.findViewById(R.id.port_number_analogInput)).setText("1"); + LinearLayout var4 = (LinearLayout)this.findViewById(R.id.linearLayout_analogInput2); + this.d = this.getLayoutInflater().inflate(R.layout.analog_input_device, var4, true); + ((TextView)this.d.findViewById(R.id.port_number_analogInput)).setText("2"); + LinearLayout var5 = (LinearLayout)this.findViewById(R.id.linearLayout_analogInput3); + this.e = this.getLayoutInflater().inflate(R.layout.analog_input_device, var5, true); + ((TextView)this.e.findViewById(R.id.port_number_analogInput)).setText("3"); + LinearLayout var6 = (LinearLayout)this.findViewById(R.id.linearLayout_analogInput4); + this.f = this.getLayoutInflater().inflate(R.layout.analog_input_device, var6, true); + ((TextView)this.f.findViewById(R.id.port_number_analogInput)).setText("4"); + LinearLayout var7 = (LinearLayout)this.findViewById(R.id.linearLayout_analogInput5); + this.g = this.getLayoutInflater().inflate(R.layout.analog_input_device, var7, true); + ((TextView)this.g.findViewById(R.id.port_number_analogInput)).setText("5"); + LinearLayout var8 = (LinearLayout)this.findViewById(R.id.linearLayout_analogInput6); + this.h = this.getLayoutInflater().inflate(R.layout.analog_input_device, var8, true); + ((TextView)this.h.findViewById(R.id.port_number_analogInput)).setText("6"); + LinearLayout var9 = (LinearLayout)this.findViewById(R.id.linearLayout_analogInput7); + this.i = this.getLayoutInflater().inflate(R.layout.analog_input_device, var9, true); + ((TextView)this.i.findViewById(R.id.port_number_analogInput)).setText("7"); + } + + protected void onStart() { + super.onStart(); + this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + Bundle var1 = this.getIntent().getExtras(); + if(var1 != null) { + Iterator var2 = var1.keySet().iterator(); + + while(var2.hasNext()) { + String var6 = (String)var2.next(); + DeviceConfiguration var7 = (DeviceConfiguration)var1.getSerializable(var6); + this.j.add(Integer.parseInt(var6), var7); + } + + for(int var3 = 0; var3 < this.j.size(); ++var3) { + View var4 = this.a(var3); + DeviceConfiguration var5 = this.j.get(var3); + this.a(var4); + this.b(var4, var5); + this.a(var4, var5); + } + } + + } + + public void saveAnalogInputDevices(View var1) { + this.a(); + } + + private class a implements TextWatcher { + private int b; + + private a(View var2) { + this.b = Integer.parseInt(((TextView)var2.findViewById(R.id.port_number_analogInput)).getText().toString()); + } + + // $FF: synthetic method + a(View var2, Object var3) { + this(var2); + } + + public void afterTextChanged(Editable var1) { + EditAnalogInputDevicesActivity.this.j.get(this.b).setName(var1.toString()); + } + + public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + + public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditAnalogOutputDevicesActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditAnalogOutputDevicesActivity.java similarity index 90% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditAnalogOutputDevicesActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditAnalogOutputDevicesActivity.java index 7b9d555..016e25d 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditAnalogOutputDevicesActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditAnalogOutputDevicesActivity.java @@ -1,193 +1,195 @@ -package com.qualcomm.ftccommon.configuration; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.Spinner; -import android.widget.TextView; -import android.widget.AdapterView.OnItemSelectedListener; -import com.qualcomm.ftccommon.R; -import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; -import com.qualcomm.robotcore.hardware.configuration.Utility; -import com.qualcomm.robotcore.util.RobotLog; -import java.util.ArrayList; -import java.util.Iterator; - -public class EditAnalogOutputDevicesActivity extends Activity { - private Utility a; - private View b; - private View c; - private ArrayList d = new ArrayList(); - private OnItemSelectedListener e = new OnItemSelectedListener() { - public void onItemSelected(AdapterView var1, View var2, int var3, long var4) { - String var6 = var1.getItemAtPosition(var3).toString(); - LinearLayout var7 = (LinearLayout)var2.getParent().getParent().getParent(); - if(var6.equalsIgnoreCase(DeviceConfiguration.ConfigurationType.NOTHING.toString())) { - EditAnalogOutputDevicesActivity.this.a(var7); - } else { - EditAnalogOutputDevicesActivity.this.a(var7, var6); - } - } - - public void onNothingSelected(AdapterView var1) { - } - }; - - private View a(int var1) { - switch(var1) { - case 0: - return this.b; - case 1: - return this.c; - default: - return null; - } - } - - private void a() { - Bundle var1 = new Bundle(); - - for(int var2 = 0; var2 < this.d.size(); ++var2) { - DeviceConfiguration var6 = (DeviceConfiguration)this.d.get(var2); - var1.putSerializable(String.valueOf(var2), var6); - } - - Intent var3 = new Intent(); - var3.putExtras(var1); - var3.putExtras(var1); - this.setResult(-1, var3); - this.finish(); - } - - private void a(View var1) { - ((EditText)var1.findViewById(R.id.editTextResult_analogOutput)).addTextChangedListener(new EditAnalogOutputDevicesActivity.a(var1, null)); - } - - private void a(View var1, DeviceConfiguration var2) { - Spinner var3 = (Spinner)var1.findViewById(R.id.choiceSpinner_analogOutput); - ArrayAdapter var4 = (ArrayAdapter)var3.getAdapter(); - if(var2.isEnabled()) { - var3.setSelection(var4.getPosition(var2.getType().toString())); - } else { - var3.setSelection(0); - } - - var3.setOnItemSelectedListener(this.e); - } - - private void a(EditText var1, DeviceConfiguration var2) { - if(var1.getText().toString().equalsIgnoreCase("NO DEVICE ATTACHED")) { - var1.setText(""); - var2.setName(""); - } else { - var1.setText(var2.getName()); - } - } - - private void a(LinearLayout var1) { - int var2 = Integer.parseInt(((TextView)var1.findViewById(R.id.port_number_analogOutput)).getText().toString()); - EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_analogOutput); - var3.setEnabled(false); - var3.setText("NO DEVICE ATTACHED"); - ((DeviceConfiguration)this.d.get(var2)).setEnabled(false); - } - - private void a(LinearLayout var1, String var2) { - int var3 = Integer.parseInt(((TextView)var1.findViewById(R.id.port_number_analogOutput)).getText().toString()); - EditText var4 = (EditText)var1.findViewById(R.id.editTextResult_analogOutput); - var4.setEnabled(true); - DeviceConfiguration var5 = (DeviceConfiguration)this.d.get(var3); - var5.setType(var5.typeFromString(var2)); - var5.setEnabled(true); - this.a(var4, var5); - } - - private void b(View var1, DeviceConfiguration var2) { - EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_analogOutput); - if(var2.isEnabled()) { - var3.setText(var2.getName()); - var3.setEnabled(true); - } else { - var3.setText("NO DEVICE ATTACHED"); - var3.setEnabled(false); - } - } - - public void cancelanalogOutputDevices(View var1) { - this.setResult(0, new Intent()); - this.finish(); - } - - protected void onCreate(Bundle var1) { - super.onCreate(var1); - this.setContentView(R.layout.analog_outputs); - PreferenceManager.setDefaultValues(this, R.xml.preferences, false); - this.a = new Utility(this); - RobotLog.writeLogcatToDisk(this, 1024); - LinearLayout var2 = (LinearLayout)this.findViewById(R.id.linearLayout_analogOutput0); - this.b = this.getLayoutInflater().inflate(R.layout.analog_output_device, var2, true); - ((TextView)this.b.findViewById(R.id.port_number_analogOutput)).setText("0"); - LinearLayout var3 = (LinearLayout)this.findViewById(R.id.linearLayout_analogOutput1); - this.c = this.getLayoutInflater().inflate(R.layout.analog_output_device, var3, true); - ((TextView)this.c.findViewById(R.id.port_number_analogOutput)).setText("1"); - } - - protected void onStart() { - super.onStart(); - this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - Bundle var1 = this.getIntent().getExtras(); - if(var1 != null) { - Iterator var2 = var1.keySet().iterator(); - - while(var2.hasNext()) { - String var6 = (String)var2.next(); - DeviceConfiguration var7 = (DeviceConfiguration)var1.getSerializable(var6); - this.d.add(Integer.parseInt(var6), var7); - } - - for(int var3 = 0; var3 < this.d.size(); ++var3) { - View var4 = this.a(var3); - DeviceConfiguration var5 = (DeviceConfiguration)this.d.get(var3); - this.a(var4); - this.b(var4, var5); - this.a(var4, var5); - } - } - - } - - public void saveanalogOutputDevices(View var1) { - this.a(); - } - - private class a implements TextWatcher { - private int b; - - private a(View var2) { - this.b = Integer.parseInt(((TextView)var2.findViewById(R.id.port_number_analogOutput)).getText().toString()); - } - - // $FF: synthetic method - a(View var2, Object var3) { - this(); - } - - public void afterTextChanged(Editable var1) { - ((DeviceConfiguration)EditAnalogOutputDevicesActivity.this.d.get(this.b)).setName(var1.toString()); - } - - public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - - public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - } -} +package com.qualcomm.ftccommon.configuration; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.Spinner; +import android.widget.TextView; + +import com.qualcomm.ftccommon.R; +import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; +import com.qualcomm.robotcore.hardware.configuration.Utility; +import com.qualcomm.robotcore.util.RobotLog; + +import java.util.ArrayList; +import java.util.Iterator; + +public class EditAnalogOutputDevicesActivity extends Activity { + private Utility a; + private View b; + private View c; + private ArrayList d = new ArrayList(); + private OnItemSelectedListener e = new OnItemSelectedListener() { + public void onItemSelected(AdapterView var1, View var2, int var3, long var4) { + String var6 = var1.getItemAtPosition(var3).toString(); + LinearLayout var7 = (LinearLayout)var2.getParent().getParent().getParent(); + if(var6.equalsIgnoreCase(DeviceConfiguration.ConfigurationType.NOTHING.toString())) { + EditAnalogOutputDevicesActivity.this.a(var7); + } else { + EditAnalogOutputDevicesActivity.this.a(var7, var6); + } + } + + public void onNothingSelected(AdapterView var1) { + } + }; + + private View a(int var1) { + switch(var1) { + case 0: + return this.b; + case 1: + return this.c; + default: + return null; + } + } + + private void a() { + Bundle var1 = new Bundle(); + + for(int var2 = 0; var2 < this.d.size(); ++var2) { + DeviceConfiguration var6 = this.d.get(var2); + var1.putSerializable(String.valueOf(var2), var6); + } + + Intent var3 = new Intent(); + var3.putExtras(var1); + var3.putExtras(var1); + this.setResult(-1, var3); + this.finish(); + } + + private void a(View var1) { + ((EditText)var1.findViewById(R.id.editTextResult_analogOutput)).addTextChangedListener(new a(var1, null)); + } + + private void a(View var1, DeviceConfiguration var2) { + Spinner var3 = (Spinner)var1.findViewById(R.id.choiceSpinner_analogOutput); + ArrayAdapter var4 = (ArrayAdapter)var3.getAdapter(); + if(var2.isEnabled()) { + var3.setSelection(var4.getPosition(var2.getType().toString())); + } else { + var3.setSelection(0); + } + + var3.setOnItemSelectedListener(this.e); + } + + private void a(EditText var1, DeviceConfiguration var2) { + if(var1.getText().toString().equalsIgnoreCase("NO DEVICE ATTACHED")) { + var1.setText(""); + var2.setName(""); + } else { + var1.setText(var2.getName()); + } + } + + private void a(LinearLayout var1) { + int var2 = Integer.parseInt(((TextView)var1.findViewById(R.id.port_number_analogOutput)).getText().toString()); + EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_analogOutput); + var3.setEnabled(false); + var3.setText("NO DEVICE ATTACHED"); + this.d.get(var2).setEnabled(false); + } + + private void a(LinearLayout var1, String var2) { + int var3 = Integer.parseInt(((TextView)var1.findViewById(R.id.port_number_analogOutput)).getText().toString()); + EditText var4 = (EditText)var1.findViewById(R.id.editTextResult_analogOutput); + var4.setEnabled(true); + DeviceConfiguration var5 = this.d.get(var3); + var5.setType(var5.typeFromString(var2)); + var5.setEnabled(true); + this.a(var4, var5); + } + + private void b(View var1, DeviceConfiguration var2) { + EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_analogOutput); + if(var2.isEnabled()) { + var3.setText(var2.getName()); + var3.setEnabled(true); + } else { + var3.setText("NO DEVICE ATTACHED"); + var3.setEnabled(false); + } + } + + public void cancelanalogOutputDevices(View var1) { + this.setResult(0, new Intent()); + this.finish(); + } + + protected void onCreate(Bundle var1) { + super.onCreate(var1); + this.setContentView(R.layout.analog_outputs); + PreferenceManager.setDefaultValues(this, R.xml.preferences, false); + this.a = new Utility(this); + RobotLog.writeLogcatToDisk(this, 1024); + LinearLayout var2 = (LinearLayout)this.findViewById(R.id.linearLayout_analogOutput0); + this.b = this.getLayoutInflater().inflate(R.layout.analog_output_device, var2, true); + ((TextView)this.b.findViewById(R.id.port_number_analogOutput)).setText("0"); + LinearLayout var3 = (LinearLayout)this.findViewById(R.id.linearLayout_analogOutput1); + this.c = this.getLayoutInflater().inflate(R.layout.analog_output_device, var3, true); + ((TextView)this.c.findViewById(R.id.port_number_analogOutput)).setText("1"); + } + + protected void onStart() { + super.onStart(); + this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + Bundle var1 = this.getIntent().getExtras(); + if(var1 != null) { + Iterator var2 = var1.keySet().iterator(); + + while(var2.hasNext()) { + String var6 = (String)var2.next(); + DeviceConfiguration var7 = (DeviceConfiguration)var1.getSerializable(var6); + this.d.add(Integer.parseInt(var6), var7); + } + + for(int var3 = 0; var3 < this.d.size(); ++var3) { + View var4 = this.a(var3); + DeviceConfiguration var5 = this.d.get(var3); + this.a(var4); + this.b(var4, var5); + this.a(var4, var5); + } + } + + } + + public void saveanalogOutputDevices(View var1) { + this.a(); + } + + private class a implements TextWatcher { + private int b; + + private a(View var2) { + this.b = Integer.parseInt(((TextView)var2.findViewById(R.id.port_number_analogOutput)).getText().toString()); + } + + // $FF: synthetic method + a(View var2, Object var3) { + this(var2); + } + + public void afterTextChanged(Editable var1) { + EditAnalogOutputDevicesActivity.this.d.get(this.b).setName(var1.toString()); + } + + public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + + public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditDeviceInterfaceModuleActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditDeviceInterfaceModuleActivity.java similarity index 91% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditDeviceInterfaceModuleActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditDeviceInterfaceModuleActivity.java index 1fb4f56..d101097 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditDeviceInterfaceModuleActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditDeviceInterfaceModuleActivity.java @@ -1,204 +1,201 @@ -package com.qualcomm.ftccommon.configuration; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.EditText; -import android.widget.ListView; -import android.widget.TextView; -import android.widget.AdapterView.OnItemClickListener; -import com.qualcomm.ftccommon.R; -import com.qualcomm.ftccommon.configuration.EditAnalogInputDevicesActivity; -import com.qualcomm.ftccommon.configuration.EditAnalogOutputDevicesActivity; -import com.qualcomm.ftccommon.configuration.EditDigitalDevicesActivity; -import com.qualcomm.ftccommon.configuration.EditI2cDevicesActivity; -import com.qualcomm.ftccommon.configuration.EditPWMDevicesActivity; -import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; -import com.qualcomm.robotcore.hardware.configuration.DeviceInterfaceModuleConfiguration; -import com.qualcomm.robotcore.hardware.configuration.Utility; -import com.qualcomm.robotcore.util.RobotLog; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class EditDeviceInterfaceModuleActivity extends Activity { - public static final int EDIT_ANALOG_INPUT_REQUEST_CODE = 203; - public static final int EDIT_ANALOG_OUTPUT_REQUEST_CODE = 205; - public static final String EDIT_DEVICE_INTERFACE_MODULE_CONFIG = "EDIT_DEVICE_INTERFACE_MODULE_CONFIG"; - public static final int EDIT_DIGITAL_REQUEST_CODE = 204; - public static final int EDIT_I2C_PORT_REQUEST_CODE = 202; - public static final int EDIT_PWM_PORT_REQUEST_CODE = 201; - private Utility a; - private String b; - private Context c; - private DeviceInterfaceModuleConfiguration d; - private EditText e; - private ArrayList f = new ArrayList(); - private OnItemClickListener g = new OnItemClickListener() { - public void onItemClick(AdapterView var1, View var2, int var3, long var4) { - switch(var3) { - case 0: - EditDeviceInterfaceModuleActivity.this.a(201, EditDeviceInterfaceModuleActivity.this.d.getPwmDevices(), EditPWMDevicesActivity.class); - return; - case 1: - EditDeviceInterfaceModuleActivity.this.a(202, EditDeviceInterfaceModuleActivity.this.d.getI2cDevices(), EditI2cDevicesActivity.class); - return; - case 2: - EditDeviceInterfaceModuleActivity.this.a(203, EditDeviceInterfaceModuleActivity.this.d.getAnalogInputDevices(), EditAnalogInputDevicesActivity.class); - return; - case 3: - EditDeviceInterfaceModuleActivity.this.a(204, EditDeviceInterfaceModuleActivity.this.d.getDigitalDevices(), EditDigitalDevicesActivity.class); - return; - case 4: - EditDeviceInterfaceModuleActivity.this.a(205, EditDeviceInterfaceModuleActivity.this.d.getAnalogOutputDevices(), EditAnalogOutputDevicesActivity.class); - return; - default: - } - } - }; - - private ArrayList a(Bundle var1) { - ArrayList var2 = new ArrayList(); - Iterator var3 = var1.keySet().iterator(); - - while(var3.hasNext()) { - String var4 = (String)var3.next(); - DeviceConfiguration var5 = (DeviceConfiguration)var1.getSerializable(var4); - var2.add(Integer.parseInt(var4), var5); - } - - return var2; - } - - private void a() { - if(!this.b.toLowerCase().contains("Unsaved".toLowerCase())) { - String var1 = "Unsaved " + this.b; - this.a.saveToPreferences(var1, R.string.pref_hardware_config_filename); - this.b = var1; - } - - this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - } - - private void a(int var1, List var2, Class var3) { - Bundle var4 = new Bundle(); - - for(int var5 = 0; var5 < var2.size(); ++var5) { - var4.putSerializable(String.valueOf(var5), (Serializable)var2.get(var5)); - } - - Intent var6 = new Intent(this.c, var3); - var6.putExtras(var4); - this.setResult(-1, var6); - this.startActivityForResult(var6, var1); - } - - private void b() { - Intent var1 = new Intent(); - this.d.setName(this.e.getText().toString()); - var1.putExtra("EDIT_DEVICE_INTERFACE_MODULE_CONFIG", this.d); - this.setResult(-1, var1); - this.finish(); - } - - public void cancelDeviceInterface(View var1) { - this.setResult(0, new Intent()); - this.finish(); - } - - protected void onActivityResult(int var1, int var2, Intent var3) { - if(var2 == -1) { - if(var1 == 201) { - Bundle var8 = var3.getExtras(); - if(var8 != null) { - this.d.setPwmDevices(this.a(var8)); - } - } else if(var1 == 203) { - Bundle var7 = var3.getExtras(); - if(var7 != null) { - this.d.setAnalogInputDevices(this.a(var7)); - } - } else if(var1 == 204) { - Bundle var6 = var3.getExtras(); - if(var6 != null) { - this.d.setDigitalDevices(this.a(var6)); - } - } else if(var1 == 202) { - Bundle var5 = var3.getExtras(); - if(var5 != null) { - this.d.setI2cDevices(this.a(var5)); - } - } else if(var1 == 205) { - Bundle var4 = var3.getExtras(); - if(var4 != null) { - this.d.setAnalogOutputDevices(this.a(var4)); - } - } - - this.a(); - } - - } - - protected void onCreate(Bundle var1) { - super.onCreate(var1); - this.setContentView(R.layout.device_interface_module); - String[] var2 = this.getResources().getStringArray(R.array.device_interface_module_options_array); - ListView var3 = (ListView)this.findViewById(R.id.listView_devices); - var3.setAdapter(new ArrayAdapter(this, 17367043, var2)); - var3.setOnItemClickListener(this.g); - this.c = this; - PreferenceManager.setDefaultValues(this, R.xml.preferences, false); - this.a = new Utility(this); - RobotLog.writeLogcatToDisk(this, 1024); - this.e = (EditText)this.findViewById(R.id.device_interface_module_name); - this.e.addTextChangedListener(new EditDeviceInterfaceModuleActivity.a(null)); - } - - protected void onStart() { - super.onStart(); - this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - this.b = this.a.getFilenameFromPrefs(R.string.pref_hardware_config_filename, "No current file!"); - Serializable var1 = this.getIntent().getSerializableExtra("EDIT_DEVICE_INTERFACE_MODULE_CONFIG"); - if(var1 != null) { - this.d = (DeviceInterfaceModuleConfiguration)var1; - this.f = (ArrayList)this.d.getDevices(); - this.e.setText(this.d.getName()); - ((TextView)this.findViewById(R.id.device_interface_module_serialNumber)).setText(this.d.getSerialNumber().toString()); - } - - } - - public void saveDeviceInterface(View var1) { - this.b(); - } - - private class a implements TextWatcher { - private a() { - } - - // $FF: synthetic method - a(Object var2) { - this(); - } - - public void afterTextChanged(Editable var1) { - String var2 = var1.toString(); - EditDeviceInterfaceModuleActivity.this.d.setName(var2); - } - - public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - - public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - } -} +package com.qualcomm.ftccommon.configuration; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.ListView; +import android.widget.TextView; + +import com.qualcomm.ftccommon.R; +import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; +import com.qualcomm.robotcore.hardware.configuration.DeviceInterfaceModuleConfiguration; +import com.qualcomm.robotcore.hardware.configuration.Utility; +import com.qualcomm.robotcore.util.RobotLog; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class EditDeviceInterfaceModuleActivity extends Activity { + public static final int EDIT_ANALOG_INPUT_REQUEST_CODE = 203; + public static final int EDIT_ANALOG_OUTPUT_REQUEST_CODE = 205; + public static final String EDIT_DEVICE_INTERFACE_MODULE_CONFIG = "EDIT_DEVICE_INTERFACE_MODULE_CONFIG"; + public static final int EDIT_DIGITAL_REQUEST_CODE = 204; + public static final int EDIT_I2C_PORT_REQUEST_CODE = 202; + public static final int EDIT_PWM_PORT_REQUEST_CODE = 201; + private Utility a; + private String b; + private Context c; + private DeviceInterfaceModuleConfiguration d; + private EditText e; + private ArrayList f = new ArrayList(); + private OnItemClickListener g = new OnItemClickListener() { + public void onItemClick(AdapterView var1, View var2, int var3, long var4) { + switch(var3) { + case 0: + EditDeviceInterfaceModuleActivity.this.a(201, EditDeviceInterfaceModuleActivity.this.d.getPwmDevices(), EditPWMDevicesActivity.class); + return; + case 1: + EditDeviceInterfaceModuleActivity.this.a(202, EditDeviceInterfaceModuleActivity.this.d.getI2cDevices(), EditI2cDevicesActivity.class); + return; + case 2: + EditDeviceInterfaceModuleActivity.this.a(203, EditDeviceInterfaceModuleActivity.this.d.getAnalogInputDevices(), EditAnalogInputDevicesActivity.class); + return; + case 3: + EditDeviceInterfaceModuleActivity.this.a(204, EditDeviceInterfaceModuleActivity.this.d.getDigitalDevices(), EditDigitalDevicesActivity.class); + return; + case 4: + EditDeviceInterfaceModuleActivity.this.a(205, EditDeviceInterfaceModuleActivity.this.d.getAnalogOutputDevices(), EditAnalogOutputDevicesActivity.class); + return; + default: + } + } + }; + + private ArrayList a(Bundle var1) { + ArrayList var2 = new ArrayList(); + Iterator var3 = var1.keySet().iterator(); + + while(var3.hasNext()) { + String var4 = (String)var3.next(); + DeviceConfiguration var5 = (DeviceConfiguration)var1.getSerializable(var4); + var2.add(Integer.parseInt(var4), var5); + } + + return var2; + } + + private void a() { + if(!this.b.toLowerCase().contains("Unsaved".toLowerCase())) { + String var1 = "Unsaved " + this.b; + this.a.saveToPreferences(var1, R.string.pref_hardware_config_filename); + this.b = var1; + } + + this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + } + + private void a(int var1, List var2, Class var3) { + Bundle var4 = new Bundle(); + + for(int var5 = 0; var5 < var2.size(); ++var5) { + var4.putSerializable(String.valueOf(var5), (Serializable)var2.get(var5)); + } + + Intent var6 = new Intent(this.c, var3); + var6.putExtras(var4); + this.setResult(-1, var6); + this.startActivityForResult(var6, var1); + } + + private void b() { + Intent var1 = new Intent(); + this.d.setName(this.e.getText().toString()); + var1.putExtra("EDIT_DEVICE_INTERFACE_MODULE_CONFIG", this.d); + this.setResult(-1, var1); + this.finish(); + } + + public void cancelDeviceInterface(View var1) { + this.setResult(0, new Intent()); + this.finish(); + } + + protected void onActivityResult(int var1, int var2, Intent var3) { + if(var2 == -1) { + if(var1 == 201) { + Bundle var8 = var3.getExtras(); + if(var8 != null) { + this.d.setPwmDevices(this.a(var8)); + } + } else if(var1 == 203) { + Bundle var7 = var3.getExtras(); + if(var7 != null) { + this.d.setAnalogInputDevices(this.a(var7)); + } + } else if(var1 == 204) { + Bundle var6 = var3.getExtras(); + if(var6 != null) { + this.d.setDigitalDevices(this.a(var6)); + } + } else if(var1 == 202) { + Bundle var5 = var3.getExtras(); + if(var5 != null) { + this.d.setI2cDevices(this.a(var5)); + } + } else if(var1 == 205) { + Bundle var4 = var3.getExtras(); + if(var4 != null) { + this.d.setAnalogOutputDevices(this.a(var4)); + } + } + + this.a(); + } + + } + + protected void onCreate(Bundle var1) { + super.onCreate(var1); + this.setContentView(R.layout.device_interface_module); + String[] var2 = this.getResources().getStringArray(R.array.device_interface_module_options_array); + ListView var3 = (ListView)this.findViewById(R.id.listView_devices); + var3.setAdapter(new ArrayAdapter(this, 17367043, var2)); + var3.setOnItemClickListener(this.g); + this.c = this; + PreferenceManager.setDefaultValues(this, R.xml.preferences, false); + this.a = new Utility(this); + RobotLog.writeLogcatToDisk(this, 1024); + this.e = (EditText)this.findViewById(R.id.device_interface_module_name); + this.e.addTextChangedListener(new a(null)); + } + + protected void onStart() { + super.onStart(); + this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + this.b = this.a.getFilenameFromPrefs(R.string.pref_hardware_config_filename, "No current file!"); + Serializable var1 = this.getIntent().getSerializableExtra("EDIT_DEVICE_INTERFACE_MODULE_CONFIG"); + if(var1 != null) { + this.d = (DeviceInterfaceModuleConfiguration)var1; + this.f = (ArrayList)this.d.getDevices(); + this.e.setText(this.d.getName()); + ((TextView)this.findViewById(R.id.device_interface_module_serialNumber)).setText(this.d.getSerialNumber().toString()); + } + + } + + public void saveDeviceInterface(View var1) { + this.b(); + } + + private class a implements TextWatcher { + private a() { + } + + // $FF: synthetic method + a(Object var2) { + this(); + } + + public void afterTextChanged(Editable var1) { + String var2 = var1.toString(); + EditDeviceInterfaceModuleActivity.this.d.setName(var2); + } + + public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + + public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditDigitalDevicesActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditDigitalDevicesActivity.java similarity index 91% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditDigitalDevicesActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditDigitalDevicesActivity.java index 5ca5012..8920f08 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditDigitalDevicesActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditDigitalDevicesActivity.java @@ -1,229 +1,230 @@ -package com.qualcomm.ftccommon.configuration; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.Spinner; -import android.widget.TextView; -import android.widget.AdapterView.OnItemSelectedListener; -import com.qualcomm.ftccommon.R; -import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; -import com.qualcomm.robotcore.hardware.configuration.Utility; -import com.qualcomm.robotcore.util.RobotLog; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Iterator; - -public class EditDigitalDevicesActivity extends Activity { - private Utility a; - private View b; - private View c; - private View d; - private View e; - private View f; - private View g; - private View h; - private View i; - private ArrayList j = new ArrayList(); - private OnItemSelectedListener k = new OnItemSelectedListener() { - public void onItemSelected(AdapterView var1, View var2, int var3, long var4) { - String var6 = var1.getItemAtPosition(var3).toString(); - LinearLayout var7 = (LinearLayout)var2.getParent().getParent().getParent(); - if(var6.equalsIgnoreCase(DeviceConfiguration.ConfigurationType.NOTHING.toString())) { - EditDigitalDevicesActivity.this.a(var7); - } else { - EditDigitalDevicesActivity.this.a(var7, var6); - } - } - - public void onNothingSelected(AdapterView var1) { - } - }; - - private View a(int var1) { - switch(var1) { - case 0: - return this.b; - case 1: - return this.c; - case 2: - return this.d; - case 3: - return this.e; - case 4: - return this.f; - case 5: - return this.g; - case 6: - return this.h; - case 7: - return this.i; - default: - return null; - } - } - - private void a() { - Bundle var1 = new Bundle(); - - for(int var2 = 0; var2 < this.j.size(); ++var2) { - var1.putSerializable(String.valueOf(var2), (Serializable)this.j.get(var2)); - } - - Intent var3 = new Intent(); - var3.putExtras(var1); - var3.putExtras(var1); - this.setResult(-1, var3); - this.finish(); - } - - private void a(View var1) { - ((EditText)var1.findViewById(R.id.editTextResult_digital_device)).addTextChangedListener(new EditDigitalDevicesActivity.a(var1, null)); - } - - private void a(View var1, DeviceConfiguration var2) { - Spinner var3 = (Spinner)var1.findViewById(R.id.choiceSpinner_digital_device); - ArrayAdapter var4 = (ArrayAdapter)var3.getAdapter(); - if(var2.isEnabled()) { - var3.setSelection(var4.getPosition(var2.getType().toString())); - } else { - var3.setSelection(0); - } - - var3.setOnItemSelectedListener(this.k); - } - - private void a(EditText var1, DeviceConfiguration var2) { - if(var1.getText().toString().equalsIgnoreCase("NO DEVICE ATTACHED")) { - var1.setText(""); - var2.setName(""); - } else { - var1.setText(var2.getName()); - } - } - - private void a(LinearLayout var1) { - int var2 = Integer.parseInt(((TextView)var1.findViewById(R.id.port_number_digital_device)).getText().toString()); - EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_digital_device); - var3.setEnabled(false); - var3.setText("NO DEVICE ATTACHED"); - ((DeviceConfiguration)this.j.get(var2)).setEnabled(false); - } - - private void a(LinearLayout var1, String var2) { - int var3 = Integer.parseInt(((TextView)var1.findViewById(R.id.port_number_digital_device)).getText().toString()); - EditText var4 = (EditText)var1.findViewById(R.id.editTextResult_digital_device); - var4.setEnabled(true); - DeviceConfiguration var5 = (DeviceConfiguration)this.j.get(var3); - var5.setType(var5.typeFromString(var2)); - var5.setEnabled(true); - this.a(var4, var5); - } - - private void b(View var1, DeviceConfiguration var2) { - EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_digital_device); - if(var2.isEnabled()) { - var3.setText(var2.getName()); - var3.setEnabled(true); - } else { - var3.setText("NO DEVICE ATTACHED"); - var3.setEnabled(false); - } - } - - public void cancelDigitalDevices(View var1) { - this.setResult(0, new Intent()); - this.finish(); - } - - protected void onCreate(Bundle var1) { - super.onCreate(var1); - this.setContentView(R.layout.digital_devices); - PreferenceManager.setDefaultValues(this, R.xml.preferences, false); - this.a = new Utility(this); - RobotLog.writeLogcatToDisk(this, 1024); - LinearLayout var2 = (LinearLayout)this.findViewById(R.id.linearLayout_digital_device0); - this.b = this.getLayoutInflater().inflate(R.layout.digital_device, var2, true); - ((TextView)this.b.findViewById(R.id.port_number_digital_device)).setText("0"); - LinearLayout var3 = (LinearLayout)this.findViewById(R.id.linearLayout_digital_device1); - this.c = this.getLayoutInflater().inflate(R.layout.digital_device, var3, true); - ((TextView)this.c.findViewById(R.id.port_number_digital_device)).setText("1"); - LinearLayout var4 = (LinearLayout)this.findViewById(R.id.linearLayout_digital_device2); - this.d = this.getLayoutInflater().inflate(R.layout.digital_device, var4, true); - ((TextView)this.d.findViewById(R.id.port_number_digital_device)).setText("2"); - LinearLayout var5 = (LinearLayout)this.findViewById(R.id.linearLayout_digital_device3); - this.e = this.getLayoutInflater().inflate(R.layout.digital_device, var5, true); - ((TextView)this.e.findViewById(R.id.port_number_digital_device)).setText("3"); - LinearLayout var6 = (LinearLayout)this.findViewById(R.id.linearLayout_digital_device4); - this.f = this.getLayoutInflater().inflate(R.layout.digital_device, var6, true); - ((TextView)this.f.findViewById(R.id.port_number_digital_device)).setText("4"); - LinearLayout var7 = (LinearLayout)this.findViewById(R.id.linearLayout_digital_device5); - this.g = this.getLayoutInflater().inflate(R.layout.digital_device, var7, true); - ((TextView)this.g.findViewById(R.id.port_number_digital_device)).setText("5"); - LinearLayout var8 = (LinearLayout)this.findViewById(R.id.linearLayout_digital_device6); - this.h = this.getLayoutInflater().inflate(R.layout.digital_device, var8, true); - ((TextView)this.h.findViewById(R.id.port_number_digital_device)).setText("6"); - LinearLayout var9 = (LinearLayout)this.findViewById(R.id.linearLayout_digital_device7); - this.i = this.getLayoutInflater().inflate(R.layout.digital_device, var9, true); - ((TextView)this.i.findViewById(R.id.port_number_digital_device)).setText("7"); - } - - protected void onStart() { - super.onStart(); - this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - Bundle var1 = this.getIntent().getExtras(); - if(var1 != null) { - Iterator var2 = var1.keySet().iterator(); - - while(var2.hasNext()) { - String var6 = (String)var2.next(); - DeviceConfiguration var7 = (DeviceConfiguration)var1.getSerializable(var6); - this.j.add(Integer.parseInt(var6), var7); - } - - for(int var3 = 0; var3 < this.j.size(); ++var3) { - View var4 = this.a(var3); - DeviceConfiguration var5 = (DeviceConfiguration)this.j.get(var3); - this.a(var4); - this.b(var4, var5); - this.a(var4, var5); - } - } - - } - - public void saveDigitalDevices(View var1) { - this.a(); - } - - private class a implements TextWatcher { - private int b; - - private a(View var2) { - this.b = Integer.parseInt(((TextView)var2.findViewById(R.id.port_number_digital_device)).getText().toString()); - } - - // $FF: synthetic method - a(View var2, Object var3) { - this(); - } - - public void afterTextChanged(Editable var1) { - ((DeviceConfiguration)EditDigitalDevicesActivity.this.j.get(this.b)).setName(var1.toString()); - } - - public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - - public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - } -} +package com.qualcomm.ftccommon.configuration; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.Spinner; +import android.widget.TextView; + +import com.qualcomm.ftccommon.R; +import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; +import com.qualcomm.robotcore.hardware.configuration.Utility; +import com.qualcomm.robotcore.util.RobotLog; + +import java.util.ArrayList; +import java.util.Iterator; + +public class EditDigitalDevicesActivity extends Activity { + private Utility a; + private View b; + private View c; + private View d; + private View e; + private View f; + private View g; + private View h; + private View i; + private ArrayList j = new ArrayList(); + private OnItemSelectedListener k = new OnItemSelectedListener() { + public void onItemSelected(AdapterView var1, View var2, int var3, long var4) { + String var6 = var1.getItemAtPosition(var3).toString(); + LinearLayout var7 = (LinearLayout)var2.getParent().getParent().getParent(); + if(var6.equalsIgnoreCase(DeviceConfiguration.ConfigurationType.NOTHING.toString())) { + EditDigitalDevicesActivity.this.a(var7); + } else { + EditDigitalDevicesActivity.this.a(var7, var6); + } + } + + public void onNothingSelected(AdapterView var1) { + } + }; + + private View a(int var1) { + switch(var1) { + case 0: + return this.b; + case 1: + return this.c; + case 2: + return this.d; + case 3: + return this.e; + case 4: + return this.f; + case 5: + return this.g; + case 6: + return this.h; + case 7: + return this.i; + default: + return null; + } + } + + private void a() { + Bundle var1 = new Bundle(); + + for(int var2 = 0; var2 < this.j.size(); ++var2) { + var1.putSerializable(String.valueOf(var2), this.j.get(var2)); + } + + Intent var3 = new Intent(); + var3.putExtras(var1); + var3.putExtras(var1); + this.setResult(-1, var3); + this.finish(); + } + + private void a(View var1) { + ((EditText)var1.findViewById(R.id.editTextResult_digital_device)).addTextChangedListener(new a(var1, null)); + } + + private void a(View var1, DeviceConfiguration var2) { + Spinner var3 = (Spinner)var1.findViewById(R.id.choiceSpinner_digital_device); + ArrayAdapter var4 = (ArrayAdapter)var3.getAdapter(); + if(var2.isEnabled()) { + var3.setSelection(var4.getPosition(var2.getType().toString())); + } else { + var3.setSelection(0); + } + + var3.setOnItemSelectedListener(this.k); + } + + private void a(EditText var1, DeviceConfiguration var2) { + if(var1.getText().toString().equalsIgnoreCase("NO DEVICE ATTACHED")) { + var1.setText(""); + var2.setName(""); + } else { + var1.setText(var2.getName()); + } + } + + private void a(LinearLayout var1) { + int var2 = Integer.parseInt(((TextView)var1.findViewById(R.id.port_number_digital_device)).getText().toString()); + EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_digital_device); + var3.setEnabled(false); + var3.setText("NO DEVICE ATTACHED"); + this.j.get(var2).setEnabled(false); + } + + private void a(LinearLayout var1, String var2) { + int var3 = Integer.parseInt(((TextView)var1.findViewById(R.id.port_number_digital_device)).getText().toString()); + EditText var4 = (EditText)var1.findViewById(R.id.editTextResult_digital_device); + var4.setEnabled(true); + DeviceConfiguration var5 = this.j.get(var3); + var5.setType(var5.typeFromString(var2)); + var5.setEnabled(true); + this.a(var4, var5); + } + + private void b(View var1, DeviceConfiguration var2) { + EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_digital_device); + if(var2.isEnabled()) { + var3.setText(var2.getName()); + var3.setEnabled(true); + } else { + var3.setText("NO DEVICE ATTACHED"); + var3.setEnabled(false); + } + } + + public void cancelDigitalDevices(View var1) { + this.setResult(0, new Intent()); + this.finish(); + } + + protected void onCreate(Bundle var1) { + super.onCreate(var1); + this.setContentView(R.layout.digital_devices); + PreferenceManager.setDefaultValues(this, R.xml.preferences, false); + this.a = new Utility(this); + RobotLog.writeLogcatToDisk(this, 1024); + LinearLayout var2 = (LinearLayout)this.findViewById(R.id.linearLayout_digital_device0); + this.b = this.getLayoutInflater().inflate(R.layout.digital_device, var2, true); + ((TextView)this.b.findViewById(R.id.port_number_digital_device)).setText("0"); + LinearLayout var3 = (LinearLayout)this.findViewById(R.id.linearLayout_digital_device1); + this.c = this.getLayoutInflater().inflate(R.layout.digital_device, var3, true); + ((TextView)this.c.findViewById(R.id.port_number_digital_device)).setText("1"); + LinearLayout var4 = (LinearLayout)this.findViewById(R.id.linearLayout_digital_device2); + this.d = this.getLayoutInflater().inflate(R.layout.digital_device, var4, true); + ((TextView)this.d.findViewById(R.id.port_number_digital_device)).setText("2"); + LinearLayout var5 = (LinearLayout)this.findViewById(R.id.linearLayout_digital_device3); + this.e = this.getLayoutInflater().inflate(R.layout.digital_device, var5, true); + ((TextView)this.e.findViewById(R.id.port_number_digital_device)).setText("3"); + LinearLayout var6 = (LinearLayout)this.findViewById(R.id.linearLayout_digital_device4); + this.f = this.getLayoutInflater().inflate(R.layout.digital_device, var6, true); + ((TextView)this.f.findViewById(R.id.port_number_digital_device)).setText("4"); + LinearLayout var7 = (LinearLayout)this.findViewById(R.id.linearLayout_digital_device5); + this.g = this.getLayoutInflater().inflate(R.layout.digital_device, var7, true); + ((TextView)this.g.findViewById(R.id.port_number_digital_device)).setText("5"); + LinearLayout var8 = (LinearLayout)this.findViewById(R.id.linearLayout_digital_device6); + this.h = this.getLayoutInflater().inflate(R.layout.digital_device, var8, true); + ((TextView)this.h.findViewById(R.id.port_number_digital_device)).setText("6"); + LinearLayout var9 = (LinearLayout)this.findViewById(R.id.linearLayout_digital_device7); + this.i = this.getLayoutInflater().inflate(R.layout.digital_device, var9, true); + ((TextView)this.i.findViewById(R.id.port_number_digital_device)).setText("7"); + } + + protected void onStart() { + super.onStart(); + this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + Bundle var1 = this.getIntent().getExtras(); + if(var1 != null) { + Iterator var2 = var1.keySet().iterator(); + + while(var2.hasNext()) { + String var6 = (String)var2.next(); + DeviceConfiguration var7 = (DeviceConfiguration)var1.getSerializable(var6); + this.j.add(Integer.parseInt(var6), var7); + } + + for(int var3 = 0; var3 < this.j.size(); ++var3) { + View var4 = this.a(var3); + DeviceConfiguration var5 = this.j.get(var3); + this.a(var4); + this.b(var4, var5); + this.a(var4, var5); + } + } + + } + + public void saveDigitalDevices(View var1) { + this.a(); + } + + private class a implements TextWatcher { + private int b; + + private a(View var2) { + this.b = Integer.parseInt(((TextView)var2.findViewById(R.id.port_number_digital_device)).getText().toString()); + } + + // $FF: synthetic method + a(View var2, Object var3) { + this(var2); + } + + public void afterTextChanged(Editable var1) { + EditDigitalDevicesActivity.this.j.get(this.b).setName(var1.toString()); + } + + public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + + public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditI2cDevicesActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditI2cDevicesActivity.java similarity index 91% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditI2cDevicesActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditI2cDevicesActivity.java index cfeb7c5..daf0ad4 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditI2cDevicesActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditI2cDevicesActivity.java @@ -1,217 +1,219 @@ -package com.qualcomm.ftccommon.configuration; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.Spinner; -import android.widget.TextView; -import android.widget.AdapterView.OnItemSelectedListener; -import com.qualcomm.ftccommon.R; -import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; -import com.qualcomm.robotcore.hardware.configuration.Utility; -import com.qualcomm.robotcore.util.RobotLog; -import java.util.ArrayList; -import java.util.Iterator; - -public class EditI2cDevicesActivity extends Activity { - private Utility a; - private View b; - private View c; - private View d; - private View e; - private View f; - private View g; - private ArrayList h = new ArrayList(); - private OnItemSelectedListener i = new OnItemSelectedListener() { - public void onItemSelected(AdapterView var1, View var2, int var3, long var4) { - String var6 = var1.getItemAtPosition(var3).toString(); - LinearLayout var7 = (LinearLayout)var2.getParent().getParent().getParent(); - if(var6.equalsIgnoreCase(DeviceConfiguration.ConfigurationType.NOTHING.toString())) { - EditI2cDevicesActivity.this.a(var7); - } else { - EditI2cDevicesActivity.this.a(var7, var6); - } - } - - public void onNothingSelected(AdapterView var1) { - } - }; - - private View a(int var1) { - switch(var1) { - case 0: - return this.b; - case 1: - return this.c; - case 2: - return this.d; - case 3: - return this.e; - case 4: - return this.f; - case 5: - return this.g; - default: - return null; - } - } - - private void a() { - Bundle var1 = new Bundle(); - - for(int var2 = 0; var2 < this.h.size(); ++var2) { - DeviceConfiguration var6 = (DeviceConfiguration)this.h.get(var2); - var1.putSerializable(String.valueOf(var2), var6); - } - - Intent var3 = new Intent(); - var3.putExtras(var1); - var3.putExtras(var1); - this.setResult(-1, var3); - this.finish(); - } - - private void a(View var1) { - ((EditText)var1.findViewById(R.id.editTextResult_i2c)).addTextChangedListener(new EditI2cDevicesActivity.a(var1, null)); - } - - private void a(View var1, DeviceConfiguration var2) { - Spinner var3 = (Spinner)var1.findViewById(R.id.choiceSpinner_i2c); - ArrayAdapter var4 = (ArrayAdapter)var3.getAdapter(); - if(var2.isEnabled()) { - var3.setSelection(var4.getPosition(var2.getType().toString())); - } else { - var3.setSelection(0); - } - - var3.setOnItemSelectedListener(this.i); - } - - private void a(EditText var1, DeviceConfiguration var2) { - if(var1.getText().toString().equalsIgnoreCase("NO DEVICE ATTACHED")) { - var1.setText(""); - var2.setName(""); - } else { - var1.setText(var2.getName()); - } - } - - private void a(LinearLayout var1) { - int var2 = Integer.parseInt(((TextView)var1.findViewById(R.id.port_number_i2c)).getText().toString()); - EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_i2c); - var3.setEnabled(false); - var3.setText("NO DEVICE ATTACHED"); - ((DeviceConfiguration)this.h.get(var2)).setEnabled(false); - } - - private void a(LinearLayout var1, String var2) { - int var3 = Integer.parseInt(((TextView)var1.findViewById(R.id.port_number_i2c)).getText().toString()); - EditText var4 = (EditText)var1.findViewById(R.id.editTextResult_i2c); - var4.setEnabled(true); - DeviceConfiguration var5 = (DeviceConfiguration)this.h.get(var3); - var5.setType(var5.typeFromString(var2)); - var5.setEnabled(true); - this.a(var4, var5); - } - - private void b(View var1, DeviceConfiguration var2) { - EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_i2c); - if(var2.isEnabled()) { - var3.setText(var2.getName()); - var3.setEnabled(true); - } else { - var3.setText("NO DEVICE ATTACHED"); - var3.setEnabled(false); - } - } - - public void cancelI2cDevices(View var1) { - this.setResult(0, new Intent()); - this.finish(); - } - - protected void onCreate(Bundle var1) { - super.onCreate(var1); - this.setContentView(R.layout.i2cs); - PreferenceManager.setDefaultValues(this, R.xml.preferences, false); - this.a = new Utility(this); - RobotLog.writeLogcatToDisk(this, 1024); - LinearLayout var2 = (LinearLayout)this.findViewById(R.id.linearLayout_i2c0); - this.b = this.getLayoutInflater().inflate(R.layout.i2c_device, var2, true); - ((TextView)this.b.findViewById(R.id.port_number_i2c)).setText("0"); - LinearLayout var3 = (LinearLayout)this.findViewById(R.id.linearLayout_i2c1); - this.c = this.getLayoutInflater().inflate(R.layout.i2c_device, var3, true); - ((TextView)this.c.findViewById(R.id.port_number_i2c)).setText("1"); - LinearLayout var4 = (LinearLayout)this.findViewById(R.id.linearLayout_i2c2); - this.d = this.getLayoutInflater().inflate(R.layout.i2c_device, var4, true); - ((TextView)this.d.findViewById(R.id.port_number_i2c)).setText("2"); - LinearLayout var5 = (LinearLayout)this.findViewById(R.id.linearLayout_i2c3); - this.e = this.getLayoutInflater().inflate(R.layout.i2c_device, var5, true); - ((TextView)this.e.findViewById(R.id.port_number_i2c)).setText("3"); - LinearLayout var6 = (LinearLayout)this.findViewById(R.id.linearLayout_i2c4); - this.f = this.getLayoutInflater().inflate(R.layout.i2c_device, var6, true); - ((TextView)this.f.findViewById(R.id.port_number_i2c)).setText("4"); - LinearLayout var7 = (LinearLayout)this.findViewById(R.id.linearLayout_i2c5); - this.g = this.getLayoutInflater().inflate(R.layout.i2c_device, var7, true); - ((TextView)this.g.findViewById(R.id.port_number_i2c)).setText("5"); - } - - protected void onStart() { - super.onStart(); - this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - Bundle var1 = this.getIntent().getExtras(); - if(var1 != null) { - Iterator var2 = var1.keySet().iterator(); - - while(var2.hasNext()) { - String var6 = (String)var2.next(); - DeviceConfiguration var7 = (DeviceConfiguration)var1.getSerializable(var6); - this.h.add(Integer.parseInt(var6), var7); - } - - for(int var3 = 0; var3 < this.h.size(); ++var3) { - View var4 = this.a(var3); - DeviceConfiguration var5 = (DeviceConfiguration)this.h.get(var3); - this.a(var4); - this.b(var4, var5); - this.a(var4, var5); - } - } - - } - - public void saveI2cDevices(View var1) { - this.a(); - } - - private class a implements TextWatcher { - private int b; - - private a(View var2) { - this.b = Integer.parseInt(((TextView)var2.findViewById(R.id.port_number_i2c)).getText().toString()); - } - - // $FF: synthetic method - a(View var2, Object var3) { - this(); - } - - public void afterTextChanged(Editable var1) { - ((DeviceConfiguration)EditI2cDevicesActivity.this.h.get(this.b)).setName(var1.toString()); - } - - public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - - public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - } -} +package com.qualcomm.ftccommon.configuration; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.Spinner; +import android.widget.TextView; + +import com.qualcomm.ftccommon.R; +import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; +import com.qualcomm.robotcore.hardware.configuration.Utility; +import com.qualcomm.robotcore.util.RobotLog; + +import java.util.ArrayList; +import java.util.Iterator; + +public class EditI2cDevicesActivity extends Activity { + private Utility a; + private View b; + private View c; + private View d; + private View e; + private View f; + private View g; + private ArrayList h = new ArrayList(); + private OnItemSelectedListener i = new OnItemSelectedListener() { + public void onItemSelected(AdapterView var1, View var2, int var3, long var4) { + String var6 = var1.getItemAtPosition(var3).toString(); + LinearLayout var7 = (LinearLayout)var2.getParent().getParent().getParent(); + if(var6.equalsIgnoreCase(DeviceConfiguration.ConfigurationType.NOTHING.toString())) { + EditI2cDevicesActivity.this.a(var7); + } else { + EditI2cDevicesActivity.this.a(var7, var6); + } + } + + public void onNothingSelected(AdapterView var1) { + } + }; + + private View a(int var1) { + switch(var1) { + case 0: + return this.b; + case 1: + return this.c; + case 2: + return this.d; + case 3: + return this.e; + case 4: + return this.f; + case 5: + return this.g; + default: + return null; + } + } + + private void a() { + Bundle var1 = new Bundle(); + + for(int var2 = 0; var2 < this.h.size(); ++var2) { + DeviceConfiguration var6 = this.h.get(var2); + var1.putSerializable(String.valueOf(var2), var6); + } + + Intent var3 = new Intent(); + var3.putExtras(var1); + var3.putExtras(var1); + this.setResult(-1, var3); + this.finish(); + } + + private void a(View var1) { + ((EditText)var1.findViewById(R.id.editTextResult_i2c)).addTextChangedListener(new a(var1, null)); + } + + private void a(View var1, DeviceConfiguration var2) { + Spinner var3 = (Spinner)var1.findViewById(R.id.choiceSpinner_i2c); + ArrayAdapter var4 = (ArrayAdapter)var3.getAdapter(); + if(var2.isEnabled()) { + var3.setSelection(var4.getPosition(var2.getType().toString())); + } else { + var3.setSelection(0); + } + + var3.setOnItemSelectedListener(this.i); + } + + private void a(EditText var1, DeviceConfiguration var2) { + if(var1.getText().toString().equalsIgnoreCase("NO DEVICE ATTACHED")) { + var1.setText(""); + var2.setName(""); + } else { + var1.setText(var2.getName()); + } + } + + private void a(LinearLayout var1) { + int var2 = Integer.parseInt(((TextView)var1.findViewById(R.id.port_number_i2c)).getText().toString()); + EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_i2c); + var3.setEnabled(false); + var3.setText("NO DEVICE ATTACHED"); + this.h.get(var2).setEnabled(false); + } + + private void a(LinearLayout var1, String var2) { + int var3 = Integer.parseInt(((TextView)var1.findViewById(R.id.port_number_i2c)).getText().toString()); + EditText var4 = (EditText)var1.findViewById(R.id.editTextResult_i2c); + var4.setEnabled(true); + DeviceConfiguration var5 = this.h.get(var3); + var5.setType(var5.typeFromString(var2)); + var5.setEnabled(true); + this.a(var4, var5); + } + + private void b(View var1, DeviceConfiguration var2) { + EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_i2c); + if(var2.isEnabled()) { + var3.setText(var2.getName()); + var3.setEnabled(true); + } else { + var3.setText("NO DEVICE ATTACHED"); + var3.setEnabled(false); + } + } + + public void cancelI2cDevices(View var1) { + this.setResult(0, new Intent()); + this.finish(); + } + + protected void onCreate(Bundle var1) { + super.onCreate(var1); + this.setContentView(R.layout.i2cs); + PreferenceManager.setDefaultValues(this, R.xml.preferences, false); + this.a = new Utility(this); + RobotLog.writeLogcatToDisk(this, 1024); + LinearLayout var2 = (LinearLayout)this.findViewById(R.id.linearLayout_i2c0); + this.b = this.getLayoutInflater().inflate(R.layout.i2c_device, var2, true); + ((TextView)this.b.findViewById(R.id.port_number_i2c)).setText("0"); + LinearLayout var3 = (LinearLayout)this.findViewById(R.id.linearLayout_i2c1); + this.c = this.getLayoutInflater().inflate(R.layout.i2c_device, var3, true); + ((TextView)this.c.findViewById(R.id.port_number_i2c)).setText("1"); + LinearLayout var4 = (LinearLayout)this.findViewById(R.id.linearLayout_i2c2); + this.d = this.getLayoutInflater().inflate(R.layout.i2c_device, var4, true); + ((TextView)this.d.findViewById(R.id.port_number_i2c)).setText("2"); + LinearLayout var5 = (LinearLayout)this.findViewById(R.id.linearLayout_i2c3); + this.e = this.getLayoutInflater().inflate(R.layout.i2c_device, var5, true); + ((TextView)this.e.findViewById(R.id.port_number_i2c)).setText("3"); + LinearLayout var6 = (LinearLayout)this.findViewById(R.id.linearLayout_i2c4); + this.f = this.getLayoutInflater().inflate(R.layout.i2c_device, var6, true); + ((TextView)this.f.findViewById(R.id.port_number_i2c)).setText("4"); + LinearLayout var7 = (LinearLayout)this.findViewById(R.id.linearLayout_i2c5); + this.g = this.getLayoutInflater().inflate(R.layout.i2c_device, var7, true); + ((TextView)this.g.findViewById(R.id.port_number_i2c)).setText("5"); + } + + protected void onStart() { + super.onStart(); + this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + Bundle var1 = this.getIntent().getExtras(); + if(var1 != null) { + Iterator var2 = var1.keySet().iterator(); + + while(var2.hasNext()) { + String var6 = (String)var2.next(); + DeviceConfiguration var7 = (DeviceConfiguration)var1.getSerializable(var6); + this.h.add(Integer.parseInt(var6), var7); + } + + for(int var3 = 0; var3 < this.h.size(); ++var3) { + View var4 = this.a(var3); + DeviceConfiguration var5 = this.h.get(var3); + this.a(var4); + this.b(var4, var5); + this.a(var4, var5); + } + } + + } + + public void saveI2cDevices(View var1) { + this.a(); + } + + private class a implements TextWatcher { + private int b; + + private a(View var2) { + this.b = Integer.parseInt(((TextView)var2.findViewById(R.id.port_number_i2c)).getText().toString()); + } + + // $FF: synthetic method + a(View var2, Object var3) { + this(var2); + } + + public void afterTextChanged(Editable var1) { + EditI2cDevicesActivity.this.h.get(this.b).setName(var1.toString()); + } + + public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + + public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditLegacyModuleControllerActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditLegacyModuleControllerActivity.java similarity index 90% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditLegacyModuleControllerActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditLegacyModuleControllerActivity.java index ad926a0..30f7638 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditLegacyModuleControllerActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditLegacyModuleControllerActivity.java @@ -1,370 +1,368 @@ -package com.qualcomm.ftccommon.configuration; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.Spinner; -import android.widget.TextView; -import android.widget.AdapterView.OnItemSelectedListener; -import com.qualcomm.ftccommon.R; -import com.qualcomm.ftccommon.configuration.EditMatrixControllerActivity; -import com.qualcomm.ftccommon.configuration.EditMotorControllerActivity; -import com.qualcomm.ftccommon.configuration.EditServoControllerActivity; -import com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration; -import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; -import com.qualcomm.robotcore.hardware.configuration.LegacyModuleControllerConfiguration; -import com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration; -import com.qualcomm.robotcore.hardware.configuration.MotorConfiguration; -import com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration; -import com.qualcomm.robotcore.hardware.configuration.ServoConfiguration; -import com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration; -import com.qualcomm.robotcore.hardware.configuration.Utility; -import com.qualcomm.robotcore.util.RobotLog; -import com.qualcomm.robotcore.util.SerialNumber; -import java.io.Serializable; -import java.util.ArrayList; - -public class EditLegacyModuleControllerActivity extends Activity { - public static final String EDIT_LEGACY_CONFIG = "EDIT_LEGACY_CONFIG"; - public static final int EDIT_MATRIX_CONTROLLER_REQUEST_CODE = 103; - public static final int EDIT_MOTOR_CONTROLLER_REQUEST_CODE = 101; - public static final int EDIT_SERVO_CONTROLLER_REQUEST_CODE = 102; - private static boolean a = false; - private Utility b; - private String c; - private Context d; - private LegacyModuleControllerConfiguration e; - private EditText f; - private ArrayList g = new ArrayList(); - private View h; - private View i; - private View j; - private View k; - private View l; - private View m; - private OnItemSelectedListener n = new OnItemSelectedListener() { - public void onItemSelected(AdapterView var1, View var2, int var3, long var4) { - String var6 = var1.getItemAtPosition(var3).toString(); - LinearLayout var7 = (LinearLayout)var2.getParent().getParent().getParent(); - if(var6.equalsIgnoreCase(DeviceConfiguration.ConfigurationType.NOTHING.toString())) { - EditLegacyModuleControllerActivity.this.a(var7); - } else { - EditLegacyModuleControllerActivity.this.a(var7, var6); - } - } - - public void onNothingSelected(AdapterView var1) { - } - }; - - private View a(int var1) { - switch(var1) { - case 0: - return this.h; - case 1: - return this.i; - case 2: - return this.j; - case 3: - return this.k; - case 4: - return this.l; - case 5: - return this.m; - default: - return null; - } - } - - private void a() { - Intent var1 = new Intent(); - this.e.setName(this.f.getText().toString()); - var1.putExtra("EDIT_LEGACY_CONFIG", this.e); - this.setResult(-1, var1); - this.finish(); - } - - private void a(int var1, int var2) { - ((Button)this.a(var1).findViewById(R.id.edit_controller_btn)).setVisibility(var2); - } - - private void a(int var1, String var2) { - DeviceConfiguration var3 = (DeviceConfiguration)this.g.get(var1); - String var4 = var3.getName(); - ArrayList var5 = new ArrayList(); - SerialNumber var6 = ControllerConfiguration.NO_SERIAL_NUMBER; - if(!var3.getType().toString().equalsIgnoreCase(var2)) { - Object var7 = new ControllerConfiguration("dummy module", var5, var6, DeviceConfiguration.ConfigurationType.NOTHING); - if(var2.equalsIgnoreCase(DeviceConfiguration.ConfigurationType.MOTOR_CONTROLLER.toString())) { - for(int var16 = 1; var16 <= 2; ++var16) { - var5.add(new MotorConfiguration(var16)); - } - - var7 = new MotorControllerConfiguration(var4, var5, var6); - ((ControllerConfiguration)var7).setPort(var1); - } else if(var2.equalsIgnoreCase(DeviceConfiguration.ConfigurationType.SERVO_CONTROLLER.toString())) { - for(int var14 = 1; var14 <= 6; ++var14) { - var5.add(new ServoConfiguration(var14)); - } - - var7 = new ServoControllerConfiguration(var4, var5, var6); - ((ControllerConfiguration)var7).setPort(var1); - } else if(var2.equalsIgnoreCase(DeviceConfiguration.ConfigurationType.MATRIX_CONTROLLER.toString())) { - ArrayList var8 = new ArrayList(); - - for(int var9 = 1; var9 <= 4; ++var9) { - var8.add(new MotorConfiguration(var9)); - } - - ArrayList var10 = new ArrayList(); - - for(int var11 = 1; var11 <= 4; ++var11) { - var10.add(new ServoConfiguration(var11)); - } - - var7 = new MatrixControllerConfiguration(var4, var8, var10, var6); - ((ControllerConfiguration)var7).setPort(var1); - } - - ((ControllerConfiguration)var7).setEnabled(true); - this.b((DeviceConfiguration)var7); - } - - } - - private void a(View var1, DeviceConfiguration var2) { - Spinner var3 = (Spinner)var1.findViewById(R.id.choiceSpinner_legacyModule); - var3.setSelection(((ArrayAdapter)var3.getAdapter()).getPosition(var2.getType().toString())); - var3.setOnItemSelectedListener(this.n); - String var4 = var2.getName(); - EditText var5 = (EditText)var1.findViewById(R.id.editTextResult_name); - int var6 = Integer.parseInt(((TextView)var1.findViewById(R.id.portNumber)).getText().toString()); - var5.addTextChangedListener(new EditLegacyModuleControllerActivity.a(var2, null)); - var5.setText(var4); - if(a) { - RobotLog.e("[populatePort] name: " + var4 + ", port: " + var6 + ", type: " + var2.getType()); - } - - } - - private void a(EditText var1, DeviceConfiguration var2) { - if(var1.getText().toString().equalsIgnoreCase("NO DEVICE ATTACHED")) { - var1.setText(""); - var2.setName(""); - } else { - var1.setText(var2.getName()); - } - } - - private void a(LinearLayout var1) { - int var2 = Integer.parseInt(((TextView)var1.findViewById(R.id.portNumber)).getText().toString()); - EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_name); - var3.setEnabled(false); - var3.setText("NO DEVICE ATTACHED"); - DeviceConfiguration var4 = new DeviceConfiguration(DeviceConfiguration.ConfigurationType.NOTHING); - var4.setPort(var2); - this.b(var4); - this.a(var2, 8); - } - - private void a(LinearLayout var1, String var2) { - int var3 = Integer.parseInt(((TextView)var1.findViewById(R.id.portNumber)).getText().toString()); - EditText var4 = (EditText)var1.findViewById(R.id.editTextResult_name); - DeviceConfiguration var5 = (DeviceConfiguration)this.g.get(var3); - var4.setEnabled(true); - this.a(var4, var5); - DeviceConfiguration.ConfigurationType var6 = var5.typeFromString(var2); - if(var6 != DeviceConfiguration.ConfigurationType.MOTOR_CONTROLLER && var6 != DeviceConfiguration.ConfigurationType.SERVO_CONTROLLER && var6 != DeviceConfiguration.ConfigurationType.MATRIX_CONTROLLER) { - var5.setType(var6); - if(var6 == DeviceConfiguration.ConfigurationType.NOTHING) { - var5.setEnabled(false); - } else { - var5.setEnabled(true); - } - - this.a(var3, 8); - } else { - this.a(var3, var2); - this.a(var3, 0); - } - - if(a) { - DeviceConfiguration var7 = (DeviceConfiguration)this.g.get(var3); - RobotLog.e("[changeDevice] modules.get(port) name: " + var7.getName() + ", port: " + var7.getPort() + ", type: " + var7.getType()); - } - - } - - private void a(DeviceConfiguration var1) { - var1.setName(((EditText)((LinearLayout)this.a(var1.getPort())).findViewById(R.id.editTextResult_name)).getText().toString()); - if(var1.getType() == DeviceConfiguration.ConfigurationType.MOTOR_CONTROLLER) { - Intent var2 = new Intent(this.d, EditMotorControllerActivity.class); - var2.putExtra("EDIT_MOTOR_CONTROLLER_CONFIG", var1); - var2.putExtra("requestCode", 101); - this.setResult(-1, var2); - this.startActivityForResult(var2, 101); - } else { - if(var1.getType() == DeviceConfiguration.ConfigurationType.SERVO_CONTROLLER) { - Intent var5 = new Intent(this.d, EditServoControllerActivity.class); - var5.putExtra("Edit Servo ControllerConfiguration Activity", var1); - this.setResult(-1, var5); - this.startActivityForResult(var5, 102); - return; - } - - if(var1.getType() == DeviceConfiguration.ConfigurationType.MATRIX_CONTROLLER) { - Intent var7 = new Intent(this.d, EditMatrixControllerActivity.class); - var7.putExtra("Edit Matrix ControllerConfiguration Activity", var1); - this.setResult(-1, var7); - this.startActivityForResult(var7, 103); - return; - } - } - - } - - private void b(DeviceConfiguration var1) { - int var2 = var1.getPort(); - this.g.set(var2, var1); - } - - private boolean c(DeviceConfiguration var1) { - return var1.getType() == DeviceConfiguration.ConfigurationType.MOTOR_CONTROLLER || var1.getType() == DeviceConfiguration.ConfigurationType.SERVO_CONTROLLER; - } - - public void cancelLegacyController(View var1) { - this.setResult(0, new Intent()); - this.finish(); - } - - public void editController_portALL(View var1) { - LinearLayout var2 = (LinearLayout)var1.getParent().getParent(); - int var3 = Integer.parseInt(((TextView)var2.findViewById(R.id.portNumber)).getText().toString()); - DeviceConfiguration var4 = (DeviceConfiguration)this.g.get(var3); - if(!this.c(var4)) { - this.a(var3, ((Spinner)var2.findViewById(R.id.choiceSpinner_legacyModule)).getSelectedItem().toString()); - } - - this.a(var4); - } - - protected void onActivityResult(int var1, int var2, Intent var3) { - if(var2 == -1) { - Serializable var4; - if(var1 == 101) { - var4 = var3.getSerializableExtra("EDIT_MOTOR_CONTROLLER_CONFIG"); - } else if(var1 == 102) { - var4 = var3.getSerializableExtra("Edit Servo ControllerConfiguration Activity"); - } else { - var4 = null; - if(var1 == 103) { - var4 = var3.getSerializableExtra("Edit Matrix ControllerConfiguration Activity"); - } - } - - if(var4 != null) { - ControllerConfiguration var5 = (ControllerConfiguration)var4; - this.b(var5); - this.a(this.a(var5.getPort()), (DeviceConfiguration)this.g.get(var5.getPort())); - if(!this.c.toLowerCase().contains("Unsaved".toLowerCase())) { - String var6 = "Unsaved " + this.c; - this.b.saveToPreferences(var6, R.string.pref_hardware_config_filename); - this.c = var6; - } - - this.b.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - } - } - - } - - protected void onCreate(Bundle var1) { - super.onCreate(var1); - this.setContentView(R.layout.legacy); - LinearLayout var2 = (LinearLayout)this.findViewById(R.id.linearLayout0); - this.h = this.getLayoutInflater().inflate(R.layout.simple_device, var2, true); - ((TextView)this.h.findViewById(R.id.portNumber)).setText("0"); - LinearLayout var3 = (LinearLayout)this.findViewById(R.id.linearLayout1); - this.i = this.getLayoutInflater().inflate(R.layout.simple_device, var3, true); - ((TextView)this.i.findViewById(R.id.portNumber)).setText("1"); - LinearLayout var4 = (LinearLayout)this.findViewById(R.id.linearLayout2); - this.j = this.getLayoutInflater().inflate(R.layout.simple_device, var4, true); - ((TextView)this.j.findViewById(R.id.portNumber)).setText("2"); - LinearLayout var5 = (LinearLayout)this.findViewById(R.id.linearLayout3); - this.k = this.getLayoutInflater().inflate(R.layout.simple_device, var5, true); - ((TextView)this.k.findViewById(R.id.portNumber)).setText("3"); - LinearLayout var6 = (LinearLayout)this.findViewById(R.id.linearLayout4); - this.l = this.getLayoutInflater().inflate(R.layout.simple_device, var6, true); - ((TextView)this.l.findViewById(R.id.portNumber)).setText("4"); - LinearLayout var7 = (LinearLayout)this.findViewById(R.id.linearLayout5); - this.m = this.getLayoutInflater().inflate(R.layout.simple_device, var7, true); - ((TextView)this.m.findViewById(R.id.portNumber)).setText("5"); - this.d = this; - PreferenceManager.setDefaultValues(this, R.xml.preferences, false); - this.b = new Utility(this); - RobotLog.writeLogcatToDisk(this, 1024); - this.f = (EditText)this.findViewById(R.id.device_interface_module_name); - } - - protected void onStart() { - super.onStart(); - this.b.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - this.c = this.b.getFilenameFromPrefs(R.string.pref_hardware_config_filename, "No current file!"); - Serializable var1 = this.getIntent().getSerializableExtra("EDIT_LEGACY_CONFIG"); - if(var1 != null) { - this.e = (LegacyModuleControllerConfiguration)var1; - this.g = (ArrayList)this.e.getDevices(); - this.f.setText(this.e.getName()); - this.f.addTextChangedListener(new EditLegacyModuleControllerActivity.a(this.e, null)); - ((TextView)this.findViewById(R.id.legacy_serialNumber)).setText(this.e.getSerialNumber().toString()); - - for(int var2 = 0; var2 < this.g.size(); ++var2) { - DeviceConfiguration var3 = (DeviceConfiguration)this.g.get(var2); - if(a) { - RobotLog.e("[onStart] module name: " + var3.getName() + ", port: " + var3.getPort() + ", type: " + var3.getType()); - } - - this.a(this.a(var2), var3); - } - } - - } - - public void saveLegacyController(View var1) { - this.a(); - } - - private class a implements TextWatcher { - private DeviceConfiguration b; - - private a(DeviceConfiguration var2) { - this.b = var2; - } - - // $FF: synthetic method - a(DeviceConfiguration var2, Object var3) { - this(); - } - - public void afterTextChanged(Editable var1) { - String var2 = var1.toString(); - this.b.setName(var2); - } - - public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - - public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - } -} +package com.qualcomm.ftccommon.configuration; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.Spinner; +import android.widget.TextView; + +import com.qualcomm.ftccommon.R; +import com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration; +import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; +import com.qualcomm.robotcore.hardware.configuration.LegacyModuleControllerConfiguration; +import com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration; +import com.qualcomm.robotcore.hardware.configuration.MotorConfiguration; +import com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration; +import com.qualcomm.robotcore.hardware.configuration.ServoConfiguration; +import com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration; +import com.qualcomm.robotcore.hardware.configuration.Utility; +import com.qualcomm.robotcore.util.RobotLog; +import com.qualcomm.robotcore.util.SerialNumber; + +import java.io.Serializable; +import java.util.ArrayList; + +public class EditLegacyModuleControllerActivity extends Activity { + public static final String EDIT_LEGACY_CONFIG = "EDIT_LEGACY_CONFIG"; + public static final int EDIT_MATRIX_CONTROLLER_REQUEST_CODE = 103; + public static final int EDIT_MOTOR_CONTROLLER_REQUEST_CODE = 101; + public static final int EDIT_SERVO_CONTROLLER_REQUEST_CODE = 102; + private static boolean a = false; + private Utility b; + private String c; + private Context d; + private LegacyModuleControllerConfiguration e; + private EditText f; + private ArrayList g = new ArrayList(); + private View h; + private View i; + private View j; + private View k; + private View l; + private View m; + private OnItemSelectedListener n = new OnItemSelectedListener() { + public void onItemSelected(AdapterView var1, View var2, int var3, long var4) { + String var6 = var1.getItemAtPosition(var3).toString(); + LinearLayout var7 = (LinearLayout)var2.getParent().getParent().getParent(); + if(var6.equalsIgnoreCase(DeviceConfiguration.ConfigurationType.NOTHING.toString())) { + EditLegacyModuleControllerActivity.this.a(var7); + } else { + EditLegacyModuleControllerActivity.this.a(var7, var6); + } + } + + public void onNothingSelected(AdapterView var1) { + } + }; + + private View a(int var1) { + switch(var1) { + case 0: + return this.h; + case 1: + return this.i; + case 2: + return this.j; + case 3: + return this.k; + case 4: + return this.l; + case 5: + return this.m; + default: + return null; + } + } + + private void a() { + Intent var1 = new Intent(); + this.e.setName(this.f.getText().toString()); + var1.putExtra("EDIT_LEGACY_CONFIG", this.e); + this.setResult(-1, var1); + this.finish(); + } + + private void a(int var1, int var2) { + this.a(var1).findViewById(R.id.edit_controller_btn).setVisibility(var2); + } + + private void a(int var1, String var2) { + DeviceConfiguration var3 = this.g.get(var1); + String var4 = var3.getName(); + ArrayList var5 = new ArrayList(); + SerialNumber var6 = ControllerConfiguration.NO_SERIAL_NUMBER; + if(!var3.getType().toString().equalsIgnoreCase(var2)) { + Object var7 = new ControllerConfiguration("dummy module", var5, var6, DeviceConfiguration.ConfigurationType.NOTHING); + if(var2.equalsIgnoreCase(DeviceConfiguration.ConfigurationType.MOTOR_CONTROLLER.toString())) { + for(int var16 = 1; var16 <= 2; ++var16) { + var5.add(new MotorConfiguration(var16)); + } + + var7 = new MotorControllerConfiguration(var4, var5, var6); + ((ControllerConfiguration)var7).setPort(var1); + } else if(var2.equalsIgnoreCase(DeviceConfiguration.ConfigurationType.SERVO_CONTROLLER.toString())) { + for(int var14 = 1; var14 <= 6; ++var14) { + var5.add(new ServoConfiguration(var14)); + } + + var7 = new ServoControllerConfiguration(var4, var5, var6); + ((ControllerConfiguration)var7).setPort(var1); + } else if(var2.equalsIgnoreCase(DeviceConfiguration.ConfigurationType.MATRIX_CONTROLLER.toString())) { + ArrayList var8 = new ArrayList(); + + for(int var9 = 1; var9 <= 4; ++var9) { + var8.add(new MotorConfiguration(var9)); + } + + ArrayList var10 = new ArrayList(); + + for(int var11 = 1; var11 <= 4; ++var11) { + var10.add(new ServoConfiguration(var11)); + } + + var7 = new MatrixControllerConfiguration(var4, var8, var10, var6); + ((ControllerConfiguration)var7).setPort(var1); + } + + ((ControllerConfiguration)var7).setEnabled(true); + this.b((DeviceConfiguration)var7); + } + + } + + private void a(View var1, DeviceConfiguration var2) { + Spinner var3 = (Spinner)var1.findViewById(R.id.choiceSpinner_legacyModule); + var3.setSelection(((ArrayAdapter)var3.getAdapter()).getPosition(var2.getType().toString())); + var3.setOnItemSelectedListener(this.n); + String var4 = var2.getName(); + EditText var5 = (EditText)var1.findViewById(R.id.editTextResult_name); + int var6 = Integer.parseInt(((TextView)var1.findViewById(R.id.portNumber)).getText().toString()); + var5.addTextChangedListener(new a(var2, null)); + var5.setText(var4); + if(a) { + RobotLog.e("[populatePort] name: " + var4 + ", port: " + var6 + ", type: " + var2.getType()); + } + + } + + private void a(EditText var1, DeviceConfiguration var2) { + if(var1.getText().toString().equalsIgnoreCase("NO DEVICE ATTACHED")) { + var1.setText(""); + var2.setName(""); + } else { + var1.setText(var2.getName()); + } + } + + private void a(LinearLayout var1) { + int var2 = Integer.parseInt(((TextView)var1.findViewById(R.id.portNumber)).getText().toString()); + EditText var3 = (EditText)var1.findViewById(R.id.editTextResult_name); + var3.setEnabled(false); + var3.setText("NO DEVICE ATTACHED"); + DeviceConfiguration var4 = new DeviceConfiguration(DeviceConfiguration.ConfigurationType.NOTHING); + var4.setPort(var2); + this.b(var4); + this.a(var2, 8); + } + + private void a(LinearLayout var1, String var2) { + int var3 = Integer.parseInt(((TextView)var1.findViewById(R.id.portNumber)).getText().toString()); + EditText var4 = (EditText)var1.findViewById(R.id.editTextResult_name); + DeviceConfiguration var5 = this.g.get(var3); + var4.setEnabled(true); + this.a(var4, var5); + DeviceConfiguration.ConfigurationType var6 = var5.typeFromString(var2); + if(var6 != DeviceConfiguration.ConfigurationType.MOTOR_CONTROLLER && var6 != DeviceConfiguration.ConfigurationType.SERVO_CONTROLLER && var6 != DeviceConfiguration.ConfigurationType.MATRIX_CONTROLLER) { + var5.setType(var6); + if(var6 == DeviceConfiguration.ConfigurationType.NOTHING) { + var5.setEnabled(false); + } else { + var5.setEnabled(true); + } + + this.a(var3, 8); + } else { + this.a(var3, var2); + this.a(var3, 0); + } + + if(a) { + DeviceConfiguration var7 = this.g.get(var3); + RobotLog.e("[changeDevice] modules.get(port) name: " + var7.getName() + ", port: " + var7.getPort() + ", type: " + var7.getType()); + } + + } + + private void a(DeviceConfiguration var1) { + var1.setName(((EditText) this.a(var1.getPort()).findViewById(R.id.editTextResult_name)).getText().toString()); + if(var1.getType() == DeviceConfiguration.ConfigurationType.MOTOR_CONTROLLER) { + Intent var2 = new Intent(this.d, EditMotorControllerActivity.class); + var2.putExtra("EDIT_MOTOR_CONTROLLER_CONFIG", var1); + var2.putExtra("requestCode", 101); + this.setResult(-1, var2); + this.startActivityForResult(var2, 101); + } else { + if(var1.getType() == DeviceConfiguration.ConfigurationType.SERVO_CONTROLLER) { + Intent var5 = new Intent(this.d, EditServoControllerActivity.class); + var5.putExtra("Edit Servo ControllerConfiguration Activity", var1); + this.setResult(-1, var5); + this.startActivityForResult(var5, 102); + return; + } + + if(var1.getType() == DeviceConfiguration.ConfigurationType.MATRIX_CONTROLLER) { + Intent var7 = new Intent(this.d, EditMatrixControllerActivity.class); + var7.putExtra("Edit Matrix ControllerConfiguration Activity", var1); + this.setResult(-1, var7); + this.startActivityForResult(var7, 103); + return; + } + } + + } + + private void b(DeviceConfiguration var1) { + int var2 = var1.getPort(); + this.g.set(var2, var1); + } + + private boolean c(DeviceConfiguration var1) { + return var1.getType() == DeviceConfiguration.ConfigurationType.MOTOR_CONTROLLER || var1.getType() == DeviceConfiguration.ConfigurationType.SERVO_CONTROLLER; + } + + public void cancelLegacyController(View var1) { + this.setResult(0, new Intent()); + this.finish(); + } + + public void editController_portALL(View var1) { + LinearLayout var2 = (LinearLayout)var1.getParent().getParent(); + int var3 = Integer.parseInt(((TextView)var2.findViewById(R.id.portNumber)).getText().toString()); + DeviceConfiguration var4 = this.g.get(var3); + if(!this.c(var4)) { + this.a(var3, ((Spinner)var2.findViewById(R.id.choiceSpinner_legacyModule)).getSelectedItem().toString()); + } + + this.a(var4); + } + + protected void onActivityResult(int var1, int var2, Intent var3) { + if(var2 == -1) { + Serializable var4; + if(var1 == 101) { + var4 = var3.getSerializableExtra("EDIT_MOTOR_CONTROLLER_CONFIG"); + } else if(var1 == 102) { + var4 = var3.getSerializableExtra("Edit Servo ControllerConfiguration Activity"); + } else { + var4 = null; + if(var1 == 103) { + var4 = var3.getSerializableExtra("Edit Matrix ControllerConfiguration Activity"); + } + } + + if(var4 != null) { + ControllerConfiguration var5 = (ControllerConfiguration)var4; + this.b(var5); + this.a(this.a(var5.getPort()), this.g.get(var5.getPort())); + if(!this.c.toLowerCase().contains("Unsaved".toLowerCase())) { + String var6 = "Unsaved " + this.c; + this.b.saveToPreferences(var6, R.string.pref_hardware_config_filename); + this.c = var6; + } + + this.b.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + } + } + + } + + protected void onCreate(Bundle var1) { + super.onCreate(var1); + this.setContentView(R.layout.legacy); + LinearLayout var2 = (LinearLayout)this.findViewById(R.id.linearLayout0); + this.h = this.getLayoutInflater().inflate(R.layout.simple_device, var2, true); + ((TextView)this.h.findViewById(R.id.portNumber)).setText("0"); + LinearLayout var3 = (LinearLayout)this.findViewById(R.id.linearLayout1); + this.i = this.getLayoutInflater().inflate(R.layout.simple_device, var3, true); + ((TextView)this.i.findViewById(R.id.portNumber)).setText("1"); + LinearLayout var4 = (LinearLayout)this.findViewById(R.id.linearLayout2); + this.j = this.getLayoutInflater().inflate(R.layout.simple_device, var4, true); + ((TextView)this.j.findViewById(R.id.portNumber)).setText("2"); + LinearLayout var5 = (LinearLayout)this.findViewById(R.id.linearLayout3); + this.k = this.getLayoutInflater().inflate(R.layout.simple_device, var5, true); + ((TextView)this.k.findViewById(R.id.portNumber)).setText("3"); + LinearLayout var6 = (LinearLayout)this.findViewById(R.id.linearLayout4); + this.l = this.getLayoutInflater().inflate(R.layout.simple_device, var6, true); + ((TextView)this.l.findViewById(R.id.portNumber)).setText("4"); + LinearLayout var7 = (LinearLayout)this.findViewById(R.id.linearLayout5); + this.m = this.getLayoutInflater().inflate(R.layout.simple_device, var7, true); + ((TextView)this.m.findViewById(R.id.portNumber)).setText("5"); + this.d = this; + PreferenceManager.setDefaultValues(this, R.xml.preferences, false); + this.b = new Utility(this); + RobotLog.writeLogcatToDisk(this, 1024); + this.f = (EditText)this.findViewById(R.id.device_interface_module_name); + } + + protected void onStart() { + super.onStart(); + this.b.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + this.c = this.b.getFilenameFromPrefs(R.string.pref_hardware_config_filename, "No current file!"); + Serializable var1 = this.getIntent().getSerializableExtra("EDIT_LEGACY_CONFIG"); + if(var1 != null) { + this.e = (LegacyModuleControllerConfiguration)var1; + this.g = (ArrayList)this.e.getDevices(); + this.f.setText(this.e.getName()); + this.f.addTextChangedListener(new a(this.e, null)); + ((TextView)this.findViewById(R.id.legacy_serialNumber)).setText(this.e.getSerialNumber().toString()); + + for(int var2 = 0; var2 < this.g.size(); ++var2) { + DeviceConfiguration var3 = this.g.get(var2); + if(a) { + RobotLog.e("[onStart] module name: " + var3.getName() + ", port: " + var3.getPort() + ", type: " + var3.getType()); + } + + this.a(this.a(var2), var3); + } + } + + } + + public void saveLegacyController(View var1) { + this.a(); + } + + private class a implements TextWatcher { + private DeviceConfiguration b; + + private a(DeviceConfiguration var2) { + this.b = var2; + } + + // $FF: synthetic method + a(DeviceConfiguration var2, Object var3) { + this(var2); + } + + public void afterTextChanged(Editable var1) { + String var2 = var1.toString(); + this.b.setName(var2); + } + + public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + + public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditMatrixControllerActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditMatrixControllerActivity.java similarity index 90% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditMatrixControllerActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditMatrixControllerActivity.java index 5fa770a..2ff0ab7 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditMatrixControllerActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditMatrixControllerActivity.java @@ -1,216 +1,218 @@ -package com.qualcomm.ftccommon.configuration; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.TextView; -import com.qualcomm.ftccommon.R; -import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; -import com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration; -import com.qualcomm.robotcore.hardware.configuration.Utility; -import com.qualcomm.robotcore.util.RobotLog; -import java.io.Serializable; -import java.util.ArrayList; - -public class EditMatrixControllerActivity extends Activity { - public static final String EDIT_MATRIX_ACTIVITY = "Edit Matrix ControllerConfiguration Activity"; - private Utility a; - private MatrixControllerConfiguration b; - private ArrayList c; - private ArrayList d; - private EditText e; - private View f; - private View g; - private View h; - private View i; - private View j; - private View k; - private View l; - private View m; - - private View a(int var1) { - switch(var1) { - case 1: - return this.f; - case 2: - return this.g; - case 3: - return this.h; - case 4: - return this.i; - default: - return null; - } - } - - private void a() { - Intent var1 = new Intent(); - this.b.addServos(this.d); - this.b.addMotors(this.c); - this.b.setName(this.e.getText().toString()); - var1.putExtra("Edit Matrix ControllerConfiguration Activity", this.b); - this.setResult(-1, var1); - this.finish(); - } - - private void a(int var1, View var2, ArrayList var3) { - CheckBox var4 = (CheckBox)var2.findViewById(R.id.checkbox_port_matrix); - DeviceConfiguration var5 = (DeviceConfiguration)var3.get(var1 - 1); - if(var5.isEnabled()) { - var4.setChecked(true); - ((EditText)var2.findViewById(R.id.editTextResult_matrix)).setText(var5.getName()); - } else { - var4.setChecked(true); - var4.performClick(); - } - } - - private void a(View var1, DeviceConfiguration var2) { - ((EditText)var1.findViewById(R.id.editTextResult_matrix)).addTextChangedListener(new EditMatrixControllerActivity.a(var2, null)); - } - - private View b(int var1) { - switch(var1) { - case 1: - return this.j; - case 2: - return this.k; - case 3: - return this.l; - case 4: - return this.m; - default: - return null; - } - } - - private void b(int var1, View var2, ArrayList var3) { - final EditText var4 = (EditText)var2.findViewById(R.id.editTextResult_matrix); - final DeviceConfiguration var5 = (DeviceConfiguration)var3.get(var1 - 1); - ((CheckBox)var2.findViewById(R.id.checkbox_port_matrix)).setOnClickListener(new OnClickListener() { - public void onClick(View var1) { - if(((CheckBox)var1).isChecked()) { - var4.setEnabled(true); - var4.setText(""); - var5.setEnabled(true); - var5.setName(""); - } else { - var4.setEnabled(false); - var5.setEnabled(false); - var5.setName("NO DEVICE ATTACHED"); - var4.setText("NO DEVICE ATTACHED"); - } - } - }); - } - - public void cancelMatrixController(View var1) { - this.setResult(0, new Intent()); - this.finish(); - } - - protected void onCreate(Bundle var1) { - super.onCreate(var1); - this.setContentView(R.layout.matrices); - PreferenceManager.setDefaultValues(this, R.xml.preferences, false); - this.a = new Utility(this); - RobotLog.writeLogcatToDisk(this, 1024); - this.e = (EditText)this.findViewById(R.id.matrixcontroller_name); - LinearLayout var2 = (LinearLayout)this.findViewById(R.id.linearLayout_matrix1); - this.f = this.getLayoutInflater().inflate(R.layout.matrix_devices, var2, true); - ((TextView)this.f.findViewById(R.id.port_number_matrix)).setText("1"); - LinearLayout var3 = (LinearLayout)this.findViewById(R.id.linearLayout_matrix2); - this.g = this.getLayoutInflater().inflate(R.layout.matrix_devices, var3, true); - ((TextView)this.g.findViewById(R.id.port_number_matrix)).setText("2"); - LinearLayout var4 = (LinearLayout)this.findViewById(R.id.linearLayout_matrix3); - this.h = this.getLayoutInflater().inflate(R.layout.matrix_devices, var4, true); - ((TextView)this.h.findViewById(R.id.port_number_matrix)).setText("3"); - LinearLayout var5 = (LinearLayout)this.findViewById(R.id.linearLayout_matrix4); - this.i = this.getLayoutInflater().inflate(R.layout.matrix_devices, var5, true); - ((TextView)this.i.findViewById(R.id.port_number_matrix)).setText("4"); - LinearLayout var6 = (LinearLayout)this.findViewById(R.id.linearLayout_matrix5); - this.j = this.getLayoutInflater().inflate(R.layout.matrix_devices, var6, true); - ((TextView)this.j.findViewById(R.id.port_number_matrix)).setText("1"); - LinearLayout var7 = (LinearLayout)this.findViewById(R.id.linearLayout_matrix6); - this.k = this.getLayoutInflater().inflate(R.layout.matrix_devices, var7, true); - ((TextView)this.k.findViewById(R.id.port_number_matrix)).setText("2"); - LinearLayout var8 = (LinearLayout)this.findViewById(R.id.linearLayout_matrix7); - this.l = this.getLayoutInflater().inflate(R.layout.matrix_devices, var8, true); - ((TextView)this.l.findViewById(R.id.port_number_matrix)).setText("3"); - LinearLayout var9 = (LinearLayout)this.findViewById(R.id.linearLayout_matrix8); - this.m = this.getLayoutInflater().inflate(R.layout.matrix_devices, var9, true); - ((TextView)this.m.findViewById(R.id.port_number_matrix)).setText("4"); - } - - protected void onStart() { - super.onStart(); - this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - Serializable var1 = this.getIntent().getSerializableExtra("Edit Matrix ControllerConfiguration Activity"); - if(var1 != null) { - this.b = (MatrixControllerConfiguration)var1; - this.c = (ArrayList)this.b.getMotors(); - this.d = (ArrayList)this.b.getServos(); - } - - this.e.setText(this.b.getName()); - int var2 = 0; - - while(true) { - int var3 = this.c.size(); - int var4 = 0; - if(var2 >= var3) { - while(var4 < this.d.size()) { - View var5 = this.a(var4 + 1); - this.b(var4 + 1, var5, this.d); - this.a(var5, (DeviceConfiguration)this.d.get(var4)); - this.a(var4 + 1, var5, this.d); - ++var4; - } - - return; - } - - View var6 = this.b(var2 + 1); - this.b(var2 + 1, var6, this.c); - this.a(var6, (DeviceConfiguration)this.c.get(var2)); - this.a(var2 + 1, var6, this.c); - ++var2; - } - } - - public void saveMatrixController(View var1) { - this.a(); - } - - private class a implements TextWatcher { - private DeviceConfiguration b; - - private a(DeviceConfiguration var2) { - this.b = var2; - } - - // $FF: synthetic method - a(DeviceConfiguration var2, Object var3) { - this(); - } - - public void afterTextChanged(Editable var1) { - String var2 = var1.toString(); - this.b.setName(var2); - } - - public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - - public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - } -} +package com.qualcomm.ftccommon.configuration; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.qualcomm.ftccommon.R; +import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; +import com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration; +import com.qualcomm.robotcore.hardware.configuration.Utility; +import com.qualcomm.robotcore.util.RobotLog; + +import java.io.Serializable; +import java.util.ArrayList; + +public class EditMatrixControllerActivity extends Activity { + public static final String EDIT_MATRIX_ACTIVITY = "Edit Matrix ControllerConfiguration Activity"; + private Utility a; + private MatrixControllerConfiguration b; + private ArrayList c; + private ArrayList d; + private EditText e; + private View f; + private View g; + private View h; + private View i; + private View j; + private View k; + private View l; + private View m; + + private View a(int var1) { + switch(var1) { + case 1: + return this.f; + case 2: + return this.g; + case 3: + return this.h; + case 4: + return this.i; + default: + return null; + } + } + + private void a() { + Intent var1 = new Intent(); + this.b.addServos(this.d); + this.b.addMotors(this.c); + this.b.setName(this.e.getText().toString()); + var1.putExtra("Edit Matrix ControllerConfiguration Activity", this.b); + this.setResult(-1, var1); + this.finish(); + } + + private void a(int var1, View var2, ArrayList var3) { + CheckBox var4 = (CheckBox)var2.findViewById(R.id.checkbox_port_matrix); + DeviceConfiguration var5 = var3.get(var1 - 1); + if(var5.isEnabled()) { + var4.setChecked(true); + ((EditText)var2.findViewById(R.id.editTextResult_matrix)).setText(var5.getName()); + } else { + var4.setChecked(true); + var4.performClick(); + } + } + + private void a(View var1, DeviceConfiguration var2) { + ((EditText)var1.findViewById(R.id.editTextResult_matrix)).addTextChangedListener(new a(var2, null)); + } + + private View b(int var1) { + switch(var1) { + case 1: + return this.j; + case 2: + return this.k; + case 3: + return this.l; + case 4: + return this.m; + default: + return null; + } + } + + private void b(int var1, View var2, ArrayList var3) { + final EditText var4 = (EditText)var2.findViewById(R.id.editTextResult_matrix); + final DeviceConfiguration var5 = var3.get(var1 - 1); + var2.findViewById(R.id.checkbox_port_matrix).setOnClickListener(new OnClickListener() { + public void onClick(View var1) { + if (((CheckBox) var1).isChecked()) { + var4.setEnabled(true); + var4.setText(""); + var5.setEnabled(true); + var5.setName(""); + } else { + var4.setEnabled(false); + var5.setEnabled(false); + var5.setName("NO DEVICE ATTACHED"); + var4.setText("NO DEVICE ATTACHED"); + } + } + }); + } + + public void cancelMatrixController(View var1) { + this.setResult(0, new Intent()); + this.finish(); + } + + protected void onCreate(Bundle var1) { + super.onCreate(var1); + this.setContentView(R.layout.matrices); + PreferenceManager.setDefaultValues(this, R.xml.preferences, false); + this.a = new Utility(this); + RobotLog.writeLogcatToDisk(this, 1024); + this.e = (EditText)this.findViewById(R.id.matrixcontroller_name); + LinearLayout var2 = (LinearLayout)this.findViewById(R.id.linearLayout_matrix1); + this.f = this.getLayoutInflater().inflate(R.layout.matrix_devices, var2, true); + ((TextView)this.f.findViewById(R.id.port_number_matrix)).setText("1"); + LinearLayout var3 = (LinearLayout)this.findViewById(R.id.linearLayout_matrix2); + this.g = this.getLayoutInflater().inflate(R.layout.matrix_devices, var3, true); + ((TextView)this.g.findViewById(R.id.port_number_matrix)).setText("2"); + LinearLayout var4 = (LinearLayout)this.findViewById(R.id.linearLayout_matrix3); + this.h = this.getLayoutInflater().inflate(R.layout.matrix_devices, var4, true); + ((TextView)this.h.findViewById(R.id.port_number_matrix)).setText("3"); + LinearLayout var5 = (LinearLayout)this.findViewById(R.id.linearLayout_matrix4); + this.i = this.getLayoutInflater().inflate(R.layout.matrix_devices, var5, true); + ((TextView)this.i.findViewById(R.id.port_number_matrix)).setText("4"); + LinearLayout var6 = (LinearLayout)this.findViewById(R.id.linearLayout_matrix5); + this.j = this.getLayoutInflater().inflate(R.layout.matrix_devices, var6, true); + ((TextView)this.j.findViewById(R.id.port_number_matrix)).setText("1"); + LinearLayout var7 = (LinearLayout)this.findViewById(R.id.linearLayout_matrix6); + this.k = this.getLayoutInflater().inflate(R.layout.matrix_devices, var7, true); + ((TextView)this.k.findViewById(R.id.port_number_matrix)).setText("2"); + LinearLayout var8 = (LinearLayout)this.findViewById(R.id.linearLayout_matrix7); + this.l = this.getLayoutInflater().inflate(R.layout.matrix_devices, var8, true); + ((TextView)this.l.findViewById(R.id.port_number_matrix)).setText("3"); + LinearLayout var9 = (LinearLayout)this.findViewById(R.id.linearLayout_matrix8); + this.m = this.getLayoutInflater().inflate(R.layout.matrix_devices, var9, true); + ((TextView)this.m.findViewById(R.id.port_number_matrix)).setText("4"); + } + + protected void onStart() { + super.onStart(); + this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + Serializable var1 = this.getIntent().getSerializableExtra("Edit Matrix ControllerConfiguration Activity"); + if(var1 != null) { + this.b = (MatrixControllerConfiguration)var1; + this.c = (ArrayList)this.b.getMotors(); + this.d = (ArrayList)this.b.getServos(); + } + + this.e.setText(this.b.getName()); + int var2 = 0; + + while(true) { + int var3 = this.c.size(); + int var4 = 0; + if(var2 >= var3) { + while(var4 < this.d.size()) { + View var5 = this.a(var4 + 1); + this.b(var4 + 1, var5, this.d); + this.a(var5, this.d.get(var4)); + this.a(var4 + 1, var5, this.d); + ++var4; + } + + return; + } + + View var6 = this.b(var2 + 1); + this.b(var2 + 1, var6, this.c); + this.a(var6, this.c.get(var2)); + this.a(var2 + 1, var6, this.c); + ++var2; + } + } + + public void saveMatrixController(View var1) { + this.a(); + } + + private class a implements TextWatcher { + private DeviceConfiguration b; + + private a(DeviceConfiguration var2) { + this.b = var2; + } + + // $FF: synthetic method + a(DeviceConfiguration var2, Object var3) { + this(var2); + } + + public void afterTextChanged(Editable var1) { + String var2 = var1.toString(); + this.b.setName(var2); + } + + public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + + public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditMotorControllerActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditMotorControllerActivity.java similarity index 97% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditMotorControllerActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditMotorControllerActivity.java index 2e4fff6..12707e2 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditMotorControllerActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditMotorControllerActivity.java @@ -1,160 +1,162 @@ -package com.qualcomm.ftccommon.configuration; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.TextView; -import com.qualcomm.ftccommon.R; -import com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration; -import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; -import com.qualcomm.robotcore.hardware.configuration.MotorConfiguration; -import com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration; -import com.qualcomm.robotcore.hardware.configuration.Utility; -import com.qualcomm.robotcore.util.RobotLog; -import java.io.Serializable; -import java.util.ArrayList; - -public class EditMotorControllerActivity extends Activity { - public static final String EDIT_MOTOR_CONTROLLER_CONFIG = "EDIT_MOTOR_CONTROLLER_CONFIG"; - private Utility a; - private MotorControllerConfiguration b; - private ArrayList c = new ArrayList(); - private MotorConfiguration d = new MotorConfiguration(1); - private MotorConfiguration e = new MotorConfiguration(2); - private EditText f; - private boolean g = true; - private boolean h = true; - private CheckBox i; - private CheckBox j; - private EditText k; - private EditText l; - - private void a() { - this.i.setOnClickListener(new OnClickListener() { - public void onClick(View var1) { - if(((CheckBox)var1).isChecked()) { - EditMotorControllerActivity.this.g = true; - EditMotorControllerActivity.this.k.setEnabled(true); - EditMotorControllerActivity.this.k.setText(""); - EditMotorControllerActivity.this.d.setPort(1); - EditMotorControllerActivity.this.d.setType(DeviceConfiguration.ConfigurationType.MOTOR); - } else { - EditMotorControllerActivity.this.g = false; - EditMotorControllerActivity.this.k.setEnabled(false); - EditMotorControllerActivity.this.k.setText("NO DEVICE ATTACHED"); - EditMotorControllerActivity.this.d.setType(DeviceConfiguration.ConfigurationType.NOTHING); - } - } - }); - } - - private void a(MotorConfiguration var1, CheckBox var2) { - if(!var1.getName().equals("NO DEVICE ATTACHED") && var1.getType() != DeviceConfiguration.ConfigurationType.NOTHING) { - var2.setChecked(true); - } else { - var2.setChecked(true); - var2.performClick(); - } - } - - private void b() { - this.j.setOnClickListener(new OnClickListener() { - public void onClick(View var1) { - if(((CheckBox)var1).isChecked()) { - EditMotorControllerActivity.this.h = true; - EditMotorControllerActivity.this.l.setEnabled(true); - EditMotorControllerActivity.this.l.setText(""); - EditMotorControllerActivity.this.e.setPort(2); - EditMotorControllerActivity.this.d.setType(DeviceConfiguration.ConfigurationType.MOTOR); - } else { - EditMotorControllerActivity.this.h = false; - EditMotorControllerActivity.this.l.setEnabled(false); - EditMotorControllerActivity.this.l.setText("NO DEVICE ATTACHED"); - EditMotorControllerActivity.this.d.setType(DeviceConfiguration.ConfigurationType.NOTHING); - } - } - }); - } - - private void c() { - Intent var1 = new Intent(); - ArrayList var2 = new ArrayList(); - if(this.g) { - MotorConfiguration var3 = new MotorConfiguration(this.k.getText().toString()); - var3.setEnabled(true); - var3.setPort(1); - var2.add(var3); - } else { - var2.add(new MotorConfiguration(1)); - } - - if(this.h) { - MotorConfiguration var5 = new MotorConfiguration(this.l.getText().toString()); - var5.setEnabled(true); - var5.setPort(2); - var2.add(var5); - } else { - var2.add(new MotorConfiguration(2)); - } - - this.b.addMotors(var2); - this.b.setName(this.f.getText().toString()); - var1.putExtra("EDIT_MOTOR_CONTROLLER_CONFIG", this.b); - this.setResult(-1, var1); - this.finish(); - } - - public void cancelMotorController(View var1) { - this.setResult(0, new Intent()); - this.finish(); - } - - protected void onCreate(Bundle var1) { - super.onCreate(var1); - this.setContentView(R.layout.motors); - PreferenceManager.setDefaultValues(this, R.xml.preferences, false); - this.a = new Utility(this); - RobotLog.writeLogcatToDisk(this, 1024); - this.f = (EditText)this.findViewById(R.id.controller_name); - this.i = (CheckBox)this.findViewById(R.id.checkbox_port7); - this.j = (CheckBox)this.findViewById(R.id.checkbox_port6); - this.k = (EditText)this.findViewById(R.id.editTextResult_analogInput7); - this.l = (EditText)this.findViewById(R.id.editTextResult_analogInput6); - } - - protected void onStart() { - super.onStart(); - this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - Serializable var1 = this.getIntent().getSerializableExtra("EDIT_MOTOR_CONTROLLER_CONFIG"); - if(var1 != null) { - this.b = (MotorControllerConfiguration)var1; - this.c = (ArrayList)this.b.getMotors(); - this.d = (MotorConfiguration)this.c.get(0); - this.e = (MotorConfiguration)this.c.get(1); - this.f.setText(this.b.getName()); - TextView var2 = (TextView)this.findViewById(R.id.motor_controller_serialNumber); - String var3 = this.b.getSerialNumber().toString(); - if(var3.equalsIgnoreCase(ControllerConfiguration.NO_SERIAL_NUMBER.toString())) { - var3 = "No serial number"; - } - - var2.setText(var3); - this.k.setText(this.d.getName()); - this.l.setText(this.e.getName()); - this.a(); - this.a(this.d, this.i); - this.b(); - this.a(this.e, this.j); - } - - } - - public void saveMotorController(View var1) { - this.c(); - } -} +package com.qualcomm.ftccommon.configuration; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.TextView; + +import com.qualcomm.ftccommon.R; +import com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration; +import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; +import com.qualcomm.robotcore.hardware.configuration.MotorConfiguration; +import com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration; +import com.qualcomm.robotcore.hardware.configuration.Utility; +import com.qualcomm.robotcore.util.RobotLog; + +import java.io.Serializable; +import java.util.ArrayList; + +public class EditMotorControllerActivity extends Activity { + public static final String EDIT_MOTOR_CONTROLLER_CONFIG = "EDIT_MOTOR_CONTROLLER_CONFIG"; + private Utility a; + private MotorControllerConfiguration b; + private ArrayList c = new ArrayList(); + private MotorConfiguration d = new MotorConfiguration(1); + private MotorConfiguration e = new MotorConfiguration(2); + private EditText f; + private boolean g = true; + private boolean h = true; + private CheckBox i; + private CheckBox j; + private EditText k; + private EditText l; + + private void a() { + this.i.setOnClickListener(new OnClickListener() { + public void onClick(View var1) { + if(((CheckBox)var1).isChecked()) { + EditMotorControllerActivity.this.g = true; + EditMotorControllerActivity.this.k.setEnabled(true); + EditMotorControllerActivity.this.k.setText(""); + EditMotorControllerActivity.this.d.setPort(1); + EditMotorControllerActivity.this.d.setType(DeviceConfiguration.ConfigurationType.MOTOR); + } else { + EditMotorControllerActivity.this.g = false; + EditMotorControllerActivity.this.k.setEnabled(false); + EditMotorControllerActivity.this.k.setText("NO DEVICE ATTACHED"); + EditMotorControllerActivity.this.d.setType(DeviceConfiguration.ConfigurationType.NOTHING); + } + } + }); + } + + private void a(MotorConfiguration var1, CheckBox var2) { + if(!var1.getName().equals("NO DEVICE ATTACHED") && var1.getType() != DeviceConfiguration.ConfigurationType.NOTHING) { + var2.setChecked(true); + } else { + var2.setChecked(true); + var2.performClick(); + } + } + + private void b() { + this.j.setOnClickListener(new OnClickListener() { + public void onClick(View var1) { + if(((CheckBox)var1).isChecked()) { + EditMotorControllerActivity.this.h = true; + EditMotorControllerActivity.this.l.setEnabled(true); + EditMotorControllerActivity.this.l.setText(""); + EditMotorControllerActivity.this.e.setPort(2); + EditMotorControllerActivity.this.d.setType(DeviceConfiguration.ConfigurationType.MOTOR); + } else { + EditMotorControllerActivity.this.h = false; + EditMotorControllerActivity.this.l.setEnabled(false); + EditMotorControllerActivity.this.l.setText("NO DEVICE ATTACHED"); + EditMotorControllerActivity.this.d.setType(DeviceConfiguration.ConfigurationType.NOTHING); + } + } + }); + } + + private void c() { + Intent var1 = new Intent(); + ArrayList var2 = new ArrayList(); + if(this.g) { + MotorConfiguration var3 = new MotorConfiguration(this.k.getText().toString()); + var3.setEnabled(true); + var3.setPort(1); + var2.add(var3); + } else { + var2.add(new MotorConfiguration(1)); + } + + if(this.h) { + MotorConfiguration var5 = new MotorConfiguration(this.l.getText().toString()); + var5.setEnabled(true); + var5.setPort(2); + var2.add(var5); + } else { + var2.add(new MotorConfiguration(2)); + } + + this.b.addMotors(var2); + this.b.setName(this.f.getText().toString()); + var1.putExtra("EDIT_MOTOR_CONTROLLER_CONFIG", this.b); + this.setResult(-1, var1); + this.finish(); + } + + public void cancelMotorController(View var1) { + this.setResult(0, new Intent()); + this.finish(); + } + + protected void onCreate(Bundle var1) { + super.onCreate(var1); + this.setContentView(R.layout.motors); + PreferenceManager.setDefaultValues(this, R.xml.preferences, false); + this.a = new Utility(this); + RobotLog.writeLogcatToDisk(this, 1024); + this.f = (EditText)this.findViewById(R.id.controller_name); + this.i = (CheckBox)this.findViewById(R.id.checkbox_port7); + this.j = (CheckBox)this.findViewById(R.id.checkbox_port6); + this.k = (EditText)this.findViewById(R.id.editTextResult_analogInput7); + this.l = (EditText)this.findViewById(R.id.editTextResult_analogInput6); + } + + protected void onStart() { + super.onStart(); + this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + Serializable var1 = this.getIntent().getSerializableExtra("EDIT_MOTOR_CONTROLLER_CONFIG"); + if(var1 != null) { + this.b = (MotorControllerConfiguration)var1; + this.c = (ArrayList)this.b.getMotors(); + this.d = (MotorConfiguration)this.c.get(0); + this.e = (MotorConfiguration)this.c.get(1); + this.f.setText(this.b.getName()); + TextView var2 = (TextView)this.findViewById(R.id.motor_controller_serialNumber); + String var3 = this.b.getSerialNumber().toString(); + if(var3.equalsIgnoreCase(ControllerConfiguration.NO_SERIAL_NUMBER.toString())) { + var3 = "No serial number"; + } + + var2.setText(var3); + this.k.setText(this.d.getName()); + this.l.setText(this.e.getName()); + this.a(); + this.a(this.d, this.i); + this.b(); + this.a(this.e, this.j); + } + + } + + public void saveMotorController(View var1) { + this.c(); + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditPWMDevicesActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditPWMDevicesActivity.java similarity index 85% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditPWMDevicesActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditPWMDevicesActivity.java index 64eaff5..92431d8 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditPWMDevicesActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditPWMDevicesActivity.java @@ -1,160 +1,161 @@ -package com.qualcomm.ftccommon.configuration; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.TextView; -import com.qualcomm.ftccommon.R; -import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; -import com.qualcomm.robotcore.hardware.configuration.Utility; -import com.qualcomm.robotcore.util.RobotLog; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Iterator; - -public class EditPWMDevicesActivity extends Activity { - public static final String EDIT_PWM_DEVICES = "EDIT_PWM_DEVICES"; - private Utility a; - private View b; - private View c; - private ArrayList d = new ArrayList(); - - private void a() { - Bundle var1 = new Bundle(); - - for(int var2 = 0; var2 < this.d.size(); ++var2) { - var1.putSerializable(String.valueOf(var2), (Serializable)this.d.get(var2)); - } - - Intent var3 = new Intent(); - var3.putExtras(var1); - var3.putExtras(var1); - this.setResult(-1, var3); - this.finish(); - } - - private void a(int var1) { - View var2 = this.d(var1); - CheckBox var3 = (CheckBox)var2.findViewById(R.id.checkbox_port_pwm); - DeviceConfiguration var4 = (DeviceConfiguration)this.d.get(var1); - if(var4.isEnabled()) { - var3.setChecked(true); - ((EditText)var2.findViewById(R.id.editTextResult_pwm)).setText(var4.getName()); - } else { - var3.setChecked(true); - var3.performClick(); - } - } - - private void b(int var1) { - View var2 = this.d(var1); - ((EditText)var2.findViewById(R.id.editTextResult_pwm)).addTextChangedListener(new EditPWMDevicesActivity.a(var2, null)); - } - - private void c(int var1) { - View var2 = this.d(var1); - final EditText var3 = (EditText)var2.findViewById(R.id.editTextResult_pwm); - final DeviceConfiguration var4 = (DeviceConfiguration)this.d.get(var1); - ((CheckBox)var2.findViewById(R.id.checkbox_port_pwm)).setOnClickListener(new OnClickListener() { - public void onClick(View var1) { - if(((CheckBox)var1).isChecked()) { - var3.setEnabled(true); - var3.setText(""); - var4.setEnabled(true); - var4.setName(""); - } else { - var3.setEnabled(false); - var4.setEnabled(false); - var4.setName("NO DEVICE ATTACHED"); - var3.setText("NO DEVICE ATTACHED"); - } - } - }); - } - - private View d(int var1) { - switch(var1) { - case 0: - return this.b; - case 1: - return this.c; - default: - return null; - } - } - - public void cancelPWMDevices(View var1) { - this.setResult(0, new Intent()); - this.finish(); - } - - protected void onCreate(Bundle var1) { - super.onCreate(var1); - this.setContentView(R.layout.pwms); - PreferenceManager.setDefaultValues(this, R.xml.preferences, false); - this.a = new Utility(this); - RobotLog.writeLogcatToDisk(this, 1024); - LinearLayout var2 = (LinearLayout)this.findViewById(R.id.linearLayout_pwm0); - this.b = this.getLayoutInflater().inflate(R.layout.pwm_device, var2, true); - ((TextView)this.b.findViewById(R.id.port_number_pwm)).setText("0"); - LinearLayout var3 = (LinearLayout)this.findViewById(R.id.linearLayout_pwm1); - this.c = this.getLayoutInflater().inflate(R.layout.pwm_device, var3, true); - ((TextView)this.c.findViewById(R.id.port_number_pwm)).setText("1"); - } - - protected void onStart() { - super.onStart(); - this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - Bundle var1 = this.getIntent().getExtras(); - if(var1 != null) { - Iterator var2 = var1.keySet().iterator(); - - while(var2.hasNext()) { - String var4 = (String)var2.next(); - this.d.add(Integer.parseInt(var4), (DeviceConfiguration)var1.getSerializable(var4)); - } - - for(int var3 = 0; var3 < this.d.size(); ++var3) { - this.c(var3); - this.b(var3); - this.a(var3); - } - } - - } - - public void savePWMDevices(View var1) { - this.a(); - } - - private class a implements TextWatcher { - private int b; - - private a(View var2) { - this.b = Integer.parseInt(((TextView)var2.findViewById(R.id.port_number_pwm)).getText().toString()); - } - - // $FF: synthetic method - a(View var2, Object var3) { - this(); - } - - public void afterTextChanged(Editable var1) { - ((DeviceConfiguration)EditPWMDevicesActivity.this.d.get(this.b)).setName(var1.toString()); - } - - public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - - public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - } -} +package com.qualcomm.ftccommon.configuration; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.qualcomm.ftccommon.R; +import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; +import com.qualcomm.robotcore.hardware.configuration.Utility; +import com.qualcomm.robotcore.util.RobotLog; + +import java.util.ArrayList; +import java.util.Iterator; + +public class EditPWMDevicesActivity extends Activity { + public static final String EDIT_PWM_DEVICES = "EDIT_PWM_DEVICES"; + private Utility a; + private View b; + private View c; + private ArrayList d = new ArrayList(); + + private void a() { + Bundle var1 = new Bundle(); + + for(int var2 = 0; var2 < this.d.size(); ++var2) { + var1.putSerializable(String.valueOf(var2), this.d.get(var2)); + } + + Intent var3 = new Intent(); + var3.putExtras(var1); + var3.putExtras(var1); + this.setResult(-1, var3); + this.finish(); + } + + private void a(int var1) { + View var2 = this.d(var1); + CheckBox var3 = (CheckBox)var2.findViewById(R.id.checkbox_port_pwm); + DeviceConfiguration var4 = this.d.get(var1); + if(var4.isEnabled()) { + var3.setChecked(true); + ((EditText)var2.findViewById(R.id.editTextResult_pwm)).setText(var4.getName()); + } else { + var3.setChecked(true); + var3.performClick(); + } + } + + private void b(int var1) { + View var2 = this.d(var1); + ((EditText)var2.findViewById(R.id.editTextResult_pwm)).addTextChangedListener(new a(var2, null)); + } + + private void c(int var1) { + View var2 = this.d(var1); + final EditText var3 = (EditText)var2.findViewById(R.id.editTextResult_pwm); + final DeviceConfiguration var4 = this.d.get(var1); + var2.findViewById(R.id.checkbox_port_pwm).setOnClickListener(new OnClickListener() { + public void onClick(View var1) { + if (((CheckBox) var1).isChecked()) { + var3.setEnabled(true); + var3.setText(""); + var4.setEnabled(true); + var4.setName(""); + } else { + var3.setEnabled(false); + var4.setEnabled(false); + var4.setName("NO DEVICE ATTACHED"); + var3.setText("NO DEVICE ATTACHED"); + } + } + }); + } + + private View d(int var1) { + switch(var1) { + case 0: + return this.b; + case 1: + return this.c; + default: + return null; + } + } + + public void cancelPWMDevices(View var1) { + this.setResult(0, new Intent()); + this.finish(); + } + + protected void onCreate(Bundle var1) { + super.onCreate(var1); + this.setContentView(R.layout.pwms); + PreferenceManager.setDefaultValues(this, R.xml.preferences, false); + this.a = new Utility(this); + RobotLog.writeLogcatToDisk(this, 1024); + LinearLayout var2 = (LinearLayout)this.findViewById(R.id.linearLayout_pwm0); + this.b = this.getLayoutInflater().inflate(R.layout.pwm_device, var2, true); + ((TextView)this.b.findViewById(R.id.port_number_pwm)).setText("0"); + LinearLayout var3 = (LinearLayout)this.findViewById(R.id.linearLayout_pwm1); + this.c = this.getLayoutInflater().inflate(R.layout.pwm_device, var3, true); + ((TextView)this.c.findViewById(R.id.port_number_pwm)).setText("1"); + } + + protected void onStart() { + super.onStart(); + this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + Bundle var1 = this.getIntent().getExtras(); + if(var1 != null) { + Iterator var2 = var1.keySet().iterator(); + + while(var2.hasNext()) { + String var4 = (String)var2.next(); + this.d.add(Integer.parseInt(var4), (DeviceConfiguration)var1.getSerializable(var4)); + } + + for(int var3 = 0; var3 < this.d.size(); ++var3) { + this.c(var3); + this.b(var3); + this.a(var3); + } + } + + } + + public void savePWMDevices(View var1) { + this.a(); + } + + private class a implements TextWatcher { + private int b; + + private a(View var2) { + this.b = Integer.parseInt(((TextView)var2.findViewById(R.id.port_number_pwm)).getText().toString()); + } + + // $FF: synthetic method + a(View var2, Object var3) { + this(var2); + } + + public void afterTextChanged(Editable var1) { + EditPWMDevicesActivity.this.d.get(this.b).setName(var1.toString()); + } + + public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + + public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditServoControllerActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditServoControllerActivity.java similarity index 90% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditServoControllerActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditServoControllerActivity.java index 6e85f41..83f3e27 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/EditServoControllerActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/EditServoControllerActivity.java @@ -1,188 +1,190 @@ -package com.qualcomm.ftccommon.configuration; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.TextView; -import com.qualcomm.ftccommon.R; -import com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration; -import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; -import com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration; -import com.qualcomm.robotcore.hardware.configuration.Utility; -import com.qualcomm.robotcore.util.RobotLog; -import java.io.Serializable; -import java.util.ArrayList; - -public class EditServoControllerActivity extends Activity { - public static final String EDIT_SERVO_ACTIVITY = "Edit Servo ControllerConfiguration Activity"; - private Utility a; - private ServoControllerConfiguration b; - private ArrayList c; - private EditText d; - private View e; - private View f; - private View g; - private View h; - private View i; - private View j; - - private void a() { - Intent var1 = new Intent(); - this.b.addServos(this.c); - this.b.setName(this.d.getText().toString()); - var1.putExtra("Edit Servo ControllerConfiguration Activity", this.b); - this.setResult(-1, var1); - this.finish(); - } - - private void a(int var1) { - View var2 = this.d(var1); - ((EditText)var2.findViewById(R.id.editTextResult_servo)).addTextChangedListener(new EditServoControllerActivity.a(var2, null)); - } - - private void b(int var1) { - View var2 = this.d(var1); - CheckBox var3 = (CheckBox)var2.findViewById(R.id.checkbox_port_servo); - DeviceConfiguration var4 = (DeviceConfiguration)this.c.get(var1 - 1); - if(var4.isEnabled()) { - var3.setChecked(true); - ((EditText)var2.findViewById(R.id.editTextResult_servo)).setText(var4.getName()); - } else { - var3.setChecked(true); - var3.performClick(); - } - } - - private void c(int var1) { - View var2 = this.d(var1); - final EditText var3 = (EditText)var2.findViewById(R.id.editTextResult_servo); - final DeviceConfiguration var4 = (DeviceConfiguration)this.c.get(var1 - 1); - ((CheckBox)var2.findViewById(R.id.checkbox_port_servo)).setOnClickListener(new OnClickListener() { - public void onClick(View var1) { - if(((CheckBox)var1).isChecked()) { - var3.setEnabled(true); - var3.setText(""); - var4.setEnabled(true); - var4.setName(""); - } else { - var3.setEnabled(false); - var4.setEnabled(false); - var4.setName("NO DEVICE ATTACHED"); - var3.setText("NO DEVICE ATTACHED"); - } - } - }); - } - - private View d(int var1) { - switch(var1) { - case 1: - return this.e; - case 2: - return this.f; - case 3: - return this.g; - case 4: - return this.h; - case 5: - return this.i; - case 6: - return this.j; - default: - return null; - } - } - - public void cancelServoController(View var1) { - this.setResult(0, new Intent()); - this.finish(); - } - - protected void onCreate(Bundle var1) { - super.onCreate(var1); - this.setContentView(R.layout.servos); - PreferenceManager.setDefaultValues(this, R.xml.preferences, false); - this.a = new Utility(this); - RobotLog.writeLogcatToDisk(this, 1024); - this.d = (EditText)this.findViewById(R.id.servocontroller_name); - LinearLayout var2 = (LinearLayout)this.findViewById(R.id.linearLayout_servo1); - this.e = this.getLayoutInflater().inflate(R.layout.servo, var2, true); - ((TextView)this.e.findViewById(R.id.port_number_servo)).setText("1"); - LinearLayout var3 = (LinearLayout)this.findViewById(R.id.linearLayout_servo2); - this.f = this.getLayoutInflater().inflate(R.layout.servo, var3, true); - ((TextView)this.f.findViewById(R.id.port_number_servo)).setText("2"); - LinearLayout var4 = (LinearLayout)this.findViewById(R.id.linearLayout_servo3); - this.g = this.getLayoutInflater().inflate(R.layout.servo, var4, true); - ((TextView)this.g.findViewById(R.id.port_number_servo)).setText("3"); - LinearLayout var5 = (LinearLayout)this.findViewById(R.id.linearLayout_servo4); - this.h = this.getLayoutInflater().inflate(R.layout.servo, var5, true); - ((TextView)this.h.findViewById(R.id.port_number_servo)).setText("4"); - LinearLayout var6 = (LinearLayout)this.findViewById(R.id.linearLayout_servo5); - this.i = this.getLayoutInflater().inflate(R.layout.servo, var6, true); - ((TextView)this.i.findViewById(R.id.port_number_servo)).setText("5"); - LinearLayout var7 = (LinearLayout)this.findViewById(R.id.linearLayout_servo6); - this.j = this.getLayoutInflater().inflate(R.layout.servo, var7, true); - ((TextView)this.j.findViewById(R.id.port_number_servo)).setText("6"); - } - - protected void onStart() { - super.onStart(); - this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - Serializable var1 = this.getIntent().getSerializableExtra("Edit Servo ControllerConfiguration Activity"); - if(var1 != null) { - this.b = (ServoControllerConfiguration)var1; - this.c = (ArrayList)this.b.getServos(); - } - - this.d.setText(this.b.getName()); - TextView var2 = (TextView)this.findViewById(R.id.servo_controller_serialNumber); - String var3 = this.b.getSerialNumber().toString(); - if(var3.equalsIgnoreCase(ControllerConfiguration.NO_SERIAL_NUMBER.toString())) { - var3 = "No serial number"; - } - - var2.setText(var3); - - for(int var4 = 0; var4 < this.c.size(); ++var4) { - this.c(var4 + 1); - this.a(var4 + 1); - this.b(var4 + 1); - } - - } - - public void saveServoController(View var1) { - this.a(); - } - - private class a implements TextWatcher { - private int b; - - private a(View var2) { - this.b = Integer.parseInt(((TextView)var2.findViewById(R.id.port_number_servo)).getText().toString()); - } - - // $FF: synthetic method - a(View var2, Object var3) { - this(); - } - - public void afterTextChanged(Editable var1) { - ((DeviceConfiguration)EditServoControllerActivity.this.c.get(-1 + this.b)).setName(var1.toString()); - } - - public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - - public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { - } - } -} +package com.qualcomm.ftccommon.configuration; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.qualcomm.ftccommon.R; +import com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration; +import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; +import com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration; +import com.qualcomm.robotcore.hardware.configuration.Utility; +import com.qualcomm.robotcore.util.RobotLog; + +import java.io.Serializable; +import java.util.ArrayList; + +public class EditServoControllerActivity extends Activity { + public static final String EDIT_SERVO_ACTIVITY = "Edit Servo ControllerConfiguration Activity"; + private Utility a; + private ServoControllerConfiguration b; + private ArrayList c; + private EditText d; + private View e; + private View f; + private View g; + private View h; + private View i; + private View j; + + private void a() { + Intent var1 = new Intent(); + this.b.addServos(this.c); + this.b.setName(this.d.getText().toString()); + var1.putExtra("Edit Servo ControllerConfiguration Activity", this.b); + this.setResult(-1, var1); + this.finish(); + } + + private void a(int var1) { + View var2 = this.d(var1); + ((EditText)var2.findViewById(R.id.editTextResult_servo)).addTextChangedListener(new a(var2, null)); + } + + private void b(int var1) { + View var2 = this.d(var1); + CheckBox var3 = (CheckBox)var2.findViewById(R.id.checkbox_port_servo); + DeviceConfiguration var4 = this.c.get(var1 - 1); + if(var4.isEnabled()) { + var3.setChecked(true); + ((EditText)var2.findViewById(R.id.editTextResult_servo)).setText(var4.getName()); + } else { + var3.setChecked(true); + var3.performClick(); + } + } + + private void c(int var1) { + View var2 = this.d(var1); + final EditText var3 = (EditText)var2.findViewById(R.id.editTextResult_servo); + final DeviceConfiguration var4 = this.c.get(var1 - 1); + var2.findViewById(R.id.checkbox_port_servo).setOnClickListener(new OnClickListener() { + public void onClick(View var1) { + if (((CheckBox) var1).isChecked()) { + var3.setEnabled(true); + var3.setText(""); + var4.setEnabled(true); + var4.setName(""); + } else { + var3.setEnabled(false); + var4.setEnabled(false); + var4.setName("NO DEVICE ATTACHED"); + var3.setText("NO DEVICE ATTACHED"); + } + } + }); + } + + private View d(int var1) { + switch(var1) { + case 1: + return this.e; + case 2: + return this.f; + case 3: + return this.g; + case 4: + return this.h; + case 5: + return this.i; + case 6: + return this.j; + default: + return null; + } + } + + public void cancelServoController(View var1) { + this.setResult(0, new Intent()); + this.finish(); + } + + protected void onCreate(Bundle var1) { + super.onCreate(var1); + this.setContentView(R.layout.servos); + PreferenceManager.setDefaultValues(this, R.xml.preferences, false); + this.a = new Utility(this); + RobotLog.writeLogcatToDisk(this, 1024); + this.d = (EditText)this.findViewById(R.id.servocontroller_name); + LinearLayout var2 = (LinearLayout)this.findViewById(R.id.linearLayout_servo1); + this.e = this.getLayoutInflater().inflate(R.layout.servo, var2, true); + ((TextView)this.e.findViewById(R.id.port_number_servo)).setText("1"); + LinearLayout var3 = (LinearLayout)this.findViewById(R.id.linearLayout_servo2); + this.f = this.getLayoutInflater().inflate(R.layout.servo, var3, true); + ((TextView)this.f.findViewById(R.id.port_number_servo)).setText("2"); + LinearLayout var4 = (LinearLayout)this.findViewById(R.id.linearLayout_servo3); + this.g = this.getLayoutInflater().inflate(R.layout.servo, var4, true); + ((TextView)this.g.findViewById(R.id.port_number_servo)).setText("3"); + LinearLayout var5 = (LinearLayout)this.findViewById(R.id.linearLayout_servo4); + this.h = this.getLayoutInflater().inflate(R.layout.servo, var5, true); + ((TextView)this.h.findViewById(R.id.port_number_servo)).setText("4"); + LinearLayout var6 = (LinearLayout)this.findViewById(R.id.linearLayout_servo5); + this.i = this.getLayoutInflater().inflate(R.layout.servo, var6, true); + ((TextView)this.i.findViewById(R.id.port_number_servo)).setText("5"); + LinearLayout var7 = (LinearLayout)this.findViewById(R.id.linearLayout_servo6); + this.j = this.getLayoutInflater().inflate(R.layout.servo, var7, true); + ((TextView)this.j.findViewById(R.id.port_number_servo)).setText("6"); + } + + protected void onStart() { + super.onStart(); + this.a.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + Serializable var1 = this.getIntent().getSerializableExtra("Edit Servo ControllerConfiguration Activity"); + if(var1 != null) { + this.b = (ServoControllerConfiguration)var1; + this.c = (ArrayList)this.b.getServos(); + } + + this.d.setText(this.b.getName()); + TextView var2 = (TextView)this.findViewById(R.id.servo_controller_serialNumber); + String var3 = this.b.getSerialNumber().toString(); + if(var3.equalsIgnoreCase(ControllerConfiguration.NO_SERIAL_NUMBER.toString())) { + var3 = "No serial number"; + } + + var2.setText(var3); + + for(int var4 = 0; var4 < this.c.size(); ++var4) { + this.c(var4 + 1); + this.a(var4 + 1); + this.b(var4 + 1); + } + + } + + public void saveServoController(View var1) { + this.a(); + } + + private class a implements TextWatcher { + private int b; + + private a(View var2) { + this.b = Integer.parseInt(((TextView)var2.findViewById(R.id.port_number_servo)).getText().toString()); + } + + // $FF: synthetic method + a(View var2, Object var3) { + this(var2); + } + + public void afterTextChanged(Editable var1) { + EditServoControllerActivity.this.c.get(-1 + this.b).setName(var1.toString()); + } + + public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + + public void onTextChanged(CharSequence var1, int var2, int var3, int var4) { + } + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/FtcConfigurationActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/FtcConfigurationActivity.java similarity index 91% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/FtcConfigurationActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/FtcConfigurationActivity.java index 7aa0a2d..0c2b663 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/FtcConfigurationActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/FtcConfigurationActivity.java @@ -1,434 +1,430 @@ -package com.qualcomm.ftccommon.configuration; - -import android.app.Activity; -import android.app.AlertDialog; -import android.app.AlertDialog.Builder; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.DialogInterface.OnClickListener; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.view.View; -import android.widget.AdapterView; -import android.widget.Button; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.ListView; -import android.widget.TextView; -import android.widget.AdapterView.OnItemClickListener; -import com.qualcomm.ftccommon.DbgLog; -import com.qualcomm.ftccommon.R; -import com.qualcomm.ftccommon.configuration.EditDeviceInterfaceModuleActivity; -import com.qualcomm.ftccommon.configuration.EditLegacyModuleControllerActivity; -import com.qualcomm.ftccommon.configuration.EditMotorControllerActivity; -import com.qualcomm.ftccommon.configuration.EditServoControllerActivity; -import com.qualcomm.hardware.ModernRoboticsDeviceManager; -import com.qualcomm.robotcore.eventloop.EventLoopManager; -import com.qualcomm.robotcore.exception.RobotCoreException; -import com.qualcomm.robotcore.hardware.DeviceManager; -import com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration; -import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; -import com.qualcomm.robotcore.hardware.configuration.DeviceInfoAdapter; -import com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler; -import com.qualcomm.robotcore.hardware.configuration.Utility; -import com.qualcomm.robotcore.util.RobotLog; -import com.qualcomm.robotcore.util.SerialNumber; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.Map.Entry; - -public class FtcConfigurationActivity extends Activity { - OnClickListener a = new OnClickListener() { - public void onClick(DialogInterface var1, int var2) { - } - }; - OnClickListener b = new OnClickListener() { - public void onClick(DialogInterface var1, int var2) { - FtcConfigurationActivity.this.j.saveToPreferences(FtcConfigurationActivity.this.i.substring(7).trim(), R.string.pref_hardware_config_filename); - FtcConfigurationActivity.this.finish(); - } - }; - OnClickListener c = new OnClickListener() { - public void onClick(DialogInterface var1, int var2) { - } - }; - private Thread d; - private Map e = new HashMap(); - private Context f; - private DeviceManager g; - private Button h; - private String i = "No current file!"; - private Utility j; - protected SharedPreferences preferences; - protected Map scannedDevices = new HashMap(); - protected Set> scannedEntries = new HashSet(); - - private void a() { - ((Button)this.findViewById(R.id.devices_holder).findViewById(R.id.info_btn)).setOnClickListener(new android.view.View.OnClickListener() { - public void onClick(View var1) { - Builder var2 = FtcConfigurationActivity.this.j.buildBuilder("Devices", "These are the devices discovered by the Hardware Wizard. You can click on the name of each device to edit the information relating to that device. Make sure each device has a unique name. The names should match what is in the Op mode code. Scroll down to see more devices if there are any."); - var2.setPositiveButton("Ok", FtcConfigurationActivity.this.a); - AlertDialog var4 = var2.create(); - var4.show(); - ((TextView)var4.findViewById(16908299)).setTextSize(14.0F); - } - }); - ((Button)this.findViewById(R.id.save_holder).findViewById(R.id.info_btn)).setOnClickListener(new android.view.View.OnClickListener() { - public void onClick(View var1) { - Builder var2 = FtcConfigurationActivity.this.j.buildBuilder("Save Configuration", "Clicking the save button will create an xml file in: \n /sdcard/FIRST/ \nThis file will be used to initialize the robot."); - var2.setPositiveButton("Ok", FtcConfigurationActivity.this.a); - AlertDialog var4 = var2.create(); - var4.show(); - ((TextView)var4.findViewById(16908299)).setTextSize(14.0F); - } - }); - } - - private void a(String var1) { - String var2 = "Found " + var1; - this.j.setOrangeText(var2, "Please fix and re-save.", R.id.warning_layout, R.layout.orange_warning, R.id.orangetext0, R.id.orangetext1); - } - - private void a(ArrayList var1) { - this.e = new HashMap(); - Iterator var2 = var1.iterator(); - - while(var2.hasNext()) { - ControllerConfiguration var3 = (ControllerConfiguration)var2.next(); - this.e.put(var3.getSerialNumber(), var3); - } - - } - - private HashMap b() { - HashMap var1 = new HashMap(); - Iterator var2 = this.scannedEntries.iterator(); - - while(var2.hasNext()) { - Entry var3 = (Entry)var2.next(); - SerialNumber var4 = (SerialNumber)var3.getKey(); - if(this.e.containsKey(var4)) { - var1.put(var4, this.e.get(var4)); - } else { - switch(null.a[((DeviceManager.DeviceType)var3.getValue()).ordinal()]) { - case 1: - var1.put(var4, this.j.buildMotorController(var4)); - break; - case 2: - var1.put(var4, this.j.buildServoController(var4)); - break; - case 3: - var1.put(var4, this.j.buildLegacyModule(var4)); - break; - case 4: - var1.put(var4, this.j.buildDeviceInterfaceModule(var4)); - } - } - } - - return var1; - } - - private void c() { - if(this.i.toLowerCase().contains("Unsaved".toLowerCase())) { - EditText var1 = new EditText(this.f); - var1.setEnabled(false); - var1.setText(""); - Builder var2 = this.j.buildBuilder("Unsaved changes", "If you scan, your current unsaved changes will be lost."); - var2.setView(var1); - var2.setPositiveButton("Ok", new OnClickListener() { - public void onClick(DialogInterface var1, int var2) { - FtcConfigurationActivity.this.d.start(); - } - }); - var2.setNegativeButton("Cancel", this.c); - var2.show(); - } else { - this.d.start(); - } - } - - private void d() { - ReadXMLFileHandler var1 = new ReadXMLFileHandler(this.f); - if(!this.i.equalsIgnoreCase("No current file!")) { - try { - this.a((ArrayList)var1.parse(new FileInputStream(Utility.CONFIG_FILES_DIR + this.i + ".xml"))); - this.h(); - this.f(); - } catch (RobotCoreException var4) { - RobotLog.e("Error parsing XML file"); - RobotLog.logStacktrace(var4); - this.j.complainToast("Error parsing XML file: " + this.i, this.f); - } catch (FileNotFoundException var5) { - DbgLog.error("File was not found: " + this.i); - DbgLog.logStacktrace(var5); - this.j.complainToast("That file was not found: " + this.i, this.f); - } - } - } - - private void e() { - if(this.e.size() == 0) { - this.j.setOrangeText("Scan to find devices.", "In order to find devices: \n 1. Attach a robot \n 2. Press the \'Scan\' button", R.id.empty_devicelist, R.layout.orange_warning, R.id.orangetext0, R.id.orangetext1); - this.g(); - } else { - LinearLayout var1 = (LinearLayout)this.findViewById(R.id.empty_devicelist); - var1.removeAllViews(); - var1.setVisibility(8); - } - } - - private void f() { - if(this.e.size() == 0) { - this.j.setOrangeText("No devices found!", "In order to find devices: \n 1. Attach a robot \n 2. Press the \'Scan\' button", R.id.empty_devicelist, R.layout.orange_warning, R.id.orangetext0, R.id.orangetext1); - this.g(); - } else { - LinearLayout var1 = (LinearLayout)this.findViewById(R.id.empty_devicelist); - var1.removeAllViews(); - var1.setVisibility(8); - } - } - - private void g() { - LinearLayout var1 = (LinearLayout)this.findViewById(R.id.warning_layout); - var1.removeAllViews(); - var1.setVisibility(8); - } - - private void h() { - ListView var1 = (ListView)this.findViewById(R.id.controllersList); - var1.setAdapter(new DeviceInfoAdapter(this, 17367044, this.e)); - var1.setOnItemClickListener(new OnItemClickListener() { - public void onItemClick(AdapterView var1, View var2, int var3, long var4) { - ControllerConfiguration var6 = (ControllerConfiguration)var1.getItemAtPosition(var3); - DeviceConfiguration.ConfigurationType var7 = var6.getType(); - if(var7.equals(DeviceConfiguration.ConfigurationType.MOTOR_CONTROLLER)) { - Intent var8 = new Intent(FtcConfigurationActivity.this.f, EditMotorControllerActivity.class); - var8.putExtra("EDIT_MOTOR_CONTROLLER_CONFIG", var6); - var8.putExtra("requestCode", 1); - FtcConfigurationActivity.this.setResult(-1, var8); - FtcConfigurationActivity.this.startActivityForResult(var8, 1); - } - - if(var7.equals(DeviceConfiguration.ConfigurationType.SERVO_CONTROLLER)) { - Intent var11 = new Intent(FtcConfigurationActivity.this.f, EditServoControllerActivity.class); - var11.putExtra("Edit Servo ControllerConfiguration Activity", var6); - var11.putExtra("requestCode", 2); - FtcConfigurationActivity.this.setResult(-1, var11); - FtcConfigurationActivity.this.startActivityForResult(var11, 2); - } - - if(var7.equals(DeviceConfiguration.ConfigurationType.LEGACY_MODULE_CONTROLLER)) { - Intent var14 = new Intent(FtcConfigurationActivity.this.f, EditLegacyModuleControllerActivity.class); - var14.putExtra("EDIT_LEGACY_CONFIG", var6); - var14.putExtra("requestCode", 3); - FtcConfigurationActivity.this.setResult(-1, var14); - FtcConfigurationActivity.this.startActivityForResult(var14, 3); - } - - if(var7.equals(DeviceConfiguration.ConfigurationType.DEVICE_INTERFACE_MODULE)) { - Intent var17 = new Intent(FtcConfigurationActivity.this.f, EditDeviceInterfaceModuleActivity.class); - var17.putExtra("EDIT_DEVICE_INTERFACE_MODULE_CONFIG", var6); - var17.putExtra("requestCode", 4); - FtcConfigurationActivity.this.setResult(-1, var17); - FtcConfigurationActivity.this.startActivityForResult(var17, 4); - } - - } - }); - } - - private void i() { - if(!this.i.toLowerCase().contains("Unsaved".toLowerCase())) { - String var1 = "Unsaved " + this.i; - this.j.saveToPreferences(var1, R.string.pref_hardware_config_filename); - this.i = var1; - } - - } - - protected void onActivityResult(int var1, int var2, Intent var3) { - if(var2 != 0) { - Serializable var4; - if(var1 == 1) { - var4 = var3.getSerializableExtra("EDIT_MOTOR_CONTROLLER_CONFIG"); - } else if(var1 == 2) { - var4 = var3.getSerializableExtra("Edit Servo ControllerConfiguration Activity"); - } else if(var1 == 3) { - var4 = var3.getSerializableExtra("EDIT_LEGACY_CONFIG"); - } else { - var4 = null; - if(var1 == 4) { - var4 = var3.getSerializableExtra("EDIT_DEVICE_INTERFACE_MODULE_CONFIG"); - } - } - - if(var4 != null) { - ControllerConfiguration var5 = (ControllerConfiguration)var4; - this.scannedDevices.put(var5.getSerialNumber(), var5.configTypeToDeviceType(var5.getType())); - this.e.put(var5.getSerialNumber(), var5); - this.h(); - this.i(); - } else { - DbgLog.error("Received Result with an incorrect request code: " + String.valueOf(var1)); - } - } - } - - public void onBackPressed() { - if(this.i.toLowerCase().contains("Unsaved".toLowerCase())) { - if(!this.j.writeXML(this.e)) { - final EditText var1 = new EditText(this); - var1.setText(this.j.prepareFilename(this.i)); - Builder var2 = this.j.buildBuilder("Unsaved changes", "Please save your file before exiting the Hardware Wizard! \n If you click \'Cancel\' your changes will be lost."); - var2.setView(var1); - var2.setPositiveButton("Ok", new OnClickListener() { - public void onClick(DialogInterface var1x, int var2) { - String var3 = (var1.getText().toString() + ".xml").trim(); - if(var3.equals(".xml")) { - FtcConfigurationActivity.this.j.complainToast("File not saved: Please entire a filename.", FtcConfigurationActivity.this.f); - } else { - try { - FtcConfigurationActivity.this.j.writeToFile(var3); - } catch (RobotCoreException var6) { - FtcConfigurationActivity.this.j.complainToast(var6.getMessage(), FtcConfigurationActivity.this.f); - DbgLog.error(var6.getMessage()); - return; - } catch (IOException var7) { - FtcConfigurationActivity.this.a(var7.getMessage()); - DbgLog.error(var7.getMessage()); - return; - } - - FtcConfigurationActivity.this.g(); - FtcConfigurationActivity.this.j.saveToPreferences(var1.getText().toString(), R.string.pref_hardware_config_filename); - FtcConfigurationActivity.this.i = var1.getText().toString(); - FtcConfigurationActivity.this.j.updateHeader("robot_config", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - FtcConfigurationActivity.this.j.confirmSave(); - FtcConfigurationActivity.this.finish(); - } - } - }); - var2.setNegativeButton("Cancel", this.b); - var2.show(); - } - } else { - super.onBackPressed(); - } - } - - protected void onCreate(Bundle var1) { - super.onCreate(var1); - this.setContentView(R.layout.activity_ftc_configuration); - RobotLog.writeLogcatToDisk(this, 1024); - this.f = this; - this.j = new Utility(this); - this.h = (Button)this.findViewById(R.id.scanButton); - this.a(); - - try { - this.g = new ModernRoboticsDeviceManager(this.f, (EventLoopManager)null); - } catch (RobotCoreException var3) { - this.j.complainToast("Failed to open the Device Manager", this.f); - DbgLog.error("Failed to open deviceManager: " + var3.toString()); - DbgLog.logStacktrace(var3); - } - - this.preferences = PreferenceManager.getDefaultSharedPreferences(this); - } - - protected void onDestroy() { - super.onDestroy(); - this.j.resetCount(); - } - - protected void onStart() { - super.onStart(); - this.i = this.j.getFilenameFromPrefs(R.string.pref_hardware_config_filename, "No current file!"); - if(this.i.equalsIgnoreCase("No current file!")) { - this.j.createConfigFolder(); - } - - this.j.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - this.e(); - if(!this.i.toLowerCase().contains("Unsaved".toLowerCase())) { - this.d(); - } - - this.h.setOnClickListener(new android.view.View.OnClickListener() { - public void onClick(View var1) { - FtcConfigurationActivity.this.d = new Thread(new Runnable() { - public void run() { - try { - DbgLog.msg("Scanning USB bus"); - FtcConfigurationActivity.this.scannedDevices = FtcConfigurationActivity.this.g.scanForUsbDevices(); - } catch (RobotCoreException var2) { - DbgLog.error("Device scan failed: " + var2.toString()); - } - - FtcConfigurationActivity.this.runOnUiThread(new Runnable() { - public void run() { - FtcConfigurationActivity.this.j.resetCount(); - FtcConfigurationActivity.this.g(); - FtcConfigurationActivity.this.i(); - FtcConfigurationActivity.this.j.updateHeader(FtcConfigurationActivity.this.i, R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - FtcConfigurationActivity.this.scannedEntries = FtcConfigurationActivity.this.scannedDevices.entrySet(); - FtcConfigurationActivity.this.e = FtcConfigurationActivity.this.b(); - FtcConfigurationActivity.this.h(); - FtcConfigurationActivity.this.f(); - } - }); - } - }); - FtcConfigurationActivity.this.c(); - } - }); - } - - public void saveConfiguration(View var1) { - if(!this.j.writeXML(this.e)) { - final EditText var2 = new EditText(this); - var2.setText(this.j.prepareFilename(this.i)); - Builder var3 = this.j.buildBuilder("Enter file name", "Please enter the file name"); - var3.setView(var2); - var3.setPositiveButton("Ok", new OnClickListener() { - public void onClick(DialogInterface var1, int var2x) { - String var3 = (var2.getText().toString() + ".xml").trim(); - if(var3.equals(".xml")) { - FtcConfigurationActivity.this.j.complainToast("File not saved: Please entire a filename.", FtcConfigurationActivity.this.f); - } else { - try { - FtcConfigurationActivity.this.j.writeToFile(var3); - } catch (RobotCoreException var6) { - FtcConfigurationActivity.this.j.complainToast(var6.getMessage(), FtcConfigurationActivity.this.f); - DbgLog.error(var6.getMessage()); - return; - } catch (IOException var7) { - FtcConfigurationActivity.this.a(var7.getMessage()); - DbgLog.error(var7.getMessage()); - return; - } - - FtcConfigurationActivity.this.g(); - FtcConfigurationActivity.this.j.saveToPreferences(var2.getText().toString(), R.string.pref_hardware_config_filename); - FtcConfigurationActivity.this.i = var2.getText().toString(); - FtcConfigurationActivity.this.j.updateHeader("robot_config", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - FtcConfigurationActivity.this.j.confirmSave(); - } - } - }); - var3.setNegativeButton("Cancel", this.c); - var3.show(); - } - } -} +package com.qualcomm.ftccommon.configuration; + +import android.app.Activity; +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; +import android.content.Context; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.view.View; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.Button; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.ListView; +import android.widget.TextView; + +import com.qualcomm.ftccommon.DbgLog; +import com.qualcomm.hardware.ModernRoboticsDeviceManager; +import com.qualcomm.robotcore.exception.RobotCoreException; +import com.qualcomm.robotcore.hardware.DeviceManager; +import com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration; +import com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration; +import com.qualcomm.robotcore.hardware.configuration.DeviceInfoAdapter; +import com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler; +import com.qualcomm.robotcore.hardware.configuration.Utility; +import com.qualcomm.robotcore.util.RobotLog; +import com.qualcomm.robotcore.util.SerialNumber; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +public class FtcConfigurationActivity extends Activity { + protected SharedPreferences preferences; + protected Map scannedDevices = new HashMap(); + protected Set> scannedEntries = new HashSet(); + OnClickListener a = new OnClickListener() { + public void onClick(DialogInterface var1, int var2) { + } + }; + OnClickListener c = new OnClickListener() { + public void onClick(DialogInterface var1, int var2) { + } + }; + private Thread d; + private Map e = new HashMap(); + private Context f; + private DeviceManager g; + private Button h; + private String i = "No current file!"; + private Utility j; + OnClickListener b = new OnClickListener() { + public void onClick(DialogInterface var1, int var2) { + FtcConfigurationActivity.this.j.saveToPreferences(FtcConfigurationActivity.this.i.substring(7).trim(), R.string.pref_hardware_config_filename); + FtcConfigurationActivity.this.finish(); + } + }; + + private void a() { + this.findViewById(R.id.devices_holder).findViewById(R.id.info_btn).setOnClickListener(new View.OnClickListener() { + public void onClick(View var1) { + Builder var2 = FtcConfigurationActivity.this.j.buildBuilder("Devices", "These are the devices discovered by the Hardware Wizard. You can click on the name of each device to edit the information relating to that device. Make sure each device has a unique name. The names should match what is in the Op mode code. Scroll down to see more devices if there are any."); + var2.setPositiveButton("Ok", FtcConfigurationActivity.this.a); + AlertDialog var4 = var2.create(); + var4.show(); + ((TextView) var4.findViewById(R.id.writeXML_text)).setTextSize(14.0F); + } + }); + this.findViewById(R.id.save_holder).findViewById(R.id.info_btn).setOnClickListener(new View.OnClickListener() { + public void onClick(View var1) { + Builder var2 = FtcConfigurationActivity.this.j.buildBuilder("Save Configuration", "Clicking the save button will create an xml file in: \n /sdcard/FIRST/ \nThis file will be used to initialize the robot."); + var2.setPositiveButton("Ok", FtcConfigurationActivity.this.a); + AlertDialog var4 = var2.create(); + var4.show(); + ((TextView) var4.findViewById(R.id.writeXML_text)).setTextSize(14.0F); + } + }); + } + + private void a(String var1) { + String var2 = "Found " + var1; + this.j.setOrangeText(var2, "Please fix and re-save.", R.id.warning_layout, R.layout.orange_warning, R.id.orangetext0, R.id.orangetext1); + } + + private void a(ArrayList var1) { + this.e = new HashMap(); + Iterator var2 = var1.iterator(); + + while(var2.hasNext()) { + ControllerConfiguration var3 = (ControllerConfiguration)var2.next(); + this.e.put(var3.getSerialNumber(), var3); + } + + } + + private HashMap b() { + HashMap var1 = new HashMap(); + Iterator> var2 = this.scannedEntries.iterator(); + + while(var2.hasNext()) { + Entry var3 = var2.next(); + SerialNumber var4 = (SerialNumber)var3.getKey(); + if(this.e.containsKey(var4)) { + var1.put(var4, this.e.get(var4)); + } else { + switch (((DeviceManager.DeviceType) var3.getValue()).ordinal()) { + case 1: + var1.put(var4, this.j.buildMotorController(var4)); + break; + case 2: + var1.put(var4, this.j.buildServoController(var4)); + break; + case 3: + var1.put(var4, this.j.buildLegacyModule(var4)); + break; + case 4: + var1.put(var4, this.j.buildDeviceInterfaceModule(var4)); + } + } + } + + return var1; + } + + private void c() { + if(this.i.toLowerCase().contains("Unsaved".toLowerCase())) { + EditText var1 = new EditText(this.f); + var1.setEnabled(false); + var1.setText(""); + Builder var2 = this.j.buildBuilder("Unsaved changes", "If you scan, your current unsaved changes will be lost."); + var2.setView(var1); + var2.setPositiveButton("Ok", new OnClickListener() { + public void onClick(DialogInterface var1, int var2) { + FtcConfigurationActivity.this.d.start(); + } + }); + var2.setNegativeButton("Cancel", this.c); + var2.show(); + } else { + this.d.start(); + } + } + + private void d() { + ReadXMLFileHandler var1 = new ReadXMLFileHandler(this.f); + if(!this.i.equalsIgnoreCase("No current file!")) { + try { + this.a((ArrayList)var1.parse(new FileInputStream(Utility.CONFIG_FILES_DIR + this.i + ".xml"))); + this.h(); + this.f(); + } catch (RobotCoreException var4) { + RobotLog.e("Error parsing XML file"); + RobotLog.logStacktrace(var4); + this.j.complainToast("Error parsing XML file: " + this.i, this.f); + } catch (FileNotFoundException var5) { + DbgLog.error("File was not found: " + this.i); + DbgLog.logStacktrace(var5); + this.j.complainToast("That file was not found: " + this.i, this.f); + } + } + } + + private void e() { + if(this.e.size() == 0) { + this.j.setOrangeText("Scan to find devices.", "In order to find devices: \n 1. Attach a robot \n 2. Press the \'Scan\' button", R.id.empty_devicelist, R.layout.orange_warning, R.id.orangetext0, R.id.orangetext1); + this.g(); + } else { + LinearLayout var1 = (LinearLayout)this.findViewById(R.id.empty_devicelist); + var1.removeAllViews(); + var1.setVisibility(View.GONE); + } + } + + private void f() { + if(this.e.size() == 0) { + this.j.setOrangeText("No devices found!", "In order to find devices: \n 1. Attach a robot \n 2. Press the \'Scan\' button", R.id.empty_devicelist, R.layout.orange_warning, R.id.orangetext0, R.id.orangetext1); + this.g(); + } else { + LinearLayout var1 = (LinearLayout)this.findViewById(R.id.empty_devicelist); + var1.removeAllViews(); + var1.setVisibility(View.GONE); + } + } + + private void g() { + LinearLayout var1 = (LinearLayout)this.findViewById(R.id.warning_layout); + var1.removeAllViews(); + var1.setVisibility(View.GONE); + } + + private void h() { + ListView var1 = (ListView)this.findViewById(R.id.controllersList); + var1.setAdapter(new DeviceInfoAdapter(this, 17367044, this.e)); + var1.setOnItemClickListener(new OnItemClickListener() { + public void onItemClick(AdapterView var1, View var2, int var3, long var4) { + ControllerConfiguration var6 = (ControllerConfiguration)var1.getItemAtPosition(var3); + DeviceConfiguration.ConfigurationType var7 = var6.getType(); + if(var7.equals(DeviceConfiguration.ConfigurationType.MOTOR_CONTROLLER)) { + Intent var8 = new Intent(FtcConfigurationActivity.this.f, EditMotorControllerActivity.class); + var8.putExtra("EDIT_MOTOR_CONTROLLER_CONFIG", var6); + var8.putExtra("requestCode", 1); + FtcConfigurationActivity.this.setResult(-1, var8); + FtcConfigurationActivity.this.startActivityForResult(var8, 1); + } + + if(var7.equals(DeviceConfiguration.ConfigurationType.SERVO_CONTROLLER)) { + Intent var11 = new Intent(FtcConfigurationActivity.this.f, EditServoControllerActivity.class); + var11.putExtra("Edit Servo ControllerConfiguration Activity", var6); + var11.putExtra("requestCode", 2); + FtcConfigurationActivity.this.setResult(-1, var11); + FtcConfigurationActivity.this.startActivityForResult(var11, 2); + } + + if(var7.equals(DeviceConfiguration.ConfigurationType.LEGACY_MODULE_CONTROLLER)) { + Intent var14 = new Intent(FtcConfigurationActivity.this.f, EditLegacyModuleControllerActivity.class); + var14.putExtra("EDIT_LEGACY_CONFIG", var6); + var14.putExtra("requestCode", 3); + FtcConfigurationActivity.this.setResult(-1, var14); + FtcConfigurationActivity.this.startActivityForResult(var14, 3); + } + + if(var7.equals(DeviceConfiguration.ConfigurationType.DEVICE_INTERFACE_MODULE)) { + Intent var17 = new Intent(FtcConfigurationActivity.this.f, EditDeviceInterfaceModuleActivity.class); + var17.putExtra("EDIT_DEVICE_INTERFACE_MODULE_CONFIG", var6); + var17.putExtra("requestCode", 4); + FtcConfigurationActivity.this.setResult(-1, var17); + FtcConfigurationActivity.this.startActivityForResult(var17, 4); + } + + } + }); + } + + private void i() { + if(!this.i.toLowerCase().contains("Unsaved".toLowerCase())) { + String var1 = "Unsaved " + this.i; + this.j.saveToPreferences(var1, R.string.pref_hardware_config_filename); + this.i = var1; + } + + } + + protected void onActivityResult(int var1, int var2, Intent var3) { + if(var2 != 0) { + Serializable var4; + if(var1 == 1) { + var4 = var3.getSerializableExtra("EDIT_MOTOR_CONTROLLER_CONFIG"); + } else if(var1 == 2) { + var4 = var3.getSerializableExtra("Edit Servo ControllerConfiguration Activity"); + } else if(var1 == 3) { + var4 = var3.getSerializableExtra("EDIT_LEGACY_CONFIG"); + } else { + var4 = null; + if(var1 == 4) { + var4 = var3.getSerializableExtra("EDIT_DEVICE_INTERFACE_MODULE_CONFIG"); + } + } + + if(var4 != null) { + ControllerConfiguration var5 = (ControllerConfiguration)var4; + this.scannedDevices.put(var5.getSerialNumber(), var5.configTypeToDeviceType(var5.getType())); + this.e.put(var5.getSerialNumber(), var5); + this.h(); + this.i(); + } else { + DbgLog.error("Received Result with an incorrect request code: " + String.valueOf(var1)); + } + } + } + + public void onBackPressed() { + if(this.i.toLowerCase().contains("Unsaved".toLowerCase())) { + if(!this.j.writeXML(this.e)) { + final EditText var1 = new EditText(this); + var1.setText(this.j.prepareFilename(this.i)); + Builder var2 = this.j.buildBuilder("Unsaved changes", "Please save your file before exiting the Hardware Wizard! \n If you click \'Cancel\' your changes will be lost."); + var2.setView(var1); + var2.setPositiveButton("Ok", new OnClickListener() { + public void onClick(DialogInterface var1x, int var2) { + String var3 = (var1.getText().toString() + ".xml").trim(); + if(var3.equals(".xml")) { + FtcConfigurationActivity.this.j.complainToast("File not saved: Please entire a filename.", FtcConfigurationActivity.this.f); + } else { + try { + FtcConfigurationActivity.this.j.writeToFile(var3); + } catch (RobotCoreException var6) { + FtcConfigurationActivity.this.j.complainToast(var6.getMessage(), FtcConfigurationActivity.this.f); + DbgLog.error(var6.getMessage()); + return; + } catch (IOException var7) { + FtcConfigurationActivity.this.a(var7.getMessage()); + DbgLog.error(var7.getMessage()); + return; + } + + FtcConfigurationActivity.this.g(); + FtcConfigurationActivity.this.j.saveToPreferences(var1.getText().toString(), R.string.pref_hardware_config_filename); + FtcConfigurationActivity.this.i = var1.getText().toString(); + FtcConfigurationActivity.this.j.updateHeader("robot_config", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + FtcConfigurationActivity.this.j.confirmSave(); + FtcConfigurationActivity.this.finish(); + } + } + }); + var2.setNegativeButton("Cancel", this.b); + var2.show(); + } + } else { + super.onBackPressed(); + } + } + + protected void onCreate(Bundle var1) { + super.onCreate(var1); + this.setContentView(R.layout.activity_ftc_configuration); + RobotLog.writeLogcatToDisk(this, 1024); + this.f = this; + this.j = new Utility(this); + this.h = (Button)this.findViewById(R.id.scanButton); + this.a(); + + try { + this.g = new ModernRoboticsDeviceManager(this.f, null); + } catch (RobotCoreException var3) { + this.j.complainToast("Failed to open the Device Manager", this.f); + DbgLog.error("Failed to open deviceManager: " + var3.toString()); + DbgLog.logStacktrace(var3); + } + + this.preferences = PreferenceManager.getDefaultSharedPreferences(this); + } + + protected void onDestroy() { + super.onDestroy(); + this.j.resetCount(); + } + + protected void onStart() { + super.onStart(); + this.i = this.j.getFilenameFromPrefs(R.string.pref_hardware_config_filename, "No current file!"); + if(this.i.equalsIgnoreCase("No current file!")) { + this.j.createConfigFolder(); + } + + this.j.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + this.e(); + if(!this.i.toLowerCase().contains("Unsaved".toLowerCase())) { + this.d(); + } + + this.h.setOnClickListener(new View.OnClickListener() { + public void onClick(View var1) { + FtcConfigurationActivity.this.d = new Thread(new Runnable() { + public void run() { + try { + DbgLog.msg("Scanning USB bus"); + FtcConfigurationActivity.this.scannedDevices = FtcConfigurationActivity.this.g.scanForUsbDevices(); + } catch (RobotCoreException var2) { + DbgLog.error("Device scan failed: " + var2.toString()); + } + + FtcConfigurationActivity.this.runOnUiThread(new Runnable() { + public void run() { + FtcConfigurationActivity.this.j.resetCount(); + FtcConfigurationActivity.this.g(); + FtcConfigurationActivity.this.i(); + FtcConfigurationActivity.this.j.updateHeader(FtcConfigurationActivity.this.i, R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + FtcConfigurationActivity.this.scannedEntries = FtcConfigurationActivity.this.scannedDevices.entrySet(); + FtcConfigurationActivity.this.e = FtcConfigurationActivity.this.b(); + FtcConfigurationActivity.this.h(); + FtcConfigurationActivity.this.f(); + } + }); + } + }); + FtcConfigurationActivity.this.c(); + } + }); + } + + public void saveConfiguration(View var1) { + if(!this.j.writeXML(this.e)) { + final EditText var2 = new EditText(this); + var2.setText(this.j.prepareFilename(this.i)); + Builder var3 = this.j.buildBuilder("Enter file name", "Please enter the file name"); + var3.setView(var2); + var3.setPositiveButton("Ok", new OnClickListener() { + public void onClick(DialogInterface var1, int var2x) { + String var3 = (var2.getText().toString() + ".xml").trim(); + if(var3.equals(".xml")) { + FtcConfigurationActivity.this.j.complainToast("File not saved: Please entire a filename.", FtcConfigurationActivity.this.f); + } else { + try { + FtcConfigurationActivity.this.j.writeToFile(var3); + } catch (RobotCoreException var6) { + FtcConfigurationActivity.this.j.complainToast(var6.getMessage(), FtcConfigurationActivity.this.f); + DbgLog.error(var6.getMessage()); + return; + } catch (IOException var7) { + FtcConfigurationActivity.this.a(var7.getMessage()); + DbgLog.error(var7.getMessage()); + return; + } + + FtcConfigurationActivity.this.g(); + FtcConfigurationActivity.this.j.saveToPreferences(var2.getText().toString(), R.string.pref_hardware_config_filename); + FtcConfigurationActivity.this.i = var2.getText().toString(); + FtcConfigurationActivity.this.j.updateHeader("robot_config", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + FtcConfigurationActivity.this.j.confirmSave(); + } + } + }); + var3.setNegativeButton("Cancel", this.c); + var3.show(); + } + } +} diff --git a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/FtcLoadFileActivity.java b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/FtcLoadFileActivity.java similarity index 92% rename from FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/FtcLoadFileActivity.java rename to FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/FtcLoadFileActivity.java index e855688..c381f2d 100644 --- a/FtcRobotController/app/src/main/java/com/qualcomm/ftccommon/configuration/FtcLoadFileActivity.java +++ b/FtcRobotController/FtcCommon/src/main/java/com/qualcomm/ftccommon/configuration/FtcLoadFileActivity.java @@ -1,151 +1,151 @@ -package com.qualcomm.ftccommon.configuration; - -import android.app.Activity; -import android.app.AlertDialog; -import android.app.AlertDialog.Builder; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.DialogInterface.OnClickListener; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.TextView; -import com.qualcomm.ftccommon.DbgLog; -import com.qualcomm.ftccommon.R; -import com.qualcomm.ftccommon.configuration.AutoConfigureActivity; -import com.qualcomm.ftccommon.configuration.FtcConfigurationActivity; -import com.qualcomm.robotcore.hardware.configuration.Utility; -import java.io.File; -import java.util.ArrayList; -import java.util.Iterator; - -public class FtcLoadFileActivity extends Activity { - public static final String CONFIGURE_FILENAME = "CONFIGURE_FILENAME"; - OnClickListener a = new OnClickListener() { - public void onClick(DialogInterface var1, int var2) { - } - }; - private ArrayList b = new ArrayList(); - private Context c; - private Utility d; - - private String a(View var1, boolean var2) { - String var3 = ((TextView)((LinearLayout)((LinearLayout)var1.getParent()).getParent()).findViewById(R.id.filename_editText)).getText().toString(); - if(var2) { - var3 = var3 + ".xml"; - } - - return var3; - } - - private void a() { - ((Button)this.findViewById(R.id.files_holder).findViewById(R.id.info_btn)).setOnClickListener(new android.view.View.OnClickListener() { - public void onClick(View var1) { - Builder var2 = FtcLoadFileActivity.this.d.buildBuilder("Available files", "These are the files the Hardware Wizard was able to find. You can edit each file by clicking the edit button. The \'Activate\' button will set that file as the current configuration file, which will be used to start the robot."); - var2.setPositiveButton("Ok", FtcLoadFileActivity.this.a); - AlertDialog var4 = var2.create(); - var4.show(); - ((TextView)var4.findViewById(16908299)).setTextSize(14.0F); - } - }); - ((Button)this.findViewById(R.id.autoconfigure_holder).findViewById(R.id.info_btn)).setOnClickListener(new android.view.View.OnClickListener() { - public void onClick(View var1) { - Builder var2 = FtcLoadFileActivity.this.d.buildBuilder("AutoConfigure", "This is the fastest way to get a new machine up and running. The AutoConfigure tool will automatically enter some default names for devices. AutoConfigure expects certain devices. If there are other devices attached, the AutoConfigure tool will not name them."); - var2.setPositiveButton("Ok", FtcLoadFileActivity.this.a); - AlertDialog var4 = var2.create(); - var4.show(); - ((TextView)var4.findViewById(16908299)).setTextSize(14.0F); - } - }); - } - - private void b() { - if(this.b.size() == 0) { - this.d.setOrangeText("No files found!", "In order to proceed, you must create a new file", R.id.empty_filelist, R.layout.orange_warning, R.id.orangetext0, R.id.orangetext1); - } else { - ViewGroup var1 = (ViewGroup)this.findViewById(R.id.empty_filelist); - var1.removeAllViews(); - var1.setVisibility(8); - } - } - - private void c() { - ViewGroup var1 = (ViewGroup)this.findViewById(R.id.inclusionlayout); - var1.removeAllViews(); - Iterator var2 = this.b.iterator(); - - while(var2.hasNext()) { - String var3 = (String)var2.next(); - View var4 = LayoutInflater.from(this).inflate(R.layout.file_info, (ViewGroup)null); - var1.addView(var4); - ((TextView)var4.findViewById(R.id.filename_editText)).setText(var3); - } - - } - - public void file_activate_button(View var1) { - String var2 = this.a(var1, false); - this.d.saveToPreferences(var2, R.string.pref_hardware_config_filename); - this.d.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - } - - public void file_delete_button(View var1) { - String var2 = this.a(var1, true); - File var3 = new File(Utility.CONFIG_FILES_DIR + var2); - if(var3.exists()) { - var3.delete(); - } else { - this.d.complainToast("That file does not exist: " + var2, this.c); - DbgLog.error("Tried to delete a file that does not exist: " + var2); - } - - this.b = this.d.getXMLFiles(); - this.d.saveToPreferences("No current file!", R.string.pref_hardware_config_filename); - this.d.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - this.c(); - } - - public void file_edit_button(View var1) { - String var2 = this.a(var1, true); - this.d.saveToPreferences(var2, R.string.pref_hardware_config_filename); - this.startActivity(new Intent(this.c, FtcConfigurationActivity.class)); - } - - public void launch_autoConfigure(View var1) { - this.startActivity(new Intent(this.getBaseContext(), AutoConfigureActivity.class)); - } - - public void new_button(View var1) { - this.d.saveToPreferences("No current file!", R.string.pref_hardware_config_filename); - this.startActivity(new Intent(this.c, FtcConfigurationActivity.class)); - } - - public void onBackPressed() { - String var1 = this.d.getFilenameFromPrefs(R.string.pref_hardware_config_filename, "No current file!"); - Intent var2 = new Intent(); - var2.putExtra("CONFIGURE_FILENAME", var1); - this.setResult(-1, var2); - this.finish(); - } - - protected void onCreate(Bundle var1) { - super.onCreate(var1); - this.setContentView(R.layout.activity_load); - this.c = this; - this.d = new Utility(this); - this.d.createConfigFolder(); - this.a(); - } - - protected void onStart() { - super.onStart(); - this.b = this.d.getXMLFiles(); - this.b(); - this.d.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); - this.c(); - } -} +package com.qualcomm.ftccommon.configuration; + +import android.app.Activity; +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; +import android.content.Context; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.qualcomm.ftccommon.DbgLog; +import com.qualcomm.ftccommon.R; +import com.qualcomm.robotcore.hardware.configuration.Utility; + +import java.io.File; +import java.util.ArrayList; +import java.util.Iterator; + +public class FtcLoadFileActivity extends Activity { + public static final String CONFIGURE_FILENAME = "CONFIGURE_FILENAME"; + OnClickListener a = new OnClickListener() { + public void onClick(DialogInterface var1, int var2) { + } + }; + private ArrayList b = new ArrayList(); + private Context c; + private Utility d; + + private String a(View var1, boolean var2) { + String var3 = ((TextView)((LinearLayout)((LinearLayout)var1.getParent()).getParent()).findViewById(R.id.filename_editText)).getText().toString(); + if(var2) { + var3 = var3 + ".xml"; + } + + return var3; + } + + private void a() { + ((Button)this.findViewById(R.id.files_holder).findViewById(R.id.info_btn)).setOnClickListener(new View.OnClickListener() { + public void onClick(View var1) { + Builder var2 = FtcLoadFileActivity.this.d.buildBuilder("Available files", "These are the files the Hardware Wizard was able to find. You can edit each file by clicking the edit button. The \'Activate\' button will set that file as the current configuration file, which will be used to start the robot."); + var2.setPositiveButton("Ok", FtcLoadFileActivity.this.a); + AlertDialog var4 = var2.create(); + var4.show(); + ((TextView)var4.findViewById(16908299)).setTextSize(14.0F); + } + }); + ((Button)this.findViewById(R.id.autoconfigure_holder).findViewById(R.id.info_btn)).setOnClickListener(new View.OnClickListener() { + public void onClick(View var1) { + Builder var2 = FtcLoadFileActivity.this.d.buildBuilder("AutoConfigure", "This is the fastest way to get a new machine up and running. The AutoConfigure tool will automatically enter some default names for devices. AutoConfigure expects certain devices. If there are other devices attached, the AutoConfigure tool will not name them."); + var2.setPositiveButton("Ok", FtcLoadFileActivity.this.a); + AlertDialog var4 = var2.create(); + var4.show(); + ((TextView)var4.findViewById(16908299)).setTextSize(14.0F); + } + }); + } + + private void b() { + if(this.b.size() == 0) { + this.d.setOrangeText("No files found!", "In order to proceed, you must create a new file", R.id.empty_filelist, R.layout.orange_warning, R.id.orangetext0, R.id.orangetext1); + } else { + ViewGroup var1 = (ViewGroup)this.findViewById(R.id.empty_filelist); + var1.removeAllViews(); + var1.setVisibility(8); + } + } + + private void c() { + ViewGroup var1 = (ViewGroup)this.findViewById(R.id.inclusionlayout); + var1.removeAllViews(); + Iterator var2 = this.b.iterator(); + + while(var2.hasNext()) { + String var3 = (String)var2.next(); + View var4 = LayoutInflater.from(this).inflate(R.layout.file_info, (ViewGroup)null); + var1.addView(var4); + ((TextView)var4.findViewById(R.id.filename_editText)).setText(var3); + } + + } + + public void file_activate_button(View var1) { + String var2 = this.a(var1, false); + this.d.saveToPreferences(var2, R.string.pref_hardware_config_filename); + this.d.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + } + + public void file_delete_button(View var1) { + String var2 = this.a(var1, true); + File var3 = new File(Utility.CONFIG_FILES_DIR + var2); + if(var3.exists()) { + var3.delete(); + } else { + this.d.complainToast("That file does not exist: " + var2, this.c); + DbgLog.error("Tried to delete a file that does not exist: " + var2); + } + + this.b = this.d.getXMLFiles(); + this.d.saveToPreferences("No current file!", R.string.pref_hardware_config_filename); + this.d.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + this.c(); + } + + public void file_edit_button(View var1) { + String var2 = this.a(var1, true); + this.d.saveToPreferences(var2, R.string.pref_hardware_config_filename); + this.startActivity(new Intent(this.c, FtcConfigurationActivity.class)); + } + + public void launch_autoConfigure(View var1) { + this.startActivity(new Intent(this.getBaseContext(), AutoConfigureActivity.class)); + } + + public void new_button(View var1) { + this.d.saveToPreferences("No current file!", R.string.pref_hardware_config_filename); + this.startActivity(new Intent(this.c, FtcConfigurationActivity.class)); + } + + public void onBackPressed() { + String var1 = this.d.getFilenameFromPrefs(R.string.pref_hardware_config_filename, "No current file!"); + Intent var2 = new Intent(); + var2.putExtra("CONFIGURE_FILENAME", var1); + this.setResult(-1, var2); + this.finish(); + } + + protected void onCreate(Bundle var1) { + super.onCreate(var1); + this.setContentView(R.layout.activity_load); + this.c = this; + this.d = new Utility(this); + this.d.createConfigFolder(); + this.a(); + } + + protected void onStart() { + super.onStart(); + this.b = this.d.getXMLFiles(); + this.b(); + this.d.updateHeader("No current file!", R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); + this.c(); + } +} diff --git a/FtcRobotController/FtcCommon/src/main/res/drawable/lib_button_shape.xml b/FtcRobotController/FtcCommon/src/main/res/drawable/lib_button_shape.xml new file mode 100644 index 0000000..0e2568b --- /dev/null +++ b/FtcRobotController/FtcCommon/src/main/res/drawable/lib_button_shape.xml @@ -0,0 +1,19 @@ + + + + + + + + \ No newline at end of file diff --git a/FtcRobotController/FtcCommon/src/main/res/layout/about.xml b/FtcRobotController/FtcCommon/src/main/res/layout/about.xml new file mode 100644 index 0000000..18bc2d1 --- /dev/null +++ b/FtcRobotController/FtcCommon/src/main/res/layout/about.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/FtcRobotController/FtcCommon/src/main/res/layout/activity_autoconfigure.xml b/FtcRobotController/FtcCommon/src/main/res/layout/activity_autoconfigure.xml new file mode 100644 index 0000000..a7218dc --- /dev/null +++ b/FtcRobotController/FtcCommon/src/main/res/layout/activity_autoconfigure.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + +