List of usage examples for android.widget ImageView setOnClickListener
public void setOnClickListener(@Nullable OnClickListener l)
From source file:com.easemob.chatuidemo.activity.ContactlistFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //T??home???appcrash if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) return;// w w w . ja v a 2 s.co m inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); listView = (ListView) getView().findViewById(R.id.list); sidebar = (Sidebar) getView().findViewById(R.id.sidebar); sidebar.setListView(listView); getView().findViewById(R.id.back).setOnClickListener(this); //??? blackList = EMContactManager.getInstance().getBlackListUsernames(); contactList = new ArrayList<User>(); // ?contactlist getContactList(); //? query = (EditText) getView().findViewById(R.id.query); query.setHint(R.string.search); clearSearch = (ImageButton) getView().findViewById(R.id.search_clear); query.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s); if (s.length() > 0) { clearSearch.setVisibility(View.VISIBLE); } else { clearSearch.setVisibility(View.INVISIBLE); } } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void afterTextChanged(Editable s) { } }); clearSearch.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { query.getText().clear(); hideSoftKeyboard(); } }); // adapter adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList); listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String username = adapter.getItem(position).getUsername(); if (Constant.NEW_FRIENDS_USERNAME.equals(username)) { // ? User user = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getContactList() .get(Constant.NEW_FRIENDS_USERNAME); user.setUnreadMsgCount(0); startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class)); } else if (Constant.GROUP_USERNAME.equals(username)) { // ?? startActivity(new Intent(getActivity(), GroupsActivity.class)); } else if (Constant.CHAT_ROOM.equals(username)) { //?? startActivity(new Intent(getActivity(), PublicChatRoomsActivity.class)); } // else if(Constant.CHAT_ROBOT.equals(username)){ // //Robot? // startActivity(new Intent(getActivity(), RobotsActivity.class)); // } else { // demo?? startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId", adapter.getItem(position).getUsername())); } } }); listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // ?? if (getActivity().getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getActivity().getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); ImageView addContactView = (ImageView) getView().findViewById(R.id.iv_new_contact); // ? addContactView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(getActivity(), AddContactActivity.class)); } }); registerForContextMenu(listView); progressBar = (View) getView().findViewById(R.id.progress_bar); contactSyncListener = new HXContactSyncListener(); HXSDKHelper.getInstance().addSyncContactListener(contactSyncListener); blackListSyncListener = new HXBlackListSyncListener(); HXSDKHelper.getInstance().addSyncBlackListListener(blackListSyncListener); contactInfoSyncListener = new HXContactInfoSyncListener(); ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getUserProfileManager() .addSyncContactInfoListener(contactInfoSyncListener); if (!HXSDKHelper.getInstance().isContactsSyncedWithServer()) { progressBar.setVisibility(View.VISIBLE); } else { progressBar.setVisibility(View.GONE); } }
From source file:com.layer.atlas.messenger.AtlasMessagesScreen.java
private void prepareActionBar() { ImageView menuBtn = (ImageView) findViewById(R.id.atlas_actionbar_left_btn); menuBtn.setImageResource(R.drawable.atlas_ctl_btn_back); menuBtn.setVisibility(View.VISIBLE); menuBtn.setOnClickListener(new OnClickListener() { public void onClick(View v) { finish();/*from w w w .ja va2s. c o m*/ } }); ((TextView) findViewById(R.id.atlas_actionbar_title_text)).setText("Messages"); ((TextView) findViewById(R.id.atlas_actionbar_title_text)).setOnClickListener(new OnClickListener() { public void onClick(View v) { messagesList.requestRefreshValues(true, false); } }); ImageView settingsBtn = (ImageView) findViewById(R.id.atlas_actionbar_right_btn); settingsBtn.setImageResource(R.drawable.atlas_ctl_btn_detail); settingsBtn.setVisibility(View.VISIBLE); settingsBtn.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (conv == null) return; AtlasConversationSettingsScreen.conv = conv; Intent intent = new Intent(v.getContext(), AtlasConversationSettingsScreen.class); startActivityForResult(intent, REQUEST_CODE_SETTINGS); } }); Tools.setStatusBarColor(getWindow(), getResources().getColor(R.color.atlas_background_blue_dark)); }
From source file:cn.ucai.superwechart.activity.ContactlistFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //T??home???appcrash if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) return;//from w ww .j a v a 2s .com inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); listView = (ListView) getView().findViewById(R.id.list); sidebar = (Sidebar) getView().findViewById(R.id.sidebar); sidebar.setListView(listView); //??? blackList = EMContactManager.getInstance().getBlackListUsernames(); contactList = new ArrayList<User>(); // ?contactlist getContactList(); //? query = (EditText) getView().findViewById(R.id.query); query.setHint(R.string.search); clearSearch = (ImageButton) getView().findViewById(R.id.search_clear); query.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s); if (s.length() > 0) { clearSearch.setVisibility(View.VISIBLE); } else { clearSearch.setVisibility(View.INVISIBLE); } } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void afterTextChanged(Editable s) { } }); clearSearch.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { query.getText().clear(); hideSoftKeyboard(); } }); // adapter adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList); listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String username = adapter.getItem(position).getUsername(); if (Constant.NEW_FRIENDS_USERNAME.equals(username)) { // ? User user = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getContactList() .get(Constant.NEW_FRIENDS_USERNAME); user.setUnreadMsgCount(0); startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class)); } else if (Constant.GROUP_USERNAME.equals(username)) { // ?? startActivity(new Intent(getActivity(), GroupsActivity.class)); } else if (Constant.CHAT_ROOM.equals(username)) { //?? startActivity(new Intent(getActivity(), PublicChatRoomsActivity.class)); } else if (Constant.CHAT_ROBOT.equals(username)) { //Robot? startActivity(new Intent(getActivity(), RobotsActivity.class)); } else { // demo?? startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId", adapter.getItem(position).getUsername())); } } }); listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // ?? if (getActivity().getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getActivity().getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); ImageView addContactView = (ImageView) getView().findViewById(R.id.iv_new_contact); // ? addContactView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(getActivity(), AddContactActivity.class)); } }); registerForContextMenu(listView); progressBar = (View) getView().findViewById(R.id.progress_bar); contactSyncListener = new HXContactSyncListener(); HXSDKHelper.getInstance().addSyncContactListener(contactSyncListener); blackListSyncListener = new HXBlackListSyncListener(); HXSDKHelper.getInstance().addSyncBlackListListener(blackListSyncListener); contactInfoSyncListener = new HXContactInfoSyncListener(); ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getUserProfileManager() .addSyncContactInfoListener(contactInfoSyncListener); if (!HXSDKHelper.getInstance().isContactsSyncedWithServer()) { progressBar.setVisibility(View.VISIBLE); } else { progressBar.setVisibility(View.GONE); } }
From source file:com.fivetrue.workout.timer.view.PagerSlidingTabStrip.java
private void addIconTab(final int position, Drawable drawable) { ImageView tab = new ImageView(getContext()); tab.setFocusable(true);//w w w . j a v a2 s . com tab.setImageDrawable(drawable); tab.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { pager.setCurrentItem(position); } }); tab.setSelected(currentPosition == position); LinearLayout.LayoutParams params = defaultTabLayoutParams; if (shouldExpand) { params = expandedTabLayoutParams; } tabsContainer.addView(tab, params); }
From source file:azad.hallaji.farzad.com.masirezendegi.PageVirayesh.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_page_virayesh); Fabric.with(this, new Crashlytics()); TextView virayeshTextinToolbar = (TextView) findViewById(R.id.virayeshTextinToolbar); final TextView zaxireTextinToolbar = (TextView) findViewById(R.id.zaxireTextinToolbar); init();//w ww .jav a 2 s . c o m ableall(false); drawer = (DrawerLayout) findViewById(R.id.drawer_layout); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); ImageView imageView = (ImageView) findViewById(R.id.menuButton); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { drawer.openDrawer(Gravity.END); } }); if (GlobalVar.getUserType().equals("adviser") || GlobalVar.getUserType().equals("user")) { Menu nav_Menu = navigationView.getMenu(); nav_Menu.findItem(R.id.nav_marakez).setVisible(true); nav_Menu.findItem(R.id.nav_profile).setVisible(true); nav_Menu.findItem(R.id.nav_login).setVisible(false); nav_Menu.findItem(R.id.nav_moshaverin).setVisible(true); nav_Menu.findItem(R.id.nav_porseshha).setVisible(true); nav_Menu.findItem(R.id.nav_logout).setVisible(true); } else { Menu nav_Menu = navigationView.getMenu(); nav_Menu.findItem(R.id.nav_marakez).setVisible(true); nav_Menu.findItem(R.id.nav_profile).setVisible(false); nav_Menu.findItem(R.id.nav_login).setVisible(true); nav_Menu.findItem(R.id.nav_moshaverin).setVisible(true); nav_Menu.findItem(R.id.nav_porseshha).setVisible(true); nav_Menu.findItem(R.id.nav_logout).setVisible(false); } final ImageView imageView1 = (ImageView) findViewById(R.id.onclickeasadinchimastanxanim); imageView1.setVisibility(View.GONE); if (isOnline()) { setAlage(); if (GlobalVar.getUserType().equals("adviser")) { virayeshTextinToolbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ableall(true); sihhhhh1.setVisibility(View.VISIBLE); sihhhhh2.setVisibility(View.VISIBLE); imageView1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent pickPhoto = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(pickPhoto, 1);//one can be replaced with any action code } }); zaxireTextinToolbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { postgetData(); } }); } }); imageView1.setVisibility(View.VISIBLE); barchasbEdit.setVisibility(View.VISIBLE); costperminEdit.setVisibility(View.VISIBLE); maxtimeEdit.setVisibility(View.VISIBLE); sexEdit.setVisibility(View.VISIBLE); dialtecEdit.setVisibility(View.VISIBLE); aboutmeEdit.setVisibility(View.VISIBLE); } else if (GlobalVar.getUserType().equals("user")) { virayeshTextinToolbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { TextView textView = (TextView) findViewById(R.id.sihhhhh1); TextView textView2 = (TextView) findViewById(R.id.sihhhhh2); textView.setVisibility(View.GONE); textView2.setVisibility(View.GONE); imageView1.setVisibility(View.VISIBLE); boolean b = false; sihhhhh1.setVisibility(View.GONE); sihhhhh2.setVisibility(View.GONE); namexanivadeEdit.setEnabled(!b); shomareteleEdit.setEnabled(!b); emailEdit.setEnabled(!b); barchasbEdit.setVisibility(View.GONE); costperminEdit.setVisibility(View.GONE); maxtimeEdit.setVisibility(View.GONE); sexEdit.setVisibility(View.GONE); dialtecEdit.setVisibility(View.GONE); aboutmeEdit.setVisibility(View.GONE); imageView1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent pickPhoto = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(pickPhoto, 1);//one can be replaced with any action code } }); zaxireTextinToolbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { postgetData(); } }); } }); } } else { Toast.makeText(getApplicationContext(), "Network isn't available", Toast.LENGTH_LONG).show(); } }
From source file:cn.hbm.superwechat.activity.ContactlistFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mContext = getActivity();//from ww w.j a v a 2 s .c o m updateContactListener();//? //T??home???appcrash if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) return; inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); listView = (ListView) getView().findViewById(R.id.list); sidebar = (Sidebar) getView().findViewById(R.id.sidebar); sidebar.setListView(listView); //??? blackList = EMContactManager.getInstance().getBlackListUsernames(); contactList = new ArrayList<User>(); // ?contactlist getContactList(); //? query = (EditText) getView().findViewById(R.id.query); query.setHint(R.string.search); clearSearch = (ImageButton) getView().findViewById(R.id.search_clear); query.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s); if (s.length() > 0) { clearSearch.setVisibility(View.VISIBLE); } else { clearSearch.setVisibility(View.INVISIBLE); } } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void afterTextChanged(Editable s) { } }); clearSearch.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { query.getText().clear(); hideSoftKeyboard(); } }); // adapter adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList); listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String username = adapter.getItem(position).getUsername(); if (Constant.NEW_FRIENDS_USERNAME.equals(username)) { // ? User user = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getContactList() .get(Constant.NEW_FRIENDS_USERNAME); user.setUnreadMsgCount(0); startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class)); } else if (Constant.GROUP_USERNAME.equals(username)) { // ?? startActivity(new Intent(getActivity(), GroupsActivity.class)); } else if (Constant.CHAT_ROOM.equals(username)) { //?? startActivity(new Intent(getActivity(), PublicChatRoomsActivity.class)); } else if (Constant.CHAT_ROBOT.equals(username)) { //Robot? startActivity(new Intent(getActivity(), RobotsActivity.class)); } else { // demo?? startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId", adapter.getItem(position).getUsername())); } } }); listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // ?? if (getActivity().getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getActivity().getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); ImageView addContactView = (ImageView) getView().findViewById(R.id.iv_new_contact); // ? addContactView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(getActivity(), AddContactActivity.class)); } }); registerForContextMenu(listView); progressBar = (View) getView().findViewById(R.id.progress_bar); contactSyncListener = new HXContactSyncListener(); HXSDKHelper.getInstance().addSyncContactListener(contactSyncListener); blackListSyncListener = new HXBlackListSyncListener(); HXSDKHelper.getInstance().addSyncBlackListListener(blackListSyncListener); contactInfoSyncListener = new HXContactInfoSyncListener(); ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getUserProfileManager() .addSyncContactInfoListener(contactInfoSyncListener); if (!HXSDKHelper.getInstance().isContactsSyncedWithServer()) { progressBar.setVisibility(View.VISIBLE); } else { progressBar.setVisibility(View.GONE); } }
From source file:com.xnote.lol.xnote.views.SlidingTabLayout.java
private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final View.OnClickListener tabClickListener = new TabClickListener(); // calcluating horizontal padding for tabs so they fill the screen: int tabWidth = (int) Math.floor(((double) mScreenHorizontalWidth / adapter.getCount())); for (int i = 0; i < adapter.getCount(); i++) { ImageView tabView = new ImageView(getContext()); tabView.setImageDrawable(getPositiveIconDrawable(i)); tabView.setScaleType(ImageView.ScaleType.FIT_CENTER); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); tabView.setPadding(padding, padding, padding, padding); tabView.setLayoutParams(new LinearLayout.LayoutParams(tabWidth, ViewGroup.LayoutParams.WRAP_CONTENT)); tabView.setOnClickListener(tabClickListener); mTabStrip.addView(tabView);//w w w. j a v a2 s. co m } }
From source file:com.Candy.ota.CandyOTA.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mDeviceOut = (TextView) getView().findViewById(ID_DEVICE_NAME); mCodenameOut = (TextView) getView().findViewById(ID_DEVICE_CODE_NAME); mCurVerOut = (TextView) getView().findViewById(ID_CURRENT_VERSION); mCurFileOut = (TextView) getView().findViewById(ID_CURRENT_FILE); mUpdateFile = (TextView) getView().findViewById(ID_UPDATE_FILE); mStatusIcon = (ImageView) getView().findViewById(ID_STATUS_IMAGE); final ImageView setButton = (ImageView) getView().findViewById(R.id.btn_setting); final ImageView updateButton = (ImageView) getView().findViewById(R.id.btn_update); prefs = this.getActivity().getSharedPreferences("UpdateChecker", 0); prefs.registerOnSharedPreferenceChangeListener(this); if (UpdateChecker.connectivityAvailable(getActivity())) { doTheUpdateCheck();//from w w w.j ava2 s.c om } else { Toast.makeText(getView().getContext(), R.string.toast_no_data_text, Toast.LENGTH_LONG).show(); } setDeviceInfoContainer(); addShortCutFragment(); setInitialUpdateInterval(); updateButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (UpdateChecker.connectivityAvailable(getActivity())) { doTheUpdateCheck(); } setDeviceInfoContainer(); addShortCutFragment(); } }); }
From source file:com.survivingwithandroid.weatherapp.settings.SearchLocationActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search_location_activity); client = WeatherContext.getInstance().getClient(this); Log.d("App", "Client [" + client + "]"); cityListView = (ListView) findViewById(R.id.cityList); bar = (ProgressBar) findViewById(R.id.progressBar2); adp = new CityAdapter(SearchLocationActivity.this, new ArrayList<City>()); cityListView.setAdapter(adp);//from w w w .j a v a 2s . c om ImageView searchView = (ImageView) findViewById(R.id.imgSearch); final EditText edt = (EditText) findViewById(R.id.cityEdtText); edt.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { search(v.getText().toString()); return true; } return false; } }); searchView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { search(edt.getEditableText().toString()); } }); cityListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int pos, long id) { SharedPreferences sharedPref = PreferenceManager .getDefaultSharedPreferences(SearchLocationActivity.this); SharedPreferences.Editor editor = sharedPref.edit(); City city = (City) parent.getItemAtPosition(pos); editor.putString("cityid", city.getId()); editor.putString("cityName", city.getName()); editor.putString("country", city.getCountry()); editor.commit(); NavUtils.navigateUpFromSameTask(SearchLocationActivity.this); } }); ImageView locImg = (ImageView) findViewById(R.id.imgLocationSearch); locImg.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { bar.setVisibility(View.VISIBLE); try { client.searchCityByLocation(WeatherClient.createDefaultCriteria(), new WeatherClient.CityEventListener() { @Override public void onCityListRetrieved(List<City> cityList) { bar.setVisibility(View.GONE); adp.setCityList(cityList); adp.notifyDataSetChanged(); } @Override public void onWeatherError(WeatherLibException wle) { bar.setVisibility(View.GONE); } @Override public void onConnectionError(Throwable t) { bar.setVisibility(View.GONE); } }); } catch (LocationProviderNotFoundException lpnfe) { } } }); }
From source file:cn.ucai.superwechat.fragment.ContactlistFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //T??home???appcrash if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) return;/*w ww. j a va2 s.c om*/ inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); listView = (ListView) getView().findViewById(cn.ucai.superwechat.R.id.list); sidebar = (Sidebar) getView().findViewById(cn.ucai.superwechat.R.id.sidebar); sidebar.setListView(listView); //??? blackList = EMContactManager.getInstance().getBlackListUsernames(); mContactList = new ArrayList<Contact>(); // ?contactlist getContactList(); //? query = (EditText) getView().findViewById(cn.ucai.superwechat.R.id.query); query.setHint(cn.ucai.superwechat.R.string.search); clearSearch = (ImageButton) getView().findViewById(cn.ucai.superwechat.R.id.search_clear); query.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s); if (s.length() > 0) { clearSearch.setVisibility(View.VISIBLE); } else { clearSearch.setVisibility(View.INVISIBLE); } } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void afterTextChanged(Editable s) { } }); clearSearch.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { query.getText().clear(); hideSoftKeyboard(); } }); // adapter adapter = new ContactAdapter(getActivity(), cn.ucai.superwechat.R.layout.row_contact, mContactList); listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String username = adapter.getItem(position).getMContactCname(); if (Constant.NEW_FRIENDS_USERNAME.equals(username)) { // ? EMUser user = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getContactList() .get(Constant.NEW_FRIENDS_USERNAME); user.setUnreadMsgCount(0); startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class)); } else if (Constant.GROUP_USERNAME.equals(username)) { // ?? startActivity(new Intent(getActivity(), GroupsActivity.class)); } else if (Constant.CHAT_ROOM.equals(username)) { //?? // startActivity(new Intent(getActivity(), PublicChatRoomsActivity.class)); } else if (Constant.CHAT_ROBOT.equals(username)) { //Robot? // startActivity(new Intent(getActivity(), RobotsActivity.class)); } else { // demo?? startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId", adapter.getItem(position).getMContactCname())); } } }); listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // ?? if (getActivity().getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getActivity().getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); ImageView addContactView = (ImageView) getView().findViewById(cn.ucai.superwechat.R.id.iv_new_contact); // ? addContactView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(getActivity(), AddContactActivity.class)); } }); registerForContextMenu(listView); progressBar = (View) getView().findViewById(cn.ucai.superwechat.R.id.progress_bar); contactSyncListener = new HXContactSyncListener(); HXSDKHelper.getInstance().addSyncContactListener(contactSyncListener); blackListSyncListener = new HXBlackListSyncListener(); HXSDKHelper.getInstance().addSyncBlackListListener(blackListSyncListener); contactInfoSyncListener = new HXContactInfoSyncListener(); ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getUserProfileManager() .addSyncContactInfoListener(contactInfoSyncListener); if (!HXSDKHelper.getInstance().isContactsSyncedWithServer()) { progressBar.setVisibility(View.VISIBLE); } else { progressBar.setVisibility(View.GONE); } registerContactListChangedReceiver(); }