Search in sources :

Example 1 with Library

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;
}
Also used : Library(com.michaelcarrano.detectivedroid.model.Library)

Example 2 with Library

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;
}
Also used : Context(android.content.Context) PackageManager(android.content.pm.PackageManager) ArrayList(java.util.ArrayList) Library(com.michaelcarrano.detectivedroid.model.Library) AppSource(com.michaelcarrano.detectivedroid.model.AppSource)

Example 3 with Library

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);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Library(com.michaelcarrano.detectivedroid.model.Library) HashSet(java.util.HashSet)

Aggregations

Library (com.michaelcarrano.detectivedroid.model.Library)3 Context (android.content.Context)1 PackageManager (android.content.pm.PackageManager)1 AppSource (com.michaelcarrano.detectivedroid.model.AppSource)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1