Adding DeviceScreeenInfo

This commit is contained in:
2025-02-23 12:38:13 -05:00
parent 0f4d184922
commit 99f7061a9f
11 changed files with 132 additions and 15 deletions

View File

@@ -5,7 +5,7 @@ using Navigator.Services;
using Navigator.Views;
using MarketData.Service;
using Navigator.Utils;
/*
namespace Navigator
{
public partial class App : Application
@@ -15,6 +15,7 @@ namespace Navigator
{
InitializeComponent();
DependencyService.Register<MockDataStore>();
DependencyService.Register<DeviceScreenInfo>();
if(!DesignMode.IsDesignModeEnabled)
{
if(MarketDataServiceClient.IsWiFiNetwork())MarketDataServiceClient.GetInstance().SetUrl(AppSettingsManager.Settings["Service_Local"],AppSettingsManager.Settings["ServiceUser"]);
@@ -36,3 +37,4 @@ namespace Navigator
}
}
}
*/

View File

@@ -5,6 +5,7 @@ using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Navigator.Droid;
using Android.Views.InputMethods;
using Android.Util;
[assembly: ExportRenderer(typeof(EntryWithCustomKeyboardReturnButton), typeof(EntryWithCustomKeyboardReturnButtonCustomRenderer))]
@@ -19,7 +20,7 @@ namespace Navigator.Droid
{
base.OnElementChanged(e);
var customEntry = Element as EntryWithCustomKeyboardReturnButton;
var customEntry = Element as EntryWithCustomKeyboardReturnButton;
if (Control != null && customEntry != null)
{

View File

@@ -1,5 +1,4 @@

using Android.App;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.OS;

View File

@@ -14,6 +14,8 @@ namespace Navigator
{
InitializeComponent();
DependencyService.Register<MockDataStore>();
DependencyService.Register<DeviceScreenInfo>();
InitializeConnection();
MainPage = new MainPage();

View File

@@ -12,6 +12,8 @@ namespace Navigator.Core
{
public IDataStore<Item> DataStore => DependencyService.Get<IDataStore<Item>>();
public IDeviceScreenInfo DeviceScreenInfo => DependencyService.Get<IDeviceScreenInfo>();
bool isBusy = false;
public bool IsBusy
{
@@ -20,12 +22,37 @@ namespace Navigator.Core
}
string title = string.Empty;
public string Title
{
get { return title; }
set { SetProperty(ref title, value); }
}
public bool IsDeviceTablet
{
get
{
return DeviceScreenInfo.IsDeviceTablet();
}
}
public double ScreenWidth
{
get
{
return DeviceScreenInfo.GetScreenDimensions().Width;
}
}
public double ScreenHeight
{
get
{
return DeviceScreenInfo.GetScreenDimensions().Height;
}
}
protected bool SetProperty<T>(ref T backingStore, T value,[CallerMemberName] string propertyName = "",Action onChanged = null)
{
if (EqualityComparer<T>.Default.Equals(backingStore, value))return false;
@@ -36,6 +63,7 @@ namespace Navigator.Core
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
var changed = PropertyChanged;

View File

@@ -0,0 +1,17 @@
using Xamarin.Essentials;
namespace Navigator.Services
{
public class DeviceScreenInfo : IDeviceScreenInfo
{
public (double Width, double Height) GetScreenDimensions()
{
return (DeviceDisplay.MainDisplayInfo.Width, DeviceDisplay.MainDisplayInfo.Height);
}
public bool IsDeviceTablet()
{
return DeviceInfo.Idiom.Equals(DeviceIdiom.Tablet);
}
}
}

View File

@@ -0,0 +1,11 @@

namespace Navigator.Services
{
public interface IDeviceScreenInfo
{
(double Width, double Height) GetScreenDimensions();
bool IsDeviceTablet();
}
}

View File

@@ -4,11 +4,8 @@ using System.IO.Compression;
using System.IO;
using System.Globalization;
using System.Linq;
using Microsoft.Win32;
using System.Diagnostics;
using System.Collections.Generic;
using Navigator.MarketDataModel;
//using MarketData.MarketDataModel;
namespace Navigator.Utils
{
@@ -29,6 +26,7 @@ namespace Navigator.Utils
}
return sb.ToString() + str;
}
public static String RemoveHtml(String strItem)
{
String[] codes = { "&#x27;","&#187;" };
@@ -39,6 +37,7 @@ namespace Navigator.Utils
}
return strItem;
}
public static String RemoveDivs(String strItem)
{
StringBuilder sb=new StringBuilder();
@@ -53,6 +52,7 @@ namespace Navigator.Utils
}
return sb.ToString();
}
public static String BetweenString(String strItem, String strBegin, String strEnd)
{
if (null == strItem) return null;
@@ -74,6 +74,7 @@ namespace Navigator.Utils
}
return sb.ToString();
}
public static String RemoveAfter(String strItem, char charItem)
{
StringBuilder sb = new StringBuilder();
@@ -85,10 +86,12 @@ namespace Navigator.Utils
}
return sb.ToString();
}
public static bool OutOfRange(double value)
{
return value > 100000000000000000000.00 || value< -99999999999999999999.99;
}
public static String RemoveControlChars(String strItem)
{
StringBuilder sb=new StringBuilder();
@@ -99,6 +102,7 @@ namespace Navigator.Utils
}
return sb.ToString();
}
public static String GetPath(String strPathFileName)
{
int index=strPathFileName.LastIndexOf('\\');
@@ -106,18 +110,21 @@ namespace Navigator.Utils
String strPath = strPathFileName.Substring(0, index);
return strPath;
}
public static String KeepBefore(String strItem,String strKeepBefore)
{
int startPos=strItem.IndexOf(strKeepBefore);
if(-1==startPos)return null;
return strItem.Substring(0,startPos);
}
public static String KeepAfter(String strItem,String strKeepAfter)
{
int startPos=strItem.IndexOf(strKeepAfter);
if(-1==startPos)return null;
return strItem.Substring(startPos+strKeepAfter.Length);
}
public static String KeepAfterLast(String strItem,String strKeepAfter)
{
if(null==strItem)return null;
@@ -125,6 +132,7 @@ namespace Navigator.Utils
if(-1==startPos)return null;
return strItem.Substring(startPos+strKeepAfter.Length);
}
public static String Find(String strItem,String search,char delimeter)
{
if(null==strItem)return null;
@@ -146,6 +154,7 @@ namespace Navigator.Utils
if(!foundDelimeter)return null;
return sb.ToString();
}
public static String FindFirst(String strItem,String search,char delimeter)
{
if(null==strItem)return null;
@@ -167,10 +176,12 @@ namespace Navigator.Utils
if(!foundDelimeter)return null;
return sb.ToString();
}
public static String AddQuotes(String item)
{
return "\"" + item + "\"";
}
public static long DateToLong(DateTime date)
{
int year = date.Year;
@@ -178,6 +189,7 @@ namespace Navigator.Utils
int day = date.Day;
return (year * 10000) + (month * 100) + day;
}
public static DateTime LongToDate(long longDate)
{
int year = (int)(longDate / 10000);
@@ -185,41 +197,49 @@ namespace Navigator.Utils
int day = (int)(longDate - ((int)(longDate / 100)) * 100);
return new DateTime(year, month, day);
}
public static String DateTimeToStringHHMMSS(DateTime dateTime)
{
if (Utility.IsEpoch(dateTime)) return "";
return dateTime.ToString("HH:mm:ss");
}
public static String DateTimeToStringMMSDDSYYYY(DateTime dateTime)
{
if (Utility.IsEpoch(dateTime)) return "";
return dateTime.ToString("MM/dd/yyyy");
}
public static String DateTimeToStringMMSDDSYYYYHHMMSS(DateTime dateTime)
{
if (Utility.IsEpoch(dateTime)) return "";
return dateTime.ToString("MM/dd/yyyy hh:mm:ss");
}
public static String DateTimeToStringMMHDDHYYYY(DateTime dateTime)
{
if (Utility.IsEpoch(dateTime)) return "";
return dateTime.ToString("MM-dd-yyyy");
}
public static String DateTimeToStringYYYYHMMHDD(DateTime dateTime)
{
if (Utility.IsEpoch(dateTime)) return "";
return dateTime.ToString("yyyy-MM-dd");
}
public static String DateTimeToStringYYYYHMMHDDHHMMSS(DateTime dateTime)
{
if (Utility.IsEpoch(dateTime)) return "";
return dateTime.ToString("yyyy-MM-dd HH:MM:ss");
}
public static String DateTimeToStringYYYYMMDD(DateTime dateTime)
{
if (Utility.IsEpoch(dateTime)) return "";
return dateTime.ToString("yyyyMMdd");
}
public static String AsteriskForString(String str)
{
StringBuilder sb = new StringBuilder();
@@ -227,6 +247,7 @@ namespace Navigator.Utils
for (int index = 0; index < length; index++) sb.Append("*");
return sb.ToString();
}
public static String FormatNumber(double number)
{
StringBuilder sb=new StringBuilder();
@@ -234,6 +255,7 @@ namespace Navigator.Utils
else sb.Append(String.Format("{0:0.000}", number));
return sb.ToString();
}
public static String FormatNumber(double number,int places,bool commas=false)
{
StringBuilder sb = new StringBuilder();
@@ -247,6 +269,7 @@ namespace Navigator.Utils
else sb.Append(String.Format(formatString.ToString(), number));
return sb.ToString();
}
public static String FormatCurrency(double number)
{
StringBuilder sb=new StringBuilder();
@@ -254,6 +277,7 @@ namespace Navigator.Utils
else sb.Append(String.Format("{0:C}", number));
return sb.ToString();
}
public static String FormatCurrency(double number,int decimals)
{
StringBuilder sb=new StringBuilder();
@@ -262,6 +286,7 @@ namespace Navigator.Utils
else sb.Append(String.Format(currencyFormat, number));
return sb.ToString();
}
public static String FormatPercent(double number)
{
StringBuilder sb = new StringBuilder();
@@ -269,12 +294,14 @@ namespace Navigator.Utils
else sb.Append(String.Format("{0:P}", number));
return sb.ToString();
}
public static String ConformDate(String strDate)
{
String[] elements=strDate.Split(' ');
if(elements.Length<3)return strDate;
return elements[0]+" "+elements[1]+" "+elements[2];
}
public static DateTime ParseDate(String strDate)
{
System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("en-US");
@@ -283,6 +310,7 @@ namespace Navigator.Utils
DateTime dateTime=DateTime.ParseExact(strDate, formats, new System.Globalization.CultureInfo("en-US"), DateTimeStyles.AssumeLocal);
return dateTime;
}
public static double ParsePercent(String strPercent)
{
if (null == strPercent) return double.NaN;
@@ -290,6 +318,7 @@ namespace Navigator.Utils
try { return double.Parse(strPercent)/100.00; }
catch (Exception) { return double.NaN; }
}
public static double ParseCurrency(String strNumber)
{
if (null == strNumber) return double.NaN;
@@ -302,10 +331,12 @@ namespace Navigator.Utils
try { return double.Parse(strNumber); }
catch (Exception) { return double.NaN; }
}
public static String FormatCurrencyWithQuotes(double number)
{
return AddQuotes(FormatCurrency(number));
}
public static String FormatDates(DateTime d1, DateTime d2)
{
StringBuilder sb=new StringBuilder();
@@ -313,6 +344,7 @@ namespace Navigator.Utils
sb.Append(Utility.DateTimeToStringMMSDDSYYYY(d2));
return sb.ToString();
}
public static String TrimToSpace(String strString)
{
if (null == strString) return strString;
@@ -325,22 +357,27 @@ namespace Navigator.Utils
}
return sb.ToString();
}
public static String BooleanToYesNoString(bool booleanValue)
{
return booleanValue ? "Yes" : "No";
}
public static bool IsEpoch(DateTime dateTime)
{
return dateTime.Equals(epoch);
}
public static DateTime Epoch
{
get { return epoch; }
}
public static TimeSpan OneDay
{
get{return oneDay;}
}
public static String ListToString(List<String> list,char separator=',')
{
StringBuilder sb=new StringBuilder();
@@ -352,12 +389,14 @@ namespace Navigator.Utils
}
return sb.ToString();
}
public static List<String> ToList(String items,char separator=',')
{
List<String> list = items.Split(separator).ToList<String>();
list=(from String s in list select s.Trim()).ToList<String>();
return list;
}
public static String FromList(List<String> items,String postFix=",")
{
StringBuilder sb=new StringBuilder();
@@ -368,6 +407,7 @@ namespace Navigator.Utils
}
return sb.ToString();
}
public static byte[] Compress(String strString)
{
MemoryStream outputStream = null;
@@ -387,7 +427,6 @@ namespace Navigator.Utils
}
catch (Exception)
{
// MDTrace.WriteLine(LogLevel.DEBUG,exception);
return null;
}
finally
@@ -404,6 +443,7 @@ namespace Navigator.Utils
}
}
}
public static String Decompress(byte[] compressedBytes)
{
MemoryStream compressedStream = new MemoryStream(compressedBytes);
@@ -430,7 +470,6 @@ namespace Navigator.Utils
}
catch (Exception)
{
// MDTrace.WriteLine(LogLevel.DEBUG,exception);
return null;
}
finally
@@ -452,28 +491,29 @@ namespace Navigator.Utils
}
}
}
//public static void LaunchBrowserSearch(String searchTerm)
//{
// Process.Start("https://www.google.com/search?q="+Uri.EscapeDataString(searchTerm)+"/");
//}
public static bool IsZeroOrNaN(double value)
{
return IsNaN(value)||IsZero(value);
}
private static bool IsZero(double value)
{
if(value==0.00)return true;
return false;
}
private static bool IsNaN(double value)
{
return double.IsNaN(value);
}
public static void DeleteFile(String pathFileName)
{
if(!File.Exists(pathFileName))return;
try{File.Delete(pathFileName);}catch(Exception){;}
}
private static DateTime GetRunDate(String strPathFileName)
{
DateTime runDate=DateTime.Now.Date;
@@ -512,7 +552,6 @@ namespace Navigator.Utils
}
catch(Exception)
{
// MDTrace.WriteLine(LogLevel.DEBUG,String.Format("GetRunDate:{0}",exception.ToString()));
return runDate;
}
finally

