Search in sources :

Example 26 with OnLongClickListener

use of android.view.View.OnLongClickListener in project android-app by spark.

the class TinkerFragment method setupListeners.

private void setupListeners() {
    // Set up pin listeners
    for (final Pin pin : allPins) {
        for (View view : list(pin.view, (ViewGroup) pin.view.getParent())) {
            view.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Pin writeModePin = getPinInWriteMode();
                    if (writeModePin != null && !pin.equals(selectedPin)) {
                        writeModePin.showAnalogWriteValue();
                        unmutePins();
                        return;
                    }
                    selectedPin = pin;
                    onPinClick(pin);
                }
            });
            view.setOnLongClickListener(new OnLongClickListener() {

                @Override
                public boolean onLongClick(View v) {
                    Pin writeModePin = getPinInWriteMode();
                    if (writeModePin != null && !pin.equals(selectedPin)) {
                        writeModePin.showAnalogWriteValue();
                        unmutePins();
                        return true;
                    }
                    selectedPin = pin;
                    showTinkerSelect(pin);
                    return true;
                }
            });
        }
    }
    // Set up other listeners
    Ui.findView(this, R.id.tinker_main).setOnClickListener(this);
}
Also used : OnLongClickListener(android.view.View.OnLongClickListener) OnClickListener(android.view.View.OnClickListener) View(android.view.View) TextView(android.widget.TextView)

Example 27 with OnLongClickListener

use of android.view.View.OnLongClickListener in project Conversations by siacs.

the class MessageAdapter method getView.

