Skip to content

Commit

Permalink
New launch options & fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
threethan committed Jul 29, 2023
1 parent 85d2352 commit cd9a00f
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 66 deletions.
7 changes: 3 additions & 4 deletions Launcher/App/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ android {

defaultConfig {
minSdkVersion 23
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 23
versionCode 200
versionName "2.0.0"
targetSdkVersion 33
versionCode 210
versionName "2.1.0"
}

compileOptions {
Expand Down
10 changes: 4 additions & 6 deletions Launcher/App/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<uses-feature android:name="oculus.software.handtracking" android:required="false"/>
<uses-permission android:name="com.oculus.permission.HAND_TRACKING"/>

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

<application
android:icon="@drawable/ic_appicon"
android:label="@string/app_name"
Expand All @@ -17,20 +19,16 @@
android:usesCleartextTraffic="true"
android:allowBackup="true">

<meta-data android:name="com.oculus.vrshell.supports_free_resizing" android:value="true" maxSizeX="1280" maxSizeY="1000" minSizeX="400" minSizeY="400"/>

<activity
android:name=".MainActivity"
android:launchMode="singleInstance"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="unspecified"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

</activity>

<service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.content.Intent;
import android.view.accessibility.AccessibilityEvent;

import java.lang.reflect.Array;

public class LauncherAccessibilityService extends AccessibilityService
{
public void onAccessibilityEvent(AccessibilityEvent event)
Expand All @@ -13,10 +15,10 @@ public void onAccessibilityEvent(AccessibilityEvent event)
String exploreAccessibilityEventName = getResources().getString(R.string.accessibility_event_name);

if (exploreAccessibilityEventName.compareTo(eventText) == 0) {
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.threethan.launcher");
Intent launchIntent = new Intent(this, MainActivity.class);

launchIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(launchIntent);
launchIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
this.startActivity(launchIntent);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Log.i("LauncherStartup", "0. Set View");
Log.i("LauncherStartup", "1. Set View");


setContentView(R.layout.activity_main);


Log.i("LauncherStartup", "1. Get Setting Provider");
Log.i("LauncherStartup", "2. Get Setting Provider");

sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
settingsProvider = SettingsProvider.getInstance(this);
Expand Down Expand Up @@ -403,13 +403,7 @@ private void showSettingsMain() {
dialog.findViewById(R.id.settings_service).setOnClickListener(view -> {
Intent localIntent = new Intent("android.settings.ACCESSIBILITY_SETTINGS");
localIntent.setPackage("com.android.settings");
finish();
new Timer().schedule(new TimerTask() {
@Override
public void run() {
startActivity(localIntent);
}
}, 600);
startActivity(localIntent);
});
}

Expand Down Expand Up @@ -496,6 +490,7 @@ public void openApp(ApplicationInfo app) {
public void openAppDetails(String pkg) {
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + pkg));

startActivity(intent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.util.Log;

import com.threethan.launcher.platforms.AbstractPlatform;
import com.threethan.launcher.platforms.AppPlatform;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -29,13 +30,15 @@ public class SettingsProvider {
private static Context context;
private final String KEY_APP_GROUPS = "prefAppGroups";
private final String KEY_APP_LIST = "prefAppList";
private final String KEY_LAUNCH_OUT = "prefLaunchOutList";
private final String KEY_SELECTED_GROUPS = "prefSelectedGroups";
private final String SEPARATOR = "\r";
//storage
private final SharedPreferences sharedPreferences;
private Map<String, String> appListMap = new HashMap<>();
private Set<String> appGroupsSet = new HashSet<>();
private Set<String> selectedGroupsSet = new HashSet<>();
private static Set<String> appsToLaunchOut = new HashSet<>();

private SettingsProvider(Context context) {
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
Expand All @@ -62,6 +65,15 @@ public static String getAppDisplayName(Context context, String pkg, CharSequence
return retVal;
}

public static boolean getAppLaunchOut(String pkg) {
return (appsToLaunchOut.contains(pkg));
}

public static void setAppLaunchOut(String pkg, boolean shouldLaunchOut) {
if (shouldLaunchOut) appsToLaunchOut.add(pkg);
else appsToLaunchOut.remove(pkg);
}

public Map<String, String> getAppList() {
readValues();
return appListMap;
Expand All @@ -86,7 +98,9 @@ public ArrayList<ApplicationInfo> getInstalledApps(Context context, List<String>
// Sort if groups are present
for (ApplicationInfo app : allApps) {
if (!appListMap.containsKey(app.packageName)) {
appListMap.put(app.packageName, AbstractPlatform.isVirtualRealityApp(app) ? context.getString(R.string.default_apps_group) : context.getString(R.string.android_apps_group));
final boolean isVr = AbstractPlatform.isVirtualRealityApp(app);
appListMap.put(app.packageName, isVr ? context.getString(R.string.default_apps_group) : context.getString(R.string.android_apps_group));
if (isVr) appsToLaunchOut.add(app.packageName);
}
}
}
Expand All @@ -109,7 +123,7 @@ public ArrayList<ApplicationInfo> getInstalledApps(Context context, List<String>
boolean showAll = selected.isEmpty();
boolean isNotAssigned = !apps.containsKey(pkg) && first;
boolean isInGroup = apps.containsKey(pkg) && selected.contains(apps.get(pkg));
boolean isVr = hasMetadata(installedApplication, "com.samsung.android.vr.application.mode");
boolean isVr = hasMetadata(installedApplication, "com.oculus.supportedDevices");
boolean isEnvironment = !isVr && hasMetadata(installedApplication, "com.oculus.environmentVersion");
if (showAll || isNotAssigned || isInGroup) {
boolean isSystemApp = (installedApplication.flags & ApplicationInfo.FLAG_SYSTEM) == 1;
Expand Down Expand Up @@ -152,14 +166,9 @@ public ArrayList<ApplicationInfo> getInstalledApps(Context context, List<String>

return sortedApps;
}

public boolean hasMetadata(ApplicationInfo app, String metadata) {
if (app.metaData != null) {
for (String key : app.metaData.keySet()) {
if (metadata.compareTo(key) == 0) {
return true;
}
}
return app.metaData.keySet().contains(metadata);
}
return false;
}
Expand Down Expand Up @@ -211,6 +220,7 @@ private synchronized void readValues() {
defaultGroupsSet.add(context.getString(R.string.android_apps_group));
appGroupsSet = sharedPreferences.getStringSet(KEY_APP_GROUPS, defaultGroupsSet);
selectedGroupsSet = sharedPreferences.getStringSet(KEY_SELECTED_GROUPS, defaultGroupsSet);
appsToLaunchOut = sharedPreferences.getStringSet(KEY_LAUNCH_OUT, defaultGroupsSet);

appListMap.clear();

Expand All @@ -232,6 +242,7 @@ private synchronized void storeValues() {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putStringSet(KEY_APP_GROUPS, appGroupsSet);
editor.putStringSet(KEY_SELECTED_GROUPS, selectedGroupsSet);
editor.putStringSet(KEY_LAUNCH_OUT, appsToLaunchOut);

Map<String, Set<String>> appListSetMap = new HashMap<>();
for (String group : appGroupsSet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ boolean downloadIconFromUrl(String url, File iconFile) {
}
}
} catch (FileNotFoundException e) {
System.err.println("File not found: " + e.getMessage());
Log.d("File not found", e.getMessage());
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.threethan.launcher.platforms;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Looper;
import android.util.Log;

import java.util.ArrayList;
import com.threethan.launcher.SettingsProvider;

import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Handler;

public class AppPlatform extends AbstractPlatform {
@Override
Expand All @@ -22,20 +21,16 @@ public boolean isSupported(Context context) {
@Override
public void runApp(Activity context, ApplicationInfo appInfo) {
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(appInfo.packageName);
context.finish();
Log.i("LAUNCHING",appInfo.packageName);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
context.startActivity(launchIntent);
}
}, 600);
// Backup, in case the first call fails
new Timer().schedule(new TimerTask() {
@Override
public void run() {
context.startActivity(launchIntent);
}
}, 1500);
if (SettingsProvider.getAppLaunchOut(appInfo.packageName)) {
context.finish();
new Timer().schedule(new TimerTask() {
@Override
public void run() {
context.startActivity(launchIntent);
}
}, 650);
} else {
context.startActivity(launchIntent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -157,7 +158,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
} else if (event.getAction() == DragEvent.ACTION_DRAG_ENDED) {
mainActivityContext.reloadUI();
} else if (event.getAction() == DragEvent.ACTION_DROP) {
if (System.currentTimeMillis() - lastClickTime < 250) {
if (System.currentTimeMillis() - lastClickTime < 300) {
try {
showAppDetails(currentApp);
} catch (PackageManager.NameNotFoundException e) {
Expand Down Expand Up @@ -221,6 +222,23 @@ private void showAppDetails(ApplicationInfo currentApp) throws PackageManager.Na
// info action
appDetailsDialog.findViewById(R.id.info).setOnClickListener(view13 -> mainActivityContext.openAppDetails(currentApp.packageName));

// toggle launch mode
final boolean[] launchOut = {SettingsProvider.getAppLaunchOut(currentApp.packageName)};
final Button launchModeBtn = appDetailsDialog.findViewById(R.id.launch_mode);
final boolean isVr = AbstractPlatform.isVirtualRealityApp(currentApp);
if (isVr) { //VR apps MUST launch out, so just hide the option
launchModeBtn.setVisibility(View.GONE);
if (!launchOut[0]) SettingsProvider.setAppLaunchOut(currentApp.packageName, true); //Failsafe
} else {
launchModeBtn.setVisibility(View.VISIBLE);
launchModeBtn.setText(context.getString(launchOut[0] ? R.string.launch_out : R.string.launch_in));
appDetailsDialog.findViewById(R.id.launch_mode).setOnClickListener(view13 -> {
SettingsProvider.setAppLaunchOut(currentApp.packageName, !launchOut[0]);
launchOut[0] = SettingsProvider.getAppLaunchOut(currentApp.packageName);
launchModeBtn.setText(context.getString(launchOut[0] ? R.string.launch_out : R.string.launch_in));
});
}

// set name
PackageManager packageManager = mainActivityContext.getPackageManager();
String name = SettingsProvider.getAppDisplayName(mainActivityContext, currentApp.packageName, currentApp.loadLabel(packageManager));
Expand Down
42 changes: 30 additions & 12 deletions Launcher/App/src/main/res/layout/dialog_app_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:paddingBottom="20dp"
android:text="@string/app_details"
android:textColor="@android:color/white"
android:textSize="20sp" />
Expand All @@ -34,27 +33,46 @@

<ImageView
android:id="@+id/app_icon"
android:layout_width="120dp"
android:layout_height="67.5dp"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginEnd="10dp" />

<EditText
android:id="@+id/app_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_weight="1"
android:autofillHints="text"
android:backgroundTint="@android:color/white"
android:inputType="text"
android:textColor="@android:color/white" />
</LinearLayout>

<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:background="@drawable/bkg_button"
android:text="@android:string/ok"
android:textColor="@android:color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:gravity="right"
android:orientation="horizontal">

<Button
android:id="@+id/launch_mode"
android:layout_width="190dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:background="@drawable/bkg_button"
android:text="@string/launch_in"
android:textColor="@android:color/white" />

<Button
android:id="@+id/ok"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginLeft="10dp"
android:background="@drawable/bkg_button"
android:text="@android:string/ok"
android:textColor="@android:color/white" />
</LinearLayout>
</LinearLayout>
6 changes: 5 additions & 1 deletion Launcher/App/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Lightning Launcher</string>
<string name="default_apps_group">Apps</string>
<string name="default_apps_group">Games</string>
<string name="android_apps_group">Tools</string>
<string name="add_group">Add Group</string>
<string name="delete_group">Delete Group</string>
Expand All @@ -15,4 +15,8 @@

<string name="service_desc">When this service is enabled, Lightning Launcher will open automatically when you hover the cursor over the App Library icon for about half a second. This may make it difficult to access the normal app launcher!</string>
<string name="accessibility_event_name">[App Library]</string>

<string name="launch_in">Runs in: this window</string>
<string name="launch_out">Runs in: own window</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
android:description="@string/service_desc"
android:settingsActivity=""
android:accessibilityEventTypes="typeWindowStateChanged"
android:accessibilityFlags="flagDefault|flagRequestAccessibilityButton"
android:accessibilityFlags="flagDefault"
android:notificationTimeout="1000"
android:canRetrieveWindowContent="true"
android:canRequestFilterKeyEvents="true" />
Loading

0 comments on commit cd9a00f

Please sign in to comment.