70. TV Menu Drawing Scheme

Source: Internet
Author: User

This TV menu drawing program here is the demo implementation

① first simulates the menu data. In real programming, this should be the real menu data stored in the local database or other location, because it is demo, so here is the analog data

② then converts the JSON data (the JSON string that was simulated in the previous step) to the list of objects by Fastjson, where the object refers to "display items" that need to be displayed on the TV, such as pictures, lines, "fish-flavored shredded pork", etc.

③ iterates through the list of objects, invoking different drawing methods to implement the drawing, depending on the type of item passed into the drawing factory, by calling the Paint method in Menumanager.

The above is the implementation of the demo program.

If you want to use commercially, you need to implement the following points:

① Menu switch, this piece is mainly the display when the menu empty and redraw

② The reading of the menu, need to be able to complete the read and write operation quickly and without error

③ menu Information automatic refresh, background run service timed from the server to obtain a list of sold-out dishes, and the list of local dishes to compare, find the list should be marked as sold out and sold out and achieve the drawing

1, menuactivity Processing menu class

        String demodata = "{\ n" + "\" menu_type\ ": 0,\n" + "\" date\ ": \" \ ", \ n" + "\" day\ ": \" \ ", \ n" + "\" time_bucket_name\ ": \" lunch \ "\ n" + "\" Time_buck Et_id\ ": \" 31\ ", \ n" + "\" list\ ": [\ n" + "{\ n" + "\" it                Em_type\ ": 0,\n" + "\" item_id\ ": 1,\n" + "\" content\ ": \" dry ", \ n" + "\" x\ ": 10,\n" + "\" y\ ": 80.5,\n" + "\" fo Nt_size\ ": 30,\n" + "\" font_type\ ": 0,\n" + "\" color\ ": \" #ffffff \ "\                N "+"},\n "+" {\ n "+" \ "item_type\": 1,\n "+            "\" item_id\ ": 2,\n" + "\" content\ ": \" Pork Bun ", \ n" + " \ "x\": 100,\n "+               "\" y\ ": 80.5,\n" + "\" font_size\ ": 30,\n" + " \ "font_type\": 1,\n "+" \ "color\": \ "#000000 \", \ n "+" \ "Chargeit                Em_id\ ": 341,\n" + "\" price\ ": 12.5,\n" + "\" show_price\ ": 0,\n" +            "\" indent\ ": 350,\n" + "\" dynamic_price\ ": 0,\n" + "            \ "dynamic_content\": 1\n "+"},\n "+" {\ n "+" \ "item_type\": 1,\n "+" \ "item_id\": 3,\n "+" \ "content\": \ "            Delicious meat bun \ ", \ n" + "\" x\ ": 400,\n" + "\" y\ ": 180,\n" + " \ "font_size\": 30,\n "+" \ "font_type\": 0,\n "+" \ "color\    ": \" #000000 \ ", \ n" +            "\" chargeitem_id\ ": 341,\n" + "\" price\ ": 12,\n" + " \ "show_price\": 1,\n "+" \ "indent\": 400,\n "+" \ "Dynamic_pr        Ice\ ": 1,\n" + "\" dynamic_content\ ": 1\n" + "},\n" + "                {\ n "+" \ "item_type\": 2,\n "+" \ "item_id\": 4,\n "+ "\" x\ ": 0,\n" + "\" y\ ": 400,\n" + "\" width\ ": 2048\                N "+"},\n "+" {\ n "+" \ "item_type\": 3,\n "+ "\" item_id\ ": 5,\n" + "\" x\ ": 500,\n" + "\" y \ ": 20,\n" + "\" height\ ": 1000\n" + "},\n" + "{\ n    " +                "        \ "item_type\": 4,\n "+" \ "item_id\": 6,\n "+" \ "x\": 100,\n "            + "\" y\ ": 200,\n" + "\" width\ ": 300,\n" + "                \ "height\": 300,\n "+" \ "src\": \ "http://7rflgy.com1.z0.glb.clouddn.com/image-14.jpg\" \ n "+                "},\n" + "{\ n" + "\" item_type\ ": 5,\n" + "\" item_id\ ": 7,\n" + "\" src\ ": \" Http://7rflgy.com1.z0.glb.clouddn.com/blac    Kboard.jpeg\ "\ n" + "\" laying_mode\ ": 0\n" + "}\n" + " ]\n "+"} ";//Let's say this is the menu data for a certain business time period from the server.        intLength = Demodata.getbytes (). length*4; Jsonobject Objdemo=Json.parseobject (Demodata); Com.alibaba.fastjson.JSONArray Arraydemo= Objdemo.getjsonarray ("list"); List<DisplayMenuItem> list = Com.alibaba.fastjson.JSONArray.parseArray (Arraydemo.tojsonstring (), Displaymenuitem .class);//by Fastjson parsing each element in the array, you get a collection of all the "show items" for a menumenumanager.getinstance (). ShowMenu (list); 

2, Menumanager

/**     * Displays the menu and updates the local binding ID list     *     * @param displaymenuitemlist     *    /public void ShowMenu (list< Displaymenuitem> displaymenuitemlist) {        mapserverwidgetmatchid.clear ();        for (Displaymenuitem item:displaymenuitemlist) {            paintfactory.getpaint (item). Paint (Rlmain, ivmain);// The Paint factory class is drawn on Rlmain based on the type of item            if (Item.item_type = = Menuactivity.itemtypemenu) {                if (item.chargeitem_id! =-1 && item.chargeitem_id! = 0) {                    mapserverwidgetmatchid.put (item.chargeitem_id, item.item_id);// If it is associated to the server, it is recorded in the map, used for dynamic sold                out information}}        }        Commonutils.logwuwei ("", "size is" + Mapserverwidgetmatchid.keyset (). Size ());    }

  

3, Drawing factory class Paintfactory

/** * author:created by Zzl on 16/1/8.    */public class Paintfactory {public static Context ctxt;    public static int fenbianlv[]= new INT[2];    public static double x_fraction;    public static double y_fraction;    public static Typeface Fontfacechalkboard;        public static void Init () {ctxt = Mainapplication.getcontext ();        FENBIANLV = Commonutils.getscreenwidthandheight (Mainapplication.getmactivity ());        X_fraction = fenbianlv[0]/1920.0;        Y_fraction = fenbianlv[1]/1080.0;    Fontfacechalkboard = Typeface.createfromasset (Mainapplication.getmactivity (). Getassets (), "Fonts/pianpina.ttf");        public static Basepaint Getpaint (Displaymenuitem Item) {switch (Item.item_type)//Call different methods to finish drawing according to the type of item            {Case MenuActivity.ItemTypeText:return new Painttext (item);            Case MenuActivity.ItemTypeMenu:return New Paintmenuitem (item);     Case Menuactivity.itemtypehorizontalline:           return new Painthorizontalline (item);            Case MenuActivity.ItemTypeVerticalLine:return New Paintverticalline (item);            Case MenuActivity.ItemTypePicture:return New Paintpic (item);        Case MenuActivity.ItemTypeBackgroundPic:return New Paintbackgroundpic (item);    } return null; }}

70. TV Menu Drawing Scheme

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.