[Roam-commit] SF.net SVN: roam: [122] Trunk/Source
Status: Alpha
Brought to you by:
jonfroehlich
|
From: <jon...@us...> - 2008-03-06 15:44:49
|
Revision: 122
http://roam.svn.sourceforge.net/roam/?rev=122&view=rev
Author: jonfroehlich
Date: 2008-03-06 07:44:44 -0800 (Thu, 06 Mar 2008)
Log Message:
-----------
updated utility functions
Modified Paths:
--------------
Trunk/Source/Roam/Utils/DeviceUtils.cs
Trunk/Source/Roam/Utils/PowerUtils.cs
Trunk/Source/Roam.Common/Utils/TimeUtils.cs
Trunk/Source/Roam.UI/Forms/SplashForm.cs
Trunk/Source/Roam.UI/Utils/DrawingUtils.cs
Trunk/Source/Roam.suo
Modified: Trunk/Source/Roam/Utils/DeviceUtils.cs
===================================================================
--- Trunk/Source/Roam/Utils/DeviceUtils.cs 2008-03-02 00:55:29 UTC (rev 121)
+++ Trunk/Source/Roam/Utils/DeviceUtils.cs 2008-03-06 15:44:44 UTC (rev 122)
@@ -17,6 +17,7 @@
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
+using Microsoft.WindowsMobile.Status;
namespace Roam.Utils
{
@@ -33,6 +34,13 @@
/// <author>Jon Froehlich</author>
public static class DeviceUtils
{
+ public static bool IsPhoneSilent()
+ {
+ string phoneProfile = SystemState.PhoneProfile;
+ return phoneProfile.IndexOf("Silent") != -1 ||
+ phoneProfile.IndexOf("Meeting") != -1;
+ }
+
/// <summary>
/// This function returns the amount of time, in milliseconds, that the
/// system has been idle.
Modified: Trunk/Source/Roam/Utils/PowerUtils.cs
===================================================================
--- Trunk/Source/Roam/Utils/PowerUtils.cs 2008-03-02 00:55:29 UTC (rev 121)
+++ Trunk/Source/Roam/Utils/PowerUtils.cs 2008-03-06 15:44:44 UTC (rev 122)
@@ -37,6 +37,38 @@
public const uint POWER_FORCE = 0x00001000;
public const int ERROR_SUCCESS = 0;
+ public static bool IsDeviceIdleMessage(PowerBroadcast powerBroadcast)
+ {
+ return IsDeviceIdleMessage(powerBroadcast.GetSystemPowerStateAsString());
+ }
+
+ //List of power states from http://peterfoot.net/HowToGetSystemPowerStateNameAndFlags.aspx
+ // [On] = 0x10000 // on state
+ // Off = 0x20000 // no power, full off
+ // Critical = 0x40000 // critical off
+ // Boot = 0x80000 // boot state
+ // Idle = 0x100000 // idle state
+ // Suspend = 0x200000 // suspend state
+ // Unattended = 0x400000 // Unattended state.
+ // Reset = 0x800000 // reset state
+ // UserIdle = 0x1000000 // user idle state
+ // BackLightOn = 0x2000000 // device screen backlight on
+ // Password = 0x10000000 // This state is password protected.
+ public static bool IsDeviceIdleMessage(string powerMessage)
+ {
+ //device idle messages I have seen:
+ // backlightoff
+ // screenoff
+ // useridle
+ return powerMessage.IndexOf("idle") != -1 || powerMessage.IndexOf("off") != -1;
+ }
+
+ public static bool IsDeviceCurrentlyIdle()
+ {
+ string powerStateName = PowerUtils.GetSystemPowerState().PowerStateName;
+ return IsDeviceIdleMessage(powerStateName);
+ }
+
// allows a null psState
[DllImport("coredll.dll", SetLastError = true)]
public static extern int SetSystemPowerState(IntPtr psState, PowerStateFlags flags, uint Options);
Modified: Trunk/Source/Roam.Common/Utils/TimeUtils.cs
===================================================================
--- Trunk/Source/Roam.Common/Utils/TimeUtils.cs 2008-03-02 00:55:29 UTC (rev 121)
+++ Trunk/Source/Roam.Common/Utils/TimeUtils.cs 2008-03-06 15:44:44 UTC (rev 122)
@@ -117,17 +117,45 @@
}
public static readonly DateTime UNIX_START_DATE = new DateTime(1970, 1, 1, 0, 0, 0);
+ public static readonly DateTime JAVA_START_DATE = new DateTime(1970, 1, 1, 0, 0, 0);
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="dateTime"></param>
+ /// <returns>Unix time in seconds</returns>
public static long ConvertToUnixTimeStamp(DateTime dateTime)
{
TimeSpan ts = UNIX_START_DATE - UNIX_START_DATE;
return (long)ts.TotalSeconds;
}
- public static DateTime ConvertToDateTime(long unixTimeStamp)
+ /// <summary>
+ /// Takes in unix time stamp in seconds
+ /// </summary>
+ /// <param name="unixTimeStamp"></param>
+ /// <returns></returns>
+ public static DateTime ConvertFromUnixTime(long unixTimeStamp)
{
return UNIX_START_DATE.AddSeconds(unixTimeStamp);
}
+ /// <summary>
+ /// Converts to milliseconds
+ /// </summary>
+ /// <param name="dateTime"></param>
+ /// <returns></returns>
+ public static long ConvertToJavaTimeStamp(DateTime dateTime)
+ {
+ // the starting time of Java\x92s system
+ long timeStamp = (long)((TimeSpan)(dateTime - JAVA_START_DATE)).TotalMilliseconds;
+ return timeStamp;
+ }
+
+ public static DateTime ConvertFromJavaTimeStamp(long javaTimeStamp)
+ {
+ return JAVA_START_DATE.AddMilliseconds(javaTimeStamp);
+ }
+
}
}
Modified: Trunk/Source/Roam.UI/Forms/SplashForm.cs
===================================================================
--- Trunk/Source/Roam.UI/Forms/SplashForm.cs 2008-03-02 00:55:29 UTC (rev 121)
+++ Trunk/Source/Roam.UI/Forms/SplashForm.cs 2008-03-06 15:44:44 UTC (rev 122)
@@ -30,6 +30,7 @@
using System.Diagnostics;
using Roam.Common.Utils;
using Roam.UI.Utils;
+using OpenNETCF.Windows.Forms;
namespace Roam.UI.Forms
{
@@ -43,7 +44,7 @@
public partial class SplashForm : Form, IProgress
{
#region Delegates
- private delegate void NoParamsDelegate();
+ private delegate void EmptyDelegate();
private delegate void IntParamDelegate(int i);
#endregion Delegates
@@ -56,10 +57,23 @@
private Color _logColor = Color.White;
private System.Windows.Forms.Timer _animationTimer = new System.Windows.Forms.Timer();
private MemoryAppender _memoryAppender = null;
- private NoParamsDelegate _invalidateDelegate;
+ private EmptyDelegate _invalidateDelegate;
private bool _drawAlphaLayer = true;
- private int _alphaValue = 128;
- private Color _alphaColor = Color.Black;
+ private int _overlayAlphaValue = 128;
+ private Color _overlayAlphaColor = Color.Black;
+
+ private bool _drawLog = true;
+
+ private Rectangle _overlayBounds;
+ private bool _overlayBoundsSet = false;
+
+ private bool _preferredProgressBarLocationSet = false;
+ private Point _preferredProgressBarLocation;
+
+ private bool _preferredProgressBarSizeSet = false;
+ private Size _preferredProgressBarSize;
+
+ private Point _titleLocation = new Point(2, 2);
#endregion Private Fields
public SplashForm()
@@ -91,8 +105,16 @@
/// </summary>
public Color AlphaLayerColor
{
- get { return _alphaColor; }
- set { _alphaColor = value; }
+ get { return _overlayAlphaColor; }
+ set
+ {
+ if (value != _overlayAlphaColor)
+ {
+ _overlayAlphaColor = value;
+ if (this.InvokeRequired) { this.Invoke(_invalidateDelegate); }
+ else { this.Invalidate(); }
+ }
+ }
}
/// <summary>
@@ -100,8 +122,16 @@
/// </summary>
public int AlphaValue
{
- get { return _alphaValue; }
- set { _alphaValue = value; }
+ get { return _overlayAlphaValue; }
+ set
+ {
+ if (value != _overlayAlphaValue)
+ {
+ _overlayAlphaValue = value;
+ if (this.InvokeRequired) { this.Invoke(_invalidateDelegate); }
+ else { this.Invalidate(); }
+ }
+ }
}
/// <summary>
@@ -110,7 +140,15 @@
public bool DrawAlphaLayer
{
get { return _drawAlphaLayer; }
- set { _drawAlphaLayer = value; }
+ set
+ {
+ if (value != _drawAlphaLayer)
+ {
+ _drawAlphaLayer = value;
+ if (this.InvokeRequired) { this.Invoke(_invalidateDelegate); }
+ else { this.Invalidate(); }
+ }
+ }
}
public int Maximum
@@ -118,18 +156,26 @@
get { return _progressBar.Maximum; }
set
{
- if (this.InvokeRequired)
+ if (value != _progressBar.Maximum)
{
- IntParamDelegate anonDelegate = delegate(int i) { _progressBar.Maximum = i; };
- this.Invoke(anonDelegate, value);
+ if (this.InvokeRequired)
+ {
+ IntParamDelegate anonDelegate = delegate(int i) { _progressBar.Maximum = i; };
+ this.Invoke(anonDelegate, value);
+ }
+ else
+ {
+ _progressBar.Maximum = value;
+ }
}
- else
- {
- _progressBar.Maximum = value;
- }
}
}
+ public ProgressBar2 ProgressBar
+ {
+ get { return _progressBar; }
+ }
+
public int Minimum
{
get { return _progressBar.Minimum; }
@@ -192,11 +238,87 @@
if (_strTitle != value)
{
_strTitle = value;
- this.Invalidate();
+ if (this.InvokeRequired) { this.Invoke(_invalidateDelegate); }
+ else { this.Invalidate(); }
}
}
}
+ public Point TitleLocation
+ {
+ get
+ {
+ return _titleLocation;
+ }
+ set
+ {
+ if (_titleLocation != value)
+ {
+ _titleLocation = value;
+ if (this.InvokeRequired) { this.Invoke(_invalidateDelegate); }
+ else { this.Invalidate(); }
+ }
+ }
+ }
+
+ public Rectangle OverlayBounds
+ {
+ get
+ {
+ return _overlayBoundsSet ? _overlayBounds :
+ new Rectangle(30, 80, this.ClientRectangle.Width - 60,
+ this.ClientRectangle.Height - 110);
+ }
+ set
+ {
+ _overlayBoundsSet = true;
+ if (value != _overlayBounds)
+ {
+ _overlayBounds = value;
+ if (this.InvokeRequired) { this.Invoke(_invalidateDelegate); }
+ else { this.Invalidate(); }
+ }
+ }
+ }
+
+ public Point PreferredProgressBarLocation
+ {
+ get
+ {
+ return _preferredProgressBarLocationSet ? _preferredProgressBarLocation :
+ new Point(30, 50);
+ }
+ set
+ {
+ _preferredProgressBarLocationSet = true;
+ if (value != _preferredProgressBarLocation)
+ {
+ _preferredProgressBarLocation = value;
+ if (this.InvokeRequired) { this.Invoke(_invalidateDelegate); }
+ else { this.Invalidate(); }
+ }
+ }
+ }
+
+ public Size PreferredProgressBarSize
+ {
+ get
+ {
+ return _preferredProgressBarSizeSet ? _preferredProgressBarSize :
+ new Size(this.ClientRectangle.Width - 60, _progressBar.Height);
+ }
+ set
+ {
+ _preferredProgressBarSizeSet = true;
+ if (value != _preferredProgressBarSize)
+ {
+ _preferredProgressBarSize = value;
+ if (this.InvokeRequired) { this.Invoke(_invalidateDelegate); }
+ else { this.Invalidate(); }
+ }
+ }
+ }
+
//public String Log
//{
// get
@@ -231,14 +353,8 @@
if (_logFont != value)
{
_logFont = value;
- if (this.InvokeRequired)
- {
- this.Invoke(_invalidateDelegate);
- }
- else
- {
- this.Invalidate();
- }
+ if (this.InvokeRequired) { this.Invoke(_invalidateDelegate); }
+ else { this.Invalidate(); }
}
}
}
@@ -315,12 +431,13 @@
protected virtual void UpdateLayout(Graphics g)
{
- Point preferredProgressBarLocation = new Point(30, 50);
- Size preferredProgressBarSize = new Size(this.ClientRectangle.Width - 60, _progressBar.Height);
+ Point preferredProgressBarLocation = PreferredProgressBarLocation;
+ Size preferredProgressBarSize = PreferredProgressBarSize;
if (_progressBar.Location != preferredProgressBarLocation)
{
_progressBar.Location = preferredProgressBarLocation;
}
+
if (_progressBar.Size != preferredProgressBarSize)
{
_progressBar.Size = preferredProgressBarSize;
@@ -350,10 +467,6 @@
Brush backBrush = new SolidBrush(this.BackColor);
g.FillRectangle(backBrush, this.ClientRectangle);
- //draw the title
- Brush frontBrush = new SolidBrush(this.ForeColor);
- g.DrawString(Title, this.Font, frontBrush, 2, 2);
-
//draw image
IntPtr hDC = g.GetHdc();
RECT rc = RECT.FromXYWH(0, 0, ClientRectangle.Width, ClientRectangle.Height);
@@ -364,28 +477,34 @@
g.ReleaseHdc(hDC);
//draw the translucent overlay
- Rectangle overlayBounds = new Rectangle(30, 80, this.ClientRectangle.Width - 60,
- this.ClientRectangle.Height - 110);
+ Rectangle overlayBounds = OverlayBounds;
if (_drawAlphaLayer)
{
- DrawTranslucentLayer(_bmpOffScreen, overlayBounds, _alphaColor, _alphaValue);
+ DrawTranslucentLayer(_bmpOffScreen, overlayBounds, _overlayAlphaColor, _overlayAlphaValue);
}
- //draw log
+ //draw the title
+ Brush frontBrush = new SolidBrush(this.ForeColor);
+ g.DrawString(Title, this.Font, frontBrush, _titleLocation.X, _titleLocation.Y);
+
+ //draw log, be aware that we set the clip here.
Brush logFontBrush = new SolidBrush(_logColor);
- StringBuilder sb = new StringBuilder(_logBuffer.Count);
- foreach (String str in _logBuffer)
+ if (_drawLog)
{
- sb.Append(str);
+ StringBuilder sb = new StringBuilder(_logBuffer.Count);
+ foreach (String str in _logBuffer)
+ {
+ sb.Append(str);
+ }
+ String strLog = sb.ToString();
+ SizeF textBounds = g.MeasureString(strLog, _logFont);
+ RectangleF textDrawArea = new RectangleF(overlayBounds.X,
+ overlayBounds.Y + overlayBounds.Height - textBounds.Height,
+ overlayBounds.Width, textBounds.Height);
+ g.Clip = new Region(overlayBounds);
+ g.DrawString(strLog, _logFont, logFontBrush, textDrawArea);
}
- String strLog = sb.ToString();
- SizeF textBounds = g.MeasureString(strLog, _logFont);
- RectangleF textDrawArea = new RectangleF(overlayBounds.X,
- overlayBounds.Y + overlayBounds.Height - textBounds.Height,
- overlayBounds.Width, textBounds.Height);
- g.Clip = new Region(overlayBounds);
- g.DrawString(strLog, _logFont, logFontBrush, textDrawArea);
-
+
pe.Graphics.DrawImage(_bmpOffScreen, 0, 0);
//cleanup
@@ -468,7 +587,7 @@
{
if (InvokeRequired)
{
- NoParamsDelegate performStepDelegate = PerformStep;
+ EmptyDelegate performStepDelegate = PerformStep;
this.Invoke(performStepDelegate);
}
else
Modified: Trunk/Source/Roam.UI/Utils/DrawingUtils.cs
===================================================================
--- Trunk/Source/Roam.UI/Utils/DrawingUtils.cs 2008-03-02 00:55:29 UTC (rev 121)
+++ Trunk/Source/Roam.UI/Utils/DrawingUtils.cs 2008-03-06 15:44:44 UTC (rev 122)
@@ -305,10 +305,16 @@
return ret == 0 ? false : true;
}
- private static Control _control = new Control();
+ private static Control _control = null;
public static SizeF MeasureString(string s, Font font)
{
SizeF sizeText;
+
+ if (_control == null)
+ {
+ _control = new Control();
+ }
+
lock (_control)
{
Graphics g = _control.CreateGraphics();
Modified: Trunk/Source/Roam.suo
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|