<file_sep>package com.dreampany.frame.data.util;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;

import com.dreampany.frame.data.model.Color;
import com.dreampany.frame.ui.activity.BaseActivity;

public class BarUtil {

    public static void hide(Activity activity) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
            activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        } else {
            View decorView = activity.getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);
        }

        //hideToolbar(activity);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public static void setStatusColor(Activity activity, Color color) {
        Window window = activity.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            window.setStatusBarColor(ColorUtil.getColor(activity, color.getColorPrimaryDarkId()));
        }
        // window.set(activity.getResources().getColor(R.color.example_color));
    }

    public static void setStatusColor(BaseActivity activity, Color color) {
        setStatusColor((Activity) activity, color);
    }


    private static int backupStatusColor;

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public static void backupStatusColor(Activity activity) {
        Window window = activity.getWindow();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            backupStatusColor = window.getStatusBarColor();
        }
    }


    public static void backupStatusColor(BaseActivity activity) {
        backupStatusColor((Activity) activity);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public static void restoreStatusColor(Activity activity) {
        Window window = activity.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            window.setStatusBarColor(backupStatusColor);
        }
    }

    public static void setActionBarColor(Toolbar toolbar, Color color) {
        if (toolbar != null) {
            toolbar.setBackgroundColor(ColorUtil.getColor(toolbar.getContext(), color.getColorPrimaryId()));
        }
    }


    public static void showToolbar(Activity activity) {
        if (BaseActivity.class.isInstance(activity)) {
           // showToolbar((BaseActivity) activity);
        }
    }

    public static void showToolbar(Toolbar toolbar) {
        if (toolbar != null) {
            toolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2));
        }
        //  mFabButton.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).startUi();
    }

    public static void hideToolbar(Activity activity) {
        if (BaseActivity.class.isInstance(activity)) {
           // hideToolbar((BaseActivity) activity);
        }
    }

    public static void hideToolbar(Toolbar toolbar) {
        if (toolbar != null) {
            toolbar.animate().translationY(-toolbar.getHeight()).setInterpolator(new AccelerateInterpolator(2));
        }
        //mToolbar.animate().translationY(-mToolbar.getHeight()).setInterpolator(new AccelerateInterpolator(2));

        // FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mFabButton.getLayoutParams();
        // int fabBottomMargin = lp.bottomMargin;
        // mFabButton.animate().translationY(mFabButton.getHeight()+fabBottomMargin).setInterpolator(new AccelerateInterpolator(2)).startUi();
    }
}
<file_sep>package com.dreampany.frame.data.callback;

import com.dreampany.frame.data.event.NetworkEvent;

/**
 * Created by nuc on 6/11/2017.
 */

public interface NetworkCallback {
    void onInternet(boolean internet);
    void onNetworkEvent(NetworkEvent event);
}
<file_sep>package com.dreampany.frame.data.event;

import com.dreampany.frame.data.enums.NetworkStatus;

/**
 * Created by nuc on 6/11/2017.
 */

public class NetworkEvent {
    protected final NetworkStatus networkStatus;

    protected NetworkEvent(NetworkStatus networkStatus) {
        this.networkStatus = networkStatus;
    }

    public NetworkStatus getNetworkStatus() {
        return networkStatus;
    }
}
<file_sep>package com.dreampany.frame.data.manager;

import com.dreampany.frame.data.thread.Runner;

/**
 * Created by nuc on 5/20/2017.
 */

public abstract class Manager extends Runner {

    protected volatile boolean started;

    public void start() {
        super.start();
    }

    public void stop() {
        super.stop();
    }

    @Override
    public void run() {
        super.run();
    }
}
<file_sep>package com.dreampany.frame.data.model;

import android.os.Parcel;
import android.os.Parcelable;

import com.dreampany.frame.data.enums.Type;
import com.dreampany.frame.data.enums.SQLiteQueryType;
import com.dreampany.frame.data.enums.SQLiteSelectionType;

import java.lang.reflect.Field;

/**
 * Created by nuc on 12/3/2016.
 */

public class SQLiteTask<T extends Base, X extends Type> extends Task<T, X> {

    private long hash;
    private int count;
    private SQLiteQueryType queryType;
    private SQLiteSelectionType selectionType;

    public SQLiteTask() {
    }

    public SQLiteTask(T item) {
        super(item);
    }

    protected SQLiteTask(Parcel in) {
        super(in);
        hash = in.readLong();
        count = in.readInt();
        queryType = in.readParcelable(SQLiteQueryType.class.getClassLoader());
        selectionType = in.readParcelable(SQLiteSelectionType.class.getClassLoader());
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeLong(hash);
        dest.writeInt(count);
        dest.writeParcelable(queryType, flags);
        dest.writeParcelable(selectionType, flags);
    }

    public static final Parcelable.Creator<SQLiteTask> CREATOR = new Parcelable.Creator<SQLiteTask>() {
        @Override
        public SQLiteTask createFromParcel(Parcel in) {
            return new SQLiteTask(in);
        }

        @Override
        public SQLiteTask[] newArray(int size) {
            return new SQLiteTask[size];
        }
    };

    public void setHash(long hash) {
        this.hash = hash;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public void setQueryType(SQLiteQueryType queryType) {
        this.queryType = queryType;
    }

    public void setSelectionType(SQLiteSelectionType selectionType) {
        this.selectionType = selectionType;
    }

    public long getHash() {
        return hash;
    }

    public long getCount() {
        return count;
    }

    public SQLiteQueryType getQueryType() {
        return queryType;
    }

    public SQLiteSelectionType getSelectionType() {
        return selectionType;
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        String newLine = System.getProperty("line.separator");

        result.append(this.getClass().getName());
        result.append(" Object {");
        result.append(newLine);

        //determine fields declared in this class only (no fields of superclass)
        Field[] fields = this.getClass().getDeclaredFields();

        //print field names paired with their values
        for (Field field : fields) {
            result.append("  ");
            try {
                result.append(field.getName());
                result.append(": ");
                //requires access to private field:
                result.append(field.get(this));
            } catch (IllegalAccessException ex) {
                //System.out.println(ex);
                ex.printStackTrace();
            }
            result.append(newLine);
        }
        result.append("}");

        return result.toString();
    }
}
<file_sep>package com.dreampany.frame.ui.activity;

import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.view.MenuItem;

/**
 * Created by nuc on 2/13/2017.
 */

public abstract class BaseBottomNavigationActivity extends BaseMenuActivity implements BottomNavigationView.OnNavigationItemSelectedListener {

    protected int currentNavId;

    @Override
    protected void startUi(boolean fullScreen) {
        super.startUi(fullScreen);

        final BottomNavigationView bottomNavigationView = getBottomNavigationView();
        if (bottomNavigationView != null) {
            bottomNavigationView.setOnNavigationItemSelectedListener(this);
        }
    }

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        int targetNavId = item.getItemId();
        if (targetNavId != currentNavId) {
            onNavigationItem(targetNavId);
            currentNavId = targetNavId;
            return true;
        }
        return false;
    }

    protected int getBottomNavigationViewId() {
        return 0;
    }

    protected BottomNavigationView getBottomNavigationView() {
        return (BottomNavigationView) findViewById(getBottomNavigationViewId());
    }

    protected void onNavigationItem(int navItemId) {
    }
}
<file_sep>package com.dreampany.frame.data.provider.pref;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

/**
 * Created by nuc on 1/12/2017.
 */

public abstract class BasePref {

    protected int getMode() {
        return Context.MODE_PRIVATE;
    }

    protected String getPrefName() {
        return context.getPackageName();
    }

    protected void release() {
        context = null;
        publicPref = null;
        privatePref = null;
    }

    protected Context context;
    private SharedPreferences publicPref;
    private SharedPreferences privatePref;

    protected BasePref(Context context) {
        this.context = context.getApplicationContext();
        publicPref = PreferenceManager.getDefaultSharedPreferences(context);
        privatePref = this.context.getSharedPreferences(getPrefName(), getMode());
    }

