use of fr.neamar.kiss.pojo.AppPojo in project KISS by Neamar.
the class LoadAppPojos method doInBackground.
@Override
protected ArrayList<AppPojo> doInBackground(Void... params) {
long start = System.nanoTime();
ArrayList<AppPojo> apps = new ArrayList<>();
String excludedAppList = PreferenceManager.getDefaultSharedPreferences(context).getString("excluded-apps-list", context.getPackageName() + ";");
List excludedApps = Arrays.asList(excludedAppList.split(";"));
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
UserManager manager = (UserManager) context.getSystemService(Context.USER_SERVICE);
LauncherApps launcher = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
// Handle multi-profile support introduced in Android 5 (#542)
for (android.os.UserHandle profile : manager.getUserProfiles()) {
UserHandle user = new UserHandle(manager.getSerialNumberForUser(profile), profile);
for (LauncherActivityInfo activityInfo : launcher.getActivityList(null, profile)) {
ApplicationInfo appInfo = activityInfo.getApplicationInfo();
String fullPackageName = user.addUserSuffixToString(appInfo.packageName, '#');
if (!excludedApps.contains(fullPackageName)) {
AppPojo app = new AppPojo();
app.id = user.addUserSuffixToString(pojoScheme + appInfo.packageName + "/" + activityInfo.getName(), '/');
app.setName(activityInfo.getLabel().toString());
app.packageName = appInfo.packageName;
app.activityName = activityInfo.getName();
// Wrap Android user handle in opaque container that will work across
// all Android versions
app.userHandle = user;
app.setTags(tagsHandler.getTags(app.id));
apps.add(app);
}
}
}
} else {
PackageManager manager = context.getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
for (ResolveInfo info : manager.queryIntentActivities(mainIntent, 0)) {
ApplicationInfo appInfo = info.activityInfo.applicationInfo;
if (!excludedApps.contains(appInfo.packageName)) {
AppPojo app = new AppPojo();
app.id = pojoScheme + appInfo.packageName + "/" + info.activityInfo.name;
app.setName(info.loadLabel(manager).toString());
app.packageName = appInfo.packageName;
app.activityName = info.activityInfo.name;
app.userHandle = new UserHandle();
app.setTags(tagsHandler.getTags(app.id));
apps.add(app);
}
}
}
// Apply app sorting preference
if (prefs.getString("sort-apps", "alphabetical").equals("invertedAlphabetical")) {
Collections.sort(apps, Collections.reverseOrder(new AppPojo.NameComparator()));
} else {
Collections.sort(apps, new AppPojo.NameComparator());
}
long end = System.nanoTime();
Log.i("time", Long.toString((end - start) / 1000000) + " milliseconds to list apps");
return apps;
}
use of fr.neamar.kiss.pojo.AppPojo in project KISS by Neamar.
the class AppProvider method getAllApps.
public ArrayList<Pojo> getAllApps() {
ArrayList<Pojo> records = new ArrayList<>(pojos.size());
records.trimToSize();
for (AppPojo pojo : pojos) {
pojo.displayName = pojo.name;
pojo.displayTags = pojo.tags;
records.add(pojo);
}
return records;
}
use of fr.neamar.kiss.pojo.AppPojo in project KISS by Neamar.
the class AppProvider method getResults.
public ArrayList<Pojo> getResults(String query) {
query = StringNormalizer.normalize(query);
ArrayList<Pojo> records = new ArrayList<>();
int relevance;
// The position inside the query
int queryPos;
// The position inside pojo.nameNormalized
int normalizedAppPos;
// The position inside pojo.name, updated after we increment normalizedAppPos
int appPos;
int beginMatch;
int matchedWordStarts;
int totalWordStarts;
ArrayList<Pair<Integer, Integer>> matchPositions;
for (AppPojo pojo : pojos) {
pojo.displayName = pojo.name;
pojo.displayTags = pojo.tags;
relevance = 0;
queryPos = 0;
normalizedAppPos = 0;
appPos = pojo.mapPosition(normalizedAppPos);
beginMatch = 0;
matchedWordStarts = 0;
totalWordStarts = 0;
matchPositions = null;
boolean match = false;
int inputLength = pojo.nameNormalized.length();
while (normalizedAppPos < inputLength) {
int cApp = pojo.nameNormalized.codePointAt(normalizedAppPos);
if (queryPos < query.length() && query.codePointAt(queryPos) == cApp) {
// If we aren't already matching something, let's save the beginning of the match
if (!match) {
beginMatch = normalizedAppPos;
match = true;
}
// If we are at the beginning of a word, add it to matchedWordStarts
if (appPos == 0 || normalizedAppPos == 0 || Character.isUpperCase(pojo.name.codePointAt(appPos)) || Character.isWhitespace(pojo.name.codePointBefore(appPos)))
matchedWordStarts += 1;
// Increment the position in the query
queryPos += Character.charCount(query.codePointAt(queryPos));
} else if (match) {
if (matchPositions == null)
matchPositions = new ArrayList<>();
matchPositions.add(Pair.create(beginMatch, normalizedAppPos));
match = false;
}
// If we are at the beginning of a word, add it to totalWordsStarts
if (appPos == 0 || normalizedAppPos == 0 || Character.isUpperCase(pojo.name.codePointAt(appPos)) || Character.isWhitespace(pojo.name.codePointBefore(appPos)))
totalWordStarts += 1;
normalizedAppPos += Character.charCount(cApp);
appPos = pojo.mapPosition(normalizedAppPos);
}
boolean matchedTags = false;
if (match) {
if (matchPositions == null)
matchPositions = new ArrayList<>();
matchPositions.add(Pair.create(beginMatch, normalizedAppPos));
}
int tagStart = 0;
int tagEnd = 0;
if (queryPos == query.length() && matchPositions != null) {
// Add percentage of matched letters, but at a weight of 40
relevance += (int) (((double) queryPos / pojo.nameNormalized.length()) * 40);
// Add percentage of matched upper case letters (start of word), but at a weight of 60
relevance += (int) (((double) matchedWordStarts / totalWordStarts) * 60);
// The more fragmented the matches are, the less the result is important
relevance *= (0.2 + 0.8 * (1.0 / matchPositions.size()));
} else {
if (pojo.tagsNormalized.startsWith(query)) {
relevance = 4 + query.length();
} else if (pojo.tagsNormalized.indexOf(query) >= 0) {
relevance = 3 + query.length();
}
if (relevance > 0) {
matchedTags = true;
}
tagStart = pojo.tagsNormalized.indexOf(query);
tagEnd = tagStart + query.length();
}
if (relevance > 0) {
if (!matchedTags) {
pojo.setDisplayNameHighlightRegion(matchPositions);
} else {
pojo.setTagHighlight(tagStart, tagEnd);
}
pojo.relevance = relevance;
records.add(pojo);
}
}
return records;
}
use of fr.neamar.kiss.pojo.AppPojo in project KISS by Neamar.
the class AppProvider method findById.
/**
* Return a Pojo
*
* @param id we're looking for
* @param allowSideEffect do we allow this function to have potential side effect? Set to false to ensure none.
* @return an AppPojo, or null
*/
public Pojo findById(String id, Boolean allowSideEffect) {
for (Pojo pojo : pojos) {
if (pojo.id.equals(id)) {
// Reset displayName to default value
if (allowSideEffect) {
pojo.displayName = pojo.name;
if (pojo instanceof AppPojo) {
AppPojo appPojo = (AppPojo) pojo;
appPojo.displayTags = appPojo.tags;
}
}
return pojo;
}
}
return null;
}
Aggregations