Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
gregkorossy committed Oct 27, 2017
2 parents f06543f + 8fce45f commit 8767eb5
Show file tree
Hide file tree
Showing 14 changed files with 266 additions and 43 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

**2017-10-27**

New version: 27.0.0.0 (based on v27.0.0)

- `PreferenceCategory`'s text color can be set from code (`setColor(...)` or `setColorResource(...)`) and XML (`app:pref_categoryColor` attribute)
- Added `PreferenceActivityResultListener` that can be used for handling click events by starting an `Activity` for result and receiving the results
- Enabled scrollbars on the preference list

**2017-10-24**

New version: 26.1.0.3 (based on v26.1.0)
Expand Down
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ If you would like to support me, you may donate some small amount via PayPal.
### 1. Add gradle dependency
First, **remove** the unnecessary lines of preference-v7 and preference-v14 from your gradle file as the bugfix contains both of them:
```gradle
compile 'com.android.support:preference-v7:26.1.0'
compile 'com.android.support:preference-v14:26.1.0'
compile 'com.android.support:preference-v7:27.0.0'
compile 'com.android.support:preference-v14:27.0.0'
```
And **add** this single line to your gradle file:
```gradle
compile 'com.takisoft.fix:preference-v7:26.1.0.3'
compile 'com.takisoft.fix:preference-v7:27.0.0.0'
```
> Notice the versioning: the first three numbers are *always* the same as the latest official library while the last number is for own updates. I try to keep it up-to-date but if, for whatever reasons, I wouldn't notice the new support library versions, just issue a ticket.
Expand Down Expand Up @@ -92,17 +92,17 @@ Now you can enjoy using the support preferences API without losing all your hair
There are additional preferences not part of the official support library, but decided to add them to some extra libraries. You can add all of them to your project using

```gradle
compile 'com.takisoft.fix:preference-v7-extras:26.1.0.3'
compile 'com.takisoft.fix:preference-v7-extras:27.0.0.0'
```

or one or more groups:

Preference | Dependency | Preview
-|-|-
[`RingtonePreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#ringtonepreference) | `compile 'com.takisoft.fix:preference-v7-ringtone:26.1.0.3'` | ![API 15](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/ringtone_api26.png)
[`DatePickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#datepickerpreference) | `compile 'com.takisoft.fix:preference-v7-datetimepicker:26.1.0.3'` | ![API 15](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/datepicker_api26.png)
[`TimePickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#timepickerpreference) | `compile 'com.takisoft.fix:preference-v7-datetimepicker:26.1.0.3'` | ![API 15](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/timepicker_api26.png)
[`ColorPickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#colorpickerpreference) | `compile 'com.takisoft.fix:preference-v7-colorpicker:26.1.0.3'` | ![API 15](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/colorpicker_api26_fixed.png)
[`RingtonePreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#ringtonepreference) | `compile 'com.takisoft.fix:preference-v7-ringtone:27.0.0.0'` | ![API 15](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/ringtone_api26.png)
[`DatePickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#datepickerpreference) | `compile 'com.takisoft.fix:preference-v7-datetimepicker:27.0.0.0'` | ![API 15](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/datepicker_api26.png)
[`TimePickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#timepickerpreference) | `compile 'com.takisoft.fix:preference-v7-datetimepicker:27.0.0.0'` | ![API 15](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/timepicker_api26.png)
[`ColorPickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#colorpickerpreference) | `compile 'com.takisoft.fix:preference-v7-colorpicker:27.0.0.0'` | ![API 15](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/colorpicker_api26_fixed.png)

---

Expand Down Expand Up @@ -148,7 +148,7 @@ The original implementation uses `?attr/textAppearanceSmall` as the message styl
---

## Version
The current stable version is **26.1.0.3**.
The current stable version is **27.0.0.0**.

## Notes #
This demo / bugfix is set to work on API level 14+.
Expand All @@ -167,6 +167,14 @@ API 15 | API 21 | API 26

### Changelog

**2017-10-27**

New version: 27.0.0.0 (based on v27.0.0)

- `PreferenceCategory`'s text color can be set from code (`setColor(...)` or `setColorResource(...)`) and XML (`app:pref_categoryColor` attribute)
- Added `PreferenceActivityResultListener` that can be used for handling click events by starting an `Activity` for result and receiving the results
- Enabled scrollbars on the preference list

**2017-10-24**

New version: 26.1.0.3 (based on v26.1.0)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.takisoft.preferencefix;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.preference.Preference;
import android.util.AttributeSet;
import android.widget.Toast;

import com.takisoft.fix.support.v7.preference.PreferenceActivityResultListener;
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompat;

public class ActivityResultTestPreference extends Preference implements PreferenceActivityResultListener {
public static final int RC_GET_CONTENT = 3462;

public ActivityResultTestPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}

public ActivityResultTestPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

public ActivityResultTestPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}

public ActivityResultTestPreference(Context context) {
super(context);
}

@Override
public void onPreferenceClick(@NonNull PreferenceFragmentCompat fragment, @NonNull Preference preference) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);

fragment.startActivityForResult(intent, RC_GET_CONTENT);
}

@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == RC_GET_CONTENT && resultCode == Activity.RESULT_OK && data != null) {
Toast.makeText(getContext(), data.getDataString(), Toast.LENGTH_LONG).show();
}
}
}
8 changes: 6 additions & 2 deletions app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@
android:title="SeekBarPreference"
app:showSeekBarValue="false" />
</PreferenceCategory>
<PreferenceCategory android:title="PreferenceCategory using preference_fallback_accent_color below API 21">

