<commit_before>package com.nostra13.universalimageloader.core.download.handlers;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.image.SimpleTextImage;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

/**
 * Renderer for text on a coloured background. Nice and simple image to mimic the way
 * that Gmail shows initials of people in a list without an image
 *
 * @author <NAME>
 * @project UniversalImageLoader
 */
public class TextSchemeHandler extends SchemeHandler
{
	@Override
	public InputStream getStreamForPath(Context context, String path, Object optionForDownloader, int connectTimeout, int readTimeout)
	{
		SimpleTextImage image = new SimpleTextImage();
		image.fromUrl(path);
		TextView textView = getTextView(context);
		String text = image.getText();
		textView.setText(image.isUsingInitials() ? image.getInitials() : text);
		textView.setBackgroundColor(image.getColour());
		switch (image.getTypeFace())
		{
			case SimpleTextImage.TYPEFACE_MONOSPACE:
				textView.setTypeface(Typeface.MONOSPACE);
				break;

			case SimpleTextImage.TYPEFACE_CONDENSED:
				textView.setTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL));
				break;

			case SimpleTextImage.TYPEFACE_THIN:
				textView.setTypeface(Typeface.create("sans-serif-thin", Typeface.SANS_SERIF.getStyle()));
				break;
		}
		Drawable bgDrawable = textView.getBackground();
		Bitmap bitmap = Bitmap.createBitmap(384, 384, Bitmap.Config.ARGB_8888);
		Canvas canvas = new Canvas(bitmap);
		bgDrawable.draw(canvas);
		textView.draw(canvas);
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		bitmap.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
		byte[] bitmapdata = bos.toByteArray();
		return new ByteArrayInputStream(bitmapdata);
	}

	private TextView getTextView(Context context)
	{
		TextView textView = new TextView(context);
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
		params.gravity = Gravity.CENTER;
		textView.setLayoutParams(params);
		textView.setGravity(Gravity.CENTER);
		textView.setPadding(16, 46, 16, 16);
		textView.layout(0, 0, 384, 384);
		textView.requestLayout();
		textView.setTextSize(68);
		textView.setTextColor(Color.WHITE);
		return textView;
	}
}<commit_msg>Fix for text scaling in simple text image<commit_after>package com.nostra13.universalimageloader.core.download.handlers;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.image.SimpleTextImage;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

/**
 * Renderer for text on a coloured background. Nice and simple image to mimic the way
 * that Gmail shows initials of people in a list without an image
 *
 * @author <NAME>
 * @project UniversalImageLoader
 */
public class TextSchemeHandler extends SchemeHandler
{
	@Override
	public InputStream getStreamForPath(Context context, String path, Object optionForDownloader, int connectTimeout, int readTimeout)
	{
		SimpleTextImage image = new SimpleTextImage();
		image.fromUrl(path);
		TextView textView = getTextView(context);
		String text = image.getText();
		textView.setText(image.isUsingInitials() ? image.getInitials() : text);
		textView.setBackgroundColor(image.getColour());
		switch (image.getTypeFace())
		{
			case SimpleTextImage.TYPEFACE_MONOSPACE:
				textView.setTypeface(Typeface.MONOSPACE);
				break;

			case SimpleTextImage.TYPEFACE_CONDENSED:
				textView.setTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL));
				break;

			case SimpleTextImage.TYPEFACE_THIN:
				textView.setTypeface(Typeface.create("sans-serif-thin", Typeface.SANS_SERIF.getStyle()));
				break;
		}
		Drawable bgDrawable = textView.getBackground();
		Bitmap bitmap = Bitmap.createBitmap(384, 384, Bitmap.Config.ARGB_8888);
		Canvas canvas = new Canvas(bitmap);
		bgDrawable.draw(canvas);
		textView.draw(canvas);
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		bitmap.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
		byte[] bitmapdata = bos.toByteArray();
		return new ByteArrayInputStream(bitmapdata);
	}

	private TextView getTextView(Context context)
	{
		TextView textView = new TextView(context);
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
		params.gravity = Gravity.CENTER;
		textView.setLayoutParams(params);
		textView.setGravity(Gravity.CENTER);
		textView.layout(0, 0, 384, 384);
		textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, 220);
		textView.requestLayout();
		textView.setPadding(16, 46, 16, 16);
		textView.setTextColor(Color.WHITE);
		return textView;
	}
}
{'fraction_non_alphanumeric': 0.10256884124930697, 'fraction_numerical': 0.012382184439105525, 'mean_word_length': 5.714640198511166, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4945777', 'n_tokens_mistral': 1807, 'n_tokens_neox': 1627, 'n_words': 346}