Example usage for android.widget ImageView setClickable

List of usage examples for android.widget ImageView setClickable

Introduction

In this page you can find the example usage for android.widget ImageView setClickable.

Prototype

public void setClickable(boolean clickable) 

Source Link

Document

Enables or disables click events for this view.

Usage

From source file:com.TakeTaxi.jy.OnrouteScreen.java

public void pingpicked(JSONObject json) {

    try {//w w  w  .  j  a v a 2 s  .  co  m

        int driverpicked = json.getInt("picked");
        int drivercancelled = json.getInt("dcancel");
        int starttime = json.getInt("datetime");

        // /////////////////////////////// DRIVER CANCEL ////////
        if (drivercancelled == 1) {

            // //// DRIVER CANCEL LATE /////

            if (starttime + 300 <= Query.getServerTime()) {
                handlerboolean = false;
                handler.removeCallbacks(r);

                AlertDialog dcancelbuilder = new AlertDialog.Builder(OnrouteScreen.this).create();
                dcancelbuilder
                        .setMessage("Job has been cancelled.\nWould you like to report a late cancellation?.");

                // //// DRIVER CANCEL LATE - NO REPORT LATE/////
                button_cancelJob_noquery(dcancelbuilder);
                // //// DRIVER CANCEL LATE - REPORT LATE /////
                button_drivercancel_reportlate(dcancelbuilder);

                dcancelbuilder.show();

            } else {
                // /////////////////////////////// DRIVER CANCEL NO ALERTS -
                // WITHIN TIME LIMIT///////////////
                handlerboolean = false;
                handler.removeCallbacks(r);

                alertdialog_drivercancelintime();

            }
        }
        if (driverpicked == 1) {
            // /////////////////////////////// CONFIRM PICK UP
            // ///////////////////////////////////////////

            handlerboolean = false;
            handler.removeCallbacks(r);
            AlertDialog.Builder alert = new AlertDialog.Builder(OnrouteScreen.this);
            final Drawable thumbsup = getResources().getDrawable(R.drawable.thumbsup);
            final Drawable thumbsupwhite = getResources().getDrawable(R.drawable.thumbsupwhite);
            final Drawable thumbsdown = getResources().getDrawable(R.drawable.thumbsdown);
            final Drawable thumbsdownwhite = getResources().getDrawable(R.drawable.thumbsdownwhite);
            LinearLayout layout = new LinearLayout(OnrouteScreen.this);
            layout.setOrientation(1);
            layout.setGravity(17);

            TextView tx1 = new TextView(OnrouteScreen.this);
            tx1.setText("Driver says you have been picked up");
            tx1.setGravity(17);
            tx1.setTextSize(20);
            tx1.setTextColor(Color.WHITE);
            tx1.setPadding(10, 10, 10, 10);

            TextView tx2 = new TextView(OnrouteScreen.this);
            tx2.setText("Please rate your driver");
            tx2.setGravity(17);
            tx2.setTextSize(16);

            LinearLayout imglayout = new LinearLayout(OnrouteScreen.this);
            imglayout.setOrientation(0);
            imglayout.setGravity(17);

            final ImageView ivup = new ImageView(OnrouteScreen.this);
            ivup.setImageDrawable(thumbsupwhite);
            ivup.setClickable(true);
            ivup.setPadding(0, 5, 30, 5);
            final ImageView ivdown = new ImageView(OnrouteScreen.this);
            ivdown.setImageDrawable(thumbsdownwhite);
            ivdown.setClickable(true);
            ivup.setPadding(30, 5, 0, 5);
            imglayout.addView(ivup);
            imglayout.addView(ivdown);

            layout.addView(tx1);
            layout.addView(tx2);

            layout.addView(imglayout);
            // /////////////////////////////// CONFIRM PICK UP - RATINGS
            // ///////////////////////////////////////////

            ivup.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    if (thumbsupboolean == false) {
                        thumbsupboolean = true;
                        thumbsdownboolean = false;
                        ivup.setImageDrawable(thumbsup);
                        ivdown.setImageDrawable(thumbsdownwhite);
                        rating = 1;
                    } else {
                        thumbsupboolean = false;
                        ivup.setImageDrawable(thumbsupwhite);
                        rating = 0;
                    }

                }
            });

            ivdown.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    if (thumbsdownboolean == false) {
                        thumbsdownboolean = true;
                        thumbsupboolean = false;
                        ivdown.setImageDrawable(thumbsdown);
                        ivup.setImageDrawable(thumbsupwhite);

                        AlertDialog alert = new AlertDialog.Builder(OnrouteScreen.this).create();

                        alert.setMessage("Please pick one");
                        alert.setButton("No show", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                rating = -1;
                            }
                        });
                        alert.setButton2("Driver late", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                rating = -2;
                            }
                        });
                        alert.setButton3("Poor service", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                rating = -3;
                            }
                        });
                        alert.show();

                    } else {
                        thumbsupboolean = false;
                        ivdown.setImageDrawable(thumbsdownwhite);
                        rating = 0;
                    }

                }
            });

            button_completed_finish(alert);

            alert.setView(layout);
            alert.create();
            alert.show();
        } else {
        }

    } catch (JSONException e) {
    }
}

