package com.gracker.delaytest;

import android.os.Handler;
import android.support.v4.os.TraceCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private static final int DEALY_TIME = 300;

    private ImageView zhihuImage;
    private TextView imageWidth;
    private TextView imageHeight;

    private Handler myHandler = new Handler();
    private Runnable mLoadingRunnable = new Runnable() {

        @Override
        public void run() {
            updateText();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        zhihuImage = (ImageView) findViewById(R.id.zhihu_img);

        imageWidth = (TextView) findViewById(R.id.img_width_txt);
        imageHeight = (TextView) findViewById(R.id.img_height_txt);

        //  第一种写法:直接Post
//        myHandler.post(mLoadingRunnable);

//  第二种写法:直接PostDelay 300ms.
//  myHandler.postDelayed(mLoadingRunnable, DEALY_TIME);

//        第三种写法:
//        优化的DelayLoad
        getWindow().getDecorView().post(new Runnable() {
            @Override
            public void run() {
                myHandler.post(mLoadingRunnable);
            }
        });
    }

    private void updateText() {
        TraceCompat.beginSection("updateText");
        imageWidth.setText("image : w=" + zhihuImage.getWidth());
        imageHeight.setText("image : h=" + zhihuImage.getWidth());
        TraceCompat.endSection();
    }
}

@@ -366,19 +366,17 @@
  zhihuIm
-age
+g
 ;%0A    pr
@@ -400,16 +400,19 @@
 ageWidth
+Txt
 ;%0A    pr
@@ -437,16 +437,19 @@
 geHeight
+Txt
 ;%0A%0A    p
@@ -817,19 +817,17 @@
  zhihuIm
-age
+g
  = (Imag
@@ -882,16 +882,19 @@
 ageWidth
+Txt
  = (Text
@@ -952,16 +952,19 @@
 geHeight
+Txt
  = (Text
@@ -1009,18 +1009,14 @@
 );%0A%0A
-   
+//
     
- //
   %E7%AC%AC%E4%B8%80
@@ -1028,18 +1028,16 @@
 %E6%8E%A5Post%0A//
-  
       my
@@ -1071,16 +1071,20 @@
 le);%0A%0A//
+    
   %E7%AC%AC%E4%BA%8C%E7%A7%8D%E5%86%99%E6%B3%95:
@@ -1104,16 +1104,20 @@
 00ms.%0A//
+    
   myHand
@@ -1172,18 +1172,16 @@
 //      
-  
 %E7%AC%AC%E4%B8%89%E7%A7%8D%E5%86%99%E6%B3%95:%0A/
@@ -1181,18 +1181,16 @@
 %E4%B8%89%E7%A7%8D%E5%86%99%E6%B3%95:%0A//
-  
       %E4%BC%98%E5%8C%96
@@ -1492,16 +1492,19 @@
 ageWidth
+Txt
 .setText
@@ -1518,35 +1518,33 @@
  : w=%22 + zhihuIm
-age
+g
 .getWidth());%0A  
@@ -1560,16 +1560,19 @@
 geHeight
+Txt
 .setText
@@ -1594,19 +1594,17 @@
  zhihuIm
-age
+g
 .getWidt

update MainActivity code style