use of fr.neamar.kiss.pojo.Pojo 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.Pojo in project KISS by Neamar.
the class SettingsProvider method getResults.
public ArrayList<Pojo> getResults(String query) {
ArrayList<Pojo> results = new ArrayList<>();
int relevance;
String settingNameLowerCased;
for (SettingsPojo setting : pojos) {
relevance = 0;
settingNameLowerCased = setting.nameNormalized;
if (settingNameLowerCased.startsWith(query))
relevance = 10;
else if (settingNameLowerCased.contains(" " + query))
relevance = 5;
else if (settingName.startsWith(query)) {
// Also display for a search on "settings" for instance
relevance = 4;
}
if (relevance > 0) {
setting.displayName = setting.name.replaceFirst("(?i)(" + Pattern.quote(query) + ")", "{$1}");
setting.relevance = relevance;
results.add(setting);
}
}
return results;
}
use of fr.neamar.kiss.pojo.Pojo in project KISS by Neamar.
the class TogglesProvider method getResults.
public ArrayList<Pojo> getResults(String query) {
ArrayList<Pojo> results = new ArrayList<>();
int relevance;
String toggleNameLowerCased;
for (TogglesPojo toggle : pojos) {
relevance = 0;
toggleNameLowerCased = toggle.nameNormalized;
if (toggleNameLowerCased.startsWith(query))
relevance = 75;
else if (toggleNameLowerCased.contains(" " + query))
relevance = 30;
else if (toggleNameLowerCased.contains(query))
relevance = 1;
else if (toggleName.startsWith(query)) {
// Also display for a search on "settings" for instance
relevance = 4;
}
if (relevance > 0) {
toggle.displayName = toggle.name.replaceFirst("(?i)(" + Pattern.quote(query) + ")", "{$1}");
toggle.relevance = relevance;
results.add(toggle);
}
}
return results;
}
use of fr.neamar.kiss.pojo.Pojo in project KISS by Neamar.
the class DataHandler method getFavorites.
/**
* Return most used items.<br />
* May return null if no items were ever selected (app first use)
*
* @param limit max number of items to retrieve. You may end with less items if favorites contains non existing items.
* @return favorites' pojo
*/
public ArrayList<Pojo> getFavorites(int limit) {
ArrayList<Pojo> favorites = new ArrayList<>(limit);
String favApps = PreferenceManager.getDefaultSharedPreferences(this.context).getString("favorite-apps-list", "");
List<String> favAppsList = Arrays.asList(favApps.split(";"));
// Find associated items
for (int i = 0; i < favAppsList.size(); i++) {
Pojo pojo = getPojo(favAppsList.get(i));
if (pojo != null) {
favorites.add(pojo);
}
if (favorites.size() >= limit) {
break;
}
}
return favorites;
}
use of fr.neamar.kiss.pojo.Pojo in project KISS by Neamar.
the class MainActivity method displayFavorites.
public void displayFavorites() {
int[] favoritesIds = favoritesKissBar.getVisibility() == View.VISIBLE ? favsIds : favBarIds;
ArrayList<Pojo> favoritesPojo = KissApplication.getDataHandler(MainActivity.this).getFavorites(tryToRetrieve);
if (favoritesPojo.size() == 0) {
int noFavCnt = prefs.getInt("no-favorites-tip", 0);
if (noFavCnt < 3 && !prefs.getBoolean("enable-favorites-bar", false)) {
Toast toast = Toast.makeText(MainActivity.this, getString(R.string.no_favorites), Toast.LENGTH_SHORT);
toast.show();
prefs.edit().putInt("no-favorites-tip", ++noFavCnt).apply();
}
}
// Don't look for items after favIds length, we won't be able to display them
for (int i = 0; i < Math.min(favoritesIds.length, favoritesPojo.size()); i++) {
Pojo pojo = favoritesPojo.get(i);
ImageView image = (ImageView) findViewById(favoritesIds[i]);
Result result = Result.fromPojo(MainActivity.this, pojo);
Drawable drawable = result.getDrawable(MainActivity.this);
if (drawable != null) {
image.setImageDrawable(drawable);
} else {
Log.e(TAG, "Falling back to default image for favorite.");
// Use the default contact image otherwise
image.setImageResource(R.drawable.ic_contact);
}
image.setVisibility(View.VISIBLE);
image.setContentDescription(pojo.displayName);
}
// Hide empty favorites (not enough favorites yet)
for (int i = favoritesPojo.size(); i < favoritesIds.length; i++) {
findViewById(favoritesIds[i]).setVisibility(View.GONE);
}
}
Aggregations