diff --git a/.idea/misc.xml b/.idea/misc.xml index 71f92fa..5d19981 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 6a450d5..26ceac0 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -19,11 +19,10 @@ android:label="@string/app_name" android:theme="@android:style/Theme.Holo.Light" > - diff --git a/USB-Device-Info---Android.iml b/USB-Device-Info---Android.iml index d50f2d5..4478965 100644 --- a/USB-Device-Info---Android.iml +++ b/USB-Device-Info---Android.iml @@ -8,7 +8,7 @@ - + diff --git a/_media/icons/feature.png b/_media/icons/feature.png new file mode 100644 index 0000000..b3dc054 Binary files /dev/null and b/_media/icons/feature.png differ diff --git a/_media/icons/icon.svg b/_media/icons/ic_launcher.svg similarity index 100% rename from _media/icons/icon.svg rename to _media/icons/ic_launcher.svg diff --git a/_media/icons/icon_hires.png b/_media/icons/icon_hires.png deleted file mode 100644 index cedbd66..0000000 Binary files a/_media/icons/icon_hires.png and /dev/null differ diff --git a/_media/icons/web_icon.png b/_media/icons/web_icon.png new file mode 100644 index 0000000..db4549f Binary files /dev/null and b/_media/icons/web_icon.png differ diff --git a/_media/screenshots/tablet_1.png b/_media/screenshots/tablet_1.png new file mode 100644 index 0000000..5851e82 Binary files /dev/null and b/_media/screenshots/tablet_1.png differ diff --git a/_media/screenshots/tablet_2.png b/_media/screenshots/tablet_2.png new file mode 100644 index 0000000..293b73a Binary files /dev/null and b/_media/screenshots/tablet_2.png differ diff --git a/app/app.iml b/app/app.iml index 0ca969e..6d6de70 100644 --- a/app/app.iml +++ b/app/app.iml @@ -23,17 +23,19 @@ - + + + @@ -82,23 +84,59 @@ + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 298d380..8e9a879 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,22 +1,48 @@ apply plugin: 'com.android.application' +apply plugin: 'android-apt' +final int versionMajor = 1 +final int versionMinor = 0 +final int versionPatch = 0 +final int androidVersionCode = 6 + + +final int targetSdk = rootProject.targetSdkVersion; +final int minSdkRed = rootProject.minSdkVersion; + +final String semanticVersion = "${versionMajor}.${versionMinor}.${versionPatch}" android { - compileSdkVersion 14 - buildToolsVersion "24.0.1" + compileSdkVersion rootProject.compileSdkVersion + buildToolsVersion rootProject.buildToolsVersion defaultConfig { applicationId "aws.apps.usbDeviceEnumerator" - minSdkVersion 12 - targetSdkVersion 14 - versionCode 5 - versionName "0.0.5" + minSdkVersion minSdkRed + targetSdkVersion targetSdk + versionCode androidVersionCode + versionName semanticVersion + + buildConfigField "String", "USB_DB_URL", quoteString("http://aschillings.co.uk/download/db/android_usb.db3") + buildConfigField "String", "USB_DB_FILE_NAME", quoteString("usb.db3") + + buildConfigField "String", "COMPANY_DB_URL", quoteString("http://aschillings.co.uk/download/db/android_company.db3") + buildConfigField "String", "COMPANY_DB_FILE_NAME", quoteString("company.db3") + + buildConfigField "String", "LOGO_ZIP_URL", quoteString("http://aschillings.co.uk/download/db/company_logos.zip") + buildConfigField "String", "LOGO_ZIP_FILE_NAME", quoteString("logos.zip") } dependencies { + + apt 'com.jakewharton:butterknife-compiler:8.4.0' + compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':usbdeviceenumerator') + compile 'com.jakewharton:butterknife:8.4.0' + compile 'com.android.support:appcompat-v7:24.2.0' + compile 'com.android.support:design:24.2.0' testCompile 'junit:junit:4.12' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0284cea..c3a3235 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,27 +1,23 @@ - - + package="aws.apps.usbDeviceEnumerator"> - + + android:theme="@style/AppTheme"> diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/activities/MainActivity.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/activities/MainActivity.java deleted file mode 100644 index 79ff319..0000000 --- a/app/src/main/java/aws/apps/usbDeviceEnumerator/activities/MainActivity.java +++ /dev/null @@ -1,514 +0,0 @@ -/******************************************************************************* - * Copyright 2011 Alexandros Schillings - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ -package aws.apps.usbDeviceEnumerator.activities; - -import android.app.Activity; -import android.app.AlertDialog; -import android.app.DialogFragment; -import android.app.Fragment; -import android.app.FragmentTransaction; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.hardware.usb.UsbDevice; -import android.hardware.usb.UsbManager; -import android.os.AsyncTask; -import android.os.Bundle; -import android.os.Environment; -import android.util.Log; -import android.util.Pair; -import android.view.Gravity; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemClickListener; -import android.widget.ArrayAdapter; -import android.widget.LinearLayout.LayoutParams; -import android.widget.ListView; -import android.widget.TabHost; -import android.widget.TabHost.OnTabChangeListener; -import android.widget.TabHost.TabSpec; -import android.widget.TabWidget; -import android.widget.TextView; -import android.widget.Toast; - -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URL; -import java.net.URLConnection; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; - -import aws.apps.usbDeviceEnumerator.R; -import aws.apps.usbDeviceEnumerator.data.DbAccessCompany; -import aws.apps.usbDeviceEnumerator.data.DbAccessUsb; -import aws.apps.usbDeviceEnumerator.data.ZipAccessCompany; -import aws.apps.usbDeviceEnumerator.fragments.AbstractUsbDeviceInfoFragment; -import aws.apps.usbDeviceEnumerator.fragments.ProgressDialogFragment; -import aws.apps.usbDeviceEnumerator.fragments.UsbDeviceInfoAndroidFragment; -import aws.apps.usbDeviceEnumerator.fragments.UsbDeviceInfoLinuxFragment; -import aws.apps.usbDeviceEnumerator.usb.sysbususb.SysBusUsbDevice; -import aws.apps.usbDeviceEnumerator.usb.sysbususb.SysBusUsbManager; -import aws.apps.usbDeviceEnumerator.util.UsefulBits; - -public class MainActivity extends Activity implements OnTabChangeListener { - private final static String TAB_ANDROID_INFO = "Android"; - private final static String TAB_LINUX_INFO = "Linux"; - final String TAG = this.getClass().getName(); - private final String DIALOG_FRAGMENT_TAG = "progress_dialog"; - private UsefulBits mUsefulBits; - - private ListView mListUsbAndroid; - private TextView mTvDeviceCountAndroid; - - private ListView mListUsbLinux; - private TextView mTvDeviceCountLinux; - - private UsbManager mUsbManAndroid; - private SysBusUsbManager mUsbManagerLinux; - - private DbAccessUsb mDbUsb; - private DbAccessCompany mDbComp; - private ZipAccessCompany mZipComp; - - private TabHost mTabHost; - private TabWidget mTabWidget; - private HashMap mAndroidUsbDeviceList; - private HashMap mLinuxUsbDeviceList; - - private boolean mIsSmallScreen = true; - - private void dialogFragmentDismiss(String tag) { - Log.d(TAG, "^ Dimissing Fragment : " + tag); - - DialogFragment dialog = (DialogFragment) getFragmentManager().findFragmentByTag(tag); - if (dialog != null) { - if (DIALOG_FRAGMENT_TAG.equals(tag)) { - Log.d(TAG, "^ Dimissing Fragment!"); - ((ProgressDialogFragment) dialog).dismissAllowingStateLoss(); - } else { - dialog.dismiss(); - } - } - } - - private void dialogFragmentShow(String tag) { - FragmentTransaction ft = getFragmentManager().beginTransaction(); - Fragment prev = getFragmentManager().findFragmentByTag(tag); - if (prev != null) { - ft.remove(prev); - } - ft.addToBackStack(null); - - DialogFragment newFragment = null; - if (DIALOG_FRAGMENT_TAG.equals(tag)) { - newFragment = ProgressDialogFragment.newInstance(getString(R.string.text_downloading_files), null); - } - ft.add(newFragment, tag); - ft.commitAllowingStateLoss(); - } - - private void dialogFragmentUpdate(String tag, String title, Integer progress) { - DialogFragment dialogFragment = (DialogFragment) getFragmentManager().findFragmentByTag(tag); - if (dialogFragment != null) { - if (title != null) { - ((ProgressDialogFragment) dialogFragment).setTitle(title); - } - if (progress != null) { - ((ProgressDialogFragment) dialogFragment).setProgress(progress); - } - } - } - - private void displayAndroidUsbDeviceInfo(String device) { - if (mIsSmallScreen) { - Intent i = new Intent(getApplicationContext(), UsbInfoActivity.class); - i.putExtra(UsbInfoActivity.EXTRA_TYPE, AbstractUsbDeviceInfoFragment.TYPE_ANDROID_INFO); - i.putExtra(UsbInfoActivity.EXTRA_DATA_ANDROID, device); - startActivity(i); - } else { - stackAFragment(device); - } - } - - private void displayLinuxUsbDeviceInfo(SysBusUsbDevice device) { - if (mIsSmallScreen) { - Intent i = new Intent(getApplicationContext(), UsbInfoActivity.class); - i.putExtra(UsbInfoActivity.EXTRA_TYPE, AbstractUsbDeviceInfoFragment.TYPE_LINUX_INFO); - i.putExtra(UsbInfoActivity.EXTRA_DATA_LINUX, device); - startActivity(i); - } else { - stackAFragment(device); - } - } - - private View getListViewEmptyView(String text) { - TextView emptyView = new TextView(getApplicationContext()); - emptyView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); - emptyView.setText(text); - emptyView.setTextSize(20f); - emptyView.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL); - return emptyView; - } - - private void initialiseDbComponents() { - // Prompt user to DL db if it is missing. - if (!new File(mDbUsb.getLocalDbFullPath()).exists()) { - mUsefulBits.ShowAlert(getString(R.string.alert_db_not_found_title), - getString(R.string.alert_db_not_found_instructions), - getString(android.R.string.ok)); - Log.w(TAG, "^ Database not found: " + mDbUsb.getLocalDbFullPath()); - return; - } - } - - private boolean isSmallScreen() { - Boolean res; - if (findViewById(R.id.fragment_container) == null) { - res = true; - } else { - res = false; - } - Log.d(TAG, "^ Is this device a small screen? " + res); - return res; - } - - private TabSpec newTab(String tag, int labelId, int tabContentId) { - TabSpec tabSpec = mTabHost.newTabSpec(tag); - tabSpec.setIndicator(tag); - tabSpec.setContent(tabContentId); - return tabSpec; - } - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.act_main); - mIsSmallScreen = isSmallScreen(); - mUsefulBits = new UsefulBits(this); - - mUsbManAndroid = (UsbManager) getSystemService(Context.USB_SERVICE); - mUsbManagerLinux = new SysBusUsbManager(); - mTvDeviceCountAndroid = (TextView) findViewById(R.id.lbl_devices_api); - mTvDeviceCountLinux = (TextView) findViewById(R.id.lbl_devices_linux); - - mTabHost = (TabHost) findViewById(android.R.id.tabhost); - - mDbUsb = new DbAccessUsb(this); - mDbComp = new DbAccessCompany(this); - mZipComp = new ZipAccessCompany(this); - - mListUsbAndroid = (ListView) findViewById(R.id.usb_list_api); - mListUsbAndroid.setChoiceMode(ListView.CHOICE_MODE_SINGLE); - mListUsbAndroid.setOnItemClickListener(new OnItemClickListener() { - - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - mListUsbAndroid.setItemChecked(position, true); - displayAndroidUsbDeviceInfo(((TextView) view).getText().toString()); - } - }); - View emptyView = getListViewEmptyView(getString(R.string.label_empty_list)); - ((ViewGroup) mListUsbAndroid.getParent()).addView(emptyView); - mListUsbAndroid.setEmptyView(emptyView); - /// - mListUsbLinux = (ListView) findViewById(R.id.usb_list_linux); - mListUsbLinux.setChoiceMode(ListView.CHOICE_MODE_SINGLE); - mListUsbLinux.setOnItemClickListener(new OnItemClickListener() { - - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - mListUsbLinux.setItemChecked(position, true); - displayLinuxUsbDeviceInfo(mLinuxUsbDeviceList.get(((TextView) view).getText().toString())); - } - }); - - emptyView = getListViewEmptyView(getString(R.string.label_empty_list)); - ((ViewGroup) mListUsbLinux.getParent()).addView(emptyView); - mListUsbLinux.setEmptyView(emptyView); - - setupTabs(); - - initialiseDbComponents(); - refreshUsbDevices(); - } - - /** Creates the menu items */ - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.main_menu, menu); - return true; - } - - /** Handles item selections */ - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_about: - mUsefulBits.showAboutDialogue(); - return true; - case R.id.menu_update_db: - if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { - Log.d(TAG, "^ SD card not available."); - mUsefulBits.showToast(getString(R.string.sd_not_available), Toast.LENGTH_SHORT, Gravity.TOP, 0, 0); - return true; - } - - if (!mUsefulBits.createDirectories(mDbUsb.getLocalDbLocation())) { - return true; - } - if (!mUsefulBits.createDirectories(mDbComp.getLocalDbLocation())) { - return true; - } - if (!mUsefulBits.createDirectories(mZipComp.getLocalZipLocation())) { - return true; - } - - if (!mUsefulBits.isOnline()) { // If we are not online, cancel everything - mUsefulBits.ShowAlert( - getString(R.string.text_device_offline), - getString(R.string.text_device_offline_instructions), - getString(android.R.string.ok)); - return true; - } - - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setMessage(getString(R.string.alert_update_db)) - .setPositiveButton(getString(android.R.string.yes), new DialogInterface.OnClickListener() { - @SuppressWarnings("unchecked") - @Override - public void onClick(DialogInterface dialog, int which) { - ArrayList> downloads = new ArrayList>(); - - downloads.add(new Pair( - getString(R.string.url_usb_db), - mDbUsb.getLocalDbFullPath())); - - downloads.add(new Pair( - getString(R.string.url_company_db), - mDbComp.getLocalDbFullPath())); - - downloads.add(new Pair( - getString(R.string.url_company_logo_zip), - mZipComp.getLocalZipFullPath())); - - new DownloadFile().execute(downloads); - } - - }) - .setNegativeButton(getString(android.R.string.no), null).show(); - return true; - case R.id.menu_refresh: - refreshUsbDevices(); - return true; - } - - return false; - } - - @Override - public void onTabChanged(String tabId) { - if (mIsSmallScreen) { - return; - } - int position = -1; - - if (tabId.equals(TAB_ANDROID_INFO)) { - position = mListUsbAndroid.getCheckedItemPosition(); - if (position != ListView.INVALID_POSITION) { - String text = (String) mListUsbAndroid.getItemAtPosition(position); - stackAFragment(text); - } else { - stackAFragment(new String()); - } - } else if (tabId.equals(TAB_LINUX_INFO)) { - position = mListUsbLinux.getCheckedItemPosition(); - if (position != ListView.INVALID_POSITION) { - String text = (String) mListUsbLinux.getItemAtPosition(position); - stackAFragment(mLinuxUsbDeviceList.get(text)); - } else { - stackAFragment(new String()); - } - - } - } - - - private void refreshUsbDevices() { - - // Getting devices from API - { - mAndroidUsbDeviceList = mUsbManAndroid.getDeviceList(); - String[] array = mAndroidUsbDeviceList.keySet().toArray(new String[mAndroidUsbDeviceList.keySet().size()]); - - Arrays.sort(array); - - ArrayAdapter adaptor = new ArrayAdapter(getApplicationContext(), R.layout.list_item, array); - mListUsbAndroid.setAdapter(adaptor); - mTvDeviceCountAndroid.setText("Device List (" + mAndroidUsbDeviceList.size() + "):"); - } - - // Getting devices from Linux subsystem - { - mLinuxUsbDeviceList = mUsbManagerLinux.getUsbDevices(); - String[] array = mLinuxUsbDeviceList.keySet().toArray(new String[mLinuxUsbDeviceList.keySet().size()]); - - Arrays.sort(array); - - ArrayAdapter adaptor = new ArrayAdapter(getApplicationContext(), R.layout.list_item, array); - mListUsbLinux.setAdapter(adaptor); - mTvDeviceCountLinux.setText("Device List (" + mLinuxUsbDeviceList.size() + "):"); - } - } - - private void setupTabs() { - mTabHost.setup(); // you must call this before adding your tabs! - - mTabHost.addTab(newTab(TAB_ANDROID_INFO, R.string.label_tab_api, R.id.tab_1)); - mTabHost.addTab(newTab(TAB_LINUX_INFO, R.string.label_tab_linux, R.id.tab_2)); - - mTabWidget = mTabHost.getTabWidget(); - - for (int i = 0; i < mTabWidget.getChildCount(); i++) { - final TextView tv = (TextView) mTabWidget.getChildAt(i).findViewById(android.R.id.title); - tv.setTextColor(this.getResources().getColorStateList(R.drawable.tab_text_selector)); - } - - mTabHost.setOnTabChangedListener(this); - } - - private void stackAFragment(String usbKey) { - Fragment f = new UsbDeviceInfoAndroidFragment(usbKey); - - FragmentTransaction ft = getFragmentManager().beginTransaction(); - ft.replace(R.id.fragment_container, f); - ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); - - ft.commit(); - } - - private void stackAFragment(SysBusUsbDevice usbDevice) { - Fragment f = new UsbDeviceInfoLinuxFragment(usbDevice); - - FragmentTransaction ft = getFragmentManager().beginTransaction(); - ft.replace(R.id.fragment_container, f); - ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); - - ft.commit(); - } - - private class DownloadFile extends AsyncTask>, Integer, Boolean> { - // This is the message which will be shown on the progress bar - MessageFormat form = new MessageFormat("Downloading file: {0} of {1}..."); - - @Override - protected Boolean doInBackground(ArrayList>... downloadLists) { - int count; - - URL url; - String filePath = ""; - URLConnection conection; - InputStream is; - OutputStream os; - Boolean bOK = true; - - - ArrayList> downloads = downloadLists[0]; - - int downloadCounter = 0; - - for (Pair download : downloads) { - try { - url = new URL(download.first); - filePath = download.second; - - Log.d(TAG, "^ Downloading: " + url); - Log.d(TAG, "^ To : " + filePath); - - conection = url.openConnection(); - conection.connect(); - int lenghtOfFile = conection.getContentLength(); - - // download the file - is = new BufferedInputStream(url.openStream()); - os = new FileOutputStream(filePath); - - byte data[] = new byte[1024]; - - long total = 0; - - while ((count = is.read(data)) != -1) { - total += count; - // The first number is the current file - // The second is the total number of files to download - // The third is the current progress - publishProgress(downloadCounter + 1, downloads.size(), (int) (total * 100 / lenghtOfFile)); - os.write(data, 0, count); - } - - os.flush(); - os.close(); - is.close(); - - } catch (Exception e) { - Log.e(TAG, "^ Error while downloading.", e); - bOK = false; - e.printStackTrace(); - } - - downloadCounter += 1; - } - - -// String[][] pair = list[0]; -// for(int i = 0; i < list[0].length; i++){ -// -// } - return bOK; - } - - @Override - protected void onPostExecute(Boolean result) { - - if (result) { // The download is ok. - Toast.makeText(MainActivity.this, getString(R.string.download_ok), Toast.LENGTH_SHORT).show(); - } else { // There was an error. - Toast.makeText(MainActivity.this, getString(R.string.download_error), Toast.LENGTH_SHORT).show(); - } - - dialogFragmentDismiss(DIALOG_FRAGMENT_TAG); - } - - @Override - protected void onPreExecute() { - dialogFragmentShow(DIALOG_FRAGMENT_TAG); - } - - @Override - public void onProgressUpdate(Integer... args) { - Object[] testArgs = {args[0], args[1]}; - dialogFragmentUpdate(DIALOG_FRAGMENT_TAG, form.format(testArgs), args[2]); - } - } -} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/activities/UsbInfoActivity.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/activities/UsbInfoActivity.java deleted file mode 100644 index 53c39af..0000000 --- a/app/src/main/java/aws/apps/usbDeviceEnumerator/activities/UsbInfoActivity.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright 2011 Alexandros Schillings - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ -package aws.apps.usbDeviceEnumerator.activities; - -import android.app.Activity; -import android.app.Fragment; -import android.app.FragmentTransaction; -import android.os.Bundle; - -import aws.apps.usbDeviceEnumerator.R; -import aws.apps.usbDeviceEnumerator.fragments.AbstractUsbDeviceInfoFragment; -import aws.apps.usbDeviceEnumerator.fragments.UsbDeviceInfoAndroidFragment; -import aws.apps.usbDeviceEnumerator.fragments.UsbDeviceInfoLinuxFragment; -import aws.apps.usbDeviceEnumerator.usb.sysbususb.SysBusUsbDevice; - -public class UsbInfoActivity extends Activity { - public static final String EXTRA_TYPE = "type"; - public static final String EXTRA_DATA_ANDROID = "data_android"; - public static final String EXTRA_DATA_LINUX = "data_linux"; - - /** Called when the activity is first created. */ - - private int mType; - private String mAndroidKey; - private SysBusUsbDevice mLinuxDevice; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.act_usb_info); - - Bundle b = getIntent().getExtras(); - if (b != null) { - mType = b.getInt(EXTRA_TYPE); - mAndroidKey = b.getString(EXTRA_DATA_ANDROID); - mLinuxDevice = b.getParcelable(EXTRA_DATA_LINUX); - - if (mType == AbstractUsbDeviceInfoFragment.TYPE_ANDROID_INFO) { - Fragment f = new UsbDeviceInfoAndroidFragment(mAndroidKey); - - FragmentTransaction ft = getFragmentManager().beginTransaction(); - ft.replace(R.id.fragment_container, f); - ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); - - ft.commit(); - } else if (mType == AbstractUsbDeviceInfoFragment.TYPE_LINUX_INFO) { - Fragment f = new UsbDeviceInfoLinuxFragment(mLinuxDevice); - - FragmentTransaction ft = getFragmentManager().beginTransaction(); - ft.replace(R.id.fragment_container, f); - ft.setTransition(FragmentTransaction.TRANSIT_NONE); - - ft.commit(); - } else { - finish(); - } - } else { - finish(); - } - } -} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DataProvider.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DataProvider.java new file mode 100644 index 0000000..d4c8e25 --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DataProvider.java @@ -0,0 +1,9 @@ +package aws.apps.usbDeviceEnumerator.data; + +public interface DataProvider { + String getUrl(); + + String getDataFilePath(); + + boolean isDataAvailable(); +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DataProviderCompanyInfo.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DataProviderCompanyInfo.java new file mode 100644 index 0000000..a67ee0d --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DataProviderCompanyInfo.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright 2011 Alexandros Schillings + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package aws.apps.usbDeviceEnumerator.data; + +import android.content.Context; +import android.database.Cursor; +import android.util.Log; + +import java.io.File; + +import aws.apps.usbDeviceEnumerator.BuildConfig; + +public class DataProviderCompanyInfo implements DataProvider { + public static final String UNKNOWN_RESULT = "not found"; + private final String TAG = this.getClass().getName(); + private Context context; + + private String fileFullPath = ""; + + public DataProviderCompanyInfo(Context context) { + this.context = context.getApplicationContext(); + doPathStuff(); + } + + private static String tryNull(final String suspect, + final String defaultString) { + if (suspect == null) { + return defaultString; + } + return suspect; + } + + @Override + public boolean isDataAvailable() { + final boolean okToAccessData; + + if (!new File(getDataFilePath()).exists()) { + Log.e(TAG, "^ Cannot access: " + fileFullPath); + okToAccessData = false; + } else { + okToAccessData = true; + } + + return okToAccessData; + } + + private void doPathStuff() { + final File baseDir = StorageUtils.getExternalStorageLocation(context); + + if (baseDir == null) { + fileFullPath = ""; + } else { + fileFullPath = new File(baseDir, BuildConfig.COMPANY_DB_FILE_NAME).getAbsolutePath(); + } + } + + @Override + public String getDataFilePath() { + return fileFullPath; + } + + @Override + public String getUrl() { + return BuildConfig.COMPANY_DB_URL; + } + + public String getLogoName(String companyNameString) { + + final Cursor cur = StorageUtils.executeQuery( + context, + getDataFilePath(), + "companies, company_name_spellings", + new String[]{"companies.logo"}, + "company_name_spellings.company_name=? AND company_name_spellings.companyId=companies._id", + new String[]{companyNameString}, + "companies.logo ASC"); + + final String result = StorageUtils.getStringAndClose(cur, "logo"); + + return tryNull(result, UNKNOWN_RESULT); + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DataProviderCompanyLogo.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DataProviderCompanyLogo.java new file mode 100644 index 0000000..cc59552 --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DataProviderCompanyLogo.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright 2011 Alexandros Schillings + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package aws.apps.usbDeviceEnumerator.data; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.text.TextUtils; +import android.util.Log; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +import aws.apps.usbDeviceEnumerator.BuildConfig; + +public class DataProviderCompanyLogo implements DataProvider { + private final String TAG = this.getClass().getName(); + private Context context; + + private String fileFullPath = ""; + + public DataProviderCompanyLogo(Context context) { + this.context = context.getApplicationContext(); + doPathStuff(); + } + + private void doPathStuff() { + final File baseDir = StorageUtils.getExternalStorageLocation(context); + + if (baseDir == null) { + fileFullPath = ""; + } else { + fileFullPath = new File(baseDir, BuildConfig.LOGO_ZIP_FILE_NAME).getAbsolutePath(); + } + } + + @Override + public String getDataFilePath() { + return fileFullPath; + } + + @Override + public String getUrl() { + return BuildConfig.LOGO_ZIP_URL; + } + + public Bitmap getLogoBitmap(final String logoName) { + Log.d(TAG, "^ Getting logo '" + logoName + "' from '" + fileFullPath + "'"); + + Bitmap result = null; + if (TextUtils.isEmpty(logoName)) { + result = null; + } else { + try { + FileInputStream fis = new FileInputStream(fileFullPath); + ZipInputStream zis = new ZipInputStream(fis); + ZipEntry ze = null; + + // Until we find their map, or we run out of options + if (zis.getNextEntry() != null) ze = zis.getNextEntry(); + + while ((ze = zis.getNextEntry()) != null) { + if (ze.getName().equals(logoName)) { + Log.d(TAG, "^ Found it!"); + result = BitmapFactory.decodeStream(zis); + break; + } + } + + zis.close(); + } catch (FileNotFoundException e) { + Log.e(TAG, "^ Error opening zip file: ", e); + e.printStackTrace(); + } catch (IOException e) { + Log.e(TAG, "^ Error opening zip file: ", e); + e.printStackTrace(); + } + } + return result; + } + + @Override + public boolean isDataAvailable() { + final boolean okToAccessData; + + if (!new File(getDataFilePath()).exists()) { + Log.e(TAG, "^ Cannot access: " + fileFullPath); + okToAccessData = false; + } else { + okToAccessData = true; + } + + return okToAccessData; + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DataProviderUsbInfo.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DataProviderUsbInfo.java new file mode 100644 index 0000000..c2a95d6 --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DataProviderUsbInfo.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright 2011 Alexandros Schillings + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package aws.apps.usbDeviceEnumerator.data; + +import android.content.Context; +import android.database.Cursor; +import android.util.Log; + +import java.io.File; + +import aws.apps.usbDeviceEnumerator.BuildConfig; + +public class DataProviderUsbInfo implements DataProvider { + + public static final String UNKNOWN_RESULT = "not found"; + private final String TAG = this.getClass().getName(); + private Context context; + + private String fileFullPath = ""; + + public DataProviderUsbInfo(Context context) { + this.context = context.getApplicationContext(); + doPathStuff(); + } + + private static String tryNull(final String suspect, + final String defaultString) { + if (suspect == null) { + return defaultString; + } + return suspect; + } + + @Override + public boolean isDataAvailable() { + final boolean okToAccessData; + + if (!new File(getDataFilePath()).exists()) { + Log.e(TAG, "^ Cannot access: " + fileFullPath); + okToAccessData = false; + } else { + okToAccessData = true; + } + + return okToAccessData; + } + + private void doPathStuff() { + final File baseDir = StorageUtils.getExternalStorageLocation(context); + + if (baseDir == null) { + fileFullPath = ""; + } else { + fileFullPath = new File(baseDir, BuildConfig.USB_DB_FILE_NAME).getAbsolutePath(); + } + } + + @Override + public String getDataFilePath() { + return fileFullPath; + } + + @Override + public String getUrl() { + return BuildConfig.USB_DB_URL; + } + + public String getProductName(String vid, String pid) { + final Cursor cur = StorageUtils.executeQuery( + context, + getDataFilePath(), + "usb", + new String[]{"vid", "vendor_name", "did", "device_name", "ifid", "interface_name"}, + "did=? AND vid=?", + new String[]{vid, pid}, + "vid, did, ifid ASC"); + + final String result = StorageUtils.getStringAndClose(cur, "device_name"); + + return tryNull(result, UNKNOWN_RESULT); + } + + public String getVendorName(String vid) { + final Cursor cur = StorageUtils.executeQuery( + context, + getDataFilePath(), + "usb", + new String[]{"vid", "vendor_name", "did", "device_name", "ifid", "interface_name"}, + "vid=? AND did=''", + new String[]{vid}, + "vid, did, ifid ASC"); + + final String result = StorageUtils.getStringAndClose(cur, "vendor_name"); + + return tryNull(result, UNKNOWN_RESULT); + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DbAccessCompany.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DbAccessCompany.java deleted file mode 100644 index 03f9035..0000000 --- a/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DbAccessCompany.java +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* - * Copyright 2011 Alexandros Schillings - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ -package aws.apps.usbDeviceEnumerator.data; - -import android.content.Context; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.os.Environment; -import android.util.Log; -import android.view.Gravity; -import android.widget.Toast; - -import java.io.File; - -import aws.apps.usbDeviceEnumerator.R; -import aws.apps.usbDeviceEnumerator.util.UsefulBits; - -public class DbAccessCompany { - public final static String UNKNOWN_RESULT = "???"; - private final String TAG = this.getClass().getName(); - private Context context; - private UsefulBits uB; - - private String localDbLocation = ""; - private String localDbFullPath = ""; - - private SQLiteDatabase db; - - public DbAccessCompany(Context context) { - this.context = context; - uB = new UsefulBits(context); - doDbPathStuff(); - } - - public boolean doDBChecks() { - if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { - Log.d(TAG, "^ SD card not available."); - uB.ShowAlert(context.getString(R.string.sd_error), - context.getString(R.string.sd_not_available), - context.getString(android.R.string.ok)); - return false; - } - - if (!new File(localDbFullPath).exists()) { - uB.ShowAlert(context.getString(R.string.alert_db_not_found_title), - context.getString(R.string.alert_db_not_found_instructions), - context.getString(android.R.string.ok)); - Log.e(TAG, "^ Database not found: " + localDbFullPath); - return false; - } - - return true; - } - - private void doDbPathStuff() { - localDbLocation = Environment.getExternalStorageDirectory() + context.getString(R.string.sd_db_location_company); - localDbFullPath = localDbLocation + context.getString(R.string.sd_db_name_company); - } - - private Cursor executeQuery(String table, String[] fields, String where, String order) { - - try { - db = SQLiteDatabase.openDatabase(localDbFullPath, null, SQLiteDatabase.OPEN_READONLY); - - if (!db.isOpen()) { - Log.e(TAG, "^ DB was not opened!"); - uB.showToast(context.getString(R.string.error_could_not_open_db), - Toast.LENGTH_SHORT, Gravity.TOP, 0, 0); - return null; - } - - return db.query(table, fields, where, null, null, null, order); - } catch (Exception e) { - Log.e(TAG, "^ executeQuery(): " + e.getMessage()); - if (db.isOpen()) { - db.close(); - } - } - return null; - } - - public String getLocalDbFullPath() { - return localDbFullPath; - } - - public String getLocalDbLocation() { - return localDbLocation; - } - - public String getLogo(String CompanyNameString) { - String result = ""; - Cursor cur = executeQuery("companies, company_name_spellings", - new String[]{"companies.logo"}, - "company_name_spellings.company_name='" + CompanyNameString + - "' AND company_name_spellings.companyId=companies._id", - "companies.logo ASC"); - - if (cur != null) { - if (cur.getCount() > 0) { - cur.moveToFirst(); - result = cur.getString(cur.getColumnIndex("logo")); - } else { - result = UNKNOWN_RESULT; - } - - if (!cur.isClosed()) { - cur.close(); - } - if (db.isOpen()) { - db.close(); - } - } - - return tryNull(result, UNKNOWN_RESULT); - } - - - private String tryNull(String suspect, String defaultString) { - if (suspect == null) { - return defaultString; - } - return suspect; - } -} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DbAccessUsb.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DbAccessUsb.java deleted file mode 100644 index 601938d..0000000 --- a/app/src/main/java/aws/apps/usbDeviceEnumerator/data/DbAccessUsb.java +++ /dev/null @@ -1,168 +0,0 @@ -/******************************************************************************* - * Copyright 2011 Alexandros Schillings - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ -package aws.apps.usbDeviceEnumerator.data; - -import android.content.Context; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.os.Environment; -import android.util.Log; -import android.view.Gravity; -import android.widget.Toast; - -import java.io.File; - -import aws.apps.usbDeviceEnumerator.R; -import aws.apps.usbDeviceEnumerator.util.UsefulBits; - -public class DbAccessUsb { - public final static String UNKNOWN_RESULT = "not in database"; - private final String TAG = this.getClass().getName(); - private Context context; - private UsefulBits uB; - - private String localDbLocation = ""; - private String localDbFullPath = ""; - - private SQLiteDatabase db; - - public DbAccessUsb(Context context) { - this.context = context; - uB = new UsefulBits(context); - doDbPathStuff(); - } - - public boolean doDBChecks() { - if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { - Log.d(TAG, "^ SD card not available."); - uB.ShowAlert(context.getString(R.string.sd_error), - context.getString(R.string.sd_not_available), - context.getString(android.R.string.ok)); - return false; - } - - if (!new File(localDbFullPath).exists()) { - uB.ShowAlert(context.getString(R.string.alert_db_not_found_title), - context.getString(R.string.alert_db_not_found_instructions), - context.getString(android.R.string.ok)); - Log.e(TAG, "^ Database not found: " + localDbFullPath); - return false; - } - - return true; - } - - private void doDbPathStuff() { - localDbLocation = Environment.getExternalStorageDirectory() + context.getString(R.string.sd_db_location_usb); - localDbFullPath = localDbLocation + context.getString(R.string.sd_db_name_usb); - } - - private Cursor executeQuery(String table, String[] fields, String where, String order) { - - try { - db = SQLiteDatabase.openDatabase(localDbFullPath, null, SQLiteDatabase.OPEN_READONLY); - - if (!db.isOpen()) { - Log.e(TAG, "^ DB was not opened!"); - uB.showToast(context.getString(R.string.error_could_not_open_db), - Toast.LENGTH_SHORT, Gravity.TOP, 0, 0); - return null; - } - - return db.query(table, fields, where, null, null, null, order); - } catch (Exception e) { - Log.e(TAG, "^ executeQuery(): " + e.getMessage()); - if (db.isOpen()) { - db.close(); - } - } - return null; - } - - - public String getLocalDbFullPath() { - return localDbFullPath; - } - - public String getLocalDbLocation() { - return localDbLocation; - } - - public String getProduct(String VID, String PID) { - String result = ""; - Cursor cur = executeQuery("usb", - new String[]{"vid", "vendor_name", "did", "device_name", "ifid", "interface_name"}, - "did='" + PID + "' AND vid='" + VID + "'", - "vid, did, ifid ASC"); - - if (cur != null) { - //Log.d(TAG, "^ getProduct(" + PID + "): " + cur.getCount()); - if (cur.getCount() > 0) { - cur.moveToFirst(); - result = cur.getString(cur.getColumnIndex("device_name")); - cur.close(); - db.close(); - } else { - result = "not in db"; - } - if (!cur.isClosed()) { - cur.close(); - } - if (db.isOpen()) { - db.close(); - } - } - - return tryNull(result, UNKNOWN_RESULT); - } - - public String getVendor(String VID) { - String result = ""; - Cursor cur = executeQuery("usb", - new String[]{"vid", "vendor_name", "did", "device_name", "ifid", "interface_name"}, - "vid='" + VID + "' AND did=''", - "vid, did, ifid ASC"); - - if (cur != null) { - //Log.d(TAG, "^ getVendor(" + VID + "): " + cur.getCount()); - if (cur.getCount() > 0) { - cur.moveToFirst(); - result = cur.getString(cur.getColumnIndex("vendor_name")); - cur.close(); - db.close(); - } else { - result = UNKNOWN_RESULT; - } - - if (!cur.isClosed()) { - cur.close(); - } - if (db.isOpen()) { - db.close(); - } - } - - return tryNull(result, UNKNOWN_RESULT); - } - - - private String tryNull(String suspect, String defaultString) { - if (suspect == null) { - return defaultString; - } - return suspect; - } -} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/data/StorageUtils.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/data/StorageUtils.java new file mode 100644 index 0000000..6016f44 --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/data/StorageUtils.java @@ -0,0 +1,81 @@ +package aws.apps.usbDeviceEnumerator.data; + +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.support.v4.content.ContextCompat; +import android.util.Log; + +import java.io.File; + +import aws.apps.usbDeviceEnumerator.R; +import aws.apps.usbDeviceEnumerator.util.NotifyUser; + +/*package*/ class StorageUtils { + private static final String TAG = StorageUtils.class.getSimpleName(); + + public static File getExternalStorageLocation(final Context context) { + final File[] dirs = ContextCompat.getExternalFilesDirs(context, null); + final File dir; + + if (dirs == null || dirs.length == 0) { + dir = null; + } else { + dir = dirs[0]; + } + + return dir; + } + + public static Cursor executeQuery(final Context context, + final String dbPath, + final String table, + final String[] fields, + final String selection, + final String[] selectionArgs, + final String order) { + + SQLiteDatabase db = null; + + try { + db = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READONLY); + + if (!db.isOpen()) { + Log.e(TAG, "^ DB was not opened!"); + NotifyUser.notify(context, R.string.error_could_not_open_db); + return null; + } + + return db.query(table, fields, selection, selectionArgs, null, null, order); + } catch (Exception e) { + Log.e(TAG, "^ executeQuery(): " + e.getMessage()); + if (db != null && db.isOpen()) { + db.close(); + } + } + return null; + } + + public static String getStringAndClose(final Cursor cursor, + final String colName) { + final String result; + + if (cursor != null) { + if (cursor.getCount() > 0) { + cursor.moveToFirst(); + result = cursor.getString(cursor.getColumnIndex(colName)); + cursor.close(); + } else { + result = null; + } + + if (!cursor.isClosed()) { + cursor.close(); + } + } else { + result = null; + } + + return result; + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/data/ZipAccessCompany.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/data/ZipAccessCompany.java deleted file mode 100644 index 443051b..0000000 --- a/app/src/main/java/aws/apps/usbDeviceEnumerator/data/ZipAccessCompany.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright 2011 Alexandros Schillings - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ -package aws.apps.usbDeviceEnumerator.data; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.os.Environment; -import android.util.Log; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -import aws.apps.usbDeviceEnumerator.R; - -public class ZipAccessCompany { - private final String TAG = this.getClass().getName(); - private Context context; - - private String localZipLocation = ""; - private String localZipFullPath = ""; - - public ZipAccessCompany(Context context) { - this.context = context; - doPathStuff(); - } - - private void doPathStuff() { - localZipLocation = Environment.getExternalStorageDirectory() + context.getString(R.string.sd_zip_location_company); - localZipFullPath = localZipLocation + context.getString(R.string.sd_zip_name_company); - } - - public String getLocalZipFullPath() { - return localZipFullPath; - } - - public String getLocalZipLocation() { - return localZipLocation; - } - - public Bitmap getLogo(final String logo) { - Log.d(TAG, "^ Getting logo '" + logo + "' from '" + localZipFullPath + "'"); - Bitmap result = null; - try { - FileInputStream fis = new FileInputStream(localZipFullPath); - ZipInputStream zis = new ZipInputStream(fis); - ZipEntry ze = null; - - // Until we find their map, or we run out of options - if (zis.getNextEntry() != null) ze = zis.getNextEntry(); - - while ((ze = zis.getNextEntry()) != null) { - if (ze.getName().equals(logo)) { - Log.d(TAG, "^ Found it!"); - result = BitmapFactory.decodeStream(zis); - break; - } else { - - } - } - - } catch (FileNotFoundException e) { - Log.e(TAG, "^ Error opening zip file: ", e); - e.printStackTrace(); - } catch (IOException e) { - Log.e(TAG, "^ Error opening zip file: ", e); - e.printStackTrace(); - } - - return result; - } -} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/fragments/UsbDeviceInfoAndroidFragment.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/fragments/UsbDeviceInfoAndroidFragment.java deleted file mode 100644 index 015433a..0000000 --- a/app/src/main/java/aws/apps/usbDeviceEnumerator/fragments/UsbDeviceInfoAndroidFragment.java +++ /dev/null @@ -1,225 +0,0 @@ -/******************************************************************************* - * Copyright 2011 Alexandros Schillings - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ -package aws.apps.usbDeviceEnumerator.fragments; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; -import android.hardware.usb.UsbDevice; -import android.hardware.usb.UsbEndpoint; -import android.hardware.usb.UsbInterface; -import android.hardware.usb.UsbManager; -import android.os.Bundle; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageButton; -import android.widget.LinearLayout; -import android.widget.TableLayout; -import android.widget.TableRow; -import android.widget.TextView; - -import aws.apps.usbDeviceEnumerator.R; -import aws.apps.usbDeviceEnumerator.data.DbAccessCompany; -import aws.apps.usbDeviceEnumerator.data.DbAccessUsb; -import aws.apps.usbDeviceEnumerator.data.ZipAccessCompany; -import aws.apps.usbDeviceEnumerator.usb.UsbConstants; -import aws.apps.usbDeviceEnumerator.util.UsefulBits; - -public class UsbDeviceInfoAndroidFragment extends AbstractUsbDeviceInfoFragment { - public final static int TYPE_ANDROID_INFO = 0; - public final static int TYPE_LINUX_INFO = 1; - public final static String DEFAULT_STRING = "???"; - private final static String BUNDLE_USB_KEY = "BUNDLE_USBKEY"; - private final String TAG = this.getClass().getName(); - private String usbKey = DEFAULT_STRING; - private TableLayout tblUsbInfoHeader; - private TableLayout tblUsbInfoTop; - private TableLayout tblUsbInfoBottom; - private TextView tvVID; - private TextView tvPID; - private TextView tvVendorDb; - private TextView tvProductDb; - private TextView tvDevicePath; - private TextView tvDeviceClass; - private ImageButton btnLogo; - private UsbManager usbMan; - private DbAccessUsb dbUsb; - private DbAccessCompany dbComp; - private ZipAccessCompany zipComp; - - private Context context; - - public UsbDeviceInfoAndroidFragment() { - - } - - public UsbDeviceInfoAndroidFragment(String usbKey) { - this.usbKey = usbKey; - } - - private void addDataRow(LayoutInflater inflater, TableLayout tlb, String cell1Text, String cell2Text) { - TableRow row = (TableRow) inflater.inflate(R.layout.usb_table_row_data, null); - TextView tv1 = (TextView) row.findViewById(R.id.usb_tablerow_cell1); - TextView tv2 = (TextView) row.findViewById(R.id.usb_tablerow_cell2); - tv1.setText(cell1Text); - tv2.setText(cell2Text); - tlb.addView(row); - } - - @Override - public int getType() { - return TYPE_ANDROID_INFO; - } - - private void loadLogo(String logo) { - Drawable d = context.getResources().getDrawable(R.drawable.no_image); - Bitmap b = zipComp.getLogo(logo); - - if (b != null) { - d = new BitmapDrawable(b); - } else { - Log.w(TAG, "^ Bitmap is null"); - } - - btnLogo.setImageDrawable(d); - } - - /** - * If we are being created with saved state, restore our state - */ - @Override - public void onCreate(Bundle saved) { - super.onCreate(saved); - if (null != saved) { - usbKey = saved.getString(BUNDLE_USB_KEY); - } - } - - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saved) { - View v = new LinearLayout(getActivity().getApplicationContext()); - context = getActivity().getApplicationContext(); - usbMan = (UsbManager) context.getSystemService(Context.USB_SERVICE); - - - if (usbMan == null || usbMan.getDeviceList().get(usbKey) == null) { - return v; - } else { - v = inflater.inflate(R.layout.usb_info_android, container, false); - } - - tblUsbInfoHeader = (TableLayout) v.findViewById(R.id.tblUsbInfo_title); - tblUsbInfoTop = (TableLayout) v.findViewById(R.id.tblUsbInfo_top); - tblUsbInfoBottom = (TableLayout) v.findViewById(R.id.tblUsbInfo_bottom); - tvVID = ((TextView) v.findViewById(R.id.tvVID)); - tvPID = ((TextView) v.findViewById(R.id.tvPID)); - tvProductDb = ((TextView) v.findViewById(R.id.tvProductDb)); - tvVendorDb = ((TextView) v.findViewById(R.id.tvVendorDb)); - tvDevicePath = ((TextView) v.findViewById(R.id.tvDevicePath)); - tvDeviceClass = ((TextView) v.findViewById(R.id.tvDeviceClass)); - btnLogo = (ImageButton) v.findViewById(R.id.btnLogo); - btnLogo.setImageDrawable(context.getResources().getDrawable(R.drawable.no_image)); - dbUsb = new DbAccessUsb(context); - dbComp = new DbAccessCompany(context); - zipComp = new ZipAccessCompany(context); - - populateAndroidTable(inflater); - - return v; - } - - @Override - public void onSaveInstanceState(Bundle toSave) { - toSave.putString(BUNDLE_USB_KEY, usbKey); - } - - private String padLeft(String string, String padding, int size) { - String pad = ""; - while ((pad + string).length() < size) { - pad += padding + pad; - } - return pad + string; - } - - private void populateAndroidTable(LayoutInflater inflater) { - UsbDevice device = usbMan.getDeviceList().get(usbKey); - tvDevicePath.setText(usbKey); - - if (device != null) { - tvVID.setText(padLeft(Integer.toHexString(device.getVendorId()), "0", 4)); - tvPID.setText(padLeft(Integer.toHexString(device.getDeviceId()), "0", 4)); - tvDeviceClass.setText(UsbConstants.resolveUsbClass(device.getDeviceClass())); - if (dbUsb.doDBChecks()) { - String vid = tvVID.getText().toString(); - String pid = tvPID.getText().toString(); - String vendor_name = dbUsb.getVendor(vid); - - tvVendorDb.setText(vendor_name); - tvProductDb.setText(dbUsb.getProduct(vid, pid)); - - - if (dbComp.doDBChecks()) { - String logo = dbComp.getLogo(vendor_name); - loadLogo(logo); - } - } - - UsbInterface iface; - for (int i = 0; i < device.getInterfaceCount(); i++) { - iface = device.getInterface(i); - if (iface != null) { - - addDataRow(inflater, tblUsbInfoBottom, getActivity().getString(R.string.interface_) + i, ""); - addDataRow(inflater, tblUsbInfoBottom, getActivity().getString(R.string.class_), UsbConstants.resolveUsbClass((iface.getInterfaceClass()))); - - String endpointText = getActivity().getString(R.string.none); - if (iface.getEndpointCount() > 0) { - UsbEndpoint endpoint; - for (int j = 0; j < iface.getEndpointCount(); j++) { - endpoint = iface.getEndpoint(j); - endpointText = "#" + j + "\n"; - endpointText += getActivity().getString(R.string.address_) + endpoint.getAddress() + " (" + padLeft(Integer.toBinaryString(endpoint.getAddress()), "0", 8) + ")\n"; - endpointText += getActivity().getString(R.string.number_) + endpoint.getEndpointNumber() + "\n"; - endpointText += getActivity().getString(R.string.direction_) + UsbConstants.resolveUsbEndpointDirection(endpoint.getDirection()) + "\n"; - endpointText += getActivity().getString(R.string.type_) + UsbConstants.resolveUsbEndpointType(endpoint.getType()) + "\n"; - endpointText += getActivity().getString(R.string.poll_interval_) + endpoint.getInterval() + "\n"; - endpointText += getActivity().getString(R.string.max_packet_size_) + endpoint.getMaxPacketSize() + "\n"; - endpointText += getActivity().getString(R.string.attributes_) + padLeft(Integer.toBinaryString(endpoint.getAttributes()), "0", 8); - addDataRow(inflater, tblUsbInfoBottom, "\t" + getActivity().getString(R.string.endpoint_), endpointText); - } - } else { - addDataRow(inflater, tblUsbInfoBottom, "\tEndpoints:", "none"); - } - } - } - } - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - UsefulBits uB = new UsefulBits(getActivity()); - sb.append(uB.tableToString(tblUsbInfoHeader)); - sb.append(uB.tableToString(tblUsbInfoTop)); - sb.append("\n"); - sb.append(uB.tableToString(tblUsbInfoBottom)); - return sb.toString(); - } -} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/fragments/UsbDeviceInfoLinuxFragment.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/fragments/UsbDeviceInfoLinuxFragment.java deleted file mode 100644 index 9f0dbbf..0000000 --- a/app/src/main/java/aws/apps/usbDeviceEnumerator/fragments/UsbDeviceInfoLinuxFragment.java +++ /dev/null @@ -1,211 +0,0 @@ -/******************************************************************************* - * Copyright 2011 Alexandros Schillings - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ -package aws.apps.usbDeviceEnumerator.fragments; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; -import android.os.Bundle; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageButton; -import android.widget.LinearLayout; -import android.widget.TableLayout; -import android.widget.TableRow; -import android.widget.TextView; - -import aws.apps.usbDeviceEnumerator.R; -import aws.apps.usbDeviceEnumerator.data.DbAccessCompany; -import aws.apps.usbDeviceEnumerator.data.DbAccessUsb; -import aws.apps.usbDeviceEnumerator.data.ZipAccessCompany; -import aws.apps.usbDeviceEnumerator.usb.UsbConstants; -import aws.apps.usbDeviceEnumerator.usb.sysbususb.SysBusUsbDevice; -import aws.apps.usbDeviceEnumerator.util.UsefulBits; - -public class UsbDeviceInfoLinuxFragment extends AbstractUsbDeviceInfoFragment { - public final static int TYPE_ANDROID_INFO = 0; - public final static int TYPE_LINUX_INFO = 1; - public final static String DEFAULT_STRING = "???"; - private final static String BUNDLE_MY_USB_INFO = "BUNDLE_MY_USB_INFO"; - private final String TAG = this.getClass().getName(); - private TableLayout tblUsbInfoHeader; - private TableLayout tblUsbInfoTop; - private TableLayout tblUsbInfoBottom; - private TextView tvVID; - private TextView tvPID; - private TextView tvVendorReported; - private TextView tvProductReported; - private TextView tvVendorDb; - private TextView tvProductDb; - private TextView tvDevicePath; - private TextView tvDeviceClass; - private ImageButton btnLogo; - private DbAccessUsb dbUsb; - private DbAccessCompany dbComp; - private ZipAccessCompany zipComp; - private SysBusUsbDevice myUsbDevice; - - - private Context context; - - public UsbDeviceInfoLinuxFragment() { - } - - - public UsbDeviceInfoLinuxFragment(SysBusUsbDevice myUsbDevice) { - this.myUsbDevice = myUsbDevice; - } - - private void addDataRow(LayoutInflater inflater, TableLayout tlb, String cell1Text, String cell2Text) { - TableRow row = (TableRow) inflater.inflate(R.layout.usb_table_row_data, null); - TextView tv1 = (TextView) row.findViewById(R.id.usb_tablerow_cell1); - TextView tv2 = (TextView) row.findViewById(R.id.usb_tablerow_cell2); - tv1.setText(cell1Text); - tv2.setText(cell2Text); - tlb.addView(row); - } - - @Override - public int getType() { - return TYPE_LINUX_INFO; - } - - private void loadLogo(String logo) { - Drawable d = context.getResources().getDrawable(R.drawable.no_image); - Bitmap b = zipComp.getLogo(logo); - - if (b != null) { - d = new BitmapDrawable(b); - } else { - Log.w(TAG, "^ Bitmap is null"); - } - - btnLogo.setImageDrawable(d); - } - - - /** - * If we are being created with saved state, restore our state - */ - @Override - public void onCreate(Bundle saved) { - super.onCreate(saved); - if (null != saved) { - myUsbDevice = (SysBusUsbDevice) saved.getParcelable(BUNDLE_MY_USB_INFO); - } - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saved) { - View v = new LinearLayout(getActivity().getApplicationContext()); - context = getActivity().getApplicationContext(); - - if (myUsbDevice == null) { - return v; - } else { - v = inflater.inflate(R.layout.usb_info_linux, container, false); - } - - tblUsbInfoHeader = (TableLayout) v.findViewById(R.id.tblUsbInfo_title); - tblUsbInfoTop = (TableLayout) v.findViewById(R.id.tblUsbInfo_top); - tblUsbInfoBottom = (TableLayout) v.findViewById(R.id.tblUsbInfo_bottom); - tvVID = ((TextView) v.findViewById(R.id.tvVID)); - tvPID = ((TextView) v.findViewById(R.id.tvPID)); - tvProductDb = ((TextView) v.findViewById(R.id.tvProductDb)); - tvVendorDb = ((TextView) v.findViewById(R.id.tvVendorDb)); - tvProductReported = ((TextView) v.findViewById(R.id.tvProductReported)); - tvVendorReported = ((TextView) v.findViewById(R.id.tvVendorReported)); - tvDevicePath = ((TextView) v.findViewById(R.id.tvDevicePath)); - tvDeviceClass = ((TextView) v.findViewById(R.id.tvDeviceClass)); - btnLogo = (ImageButton) v.findViewById(R.id.btnLogo); - btnLogo.setImageDrawable(context.getResources().getDrawable(R.drawable.no_image)); - dbUsb = new DbAccessUsb(context); - dbComp = new DbAccessCompany(context); - zipComp = new ZipAccessCompany(context); - - populateLinuxTable(inflater); - - return v; - } - - @Override - public void onSaveInstanceState(Bundle toSave) { - toSave.putParcelable(BUNDLE_MY_USB_INFO, myUsbDevice); - } - - private String padLeft(String string, String padding, int size) { - String pad = ""; - while ((pad + string).length() < size) { - pad += padding + pad; - } - return pad + string; - } - - private void populateLinuxTable(LayoutInflater inflater) { - if (myUsbDevice == null) { - return; - } - tvDevicePath.setText(myUsbDevice.getDevicePath()); - - tvVID.setText(padLeft(myUsbDevice.getVID(), "0", 4)); - tvPID.setText(padLeft(myUsbDevice.getPID(), "0", 4)); - tvDeviceClass.setText(UsbConstants.resolveUsbClass(myUsbDevice.getDeviceClass())); - - tvVendorReported.setText(myUsbDevice.getReportedVendorName()); - tvProductReported.setText(myUsbDevice.getReportedProductName()); - - if (dbUsb.doDBChecks()) { - String vid = tvVID.getText().toString(); - String pid = tvPID.getText().toString(); - tvVendorDb.setText(dbUsb.getVendor(vid)); - tvProductDb.setText(dbUsb.getProduct(vid, pid)); - } - - if (dbComp.doDBChecks()) { - String searchFor = ""; - - if (tvVendorDb.getText().toString().trim().length() > 0) { - searchFor = tvVendorDb.getText().toString(); - } else { - searchFor = myUsbDevice.getReportedVendorName(); - } - Log.d(TAG, "^ Searching for '" + searchFor + "'"); - loadLogo(dbComp.getLogo(searchFor)); - } - addDataRow(inflater, tblUsbInfoBottom, getActivity().getString(R.string.usb_version_), myUsbDevice.getUsbVersion()); - addDataRow(inflater, tblUsbInfoBottom, getActivity().getString(R.string.speed_), myUsbDevice.getSpeed()); - addDataRow(inflater, tblUsbInfoBottom, getActivity().getString(R.string.protocol_), myUsbDevice.getDeviceProtocol()); - addDataRow(inflater, tblUsbInfoBottom, getActivity().getString(R.string.maximum_power_), myUsbDevice.getMaxPower()); - addDataRow(inflater, tblUsbInfoBottom, getActivity().getString(R.string.serial_number_), myUsbDevice.getSerialNumber()); - - //addHeaderRow(inflater, tblUsbInfo, "Interfaces"); - - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - UsefulBits uB = new UsefulBits(getActivity()); - sb.append(uB.tableToString(tblUsbInfoHeader)); - sb.append(uB.tableToString(tblUsbInfoTop)); - sb.append("\n"); - sb.append(uB.tableToString(tblUsbInfoBottom)); - return sb.toString(); - } -} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/MyAlertBox.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/MyAlertBox.java deleted file mode 100644 index cb93716..0000000 --- a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/MyAlertBox.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright 2011 Alexandros Schillings - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ -package aws.apps.usbDeviceEnumerator.ui; - -import android.app.AlertDialog; -import android.content.Context; -import android.text.SpannableString; -import android.text.method.LinkMovementMethod; -import android.text.util.Linkify; -import android.widget.ScrollView; -import android.widget.TextView; - -public class MyAlertBox { - - public static AlertDialog create(Context context, String text, String title, String button) { - return new AlertDialog.Builder(context) - .setTitle(title) - .setCancelable(true) - .setIcon(android.R.drawable.ic_dialog_info) - .setPositiveButton(button, null) - .setView(LinkifyText(context, text)) - .create(); - } - - public static ScrollView LinkifyText(Context context, String message) { - ScrollView svMessage = new ScrollView(context); - TextView tvMessage = new TextView(context); - - SpannableString spanText = new SpannableString(message); - - Linkify.addLinks(spanText, Linkify.ALL); - tvMessage.setText(spanText); - tvMessage.setMovementMethod(LinkMovementMethod.getInstance()); - - svMessage.setPadding(14, 2, 10, 12); - svMessage.addView(tvMessage); - - return svMessage; - } -} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/common/DialogFactory.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/common/DialogFactory.java new file mode 100644 index 0000000..15b2aff --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/common/DialogFactory.java @@ -0,0 +1,28 @@ +package aws.apps.usbDeviceEnumerator.ui.common; + +import android.app.Dialog; +import android.content.Context; +import android.support.v7.app.AlertDialog; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.TextView; + +import aws.apps.usbDeviceEnumerator.R; + +public class DialogFactory { + + public static Dialog createOkDialog(final Context context, final int title, final int message) { + final View view = LayoutInflater.from(context).inflate(R.layout.dialog_textview, null); + final TextView textView = (TextView) view.findViewById(R.id.text); + + textView.setText(message); + + return new AlertDialog.Builder(context) + .setTitle(title) + .setCancelable(false) + .setPositiveButton(android.R.string.ok, null) + .setView(view) + .create(); + } + +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/common/Navigation.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/common/Navigation.java new file mode 100644 index 0000000..ebef9db --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/common/Navigation.java @@ -0,0 +1,76 @@ +package aws.apps.usbDeviceEnumerator.ui.common; + +import android.content.Intent; +import android.support.v4.app.ActivityCompat; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; + +import aws.apps.usbDeviceEnumerator.R; +import aws.apps.usbDeviceEnumerator.ui.usbinfo.InfoFragmentFactory; +import aws.apps.usbDeviceEnumerator.ui.usbinfo.UsbInfoActivity; +import uk.co.alt236.usbdeviceenumerator.sysbususb.SysBusUsbDevice; + +public class Navigation { + private static final String TAG = Navigation.class.getSimpleName(); + private static final int FRAGMENT_CONTAINER = R.id.fragment_container; + private static final int DEFAULT_FRAGMENT_TRANSACTION = FragmentTransaction.TRANSIT_FRAGMENT_FADE; + + private final AppCompatActivity activity; + + public Navigation(AppCompatActivity activity) { + this.activity = activity; + } + + public void showAndroidUsbDeviceInfo(String device) { + if (isSmallScreen()) { + final Intent i = new Intent(activity.getApplicationContext(), UsbInfoActivity.class); + i.putExtra(UsbInfoActivity.EXTRA_DATA_ANDROID, device); + startActivity(i); + } else { + final Fragment fragment = InfoFragmentFactory.getFragment(device); + stackFragment(fragment); + } + } + + public void showLinuxUsbDeviceInfo(SysBusUsbDevice device) { + if (isSmallScreen()) { + final Intent i = new Intent(activity.getApplicationContext(), UsbInfoActivity.class); + i.putExtra(UsbInfoActivity.EXTRA_DATA_LINUX, device); + startActivity(i); + } else { + final Fragment fragment = InfoFragmentFactory.getFragment(device); + stackFragment(fragment); + } + } + + public boolean isSmallScreen() { + final boolean res = activity.findViewById(FRAGMENT_CONTAINER) == null; + Log.d(TAG, "^ Is " + activity.getClass().getName() + " running in a small screen? " + res); + return res; + } + + public void stackFragment(Fragment fragment) { + final FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction(); + ft.replace(FRAGMENT_CONTAINER, fragment); + ft.setTransition(DEFAULT_FRAGMENT_TRANSACTION); + + ft.commit(); + } + + public void removeFragmentsFromContainer() { + final Fragment fragment = activity.getSupportFragmentManager().findFragmentById(FRAGMENT_CONTAINER); + + if (fragment != null) { + final FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction(); + ft.remove(fragment); + ft.setTransition(DEFAULT_FRAGMENT_TRANSACTION); + ft.commit(); + } + } + + private void startActivity(final Intent intent) { + ActivityCompat.startActivity(activity, intent, null); + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/dbupdate/DatabaseUpdater.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/dbupdate/DatabaseUpdater.java new file mode 100644 index 0000000..b66da46 --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/dbupdate/DatabaseUpdater.java @@ -0,0 +1,101 @@ +package aws.apps.usbDeviceEnumerator.ui.dbupdate; + +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.os.Environment; +import android.util.Log; + +import java.util.ArrayList; +import java.util.List; + +import aws.apps.usbDeviceEnumerator.R; +import aws.apps.usbDeviceEnumerator.data.DataProviderCompanyInfo; +import aws.apps.usbDeviceEnumerator.data.DataProviderCompanyLogo; +import aws.apps.usbDeviceEnumerator.data.DataProviderUsbInfo; +import aws.apps.usbDeviceEnumerator.ui.common.DialogFactory; +import aws.apps.usbDeviceEnumerator.ui.progress.ProgressDialogControl; +import aws.apps.usbDeviceEnumerator.util.NetworkUtils; +import aws.apps.usbDeviceEnumerator.util.NotifyUser; + +public class DatabaseUpdater { + private static final String TAG = DatabaseUpdater.class.getSimpleName(); + + private final ProgressDialogControl progressDialogControl; + private final DataProviderCompanyInfo dbAccessCompany; + private final DataProviderUsbInfo dbAccessUsb; + private final DataProviderCompanyLogo zipAccessCompany; + + public DatabaseUpdater(final ProgressDialogControl progressDialogControl, + final DataProviderCompanyInfo dbAccessCompany, + final DataProviderUsbInfo dbAccessUsb, + final DataProviderCompanyLogo zipAccessCompany) { + + this.progressDialogControl = progressDialogControl; + this.dbAccessCompany = dbAccessCompany; + this.dbAccessUsb = dbAccessUsb; + this.zipAccessCompany = zipAccessCompany; + } + + public void start(final Context context) { + + if (validate(context)) { + final AlertDialog.Builder builder = new AlertDialog.Builder(context); + final List downloadables + = createDownloadables(context); + + builder.setMessage(R.string.alert_update_db) + .setNegativeButton(android.R.string.no, null) + .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { + @SuppressWarnings("unchecked") + @Override + public void onClick(DialogInterface dialog, int which) { + final FileDownloadTask.Downloadable[] array + = downloadables.toArray(new FileDownloadTask.Downloadable[downloadables.size()]); + new FileDownloadTask(context, progressDialogControl).execute(array); + } + }); + + builder.create().show(); + } + } + + private boolean validate(final Context context) { + final boolean valid; + + if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { + Log.d(TAG, "^ SD card not available."); + NotifyUser.notify(context, R.string.sd_not_available); + valid = false; + } else if (!NetworkUtils.isOnline(context)) { // If we are not online, cancel everything + DialogFactory.createOkDialog( + context, + R.string.text_device_offline, + R.string.text_device_offline_instructions) + .show(); + valid = false; + } else { + valid = true; + } + + return valid; + } + + private List createDownloadables(final Context context) { + final List downloads = new ArrayList(); + + downloads.add(new FileDownloadTask.Downloadable( + dbAccessUsb.getUrl(), + dbAccessUsb.getDataFilePath())); + + downloads.add(new FileDownloadTask.Downloadable( + dbAccessCompany.getUrl(), + dbAccessCompany.getDataFilePath())); + + downloads.add(new FileDownloadTask.Downloadable( + zipAccessCompany.getUrl(), + zipAccessCompany.getDataFilePath())); + + return downloads; + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/dbupdate/FileDownloadTask.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/dbupdate/FileDownloadTask.java new file mode 100644 index 0000000..6469f2f --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/dbupdate/FileDownloadTask.java @@ -0,0 +1,157 @@ +package aws.apps.usbDeviceEnumerator.ui.dbupdate; + +import android.content.Context; +import android.os.AsyncTask; +import android.util.Log; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; +import java.net.URLConnection; +import java.text.MessageFormat; + +import aws.apps.usbDeviceEnumerator.R; +import aws.apps.usbDeviceEnumerator.ui.progress.ProgressDialogControl; +import aws.apps.usbDeviceEnumerator.util.NotifyUser; + +/*package*/ class FileDownloadTask extends AsyncTask { + private static final String TAG = FileDownloadTask.class.getSimpleName(); + private final MessageFormat form = new MessageFormat("Downloading file: {0} of {1}..."); + private final ProgressDialogControl progressDialogControl; + private final Context context; + + public FileDownloadTask(final Context context, + final ProgressDialogControl progressDialogControl) { + this.progressDialogControl = progressDialogControl; + this.context = context.getApplicationContext(); + } + + @Override + protected Boolean doInBackground(Downloadable... downloadables) { + int count; + + URL url; + String filePath; + URLConnection connection; + InputStream is; + OutputStream os; + Boolean bOK = true; + + int downloadCounter = 0; + + for (Downloadable download : downloadables) { + try { + url = new URL(download.getFrom()); + filePath = download.getTo(); + + Log.d(TAG, "^ Downloading: " + url); + Log.d(TAG, "^ To : " + filePath); + + if (createDirStructure(filePath)) { + connection = url.openConnection(); + connection.connect(); + final int contentLength = connection.getContentLength(); + + // download the file + is = new BufferedInputStream(url.openStream()); + os = new FileOutputStream(filePath); + + final byte data[] = new byte[1024]; + + long total = 0; + + while ((count = is.read(data)) != -1) { + total += count; + // The first number is the current file + // The second is the total number of files to download + // The third is the current progress + publishProgress(downloadCounter + 1, downloadables.length, (int) (total * 100 / contentLength)); + os.write(data, 0, count); + } + + os.flush(); + os.close(); + is.close(); + } else { + Log.e(TAG, "^ Failed to create directory structure"); + bOK = false; + } + } catch (IOException e) { + Log.e(TAG, "^ Error while downloading.", e); + bOK = false; + e.printStackTrace(); + } + + downloadCounter += 1; + } + + return bOK; + } + + private boolean createDirStructure(final String filePath) { + final File file = new File(filePath); + final File parent = file.getParentFile(); + + final boolean createFile; + + if (parent.exists()) { + createFile = false; + } else { + createFile = true; + } + + Log.d(TAG, "^ Need to create path for '" + file.getAbsolutePath() + "'? " + createFile); + + if (createFile) { + Log.d(TAG, "^ Creating path for: " + file.getAbsolutePath()); + return parent.mkdirs(); + } else { + return true; + } + } + + @Override + protected void onPostExecute(Boolean result) { + + if (result) { // The download is ok. + NotifyUser.notify(context, R.string.download_ok); + } else { // There was an error. + NotifyUser.notify(context, R.string.download_error); + } + + progressDialogControl.dismiss(); + } + + @Override + protected void onPreExecute() { + progressDialogControl.show(); + } + + @Override + public void onProgressUpdate(Integer... args) { + Object[] testArgs = {args[0], args[1]}; + progressDialogControl.updateProgress(form.format(testArgs), args[2]); + } + + public static class Downloadable { + private final String from; + private final String to; + + public Downloadable(String from, String to) { + this.from = from; + this.to = to; + } + + public String getFrom() { + return from; + } + + public String getTo() { + return to; + } + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/main/AboutDialogFactory.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/main/AboutDialogFactory.java new file mode 100644 index 0000000..974c546 --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/main/AboutDialogFactory.java @@ -0,0 +1,65 @@ +package aws.apps.usbDeviceEnumerator.ui.main; + +import android.app.Activity; +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.support.v7.app.AlertDialog; +import android.text.SpannableString; +import android.text.method.LinkMovementMethod; +import android.text.util.Linkify; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.TextView; + +import aws.apps.usbDeviceEnumerator.BuildConfig; +import aws.apps.usbDeviceEnumerator.R; + + +/*package*/ final class AboutDialogFactory { + + private AboutDialogFactory() { + // NOOP + } + + private static String constructAboutText(final Context context) { + String title = context.getString(R.string.app_name) + " v" + BuildConfig.VERSION_NAME; + + final StringBuilder sb = new StringBuilder(); + + sb.append(context.getString(R.string.app_changelog)); + sb.append("\n\n"); + sb.append(context.getString(R.string.app_notes)); + sb.append("\n\n"); + sb.append(context.getString(R.string.app_acknowledgements)); + sb.append("\n\n"); + sb.append(context.getString(R.string.app_copyright)); + + return sb.toString(); + } + + public static Dialog createAboutDialog(final Context context) { + final View view = LayoutInflater.from(context).inflate(R.layout.dialog_textview, null); + final TextView textView = (TextView) view.findViewById(R.id.text); + + final SpannableString text = new SpannableString(constructAboutText(context)); + + textView.setText(text); + textView.setAutoLinkMask(Activity.RESULT_OK); + textView.setMovementMethod(LinkMovementMethod.getInstance()); + + Linkify.addLinks(text, Linkify.ALL); + + final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { + public void onClick(final DialogInterface dialog, final int id) { + } + }; + + return new AlertDialog.Builder(context) + .setTitle(R.string.label_menu_about) + .setCancelable(false) + .setPositiveButton(android.R.string.ok, listener) + .setView(view) + .create(); + } +} \ No newline at end of file diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/main/MainActivity.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/main/MainActivity.java new file mode 100644 index 0000000..b4e3339 --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/main/MainActivity.java @@ -0,0 +1,220 @@ +/******************************************************************************* + * Copyright 2011 Alexandros Schillings + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package aws.apps.usbDeviceEnumerator.ui.main; + +import android.content.Context; +import android.hardware.usb.UsbDevice; +import android.hardware.usb.UsbManager; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.ArrayAdapter; +import android.widget.ListAdapter; +import android.widget.ListView; +import android.widget.TextView; + +import java.io.File; +import java.util.Arrays; +import java.util.Map; + +import aws.apps.usbDeviceEnumerator.R; +import aws.apps.usbDeviceEnumerator.data.DataProviderCompanyInfo; +import aws.apps.usbDeviceEnumerator.data.DataProviderCompanyLogo; +import aws.apps.usbDeviceEnumerator.data.DataProviderUsbInfo; +import aws.apps.usbDeviceEnumerator.ui.common.DialogFactory; +import aws.apps.usbDeviceEnumerator.ui.common.Navigation; +import aws.apps.usbDeviceEnumerator.ui.dbupdate.DatabaseUpdater; +import aws.apps.usbDeviceEnumerator.ui.main.tabs.TabController; +import aws.apps.usbDeviceEnumerator.ui.main.tabs.TabViewHolder; +import aws.apps.usbDeviceEnumerator.ui.progress.ProgressDialogControl; +import aws.apps.usbDeviceEnumerator.ui.usbinfo.InfoFragmentFactory; +import uk.co.alt236.usbdeviceenumerator.sysbususb.SysBusUsbDevice; +import uk.co.alt236.usbdeviceenumerator.sysbususb.SysBusUsbManager; + +public class MainActivity extends AppCompatActivity { + final String TAG = this.getClass().getName(); + + private UsbManager mUsbManAndroid; + private SysBusUsbManager mUsbManagerLinux; + + private DataProviderUsbInfo mDbUsb; + private DataProviderCompanyInfo mDbComp; + private DataProviderCompanyLogo mZipComp; + + private Map mAndroidDeviceMap; + private Map mLinuxDeviceMap; + + private ProgressDialogControl progressDialogControl; + private Navigation mNavigation; + + private TabController mTabController; + + private void checkIfDbPresent() { + // Prompt user to DL db if it is missing. + if (!new File(mDbUsb.getDataFilePath()).exists()) { + DialogFactory.createOkDialog(this, + R.string.alert_db_not_found_title, + R.string.alert_db_not_found_instructions) + .show(); + Log.w(TAG, "^ Database not found: " + mDbUsb.getDataFilePath()); + } + } + + /** + * Called when the activity is first created. + */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.act_main); + mTabController = new TabController(this); + mNavigation = new Navigation(this); + + mUsbManAndroid = (UsbManager) getSystemService(Context.USB_SERVICE); + mUsbManagerLinux = new SysBusUsbManager(); + + mDbUsb = new DataProviderUsbInfo(this); + mDbComp = new DataProviderCompanyInfo(this); + mZipComp = new DataProviderCompanyLogo(this); + + mTabController.setup(new TabController.OnTabChangeListener() { + @Override + public void onTabChangeListener(String tag, TabViewHolder holder) { + onTabChanged(tag, holder); + } + }); + + // Setup android list - tab1; + mTabController.getHolderForTag(TabController.TAB_ANDROID_INFO) + .getList().setOnItemClickListener(new OnItemClickListener() { + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + ((ListView) parent).setItemChecked(position, true); + mNavigation.showAndroidUsbDeviceInfo(((TextView) view).getText().toString()); + } + }); + + + // Setup linux list - tab2 + mTabController.getHolderForTag(TabController.TAB_LINUX_INFO) + .getList().setOnItemClickListener(new OnItemClickListener() { + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + ((ListView) parent).setItemChecked(position, true); + mNavigation.showLinuxUsbDeviceInfo(mLinuxDeviceMap.get(((TextView) view).getText().toString())); + } + }); + + + checkIfDbPresent(); + refreshUsbDevices(); + } + + /** + * Creates the menu items + */ + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.main_menu, menu); + return super.onCreateOptionsMenu(menu); + } + + /** + * Handles item selections + */ + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_about: + AboutDialogFactory.createAboutDialog(this).show(); + return true; + case R.id.menu_update_db: + final ProgressDialogControl control = new ProgressDialogControl(getSupportFragmentManager()); + final DatabaseUpdater databaseUpdater = new DatabaseUpdater(control, mDbComp, mDbUsb, mZipComp); + + databaseUpdater.start(this); + return true; + case R.id.menu_refresh: + refreshUsbDevices(); + return true; + } + + return false; + } + + private void onTabChanged(String tabId, TabViewHolder tabViewHolder) { + if (mNavigation.isSmallScreen()) { + return; + } + + final ListView listView = tabViewHolder.getList(); + final int checkedItemPosition = listView.getCheckedItemPosition(); + final Fragment fragment; + + if (checkedItemPosition == ListView.INVALID_POSITION) { + fragment = null; + } else { + final String text = (String) listView.getItemAtPosition(checkedItemPosition); + + switch (tabId) { + case TabController.TAB_ANDROID_INFO: + fragment = InfoFragmentFactory.getFragment(text); + break; + case TabController.TAB_LINUX_INFO: + fragment = InfoFragmentFactory.getFragment(mLinuxDeviceMap.get(text)); + break; + default: + fragment = null; + break; + } + } + + if (fragment == null) { + mNavigation.removeFragmentsFromContainer(); + } else { + mNavigation.stackFragment(fragment); + } + } + + + private void refreshUsbDevices() { + mAndroidDeviceMap = mUsbManAndroid.getDeviceList(); + mLinuxDeviceMap = mUsbManagerLinux.getUsbDevices(); + + updateList(mTabController.getHolderForTag(TabController.TAB_ANDROID_INFO), mAndroidDeviceMap); + updateList(mTabController.getHolderForTag(TabController.TAB_LINUX_INFO), mLinuxDeviceMap); + } + + private void updateList(final TabViewHolder holder, final Map map) { + final String[] array = map.keySet().toArray(new String[map.keySet().size()]); + + Arrays.sort(array); + + final ListAdapter adapter = new ArrayAdapter<>(getApplicationContext(), R.layout.list_item, array); + holder.getList().setAdapter(adapter); + + final String count = getString(R.string.text_number_of_devices, array.length); + holder.getCount().setText(count); + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/main/tabs/TabController.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/main/tabs/TabController.java new file mode 100644 index 0000000..1bc51ed --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/main/tabs/TabController.java @@ -0,0 +1,91 @@ +package aws.apps.usbDeviceEnumerator.ui.main.tabs; + +import android.app.Activity; +import android.support.design.widget.TabLayout; +import android.support.v4.view.ViewPager; +import android.view.LayoutInflater; +import android.view.View; + +import aws.apps.usbDeviceEnumerator.R; +import butterknife.BindView; +import butterknife.ButterKnife; + +public class TabController { + public final static String TAB_ANDROID_INFO = "tab_android"; + public final static String TAB_LINUX_INFO = "tab_linux"; + + private static final int[] TAB_LABELS = {R.string.label_tab_api, R.string.label_tab_linux}; + private static final String[] TAB_TAGS = {TAB_ANDROID_INFO, TAB_LINUX_INFO}; + + private final Activity activity; + + @BindView(R.id.tabs) + protected TabLayout tabLayout; + + @BindView(R.id.pager) + protected ViewPager viewPager; + + private TabViewHolder[] tabViewHolders; + + public TabController(final Activity activity) { + ButterKnife.bind(this, activity); + this.activity = activity; + } + + public void setup(final OnTabChangeListener listener) { + // These should really be fragments + + final View[] pages = createPages(); + final TabPagerAdapter adapter = new TabPagerAdapter(activity, pages, TAB_LABELS, TAB_TAGS); + + viewPager.setOffscreenPageLimit(3); + viewPager.setAdapter(adapter); + tabLayout.setupWithViewPager(viewPager); + + viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + // NOOP + } + + @Override + public void onPageSelected(int position) { + final String tag = adapter.getTabTag(position); + final TabViewHolder holder = tabViewHolders[position]; + + listener.onTabChangeListener(tag, holder); + } + + @Override + public void onPageScrollStateChanged(int state) { + // NOOP + } + }); + } + + private View[] createPages() { + final View[] views = new View[TAB_TAGS.length]; + tabViewHolders = new TabViewHolder[TAB_TAGS.length]; + + for (int i = 0; i < TAB_TAGS.length; i++) { + views[i] = LayoutInflater.from(activity).inflate(R.layout.tab_device_list, viewPager, false); + tabViewHolders[i] = new TabViewHolder(views[i]); + } + + return views; + } + + public TabViewHolder getHolderForTag(final String tag) { + for (int i = 0; i < TAB_TAGS.length; i++) { + if (TAB_TAGS[i].equals(tag)) { + return tabViewHolders[i]; + } + } + + return null; + } + + public interface OnTabChangeListener { + void onTabChangeListener(final String tag, final TabViewHolder holder); + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/main/tabs/TabPagerAdapter.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/main/tabs/TabPagerAdapter.java new file mode 100644 index 0000000..33d1bf8 --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/main/tabs/TabPagerAdapter.java @@ -0,0 +1,55 @@ +package aws.apps.usbDeviceEnumerator.ui.main.tabs; + +import android.content.Context; +import android.support.v4.view.PagerAdapter; +import android.view.View; +import android.view.ViewGroup; + +/*package*/ class TabPagerAdapter extends PagerAdapter { + + private final Context context; + private final int[] labels; + private final String[] tabTags; + private final View[] pages; + + public TabPagerAdapter(final Context context, + final View[] pages, + final int[] labels, + final String[] tabTags) { + this.context = context.getApplicationContext(); + this.labels = labels; + this.tabTags = tabTags; + this.pages = pages; + } + + @Override + public Object instantiateItem(ViewGroup collection, int position) { + collection.addView(pages[position], 0); + return pages[position]; + } + + @Override + public void destroyItem(ViewGroup collection, int position, Object view) { + collection.removeView((View) view); + } + + @Override + public int getCount() { + return pages.length; + } + + @Override + public boolean isViewFromObject(View view, Object object) { + return view == object; + } + + @Override + public CharSequence getPageTitle(int position) { + return context.getText(labels[position]); + } + + public String getTabTag(final int position) { + return tabTags[position]; + } + +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/main/tabs/TabViewHolder.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/main/tabs/TabViewHolder.java new file mode 100644 index 0000000..a9612fb --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/main/tabs/TabViewHolder.java @@ -0,0 +1,36 @@ +package aws.apps.usbDeviceEnumerator.ui.main.tabs; + +import android.view.View; +import android.widget.ListView; +import android.widget.TextView; + +import aws.apps.usbDeviceEnumerator.R; +import butterknife.BindView; +import butterknife.ButterKnife; + +public class TabViewHolder { + + private final View rootView; + @BindView(android.R.id.list) + protected ListView list; + @BindView(android.R.id.empty) + protected View empty; + @BindView(R.id.count) + protected TextView count; + + public TabViewHolder(final View rootView) { + ButterKnife.bind(this, rootView); + + this.rootView = rootView; + this.list.setEmptyView(empty); + this.list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); + } + + public ListView getList() { + return list; + } + + public TextView getCount() { + return count; + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/progress/ProgressDialogControl.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/progress/ProgressDialogControl.java new file mode 100644 index 0000000..d9c7e80 --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/progress/ProgressDialogControl.java @@ -0,0 +1,61 @@ +package aws.apps.usbDeviceEnumerator.ui.progress; + +import android.support.v4.app.DialogFragment; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; +import android.util.Log; + +import aws.apps.usbDeviceEnumerator.R; + +public class ProgressDialogControl { + private static final String TAG = ProgressDialogControl.class.getSimpleName(); + private static final String DIALOG_FRAGMENT_TAG = "progress_dialog"; + + private final FragmentManager fragmentManager; + + public ProgressDialogControl(final FragmentManager fragmentManager) { + this.fragmentManager = fragmentManager; + } + + public void dismiss() { + Log.d(TAG, "^ Dimissing Fragment : " + DIALOG_FRAGMENT_TAG); + + DialogFragment dialog = (DialogFragment) fragmentManager.findFragmentByTag(DIALOG_FRAGMENT_TAG); + if (dialog != null) { + Log.d(TAG, "^ Dismissing Fragment!"); + dialog.dismissAllowingStateLoss(); + } + } + + public void updateProgress(final String title, + final Integer progress) { + + DialogFragment dialogFragment = (DialogFragment) fragmentManager.findFragmentByTag(DIALOG_FRAGMENT_TAG); + if (dialogFragment != null) { + if (title != null) { + ((ProgressDialogFragment) dialogFragment).setTitle(title); + } + if (progress != null) { + ((ProgressDialogFragment) dialogFragment).setProgress(progress); + } + } + } + + public void show() { + final FragmentTransaction ft = fragmentManager.beginTransaction(); + final Fragment prev = fragmentManager.findFragmentByTag(DIALOG_FRAGMENT_TAG); + + if (prev != null) { + ft.remove(prev); + } + + ft.addToBackStack(null); + + final DialogFragment newFragment + = ProgressDialogFragment.newInstance(R.string.text_downloading_files, null); + + ft.add(newFragment, DIALOG_FRAGMENT_TAG); + ft.commitAllowingStateLoss(); + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/fragments/ProgressDialogFragment.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/progress/ProgressDialogFragment.java similarity index 83% rename from app/src/main/java/aws/apps/usbDeviceEnumerator/fragments/ProgressDialogFragment.java rename to app/src/main/java/aws/apps/usbDeviceEnumerator/ui/progress/ProgressDialogFragment.java index ea02ceb..54aef7c 100644 --- a/app/src/main/java/aws/apps/usbDeviceEnumerator/fragments/ProgressDialogFragment.java +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/progress/ProgressDialogFragment.java @@ -1,23 +1,21 @@ -package aws.apps.usbDeviceEnumerator.fragments; +package aws.apps.usbDeviceEnumerator.ui.progress; import android.app.Dialog; -import android.app.DialogFragment; import android.app.ProgressDialog; import android.os.Bundle; +import android.support.v4.app.DialogFragment; public class ProgressDialogFragment extends DialogFragment { - public static ProgressDialogFragment newInstance(String title, String message) { + protected static ProgressDialogFragment newInstance(int title, String message) { ProgressDialogFragment frag = new ProgressDialogFragment(); Bundle args = new Bundle(); - args.putString("title", title); + args.putInt("title", title); args.putString("message", message); frag.setArguments(args); return frag; } - ; - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -26,7 +24,7 @@ public void onCreate(Bundle savedInstanceState) { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - String title = getArguments().getString("title"); + int title = getArguments().getInt("title"); String message = getArguments().getString("message"); ProgressDialog dialog = new ProgressDialog(getActivity()); @@ -47,7 +45,7 @@ public void setMessage(String message) { } public void setTitle(String message) { - ((ProgressDialog) this.getDialog()).setTitle(message); + (this.getDialog()).setTitle(message); } public void setProgress(int progress) { diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/AndroidUsbInfoFragment.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/AndroidUsbInfoFragment.java new file mode 100644 index 0000000..9aa6c52 --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/AndroidUsbInfoFragment.java @@ -0,0 +1,197 @@ +/******************************************************************************* + * Copyright 2011 Alexandros Schillings + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package aws.apps.usbDeviceEnumerator.ui.usbinfo; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; +import android.hardware.usb.UsbDevice; +import android.hardware.usb.UsbEndpoint; +import android.hardware.usb.UsbInterface; +import android.hardware.usb.UsbManager; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TableLayout; +import android.widget.TextView; + +import aws.apps.usbDeviceEnumerator.R; +import aws.apps.usbDeviceEnumerator.data.DataProviderCompanyInfo; +import aws.apps.usbDeviceEnumerator.data.DataProviderCompanyLogo; +import aws.apps.usbDeviceEnumerator.data.DataProviderUsbInfo; +import uk.co.alt236.usbdeviceenumerator.UsbConstants; + +public class AndroidUsbInfoFragment extends BaseInfoFragment { + public final static int TYPE_ANDROID_INFO = 0; + public final static int TYPE_LINUX_INFO = 1; + public final static String DEFAULT_STRING = "???"; + private final static String EXTRA_DATA = AndroidUsbInfoFragment.class.getName() + ".BUNDLE_DATA"; + private static final int LAYOUT_ID = R.layout.fragment_usb_info; + + private final String TAG = this.getClass().getName(); + private String usbKey = DEFAULT_STRING; + private InfoViewHolder viewHolder; + private UsbManager usbMan; + private DataFetcher dataFetcher; + private UsbDevice device; + private boolean validData; + + public static Fragment create(final String usbKey) { + final Fragment fragment = new AndroidUsbInfoFragment(); + final Bundle bundle = new Bundle(); + bundle.putString(EXTRA_DATA, usbKey); + fragment.setArguments(bundle); + return fragment; + } + + @Override + public void onAttach(final Context context) { + super.onAttach(context); + + usbMan = (UsbManager) getContext().getSystemService(Context.USB_SERVICE); + dataFetcher = new DataFetcher( + new DataProviderCompanyInfo(context), + new DataProviderUsbInfo(context), + new DataProviderCompanyLogo(context)); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saved) { + usbKey = getArguments().getString(EXTRA_DATA, DEFAULT_STRING); + device = usbMan.getDeviceList().get(usbKey); + + final View view; + + if (usbKey == null || device == null) { + view = inflater.inflate(R.layout.fragment_error, container, false); + validData = false; + } else { + view = inflater.inflate(LAYOUT_ID, container, false); + validData = true; + } + + return view; + } + + @Override + public void onViewCreated(View view, Bundle bundle) { + super.onViewCreated(view, bundle); + viewHolder = new InfoViewHolder(view); + + usbKey = getArguments().getString(EXTRA_DATA, DEFAULT_STRING); + + + if (validData) { + viewHolder = new InfoViewHolder(view); + populateDataTable(LayoutInflater.from(getContext())); + } else { + final TextView textView = (TextView) view.findViewById(R.id.errorText); + if (usbKey == null) { + textView.setText(R.string.error_loading_device_info_unknown); + } else { + textView.setText(R.string.error_loading_device_info_device_disconnected); + } + } + } + + private void populateDataTable(LayoutInflater inflater) { + final String vid = CommonLogic.padLeft(Integer.toHexString(device.getVendorId()), "0", 4); + final String pid = CommonLogic.padLeft(Integer.toHexString(device.getDeviceId()), "0", 4); + final String deviceClass = UsbConstants.resolveUsbClass(device.getDeviceClass()); + + viewHolder.getLogo().setImageResource(R.drawable.no_image); + + viewHolder.getVid().setText(vid); + viewHolder.getPid().setText(pid); + viewHolder.getDevicePath().setText(usbKey); + viewHolder.getDeviceClass().setText(deviceClass); + + viewHolder.getReportedVendor().setText("n/a"); + viewHolder.getReportedProduct().setText("n/a"); + + UsbInterface iFace; + for (int i = 0; i < device.getInterfaceCount(); i++) { + iFace = device.getInterface(i); + if (iFace != null) { + final TableLayout bottomTable = viewHolder.getBottomTable(); + final String usbClass = UsbConstants.resolveUsbClass((iFace.getInterfaceClass())); + + CommonLogic.addDataRow(inflater, bottomTable, getString(R.string.interface_) + i, ""); + CommonLogic.addDataRow(inflater, bottomTable, getString(R.string.class_), usbClass); + + if (iFace.getEndpointCount() > 0) { + String endpointText; + for (int j = 0; j < iFace.getEndpointCount(); j++) { + endpointText = getEndpointText(iFace.getEndpoint(j), j); + CommonLogic.addDataRow(inflater, bottomTable, getString(R.string.endpoint_), endpointText); + } + } else { + CommonLogic.addDataRow(inflater, bottomTable, "\tEndpoints:", "none"); + } + } + } + + loadAsyncData(vid, pid, null); + } + + private String getEndpointText(final UsbEndpoint endpoint, final int index) { + final String addressInBinary = CommonLogic.padLeft(Integer.toBinaryString(endpoint.getAddress()), "0", 8); + + String endpointText = "#" + index + "\n"; + endpointText += getString(R.string.address_) + endpoint.getAddress() + " (" + addressInBinary + ")\n"; + endpointText += getString(R.string.number_) + endpoint.getEndpointNumber() + "\n"; + endpointText += getString(R.string.direction_) + UsbConstants.resolveUsbEndpointDirection(endpoint.getDirection()) + "\n"; + endpointText += getString(R.string.type_) + UsbConstants.resolveUsbEndpointType(endpoint.getType()) + "\n"; + endpointText += getString(R.string.poll_interval_) + endpoint.getInterval() + "\n"; + endpointText += getString(R.string.max_packet_size_) + endpoint.getMaxPacketSize() + "\n"; + endpointText += getString(R.string.attributes_) + CommonLogic.padLeft(Integer.toBinaryString(endpoint.getAttributes()), "0", 8); + + return endpointText; + } + + private void loadAsyncData(String vid, String pid, String reportedVendorName) { + dataFetcher.fetchData(vid, pid, reportedVendorName, new DataFetcher.Callback() { + @Override + public void onSuccess(final String vendorFromDb, + final String productFromDb, + final Bitmap bitmap) { + + if (isAdded() && getActivity() != null && getView() != null) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + viewHolder.getVendorFromDb().setText(vendorFromDb); + viewHolder.getProductFromDb().setText(productFromDb); + if (bitmap != null) { + final BitmapDrawable drawable = new BitmapDrawable(getContext().getResources(), bitmap); + viewHolder.getLogo().setImageDrawable(drawable); + } else { + viewHolder.getLogo().setImageResource(R.drawable.no_image); + } + } + }); + } + } + }); + } + + @Override + public String getSharePayload() { + return CommonLogic.getSharePayload(viewHolder); + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/fragments/AbstractUsbDeviceInfoFragment.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/BaseInfoFragment.java similarity index 75% rename from app/src/main/java/aws/apps/usbDeviceEnumerator/fragments/AbstractUsbDeviceInfoFragment.java rename to app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/BaseInfoFragment.java index 05450e2..8f79b32 100644 --- a/app/src/main/java/aws/apps/usbDeviceEnumerator/fragments/AbstractUsbDeviceInfoFragment.java +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/BaseInfoFragment.java @@ -13,22 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ -package aws.apps.usbDeviceEnumerator.fragments; +package aws.apps.usbDeviceEnumerator.ui.usbinfo; -import android.app.Fragment; import android.os.Bundle; +import android.support.v4.app.Fragment; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import aws.apps.usbDeviceEnumerator.R; -import aws.apps.usbDeviceEnumerator.util.UsefulBits; -public abstract class AbstractUsbDeviceInfoFragment extends Fragment { - public final static int TYPE_ANDROID_INFO = 0; - public final static int TYPE_LINUX_INFO = 1; - - public abstract int getType(); +/*package*/ abstract class BaseInfoFragment extends Fragment { @Override public void onCreate(Bundle saved) { @@ -40,18 +35,20 @@ public void onCreate(Bundle saved) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.frag_menu, menu); super.onCreateOptionsMenu(menu, inflater); - } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_export: - UsefulBits.share(getActivity(), "USB Info", this.toString()); + ShareUtils.share( + getActivity(), + getString(R.string.app_name), + getSharePayload()); return true; } - return false; + return super.onOptionsItemSelected(item); } - public abstract String toString(); + public abstract String getSharePayload(); } diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/CommonLogic.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/CommonLogic.java new file mode 100644 index 0000000..f46ec2a --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/CommonLogic.java @@ -0,0 +1,38 @@ +package aws.apps.usbDeviceEnumerator.ui.usbinfo; + +import android.view.LayoutInflater; +import android.widget.TableLayout; +import android.widget.TableRow; +import android.widget.TextView; + +import aws.apps.usbDeviceEnumerator.R; + +/*package*/ class CommonLogic { + private static final String TAG = CommonLogic.class.getSimpleName(); + + public static void addDataRow(LayoutInflater inflater, TableLayout tlb, String cell1Text, String cell2Text) { + final TableRow row = (TableRow) inflater.inflate(R.layout.usb_table_row_data, null); + final TextView tv1 = (TextView) row.findViewById(R.id.usb_tablerow_cell1); + final TextView tv2 = (TextView) row.findViewById(R.id.usb_tablerow_cell2); + tv1.setText(cell1Text); + tv2.setText(cell2Text); + tlb.addView(row); + } + + public static String padLeft(String string, String padding, int size) { + String pad = ""; + while ((pad + string).length() < size) { + pad += padding + pad; + } + return pad + string; + } + + public static String getSharePayload(final InfoViewHolder holder) { + final StringBuilder sb = new StringBuilder(); + sb.append(ShareUtils.tableToString(holder.getHeaderTable())); + sb.append(ShareUtils.tableToString(holder.getTopTable())); + sb.append('\n'); + sb.append(ShareUtils.tableToString(holder.getBottomTable())); + return sb.toString(); + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/DataFetcher.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/DataFetcher.java new file mode 100644 index 0000000..10dc472 --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/DataFetcher.java @@ -0,0 +1,73 @@ +package aws.apps.usbDeviceEnumerator.ui.usbinfo; + +import android.graphics.Bitmap; +import android.text.TextUtils; + +import aws.apps.usbDeviceEnumerator.data.DataProviderCompanyInfo; +import aws.apps.usbDeviceEnumerator.data.DataProviderCompanyLogo; +import aws.apps.usbDeviceEnumerator.data.DataProviderUsbInfo; + +/*package*/ class DataFetcher { + + private final DataProviderCompanyInfo dbComp; + private final DataProviderUsbInfo dbUsb; + private final DataProviderCompanyLogo zipComp; + + public DataFetcher(DataProviderCompanyInfo dbComp, DataProviderUsbInfo dbUsb, DataProviderCompanyLogo zipComp) { + this.dbComp = dbComp; + this.dbUsb = dbUsb; + this.zipComp = zipComp; + } + + public void fetchData(final String vid, + final String pid, + final String reportedVendorName, + final Callback callback) { + + final Runnable runnable = new Runnable() { + @Override + public void run() { + final String vendorFromDb; + final String productFromDb; + final Bitmap bitmap; + + if (dbUsb.isDataAvailable()) { + vendorFromDb = dbUsb.getVendorName(vid); + productFromDb = dbUsb.getProductName(vid, pid); + + if (dbComp.isDataAvailable()) { + final String searchFor; + + if (!TextUtils.isEmpty(vendorFromDb)) { + searchFor = vendorFromDb; + } else { + searchFor = reportedVendorName; + } + + final String logo = dbComp.getLogoName(searchFor); + bitmap = zipComp.getLogoBitmap(logo); + } else { + bitmap = null; + } + } else { + vendorFromDb = null; + productFromDb = null; + bitmap = null; + } + + callback.onSuccess(vendorFromDb, productFromDb, bitmap); + + } + }; + + final Thread thread = new Thread(runnable); + thread.start(); + } + + public interface Callback { + + void onSuccess(String vendorFromDb, String productFromDb, Bitmap bitmap); + + } + +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/InfoFragmentFactory.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/InfoFragmentFactory.java new file mode 100644 index 0000000..2c7da5a --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/InfoFragmentFactory.java @@ -0,0 +1,16 @@ +package aws.apps.usbDeviceEnumerator.ui.usbinfo; + +import android.support.v4.app.Fragment; + +import uk.co.alt236.usbdeviceenumerator.sysbususb.SysBusUsbDevice; + +public final class InfoFragmentFactory { + + public static Fragment getFragment(String usbKey) { + return AndroidUsbInfoFragment.create(usbKey); + } + + public static Fragment getFragment(SysBusUsbDevice usbDevice) { + return LinuxUsbInfoFragment.create(usbDevice); + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/InfoViewHolder.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/InfoViewHolder.java new file mode 100644 index 0000000..221e3a3 --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/InfoViewHolder.java @@ -0,0 +1,87 @@ +package aws.apps.usbDeviceEnumerator.ui.usbinfo; + +import android.view.View; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.TableLayout; +import android.widget.TextView; + +import aws.apps.usbDeviceEnumerator.R; + +/*package*/ class InfoViewHolder { + private final TableLayout tblUsbInfoHeader; + private final TableLayout tblUsbInfoTop; + private final TableLayout tblUsbInfoBottom; + private final TextView tvVID; + private final TextView tvPID; + private final TextView tvVendorReported; + private final TextView tvProductReported; + private final TextView tvVendorDb; + private final TextView tvProductDb; + private final TextView tvDevicePath; + private final TextView tvDeviceClass; + private final ImageButton logo; + + public InfoViewHolder(final View rootView) { + tblUsbInfoHeader = (TableLayout) rootView.findViewById(R.id.tblUsbInfo_title); + tblUsbInfoTop = (TableLayout) rootView.findViewById(R.id.tblUsbInfo_top); + tblUsbInfoBottom = (TableLayout) rootView.findViewById(R.id.tblUsbInfo_bottom); + tvVID = ((TextView) rootView.findViewById(R.id.tvVID)); + tvPID = ((TextView) rootView.findViewById(R.id.tvPID)); + tvProductDb = ((TextView) rootView.findViewById(R.id.tvProductDb)); + tvVendorDb = ((TextView) rootView.findViewById(R.id.tvVendorDb)); + tvProductReported = ((TextView) rootView.findViewById(R.id.tvProductReported)); + tvVendorReported = ((TextView) rootView.findViewById(R.id.tvVendorReported)); + tvDevicePath = ((TextView) rootView.findViewById(R.id.tvDevicePath)); + tvDeviceClass = ((TextView) rootView.findViewById(R.id.tvDeviceClass)); + logo = (ImageButton) rootView.findViewById(R.id.btnLogo); + } + + public ImageView getLogo() { + return logo; + } + + public TableLayout getHeaderTable() { + return tblUsbInfoHeader; + } + + public TableLayout getTopTable() { + return tblUsbInfoTop; + } + + public TableLayout getBottomTable() { + return tblUsbInfoBottom; + } + + public TextView getPid() { + return tvPID; + } + + public TextView getVid() { + return tvVID; + } + + public TextView getDevicePath() { + return tvDevicePath; + } + + public TextView getDeviceClass() { + return tvDeviceClass; + } + + public TextView getProductFromDb() { + return tvProductDb; + } + + public TextView getVendorFromDb() { + return tvVendorDb; + } + + public TextView getReportedProduct() { + return tvProductReported; + } + + public TextView getReportedVendor() { + return tvVendorReported; + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/LinuxUsbInfoFragment.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/LinuxUsbInfoFragment.java new file mode 100644 index 0000000..d81272a --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/LinuxUsbInfoFragment.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * Copyright 2011 Alexandros Schillings + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package aws.apps.usbDeviceEnumerator.ui.usbinfo; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TableLayout; +import android.widget.TextView; + +import aws.apps.usbDeviceEnumerator.R; +import aws.apps.usbDeviceEnumerator.data.DataProviderCompanyInfo; +import aws.apps.usbDeviceEnumerator.data.DataProviderCompanyLogo; +import aws.apps.usbDeviceEnumerator.data.DataProviderUsbInfo; +import uk.co.alt236.usbdeviceenumerator.UsbConstants; +import uk.co.alt236.usbdeviceenumerator.sysbususb.SysBusUsbDevice; + +public class LinuxUsbInfoFragment extends BaseInfoFragment { + public final static String DEFAULT_STRING = "???"; + private final static String EXTRA_DATA = LinuxUsbInfoFragment.class.getName() + ".BUNDLE_DATA"; + private static final int LAYOUT_ID = R.layout.fragment_usb_info; + private final String TAG = this.getClass().getName(); + private SysBusUsbDevice device; + private boolean validData; + + private InfoViewHolder viewHolder; + private DataFetcher dataFetcher; + + public static Fragment create(final SysBusUsbDevice usbDevice) { + final Fragment fragment = new LinuxUsbInfoFragment(); + final Bundle bundle = new Bundle(); + bundle.putParcelable(EXTRA_DATA, usbDevice); + fragment.setArguments(bundle); + return fragment; + } + + @Override + public void onAttach(final Context context) { + super.onAttach(context); + dataFetcher = new DataFetcher( + new DataProviderCompanyInfo(context), + new DataProviderUsbInfo(context), + new DataProviderCompanyLogo(context)); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saved) { + device = getArguments().getParcelable(EXTRA_DATA); + final View view; + + if (device == null) { + view = inflater.inflate(R.layout.fragment_error, container, false); + validData = false; + } else { + view = inflater.inflate(LAYOUT_ID, container, false); + validData = true; + } + + return view; + } + + @Override + public void onViewCreated(View view, Bundle bundle) { + super.onViewCreated(view, bundle); + + if (validData) { + viewHolder = new InfoViewHolder(view); + populateDataTable(LayoutInflater.from(getContext())); + } else { + final TextView textView = (TextView) view.findViewById(R.id.errorText); + textView.setText(R.string.error_loading_device_info_unknown); + } + } + + private void populateDataTable(LayoutInflater inflater) { + final String vid = CommonLogic.padLeft(device.getVID(), "0", 4); + final String pid = CommonLogic.padLeft(device.getPID(), "0", 4); + final String deviceClass = UsbConstants.resolveUsbClass(device.getDeviceClass()); + + viewHolder.getLogo().setImageResource(R.drawable.no_image); + + viewHolder.getVid().setText(vid); + viewHolder.getPid().setText(pid); + viewHolder.getDevicePath().setText(device.getDevicePath()); + viewHolder.getDeviceClass().setText(deviceClass); + + viewHolder.getReportedVendor().setText(device.getReportedVendorName()); + viewHolder.getReportedProduct().setText(device.getReportedProductName()); + + final TableLayout bottomTable = viewHolder.getBottomTable(); + CommonLogic.addDataRow(inflater, bottomTable, getString(R.string.usb_version_), device.getUsbVersion()); + CommonLogic.addDataRow(inflater, bottomTable, getString(R.string.speed_), device.getSpeed()); + CommonLogic.addDataRow(inflater, bottomTable, getString(R.string.protocol_), device.getDeviceProtocol()); + CommonLogic.addDataRow(inflater, bottomTable, getString(R.string.maximum_power_), device.getMaxPower()); + CommonLogic.addDataRow(inflater, bottomTable, getString(R.string.serial_number_), device.getSerialNumber()); + + loadAsyncData(vid, pid, device.getReportedVendorName()); + } + + private void loadAsyncData(String vid, String pid, String reportedVendorName) { + dataFetcher.fetchData(vid, pid, reportedVendorName, new DataFetcher.Callback() { + @Override + public void onSuccess(final String vendorFromDb, + final String productFromDb, + final Bitmap bitmap) { + + if (isAdded() && getActivity() != null && getView() != null) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + viewHolder.getVendorFromDb().setText(vendorFromDb); + viewHolder.getProductFromDb().setText(productFromDb); + if (bitmap != null) { + final BitmapDrawable drawable = new BitmapDrawable(getContext().getResources(), bitmap); + viewHolder.getLogo().setImageDrawable(drawable); + } else { + viewHolder.getLogo().setImageResource(R.drawable.no_image); + } + } + }); + } + } + }); + } + + @Override + public String getSharePayload() { + return CommonLogic.getSharePayload(viewHolder); + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/ShareUtils.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/ShareUtils.java new file mode 100644 index 0000000..0fe8c03 --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/ShareUtils.java @@ -0,0 +1,62 @@ +package aws.apps.usbDeviceEnumerator.ui.usbinfo; + +import android.app.Activity; +import android.content.Intent; +import android.support.v4.app.ActivityCompat; +import android.util.Log; +import android.view.View; +import android.widget.TableLayout; +import android.widget.TableRow; +import android.widget.TextView; + +import aws.apps.usbDeviceEnumerator.R; + +/*package*/ class ShareUtils { + private static final String TAG = ShareUtils.class.getSimpleName(); + + public static void share(final Activity activity, + final String subject, + final String text) { + + final Intent intent = new Intent(Intent.ACTION_SEND); + + intent.setType("text/plain"); + intent.putExtra(Intent.EXTRA_TEXT, text); + intent.putExtra(Intent.EXTRA_SUBJECT, subject); + intent.addCategory(Intent.CATEGORY_DEFAULT); + + final Intent share = Intent.createChooser(intent, activity.getString(R.string.share_result_via)); + ActivityCompat.startActivity(activity, intent, null); + } + + public static String tableToString(TableLayout t) { + StringBuilder sb = new StringBuilder(); + if (t != null) { + + for (int i = 0; i <= t.getChildCount() - 1; i++) { + final TableRow row = (TableRow) t.getChildAt(i); + + for (int j = 0; j <= row.getChildCount() - 1; j++) { + final View v = row.getChildAt(j); + + try { + if (v instanceof TextView) { + final TextView textView = (TextView) v; + sb.append(textView.getText()); + + if (j == 0) { + sb.append(" "); + } + } + } catch (Exception e) { + sb.append(e.toString()); + Log.e(TAG, "^ ERROR: tableToString: " + e.toString()); + } + } + sb.append("\n"); + } + } + + return sb.toString(); + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/UsbInfoActivity.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/UsbInfoActivity.java new file mode 100644 index 0000000..3fb41c5 --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/ui/usbinfo/UsbInfoActivity.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright 2011 Alexandros Schillings + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package aws.apps.usbDeviceEnumerator.ui.usbinfo; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.AppCompatActivity; +import android.view.MenuItem; + +import aws.apps.usbDeviceEnumerator.R; +import uk.co.alt236.usbdeviceenumerator.sysbususb.SysBusUsbDevice; + +public class UsbInfoActivity extends AppCompatActivity { + public static final String EXTRA_DATA_ANDROID = UsbInfoActivity.class.getName() + ".EXTRA_DATA_ANDROID"; + public static final String EXTRA_DATA_LINUX = UsbInfoActivity.class.getName() + ".EXTRA_DATA_LINUX"; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.act_usb_info); + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + final Bundle b = getIntent().getExtras(); + if (b == null) { + finish(); + } else { + final String androidKey = b.getString(EXTRA_DATA_ANDROID); + final SysBusUsbDevice linuxDevice = b.getParcelable(EXTRA_DATA_LINUX); + + final Fragment fragment; + + if (androidKey != null) { + fragment = InfoFragmentFactory.getFragment(androidKey); + } else if (linuxDevice != null) { + fragment = InfoFragmentFactory.getFragment(linuxDevice); + } else { + fragment = null; + } + + if (fragment == null) { + finish(); + } else { + showFragment(fragment); + } + } + } + + @Override + public boolean onOptionsItemSelected(final MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + onBackPressed(); + return true; + } + return super.onOptionsItemSelected(item); + } + + private void showFragment(final Fragment fragment) { + final FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + ft.replace(R.id.fragment_container, fragment); + ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); + ft.commit(); + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/util/NetworkUtils.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/util/NetworkUtils.java new file mode 100644 index 0000000..eab25fd --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/util/NetworkUtils.java @@ -0,0 +1,27 @@ +package aws.apps.usbDeviceEnumerator.util; + +import android.content.Context; +import android.net.ConnectivityManager; +import android.util.Log; + +public final class NetworkUtils { + private static final String TAG = NetworkUtils.class.getSimpleName(); + + public static boolean isOnline(final Context context) { + try { + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + + if (cm != null) { + Log.d(TAG, "^ isOnline()=true"); + return cm.getActiveNetworkInfo().isConnected(); + } else { + Log.d(TAG, "^ isOnline()=false"); + return false; + } + + } catch (Exception e) { + Log.e(TAG, "^ isOnline()=false", e); + return false; + } + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/util/NotifyUser.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/util/NotifyUser.java new file mode 100644 index 0000000..85cea7f --- /dev/null +++ b/app/src/main/java/aws/apps/usbDeviceEnumerator/util/NotifyUser.java @@ -0,0 +1,15 @@ +package aws.apps.usbDeviceEnumerator.util; + +import android.content.Context; +import android.widget.Toast; + +public class NotifyUser { + + public static void notify(final Context context, final CharSequence text) { + Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); + } + + public static void notify(final Context context, final int text) { + Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); + } +} diff --git a/app/src/main/java/aws/apps/usbDeviceEnumerator/util/UsefulBits.java b/app/src/main/java/aws/apps/usbDeviceEnumerator/util/UsefulBits.java deleted file mode 100644 index b508086..0000000 --- a/app/src/main/java/aws/apps/usbDeviceEnumerator/util/UsefulBits.java +++ /dev/null @@ -1,237 +0,0 @@ -/******************************************************************************* - * Copyright 2011 Alexandros Schillings - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ -package aws.apps.usbDeviceEnumerator.util; - -import android.app.AlertDialog; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager.NameNotFoundException; -import android.net.ConnectivityManager; -import android.util.Log; -import android.view.Gravity; -import android.view.View; -import android.widget.EditText; -import android.widget.TableLayout; -import android.widget.TableRow; -import android.widget.TextView; -import android.widget.Toast; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.text.Format; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; - -import aws.apps.usbDeviceEnumerator.R; -import aws.apps.usbDeviceEnumerator.ui.MyAlertBox; - -public class UsefulBits { - - final String TAG = this.getClass().getName(); - private Context c; - - public UsefulBits(Context cntx) { - c = cntx; - } - - public static void share(Context context, String subject, String text) { - Intent intent = new Intent(Intent.ACTION_SEND); - - intent.setType("text/plain"); - intent.putExtra(Intent.EXTRA_TEXT, text); - intent.putExtra(Intent.EXTRA_SUBJECT, subject); - intent.addCategory(Intent.CATEGORY_DEFAULT); - Intent share = Intent.createChooser(intent, context.getString(R.string.share_result_via)); - context.startActivity(share); - } - - public Calendar convertMillisToDate(long millis) { - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(millis); - return calendar; - } - - public boolean createDirectories(String dirs) { - Log.d(TAG, "^ createDirectories - Attempting to create: " + dirs); - try { - - if (new File(dirs).exists()) { - Log.d(TAG, "^ createDirectories - Directory already exist:" + dirs); - return true; - } - - // create a File object for the parent directory - File newDirectories = new File(dirs); - // have the object build the directory structure, if needed. - if (newDirectories.mkdirs()) { - showToast("Directories created: " + dirs, - Toast.LENGTH_SHORT, Gravity.TOP, 0, 0); - Log.d(TAG, "^ createDirectories - Directory created:" + dirs); - return true; - } else { - showToast("Could not create: " + dirs, - Toast.LENGTH_SHORT, Gravity.TOP, 0, 0); - Log.e(TAG, "^ createDirectories - Could not create:" + dirs); - return false; - } - - } catch (Exception e) {//Catch exception if any - showToast("Could not create: " + dirs, - Toast.LENGTH_SHORT, Gravity.TOP, 0, 0); - Log.e(TAG, "^ createDirectories - something went wrong (" + dirs + ") " + e.getMessage()); - return false; - } - } - - public String formatDateTime(String formatString, Date d) { - Format formatter = new SimpleDateFormat(formatString); - return formatter.format(d); - } - - public String getAppVersion() { - PackageInfo pi; - try { - pi = c.getPackageManager().getPackageInfo(c.getPackageName(), 0); - return pi.versionName; - } catch (NameNotFoundException e) { - return ""; - } - } - - public boolean isOnline() { - try { - ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); - - if (cm != null) { - Log.d(TAG, "^ isOnline()=true"); - return cm.getActiveNetworkInfo().isConnected(); - } else { - Log.d(TAG, "^ isOnline()=false"); - return false; - } - - } catch (Exception e) { - Log.e(TAG, "^ isOnline()=false", e); - return false; - } - } - - public void saveToFile(String fileName, File directory, String contents) { - - if (android.os.Environment.getExternalStorageState().equals( - android.os.Environment.MEDIA_MOUNTED)) { - try { - - if (directory.canWrite()) { - File gpxfile = new File(directory, fileName); - FileWriter gpxwriter = new FileWriter(gpxfile); - BufferedWriter out = new BufferedWriter(gpxwriter); - out.write(contents); - out.close(); - showToast("Saved to SD as '" + directory.getAbsolutePath() + "/" + fileName + "'", - Toast.LENGTH_SHORT, Gravity.TOP, 0, 0); - } - - } catch (Exception e) { - showToast("Could not write file:\n+ e.getMessage()", - Toast.LENGTH_SHORT, Gravity.TOP, 0, 0); - Log.e(TAG, "^ Could not write file " + e.getMessage()); - } - - } else { - showToast("No SD card is mounted...", Toast.LENGTH_SHORT, Gravity.TOP, 0, 0); - Log.e(TAG, "^ No SD card is mounted."); - } - } - - public void showAboutDialogue() { - String title = c.getString(R.string.app_name) + " v" + getAppVersion(); - - StringBuffer sb = new StringBuffer(); - - sb.append(c.getString(R.string.app_changelog)); - sb.append("\n\n"); - sb.append(c.getString(R.string.app_notes)); - sb.append("\n\n"); - sb.append(c.getString(R.string.app_acknowledgements)); - sb.append("\n\n"); - sb.append(c.getString(R.string.app_copyright)); - - MyAlertBox.create(c, sb.toString(), title, c.getString(android.R.string.ok)).show(); - } - - public void ShowAlert(String title, String text, String button) { - if (button.equals("")) { - button = c.getString(android.R.string.ok); - } - - try { - AlertDialog.Builder ad = new AlertDialog.Builder(c); - ad.setTitle(title); - ad.setMessage(text); - - ad.setPositiveButton(button, null); - ad.show(); - } catch (Exception e) { - Log.e(TAG, "^ ShowAlert()", e); - } - } - - public void showToast(String message, int duration, int location, int x_offset, int y_offset) { - Toast toast = Toast.makeText(c.getApplicationContext(), message, duration); - toast.setGravity(location, x_offset, y_offset); - toast.show(); - } - - public String tableToString(TableLayout t) { - String res = ""; - if (t == null) { - return res; - } - - for (int i = 0; i <= t.getChildCount() - 1; i++) { - TableRow row = (TableRow) t.getChildAt(i); - - for (int j = 0; j <= row.getChildCount() - 1; j++) { - View v = row.getChildAt(j); - - try { - if (v.getClass() == Class.forName("android.widget.TextView")) { - TextView tmp = (TextView) v; - res += tmp.getText(); - - if (j == 0) { - res += " "; - } - } else if (v.getClass() == Class.forName("android.widget.EditText")) { - EditText tmp = (EditText) v; - res += tmp.getText().toString(); - } else { - //do nothing - } - } catch (Exception e) { - res = e.toString(); - Log.e(TAG, "^ ERROR: tableToString: " + res); - } - } - res += "\n"; - } - return res; - } -} diff --git a/app/src/main/res/drawable-hdpi/ic_action_info.png b/app/src/main/res/drawable-hdpi/ic_action_info.png new file mode 100644 index 0000000..4da87a0 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_info.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_action_refresh.png b/app/src/main/res/drawable-hdpi/ic_action_refresh.png new file mode 100644 index 0000000..5ff6a8d Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_refresh.png differ diff --git a/app/src/main/res/drawable-hdpi/icon.png b/app/src/main/res/drawable-hdpi/icon.png deleted file mode 100644 index 3cd78ce..0000000 Binary files a/app/src/main/res/drawable-hdpi/icon.png and /dev/null differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_info.png b/app/src/main/res/drawable-mdpi/ic_action_info.png new file mode 100644 index 0000000..0932c17 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_info.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_refresh.png b/app/src/main/res/drawable-mdpi/ic_action_refresh.png new file mode 100644 index 0000000..c68c9fe Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_refresh.png differ diff --git a/app/src/main/res/drawable-mdpi/icon.png b/app/src/main/res/drawable-mdpi/icon.png deleted file mode 100644 index d04f32a..0000000 Binary files a/app/src/main/res/drawable-mdpi/icon.png and /dev/null differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_info.png b/app/src/main/res/drawable-xhdpi/ic_action_info.png new file mode 100644 index 0000000..f8e64ad Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_info.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_refresh.png b/app/src/main/res/drawable-xhdpi/ic_action_refresh.png new file mode 100644 index 0000000..a2ae1a3 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_refresh.png differ diff --git a/app/src/main/res/drawable-xhdpi/icon.png b/app/src/main/res/drawable-xhdpi/icon.png deleted file mode 100644 index fcb7b1b..0000000 Binary files a/app/src/main/res/drawable-xhdpi/icon.png and /dev/null differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_info.png b/app/src/main/res/drawable-xxhdpi/ic_action_info.png new file mode 100644 index 0000000..c03a0c5 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_info.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_refresh.png b/app/src/main/res/drawable-xxhdpi/ic_action_refresh.png new file mode 100644 index 0000000..f1d554c Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_refresh.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_info.png b/app/src/main/res/drawable-xxxhdpi/ic_action_info.png new file mode 100644 index 0000000..f1b7ebb Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_info.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_refresh.png b/app/src/main/res/drawable-xxxhdpi/ic_action_refresh.png new file mode 100644 index 0000000..7db8234 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_refresh.png differ diff --git a/app/src/main/res/layout-xlarge-land/act_main.xml b/app/src/main/res/layout-xlarge-land/act_main.xml index 727458c..c8fe66f 100644 --- a/app/src/main/res/layout-xlarge-land/act_main.xml +++ b/app/src/main/res/layout-xlarge-land/act_main.xml @@ -1,92 +1,40 @@ + android:divider="?attr/dividerVertical" + android:orientation="horizontal" + android:showDividers="middle"> - + android:layout_height="match_parent" + android:orientation="vertical"> - - - - - - - - - - - + android:layout_height="wrap_content" + app:tabGravity="fill" + app:tabMode="fixed" + tools:background="#FF00FF" /> - - - - - - - - - - - - - - - - - - - - + + + android:layout_weight="1" + android:orientation="horizontal" + tools:background="#c0c0c0" /> \ No newline at end of file diff --git a/app/src/main/res/layout-xlarge-land/fragment_error.xml b/app/src/main/res/layout-xlarge-land/fragment_error.xml new file mode 100644 index 0000000..6478f43 --- /dev/null +++ b/app/src/main/res/layout-xlarge-land/fragment_error.xml @@ -0,0 +1,19 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout-xlarge-land/usb_info_linux.xml b/app/src/main/res/layout-xlarge-land/fragment_usb_info.xml similarity index 90% rename from app/src/main/res/layout-xlarge-land/usb_info_linux.xml rename to app/src/main/res/layout-xlarge-land/fragment_usb_info.xml index 9b8d153..2b93bb0 100644 --- a/app/src/main/res/layout-xlarge-land/usb_info_linux.xml +++ b/app/src/main/res/layout-xlarge-land/fragment_usb_info.xml @@ -1,7 +1,11 @@ + android:layout_height="match_parent" + android:paddingBottom="@dimen/activity_vertical_margin" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingTop="@dimen/activity_vertical_margin"> + android:minWidth="130dip" + android:scaleType="fitXY" + android:src="@drawable/no_image" /> - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/act_main.xml b/app/src/main/res/layout/act_main.xml index 3d5292b..04f569b 100644 --- a/app/src/main/res/layout/act_main.xml +++ b/app/src/main/res/layout/act_main.xml @@ -1,87 +1,30 @@ - + android:orientation="vertical"> - + android:layout_height="wrap_content" + app:tabGravity="fill" + app:tabMode="fixed" + tools:background="#FF00FF" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_textview.xml b/app/src/main/res/layout/dialog_textview.xml new file mode 100644 index 0000000..8729276 --- /dev/null +++ b/app/src/main/res/layout/dialog_textview.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/usb_info_linux.xml b/app/src/main/res/layout/fragment_usb_info.xml similarity index 90% rename from app/src/main/res/layout/usb_info_linux.xml rename to app/src/main/res/layout/fragment_usb_info.xml index b5f7ff7..4440a0c 100644 --- a/app/src/main/res/layout/usb_info_linux.xml +++ b/app/src/main/res/layout/fragment_usb_info.xml @@ -1,7 +1,11 @@ + android:layout_height="match_parent" + android:paddingBottom="@dimen/activity_vertical_margin" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingTop="@dimen/activity_vertical_margin"> + android:minWidth="130dip" + android:scaleType="fitXY" + android:src="@drawable/no_image" /> - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/usb_info_android.xml b/app/src/main/res/layout/usb_info_android.xml deleted file mode 100644 index fc67f54..0000000 --- a/app/src/main/res/layout/usb_info_android.xml +++ /dev/null @@ -1,139 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/menu/frag_menu.xml b/app/src/main/res/menu/frag_menu.xml index 1f98ec3..3231cae 100644 --- a/app/src/main/res/menu/frag_menu.xml +++ b/app/src/main/res/menu/frag_menu.xml @@ -1,8 +1,8 @@ -

+ + android:title="@string/label_menu_export" + app:showAsAction="ifRoom|withText" /> \ No newline at end of file diff --git a/app/src/main/res/menu/main_menu.xml b/app/src/main/res/menu/main_menu.xml index a1a6d6f..b07745b 100644 --- a/app/src/main/res/menu/main_menu.xml +++ b/app/src/main/res/menu/main_menu.xml @@ -1,18 +1,17 @@ - + + android:icon="@drawable/ic_action_refresh" + android:title="@string/label_refresh" + app:showAsAction="ifRoom" /> + android:title="@string/label_menu_update_db" + app:showAsAction="never" /> + android:title="@string/label_menu_about" + app:showAsAction="never" /> \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..3928f45 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..7a2e4b0 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..7f851c2 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..1f40d33 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..925c701 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml new file mode 100644 index 0000000..79edc9c --- /dev/null +++ b/app/src/main/res/values-v21/styles.xml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-xlarge-land/styles.xml b/app/src/main/res/values-xlarge-land/styles.xml index b6e33ca..99dd28b 100644 --- a/app/src/main/res/values-xlarge-land/styles.xml +++ b/app/src/main/res/values-xlarge-land/styles.xml @@ -4,23 +4,15 @@ - - - - diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index dffb56d..fe6ca41 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -4,13 +4,11 @@ #50C0C0C0 #FFC0C0C0 #FFFFFF - - - - - - - - - + + #66e0e0e0 + #005699 + @color/usb_blue + #003D80 + #F06292 + @color/colorAccent diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..2463acb --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,6 @@ + + + 16dp + 16dp + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 348eb01..c587a11 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -16,13 +16,13 @@ ·v0.0.2 Added Interface and Endpoint resolution\n ·v0.0.3 Databases can now be downloaded.\n ·v0.0.4 Now also parses /sys/bus/usb/devices/ for those pesky devices android hides. Added export.\n - ·v0.0.5 Added support for small screen devices. Bugfixes and stability improvements. + ·v0.0.5 Added support for small screen devices. Bugfixes and stability improvements.\n + ·v1.0.0 Updated to material, better tablet support, code overhaul Notes:\n - ·To fully use this application, you need to download copies of the Vendor ID Database, the Company Name Database and the Company logo zip file.\nTo do that, Press Menu->Update DBs. Keep in mind it is about 2.5MB.\n - ·The Vendor ID database is the one used by my "USB VEN/DEV Database" application. Updating in one application will also update the other\n + ·To fully use this application, you need to download copies of the Vendor ID Database, the Company Name Database and the Company logo zip file.\nTo do that, Press Menu->Update DBs.\n ·The VID/PID database is created by parsing the following file: http://www.linux-usb.org/usb.ids @@ -30,6 +30,9 @@ About Export + Could not fetch device info.\nHas the device been disconnected? + Could not fetch device info. + API Linux @@ -40,19 +43,7 @@ There was an error while downloading the files. Downloading files… - - http://aschillings.co.uk/download/db/android_usb.db3 - http://aschillings.co.uk/download/db/android_company.db3 - http://aschillings.co.uk/download/db/company_logos.zip - - /data/alt236/usb_db/ - android_usb.db3 - - /data/alt236/company_db/ - android_company.db3 - - /data/alt236/company_db/ - company_logos.zip + Number of devices: %d Device offline The device seems to be offline.\nPlease enable either WiFi or Mobile Internet before continuing. diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 85ebba8..54131f5 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,17 +1,26 @@ + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index bbe9eb2..b544ec5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,18 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. + +ext.compileSdkVersion = 24 +ext.buildToolsVersion = "24.0.1" +ext.minSdkVersion = 12 +ext.targetSdkVersion = 24 + buildscript { repositories { jcenter() + mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:2.1.3' + classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } } @@ -13,3 +21,18 @@ allprojects { jcenter() } } + + +def quoteString(final String str) { + final String quote = "\""; + + if (str.length() > 0) { + if (str.startsWith(quote) && str.endsWith(quote)) { + return str; + } else { + return quote + str + quote; + } + } else { + return quote + quote; + } +} \ No newline at end of file diff --git a/usbdeviceenumerator/build.gradle b/usbdeviceenumerator/build.gradle index a71560d..6f68418 100644 --- a/usbdeviceenumerator/build.gradle +++ b/usbdeviceenumerator/build.gradle @@ -1,15 +1,23 @@ apply plugin: 'com.android.library' +final int versionMajor = 0 +final int versionMinor = 0 +final int versionPatch = 5 +final int androidVersionCode = 5 + +final int targetSdk = rootProject.targetSdkVersion; +final int minSdkRed = rootProject.minSdkVersion; +final String semanticVersion = "${versionMajor}.${versionMinor}.${versionPatch}" + android { - compileSdkVersion 14 - buildToolsVersion "24.0.1" + compileSdkVersion rootProject.compileSdkVersion + buildToolsVersion rootProject.buildToolsVersion defaultConfig { - minSdkVersion 12 - targetSdkVersion 14 - - versionCode 1 - versionName "1.0" + minSdkVersion minSdkRed + targetSdkVersion targetSdk + versionCode androidVersionCode + versionName semanticVersion } buildTypes { release { diff --git a/usbdeviceenumerator/src/main/java/aws/apps/usbDeviceEnumerator/usb/UsbConstants.java b/usbdeviceenumerator/src/main/java/uk/co/alt236/usbdeviceenumerator/UsbConstants.java similarity index 99% rename from usbdeviceenumerator/src/main/java/aws/apps/usbDeviceEnumerator/usb/UsbConstants.java rename to usbdeviceenumerator/src/main/java/uk/co/alt236/usbdeviceenumerator/UsbConstants.java index e03a2bc..9eb7661 100644 --- a/usbdeviceenumerator/src/main/java/aws/apps/usbDeviceEnumerator/usb/UsbConstants.java +++ b/usbdeviceenumerator/src/main/java/uk/co/alt236/usbdeviceenumerator/UsbConstants.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ -package aws.apps.usbDeviceEnumerator.usb; +package uk.co.alt236.usbdeviceenumerator; public class UsbConstants { diff --git a/usbdeviceenumerator/src/main/java/aws/apps/usbDeviceEnumerator/usb/sysbususb/ExecTerminal.java b/usbdeviceenumerator/src/main/java/uk/co/alt236/usbdeviceenumerator/sysbususb/ExecTerminal.java similarity index 98% rename from usbdeviceenumerator/src/main/java/aws/apps/usbDeviceEnumerator/usb/sysbususb/ExecTerminal.java rename to usbdeviceenumerator/src/main/java/uk/co/alt236/usbdeviceenumerator/sysbususb/ExecTerminal.java index d9e76b2..159e967 100644 --- a/usbdeviceenumerator/src/main/java/aws/apps/usbDeviceEnumerator/usb/sysbususb/ExecTerminal.java +++ b/usbdeviceenumerator/src/main/java/uk/co/alt236/usbdeviceenumerator/sysbususb/ExecTerminal.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ -package aws.apps.usbDeviceEnumerator.usb.sysbususb; +package uk.co.alt236.usbdeviceenumerator.sysbususb; import android.util.Log; diff --git a/usbdeviceenumerator/src/main/java/aws/apps/usbDeviceEnumerator/usb/sysbususb/SysBusUsbConstantsResolver.java b/usbdeviceenumerator/src/main/java/uk/co/alt236/usbdeviceenumerator/sysbususb/SysBusUsbConstantsResolver.java similarity index 99% rename from usbdeviceenumerator/src/main/java/aws/apps/usbDeviceEnumerator/usb/sysbususb/SysBusUsbConstantsResolver.java rename to usbdeviceenumerator/src/main/java/uk/co/alt236/usbdeviceenumerator/sysbususb/SysBusUsbConstantsResolver.java index f27493d..6929f8f 100644 --- a/usbdeviceenumerator/src/main/java/aws/apps/usbDeviceEnumerator/usb/sysbususb/SysBusUsbConstantsResolver.java +++ b/usbdeviceenumerator/src/main/java/uk/co/alt236/usbdeviceenumerator/sysbususb/SysBusUsbConstantsResolver.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ -package aws.apps.usbDeviceEnumerator.usb.sysbususb; +package uk.co.alt236.usbdeviceenumerator.sysbususb; /*package*/ class SysBusUsbConstantsResolver { diff --git a/usbdeviceenumerator/src/main/java/aws/apps/usbDeviceEnumerator/usb/sysbususb/SysBusUsbDevice.java b/usbdeviceenumerator/src/main/java/uk/co/alt236/usbdeviceenumerator/sysbususb/SysBusUsbDevice.java similarity index 99% rename from usbdeviceenumerator/src/main/java/aws/apps/usbDeviceEnumerator/usb/sysbususb/SysBusUsbDevice.java rename to usbdeviceenumerator/src/main/java/uk/co/alt236/usbdeviceenumerator/sysbususb/SysBusUsbDevice.java index 9753d08..4e315f0 100644 --- a/usbdeviceenumerator/src/main/java/aws/apps/usbDeviceEnumerator/usb/sysbususb/SysBusUsbDevice.java +++ b/usbdeviceenumerator/src/main/java/uk/co/alt236/usbdeviceenumerator/sysbususb/SysBusUsbDevice.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ -package aws.apps.usbDeviceEnumerator.usb.sysbususb; +package uk.co.alt236.usbdeviceenumerator.sysbususb; import android.os.Parcel; import android.os.Parcelable; diff --git a/usbdeviceenumerator/src/main/java/aws/apps/usbDeviceEnumerator/usb/sysbususb/SysBusUsbManager.java b/usbdeviceenumerator/src/main/java/uk/co/alt236/usbdeviceenumerator/sysbususb/SysBusUsbManager.java similarity index 99% rename from usbdeviceenumerator/src/main/java/aws/apps/usbDeviceEnumerator/usb/sysbususb/SysBusUsbManager.java rename to usbdeviceenumerator/src/main/java/uk/co/alt236/usbdeviceenumerator/sysbususb/SysBusUsbManager.java index b7aa32b..7ca03ab 100644 --- a/usbdeviceenumerator/src/main/java/aws/apps/usbDeviceEnumerator/usb/sysbususb/SysBusUsbManager.java +++ b/usbdeviceenumerator/src/main/java/uk/co/alt236/usbdeviceenumerator/sysbususb/SysBusUsbManager.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ -package aws.apps.usbDeviceEnumerator.usb.sysbususb; +package uk.co.alt236.usbdeviceenumerator.sysbususb; import java.io.BufferedReader; import java.io.File; diff --git a/usbdeviceenumerator/usbdeviceenumerator.iml b/usbdeviceenumerator/usbdeviceenumerator.iml index 878bc8c..54aab90 100644 --- a/usbdeviceenumerator/usbdeviceenumerator.iml +++ b/usbdeviceenumerator/usbdeviceenumerator.iml @@ -24,7 +24,7 @@ - + @@ -98,7 +98,7 @@ - +