Android Open Source - 4est Dbg






From Project

Back to project page 4est.

License

The source code is released under:

MIT License

If you think the Android project 4est listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.wordsaretoys.rise.utility;
//from   w  w  w. j  a va  2  s.  c om
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

/**
 * debug display wrapper
 */
public class Dbg {

  HashMap<String, StringBuffer> map;
  String[] keys;
  TextView debugView;
  Handler handler;
  
  public Dbg(Context context, int id) {
    Activity main  = (Activity) context;

    map = new HashMap<String, StringBuffer>();
    keys = new String[1];
    
    debugView = (TextView) main.findViewById(id);
    handler = new Handler(new Handler.Callback() {
      
      StringBuffer text = new StringBuffer();
      String[] keys = new String[16];

      @Override
      public boolean handleMessage(Message msg) {
        text.setLength(0);
        map.keySet().toArray(keys);
        for (int i = 0; i < map.size(); i++) {
          text.append(keys[i]).append(": ");
          text.append(map.get(keys[i])).append('\n');
          
        }

        // always show memory status
        text.append("free: ").append(Runtime.getRuntime().freeMemory()).append(' ');
        text.append("heap: ").append(Runtime.getRuntime().totalMemory()).append('\n');
        
        debugView.setText(text);
        handler.sendEmptyMessageDelayed(0, 250);
        return false;
      }
    });
    handler.sendEmptyMessage(0);
  }
  
  private StringBuffer find(String key) {
    StringBuffer sb = map.get(key);
    if (sb == null) {
      sb = new StringBuffer();
      map.put(key, sb);
    }
    return sb;
  }
  
  public synchronized void set(String key, String s) {
    StringBuffer sb = find(key);
    sb.setLength(0);
    sb.append(s);
  }

  public synchronized void set(String key, float f) {
    StringBuffer sb = find(key);
    sb.setLength(0);
    sb.append(f);
  }

  public synchronized void set(String key, int i) {
    StringBuffer sb = find(key);
    sb.setLength(0);
    sb.append(i);
  }

  public synchronized void set(String key, float f, float n) {
    StringBuffer sb = find(key);
    sb.setLength(0);
    f = (float)(Math.floor(f * n) / n);
    sb.append(f);
  }

  public synchronized void set(String key, float x, float y, float z, float n) {
    StringBuffer sb = find(key);
    sb.setLength(0);
    x = (float)(Math.floor(x * n) / n);
    y = (float)(Math.floor(y * n) / n);
    z = (float)(Math.floor(z * n) / n);
    sb.append(x).append(",").append(y).append(",").append(z);
  }
}




Java Source Code List

com.wordsaretoys.forest.Audio.java
com.wordsaretoys.forest.Debris.java
com.wordsaretoys.forest.Game.java
com.wordsaretoys.forest.GlView.java
com.wordsaretoys.forest.MainActivity.java
com.wordsaretoys.forest.Map.java
com.wordsaretoys.forest.Player.java
com.wordsaretoys.forest.Render.java
com.wordsaretoys.forest.Rotors.java
com.wordsaretoys.forest.Shared.java
com.wordsaretoys.forest.Skybox.java
com.wordsaretoys.rise.geometry.Camera.java
com.wordsaretoys.rise.geometry.Geom.java
com.wordsaretoys.rise.geometry.Mote.java
com.wordsaretoys.rise.geometry.Ortho.java
com.wordsaretoys.rise.geometry.Quaternion.java
com.wordsaretoys.rise.geometry.Vector.java
com.wordsaretoys.rise.glwrapper.Mesh.java
com.wordsaretoys.rise.glwrapper.Shader.java
com.wordsaretoys.rise.glwrapper.Texture.java
com.wordsaretoys.rise.meshutil.HeightMapper.java
com.wordsaretoys.rise.meshutil.IndexBuffer.java
com.wordsaretoys.rise.meshutil.SurfaceMapper.java
com.wordsaretoys.rise.meshutil.VertexBuffer.java
com.wordsaretoys.rise.meshutil.Vindexer.java
com.wordsaretoys.rise.pattern.Bitmap.java
com.wordsaretoys.rise.pattern.F2FSumMap.java
com.wordsaretoys.rise.pattern.I2FCutMap.java
com.wordsaretoys.rise.pattern.I2FMap.java
com.wordsaretoys.rise.pattern.I2IMap.java
com.wordsaretoys.rise.pattern.Pattern.java
com.wordsaretoys.rise.pattern.Ring.java
com.wordsaretoys.rise.utility.Asset.java
com.wordsaretoys.rise.utility.Board.java
com.wordsaretoys.rise.utility.Dbg.java
com.wordsaretoys.rise.utility.Interval.java
com.wordsaretoys.rise.utility.Misc.java
com.wordsaretoys.rise.utility.Needle.java