diff options
Diffstat (limited to 'extensions')
29 files changed, 1449 insertions, 0 deletions
diff --git a/extensions/baseAdapters/build.gradle b/extensions/baseAdapters/build.gradle new file mode 100644 index 00000000..74e90365 --- /dev/null +++ b/extensions/baseAdapters/build.gradle @@ -0,0 +1,96 @@ +/* + * 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. + */ + + +apply plugin: 'maven' +apply plugin: 'com.android.library' +apply plugin: 'com.android.databinding' + +android { + compileSdkVersion 21 + buildToolsVersion "21.1.2" + + defaultConfig { + minSdkVersion 7 + targetSdkVersion 21 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + packagingOptions { + exclude 'META-INF/services/javax.annotation.processing.Processor' + exclude 'META-INF/LICENSE.txt' + exclude 'META-INF/NOTICE.txt' + } +} + +dependencies { + compile "com.android.databinding:baseLibrary:${config.snapshotVersion}" + provided "com.android.databinding:annotationprocessor:${config.snapshotVersion}" + compile 'com.android.support:support-v4:+' + compile 'com.android.support:cardview-v7:+' + compile 'com.android.support:appcompat-v7:+' +} + +configurations { + jarArchives +} + + +//create jar tasks +android.libraryVariants.all { variant -> + def name = variant.buildType.name + + if (name.equals(com.android.builder.core.BuilderConstants.DEBUG)) { + return; // Skip debug builds. + } + // @Jar version is needed to run compiler tests + def task = project.tasks.create "jar${name.capitalize()}", Jar + task.dependsOn variant.javaCompile + task.from variant.javaCompile.destinationDir + def packageName = "com.android.databinding.library.baseAdapters" + def appPkgAsClass = packageName.replace('.', '/') + task.exclude("com/android/databinding/layouts/*.*") + task.exclude("$appPkgAsClass/generated/*") + task.exclude("$appPkgAsClass/BR.*") + artifacts.add('jarArchives', task); +} + +uploadArchives { +} + +uploadJarArchives { + repositories { + mavenDeployer { + repository(url: "file://${config.mavenRepoDir}") + pom.artifactId = "adapters" + pom.whenConfigured { + println("configured pom, $it") + it.dependencies.find {dep -> dep.groupId == 'com.android.support' && dep.artifactId == 'support-v4' }.optional = true + it.dependencies.find {dep -> dep.groupId == 'com.android.support' && dep.artifactId == 'cardview-v7' }.optional = true + it.dependencies.find {dep -> dep.groupId == 'com.android.support' && dep.artifactId == 'appcompat-v7' }.optional = true + } + } + } +} + +uploadArchives.dependsOn uploadJarArchives 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 { + +} diff --git a/extensions/build.gradle b/extensions/build.gradle new file mode 100644 index 00000000..cfa26978 --- /dev/null +++ b/extensions/build.gradle @@ -0,0 +1,45 @@ +/* + * 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. + */ + + +buildscript { + def Properties dataBindingProperties = new Properties() + dataBindingProperties.load(new FileInputStream("${projectDir}/../databinding.properties")) + dataBindingProperties.mavenRepoDir = "${projectDir}/../${dataBindingProperties.mavenRepoName}" + ext.config = dataBindingProperties + repositories { + jcenter() + maven { + url config.mavenRepoDir + } + } + dependencies { + classpath 'com.android.tools.build:gradle:1.1.3' + classpath "com.android.databinding:dataBinder:${config.snapshotVersion}" + } +} + +subprojects { + apply plugin: 'maven' + group = config.group + version = config.snapshotVersion + repositories { + mavenCentral() + maven { + url config.mavenRepoDir + } + } +}
\ No newline at end of file diff --git a/extensions/gradle/wrapper/gradle-wrapper.jar b/extensions/gradle/wrapper/gradle-wrapper.jar Binary files differnew file mode 100644 index 00000000..8c0fb64a --- /dev/null +++ b/extensions/gradle/wrapper/gradle-wrapper.jar diff --git a/extensions/gradle/wrapper/gradle-wrapper.properties b/extensions/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..e5fd8793 --- /dev/null +++ b/extensions/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Mar 12 15:27:48 PDT 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip diff --git a/extensions/gradlew b/extensions/gradlew new file mode 100755 index 00000000..91a7e269 --- /dev/null +++ b/extensions/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/extensions/settings.gradle b/extensions/settings.gradle new file mode 100644 index 00000000..80ebcc8c --- /dev/null +++ b/extensions/settings.gradle @@ -0,0 +1,20 @@ +/* + * 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. + */ + +/** + * These are projects that requires a compiled version of data binding. + */ +include ':baseAdapters' |