Skip to content
This repository was archived by the owner on May 1, 2021. It is now read-only.

Commit a925b14

Browse files
-fixed style of generic Preference class.
-added workaround for handling the styles of inner-PrerenceScreen class. (will be handled just after using the settings XML file.
1 parent 2d3add8 commit a925b14

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

material_preferences_library/material_preferences_library.iml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id=":material_preferences_library" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/../../AppManager" external.system.id="GRADLE" external.system.module.group="AppManager" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id=":material_preferences_library" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="MaterialPreferences" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android-gradle" name="Android-Gradle">
55
<configuration>
@@ -72,8 +72,6 @@
7272
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
7373
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
7474
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
75-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.1.1/jars" />
76-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.1.1/jars" />
7775
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
7876
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
7977
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
@@ -91,8 +89,8 @@
9189
</content>
9290
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
9391
<orderEntry type="sourceFolder" forTests="false" />
94-
<orderEntry type="library" exported="" name="support-annotations-22.1.1" level="project" />
95-
<orderEntry type="library" exported="" name="support-v4-22.1.1" level="project" />
96-
<orderEntry type="library" exported="" name="appcompat-v7-22.1.1" level="project" />
92+
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
93+
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
94+
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
9795
</component>
9896
</module>

material_preferences_library/src/main/java/com/lb/material_preferences_library/PreferenceActivity.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33
import android.os.Build.VERSION;
44
import android.os.Build.VERSION_CODES;
55
import android.os.Bundle;
6+
import android.preference.Preference;
7+
import android.preference.PreferenceGroup;
8+
import android.preference.PreferenceScreen;
69
import android.support.annotation.XmlRes;
710
import android.support.v7.widget.Toolbar;
811
import android.util.TypedValue;
912
import android.view.View;
1013
import android.view.ViewGroup;
1114

15+
import java.util.HashMap;
16+
import java.util.Map;
17+
import java.util.Stack;
18+
1219
public abstract class PreferenceActivity extends AppCompatPreferenceActivity
1320
{
1421
private Toolbar _toolbar;
@@ -37,6 +44,10 @@ protected void onCreate(final Bundle savedInstanceState)
3744
parent.removeView(shadowView);
3845
}
3946
addPreferencesFromResource(getPreferencesXmlId());
47+
final Map<Preference,PreferenceGroup> preferenceToParentMap=buildPreferenceParentTree(this);
48+
for(PreferenceGroup preferenceGroup : preferenceToParentMap.values())
49+
if(preferenceGroup!=null&&preferenceGroup instanceof PreferenceScreen)
50+
preferenceGroup.setLayoutResource(R.layout.mpl__preference);
4051
_toolbar.setClickable(true);
4152
_toolbar.setNavigationIcon(getResIdFromAttribute(this,R.attr.homeAsUpIndicator));
4253
_toolbar.setNavigationOnClickListener(new View.OnClickListener()
@@ -59,4 +70,25 @@ private static int getResIdFromAttribute(final Activity activity,final int attr)
5970
return typedValue.resourceId;
6071
}
6172

73+
@SuppressWarnings("deprecation")
74+
public static Map<Preference,PreferenceGroup> buildPreferenceParentTree(final android.preference.PreferenceActivity activity)
75+
{
76+
final Map<Preference,PreferenceGroup> result=new HashMap<>();
77+
final Stack<PreferenceGroup> curParents=new Stack<>();
78+
curParents.add(activity.getPreferenceScreen());
79+
while(!curParents.isEmpty())
80+
{
81+
final PreferenceGroup parent=curParents.pop();
82+
final int childCount=parent.getPreferenceCount();
83+
for(int i=0;i<childCount;++i)
84+
{
85+
final Preference child=parent.getPreference(i);
86+
result.put(child,parent);
87+
if(child instanceof PreferenceGroup)
88+
curParents.push((PreferenceGroup)child);
89+
}
90+
}
91+
return result;
92+
}
93+
6294
}

material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/Preference.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,21 @@ public Preference(Context context,AttributeSet attrs,int defStyleAttr)
4040
public Preference(Context context,AttributeSet attrs)
4141
{
4242
super(context,attrs);
43+
if(!_isInitialized)
44+
{
45+
_isInitialized=true;
46+
init(context,attrs,0,0);
47+
}
4348
}
4449

4550
public Preference(Context context)
4651
{
4752
super(context);
53+
if(!_isInitialized)
54+
{
55+
_isInitialized=true;
56+
init(context,null,0,0);
57+
}
4858
}
4959

5060
}

0 commit comments

Comments
 (0)