@NonNull public ProteusContext createContext(@NonNull Context base) { return createContextBuilder(base).build(); }
public Proteus build() { Map<String, Proteus.Type> types = new HashMap<>(); for (Map.Entry<String, ViewTypeParser> entry : parsers.entrySet()) { types.put(entry.getKey(), prepare(entry.getValue())); } return new Proteus(types, functions); }
public boolean isLayout(String type) { return null != proteus && proteus.has(type); } }
Proteus(@NonNull Map<String, Type> types, @NonNull final Map<String, Function> functions) { this.types = types; this.functions = new FunctionManager(functions); this.parsers = map(types); }
public Layout read(String type, Proteus proteus, JsonReader in) throws IOException { List<Layout.Attribute> attributes = new ArrayList<>(); Map<String, Value> data = null; ObjectValue extras = new ObjectValue(); String name; while (in.hasNext()) { name = in.nextName(); if (ProteusConstants.DATA.equals(name)) { data = readData(in); } else { ViewTypeParser.AttributeSet.Attribute attribute = proteus.getAttributeId(name, type); if (null != attribute) { FunctionManager manager = PROTEUS_INSTANCE_HOLDER.getProteus().functions; Value value = attribute.processor.precompile(VALUE_TYPE_ADAPTER.read(in), getContext(), manager); attributes.add(new Layout.Attribute(attribute.id, value)); } else { extras.add(name, VALUE_TYPE_ADAPTER.read(in)); } } } return new Layout(type, attributes.size() > 0 ? attributes : null, data, extras.entrySet().size() > 0 ? extras : null); }
public static ProteusContext context() { Proteus proteus = new ProteusBuilder().build(); Context context = mock(Context.class); return proteus.createContextBuilder(context).build(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_proteus); // set the toolbar Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); // setBoolean refresh button click FloatingActionButton fab = findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { alert(); } }); container = findViewById(R.id.content_main); DemoApplication application = (DemoApplication) getApplication(); proteusManager = application.getProteusManager(); ProteusContext context = proteusManager.getProteus().createContextBuilder(this) .setLayoutManager(layoutManager) .setCallback(callback) .setImageLoader(loader) .setStyleManager(styleManager) .build(); layoutInflater = context.getInflater(); }