The layout of search results in imitation iphone _android

Source: Internet
Author: User
Tags gettext int size trim home screen
Copy Code code as follows:



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 it 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 Launcher.startsearch () 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.date, Threads.message_count, Threads.recipient_ids,


Threads.snippet, Threads.snippet_charset, Threads.read, Threads.error,


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 of the application ' s context.


* @param attrs The attributes set containing the Workspace ' s customization values.


*/


Public Search (context, AttributeSet attrs) {


Super (context, attrs);


Mcontext = context;


Final float scale = context.getresources (). Getdisplaymetrics (). density;


Mwidgettopoffset = Math.Round (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 it normal place.


Mmorphanimation.setfillbefore (FALSE);


Stay in the top position after the animation finishes


Mmorphanimation.setfillafter (TRUE);


Mmorphanimation.setinterpolator (Interpolator);


Mmorphanimation.setanimationlistener (New Animation.animationlistener () {


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 the widget becomes the search dialog.


Otherwise, there is a short delay the widget reaches the top before


The search dialog shows. We do this roughly 80ms before the animation ends.


GetHandler (). postdelayed (


Mshowsearchdialogrunnable,


Math.max (Mmorphanimation.getduration ()-time_before_animation_end, 0));


}


});


Munmorphanimation = new Fromparentoriginanimation ();


Stay in the top position until the animation starts


Munmorphanimation.setfillbefore (TRUE);


No need to apply transformation after the animation finishes,


Since the "gadget is" now "in its" normal place.


Munmorphanimation.setfillafter (FALSE);


Munmorphanimation.setinterpolator (Interpolator);


Munmorphanimation.setanimationlistener (New Animation.animationlistener () {


public void Onanimationend (Animation Animation) {


Clearanimation ();


}


public void Onanimationrepeat (Animation Animation) {}


public void Onanimationstart (Animation Animation) {}


});





Mvoicesearchintent = new Intent (Android.speech.RecognizerIntent.ACTION_WEB_SEARCH);


Mvoicesearchintent.putextra (Android.speech.RecognizerIntent.EXTRA_LANGUAGE_MODEL,


Android.speech.RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);


}


/**


* Implements Onclicklistener.


*/


public void Onvoiceclick (View v) {


/*if (v = = Mvoicebutton) {


Startvoicesearch ();


} else {


Mlauncher.onsearchrequested ();


}*/


}


public void OnClick (View v) {//sxyang modified.


Msearchtext.settext ("");


Msearchresult.setvisibility (view.invisible);


}


@Override