    public void setPublicValue(String key, String value) {
        SharedPreferences.Editor editor = publicPref.edit();
        editor.putString(key, value);
        editor.apply();
    }

    public void setPublicValue(String key, boolean value) {
        SharedPreferences.Editor editor = publicPref.edit();
        editor.putBoolean(key, value);
        editor.apply();
    }

    public void setPrivateValue(String key, String value) {
        SharedPreferences.Editor editor = privatePref.edit();
        editor.putString(key, value);
        editor.apply();
    }

    public void setPrivateValue(String key, int value) {
        SharedPreferences.Editor editor = privatePref.edit();
        editor.putInt(key, value);
        editor.apply();
    }

    public void setPrivateValue(String key, long value) {
        SharedPreferences.Editor editor = privatePref.edit();
        editor.putLong(key, value);
        editor.apply();
    }

    public void setPrivateValue(String key, boolean value) {
        SharedPreferences.Editor editor = privatePref.edit();
        editor.putBoolean(key, value);
        editor.apply();
    }

    public String getPublicString(String key, String defaultValue) {
        return publicPref.getString(key, defaultValue);
    }

    public String getPrivateString(String key, String defaultValue) {
        return privatePref.getString(key, defaultValue);
    }

    public int getPrivateInt(String key, int defaultValue) {
        return privatePref.getInt(key, defaultValue);
    }

    public long getPrivateLong(String key, long defaultValue) {
        return privatePref.getLong(key, defaultValue);
    }

    public boolean getPrivateBoolean(String key, boolean defaultValue) {
        return privatePref.getBoolean(key, defaultValue);
    }

    public boolean getPublicBoolean(String key, boolean defaultValue) {
        return publicPref.getBoolean(key, defaultValue);
    }

}
<file_sep>package com.dreampany.frame.data.manager;

import android.support.annotation.NonNull;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseError;
import com.dreampany.frame.data.connection.FirebaseConnection;
import com.dreampany.frame.data.model.FirebaseLock;
import com.dreampany.frame.data.util.Constant;
import com.dreampany.frame.data.util.DataUtil;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/**
 * Created by nuc on 4/7/2016.
 */
public final class FirebaseManager {

    private final FirebaseLock<?, DatabaseError, FirebaseAuth> firebaseLock = new FirebaseLock<>();

    private static FirebaseManager firebaseManager;
    private FirebaseConnection firebaseConnection;

    private FirebaseManager() {
        firebaseConnection = new FirebaseConnection<>();
    }

    synchronized public static FirebaseManager onManager() {
        if (firebaseManager == null) {
            firebaseManager = new FirebaseManager();
        }
        return firebaseManager;
    }


    public FirebaseUser toUser() {
        return FirebaseAuth.getInstance().getCurrentUser();
    }

    public String toUid() {
        FirebaseUser user = toUser();
        if (user != null) {
            return user.getUid();
        }
        return null;
    }

    public boolean isAuthenticated() {
        return toUser() != null;
    }

    public String getUid() {
        FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
        if (user != null) {
            user.getUid();
        }
        return null;
    }

    public boolean signInAnonymously() {

        if (FirebaseManager.onManager().isAuthenticated()) return true;

        FirebaseAuth.getInstance().signInAnonymously()
                .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        notifyWaiting();
                    }
                });
        waiting();

        return FirebaseManager.onManager().isAuthenticated();
    }

    public void signOut() {
        FirebaseAuth.getInstance().signOut();
    }

    private void waiting() {
        synchronized (firebaseLock) {
            try {
                firebaseLock.wait(Constant.HALF_MINUTE);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    private void notifyWaiting() {
        synchronized (firebaseLock) {
            firebaseLock.notify();
        }
    }

    interface Key {
        String data = "data";
        String all = "all";
    }

    private <T> String toName(T t) {
        return toName(t.getClass());
    }

    private <T> String toName(Class<T> tClass) {
        return tClass.getSimpleName().toLowerCase(Locale.getDefault());
    }

    private <T> Long toHash(T t) {
        try {
            final Method getHashMethod = t.getClass().getMethod("getHash");
            AccessController.doPrivileged(new PrivilegedAction() {
                public Object run() {
                    getHashMethod.setAccessible(true);
                    return null; // nothing to return
                }
            });
            Long hash = (Long) getHashMethod.invoke(t);
            return hash;
        } catch (SecurityException | InvocationTargetException | NoSuchMethodException | IllegalArgumentException | IllegalAccessException e) {
            e.printStackTrace();
        }

        return null;
    }

    public <T> T write(T t, String childPath) {

        if (t == null) return null;

        String parentPath = Key.data + "/" + toName(t) + "/" + Key.all;
        if (!DataUtil.isEmpty(childPath)) {
            parentPath += "/" + childPath;
        }

        String hash = String.valueOf(toHash(t));

        T result = (T) firebaseConnection.addToFirebase(t, parentPath, hash);

        return result;
    }

    public <T> T write(T t) {
        if (t == null) return null;
        String parentPath = Key.data + "/" + toName(t);
        String hash = String.valueOf(toHash(t));
        T result = (T) firebaseConnection.addToFirebase(t, parentPath, hash);
        return result;
    }

    public <T> List<T> write(List<T> ts) {

        if (ts == null || ts.isEmpty()) return null;

        List<T> results = new ArrayList<>();

        for (T t : ts) {
            String parentPath = Key.data + "/" + toName(t) + "/" + Key.all;
            String childPath = String.valueOf(toHash(t));
            T result = (T) firebaseConnection.addToFirebase(t, parentPath, childPath);
            results.add(result);
        }

        return results;
    }

    public <T> List<T> read(Class<T> tClass, String childPath, long atTimestamp, int howMuch) {
        String parentPath = Key.data + "/" + toName(tClass) + "/" + Key.all + "/" + childPath;
        return firebaseConnection.takeFromFirebase(tClass, parentPath, atTimestamp, howMuch);
    }

    public <T> List<T> read(Class<T> tClass, String childPath, String orderBy, long equalTo) {
        String parentPath = Key.data + "/" + toName(tClass) + "/" + Key.all;
        if (!DataUtil.isEmpty(childPath)) {
            parentPath += "/" + childPath;
        }
        return firebaseConnection.takeFromFirebase(tClass, parentPath, orderBy, equalTo);
    }

    public <T> List<T> read(Class<T> tClass, String orderBy, long equalTo) {
        String parentPath = Key.data + "/" + toName(tClass);
        return firebaseConnection.takeFromFirebase(tClass, parentPath, orderBy, equalTo);
    }
}
<file_sep>package com.dreampany.frame.data.enums;

/**
 * Created by air on 6/27/17.
 */

public enum ApState {
    WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_ENABLING, WIFI_AP_STATE_ENABLED, WIFI_AP_STATE_FAILED
}
<file_sep>package com.dreampany.frame.data.model;

import android.os.Parcel;

import com.dreampany.frame.data.enums.Type;

/**
 * Created by nuc on 12/21/2016.
 */

public class UiTask<T extends Base> extends Task<T, Type> {

    public UiTask() {
    }

    public UiTask(T item) {
        super(item);
    }

    public UiTask(T item, Type itemType) {
        super(item);
        setItemType(itemType);
    }

    private UiTask(Parcel in) {
        super(in);
    }

    public static final Creator<UiTask> CREATOR = new Creator<UiTask>() {
        @Override
        public UiTask createFromParcel(Parcel in) {
            return new UiTask(in);
        }

        @Override
        public UiTask[] newArray(int size) {
            return new UiTask[size];
        }
    };
}
<file_sep>package com.dreampany.frame.data.manager;

import android.content.Context;
import android.content.Intent;

import com.dreampany.frame.data.receiver.InternetReceiver;
import com.dreampany.frame.data.util.NetworkUtil;

import java.io.IOException;

public class InternetManager {

    private static final String DEFAULT_PING_HOST = "www.google.com";
    private static final int DEFAULT_PING_PORT = 80;
    private static final int DEFAULT_PING_TIMEOUT_IN_MS = 2000;

    private final Context context;
    private String pingHost;
    private int pingPort;
    private int pingTimeout;
    private boolean hasInternet;

    public InternetManager(Context context) {
        this.context = context;
        this.pingHost = DEFAULT_PING_HOST;
        this.pingPort = DEFAULT_PING_PORT;
        this.pingTimeout = DEFAULT_PING_TIMEOUT_IN_MS;
    }

    public void check() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    hasInternet = NetworkUtil.hasInternet(pingHost, pingPort, pingTimeout);
                } catch (IOException e) {
                    hasInternet = false;
                } finally {
                    sendBroadcast(hasInternet);
                }
            }
        }).start();
    }

    public void setPingParameters(String host, int port, int timeoutInMs) {
        this.pingHost = host;
        this.pingPort = port;
        this.pingTimeout = timeoutInMs;
    }

    public boolean hasInternet() {
        return hasInternet;
    }

    private void sendBroadcast(boolean hasInternet) {
        Intent intent = new Intent(InternetReceiver.INTENT);
        intent.putExtra(InternetReceiver.INTENT_EXTRA, hasInternet);
        context.sendBroadcast(intent);
    }

}<file_sep>package com.dreampany.frame.data.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.os.Looper;

