List of usage examples for android.widget AdapterView.OnItemLongClickListener AdapterView.OnItemLongClickListener
AdapterView.OnItemLongClickListener
From source file:com.juick.android.ThreadFragment.java
private void initAdapter() { final FragmentActivity activity = getActivity(); listAdapter = new JuickMessagesAdapter(activity, this, JuickMessagesAdapter.TYPE_THREAD, JuickMessagesAdapter.SUBTYPE_OTHER); if (implicitlyCreated || restoreData != null) { getView().findViewById(android.R.id.empty).setVisibility(View.GONE); }/*from w w w .j a v a2 s . c o m*/ if (implicitlyCreated) { return; } final ListView listView = getListView(); listView.setOnItemClickListener(this); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position, final long id) { handler.postDelayed(new Runnable() { @Override public void run() { if (activity.isFinishing()) { System.out.println("OK"); return; } Object itemAtPosition = parent.getItemAtPosition(position); if (itemAtPosition instanceof JuickMessage && parentMessagesSource != null) { final JuickMessage msg = (JuickMessage) itemAtPosition; if (msg.getMID() != null) { doOnClickActualTime = System.currentTimeMillis(); doOnClick = new Runnable() { @Override public void run() { MessageMenu messageMenu = MainActivity.getMicroBlog(msg).getMessageMenu( activity, parentMessagesSource, listView, listAdapter); if (messageMenu != null) { messageMenu.onItemLongClick(parent, view, position, id); } } }; doOnClick.run(); doOnClick = null; } } } }, 100); return false; } }); notification = new ThreadMessagesLoadNotification(activity, handler); navMenu.setVisibility(View.GONE); Thread thr = new Thread(new Runnable() { public void run() { final Utils.Function<Void, MessagesFragment.RetainedData> then = new Utils.Function<Void, MessagesFragment.RetainedData>() { @Override public Void apply(MessagesFragment.RetainedData retainedData) { onObtainAllThread(retainedData, false); return null; } }; if (restoreData == null) { if (parentMessagesSource != null) { if (prefetched != null) { ArrayList<JuickMessage> messages = new ArrayList<JuickMessage>(); messages.add(prefetched.contextPost); if (prefetched.contextReply != null) { messages.add(prefetched.contextReply); } messages.add(prefetched); prefetched.contextPost = null; // don't confuse later prefetched.contextReply = null; prefetched = null; // to enable proper reload then.apply(new MessagesFragment.RetainedData(messages, null)); } else { parentMessagesSource.getChildren(mid, notification, new Utils.Function<Void, ArrayList<JuickMessage>>() { @Override public Void apply(ArrayList<JuickMessage> messages) { if (messages != null && messages.size() > 0 && originalMessage != null) { if (messages.get(0).getRID() != 0) { messages.add(0, originalMessage); } } preprocessMessages(messages); then.apply(new MessagesFragment.RetainedData(messages, null)); return null; } }); } } } else { then.apply((MessagesFragment.RetainedData) restoreData); restoreData = null; } } }, "Init adapter, mid=" + mid); thr.start(); }
From source file:com.juick.android.MessagesFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); LayoutInflater li = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); viewLoading = li.inflate(R.layout.listitem_loading, null); if (!messagesSource.canNext()) { viewLoading.findViewById(R.id.loadingg).setVisibility(View.GONE); viewLoading.findViewById(R.id.end_of_messages).setVisibility(View.VISIBLE); viewLoading.findViewById(R.id.progress_bar).setVisibility(View.GONE); viewLoading.findViewById(R.id.progress_loading_more).setVisibility(View.GONE); }// w w w . j ava2 s.c o m mRefreshView = (RelativeLayout) li.inflate(R.layout.pull_to_refresh_header, null); mRefreshViewText = (TextView) mRefreshView.findViewById(R.id.pull_to_refresh_text); mRefreshViewImage = (ImageView) mRefreshView.findViewById(R.id.pull_to_refresh_image); mRefreshViewProgress = (ProgressBar) mRefreshView.findViewById(R.id.pull_to_refresh_progress); mRefreshViewImage.setMinimumHeight(50); mRefreshView.setOnClickListener(this); mRefreshOriginalTopPadding = mRefreshView.getPaddingTop(); mRefreshState = TAP_TO_REFRESH; final ListView listView = getListView(); listView.setBackgroundDrawable(null); listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); installDividerColor(listView); MainActivity.restyleChildrenOrWidget(listView); listAdapter = new JuickMessagesAdapter(getActivity(), this, JuickMessagesAdapter.TYPE_MESSAGES, allMessages ? JuickMessagesAdapter.SUBTYPE_ALL : JuickMessagesAdapter.SUBTYPE_OTHER); listAdapter.setOnForgetListener(new Utils.Function<Void, JuickMessage>() { @Override public Void apply(final JuickMessage jm) { Network.executeJAHTTPS( getActivity(), null, JA_API_URL + "/pending?command=ignore&mid=" + ((JuickMessageID) jm.getMID()).getMid() + "&rid=" + jm.getRID(), new Utils.Function<Void, RESTResponse>() { @Override public Void apply(final RESTResponse response) { final Activity activity = getActivity(); if (activity == null) return null; // gone. if (response.getErrorText() != null) { activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(activity, response.getErrorText(), Toast.LENGTH_SHORT) .show(); } }); } else { activity.runOnUiThread(new Runnable() { @Override public void run() { listAdapter.remove(jm); //To change body of implemented methods use File | Settings | File Templates. if (listAdapter.getCount() == 0) { if ((activity instanceof MainActivity)) { ((MainActivity) activity).doReload(); } } } }); } return null; } }); return null; } }); listView.setOnTouchListener(this); listView.setOnScrollListener(this); listView.setOnItemClickListener(this); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position, final long id) { if (view instanceof ImageGallery) { return false; // no need that! (possibly, make this condition work only if not scrolled meanwhile) } final Object itemAtPosition = parent.getItemAtPosition(position); if (itemAtPosition instanceof JuickMessage) { doOnClickActualTime = System.currentTimeMillis(); doOnClick = new Runnable() { @Override public void run() { JuickMessage msg = (JuickMessage) itemAtPosition; MessageMenu messageMenu = MainActivity.getMicroBlog(msg).getMessageMenu(getActivity(), messagesSource, listView, listAdapter); if (messageMenu != null) { messageMenu.onItemLongClick(parent, view, position, id); } else { Toast.makeText(getActivity(), "Not implemented ;-(", Toast.LENGTH_LONG).show(); } } }; if (alternativeLongClick) { listView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); } else { doOnClick.run(); doOnClick = null; return true; } } return false; } }); listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { System.out.println(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { System.out.println(); } }); init(false); if (parent != null) { parent.onFragmentCreated(); } }