Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.PHONY: build database

build:
./gradlew build

lint:
./gradlew updateLintBaseline

install:
adb install -r app/build/outputs/apk/debug/app-debug.apk

log:
adb logcat -s Categories:D

database:
@database/fdroid.sh
@cat database/local.txt >> app/src/main/res/raw/apps_categories.csv
@database/kaggle.sh database/kaggle.csv >> app/src/main/res/raw/apps_categories.csv
@sort app/src/main/res/raw/apps_categories.csv | uniq -i > app/src/main/res/raw/apps_categories_tmp.csv
@cat app/src/main/res/raw/apps_categories_tmp.csv | grep -v "not found in databases" > app/src/main/res/raw/apps_categories.csv
@rm app/src/main/res/raw/apps_categories_tmp.csv


1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ android {
}
lint {
disable 'MissingTranslation'
baseline = file("lint-baseline.xml")
}
buildToolsVersion='35.0.1'
compileOptions {
Expand Down
1,742 changes: 1,742 additions & 0 deletions app/lint-baseline.xml

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions app/src/main/java/com/quaap/launchtime/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3716,6 +3716,20 @@ public void run() {
});
}

public void promptRecategorizeAll(final String category) {

MsgBox.alert(this,
getString(R.string.cat_recategorize_all),
getString(R.string.recat_prompt_all),
true,
true,
new Runnable() {
@Override
public void run() {
recategorizeAll();
}
});
}

public void recategorize(final String category) {

Expand Down Expand Up @@ -3762,6 +3776,49 @@ public void run() {
});
}

public void recategorizeAll() {

GlobState.execute(this, new Runnable() {
@Override
public void run() {
int moved = 0;
final int dir = mStyle.isLeftHandCategories()?-1:1;
for (AppLauncher app: db().getAllApps()) {
if (!app.isNormalApp()) continue;
String newCat = Categories.getCategoryForComponent(MainActivity.this, app.getBaseComponentName(),true,null);
if (newCat!=null) {
//Log.d(TAG, app.getLabel() +" " + newCat);
moved++;
app.setCategory(newCat);
db().updateAppCategory(app.getComponentName(), newCat);
if (mAnimationDuration>0) {
final View appview = mAppLauncherViews.get(app);
if (appview != null) {
runOnUiThread(new Runnable() {
@Override
public void run() {
appview.animate().translationXBy(dir * mScreenDim.x).setDuration(mAnimationDuration).start();
}
});
}
}
// addAppToIconSheet(newCat, app, true);
}
}

final String text = getString(R.string.moved_apps, moved);

iconHandler.postDelayed(new Runnable() {
@Override
public void run() {
hideHiddenCategories();
Toast.makeText(MainActivity.this, text, Toast.LENGTH_SHORT ).show();
}
},500);
}
});
}

