diff options
Diffstat (limited to 'extensions/baseAdapters/src')
23 files changed, 1118 insertions, 0 deletions
diff --git a/extensions/baseAdapters/src/main/AndroidManifest.xml b/extensions/baseAdapters/src/main/AndroidManifest.xml new file mode 100644 index 00000000..38cf7790 --- /dev/null +++ b/extensions/baseAdapters/src/main/AndroidManifest.xml @@ -0,0 +1,19 @@ +<!-- + ~ Copyright (C) 2015 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.databinding.library.baseAdapters"> +</manifest> diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/AbsListViewBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/AbsListViewBindingAdapter.java new file mode 100644 index 00000000..c8b481d4 --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/AbsListViewBindingAdapter.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingMethod; +import android.binding.BindingMethods; + +@BindingMethods({ + @BindingMethod(type = "android.widget.AbsListView", attribute = "android:listSelector", method = "setSelector"), + @BindingMethod(type = "android.widget.AbsListView", attribute = "android:scrollingCache", method = "setScrollingCacheEnabled"), + @BindingMethod(type = "android.widget.AbsListView", attribute = "android:smoothScrollbar", method = "setSmoothScrollbarEnabled"), +}) +public class AbsListViewBindingAdapter { + +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/AbsSeekBarBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/AbsSeekBarBindingAdapter.java new file mode 100644 index 00000000..f02be48c --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/AbsSeekBarBindingAdapter.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingMethod; +import android.binding.BindingMethods; + +@BindingMethods({ + @BindingMethod(type = "android.widget.AbsSeekBar", attribute = "android:thumbTint", method = "setThumbTintList"), + +}) +public class AbsSeekBarBindingAdapter { + +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/AbsSpinnerBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/AbsSpinnerBindingAdapter.java new file mode 100644 index 00000000..b02ff074 --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/AbsSpinnerBindingAdapter.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingAdapter; +import android.widget.AbsSpinner; +import android.widget.ArrayAdapter; +import android.widget.SpinnerAdapter; + +public class AbsSpinnerBindingAdapter { + + @BindingAdapter("android:entries") + public static void setEntries(AbsSpinner view, CharSequence[] entries) { + if (entries != null) { + SpinnerAdapter oldAdapter = view.getAdapter(); + boolean changed = true; + if (oldAdapter != null && oldAdapter.getCount() == entries.length) { + changed = false; + for (int i = 0; i < entries.length; i++) { + if (!entries[i].equals(oldAdapter.getItem(i))) { + changed = true; + break; + } + } + } + if (changed) { + ArrayAdapter<CharSequence> adapter = + new ArrayAdapter<CharSequence>(view.getContext(), + android.R.layout.simple_spinner_item, entries); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + view.setAdapter(adapter); + } + } else { + view.setAdapter(null); + } + } +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/AutoCompleteTextViewBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/AutoCompleteTextViewBindingAdapter.java new file mode 100644 index 00000000..79c06a8a --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/AutoCompleteTextViewBindingAdapter.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingMethod; +import android.binding.BindingMethods; + +@BindingMethods({ + @BindingMethod(type = "android.widget.AutoCompleteTextView", attribute = "android:completionThreshold", method = "setThreshold"), + @BindingMethod(type = "android.widget.AutoCompleteTextView", attribute = "android:popupBackground", method = "setDropDownBackgroundDrawable"), +}) +public class AutoCompleteTextViewBindingAdapter { + +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/CardViewBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/CardViewBindingAdapter.java new file mode 100644 index 00000000..ba5246dd --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/CardViewBindingAdapter.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingAdapter; +import android.binding.BindingMethod; +import android.binding.BindingMethods; +import android.support.v7.widget.CardView; + +@BindingMethods({ + @BindingMethod(type = "android.support.v7.widget.CardView", attribute = "cardCornerRadius", method = "setRadius"), + @BindingMethod(type = "android.support.v7.widget.CardView", attribute = "cardMaxElevation", method = "setMaxCardElevation"), + @BindingMethod(type = "android.support.v7.widget.CardView", attribute = "cardPreventCornerOverlap", method = "setPreventCornerOverlap"), + @BindingMethod(type = "android.support.v7.widget.CardView", attribute = "cardUseCompatPadding", method = "setUseCompatPadding"), +}) +public class CardViewBindingAdapter { + + @BindingAdapter("contentPadding") + public static void setContentPadding(CardView view, int padding) { + view.setContentPadding(padding, padding, padding, padding); + } + + @BindingAdapter("contentPaddingLeft") + public static void setContentPaddingLeft(CardView view, int left) { + int top = view.getContentPaddingTop(); + int right = view.getContentPaddingRight(); + int bottom = view.getContentPaddingBottom(); + view.setContentPadding(left, top, right, bottom); + } + + @BindingAdapter("contentPaddingTop") + public static void setContentPaddingTop(CardView view, int top) { + int left = view.getContentPaddingLeft(); + int right = view.getContentPaddingRight(); + int bottom = view.getContentPaddingBottom(); + view.setContentPadding(left, top, right, bottom); + } + + @BindingAdapter("contentPaddingRight") + public static void setContentPaddingRight(CardView view, int right) { + int left = view.getContentPaddingLeft(); + int top = view.getContentPaddingTop(); + int bottom = view.getContentPaddingBottom(); + view.setContentPadding(left, top, right, bottom); + } + + @BindingAdapter("contentPaddingBottom") + public static void setContentPaddingBottom(CardView view, int bottom) { + int left = view.getContentPaddingLeft(); + int top = view.getContentPaddingTop(); + int right = view.getContentPaddingRight(); + view.setContentPadding(left, top, right, bottom); + } +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/CheckedTextViewBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/CheckedTextViewBindingAdapter.java new file mode 100644 index 00000000..3b16d080 --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/CheckedTextViewBindingAdapter.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingMethod; +import android.binding.BindingMethods; + +@BindingMethods({ + @BindingMethod(type = "android.widget.CheckedTextView", attribute = "android:checkMark", method = "setCheckMarkDrawable"), + @BindingMethod(type = "android.widget.CheckedTextView", attribute = "android:checkMarkTint", method = "setCheckMarkTintList"), +}) +public class CheckedTextViewBindingAdapter { + +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/CompoundButtonBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/CompoundButtonBindingAdapter.java new file mode 100644 index 00000000..7115bc5c --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/CompoundButtonBindingAdapter.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingMethod; +import android.binding.BindingMethods; + +@BindingMethods({ + @BindingMethod(type = "android.widget.CompoundButton", attribute = "android:buttonTint", method = "setButtonTintList"), +}) +public class CompoundButtonBindingAdapter { + +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/Converters.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/Converters.java new file mode 100644 index 00000000..5982dc12 --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/Converters.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingConversion; +import android.content.res.ColorStateList; +import android.graphics.drawable.ColorDrawable; + +public class Converters { + @BindingConversion + public static ColorDrawable convertColorToDrawable(int color) { + return new ColorDrawable(color); + } + + @BindingConversion + public static ColorStateList convertColorToColorStateList(int color) { + return ColorStateList.valueOf(color); + } +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/FrameLayoutBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/FrameLayoutBindingAdapter.java new file mode 100644 index 00000000..49aa6a5b --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/FrameLayoutBindingAdapter.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingMethod; +import android.binding.BindingMethods; + +@BindingMethods({ + @BindingMethod(type = "android.widget.FrameLayout", attribute = "android:foregroundTint", method = "setForegroundTintList"), +}) +public class FrameLayoutBindingAdapter { + +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/ImageViewBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/ImageViewBindingAdapter.java new file mode 100644 index 00000000..e2d09293 --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/ImageViewBindingAdapter.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingMethod; +import android.binding.BindingMethods; + +@BindingMethods({ + @BindingMethod(type = "android.widget.ImageView", attribute = "android:src", method = "setImageDrawable"), + @BindingMethod(type = "android.widget.ImageView", attribute = "android:tint", method = "setImageTintList"), + @BindingMethod(type = "android.widget.ImageView", attribute = "android:tintMode", method = "setImageTintMode"), +}) +public class ImageViewBindingAdapter { + +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/LinearLayoutBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/LinearLayoutBindingAdapter.java new file mode 100644 index 00000000..b0a4cc43 --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/LinearLayoutBindingAdapter.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingMethod; +import android.binding.BindingMethods; + +@BindingMethods({ + @BindingMethod(type = "android.widget.LinearLayout", attribute = "android:divider", method = "setDividerDrawable"), + @BindingMethod(type = "android.widget.LinearLayout", attribute = "android:measureWithLargestChild", method = "setMeasureWithLargestChildEnabled"), +}) +public class LinearLayoutBindingAdapter { + +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/ProgressBarBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/ProgressBarBindingAdapter.java new file mode 100644 index 00000000..b0d6249e --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/ProgressBarBindingAdapter.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingMethod; +import android.binding.BindingMethods; + +@BindingMethods({ + @BindingMethod(type = "android.widget.ProgressBar", attribute = "android:indeterminateTint", method = "setIndeterminateTintList"), + @BindingMethod(type = "android.widget.ProgressBar", attribute = "android:progressTint", method = "setProgressTintList"), + @BindingMethod(type = "android.widget.ProgressBar", attribute = "android:secondaryProgressTint", method = "setSecondaryProgressTintList"), +}) +public class ProgressBarBindingAdapter { + +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/RadioGroupBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/RadioGroupBindingAdapter.java new file mode 100644 index 00000000..8d21b7af --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/RadioGroupBindingAdapter.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingMethod; +import android.binding.BindingMethods; + +@BindingMethods({ + @BindingMethod(type = "android.widget.RadioGroup", attribute = "android:checkedButton", method = "check"), +}) +public class RadioGroupBindingAdapter { + +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/SpinnerBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/SpinnerBindingAdapter.java new file mode 100644 index 00000000..34a62c7e --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/SpinnerBindingAdapter.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingMethod; +import android.binding.BindingMethods; + +@BindingMethods({ + @BindingMethod(type = "android.widget.Spinner", attribute = "android:popupBackground", method = "setPopupBackgroundDrawable"), +}) +public class SpinnerBindingAdapter { + +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/SwitchBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/SwitchBindingAdapter.java new file mode 100644 index 00000000..3645118a --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/SwitchBindingAdapter.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.annotation.TargetApi; +import android.binding.BindingAdapter; +import android.binding.BindingMethod; +import android.binding.BindingMethods; +import android.os.Build; +import android.widget.Switch; + +@BindingMethods({ + @BindingMethod(type = "android.widget.Switch", attribute = "android:thumb", method = "setThumbDrawable"), + @BindingMethod(type = "android.widget.Switch", attribute = "android:track", method = "setTrackDrawable"), +}) +@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) +public class SwitchBindingAdapter { + + @BindingAdapter("android:switchTextAppearance") + public static void setSwitchTextAppearance(Switch view, int value) { + view.setSwitchTextAppearance(null, value); + } +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/SwitchCompatBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/SwitchCompatBindingAdapter.java new file mode 100644 index 00000000..4c3c996a --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/SwitchCompatBindingAdapter.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingAdapter; +import android.binding.BindingMethod; +import android.binding.BindingMethods; +import android.support.v7.widget.SwitchCompat; + +@BindingMethods({ + @BindingMethod(type = "android.support.v7.widget.SwitchCompat", attribute = "android:thumb", method = "setThumbDrawable"), + @BindingMethod(type = "android.support.v7.widget.SwitchCompat", attribute = "android:track", method = "setTrackDrawable"), +}) +public class SwitchCompatBindingAdapter { + + @BindingAdapter("android:switchTextAppearance") + public static void setSwitchTextAppearance(SwitchCompat view, int value) { + view.setSwitchTextAppearance(null, value); + } +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/TabWidgetBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/TabWidgetBindingAdapter.java new file mode 100644 index 00000000..8c58e915 --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/TabWidgetBindingAdapter.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingMethod; +import android.binding.BindingMethods; + +@BindingMethods({ + @BindingMethod(type = "android.widget.TabWidget", attribute = "android:divider", method = "setDividerDrawable"), + @BindingMethod(type = "android.widget.TabWidget", attribute = "android:tabStripEnabled", method = "setStripEnabled"), + @BindingMethod(type = "android.widget.TabWidget", attribute = "android:tabStripLeft", method = "setLeftStripDrawable"), + @BindingMethod(type = "android.widget.TabWidget", attribute = "android:tabStripRight", method = "setRightStripDrawable"), +}) +public class TabWidgetBindingAdapter { + +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/TableLayoutBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/TableLayoutBindingAdapter.java new file mode 100644 index 00000000..1973799e --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/TableLayoutBindingAdapter.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingAdapter; +import android.util.SparseBooleanArray; +import android.widget.TableLayout; + +import java.util.regex.Pattern; + +public class TableLayoutBindingAdapter { + + private static Pattern sColumnPattern = Pattern.compile("\\s*,\\s*"); + + private static final int MAX_COLUMNS = 20; + + @BindingAdapter("android:collapseColumns") + public static void setCollapseColumns(TableLayout view, CharSequence columnsStr) { + SparseBooleanArray columns = parseColumns(columnsStr); + for (int i = 0; i < MAX_COLUMNS; i++) { + boolean isCollapsed = columns.get(i, false); + if (isCollapsed != view.isColumnCollapsed(i)) { + view.setColumnCollapsed(i, isCollapsed); + } + } + } + + @BindingAdapter("android:shrinkColumns") + public static void setShrinkColumns(TableLayout view, CharSequence columnsStr) { + if (columnsStr != null && columnsStr.length() > 0 && columnsStr.charAt(0) == '*') { + view.setShrinkAllColumns(true); + } else { + view.setShrinkAllColumns(false); + SparseBooleanArray columns = parseColumns(columnsStr); + int columnCount = columns.size(); + for (int i = 0; i < columnCount; i++) { + int column = columns.keyAt(i); + boolean shrinkable = columns.valueAt(i); + if (shrinkable) { + view.setColumnShrinkable(column, shrinkable); + } + } + } + } + + @BindingAdapter("android:stretchColumns") + public static void setStretchColumns(TableLayout view, CharSequence columnsStr) { + if (columnsStr != null && columnsStr.length() > 0 && columnsStr.charAt(0) == '*') { + view.setStretchAllColumns(true); + } else { + view.setStretchAllColumns(false); + SparseBooleanArray columns = parseColumns(columnsStr); + int columnCount = columns.size(); + for (int i = 0; i < columnCount; i++) { + int column = columns.keyAt(i); + boolean stretchable = columns.valueAt(i); + if (stretchable) { + view.setColumnStretchable(column, stretchable); + } + } + } + } + + private static SparseBooleanArray parseColumns(CharSequence sequence) { + SparseBooleanArray columns = new SparseBooleanArray(); + if (sequence == null) { + return columns; + } + String[] columnDefs = sColumnPattern.split(sequence); + + for (String columnIdentifier : columnDefs) { + try { + int columnIndex = Integer.parseInt(columnIdentifier); + // only valid, i.e. positive, columns indexes are handled + if (columnIndex >= 0) { + // putting true in this sparse array indicates that the + // column index was defined in the XML file + columns.put(columnIndex, true); + } + } catch (NumberFormatException e) { + // we just ignore columns that don't exist + } + } + + return columns; + } +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/TextViewBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/TextViewBindingAdapter.java new file mode 100644 index 00000000..1cd5ef4f --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/TextViewBindingAdapter.java @@ -0,0 +1,283 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingAdapter; +import android.binding.BindingMethod; +import android.binding.BindingMethods; +import android.graphics.drawable.Drawable; +import android.os.Build; +import android.text.InputFilter; +import android.text.InputType; +import android.text.method.DialerKeyListener; +import android.text.method.DigitsKeyListener; +import android.text.method.KeyListener; +import android.text.method.PasswordTransformationMethod; +import android.text.method.TextKeyListener; +import android.util.Log; +import android.util.TypedValue; +import android.widget.TextView; + +@BindingMethods({ + @BindingMethod(type = "android.widget.TextView", attribute = "android:autoLink", method = "setAutoLinkMask"), + @BindingMethod(type = "android.widget.TextView", attribute = "android:drawablePadding", method = "setCompoundDrawablePadding"), + @BindingMethod(type = "android.widget.TextView", attribute = "android:editorExtras", method = "setInputExtras"), + @BindingMethod(type = "android.widget.TextView", attribute = "android:inputType", method = "setRawInputType"), + @BindingMethod(type = "android.widget.TextView", attribute = "android:scrollHorizontally", method = "setHorizontallyScrolling"), + @BindingMethod(type = "android.widget.TextView", attribute = "android:textAllCaps", method = "setAllCaps"), + @BindingMethod(type = "android.widget.TextView", attribute = "android:textColorHighlight", method = "setHighlightColor"), + @BindingMethod(type = "android.widget.TextView", attribute = "android:textColorHint", method = "setHintTextColor"), + @BindingMethod(type = "android.widget.TextView", attribute = "android:textColorLink", method = "setLinkTextColor"), +}) +public class TextViewBindingAdapter { + + private static final String TAG = "TextViewBindingAdapters"; + + public static final int INTEGER = 0x01; + + public static final int SIGNED = 0x03; + + public static final int DECIMAL = 0x05; + + @BindingAdapter("android:autoText") + public static void setAutoText(TextView view, boolean autoText) { + KeyListener listener = view.getKeyListener(); + + TextKeyListener.Capitalize capitalize = TextKeyListener.Capitalize.NONE; + + int inputType = listener != null ? listener.getInputType() : 0; + if ((inputType & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS) != 0) { + capitalize = TextKeyListener.Capitalize.CHARACTERS; + } else if ((inputType & InputType.TYPE_TEXT_FLAG_CAP_WORDS) != 0) { + capitalize = TextKeyListener.Capitalize.WORDS; + } else if ((inputType & InputType.TYPE_TEXT_FLAG_CAP_SENTENCES) != 0) { + capitalize = TextKeyListener.Capitalize.SENTENCES; + } + view.setKeyListener(TextKeyListener.getInstance(autoText, capitalize)); + } + + @BindingAdapter("android:capitalize") + public static void setCapitalize(TextView view, TextKeyListener.Capitalize capitalize) { + KeyListener listener = view.getKeyListener(); + + int inputType = listener.getInputType(); + boolean autoText = (inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT) != 0; + view.setKeyListener(TextKeyListener.getInstance(autoText, capitalize)); + } + + @BindingAdapter("android:bufferType") + public static void setBufferType(TextView view, TextView.BufferType bufferType) { + view.setText(view.getText(), bufferType); + } + + @BindingAdapter("android:digits") + public static void setDigits(TextView view, CharSequence digits) { + if (digits != null) { + view.setKeyListener(DigitsKeyListener.getInstance(digits.toString())); + } else if (view.getKeyListener() instanceof DigitsKeyListener) { + view.setKeyListener(null); + } + } + + @BindingAdapter("android:numeric") + public static void setNumeric(TextView view, int numeric) { + view.setKeyListener(DigitsKeyListener.getInstance((numeric & SIGNED) != 0, + (numeric & DECIMAL) != 0)); + } + + @BindingAdapter("android:phoneNumber") + public static void setPhoneNumber(TextView view, boolean phoneNumber) { + if (phoneNumber) { + view.setKeyListener(DialerKeyListener.getInstance()); + } else if (view.getKeyListener() instanceof DialerKeyListener) { + view.setKeyListener(null); + } + } + + @BindingAdapter("android:drawableBottom") + public static void setDrawableBottom(TextView view, Drawable drawable) { + Drawable[] drawables = view.getCompoundDrawables(); + view.setCompoundDrawables(drawables[0], drawables[1], drawables[2], drawable); + } + + @BindingAdapter("android:drawableLeft") + public static void setDrawableLeft(TextView view, Drawable drawable) { + Drawable[] drawables = view.getCompoundDrawables(); + view.setCompoundDrawables(drawable, drawables[1], drawables[2], drawables[3]); + } + + @BindingAdapter("android:drawableRight") + public static void setDrawableRight(TextView view, Drawable drawable) { + Drawable[] drawables = view.getCompoundDrawables(); + view.setCompoundDrawables(drawables[0], drawables[1], drawable, drawables[3]); + } + + @BindingAdapter("android:drawableTop") + public static void setDrawableTop(TextView view, Drawable drawable) { + Drawable[] drawables = view.getCompoundDrawables(); + view.setCompoundDrawables(drawables[0], drawable, drawables[2], drawables[3]); + } + + @BindingAdapter("android:drawableStart") + public static void setDrawableStart(TextView view, Drawable drawable) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { + setDrawableLeft(view, drawable); + } else { + Drawable[] drawables = view.getCompoundDrawablesRelative(); + view.setCompoundDrawablesRelative(drawable, drawables[1], drawables[2], drawables[3]); + } + } + + @BindingAdapter("android:drawableEnd") + public static void setDrawableEnd(TextView view, Drawable drawable) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { + setDrawableRight(view, drawable); + } else { + Drawable[] drawables = view.getCompoundDrawablesRelative(); + view.setCompoundDrawablesRelative(drawables[0], drawables[1], drawable, drawables[3]); + } + } + + @BindingAdapter("android:imeActionLabel") + public static void setImeActionLabel(TextView view, CharSequence value) { + view.setImeActionLabel(value, view.getImeActionId()); + } + + @BindingAdapter("android:imeActionId") + public static void setImeActionLabel(TextView view, int value) { + view.setImeActionLabel(view.getImeActionLabel(), value); + } + + @BindingAdapter("android:inputMethod") + public static void setInputMethod(TextView view, CharSequence inputMethod) { + try { + Class<?> c = Class.forName(inputMethod.toString()); + view.setKeyListener((KeyListener) c.newInstance()); + } catch (ClassNotFoundException e) { + Log.e(TAG, "Could not create input method: " + inputMethod, e); + } catch (InstantiationException e) { + Log.e(TAG, "Could not create input method: " + inputMethod, e); + } catch (IllegalAccessException e) { + Log.e(TAG, "Could not create input method: " + inputMethod, e); + } + } + + @BindingAdapter("android:lineSpacingExtra") + public static void setLineSpacingExtra(TextView view, float value) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + view.setLineSpacing(value, view.getLineSpacingMultiplier()); + } else { + view.setLineSpacing(value, 1); + } + } + + @BindingAdapter("android:lineSpacingMultiplier") + public static void setLineSpacingMultiplier(TextView view, float value) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + view.setLineSpacing(view.getLineSpacingExtra(), value); + } else { + view.setLineSpacing(0, value); + } + } + + @BindingAdapter("android:maxLength") + public static void setMaxLength(TextView view, int value) { + InputFilter[] filters = view.getFilters(); + if (filters == null) { + filters = new InputFilter[]{ + new InputFilter.LengthFilter(value) + }; + } else { + boolean foundMaxLength = false; + for (int i = 0; i < filters.length; i++) { + InputFilter filter = filters[i]; + if (filter instanceof InputFilter.LengthFilter) { + foundMaxLength = true; + boolean replace = true; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + replace = ((InputFilter.LengthFilter) filter).getMax() != value; + } + if (replace) { + filters[i] = new InputFilter.LengthFilter(value); + } + break; + } + } + if (!foundMaxLength) { + // can't use Arrays.copyOf -- it shows up in API 9 + InputFilter[] oldFilters = filters; + filters = new InputFilter[oldFilters.length + 1]; + System.arraycopy(oldFilters, 0, filters, 0, oldFilters.length); + filters[filters.length - 1] = new InputFilter.LengthFilter(value); + } + } + view.setFilters(filters); + } + + @BindingAdapter("android:password") + public static void setPassword(TextView view, boolean password) { + if (password) { + view.setTransformationMethod(PasswordTransformationMethod.getInstance()); + } else if (view.getTransformationMethod() instanceof PasswordTransformationMethod) { + view.setTransformationMethod(null); + } + } + + @BindingAdapter("android:shadowColor") + public static void setShadowColor(TextView view, int color) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + float dx = view.getShadowDx(); + float dy = view.getShadowDy(); + float r = view.getShadowRadius(); + view.setShadowLayer(r, dx, dy, color); + } + } + + @BindingAdapter("android:shadowDx") + public static void setShadowDx(TextView view, float dx) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + int color = view.getShadowColor(); + float dy = view.getShadowDy(); + float r = view.getShadowRadius(); + view.setShadowLayer(r, dx, dy, color); + } + } + + @BindingAdapter("android:shadowDy") + public static void setShadowDy(TextView view, float dy) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + int color = view.getShadowColor(); + float dx = view.getShadowDx(); + float r = view.getShadowRadius(); + view.setShadowLayer(r, dx, dy, color); + } + } + + @BindingAdapter("android:shadowRadius") + public static void setShadowRadius(TextView view, float r) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + int color = view.getShadowColor(); + float dx = view.getShadowDx(); + float dy = view.getShadowDy(); + view.setShadowLayer(r, dx, dy, color); + } + } + + @BindingAdapter("android:textSize") + public static void setTextSize(TextView view, float size) { + view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); + } +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/ViewBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/ViewBindingAdapter.java new file mode 100644 index 00000000..1e361cf2 --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/ViewBindingAdapter.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingAdapter; +import android.binding.BindingMethod; +import android.binding.BindingMethods; +import android.os.Build; +import android.view.View; + +@BindingMethods({ + @BindingMethod(type = "android.view.View", attribute = "android:backgroundTint", method = "setBackgroundTintList"), + @BindingMethod(type = "android.view.View", attribute = "android:fadeScrollbars", method = "setScrollbarFadingEnabled"), + @BindingMethod(type = "android.view.View", attribute = "android:nextFocusForward", method = "setNextFocusForwardId"), + @BindingMethod(type = "android.view.View", attribute = "android:nextFocusLeft", method = "setNextFocusLeftId"), + @BindingMethod(type = "android.view.View", attribute = "android:nextFocusRight", method = "setNextFocusRightId"), + @BindingMethod(type = "android.view.View", attribute = "android:nextFocusUp", method = "setNextFocusUpId"), + @BindingMethod(type = "android.view.View", attribute = "android:nextFocusDown", method = "setNextFocusDownId"), + @BindingMethod(type = "android.view.View", attribute = "android:requiresFadingEdge", method = "setVerticalFadingEdgeEnabled"), + @BindingMethod(type = "android.view.View", attribute = "android:scrollbarDefaultDelayBeforeFade", method = "setScrollBarDefaultDelayBeforeFade"), + @BindingMethod(type = "android.view.View", attribute = "android:scrollbarFadeDuration", method = "setScrollBarFadeDuration"), + @BindingMethod(type = "android.view.View", attribute = "android:scrollbarSize", method = "setScrollBarSize"), + @BindingMethod(type = "android.view.View", attribute = "android:scrollbarStyle", method = "setScrollBarStyle"), + @BindingMethod(type = "android.view.View", attribute = "android:transformPivotX", method = "setPivotX"), + @BindingMethod(type = "android.view.View", attribute = "android:transformPivotY", method = "setPivotY"), +}) +public class ViewBindingAdapter { + public static int FADING_EDGE_NONE = 0; + public static int FADING_EDGE_HORIZONTAL = 1; + public static int FADING_EDGE_VERTICAL = 2; + + @BindingAdapter("android:padding") + public static void setPadding(View view, int padding) { + view.setPadding(padding, padding, padding, padding); + } + + @BindingAdapter("android:paddingBottom") + public static void setPaddingBottom(View view, int padding) { + view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(), + padding); + } + + @BindingAdapter("android:paddingEnd") + public static void setPaddingEnd(View view, int padding) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + view.setPaddingRelative(view.getPaddingStart(), view.getPaddingTop(), padding, + view.getPaddingBottom()); + } else { + view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), padding, + view.getPaddingBottom()); + } + } + + @BindingAdapter("android:paddingLeft") + public static void setPaddingLeft(View view, int padding) { + view.setPadding(padding, view.getPaddingTop(), view.getPaddingRight(), + view.getPaddingBottom()); + } + + @BindingAdapter("android:paddingRight") + public static void setPaddingRight(View view, int padding) { + view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), padding, + view.getPaddingBottom()); + } + + @BindingAdapter("android:paddingStart") + public static void setPaddingStart(View view, int padding) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + view.setPaddingRelative(padding, view.getPaddingTop(), view.getPaddingEnd(), + view.getPaddingBottom()); + } else { + view.setPadding(padding, view.getPaddingTop(), view.getPaddingRight(), + view.getPaddingBottom()); + } + } + + @BindingAdapter("android:paddingTop") + public static void setPaddingTop(View view, int padding) { + view.setPadding(view.getPaddingLeft(), padding, view.getPaddingRight(), + view.getPaddingBottom()); + } + + @BindingAdapter("android:requiresFadingEdge") + public static void setRequiresFadingEdge(View view, int value) { + final boolean vertical = (value & FADING_EDGE_VERTICAL) != 0; + final boolean horizontal = (value & FADING_EDGE_HORIZONTAL) != 0; + view.setVerticalFadingEdgeEnabled(vertical); + view.setHorizontalFadingEdgeEnabled(horizontal); + } +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/ViewGroupBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/ViewGroupBindingAdapter.java new file mode 100644 index 00000000..4448a30d --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/ViewGroupBindingAdapter.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.animation.LayoutTransition; +import android.annotation.TargetApi; +import android.binding.BindingAdapter; +import android.binding.BindingMethod; +import android.binding.BindingMethods; +import android.os.Build; +import android.view.ViewGroup; + +@BindingMethods({ + @BindingMethod(type = "android.view.ViewGroup", attribute = "android:alwaysDrawnWithCache", method = "setAlwaysDrawnWithCacheEnabled"), + @BindingMethod(type = "android.view.ViewGroup", attribute = "android:animationCache", method = "setAnimationCacheEnabled"), + @BindingMethod(type = "android.view.ViewGroup", attribute = "android:splitMotionEvents", method = "setMotionEventSplittingEnabled"), +}) +public class ViewGroupBindingAdapter { + + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + @BindingAdapter("android:animateLayoutChanges") + public static void setAnimateLayoutChanges(ViewGroup view, boolean animate) { + if (animate) { + view.setLayoutTransition(new LayoutTransition()); + } else { + view.setLayoutTransition(null); + } + } +} diff --git a/extensions/baseAdapters/src/main/java/android/bindings/adapters/ViewStubBindingAdapter.java b/extensions/baseAdapters/src/main/java/android/bindings/adapters/ViewStubBindingAdapter.java new file mode 100644 index 00000000..f24ab03b --- /dev/null +++ b/extensions/baseAdapters/src/main/java/android/bindings/adapters/ViewStubBindingAdapter.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.binding.adapters; + +import android.binding.BindingMethod; +import android.binding.BindingMethods; +import android.binding.Untaggable; + +@Untaggable({"android.view.ViewStub"}) +@BindingMethods({ + @BindingMethod(type = "android.view.ViewStub", attribute = "android:layout", method = "setLayoutResource") +}) +public class ViewStubBindingAdapter { + +} |