<commit_before>                                                                     
                                                                     
                                                                     
                                             
 /*****************************************************************************
  *  Copyright (c) 2011 Meta Watch Ltd.                                       *
  *  www.MetaWatch.org                                                        *
  *                                                                           *
  =============================================================================
  *                                                                           *
  *  Licensed under the Apache License, Version 2.0 (the "License");          *
  *  you may not use this file except in compliance with the License.         *
  *  You may obtain a copy of the License at                                  *
  *                                                                           *
  *    http://www.apache.org/licenses/LICENSE-2.0                             *
  *                                                                           *
  *  Unless required by applicable law or agreed to in writing, software      *
  *  distributed under the License is distributed on an "AS IS" BASIS,        *
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
  *  See the License for the specific language governing permissions and      *
  *  limitations under the License.                                           *
  *                                                                           *
  *****************************************************************************/

 /*****************************************************************************
  * Idle.java                                                                 *
  * Idle                                                                      *
  * Idle watch mode                                                           *
  *                                                                           *
  *                                                                           *
  *****************************************************************************/

package org.metawatch.manager;

import org.metawatch.manager.MetaWatchService.Preferences;
import org.metawatch.manager.Monitors.LocationData;
import org.metawatch.manager.Monitors.WeatherData;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
import android.util.Log;

public class Idle {
	
	public static byte[] overridenButtons = null;

