/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.me.androiddemo; import android.app.Activity; import android.os.Bundle; import android.net.TrafficStats; import android.graphics.Paint; import android.graphics.Bitmap; import android.graphics.Canvas; import android.widget.ImageView; import android.widget.TextView; import org.library.*; /** * * @author Drew */ public class MainActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); // ToDo add your GUI initialization code here setContentView(R.layout.main); /** String test = libfunc.getMessage(); **/ } public static Bitmap textAsBitmap(String text, float textSize, int textColor) { Paint paint = new Paint(1); paint.setTextSize(textSize); paint.setColor(textColor); paint.setTextAlign(Paint.Align.LEFT); float baseline = -paint.ascent(); int width = (int) (paint.measureText(text) + 0.0f); int height = (int) (baseline + paint.descent() + 0.0f); int trueWidth = width; if (width > height) height = width; else width = height; Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(image); canvas.drawText(text, width/2-trueWidth/2, baseline, paint); return image; } TrafficStats ts = new TrafficStats(); long total_data = ts.getMobileRxBytes() + ts.getMobileTxBytes(); String data_text = "Total usage: " + total_data + " bytes."; Bitmap oimage = textAsBitmap(data_text, 10, -16777216); TextView tview = (TextView) findViewById(R.id.tv1); tview.setText(data_text); ImageView iview = (ImageView) findViewById(R.id.iv1); iview.setImageBitmap(oimage); }