import com.dreampany.frame.data.callback.NetworkCallback;
import com.dreampany.frame.data.manager.NetworkManager;
import com.dreampany.frame.data.util.AndroidUtil;
import com.dreampany.frame.data.enums.NetworkStatus;
import com.dreampany.frame.data.event.ConnectivityChanged;
import com.dreampany.frame.data.event.NetworkEvent;

public abstract class BaseReceiver extends BroadcastReceiver {
    private final Context context;
    private NetworkCallback callback;

    public BaseReceiver(Context context, NetworkCallback callback) {
        this.context = context;
        this.callback = callback;
    }

    protected boolean hasChanged(NetworkStatus networkStatus) {
        return NetworkManager.networkStatus != networkStatus;
    }

    protected void postStatus(NetworkStatus networkStatus) {
        NetworkManager.networkStatus = networkStatus;
        post(new ConnectivityChanged(context, networkStatus));
    }

    protected void post(final NetworkEvent event) {
        if (Looper.myLooper() == Looper.getMainLooper()) {
            callback.onNetworkEvent(event);
        } else {
            AndroidUtil.post(new Runnable() {
                @Override
                public void run() {
                    callback.onNetworkEvent(event);
                }
            });
        }
    }
}<file_sep>package com.dreampany.frame.data.enums;

import android.os.Parcelable;

public interface Type extends Parcelable {
    boolean equals(Type type);

    String value();

    int ordinalValue();
}<file_sep>package com.dreampany.frame.data.util;


import android.content.Context;
import android.os.Looper;
import android.widget.Toast;

public final class NotifyUtil {
    private NotifyUtil() {
    }

    public static void longToast(Context context, String text) {
        Toast.makeText(context, text, Toast.LENGTH_LONG).show();
    }

    public static void shortToast(Context context, String text) {
        Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
    }

    public static void toast(Context context, final String text) {
        toast(context, text, Toast.LENGTH_SHORT);
    }

    public static void toast(final Context context, final String text, final int duration) {
        if (Thread.currentThread() == Looper.getMainLooper().getThread()) {
            Toast.makeText(context, text, duration).show();
        } else {
            AndroidUtil.getHandler().post(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(context, text, duration).show();
                }
            });
        }
    }
}
<file_sep>package com.dreampany.frame.ui.activity;

import android.view.Menu;
import android.view.MenuItem;

/**
 * Created by nuc on 8/9/2016.
 */
public abstract class BaseMenuActivity extends BaseActivity {

    private final int defaultMenuResourceId = 0;
    private int menuResourceId = defaultMenuResourceId;

    public int getMenuResourceId() {
        return menuResourceId;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        if (getMenuResourceId() <= defaultMenuResourceId) {
            menu.clear();
        } else {
            getMenuInflater().inflate(getMenuResourceId(), menu);
        }
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }


    public void optionMenu(int menuResourceId) {
        this.menuResourceId = menuResourceId;
        supportInvalidateOptionsMenu();
    }
}
<file_sep>package com.dreampany.frame.data.model;

import android.os.Parcel;

import com.google.common.primitives.Longs;
import com.google.firebase.database.Exclude;
import com.dreampany.frame.data.util.DataUtil;

import java.lang.reflect.Field;

/**
 * Created by nuc on 12/6/2015.
 */
public abstract class Base extends BaseParcel {

    private long id;
    private long time;
    private long hash;

    protected Base() {
    }

    protected Base(Parcel in) {
        id = in.readLong();
        time = in.readLong();
        hash = in.readLong();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(id);
        dest.writeLong(time);
        dest.writeLong(hash);
    }

    @Override
    public boolean equals(Object inObject) {

        if (this == inObject) {
            return true;
        }

        if (!Base.class.isInstance(inObject)) {
            return false;
        }

        Base base = (Base) inObject;
        return hash == base.hash;
    }

    @Override
    public int hashCode() {
        int hashCode = Longs.hashCode(hash);
        return hashCode;
    }

    @Exclude
    public long getId() {
        return this.id;
    }

    @Exclude
    public long getTime() {
        return this.time;
    }

    public long getHash() {
        return hash;
    }

    public Base setId(long id) {
        this.id = id;
        return this;
    }

    public Base setTime(long time) {
        this.time = time;
        return this;
    }

    public Base setHash(long hash) {
        this.hash = hash;
        return this;
    }

    protected String toString(Object object) {
        StringBuilder result = new StringBuilder();
        String newLine = System.getProperty("line.separator");

        result.append(object.getClass().getName());
        result.append(" Object {");
        result.append(newLine);

        //determine fields declared in this class only (no fields of superclass)
        Field[] fields = object.getClass().getDeclaredFields();

        //print field names paired with their values
        for (Field field : fields) {
            result.append("  ");
            try {
                result.append(field.getName());
                result.append(": ");
                //requires access to private field:
                result.append(field.get(object));
            } catch (IllegalAccessException ex) {
                System.out.println(ex);
            }
            result.append(newLine);
        }
        result.append("}");

        return result.toString();
    }

    public void createHash() {
        hash = DataUtil.getSha256();
    }

}
<file_sep>package com.dreampany.frame.data.model;

import android.content.Context;
import android.os.Parcel;

import com.google.common.primitives.Longs;
import com.dreampany.frame.data.enums.Type;
import com.dreampany.frame.data.enums.Processor;

/**
 * Created by nuc on 11/3/2016.
 */

public abstract class Task<T extends BaseParcel, X extends Type> extends BaseParcel {

    protected long id;
    protected T item;
    protected X itemType;
    protected X itemSource;
    protected X taskType;
    protected X density;
    protected X priority;
    protected X status;
    protected Processor processor;
    protected Context context;

    protected Task() {
    }

    protected Task(T item) {
        this.item = item;
    }

    protected Task(X taskType) {
        this.taskType = taskType;
    }

    protected Task(Parcel in) {
        super(in);
        id = in.readLong();
        if (in.readByte() == 0) {
            item = null;
        } else {
            Class<?> itemClazz = (Class<?>) in.readSerializable();
            item = in.readParcelable(itemClazz.getClassLoader());
        }
        itemType = in.readParcelable(Type.class.getClassLoader());
        itemSource = in.readParcelable(Type.class.getClassLoader());
        taskType = in.readParcelable(Type.class.getClassLoader());
        density = in.readParcelable(Type.class.getClassLoader());
        priority = in.readParcelable(Type.class.getClassLoader());
        status = in.readParcelable(Type.class.getClassLoader());
        processor = in.readParcelable(Processor.class.getClassLoader());
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeLong(id);
        if (item == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            Class<?> itemClazz = item.getClass();
            dest.writeSerializable(itemClazz);
            dest.writeParcelable(item, flags);
        }
        dest.writeParcelable(itemType, flags);
        dest.writeParcelable(itemSource, flags);
        dest.writeParcelable(taskType, flags);
        dest.writeParcelable(density, flags);
        dest.writeParcelable(priority, flags);
        dest.writeParcelable(status, flags);
        dest.writeParcelable(processor, flags);
    }

