Skip to content

Commit

Permalink
updates for new event-handling approach
Browse files Browse the repository at this point in the history
  • Loading branch information
commonsguy committed Jul 21, 2016
1 parent 948bc99 commit df8663b
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 140 deletions.
4 changes: 2 additions & 2 deletions DataBinding/Basic/app/build.gradle
Expand Up @@ -7,8 +7,8 @@ dependencies {
} }


android { android {
compileSdkVersion 23 compileSdkVersion 24
buildToolsVersion "23.0.2" buildToolsVersion "24.0.0"


defaultConfig { defaultConfig {
minSdkVersion 15 minSdkVersion 15
Expand Down
8 changes: 4 additions & 4 deletions DataBinding/Conversion/app/build.gradle
Expand Up @@ -4,13 +4,13 @@ dependencies {
compile 'de.greenrobot:eventbus:2.4.0' compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.retrofit:retrofit:1.9.0' compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.android.support:recyclerview-v7:23.1.1' compile 'com.android.support:recyclerview-v7:24.1.0'
compile 'com.android.support:cardview-v7:23.1.1' compile 'com.android.support:cardview-v7:24.1.0'
} }


android { android {
compileSdkVersion 23 compileSdkVersion 24
buildToolsVersion "23.0.2" buildToolsVersion "24.0.0"


defaultConfig { defaultConfig {
minSdkVersion 15 minSdkVersion 15
Expand Down
@@ -1,54 +1,30 @@
/*** /***
* Copyright (c) 2013-2015 CommonsWare, LLC Copyright (c) 2013-2014 CommonsWare, LLC
* Licensed under the Apache License, Version 2.0 (the Licensed under the Apache License, Version 2.0 (the "License"); you may not
* "License"); you may not use this file except in compliance with the License. You may obtain a copy
* use this file except in compliance with the License. You may of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
* obtain a copy by applicable law or agreed to in writing, software distributed under the
* of the License at http://www.apache.org/licenses/LICENSE-2.0. License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
* Unless required OF ANY KIND, either express or implied. See the License for the specific
* by applicable law or agreed to in writing, software language governing permissions and limitations under the License.
* distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES From _The Busy Coder's Guide to Android Development_
* OR CONDITIONS https://commonsware.com/Android
* OF ANY KIND, either express or implied. See the License for
* the specific
* language governing permissions and limitations under the
* License.
* <p/>
* From _The Busy Coder's Guide to Android Development_
* https://commonsware.com/Android
*/ */


package com.commonsware.android.databind.basic; package com.commonsware.android.databind.basic;


import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.databinding.DataBindingUtil;
import android.os.Build; import android.os.Build;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import com.commonsware.android.databind.basic.databinding.RowBinding; import com.commonsware.android.databind.basic.databinding.RowBinding;
import de.greenrobot.event.EventBus; import de.greenrobot.event.EventBus;


public class QuestionController public class QuestionController extends RecyclerView.ViewHolder
extends RecyclerView.ViewHolder implements View.OnTouchListener {
implements View.OnClickListener {
public static final View.OnTouchListener ON_TOUCH=
new View.OnTouchListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean onTouch(View v, MotionEvent event) {
if (Build.VERSION.SDK_INT>=
Build.VERSION_CODES.LOLLIPOP) {
v
.findViewById(R.id.row_content)
.getBackground()
.setHotspot(event.getX(), event.getY());
}

return(false);
}
};

private final RowBinding rowBinding; private final RowBinding rowBinding;
private final QuestionsFragment.QuestionsAdapter adapter; private final QuestionsFragment.QuestionsAdapter adapter;


Expand All @@ -60,15 +36,25 @@ public QuestionController(RowBinding rowBinding,
this.adapter=adapter; this.adapter=adapter;
} }


@Override public void showQuestion(Question question) {
public void onClick(View v) {
Question question=adapter.getItem(getAdapterPosition());

EventBus.getDefault().post(new QuestionClickedEvent(question)); EventBus.getDefault().post(new QuestionClickedEvent(question));
} }


@Override
public boolean onTouch(View v, MotionEvent event){
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP){
v
.findViewById(R.id.row_content)
.getBackground()
.setHotspot(event.getX(),event.getY());
}

return(false);
}

void bindModel(Question question) { void bindModel(Question question) {
rowBinding.setQuestion(question); rowBinding.setQuestion(question);
rowBinding.setController(this); rowBinding.setController(this);
rowBinding.executePendingBindings();
} }
} }
4 changes: 2 additions & 2 deletions DataBinding/Conversion/app/src/main/res/layout/row.xml
Expand Up @@ -28,8 +28,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:onClick="@{controller}" android:onClick="@{()->controller.showQuestion(question)}"
android:onTouch="@{controller.ON_TOUCH}" android:onTouch="@{(v,event)->controller.onTouch(v,event)}"
android:orientation="horizontal"> android:orientation="horizontal">


<ImageView <ImageView
Expand Down
8 changes: 4 additions & 4 deletions DataBinding/Observable/app/build.gradle
Expand Up @@ -4,13 +4,13 @@ dependencies {
compile 'de.greenrobot:eventbus:2.4.0' compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.retrofit:retrofit:1.9.0' compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.android.support:recyclerview-v7:23.1.1' compile 'com.android.support:recyclerview-v7:24.1.0'
compile 'com.android.support:cardview-v7:23.1.1' compile 'com.android.support:cardview-v7:24.1.0'
} }


android { android {
compileSdkVersion 23 compileSdkVersion 24
buildToolsVersion "23.0.2" buildToolsVersion "24.0.0"


defaultConfig { defaultConfig {
minSdkVersion 15 minSdkVersion 15
Expand Down
@@ -1,54 +1,30 @@
/*** /***
* Copyright (c) 2013-2015 CommonsWare, LLC Copyright (c) 2013-2014 CommonsWare, LLC
* Licensed under the Apache License, Version 2.0 (the Licensed under the Apache License, Version 2.0 (the "License"); you may not
* "License"); you may not use this file except in compliance with the License. You may obtain a copy
* use this file except in compliance with the License. You may of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
* obtain a copy by applicable law or agreed to in writing, software distributed under the
* of the License at http://www.apache.org/licenses/LICENSE-2.0. License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
* Unless required OF ANY KIND, either express or implied. See the License for the specific
* by applicable law or agreed to in writing, software language governing permissions and limitations under the License.
* distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES From _The Busy Coder's Guide to Android Development_
* OR CONDITIONS https://commonsware.com/Android
* OF ANY KIND, either express or implied. See the License for
* the specific
* language governing permissions and limitations under the
* License.
* <p/>
* From _The Busy Coder's Guide to Android Development_
* https://commonsware.com/Android
*/ */


package com.commonsware.android.databind.basic; package com.commonsware.android.databind.basic;


import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.databinding.DataBindingUtil;
import android.os.Build; import android.os.Build;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import com.commonsware.android.databind.basic.databinding.RowBinding; import com.commonsware.android.databind.basic.databinding.RowBinding;
import de.greenrobot.event.EventBus; import de.greenrobot.event.EventBus;


public class QuestionController public class QuestionController extends RecyclerView.ViewHolder
extends RecyclerView.ViewHolder implements View.OnTouchListener {
implements View.OnClickListener {
public static final View.OnTouchListener ON_TOUCH=
new View.OnTouchListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean onTouch(View v, MotionEvent event) {
if (Build.VERSION.SDK_INT>=
Build.VERSION_CODES.LOLLIPOP) {
v
.findViewById(R.id.row_content)
.getBackground()
.setHotspot(event.getX(), event.getY());
}

return(false);
}
};

private final RowBinding rowBinding; private final RowBinding rowBinding;
private final QuestionsFragment.QuestionsAdapter adapter; private final QuestionsFragment.QuestionsAdapter adapter;


Expand All @@ -60,15 +36,25 @@ public QuestionController(RowBinding rowBinding,
this.adapter=adapter; this.adapter=adapter;
} }


@Override public void showQuestion(Question question) {
public void onClick(View v) {
Question question=adapter.getItem(getAdapterPosition());

EventBus.getDefault().post(new QuestionClickedEvent(question)); EventBus.getDefault().post(new QuestionClickedEvent(question));
} }


@Override
public boolean onTouch(View v, MotionEvent event){
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP){
v
.findViewById(R.id.row_content)
.getBackground()
.setHotspot(event.getX(),event.getY());
}

return(false);
}

void bindModel(Question question) { void bindModel(Question question) {
rowBinding.setQuestion(question); rowBinding.setQuestion(question);
rowBinding.setController(this); rowBinding.setController(this);
rowBinding.executePendingBindings();
} }
} }
4 changes: 2 additions & 2 deletions DataBinding/Observable/app/src/main/res/layout/row.xml
Expand Up @@ -28,8 +28,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:onClick="@{controller}" android:onClick="@{()->controller.showQuestion(question)}"
android:onTouch="@{controller.ON_TOUCH}" android:onTouch="@{(v,event)->controller.onTouch(v,event)}"
android:orientation="horizontal"> android:orientation="horizontal">


<ImageView <ImageView
Expand Down
4 changes: 2 additions & 2 deletions DataBinding/Picasso/app/build.gradle
Expand Up @@ -7,8 +7,8 @@ dependencies {
} }


android { android {
compileSdkVersion 23 compileSdkVersion 24
buildToolsVersion "23.0.2" buildToolsVersion "24.0.0"


defaultConfig { defaultConfig {
minSdkVersion 15 minSdkVersion 15
Expand Down
8 changes: 4 additions & 4 deletions DataBinding/RecyclerView/app/build.gradle
Expand Up @@ -4,13 +4,13 @@ dependencies {
compile 'de.greenrobot:eventbus:2.4.0' compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.retrofit:retrofit:1.9.0' compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.android.support:recyclerview-v7:23.1.1' compile 'com.android.support:recyclerview-v7:24.1.0'
compile 'com.android.support:cardview-v7:23.1.1' compile 'com.android.support:cardview-v7:24.1.0'
} }


android { android {
compileSdkVersion 23 compileSdkVersion 24
buildToolsVersion "23.0.2" buildToolsVersion "24.0.0"


defaultConfig { defaultConfig {
minSdkVersion 15 minSdkVersion 15
Expand Down
Expand Up @@ -14,54 +14,42 @@


package com.commonsware.android.databind.basic; package com.commonsware.android.databind.basic;


import android.annotation.TargetApi;
import android.os.Build; import android.os.Build;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import com.commonsware.android.databind.basic.databinding.RowBinding; import com.commonsware.android.databind.basic.databinding.RowBinding;
import de.greenrobot.event.EventBus; import de.greenrobot.event.EventBus;


public class QuestionController public class QuestionController extends RecyclerView.ViewHolder
extends RecyclerView.ViewHolder implements View.OnTouchListener {
implements View.OnClickListener {
public static final View.OnTouchListener ON_TOUCH=
new View.OnTouchListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean onTouch(View v, MotionEvent event) {
if (Build.VERSION.SDK_INT>=
Build.VERSION_CODES.LOLLIPOP) {
v
.findViewById(R.id.row_content)
.getBackground()
.setHotspot(event.getX(), event.getY());
}

return(false);
}
};

private final RowBinding rowBinding; private final RowBinding rowBinding;
private final QuestionsFragment.QuestionsAdapter adapter;


public QuestionController(RowBinding rowBinding, public QuestionController(RowBinding rowBinding) {
QuestionsFragment.QuestionsAdapter adapter) {
super(rowBinding.getRoot()); super(rowBinding.getRoot());


this.rowBinding=rowBinding; this.rowBinding=rowBinding;
this.adapter=adapter;
} }


@Override public void showQuestion(Question question) {
public void onClick(View v) {
Question question=adapter.getItem(getAdapterPosition());

EventBus.getDefault().post(new QuestionClickedEvent(question)); EventBus.getDefault().post(new QuestionClickedEvent(question));
} }


@Override
public boolean onTouch(View v, MotionEvent event) {
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP) {
v
.findViewById(R.id.row_content)
.getBackground()
.setHotspot(event.getX(), event.getY());
}

return(false);
}

void bindModel(Question question) { void bindModel(Question question) {
rowBinding.setQuestion(question); rowBinding.setQuestion(question);
rowBinding.setController(this); rowBinding.setController(this);
rowBinding.executePendingBindings();
} }
} }
Expand Up @@ -166,7 +166,7 @@ public QuestionController onCreateViewHolder(ViewGroup parent,
RowBinding.inflate(getActivity().getLayoutInflater(), RowBinding.inflate(getActivity().getLayoutInflater(),
parent, false); parent, false);


return(new QuestionController(rowBinding, this)); return(new QuestionController(rowBinding));
} }


@Override @Override
Expand Down
4 changes: 2 additions & 2 deletions DataBinding/RecyclerView/app/src/main/res/layout/row.xml
Expand Up @@ -28,8 +28,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:onClick="@{controller}" android:onClick="@{()->controller.showQuestion(question)}"
android:onTouch="@{controller.ON_TOUCH}" android:onTouch="@{controller::onTouch}"
android:orientation="horizontal"> android:orientation="horizontal">


<ImageView <ImageView
Expand Down
4 changes: 2 additions & 2 deletions DataBinding/Scored/app/build.gradle
Expand Up @@ -7,8 +7,8 @@ dependencies {
} }


android { android {
compileSdkVersion 23 compileSdkVersion 24
buildToolsVersion "23.0.2" buildToolsVersion "24.0.0"


defaultConfig { defaultConfig {
minSdkVersion 15 minSdkVersion 15
Expand Down

0 comments on commit df8663b

Please sign in to comment.