From source file:com.near.chimerarevo.fragments.PostFragment.java

private void addImage(final String imgUrl) {
    final ImageView img = new ImageView(getActivity());
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    params.setMargins(15, 0, 15, 0);/*from  www .  j ava2s. com*/
    params.gravity = Gravity.CENTER_HORIZONTAL;
    img.setLayoutParams(params);
    img.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    lay.addView(img);

    final DisplayImageOptions options = new DisplayImageOptions.Builder().cacheOnDisk(false).cacheInMemory(true)
            .showImageOnLoading(R.drawable.empty_cr).bitmapConfig(Bitmap.Config.RGB_565)
            .imageScaleType(ImageScaleType.EXACTLY).delayBeforeLoading(150).build();
    ImageLoader.getInstance().displayImage(imgUrl, img, options);

    img.setClickable(true);
    img.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            final Dialog dialog = new Dialog(getActivity());
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.img_dialog_layout);
            ImageLoader.getInstance().displayImage(imgUrl.split("\\?resize=")[0],
                    ((TouchImageView) dialog.findViewById(R.id.dialog_image)), options);
            dialog.setCancelable(true);
            dialog.show();
        }
    });
}

From source file:com.near.chimerarevo.fragments.PostFragment.java

private void addGallery(final String[] imgUrls) {
    numGalleries++;//from w  w w . java  2 s  . c om
    if (!PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("load_imgs_pref", true)
            || numGalleries > Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getActivity())
                    .getString("gallery_num_pref", "20")))
        return;
    HorizontalScrollView hsv = new HorizontalScrollView(getActivity());
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.CENTER_HORIZONTAL;
    params.setMargins(10, 10, 10, 0);
    hsv.setLayoutParams(params);

    LinearLayout container = new LinearLayout(getActivity());
    container.setOrientation(LinearLayout.HORIZONTAL);
    for (int i = 0; i < imgUrls.length; i++) {
        final ImageView img = new ImageView(getActivity());
        LayoutParams imgPar = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        if (i == 0)
            imgPar.setMargins(5, 10, 0, 10);
        else
            imgPar.setMargins(10, 10, 0, 10);
        img.setLayoutParams(imgPar);
        img.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        container.addView(img);

        final DisplayImageOptions options = new DisplayImageOptions.Builder().cacheOnDisk(false)
                .cacheInMemory(true).showImageOnLoading(R.drawable.empty_cr).bitmapConfig(Bitmap.Config.RGB_565)
                .imageScaleType(ImageScaleType.EXACTLY).delayBeforeLoading(200).build();
        ImageLoader.getInstance().displayImage(imgUrls[i], img, options);

        final int k = i;
        img.setClickable(true);
        img.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                final Dialog dialog = new Dialog(getActivity());
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialog.setContentView(R.layout.img_dialog_layout);
                ImageLoader.getInstance().displayImage(imgUrls[k].split("\\?resize=")[0],
                        ((TouchImageView) dialog.findViewById(R.id.dialog_image)), options);
                dialog.setCancelable(true);
                dialog.show();
            }
        });
    }
    hsv.addView(container);
    lay.addView(hsv);
}

From source file:com.xiaoyu.DoctorHelp.chat.chatuidemo.adapter.MessageAdapter.java

/**
 * //from  www.j  a va  2s . com
 *
 * @param localThumb   
 * @param iv
 * @param thumbnailUrl 
 * @param message
 */
