Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 37ea7272 authored by Fs00's avatar Fs00
Browse files

Add option to show/hide app in launcher

parent 6377448f
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -19,11 +19,6 @@
        <activity
            android:name=".MainActivity_"
            android:theme="@style/Theme.Cyanea.Light.DarkActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

@@ -72,7 +67,19 @@
                <data android:scheme="content" />
                <data android:mimeType="application/pdf" />
            </intent-filter>
        </activity> <!-- About -->
        </activity>
        <!-- Alias to allow the user to hide the app from launcher -->
        <activity-alias
            android:name=".LauncherAlias"
            android:enabled="true"
            android:targetActivity=".MainActivity_">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity-alias>

        <activity
            android:name=".AboutActivity"
            android:label="About"
+24 −0
Original line number Diff line number Diff line
package com.gsnathan.pdfviewer;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -15,6 +16,10 @@ import android.view.MenuItem;

import androidx.core.app.NavUtils;

import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
import static android.content.pm.PackageManager.DONT_KILL_APP;

/**
 * A {@link PreferenceActivity} that presents a set of application settings. On
 * handset devices, settings are presented as a single list. On tablets,
@@ -76,6 +81,25 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
            }
        });

        findPreference("show_in_launcher").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                try {
                    setLauncherAliasState((boolean) newValue);
                    return true;
                } catch (Exception ignored) {
                    return false;
                }
            }
        });
    }

    private void setLauncherAliasState(boolean enableAlias) {
        getPackageManager().setComponentEnabledSetting(
                new ComponentName(this, "com.gsnathan.pdfviewer.LauncherAlias"),
                enableAlias ? COMPONENT_ENABLED_STATE_ENABLED : COMPONENT_ENABLED_STATE_DISABLED,
                DONT_KILL_APP
        );
    }

    private void setupActionBar() {
+2 −1
Original line number Diff line number Diff line
@@ -110,5 +110,6 @@
    <string name="reload">Reload PDF</string>
    <string name="reload_sum">In order to make changes, the PDF must be reloaded.</string>
    <string name="buttonLog">Continue</string>

    <string name="show_in_launcher">Show app in launcher</string>
    <string name="show_in_launcher_summary">You may need to restart your launcher for this option to take effect</string>
</resources>
 No newline at end of file
+5 −0
Original line number Diff line number Diff line
@@ -2,6 +2,11 @@
<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android">

    <SwitchPreference
        android:defaultValue="true"
        android:title="@string/show_in_launcher"
        android:summary="@string/show_in_launcher_summary" android:key="show_in_launcher"/>

    <PreferenceCategory
        android:title="@string/qualitysettings">