TableRow data updates with bright background

sponsored links
General Table of data (rows) update to keep up with some animation to the user's attention.
In Android, the color value of hex with 8 to 16, said two of them used to indicate the first two alpha channel, said after the six to rgb. In the process which, if within the specified time, the alpha channel from 0 adjusted to 0xff, on the realization of the highlight TableRow.

  • Here is the thread to achieve:


class ColorRefreshTask extends TimerTask {
                        final static int  DELAY_ONCE =200;
                        final static int TOTAL_RUNTIME = 3000;
                        final static int POWER_16_16 = 16 * 16* 16 * 16 * 16 * 16;
                        final static int INCREASE_ONCE =  0xff / (TOTAL_RUNTIME / DELAY_ONCE);
                        int color;
                        int id;
                        int startTime;
                        int alphaChannel;
                        
                        /**
                         * 
                         * @param color (TableRow's current background color)
                         * @param id TableRow's id(user id)
                         */
                        public ColorRefreshTask(int color, int id) {
                                super();
                                Log.d("color", "ready to set color!");
                                this.color = color;
                                this.id = id;
                                this.startTime = 0;
                                this.alphaChannel = 0;
                        }
                        
                        public void run(){
                                
                                int colorComm = color -0xff000000;  //RGB color value;
                                int currColor = color;
                                
                                if(startTime < TOTAL_RUNTIME) {
                                                startTime +=  DELAY_ONCE;
                                                alphaChannel +=  INCREASE_ONCE;
                                                currColor = POWER_16_16 *  alphaChannel  + colorComm;
                                                Log.d("color", Integer.toHexString(currColor));
                                                sendMsg(currColor);
                                                messageHandler.postDelayed(this,DELAY_ONCE);
                                                
                                }
                                else {
                                        sendMsg(currColor);
                                }
                                
                        
                        }
                        
                        public void startTimer(){
                                  messageHandler.postDelayed(this,DELAY_ONCE);
                        }
                        
                        
                        private void sendMsg(int currColor){
                                Message message = messageHandler.obtainMessage(); 
                                message.what = MESSAGE_HANDLE_ID_UPDATEROW_BACKGROUND;
                                Bundle bundle = new Bundle();
                                bundle.putInt(MESSAGE_KEY_ID, id);
                                bundle.putInt(MESSAGE_KEY_COLOR, currColor);
                                message.setData(bundle);
                                messageHandler.sendMessage(message);
                        }
                        
                        public void stopTimer(){
                                  this.cancel();
                        }
                        
                        
          }


  • Message processing part:

 private static final int MESSAGE_HANDLE_ID = 800;
          private static final int MESSAGE_HANDLE_ID_UPDATEROW_DATA = MESSAGE_HANDLE_ID + 1;
          private static final int MESSAGE_HANDLE_ID_UPDATEROW_BACKGROUND = MESSAGE_HANDLE_ID +2;
          private  Handler messageHandler = new Handler() {

                @Override
                public void handleMessage(Message msg) {
                        
                switch(msg.what) {
                        case  MESSAGE_HANDLE_ID_UPDATEROW_DATA:{
                                int id = msg.getData().getInt(MESSAGE_KEY_ID);
                                String fields[] = new String[5];
                                fields[0] = msg.getData().getString("fields1");
                                fields[1] = msg.getData().getString("fields2");
                                fields[2] = msg.getData().getString("fields3");
                                fields[3] = msg.getData().getString("fields4");
                                fields[4] = msg.getData().getString("fields5");
                                updateRowInTable(id, fields);
                                break;
                        }
                                                
                        case  MESSAGE_HANDLE_ID_UPDATEROW_BACKGROUND:
                        {
                                int id = msg.getData().getInt(MESSAGE_KEY_ID);
                                int color = msg.getData().getInt(MESSAGE_KEY_COLOR);
                                TableRow tableRow= (TableRow)findViewById( id);
                                if(tableRow != null) {
                                        int count = tableRow.getChildCount();
                                        for(int index = 0; index < count; index++) {
                                                TextView child = (TextView)(tableRow.getChildAt(index));
                                                if(child != null) {
                                                        child.setBackgroundColor(color);
                                                        
                                                }
                                        }
                                }
                                break;
                        }
                        default:
                                        
                }
                        
                }
                  
          };


  • Data updates (other thread will call) part:

private final void updateRowInTable(int code,String[] otherFields) {
          TableRow tableRow= (TableRow)findViewById(code);
          if(tableRow == null)  {
                  Log.d("tablerow", "can't find row in the table!");
                  return;
          }
          int bgColorEnd = (otherFields[2].indexOf("-") >= 0)  ?  0xff2e8b57 : 0xffb22222;
      for(int index = 0; index < otherFields.length; index++) {
           int identity = code * 13  +(index+1);
          
          TextView textView=  (findViewById(identity)!= null)  ?  (TextView) findViewById(identity) :  new TextView(this);  
         
          if(otherFields[index].indexOf('-') >=0) {
                  textView.setTextColor(Color.GREEN);
          }
          else if( index == 2) {
                  textView.setTextColor(Color.RED);
          }
          else  {
                  textView.setTextColor(Color.WHITE);
          }
          textView.setText(otherFields[index]);
          Log.d("tablerow", "updated  id:" + (code)  + ", value="  + otherFields[index] );
          if(findViewById(identity) == null){
                  textView.setId(identity);
                  tableRow.addView(textView);  
                  Log.d("tablerow", "add new view!");
          }
          else {
                  Log.d("tablerow", "upate view!");
          }
          textView.postInvalidate();
          //textView.invalidate();
      }
      tableRow.postInvalidate();
      //tableRow.invalidate();
      ColorRefreshTask refresh = new ColorRefreshTask(bgColorEnd,code);
      messageHandler.postDelayed(refresh, 50);  
      
}
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of TableRow data updates with bright background

  • hibernate call stored procedure

    hibernate call stored procedure

  • hibernate using c3p0 connection pooling

    Private http://www.lifevv.com/tenyo/doc/20070605102040991.html c3p0 for open source's JDBC connection pool, with the release hibernate. This article describes how to use the hibernate configuration in c3p0. c3p0 connection pool configuration is v ...

  • Hibernate configuration parameters hibernate.hbm2ddl.auto

    Hibernate in the configuration file: <properties> <property name="hibernate.hbm2ddl.auto" value="create" /> </ properties> Parameter Description: validate load hibernate, the authentication to create a database t ...

  • Build flex + spring + blazeds + hibernate application

    Build flex + spring + blazeds + hibernate application First, set up the project blazeds 1, will blazeds.war extract to a directory, such as: myflex /; 2, set up java works were such as: MyFlex, in the orientation of selection create project from exis ...

  • Hibernate connection pool configuration

    Hibernate connection pool configuration <! - Jdbc -> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </ property> <property name="connection.url"> jdbc: oracle: thin: @ 10.203.14.132:15

  • hibernate generic generic DAO

    package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

  • Hibernate secondary cache

    Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries