public class Search extends LinearLayout
implements OnClickListener, OnKeyListener, OnLongClickListener, OnItemClickListener {
// Speed at which the widget slides up/down, in pixels/ms.
private static final float ANIMATION_VELOCITY = 1.0f;
/** The distance in dips between the optical top of the widget and the top if its bounds */
private static final float WIDGET_TOP_OFFSET = 9;
private final String TAG = "SearchWidget";
private Launcher mLauncher;
private EditText mSearchText;
private ImageButton mVoiceButton;
private ImageButton mClearButton;
/** The animation that morphs the search widget to the search dialog. */
private Animation mMorphAnimation;
/** The animation that morphs the search widget back to its normal position. */
private Animation mUnmorphAnimation;
// These four are passed to () when the search widget
// has finished morphing. They are instance variables to make it possible to update
// them while the widget is morphing.
private String mInitialQuery;
private boolean mSelectInitialQuery;
private Bundle mAppSearchData;
private boolean mGlobalSearch;
ListView mSearchResultList=null;
LinearLayout mSearchResult=null;
// For voice searching
private Intent mVoiceSearchIntent;
private int mWidgetTopOffset;
private int mAlpha = 0xff;//2011-01-12 add for draw alpha
private ArrayList<Map<String, Object>> mData;
private LockScreenAdapter mAdapter;
private List<Info> dataList;
private Context mContext;
private static final String[] ALL_THREADS_PROJECTION = {
Threads._ID, , Threads.MESSAGE_COUNT, Threads.RECIPIENT_IDS,
, Threads.SNIPPET_CHARSET, , ,
Threads.HAS_ATTACHMENT
};
private static final Uri sAllThreadsUri =
Threads.CONTENT_URI.buildUpon().appendQueryParameter("simple", "true").build();
/**
* Used to inflate the Workspace from XML.
*
* @param context The application's context.
* @param attrs The attributes set containing the Workspace's customization values.
*/
public Search(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
final float scale = ().getDisplayMetrics().density;
mWidgetTopOffset = (WIDGET_TOP_OFFSET * scale);
Interpolator interpolator = new AccelerateDecelerateInterpolator();
mMorphAnimation = new ToParentOriginAnimation();
// no need to apply transformation before the animation starts,
// since the gadget is already in its normal place.
(false);
// stay in the top position after the animation finishes
(true);
(interpolator);
(new () {
// The amount of time before the animation ends to show the search dialog.
private static final long TIME_BEFORE_ANIMATION_END = 80;
// The runnable which we'll pass to our handler to show the search dialog.
private final Runnable mShowSearchDialogRunnable = new Runnable() {
public void run() {
showSearchDialog();
}
};
public void onAnimationEnd(Animation animation) { }
public void onAnimationRepeat(Animation animation) { }
public void onAnimationStart(Animation animation) {
// Make the search dialog show up ideally *just* as the animation reaches
// the top, to aid the illusion that the widget becomes the search dialog.
// Otherwise, there is a short delay when the widget reaches the top before
// the search dialog shows. We do this roughly 80ms before the animation ends.
getHandler().postDelayed(
mShowSearchDialogRunnable,
(() - TIME_BEFORE_ANIMATION_END, 0));
}
});
mUnmorphAnimation = new FromParentOriginAnimation();
// stay in the top position until the animation starts
(true);
// no need to apply transformation after the animation finishes,
// since the gadget is now back in its normal place.
(false);
(interpolator);
(new (){
public void onAnimationEnd(Animation animation) {
clearAnimation();
}
public void onAnimationRepeat(Animation animation) { }
public void onAnimationStart(Animation animation) { }
});
mVoiceSearchIntent = new Intent(.ACTION_WEB_SEARCH);
(.EXTRA_LANGUAGE_MODEL,
.LANGUAGE_MODEL_WEB_SEARCH);
}
/**
* Implements OnClickListener.
*/
public void onVoiceClick(View v) {
/*if (v == mVoiceButton) {
startVoiceSearch();
} else {
();
}*/
}
public void onClick(View v) {//sxyang modified.
("");
();
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/**
(TAG, "view="+view+"position="+position+"onItemClick title="+("title")+" intent="+("intent"));
Intent intent = (Intent) ("intent");
getContext().startActivity(intent);
*/
}
private void startVoiceSearch() {
try {
getContext().startActivity(mVoiceSearchIntent);
} catch (ActivityNotFoundException ex) {
// Should not happen, since we check the availability of
// voice search before showing the button. But just in case...
(TAG, "Could not find voice search activity");
}
}
/**
* Sets the query text. The query field is not editable, instead we forward
* the key events to the launcher, which keeps track of the text,
* calls setQuery() to show it, and gives it to the search dialog.
*/
public void setQuery(String query) {
(query, );
}
/**
* Morph the search gadget to the search dialog.
* See {@link Activity#startSearch()} for the arguments.
*/
public void startSearch(String initialQuery, boolean selectInitialQuery,
Bundle appSearchData, boolean globalSearch) {
mInitialQuery = initialQuery;
mSelectInitialQuery = selectInitialQuery;
mAppSearchData = appSearchData;
mGlobalSearch = globalSearch;
showSearchDialog();
if (isAtTop()) {
// showSearchDialog();
} else {
// Call up the keyboard before we actually call the search dialog so that it
// (hopefully) animates in at about the same time as the widget animation, and
// so that it becomes available as soon as possible. Only do this if a hard
// keyboard is not currently available.
if (getContext().getResources().getConfiguration().hardKeyboardHidden ==
Configuration.HARDKEYBOARDHIDDEN_YES) {
InputMethodManager inputManager = (InputMethodManager)
getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
// (0, null);
}
// Start the animation, unless it has already started.
// if (getAnimation() != mMorphAnimation) {
// (getAnimationDuration());
// startAnimation(mMorphAnimation);
// }
}
}
/**
* Shows the system search dialog immediately, without any animation.
*/
private void showSearchDialog() {
(TAG, "showSearchDialog getText="+());
/*(
mInitialQuery, mSelectInitialQuery, mAppSearchData, mGlobalSearch);*/
}
/**
* Restore the search gadget to its normal position.
*
* @param animate Whether to animate the movement of the gadget.
*/
public void stopSearch(boolean animate) {
setQuery("");
// Only restore if we are not already restored.
if (getAnimation() == mMorphAnimation) {
if (animate && !isAtTop()) {
(getAnimationDuration());
startAnimation(mUnmorphAnimation);
} else {
clearAnimation();
}
}
}
private boolean isAtTop() {
return getWidgetTop() == 0;
}
private int getAnimationDuration() {
return (int) (getWidgetTop() / ANIMATION_VELOCITY);
}
/**
* Modify clearAnimation() to invalidate the parent. This works around
* an issue where the region where the end of the animation placed the view
* was not redrawn after clearing the animation.
*/
@Override
public void clearAnimation() {
Animation animation = getAnimation();
if (animation != null) {
();
if (()
&& ()
&& ()) {
((View) getParent()).invalidate();
} else {
invalidate();
}
}
}
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (!() &&
(keyCode != KeyEvent.KEYCODE_DPAD_UP) &&
(keyCode != KeyEvent.KEYCODE_DPAD_DOWN) &&
(keyCode != KeyEvent.KEYCODE_DPAD_LEFT) &&
(keyCode != KeyEvent.KEYCODE_DPAD_RIGHT) &&
(keyCode != KeyEvent.KEYCODE_DPAD_CENTER)) {
// Forward key events to Launcher, which will forward text
// to search dialog
switch (()) {
case KeyEvent.ACTION_DOWN:
return (keyCode, event);
case KeyEvent.ACTION_MULTIPLE:
return (keyCode, (), event);
case KeyEvent.ACTION_UP:
return (keyCode, event);
}
}
return false;
}
/**
* Implements OnLongClickListener to pass long clicks on child views
* to the widget. This makes it possible to pick up the widget by long
* clicking on the text field or a button.
*/
public boolean onLongClick(View v) {
return performLongClick();
}
@Override
protected void onFinishInflate() {
();
mSearchText = (EditText) findViewById(.search_src_text);
/**Begin: add by liuzepeng **/
if(((),,0) == 1) {
(.search_hint_iphone);
}
/**End: add by liuzepeng **/
mVoiceButton = (ImageButton) findViewById(.search_voice_btn);//sxyang modified.
mClearButton = (ImageButton) findViewById(.search_clear_btn);//sxyang modified.
(this);
//(this);
(this);
(this);//modified by liuzepeng
(this);
(this);
mSearchResultList = (ListView)findViewById();
mSearchResult = (LinearLayout)findViewById(.search_result);
();
/**
mData = new ArrayList<Map<String, Object>>();
mAdapter = new SimpleAdapter(getContext(),
mData,
,
new String[]{"icon","title"},
new int[]{,}
);
*/
/**
(new ViewBinder(){
@Override
public boolean setViewValue(View view ,Object data,String textRepresentation){
if(view instanceof ImageView && data instanceof Drawable){
ImageView iv=(ImageView)view;
((Drawable)data);
return true;
}
return false;
}
});
*/
configureVoiceSearchButton();
configureClearSearchButton();
(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
InputMethodManager inputMethodManager = (InputMethodManager)
getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
((), 0);
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {}
});
if(cachedNumbers == null)
cachedNumbers = new HashMap<Long, String>();
dataList = new ArrayList<Info>();
mAdapter = new LockScreenAdapter(getContext(), dataList);
(mAdapter);
(new TextWatcher(){
public void afterTextChanged(Editable s) {}
public void beforeTextChanged(CharSequence s, int start, int count,int after) {}
public void onTextChanged(CharSequence s, int start, int before,int count) {
();
if (s == null || ().equals("")|| ().toString().trim() == null) {
();
return;
}
if(mQueryHandler == null)
mQueryHandler = new SearchQueryHandler(());
String filter = ().replace("'",".");
startQuery(mQueryHandler, filter);
}});
}
private static Uri sAllCanonical = ("content://mms-sms/canonical-addresses");
private static final int QUERY_FILTERED_SMS_TOKEN = 1000;
private static final int QUERY_THREAD_ID_TOKEN = 1001;
private static final int QUERY_FILTERED_CONTACTS_TOKEN = 1002;
private static final int QUERY_FAVORITES_TOKEN = 1003;
private static final int QUERY_PANEL_TOKEN = 1004;
private static final int CONTACTS_ID_INDEX = 0;
private static final int CONTACTS_LOOKUP_KEY_INDEX = 1;
private static final int CONTACTS_DISPLAY_NAME_INDEX = 2;
private static final int THREAD_ID_INDEX = 0;
private static final int RECIPIENT_IDS_INDEX = 3;
private static final int SNIPPET_INDEX = 4;
private static final int TYPE_MMS = 100;
private static final int TYPE_CONTACTS = 101;
private static final int TYPE_FAVORITES = 102;
private static final int TYPE_PANEL = 103;
private static final int TYPE_WEB = 104;
private SearchQueryHandler mQueryHandler;
private Map<Long, String> cachedNumbers;
private String[] CONTACTS_FILTER_PROJECTION = new String[] {
Contacts._ID, // 0
Contacts.LOOKUP_KEY, // 1
Contacts.DISPLAY_NAME, // 2
};
/**
* the query order is:favorites->panel->mms->contacts. At last, add web search
* cancel all querying process and start a new
*/
public void startQuery(AsyncQueryHandler handler, String filter) {
(QUERY_FAVORITES_TOKEN);
(QUERY_PANEL_TOKEN);
(QUERY_THREAD_ID_TOKEN);
(QUERY_FILTERED_SMS_TOKEN);
(QUERY_FILTERED_CONTACTS_TOKEN);
startQueryFavorites(mQueryHandler, QUERY_FAVORITES_TOKEN, " title like '%"+filter+"%'", null , filter);//query favorites
}
public void startQueryFavorites(AsyncQueryHandler handler, int token,String selection,String[] selectionArgs, String filter) {
//(token);
(token, filter, .CONTENT_URI,
null, selection, selectionArgs, null);
}
public void startQueryPanel(AsyncQueryHandler handler, int token,String selection,String[] selectionArgs, String filter) {
//(token);
(token, filter, .CONTENT_URI, null, selection, selectionArgs, null);
}
public void startQueryThreadIdFromMms(AsyncQueryHandler handler, int token,String selection,String[] selectionArgs, String filter) {
//(token);
(token, filter, Threads.CONTENT_URI,
new String[]{Conversations.THREAD_ID}, selection, selectionArgs, Conversations.IPHONE_DEFAULT_SORT_ORDER);
}
public void startQueryFilteredContentFromMms(AsyncQueryHandler handler, int token,String selection,String[] selectionArgs, String filter) {
//(token);
(token, filter, sAllThreadsUri,
ALL_THREADS_PROJECTION, selection, selectionArgs, Conversations.IPHONE_DEFAULT_SORT_ORDER);
}
public void startQueryFromContacts(AsyncQueryHandler handler, int token, String[] projection, String selection,String[] selectionArgs, String filter) {
(token);
(token, filter, (.CONTENT_FILTER_URI, filter),
projection, selection, selectionArgs, "sort_key");
}
private final class SearchQueryHandler extends AsyncQueryHandler {
Drawable mmsIcon = null, contactsIcon = null;
public SearchQueryHandler(ContentResolver contentResolver) {
super(contentResolver);
if(mmsIcon == null)
mmsIcon = getAppIcon("");
if(contactsIcon == null)
contactsIcon = getAppIcon("");
}
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
//if(cursor == null) return;
//();
switch (token) {
case QUERY_FILTERED_SMS_TOKEN:
List<ItemInfo> itemInfoList = new ArrayList<ItemInfo>();
while(()) {
long threadId = (THREAD_ID_INDEX);
String snippet = (SNIPPET_INDEX);
String recipientIds = (RECIPIENT_IDS_INDEX);
String numbers = getAddresses(recipientIds);
if(!(snippet) && !(numbers)) {
ItemInfo itemInfo = new ItemInfo();
String title = numbers;
Intent intent = new Intent();
((Threads.CONTENT_URI, threadId));
("");
("");
("from", numbers);
//("inner", true);//deleted by sunjinbiao on 20120814 for bug[548]
if (title!= null ) {
();
= title;
= intent;
}
(itemInfo);
}
}
//("()="+());
if(()>0) {
Info info = new Info();
= TYPE_MMS;
= itemInfoList;
synchronized (dataList) {
(info);
}
}
();
String filter = (String)cookie;
if(isDigits(filter) && () > 3) {
startQueryFromContacts(mQueryHandler, QUERY_FILTERED_CONTACTS_TOKEN, CONTACTS_FILTER_PROJECTION, null, null, filter);//query contacts
} else if(!isDigits(filter)) {
startQueryFromContacts(mQueryHandler, QUERY_FILTERED_CONTACTS_TOKEN, CONTACTS_FILTER_PROJECTION, null, null, filter);//query contacts
}
break;
case QUERY_THREAD_ID_TOKEN:
String id = null;
while(()) {
if (id == null)
id = " _id = " + (0);
else
id += " or _id = " + (0);
}
if (id == null)
id = " _id = -1";
startQueryFilteredContentFromMms(mQueryHandler, QUERY_FILTERED_SMS_TOKEN,id, null, (String)cookie);
break;
case QUERY_FILTERED_CONTACTS_TOKEN:
itemInfoList = new ArrayList<ItemInfo>();
if(cursor == null) break;
while(()) {
long contactId = (CONTACTS_ID_INDEX);
String lookupKey = (CONTACTS_LOOKUP_KEY_INDEX);
String name = (CONTACTS_DISPLAY_NAME_INDEX);
Uri lookupUri = (contactId, lookupKey);
ItemInfo itemInfo = new ItemInfo();
String title = name;
Intent intent = intent = new Intent(Intent.ACTION_VIEW, lookupUri);
if (title!= null ) {
();
= title;
= intent;
(itemInfo);
}
}
if(()>0) {
Info info = new Info();
= TYPE_CONTACTS;
= itemInfoList;
synchronized (dataList) {
(info);
}
}
addWebSearch((String)cookie);
break;
case QUERY_FAVORITES_TOKEN:
int titleIndex = ();
int iconIndex = ();
int intentIndex = ();
Intent intent=null;
PackageManager manager = getContext().getPackageManager();
Drawable icon=null;
while (()) {
itemInfoList = new ArrayList<ItemInfo>();
ItemInfo itemInfo = new ItemInfo();
final String title = (titleIndex);
final String intentDescription = (intentIndex);
if(intentDescription == null)
continue;
try {
intent = (intentDescription, 0);
} catch ( e) {
}
icon = getApplicationsIcons(manager, getContext(), intent);
if (title!= null ) {
();
= title;
= intent;
= icon;
(itemInfo);
}
if(()>0) {
Info info = new Info();
= TYPE_FAVORITES;
= itemInfoList;
synchronized (dataList) {
(info);
();
}
}
}
();
startQueryPanel(mQueryHandler, QUERY_PANEL_TOKEN, " title like '%"+((String)cookie)+"%'", null , (String)cookie);//query panel
break;
case QUERY_PANEL_TOKEN:
titleIndex = ();
iconIndex = ();
intentIndex = ();
intent=null;
manager = getContext().getPackageManager();
icon=null;
while (()) {
itemInfoList = new ArrayList<ItemInfo>();
ItemInfo itemInfo = new ItemInfo();
final String title = (titleIndex);
final String intentDescription = (intentIndex);
if(intentDescription == null)
continue;
try {
intent = (intentDescription, 0);
} catch ( e) {
//intent = null;
}
icon = getApplicationsIcons(manager, getContext(), intent);
if (title!= null ) {
();
= title;
= intent;
= icon;
(itemInfo);
}
if(()>0) {
Info info = new Info();
= TYPE_PANEL;
= itemInfoList;
synchronized (dataList) {
(info);
();
}
}
}
();
startQueryThreadIdFromMms(mQueryHandler, QUERY_THREAD_ID_TOKEN," body like '%"+((String)cookie)+"%'", null, ((String)cookie));//query mms
break;
default:
(TAG, "onQueryComplete called with unknown token " + token);
}
();
}
@Override
protected void onDeleteComplete(int token, Object cookie, int result) {}
}
private Info mFootInfo = null;
private void addWebSearch(String filter) {
/**Begin: add by liuzepeng **/
String editText = ().toString().trim();
//("liuzepeng","filter:"+filter+"/():"+());
if(!(filter)) {
filter = editText;
if(("")) {
();
return;
}
}
/**Begin: add by liuzepeng **/
List<ItemInfo> itemInfoList = new ArrayList<ItemInfo>();
ItemInfo itemInfo = new ItemInfo();
Drawable icon = getAppIcon("");
Uri uri = ("/s?ie=utf-8&word="+filter);
Resources re = getContext().getResources();
String title = (.web_search);
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
if (title!= null ) {
();
= title;
= intent;
= icon;
(itemInfo);
}
if(mFootInfo == null){
mFootInfo = new Info();
= TYPE_WEB;
}
= itemInfoList;
/**Begin: modified by liuzepeng **/
if(!(mFootInfo)) {
(mFootInfo);
} else {
(mFootInfo);
(mFootInfo);
}
/**Begin: modified by liuzepeng **/
();
}
private Drawable getAppIcon(String packageName) {
List<PackageInfo> packages = getContext().getPackageManager().getInstalledPackages(0);
Drawable appIcon = null;
for (int i = 0; i < (); i++) {
PackageInfo packageInfo = (i);
if((packageName)) {
appIcon = (getContext().getPackageManager());
break;
}
}
return appIcon;
}
public String getAddresses(String spaceSepIds) {
String numbers = "";
synchronized (cachedNumbers) {
String[] ids = (" ");
for (String id : ids) {
long longId;
try {
longId = (id);
} catch (NumberFormatException ex) {
// skip this id
continue;
}
String number = (longId);
if (number == null) {
getNumbers();
number = (longId);
}
if ((number)) {
(TAG, "RecipientId " + longId + " has empty number!");
} else {
numbers += number;
}
}
return numbers;
}
}
public void getNumbers() {
final ContentResolver contentResolver = ();
Cursor c = (sAllCanonical, null, null, null, null);
if (c == null) {
(TAG, "null Cursor in fill()");
return;
}
try {
synchronized (cachedNumbers) {
// Technically we don't have to clear this because the stupid
// canonical_addresses table is never GC'ed.
();
while (()) {
// TODO: don't hardcode the column indices
long id = (0);
String number = (1);
(id, number);
}
}
} finally {
();
}
}
private boolean isDigits(String str) {
if(str == null || "".equals(str))
return false;
int len = ();
for(int i=0;i<len;i++) {
char c = (i);
if(!(c))
return false;
}
return true;
}
private class Info {
public int type;
public List<ItemInfo> data;
public String toString() {
return "type="+type;
}
}
private class ItemInfo {
public Drawable icon;
public String title;
public Intent intent;
public String toString() {
return "title="+title;
}
}
class LockScreenAdapter extends BaseAdapter {
private Context context;
List<Info> data;
LayoutInflater inflater;
Drawable mmsIcon = null, contactsIcon = null;
public LockScreenAdapter(Context aContext,List<Info> aData) {
context = aContext;
inflater = (context);
data = aData;
if(mmsIcon == null)
mmsIcon = getAppIcon("");
if(contactsIcon == null)
contactsIcon = getAppIcon("");
}
public int getCount() {
return ();
}
public Object getItem(int position) {
return (position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
convertView = (.item_launcher_search, null);
if((position+1)%2 == 0 ){
(getResources().getDrawable(.result0));
}else{
(getResources().getDrawable(.result1));
}
int wrapContent = .WRAP_CONTENT;
int fillParent = .FILL_PARENT;
contentsllp = new (fillParent, wrapContent);
LinearLayout contents = (LinearLayout) ();
ImageView icon = (ImageView) ();
Info info = (position);
int type = ;
int size = ();
for (int i = 0; i < size; i++) {
ItemInfo itemInfo = (i);
(createItemView(itemInfo), contentsllp);
if(type == TYPE_MMS)
(mmsIcon);
else if(type == TYPE_CONTACTS)
(contactsIcon);
else
();
if(size>1 && i!=size -1){
TextView hLine = new TextView(getContext());
hLinellp = new (fillParent, wrapContent);
= 1;
((255, 157, 157, 160));
(hLine, hLinellp);
TextView bLine = new TextView(getContext());
((255, 255, 255, 255));
(bLine, hLinellp);
}
}
return convertView;
}
}
LinearLayout createItemView(final ItemInfo itemInfo) {
final Context cxt = getContext();
LinearLayout contentLayout = new LinearLayout(cxt);
TextView seperatorLine = new TextView(cxt);
TextView content = new TextView(cxt);
int wrapContent = .WRAP_CONTENT;
int fillParent = .FILL_PARENT;
seperatorLinellp = new (wrapContent, 45);
= 50;
= 70;
contentllp = new (fillParent, 45);
=Gravity.CENTER_VERTICAL;
= 5;
(.launcher_item_vertical_line);
();
();
(Gravity.CENTER_VERTICAL);
();
(seperatorLine, seperatorLinellp);
(content, contentllp);
(.search_item_press);
(new OnClickListener() {
@Override
public void onClick(View v) {
();
}
});
return contentLayout;
}
@Override
public void onDetachedFromWindow() {
();
}
/**
* If appropriate & available, configure voice search
*
* Note: Because the home screen search widget is always web search, we only check for
* getVoiceSearchLaunchWebSearch() modes. We don't support the alternate form of app-specific
* voice search.
*/
private void configureVoiceSearchButton() {
// Enable the voice search button if there is an activity that can handle it
PackageManager pm = getContext().getPackageManager();
ResolveInfo ri = (mVoiceSearchIntent,
PackageManager.MATCH_DEFAULT_ONLY);
boolean voiceSearchVisible = ri != null;
// finally, set visible state of voice search button, as appropriate
(voiceSearchVisible ? : );
}
private void configureClearSearchButton() {
//sxyang modified.
(new TextWatcher(){
public void afterTextChanged(Editable s) {}
public void beforeTextChanged(CharSequence s, int start, int count,int after) {}
public void onTextChanged(CharSequence s, int start, int before,int count) {
if (s == null || ().equals("")) {
();
} else {
();
}
}});
}
/**
* Sets the {@link Launcher} that this gadget will call on to display the search dialog.
*/
public void setLauncher(Launcher launcher) {
mLauncher = launcher;
}
/**
* Moves the view to the top left corner of its parent.
*/
private class ToParentOriginAnimation extends Animation {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
float dx = -getLeft() * interpolatedTime;
float dy = -getWidgetTop() * interpolatedTime;
().setTranslate(dx, dy);
}
}
/**
* Moves the view from the top left corner of its parent.
*/
private class FromParentOriginAnimation extends Animation {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
float dx = -getLeft() * (1.0f - interpolatedTime);
float dy = -getWidgetTop() * (1.0f - interpolatedTime);
().setTranslate(dx, dy);
}
}
/**
* The widget is centered vertically within it's 4x1 slot. This is
* accomplished by nesting the actual widget inside another view. For
* animation purposes, we care about the top of the actual widget rather
* than it's container. This method return the top of the actual widget.
*/
private int getWidgetTop() {
return getTop() + getChildAt(0).getTop() + mWidgetTopOffset;
}
/*
* //2011-01-12 add for draw alpha
*/
public boolean setAlpha(int alpha) {
if (mAlpha != alpha) {
mAlpha = alpha;
Drawable background = findViewById(.search_plate).getBackground();
//Drawable background = findViewById(.search_plate).getBackground();
if (background != null) {
(alpha);
} else {
(TAG, "background null");
}
background = findViewById(.search_src_text).getBackground();
if (background != null) {
if (background instanceof StateListDrawable) {
StateListDrawable stateDrawable = (StateListDrawable)background;
int stateCount = ();
for (int i = 0; i < stateCount; i++) {
Drawable d = (i);
(alpha);
}
} else {
(alpha);
}
} else {
(TAG, "background null");
}
();
return true;
}
return false;
}
/**
* Morph the search gadget to the search dialog.
* See {@link Activity#startSearch()} for the arguments.
*/
public void showstartSearch() {
//("", );
//();
if(() != ) {
();
(TAG, "showstartSearch");
if (getContext().getResources().getConfiguration().hardKeyboardHidden ==
Configuration.HARDKEYBOARDHIDDEN_YES) {
InputMethodManager inputManager = (InputMethodManager)
getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
(0, null);
}
}
}
private Drawable getApplicationsIcons(PackageManager manager,Context context, Intent intent){
Drawable icon=null;
final ResolveInfo resolveInfo = (intent, 0);
if(resolveInfo == null) return null;
final ActivityInfo activityInfo = ;
Drawable customerIcon = (context, intent);
if(customerIcon != null){
icon = (customerIcon, context);
} else {
icon = ((manager), context);
}
Bitmap bitmap = (icon,context);
BitmapDrawable bd = new BitmapDrawable(bitmap);
return bd;
}
}
<
xmlns:andro
xmlns:launcher="/apk/res/.launcher2"
android:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="top">
<LinearLayout
android:
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="14dip"
android:paddingRight="4dip"
android:paddingTop="5dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:background="@drawable/textfield_searchwidget" >
<EditText
android:
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:textSize="15sp"
android:paddingLeft="16dip"
android:hint="@string/search_hint"
android:singleLine="true"
android:background="@android:color/transparent"
android:textAppearance="?android:attr/textAppearanceMediumInverse"
android:textColor="@android:color/primary_text_light"
/>
<ImageButton
android:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="0dip"
android:background="@drawable/iphone_clean_icon"
/>
<ImageButton
android:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dip"
android:background="@*android:drawable/btn_search_dialog_voice"
android:src="@*android:drawable/ic_btn_speak_now"
/>
</LinearLayout>
<LinearLayout android:
android:layout_weight="1"
android:layout_height="0dip"
android:layout_width="fill_parent"
android:layout_marginTop="5dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="11dip"
android:background="@drawable/search_list_bg">
<ListView android:layout_width="fill_parent"
android:
android:scrollbars="vertical"
android:listSelector="@android:color/transparent"
android:cacheColorHint="#00000000"
android:divider="#CCCCCC"
android:dividerHeight="1px"
android:layout_height="fill_parent"
android:fadingEdge="none" >
</ListView>
</LinearLayout>
</>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:andro
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="horizontal">
<ImageView android: android:layout_width="30dip"
android:layout_height="30dip"
android:layout_margin="5dip" />
<LinearLayout android:
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_gravity="center_vertical"
android:layout_toRightOf="@id/icon">
</LinearLayout>
</RelativeLayout>