    @Override
    public boolean equals(Object inObject) {
        if (this == inObject) {
            return true;
        }

        if (!Task.class.isInstance(inObject)) {
            return false;
        }

        Task item = (Task) inObject;
        return id == item.id;
    }

    @Override
    public int hashCode() {
        return Longs.hashCode(id);
    }

    @Override
    protected Task<T, X> clone() throws CloneNotSupportedException {
        return (Task<T, X>) super.clone();
    }

    public Task<T, X> setId(long id) {
        this.id = id;
        return this;
    }

    public Task<T, X> setItem(T item) {
        this.item = item;
        return this;
    }

    public Task<T, X> setItemType(X itemType) {
        this.itemType = itemType;
        return this;
    }

    public Task<T, X> setItemSource(X itemSource) {
        this.itemSource = itemSource;
        return this;
    }

    public Task<T, X> setTaskType(X taskType) {
        this.taskType = taskType;
        return this;
    }

    public Task<T, X> setDensity(X density) {
        this.density = density;
        return this;
    }

    public Task<T, X> setPriority(X priority) {
        this.priority = priority;
        return this;
    }

    public Task<T, X> setStatus(X status) {
        this.status = status;
        return this;
    }

    public Task<T, X> setProcessor(Processor processor) {
        this.processor = processor;
        return this;
    }

    public Task<T, X> setContext(Context context) {
        this.context = context.getApplicationContext();
        return this;
    }

    public long getId() {
        return id;
    }

    public T getItem() {
        return item;
    }

    public X getItemType() {
        return itemType;
    }

    public X getItemSource() {
        return itemSource;
    }

    public X getTaskType() {
        return taskType;
    }

    public X getDensity() {
        return density;
    }

    public X getPriority() {
        return priority;
    }

    public X getStatus() {
        return status;
    }

    public Processor getProcessor() {
        return processor;
    }

    public Context getContext() {
        return context;
    }

    public void process() {
        processor.process(this);
    }
}
<file_sep>package com.dreampany.frame.data.enums;

import android.os.Parcel;


/**
 * Created by nuc on 12/3/2016.
 */

public enum TaskStatus implements Type {

    FAIL, SUCCESS;

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(ordinal());
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<TaskStatus> CREATOR = new Creator<TaskStatus>() {

        public TaskStatus createFromParcel(Parcel in) {
            return TaskStatus.values()[in.readInt()];
        }

        public TaskStatus[] newArray(int size) {
            return new TaskStatus[size];
        }

    };

    @Override
    public boolean equals(Type status) {
        return this == status && status instanceof TaskStatus && compareTo((TaskStatus) status) == 0;
    }
    @Override
    public int ordinalValue() {
        return ordinal();
    }
    @Override
    public String value() {
        return name();
    }
}
<file_sep>package com.dreampany.frame.data.adapter;

import android.app.Fragment;
import android.app.FragmentManager;

public class FragmentAdapter<T extends Fragment> extends BaseFragmentAdapter<T> {

    private FragmentAdapter(FragmentManager fragmentManager) {
        super(fragmentManager);
    }

    public static FragmentAdapter<?> newAdapter(FragmentManager fragmentManager) {
        return new FragmentAdapter<>(fragmentManager);
    }

    @Override
    public Fragment getItem(int position) {
        return newFragment(position);
    }
}
<file_sep>apply plugin: 'com.android.library'
apply plugin: 'idea'

android {
    compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
    buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
        targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
        versionCode 1
        versionName "0.0.1"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled true
    }
}

configurations.all {
    exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'

    //android
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:design:26.0.0-alpha1'
    compile 'com.android.support:support-v4:26.0.0-alpha1'
    compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
    compile 'com.android.support:cardview-v7:26.0.0-alpha1'
    compile 'com.android.support:preference-v7:26.0.0-alpha1'
    compile 'com.android.support:support-v13:26.0.0-alpha1'
    compile 'com.android.support:preference-v14:26.0.0-alpha1'
    compile 'com.android.support:support-vector-drawable:26.0.0-alpha1'
    compile 'com.android.support:animated-vector-drawable:26.0.0-alpha1'

    //google
    compile 'com.google.firebase:firebase-core:11.0.4'
    compile 'com.google.firebase:firebase-auth:11.0.4'
    compile 'com.google.firebase:firebase-ads:11.0.4'
    compile 'com.google.firebase:firebase-database:11.0.4'
    compile 'com.google.firebase:firebase-storage:11.0.4'
    compile 'com.google.firebase:firebase-crash:11.0.4'
    compile 'com.google.firebase:firebase-appindexing:11.0.4'
    compile 'com.google.android.gms:play-services-location:11.0.4'
    //compile 'com.google.android.gms:play-services-ads:11.0.4'
    compile 'com.google.guava:guava:23.0-android'
    compile 'com.google.code.gson:gson:2.8.1'
    compile 'com.google.protobuf:protobuf-java:3.3.0'

    //firebase
    //compile 'com.firebaseui:firebase-ui:1.0.1'

    //facebook
    compile 'com.facebook.android:facebook-android-sdk:4.18.0'
    compile 'com.facebook.fresco:fresco:1.3.0'
    compile 'com.facebook.network.connectionclass:connectionclass:1.0.1'
    compile 'com.facebook.shimmer:shimmer:0.1.0@aar'

    //twitter
    //compile 'com.twitter.sdk.android:twitter:2.2.0'

    //squareup
    compile 'com.squareup.okhttp3:okhttp:3.9.0'
    compile 'com.squareup.okio:okio:1.13.0'

    // apache
    //compile 'commons-codec:commons-codec:1.10'
    //compile 'org.apache.httpcomponents:httpclient:4.5.2'
    //compile 'org.apache.httpcomponents:httpmime:4.5.2'
    compile 'org.apache.commons:commons-lang3:3.6'

    //rx
    compile 'io.reactivex.rxjava2:rxjava:2.1.3'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'

    //util
    compile 'org.greenrobot:essentials:3.0.0-RC1'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'joda-time:joda-time:2.9.9'
    //compile 'com.wordnik:wordnik-android-client:4.0'
    compile 'com.memetix:microsoft-translator-java-api:0.6.2'
    compile 'com.kbeanie:multipicker:1.1.3@aar'
    compile 'com.karumi:dexter:4.1.0'
    compile 'com.jaredrummler:android-device-names:1.1.2'
    compile 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.0.0'
    compile 'com.sromku:simple-storage:1.2.0'
    compile 'org.kocakosm:pitaya:0.4'
    compile 'org.nibor.autolink:autolink:0.6.0'
    compile 'com.luffykou:android-common-utils:1.1.3'
    compile 'cn.trinea.android.common:trinea-android-common:4.2.15'
    compile 'com.sromku:simple-storage:1.2.0'
    compile 'io.netty:netty-buffer:4.1.0.Beta5'
    compile 'cc.mvdan.accesspoint:library:0.2.0'
    compile 'com.kbeanie:multipicker:1.1.31@aar'
    compile 'com.einmalfel:earl:1.1.0'
    compile 'com.github.pwittchen:prefser-rx2:2.1.0'
    //compile 'com.github.nisrulz:android-utils:1.0.3'
    // compile 'net.the4thdimension:android-utils:2.0.4'

    //ui library
    compile 'eu.davidea:flipview:1.1.1'
    compile 'eu.davidea:flexible-adapter:5.0.0-rc2'
    compile 'eu.davidea:flexible-adapter-databinding:1.0.0-b1@aar'
    compile 'com.daasuu:CountAnimationTextView:0.1.1'
    compile 'com.gordonwong:material-sheet-fab:1.2.1'
    compile 'com.ms-square:expandableTextView:0.1.4'
    compile 'net.cachapa.expandablelayout:expandablelayout:2.8'
    compile 'com.flyco.roundview:FlycoRoundView_Lib:1.1.4@aar'
    compile 'com.wang.avi:library:2.1.3'
    compile 'com.daimajia.swipelayout:library:1.2.0@aar'
    compile 'com.vstechlab.easyfonts:easyfonts:1.0.0'
    compile 'com.dev.sacot41:scviewpager:0.0.4'
    compile 'com.roughike:swipe-selector:1.0.6'
    compile 'com.roughike:bottom-bar:2.3.1'
    compile 'com.github.medyo:fancybuttons:1.8.3'
    compile 'id.arieridwan:pageloader:0.0.2'
    compile 'com.github.iammert:StatusView:1.3'
    compile 'com.github.gturedi:stateful-layout:1.2.1'
    //compile 'com.github.traex.rippleeffect:library:1.3'
    compile 'me.zhanghai.android.materialprogressbar:library:1.4.1'
    compile 'com.github.bassaer:chatmessageview:1.3.3'
    compile 'me.himanshusoni.chatmessageview:chat-message-view:1.0.7'
    compile 'com.github.jinatonic.confetti:confetti:1.1.0'
    compile 'com.github.apl-devs:appintro:v4.2.2'
    compile 'com.github.jakob-grabner:Circle-Progress-View:v1.3'
    // compile 'com.github.Hitta:RippleEffect:82cf00e551' //AndroidRuntime: java.lang.IllegalStateException: Underflow in restore - more restores than saves

    //maven

    //compile 'com.github.linger1216:labelview:v1.1.1'

    //compile 'com.github.shts:TriangleLabelView:1.1.2'

    // compile 'org.slf4j:slf4j-android:1.7.22'

    // compile 'io.netty:netty-buffer:5.0.0.Alpha2'

    // compile 'com.google.protobuf:protobuf-java:2.6.1'
    //  compile project(':swipe-selector')
}

