Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ru26kif committed Sep 6, 2020
1 parent 254282c commit ed7102c
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 30 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ allprojects {
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
versionCode=1
versionName="1.0"
}
}

Expand Down
4 changes: 2 additions & 2 deletions colorpreference/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
defaultConfig {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 1
versionName "1.0"
versionCode rootProject.versionCode
versionName rootProject.versionName
}

buildTypes {
Expand Down
4 changes: 2 additions & 2 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.example.prefsplus"
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 1
versionName "1.0"
versionCode rootProject.versionCode
versionName rootProject.versionName

testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
Expand Down
11 changes: 3 additions & 8 deletions demo/src/main/java/com/example/prefsplus/SettingsActivityX.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceFragmentCompat;

import com.mapzen.prefsplusx.DefaultPreferenceFragment;

/**
* Settings Activity that uses the new preferences (PreferenceFragmentCompat)
*/
Expand All @@ -19,7 +21,7 @@ protected void onCreate(Bundle savedInstanceState) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
getSupportFragmentManager().beginTransaction().replace(android.R.id.content,
new SettingsFragment()).commit();
new DefaultPreferenceFragment(R.xml.preferencesx)).commit();
}

@Override
Expand All @@ -32,11 +34,4 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

public static class SettingsFragment extends PreferenceFragmentCompat {

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.preferencesx, rootKey);
}
}
}
4 changes: 2 additions & 2 deletions prefs-plusx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
defaultConfig {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 1
versionName "1.0"
versionCode rootProject.versionCode
versionName rootProject.versionName

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
package com.mapzen.prefsplusx;

import android.content.SharedPreferences;
import android.os.Bundle;

import androidx.annotation.XmlRes;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;

import static android.content.Context.MODE_PRIVATE;

// Takes the resource file in the constructor
// Does nothing special,you can use this one whenever you don't want to declare a new fragment just for an xml preference screen
public class DefaultPreferenceFragment extends PreferenceFragmentCompat {
private final String sharedPreferencesName;
private final PreferenceScreen preferenceScreen;
private final @XmlRes int resourceFile;

DefaultPreferenceFragment(PreferenceScreen preferenceScreen, String sharedPreferencesName) {
this.preferenceScreen = preferenceScreen;
this.sharedPreferencesName=sharedPreferencesName;
public DefaultPreferenceFragment(@XmlRes int resourceFile) {
this.resourceFile=resourceFile;
}

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
PreferenceManager prefMgr = getPreferenceManager();
prefMgr.setSharedPreferencesName(sharedPreferencesName);
prefMgr.setSharedPreferencesMode(MODE_PRIVATE);
setPreferenceScreen(preferenceScreen);
setPreferencesFromResource(resourceFile, rootKey);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private void init(AttributeSet attrs, int defStyle){
attrs, R.styleable.EditIntPreference, defStyle, defStyle);
minimumValue=a.getFloat(R.styleable.EditFloatPreference_minFloatValue,Float.MIN_VALUE);
maximumValue=a.getFloat(R.styleable.EditFloatPreference_maxFloatValue,Float.MAX_VALUE);
Log.d(TAG,"Min & max"+minimumValue+" "+maximumValue);
//Log.d(TAG,"Min & max"+minimumValue+" "+maximumValue);
a.recycle();
}
super.setOnBindEditTextListener(new OnBindEditTextListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.util.AttributeSet;
import android.util.Log;

import androidx.core.content.res.TypedArrayUtils;
import androidx.preference.ListPreference;

import java.util.Arrays;
Expand All @@ -29,10 +30,17 @@ public IntListPreference(Context context, AttributeSet attrs) {
// If there are no entry values set populate it with a default array that holds
// as many entries as the entry array and maps element 0 -> 0, element 1 -> 1 and more
private void setDefaultEntryValuesIfNull(){
/*if(getEntryValues()!=null){
Log.d(TAG,"Has entry values "+ Arrays.toString(getEntryValues()));
}else{
Log.d(TAG,"Has no entry values");
}*/
if(getEntryValues()==null){
//Log.d(TAG,"Setting default entry values");
if(getEntries()==null){
Log.w(TAG,"No entries - will crash");
// You probably forgot to set the entry values
// example,in your xml,do : android:entries="@array/int_list_entries"
throw new RuntimeException("List preference has no entries");
}
final int size=getEntries().length;
CharSequence[] defaultEntryValues =new CharSequence[size];
Expand Down

0 comments on commit ed7102c

Please sign in to comment.