private void showVideoThumbView(String localThumb, ImageView iv, String thumbnailUrl, final EMMessage message) {
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(localThumb);
    if (bitmap != null) {
        // thumbnail image is already loaded, reuse the drawable
        iv.setImageBitmap(bitmap);
        iv.setClickable(true);
        iv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                VideoMessageBody videoBody = (VideoMessageBody) message.getBody();
                EMLog.d(TAG, "video view is on click");
                Intent intent = new Intent(activity, ShowVideoActivity.class);
                intent.putExtra("localpath", videoBody.getLocalUrl());
                intent.putExtra("secret", videoBody.getSecret());
                intent.putExtra("remotepath", videoBody.getRemoteUrl());
                if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked
                        && message.getChatType() != ChatType.GroupChat
                        && message.getChatType() != ChatType.ChatRoom) {
                    message.isAcked = true;
                    try {
                        EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                activity.startActivity(intent);

            }
        });

    } else {
        new LoadVideoImageTask().execute(localThumb, thumbnailUrl, iv, activity, message, this);
    }

}

From source file:com.fullteem.yueba.app.adapter.MessageAdapter.java

/**
 * /*w ww.ja  v  a 2  s  .  c o  m*/
 * 
 * @param localThumb
 *            
 * @param iv
 * @param thumbnailUrl
 *            
 * @param message
 */
private void showVideoThumbView(String localThumb, ImageView iv, String thumbnailUrl, final EMMessage message) {
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(localThumb);
    if (bitmap != null) {
        // thumbnail image is already loaded, reuse the drawable
        iv.setImageBitmap(bitmap);
        iv.setClickable(true);
        iv.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // VideoMessageBody videoBody = (VideoMessageBody)
                // message.getBody();
                // System.err.println("video view is on click");
                // Intent intent = new Intent(activity,
                // ShowVideoActivity.class);
                // intent.putExtra("localpath", videoBody.getLocalUrl());
                // intent.putExtra("secret", videoBody.getSecret());
                // intent.putExtra("remotepath", videoBody.getRemoteUrl());
                // if (message != null && message.direct ==
                // EMMessage.Direct.RECEIVE && !message.isAcked
                // && message.getChatType() != ChatType.GroupChat) {
                // message.isAcked = true;
                // try {
                // EMChatManager.getInstance().ackMessageRead(message.getFrom(),
                // message.getMsgId());
                // } catch (Exception e) {
                // e.printStackTrace();
                // }
                // }
                // activity.startActivity(intent);

            }
        });

    } else {
        // new LoadVideoImageTask().execute(localThumb, thumbnailUrl, iv,
        // activity, message, this);
    }

}

From source file:com.easemob.chatui.adapter.MessageAdapter.java

/**
 * /*w  w w.j av  a2  s.  c o  m*/
 *
 * @param localThumb   
 * @param iv
 * @param thumbnailUrl 
 * @param message
 */
private void showVideoThumbView(String localThumb, ImageView iv, String thumbnailUrl, final EMMessage message) {
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(localThumb);
    if (bitmap != null) {
        // thumbnail image is already loaded, reuse the drawable
        iv.setImageBitmap(bitmap);
        iv.setClickable(true);
        iv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                VideoMessageBody videoBody = (VideoMessageBody) message.getBody();
                EMLog.d(TAG, "video view is on click");
                Intent intent = new Intent(activity, ShowVideoActivity.class);
                intent.putExtra("localpath", videoBody.getLocalUrl());
                intent.putExtra("secret", videoBody.getSecret());
                intent.putExtra("remotepath", videoBody.getRemoteUrl());
                if (message != null && message.direct == Direct.RECEIVE && !message.isAcked
                        && message.getChatType() != ChatType.GroupChat
                        && message.getChatType() != ChatType.ChatRoom) {
                    message.isAcked = true;
                    try {
                        EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                activity.startActivity(intent);

            }
        });

    } else {
        new LoadVideoImageTask().execute(localThumb, thumbnailUrl, iv, activity, message, this);
    }

}

From source file:edu.berkeley.boinc.StatusFragment.java

