Skip to content

Commit

Permalink
Added set home app settings entry and shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
italankin committed Jun 4, 2022
1 parent 853265b commit bc7fa47
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public class LauncherShortcuts {

public static final String ID_SHORTCUT_CUSTOMIZE = "customize";
public static final String ID_SHORTCUT_SET_HOME = "set_home_app";

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand Down Expand Up @@ -47,6 +50,11 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
findPreference(R.string.pref_key_home_set_default_launcher).setOnPreferenceClickListener(preference -> {
Intent intent = new Intent(Settings.ACTION_HOME_SETTINGS);
startActivity(intent);
return true;
});
findPreference(R.string.pref_key_home_customize).setOnPreferenceClickListener(preference -> {
sendResult(new LaunchEditModeContract().result());
return true;
Expand Down Expand Up @@ -98,6 +106,28 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
});
}

@Override
public void onStart() {
super.onStart();
configureSetHomeAction();
}

private void configureSetHomeAction() {
Intent home = new Intent(Intent.ACTION_MAIN);
home.addCategory(Intent.CATEGORY_HOME);
Context context = requireContext();
ResolveInfo resolveInfo = context.getPackageManager()
.resolveActivity(home, PackageManager.MATCH_DEFAULT_ONLY);
Preference setDefaultLauncherPref = findPreference(R.string.pref_key_home_set_default_launcher);
if (resolveInfo != null && resolveInfo.activityInfo != null) {
String currentHomePackage = resolveInfo.activityInfo.packageName;
setDefaultLauncherPref.setVisible(!context.getPackageName().equals(currentHomePackage));
} else {
// better hide it to not annoy user
setDefaultLauncherPref.setVisible(false);
}
}

@Override
public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.settings, menu);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions launcher/src/main/res/drawable/ic_settings_set_home.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?colorIconTint"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#fff"
android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z" />
</vector>
1 change: 1 addition & 0 deletions launcher/src/main/res/values/prefs_keys.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- references to preference views -->
<string name="pref_key_home_set_default_launcher">set_default_launcher</string>
<string name="pref_key_search_settings">search_settings</string>
<string name="pref_key_search_most_used_reset">search_must_used_reset</string>
<string name="pref_key_wallpaper">wallpaper</string>
Expand Down
3 changes: 3 additions & 0 deletions launcher/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

<string name="popup_notifications_header">Notifications</string>

<string name="shortcut_set_default_launcher_hint">Set home app</string>

<string name="customize_hint">Customize</string>
<string name="customize_saved">Saved</string>
<string name="customize_discard_message">Discard changes?</string>
Expand Down Expand Up @@ -106,6 +108,7 @@
<string name="settings_version">Version %1$s</string>
<string name="settings_source_code">Source code</string>
<string name="settings_customize">Customize</string>
<string name="settings_set_default_launcher">Set lnch as home app</string>

<string name="settings_category_home">Home</string>
<string name="settings_home_wallpaper">Wallpaper</string>
Expand Down
6 changes: 6 additions & 0 deletions launcher/src/main/res/xml/prefs_root.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<PreferenceCategory>
<Preference
android:icon="@drawable/ic_settings_set_home"
android:key="@string/pref_key_home_set_default_launcher"
android:title="@string/settings_set_default_launcher"
app:isPreferenceVisible="false" />
<Preference
android:icon="@drawable/ic_action_rename"
android:key="@string/pref_key_home_customize"
Expand Down
8 changes: 8 additions & 0 deletions launcher/src/main/res/xml/shortcuts.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<shortcut
android:enabled="true"
android:icon="@drawable/ic_shortcut_set_home"
android:shortcutId="set_home_app"
android:shortcutShortLabel="@string/shortcut_set_default_launcher_hint"
tools:targetApi="n_mr1">
<intent android:action="android.settings.HOME_SETTINGS" />
</shortcut>
<shortcut
android:enabled="true"
android:icon="@drawable/ic_shortcut_mode_edit"
Expand Down

0 comments on commit bc7fa47

Please sign in to comment.