summaryrefslogtreecommitdiff
path: root/integration-tests/TestApp/app/src/main/java
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2015-06-17 16:09:52 -0700
committerGeorge Mount <mount@google.com>2015-06-23 15:18:43 -0700
commit716ba89e7f459f49ea85070d4710c1d79d715298 (patch)
tree256cfa9eb7d085f88d27001d35bcea9728a35596 /integration-tests/TestApp/app/src/main/java
parentaf84cb304c158381a8bf0f0ac1c37c5a2ad04bfb (diff)
downloaddata-binding-716ba89e7f459f49ea85070d4710c1d79d715298.tar.gz
Support calling listener methods without interfaces.
Bug 21594573 It is convenient to be able to assign event listeners by just referencing a method, similar to the way onClick="handler" works. This adds a whole lot of listeners for the framework. Additional listeners must be added for support library components. This isn't perfect in resolving listeners. Perfect resolution requires that each expression is evaluated in its own context within the binding statement. If, for example, the same method name is used for a listener and an accessor, we will assume that the listener is used always and there will be a compilation failure. Change-Id: If4705122b67a451430451b6e7d890eb813af1c5c
Diffstat (limited to 'integration-tests/TestApp/app/src/main/java')
-rw-r--r--integration-tests/TestApp/app/src/main/java/android/databinding/testapp/adapter/WeirdListeners.java40
-rw-r--r--integration-tests/TestApp/app/src/main/java/android/databinding/testapp/vo/ListenerBindingObject.java253
-rw-r--r--integration-tests/TestApp/app/src/main/java/android/databinding/testapp/vo/ViewBindingObject.java5
3 files changed, 298 insertions, 0 deletions
diff --git a/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/adapter/WeirdListeners.java b/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/adapter/WeirdListeners.java
new file mode 100644
index 00000000..5f7bb5d8
--- /dev/null
+++ b/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/adapter/WeirdListeners.java
@@ -0,0 +1,40 @@
+/*
+ * 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.testapp.adapter;
+
+import android.annotation.TargetApi;
+import android.databinding.BindingAdapter;
+import android.os.Build.VERSION_CODES;
+import android.view.View;
+
+public class WeirdListeners {
+ @BindingAdapter("android:onFoo")
+ public static void setListener(View view, OnFoo onFoo) {}
+
+ @BindingAdapter("android:onFoo2")
+ public static void setListener(View view, OnFoo2 onFoo) {}
+
+ @TargetApi(VERSION_CODES.ICE_CREAM_SANDWICH)
+ public static abstract class OnFoo {
+ public abstract void onFoo();
+
+ public void onBar() {}
+ }
+
+ public interface OnFoo2 {
+ void onFoo();
+ }
+}
diff --git a/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/vo/ListenerBindingObject.java b/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/vo/ListenerBindingObject.java
new file mode 100644
index 00000000..cc0c42cb
--- /dev/null
+++ b/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/vo/ListenerBindingObject.java
@@ -0,0 +1,253 @@
+/*
+ * 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.testapp.vo;
+
+import android.content.Context;
+import android.databinding.ObservableBoolean;
+import android.graphics.Outline;
+import android.media.MediaPlayer;
+import android.text.Editable;
+import android.view.ActionMode;
+import android.view.ContextMenu;
+import android.view.DragEvent;
+import android.view.KeyEvent;
+import android.view.MenuItem;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewStub;
+import android.view.WindowInsets;
+import android.view.animation.Animation;
+import android.widget.AbsListView;
+import android.widget.AdapterView;
+import android.widget.CalendarView;
+import android.widget.Chronometer;
+import android.widget.CompoundButton;
+import android.widget.ExpandableListView;
+import android.widget.NumberPicker;
+import android.widget.RadioGroup;
+import android.widget.RatingBar;
+import android.widget.SeekBar;
+import android.widget.TextView;
+import android.widget.TimePicker;
+
+public class ListenerBindingObject {
+ public static int lastClick = 0;
+ public boolean inflateCalled;
+ private final Context mContext;
+
+ public final ObservableBoolean clickable = new ObservableBoolean();
+ public final ObservableBoolean useOne = new ObservableBoolean();
+
+ public ListenerBindingObject(Context context) {
+ clickable.set(true);
+ this.mContext = context;
+ }
+
+ public void onMovedToScrapHeap(View view) { }
+
+ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
+ int totalItemCount) {}
+
+ public void onScrollStateChanged(AbsListView view, int scrollState) { }
+
+ public boolean onMenuItemClick(MenuItem item) {
+ return false;
+ }
+
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { }
+
+ public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
+ return true;
+ }
+
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { }
+
+ public void onNothingSelected(AdapterView<?> parent) { }
+
+ public void onDismiss() { }
+
+ public CharSequence fixText(CharSequence invalidText) {
+ return invalidText;
+ }
+
+ public boolean isValid(CharSequence text) {
+ return true;
+ }
+
+ public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) { }
+
+ public void onChronometerTick(Chronometer chronometer) { }
+
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { }
+
+ public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
+ int childPosition, long id) {
+ return false;
+ }
+
+ public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
+ return false;
+ }
+
+ public void onGroupCollapse(int groupPosition) { }
+
+ public void onGroupExpand(int groupPosition) { }
+
+ public String format(int value) {
+ return null;
+ }
+
+ public void onValueChange(NumberPicker picker, int oldVal, int newVal) { }
+
+ public void onScrollStateChange(NumberPicker view, int scrollState) { }
+
+ public void onCheckedChanged(RadioGroup group, int checkedId) { }
+
+ public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { }
+
+ public boolean onClose() {
+ return false;
+ }
+
+ public boolean onQueryTextChange(String newText) {
+ return false;
+ }
+
+ public boolean onQueryTextSubmit(String query) {
+ return false;
+ }
+
+ public boolean onSuggestionClick(int position) {
+ return false;
+ }
+
+ public boolean onSuggestionSelect(int position) {
+ return false;
+ }
+
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { }
+
+ public void onStartTrackingTouch(SeekBar seekBar) { }
+
+ public void onStopTrackingTouch(SeekBar seekBar) { }
+
+ public void onTabChanged(String tabId) { }
+
+ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
+ return false;
+ }
+
+ public void afterTextChanged(Editable s) { }
+
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
+
+ public void onTextChanged(CharSequence s, int start, int before, int count) { }
+
+ public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { }
+
+ public void onClick(View view) { }
+
+ public void onCompletion(MediaPlayer mp) { }
+
+ public boolean onError(MediaPlayer mp, int what, int extra) {
+ return true;
+ }
+
+ public boolean onInfo(MediaPlayer mp, int what, int extra) {
+ return true;
+ }
+
+ public void onPrepared(MediaPlayer mp) { }
+
+ public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
+ return null;
+ }
+
+ public void onCreateContextMenu(ContextMenu menu, View v,
+ ContextMenu.ContextMenuInfo menuInfo) { }
+
+ public boolean onDrag(View v, DragEvent event) {
+ return true;
+ }
+
+ public void onFocusChange(View v, boolean hasFocus) { }
+
+ public boolean onGenericMotion(View v, MotionEvent event) {
+ return true;
+ }
+
+ public boolean onHover(View v, MotionEvent event) {
+ return true;
+ }
+
+ public boolean onKey(View v, int keyCode, KeyEvent event) {
+ return true;
+ }
+
+ public boolean onLongClick(View v) {
+ return true;
+ }
+
+ public void onSystemUiVisibilityChange(int visibility) { }
+
+ public boolean onTouch(View v, MotionEvent event) {
+ return true;
+ }
+
+ public void getOutline(View view, Outline outline) { }
+
+ public void onViewAttachedToWindow(View v) { }
+
+ public void onViewDetachedFromWindow(View v) { }
+
+ public void onChildViewAdded(View parent, View child) { }
+
+ public void onChildViewRemoved(View parent, View child) { }
+
+ public void onAnimationEnd(Animation animation) { }
+
+ public void onAnimationRepeat(Animation animation) { }
+
+ public void onAnimationStart(Animation animation) { }
+
+ public void onInflate(ViewStub stub, View inflated) {
+ inflateCalled = true;
+ }
+
+ public View makeView() {
+ return new View(mContext);
+ }
+
+ public void onClick1(View view) {
+ lastClick = 1;
+ }
+
+ public static void onClick2(View view) {
+ lastClick = 2;
+ }
+
+ public void onClick3(View view) {
+ lastClick = 3;
+ }
+
+ public static void onClick4(View view) {
+ lastClick = 4;
+ }
+
+ public void onFoo() {
+ }
+
+}
diff --git a/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/vo/ViewBindingObject.java b/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/vo/ViewBindingObject.java
index bdb438eb..c55f473f 100644
--- a/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/vo/ViewBindingObject.java
+++ b/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/vo/ViewBindingObject.java
@@ -63,6 +63,8 @@ public class ViewBindingObject extends BindingAdapterBindingObject {
private int mPaddingStart = 16;
@Bindable
private int mPaddingEnd = 17;
+ @Bindable
+ private boolean mClickable = true;
public int getBackgroundTint() {
return mBackgroundTint;
@@ -148,6 +150,8 @@ public class ViewBindingObject extends BindingAdapterBindingObject {
return mPaddingTop;
}
+ public boolean getClickable() { return mClickable; }
+
public void changeValues() {
mBackgroundTint = 0xFFFF0000;
mFadeScrollbars = false;
@@ -170,6 +174,7 @@ public class ViewBindingObject extends BindingAdapterBindingObject {
mPaddingRight = 150;
mPaddingStart = 160;
mPaddingEnd = 170;
+ mClickable = false;
notifyChange();
}
}