private void loadLayout(Boolean forceUpdate) {
    //load layout, if if ClientStatus can be accessed.
    //if this is not the case, the broadcast receiver will call "loadLayout" again
    try {/*from   w  w w . jav a  2s .  c om*/

        int currentSetupStatus = BOINCActivity.monitor.getSetupStatus();
        int currentComputingStatus = BOINCActivity.monitor.getComputingStatus();
        int currentComputingSuspendReason = BOINCActivity.monitor.getComputingSuspendReason();
        int currentNetworkSuspendReason = BOINCActivity.monitor.getNetworkSuspendReason();

        // layout only if client RPC connection is established
        // otherwise BOINCActivity does not start Tabs
        if (currentSetupStatus == ClientStatus.SETUP_STATUS_AVAILABLE) {
            // return in cases nothing has changed
            if (forceUpdate || computingStatus != currentComputingStatus
                    || currentComputingSuspendReason != computingSuspendReason
                    || currentNetworkSuspendReason != networkSuspendReason) {

                // set layout and retrieve elements
                LinearLayout statusWrapper = (LinearLayout) getView().findViewById(R.id.status_wrapper);
                LinearLayout centerWrapper = (LinearLayout) getView().findViewById(R.id.center_wrapper);
                LinearLayout restartingWrapper = (LinearLayout) getView().findViewById(R.id.restarting_wrapper);
                TextView statusHeader = (TextView) getView().findViewById(R.id.status_header);
                ImageView statusImage = (ImageView) getView().findViewById(R.id.status_image);
                TextView statusDescriptor = (TextView) getView().findViewById(R.id.status_long);

                restartingWrapper.setVisibility(View.GONE);

                // adapt to specific computing status
                switch (currentComputingStatus) {
                case ClientStatus.COMPUTING_STATUS_NEVER:
                    statusWrapper.setVisibility(View.VISIBLE);
                    statusHeader.setText(BOINCActivity.monitor.getCurrentStatusTitle());
                    statusHeader.setVisibility(View.VISIBLE);
                    statusImage.setImageResource(R.drawable.playb48);
                    statusImage.setContentDescription(BOINCActivity.monitor.getCurrentStatusTitle());
                    statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                    centerWrapper.setVisibility(View.VISIBLE);
                    centerWrapper.setOnClickListener(runModeOnClickListener);
                    break;
                case ClientStatus.COMPUTING_STATUS_SUSPENDED:
                    statusWrapper.setVisibility(View.VISIBLE);
                    statusHeader.setText(BOINCActivity.monitor.getCurrentStatusTitle());
                    statusHeader.setVisibility(View.VISIBLE);
                    statusImage.setImageResource(R.drawable.pauseb48);
                    statusImage.setContentDescription(BOINCActivity.monitor.getCurrentStatusTitle());
                    statusImage.setClickable(false);
                    centerWrapper.setVisibility(View.VISIBLE);
                    switch (currentComputingSuspendReason) {
                    case BOINCDefs.SUSPEND_REASON_BATTERIES:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        statusImage.setImageResource(R.drawable.notconnectedb48);
                        statusHeader.setVisibility(View.GONE);
                        break;
                    case BOINCDefs.SUSPEND_REASON_USER_ACTIVE:
                        Boolean suspendDueToScreenOn = false;
                        try {
                            suspendDueToScreenOn = BOINCActivity.monitor.getSuspendWhenScreenOn();
                        } catch (RemoteException e) {
                        }
                        if (suspendDueToScreenOn) {
                            statusImage.setImageResource(R.drawable.screen48b);
                            statusHeader.setVisibility(View.GONE);
                        }
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_USER_REQ:
                        // state after user stops and restarts computation
                        centerWrapper.setVisibility(View.GONE);
                        restartingWrapper.setVisibility(View.VISIBLE);
                        break;
                    case BOINCDefs.SUSPEND_REASON_TIME_OF_DAY:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_BENCHMARKS:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        statusImage.setImageResource(R.drawable.watchb48);
                        statusHeader.setVisibility(View.GONE);
                        break;
                    case BOINCDefs.SUSPEND_REASON_DISK_SIZE:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_CPU_THROTTLE:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_NO_RECENT_INPUT:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_INITIAL_DELAY:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_EXCLUSIVE_APP_RUNNING:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_CPU_USAGE:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_NETWORK_QUOTA_EXCEEDED:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_OS:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_WIFI_STATE:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_BATTERY_CHARGING:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        statusImage.setImageResource(R.drawable.batteryb48);
                        statusHeader.setVisibility(View.GONE);
                        break;
                    case BOINCDefs.SUSPEND_REASON_BATTERY_OVERHEATED:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        statusImage.setImageResource(R.drawable.batteryb48);
                        statusHeader.setVisibility(View.GONE);
                        break;
                    default:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    }
                    break;
                case ClientStatus.COMPUTING_STATUS_IDLE:
                    statusWrapper.setVisibility(View.VISIBLE);
                    centerWrapper.setVisibility(View.VISIBLE);
                    statusHeader.setText(BOINCActivity.monitor.getCurrentStatusTitle());
                    statusHeader.setVisibility(View.VISIBLE);
                    statusImage.setImageResource(R.drawable.pauseb48);
                    statusImage.setContentDescription(BOINCActivity.monitor.getCurrentStatusTitle());
                    statusImage.setClickable(false);
                    statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                    break;
                case ClientStatus.COMPUTING_STATUS_COMPUTING:
                    statusWrapper.setVisibility(View.GONE);
                    break;
                }
                //save new computing status
                computingStatus = currentComputingStatus;
                computingSuspendReason = currentComputingSuspendReason;
                networkSuspendReason = currentNetworkSuspendReason;
                setupStatus = -1; // invalidate to force update next time no project
            }
        } else if (currentSetupStatus == ClientStatus.SETUP_STATUS_NOPROJECT) {

            if (setupStatus != ClientStatus.SETUP_STATUS_NOPROJECT) {
                // set layout and retrieve elements
                LinearLayout statusWrapper = (LinearLayout) getView().findViewById(R.id.status_wrapper);
                LinearLayout centerWrapper = (LinearLayout) getView().findViewById(R.id.center_wrapper);
                LinearLayout restartingWrapper = (LinearLayout) getView().findViewById(R.id.restarting_wrapper);
                TextView statusHeader = (TextView) getView().findViewById(R.id.status_header);
                ImageView statusImage = (ImageView) getView().findViewById(R.id.status_image);
                TextView statusDescriptor = (TextView) getView().findViewById(R.id.status_long);

                statusWrapper.setVisibility(View.VISIBLE);
                restartingWrapper.setVisibility(View.GONE);
                centerWrapper.setVisibility(View.VISIBLE);
                centerWrapper.setOnClickListener(addProjectOnClickListener);
                statusImage.setImageResource(R.drawable.projectsb48);
                statusHeader.setVisibility(View.GONE);
                statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusTitle());
                setupStatus = ClientStatus.SETUP_STATUS_NOPROJECT;
                computingStatus = -1;
            }
        } else { // BOINC client is not available
            //invalid computingStatus, forces layout on next event
            setupStatus = -1;
            computingStatus = -1;
        }
    } catch (Exception e) {
    }
}

