I have been working on a MediaPlayer app, where I use the MediaStore.Audio.Media to get all the songs on the SD card and their title, album, artist, etc. tags. I have a custom adapter where I want to check if the Artist field is empty, so I could set "Artist unknown" for that field. The adapter and the cursor I use are in my opinion irrelevant to this question so I'm not going to paste any code here, since this problem occurs outside the adapter as well.
Here is the problem: when an mp3 song doesn't have an artist tag, the cursor for the artist field (the MediaStore.Audio.Media.ARTIST field) returns "". I have no idea what kind of data type that is (it should be String) because whenever I compare it to a String with the value "", the comparison is false. Even if I assign the return value of that field to a temporary String, and than compare that with the before mentioned "", I still get false. I even tried null, "unknown", "", nothing works.
I've really hit a dead end here and any kind of help would be greatly appreciated.
Thank you in advance, Ivan.
I'm using the very same field (MediaStore.Audio.Media.ARTIST), but what I noticed is different.
When you try to retrieve the song's artist info and currently ther's no info available, what you get is <unknown> string.
I wanted to change that info too and I just went for a:
String artist = (((cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)) == null)
|| cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)).equals("")
|| cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)).equals("<unknown>")) ?
"Artist Unknown" : cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)));
the "null and equals.("")" checks should be useless anyway.
Related
I have a Dataframe, which has a bunch of ID name pairs in it. I create it by doing the following:
market_df = pd.DataFrame(markets_info['markets'])
market_df.astype(dict(id=int, name=str))
I received ID numbers from a process and I need to grab the associated name to that ID. I have tried creating an index on the ID and then parsing it, but that doesn't seem to set the ID correctly.
I now am trying to do the following: exch_name = MARKET_IDS.loc[MARKET_IDS['id'] == exchange_id, 'name']
I have verified that exchange_id is also of type int.
What am I missing here?
I don't know if this is because you left out some crucial information from this, but from what it sounds like in your post you're not really altering market_df at all, as your second line is not an assignment. It should read market_df = market_df.astype(dict(id=int, name=str))
I want my "GetContent" script to detect whether the device is "watch" and pass along an instruction to filter out candidate answers from a content.json file whose text field has a length greater than a certain number of characters.
content.json format:
{tags: ["literature"], text: "At once it struck me what quality went to form a man of achievement, especially in literature, and which Shakespeare possessed so enormously -- I mean negative capability, that is, when a man is capable of being in uncertainties, mysteries, doubts, without any irritable reaching after fact and reason. Source: John Keats", image: {url: "images/Shakespeare.jpg"}},
So the logic would be
if (watch) content = short_quotes_only
I would recommend exploring the device property of $vivContext (Documentation)
The device property will allow you to see which type of device a user is using (bixby-mobile, bixby-tv, etc.) and provide the data you wish to show for the device being used.
This combination of snippets worked for me:
device = $vivContext.device
console.log('device', device)
if (device == 'bixby-watch' ) { maxlength = 100
console.log('maxlength is now', maxlength)
}
then later in the script
//filters entitled content by length of text field in characters
content = content.filter(function(i) { return i.text.length < maxlength;
I have a xpages booking application, there is a view for search officer's booking record. Due to search values may contains "(" or ")" or other symbols so I would use wild card search in the code. Also I need to ensure the search result returns properly so I created extra fields to connect two fields together (e.g. Fieldname1+++Fieldname2). I put the search code in view (In Properties -> Data -> Search in view results)
Here is the code for the search
var qstring= "";
if (
(sessionScope.officerSearch != null && sessionScope.officerSearch != "")||
(sessionScope.startDateSearch != null && sessionScope.startDateSearch != "")||
(sessionScope.returnDateSearch != null && sessionScope.returnDateSearch !=""))
{
qstring = " ( FIELD location+++group contains " + sessionScope.locationSearch +"+++"+ sessionScope.groupSearch +
" | FIELD location+++officer contains " + sessionScope.locationSearch +"+++"+ sessionScope.officerSearch +")" +
" & FIELD dateYYYYMM >=" + sessionScope.startDateSearch +
"& FIELD dateYYYYMM <=" + sessionScope.returnDateSearch;
}
return qstring;
When I run the application, I have two problems. If I search only one officer, I get an exception (Notes error: Query is not understandable). If I search more than one officer, I don't get the exception but the result does not return anything. So I use a computed field, paste the search code in there and run the program again. The computed field shows what I searched.
Due to I put the code in the computed field, I can read the whole query for the search
Problem 1: If I search one officer, although it occurs exception, I can imagine the query is like this
( FIELD location+++group contains "WEST+++GP AM(OSO)" | FIELD location+++officer contains "WEST+++John Freeman") & FIELD CompYMNUM >=201001& FIELD dateYYYYMM <=201712
If I put this query in Lotus Notes Client, and cick Search button, it returns the result properly
Problem 2: If I search multiple officers, although the result does not return anything, the computed field shows the query like this
( FIELD location+++group contains "WEST+++GP AM(OSO)" | FIELD location+++officer contains "WEST+++John Freeman, Kevin Sims, Sally Johnson, Tom Chan, William Ross") & FIELD dateYYYYMM >=201001& FIELD dateYYYYMM <=201712
I put this query in Lotus Notes Client, and cick Search button, it returns the result properly too.
I feel so strange that the Lotus Notes Client can return the proper result but the xpages cannot. Also I don't understand why if I search one officer, it causes exception (Query not understandable) and if I search more than one officer, it does not exception and not result return.
I think the reason I get the exception or the review does not the the result is I have "(" and ")" in the search value? However, I used wild card search to bound the search criteria (Or I misunderstand the wild card search?)
Also another reason I think is the field location+++officer. If search multiple officers, the field only recognize one officer e.g. "WEST+++John Freeman, Kevin Sims, Sally Johnson, Tom Chan, William Ross"?
Last but not least, maybe there is coding mistake in the code? But there is mistake in the code, I guess Lotus Notes Client will not return the result.
I try to solve the problems, but every time when I run the application, those problems still occurs.
Is my query has mistake?
Grateful if someone let me know my mistakes please? Thank you.
I created an ActivityNode (an Entry) and I can add custom fields with the
setFields(List<Field> newListField)
fonction.
BUT
I am unable to modify these fields. (In this case I try to modify the value of the field named LIBENTITE)
FieldList list = myEntry.getTextFields();
List<Field> updatedList = new ArrayList<Field>();
//I add each old field in the new list, but I modify the field LIBENTITE
for(Field myField : list){
if(myField.getName().equals("LIBENTITE")){
((TextField)myField).setTextSummary("New value");
}
updatedList.add(myField);
}
myEntry.setFields(updatedList);
activityService.updateActivityNode(myEntry);
This code should replace the old list of fields with the new one, but I can't see any change in the custom field LIBENTITE of myEntry in IBM connections.
So I tried to create a new list of fields, not modifying my field but adding a new one :
for(Field myField:list){
if(!myField.getName().equals("LIBENTITE")){
updatedList.add(myField);
}
}
Field newTextField = new TextField("New Value");
newTextField .setFieldName("LIBENTITE");
updatedList.add(newTextField );
And this code is just adding the new field in myEntry. What I see is that the other custom fields did not change and I have now two custom fields named LIBENTITE, one with the old value and the second with the new value, in myEntry.
So I though that maybe if I clear the old list of Fields, and then I add the new one, it would work.
I tried the two fonctions
myEntry.clearFieldsMap();
and
myEntry.remove("LIBENTITE");
but none of them seems to work, I still can't remove a custom field from myEntry using SBT.
Any suggestions ?
I have two suggestions, as I had (or have) similar problems:
If you want to update an existing text field in an activity node, you have to call node.setField(fld) to update the field in the node object.
Code snippet from my working application, where I'm updating a text field containing a (computed) start time:
ActivityNode node = activityService.getActivityNode(id);
node.setTitle(formatTitle()); // add/update start and end time in title
boolean startFound = false;
// ...
FieldList textfields =node.getTextFields();
Iterator<Field> iterFields = textfields.iterator();
while (iterFields.hasNext()) {
TextField fld = (TextField) iterFields.next();
if (fld.getName().equals(Constants.FIELDNAME_STARTTIME)) {
fld.setTextSummary(this.getStartTimeString()); // NOTE: .setFieldValue does *not* work
node.setField(fld); // write updated field back. This seems to be the only way updating fields works
startFound=true;
}
}
If there is no field with that name, I create a new one (that's the reason I'm using the startFound boolean variable).
I think that the node.setField(fld) should do the trick. If not, there might be a way to sidestep the problem:
You have access to the underlying DOM object which was parsed in. You can use this to tweak the DOM object, which finally will be written back to Connections.
I had to use this as there seems to be another nasty bug in the SBT SDK: If you read in a text field which has no value, and write it back, an error will be thrown. Looks like the DOM object misses some required nodes, so you have to create them yourself to avoid the error.
Some code to demonstrate this:
// ....
} else if (null == fld.getTextSummary()) { // a text field without any contents. Which is BAD!
// there is a bug in the SBT API: if we read a field which has no value
// and try to write the node back (even without touching the field) a NullPointerException
// will be thrown. It seems that there is no value node set for the field. We
// can't set a value with fld.setTextSummary(), the error will still be thrown.
// therefore we have to remove the field, and - optionally - we set a defined "empty" value
// to avoid the problem.
// node.remove(fld.getName()); // remove the field -- this does *not* work! At least not for empty fields
// so we have to do it the hard way: we delete the node of the field in the cached dom structure
String fieldName = fld.getName();
DeferredElementNSImpl fldData = (DeferredElementNSImpl) fld.getDataHandler().getData();
fldData.getParentNode().removeChild(fldData); // remove the field from the cached dom structure, therefore delete it
// and create it again, but with a substitute value
Field newEmptyField = new TextField (Constants.FIELD_TEXTFIELD_EMPTY_VALUE); // create a field with a placeholder value
newEmptyField.setFieldName(fieldName);
node.setField(newEmptyField);
}
Hope that helps.
Just so that post does not stay unanswered I write the answer that was in a comment of the initial question :
"currently, there is no solution to this issue, the TextFields are read-only map. we have the issue recorded on github.com/OpenNTF/SocialSDK/issues/1657"
Each input field in the CKEditor dialogs are renamed with a unique number, but the number changes depending on what options are visible.
I need to reference 'txtUrl' which has an id something like #35_textInput.
So far I have discovered that something like this should work:
alert(CKEDITOR.instances.myElement.document.$.body.getId('txtUrl'));
But it doesn't. Please help.
#Rio, your solution was really close! This was the final solution:
var dialog = CKEDITOR.dialog.getCurrent();
dialog.setValueof('info','txtUrl',"http://google.com");
return false;
var dialog = this.getDialog();
var elem = dialog.getContentElement('info','txtUrl');
within an onchange part of an element I now use
dialog = this.getDialog();
alert(dialog.getContentElement('info', 'grootte').getInputElement().$.id);
and it gives 'cke_117_select' as a result. (It's a selectbox)
alert(dialog.getContentElement('info', 'txtUrl').getInputElement().$.id);
gives 'cke_107_textInput'.
I think this is what you (or other visitors to this page) are looking for.
SetValueOf still doesn't provide the id, which you may need if you want to do more than fill a text field with a certain text.