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

Commit 86159283 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

Add the capability to set a pinned header to SettingsPreferenceFragment

- add a FrameLayout into the preference list fragment
- add public void setPinnedHeaderView(View pinnedHeader) and
clearPinnedHeaderView() APIs for adding and clearing the pinned header

Change-Id: I50ba5dd150167e0d49cc54bee1203f46db6d7a66
parent 20b32f25
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -20,10 +20,15 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/container_material"
      android:orientation="vertical"
      android:layout_height="match_parent"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@android:color/transparent">

    <FrameLayout android:id="@+id/pinned_header"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:visibility="gone" />

    <ListView android:id="@android:id/list"
              style="@style/PreferenceFragmentListSinglePane"
              android:layout_width="match_parent"
@@ -59,6 +64,7 @@
                android:layout_alignParentStart="true"
                android:text="@*android:string/back_button_label"
                />

        <LinearLayout
                android:orientation="horizontal"
                android:layout_width="wrap_content"
@@ -79,6 +85,7 @@
                    android:layout_margin="5dip"
                    android:text="@*android:string/next_button_label"
                    />

        </LinearLayout>

    </RelativeLayout>
+22 −0
Original line number Diff line number Diff line
@@ -33,10 +33,12 @@ import android.preference.PreferenceFragment;
import android.preference.PreferenceGroupAdapter;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
@@ -77,6 +79,8 @@ public class SettingsPreferenceFragment extends PreferenceFragment implements Di
        }
    };

    private ViewGroup mPinnedHeaderFrameLayout;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
@@ -92,6 +96,24 @@ public class SettingsPreferenceFragment extends PreferenceFragment implements Di
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        final View root = super.onCreateView(inflater, container, savedInstanceState);
        mPinnedHeaderFrameLayout = (ViewGroup) root.findViewById(R.id.pinned_header);
        return root;
    }

    public void setPinnedHeaderView(View pinnedHeader) {
        mPinnedHeaderFrameLayout.addView(pinnedHeader);
        mPinnedHeaderFrameLayout.setVisibility(View.VISIBLE);
    }

    public void clearPinnedHeaderView() {
        mPinnedHeaderFrameLayout.removeAllViews();
        mPinnedHeaderFrameLayout.setVisibility(View.GONE);
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
+1 −3
Original line number Diff line number Diff line
@@ -42,10 +42,8 @@ import android.provider.MediaStore;
import android.provider.ContactsContract.DisplayPhoto;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
@@ -97,7 +95,7 @@ public class RestrictedProfileSettings extends AppRestrictionsFragment {
        if (mHeaderView == null) {
            mHeaderView = LayoutInflater.from(getActivity()).inflate(
                    R.layout.user_info_header, null);
            ((ViewGroup) getListView().getParent()).addView(mHeaderView, 0);
            setPinnedHeaderView(mHeaderView);
            mHeaderView.setOnClickListener(this);
            mUserIconView = (ImageView) mHeaderView.findViewById(android.R.id.icon);
            mUserNameView = (TextView) mHeaderView.findViewById(android.R.id.title);