Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Miscellaneous setting and Hide app icon option #2462

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
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
13 changes: 13 additions & 0 deletions play-services-base/core/src/main/kotlin/org/microg/gms/ui/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.microg.gms.ui

import android.content.ComponentName
import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
Expand Down Expand Up @@ -45,6 +46,18 @@ fun NavController.navigate(context: Context, @IdRes resId: Int, args: Bundle? =
} else null)
}

fun Context.hideAppIcon(hide: Boolean) {
val componentName = ComponentName("org.microg.gms.ui", "org.microg.gms.ui.SettingsActivity")
packageManager.setComponentEnabledSetting(
componentName,
when (hide) {
true -> PackageManager.COMPONENT_ENABLED_STATE_DISABLED
false -> PackageManager.COMPONENT_ENABLED_STATE_ENABLED
},
PackageManager.DONT_KILL_APP
)
}

val Context.systemAnimationsEnabled: Boolean
get() {
val duration: Float
Expand Down
19 changes: 19 additions & 0 deletions play-services-base/core/src/main/res/drawable/ic_hide_app_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ SPDX-FileCopyrightText: 2019, The Android Open Source Project
~ SPDX-FileCopyrightText: 2020, microG Project Team
~ SPDX-License-Identifier: Apache-2.0
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="48"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#FF000000"
android:strokeWidth="1"
android:strokeColor="#FF000000"
android:pathData="M39.6,43.85 L35.9,40.2Q33.4,42 30.4,43Q27.4,44 24,44Q19.75,44 16.1,42.475Q12.45,40.95 9.75,38.25Q7.05,35.55 5.525,31.9Q4,28.25 4,24Q4,20.6 5,17.6Q6,14.6 7.8,12.1L4.1,8.4Q3.65,7.95 3.675,7.35Q3.7,6.75 4.15,6.3Q4.6,5.85 5.225,5.85Q5.85,5.85 6.3,6.3L41.75,41.75Q42.2,42.2 42.2,42.8Q42.2,43.4 41.75,43.85Q41.3,44.3 40.675,44.3Q40.05,44.3 39.6,43.85ZM24,41Q26.75,41 29.2,40.225Q31.65,39.45 33.75,38.05L9.95,14.25Q8.55,16.35 7.775,18.8Q7,21.25 7,24Q7,31.25 11.875,36.125Q16.75,41 24,41ZM40.2,35.9 L38.05,33.75Q39.45,31.65 40.225,29.2Q41,26.75 41,24Q41,16.75 36.125,11.875Q31.25,7 24,7Q21.25,7 18.8,7.775Q16.35,8.55 14.25,9.95L12.1,7.8Q14.6,6 17.6,5Q20.6,4 24,4Q28.2,4 31.85,5.55Q35.5,7.1 38.2,9.8Q40.9,12.5 42.45,16.15Q44,19.8 44,24Q44,27.4 43,30.4Q42,33.4 40.2,35.9ZM26.15,21.85Q26.15,21.85 26.15,21.85Q26.15,21.85 26.15,21.85Q26.15,21.85 26.15,21.85Q26.15,21.85 26.15,21.85Q26.15,21.85 26.15,21.85Q26.15,21.85 26.15,21.85ZM21.85,26.15Q21.85,26.15 21.85,26.15Q21.85,26.15 21.85,26.15Q21.85,26.15 21.85,26.15Q21.85,26.15 21.85,26.15Q21.85,26.15 21.85,26.15Q21.85,26.15 21.85,26.15Z" />
</vector>
17 changes: 17 additions & 0 deletions play-services-base/core/src/main/res/drawable/ic_miscellaneous.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ SPDX-FileCopyrightText: 2019, The Android Open Source Project
~ SPDX-FileCopyrightText: 2020, microG Project Team
~ SPDX-License-Identifier: Apache-2.0
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#FF000000"
android:pathData="M5 21H3C2.4 21 2 20.6 2 20S2.4 19 3 19H5V21ZM21 21H13V19H21C21.6 19 22 19.4 22 20S21.6 21 21 21ZM10 16H8C7.4 16 7 16.4 7 17V23C7 23.6 7.4 24 8 24H10C10.6 24 11 23.6 11 23V17C11 16.4 10.6 16 10 16ZM16 26H14C13.4 26 13 26.4 13 27V33C13 33.6 13.4 34 14 34H16C16.6 34 17 33.6 17 33V27C17 26.4 16.6 26 16 26ZM21 31H19V29H21C21.6 29 22 29.4 22 30S21.6 31 21 31ZM11 31H3C2.4 31 2 30.6 2 30S2.4 29 3 29H11V31Z"/>
</vector>
4 changes: 3 additions & 1 deletion play-services-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,9 @@
android:roundIcon="@mipmap/ic_app_settings"
android:process=":ui"
android:targetActivity="org.microg.gms.ui.MainSettingsActivity"
android:taskAffinity="org.microg.gms.settings">
android:taskAffinity="org.microg.gms.settings"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@

package org.microg.gms.ui

import android.content.ComponentName
import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.SwitchPreferenceCompat
import com.google.android.gms.R
import org.microg.gms.base.core.BuildConfig
import org.microg.gms.checkin.CheckinPreferences
import org.microg.gms.gcm.GcmDatabase
import org.microg.gms.gcm.GcmPrefs
import org.microg.gms.vending.VendingPreferences
import org.microg.gms.safetynet.SafetyNetPreferences
import org.microg.gms.ui.settings.SettingsProvider
import org.microg.gms.ui.settings.getAllSettingsProviders
import org.microg.gms.vending.VendingPreferences
import org.microg.tools.ui.ResourceSettingsFragment

class SettingsFragment : ResourceSettingsFragment() {
Expand Down Expand Up @@ -60,6 +64,21 @@
summary = getString(org.microg.tools.ui.R.string.about_version_str, AboutFragment.getSelfVersion(context))
}

val hideAppIconPref = findPreference<SwitchPreferenceCompat>("pref_hide_app_icon") ?: return

if (BuildConfig.IS_HUAWEI_BUILD) {

Check failure on line 69 in play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt

View workflow job for this annotation

GitHub Actions / Gradle build

Unresolved reference: IS_HUAWEI_BUILD

Check failure on line 69 in play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt

View workflow job for this annotation

GitHub Actions / Gradle build

Unresolved reference: IS_HUAWEI_BUILD
hideAppIconPref.isVisible = false
} else {
val componentName = ComponentName("org.microg.gms.ui", "org.microg.gms.ui.SettingsActivity")
val state = requireContext().packageManager.getComponentEnabledSetting(componentName)
hideAppIconPref.isChecked = (state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED)
hideAppIconPref.setOnPreferenceChangeListener { _, newValue ->
val enabled = newValue as Boolean
requireActivity().hideAppIcon(enabled)
true
}
}

for (entry in getAllSettingsProviders(requireContext()).flatMap { it.getEntriesStatic(requireContext()) }) {
entry.createPreference()
}
Expand Down
3 changes: 3 additions & 0 deletions play-services-core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ This can take a couple of minutes."</string>
<string name="pref_gcm_confirm_new_apps_summary">Ask before registering a new app to receive push notifications</string>
<string name="pref_gcm_ping_interval">Ping interval: <xliff:g example="10 minutes">%1$s</xliff:g></string>

<string name="pref_miscellaneous_title">Miscellaneous</string>
<string name="pref_hide_app_icon_title">Hide app icon</string>
<string name="pref_hide_app_icon_summary">Hides app icon from the launcher</string>
<string name="pref_about_title">About microG Services</string>
<string name="pref_about_summary">Version information and used libraries</string>

Expand Down
28 changes: 28 additions & 0 deletions play-services-core/src/main/res/xml/preferences_hide_app_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2013-2017 microG Project Team
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory android:layout="@layout/preference_category_no_label" android:key="prefcat_other_services">
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_hide_app_icon"
android:key="pref_hide_app_icon"
android:persistent="false"
android:summary="@string/pref_hide_app_icon_summary"
android:title="@string/pref_hide_app_icon_title" />
</PreferenceCategory>
</PreferenceScreen>
10 changes: 7 additions & 3 deletions play-services-core/src/main/res/xml/preferences_start.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@
<Preference
android:icon="@drawable/ic_map_marker"
android:key="pref_location"
android:title="@string/service_name_location"/>
android:title="@string/service_name_location" />
</PreferenceCategory>
<PreferenceCategory android:layout="@layout/preference_category_no_label" android:key="prefcat_footer">
<PreferenceCategory android:layout="@layout/preference_category_no_label" android:key="prefcat_other_services">
<Preference
android:icon="@drawable/ic_miscellaneous"
android:key="pref_miscellaneous"
android:title="@string/pref_miscellaneous_title" />
<Preference
android:icon="@drawable/ic_info_outline"
android:key="pref_about"
android:title="@string/pref_about_title" />
</PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>
Loading