[Nook Color Android Development] atomclock:
A subtle issue that started with CM - 37

There was a change going from 36 to37 which has caused a problem with StaticLayout.

The problem occurs when using StaticLayout with large strings. The problem is that it takes about 10 times longer to run than it used to take.

The version that now has a problem is

public StaticLayout (CharSequence source, int bufstart, int bufend, TextPaint paint, int outerwidth, Layout.Alignment align, float spacingmult, float spacingadd, boolean includepad)

The other version of StaticLayout still works fine and can be used to substitute the previous version by using a substring in place of the CharSequence. The problem is that the result from the StaticLayout command isn't identical and this version is a little bit slower than the previous version when it is working correctly.

public StaticLayout (CharSequence source, TextPaint paint, int width, Layout.Alignment align, float spacingmult, float spacingadd, boolean includepad)

I have written some code to expose the problem.

//*********************************************************************

public class Expose extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

//163 characters

String Temp = "aaaaaa bbbbbbb ccccccccc dddddddddd eeeeeeeeeee ffffffffffffff gggggggggggggg hhhhhhhhhhhhhh iiiiiiiiiii jjjjjjjjjjjj kkkkkkkkkk lllllllllll mmmmmmmmmmm nnnnnnnnn";

String Text = Temp;

for(int i=0;i<13;i++)

{

Text += Text;

}

DisplayMetrics metrics = new DisplayMetrics();

Display display = getWindowManager().getDefaultDisplay();

display.getMetrics(metrics);

int iScreenHeight;

int iScreenWidth = display.getWidth();

if(metrics.densityDpi == DisplayMetrics.DENSITY_HIGH) iScreenHeight = display.getHeight()-2*48;

else if(metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM) iScreenHeight = display.getHeight()-2*32;

else iScreenHeight = display.getHeight()-2*24;

Bitmap bitmap = Bitmap.createBitmap(iScreenWidth, iScreenHeight, Bitmap.Config.ARGB_8888);

Paint paint = new Paint();

Canvas canvas = new Canvas(bitmap);

TextPaint MyTextPaint = new TextPaint();

paint.setTextSize(30);

paint.setTypeface(Typeface.SANS_SERIF);

paint.setTextAlign(Paint.Align.LEFT);

paint.setAntiAlias(true);

paint.setColor(Color.WHITE);

canvas.drawRect(0, 0, iScreenWidth,iScreenHeight, paint);

paint.setColor(Color.BLACK);

MyTextPaint.set(paint);

// This Takes 10 Seconds to run on CM7 - 37 and later but is instant on CM - 36 and below, stock Nook Color and emulator

// NOTE: this only manifests with very large strings

//StaticLayout layout = new StaticLayout(Text, Text.length()-2000, Text.length(), MyTextPaint, iScreenWidth,Layout.Alignment.ALIGN_NORMAL, 0, 32, false);

// This is still fast on all versions. But this is still slower than the other version when it is working correctly.

StaticLayout layout = new StaticLayout(Text.substring(Text.length()-2000, Text.length()), MyTextPaint, iScreenWidth,Layout.Alignment.ALIGN_NORMAL, 0, 32, false);

canvas.translate(0, 0);

layout.draw(canvas);

((ImageView) findViewById(R.id.DrawArea)).setImageBitmap(bitmap);

}

}

//*********************************************************************

This seemed like the right place to post this but... If it isn't the correct place then please direct me to the correct place and I will repost there.

Thanks a lot.

P.S. CM7 Is really great!!!