@Override
public View getView(int position, View view, ViewGroup parent) {
    final Message message = getItem(position);
    final boolean omemoEncryption = message.getEncryption() == Message.ENCRYPTION_AXOLOTL;
    final boolean isInValidSession = message.isValidInSession() && (!omemoEncryption || message.isTrusted());
    final Conversation conversation = message.getConversation();
    final Account account = conversation.getAccount();
    final int type = getItemViewType(position);
    ViewHolder viewHolder;
    if (view == null) {
        viewHolder = new ViewHolder();
        switch(type) {
            case SENT:
                view = activity.getLayoutInflater().inflate(R.layout.message_sent, parent, false);
                viewHolder.message_box = (LinearLayout) view.findViewById(R.id.message_box);
                viewHolder.contact_picture = (ImageView) view.findViewById(R.id.message_photo);
                viewHolder.download_button = (Button) view.findViewById(R.id.download_button);
                viewHolder.indicator = (ImageView) view.findViewById(R.id.security_indicator);
                viewHolder.edit_indicator = (ImageView) view.findViewById(R.id.edit_indicator);
                viewHolder.image = (ImageView) view.findViewById(R.id.message_image);
                viewHolder.messageBody = (CopyTextView) view.findViewById(R.id.message_body);
                viewHolder.time = (TextView) view.findViewById(R.id.message_time);
                viewHolder.indicatorReceived = (ImageView) view.findViewById(R.id.indicator_received);
                break;
            case RECEIVED:
                view = activity.getLayoutInflater().inflate(R.layout.message_received, parent, false);
                viewHolder.message_box = (LinearLayout) view.findViewById(R.id.message_box);
                viewHolder.contact_picture = (ImageView) view.findViewById(R.id.message_photo);
                viewHolder.download_button = (Button) view.findViewById(R.id.download_button);
                viewHolder.indicator = (ImageView) view.findViewById(R.id.security_indicator);
                viewHolder.edit_indicator = (ImageView) view.findViewById(R.id.edit_indicator);
                viewHolder.image = (ImageView) view.findViewById(R.id.message_image);
                viewHolder.messageBody = (CopyTextView) view.findViewById(R.id.message_body);
                viewHolder.time = (TextView) view.findViewById(R.id.message_time);
                viewHolder.indicatorReceived = (ImageView) view.findViewById(R.id.indicator_received);
                viewHolder.encryption = (TextView) view.findViewById(R.id.message_encryption);
                break;
            case STATUS:
                view = activity.getLayoutInflater().inflate(R.layout.message_status, parent, false);
                viewHolder.contact_picture = (ImageView) view.findViewById(R.id.message_photo);
                viewHolder.status_message = (TextView) view.findViewById(R.id.status_message);
                viewHolder.load_more_messages = (Button) view.findViewById(R.id.load_more_messages);
                break;
            default:
                viewHolder = null;
                break;
        }
        if (viewHolder.messageBody != null) {
            listSelectionManager.onCreate(viewHolder.messageBody, new MessageBodyActionModeCallback(viewHolder.messageBody));
            viewHolder.messageBody.setCopyHandler(this);
        }
        view.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) view.getTag();
        if (viewHolder == null) {
            return view;
        }
    }
    boolean darkBackground = type == RECEIVED && (!isInValidSession || mUseGreenBackground) || activity.isDarkTheme();
    if (type == STATUS) {
        if ("LOAD_MORE".equals(message.getBody())) {
            viewHolder.status_message.setVisibility(View.GONE);
            viewHolder.contact_picture.setVisibility(View.GONE);
            viewHolder.load_more_messages.setVisibility(View.VISIBLE);
            viewHolder.load_more_messages.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    loadMoreMessages(message.getConversation());
                }
            });
        } else {
            viewHolder.status_message.setVisibility(View.VISIBLE);
            viewHolder.load_more_messages.setVisibility(View.GONE);
            viewHolder.status_message.setText(message.getBody());
            boolean showAvatar;
            if (conversation.getMode() == Conversation.MODE_SINGLE) {
                showAvatar = true;
                loadAvatar(message, viewHolder.contact_picture, activity.getPixel(32));
            } else if (message.getCounterpart() != null) {
                showAvatar = true;
                loadAvatar(message, viewHolder.contact_picture, activity.getPixel(32));
            } else {
                showAvatar = false;
            }
            if (showAvatar) {
                viewHolder.contact_picture.setAlpha(0.5f);
                viewHolder.contact_picture.setVisibility(View.VISIBLE);
            } else {
                viewHolder.contact_picture.setVisibility(View.GONE);
            }
        }
        return view;
    } else {
        loadAvatar(message, viewHolder.contact_picture, activity.getPixel(48));
    }
    viewHolder.contact_picture.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (MessageAdapter.this.mOnContactPictureClickedListener != null) {
                MessageAdapter.this.mOnContactPictureClickedListener.onContactPictureClicked(message);
            }
        }
    });
    viewHolder.contact_picture.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) {
                MessageAdapter.this.mOnContactPictureLongClickedListener.onContactPictureLongClicked(message);
                return true;
            } else {
                return false;
            }
        }
    });
    final Transferable transferable = message.getTransferable();
    if (transferable != null && transferable.getStatus() != Transferable.STATUS_UPLOADING) {
        if (transferable.getStatus() == Transferable.STATUS_OFFER) {
            displayDownloadableMessage(viewHolder, message, activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, message)));
        } else if (transferable.getStatus() == Transferable.STATUS_OFFER_CHECK_FILESIZE) {
            displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message)));
        } else {
            displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first, darkBackground);
        }
    } else if (message.getType() == Message.TYPE_IMAGE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
        displayImageMessage(viewHolder, message);
    } else if (message.getType() == Message.TYPE_FILE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
        if (message.getFileParams().width > 0) {
            displayImageMessage(viewHolder, message);
        } else {
            displayOpenableMessage(viewHolder, message);
        }
    } else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
        if (account.isPgpDecryptionServiceConnected()) {
            if (!account.hasPendingPgpIntent(conversation)) {
                displayInfoMessage(viewHolder, activity.getString(R.string.message_decrypting), darkBackground);
            } else {
                displayInfoMessage(viewHolder, activity.getString(R.string.pgp_message), darkBackground);
            }
        } else {
            displayInfoMessage(viewHolder, activity.getString(R.string.install_openkeychain), darkBackground);
            if (viewHolder != null) {
                viewHolder.message_box.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        activity.showInstallPgpDialog();
                    }
                });
            }
        }
    } else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
        displayDecryptionFailed(viewHolder, darkBackground);
    } else {
        if (GeoHelper.isGeoUri(message.getBody())) {
            displayLocationMessage(viewHolder, message);
        } else if (message.bodyIsHeart()) {
            displayHeartMessage(viewHolder, message.getBody().trim());
        } else if (message.treatAsDownloadable() == Message.Decision.MUST) {
            try {
                URL url = new URL(message.getBody());
                displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize_on_host, UIHelper.getFileDescriptionString(activity, message), url.getHost()));
            } catch (Exception e) {
                displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message)));
            }
        } else {
            displayTextMessage(viewHolder, message, darkBackground, type);
        }
    }
    if (type == RECEIVED) {
        if (isInValidSession) {
            int bubble;
            if (!mUseGreenBackground) {
                bubble = activity.getThemeResource(R.attr.message_bubble_received_monochrome, R.drawable.message_bubble_received_white);
            } else {
                bubble = activity.getThemeResource(R.attr.message_bubble_received_green, R.drawable.message_bubble_received);
            }
            viewHolder.message_box.setBackgroundResource(bubble);
            viewHolder.encryption.setVisibility(View.GONE);
        } else {
            viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received_warning);
            viewHolder.encryption.setVisibility(View.VISIBLE);
            if (omemoEncryption && !message.isTrusted()) {
                viewHolder.encryption.setText(R.string.not_trusted);
            } else {
                viewHolder.encryption.setText(CryptoHelper.encryptionTypeToText(message.getEncryption()));
            }
        }
    }
    displayStatus(viewHolder, message, type, darkBackground, isInValidSession);
    return view;
}
Also used : Account(eu.siacs.conversations.entities.Account) Message(eu.siacs.conversations.entities.Message) Transferable(eu.siacs.conversations.entities.Transferable) Conversation(eu.siacs.conversations.entities.Conversation) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) CopyTextView(eu.siacs.conversations.ui.widget.CopyTextView) URL(java.net.URL) ActivityNotFoundException(android.content.ActivityNotFoundException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) OnLongClickListener(android.view.View.OnLongClickListener) OnClickListener(android.view.View.OnClickListener)