<PreferenceCategory
android:title="PreferenceCategory using different color"
app:pref_categoryColor="#2196f3">
<com.takisoft.preferencefix.ActivityResultTestPreference
android:summary="Click on this, it will launch a content picker Activity"
android:title="ActivityResultTestPreference" />
</PreferenceCategory>
<PreferenceCategory android:title="Another category">
<EditTextPreference
Expand Down
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
project.ext.buildToolsVersion = '26.0.2'
project.ext.buildToolsVersion = '27.0.0'
project.ext.minSdkVersion = 14
project.ext.sdkVersion = 26
project.ext.supportLibraryVersion = '26.1.0'
project.ext.supportLibraryVersionPrefix = '26.1.0'
project.ext.sdkVersion = 27
project.ext.supportLibraryVersion = '27.0.0'
project.ext.supportLibraryVersionPrefix = '27.0.0'
project.ext.supportLibraryVersionSuffix = ''
project.ext.fixLibraryVersion = '3'
project.ext.fixLibraryVersion = '0'

project.ext.extrasLibraryVersionSuffix = ''

Expand All @@ -15,7 +15,7 @@ buildscript {
maven { url "https://maven.google.com" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-rc2'
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class ColorPickerPreference extends DialogPreference {

static {
PreferenceFragmentCompat.addDialogPreference(ColorPickerPreference.class, ColorPickerPreferenceDialogFragmentCompat.class);
PreferenceFragmentCompat.registerPreferenceFragment(ColorPickerPreference.class, ColorPickerPreferenceDialogFragmentCompat.class);
}

private int[] colors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class DatePickerPreference extends DialogPreference {
public static final SimpleDateFormat FORMAT = new SimpleDateFormat(PATTERN, Locale.US);

static {
PreferenceFragmentCompat.addDialogPreference(DatePickerPreference.class, DatePickerPreferenceDialogFragmentCompat.class);
PreferenceFragmentCompat.registerPreferenceFragment(DatePickerPreference.class, DatePickerPreferenceDialogFragmentCompat.class);
}

private String summaryPattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class TimePickerPreference extends DialogPreference {
public static final SimpleDateFormat FORMAT = new SimpleDateFormat(PATTERN, Locale.US);

static {
PreferenceFragmentCompat.addDialogPreference(TimePickerPreference.class, TimePickerPreferenceDialogFragmentCompat.class);
PreferenceFragmentCompat.registerPreferenceFragment(TimePickerPreference.class, TimePickerPreferenceDialogFragmentCompat.class);
}

public static final int FORMAT_AUTO = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class RingtonePreference extends DialogPreference {
}

static {
PreferenceFragmentCompat.addDialogPreference(RingtonePreference.class, RingtonePreferenceDialogFragmentCompat.class);
PreferenceFragmentCompat.registerPreferenceFragment(RingtonePreference.class, RingtonePreferenceDialogFragmentCompat.class);
}

public RingtonePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.takisoft.fix.support.v7.preference;

import android.app.Activity;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.preference.Preference;

/**
* An interface for custom preferences that want to handle click events by either starting an
* {@link Activity} for results calling {@link Fragment#startActivityForResult(Intent, int)} or
* using the supplied {@link PreferenceFragmentCompat} fragment manually (e.g. adding a fragment to
* it).
*/
public interface PreferenceActivityResultListener {
/**
* Called when the user clicks on the preference.
*
* @param fragment The preference fragment that shows the preference screen.
* @param preference The preference instance.
*/
void onPreferenceClick(@NonNull PreferenceFragmentCompat fragment, @NonNull Preference preference);

/**
* Called when an activity you launched exits, giving you the requestCode
* you started it with, the resultCode it returned, and any additional
* data from it. The <var>resultCode</var> will be
* {@link Activity#RESULT_CANCELED} if the activity explicitly returned that,
* didn't return any result, or crashed during its operation.
*
* @param requestCode The integer request code originally supplied to startActivityForResult(), allowing you to identify who this result came from.
* @param resultCode The integer result code returned by the child activity through its setResult().
* @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
*/
void onActivityResult(int requestCode, int resultCode, @Nullable Intent data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.v4.content.res.TypedArrayUtils;
import android.support.v7.preference.PreferenceViewHolder;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
Expand All @@ -21,22 +25,27 @@
public class PreferenceCategory extends android.support.v7.preference.PreferenceCategory {
private static final int[] CATEGORY_ATTRS = new int[]{R.attr.colorAccent, R.attr.preferenceCategory_marginBottom};

protected int color;
protected View itemView;

public PreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PreferenceCategory, defStyleAttr, 0);
color = a.getColor(R.styleable.PreferenceCategory_pref_categoryColor, 0);
a.recycle();
}

public PreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this(context, attrs, defStyleAttr, 0);
}

public PreferenceCategory(Context context, AttributeSet attrs) {
super(context, attrs);
this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.preferenceCategoryStyle, android.R.attr.preferenceCategoryStyle));
}

public PreferenceCategory(Context context) {
super(context);
this(context, null);
}

private void setTitleVisibility(View itemView, boolean isVisible) {
Expand Down Expand Up @@ -86,6 +95,22 @@ public void setTitle(CharSequence title) {
setTitleVisibility(itemView, !TextUtils.isEmpty(getTitle()));
}

public void setColor(@ColorInt int color) {
this.color = color;
}

public void setColorResource(@ColorRes int resId) {
int color;

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
color = getContext().getResources().getColor(resId);
} else {
color = getContext().getColor(resId);
}

setColor(color);
}

@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
Expand All @@ -99,7 +124,7 @@ public void onBindViewHolder(PreferenceViewHolder holder) {

if (typedArray.length() > 0 && typedArray.getIndexCount() > 0) {
final int accentColor = typedArray.getColor(typedArray.getIndex(0), 0xff4081); // defaults to pink
titleView.setTextColor(accentColor);
titleView.setTextColor(color == 0 ? accentColor : color);

final int marginIdx = typedArray.getIndex(1);
final TypedValue marginValue = typedArray.peekValue(marginIdx);
Expand Down
Loading

0 comments on commit 8767eb5

Please sign in to comment.