use of com.michaelcarrano.detectivedroid.model.Library in project detective-droid by michaelcarrano.
the class LibraryAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
Library library = (Library) getItem(position);
if (convertView == null) {
convertView = mLayoutInflater.inflate(R.layout.list_item_card, parent, false);
holder = new ViewHolder();
holder.icon = (ImageView) convertView.findViewById(R.id.img_icon);
holder.name = (TextView) convertView.findViewById(R.id.text_name);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.icon.setVisibility(View.GONE);
holder.name.setText(library.getName());
return convertView;
}
use of com.michaelcarrano.detectivedroid.model.Library in project detective-droid by michaelcarrano.
the class DetectorAsyncTask method detect.
/**
* Detects all libraries by trying to load the pattern classpath in a given Application
*/
private static AppSource detect(PackageInfo pkg) {
ArrayList<Library> libraries = new ArrayList<Library>();
// Loop through known libraries
for (Library library : Libraries.getInstance().getLibraries()) {
try {
Context ctx = mContext.createPackageContext(pkg.packageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
Class<?> clazz = Class.forName(library.getPath(), false, ctx.getClassLoader());
// Detected a library!!!
if (clazz != null) {
libraries.add(library);
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
// Only return AppSource if app has a library
return libraries.size() > 0 ? new AppSource(pkg, libraries) : null;
}
use of com.michaelcarrano.detectivedroid.model.Library in project detective-droid by michaelcarrano.
the class App method parseLibrariesJson.
private void parseLibrariesJson() throws JSONException {
String jsonString = Utils.convertStreamToString(getResources().openRawResource(R.raw.libraries));
JSONArray json = new JSONArray(jsonString);
Set<Library> libraries = new HashSet<Library>();
for (int i = 0; i < json.length(); i++) {
JSONObject jsonObject = json.getJSONObject(i);
String name = jsonObject.getString("name");
String path = jsonObject.getString("path");
String source = jsonObject.getString("source");
libraries.add(new Library(name, path, source));
}
Libraries.getInstance().setLibraries(libraries);
}
Aggregations