private Long getInstallTime(String packagename) {
try {
return getPackageManager()
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/com/quaap/launchtime/apps/AppLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,12 @@ private AppLauncher(Context context, PackageManager pm, ResolveInfo ri, String c
mCategory = category;
//Log.d("LaunchTime", mPackageName + ", " + ri.activityInfo.name + ", " + mLabel + " cat " + category);
} else if (autocat) {
mCategory = Categories.getCategoryForComponent(context, mActivityName, mPackageName, true, ri.activityInfo.applicationInfo);
mCategory = Categories.getCategoryFromCsv(context, ri.activityInfo.applicationInfo);
if (mCategory==null) {
mCategory = Categories.getCategoryFromPiCat(ri.activityInfo.applicationInfo);
mCategory = Categories.getCategoryForComponent(context, mActivityName, mPackageName, true, ri.activityInfo.applicationInfo);
if (mCategory==null) {
mCategory = Categories.getCategoryFromPiCat(ri.activityInfo.applicationInfo);
}
}

//Log.d("LaunchTime", mPackageName + ", " + ri.activityInfo.name + ", " + mLabel + " auto " + category);
Expand Down
179 changes: 175 additions & 4 deletions app/src/main/java/com/quaap/launchtime/components/Categories.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.pm.ApplicationInfo;
import android.content.res.Resources;
import android.os.Build;
import android.util.Log;

import com.quaap.launchtime.GlobState;
import com.quaap.launchtime.R;
Expand All @@ -16,6 +17,12 @@
import java.util.LinkedHashMap;
import java.util.Map;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

/**
* Some portions modified from Silverfish:
* Copyright 2016 Stanislav Pintjuk
Expand Down Expand Up @@ -47,6 +54,12 @@ public class Categories {
private static final String CAT_Utilities = "Utilities";
public static final String CAT_OTHER = "Other";
private static final String CAT_SETTINGS = "Settings";
private static final String CAT_SYSTEM = "System";
private static final String CAT_MONEY = "Finance";
private static final String CAT_HEALTH = "Health";
private static final String CAT_SCIENCE = "Science";
private static final String CAT_TRAVEL = "Travel";
private static final String CAT_CAR = "Car";
public static final String CAT_HIDDEN = "Hidden";
public static final String CAT_DUMB = "Dumb__";

Expand All @@ -63,13 +76,152 @@ public class Categories {
CAT_MEDIA,
CAT_GRAPHICS,
CAT_Utilities,
CAT_SETTINGS,
CAT_MONEY,
CAT_SCIENCE,
CAT_HEALTH,
CAT_TRAVEL,
CAT_CAR,
CAT_SYSTEM,
CAT_OTHER,
CAT_SEARCH,
CAT_SETTINGS,
CAT_HIDDEN
};

private static Map<String, String[]> mCategorKeywords;
private static Map<String, String> CategoryMap;

private static void loadCategories(Context context) {
if (CategoryMap != null) return;

CategoryMap = new HashMap<>();

try (BufferedReader reader = new BufferedReader(
new InputStreamReader(context.getResources().openRawResource(R.raw.apps_categories)))) {

String line;
boolean firstLine = true;

while ((line = reader.readLine()) != null) {
if (firstLine) {
firstLine = false;
continue;
}

String[] parts = line.split(",", 2);
if (parts.length < 2) continue;

String pkg = parts[0].trim();
String categoryRaw = parts[1].trim();
String firstCategory = categoryRaw.contains("|")
? categoryRaw.substring(0, categoryRaw.indexOf("|"))
: categoryRaw;

CategoryMap.put(pkg, firstCategory);
}

Log.d("Categories", "CSV geladen, Einträge: " + CategoryMap.size());

} catch (Exception e) {
Log.e("Categories", "CSV konnte nicht geladen werden!", e);
}
}

public static String getCategoryFromCsv(Context context, ApplicationInfo appinfo) {
if (appinfo == null) return null;

return getCategoryFromCsv(context, appinfo.packageName);
}

public static String getCategoryFromCsv(Context context, String pkgname) {
if (pkgname == null) return null;
loadCategories(context);

String Cat = CategoryMap.get(pkgname);
Log.d("Categories", "Package: " + pkgname + ", Kategorie: " + Cat);
if (Cat == null) return null;

switch (Cat.toLowerCase()) {
case "games":
case "game":
case "strategy":
case "action":
return CAT_GAMES;

case "internet":
case "browser":
case "communication":
return CAT_INTERNET;

case "multimedia":
case "audio":
case "video":
case "entertainment":
case "reading":
case "videoplayer & editors":
case "music & audio":
case "news & magazines":
case "books & reference":
return CAT_MEDIA;

case "graphics":
case "photography":
case "image":
return CAT_GRAPHICS;

case "office":
case "productivity":
case "task":
case "writing":
case "tools":
case "business":
case "calendar & agenda":
return CAT_Utilities;

case "social":
case "connectivity":
case "messaging":
return CAT_TALK;

case "sports & health":
case "health & fitness":
case "medicine":
case "medical":
case "health":
case "fitness":
return CAT_HEALTH;

case "money":
case "finance":
case "bank":
return CAT_MONEY;

case "science & education":
case "translation & dictionary":
case "education":
case "dictionary":
case "translation":
return CAT_SCIENCE;

case "auto & vehicles":
return CAT_CAR;

case "travel & local":
case "maps & navigation":
case "maps":
case "navigation":
case "weather":
case "travel":
return CAT_TRAVEL;

case "system":
case "personalization":
return CAT_SYSTEM;

default:
return null;
}
}

public static void init(Context context) {
resources = context.getResources();
Expand Down Expand Up @@ -142,8 +294,15 @@ public static String getCategoryForComponent(Context context, ComponentName acti

public static String getCategoryForComponent(Context context, String actvname, String pkgname, boolean guess, ApplicationInfo ai) {

String catact = getCategoryForActivity(context, actvname, false);
String catpack = getCategoryForPackage(context, pkgname, false);
String catact = getCategoryFromCsv(context, actvname);
if (catact == null) {
catact = getCategoryForActivity(context, actvname, false);
}

String catpack = getCategoryFromCsv(context, pkgname);
if (catpack == null) {
catpack = getCategoryForPackage(context, pkgname, false);
}

String category = catact;
if (category==null || category.equals(CAT_OTHER)) category = catpack;
Expand Down Expand Up @@ -191,7 +350,7 @@ public static String getCategoryFromPiCat(ApplicationInfo appinfo) {
break;

case ApplicationInfo.CATEGORY_MAPS:
cat = CAT_INTERNET;
cat = CAT_TRAVEL;
break;

case ApplicationInfo.CATEGORY_NEWS:
Expand Down Expand Up @@ -285,6 +444,12 @@ public static String getCatLabel(Context context, String category) {
catmap.put(CAT_SETTINGS, R.string.category_Settings);
catmap.put(CAT_HIDDEN, R.string.category_Hidden);
catmap.put(CAT_DUMB, R.string.category_Dumb);
catmap.put(CAT_SYSTEM, R.string.category_System);
catmap.put(CAT_MONEY, R.string.category_Money);
catmap.put(CAT_SCIENCE, R.string.category_Science);
catmap.put(CAT_CAR, R.string.category_Car);
catmap.put(CAT_TRAVEL, R.string.category_Travel);
catmap.put(CAT_HEALTH, R.string.category_Health);
return context.getString(catmap.get(category));
}

Expand All @@ -300,6 +465,12 @@ public static String getCatFullLabel(Context context, String category) {
catmap.put(CAT_OTHER, R.string.category_Other_full);
catmap.put(CAT_SETTINGS, R.string.category_Settings_full);
catmap.put(CAT_HIDDEN, R.string.category_Hidden_full);
catmap.put(CAT_SYSTEM, R.string.category_System_full);
catmap.put(CAT_MONEY, R.string.category_Money_full);
catmap.put(CAT_HEALTH, R.string.category_Health_full);
catmap.put(CAT_SCIENCE, R.string.category_Science_full);
catmap.put(CAT_CAR, R.string.category_Car_full);
catmap.put(CAT_TRAVEL, R.string.category_Travel_full);
catmap.put(CAT_DUMB, R.string.category_Dumb_full);
return context.getString(catmap.get(category));
}
Expand Down
Loading