From source file:com.com.easemob.chatuidemo.adapter.MessageAdapter.java

/**
 * /*w w w  .  j  a v a 2s.co  m*/
 *
 * @param localThumb
 *            
 * @param iv
 * @param thumbnailUrl
 *            
 * @param message
 */
private void showVideoThumbView(String localThumb, ImageView iv, String thumbnailUrl, final EMMessage message) {
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(localThumb);
    if (bitmap != null) {
        // thumbnail image is already loaded, reuse the drawable
        iv.setImageBitmap(bitmap);
        iv.setClickable(true);
        iv.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                VideoMessageBody videoBody = (VideoMessageBody) message.getBody();
                EMLog.d(TAG, "video view is on click");
                Intent intent = new Intent(activity, ShowVideoActivity.class);
                intent.putExtra("localpath", videoBody.getLocalUrl());
                intent.putExtra("secret", videoBody.getSecret());
                intent.putExtra("remotepath", videoBody.getRemoteUrl());
                if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked
                        && message.getChatType() != ChatType.GroupChat
                        && message.getChatType() != ChatType.ChatRoom) {
                    message.isAcked = true;
                    try {
                        EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                activity.startActivity(intent);

            }
        });

    } else {
        new LoadVideoImageTask().execute(localThumb, thumbnailUrl, iv, activity, message, this);
    }

}

