upload android base code part1
This commit is contained in:
parent
e02f198e2d
commit
0a1de6c4b3
48159 changed files with 9071466 additions and 0 deletions
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* 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 {
|
||||
dependencies {
|
||||
classpath "com.android.tools.build:gradle:${dataBindingConfig.androidPluginVersion}"
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion dataBindingConfig.compileSdkVersion
|
||||
buildToolsVersion dataBindingConfig.buildToolsVersion
|
||||
dataBinding {
|
||||
enabled = true
|
||||
addDefaultAdapters = false
|
||||
}
|
||||
defaultConfig {
|
||||
minSdkVersion 7
|
||||
targetSdkVersion 23
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility dataBindingConfig.javaTargetCompatibility
|
||||
targetCompatibility dataBindingConfig.javaSourceCompatibility
|
||||
}
|
||||
packagingOptions {
|
||||
exclude 'META-INF/services/javax.annotation.processing.Processor'
|
||||
exclude 'META-INF/LICENSE.txt'
|
||||
exclude 'META-INF/NOTICE.txt'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
provided 'com.android.support:support-v4:+'
|
||||
provided 'com.android.support:cardview-v7:+'
|
||||
provided 'com.android.support:appcompat-v7:+'
|
||||
}
|
||||
|
||||
//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.
|
||||
}
|
||||
def suffix = name.capitalize()
|
||||
|
||||
def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
|
||||
source variant.javaCompile.source
|
||||
classpath = files(variant.javaCompile.classpath.files) + files(
|
||||
"${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
|
||||
}
|
||||
|
||||
def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
|
||||
classifier = 'javadoc'
|
||||
from 'build/docs/javadoc'
|
||||
}
|
||||
javadocJarTask.dependsOn javadocTask
|
||||
|
||||
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
|
||||
classifier = 'sources'
|
||||
from android.sourceSets.main.java.srcDirs
|
||||
}
|
||||
|
||||
artifacts.add('archives', javadocJarTask);
|
||||
artifacts.add('archives', sourcesJarTask);
|
||||
}
|
||||
|
||||
uploadArchives {
|
||||
repositories {
|
||||
mavenDeployer {
|
||||
pom.artifactId = "adapters"
|
||||
pom.project {
|
||||
licenses {
|
||||
license {
|
||||
name dataBindingConfig.licenseName
|
||||
url dataBindingConfig.licenseUrl
|
||||
distribution dataBindingConfig.licenseDistribution
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
task prebuild(type : Copy) {
|
||||
dependsOn uploadArchives
|
||||
from "$buildDir/outputs/aar/baseAdapters-release.aar"
|
||||
into dataBindingConfig.prebuildFolder
|
||||
rename { String fileName ->
|
||||
"databinding-adapters.aar"
|
||||
}
|
||||
}
|
|
@ -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>
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.AbsListView.OnScrollListener;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = AbsListView.class, attribute = "android:listSelector", method = "setSelector"),
|
||||
@BindingMethod(type = AbsListView.class, attribute = "android:scrollingCache", method = "setScrollingCacheEnabled"),
|
||||
@BindingMethod(type = AbsListView.class, attribute = "android:smoothScrollbar", method = "setSmoothScrollbarEnabled"),
|
||||
@BindingMethod(type = AbsListView.class, attribute = "android:onMovedToScrapHeap", method = "setRecyclerListener"),
|
||||
})
|
||||
public class AbsListViewBindingAdapter {
|
||||
|
||||
@BindingAdapter(value = {"android:onScroll", "android:onScrollStateChanged"},
|
||||
requireAll = false)
|
||||
public static void setOnScroll(AbsListView view, final OnScroll scrollListener,
|
||||
final OnScrollStateChanged scrollStateListener) {
|
||||
view.setOnScrollListener(new OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
if (scrollStateListener != null) {
|
||||
scrollStateListener.onScrollStateChanged(view, scrollState);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
|
||||
int totalItemCount) {
|
||||
if (scrollListener != null) {
|
||||
scrollListener
|
||||
.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public interface OnScroll {
|
||||
void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
|
||||
int totalItemCount);
|
||||
}
|
||||
|
||||
public interface OnScrollStateChanged {
|
||||
void onScrollStateChanged(AbsListView view, int scrollState);
|
||||
}
|
||||
}
|
|
@ -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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = android.widget.AbsSeekBar.class, attribute = "android:thumbTint", method = "setThumbTintList"),
|
||||
|
||||
})
|
||||
public class AbsSeekBarBindingAdapter {
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.widget.AbsSpinner;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.SpinnerAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AbsSpinnerBindingAdapter {
|
||||
|
||||
@BindingAdapter({"android:entries"})
|
||||
public static <T extends CharSequence> void setEntries(AbsSpinner view, T[] 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);
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter({"android:entries"})
|
||||
public static <T> void setEntries(AbsSpinner view, List<T> entries) {
|
||||
if (entries != null) {
|
||||
SpinnerAdapter oldAdapter = view.getAdapter();
|
||||
if (oldAdapter instanceof ObservableListAdapter) {
|
||||
((ObservableListAdapter) oldAdapter).setList(entries);
|
||||
} else {
|
||||
view.setAdapter(new ObservableListAdapter<T>(view.getContext(), entries,
|
||||
android.R.layout.simple_spinner_item,
|
||||
android.R.layout.simple_spinner_dropdown_item, 0));
|
||||
}
|
||||
} else {
|
||||
view.setAdapter(null);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.widget.ActionMenuView;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = ActionMenuView.class, attribute = "android:onMenuItemClick", method = "setOnMenuItemClickListener"),
|
||||
})
|
||||
public class ActionMenuViewBindingAdapter {
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.databinding.InverseBindingListener;
|
||||
import android.databinding.InverseBindingMethod;
|
||||
import android.databinding.InverseBindingMethods;
|
||||
import android.view.View;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemSelectedListener;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = AdapterView.class, attribute = "android:onItemClick", method = "setOnItemClickListener"),
|
||||
@BindingMethod(type = AdapterView.class, attribute = "android:onItemLongClick", method = "setOnItemLongClickListener"),
|
||||
})
|
||||
@InverseBindingMethods({
|
||||
@InverseBindingMethod(type = AbsListView.class, attribute = "android:selectedItemPosition"),
|
||||
})
|
||||
public class AdapterViewBindingAdapter {
|
||||
|
||||
@BindingAdapter("android:selectedItemPosition")
|
||||
public static void setSelectedItemPosition(AdapterView view, int position) {
|
||||
if (view.getSelectedItemPosition() != position) {
|
||||
view.setSelection(position);
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter(value = {"android:onItemSelected", "android:onNothingSelected",
|
||||
"android:selectedItemPositionAttrChanged"}, requireAll = false)
|
||||
public static void setOnItemSelectedListener(AdapterView view, final OnItemSelected selected,
|
||||
final OnNothingSelected nothingSelected, final InverseBindingListener attrChanged) {
|
||||
if (selected == null && nothingSelected == null && attrChanged == null) {
|
||||
view.setOnItemSelectedListener(null);
|
||||
} else {
|
||||
view.setOnItemSelectedListener(
|
||||
new OnItemSelectedComponentListener(selected, nothingSelected, attrChanged));
|
||||
}
|
||||
}
|
||||
|
||||
public static class OnItemSelectedComponentListener implements OnItemSelectedListener {
|
||||
private final OnItemSelected mSelected;
|
||||
private final OnNothingSelected mNothingSelected;
|
||||
private final InverseBindingListener mAttrChanged;
|
||||
|
||||
public OnItemSelectedComponentListener(OnItemSelected selected,
|
||||
OnNothingSelected nothingSelected, InverseBindingListener attrChanged) {
|
||||
this.mSelected = selected;
|
||||
this.mNothingSelected = nothingSelected;
|
||||
this.mAttrChanged = attrChanged;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (mSelected != null) {
|
||||
mSelected.onItemSelected(parent, view, position, id);
|
||||
}
|
||||
if (mAttrChanged != null) {
|
||||
mAttrChanged.onChange();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
if (mNothingSelected != null) {
|
||||
mNothingSelected.onNothingSelected(parent);
|
||||
}
|
||||
if (mAttrChanged != null) {
|
||||
mAttrChanged.onChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnItemSelected {
|
||||
void onItemSelected(AdapterView<?> parent, View view, int position, long id);
|
||||
}
|
||||
|
||||
public interface OnNothingSelected {
|
||||
void onNothingSelected(AdapterView<?> parent);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.databinding.adapters.AdapterViewBindingAdapter.OnItemSelected;
|
||||
import android.databinding.adapters.AdapterViewBindingAdapter.OnItemSelectedComponentListener;
|
||||
import android.databinding.adapters.AdapterViewBindingAdapter.OnNothingSelected;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.AutoCompleteTextView.Validator;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = AutoCompleteTextView.class, attribute = "android:completionThreshold", method = "setThreshold"),
|
||||
@BindingMethod(type = AutoCompleteTextView.class, attribute = "android:popupBackground", method = "setDropDownBackgroundDrawable"),
|
||||
@BindingMethod(type = AutoCompleteTextView.class, attribute = "android:onDismiss", method = "setOnDismissListener"),
|
||||
@BindingMethod(type = AutoCompleteTextView.class, attribute = "android:onItemClick", method = "setOnItemClickListener"),
|
||||
})
|
||||
public class AutoCompleteTextViewBindingAdapter {
|
||||
|
||||
@BindingAdapter(value = {"android:fixText", "android:isValid"}, requireAll = false)
|
||||
public static void setValidator(AutoCompleteTextView view, final FixText fixText,
|
||||
final IsValid isValid) {
|
||||
if (fixText == null && isValid == null) {
|
||||
view.setValidator(null);
|
||||
} else {
|
||||
view.setValidator(new Validator() {
|
||||
@Override
|
||||
public boolean isValid(CharSequence text) {
|
||||
if (isValid != null) {
|
||||
return isValid.isValid(text);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence fixText(CharSequence invalidText) {
|
||||
if (fixText != null) {
|
||||
return fixText.fixText(invalidText);
|
||||
} else {
|
||||
return invalidText;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter(value = {"android:onItemSelected", "android:onNothingSelected"},
|
||||
requireAll = false)
|
||||
public static void setOnItemSelectedListener(AutoCompleteTextView view,
|
||||
final OnItemSelected selected, final OnNothingSelected nothingSelected) {
|
||||
if (selected == null && nothingSelected == null) {
|
||||
view.setOnItemSelectedListener(null);
|
||||
} else {
|
||||
view.setOnItemSelectedListener(
|
||||
new OnItemSelectedComponentListener(selected, nothingSelected, null));
|
||||
}
|
||||
}
|
||||
|
||||
public interface IsValid {
|
||||
boolean isValid(CharSequence text);
|
||||
}
|
||||
|
||||
public interface FixText {
|
||||
CharSequence fixText(CharSequence invalidText);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.InverseBindingListener;
|
||||
import android.databinding.InverseBindingMethod;
|
||||
import android.databinding.InverseBindingMethods;
|
||||
import android.widget.CalendarView;
|
||||
import android.widget.CalendarView.OnDateChangeListener;
|
||||
|
||||
@InverseBindingMethods({
|
||||
@InverseBindingMethod(type = CalendarView.class, attribute = "android:date"),
|
||||
})
|
||||
public class CalendarViewBindingAdapter {
|
||||
@BindingAdapter("android:date")
|
||||
public static void setDate(CalendarView view, long date) {
|
||||
if (view.getDate() != date) {
|
||||
view.setDate(date);
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter(value = {"android:onSelectedDayChange", "android:dateAttrChanged"},
|
||||
requireAll = false)
|
||||
public static void setListeners(CalendarView view, final OnDateChangeListener onDayChange,
|
||||
final InverseBindingListener attrChange) {
|
||||
if (attrChange == null) {
|
||||
view.setOnDateChangeListener(onDayChange);
|
||||
} else {
|
||||
view.setOnDateChangeListener(new OnDateChangeListener() {
|
||||
@Override
|
||||
public void onSelectedDayChange(CalendarView view, int year, int month,
|
||||
int dayOfMonth) {
|
||||
if (onDayChange != null) {
|
||||
onDayChange.onSelectedDayChange(view, year, month, dayOfMonth);
|
||||
}
|
||||
attrChange.onChange();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.support.v7.widget.CardView;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = android.support.v7.widget.CardView.class, attribute = "cardCornerRadius", method = "setRadius"),
|
||||
@BindingMethod(type = android.support.v7.widget.CardView.class, attribute = "cardMaxElevation", method = "setMaxCardElevation"),
|
||||
@BindingMethod(type = android.support.v7.widget.CardView.class, attribute = "cardPreventCornerOverlap", method = "setPreventCornerOverlap"),
|
||||
@BindingMethod(type = android.support.v7.widget.CardView.class, 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);
|
||||
}
|
||||
}
|
|
@ -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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = android.widget.CheckedTextView.class, attribute = "android:checkMark", method = "setCheckMarkDrawable"),
|
||||
@BindingMethod(type = android.widget.CheckedTextView.class, attribute = "android:checkMarkTint", method = "setCheckMarkTintList"),
|
||||
})
|
||||
public class CheckedTextViewBindingAdapter {
|
||||
|
||||
}
|
|
@ -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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.widget.Chronometer;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = Chronometer.class, attribute = "android:onChronometerTick", method = "setOnChronometerTickListener"),
|
||||
})
|
||||
public class ChronometerBindingAdapter {
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.databinding.InverseBindingListener;
|
||||
import android.databinding.InverseBindingMethod;
|
||||
import android.databinding.InverseBindingMethods;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = CompoundButton.class, attribute = "android:buttonTint", method = "setButtonTintList"),
|
||||
@BindingMethod(type = CompoundButton.class, attribute = "android:onCheckedChanged", method = "setOnCheckedChangeListener"),
|
||||
})
|
||||
@InverseBindingMethods({
|
||||
@InverseBindingMethod(type = CompoundButton.class, attribute = "android:checked"),
|
||||
})
|
||||
public class CompoundButtonBindingAdapter {
|
||||
|
||||
@BindingAdapter("android:checked")
|
||||
public static void setChecked(CompoundButton view, boolean checked) {
|
||||
if (view.isChecked() != checked) {
|
||||
view.setChecked(checked);
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter(value = {"android:onCheckedChanged", "android:checkedAttrChanged"},
|
||||
requireAll = false)
|
||||
public static void setListeners(CompoundButton view, final OnCheckedChangeListener listener,
|
||||
final InverseBindingListener attrChange) {
|
||||
if (attrChange == null) {
|
||||
view.setOnCheckedChangeListener(listener);
|
||||
} else {
|
||||
view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (listener != null) {
|
||||
listener.onCheckedChanged(buttonView, isChecked);
|
||||
}
|
||||
attrChange.onChange();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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.databinding.adapters;
|
||||
|
||||
import android.databinding.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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.InverseBindingListener;
|
||||
import android.databinding.InverseBindingMethod;
|
||||
import android.databinding.InverseBindingMethods;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.DatePicker.OnDateChangedListener;
|
||||
import com.android.databinding.library.baseAdapters.R;
|
||||
|
||||
@InverseBindingMethods({
|
||||
@InverseBindingMethod(type = DatePicker.class, attribute = "android:year"),
|
||||
@InverseBindingMethod(type = DatePicker.class, attribute = "android:month"),
|
||||
@InverseBindingMethod(type = DatePicker.class, attribute = "android:day", method = "getDayOfMonth"),
|
||||
})
|
||||
public class DatePickerBindingAdapter {
|
||||
@BindingAdapter(value = {"android:year", "android:month", "android:day",
|
||||
"android:onDateChanged", "android:yearAttrChanged",
|
||||
"android:monthAttrChanged", "android:dayAttrChanged"}, requireAll = false)
|
||||
public static void setListeners(DatePicker view, int year, int month, int day,
|
||||
final OnDateChangedListener listener, final InverseBindingListener yearChanged,
|
||||
final InverseBindingListener monthChanged, final InverseBindingListener dayChanged) {
|
||||
if (year == 0) {
|
||||
year = view.getYear();
|
||||
}
|
||||
if (day == 0) {
|
||||
day = view.getDayOfMonth();
|
||||
}
|
||||
if (yearChanged == null && monthChanged == null && dayChanged == null) {
|
||||
view.init(year, month, day, listener);
|
||||
} else {
|
||||
DateChangedListener oldListener = ListenerUtil.getListener(view, R.id.onDateChanged);
|
||||
if (oldListener == null) {
|
||||
oldListener = new DateChangedListener();
|
||||
ListenerUtil.trackListener(view, oldListener, R.id.onDateChanged);
|
||||
}
|
||||
oldListener.setListeners(listener, yearChanged, monthChanged, dayChanged);
|
||||
view.init(year, month, day, oldListener);
|
||||
}
|
||||
}
|
||||
|
||||
private static class DateChangedListener implements OnDateChangedListener {
|
||||
OnDateChangedListener mListener;
|
||||
InverseBindingListener mYearChanged;
|
||||
InverseBindingListener mMonthChanged;
|
||||
InverseBindingListener mDayChanged;
|
||||
|
||||
public void setListeners(OnDateChangedListener listener, InverseBindingListener yearChanged,
|
||||
InverseBindingListener monthChanged, InverseBindingListener dayChanged) {
|
||||
mListener = listener;
|
||||
mYearChanged = yearChanged;
|
||||
mMonthChanged = monthChanged;
|
||||
mDayChanged = dayChanged;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
||||
if (mListener != null) {
|
||||
mListener.onDateChanged(view, year, monthOfYear, dayOfMonth);
|
||||
}
|
||||
if (mYearChanged != null) {
|
||||
mYearChanged.onChange();
|
||||
}
|
||||
if (mMonthChanged != null) {
|
||||
mMonthChanged.onChange();
|
||||
}
|
||||
if (mDayChanged != null) {
|
||||
mDayChanged.onChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.widget.ExpandableListView;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = ExpandableListView.class, attribute = "android:onChildClick", method = "setOnChildClickListener"),
|
||||
@BindingMethod(type = ExpandableListView.class, attribute = "android:onGroupClick", method = "setOnGroupClickListener"),
|
||||
@BindingMethod(type = ExpandableListView.class, attribute = "android:onGroupCollapse", method = "setOnGroupCollapseListener"),
|
||||
@BindingMethod(type = ExpandableListView.class, attribute = "android:onGroupExpand", method = "setOnGroupExpandListener"),
|
||||
})
|
||||
public class ExpandableListViewBindingAdapter {
|
||||
}
|
|
@ -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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = android.widget.FrameLayout.class, attribute = "android:foregroundTint", method = "setForegroundTintList"),
|
||||
})
|
||||
public class FrameLayoutBindingAdapter {
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.widget.ImageView;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = android.widget.ImageView.class, attribute = "android:tint", method = "setImageTintList"),
|
||||
@BindingMethod(type = android.widget.ImageView.class, attribute = "android:tintMode", method = "setImageTintMode"),
|
||||
})
|
||||
public class ImageViewBindingAdapter {
|
||||
@BindingAdapter("android:src")
|
||||
public static void setImageUri(ImageView view, String imageUri) {
|
||||
if (imageUri == null) {
|
||||
view.setImageURI(null);
|
||||
} else {
|
||||
view.setImageURI(Uri.parse(imageUri));
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter("android:src")
|
||||
public static void setImageUri(ImageView view, Uri imageUri) {
|
||||
view.setImageURI(imageUri);
|
||||
}
|
||||
|
||||
@BindingAdapter("android:src")
|
||||
public static void setImageDrawable(ImageView view, Drawable drawable) {
|
||||
view.setImageDrawable(drawable);
|
||||
}
|
||||
}
|
|
@ -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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = android.widget.LinearLayout.class, attribute = "android:divider", method = "setDividerDrawable"),
|
||||
@BindingMethod(type = android.widget.LinearLayout.class, attribute = "android:measureWithLargestChild", method = "setMeasureWithLargestChildEnabled"),
|
||||
})
|
||||
public class LinearLayoutBindingAdapter {
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public class ListenerUtil {
|
||||
private static SparseArray<WeakHashMap<View, WeakReference<?>>> sListeners =
|
||||
new SparseArray<WeakHashMap<View, WeakReference<?>>>();
|
||||
|
||||
/**
|
||||
* This method tracks listeners for a View. Only one listener per listenerResourceId
|
||||
* can be tracked at a time. This is useful for add*Listener and remove*Listener methods
|
||||
* when used with BindingAdapters. This guarantees not to leak the listener or the View,
|
||||
* so will not keep a strong reference to either.
|
||||
*
|
||||
* Example usage:
|
||||
*<pre><code>@BindingAdapter("onFoo")
|
||||
* public static void addFooListener(MyView view, OnFooListener listener) {
|
||||
* OnFooListener oldValue = ListenerUtil.trackListener(view, listener, R.id.fooListener);
|
||||
* if (oldValue != null) {
|
||||
* view.removeOnFooListener(oldValue);
|
||||
* }
|
||||
* if (listener != null) {
|
||||
* view.addOnFooListener(listener);
|
||||
* }
|
||||
* }</code></pre>
|
||||
*
|
||||
* @param view The View that will have this listener
|
||||
* @param listener The listener to keep track of. May be null if the listener is being removed.
|
||||
* @param listenerResourceId A unique resource ID associated with the listener type.
|
||||
* @return The previously tracked listener. This will be null if the View did not have
|
||||
* a previously-tracked listener.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T trackListener(View view, T listener, int listenerResourceId) {
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
final T oldValue = (T) view.getTag(listenerResourceId);
|
||||
view.setTag(listenerResourceId, listener);
|
||||
return oldValue;
|
||||
} else {
|
||||
synchronized (sListeners) {
|
||||
WeakHashMap<View, WeakReference<?>> listeners = sListeners.get(listenerResourceId);
|
||||
if (listeners == null) {
|
||||
listeners = new WeakHashMap<View, WeakReference<?>>();
|
||||
sListeners.put(listenerResourceId, listeners);
|
||||
}
|
||||
final WeakReference<T> oldValue;
|
||||
if (listener == null) {
|
||||
oldValue = (WeakReference<T>) listeners.remove(view);
|
||||
} else {
|
||||
oldValue = (WeakReference<T>) listeners.put(view, new WeakReference(listener));
|
||||
}
|
||||
if (oldValue == null) {
|
||||
return null;
|
||||
} else {
|
||||
return oldValue.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the previous value for a listener if one was stored previously with
|
||||
* {@link #trackListener(View, Object, int)}
|
||||
* @param view The View to check for a listener previously stored with
|
||||
* {@link #trackListener(View, Object, int)}
|
||||
* @param listenerResourceId A unique resource ID associated with the listener type.
|
||||
* @return The previously tracked listener. This will be null if the View did not have
|
||||
* a previously-tracked listener.
|
||||
*/
|
||||
public static <T> T getListener(View view, int listenerResourceId) {
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
return (T) view.getTag(listenerResourceId);
|
||||
} else {
|
||||
synchronized (sListeners) {
|
||||
WeakHashMap<View, WeakReference<?>> listeners = sListeners.get(listenerResourceId);
|
||||
if (listeners == null) {
|
||||
return null;
|
||||
}
|
||||
final WeakReference<T> oldValue = (WeakReference<T>) listeners.get(view);
|
||||
if (oldValue == null) {
|
||||
return null;
|
||||
} else {
|
||||
return oldValue.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.databinding.InverseBindingListener;
|
||||
import android.databinding.InverseBindingMethod;
|
||||
import android.databinding.InverseBindingMethods;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.NumberPicker;
|
||||
import android.widget.NumberPicker.OnValueChangeListener;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = NumberPicker.class, attribute = "android:format", method = "setFormatter"),
|
||||
@BindingMethod(type = NumberPicker.class, attribute = "android:onScrollStateChange", method = "setOnScrollListener"),
|
||||
})
|
||||
@InverseBindingMethods({
|
||||
@InverseBindingMethod(type = NumberPicker.class, attribute = "android:value"),
|
||||
})
|
||||
public class NumberPickerBindingAdapter {
|
||||
|
||||
@BindingAdapter("android:value")
|
||||
public static void setValue(NumberPicker view, int value) {
|
||||
if (view.getValue() != value) {
|
||||
view.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter(value = {"android:onValueChange", "android:valueAttrChanged"},
|
||||
requireAll = false)
|
||||
public static void setListeners(NumberPicker view, final OnValueChangeListener listener,
|
||||
final InverseBindingListener attrChange) {
|
||||
if (attrChange == null) {
|
||||
view.setOnValueChangedListener(listener);
|
||||
} else {
|
||||
view.setOnValueChangedListener(new OnValueChangeListener() {
|
||||
@Override
|
||||
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
|
||||
if (listener != null) {
|
||||
listener.onValueChange(picker, oldVal, newVal);
|
||||
}
|
||||
attrChange.onChange();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.databinding.ObservableList;
|
||||
import android.databinding.ObservableList.OnListChangedCallback;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class ObservableListAdapter<T> extends BaseAdapter {
|
||||
private List<T> mList;
|
||||
private ObservableList.OnListChangedCallback mListChangedCallback;
|
||||
private final Context mContext;
|
||||
private final int mDropDownResourceId;
|
||||
private final int mResourceId;
|
||||
private final int mTextViewResourceId;
|
||||
private final LayoutInflater mLayoutInflater;
|
||||
|
||||
public ObservableListAdapter(Context context, List<T> list, int resourceId,
|
||||
int dropDownResourceId, int textViewResourceId) {
|
||||
mContext = context;
|
||||
mResourceId = resourceId;
|
||||
mDropDownResourceId = dropDownResourceId;
|
||||
mTextViewResourceId = textViewResourceId;
|
||||
mLayoutInflater = (resourceId == 0) ? null :
|
||||
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
setList(list);
|
||||
}
|
||||
|
||||
public void setList(List<T> list) {
|
||||
if (mList == list) {
|
||||
return;
|
||||
}
|
||||
if (mList instanceof ObservableList) {
|
||||
((ObservableList) mList).removeOnListChangedCallback(mListChangedCallback);
|
||||
}
|
||||
mList = list;
|
||||
if (mList instanceof ObservableList) {
|
||||
if (mListChangedCallback == null) {
|
||||
mListChangedCallback = new OnListChangedCallback() {
|
||||
@Override
|
||||
public void onChanged(ObservableList observableList) {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeChanged(ObservableList observableList, int i,
|
||||
int i1) {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeInserted(ObservableList observableList, int i,
|
||||
int i1) {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeMoved(ObservableList observableList, int i, int i1,
|
||||
int i2) {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeRemoved(ObservableList observableList, int i,
|
||||
int i1) {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
}
|
||||
((ObservableList) mList).addOnListChangedCallback(mListChangedCallback);
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return mList.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
return getViewForResource(mResourceId, position, convertView, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
||||
return getViewForResource(mDropDownResourceId, position, convertView, parent);
|
||||
}
|
||||
|
||||
public View getViewForResource(int resourceId, int position, View convertView,
|
||||
ViewGroup parent) {
|
||||
if (convertView == null) {
|
||||
if (resourceId == 0) {
|
||||
convertView = new TextView(mContext);
|
||||
} else {
|
||||
convertView = mLayoutInflater.inflate(resourceId, parent, false);
|
||||
}
|
||||
}
|
||||
TextView text = (TextView) (mTextViewResourceId == 0 ? convertView :
|
||||
convertView.findViewById(mTextViewResourceId));
|
||||
T item = mList.get(position);
|
||||
CharSequence value;
|
||||
if (item instanceof CharSequence) {
|
||||
value = (CharSequence) item;
|
||||
} else {
|
||||
value = String.valueOf(item);
|
||||
}
|
||||
text.setText(value);
|
||||
return convertView;
|
||||
}
|
||||
}
|
|
@ -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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = android.widget.ProgressBar.class, attribute = "android:indeterminateTint", method = "setIndeterminateTintList"),
|
||||
@BindingMethod(type = android.widget.ProgressBar.class, attribute = "android:progressTint", method = "setProgressTintList"),
|
||||
@BindingMethod(type = android.widget.ProgressBar.class, attribute = "android:secondaryProgressTint", method = "setSecondaryProgressTintList"),
|
||||
})
|
||||
public class ProgressBarBindingAdapter {
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.InverseBindingListener;
|
||||
import android.databinding.InverseBindingMethod;
|
||||
import android.databinding.InverseBindingMethods;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.RadioGroup.OnCheckedChangeListener;
|
||||
|
||||
@InverseBindingMethods({
|
||||
@InverseBindingMethod(type = RadioGroup.class, attribute = "android:checkedButton", method = "getCheckedRadioButtonId"),
|
||||
})
|
||||
public class RadioGroupBindingAdapter {
|
||||
@BindingAdapter("android:checkedButton")
|
||||
public static void setCheckedButton(RadioGroup view, int id) {
|
||||
if (id != view.getCheckedRadioButtonId()) {
|
||||
view.check(id);
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter(value = {"android:onCheckedChanged", "android:checkedButtonAttrChanged"},
|
||||
requireAll = false)
|
||||
public static void setListeners(RadioGroup view, final OnCheckedChangeListener listener,
|
||||
final InverseBindingListener attrChange) {
|
||||
if (attrChange == null) {
|
||||
view.setOnCheckedChangeListener(listener);
|
||||
} else {
|
||||
view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
if (listener != null) {
|
||||
listener.onCheckedChanged(group, checkedId);
|
||||
}
|
||||
|
||||
attrChange.onChange();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.InverseBindingListener;
|
||||
import android.databinding.InverseBindingMethod;
|
||||
import android.databinding.InverseBindingMethods;
|
||||
import android.widget.RatingBar;
|
||||
import android.widget.RatingBar.OnRatingBarChangeListener;
|
||||
|
||||
@InverseBindingMethods({
|
||||
@InverseBindingMethod(type = RatingBar.class, attribute = "android:rating"),
|
||||
})
|
||||
public class RatingBarBindingAdapter {
|
||||
@BindingAdapter("android:rating")
|
||||
public static void setRating(RatingBar view, float rating) {
|
||||
if (view.getRating() != rating) {
|
||||
view.setRating(rating);
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter(value = {"android:onRatingChanged", "android:ratingAttrChanged"},
|
||||
requireAll = false)
|
||||
public static void setListeners(RatingBar view, final OnRatingBarChangeListener listener,
|
||||
final InverseBindingListener ratingChange) {
|
||||
if (ratingChange == null) {
|
||||
view.setOnRatingBarChangeListener(listener);
|
||||
} else {
|
||||
view.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
|
||||
@Override
|
||||
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
|
||||
if (listener != null) {
|
||||
listener.onRatingChanged(ratingBar, rating, fromUser);
|
||||
}
|
||||
ratingChange.onChange();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.SearchView.OnQueryTextListener;
|
||||
import android.widget.SearchView.OnSuggestionListener;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = SearchView.class, attribute = "android:onQueryTextFocusChange", method = "setOnQueryTextFocusChangeListener"),
|
||||
@BindingMethod(type = SearchView.class, attribute = "android:onSearchClick", method = "setOnSearchClickListener"),
|
||||
@BindingMethod(type = SearchView.class, attribute = "android:onClose", method = "setOnCloseListener"),
|
||||
})
|
||||
public class SearchViewBindingAdapter {
|
||||
@BindingAdapter(value = {"android:onQueryTextSubmit", "android:onQueryTextChange"},
|
||||
requireAll = false)
|
||||
public static void setOnQueryTextListener(SearchView view, final OnQueryTextSubmit submit,
|
||||
final OnQueryTextChange change) {
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
|
||||
if (submit == null && change == null){
|
||||
view.setOnQueryTextListener(null);
|
||||
} else {
|
||||
view.setOnQueryTextListener(new OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
if (submit != null) {
|
||||
return submit.onQueryTextSubmit(query);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
if (change != null) {
|
||||
return change.onQueryTextChange(newText);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter(value = {"android:onSuggestionSelect", "android:onSuggestionClick"},
|
||||
requireAll = false)
|
||||
public static void setOnSuggestListener(SearchView view, final OnSuggestionSelect submit,
|
||||
final OnSuggestionClick change) {
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
|
||||
if (submit == null && change == null) {
|
||||
view.setOnSuggestionListener(null);
|
||||
} else {
|
||||
view.setOnSuggestionListener(new OnSuggestionListener() {
|
||||
@Override
|
||||
public boolean onSuggestionSelect(int position) {
|
||||
if (submit != null) {
|
||||
return submit.onSuggestionSelect(position);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSuggestionClick(int position) {
|
||||
if (change != null) {
|
||||
return change.onSuggestionClick(position);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(VERSION_CODES.HONEYCOMB)
|
||||
public interface OnQueryTextSubmit {
|
||||
boolean onQueryTextSubmit(String query);
|
||||
}
|
||||
|
||||
@TargetApi(VERSION_CODES.HONEYCOMB)
|
||||
public interface OnQueryTextChange {
|
||||
boolean onQueryTextChange(String newText);
|
||||
}
|
||||
|
||||
@TargetApi(VERSION_CODES.HONEYCOMB)
|
||||
public interface OnSuggestionSelect {
|
||||
boolean onSuggestionSelect(int position);
|
||||
}
|
||||
|
||||
@TargetApi(VERSION_CODES.HONEYCOMB)
|
||||
public interface OnSuggestionClick {
|
||||
boolean onSuggestionClick(int position);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.InverseBindingListener;
|
||||
import android.databinding.InverseBindingMethod;
|
||||
import android.databinding.InverseBindingMethods;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
|
||||
@InverseBindingMethods({
|
||||
@InverseBindingMethod(type = SeekBar.class, attribute = "android:progress"),
|
||||
})
|
||||
public class SeekBarBindingAdapter {
|
||||
|
||||
@BindingAdapter("android:progress")
|
||||
public static void setProgress(SeekBar view, int progress) {
|
||||
if (progress != view.getProgress()) {
|
||||
view.setProgress(progress);
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter(value = {"android:onStartTrackingTouch", "android:onStopTrackingTouch",
|
||||
"android:onProgressChanged", "android:progressAttrChanged"}, requireAll = false)
|
||||
public static void setOnSeekBarChangeListener(SeekBar view, final OnStartTrackingTouch start,
|
||||
final OnStopTrackingTouch stop, final OnProgressChanged progressChanged,
|
||||
final InverseBindingListener attrChanged) {
|
||||
if (start == null && stop == null && progressChanged == null && attrChanged == null) {
|
||||
view.setOnSeekBarChangeListener(null);
|
||||
} else {
|
||||
view.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (progressChanged != null) {
|
||||
progressChanged.onProgressChanged(seekBar, progress, fromUser);
|
||||
}
|
||||
if (attrChanged != null) {
|
||||
attrChanged.onChange();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
if (start != null) {
|
||||
start.onStartTrackingTouch(seekBar);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
if (stop != null) {
|
||||
stop.onStopTrackingTouch(seekBar);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnStartTrackingTouch {
|
||||
void onStartTrackingTouch(SeekBar seekBar);
|
||||
}
|
||||
|
||||
public interface OnStopTrackingTouch {
|
||||
void onStopTrackingTouch(SeekBar seekBar);
|
||||
}
|
||||
|
||||
public interface OnProgressChanged {
|
||||
void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = android.widget.Spinner.class, attribute = "android:popupBackground", method = "setPopupBackgroundDrawable"),
|
||||
})
|
||||
public class SpinnerBindingAdapter {
|
||||
}
|
|
@ -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.databinding.adapters;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.os.Build;
|
||||
import android.widget.Switch;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = android.widget.Switch.class, attribute = "android:thumb", method = "setThumbDrawable"),
|
||||
@BindingMethod(type = android.widget.Switch.class, 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);
|
||||
}
|
||||
}
|
|
@ -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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = android.support.v7.widget.SwitchCompat.class, attribute = "android:thumb", method = "setThumbDrawable"),
|
||||
@BindingMethod(type = android.support.v7.widget.SwitchCompat.class, attribute = "android:track", method = "setTrackDrawable"),
|
||||
})
|
||||
public class SwitchCompatBindingAdapter {
|
||||
|
||||
@BindingAdapter({"android:switchTextAppearance"})
|
||||
public static void setSwitchTextAppearance(SwitchCompat view, int value) {
|
||||
view.setSwitchTextAppearance(null, value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.InverseBindingAdapter;
|
||||
import android.databinding.InverseBindingListener;
|
||||
import android.widget.TabHost;
|
||||
import android.widget.TabHost.OnTabChangeListener;
|
||||
|
||||
public class TabHostBindingAdapter {
|
||||
|
||||
@InverseBindingAdapter(attribute = "android:currentTab")
|
||||
public static int getCurrentTab(TabHost view) {
|
||||
return view.getCurrentTab();
|
||||
}
|
||||
|
||||
@InverseBindingAdapter(attribute = "android:currentTab")
|
||||
public static String getCurrentTabTag(TabHost view) {
|
||||
return view.getCurrentTabTag();
|
||||
}
|
||||
|
||||
@BindingAdapter("android:currentTab")
|
||||
public static void setCurrentTab(TabHost view, int tab) {
|
||||
if (view.getCurrentTab() != tab) {
|
||||
view.setCurrentTab(tab);
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter("android:currentTab")
|
||||
public static void setCurrentTabTag(TabHost view, String tabTag) {
|
||||
if (view.getCurrentTabTag() != tabTag) {
|
||||
view.setCurrentTabByTag(tabTag);
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter(value = {"android:onTabChanged", "android:currentTabAttrChanged"},
|
||||
requireAll = false)
|
||||
public static void setListeners(TabHost view, final OnTabChangeListener listener,
|
||||
final InverseBindingListener attrChange) {
|
||||
if (attrChange == null) {
|
||||
view.setOnTabChangedListener(listener);
|
||||
} else {
|
||||
view.setOnTabChangedListener(new OnTabChangeListener() {
|
||||
@Override
|
||||
public void onTabChanged(String tabId) {
|
||||
if (listener != null) {
|
||||
listener.onTabChanged(tabId);
|
||||
}
|
||||
attrChange.onChange();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = android.widget.TabWidget.class, attribute = "android:divider", method = "setDividerDrawable"),
|
||||
@BindingMethod(type = android.widget.TabWidget.class, attribute = "android:tabStripEnabled", method = "setStripEnabled"),
|
||||
@BindingMethod(type = android.widget.TabWidget.class, attribute = "android:tabStripLeft", method = "setLeftStripDrawable"),
|
||||
@BindingMethod(type = android.widget.TabWidget.class, attribute = "android:tabStripRight", method = "setRightStripDrawable"),
|
||||
})
|
||||
public class TabWidgetBindingAdapter {
|
||||
|
||||
}
|
|
@ -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.databinding.adapters;
|
||||
|
||||
import android.databinding.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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,399 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import com.android.databinding.library.baseAdapters.R;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.databinding.InverseBindingAdapter;
|
||||
import android.databinding.InverseBindingListener;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.text.Editable;
|
||||
import android.text.InputFilter;
|
||||
import android.text.InputType;
|
||||
import android.text.Spanned;
|
||||
import android.text.SpannableString;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextWatcher;
|
||||
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 = TextView.class, attribute = "android:autoLink", method = "setAutoLinkMask"),
|
||||
@BindingMethod(type = TextView.class, attribute = "android:drawablePadding", method = "setCompoundDrawablePadding"),
|
||||
@BindingMethod(type = TextView.class, attribute = "android:editorExtras", method = "setInputExtras"),
|
||||
@BindingMethod(type = TextView.class, attribute = "android:inputType", method = "setRawInputType"),
|
||||
@BindingMethod(type = TextView.class, attribute = "android:scrollHorizontally", method = "setHorizontallyScrolling"),
|
||||
@BindingMethod(type = TextView.class, attribute = "android:textAllCaps", method = "setAllCaps"),
|
||||
@BindingMethod(type = TextView.class, attribute = "android:textColorHighlight", method = "setHighlightColor"),
|
||||
@BindingMethod(type = TextView.class, attribute = "android:textColorHint", method = "setHintTextColor"),
|
||||
@BindingMethod(type = TextView.class, attribute = "android:textColorLink", method = "setLinkTextColor"),
|
||||
@BindingMethod(type = TextView.class, attribute = "android:onEditorAction", method = "setOnEditorActionListener"),
|
||||
})
|
||||
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:text")
|
||||
public static void setText(TextView view, CharSequence text) {
|
||||
final CharSequence oldText = view.getText();
|
||||
if (text == oldText || (text == null && oldText.length() == 0)) {
|
||||
return;
|
||||
}
|
||||
if (text instanceof Spanned) {
|
||||
if (text.equals(oldText)) {
|
||||
return; // No change in the spans, so don't set anything.
|
||||
}
|
||||
} else if (!haveContentsChanged(text, oldText)) {
|
||||
return; // No content changes, so don't set anything.
|
||||
}
|
||||
view.setText(text);
|
||||
}
|
||||
|
||||
@InverseBindingAdapter(attribute = "android:text", event = "android:textAttrChanged")
|
||||
public static String getTextString(TextView view) {
|
||||
return view.getText().toString();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setIntrinsicBounds(Drawable drawable) {
|
||||
if (drawable != null) {
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter({"android:drawableBottom"})
|
||||
public static void setDrawableBottom(TextView view, Drawable drawable) {
|
||||
setIntrinsicBounds(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) {
|
||||
setIntrinsicBounds(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) {
|
||||
setIntrinsicBounds(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) {
|
||||
setIntrinsicBounds(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 {
|
||||
setIntrinsicBounds(drawable);
|
||||
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 {
|
||||
setIntrinsicBounds(drawable);
|
||||
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);
|
||||
}
|
||||
|
||||
private static boolean haveContentsChanged(CharSequence str1, CharSequence str2) {
|
||||
if ((str1 == null) != (str2 == null)) {
|
||||
return true;
|
||||
} else if (str1 == null) {
|
||||
return false;
|
||||
}
|
||||
final int length = str1.length();
|
||||
if (length != str2.length()) {
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (str1.charAt(i) != str2.charAt(i)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@BindingAdapter(value = {"android:beforeTextChanged", "android:onTextChanged",
|
||||
"android:afterTextChanged", "android:textAttrChanged"}, requireAll = false)
|
||||
public static void setTextWatcher(TextView view, final BeforeTextChanged before,
|
||||
final OnTextChanged on, final AfterTextChanged after,
|
||||
final InverseBindingListener textAttrChanged) {
|
||||
final TextWatcher newValue;
|
||||
if (before == null && after == null && on == null && textAttrChanged == null) {
|
||||
newValue = null;
|
||||
} else {
|
||||
newValue = new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
if (before != null) {
|
||||
before.beforeTextChanged(s, start, count, after);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
if (on != null) {
|
||||
on.onTextChanged(s, start, before, count);
|
||||
}
|
||||
if (textAttrChanged != null) {
|
||||
textAttrChanged.onChange();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (after != null) {
|
||||
after.afterTextChanged(s);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
final TextWatcher oldValue = ListenerUtil.trackListener(view, newValue, R.id.textWatcher);
|
||||
if (oldValue != null) {
|
||||
view.removeTextChangedListener(oldValue);
|
||||
}
|
||||
if (newValue != null) {
|
||||
view.addTextChangedListener(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
public interface AfterTextChanged {
|
||||
void afterTextChanged(Editable s);
|
||||
}
|
||||
|
||||
public interface BeforeTextChanged {
|
||||
void beforeTextChanged(CharSequence s, int start, int count, int after);
|
||||
}
|
||||
|
||||
public interface OnTextChanged {
|
||||
void onTextChanged(CharSequence s, int start, int before, int count);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.InverseBindingAdapter;
|
||||
import android.databinding.InverseBindingListener;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.widget.TimePicker;
|
||||
import android.widget.TimePicker.OnTimeChangedListener;
|
||||
|
||||
public class TimePickerBindingAdapter {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@BindingAdapter("android:hour")
|
||||
public static void setHour(TimePicker view, int hour) {
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.M) {
|
||||
if (view.getHour() != hour) {
|
||||
view.setHour(hour);
|
||||
}
|
||||
} else {
|
||||
if (view.getCurrentHour() != hour) {
|
||||
view.setCurrentHour(hour);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@BindingAdapter("android:minute")
|
||||
public static void setMinute(TimePicker view, int minute) {
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.M) {
|
||||
if (view.getMinute() != minute) {
|
||||
view.setMinute(minute);
|
||||
}
|
||||
} else {
|
||||
if (view.getCurrentMinute() != minute) {
|
||||
view.setCurrentHour(minute);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@InverseBindingAdapter(attribute = "android:hour")
|
||||
public static int getHour(TimePicker view) {
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.M) {
|
||||
return view.getHour();
|
||||
} else {
|
||||
@SuppressWarnings("deprecation")
|
||||
Integer hour = view.getCurrentHour();
|
||||
if (hour == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return hour;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@InverseBindingAdapter(attribute = "android:minute")
|
||||
public static int getMinute(TimePicker view) {
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.M) {
|
||||
return view.getMinute();
|
||||
} else {
|
||||
@SuppressWarnings("deprecation")
|
||||
Integer minute = view.getCurrentMinute();
|
||||
if (minute == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return minute;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter(value = {"android:onTimeChanged", "android:hourAttrChanged",
|
||||
"android:minuteAttrChanged"}, requireAll = false)
|
||||
public static void setListeners(TimePicker view, final OnTimeChangedListener listener,
|
||||
final InverseBindingListener hourChange, final InverseBindingListener minuteChange) {
|
||||
if (hourChange == null && minuteChange == null) {
|
||||
view.setOnTimeChangedListener(listener);
|
||||
} else {
|
||||
view.setOnTimeChangedListener(new OnTimeChangedListener() {
|
||||
@Override
|
||||
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
|
||||
if (listener != null) {
|
||||
listener.onTimeChanged(view, hourOfDay, minute);
|
||||
}
|
||||
if (hourChange != null) {
|
||||
hourChange.onChange();
|
||||
}
|
||||
if (minuteChange != null) {
|
||||
minuteChange.onChange();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.widget.Toolbar;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = Toolbar.class, attribute = "android:onMenuItemClick", method = "setOnMenuItemClickListener"),
|
||||
@BindingMethod(type = Toolbar.class, attribute = "android:onNavigationClick", method = "setNavigationOnClickListener"),
|
||||
})
|
||||
public class ToolbarBindingAdapter {
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.widget.VideoView;
|
||||
import android.widget.ViewSwitcher;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = VideoView.class, attribute = "android:onCompletion", method = "setOnCompletionListener"),
|
||||
@BindingMethod(type = VideoView.class, attribute = "android:onError", method = "setOnErrorListener"),
|
||||
@BindingMethod(type = VideoView.class, attribute = "android:onInfo", method = "setOnInfoListener"),
|
||||
@BindingMethod(type = VideoView.class, attribute = "android:onPrepared", method = "setOnPreparedListener"),
|
||||
})
|
||||
public class VideoViewBindingAdapter {
|
||||
}
|
|
@ -0,0 +1,241 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.view.View;
|
||||
import android.view.View.OnAttachStateChangeListener;
|
||||
import com.android.databinding.library.baseAdapters.R;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = View.class, attribute = "android:backgroundTint", method = "setBackgroundTintList"),
|
||||
@BindingMethod(type = View.class, attribute = "android:fadeScrollbars", method = "setScrollbarFadingEnabled"),
|
||||
@BindingMethod(type = View.class, attribute = "android:getOutline", method = "setOutlineProvider"),
|
||||
@BindingMethod(type = View.class, attribute = "android:nextFocusForward", method = "setNextFocusForwardId"),
|
||||
@BindingMethod(type = View.class, attribute = "android:nextFocusLeft", method = "setNextFocusLeftId"),
|
||||
@BindingMethod(type = View.class, attribute = "android:nextFocusRight", method = "setNextFocusRightId"),
|
||||
@BindingMethod(type = View.class, attribute = "android:nextFocusUp", method = "setNextFocusUpId"),
|
||||
@BindingMethod(type = View.class, attribute = "android:nextFocusDown", method = "setNextFocusDownId"),
|
||||
@BindingMethod(type = View.class, attribute = "android:requiresFadingEdge", method = "setVerticalFadingEdgeEnabled"),
|
||||
@BindingMethod(type = View.class, attribute = "android:scrollbarDefaultDelayBeforeFade", method = "setScrollBarDefaultDelayBeforeFade"),
|
||||
@BindingMethod(type = View.class, attribute = "android:scrollbarFadeDuration", method = "setScrollBarFadeDuration"),
|
||||
@BindingMethod(type = View.class, attribute = "android:scrollbarSize", method = "setScrollBarSize"),
|
||||
@BindingMethod(type = View.class, attribute = "android:scrollbarStyle", method = "setScrollBarStyle"),
|
||||
@BindingMethod(type = View.class, attribute = "android:transformPivotX", method = "setPivotX"),
|
||||
@BindingMethod(type = View.class, attribute = "android:transformPivotY", method = "setPivotY"),
|
||||
@BindingMethod(type = View.class, attribute = "android:onDrag", method = "setOnDragListener"),
|
||||
@BindingMethod(type = View.class, attribute = "android:onClick", method = "setOnClickListener"),
|
||||
@BindingMethod(type = View.class, attribute = "android:onApplyWindowInsets", method = "setOnApplyWindowInsetsListener"),
|
||||
@BindingMethod(type = View.class, attribute = "android:onCreateContextMenu", method = "setOnCreateContextMenuListener"),
|
||||
@BindingMethod(type = View.class, attribute = "android:onFocusChange", method = "setOnFocusChangeListener"),
|
||||
@BindingMethod(type = View.class, attribute = "android:onGenericMotion", method = "setOnGenericMotionListener"),
|
||||
@BindingMethod(type = View.class, attribute = "android:onHover", method = "setOnHoverListener"),
|
||||
@BindingMethod(type = View.class, attribute = "android:onKey", method = "setOnKeyListener"),
|
||||
@BindingMethod(type = View.class, attribute = "android:onLongClick", method = "setOnLongClickListener"),
|
||||
@BindingMethod(type = View.class, attribute = "android:onSystemUiVisibilityChange", method = "setOnSystemUiVisibilityChangeListener"),
|
||||
@BindingMethod(type = View.class, attribute = "android:onTouch", method = "setOnTouchListener"),
|
||||
})
|
||||
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, float paddingFloat) {
|
||||
final int padding = pixelsToDimensionPixelSize(paddingFloat);
|
||||
view.setPadding(padding, padding, padding, padding);
|
||||
}
|
||||
|
||||
@BindingAdapter({"android:paddingBottom"})
|
||||
public static void setPaddingBottom(View view, float paddingFloat) {
|
||||
final int padding = pixelsToDimensionPixelSize(paddingFloat);
|
||||
view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(),
|
||||
padding);
|
||||
}
|
||||
|
||||
@BindingAdapter({"android:paddingEnd"})
|
||||
public static void setPaddingEnd(View view, float paddingFloat) {
|
||||
final int padding = pixelsToDimensionPixelSize(paddingFloat);
|
||||
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, float paddingFloat) {
|
||||
final int padding = pixelsToDimensionPixelSize(paddingFloat);
|
||||
view.setPadding(padding, view.getPaddingTop(), view.getPaddingRight(),
|
||||
view.getPaddingBottom());
|
||||
}
|
||||
|
||||
@BindingAdapter({"android:paddingRight"})
|
||||
public static void setPaddingRight(View view, float paddingFloat) {
|
||||
final int padding = pixelsToDimensionPixelSize(paddingFloat);
|
||||
view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), padding,
|
||||
view.getPaddingBottom());
|
||||
}
|
||||
|
||||
@BindingAdapter({"android:paddingStart"})
|
||||
public static void setPaddingStart(View view, float paddingFloat) {
|
||||
final int padding = pixelsToDimensionPixelSize(paddingFloat);
|
||||
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, float paddingFloat) {
|
||||
final int padding = pixelsToDimensionPixelSize(paddingFloat);
|
||||
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);
|
||||
}
|
||||
|
||||
@BindingAdapter({"android:onClickListener", "android:clickable"})
|
||||
public static void setClickListener(View view, View.OnClickListener clickListener,
|
||||
boolean clickable) {
|
||||
view.setOnClickListener(clickListener);
|
||||
view.setClickable(clickable);
|
||||
}
|
||||
|
||||
@BindingAdapter({"android:onClick", "android:clickable"})
|
||||
public static void setOnClick(View view, View.OnClickListener clickListener,
|
||||
boolean clickable) {
|
||||
view.setOnClickListener(clickListener);
|
||||
view.setClickable(clickable);
|
||||
}
|
||||
|
||||
@BindingAdapter({"android:onLongClickListener", "android:longClickable"})
|
||||
public static void setOnLongClickListener(View view, View.OnLongClickListener clickListener,
|
||||
boolean clickable) {
|
||||
view.setOnLongClickListener(clickListener);
|
||||
view.setLongClickable(clickable);
|
||||
}
|
||||
|
||||
@BindingAdapter({"android:onLongClick", "android:longClickable"})
|
||||
public static void setOnLongClick(View view, View.OnLongClickListener clickListener,
|
||||
boolean clickable) {
|
||||
view.setOnLongClickListener(clickListener);
|
||||
view.setLongClickable(clickable);
|
||||
}
|
||||
|
||||
@BindingAdapter(value = {"android:onViewDetachedFromWindow", "android:onViewAttachedToWindow"},
|
||||
requireAll = false)
|
||||
public static void setOnAttachStateChangeListener(View view,
|
||||
final OnViewDetachedFromWindow detach, final OnViewAttachedToWindow attach) {
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB_MR1) {
|
||||
final OnAttachStateChangeListener newListener;
|
||||
if (detach == null && attach == null) {
|
||||
newListener = null;
|
||||
} else {
|
||||
newListener = new OnAttachStateChangeListener() {
|
||||
@Override
|
||||
public void onViewAttachedToWindow(View v) {
|
||||
if (attach != null) {
|
||||
attach.onViewAttachedToWindow(v);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewDetachedFromWindow(View v) {
|
||||
if (detach != null) {
|
||||
detach.onViewDetachedFromWindow(v);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
final OnAttachStateChangeListener oldListener = ListenerUtil.trackListener(view,
|
||||
newListener, R.id.onAttachStateChangeListener);
|
||||
if (oldListener != null) {
|
||||
view.removeOnAttachStateChangeListener(oldListener);
|
||||
}
|
||||
if (newListener != null) {
|
||||
view.addOnAttachStateChangeListener(newListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter("android:onLayoutChange")
|
||||
public static void setOnLayoutChangeListener(View view, View.OnLayoutChangeListener oldValue,
|
||||
View.OnLayoutChangeListener newValue) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
if (oldValue != null) {
|
||||
view.removeOnLayoutChangeListener(oldValue);
|
||||
}
|
||||
if (newValue != null) {
|
||||
view.addOnLayoutChangeListener(newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@BindingAdapter("android:background")
|
||||
public static void setBackground(View view, Drawable drawable) {
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
|
||||
view.setBackground(drawable);
|
||||
} else {
|
||||
view.setBackgroundDrawable(drawable);
|
||||
}
|
||||
}
|
||||
|
||||
// Follows the same conversion mechanism as in TypedValue.complexToDimensionPixelSize as used
|
||||
// when setting padding. It rounds off the float value unless the value is < 1.
|
||||
// When a value is between 0 and 1, it is set to 1. A value less than 0 is set to -1.
|
||||
private static int pixelsToDimensionPixelSize(float pixels) {
|
||||
final int result = (int) (pixels + 0.5f);
|
||||
if (result != 0) {
|
||||
return result;
|
||||
} else if (pixels == 0) {
|
||||
return 0;
|
||||
} else if (pixels > 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(VERSION_CODES.HONEYCOMB_MR1)
|
||||
public interface OnViewDetachedFromWindow {
|
||||
void onViewDetachedFromWindow(View v);
|
||||
}
|
||||
|
||||
@TargetApi(VERSION_CODES.HONEYCOMB_MR1)
|
||||
public interface OnViewAttachedToWindow {
|
||||
void onViewAttachedToWindow(View v);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.animation.LayoutTransition;
|
||||
import android.annotation.TargetApi;
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewGroup.OnHierarchyChangeListener;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.Animation.AnimationListener;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = android.view.ViewGroup.class, attribute = "android:alwaysDrawnWithCache", method = "setAlwaysDrawnWithCacheEnabled"),
|
||||
@BindingMethod(type = android.view.ViewGroup.class, attribute = "android:animationCache", method = "setAnimationCacheEnabled"),
|
||||
@BindingMethod(type = android.view.ViewGroup.class, 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);
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter(value = {"android:onChildViewAdded", "android:onChildViewRemoved"},
|
||||
requireAll = false)
|
||||
public static void setListener(ViewGroup view, final OnChildViewAdded added,
|
||||
final OnChildViewRemoved removed) {
|
||||
if (added == null && removed == null) {
|
||||
view.setOnHierarchyChangeListener(null);
|
||||
} else {
|
||||
view.setOnHierarchyChangeListener(new OnHierarchyChangeListener() {
|
||||
@Override
|
||||
public void onChildViewAdded(View parent, View child) {
|
||||
if (added != null) {
|
||||
added.onChildViewAdded(parent, child);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChildViewRemoved(View parent, View child) {
|
||||
if (removed != null) {
|
||||
removed.onChildViewRemoved(parent, child);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter(value = {"android:onAnimationStart", "android:onAnimationEnd",
|
||||
"android:onAnimationRepeat"}, requireAll = false)
|
||||
public static void setListener(ViewGroup view, final OnAnimationStart start,
|
||||
final OnAnimationEnd end, final OnAnimationRepeat repeat) {
|
||||
if (start == null && end == null && repeat == null) {
|
||||
view.setLayoutAnimationListener(null);
|
||||
} else {
|
||||
view.setLayoutAnimationListener(new AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
if (start != null) {
|
||||
start.onAnimationStart(animation);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
if (end != null) {
|
||||
end.onAnimationEnd(animation);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
if (repeat != null) {
|
||||
repeat.onAnimationRepeat(animation);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnChildViewAdded {
|
||||
void onChildViewAdded(View parent, View child);
|
||||
}
|
||||
|
||||
public interface OnChildViewRemoved {
|
||||
void onChildViewRemoved(View parent, View child);
|
||||
}
|
||||
|
||||
public interface OnAnimationStart {
|
||||
void onAnimationStart(Animation animation);
|
||||
}
|
||||
|
||||
public interface OnAnimationEnd {
|
||||
void onAnimationEnd(Animation animation);
|
||||
}
|
||||
|
||||
public interface OnAnimationRepeat {
|
||||
void onAnimationRepeat(Animation animation);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.databinding.Untaggable;
|
||||
import android.databinding.ViewStubProxy;
|
||||
import android.view.ViewStub.OnInflateListener;
|
||||
|
||||
@Untaggable({"android.view.ViewStub"})
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = android.view.ViewStub.class, attribute = "android:layout", method = "setLayoutResource")
|
||||
})
|
||||
public class ViewStubBindingAdapter {
|
||||
@BindingAdapter("android:onInflate")
|
||||
public static void setOnInflateListener(ViewStubProxy viewStubProxy,
|
||||
OnInflateListener listener) {
|
||||
viewStubProxy.setOnInflateListener(listener);
|
||||
}
|
||||
}
|
|
@ -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.databinding.adapters;
|
||||
|
||||
import android.databinding.BindingMethod;
|
||||
import android.databinding.BindingMethods;
|
||||
import android.widget.ZoomControls;
|
||||
|
||||
@BindingMethods({
|
||||
@BindingMethod(type = ZoomControls.class, attribute = "android:onZoomIn", method = "setOnZoomInClickListener"),
|
||||
@BindingMethod(type = ZoomControls.class, attribute = "android:onZoomOut", method = "setOnZoomOutClickListener"),
|
||||
})
|
||||
public class ZoomControlsBindingAdapter {
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Used to track OnAttachStateChangeListeners for View BindingAdapter -->
|
||||
<item type="id" name="onAttachStateChangeListener"/>
|
||||
<!-- Used to track TextWatcher for TextView BindingAdapter -->
|
||||
<item type="id" name="textWatcher"/>
|
||||
<!-- Used to track DatePicker OnDateChanged BindingAdapter -->
|
||||
<item type="id" name="onDateChanged"/>
|
||||
</resources>
|
Loading…
Add table
Add a link
Reference in a new issue