Example 28 with OnLongClickListener

use of android.view.View.OnLongClickListener in project wechat by motianhuo.

the class AlbumActivity method setListener.

@Override
protected void setListener() {
    findViewById(R.id.img_back).setOnClickListener(this);
    img_talk.setOnClickListener(this);
    img_talk.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            Utils.showLongToast(context, "长按发送文字");
            return true;
        }
    });
}
Also used : OnLongClickListener(android.view.View.OnLongClickListener) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View) ListView(android.widget.ListView)

Example 29 with OnLongClickListener

use of android.view.View.OnLongClickListener in project wechat by motianhuo.

the class MessageAdapter method handleImageMessage.

/**
	 * 图片消息
	 * 
	 * @param message
	 * @param holder
	 * @param position
	 * @param convertView
	 */
private void handleImageMessage(final EMMessage message, final ViewHolder holder, final int position, View convertView) {
    holder.pb.setTag(position);
    holder.iv.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            activity.startActivityForResult((new Intent(activity, ContextMenu.class)).putExtra("position", position).putExtra("type", EMMessage.Type.IMAGE.ordinal()), ChatActivity.REQUEST_CODE_CONTEXT_MENU);
            return true;
        }
    });
    // 接收方向的消息
    if (message.direct == EMMessage.Direct.RECEIVE) {
        // "it is receive msg";
        if (message.status == EMMessage.Status.INPROGRESS) {
            // "!!!! back receive";
            holder.iv.setImageResource(R.drawable.default_image);
            showDownloadImageProgress(message, holder);
        // downloadImage(message, holder);
        } else {
            // "!!!! not back receive, show image directly");
            holder.pb.setVisibility(View.GONE);
            holder.tv.setVisibility(View.GONE);
            holder.iv.setImageResource(R.drawable.default_image);
            ImageMessageBody imgBody = (ImageMessageBody) message.getBody();
            if (imgBody.getLocalUrl() != null) {
                // String filePath = imgBody.getLocalUrl();
                String remotePath = imgBody.getRemoteUrl();
                String filePath = ImageUtils.getImagePath(remotePath);
                String thumbRemoteUrl = imgBody.getThumbnailUrl();
                String thumbnailPath = ImageUtils.getThumbnailImagePath(thumbRemoteUrl);
                showImageView(thumbnailPath, holder.iv, filePath, imgBody.getRemoteUrl(), message);
            }
        }
        return;
    }
    // 发送的消息
    // process send message
    // send pic, show the pic directly
    ImageMessageBody imgBody = (ImageMessageBody) message.getBody();
    String filePath = imgBody.getLocalUrl();
    if (filePath != null && new File(filePath).exists()) {
        showImageView(ImageUtils.getThumbnailImagePath(filePath), holder.iv, filePath, null, message);
    } else {
        showImageView(ImageUtils.getThumbnailImagePath(filePath), holder.iv, filePath, IMAGE_DIR, message);
    }
    switch(message.status) {
        case SUCCESS:
            holder.pb.setVisibility(View.GONE);
            holder.tv.setVisibility(View.GONE);
            holder.staus_iv.setVisibility(View.GONE);
            break;
        case FAIL:
            holder.pb.setVisibility(View.GONE);
            holder.tv.setVisibility(View.GONE);
            holder.staus_iv.setVisibility(View.VISIBLE);
            break;
        case INPROGRESS:
            holder.staus_iv.setVisibility(View.GONE);
            holder.pb.setVisibility(View.VISIBLE);
            holder.tv.setVisibility(View.VISIBLE);
            if (timers.containsKey(message.getMsgId()))
                return;
            // set a timer
            final Timer timer = new Timer();
            timers.put(message.getMsgId(), timer);
            timer.schedule(new TimerTask() {

                @Override
                public void run() {
                    activity.runOnUiThread(new Runnable() {

                        public void run() {
                            holder.pb.setVisibility(View.VISIBLE);
                            holder.tv.setVisibility(View.VISIBLE);
                            holder.tv.setText(message.progress + "%");
                            if (message.status == EMMessage.Status.SUCCESS) {
                                holder.pb.setVisibility(View.GONE);
                                holder.tv.setVisibility(View.GONE);
                                // message.setSendingStatus(Message.SENDING_STATUS_SUCCESS);
                                timer.cancel();
                            } else if (message.status == EMMessage.Status.FAIL) {
                                holder.pb.setVisibility(View.GONE);
                                holder.tv.setVisibility(View.GONE);
                                // message.setSendingStatus(Message.SENDING_STATUS_FAIL);
                                // message.setProgress(0);
                                holder.staus_iv.setVisibility(View.VISIBLE);
                                Toast.makeText(activity, activity.getString(R.string.send_fail) + activity.getString(R.string.connect_failuer_toast), 0).show();
                                timer.cancel();
                            }
                        }
                    });
                }
            }, 0, 500);
            break;
        default:
            sendPictureMessage(message, holder);
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) OnLongClickListener(android.view.View.OnLongClickListener) Intent(android.content.Intent) ContextMenu(com.juns.wechat.chat.ContextMenu) ImageMessageBody(com.easemob.chat.ImageMessageBody) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) File(java.io.File)