//apply plugin: 'com.google.gms.google-services'

idea {
    module {
        downloadJavadoc = true
    }
}

<file_sep>package com.dreampany.frame.data.util;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Fragment;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v7.app.AppCompatActivity;

import com.dreampany.frame.data.enums.Type;
import com.dreampany.frame.data.model.Base;
import com.dreampany.frame.data.model.Task;

/**
 * Created by nuc on 4/12/2016.
 */
public final class FragmentUtil {
    private FragmentUtil() {
    }

    public static Fragment getFragmentById(Activity activity, int fragmentId) {
        return activity.getFragmentManager().findFragmentById(fragmentId);
    }

    public static <T extends Fragment> T getFragmentByTag(Activity activity, String fragmentTag) {
        return (T) activity.getFragmentManager().findFragmentByTag(fragmentTag);
    }

    public static <T extends android.support.v4.app.Fragment> T getSupportFragmentByTag(AppCompatActivity activity, String fragmentTag) {
        return (T) activity.getSupportFragmentManager().findFragmentByTag(fragmentTag);
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    public static android.support.v4.app.Fragment getFragmentById(android.support.v4.app.Fragment fragment, int fragmentId) {
        return fragment.getChildFragmentManager().findFragmentById(fragmentId);
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    public static <F extends android.support.v4.app.Fragment> F getFragmentByTag(android.support.v4.app.Fragment fragment, String fragmentTag) {
        return (F) fragment.getChildFragmentManager().findFragmentByTag(fragmentTag);
    }

    public static <F extends Fragment> F newFragment(Class<F> fragmentClass) {
        try {
            return fragmentClass.newInstance();
        } catch (InstantiationException e) {
        } catch (IllegalAccessException e) {
        }
        return null;
    }

    public static <F extends android.support.v4.app.Fragment> F newSupportFragment(Class<F> fragmentClass) {
        try {
            return fragmentClass.newInstance();
        } catch (InstantiationException e) {
        } catch (IllegalAccessException e) {
        }
        return null;
    }


    public static <F extends Fragment, T extends Base, X extends Type> F getFragment(Activity activity, Class<F> fragmentClass, Task<T, X> task) {

        F fragment = getFragmentByTag(activity, fragmentClass.getName());

        if (fragment == null) {

            fragment = newFragment(fragmentClass);

            if (fragment != null && task != null) {
                Bundle bundle = new Bundle();
                bundle.putParcelable(Task.class.getName(), task);
                fragment.setArguments(bundle);
            }
        } else if (task != null) {
            fragment.getArguments().putParcelable(Task.class.getName(), task);
        }

        return fragment;
    }


    public static <F extends Fragment, T extends Parcelable> F getFragment(Activity activity, Class<F> fragmentClass) {

        F fragment = getFragmentByTag(activity, fragmentClass.getName());

        if (fragment == null) {
            fragment = newFragment(fragmentClass);
            LogKit.verbose("New Fragment " + fragment);
           /* if (fragment != null && config != null) {
                Bundle bundle = new Bundle();
                bundle.putParcelable(config.getClass().getName(), config);
                fragment.setArguments(bundle);
            }*/
        } /*else if (config != null) {
            fragment.getArguments().putParcelable(config.getClass().getName(), config);
        }*/

        return fragment;
    }

    public static <F extends android.support.v4.app.Fragment, T extends Parcelable> F getSupportFragment(AppCompatActivity activity, Class<F> fragmentClass, Task<?, ?> task) {

        F fragment = getSupportFragmentByTag(activity, fragmentClass.getName());

        if (fragment == null) {
            fragment = newSupportFragment(fragmentClass);
            LogKit.verbose("New Fragment " + fragment);
            if (fragment != null && task != null) {
                Bundle bundle = new Bundle();
                bundle.putParcelable(Task.class.getName(), task);
                fragment.setArguments(bundle);
            }
        } else if (task != null) {
            fragment.getArguments().putParcelable(Task.class.getName(), task);
        }

        return fragment;
    }

    public static <F extends android.support.v4.app.Fragment, T extends Parcelable> F getSupportFragment(android.support.v4.app.Fragment parent, Class<F> fragmentClass, Task<?, ?> task) {

        F fragment = getFragmentByTag(parent, fragmentClass.getName());

        if (fragment == null) {
            fragment = newSupportFragment(fragmentClass);
            LogKit.verbose("New Fragment " + fragment);
            if (fragment != null && task != null) {
                Bundle bundle = new Bundle();
                bundle.putParcelable(Task.class.getName(), task);
                fragment.setArguments(bundle);
            }
        } else if (task != null) {
            fragment.getArguments().putParcelable(Task.class.getName(), task);
        }

        return fragment;
    }

    public static <F extends Fragment, T extends Base> Fragment commitFragment(final Activity activity, final Class<F> fragmentClass, final Task<T, ?> task, final int parentLayoutId) {

        final Fragment fragment = getFragment(activity, fragmentClass, task);

        Runnable commitRunnable = new Runnable() {
            @Override
            public void run() {
                if (activity.isDestroyed() || activity.isFinishing()) {
                    return;
                }
                activity.getFragmentManager().
                        beginTransaction().
                        setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out).
                        replace(parentLayoutId, fragment, fragmentClass.getName()).
                        // addToBackStack(fragmentClass.getName()).
                                commitAllowingStateLoss();
            }
        };

        AndroidUtil.postDelay(commitRunnable);

        return fragment;
    }

    public static <F extends Fragment, T extends Parcelable> F commitFragment(final Activity activity, final Class<F> fragmentClass, final int parentId) {

        final F fragment = getFragment(activity, fragmentClass);

        Runnable commitRunnable = new Runnable() {
            @Override
            public void run() {
                if (activity.isDestroyed() || activity.isFinishing()) {
                    return;
                }
                activity.getFragmentManager().
                        beginTransaction().
                        setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out).
                        replace(parentId, fragment, fragmentClass.getName()).
                        commitAllowingStateLoss();
            }
        };

        AndroidUtil.postDelay(commitRunnable);

        return fragment;
    }

