From eeaec0d59138134992f0d5eeb52e615b68e91c5f Mon Sep 17 00:00:00 2001 From: David Passmore Date: Mon, 15 Feb 2016 13:14:15 +0000 Subject: [PATCH 1/5] Update nested screen implementation in reference to #3 --- .../SettingsExampleActivity.java | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java b/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java index bd4a1b3..3d5d6d3 100644 --- a/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java +++ b/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java @@ -213,35 +213,42 @@ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preferen public void setUpNestedScreen(PreferenceScreen preferenceScreen) { final Dialog dialog = preferenceScreen.getDialog(); - AppBarLayout bar; + Toolbar tBar; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent(); - bar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.toolbar_settings, root, false); - root.addView(bar, 0); + View listRoot = dialog.findViewById(android.R.id.list); + ViewGroup mRootView = (ViewGroup) dialog.findViewById(android.R.id.content); + + + if (listRoot != null) { + LinearLayout root = (LinearLayout) listRoot.getParent(); + bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.toolbar, root, false); + root.addView(bar, 0); // insert at top } else { - ViewGroup root = (ViewGroup) dialog.findViewById(android.R.id.content); - ListView content = (ListView) root.getChildAt(0); - root.removeAllViews(); - bar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.toolbar_settings, root, false); + ListView content = (ListView) mRootView.getChildAt(0); + mRootView.removeAllViews(); - int height; - TypedValue tv = new TypedValue(); - if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) { - height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()); - }else{ - height = bar.getHeight(); - } + LinearLayout LL = new LinearLayout(this); + LL.setOrientation(LinearLayout.VERTICAL); - content.setPadding(0, height, 0, 0); + ViewGroup.LayoutParams LLParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + LL.setLayoutParams(LLParams); - root.addView(content); - root.addView(bar); + bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.toolbar, mRootView, false); + + LL.addView(bar); + LL.addView(content); + + mRootView.addView(LL); } - Toolbar Tbar = (Toolbar) bar.getChildAt(0); - Tbar.setTitle(preferenceScreen.getTitle()); - Tbar.setNavigationOnClickListener(new View.OnClickListener() { + if(listRoot != null){ + listRoot.setPadding(0, listRoot.getPaddingTop(), 0, listRoot.getPaddingBottom()); + } + + tBar.setTitle(preferenceScreen.getTitle()); + + tBar.setNavigationOnClickListener(new View.OnClickListener() { + @Override public void onClick(View v) { dialog.dismiss(); } From a1a4d0c98caea561138622d077962f243e3c20cf Mon Sep 17 00:00:00 2001 From: David Passmore Date: Mon, 15 Feb 2016 13:21:12 +0000 Subject: [PATCH 2/5] Correction to layout fix #3 --- .../SettingsExampleActivity.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java b/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java index 3d5d6d3..a8a81ad 100644 --- a/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java +++ b/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java @@ -213,7 +213,7 @@ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preferen public void setUpNestedScreen(PreferenceScreen preferenceScreen) { final Dialog dialog = preferenceScreen.getDialog(); - Toolbar tBar; + AppBarLayout appBar; View listRoot = dialog.findViewById(android.R.id.list); ViewGroup mRootView = (ViewGroup) dialog.findViewById(android.R.id.content); @@ -221,8 +221,8 @@ public void setUpNestedScreen(PreferenceScreen preferenceScreen) { if (listRoot != null) { LinearLayout root = (LinearLayout) listRoot.getParent(); - bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.toolbar, root, false); - root.addView(bar, 0); // insert at top + appBar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false); + root.addView(bar, 0); } else { ListView content = (ListView) mRootView.getChildAt(0); mRootView.removeAllViews(); @@ -233,9 +233,9 @@ public void setUpNestedScreen(PreferenceScreen preferenceScreen) { ViewGroup.LayoutParams LLParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); LL.setLayoutParams(LLParams); - bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.toolbar, mRootView, false); + appBar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, mRootView, false); - LL.addView(bar); + LL.addView(appBar); LL.addView(content); mRootView.addView(LL); @@ -245,9 +245,11 @@ public void setUpNestedScreen(PreferenceScreen preferenceScreen) { listRoot.setPadding(0, listRoot.getPaddingTop(), 0, listRoot.getPaddingBottom()); } - tBar.setTitle(preferenceScreen.getTitle()); - - tBar.setNavigationOnClickListener(new View.OnClickListener() { + Toolbar Tbar = (Toolbar) appBar.getChildAt(0); + + Tbar.setTitle(preferenceScreen.getTitle()); + + Tbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); From 5c978d28e549f70c5daeda89d4f7d2718ca217dc Mon Sep 17 00:00:00 2001 From: David Passmore Date: Mon, 15 Feb 2016 13:24:16 +0000 Subject: [PATCH 3/5] Naming fix --- .../materialsettings/SettingsExampleActivity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java b/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java index a8a81ad..335502c 100644 --- a/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java +++ b/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java @@ -221,7 +221,7 @@ public void setUpNestedScreen(PreferenceScreen preferenceScreen) { if (listRoot != null) { LinearLayout root = (LinearLayout) listRoot.getParent(); - appBar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false); + appBar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.toolbar_settings, root, false); root.addView(bar, 0); } else { ListView content = (ListView) mRootView.getChildAt(0); @@ -233,7 +233,7 @@ public void setUpNestedScreen(PreferenceScreen preferenceScreen) { ViewGroup.LayoutParams LLParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); LL.setLayoutParams(LLParams); - appBar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, mRootView, false); + appBar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.toolbar_settings, mRootView, false); LL.addView(appBar); LL.addView(content); From 057c9c03314f07802dabcbe121679079d41e7387 Mon Sep 17 00:00:00 2001 From: David Passmore Date: Mon, 15 Feb 2016 13:27:43 +0000 Subject: [PATCH 4/5] Fix --- .../verscreative/materialsettings/SettingsExampleActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java b/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java index 335502c..6bf1152 100644 --- a/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java +++ b/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java @@ -222,7 +222,7 @@ public void setUpNestedScreen(PreferenceScreen preferenceScreen) { if (listRoot != null) { LinearLayout root = (LinearLayout) listRoot.getParent(); appBar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.toolbar_settings, root, false); - root.addView(bar, 0); + root.addView(appBar, 0); } else { ListView content = (ListView) mRootView.getChildAt(0); mRootView.removeAllViews(); From 4466d36038f28f5d1f22124b706966f013acf7c4 Mon Sep 17 00:00:00 2001 From: David Passmore Date: Mon, 15 Feb 2016 13:36:22 +0000 Subject: [PATCH 5/5] [release] 1.0.2 --- .../materialsettings/SettingsExampleActivity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java b/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java index 6bf1152..5951de1 100644 --- a/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java +++ b/app/src/main/java/uk/verscreative/materialsettings/SettingsExampleActivity.java @@ -219,8 +219,8 @@ public void setUpNestedScreen(PreferenceScreen preferenceScreen) { ViewGroup mRootView = (ViewGroup) dialog.findViewById(android.R.id.content); - if (listRoot != null) { - LinearLayout root = (LinearLayout) listRoot.getParent(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent(); appBar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.toolbar_settings, root, false); root.addView(appBar, 0); } else {