Skip to content

Instantly share code, notes, and snippets.

View rickyngk's full-sized avatar

Ricky.ngk rickyngk

  • Vietnamworks
  • Vietnam
View GitHub Profile
public class SampleViewModel {
private String buttonTitle = "Click me!";
private Context context;
public static interface ISampleViewModelEventListener {
void onClickButton();
}
private ISampleViewModelEventListener listener;
public SampleViewModel(Context context, ISampleViewModelEventListener listener) {
public class SampleViewModel {
private String buttonTitle = "Click me!";
private Context context;
public SampleViewModel(Context context) {
this.context = context;
}
public String getButtonTitle() {
return buttonTitle;
@rickyngk
rickyngk / SampleViewModel.java
Created April 4, 2016 02:40
Simple View Model
package com.rickyngk.databinding.sample1;
/**
* Created by duynk on 4/4/16.
*
*/
public class SampleViewModel {
private String text = "This is a sample";
public String getText() {
@rickyngk
rickyngk / build.gradle
Created April 4, 2016 02:33
Enable data binding
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.rickyngk.databinding.sample1"
minSdkVersion 8
targetSdkVersion 23
@rickyngk
rickyngk / pom.xml
Created January 25, 2016 17:06
graphaware sample pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.r</groupId>
<artifactId>try_graphaware</artifactId>
<version>1.0-SNAPSHOT</version>
@rickyngk
rickyngk / Entities.java
Created January 15, 2016 17:40
EntityX exmaples
public class Person extends EntityX {
public Person() {super();}
@BindField("username") String name;
@BindField("age") int age;
@BindField("address") Address userAddress;
@BindField("wishListItems") ArrayList<int> wishList;
@BindField("phones") ArrayList<Phone> phones;
}
@rickyngk
rickyngk / EntityX.java
Last active January 15, 2016 17:33
Entity X import JSON
public void importFromJson(JSONObject input) throws Exception{
for (Field field : this.getClass().getDeclaredFields()) {
String fieldName = field.getName();
if (fields.containsKey(fieldName)) {
field.setAccessible(true);
EntityMetaData t = fields.get(fieldName);
if (input.has(t.key)) {
if (t.isArray) {
JSONArray array = null;
try {
@rickyngk
rickyngk / EntityX.java
Last active January 15, 2016 17:22
EntityX export json
public JSONObject exportToJson() throws Exception{
JSONObject outputJsonObject = new JSONObject();
for (Field field : this.getClass().getDeclaredFields()) {
String fieldName = field.getName();
if (fields.containsKey(fieldName)) {
field.setAccessible(true);
EntityMetaData t = fields.get(fieldName);
Object fieldValue = field.get(this);
if (fieldValue != null) {
@rickyngk
rickyngk / EntityX.java
Last active January 15, 2016 17:20
EntityX annotations mapping
public abstract class EntityX {
static class EntityMetaData {
String key;
Class entityType;
Class<?> collectionType;
boolean isArray = false;
boolean isDerivedFromEntity;
EntityMetaData(String key, Class entityType, Class collectionType) {
this.key = key;
this.entityType = entityType;
@rickyngk
rickyngk / LauncherActivity.java
Created December 29, 2015 04:19
Fullscreen Activity
public class LauncherActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
hideSystemUI();
setContentView(R.layout.activity_launcher);
}
private void hideSystemUI() {