Skip to content

Commit

Permalink
Resolves #56
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Sharat committed Sep 2, 2016
1 parent e11c240 commit b397710
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 144 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import android.view.View;
import android.widget.Toast;

import com.flipkart.android.proteus.demo.LogbackConfigureHelper;

/**
* BaseActivity
*
Expand All @@ -38,8 +36,6 @@ public BaseActivity() {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

LogbackConfigureHelper.configure();

long startTime = System.currentTimeMillis();

View view = createAndBindView();
Expand Down
1 change: 0 additions & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ dependencies {
compile 'com.android.support:support-annotations:24.1.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.4'
compile 'org.slf4j:slf4j-api:1.7.6'

testCompile 'junit:junit:4.12'
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.regex.Pattern;

Expand All @@ -37,7 +34,6 @@
*/
public class DataContext {

private static Logger logger = LoggerFactory.getLogger(DataContext.class);
private final boolean isClone;
private JsonObject data;
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

Expand All @@ -39,9 +40,6 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
Expand All @@ -51,7 +49,7 @@
*/
public class DataParsingLayoutBuilder extends SimpleLayoutBuilder {

private static Logger logger = LoggerFactory.getLogger(DataAndViewParsingLayoutBuilder.class);
private static final String TAG = "LayoutBuilder";
private Map<String, Formatter> formatter = new HashMap<>();

protected DataParsingLayoutBuilder(@NonNull IdGenerator idGenerator) {
Expand All @@ -65,7 +63,7 @@ protected void handleChildren(LayoutHandler handler, ProteusView view) {
JsonObject layout = viewManager.getLayout();

if (ProteusConstants.isLoggingEnabled()) {
logger.debug("Parsing children for view with " + Utils.getLayoutIdentifier(layout));
Log.d(TAG, "Parsing children for view with " + Utils.getLayoutIdentifier(layout));
}

if (layout == null) {
Expand Down Expand Up @@ -188,7 +186,7 @@ private JsonElement findAndReplaceValues(LayoutHandler handler, ProteusView view
DataContext dataContext = viewManager.getDataContext();

if (ProteusConstants.isLoggingEnabled()) {
logger.debug("Find '" + stringValue + "' for " + attribute + " for view with " + Utils.getLayoutIdentifier(viewManager.getLayout()));
Log.d(TAG, "Find '" + stringValue + "' for " + attribute + " for view with " + Utils.getLayoutIdentifier(viewManager.getLayout()));
}

char firstChar = TextUtils.isEmpty(stringValue) ? 0 : stringValue.charAt(0);
Expand Down Expand Up @@ -318,7 +316,7 @@ public JsonObject getChildLayout(JsonElement type, JsonObject source, ProteusVie
@Nullable
protected JsonObject onLayoutRequired(String type, ProteusView parent) {
if (ProteusConstants.isLoggingEnabled()) {
logger.debug("Fetching child layout: " + type);
Log.d(TAG, "Fetching child layout: " + type);
}
if (listener != null) {
return listener.onLayoutRequired(type, parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

Expand All @@ -34,9 +35,6 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

Expand All @@ -46,6 +44,8 @@
*/
public class SimpleLayoutBuilder implements LayoutBuilder {

private static final String TAG = "SimpleLayoutBuilder";

@Nullable
protected LayoutBuilderCallback listener;
private HashMap<String, LayoutHandler> layoutHandlers = new HashMap<>();
Expand All @@ -54,8 +54,6 @@ public class SimpleLayoutBuilder implements LayoutBuilder {

private boolean isSynchronousRendering = false;

private static Logger logger = LoggerFactory.getLogger(SimpleLayoutBuilder.class);

private IdGenerator idGenerator;

protected SimpleLayoutBuilder(@NonNull IdGenerator idGenerator) {
Expand Down Expand Up @@ -150,7 +148,7 @@ protected void onAfterCreateView(LayoutHandler handler, ProteusView view, ViewGr

protected ProteusViewManager createViewManager(LayoutHandler handler, View parent, JsonObject layout, JsonObject data, int index, Styles styles) {
if (ProteusConstants.isLoggingEnabled()) {
logger.debug("ProteusView created with " + Utils.getLayoutIdentifier(layout));
Log.d(TAG, "ProteusView created with " + Utils.getLayoutIdentifier(layout));
}

ProteusViewManagerImpl viewManager = new ProteusViewManagerImpl();
Expand All @@ -169,15 +167,15 @@ protected ProteusViewManager createViewManager(LayoutHandler handler, View paren

protected void handleChildren(LayoutHandler handler, ProteusView view) {
if (ProteusConstants.isLoggingEnabled()) {
logger.debug("Parsing children for view with " + Utils.getLayoutIdentifier(view.getViewManager().getLayout()));
Log.d(TAG, "Parsing children for view with " + Utils.getLayoutIdentifier(view.getViewManager().getLayout()));
}

handler.handleChildren(view);
}

public boolean handleAttribute(LayoutHandler handler, ProteusView view, String attribute, JsonElement value) {
if (ProteusConstants.isLoggingEnabled()) {
logger.debug("Handle '" + attribute + "' : " + value.toString() + " for view with " + Utils.getLayoutIdentifier(view.getViewManager().getLayout()));
Log.d(TAG, "Handle '" + attribute + "' : " + value.toString() + " for view with " + Utils.getLayoutIdentifier(view.getViewManager().getLayout()));
}
//noinspection unchecked
return handler.handleAttribute((View) view, attribute, value);
Expand All @@ -192,7 +190,7 @@ protected void onUnknownAttributeEncountered(String attribute, JsonElement value
@Nullable
protected ProteusView onUnknownViewEncountered(String type, ViewGroup parent, JsonObject layout, JsonObject data, int index, Styles styles) {
if (ProteusConstants.isLoggingEnabled()) {
logger.debug("No LayoutHandler for: " + type);
Log.d(TAG, "No LayoutHandler for: " + type);
}
if (listener != null) {
return listener.onUnknownViewType(type, parent, layout, data, index, styles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.os.Build;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.Pair;
import android.util.TypedValue;
import android.view.Gravity;
Expand All @@ -38,9 +39,6 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -55,6 +53,8 @@
*/
public class ParseHelper {

private static final String TAG = "ParseHelper";

private static final String TRUE = "true";
private static final String FALSE = "false";

Expand Down Expand Up @@ -125,7 +125,6 @@ public class ParseHelper {
private static final Map<String, ImageView.ScaleType> sImageScaleType = new HashMap<>();
private static Map<String, Integer> styleMap = new HashMap<>();
private static Map<String, Integer> attributeMap = new HashMap<>();
private static Logger logger = LoggerFactory.getLogger(ParseHelper.class);

static {
sStateMap.put("state_pressed", android.R.attr.state_pressed);
Expand Down Expand Up @@ -201,7 +200,7 @@ public static int parseInt(String attributeValue) {
number = Integer.parseInt(attributeValue);
} catch (NumberFormatException e) {
if (ProteusConstants.isLoggingEnabled()) {
logger.error(attributeValue + " is NAN. Error: " + e.getMessage());
Log.e(TAG, attributeValue + " is NAN. Error: " + e.getMessage());
}
number = 0;
}
Expand All @@ -217,7 +216,7 @@ public static float parseFloat(String attributeValue) {
number = Float.parseFloat(attributeValue);
} catch (NumberFormatException e) {
if (ProteusConstants.isLoggingEnabled()) {
logger.error(attributeValue + " is NAN. Error: " + e.getMessage());
Log.e(TAG, attributeValue + " is NAN. Error: " + e.getMessage());
}
number = 0;
}
Expand All @@ -233,7 +232,7 @@ public static double parseDouble(String attributeValue) {
number = Double.parseDouble(attributeValue);
} catch (NumberFormatException e) {
if (ProteusConstants.isLoggingEnabled()) {
logger.error(attributeValue + " is NAN. Error: " + e.getMessage());
Log.e(TAG, attributeValue + " is NAN. Error: " + e.getMessage());
}
number = 0;
}
Expand Down Expand Up @@ -324,7 +323,7 @@ public static float parseDimension(final String dimension, Context context) {
value = (int) context.getResources().getDimension(resourceId);
} catch (Exception e) {
if (ProteusConstants.isLoggingEnabled()) {
logger.error("could not find a dimension with name " + dimension + ". Error: " + e.getMessage());
Log.e(TAG, "could not find a dimension with name " + dimension + ". Error: " + e.getMessage());
}
value = 0;
}
Expand Down Expand Up @@ -353,7 +352,7 @@ public static float parseDimension(final String dimension, Context context) {
a.recycle();
} catch (Exception e) {
if (ProteusConstants.isLoggingEnabled()) {
logger.error("could not find a dimension with name " + dimension + ". Error: " + e.getMessage());
Log.e(TAG, "could not find a dimension with name " + dimension + ". Error: " + e.getMessage());
}
value = 0;
}
Expand Down Expand Up @@ -400,15 +399,15 @@ public static int getAttributeId(Context context, String attribute) {

} catch (ClassNotFoundException e) {
if (ProteusConstants.isLoggingEnabled()) {
logger.error(e.getMessage() + "");
Log.e(TAG, e.getMessage() + "");
}
} catch (NoSuchFieldException e) {
if (ProteusConstants.isLoggingEnabled()) {
logger.error(e.getMessage() + "");
Log.e(TAG, e.getMessage() + "");
}
} catch (IllegalAccessException e) {
if (ProteusConstants.isLoggingEnabled()) {
logger.error(e.getMessage() + "");
Log.e(TAG, e.getMessage() + "");
}
}
}
Expand All @@ -424,7 +423,7 @@ public static int parseColor(String color) {
return Color.parseColor(color);
} catch (IllegalArgumentException ex) {
if (ProteusConstants.isLoggingEnabled()) {
logger.error("Invalid color : " + color + ". Using #000000");
Log.e(TAG, "Invalid color : " + color + ". Using #000000");
}
return Color.BLACK;
}
Expand All @@ -438,7 +437,7 @@ public static Integer parseId(String id) {
return Integer.valueOf(id);
} catch (NumberFormatException ex) {
if (ProteusConstants.isLoggingEnabled()) {
logger.error(id + " is not a valid resource ID.");
Log.e(TAG, id + " is not a valid resource ID.");
}
}
return null;
Expand All @@ -460,7 +459,7 @@ public static void addRelativeLayoutRule(View view, int verb, int anchor) {
view.setLayoutParams(params);
} else {
if (ProteusConstants.isLoggingEnabled()) {
logger.error("cannot add relative layout rules when container is not relative");
Log.e(TAG, "cannot add relative layout rules when container is not relative");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.flipkart.android.proteus.parser;

import android.content.res.XmlResourceParser;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

Expand All @@ -28,8 +29,6 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

Expand All @@ -47,8 +46,9 @@
*/
public abstract class Parser<V extends View> implements LayoutHandler<V> {

private static final String TAG = "Parser";

private static XmlResourceParser sParser = null;
private static Logger logger = LoggerFactory.getLogger(Parser.class);
private Map<String, AttributeProcessor> handlers = new HashMap<>();

@Override
Expand All @@ -63,7 +63,7 @@ public void onAfterCreateView(V view, ViewGroup parent, JsonObject layout, JsonO
view.setLayoutParams(layoutParams);
} catch (Exception e) {
if (ProteusConstants.isLoggingEnabled()) {
logger.error("#createView()", e.getMessage() + "");
Log.e(TAG, "#createView() : " + e.getMessage());
}
}
}
Expand Down
Loading

0 comments on commit b397710

Please sign in to comment.