-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3732 from hieupham007/timob-11604-3_0_X
Timob 11604 3 0 x: Implementing SearchView
- Loading branch information
Showing
8 changed files
with
343 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
android/modules/ui/src/java/ti/modules/titanium/ui/SearchViewProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2009-2013 by Appcelerator, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
package ti.modules.titanium.ui; | ||
|
||
|
||
import org.appcelerator.kroll.annotations.Kroll; | ||
import org.appcelerator.kroll.common.Log; | ||
import org.appcelerator.titanium.TiC; | ||
import org.appcelerator.titanium.proxy.TiViewProxy; | ||
import org.appcelerator.titanium.view.TiUIView; | ||
|
||
import ti.modules.titanium.ui.android.AndroidModule; | ||
import ti.modules.titanium.ui.widget.searchview.TiUISearchView; | ||
import android.app.Activity; | ||
import android.os.Build; | ||
|
||
@Kroll.proxy(creatableInModule = AndroidModule.class, propertyAccessors = { | ||
TiC.PROPERTY_ICONIFIED, TiC.PROPERTY_ICONIFIED_BY_DEFAULT, TiC.PROPERTY_HINT_TEXT, TiC.PROPERTY_VALUE }) | ||
public class SearchViewProxy extends TiViewProxy { | ||
|
||
private static final String TAG = "SearchProxy"; | ||
|
||
public SearchViewProxy() { | ||
super(); | ||
defaultValues.put(TiC.PROPERTY_ICONIFIED_BY_DEFAULT, true); | ||
} | ||
|
||
@Override | ||
public TiUIView createView(Activity activity) { | ||
if (Build.VERSION.SDK_INT >= TiC.API_LEVEL_HONEYCOMB) { | ||
return new TiUISearchView(this); | ||
} | ||
|
||
Log.e(TAG, "SearchView is only supported on target API 11+"); | ||
return null; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
android/modules/ui/src/java/ti/modules/titanium/ui/widget/searchview/TiUISearchView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/** | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2009-2013 by Appcelerator, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
package ti.modules.titanium.ui.widget.searchview; | ||
|
||
import org.appcelerator.kroll.KrollDict; | ||
import org.appcelerator.kroll.KrollProxy; | ||
import org.appcelerator.titanium.TiC; | ||
import org.appcelerator.titanium.proxy.TiViewProxy; | ||
import org.appcelerator.titanium.util.TiConvert; | ||
import org.appcelerator.titanium.util.TiUIHelper; | ||
import org.appcelerator.titanium.view.TiUIView; | ||
|
||
import ti.modules.titanium.ui.widget.searchbar.TiUISearchBar.OnSearchChangeListener; | ||
import android.widget.SearchView; | ||
|
||
public class TiUISearchView extends TiUIView implements SearchView.OnQueryTextListener, SearchView.OnCloseListener { | ||
private SearchView searchView; | ||
|
||
public static final String TAG = "SearchView"; | ||
|
||
protected OnSearchChangeListener searchChangeListener; | ||
|
||
public TiUISearchView(TiViewProxy proxy) { | ||
super(proxy); | ||
|
||
searchView = new SearchView(proxy.getActivity()); | ||
searchView.setOnQueryTextListener(this); | ||
searchView.setOnCloseListener(this); | ||
searchView.setOnQueryTextFocusChangeListener(this); | ||
|
||
setNativeView(searchView); | ||
|
||
} | ||
|
||
@Override | ||
public void processProperties(KrollDict props) { | ||
super.processProperties(props); | ||
|
||
// Check if the hint text is specified when the view is created. | ||
if (props.containsKey(TiC.PROPERTY_HINT_TEXT)) { | ||
searchView.setQueryHint(props.getString(TiC.PROPERTY_HINT_TEXT)); | ||
} | ||
if (props.containsKey(TiC.PROPERTY_VALUE)) { | ||
searchView.setQuery(props.getString(TiC.PROPERTY_VALUE), false); | ||
} | ||
if (props.containsKey(TiC.PROPERTY_ICONIFIED)) { | ||
searchView.setIconified(props.getBoolean(TiC.PROPERTY_ICONIFIED)); | ||
} | ||
if (props.containsKey(TiC.PROPERTY_ICONIFIED_BY_DEFAULT)) { | ||
searchView.setIconifiedByDefault(props.getBoolean(TiC.PROPERTY_ICONIFIED_BY_DEFAULT)); | ||
} | ||
if (props.containsKey(TiC.PROPERTY_SUBMIT_ENABLED)) { | ||
searchView.setSubmitButtonEnabled((props.getBoolean(TiC.PROPERTY_SUBMIT_ENABLED))); | ||
} | ||
} | ||
|
||
@Override | ||
public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy) { | ||
|
||
if (key.equals(TiC.PROPERTY_HINT_TEXT)) { | ||
searchView.setQueryHint((String) newValue); | ||
} else if (key.equals(TiC.PROPERTY_VALUE)) { | ||
searchView.setQuery((String) newValue, false); | ||
} else if (key.equals(TiC.PROPERTY_ICONIFIED)) { | ||
searchView.setIconified(TiConvert.toBoolean(newValue)); | ||
} else if (key.equals(TiC.PROPERTY_ICONIFIED_BY_DEFAULT)) { | ||
searchView.setIconifiedByDefault(TiConvert.toBoolean(newValue)); | ||
} else if (key.equals(TiC.PROPERTY_SUBMIT_ENABLED)) { | ||
searchView.setSubmitButtonEnabled(TiConvert.toBoolean(newValue)); | ||
} else { | ||
super.propertyChanged(key, oldValue, newValue, proxy); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean onClose() { | ||
proxy.fireEvent(TiC.EVENT_CANCEL, null); | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean onQueryTextChange(String query) { | ||
proxy.setProperty(TiC.PROPERTY_VALUE, query); | ||
if (searchChangeListener != null) { | ||
searchChangeListener.filterBy(query); | ||
} | ||
proxy.fireEvent(TiC.EVENT_CHANGE, null); | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean onQueryTextSubmit(String query) { | ||
TiUIHelper.showSoftKeyboard(nativeView, false); | ||
proxy.fireEvent(TiC.EVENT_SUBMIT, null); | ||
return false; | ||
} | ||
|
||
public void setOnSearchChangeListener(OnSearchChangeListener listener) { | ||
searchChangeListener = listener; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.