Xamarin: How to get current theme name in code? - xamarin.android

In Xamarin Android, how do I get the current theme name programmatically? I need to get the name as a string such as "Theme.AppCompat.Light.Dialog".

You may refer to the code bellow:
PackageInfo packageInfo;
packageInfo = PackageManager.GetPackageInfo(PackageName,PackageInfoFlags.MetaData);
int themeResId = packageInfo.ApplicationInfo.Theme;
var name = Theme.Resources.GetResourceEntryName(themeResId);
And here is the reference about how to get theme name in Android project(using java)

Related

How to localize the Autodesk Forge Viewer DiffTool extension

We are using the Autodesk Forge Viewer DiffTool extension, but we need to change one of the texts:
Every tutorial shows how add localization to your own extension, but I couldn't find how to change a translation in an existing extension you are using.
Moreover, without knowing what the translation key is, I would have "guess" it, which isn't really great either.
So, how do I change the translation for this text?
There is no supported way to hook into the translation service of the Viewer to change the text. If the translation is wrong, please let us know, and we can fix that on our side.
If you want to change the text for some other reasons, then one thing you could do is wait for the initialization of the extension's UI and change the button's content using DOM APIs:
let extensionConfig = {}
extensionConfig['mimeType'] = 'application/vnd.autodesk.revit'
extensionConfig['primaryModels'] = [model1]
extensionConfig['diffModels'] = [model2]
extensionConfig['diffMode'] = 'overlay'
extensionConfig['versionA'] = '2'
extensionConfig['versionB'] = '1'
extensionConfig['onInitialized'] = () => {
let button = document.getElementById("diffFacetsRemovedButton");
let label = button.nextSibling;
label.innerHTML = label.innerHTML.replace("Odebrat", "Něco jiného");
}
viewer.loadExtension('Autodesk.DiffTool', extensionConfig);

Get current input language on android (Xamarin)

Is there any way to get current input language?
I've tried this:
editText_input.TextLocale
but it returns default system language. Also I tried to look into
Android.Views.InputMethods.InputMethodManager
but no luck as well. Any suggestions?
It seems you could only get the keyboard language by using:
InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
InputMethodSubtype ims = imm.CurrentInputMethodSubtype;
string localeString = ims.Locale;
For example:

ios application Localization

How can I set ios application supported languages?
e.g I use NSDate to get current day. If the device language is other than my supported languages NSDateFormatter returns "day" in device's language but I want to get in English if I don't support that language.
I know there is a way to get day in specific language using NSLocal but I don't want to do that way because I need to convert other strings as well.
The Apple documentation covers this pretty clearly. I know all you need is the word "day", but the following will help you include any word for any language if you do as follows:
1) You need to place all of the words (Strings) in your application into a single .swift file. Each word should be returned in a function that converts this string into the localized string per the device's NSLocal set in the device settings:
struct Localization {
static let all: String = {
return getLocalized("All")
}()
static let allMedia: String = {
return getLocalized("All Media")
}()
static let back: String = {
return getLocalized("Back")
}()
// ...and do this for each string
}
2) This file should also contain a static function that will convert the string:
static func getLocalized(_ string: String) -> String {
return NSLocalizedString(string, comment: "")
}
Here, the NSLocalizedString( method will do all of the heavy lifting for you. If will look into the .XLIFF file (we will get to that) in your project and grab the correct string per the device NSLocale. This method also includes a "comment" to tell the language translator what to do with the "string" parameter you passed along with it.
3) Reviewing all of the strings that you placed in your .swift file, you need to include each of those into an .XLIFF file. This is the file that a language expert will need to go over and include the proper translated word per string in the .XLIFF. As I stated before, this is the file that once included inside your project, the NSLocalizedString( method will search this file and grab the correct translated string for you.
And that's it!

How to get format settings of field in drupal 8?

I have a drupal 8 project and I was requested by my customer to get format settings of field in content type to respond to an api for mobile app. I created a new module, and trying to get data of format settings. But haven't succeed. I just get all setting of a field, but not display settings of field in content type.
On picture below, I want get all data of format column, and show it as a json. Please help me. Thanks so much!
If you want to extract the formatter settings for a specific field, you can use this option:
/** #var \Drupal\Core\Entity\EntityDisplayRepository $entityDisplayRepository */
$entityDisplayRepository = \Drupal::service('entity_display.repository');
$productViewDisplay = $entityDisplayRepository->getViewDisplay('node', 'page', 'teaser' /* optional */);
$all_formatters_settings = $productViewDisplay->get('content');
$formatter_settings = $all_formatters_settings['field_my_field'];
If you need to get the settings for the widget, you can similarly call the function getFormDisplay in the repository instead of getViewDisplay:
/** #var \Drupal\Core\Entity\EntityDisplayRepository $entityDisplayRepository */
$entityDisplayRepository = \Drupal::service('entity_display.repository');
$productViewDisplay = $entityDisplayRepository->getFormDisplay('node', 'page', 'teaser' /* optional */);
$all_formatters_settings = $productViewDisplay->get('content');
$formatter_settings = $all_formatters_settings['field_my_field'];
There is another way to get the formatter settings.
$formatter_settings = \Drupal::entityTypeManager()
->getStorage('entity_view_display')
->load("entity_type_id.entity_bundle.view_mode")
->getRenderer('field_logo_kataloga')
->getSettings();

Monodroid screen dimensions

I'm trying to reference WindowManger so I can get the default screen's dimensions but I can't seem to find reference to it. (this is API 8, froyo 2.2). I even tried:
dynamic wm = Android.App.Application.Context.GetSystemService(Android.Content.Context.WindowService);
Display display = wm.getDefaultDisplay();
But got an error indicating that Object doesn't respond to getDefaultDisplay.
Also I tried:
var wm = (IWindowManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.WindowService);
Display display = wm.DefaultDisplay;
But I get an invalid cast exception.
Saw this post, but I can't resolve WindowManager. Any ideas what's going on here?
WindowManager is the IWindowManager interface. Instead of the cast, try using the .JavaCast<T>() extension method:
var wm = context.GetSystemService(Android.Content.Context.WindowService)
.JavaCast<IWindowManager>();
var d = wm.DefaultDisplay;
You can also check out the AccelerometerPlay sample.
Another simpler way is
Display display = this.WindowManager.DefaultDisplay;
You can get the Width and Height properties from the display object.
using Android.Runtime; //for JavaCast
var windowManager = Android.App.Application.Context.GetSystemService(Android.Content.Context.WindowService).JavaCast<IWindowManager>();

Resources