diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 28ada1c..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,36 +0,0 @@ -Change Log -========== - -Version 1.0.5 *(2017-12-04)* ----------------------------- - -- Update Support lib version to 27.0.2 - -Version 1.0.4 *(2017-11-02)* ----------------------------- - -- Update internal dependencies. - -Version 1.0.3 *(2017-04-22)* ----------------------------- - -- Fix NullPointerException when the array referenced by `colorChoices` attribute contains color references instead of color strings. -- Update internal dependencies. - -Version 1.0.2 *(2016-10-02)* ----------------------------- - -- The inbuilt color picker can now be used in any activity. -- Changed gradle compile statement. - - -Version 1.0.1 *(2016-09-28)* ----------------------------- - -- Added support for the support-preference-v7/v14 library. - - -Version 1.0.0 *(2016-09-24)* ----------------------------- - -- Initial release. \ No newline at end of file diff --git a/core/src/main/java/com/kizitonwose/colorpreference/ColorDialog.java b/core/src/main/java/com/kizitonwose/colorpreference/ColorDialog.java index e897dd7..12c7be1 100644 --- a/core/src/main/java/com/kizitonwose/colorpreference/ColorDialog.java +++ b/core/src/main/java/com/kizitonwose/colorpreference/ColorDialog.java @@ -82,7 +82,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { LayoutInflater layoutInflater = LayoutInflater.from(getActivity()); View rootView = layoutInflater.inflate(R.layout.dialog_colors, null); - colorGrid = (GridLayout) rootView.findViewById(R.id.color_grid); + colorGrid = rootView.findViewById(R.id.color_grid); colorGrid.setColumnCount(numColumns); repopulateItems(); diff --git a/core/src/main/java/com/kizitonwose/colorpreference/ColorPreference.java b/core/src/main/java/com/kizitonwose/colorpreference/ColorPreference.java index 30408a5..a7807cb 100644 --- a/core/src/main/java/com/kizitonwose/colorpreference/ColorPreference.java +++ b/core/src/main/java/com/kizitonwose/colorpreference/ColorPreference.java @@ -36,7 +36,7 @@ private void initAttrs(AttributeSet attrs, int defStyle) { TypedArray a = getContext().getTheme().obtainStyledAttributes( attrs, R.styleable.ColorPreference, defStyle, defStyle); - PreviewSize previewSize = PreviewSize.NORMAL; + PreviewSize previewSize; try { numColumns = a.getInteger(R.styleable.ColorPreference_numColumns, numColumns); colorShape = ColorShape.getShape(a.getInteger(R.styleable.ColorPreference_colorShape, 1)); @@ -56,8 +56,10 @@ private void initAttrs(AttributeSet attrs, int defStyle) { @Override protected void onBindView(View view) { super.onBindView(view); - ImageView previewView = (ImageView) view.findViewById(R.id.color_view); - ColorUtils.setColorViewValue(previewView, value, false, colorShape); + ImageView colorView = view.findViewById(R.id.color_view); + if (colorView != null) { + ColorUtils.setColorViewValue(colorView, value, false, colorShape); + } } public void setValue(int value) { diff --git a/core/src/main/java/com/kizitonwose/colorpreference/ColorUtils.java b/core/src/main/java/com/kizitonwose/colorpreference/ColorUtils.java index afcc237..2ead517 100644 --- a/core/src/main/java/com/kizitonwose/colorpreference/ColorUtils.java +++ b/core/src/main/java/com/kizitonwose/colorpreference/ColorUtils.java @@ -86,18 +86,22 @@ public static void showDialog(Context context, ColorDialog.OnColorSelectedListen fragment.setOnColorSelectedListener(listener); Activity activity = Utils.resolveContext(context); - activity.getFragmentManager().beginTransaction() - .add(fragment, tag) - .commit(); + if (activity != null) { + activity.getFragmentManager() + .beginTransaction() + .add(fragment, tag) + .commit(); + } } public static void attach(Context context, ColorDialog.OnColorSelectedListener listener, String tag) { Activity activity = Utils.resolveContext(context); - ColorDialog fragment = (ColorDialog) activity - .getFragmentManager().findFragmentByTag(tag); - if (fragment != null) { - // re-bind preference to fragment - fragment.setOnColorSelectedListener(listener); + if (activity != null) { + ColorDialog fragment = (ColorDialog) activity.getFragmentManager().findFragmentByTag(tag); + if (fragment != null) { + // re-bind preference to fragment + fragment.setOnColorSelectedListener(listener); + } } } diff --git a/core/src/main/java/com/kizitonwose/colorpreference/Utils.java b/core/src/main/java/com/kizitonwose/colorpreference/Utils.java index 168c646..1b1470b 100644 --- a/core/src/main/java/com/kizitonwose/colorpreference/Utils.java +++ b/core/src/main/java/com/kizitonwose/colorpreference/Utils.java @@ -9,9 +9,9 @@ * @author Kizito Nwose */ -public class Utils { +class Utils { @Nullable - public static Activity resolveContext(Context context) { + static Activity resolveContext(Context context) { if (context instanceof Activity) { return (Activity) context; } else if (context instanceof ContextWrapper) { diff --git a/support/src/main/java/com/kizitonwose/colorpreferencecompat/ColorPreferenceCompat.java b/support/src/main/java/com/kizitonwose/colorpreferencecompat/ColorPreferenceCompat.java index 99d5eb6..49bd0fa 100644 --- a/support/src/main/java/com/kizitonwose/colorpreferencecompat/ColorPreferenceCompat.java +++ b/support/src/main/java/com/kizitonwose/colorpreferencecompat/ColorPreferenceCompat.java @@ -43,7 +43,7 @@ private void initAttrs(AttributeSet attrs, int defStyle) { TypedArray a = getContext().getTheme().obtainStyledAttributes( attrs, R.styleable.ColorPreferenceCompat, defStyle, defStyle); - PreviewSize previewSize = PreviewSize.NORMAL; + PreviewSize previewSize; try { numColumns = a.getInteger(R.styleable.ColorPreferenceCompat_numColumns, numColumns); colorShape = ColorShape.getShape(a.getInteger(R.styleable.ColorPreferenceCompat_colorShape, 1)); @@ -63,8 +63,10 @@ private void initAttrs(AttributeSet attrs, int defStyle) { @Override public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); - ImageView previewView = (ImageView) holder.findViewById(R.id.color_view); - ColorUtils.setColorViewValue(previewView, value, false, colorShape); + ImageView colorView = (ImageView) holder.findViewById(R.id.color_view); + if (colorView != null) { + ColorUtils.setColorViewValue(colorView, value, false, colorShape); + } } public void setValue(int value) {