Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
# Built application files
# built application files
*.apk
*.ap_

# Files for the Dalvik VM
# files for the dex VM
*.dex

# Java class files
*.class

# Generated files
# generated files
bin/
gen/
out/

# Gradle files
# Intellij project files
*.iml
*.ipr
*.iws
.idea/

# Ignore gradle files
.gradle/
build/
/*/build/
gradle/
gradlew
gradlew.bat

# Local configuration file (sdk path, etc)
local.properties
project.properties

# Eclipse project files
.classpath
.project

# Proguard folder generated by Eclipse
proguard/

# Log Files
# Log files
*.log
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
2 changes: 1 addition & 1 deletion .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 49 additions & 26 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions app/app.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="DataBindingSamples" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="HJAndroidDataBinding" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down Expand Up @@ -73,7 +73,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.databinding/library/1.0-rc0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.databinding/library/1.0-rc1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/cardview-v7/22.0.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/22.0.0/jars" />
Expand All @@ -96,27 +96,27 @@
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="antlr4-4.4" level="project" />
<orderEntry type="library" exported="" name="kotlin-runtime-0.11.91" level="project" />
<orderEntry type="library" exported="" name="antlr4-4.5" level="project" />
<orderEntry type="library" exported="" name="kotlin-runtime-0.12.613" level="project" />
<orderEntry type="library" exported="" name="org.abego.treelayout.core-1.0.1" level="project" />
<orderEntry type="library" exported="" name="antlr-runtime-3.5.2" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
<orderEntry type="library" exported="" name="kotlin-stdlib-0.11.91" level="project" />
<orderEntry type="library" exported="" name="antlr4-runtime-4.5" level="project" />
<orderEntry type="library" exported="" name="picasso-2.5.2" level="project" />
<orderEntry type="library" exported="" name="commons-io-2.4" level="project" />
<orderEntry type="library" exported="" name="baseLibrary-1.0-rc0" level="project" />
<orderEntry type="library" exported="" name="baseLibrary-1.0-rc1" level="project" />
<orderEntry type="library" exported="" name="commons-lang3-3.3.2" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-22.0.0" level="project" />
<orderEntry type="library" exported="" name="adapters-1.0-rc0" level="project" />
<orderEntry type="library" exported="" name="antlr4-runtime-4.4" level="project" />
<orderEntry type="library" exported="" name="guava-17.0" level="project" />
<orderEntry type="library" exported="" name="adapters-1.0-rc1" level="project" />
<orderEntry type="library" exported="" name="commons-codec-1.10" level="project" />
<orderEntry type="library" exported="" name="compiler-1.0-rc1" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
<orderEntry type="library" exported="" name="antlr4-annotations-4.4" level="project" />
<orderEntry type="library" exported="" name="compiler-1.0-rc0" level="project" />
<orderEntry type="library" exported="" name="library-1.0-rc0" level="project" />
<orderEntry type="library" exported="" name="compilerCommon-1.0-rc1" level="project" />
<orderEntry type="library" exported="" name="ST4-4.0.8" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="kotlin-stdlib-0.12.613" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-22.0.0" level="project" />
<orderEntry type="library" exported="" name="library-1.0-rc1" level="project" />
<orderEntry type="library" exported="" name="antlr4-annotations-4.5" level="project" />
</component>
</module>
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'com.android.databinding'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
buildToolsVersion '22.0.1'

defaultConfig {
applicationId "com.liangfeizc.databindingsamples"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.liangfeizc.databindingsamples;

import android.content.Intent;
import android.databinding.BindingAdapter;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.style.DynamicDrawableSpan;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.liangfeizc.databindingsamples.attributesetters.AttributeSettersActivity;
import com.liangfeizc.databindingsamples.basic.BasicActivity;
Expand All @@ -19,6 +24,7 @@
import com.liangfeizc.databindingsamples.resources.ResourceActivity;
import com.liangfeizc.databindingsamples.viewids.ViewWithIDsActivity;
import com.liangfeizc.databindingsamples.viewstub.ViewStubActivity;
import com.squareup.picasso.Picasso;

public class MainActivity extends AppCompatActivity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,81 @@
import android.databinding.DataBindingUtil;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.liangfeizc.databindingsamples.BaseActivity;
import com.liangfeizc.databindingsamples.R;
import com.liangfeizc.databindingsamples.basic.User;
import com.liangfeizc.databindingsamples.databinding.ActivityAttributeSettersBinding;
import com.squareup.picasso.Picasso;

public class AttributeSettersActivity extends BaseActivity {
private ActivityAttributeSettersBinding binding;
private static final String TAG = "AttributeSetters";
public static final String IMG_URL = "http://tvfan.kyodo.co.jp/wp-content/uploads/2015/01/15027b37a4104edd85fb5b79a6c9e3ac-344x516.jpg";
public View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(
getApplicationContext(),
"User view is clicked",
Toast.LENGTH_LONG).show();
}
};
public static final String IMG_URL = "https://avatars2.githubusercontent.com/u/8111106?v=3&s=460";
//"http://tvfan.kyodo.co.jp/wp-content/uploads/2015/01/15027b37a4104edd85fb5b79a6c9e3ac-344x516.jpg";
public static final String NAMESPACE = "AttributeSettersActivity";
public View.OnClickListener clickListener,firstClickListener,secondClickListener;
private static boolean ifFirst = true;
private User user = new User("Jue","Huang",24);

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

ActivityAttributeSettersBinding binding =
DataBindingUtil.setContentView(this, R.layout.activity_attribute_setters);

binding = DataBindingUtil.setContentView(this, R.layout.activity_attribute_setters);
initListener();
binding.setActivity(this);
binding.setImageUrl(IMG_URL);
binding.setUser(user);

}

@BindingAdapter({"bind:imageUrl", "bind:error"})
public static void loadImage(ImageView view, String url, Drawable error) {
Picasso.with(view.getContext()).load(url).error(error).into(view);
private void initListener() {
firstClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(
getApplicationContext(),
"User view is clicked-first",
Toast.LENGTH_SHORT).show();
changeListener();

}
};

secondClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(
getApplicationContext(),
"User view is clicked-second",
Toast.LENGTH_SHORT).show();
changeListener();
}
};

clickListener = firstClickListener;
}

private void changeListener() {
ifFirst = !ifFirst;
clickListener = (ifFirst)? firstClickListener: secondClickListener;
//如果没有binding的setActivity,则无法刷新clicklistener
binding.setActivity(this);
}

//这个函数可以写在任何一个class当中,所有imageview满足以下三个入参的都会运行该函数
@BindingAdapter({"bind:imageUrl", "bind:error","bind:namespace"})
public static void loadImage(ImageView view, String url, Drawable error,String namespace) {
if (namespace.equals(NAMESPACE)){
Picasso.with(view.getContext()).load(url).error(error).into(view);
Toast.makeText(view.getContext(), "loading:"+namespace, Toast.LENGTH_SHORT).show();
}

}
}

Loading