Skip to content

Commit

Permalink
Fix issue#2
Browse files Browse the repository at this point in the history
  • Loading branch information
nekocode committed Jul 29, 2016
1 parent e397138 commit e6f84bf
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 44 deletions.
2 changes: 1 addition & 1 deletion lib-emojix/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
buildToolsVersion "24.0.0"

defaultConfig {
minSdkVersion 7
minSdkVersion 11
targetSdkVersion 23
}
lintOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,26 @@ protected EmojixLayoutInflater(LayoutInflater original, Context newContext) {
setUpLayoutFactories(false);
}

protected EmojixLayoutInflater(LayoutInflater original, Context newContext, final boolean cloned) {
super(original, newContext);
setUpLayoutFactories(cloned);
}

private void setUpLayoutFactories(boolean cloned) {
if (cloned) return;
// If we are HC+ we get and set Factory2 otherwise we just wrap Factory1
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
if (getFactory2() != null && !(getFactory2() instanceof WrapperFactory2)) {
// Sets both Factory/Factory2
setFactory2(getFactory2());
}

if (getFactory2() != null && !(getFactory2() instanceof WrapperFactory2)) {
setFactory2(getFactory2());
}
// We can do this as setFactory2 is used for both methods.

if (getFactory() != null && !(getFactory() instanceof WrapperFactory)) {
setFactory(getFactory());
}
}

@Override
public LayoutInflater cloneInContext(Context newContext) {
return new EmojixLayoutInflater(this, newContext);
return new EmojixLayoutInflater(this, newContext, true);
}

@Override
Expand Down Expand Up @@ -138,42 +140,10 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom,
return view;
}


private static class WrapperFactory implements Factory {
private final Factory factory;
private final EmojixLayoutInflater inflater;

public WrapperFactory(Factory factory, EmojixLayoutInflater inflater) {
this.factory = factory;
this.inflater = inflater;
}

@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
return inflater.onViewCreated(
factory.onCreateView(name, context, attrs),
context, attrs);
}
}

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static class WrapperFactory2 implements Factory2 {
protected final Factory2 factory2;
protected final EmojixLayoutInflater inflater;
private static class BaseFactory {
static private Field constructorArgs = null;

public WrapperFactory2(Factory2 factory2, EmojixLayoutInflater inflater) {
this.factory2 = factory2;
this.inflater = inflater;
}

@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
return inflater.onViewCreated(factory2.onCreateView(name, context, attrs), context, attrs);
}

@Override
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
protected View createView(EmojixLayoutInflater inflater, String name, Context context, AttributeSet attrs) {
View view = null;

// Try to create view manually
Expand Down Expand Up @@ -217,6 +187,50 @@ public View onCreateView(View parent, String name, Context context, AttributeSet
}
}

return view;
}
}

private static class WrapperFactory extends BaseFactory implements Factory {
private final Factory factory;
private final EmojixLayoutInflater inflater;

public WrapperFactory(Factory factory, EmojixLayoutInflater inflater) {
this.factory = factory;
this.inflater = inflater;
}

@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
View view = createView(inflater, name, context, attrs);

if (view == null) {
view = factory.onCreateView(name, context, attrs);
}

return inflater.onViewCreated(view, context, attrs);
}
}

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static class WrapperFactory2 extends BaseFactory implements Factory2 {
protected final Factory2 factory2;
protected final EmojixLayoutInflater inflater;

public WrapperFactory2(Factory2 factory2, EmojixLayoutInflater inflater) {
this.factory2 = factory2;
this.inflater = inflater;
}

@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
return inflater.onViewCreated(factory2.onCreateView(name, context, attrs), context, attrs);
}

@Override
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
View view = createView(inflater, name, context, attrs);

if (view == null) {
view = factory2.onCreateView(name, context, attrs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.util.Log;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
Expand Down

0 comments on commit e6f84bf

Please sign in to comment.