I could not find any column to set background image inside SearchManager class.
When Google Play app's search result is selected, a background image is displayed but I don't seem to find any public api/column to set it.
Here is my code for content provider's query method
Any idea guys?
Device: Nexus player
#Nullable
#Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
final String searchKey = (selectionArgs == null) ? "" : selectionArgs[0];
if (!TextUtils.isEmpty(searchKey)) {
// Get title list from search query
ArrayList<TitleSimpleInfo> searchedTitleList = searchTitlesWithKeyword(searchKey);
// return null cursor if no data found
if (searchedTitleList == null || searchedTitleList.isEmpty()) {
return null;
}
// prepare cursor
MatrixCursor matrixCursor = new MatrixCursor(new String[]{
SearchManager.SUGGEST_COLUMN_TEXT_1,
SearchManager.SUGGEST_COLUMN_TEXT_2,
SearchManager.SUGGEST_COLUMN_CONTENT_TYPE,
SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
SearchManager.SUGGEST_COLUMN_INTENT_DATA,
SearchManager.SUGGEST_COLUMN_RESULT_CARD_IMAGE,
});
// add search result to cursor
for (TitleSimpleInfo title : searchedTitleList) {
matrixCursor.addRow(new Object[]{
title.getTitleName(),
title.getTitleCatch(),
SEARCH_CONTENT_TYPE,
Intent.ACTION_SEARCH,
SEARCH_INTENT_DATA + title.getTitleCode(),
SEARCH_IMAGE_HEADER + title.getThumbnailUrl(),
});
}
return matrixCursor;
} else {
return null;
}
}
Related
The goal is to filter the tableView .So, when I input something to filter it works just fine , but then when I hit backspace or remove the inputs on the textField Area to go back,the tableView shows no content in the table ,Then I have to restart the program to reload and show the data.The data is saved and loaded from an xml file.
Also, I put an ObservaleList of contacts on the Data Class to load and store the contactList ,But on the Controller I have a similar list for the filter then the controller extends the data class to getContacts from there and add the filtredList to it. I am pretty much sure that the problem comes from that
public Data() {
contacts = FXCollections.observableArrayList();
}
public ObservableList<Contact> getContacts() {
return contacts;
}
This is below the filter handle
public void filterContactList(String oldValue, String newValue) {
ObservableList<Contact> filteredList = FXCollections.observableArrayList();
if (filterInput == null || newValue.length() < oldValue.length() || newValue == null){
contactsTable.setItems(getContacts());
}else {
newValue = newValue.toUpperCase();
for (Contact contact: contactsTable.getItems()){
String filterFirstName = contact.getFirstName();
String filterLastName = contact.getFirstName();
if (filterFirstName.toUpperCase().contains(newValue) || filterLastName.toUpperCase().contains(newValue)){
filteredList.add(contact);
}
}
contactsTable.setItems(filteredList);
}
}
and this is the init listener
filterInput.textProperty().addListener(new ChangeListener<String>() {
#Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
filterContactList((String) oldValue, (String) newValue);
}
});
Do yourself a favor an use FilteredList for this:
private FilteredList<Contact> filteredContacts = new FilteredList<>(getContacts());
...
contactsTable.setItems(filteredList);
...
public void filterContactList(String oldValue, String newValue) {
if (newValue == null) {
filteredContacts.setPredicate(null);
} else {
final String lower = newValue.toLowerCase();
filteredContacts.setPredicte(contact -> contact.getFirstName().toLowerCase().contains(lower) || contact.getLastName().toLowerCase().contains(lower));
}
}
BTW: since this is called from a listener to filterInput's textProperty, I removed the check for null.
I'm trying to set field at index 0 in Vaadin combo box to default value, so I could avoid error message if user doesen't select anything. So I would like that instead of blank field I have populated field at index 0.
I have tried to set it and managed it with this:
field.setNullSelectionAllowed(true);
field.setNullSelectionItemId(container.getIdByIndex(0));
So I don't have blank value at index 0, instead my previous value of index 1 is now at index 0. And that is exactly what I want and need and in combo box looks just as I want.
But, unfortunately, when I submit my form, value is not passed. Only values after index 0 are passed. It's so frustrating, can somebody help me? Value passed to setNullSelectionItemId exists 100%.
How can I grab value from index at place 0 in combo box?
p.s. here is my code:
public Field<?> buildAndBindComboBox(final String caption, final BeanItemContainer<?> container,
final Object propertyId, final String title, final ValueChangeListener listener, final boolean nullAllowed,
final boolean required, final boolean enabled, final boolean visible) {
#SuppressWarnings("serial")
ComboBox field = new ComboBox(caption, container) {
// http://dev.vaadin.com/ticket/10544
// - typing in ComboBox causes Internal Error
private boolean inFilterMode;
#Override
public void containerItemSetChange(com.vaadin.data.Container.ItemSetChangeEvent event) {
if (inFilterMode) {
super.containerItemSetChange(event);
}
}
#Override
protected List<?> getOptionsWithFilter(boolean needNullSelectOption) {
try {
inFilterMode = true;
return super.getOptionsWithFilter(needNullSelectOption);
} finally {
inFilterMode = false;
}
}
};
field.setStyleName("comboBox");
field.setInputPrompt("Select");
if(defaultValue == true){
field.setNullSelectionAllowed(false);
field.setNullSelectionItemId(container.getIdByIndex(0).toString());
//field.select(container.getIdByIndex(0));
//field.setValue(container.getIdByIndex(0));
//field.setRequired(false);
defaultValue = false;
} else {
field.setNullSelectionAllowed(nullAllowed);
field.setRequired(required);
}
field.setImmediate(true);
field.setNewItemsAllowed(false);
field.setFilteringMode(FilteringMode.CONTAINS);
if (title != null) {
field.setItemCaptionPropertyId(title);
}
//field.setNullSelectionAllowed(nullAllowed);
//field.setRequired(required);
field.setVisible(visible);
if (listener != null) {
field.addValueChangeListener(listener);
}
this.bind(field, propertyId);
field.setEnabled(enabled);
return field;
}
public void setDefaultValueFirstItem(boolean def){
defaultValue = def;
}
It is binded like this:
commitmentFeeBinder.setDefaultValueFirstItem(true);
commitmentFeeBinder.buildAndBindComboBox("No working day labels", noWorkingDays, "noWorkingDaysCF", "title", null, false, !transaCF, true, !transaCF);
If I understood your question correctly, Steffen Harbich is correct in suggesting that if you want the first item to be selected by default you should disable null selection and select the first item by default. E.g. this works:
ComboBox cb = new ComboBox("", Arrays.asList("First", "Second", "Third"));
cb.setNullSelectionAllowed(false);
cb.select("First");
Or alternatively with a BeanItemContainer:
List<MyBean> beans = Arrays.asList(new MyBean("First"), new MyBean("Second"), new MyBean("Third"));
BeanItemContainer<MyBean> bic = new BeanItemContainer<>(MyBean.class, beans);
ComboBox cb = new ComboBox("", bic);
cb.setNullSelectionAllowed(false);
cb.select(bic.getIdByIndex(0));
private void resetComboBoxToIndex(ComboBox combo, int index) {
BeanItemContainer<Bean_ComboBox> items_combo = (BeanItemContainer<Bean_ComboBox>)combo.getContainerDataSource();
if(items_combo != null && items_combo.size() > index) {
Bean_ComboBox primerItem = items_combo.getIdByIndex(index);
if(primerItem != null) {
combo.select(primerItem);
}
}
}
My modelView:
public string Status {
get { return _status; }
set {
if (value == _status) {
return;
}
_status = value;
OnPropertyChanged ("Status");
}
My View:
Label labelStatus = new Label {
TextColor = Color.Green,
FontSize = 20d
};
labelStatus.SetBinding (Label.TextProperty, "Status");
Then I want to present the status using something like:
string presentStatus = string.Format("Your status is {0}...", labelStatus);
Label yourStatus = new Label{Text=presentStatus}
But that doesn't really work. Nor does using
string presentStatus = string.Format("Your status is {0}...", SetBinding(Label.TextProperty,"Status"));
So how should I do to add my bound values with more text before presenting them for the user in a view.
If using XAML (which i don't), it seems possible according to: http://developer.xamarin.com/guides/cross-platform/xamarin-forms/xaml-for-xamarin-forms/data_binding_basics/
Xamarin Forms binding implementation doesn't currently allow complex binding scenarios like embedding bound text within static text.
There are two options
a. use multiple labels - one with the static text, one with the bound text
b. use a property on your ViewModel that concatenates the text for you
public string StatusText
{
get
{
return string.Format("Your status is {0}...", Status);
}
}
public string Status {
get { return _status; }
set {
if (value == _status) {
return;
}
_status = value;
OnPropertyChanged ("Status");
OnPropertyChanged ("StatusText");
}
You can do that in the BindingContextChanged-event:
labelStatus.BindingContextChanged += (sender, e) =>
{
// Here you can change the Text dynamically
// E.G. labelStatus.text = "Title: " + labelStatus.text
};
i'm creating one application in which i get gift images with id's from web server through JSON. When i click on any gift image, it goes on next page where it shows all information of that image (get image information with its id from web server through JSON).
Problem is: When i click on any gift image on page to see its relevant information, it gets the last gift image id every time, i want when i click on any image, it gets the specific image id which i click. How it is possible??
Screenshot of the page is : http://ugo.offroadstudios.com/gifts.png
Here is sample code:
public class Gifts extends MainScreen {
String giftsid;
BitmapField giftimg;
public Gifts(){
setTitle("Gift Store");
creategifts();
}
public void creategifts()
{
//Link URL
String strURL = "http://ugo.offroadstudios.com/api/frndgift/?loginusername=adil;deviceside=true";
webConnection wb = new webConnection();
String res = wb.getJson(strURL);
try {
JSONObject object = new JSONObject(res);
if(object.getString("status") == "error")
{
Dialog.alert("Invalid "+object.getString("status"));
}
else
{
int totalgifts;
totalgifts = object.getInt("totalgifts");
Bitmap listThumb;
JSONArray imagearr;
JSONArray giftsidarr;
String imgname;
Bitmap bmpResized;
for(int i=0; i < totalgifts; i++){
imagearr = object.getJSONArray("gifts_image");
imgname = imagearr.getString(i);
giftsidarr = object.getJSONArray("gifts_id");
giftsid = giftsidarr.getString(i);
listThumb = getImage.getImageFromUrl("http://ugo.offroadstudios.com/wp-content/plugins/bp-gifts-rebirth/includes/images/"+imgname+";deviceside=true");
bmpResized = GPATools.ResizeTransparentBitmap(listThumb, 80, 80,
Bitmap.FILTER_LANCZOS, Bitmap.SCALE_TO_FIT);
giftimg =new BitmapField(bmpResized,FOCUSABLE)
{
protected boolean navigationClick(int status, int time)
{
Dialog.alert("giftsid "+giftsid);
UiApplication.getUiApplication().pushScreen(new SendGift(giftsid));
return true;
}
};
add(giftimg);
}
}
}
catch (JSONException e) {
System.out.println("EX is "+e);
e.printStackTrace();
}
}
}
You are always getting the gift id of the last gift in the list because you have created your buttons with this code:
giftimg =new BitmapField(bmpResized,FOCUSABLE)
{
protected boolean navigationClick(int status, int time)
{
Dialog.alert("giftsid "+giftsid);
UiApplication.getUiApplication().pushScreen(new SendGift(giftsid));
return true;
}
};
Your navigationClick() method used the giftsid variable, which is a persistent member variable of your class. You assign this variable in your for loop, so the final value it keeps is the last value assigned in the loop (giftsidarr.getString(totalgifts)).
Although you declare the navigationClick() method in a loop where the giftsid is many different values, the navigationClick() method uses the value of giftsid when it is run. The last value.
There's many ways to fix it. You can use a separate constant value in your loop:
final String nextGiftsId = giftsid;
giftimg =new BitmapField(bmpResized,FOCUSABLE)
{
protected boolean navigationClick(int status, int time)
{
Dialog.alert("nextGiftsId= "+nextGiftsId);
UiApplication.getUiApplication().pushScreen(new SendGift(nextGiftsId));
return true;
}
};
Or, as Signare suggested, attach a cookie to each button that identifies its corresponding gift:
giftimg =new BitmapField(bmpResized,FOCUSABLE)
{
protected boolean navigationClick(int status, int time)
{
String giftId = (String)getCookie(); // read gift id from the cookie
Dialog.alert("giftId= "+giftId);
UiApplication.getUiApplication().pushScreen(new SendGift(giftId));
return true;
}
};
giftimg.setCookie(giftsid); // set the cookie after creating the field
Inside your for loop, add the following code -
giftimg[i].setChangeListener(this);
Then -
public void fieldChanged(Field field, int context) {
for(int i=0;i<totalgifts;i++) {
if(field == giftimg[i]) {
// you can trigger your event
}
}
EDIT :-
giftimg[i].setChangeListener(listener);
listener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
if ( field instanceof BitmapField ) {
for(int i=0;i<totalgifts;i++) {
if ( field == giftimg[i] ) {
// you can trigger your event
}
}
}
}
};
I'm having trouble to handle KeyboardEvents on DartFlash.
I don't know what I'm doing wrong here. Could someone help me?
My intention is to just create a very simple walking character and every time I hit a key, it moves in the x and y, only to start understanding DartFlash API.
Here is the full source code:
class Character extends Sprite
{
TextureAtlas _atlas;
Bitmap _currentBitmap;
int _direction;
String _name;
Character(this._name, this._atlas)
{
this._direction=Direction.down;
this._currentBitmap=this.getBitmap("stand", this._direction);
addChild(this._currentBitmap);
}
String get name => this._name;
Bitmap getBitmap(String name, [int direction, int number])
{
if(direction == null)
{
return new Bitmap(this._atlas.getBitmapData(name));
} else if (number == null)
{
return new Bitmap(this._atlas.getBitmapData("${name}-${Direction.getDirectionName(direction)}"));
}
return new Bitmap(this._atlas.getBitmapData("${name}-${Direction.getDirectionName(direction)}-${number}"));
}
}
Character dk;
void keyboardListener(KeyboardEvent ke) {
print("Key code: ${ke.keyCode}");
dk.x+=1;
dk.y+=1;
}
void main()
{
Stage mainStage = new Stage("mainStage", html.document.query("#mainStage"));
RenderLoop renderLoop = new RenderLoop();
renderLoop.addStage(mainStage);
Resource resource=new Resource();
resource.addTextureAtlas("DarkKnight", "resources/DarkKnight.json", TextureAtlasFormat.JSONARRAY);
resource.load().then((res)
{
print(resource.toString());
dk=new Character("DarkKnight", resource.getTextureAtlas("DarkKnight"));
dk.x=10;
dk.y=10;
mainStage.addChild(dk);
dk.addEventListener(KeyboardEvent.KEY_DOWN, keyboardListener, false);
mainStage.focus=dk;
print("${mainStage.focus.name}");
});
}
There is an easy workaround. Just add an "tabindex" attribute to the canvas element and afterwards you will received KeyboardEvents. If the "tabindex" is not set, then the canvas does not receive keyboard events.
<canvas id="stage" width="800" height="600" tabindex="1"></canvas>
The canvas also needs the focus. You can get the focus by clicking on the canvas or problematically set the focus:
query('#stage').focus();