View File

@@ -4,6 +4,7 @@ using MarketData.Service;
using Navigator.Core;
using System.ComponentModel;
using Navigator.Utils;
using System.Text;
namespace Navigator.ViewModels
{
@@ -105,6 +106,21 @@ namespace Navigator.ViewModels
set{SetProperty(ref status,value);}
}
public String ScreenDimensions
{
get
{
StringBuilder sb = new StringBuilder();
sb.Append("Device (");
sb.Append(Utility.FormatNumber(ScreenWidth,0));
sb.Append("x");
sb.Append(Utility.FormatNumber(ScreenHeight,0));
sb.Append(")");
sb.Append(IsDeviceTablet?"Tablet":"Phone");
return sb.ToString();
}
}
public String IPAddress
{
get{return ipAddress;}

View File

@@ -91,6 +91,7 @@ namespace Navigator.ViewModels
ServiceResult serviceResult=null;
IsBusy=true;
ShowActivity=!IsRefreshing;
Task workerTask=Task.Factory.StartNew(()=>
{
StopLimit stopLimit=null;
@@ -136,6 +137,7 @@ namespace Navigator.ViewModels
}
ChartTitle=sb.ToString();
}
bollingerBandRenderer.DeviceIsTablet=DeviceScreenInfo.IsDeviceTablet();
bollingerBandRenderer.PortfolioTradesWithParityPrice=portfolioTradesWithParityPrice;
bollingerBandRenderer.K=BollingerBandModel.K(bollingerBands);
bollingerBandRenderer.KL1=BollingerBandModel.KL1(bollingerBands);
@@ -209,7 +211,6 @@ namespace Navigator.ViewModels
refreshCommand=new RelayCommand(param=>
{
HandleBollingerBandRequest();
// IsRefreshing=false;
},param=>{return !IsRefreshing;});
}
return refreshCommand;

View File

@@ -73,6 +73,7 @@
</Button.Behaviors>
</Button>
<Label Text="{Binding Status,Mode=TwoWay}" />
<Label Text="{Binding ScreenDimensions, Mode=OneWay}"/>
</StackLayout>
</StackLayout>
</ScrollView>