From source file:com.irccloud.android.activity.UploadsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (ColorFormatter.file_uri_template != null)
        template = UriTemplate.fromTemplate(ColorFormatter.file_uri_template);
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= 21) {
        Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name),
                cloud, 0xFFF2F7FC));// www.  j a v  a  2 s.co  m
        cloud.recycle();
    }

    if (Build.VERSION.SDK_INT >= 14) {
        try {
            java.io.File httpCacheDir = new java.io.File(getCacheDir(), "http");
            long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
            HttpResponseCache.install(httpCacheDir, httpCacheSize);
        } catch (IOException e) {
            Log.i("IRCCloud", "HTTP response cache installation failed:" + e);
        }
    }
    setContentView(R.layout.ignorelist);

    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
        getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar));
        getSupportActionBar().setElevation(0);
    }

    if (savedInstanceState != null && savedInstanceState.containsKey("cid")) {
        cid = savedInstanceState.getInt("cid");
        to = savedInstanceState.getString("to");
        msg = savedInstanceState.getString("msg");
        page = savedInstanceState.getInt("page");
        File[] files = (File[]) savedInstanceState.getSerializable("adapter");
        for (File f : files) {
            adapter.addFile(f);
        }
        adapter.notifyDataSetChanged();
    }

    footer = getLayoutInflater().inflate(R.layout.messageview_header, null);
    ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setAdapter(adapter);
    listView.addFooterView(footer);
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (canLoadMore && firstVisibleItem + visibleItemCount > totalItemCount - 4) {
                canLoadMore = false;
                new FetchFilesTask().execute((Void) null);
            }
        }
    });
    listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            final File f = (File) adapter.getItem(i);

            AlertDialog.Builder builder = new AlertDialog.Builder(UploadsActivity.this);
            builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB);
            final View v = getLayoutInflater().inflate(R.layout.dialog_upload, null);
            final EditText messageinput = (EditText) v.findViewById(R.id.message);
            messageinput.setText(msg);
            final ImageView thumbnail = (ImageView) v.findViewById(R.id.thumbnail);

            v.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (messageinput.hasFocus()) {
                        v.post(new Runnable() {
                            @Override
                            public void run() {
                                v.scrollTo(0, v.getBottom());
                            }
                        });
                    }
                }
            });

            if (f.mime_type.startsWith("image/")) {
                try {
                    thumbnail.setImageBitmap(f.image);
                    thumbnail.setVisibility(View.VISIBLE);
                    thumbnail.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            Intent i = new Intent(UploadsActivity.this, ImageViewerActivity.class);
                            i.setData(Uri.parse(f.url));
                            startActivity(i);
                        }
                    });
                    thumbnail.setClickable(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                thumbnail.setVisibility(View.GONE);
            }

            ((TextView) v.findViewById(R.id.filesize)).setText(f.metadata);
            v.findViewById(R.id.filename).setVisibility(View.GONE);
            v.findViewById(R.id.filename_heading).setVisibility(View.GONE);

            builder.setTitle("Send A File To " + to);
            builder.setView(v);
            builder.setPositiveButton("Send", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String message = messageinput.getText().toString();
                    if (message.length() > 0)
                        message += " ";
                    message += f.url;

                    dialog.dismiss();
                    if (getParent() == null) {
                        setResult(Activity.RESULT_OK);
                    } else {
                        getParent().setResult(Activity.RESULT_OK);
                    }
                    finish();

                    NetworkConnection.getInstance().say(cid, to, message);
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            AlertDialog d = builder.create();
            d.setOwnerActivity(UploadsActivity.this);
            d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
            d.show();
        }
    });
}

From source file:com.xiaoyu.DoctorHelp.chat.chatuidemo.adapter.MessageAdapter.java

/**
 * load image into image view//from ww w .  jav  a  2  s  . c  om
 *
 * @param thumbernailPath
 * @param iv
 * @param
 * @return the image exists or not
 */
private boolean showImageView(final String thumbernailPath, final ImageView iv, final String localFullSizePath,
        String remoteDir, final EMMessage message) {
    // String imagename =
    // localFullSizePath.substring(localFullSizePath.lastIndexOf("/") + 1,
    // localFullSizePath.length());
    // final String remote = remoteDir != null ? remoteDir+imagename :
    // imagename;
    final String remote = remoteDir;
    EMLog.d("###", "local = " + localFullSizePath + " remote: " + remote);
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(thumbernailPath);
    if (bitmap != null) {
        // thumbnail image is already loaded, reuse the drawable
        iv.setImageBitmap(bitmap);
        iv.setClickable(true);
        iv.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                EMLog.d(TAG, "image view on click");
                Intent intent = new Intent(activity, ShowBigImage.class);
                File file = new File(localFullSizePath);
                if (file.exists()) {
                    Uri uri = Uri.fromFile(file);
                    intent.putExtra("uri", uri);
                    EMLog.d(TAG, "here need to check why download everytime");
                } else {
                    // The local full size pic does not exist yet.
                    // ShowBigImage needs to download it from the server
                    // first
                    // intent.putExtra("", message.get);
                    ImageMessageBody body = (ImageMessageBody) message.getBody();
                    intent.putExtra("secret", body.getSecret());
                    intent.putExtra("remotepath", remote);
                }
                if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked
                        && message.getChatType() != ChatType.GroupChat
                        && message.getChatType() != ChatType.ChatRoom) {
                    try {
                        EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                        message.isAcked = true;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                activity.startActivity(intent);
            }
        });
        return true;
    } else {

        new LoadImageTask().execute(thumbernailPath, localFullSizePath, remote, message.getChatType(), iv,
                activity, message);
        return true;
    }

}