zoukankan      html  css  js  c++  java
  • AB_Converters 工具类详解

    以上目前AB提供的converters包下的工具类。下面将逐一介绍。

    介绍前提到 DependentObservable 。他可以实现类似自定义Converters的作用。文章末尾作解释。

    【ADAPTER】:返回一个Adapter对象。

    ADAPTER accepts only one argument, and it must be DynamicObject

    需要使用DynamicObject对象作为其参数。ADAPTER({xxxxx,xxxx});

      java代码中可通过 gueei.binding.collections.Utility.getSimpleAdapter调用

    @item template gueei.binding.viewAttributes.templates.Layout
    @item source Object
    @item @optional spinnerTemplate gueei.binding.viewAttributes.templates.Layout
    @item @optional enable String child property that determines the enabled state of the item
    @item @optional filter android.widget.Filter filter supplies to adapter

    ADAPTER({template=@layout/list_item, source=Demos,enable=true})

    【AFTERCOMMAND】:Trigger the provided animation after the command is executed. 当Command方法执行完后触发动画。

    (This is NOT compatible with the newer Property-based animation) _mark  不适用newer Property-based animation。是指??

    @arg animationId integer, specify by "@anim/animation"
    @arg command gueei.binding.Command
    @arg @optional condition boolean

    @return gueei.binding.viewAttributes.view.AnimationTrigger

    binding:animation="AFTERCOMMAND(@anim/shake, CheckPassword, NOT(PasswordCorrect))"

    【ALT_TEMPELATE】 交替布局。

    binding:itemTemplate="ALT_TEMPLATE(
                @layout/arraylist_item, @layout/arraylist_item1, @layout/arraylist_item2)"

    @return gueei.binding.viewAttributes.templates.Layout

    【AND】 逻辑与

    AND(arg ...) 大于1个参数,全true为true。

    【ARG】 Passing extra arguments to command. 传递额外参数给指定的方法。

    binding:onItemClicked="ARG(ToggleItem, =id/lvItems.clickedItem)" ———— ARG(Command cmd,Object arg ...)
    @return command gueei.binding.Command
    在 Command 的 invoke(View, args) 方法中,新增的args参数会被作为最左边的参数被调用。
    例如:默认情况下 绑定 binding:onChecked="Fire" 属性,对象的Command Fire 的回调是 invoke(View,Boolean)。
    这时如果 使用ARGB—— binding:onChecked="ARGB(Fire,1,2)"。 则对应的回调 会是 invoke(View,Integer,Integer,Boolean)

    【ARGB】 转化为RGB或者ARGB的色值。

    @return integer Android color-coded Integer
    RGB——ARGB(0,0,0); ARGB——ARGB(255,0,255,0)

     【CONCAT】 字符串连接,等同于java的concat方法。

    CONCAT('str1 ','str2')
    @return String

    【EQUAL】 equal比较。注:如果两个参数都为空,则返回true。

    EQUAL(conditon1,conditon2)
    @return Boolean

    【FALSE】 Constant that always return false. Takes no argument 。无参,始终返回false。_ binding:text="FASLE()"

    【FORMAT】 类似于java中的String.format(formatstring, item...)

      @arg formatString String _Java-styled format string
      @arg str String _If supplied Object, it will call Object.toString()

    @return android.text.Spanned formatted with HTML tags in string

    目前尝试 。binding:text="FORMAT('123','%05d')" 界面显示 123.未出现预想的00123,而binding:text="FORMAT('123','test%05d')"。还是显示123

    【HIGHLIGHT_SPAN】  all occurences in a given text with a span。

     Param 0: TextInput 需要处理的Str
     Param 1: Text to search 目标文本
     Param 2: SpanCreatorCommand or SpanListCreatorCommand for creating the Spans 传递通过两种方式创建得到的SPAN 或 SPANS 的 List
    @return list of Spans

    详见com.gueei.demos.markupDemo.viewModels.TextViewSpan 示例。

    【HTML】  按HTML风格 转化SPAN 显示(表述不确切)

    /**
     * Concat, Styles and Convert HTML Charsequences into Styled Spanned.  
     * 
     * @usage str str ...
     * 
     * @arg str String : If supplied Object, it will call Object.toString()
     * 
     * @return android.text.Spanned : formatted with HTML tags in string
     */
    public class HTML

    binding:text="HTML(Title, ' ', '<sup>', Id, '</sup>')" _ id 以上标形式展示。

    【IF_NULL】 逻辑判断

     * @usage condition arg_if_null arg_if_not
     *
     * @arg condition boolean
     * @arg arg_if_null Object
     * @arg arg_if_not Object
     *
     * @return Object

    【IF】  逻辑判断

    * @usage condition arg_if_true arg_if_false
     * 
     * @arg condition boolean
     * @arg arg_if_true Object
     * @arg arg_if_false Object
     * 
     * @return boolean

    【INJECT】 INJECT binding statements into layout templates. 给layout注入 binding 属性。

    常用于对一些模版 layout 的部分效果进行变更。

    /**
     * INJECT binding statements into layout templates. <br/>
     * Most probably those templates came from external libraries (e.g. android) that you cannot change <br/>
     * This is much more convenient than everytime you need to copy those standard templates. <br/>
     * <br/>
     * 
     * The most common usage is on those templates for spinners, listviews (e.g. @android:layout/simple_list_item1). <br/>
     * Suppose We need to inject the statement to the textview (@android:id/textview1), then: <br/>
     * binding:itemTemplate="INJECT(@android:layout/simple_list_item1, { id=@android:id/textview1, attr='text', statement='Name' })" <br/>
     * Note it is possible to inject more than one attribute, for example you can change the color of the above mentioned text view too: <br/>
     * binding:itemTemplate="INJECT(@android:layout/simple_list_item1, { id=@android:id/textview1, attr='text', statement='Name' }, { id=@android:id/textview1, attr='backgroundColor', statement='ARGB(255,0,0)' })" <br/>
     * @usage layout params ...
     * 
     * @arg layout gueei.binding.viewAttributes.templates.Layout Layout of the template-to-inject
     * @arg params DynamicObject
     * 
     * @item id integer Android Id value of the widget 
     * @item attr Attribute name of that widget
     * @item statement Binding Statement to be injected
     *
     * @return gueei.binding.viewAttributes.templates.Layout
     */

    【IS_NOT_NULL】 return true if the argument is NOT null 。

    binding:text ="IS_NOT_NULL(1)"

    【ISNULL】 同上。

    【ITEM_LAYOUT】 ITEM_LAYOUT this adapter is used for bindable linear layouts

    binding:itemLayout="ITEM_LAYOUT('LayoutId')" 
    
    binding:itemPath="ITEM_LAYOUT(@layout/binablelinearlayout_item)" 

    【LEN】 Length of the given String, if provided is an object, object.toString().length() will be evaluated。测试指定对象长度,非String会强转

    * @arg str String
    * 
    * @return integer

    【LOWER】 小写 binding:text="LOWER("LOVWERASD")"

    【MENU】

    /**
     * Use exclusively for contextMenu attribute
     * 
     * @usage menu_xml_id model
     * 
     * @arg menu_xml integer XML id of the context menu, e.g. @menu/context_menu
     * @arg model Object View model to bind to the menu, most probably it will be just "."
     * 
     * @return gueei.binding.menu.ContextMenuBinder
     * 
     * @author andy
     *
     */

    【NOT】 逻辑非

     * @arg arg boolean
     * 
     * @return boolean

    【NULL】 常量,永远返回null.  --- NULL()

    【OR】 逻辑或 操作。 只要有一个参数为 true,则结果为true。

    【PROP】 

    /**
     * Dynamically evaluate the statement for the given view_model
     * 
     * @usage view_model statement
     * 
     * @arg view_model Object the Context to evaluate the statement
     * @arg statement String
     * 
     * @return Object
     */

    【ROW_CHILD】 this adapter is used for bindable table layouts

    binding:rowChild="ROW_CHILD('Children','LayoutId','ColSpan')"  

    【SECTION】 Returns a Single Item Adapter (SingletonAdapter) for the given object.

    /**
     * Returns a Single Item Adapter (SingletonAdapter) for the given object. <br/>
     * This is most useful as declaring header/footer templates for list views, or as divider to divide list in sections
     * 
     * @usage object layout
     * @arg object Object 
     * @arg layout gueei.binding.viewAttributes.templates.Layout
     * 
     * @return Adapter
     * 
     */

    【SPAN】 返回List<SPAN>对象

    /**
     * Span for text/editfields
     * 
     * Param 0: TextInput
     * Param 1: Span or List of Spans
     * 
     * @return list of Spans
     */

    【STITCH】 就是将多个ADAPTER展示在一个listView中。

    /**
     * STITCH multiple adapters to one adapter for used in List Views. <br/>
     * 
     * @usage adapter adapter ...
     * @arg adapter android.widget.Adapter
     *  
     * @return android.widget.Adapter
     */

    【TAB】 

    【TRUE】 常量,永远返回true。 TRUE()

    【TYPEFACE_FROM_ASSET】  

    /**
     * Get type face from asset folder
     *  
     * @usage type_name
     * @arg type_name String Name of the typeface
     * 
     * @return android.graphics.Typeface
     */

    【UPPER】 大写。

    DependentObservable is an Observable that `Observes` other observables, once any of those observables changes, it calculate its value accordingly; a Converter is the same as DependentObservable, only DependentObservable is readonly, a Converter can do reverse conversion.
    Android-Binding supports custom Converters (along with some built-in) to declared in XML layout, first, we have to create a class extends from DependentObservable:
    public class FormatDisplay extends DependentObservable<CharSequence> {
        public FormatDisplay(IObservable<?>[] dependents) {
            super(CharSequence.class, dependents);
        }
        @Override
        public CharSequence calculateValue(Object... args) throws Exception {
            Double display = (Double)args[0];
            DecimalFormat format = new DecimalFormat();
            format.applyPattern("#.######");
            String output = format.format(display);
            if (output.length() <= 10) return output;
            format.applyPattern("0.########E00");
            return format.format(display);
        }
    }

    Now, we modify our layout to:

    <TextView android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:textSize="45dip"
        android:gravity="right|bottom" 
        binding:text="com.gueei.tutorials.calculator.FormatDisplay(Display)"
        android:layout_weight="1"/>
  • 相关阅读:
    js-数组方法的使用和详谈
    JS中的作用域(一)-详谈
    vue中的axios
    GitHub使用
    nodejs项目文件搭建环境
    我的黑客和渗透测试学习路线
    带你了解后渗透工具Koadic
    黑客专用多功能记事本
    Kali环境使用Metasploit生成木马入侵安卓手机
    邪恶葫芦工具包
  • 原文地址:https://www.cnblogs.com/pinotao/p/3299067.html
Copyright © 2011-2022 走看看