java.lang.Object | |
↳ | com.datalogic.device.configuration.ProfileManager |
ProfileManager
gives the developer the ability to create a profile and to load it explicitly or to associate it to a loading condition to be automatically loaded.
A profile is a set of Property
s with their value.
The utility of a profile is that we can collect in it the setting of the properties we need for a
specific purpose and then we can load it explicitly calling loadProfile(String)
or automatically when
an activity comes to foreground, defining a rule (addProfileRule(StringBuffer, String, String, ArrayList
) that associates that profile with the activity.
A profile is identified by a symbolic name that must be unique on the device.
When a profile is created it is assigned a PersistenceType
that can be:
{ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Profile Description Schema", "description": "Schema of a profile.", "type": "object", "version": "2.0.0", "definitions": { "properties": { "type": "array", "items": { "$ref": "#/definitions/property" } }, "property": { "type": "object", "properties": { "id": { "type": ["integer", "string"], "description": "Unique integer identifier of the property. The defining string can be used instead of the numeric value." }, "value": { "type": "string", "description": "Value of the property. It is a string and it will be parsed according to the specific type of the property. Value for a CharacterProperty is the unicode format (i.e: \\uFFFF)." } }, "required": ["id", "value"] }, }, "properties": { "version": { "type": "string", "description": "Version of the schema. If you use this the value must be 2.0.0." } , "description": { "type": "string", "description": "Short string describing the profile." }, "properties": { "$ref": "#/definitions/properties", "description": "List of properties with their value." } } }
loadProfile(String)
,
addProfileRule(StringBuffer, String, String, ArrayList)
to define a rule that associates the profile to a set of activities.
When one of the specified activities comes to the foreground
the profile will be automatically loaded. The previous configuration will be restored when the activity will be no more in foreground.
An activity can have only one profile associated.
loadProfile(String)
fails if there is already a profile manually loaded.
ProfileManager(Context)
.
PropertyID
,value} to be set applying the profile.
createProfile(String, HashMap, String, PersistenceType)
.
ProfileManager pm = new ProfileManager(this); HashMapTo add a rule to automatically load the profile profilo_128.json when the app with package com.datalogic.testprofilo1 comes to the foreground do the following steps:map = new HashMap (); map.put(PropertyID.CODE128_ENABLE, "true"); // BooleanProperty map.put(PropertyID.CODE128_LENGTH2, "10"); // NumericProperty map.put(PropertyID.CODE128_GS1_USER_ID, String.format ("\\u%04x", (int)'a')); // CharacterProperty map.put(PropertyID.CODE128_LENGTH_CONTROL, LengthControlMode.ONE_FIXED.toString()); // EnumProperty map.put(PropertyID.LABEL_PREFIX, "pippo"); // TextProperty pm.createProfile("profilo_128.json", map, "enable code128, disable datamatrix", PersistenceType.ENTERPRISE_RESET_PERSISTENT);
ProfileManager(Context)
.
addProfileRule(StringBuffer, String, String, ArrayList)
.
ProfileManager pm = new ProfileManager(this); StringBuffer rule1_name = new StringBuffer("rule_1"); pm.addProfileRule(rule1_name, "profilo_1.json", "com.datalogic.testprofilo1", new ArrayListTo manually load the profile profilo_128.json do the following steps:());
ProfileManager(Context)
.
loadProfile(String)
.
ProfileManager pm = new ProfileManager(this); pm.loadProfile("profilo_1.json");To get the identifier of the profile manually loaded, if any, do the following steps:
ProfileManager(Context)
.
getLoadedProfile()
.
ProfileManager pm = new ProfileManager(this); String profile = pm.getLoadedProfile();To unload the profile manually loaded do the following steps:
ProfileManager(Context)
.
unloadProfile()
.
ProfileManager pm = new ProfileManager(this); pm.unloadProfile();To delete the profile profilo_128.json do the following steps:
ProfileManager(Context)
.
deleteProfile(String)
.
ProfileManager pm = new ProfileManager(this); pm.deleteProfile("profilo_1.json");To remove the rule "rule_1" do the following steps:
ProfileManager(Context)
.
removeProfileRule(String)
.
ProfileManager pm = new ProfileManager(this); pm.removeProfileRule("rule_1");To get the list of all the profiles saved on the device do the following steps:
ProfileManager(Context)
.
getProfilesList()
.
ProfileManager pm = new ProfileManager(this); ArrayListTo get the list of all the rules defined on the device do the following steps:profileList = pm.getProfilesList();
ProfileManager(Context)
.
getProfileRulesList()
.
ProfileManager pm = new ProfileManager(this); ArrayListprofileRuleList = pm.getProfileRulesList();
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This is the constructor of ProfileManager.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a rule to automatically load the given profile when one of the specified activities comes to foreground.
| |||||||||||
Creates the profile with the given name and the specified persistence type.
| |||||||||||
Saves the given map as a profile with the specified name, description and persistence type.
| |||||||||||
Deletes the given profile.
| |||||||||||
Returns the name of the manually loaded profile, otherwise an empty string.
| |||||||||||
Gets the list of all the profile rules defined on the device.
| |||||||||||
Gets the list of all the profiles saved on the device.
| |||||||||||
Applies the given profile.
| |||||||||||
Delete the specified rule.
| |||||||||||
Revert the manually loaded profile restoring the values previously set on the device.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
This is the constructor of ProfileManager.
context | Context context of the caller application |
---|
ConfigException | in case of error. |
---|
Creates a rule to automatically load the given profile when one of the specified activities comes to foreground.
The specified activities must all belong to the same package.
When the activity is no more in foreground the previous configuration is restored.
A rule is uniquely identified by its name which must therefore be unique. In input, through parameter name, you can specify the name to be associated with the rule.
If name is unique it is used, otherwise the method makes it unique adding it a suffix.
The caller can learn the string used to name the rule because the StringBuffer object name is updated.
The profile associated to the rule is the one found with the given name.
There must be only one rule to be loaded when an activity comes to the foreground.
If one of the specified activities already has an associated profile the method fails.
The persistence to reboot of a rule is that of the referred profile. If the referred profile is deleted by reboot all the rules in which it is referred are deleted.
name | StringBuffer in input an empty string or the preferred name for the rule, in output the unique name assigned
to the rule; if the value in input is unique and not empty is the value used otherwise the method makes it unique adding a suffix. |
---|---|
profile | String the name of the profile to be loaded when one of the given activities comes to foreground. |
packageName | String name of the package containing the given activities. |
classes | ArrayList list of class names inside of the package for which the profile must be loaded.
If the list is empty it means all the classes of the package. |
SUCCESS
in case of success, otherwise a possible error
code, matching one of the ConfigException
error constants.ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
---|
Creates the profile with the given name and the specified persistence type.
If a profile with the same name is already present the method fails.
The schema of the profile file is:
{ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Profile Description Schema", "description": "Schema of a profile.", "type": "object", "version": "2.0.0", "definitions": { "properties": { "type": "array", "items": { "$ref": "#/definitions/property" } }, "property": { "type": "object", "properties": { "id": { "type": ["integer", "string"], "description": "Unique integer identifier of the property. The defining string can be used instead of the numeric value." }, "value": { "type": "string", "description": "Value of the property. It is a string and it will be parsed according to the specific type of the property. Value for a CharacterProperty is the unicode format (i.e: \\uFFFF)." } }, "required": ["id", "value"] }, }, "properties": { "version": { "type": "string", "description": "Version of the schema. If you use this the value must be 2.0.0." } , "description": { "type": "string", "description": "Short string describing the profile." }, "properties": { "$ref": "#/definitions/properties", "description": "List of properties with their value." } } }
name | String name to be used to create the profile file.
The name must have the ".json" extension, otherwise it is added by the method. |
---|---|
profile | File file of the profile to be saved on the device.
The file must have the schema shown above. |
persistence | the persistence mode assigned to the profile file to be created.
Only REBOOT_PERSISTENT and ENTERPRISE_RESET_PERSISTENT are allowed.
It is not possible to create a profile with FACTORY_RESET_PERSISTENT persistence.
A Factory Reset Persistent profile can only be preinstalled on the device by an Espresso OTA and cannot be deleted. |
SUCCESS
in case of success, otherwise a possible error
code, matching one of the ConfigException
error constants.ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
---|
Saves the given map as a profile with the specified name, description and persistence type.
If a profile with the same name is already present the method fails.
The profile file is a .json file with the schema shown in createProfile(String, File, PersistenceType)
.
name | String name to be used to create the profile file.
The name must have the ".json" extension, otherwise it is added. |
---|---|
map | HasMap map of properties with their value to be saved as profile. |
description | String description to be associated to the profile. |
persistence | the persistence mode to be assigned to the profile.
Only REBOOT_PERSISTENT and ENTERPRISE_RESET_PERSISTENT are allowed.
It is not possible to save a profile with FACTORY_RESET_PERSISTENT persistence. |
SUCCESS
in case of success, otherwise a possible error
code, matching one of the ConfigException
error constants.ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
---|
Deletes the given profile.
The method fails if the profile has FACTORY_RESET_PERSISTENT
persistence or
it is currently loaded or it is associated to a rule.
name | String name of the profile file to be deleted. |
---|
SUCCESS
in case of success, otherwise a possible error
code, matching one of the ConfigException
error constants.ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
---|
Returns the name of the manually loaded profile, otherwise an empty string.
Gets the list of all the profile rules defined on the device.
ProfileRuleType
> in case of success, otherwise, if exceptions are not enabled, a null pointer.ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
---|
Gets the list of all the profiles saved on the device.
ProfileType
> in case of success, otherwise, if exceptions are not enabled, a null pointer.ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
---|
Applies the given profile. If there is already a manually loaded profile the method fails.
The properties listed in the profile are set to the values specified in the profile.
The changes done to the configuration loading the profile are persistent to the reboot of the device.
To unload the profile the method unloadProfile()
must be invoked.
name | String name of the profile file to be loaded. |
---|
SUCCESS
in case of success, otherwise a possible error
code, matching one of the ConfigException
error constants.ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
---|
Delete the specified rule.
name | String name of the rule to be deleted. |
---|
SUCCESS
in case of success, otherwise a possible error
code, matching one of the ConfigException
error constants.ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
---|
Revert the manually loaded profile restoring the values previously set on the device. It fails if there isn't a profile manually loaded.
SUCCESS
in case of success, otherwise a possible error
code, matching one of the ConfigException
error constants.ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
---|