    public static <F extends android.support.v4.app.Fragment, T extends Parcelable> F commitFragmentCompat(final AppCompatActivity activity, final Class<F> fragmentClass, final int parentId) {

        final F fragment = getSupportFragment(activity, fragmentClass, null);

        Runnable commitRunnable = new Runnable() {
            @Override
            public void run() {
                if (activity.isDestroyed() || activity.isFinishing()) {
                    return;
                }
                activity.getSupportFragmentManager().
                        beginTransaction().
                        //setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out).
                                replace(parentId, fragment, fragmentClass.getName()).
                        commitAllowingStateLoss();
            }
        };

        AndroidUtil.postDelay(commitRunnable);

        return fragment;
    }

    public static <F extends android.support.v4.app.Fragment, T extends Parcelable> F commitFragmentCompat(final AppCompatActivity activity, final Class<F> fragmentClass, final int parentId, Task<?, ?> task) {

        final F fragment = getSupportFragment(activity, fragmentClass, task);

        Runnable commitRunnable = new Runnable() {
            @Override
            public void run() {
                if (activity.isDestroyed() || activity.isFinishing()) {
                    return;
                }
                activity.getSupportFragmentManager().
                        beginTransaction().
                        //setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out).
                                replace(parentId, fragment, fragmentClass.getName()).
                        commitAllowingStateLoss();
            }
        };

        AndroidUtil.postDelay(commitRunnable);

        return fragment;
    }

    public static <F extends android.support.v4.app.Fragment, T extends Parcelable> F commitFragmentCompat(final android.support.v4.app.Fragment parent, final Class<F> fragmentClass, final int parentId) {

        final F fragment = getSupportFragment(parent, fragmentClass, null);

        Runnable commitRunnable = new Runnable() {
            @Override
            public void run() {
                parent.getChildFragmentManager().
                        beginTransaction().
                        //setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out).
                                replace(parentId, fragment, fragmentClass.getName()).
                        commitAllowingStateLoss();
            }
        };

        AndroidUtil.post(commitRunnable, 500L); // need a good time to load parent fragment

        return fragment;
    }
}

<file_sep>package com.dreampany.frame.data.util;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

/**
 * Created by nuc on 1/18/2017.
 */

public final class JsonUtil {
    private JsonUtil() {}

    public static JsonObject getJsonObject(String json) {
        JsonParser parser = new JsonParser();
        return parser.parse(json).getAsJsonObject();
    }
}
<file_sep>package com.dreampany.frame.data.enums;

import android.os.Parcelable;

import com.dreampany.frame.data.model.Task;

public interface Processor extends Parcelable {
    void process(Task task);
}<file_sep>/*
package com.ringbyte.framekit.data.model;

import android.databinding.Bindable;
import android.os.Parcel;

import com.ringbyte.english.BR;

*/
/**
 * Created by nuc on 8/22/2015.
 *//*

public class Category extends Base {

    private String title;
    private long count;
    private boolean checked;

    public Category(String title) {
        this.title = title;
    }

    public Category(String title, boolean checked) {
        this.title = title;
        this.checked = checked;
    }

    protected Category(Parcel in) {
        super(in);
        title = in.readString();
        count = in.readLong();
        checked = in.readByte() != 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeString(title);
        dest.writeLong(count);
        dest.writeByte((byte) (checked ? 1 : 0));
    }

    public static final Creator<Category> CREATOR = new Creator<Category>() {
        @Override
        public Category createFromParcel(Parcel in) {
            return new Category(in);
        }

        @Override
        public Category[] newArray(int size) {
            return new Category[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    public Category setCategory(Category category) {
        setTitle(category.title);
        setCount(category.count);

        setChecked(category.checked);
        return this;
    }

    @Bindable
    public String getTitle() {
        return this.title;
    }

    @Bindable
    public long getCount() {
        return count;
    }

    @Bindable
    public boolean isChecked() {
        return checked;
    }

    public Category setTitle(String title) {
        this.title = title;
        notifyPropertyChanged(BR.title);
        return this;
    }

    public Category setCount(long count) {
        this.count = count;
        notifyPropertyChanged(BR.count);
        return this;
    }

    public Category setChecked(boolean checked) {
        this.checked = checked;
        notifyPropertyChanged(BR.checked);
        return this;
    }
}
*/
<file_sep>package com.dreampany.frame.data.manager;

import android.content.Context;

import com.dreampany.frame.data.enums.Type;
import com.dreampany.frame.data.model.Point;
import com.dreampany.frame.data.model.Session;
import com.dreampany.frame.data.provider.pref.FramePref;
import com.dreampany.frame.data.provider.sqlite.FrameSQLite;
import com.dreampany.frame.data.util.AndroidUtil;
import com.dreampany.frame.data.util.DataUtil;

/**
 * Created by air on 5/11/17.
 */

public final class PointManager {

    public static final long defaultThreshold = 100;
    public static final long defaultPoints = 1000L;
    private static final String usedPoints = "used_points";

    private static PointManager manager;
    private long threshold = defaultThreshold;

    private PointManager() {

    }

    public static synchronized PointManager onInstance() {
        if (manager == null) {
            manager = new PointManager();
        }
        return manager;
    }


    public long toPoints(long credits) {
        long points = credits / threshold;
        return points < 0L ? 0L : points;
    }

    public void trackPoints(Context context, Session session, Type pointType) {
        long credits = session.getSessionTime() / 1000; // seconds
        long points = toPoints(credits);

        Point point = new Point();
        point.setHash(session.getHash());
        point.setPoints(points);
        point.setType(pointType);

        FrameSQLite.onInstance(context).write(point);
    }

    public void trackPoints(Context context, long hash, long points, Type pointType) {
        Point point = new Point();
        point.setHash(hash);
        point.setPoints(points);
        point.setType(pointType);

        FrameSQLite.onInstance(context).write(point);
    }

    public long getAvailablePoints(Context context) {
        long totalPoints = FrameSQLite.onInstance(context).getPoints();
        long usedPoints = FramePref.onInstance(context).getLong(PointManager.usedPoints);
        return totalPoints - usedPoints;
    }

    public long getPoints(Context context, Type... types) {
        long points = 0L;
        for (Type type : types) {
            points += FrameSQLite.onInstance(context).getPoints(type);
        }
        return points;
    }

    public void dragDefaultPoints(Context context, Type pointType) {
        if (FrameSQLite.onInstance(context).isEmpty(pointType)) {
            String appId = AndroidUtil.getApplicationId(context);
            long hash = DataUtil.getSha256(appId);
            Point point = new Point();
            point.setHash(hash);
            point.setPoints(defaultPoints);
            point.setType(pointType);
            FrameSQLite.onInstance(context).write(point);
        }
    }
}
<file_sep>package com.dreampany.frame.data.thread;

public abstract class Runner implements Runnable {

    protected long defaultWait = 1000L;
    protected long superWait = 3 * defaultWait;
    protected long periodWait = 1000L / 100;
    protected long wait = defaultWait;

    private Thread thread;
    private boolean running;
    private final Object guard = new Object();
    private volatile boolean guarded;

    public void start() {
        if (running) {
            return;
        }
        running = true;
        thread = new Thread(this);
        thread.setDaemon(true);
        thread.start();
    }

    public void stop() {
        if (!running) {
            return;
        }
        running = false;
        thread.interrupt();
        notifyRunner();
    }

    public void waitRunner(long timeoutMs) {
        if (guarded) {
            //return;
        }
        guarded = true;
        synchronized (guard) {
            try {
                if (timeoutMs > 0L) {
                    guard.wait(timeoutMs);
                } else {
                    guard.wait();
                }
            } catch (InterruptedException e) {
            }
        }
    }

    public void notifyRunner() {
        if (!guarded) {
            //return;
        }
        guarded = false;
        synchronized (guard) {
            guard.notify();
        }
    }