	static Bitmap createLcdIdle(Context context) {
		Bitmap bitmap = Bitmap.createBitmap(96, 96, Bitmap.Config.RGB_565);
		Canvas canvas = new Canvas(bitmap);
		
		TextPaint paintSmall = new TextPaint();
		paintSmall.setColor(Color.BLACK);
		paintSmall.setTextSize(FontCache.instance(context).Small.size);
		paintSmall.setTypeface(FontCache.instance(context).Small.face);
		
		TextPaint paintLarge = new TextPaint();
		paintLarge.setColor(Color.BLACK);
		paintLarge.setTextSize(FontCache.instance(context).Large.size);
		paintLarge.setTypeface(FontCache.instance(context).Large.face);
		
		canvas.drawColor(Color.WHITE);
		
		canvas = drawLine(canvas, 32);		
		if(!Preferences.disableWeather) {
			if (WeatherData.received) {
				
				// icon
				Bitmap image = Utils.loadBitmapFromAssets(context, WeatherData.icon);
				canvas.drawBitmap(image, 36, 37, null);
				
				// condition
				canvas.save();
				TextPaint paint = new TextPaint(paintSmall);
				StaticLayout layout = new StaticLayout(WeatherData.condition, paint, 60, android.text.Layout.Alignment.ALIGN_NORMAL, 1.3f, 0, false);
				canvas.translate(1, 35); //position the text
				layout.draw(canvas);
				canvas.restore();								
			
				// temperatures
				if (WeatherData.celsius) {
					paintLarge.setTextAlign(Paint.Align.RIGHT);
					canvas.drawText(WeatherData.temp, 82, 46, paintLarge);
					//RM: since the degree symbol draws wrong...
					canvas.drawText("O", 82, 40, paintSmall);
					canvas.drawText("C", 95, 46, paintLarge);
				}
				else {
					paintLarge.setTextAlign(Paint.Align.RIGHT);
					canvas.drawText(WeatherData.temp, 83, 46, paintLarge);
					//RM: since the degree symbol draws wrong...
					canvas.drawText("O", 83, 40, paintSmall);
					canvas.drawText("F", 95, 46, paintLarge);
				}
				paintLarge.setTextAlign(Paint.Align.LEFT);
							
				canvas.drawText("High", 64, 54, paintSmall);
				canvas.drawText("Low", 64, 62, paintSmall);
				
				paintSmall.setTextAlign(Paint.Align.RIGHT);
				canvas.drawText(WeatherData.tempHigh, 95, 54, paintSmall);
				canvas.drawText(WeatherData.tempLow, 95, 62, paintSmall);
				paintSmall.setTextAlign(Paint.Align.LEFT);

				canvas.drawText((String) TextUtils.ellipsize(WeatherData.locationName, paintSmall, 63, TruncateAt.END), 1, 62, paintSmall);
							
			} else {
				paintSmall.setTextAlign(Paint.Align.CENTER);
				if (Preferences.weatherGeolocation) {
					if( !LocationData.received ) {
						canvas.drawText("awaiting location", 48, 50, paintSmall);
					}
					else {
						canvas.drawText("awaiting weather", 48, 50, paintSmall);
					}
				}
				else {
					canvas.drawText("no data", 48, 50, paintSmall);
				}
				paintSmall.setTextAlign(Paint.Align.LEFT);
			}
						
			// Debug current time
			//String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
			//String currentTimeString = new SimpleDateFormat("HH:mm").format(new Date());
			//canvas.drawText(currentTimeString, 0, 56, paintSmall);
			
			canvas = drawLine(canvas, 64);
		}
		
		// icons row
		//Bitmap imageI = Utils.loadBitmapFromAssets(context, "idle_icons_row.bmp");
		//canvas.drawBitmap(imageI, 0, 66, null);
				
		int rows = 3;
		/*
		if (Utils.isGmailAccessSupported(context))
			rows = 3;
		else
			rows = 2;
		*/
		int yPos = !Preferences.disableWeather ? 67 : 36;
		// icons<commit_msg>Added outline to condition and location text, so it doesn't blend into the weather icon<commit_after>                                                                     
                                                                     
                                                                     
                                             
 /*****************************************************************************
  *  Copyright (c) 2011 Meta Watch Ltd.                                       *
  *  www.MetaWatch.org                                                        *
  *                                                                           *
  =============================================================================
  *                                                                           *
  *  Licensed under the Apache License, Version 2.0 (the "License");          *
  *  you may not use this file except in compliance with the License.         *
  *  You may obtain a copy of the License at                                  *
  *                                                                           *
  *    http://www.apache.org/licenses/LICENSE-2.0                             *
  *                                                                           *
  *  Unless required by applicable law or agreed to in writing, software      *
  *  distributed under the License is distributed on an "AS IS" BASIS,        *
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
  *  See the License for the specific language governing permissions and      *
  *  limitations under the License.                                           *
  *                                                                           *
  *****************************************************************************/

 /*****************************************************************************
  * Idle.java                                                                 *
  * Idle                                                                      *
  * Idle watch mode                                                           *
  *                                                                           *
  *                                                                           *
  *****************************************************************************/

package org.metawatch.manager;

import org.metawatch.manager.MetaWatchService.Preferences;
import org.metawatch.manager.Monitors.LocationData;
import org.metawatch.manager.Monitors.WeatherData;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
import android.util.Log;

public class Idle {
	
	public static byte[] overridenButtons = null;

	static void drawWrappedText(String text, Canvas canvas, int x, int y, int width, TextPaint paint) {
		canvas.save();
		StaticLayout layout = new StaticLayout(text, paint, width, android.text.Layout.Alignment.ALIGN_NORMAL, 1.0f, 0, false);
		canvas.translate(x, y); //position the text
		layout.draw(canvas);
		canvas.restore();	
	}
	
	static void drawOutlinedText(String text, Canvas canvas, int x, int y, TextPaint col, TextPaint outline) {
		canvas.drawText(text, x+1, y, outline);
		canvas.drawText(text, x-1, y, outline);
		canvas.drawText(text, x, y+1, outline);
		canvas.drawText(text, x, y-1, outline);
	
		canvas.drawText(text, x, y, col);
	}
	
	static void drawWrappedOutlinedText(String text, Canvas canvas, int x, int y, int width, TextPaint col, TextPaint outline) {
		drawWrappedText(text, canvas, x-1, y, width, outline);
		drawWrappedText(text, canvas, x+1, y, width, outline);
		drawWrappedText(text, canvas, x, y-1, width, outline);
		drawWrappedText(text, canvas, x, y+1, width, outline);
		
		drawWrappedText(text, canvas, x, y, width, col);
	}

	static Bitmap createLcdIdle(Context context) {
		Bitmap bitmap = Bitmap.createBitmap(96, 96, Bitmap.Config.RGB_565);
		Canvas canvas = new Canvas(bitmap);
		
		TextPaint paintSmall = new TextPaint();
		paintSmall.setColor(Color.BLACK);
		paintSmall.setTextSize(FontCache.instance(context).Small.size);
		paintSmall.setTypeface(FontCache.instance(context).Small.face);
		
		TextPaint paintSmallOutline = new TextPaint();
		paintSmallOutline.setColor(Color.WHITE);
		paintSmallOutline.setTextSize(FontCache.instance(context).Small.size);
		paintSmallOutline.setTypeface(FontCache.instance(context).Small.face);
		
		TextPaint paintLarge = new TextPaint();
		paintLarge.setColor(Color.BLACK);
		paintLarge.setTextSize(FontCache.instance(context).Large.size);
		paintLarge.setTypeface(FontCache.instance(context).Large.face);
		
		canvas.drawColor(Color.WHITE);
		
		canvas = drawLine(canvas, 32);		
		if(!Preferences.disableWeather) {
			if (WeatherData.received) {
				
				//WeatherData.icon = "weather_sunny.bmp";
				//WeatherData.locationName = "a really long place name";
				//WeatherData.condition = "cloudy with a chance of meatballs";
				
				// icon
				Bitmap image = Utils.loadBitmapFromAssets(context, WeatherData.icon);
				canvas.drawBitmap(image, 36, 37, null);
				
				// condition
				drawWrappedOutlinedText(WeatherData.condition, canvas, 1, 35, 60, paintSmall, paintSmallOutline);
				
				
				// temperatures
				if (WeatherData.celsius) {
					paintLarge.setTextAlign(Paint.Align.RIGHT);
					canvas.drawText(WeatherData.temp, 82, 46, paintLarge);
					//RM: since the degree symbol draws wrong...
					canvas.drawText("O", 82, 40, paintSmall);
					canvas.drawText("C", 95, 46, paintLarge);
				}
				else {
					paintLarge.setTextAlign(Paint.Align.RIGHT);
					canvas.drawText(WeatherData.temp, 83, 46, paintLarge);
					//RM: since the degree symbol draws wrong...
					canvas.drawText("O", 83, 40, paintSmall);
					canvas.drawText("F", 95, 46, paintLarge);
				}
				paintLarge.setTextAlign(Paint.Align.LEFT);
							
				canvas.drawText("High", 64, 54, paintSmall);
				canvas.drawText("Low", 64, 62, paintSmall);
				
				paintSmall.setTextAlign(Paint.Align.RIGHT);
				canvas.drawText(WeatherData.tempHigh, 95, 54, paintSmall);
				canvas.drawText(WeatherData.tempLow, 95, 62, paintSmall);
				paintSmall.setTextAlign(Paint.Align.LEFT);

				drawOutlinedText((String) TextUtils.ellipsize(WeatherData.locationName, paintSmall, 63, TruncateAt.END), canvas, 1, 62, paintSmall, paintSmallOutline);
							
			} else {
				paintSmall.setTextAlign(Paint.Align.CENTER);
				if (Preferences.weatherGeolocation) {
					if( !LocationData.received ) {
						canvas.drawText("Awaiting location", 48, 50, paintSmall);
					}
					else {
						canvas.drawText("Awaiting weather", 48, 50, paintSmall);
					}
				}
				else {
					canvas.drawText("No data", 48, 50, paintSmall);
				}
				paintSmall.setTextAlign(Paint.Align.LEFT);
			}
						
			// Debug current time
			//String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
			//String currentTimeString = new SimpleDateFormat("HH:mm").format(new Date());
			//canvas.drawText(currentTimeString, 0, 56, paintSmall);
			
			canvas = drawLine(canvas, 64);
		}
		
		// icons row
		//Bitmap imageI = Utils.loadBitmapFromAssets(context, "idle_icons_row.bmp");
		//canvas.drawBitmap(imageI, 0, 66, null);
				
		int rows = 3;
		/*
		if (Utils.isGmailAccessSupported(context))
			rows = 3;
		else
			rows = 2;
		*/
		int yPos = !Preferences.disableWeather ? 67 : 36;
		// icons
{'fraction_non_alphanumeric': 0.15025832376578646, 'fraction_numerical': 0.015068886337543054, 'mean_word_length': 1.9653191489361703, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 82, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '230669', 'n_tokens_mistral': 4259, 'n_tokens_neox': 3439, 'n_words': 800}