Example 30 with OnLongClickListener

use of android.view.View.OnLongClickListener in project wechat by motianhuo.

the class MessageAdapter method handleVideoMessage.

/**
	 * 视频消息
	 * 
	 * @param message
	 * @param holder
	 * @param position
	 * @param convertView
	 */
private void handleVideoMessage(final EMMessage message, final ViewHolder holder, final int position, View convertView) {
    VideoMessageBody videoBody = (VideoMessageBody) message.getBody();
    // final File image=new File(PathUtil.getInstance().getVideoPath(),
    // videoBody.getFileName());
    String localThumb = videoBody.getLocalThumb();
    holder.iv.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            activity.startActivityForResult(new Intent(activity, ContextMenu.class).putExtra("position", position).putExtra("type", EMMessage.Type.VIDEO.ordinal()), ChatActivity.REQUEST_CODE_CONTEXT_MENU);
            return true;
        }
    });
    if (localThumb != null) {
        showVideoThumbView(localThumb, holder.iv, videoBody.getThumbnailUrl(), message);
    }
    if (videoBody.getLength() > 0) {
        String time = DateUtils.toTimeBySecond(videoBody.getLength());
        holder.timeLength.setText(time);
    }
    holder.playBtn.setImageResource(R.drawable.video_download_btn_nor);
    if (message.direct == EMMessage.Direct.RECEIVE) {
        if (videoBody.getVideoFileLength() > 0) {
            String size = TextFormater.getDataSize(videoBody.getVideoFileLength());
            holder.size.setText(size);
        }
    } else {
        if (videoBody.getLocalUrl() != null && new File(videoBody.getLocalUrl()).exists()) {
            String size = TextFormater.getDataSize(new File(videoBody.getLocalUrl()).length());
            holder.size.setText(size);
        }
    }
    if (message.direct == EMMessage.Direct.RECEIVE) {
        // System.err.println("it is receive msg");
        if (message.status == EMMessage.Status.INPROGRESS) {
            // System.err.println("!!!! back receive");
            holder.iv.setImageResource(R.drawable.default_image);
            showDownloadImageProgress(message, holder);
        } else {
            // System.err.println("!!!! not back receive, show image directly");
            holder.iv.setImageResource(R.drawable.default_image);
            if (localThumb != null) {
                showVideoThumbView(localThumb, holder.iv, videoBody.getThumbnailUrl(), message);
            }
        }
        return;
    }
    holder.pb.setTag(position);
    // until here ,deal with send video msg
    switch(message.status) {
        case SUCCESS:
            holder.pb.setVisibility(View.GONE);
            holder.staus_iv.setVisibility(View.GONE);
            holder.tv.setVisibility(View.GONE);
            break;
        case FAIL:
            holder.pb.setVisibility(View.GONE);
            holder.tv.setVisibility(View.GONE);
            holder.staus_iv.setVisibility(View.VISIBLE);
            break;
        case INPROGRESS:
            if (timers.containsKey(message.getMsgId()))
                return;
            // set a timer
            final Timer timer = new Timer();
            timers.put(message.getMsgId(), timer);
            timer.schedule(new TimerTask() {

                @Override
                public void run() {
                    activity.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            holder.pb.setVisibility(View.VISIBLE);
                            holder.tv.setVisibility(View.VISIBLE);
                            holder.tv.setText(message.progress + "%");
                            if (message.status == EMMessage.Status.SUCCESS) {
                                holder.pb.setVisibility(View.GONE);
                                holder.tv.setVisibility(View.GONE);
                                // message.setSendingStatus(Message.SENDING_STATUS_SUCCESS);
                                timer.cancel();
                            } else if (message.status == EMMessage.Status.FAIL) {
                                holder.pb.setVisibility(View.GONE);
                                holder.tv.setVisibility(View.GONE);
                                // message.setSendingStatus(Message.SENDING_STATUS_FAIL);
                                // message.setProgress(0);
                                holder.staus_iv.setVisibility(View.VISIBLE);
                                Toast.makeText(activity, activity.getString(R.string.send_fail) + activity.getString(R.string.connect_failuer_toast), 0).show();
                                timer.cancel();
                            }
                        }
                    });
                }
            }, 0, 500);
            break;
        default:
            // sendMsgInBackground(message, holder);
            sendPictureMessage(message, holder);
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) OnLongClickListener(android.view.View.OnLongClickListener) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) File(java.io.File) VideoMessageBody(com.easemob.chat.VideoMessageBody)

Aggregations

OnLongClickListener (android.view.View.OnLongClickListener)34 View (android.view.View)33 TextView (android.widget.TextView)17 Longpress (android.view.Longpress)12 ImageView (android.widget.ImageView)12 OnClickListener (android.view.View.OnClickListener)10 Intent (android.content.Intent)9 ContextMenu (com.juns.wechat.chat.ContextMenu)4 RecyclerView (android.support.v7.widget.RecyclerView)3 LinearLayout (android.widget.LinearLayout)3 File (java.io.File)3 SuppressLint (android.annotation.SuppressLint)2 ViewGroup (android.view.ViewGroup)2 ListView (android.widget.ListView)2 RelativeLayout (android.widget.RelativeLayout)2 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 LayoutTransition (android.animation.LayoutTransition)1 AlertDialog (android.app.AlertDialog)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1