Skip to content

Commit

Permalink
Open app info on long press
Browse files Browse the repository at this point in the history
  • Loading branch information
tanujnotes committed Dec 24, 2020
1 parent 2fb2288 commit a30e896
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions app/src/main/java/app/olauncher/light/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class MainActivity extends Activity implements View.OnClickListener, View

public interface AppClickListener {
void appClicked(AppModel appModel, int flag);

void appLongPress(AppModel appModel);
}

@Override
Expand Down Expand Up @@ -297,6 +299,13 @@ private void launchApp(AppModel appModel) {
}
}

private void openAppInfo(AppModel appModel) {
LauncherApps launcher = (LauncherApps) getSystemService(Context.LAUNCHER_APPS_SERVICE);
Intent intent = getPackageManager().getLaunchIntentForPackage(appModel.appPackage);
if (intent == null || intent.getComponent() == null) return;
launcher.startAppDetailsActivity(intent.getComponent(), appModel.userHandle, null, null);
}

private void setHomeApp(AppModel appModel, int flag) {
prefs.setHomeApp(appModel, flag);
backToHome();
Expand All @@ -314,7 +323,7 @@ private String getDefaultLauncherPackage() {
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo result = getPackageManager().resolveActivity(intent, 0);
if (result == null && result.activityInfo == null)
if (result == null || result.activityInfo == null)
return "android";
return result.activityInfo.packageName;
}
Expand Down Expand Up @@ -421,9 +430,18 @@ private void checkForDoubleTap() {
}

private AppClickListener getAppClickListener() {
return (appModel, flag) -> {
if (flag == FLAG_LAUNCH_APP) prepareToLaunchApp(appModel);
else setHomeApp(appModel, flag);
return new AppClickListener() {
@Override
public void appClicked(AppModel appModel, int flag) {
if (flag == FLAG_LAUNCH_APP) prepareToLaunchApp(appModel);
else setHomeApp(appModel, flag);
}

@Override
public void appLongPress(AppModel appModel) {
hideKeyboard();
openAppInfo(appModel);
}
};
}

Expand Down Expand Up @@ -584,6 +602,11 @@ public View getView(int position, View convertView, ViewGroup parent) {
AppModel clickedAppModel = (AppModel) viewHolder.appName.getTag();
appClickListener.appClicked(clickedAppModel, flag);
});
viewHolder.appName.setOnLongClickListener(view -> {
AppModel clickedAppModel = (AppModel) viewHolder.appName.getTag();
appClickListener.appLongPress(clickedAppModel);
return true;
});
if (appModel.userHandle == android.os.Process.myUserHandle())
viewHolder.indicator.setVisibility(View.GONE);
else viewHolder.indicator.setVisibility(View.VISIBLE);
Expand Down

0 comments on commit a30e896

Please sign in to comment.