Skip to content

Instantly share code, notes, and snippets.

View jayjaykim's full-sized avatar

Jayjay jayjaykim

View GitHub Profile
/**
* Created by jayjay on 2016. 11. 27..
*/
public class AbstractClass {
public static void main(String[] args) {
NormalClass obj1 = new NormalClass();
// SomeInterface obj2 = new SomeInterface();
// SomeAbstractClass obj3 = new A;bstractClass()
SomeInterface obj2 = new SomeInterface() {
@jayjaykim
jayjaykim / AnonymousClassComparison.java
Created September 11, 2016 13:52
AnonymousClassComparison
/**
* Created by jayjay on 2016. 9. 11..
*/
public class TestInterface {
String msg;
int number;
float floatNumber;
public interface ClickListener {
void onClick();
@jayjaykim
jayjaykim / TestSingleton.java
Created September 6, 2016 04:52
TestSingleton.java which is imperfect in multi-threading environment
public class Communication {
static Communication instance;
private Communication() {
}
public static Communication getInstance() {
if(instance == null)
instance = new Communication();
@jayjaykim
jayjaykim / TestForEach.java
Created September 6, 2016 04:50
TestForEach.java
public class TestForeach {
public static void main(String[] args) {
String[] msgs = {"aa", "bb", "cc", "dd"};
String[] msg1 = new String[]{"aa", "bb", "cc", "dd"};
final int size = msg1.length;
for(int i = 0; i < size; i++) {
System.out.println(msgs[i]);
}
@jayjaykim
jayjaykim / RemoveEntryForLoop.java
Created August 27, 2016 02:27
remove an entry in for-loop statement
public class TestList {
public static void main(String[] args) {
String[] strings = {"hi", "hello", "mine", "you"};
List<String> list = Lists.newArrayList(strings);
// item or entry == 항목
System.out.println("list : " + list);
final int size = list.size();
for(int i = size - 1; i >= 0; i--) {
@jayjaykim
jayjaykim / MVvsMVP.java
Last active August 26, 2016 11:42
Legacy MV vs MVP
/**
* Legacy
*/
public class ActivityA {
public void onCreate(A state) {
Volley.getList(new Callback() {
public void onSuccess(List<Image> list) {
showImageList(List<Image> list);
}
@jayjaykim
jayjaykim / FoldUnfold.java
Last active August 26, 2016 11:40
RecyclerView Fold/Unfold implementations
public class FileWrapper {
int type; // 0 : File, 1 : Directory
int depth; // 0~n
File file;
// contructor for injecting depedency, e.g. File object, type, depth
// setters and getters
}
public class Adapter extends RecyclerView.Adapter<RecyclerView.Holder> {
@jayjaykim
jayjaykim / TestStatic.java
Created August 21, 2016 12:44
java static keyword usage
public class TestStatic {
public static void main(String[] args) {
Sample sample1 = new Sample();
Sample sample2 = new Sample();
Sample sample3 = new Sample();
Sample.number1 = 2;
Sample.method1();
sample1.setNumber2(1);
@jayjaykim
jayjaykim / TestLruCache
Last active August 6, 2016 12:36
LruCache Sample code
package com.jayjaylab.android.test.plainjava;
import android.support.v4.util.LruCache;
import android.util.Log;
/**
* Created by jayjay on 2016. 8. 6..
*/
public class TestLruCache {
static final String TAG = TestLruCache.class.getSimpleName();
@jayjaykim
jayjaykim / gist:2ff5e1b4458f3b2e49e4
Last active March 23, 2016 11:22
Endless Scrolling with AdapterViews and RecyclerViews
// Instead of using [Endless Scrolling with AdapterViews and RecyclerViews]
// (https://github.com/codepath/android_guides/wiki/Endless-Scrolling-with-AdapterViews-and-RecyclerView/_edit)
// introduced in codepath.
// There's more simple and less computational way to implement endless scrolling. You can replace 1 in if-statement
// if(position == getItemCount() - 1) for fine tuning.
// Make use of the following code snippet in your project.
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
EndlessScrollListener endlessScrollListener