    protected void silentStop() {
        if (running) {
            running = false;
        }
    }

    public boolean isRunning() {
        return running;
    }

    private void waitFor(long timeout) throws InterruptedException {
        Thread.sleep(timeout);
    }

    protected abstract boolean looping() throws InterruptedException;

    @Override
    public void run() {
        try {
            while (running) {
                boolean looped = looping();
                if (!looped) {
                    break;
                }
            }
        } catch (InterruptedException interrupt) {
        }
        running = false;
    }
}<file_sep>package com.dreampany.frame.data.util;

import android.Manifest;
import android.app.Activity;
import android.app.ActivityManager;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.hardware.display.DisplayManager;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Parcelable;
import android.os.PowerManager;
import android.provider.Settings;
import android.speech.tts.TextToSpeech;
import android.support.annotation.RequiresApi;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.util.Base64;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import com.google.common.hash.Hashing;
import com.jaredrummler.android.device.DeviceName;
import com.karumi.dexter.Dexter;
import com.karumi.dexter.listener.single.PermissionListener;
import com.dreampany.frame.data.manager.PermissionManager;
import com.dreampany.frame.data.model.Task;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

public final class AndroidUtil {
    private static final String TAG = AndroidUtil.class.getSimpleName();
    private static boolean debug = true;

    private AndroidUtil() {
    }

    public static void setDebug(Context context) {
        AndroidUtil.debug = isDebug(context);
    }

    public static final String WRITE_EXTERNAL_STORAGE = Manifest.permission.WRITE_EXTERNAL_STORAGE;

    public static boolean isMarshmallow() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
    }

    public static boolean isPermissionGranted(Context context, String permission) {
        return PermissionManager.isPermissionGranted(context, permission);
    }

    public static void requestPermission(Activity activity, String permission, PermissionListener permissionListener) {
        Dexter.withActivity(activity)
                .withPermission(permission)
                .withListener(permissionListener)
                .check();
    }

    public static boolean isDebug() {
        return debug;
        //return false;
    }

    public static boolean isDebug(Context context) {
        boolean debuggable = false;

        Context appContext = context.getApplicationContext();
        PackageManager pm = appContext.getPackageManager();
        try {
            ApplicationInfo appInfo = pm.getApplicationInfo(appContext.getPackageName(), 0);
            debuggable = (0 != (appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE));
        } catch (PackageManager.NameNotFoundException e) {
            /*debuggable variable will remain false*/
        }

        return debuggable;
    }


    public static boolean needThread(Thread thread) {
        return (thread == null || !thread.isAlive());
    }

    public static Thread createThread(Runnable runnable) {
        return new Thread(runnable);
    }

    public static Thread createThread(Runnable runnable, String name) {
        Thread thread = new Thread(runnable);
        thread.setName(name);
        thread.setDaemon(true);
        return thread;
    }

    public static void sleep(long time) {
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {

        }
    }

/*    public static String getApplicationId() {
        return BuildConfig.APPLICATION_ID;
    }

    public static int getVersionCode() {
        return BuildConfig.VERSION_CODE;
    }*/

    public static long getDeviceId(Context context) {
        String androidId = Settings.Secure.getString(context.getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);//InstanceID.getInstance(context).getId();
        long deviceId = Hashing.sha256().newHasher().putUnencodedChars(androidId).hash().asLong();

        return Math.abs(deviceId);
    }

    public static long getPackageId(Context context) {
        String packageName = context.getApplicationContext().getPackageName();
        return DataUtil.getSha256(packageName);
    }

    public static String getDeviceName() {
        return DeviceName.getDeviceName();
    }

    public static boolean isAndroid() {
        return System.getProperty("java.vm.name").equalsIgnoreCase("Dalvik");
    }


    public static void log(String unit, String message) {
        if (isDebug()) {
            if (isAndroid()) {
                Log.d(unit, message);
            } else {
                System.out.println(unit + ": " + message);
            }
        }
    }

    public static void logE(String unit, String message) {
        if (isAndroid()) {
            Log.d(unit, "FATAL ERROR: " + message);
        } else {
            System.out.println(unit + ": FATAL ERROR: " + message);
        }

        throw new RuntimeException(unit + ": FATAL ERROR: " + message);
    }

    public static byte byteOfInt(int value, int which) {
        int shift = which * 8;
        return (byte) (value >> shift);
    }

    public static InetAddress intToInet(int value) {
        byte[] bytes = new byte[4];

        for (int e = 0; e < 4; ++e) {
            bytes[e] = byteOfInt(value, e);
        }

        try {
            return InetAddress.getByAddress(bytes);
        } catch (UnknownHostException var3) {
            return null;
        }
    }

    public static Object invokeQuietly(Method method, Object receiver, Object... args) {
        try {
            return method.invoke(receiver, args);
        } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException var4) {
            Log.e("WM", "", var4);
            return null;
        }
    }

    public static <T extends Activity> void openActivity(Activity activity, Class<T> clazz) {
        activity.startActivity(new Intent(activity, clazz));
    }

    public static <T extends Activity> void openDestroyActivity(Activity activity, Class<T> clazz) {
        activity.startActivity(new Intent(activity, clazz));
        activity.finish();
    }

    public static <T extends Activity> void openActivity(Fragment fragment, Class<T> clazz) {
        fragment.getActivity().startActivity(new Intent(fragment.getActivity(), clazz));
    }

    public static <T extends Activity> void openDestroyActivity(Fragment fragment, Class<T> clazz) {
        fragment.getActivity().startActivity(new Intent(fragment.getActivity(), clazz));
        fragment.getActivity().finish();
    }

    public static <T extends Activity> void openActivity(Activity activity, Class<T> clazz, Task<?, ?> task) {
        Intent intent = new Intent(activity, clazz);
        if (task != null) {
            intent.putExtra(Task.class.getName(), (Parcelable) task);
        }
        activity.startActivity(intent);
    }

    public static <T extends Activity> void openActivityForResult(Activity activity, Class<T> clazz, int resultCode) {
        activity.startActivityForResult(new Intent(activity, clazz), resultCode);
    }


    public static String printKeyHash(Activity context) {
        PackageInfo packageInfo;
        String key = null;
        try {
            //getting application package name, as defined in manifest
            String packageName = context.getApplicationContext().getPackageName();

            //Retriving package verbose
            packageInfo = context.getPackageManager().getPackageInfo(packageName,
                    PackageManager.GET_SIGNATURES);

            Log.e("Package Name=", context.getApplicationContext().getPackageName());

            for (android.content.pm.Signature signature : packageInfo.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                key = new String(Base64.encode(md.digest(), 0));

                // String key = new String(Base64.encodeBytes(md.digest()));
                Log.e("Key Hash=", key);
            }
        } catch (PackageManager.NameNotFoundException e1) {
            Log.e("Name not found", e1.toString());
        } catch (NoSuchAlgorithmException e) {
            Log.e("No such an algorithm", e.toString());
        } catch (Exception e) {
            Log.e("Exception", e.toString());
        }

        return key;
    }

    public static Locale getCurrentLocale(Context context) {
        return context.getResources().getConfiguration().locale;
    }
    //Build information
