I was looking into ways to localize an application. I saw this example: http://msdn.microsoft.com/en-us/library/ff637520(v=vs.92).aspx but I was wondering if it would be possible to use a different language than the one the user sets on his phone. Let's say that the user sets his language to English, but I want my app to display an interface in spanish if the user chooses so using some listbox.
Do you have any articles regarding this?
Thanks!
It is possible and I do it with my Google Reader client gReadie using the following code, which I call on application start and resume.
public static void SetLanguage() {
CultureInfo c = null;
switch (ViewModel.UserSettings.Language) {
case Language.Default:
break;
case Language.English:
c = new CultureInfo("en-US");
break;
case Language.Chinese:
c = new CultureInfo("zh-CN");
break;
case Language.French:
c = new CultureInfo("fr-FR");
break;
case Language.German:
c = new CultureInfo("de-DE");
break;
}
if (c != null) {
Thread.CurrentThread.CurrentUICulture = c;
ApplicationStrings.Culture = c;
}
}
So basically I have a dropdown in my settings which is bound to a languge enum and allows the user to choose their phone language (default) or one of the supported lanaguages.
Then on app start I set the language of the UI thread and of my ApplicationStrings resource file to match their selection.
Related
i am new to WIA. And i have been asked to make scaning service scan faster and duplex. My current service scan one page, then put it in pdf and so on untill there is less then 20 pages(this number just a crutch used before me, will be glad if someone explane how to get "if there is any paper in there" variable). I started to dig and found docs on MSDN describing properties and after found this post describing duplex sanning, but with mysterious 5 in set. After I found this and figured out what i need WIA_DPS_DOCUMENT_HANDLING_SELECT to set to 0x205(FEEDER + DUPLEX + AUTO_ADVANCE). So I tried to setup them like this:
private static void SetProperty(Property property, int value)
{
IProperty x = (IProperty)property;
Object val = value;
x.set_Value(ref val);
}
...some code...
foreach (Property prop in device.Properties)
{
//LOGGER.Warn(prop.Name);
//LOGGER.Warn(prop.PropertyID);
switch ((Int32)prop.PropertyID)
{
// Document Handling Select
case 3088:
SetProperty(prop, 517);
break;
// Pages
case 3096:
SetProperty(prop, 1);
break;
}
}
And it did't worked for me... It just stuck on setting... Can Somebody explain how to setup AUTO_ADVANCE and DUPLEX props? Or maybe "make scanning faster and duplex" need something more then just AUTO_ADVANCE and DUPLEX and my perception about them is wrong? Or I should considering "ISIS / TWAIN (Windows XP / Vista / 7 / 8 / 8.1 / 10)" string in my scan description and use other libraries?
(Window 10, Canon DR-M160||, DR-M160 & DR-M160II Driver for Windows)
and also here is the current fetch function:
public List<ImageFile> FetchImageList()
{
List<ImageFile> imageList = new List<ImageFile>();
//bool hasMorePages = true;
int testcount = 0;
while (testcount >= 0)
{
testcount--;
WIA.Device device = FindDevice(_deviceId);
if (device == null)
{
LOGGER.Warn("Scanner device not found");
return null;
}
// get item
WIA.Item scanItem = device.Items[1] as WIA.Item;
LOGGER.Debug($"ScanItem: {scanItem.ItemID}");
try
{
foreach (Property prop in device.Properties)
{
//LOGGER.Warn(prop.Name);
//LOGGER.Warn(prop.PropertyID);
switch ((Int32)prop.PropertyID)
{
// Document Handling Select
case 3088:
LOGGER.Warn("here");
SetProperty(prop, 517);
LOGGER.Warn("here");
break;
// Pages
case 3096:
SetProperty(prop, 1);
break;
}
}
// scan image
WIA.ICommonDialog wiaCommonDialog = new WIA.CommonDialog();
WIA.ImageFile image = (WIA.ImageFile)scanItem.Transfer(WIA.FormatID.wiaFormatPNG);
imageList.Add(image);
LOGGER.Warn("Front");
//get back side
image = (WIA.ImageFile)scanItem.Transfer(WIA.FormatID.wiaFormatPNG);
imageList.Add(image);
LOGGER.Warn("Back");
}
catch (Exception e)
{
throw (e);
}
}
return imageList;
}
Well... I tried to make duplex scan without AUTO_ADVANCE and got HRESULT: 0x8000FFFF (E_UNEXPECTED) on Transfer call. According to this post(even though that was on Windows 7) I guess there is no way to solve this for me by using WIA, still hope there will other suggestions...
Solved problem
I used saraff.twain and it worked for me:
- git page :https://github.com/saraff-9EB1047A4BEB4cef8506B29BA325BD5A/Saraff.Twain.NET
good library with grate wiki page.(Also have similar library for .net 4.6.1)
I currently am porting one of my libraries to Windows Phone 8.1 Runtime and stepped into a missing API which you can use in Windows Phone 8.0 and Windows Phone Silverlight 8.1 apps.
What I need is the DeviceNetworkInformation to get with what kind of NetworkInterfaceType is the device connected to the internet.
Sample code in Windows Phone 8.0.
public void GetDeviceConnectionInfo()
{
DeviceNetworkInformation.ResolveHostNameAsync(new DnsEndPoint("microsoft.com", 80),
nrr =>
{
NetworkInterfaceInfo info = nrr.NetworkInterface;
if (info != null)
{
switch (info.InterfaceType)
{
case NetworkInterfaceType.Ethernet:
// Do something
break;
case NetworkInterfaceType.MobileBroadbandCdma:
case NetworkInterfaceType.MobileBroadbandGsm:
switch (info.InterfaceSubtype)
{
case NetworkInterfaceSubType.Cellular_3G:
case NetworkInterfaceSubType.Cellular_EVDO:
case NetworkInterfaceSubType.Cellular_EVDV:
case NetworkInterfaceSubType.Cellular_HSPA:
// Do something
break;
}
// Do something
break;
case NetworkInterfaceType.Wireless80211:
// Do something
break;
}
}
}, null);
}
And you could access the carrier's name with DeviceNetworkInformation.CellularMobileOperator.
EDIT: The following suggestion works Windows Phone 8.1 Apps.
I would not recommend using IanaInterfaceType, InboundMaxBitsPerSecond or OutboundMaxBitsPerSecond to determine the connection type, as they are very inaccurate.
The following method gets the connection type as seen in the status bar of the WP. Note that the mode of connection does not necessarily give an indication of the upload / download speed!
using Windows.Networking.Connectivity;
/// <summary>
/// Detect the current connection type
/// </summary>
/// <returns>
/// 2 for 2G, 3 for 3G, 4 for 4G
/// 100 for WiFi
/// 0 for unknown or not connected</returns>
private static byte GetConnectionGeneration()
{
ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();
if (profile.IsWwanConnectionProfile)
{
WwanDataClass connectionClass = profile.WwanConnectionProfileDetails.GetCurrentDataClass();
switch (connectionClass)
{
//2G-equivalent
case WwanDataClass.Edge:
case WwanDataClass.Gprs:
return 2;
//3G-equivalent
case WwanDataClass.Cdma1xEvdo:
case WwanDataClass.Cdma1xEvdoRevA:
case WwanDataClass.Cdma1xEvdoRevB:
case WwanDataClass.Cdma1xEvdv:
case WwanDataClass.Cdma1xRtt:
case WwanDataClass.Cdma3xRtt:
case WwanDataClass.CdmaUmb:
case WwanDataClass.Umts:
case WwanDataClass.Hsdpa:
case WwanDataClass.Hsupa:
return 3;
//4G-equivalent
case WwanDataClass.LteAdvanced:
return 4;
//not connected
case WwanDataClass.None:
return 0;
//unknown
case WwanDataClass.Custom:
default:
return 0;
}
}
else if (profile.IsWlanConnectionProfile)
{
return 100;
}
return 0;
}
Sorry, I don't know about the carrier's name, but the Access Point Name (APN) might also be of use, as the Access Point is connected to the carrier:
ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();
string apn = profile.WwanConnectionProfileDetails.AccessPointName;
It is not all exactly the same but we can do pretty much the same in Windows 8.1 for detecting network type as we could on earlier versions, except the namespace and classes are different. A good article that covers most of the possible scenarios can be found here.
Effectively instead of accessing the specifics about the network connection you adjust your behavior based on the NetworkCostType. Basically if the user's connection is one that has little to no metering you do what you like, but if they are on a data plan or at a place where making a call out to the Internet will incur a fee to the user you should prompt them or handle it differently. Perhaps waiting until Wifi or ethernet is available.
If you are interested more in the technical information about the network, the best I could find are the properties of the ConnectionProfile.NetworkAdapter class. You can get instance of ConnectionProfile class like this (taken from this Microsoft article):
//Get the Internet connection profile
string connectionProfileInfo = string.Empty;
try {
ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
if (InternetConnectionProfile == null) {
NotifyUser("Not connected to Internet\n");
}
else {
connectionProfileInfo = GetConnectionProfile(InternetConnectionProfile);
NotifyUser("Internet connection profile = " +connectionProfileInfo);
}
}
catch (Exception ex) {
NotifyUser("Unexpected exception occurred: " + ex.ToString());
}
In NetworkAdapter class you have properties like IanaInterfaceType, InboundMaxBitsPerSecond and OutboundMaxBitsPerSecond which give you pretty good idea about how fast your network is. For example, IanaInterfaceType for IEEE 802.11 Wifi is 71...You can look at more details here: NetworkAdapter and IanaInterfaceType.
Edit: Here is the complete list of Iana interface types
I am developing a Xamarin.iOS Bluetooth enabled app and i have some hurdles which i need to overcome. I am trying to make a connection from C# iOS app to peripheral device; I can connect successfully to the device but after discovering services and characteristics of the device, I need to catch particular service so that i can further use it for different purposes.
Now, the issue is how can i catch particular service from list of services in the cb peripheral object. Each service is identified by CBUUID object and i already know the CBUUID object that the device is returning, but i am not sure how can i compare them so that i know i catch the appropriate service.
If you are targeting iOS 7.1 (or later) then you can compare the System.String Uuid property of CFUUID. That's the easiest way. E.g.
if (cbuuid1.Uuid == cbuuid2.Uuid)
Console.WriteLine ("Equal");
else
Console.WriteLine ("Different");
Otherwise (iOS 7.0 and earlier) you'll need to compare the NSData Data properties of CFUUID. First compare their length and, if equal, compare each byte inside them. E.g.
bool equal = false;
using (var d1 = cbuuid1.Data)
using (var d2 = cbuuid2.Data) {
if (d1.Lenght == d2.Length) {
for (int i=0; i < d1.Lenght; i++) {
if (d1 [i] != d2 [i]) {
equal = false;
break;
}
}
}
}
Console.WriteLine (equal ? "Equal" : "Different");
When the phone is in the local network it has ip 192.168.0.x when it is outside wifi access it uses internet connection provided by mobile network(the internet accessed when you have sim inside the phone).
How to determine by C# which kind of connection is used at the time?
EDIT:
NetworkInterfaceInfo netInterfaceInfo = socket.GetCurrentNetworkInterface();
var type = netInterfaceInfo.InterfaceType;
var subType = netInterfaceInfo.InterfaceSubtype;
You can try this method to check network states:
public static string GetNetStates()
{
var info = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType;
switch (info)
{
case NetworkInterfaceType.MobileBroadbandCdma:
return "CDMA";
case NetworkInterfaceType.MobileBroadbandGsm:
return "CSM";
case NetworkInterfaceType.Wireless80211:
return "WiFi";
case NetworkInterfaceType.Ethernet:
return "Ethernet";
case NetworkInterfaceType.None:
return "None";
default:
return "Other";
}
}
I need to create a qrreader with windows phone.
Xzing examples only print to video the qr string captured,
I need an example of how to understand if this string is a vcard and, consequently, save it in contact, or if it is a link and open it in the browser.
private void ScanPreviewBuffer()
{
try
{
_photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
var binarizer = new HybridBinarizer(_luminance);
var binBitmap = new BinaryBitmap(binarizer);
var result = _reader.decode(binBitmap);
Dispatcher.BeginInvoke(() => CheckQr(result.Text));
}
catch { }
}
private void CheckQr(string qrString)
{
VibrateController vibrate = VibrateController.Default;
vibrate.Start(TimeSpan.FromMilliseconds(500));
MessageBox.Show(qrString);
/* CONTROLS HERE */
}
Obviously you have to start by parsing the qrString content to get what you want, i think we'll both agree on that point ;)
So the main issues are :
Determining formats (url or vcard)
Parsing them (if needed)
Using them to trigger wanted actions
1. About vCard
To determine if you qrString holds a vCard, maybe you could just try to match (with string.Contains or string.StartsWith methods) the vCard header which is BEGIN:VCARD and always seems to be the same from one version to another (see wikipedia).
For Windows Phone 7, there's no builtin features to parse vCards, so you have to do it by yourself or you could try to use the vCard library For Windows Phone. It would be used this way :
byte[] byteArray = Encoding.UTF8.GetBytes(qrString);
using (StreamReader reader = new StreamReader(new MemoryStream(byteArray)))
{
vCard card = new vCard(reader);
// access here card.PropertyFromvCard to get the information you need
}
There's not so much documentation about it, but sources are available on codeplex, so you'll probably find all the property names and samples you need.
For Windows Phone 8, the builtin ContactInformation.ParseVcardAsync method could help you to parse your qrString content (here is an official tutorial)
Then you need to finally create your contact :
If you're developping your App on Windows Phone 7, there's no way to create a contact directly from your application. You need to use the "save contact task" and pre-populate the fields you need. Here's an example :
SaveContactTask saveContactTask = new SaveContactTask();
saveContactTask.Completed += new EventHandler<SaveContactResult>(saveContactTask_Completed);
saveContactTask.FirstName = "John"; // card.PropertyFromvCard and so on...
saveContactTask.LastName = "Doe";
saveContactTask.MobilePhone = "2065550123";
saveContactTask.Show();
If you're developping on Windows Phone 8 (and it doesn't seem to be the case given your question tags), you can create a Custom contact store and write directly into it
2. About URLs
To know if you're dealing with an URL or not, i would advice you to follow suggestions coming with this SO answer. To make a long story short, here's the code you could use or at least something similar :
static bool IsValidUrl(string qrString)
{
Uri uri;
return Uri.TryCreate(urlString, UriKind.Absolute, out uri)
&& (uri.Scheme == Uri.UriSchemeHttp
|| uri.Scheme == Uri.UriSchemeHttps
|| uri.Scheme == Uri.UriSchemeFtp
|| uri.Scheme == Uri.UriSchemeMailto
/*...*/);
}
And finally to open your URL into a web browser (if it is a valid one of course), you could use the WebBrowser task or embed a true WebBrowser into your application with the WebBrowser control and make good use of it.
ZXing has a class called ResultParser with a static method parseResult.
The ResultParser supports some common content formats like vCard, vEvent, URL, etc.
It gives you as a result an instance of AddressBookParsedResult for vCard content back.
ParsedResult parsedResult = ResultParser.parseResult(result);