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

Commit 8ea05ccb authored by Danny Baumann's avatar Danny Baumann Committed by Adnan
Browse files

Hide heads up settings and show a notice if heads up is disabled.

This follows a UI pattern used at several other places, such as
daydream, screencast, profiles or blacklist settings.

Change-Id: I5635338ceccae8ba8450284d3078889333fb77c6
parent 3bc3238c
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The CyanogenMod Project

     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.
-->

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/prefs_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <TextView
        android:id="@+id/disabled_text"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="@string/heads_up_disabled_notice" />

</FrameLayout>
+1 −0
Original line number Diff line number Diff line
@@ -325,6 +325,7 @@
    <string name="add_heads_up_blacklist_summary">Don\'t show heads up from these applications</string>
    <string name="heads_up_dnd_title">Do not disturb</string>
    <string name="heads_up_blacklist_title">Blacklist</string>
    <string name="heads_up_disabled_notice">To allow applications to display interactive notifications in a pop-up window on your screen, enable Heads up.</string>

    <string name="title_tile_airplane">Airplane mode</string>
    <string name="title_tile_battery">Battery stats</string>
+41 −0
Original line number Diff line number Diff line
@@ -24,14 +24,19 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceGroup;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Switch;
@@ -67,6 +72,16 @@ public class HeadsUpSettings extends SettingsPreferenceFragment
    private Switch mActionBarSwitch;
    private HeadsUpEnabler mHeadsUpEnabler;

    private ViewGroup mPrefsContainer;
    private View mDisabledText;

    private ContentObserver mSettingsObserver = new ContentObserver(new Handler()) {
        @Override
        public void onChange(boolean selfChange, Uri uri) {
            updateEnabledState();
        }
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
@@ -122,6 +137,19 @@ public class HeadsUpSettings extends SettingsPreferenceFragment
        setHasOptionsMenu(true);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.headsup_fragment, container, false);
        mPrefsContainer = (ViewGroup) v.findViewById(R.id.prefs_container);
        mDisabledText = v.findViewById(R.id.disabled_text);

        View prefs = super.onCreateView(inflater, mPrefsContainer, savedInstanceState);
        mPrefsContainer.addView(prefs);

        return v;
    }

    @Override
    public void onResume() {
        super.onResume();
@@ -131,6 +159,11 @@ public class HeadsUpSettings extends SettingsPreferenceFragment
        refreshCustomApplicationPrefs();
        getListView().setOnItemLongClickListener(this);
        getActivity().invalidateOptionsMenu();

        getContentResolver().registerContentObserver(
                Settings.System.getUriFor(Settings.System.HEADS_UP_NOTIFICATION),
                true, mSettingsObserver);
        updateEnabledState();
    }

    @Override
@@ -139,6 +172,7 @@ public class HeadsUpSettings extends SettingsPreferenceFragment
        if (mHeadsUpEnabler != null) {
            mHeadsUpEnabler.pause();
        }
        getContentResolver().unregisterContentObserver(mSettingsObserver);
    }

    /**
@@ -355,6 +389,13 @@ public class HeadsUpSettings extends SettingsPreferenceFragment
        Settings.System.putString(getContentResolver(), setting, value);
    }

    private void updateEnabledState() {
        boolean enabled = Settings.System.getInt(getContentResolver(),
                Settings.System.HEADS_UP_NOTIFICATION, 0) != 0;
        mPrefsContainer.setVisibility(enabled ? View.VISIBLE : View.GONE);
        mDisabledText.setVisibility(enabled ? View.GONE : View.VISIBLE);
    }

    @Override
    public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
        final Preference pref =