/*    public static boolean isDebug(BuildConfig buildConfig) {
        return BuildConfig.DEBUG;
    }*/

    public static float dp2px(final Context context, final float dpValue) {
        return dpValue * context.getResources().getDisplayMetrics().density;
    }

    public static void hideKeyboard(Activity activity) {
       /* ((InputMethodManager) view.getContext().getSystemService(Activity.INPUT_METHOD_SERVICE))
                .hideSoftInputFromWindow(view.getWindowToken(), 0);*/

        View view = activity.getCurrentFocus();
        if (view != null) {
            InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }

    public static void showKeyboard(Activity activity) {
        // Check if no view has focus:
        View view = activity.getCurrentFocus();
        if (view != null) {
            InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
        }
    }

    /**
     * Is the screen of the device on.
     *
     * @param context the getContext
     * @return true when (at least one) screen is on
     */
    public static boolean isScreenOn(Context context) {
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
            DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
            boolean screenOn = false;
            for (Display display : dm.getDisplays()) {
                if (display.getState() != Display.STATE_OFF) {
                    screenOn = true;
                }
            }
            return screenOn;
        } else {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            //noinspection deprecation
            return pm.isScreenOn();
        }
    }

    public static String getApplicationId(Context context) {
        PackageInfo packageInfo = getPackageInfo(context);
        if (packageInfo != null) {
            return packageInfo.packageName;
        }
        return null;
    }

    public static int getVersionCode(Context context) {
        PackageInfo packageInfo = getPackageInfo(context);
        if (packageInfo != null) {
            return packageInfo.versionCode;
        }
        return 0;
    }

    private static PackageInfo getPackageInfo(Context context) {
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            return packageInfo;
        } catch (PackageManager.NameNotFoundException nameException) {
            return null;
        }
    }

    // Android System Queue
    private static Handler handler;
    private static Handler nonUiHandler = new Handler(Looper.myLooper());

    public static Handler getHandler() {
        if (handler == null) {
            handler = new Handler(Looper.getMainLooper());
        }
        return handler;
    }

    private static final long defaultDelay = 250L;

    public static void removeRunnable(Runnable runnable) {
        getHandler().removeCallbacks(runnable);
    }

    public static void post(Runnable runnable, long timeDelay) {
        getHandler().postDelayed(runnable, timeDelay);
    }

    public static void postDelay(Runnable runnable) {
        post(runnable, defaultDelay);
    }

    public static void post(Runnable runnable) {
        getHandler().post(runnable);
    }

    public static void postNonUi(Runnable runnable, long timeout) {
        nonUiHandler.postDelayed(runnable, timeout);
    }

/*    // Creating
    public static <T extends Fragment> T newFragment(Class<T> fragmentClass) {
        try {
            return fragmentClass.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }*/


    // Checking and Getting

    public static boolean isNull(Object object) {
        return object == null;
    }

    public static boolean isNull(View view) {
        return view == null;
    }

    public static boolean isNull(Context context) {
        return context == null;
    }

    public static View getViewById(View parentView, int viewId) {
        if (!isNull(parentView)) {
            return parentView.findViewById(viewId);
        }
        return null;
    }

    public static ViewPager getViewPager(View parentView, int viewPagerId) {
        View viewPager = getViewById(parentView, viewPagerId);
        if (ViewPager.class.isInstance(viewPager)) {
            return (ViewPager) viewPager;
        }
        return null;
    }

    public static TabLayout getTabLayout(View parentView, int tabLayoutId) {
        View tabLayout = getViewById(parentView, tabLayoutId);
        if (TabLayout.class.isInstance(tabLayout)) {
            return (TabLayout) tabLayout;
        }
        return null;
    }

    private static TextToSpeech textToSpeech;

    public static void initTextToSpeech(Context context) {
        if (textToSpeech == null) {
            try {
                textToSpeech = new TextToSpeech(context.getApplicationContext(), new TextToSpeech.OnInitListener() {
                    @Override
                    public void onInit(int status) {
                        if (status != TextToSpeech.ERROR) {
                            textToSpeech.setLanguage(Locale.getDefault());
                        }
                    }
                });
            } catch (IllegalArgumentException e) {

            }
        }
    }

    public static void speak(String text) {
        if (textToSpeech != null) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null, null);
            } else {
                textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null);
            }
        }
    }


    public static void stopTextToSpeech() {
        if (textToSpeech != null) {
            textToSpeech.stop();
            textToSpeech.shutdown();
            textToSpeech = null;
        }
    }


    public static void openVideo(Context context, String uri) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        intent.setDataAndType(Uri.parse(uri), "video/mp4");
        context.startActivity(intent);
    }

    public static boolean isServiceRunning(Context context, Class<?> serviceClass) {
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
            if (serviceClass.getName().equals(service.service.getClassName())) {
                return true;
            }
        }
        return false;
    }

    public static boolean startService(Context context, Class<?> serviceClass) {
        if (AndroidUtil.isServiceRunning(context, serviceClass)) {
            return false;
        }

        Intent intent = new Intent(context, serviceClass);
        context.startService(intent);
        return true;
    }

    public static boolean stopService(Context context, Class<?> serviceClass) {
        return context.stopService(new Intent(context, serviceClass));
    }

    public static boolean bindService(Context context, Class<?> serviceClass, ServiceConnection serviceConnection) {
        return context.bindService(new Intent(context, serviceClass), serviceConnection, Context.BIND_AUTO_CREATE);
    }

    public static boolean unbindService(Context context, ServiceConnection serviceConnection) {
        context.unbindService(serviceConnection);
        return true;
    }

    public static boolean hasLollipop() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
    }

    public static boolean isJellyBeanMR2() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2;
    }

    public static boolean hasFeature(Context context, String feature) {
        return context.getApplicationContext().getPackageManager().hasSystemFeature(feature);
    }

    public static BluetoothManager getBluetoothManager(Context context) {
        return (BluetoothManager) context.getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE);
    }

    private static HandlerThread handlerThread;
    private static Handler backgroundHandler;

    public static Handler getBackgroundHandler() {
        if (handlerThread == null) {
            handlerThread = new HandlerThread("background-thread");
            handlerThread.start();
            backgroundHandler = new Handler(handlerThread.getLooper());
        }

        return backgroundHandler;
    }

    public static boolean isAppInstalled(Context context, String packageName) {
        PackageManager pm = context.getPackageManager();
        try {
            pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
            return true;
        } catch (PackageManager.NameNotFoundException e) {
        }

        return false;
    }

    public static int getTargetSDKVersion(Context context) {
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            return packageInfo.applicationInfo.targetSdkVersion;
        } catch (PackageManager.NameNotFoundException nnf) {
            return -1;
        }
    }

/*    public static boolean isShareServiceRunning(Context ctx) {
        ActivityManager manager = (ActivityManager) ctx
                .getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningServiceInfo service : manager
                .getRunningServices(Integer.MAX_VALUE)) {
            if (SHAREthemService.class.getCanonicalName().equals(service.service.getClassName())) {
                return true;
            }
        }
        return false;
    }*/

    @RequiresApi(api = Build.VERSION_CODES.M)
    public static boolean hasOverlayPermission(Context context) {
        return Settings.canDrawOverlays(context.getApplicationContext());
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    public static boolean hasWriteSettingsPermission(Context context) {
        return Settings.System.canWrite(context.getApplicationContext());
    }

    public static boolean checkOverlayPermission(Activity activity, int requestCode) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            return true;
        }
        if (!hasOverlayPermission(activity)) {
            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + activity.getPackageName()));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            activity.startActivityForResult(intent, requestCode);
            return false;
        } else {
            return true;
        }
    }

    public static boolean checkWriteSettingsPermission(Activity activity, int requestCode) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            return true;
        }
        if (!hasWriteSettingsPermission(activity.getApplicationContext())) {
            Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + activity.getPackageName()));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            activity.startActivityForResult(intent, requestCode);
            return false;
        } else {
            return true;
        }
    }

    public static boolean hasPermission(Context context, String permission) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            return true;
        }
       return ContextCompat.checkSelfPermission(context.getApplicationContext(), permission) == PackageManager.PERMISSION_GRANTED;
    }

    public static List<String> getStrings(Context context, int resourceId) {
        Resources resources = context.getResources();
        String[] items = resources.getStringArray(resourceId);
        return Arrays.asList(items);
    }
}
<file_sep>package com.dreampany.frame.data.model;

/**
 * Created by air on 7/20/17.
 */

public class Entry {
}
<file_sep># frame
A android framwork to work happily.
<file_sep>package com.dreampany.frame.data.connection;

/**
 * Created by nuc on 6/10/2016.
 */
public interface Connection {
    void start();
    void stop();
}
