List of usage examples for android.widget ListView getAdapter
@Override
public ListAdapter getAdapter()
From source file:io.jari.geenstijl.Blog.java
void initUI(final Artikel[] artikelen, final boolean doSwitchState) { final PullToRefreshLayout mPullToRefreshLayout = (PullToRefreshLayout) findViewById(R.id.ptr_layout); runOnUiThread(new Runnable() { public void run() { ListView siteSwitch = (ListView) findViewById(R.id.site_switcher); String domain = getSharedPreferences("geenstijl", 0).getString("gsdomain", "www.geenstijl.nl"); if (domain.equals("www.geenstijl.nl")) { actionBar.setTitle("GeenStijl"); siteSwitch.setItemChecked(0, true); } else { actionBar.setTitle("GeenStijl.TV"); siteSwitch.setItemChecked(1, true); }/*from w ww . j ava 2 s. c o m*/ final ListView show = (ListView) findViewById(R.id.show); if (showTopPadding == 0) showTopPadding = show.getPaddingTop(); show.setScrollingCacheEnabled(false); show.setAdapter(new ArtikelAdapter(Blog.this, 0, artikelen)); //#HOLOYOLO if (Build.VERSION.SDK_INT >= 19) { SystemBarTintManager.SystemBarConfig config = tintManager.getConfig(); show.setPadding(0, showTopPadding + config.getPixelInsetTop(true), 0, 0); } //hiding the actionbar when scrolling show.setOnScrollListener(new AbsListView.OnScrollListener() { int mLastFirstVisibleItem = 0; public void onScrollStateChanged(AbsListView view, int scrollState) { } public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (view.getId() == show.getId()) { final int currentFirstVisibleItem = show.getFirstVisiblePosition(); if (currentFirstVisibleItem > mLastFirstVisibleItem && actionBar.isShowing()) { enableImmersive(true, show); } else if (currentFirstVisibleItem < mLastFirstVisibleItem && !actionBar.isShowing()) { enableImmersive(false, show); } mLastFirstVisibleItem = currentFirstVisibleItem; } } }); //footer if (show.getAdapter().getClass() != HeaderViewListAdapter.class) { //check if footer is present, if not, add it View footer = getLayoutInflater().inflate(R.layout.meerrr, null); final View button = footer.findViewById(R.id.more); if (Build.VERSION.SDK_INT >= 19) { ViewGroup.LayoutParams params = button.getLayoutParams(); SystemBarTintManager.SystemBarConfig config = tintManager.getConfig(); ((ViewGroup.MarginLayoutParams) params).bottomMargin = config.getPixelInsetBottom(); } button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { button.setEnabled(false); mPullToRefreshLayout.setRefreshing(true); enableImmersive(false, show); forceNoImmersive = true; new Thread(new Runnable() { public void run() { try { final Artikel[] artikelen2 = API.getArticles(true, true, getApplicationContext()); runOnUiThread(new Runnable() { public void run() { ListView show = (ListView) findViewById(R.id.show); //java is such a beautiful language *cough* ArtikelAdapter artikelAdapter = (ArtikelAdapter) ((HeaderViewListAdapter) show .getAdapter()).getWrappedAdapter(); artikelAdapter.update(artikelen2); mPullToRefreshLayout.setRefreshComplete(); button.setVisibility(View.GONE); forceNoImmersive = false; } }); } catch (final Exception e) { e.printStackTrace(); runOnUiThread(new Runnable() { public void run() { button.setEnabled(true); mPullToRefreshLayout.setRefreshComplete(); forceNoImmersive = false; Crouton.makeText(Blog.this, e.getLocalizedMessage() == null ? "Onbekende fout" : e.getLocalizedMessage(), Style.ALERT).show(); } }); } } }).start(); } }); show.addFooterView(footer); } //grreat success! if (doSwitchState) switchState(STATE_SHOW); else mPullToRefreshLayout.setRefreshComplete(); } }); }
From source file:org.botlibre.sdk.activity.ChatActivity.java
public void response(final ChatResponse response) { if (speechPlayer != null || tts != null) { try {// www. ja va 2s.co m tts.stop(); speechPlayer.pause(); } catch (Exception ignore) { Log.e("RESPONSE", "Error: " + ignore.getMessage()); } } //needs when calling "sleep" or the its not going to let the mic off //also to stop the mic until the bot finish the sentence try { stopListening(); this.response = response; String status = ""; if (response.emote != null && !response.emote.equals("NONE")) { status = status + response.emote.toLowerCase(); } if (response.action != null) { if (!status.isEmpty()) { status = status + " "; } status = status + response.action; } if (response.pose != null) { if (!status.isEmpty()) { status = status + " "; } status = status + response.pose; } if (response.command != null) { JSONObject jsonObject = response.getCommand(); Command command = new Command(this, jsonObject); } TextView statusView = (TextView) findViewById(R.id.statusText); statusView.setText(status); final String text = response.message; final ListView list = (ListView) findViewById(R.id.chatList); if (text == null) { list.post(new Runnable() { @Override public void run() { ChatResponse ready = new ChatResponse(); ready.message = "ready"; messages.add(ready); ((ChatListAdapter) list.getAdapter()).notifyDataSetChanged(); list.invalidateViews(); if (list.getCount() > 2) { list.setSelection(list.getCount() - 2); } beginListening(); } }); return; } list.post(new Runnable() { @Override public void run() { messages.add(response); ((ChatListAdapter) list.getAdapter()).notifyDataSetChanged(); list.invalidateViews(); if (list.getCount() > 2) { list.setSelection(list.getCount() - 2); } } }); WebView responseView = (WebView) findViewById(R.id.responseText); String html = Utils.linkHTML(text); if (html.contains("<") && html.contains(">")) { html = linkPostbacks(html); } responseView.loadDataWithBaseURL(null, html, "text/html", "utf-8", null); boolean talk = (text.trim().length() > 0) && (MainActivity.deviceVoice || (this.response.speech != null && this.response.speech.length() > 0)); if (MainActivity.sound && talk) { if (!MainActivity.disableVideo && !videoError && this.response.isVideo() && this.response.isVideoTalk()) { videoView.setOnPreparedListener(new OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { try { mp.setLooping(true); if (!MainActivity.deviceVoice) { // Voice audio speechPlayer = playAudio(response.speech, false, false, false); speechPlayer.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mp.release(); videoView.post(new Runnable() { public void run() { cycleVideo(response); } }); runOnUiThread(new Runnable() { public void run() { if (!music) { beginListening(); } } }); } }); speechPlayer.start(); } else { HashMap<String, String> params = new HashMap<String, String>(); params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "id"); tts.speak(Utils.stripTags(text), TextToSpeech.QUEUE_FLUSH, params); } } catch (Exception exception) { Log.wtf(exception.getMessage(), exception); } } }); playVideo(this.response.avatarTalk, false); } else if (talk) { if (!MainActivity.deviceVoice) { // Voice audio playAudio(this.response.speech, false, false, true); } else { HashMap<String, String> params = new HashMap<String, String>(); params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "id"); this.tts.speak(Utils.stripTags(text), TextToSpeech.QUEUE_FLUSH, params); } } } else if (talk && (!MainActivity.disableVideo && !videoError && this.response.isVideo() && this.response.avatarTalk != null)) { videoView.setOnPreparedListener(new OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mp.setLooping(false); } }); videoView.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { videoView.setOnCompletionListener(null); cycleVideo(response); } }); playVideo(this.response.avatarTalk, false); runOnUiThread(new Runnable() { public void run() { beginListening(); } }); } else { runOnUiThread(new Runnable() { public void run() { beginListening(); } }); } } catch (Exception exception) { Log.wtf(exception.getMessage(), exception); } if (micLastStat) { MainActivity.listenInBackground = true; } }
From source file:org.uguess.android.sysinfo.ApplicationManager.java
void toggleAllSelection(boolean selected) { ListView lstApps = getListView(); int totalCount = lstApps.getCount(); for (int i = 0; i < totalCount; i++) { AppInfoHolder holder = (AppInfoHolder) lstApps.getItemAtPosition(i); holder.checked = selected;/*from w w w .ja v a2 s. c om*/ } if (!selected) { hideButtons(); } ((ArrayAdapter) lstApps.getAdapter()).notifyDataSetChanged(); }
From source file:com.waz.zclient.pages.main.conversation.ConversationFragment.java
private View getViewByPosition(int pos, ListView listView) { final int firstListItemPosition = listView.getFirstVisiblePosition(); final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1; if (pos < firstListItemPosition || pos > lastListItemPosition) { return listView.getAdapter().getView(pos, null, listView); } else {/*from w w w .ja v a 2s . co m*/ final int childIndex = pos - firstListItemPosition; return listView.getChildAt(childIndex); } }
From source file:cat.wuyingren.rorhelper.fragments.GameListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); dataSource = new GameDataSource(getActivity()); dataSource.open();// w ww. j a va 2s. c o m values = dataSource.getAllGames(); adapter = new MultipleRowAdapter(getActivity(), values); setListAdapter(adapter); final ListView listView = getListView(); listView.setItemsCanFocus(false); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new ListView.MultiChoiceModeListener() { @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { // Here you can do something when items are selected/de-selected, // such as update the title in the CAB //mode.setTag(); int selectionColor = getResources().getColor(R.color.colorPrimary); Log.w("TAG", "onItemCheckedStateChanged() " + checked + " " + position); mode.setSubtitle(listView.getCheckedItemCount() + " selected"); if (checked) { listView.getChildAt(position).setBackgroundColor(selectionColor); } else { listView.getChildAt(position) .setBackgroundColor(getResources().getColor(android.R.color.transparent)); } } @Override public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) { // Inflate the menu for the CAB Log.w("TAG", "onCreateActionMode"); MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.menu_context, menu); mode.setTitle(getString(R.string.action_choose)); return true; } @Override public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) { // Here you can perform updates to the CAB due to // an invalidate() request return false; } @Override public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) { // Respond to clicks on the actions in the CAB switch (item.getItemId()) { case R.id.action_delete: deleteItems(listView.getCheckedItemPositions()); mode.finish(); return true; default: return false; } } @Override public void onDestroyActionMode(android.view.ActionMode mode) { // Here you can make any necessary updates to the activity when // the CAB is removed. By default, selected items are deselected/unchecked. SparseBooleanArray checked = listView.getCheckedItemPositions(); for (int i = 0; i < listView.getAdapter().getCount(); i++) { if (checked.get(i)) { listView.getChildAt(i) .setBackgroundColor(getResources().getColor(android.R.color.transparent)); } } } }); // dataSource.close(); }