I am making list of logos inside a BoxLayout.Y_AXIS. it is taking too long to be shown. The logos are loaded from the Storage. I am quite new on Codenameone, less than three months, and the code I use is below:
public void makeList( ) {
this.membersContainer.removeAll();
int membersNo = this.members.size();
ToastBar.showInfoMessage("Βρέθηκαν " + membersNo);
for( Map.Entry<String,String[]> entry: this.members.entrySet() ) {
Button b = new Button();
b.setUIID("Label");
b.setUnselectedStyle( this.itemStyle);
Object[] s = entry.getValue();
try {
ToastBar.showInfoMessage( s[0].toString() );
b.setIcon( EncodedImage.create( Storage.getInstance().createInputStream( s[0].toString()) ) );
b.addActionListener(e -> {
new MemberGui ( entry.getKey(), s[0].toString(), s[1].toString(), s[2].toString(), s[3].toString(), this ).show();
});
}
catch(IOException ex) {
ToastBar.showErrorMessage(ex.getMessage());
}
this.membersContainer.add(b);
}
}
I am wondering is there any other way to create this List of logos? Right now it takes more than 40 seconds to show this screen on iphone 7 plus.
thank you.
Use InfiniteContainer and only load 10 logos at a time. See https://www.codenameone.com/javadoc/com/codename1/ui/InfiniteContainer.html
Related
I'm learning Activiti 7, I drew a BPMN diagram as below:
When the highlight1 UserTask has been completed but the highlight2 UserTask is still pending, I ran the following code to highlight the completed flow element.
private AjaxResponse highlightHistoricProcess(#RequestParam("instanceId") String instanceId,
#AuthenticationPrincipal UserInfo userInfo) {
try {
// Get the instance from the history table
HistoricProcessInstance instance = historyService
.createHistoricProcessInstanceQuery().processInstanceId(instanceId).singleResult();
BpmnModel bpmnModel = repositoryService.getBpmnModel(instance.getProcessDefinitionId());
Process process = bpmnModel.getProcesses().get(0);
// Get all process elements, including sequences, events, activities, etc.
Collection<FlowElement> flowElements = process.getFlowElements();
Map<String, String> sequenceFlowMap = Maps.newHashMap();
flowElements.forEach(e -> {
if (e instanceof SequenceFlow) {
SequenceFlow sequenceFlow = (SequenceFlow) e;
String sourceRef = sequenceFlow.getSourceRef();
String targetRef = sequenceFlow.getTargetRef();
sequenceFlowMap.put(sourceRef + targetRef, sequenceFlow.getId());
}
});
// Get all historical Activities, i.e. those that have been executed and those that are currently being executed
List<HistoricActivityInstance> actList = historyService.createHistoricActivityInstanceQuery()
.processInstanceId(instanceId)
.list();
// Each history Activity is combined two by two
Set<String> actPairSet = new HashSet<>();
for (HistoricActivityInstance actA : actList) {
for (HistoricActivityInstance actB : actList) {
if (actA != actB) {
actPairSet.add(actA.getActivityId() + actB.getActivityId());
}
}
}
// Highlight Link ID
Set<String> highSequenceSet = Sets.newHashSet();
actPairSet.forEach(actPair -> {
logger.info("actPair:{}, seq:{}", actPair, sequenceFlowMap.get(actPair));
highSequenceSet.add(sequenceFlowMap.get(actPair));
logger.info("{}",highSequenceSet.toString());
});
// Get the completed Activity
List<HistoricActivityInstance> finishedActList = historyService
.createHistoricActivityInstanceQuery()
.processInstanceId(instanceId)
.finished()
.list();
// Highlight the completed Activity
Set<String> highActSet = Sets.newHashSet();
finishedActList.forEach(point -> highActSet.add(point.getActivityId()));
// Get the pending highlighted node, i.e. the currently executing node
List<HistoricActivityInstance> unfinishedActList = historyService
.createHistoricActivityInstanceQuery()
.processInstanceId(instanceId)
.unfinished()
.list();
Set<String> unfinishedPointSet = Sets.newHashSet();
unfinishedActList.forEach(point -> unfinishedPointSet.add(point.getActivityId()));
...
return AjaxResponse.ajax(ResponseCode.SUCCESS.getCode(),
ResponseCode.SUCCESS.getDesc(),
null);
} catch (Exception e) {
e.printStackTrace();
return AjaxResponse.ajax(ResponseCode.ERROR.getCode(),
"highlight failure",
e.toString());
}
}
Please see this piece of code:
// Highlight Link ID
Set<String> highSequenceSet = Sets.newHashSet();
actPairSet.forEach(actPair -> {
logger.info("actPair:{}, seq:{}", actPair, sequenceFlowMap.get(actPair));
highSequenceSet.add(sequenceFlowMap.get(actPair));
logger.info("{}",highSequenceSet.toString());
});
It was expected to get 2 elements in the highSequenceSet, but it got 3, with a unexpected null.
The log printed in the console was:
Why is the first null added to the HashSet but not the rest?
Why is the first null added to the HashSet but not the rest?
HashSet implements the Set interface, duplicate values are not allowed.
I have a CN1 application that uses three pickers inside a container.
One of the pickers just contains small strings like "1x" , "2x" , etc.
Every time an item is selected on the running application, the selected text spins really fast, what looks kind of odd.
I have tried setting padding and margin to zero, and set SmoothScrolling to false.
picker.setSmoothScrolling(false);
All to no avail.
Is there ant solution to it? Many thanks in advance ..
Here is the relevant part of the code:
private final Picker pickerInterval = new Picker();
private final Picker pickerDayOrMonth = new Picker();
private final Picker pickerFinal = new Picker();
String stringPickerInterval = "repetir a cada ..";
pickerInterval.setType(Display.PICKER_TYPE_STRINGS);
pickerInterval.setUIID("DatePickerDialog");
pickerInterval.setStrings("1","2","3","4","5","6","6","8","9","10","11","12",stringPickerInterval);
pickerInterval.setSelectedString(stringPickerInterval);
pickerInterval.addActionListener((e) -> {
if (!pickerInterval.getSelectedString().equals(stringPickerInterval)) {
pickerInterval.setUIID("DatePickerDialogSelected");
} else {
pickerInterval.setUIID("DatePickerDialog");
}
});
String stringPickerDayOr = "dias ou semanas ou ...";
pickerDayOrMonth.setType(Display.PICKER_TYPE_STRINGS);
pickerDayOrMonth.setUIID("DatePickerDialog");
pickerDayOrMonth.setStrings("Dia(s)", "Semana(s)", "Mes(es)","Ano(s)" , stringPickerDayOr);
pickerDayOrMonth.setSelectedString(stringPickerDayOr);
pickerDayOrMonth.addActionListener((e) -> {
if (!pickerDayOrMonth.getSelectedString().equals(stringPickerDayOr)) {
pickerDayOrMonth.setUIID("DatePickerDialogSelected");
} else {
pickerDayOrMonth.setUIID("DatePickerDialog");
}
});
String stringPickerFinal = "freqüência das repetições ..";
pickerFinal.setType(Display.PICKER_TYPE_STRINGS);
pickerFinal.setUIID("DatePickerDialog");
pickerFinal.setStrings("1 x","2 x","3 x","4 x","5 x","6 x","6 x","8 x","9 x","10 x","11 x","12 x" , stringPickerFinal);
pickerFinal.setSelectedString(stringPickerFinal);
pickerFinal.addActionListener((e) -> {
if (!pickerFinal.getSelectedString().equals(stringPickerFinal)) {
pickerFinal.setUIID("DatePickerDialogSelected");
} else {
pickerFinal.setUIID("DatePickerDialog");
}
});
container = new Container(new GridLayout(1, 3));
container.setUIID("ContainerPicker");
container.add(pickerInterval).add(pickerDayOrMonth).add(pickerFinal);
I am working around with Salesforce and force.com API and metadata API, version 36.
I can create a custom field in a Lead object but by default I can see it's hidden and this means I cannot create a new Lead with these custom fields because it returns a bad request (400 status code).
Is there any way by Code to set the custom field Visible?
public boolean createCustomExtTextField(String name, LoginResult metadataLoginResult, int length) {
boolean success = false;
CustomField cs = new CustomField();
cs.setFullName("Lead."+name+"__c");
cs.setLabel("Custom"+name+"Field");
cs.setType(FieldType.LongTextArea);
cs.setLength(length);
cs.setVisibleLines(50); // max 50
try {
MetadataConnection metadataConnection = createMetadataConnection(metadataLoginResult);
SaveResult[] results = metadataConnection.createMetadata(new Metadata[] { cs });
for (SaveResult r : results) {
if (r.isSuccess()) {
success = true;
} else {
System.out.println("Errors were encountered while creating " + r.getFullName());
for (com.sforce.soap.metadata.Error e : r.getErrors()) {
System.out.println("Error message: " + e.getMessage());
System.out.println("Status code: " + e.getStatusCode());
}
}
}
} catch (ConnectionException e) {
e.printStackTrace();
}
return success;
}
I am googling a lot and don't find something that actually helped. So, any hints are welcomed. Thank you.
Finally found a solution to this. I final one for me was to make all custom fields REQUIRED.
CustomField cs = new CustomField();
cs.setFullName("Lead.YourCompanyName" + name + "__c");
cs.setLabel("YourCompanyName" + name);
cs.setRequired(true);
...
com.sforce.soap.enterprise.LoginResult metadataLoginResult = operations.loginToMetadata(username, password, "https://login.salesforce.com/services/Soap/c/36.0");
...
private boolean createFieldInMetadata(LoginResult metadataLoginResult, CustomField cs) {
boolean success = false;
try {
MetadataConnection metadataConnection = createMetadataConnection(metadataLoginResult);
SaveResult[] results = metadataConnection.createMetadata(new Metadata[] { cs });
for (SaveResult r : results) {
if (r.isSuccess()) {
success = true;
} else {
System.out.println("Errors were encountered while creating " + r.getFullName());
for (com.sforce.soap.metadata.Error e : r.getErrors()) {
System.out.println("Error message: " + e.getMessage());
System.out.println("Status code: " + e.getStatusCode());
}
}
}
} catch (Exception e) {
}
return success;
}
And so it will appear in the page layout. Very important to know, a required field cannot have just an empty value set, it must be something. So if not all custom fields are required in your logic and you wanna avoid the entire process of unzipping page layout and zipping it back (however it may be done) just add "N/A" or any char at choice to the required by code but not your project custom fields.
I managed to make the custom Field Level Security visible for "Admin" profile but not Field Accessability to visible. The latter is untested.
I would like to ask, how it is possible to get all accessible camera resolutions in Windows Phone 8.1 app (for both silverlight and WinRT). I wanted to use:
Windows.Phone.Media.Capture.PhotoCaptureDevice.GetAvailableCaptureResolutions(
Windows.Phone.Media.Capture.CameraSensorLocation.Back);
But I am getting message that namespace Windows.Phone.Media.Capture is obsolete and may not be supported from next version of Windows Phone starting with Windows Phone Blue and that I should use Windows.Media.Capture instead. However Windows.Media.Capture does not allow me to get accessible camera resolutions, so I would like to ask, how to solve this.
Thank you.
It can be done like this:
First let's define method to get Device ID which will be used to take a photo:
private static async Task<DeviceInformation> GetCameraID(Windows.Devices.Enumeration.Panel desiredCamera)
{
DeviceInformation deviceID = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture))
.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desiredCamera);
if (deviceID != null) return deviceID;
else throw new Exception(string.Format("Camera of type {0} doesn't exist.", desiredCamera));
}
Then after we initialize the camera - we can read the resolutions like this:
private async void InitCameraBtn_Click(object sender, RoutedEventArgs e)
{
var cameraID = await GetCameraID(Windows.Devices.Enumeration.Panel.Back);
captureManager = new MediaCapture();
await captureManager.InitializeAsync(new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Video,
PhotoCaptureSource = PhotoCaptureSource.VideoPreview,
AudioDeviceId = string.Empty,
VideoDeviceId = cameraID.Id
});
// Get resolutions
var resolutions = captureManager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Select(x => x as VideoEncodingProperties).ToList();
// get width and height:
uint width = resolutions[0].Width;
uint height = resolutions[0].Height;
}
I am creating a silverlight application as a web resource for CRM 2011. Now i am creating a ServiceAppointment record in DB and after creating it i want to change its Status to "reserved" instead of requested.
I googled about this and come across the examples like Close a Service Activity Through Code and Microsoft.Crm.Sdk.Messages.SetStateRequest
They all suggesting to use "SetStateRequest" and for using this i have to set the OptionSetValue like
request["State"] = new OptionSetValue(4);
But above line gives me error saying "OptionSetValue does not contain constructor which takes one argument"
BTW i am using SOAP end point of CRM 2011 service in silverlight application
Any ideas friends?
EDIT
Following is my code
var request = new OrganizationRequest { RequestName = "SetStateRequest" };
request["State"] = 3;
request["Status"] = 4;
request["EntityMoniker"] = new EntityReference() { Id = createdActivityId, LogicalName = "serviceappointment" };
crmService.BeginExecute(request,ChangeActivityStatusCallback,crmService);
And my callback function is
private void ChangeActivityStatusCallback(IAsyncResult result) {
OrganizationResponse response;
try
{
response = ((IOrganizationService)result.AsyncState).EndExecute(result);
}
catch (Exception ex)
{
_syncContext.Send(ShowError, ex);
return;
}
}
You must some how be referencing some other OptionSetValue class that is not the Microsoft.Xrm.Sdk one. Try appending the namespace to see if that resolves your issue:
request["State"] = new Microsoft.Xrm.Sdk.OptionSetValue(4);
Also, why are you using late bound on the SetStateRequest? Just use the SetStateRequest class:
public static Microsoft.Crm.Sdk.Messages.SetStateResponse SetState(this IOrganizationService service,
Entity entity, int state, int? status)
{
var setStateReq = new Microsoft.Crm.Sdk.Messages.SetStateRequest();
setStateReq.EntityMoniker = entity.ToEntityReference();
setStateReq.State = new OptionSetValue(state);
setStateReq.Status = new OptionSetValue(status ?? -1);
return (Microsoft.Crm.Sdk.Messages.SetStateResponse)service.Execute(setStateReq);
}
Thanks Daryl for you time and effort. I have solved my problem with the way u have suggested.
I am posting my code that worked for me.
var request = new OrganizationRequest { RequestName = "SetState" };
request["State"] = new OptionSetValue { Value = 3 };
request["Status"] = new OptionSetValue { Value = 4 };
request["EntityMoniker"] = new EntityReference() { Id = createdActivityId, LogicalName = "serviceappointment" };
crmService.BeginExecute(request,ChangeActivityStatusCallback,crmService);
private void ChangeActivityStatusCallback(IAsyncResult result) {
OrganizationResponse response;
try
{
response = ((IOrganizationService)result.AsyncState).EndExecute(result);
}
catch (Exception ex)
{
_syncContext.Send(ShowError, ex);
return;
}
}