Search in sources :

Example 6 with Library

use of com.mikepenz.aboutlibraries.entity.Library in project AboutLibraries by mikepenz.

the class Libs method init.

/**
     * init method
     *
     * @param fields
     */
private void init(Context ctx, String[] fields) {
    ArrayList<String> foundLicenseIdentifiers = new ArrayList<>();
    ArrayList<String> foundInternalLibraryIdentifiers = new ArrayList<>();
    ArrayList<String> foundExternalLibraryIdentifiers = new ArrayList<>();
    if (fields != null) {
        for (String field : fields) {
            if (field.startsWith(DEFINE_LICENSE)) {
                foundLicenseIdentifiers.add(field.replace(DEFINE_LICENSE, ""));
            } else if (field.startsWith(DEFINE_INT)) {
                foundInternalLibraryIdentifiers.add(field.replace(DEFINE_INT, ""));
            } else if (field.startsWith(DEFINE_EXT)) {
                foundExternalLibraryIdentifiers.add(field.replace(DEFINE_EXT, ""));
            }
        }
    }
    //add licenses
    for (String licenseIdentifier : foundLicenseIdentifiers) {
        License license = genLicense(ctx, licenseIdentifier);
        if (license != null) {
            licenses.add(license);
        }
    }
    //add internal libs
    for (String internalIdentifier : foundInternalLibraryIdentifiers) {
        Library library = genLibrary(ctx, internalIdentifier);
        if (library != null) {
            library.setInternal(true);
            internLibraries.add(library);
        }
    }
    //add external libs
    for (String externalIdentifier : foundExternalLibraryIdentifiers) {
        Library library = genLibrary(ctx, externalIdentifier);
        if (library != null) {
            library.setInternal(false);
            externLibraries.add(library);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) License(com.mikepenz.aboutlibraries.entity.License) Library(com.mikepenz.aboutlibraries.entity.Library)

Example 7 with Library

use of com.mikepenz.aboutlibraries.entity.Library in project AboutLibraries by mikepenz.

the class Libs method find.

/**
 * @param libraries
 * @param searchTerm
 * @param idOnly
 * @param limit
 * @return
 */
private ArrayList<Library> find(ArrayList<Library> libraries, String searchTerm, boolean idOnly, int limit) {
    ArrayList<Library> localLibs = new ArrayList<>();
    int count = 0;
    for (Library library : libraries) {
        if (idOnly) {
            if (library.getDefinedName().toLowerCase().contains(searchTerm.toLowerCase())) {
                localLibs.add(library);
                count = count + 1;
                if (limit != -1 && limit < count) {
                    break;
                }
            }
        } else {
            if (library.getLibraryName().toLowerCase().contains(searchTerm.toLowerCase()) || library.getDefinedName().toLowerCase().contains(searchTerm.toLowerCase())) {
                localLibs.add(library);
                count = count + 1;
                if (limit != -1 && limit < count) {
                    break;
                }
            }
        }
    }
    return localLibs;
}
Also used : ArrayList(java.util.ArrayList) Library(com.mikepenz.aboutlibraries.entity.Library)

Example 8 with Library

use of com.mikepenz.aboutlibraries.entity.Library in project AboutLibraries by mikepenz.

the class Libs method genLibrary.

/**
 * @param libraryName
 * @return
 */
private Library genLibrary(Context ctx, String libraryName) {
    libraryName = libraryName.replace("-", "_");
    try {
        Library lib = new Library();
        // Get custom vars to insert into defined areas
        HashMap<String, String> customVariables = getCustomVariables(ctx, libraryName);
        lib.setDefinedName(libraryName);
        lib.setAuthor(getStringResourceByName(ctx, "library_" + libraryName + "_author"));
        lib.setAuthorWebsite(getStringResourceByName(ctx, "library_" + libraryName + "_authorWebsite"));
        lib.setLibraryName(getStringResourceByName(ctx, "library_" + libraryName + "_libraryName"));
        lib.setLibraryDescription(insertVariables(getStringResourceByName(ctx, "library_" + libraryName + "_libraryDescription"), customVariables));
        lib.setLibraryVersion(getStringResourceByName(ctx, "library_" + libraryName + "_libraryVersion"));
        lib.setLibraryWebsite(getStringResourceByName(ctx, "library_" + libraryName + "_libraryWebsite"));
        String licenseId = getStringResourceByName(ctx, "library_" + libraryName + "_licenseId");
        if (TextUtils.isEmpty(licenseId)) {
            License license = new License();
            license.setLicenseName(getStringResourceByName(ctx, "library_" + libraryName + "_licenseVersion"));
            license.setLicenseWebsite(getStringResourceByName(ctx, "library_" + libraryName + "_licenseLink"));
            license.setLicenseShortDescription(insertVariables(getStringResourceByName(ctx, "library_" + libraryName + "_licenseContent"), customVariables));
            lib.setLicense(license);
        } else {
            License license = getLicense(licenseId);
            if (license != null) {
                license = license.copy();
                license.setLicenseShortDescription(insertVariables(license.getLicenseShortDescription(), customVariables));
                license.setLicenseDescription(insertVariables(license.getLicenseDescription(), customVariables));
                lib.setLicense(license);
            }
        }
        lib.setOpenSource(Boolean.valueOf(getStringResourceByName(ctx, "library_" + libraryName + "_isOpenSource")));
        lib.setRepositoryLink(getStringResourceByName(ctx, "library_" + libraryName + "_repositoryLink"));
        lib.setClassPath(getStringResourceByName(ctx, "library_" + libraryName + "_classPath"));
        if (TextUtils.isEmpty(lib.getLibraryName()) && TextUtils.isEmpty(lib.getLibraryDescription())) {
            return null;
        }
        return lib;
    } catch (Exception ex) {
        Log.e("aboutlibraries", "Failed to generateLibrary from file: " + ex.toString());
        return null;
    }
}
Also used : License(com.mikepenz.aboutlibraries.entity.License) Library(com.mikepenz.aboutlibraries.entity.Library)

Example 9 with Library

use of com.mikepenz.aboutlibraries.entity.Library in project AboutLibraries by mikepenz.

the class Libs method addExternalLibrary.

private void addExternalLibrary(Context ctx, String externalIdentifier) {
    Library library = genLibrary(ctx, externalIdentifier);
    if (library != null) {
        library.setInternal(false);
        externLibraries.add(library);
    }
}
Also used : Library(com.mikepenz.aboutlibraries.entity.Library)

Example 10 with Library

use of com.mikepenz.aboutlibraries.entity.Library in project AboutLibraries by mikepenz.

the class Libs method prepareLibraries.

/**
 * This will summarize all libraries and elimate duplicates
 *
 * @param internalLibraries    the String[] with the internalLibraries (if set manual)
 * @param excludeLibraries     the String[] with the libs to be excluded
 * @param autoDetect           defines if the libraries should be resolved by their classpath (if possible)
 * @param checkCachedDetection defines if we should check the cached autodetected libraries (per version) (default: enabled)
 * @param sort                 defines if the array should be sorted
 * @return the summarized list of included Libraries
 */
public ArrayList<Library> prepareLibraries(Context ctx, String[] internalLibraries, String[] excludeLibraries, boolean autoDetect, boolean checkCachedDetection, boolean sort) {
    boolean isExcluding = excludeLibraries != null;
    HashMap<String, Library> libraries = isExcluding ? new HashMap<String, Library>() : null;
    ArrayList<Library> resultLibraries = new ArrayList<>();
    if (autoDetect) {
        List<Library> autoDetected = getAutoDetectedLibraries(ctx, checkCachedDetection);
        resultLibraries.addAll(autoDetected);
        if (isExcluding) {
            for (Library lib : autoDetected) {
                libraries.put(lib.getDefinedName(), lib);
            }
        }
    }
    // Add all external libraries
    List<Library> extern = getExternLibraries();
    resultLibraries.addAll(extern);
    if (isExcluding) {
        for (Library lib : extern) {
            libraries.put(lib.getDefinedName(), lib);
        }
    }
    // Now add all libs which do not contains the info file, but are in the AboutLibraries lib
    if (internalLibraries != null) {
        for (String internalLibrary : internalLibraries) {
            Library lib = getLibrary(internalLibrary);
            if (isExcluding && lib != null) {
                resultLibraries.add(lib);
                libraries.put(lib.getDefinedName(), lib);
            }
        }
    }
    // remove libraries which should be excluded
    if (isExcluding) {
        for (String excludeLibrary : excludeLibraries) {
            Library lib = libraries.get(excludeLibrary);
            if (lib != null) {
                resultLibraries.remove(lib);
            }
        }
    }
    if (sort) {
        Collections.sort(resultLibraries);
    }
    return resultLibraries;
}
Also used : ArrayList(java.util.ArrayList) Library(com.mikepenz.aboutlibraries.entity.Library)

Aggregations

Library (com.mikepenz.aboutlibraries.entity.Library)11 ArrayList (java.util.ArrayList)6 License (com.mikepenz.aboutlibraries.entity.License)3 PackageInfo (android.content.pm.PackageInfo)2 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 LibraryItem (com.mikepenz.aboutlibraries.ui.item.LibraryItem)1 FastAdapter (com.mikepenz.fastadapter.FastAdapter)1 ItemAdapter (com.mikepenz.fastadapter.adapters.ItemAdapter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1