public void Onitemclick (adapterview<?> parent, view view, int position, long ID) {


/**


LOG.W (TAG, "view=" +view+ "position=" +position+ "id=" +id);





Map map = (map) madapter.getitem (position);


LOG.W (TAG, "Onitemclick title=" +map.get ("title") + "intent=" +map.get ("intent"));


Intent Intent = (Intent) map.get ("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 the case ...


LOG.W (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) {


Msearchtext.settext (query, TextView.BufferType.NORMAL);


}


/**


* Morph the search gadget to the search dialog.


* @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 about the same time as the widget animation, and


So, it becomes available as soon as possible. Only does 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);


inputmanager.showsoftinputunchecked (0, NULL);


}





Start the animation, unless it has already started.


if (Getanimation ()!= mmorphanimation) {


Mmorphanimation.setduration (Getanimationduration ());


Startanimation (mmorphanimation);


//            }


}


}


/**


* Shows the system search dialog immediately, without any animation.


*/


private void Showsearchdialog () {


LOG.D (TAG, "Showsearchdialog gettext=" +msearchtext.gettext ());





/*mlauncher.showsearchdialog (


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 ()) {


Munmorphanimation.setduration (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 animation placed the view


* wasn't redrawn after clearing the animation.


*/


@Override


public void Clearanimation () {


Animation Animation = Getanimation ();


if (animation!= null) {


Super.clearanimation ();


if (animation.hasended ()


&& Animation.getfillafter ()


&& animation.willchangebounds ()) {


(View) GetParent ()). Invalidate ();


} else {


Invalidate ();


}


}


}





public boolean OnKey (View v, int keycode, keyevent event) {


if (!event.issystem () &&


(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'll Forward text


To Search Dialog


Switch (event.getaction ()) {


Case Keyevent.action_down:


Return Mlauncher.onkeydown (KeyCode, event);


Case Keyevent.action_multiple:


Return Mlauncher.onkeymultiple (KeyCode, Event.getrepeatcount (), event);


Case KEYEVENT.ACTION_UP:


Return Mlauncher.onkeyup (KeyCode, event);


}


}


return false;


}


/**


* Implements Onlongclicklistener to pass long clicks on the child views


* to the widget. This is makes it possible to pick the widget by long


* Clicking on the Text field or a button.


*/


public boolean Onlongclick (View v) {


return Performlongclick ();


}


@Override


protected void Onfinishinflate () {


Super.onfinishinflate ();


Msearchtext = (edittext) Findviewbyid (R.id.search_src_text);


/**begin:add by Liuzepeng **/


if (Mcontext.getcontentresolver (), Android.provider.Settings.System.getInt (), android.provider.settings.system.isiphone,0) = = 1) {


Msearchtext.sethint (R.string.search_hint_iphone);


}


/**end:add by Liuzepeng **/


Mvoicebutton = (ImageButton) Findviewbyid (R.ID.SEARCH_VOICE_BTN);//sxyang modified.


Mclearbutton = (ImageButton) Findviewbyid (R.ID.SEARCH_CLEAR_BTN);//sxyang modified.








Msearchtext.setonkeylistener (this);


Msearchtext.setonclicklistener (this);


Mvoicebutton.setonclicklistener (this);


Mclearbutton.setonclicklistener (this);//modified by Liuzepeng





Msearchtext.setonlongclicklistener (this);


Mvoicebutton.setonlongclicklistener (this);





Msearchresultlist = (ListView) Findviewbyid (R.id.searchresultview);


Msearchresult = (linearlayout) Findviewbyid (R.id.search_result);


Msearchresult.setvisibility (View.gone);


/**


Mdata = new arraylist<map<string, object>> ();


Madapter = new Simpleadapter (GetContext (),


Mdata,


R.layout.searchitem,


New string[]{"icon", "title"},


New Int[]{r.id.searchappicon,r.id.searchapptitle}


);


*/








/**


Madapter.setviewbinder (New Viewbinder () {


@Override


public Boolean setviewvalue (view view, Object data,string textrepresentation) {


if (view instanceof imageview && data instanceof drawable) {


ImageView iv= (imageview) view;


Iv.setimagedrawable ((drawable) data);


return true;


}


return false;


}


});


*/








Configurevoicesearchbutton ();


Configureclearsearchbutton ();


Msearchresultlist.setonscrolllistener (New Onscrolllistener () {


@Override


public void onscrollstatechanged (Abslistview view, int scrollstate) {


Inputmethodmanager Inputmethodmanager = (Inputmethodmanager)


GetContext (). Getsystemservice (Context.input_method_service);


Inputmethodmanager.hidesoftinputfromwindow (Msearchresultlist.getwindowtoken (), 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);


Msearchresultlist.setadapter (Madapter);


Msearchtext.addtextchangedlistener (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) {





Datalist.clear ();





if (s = = NULL | | s.tostring (). Equals ("") | | Msearchtext.gettext (). toString (). Trim () = null) {


Msearchresult.setvisibility (view.invisible);


Return


}


if (Mqueryhandler = null)


Mqueryhandler = new Searchqueryhandler (Mlauncher.getcontentresolver ());


String filter = s.tostring (). Replace ("',". ");


Startquery (Mqueryhandler, filter);





}});


}


private static Uri sallcanonical = Uri.parse ("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) {


Handler.canceloperation (Query_favorites_token);


Handler.canceloperation (Query_panel_token);


Handler.canceloperation (Query_thread_id_token);


Handler.canceloperation (Query_filtered_sms_token);


Handler.canceloperation (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) {


Handler.canceloperation (token);


Handler.startquery (token, filter, LauncherSettings.Favorites.CONTENT_URI,


NULL, selection, Selectionargs, null);


}


public void Startquerypanel (Asyncqueryhandler handler, int token,string selection,string[] Selectionargs, String filter ) {


Handler.canceloperation (token);


Handler.startquery (token, filter, LauncherSettings.Panel.CONTENT_URI, NULL, selection, Selectionargs, null);


}


public void Startquerythreadidfrommms (Asyncqueryhandler handler, int token,string selection,string[] Selectionargs, String filter) {


Handler.canceloperation (token);


Handler.startquery (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) {


Handler.canceloperation (token);


Handler.startquery (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) {


Handler.canceloperation (token);


Handler.startquery (token, filter, Uri.withappendedpath (ContactsContract.Contacts.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 ("Com.android.mms");


if (Contactsicon = null)


Contactsicon = Getappicon ("com.android.contacts");


}


@Override


protected void Onquerycomplete (int token, Object cookie, Cursor Cursor) {


if (cursor = null) return;


Datalist.clear ();


Switch (token) {


Case Query_filtered_sms_token:


list<iteminfo> iteminfolist = new arraylist<iteminfo> ();


while (Cursor.movetonext ()) {


Long threadId = Cursor.getlong (Thread_id_index);


String snippet = cursor.getstring (Snippet_index);


String recipientids = cursor.getstring (Recipient_ids_index);





String numbers = getaddresses (recipientids);


if (! Textutils.isempty (snippet) &&! Textutils.isempty (Numbers)) {


ItemInfo iteminfo = new ItemInfo ();


String title = numbers;


Intent Intent = new Intent ();


Intent.setdata (Contenturis.withappendedid (Threads.content_uri, threadId));


Intent.setaction ("Android.intent.action.VIEW");


Intent.addcategory ("Android.intent.category.DEFAULT");


Intent.putextra ("from", numbers);


Intent.putextra ("inner", true);//deleted by Sunjinbiao in 20120814 for bug[548]


if (title!= null) {


Msearchresult.setvisibility (view.visible);


Iteminfo.title = title;


Iteminfo.intent = Intent;


}


Iteminfolist.add (ItemInfo);


}


}


System.out.println ("iteminfolist.size () =" +iteminfolist.size ());


if (Iteminfolist.size () >0) {


Info info = new info ();


Info.type = Type_mms;


Info.data = iteminfolist;


Synchronized (dataList) {


Datalist.add (info);


}


}


Madapter.notifydatasetchanged ();


String filter = (string) cookie;


if (isdigits (filter) && filter.length () > 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 (Cursor.movetonext ()) {


if (id = = NULL)


id = "_ID =" + cursor.getlong (0);


Else


ID + = "or _id =" + cursor.getlong (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 (Cursor.movetonext ()) {


Long ContactID = Cursor.getlong (Contacts_id_index);


String LookupKey = cursor.getstring (Contacts_lookup_key_index);


String name = cursor.getstring (Contacts_display_name_index);


Uri Lookupuri = Contacts.getlookupuri (ContactID, LookupKey);


ItemInfo iteminfo = new ItemInfo ();


String title = name;


Intent Intent = Intent = new Intent (Intent.action_view, Lookupuri);


if (title!= null) {


Msearchresult.setvisibility (view.visible);


Iteminfo.title = title;


Iteminfo.intent = Intent;


Iteminfolist.add (ItemInfo);


}


}


if (Iteminfolist.size () >0) {


Info info = new info ();


Info.type = type_contacts;


Info.data = iteminfolist;


Synchronized (dataList) {


Datalist.add (info);


}


}


Addwebsearch ((String) cookie);


Break


Case Query_favorites_token:


int titleindex = Cursor.getcolumnindexorthrow (LauncherSettings.Favorites.TITLE);


int iconindex = Cursor.getcolumnindexorthrow (LauncherSettings.Favorites.ICON);


int intentindex = Cursor.getcolumnindexorthrow (LauncherSettings.Favorites.INTENT);


Intent Intent=null;


Packagemanager manager = GetContext (). Getpackagemanager ();


Drawable Icon=null;


while (Cursor.movetonext ()) {


Iteminfolist = new arraylist<iteminfo> ();


ItemInfo iteminfo = new ItemInfo ();


Final String title = Cursor.getstring (Titleindex);


Final String intentdescription = cursor.getstring (Intentindex);





if (intentdescription = null)


Continue


try {


Intent = Intent.parseuri (intentdescription, 0);


catch (Java.net.URISyntaxException e) {





}


icon = getapplicationsicons (Manager, GetContext (), intent);





if (title!= null) {


Msearchresult.setvisibility (view.visible);


Iteminfo.title = title;


Iteminfo.intent = Intent;


Iteminfo.icon = icon;


Iteminfolist.add (ItemInfo);


}


if (Iteminfolist.size () >0) {


Info info = new info ();


Info.type = type_favorites;


Info.data = iteminfolist;


Synchronized (dataList) {


Datalist.add (info);


Madapter.notifydatasetchanged ();


}


}


}


Madapter.notifydatasetchanged ();


Startquerypanel (Mqueryhandler, Query_panel_token, "title like '%" + ((string) cookie) + "%", null, (string) cookie); Query panel


Break


Case Query_panel_token:


Titleindex = Cursor.getcolumnindexorthrow (LauncherSettings.Panel.TITLE);


IconIndex = Cursor.getcolumnindexorthrow (LauncherSettings.Panel.ICON);


Intentindex = Cursor.getcolumnindexorthrow (LauncherSettings.Panel.INTENT);


Intent=null;


Manager = GetContext (). Getpackagemanager ();


Icon=null;


while (Cursor.movetonext ()) {


Iteminfolist = new arraylist<iteminfo> ();


ItemInfo iteminfo = new ItemInfo ();


Final String title = Cursor.getstring (Titleindex);


Final String intentdescription = cursor.getstring (Intentindex);





if (intentdescription = null)


Continue


try {


Intent = Intent.parseuri (intentdescription, 0);


catch (Java.net.URISyntaxException e) {


intent = NULL;


}


icon = getapplicationsicons (Manager, GetContext (), intent);


if (title!= null) {


Msearchresult.setvisibility (view.visible);


Iteminfo.title = title;


Iteminfo.intent = Intent;


Iteminfo.icon = icon;


Iteminfolist.add (ItemInfo);


}


if (Iteminfolist.size () >0) {


Info info = new info ();


Info.type = Type_panel;


Info.data = iteminfolist;


Synchronized (dataList) {


Datalist.add (info);


Madapter.notifydatasetchanged ();


}


}


}


Madapter.notifydatasetchanged ();


Startquerythreadidfrommms (Mqueryhandler, Query_thread_id_token, "body like '%" + ((string) cookie) + "%", null, ((string ));//query MMS


Break


Default


LOG.E (TAG, "onquerycomplete called with unknown token" + token);


}


Cursor.close ();


}


@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 = Msearchtext.gettext (). toString (). Trim ();


LOG.V ("Liuzepeng", "Filter:" +filter+ "/msearchtext.gettext" (): "+msearchtext.gettext ());


if (!edittext.equals (filter)) {


Filter = EditText;


if (Filter.equals ("")) {


Msearchresult.setvisibility (view.invisible);


Return


}


}


/**begin:add by Liuzepeng **/


list<iteminfo> iteminfolist = new arraylist<iteminfo> ();


ItemInfo iteminfo = new ItemInfo ();





drawable icon = Getappicon ("Com.android.browser");


Uri uri = uri.parse ("http://m.baidu.com/s?ie=utf-8&word=" +filter);


resources re = GetContext (). Getresources ();


String title = re.getstring (R.string.web_search);


Intent Intent = new Intent (Intent.action_view,uri);





if (title!= null) {


Msearchresult.setvisibility (view.visible);


Iteminfo.title = title;


Iteminfo.intent = Intent;


Iteminfo.icon = icon;


Iteminfolist.add (ItemInfo);


}


if (Mfootinfo = = null) {


Mfootinfo = new Info ();


Mfootinfo.type = Type_web;


}


Mfootinfo.data = iteminfolist;


/**begin:modified by Liuzepeng **/


if (!datalist.contains (Mfootinfo)) {


Datalist.add (Mfootinfo);


} else {


Datalist.remove (Mfootinfo);


Datalist.add (Mfootinfo);


}


/**begin:modified by Liuzepeng **/


Madapter.notifydatasetchanged ();


}


Private drawable Getappicon (String packagename) {


list<packageinfo> packages = GetContext (). Getpackagemanager (). getinstalledpackages (0);


Drawable AppIcon = null;


for (int i = 0; i < packages.size (); i++) {


PackageInfo PackageInfo = Packages.get (i);


if (PackageInfo.packageName.equals (PackageName)) {


AppIcon = PackageInfo.applicationInfo.loadIcon (GetContext (). Getpackagemanager ());


Break


}


}


return AppIcon;


}





public string getaddresses (string spacesepids) {


String numbers = "";


Synchronized (cachednumbers) {


string[] ids = Spacesepids.split ("");


for (String id:ids) {


Long LongId;


try {


LongId = Long.parselong (ID);


catch (NumberFormatException ex) {


Skip this ID


Continue


}


String number = Cachednumbers.get (LongId);


if (number = null) {


Getnumbers ();


Number = Cachednumbers.get (LongId);


}


if (textutils.isempty (number)) {


LOG.W (TAG, "Recipientid" + LongId + "has empty number!");


} else {


Numbers + = number;


}


}


return numbers;


}


}





public void Getnumbers () {


Final Contentresolver contentresolver = Mlauncher.getcontentresolver ();


Cursor C = contentresolver.query (sallcanonical, NULL, NULL, NULL, NULL);


if (c = = null) {


LOG.W (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.


Cachednumbers.clear ();


while (C.movetonext ()) {


Todo:don ' t hardcode the column indices


Long id = c.getlong (0);


String number = c.getstring (1);


Cachednumbers.put (ID, number);


}


}


finally {


C.close ();


}


}


Private Boolean isdigits (String str) {


if (str = NULL | | ". Equals (str))


return false;


int len = Str.length ();


for (int i=0;i<len;i++) {


char C = Str.charat (i);


if (! Character.isdigit (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;


List<info> data;


Layoutinflater Inflater;


Drawable Mmsicon = null, Contactsicon = NULL;


Public Lockscreenadapter (Context acontext,list<info> adata) {


context = Acontext;


Inflater = Layoutinflater.from (context);


data = Adata;


if (Mmsicon = null)


Mmsicon = Getappicon ("Com.android.mms");


if (Contactsicon = null)


Contactsicon = Getappicon ("com.android.contacts");


}


public int GetCount () {


return Data.size ();


}


Public Object getitem (int position) {


return Data.get (position);


}


public long getitemid (int position) {


return position;


}


Public View GetView (int position, View Convertview, ViewGroup parent) {


Convertview = inflater.inflate (R.layout.item_launcher_search, NULL);





if ((position+1)%2 = = 0) {


Convertview.setbackgrounddrawable (Getresources (). getdrawable (r.drawable.result0));


}else{


Convertview.setbackgrounddrawable (Getresources (). getdrawable (R.DRAWABLE.RESULT1));


}





int wrapcontent = LinearLayout.LayoutParams.WRAP_CONTENT;


int fillparent = LinearLayout.LayoutParams.FILL_PARENT;


Linearlayout.layoutparams CONTENTSLLP = new Linearlayout.layoutparams (fillparent, wrapcontent);


LinearLayout contents = (linearlayout) Convertview.findviewbyid (r.id.contents);


ImageView icon = (imageview) Convertview.findviewbyid (R.id.icon);





Info info = data.get (position);


int type = Info.type;


int size = Info.data.size ();


for (int i = 0; i < size; i++) {


ItemInfo ItemInfo = Info.data.get (i);


Contents.addview (Createitemview (iteminfo), CONTENTSLLP);


if (type = = Type_mms)


Icon.setbackgrounddrawable (Mmsicon);


else if (type = = type_contacts)


Icon.setbackgrounddrawable (Contactsicon);


Else


Icon.setbackgrounddrawable (Iteminfo.icon);


if (size>1 && i!=size-1) {


TextView hline = new TextView (GetContext ());





Linearlayout.layoutparams HLINELLP = new Linearlayout.layoutparams (fillparent, wrapcontent);


Hlinellp.height = 1;


Hline.setbackgroundcolor (Color.argb (255, 157, 157, 160));


Contents.addview (Hline, HLINELLP);


TextView bLine = new TextView (GetContext ());


Bline.setbackgroundcolor (Color.argb (255, 255, 255, 255));


Contents.addview (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 = LinearLayout.LayoutParams.WRAP_CONTENT;


int fillparent = LinearLayout.LayoutParams.FILL_PARENT;


Linearlayout.layoutparams SEPERATORLINELLP = new Linearlayout.layoutparams (wrapcontent, 45);


Seperatorlinellp.rightmargin = 50;


Seperatorlinellp.height = 70;


Linearlayout.layoutparams CONTENTLLP = new Linearlayout.layoutparams (fillparent, 45);


contentllp.gravity=gravity.center_vertical;


Contentllp.leftmargin = 5;





Seperatorline.setbackgroundresource (R.drawable.launcher_item_vertical_line);


Content.settext (Iteminfo.title);


Content.settextcolor (Color.Black);


Content.setgravity (gravity.center_vertical);





Contentlayout.setorientation (linearlayout.horizontal);





Contentlayout.addview (Seperatorline, SEPERATORLINELLP);


Contentlayout.addview (content, CONTENTLLP);


Contentlayout.setbackgroundresource (r.drawable.search_item_press);


Contentlayout.setonclicklistener (New Onclicklistener () {


@Override


public void OnClick (View v) {


Cxt.startactivity (iteminfo.intent);


}


});





return contentlayout;


}








@Override


public void Ondetachedfromwindow () {


Super.ondetachedfromwindow ();


}


/**


* If appropriate & available, configure voice search


*


* Note:because the Home screen search widget is always web search, we have 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 a activity that can handle it


Packagemanager pm = GetContext (). Getpackagemanager ();


Resolveinfo ri = pm.resolveactivity (mvoicesearchintent,


PACKAGEMANAGER.MATCH_DEFAULT_ONLY);


Boolean voicesearchvisible = ri!= null;


Finally, set visible state of voice search button, as appropriate


Mvoicebutton.setvisibility (voicesearchvisible?) View.VISIBLE:View.GONE);


}


private void Configureclearsearchbutton () {


Sxyang modified.


Msearchtext.addtextchangedlistener (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 | | s.tostring (). Equals ("")) {


Mclearbutton.setvisibility (view.invisible);


} else {


Mclearbutton.setvisibility (view.visible);


}


}});


}


/**


* Sets the {@link Launcher} that this gadget would call in to display the search dialog.


*/


public void Setlauncher (Launcher Launcher) {


Mlauncher = launcher;


}





/**


* Moves the view to the top left corner of it parent.


*/


Private class Toparentoriginanimation extends Animation {


@Override


protected void Applytransformation (float interpolatedtime, transformation t) {


float dx =-getleft () * interpolatedtime;


float dy =-getwidgettop () * interpolatedtime;


T.getmatrix (). settranslate (dx, dy);


}


}


/**


* Moves the view from the top left corner to 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);


T.getmatrix (). 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 is 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 (r.id.search_plate). Getbackground ();


drawable background = Findviewbyid (r.id.search_plate). Getbackground ();


if (background!= null) {


Background.setalpha (Alpha);


} else {


LOG.D (TAG, "background null");


}


Background = Findviewbyid (R.id.search_src_text). Getbackground ();


if (background!= null) {


if (background instanceof statelistdrawable) {


Statelistdrawable statedrawable = (statelistdrawable) background;


int statecount = Statedrawable.getstatecount ();


for (int i = 0; i < Statecount; i++) {


drawable d = statedrawable.getstatedrawable (i);


D.setalpha (Alpha);


}


} else {


Background.setalpha (Alpha);


}


} else {


LOG.D (TAG, "background null");


}


This.invalidate ();


return true;


}


return false;


}


/**


* Morph the search gadget to the search dialog.


* @link Activity#startsearch ()} for the arguments.


*/


public void Showstartsearch () {


Msearchtext.settext ("", TextView.BufferType.NORMAL);


Msearchresult.setvisibility (View.gone);


if (msearchresult.getvisibility ()!= view.visible) {


Msearchtext.requestfocus ();


LOG.D (TAG, "Showstartsearch");


if (GetContext (). Getresources (). GetConfiguration (). Hardkeyboardhidden = =


Configuration.hardkeyboardhidden_yes) {


Inputmethodmanager InputManager = (Inputmethodmanager)


GetContext (). Getsystemservice (Context.input_method_service);


inputmanager.showsoftinputunchecked (0, NULL);


}


}





}


Private drawable getapplicationsicons (packagemanager manager,context context, Intent Intent) {


Drawable Icon=null;


Final Resolveinfo resolveinfo = manager.resolveactivity (Intent, 0);


if (Resolveinfo = null) return null;


Final Activityinfo activityinfo = Resolveinfo.activityinfo;


drawable Customericon = Utilities.getcustomericon (context, intent);


if (Customericon!= null) {


icon = Utilities.createiconthumbnail (Customericon, context);


} else {


icon = Utilities.createiconthumbnail (Activityinfo.loadicon (manager), context);


}


Bitmap Bitmap = Utilities.createmiddleicon (Icon,context);


bitmapdrawable bd = new bitmapdrawable (bitmap);


return BD;


}


}


<com.hskj.hometest.search


Xmlns:android= "Http://schemas.android.com/apk/res/android"


Xmlns:launcher= "Http://schemas.android.com/apk/res/com.android.launcher2"


Android:id= "@+id/widget_search"


Android:layout_width= "Fill_parent"


android:layout_height= "Fill_parent"


android:orientation= "Vertical"


android:gravity= "Top" >


<linearlayout


Android:id= "@+id/search_plate"


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:id= "@+id/search_src_text"


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:id= "@+id/search_clear_btn"


Android:layout_width= "Wrap_content"


android:layout_height= "Wrap_content"


android:layout_marginright= "0dip"


android:background= "@drawable/iphone_clean_icon"


/>


<imagebutton


Android:id= "@+id/search_voice_btn"


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:id= "@+id/search_result"


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:id= "@+id/searchresultview"


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>





</com.hskj.hometest.Search>


<?xml version= "1.0" encoding= "Utf-8"?>


<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"


Android:layout_width= "Fill_parent" android:layout_height= "Fill_parent"


android:orientation= "Horizontal" >


<imageview android:id= "@+id/icon" android:layout_width= "30dip"


android:layout_height= "30dip"


android:layout_margin= "5dip"/>


<linearlayout android:id= "@+id/contents"


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>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.