Example usage for android.widget ImageView setOnClickListener

List of usage examples for android.widget ImageView setOnClickListener

Introduction

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

Prototype

public void setOnClickListener(@Nullable OnClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked.

Usage

From source file:Main.java

public static void showPopWindow(Context context, View parent, int drawableId) {
    if (drawableId == 0) {
        return;//  w  w  w  .j a v  a 2s. co m
    }
    if (pop == null) {
        ImageView imageView = null;
        imageView = new ImageView(context);
        imageView.setBackgroundResource(drawableId);
        pop = new PopupWindow(imageView, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        imageView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (pop != null) {
                    pop.dismiss();
                    pop = null;
                }
            }
        });
    }
    if (!pop.isShowing()) {
        pop.showAtLocation(parent, Gravity.BOTTOM, 0, 0);

    }
}

From source file:com.frostwire.android.offers.InHouseBannerFactory.java

public static void loadAd(final ImageView placeholder, AdFormat adFormat) {
    Message randomMessage = Message.random();
    int randomDrawable = getRandomDrawable(adFormat, randomMessage);
    placeholder.setImageDrawable(ContextCompat.getDrawable(placeholder.getContext(), randomDrawable));
    placeholder.setOnClickListener(CLICK_LISTENERS.get(randomMessage));
}

From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java

private static RelativeLayout getTextViewForCode(final Context context, final String text) {
    final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final RelativeLayout codeLayout = (RelativeLayout) inflater.inflate(R.layout.code, null);
    final WebView webView = (WebView) codeLayout.findViewById(R.id.code);
    loadText(webView, text);//from   www . j a va 2  s .c  o  m

    StackXQuickActionMenu quickActionMenu = new StackXQuickActionMenu(context)
            .addEmailQuickActionItem("Code sample from StackX", text).addCopyToClipboardItem(text);
    final QuickActionMenu actionMenu = quickActionMenu.addItem(R.string.fullscreen, new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(context, FullscreenTextActivity.class);
            intent.putExtra(StringConstants.TEXT, text);
            context.startActivity(intent);
        }
    }).build();

    ImageView imageView = (ImageView) codeLayout.findViewById(R.id.codeQuickActionMenu);
    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            actionMenu.show(v);
        }
    });

    return codeLayout;
}

From source file:com.cw.litenote.note.AudioUi_note.java

private static void setAudioBlockListener(final AppCompatActivity act, final String audioStr,
        final ViewPager _pager) {
    SeekBar seekBarProgress = (SeekBar) act.findViewById(R.id.pager_img_audio_seek_bar);
    ImageView mPager_audio_play_button = (ImageView) act.findViewById(R.id.pager_btn_audio_play);

    // set audio play and pause control image
    mPager_audio_play_button.setOnClickListener(new View.OnClickListener() {
        @Override/*from  w  w w  .j  a  v  a 2s  .  c o m*/
        public void onClick(View v) {

            //                // check permission first time, request phone permission
            //                if(Build.VERSION.SDK_INT >= M)//API23
            //                {
            //                    int permissionPhone = ActivityCompat.checkSelfPermission(act, Manifest.permission.READ_PHONE_STATE);
            //                    if(permissionPhone != PackageManager.PERMISSION_GRANTED)
            //                    {
            //                        ActivityCompat.requestPermissions(act,
            //                                new String[]{Manifest.permission.READ_PHONE_STATE},
            //                                Util.PERMISSIONS_REQUEST_PHONE);
            //                    }
            //                    else
            //                        UtilAudio.setPhoneListener(act);
            //                }
            //                else
            //                    UtilAudio.setPhoneListener(act);

            isPausedAtSeekerAnchor = false;

            if ((Audio_manager.isRunnableOn_page) || (BackgroundAudioService.mMediaPlayer == null)) {
                // use this flag to determine new play or not in note
                BackgroundAudioService.mIsPrepared = false;
            }
            playAudioInPager(act, audioStr, _pager);
        }
    });

    // set seek bar listener
    seekBarProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            if (BackgroundAudioService.mMediaPlayer != null) {
                int mPlayAudioPosition = (int) (((float) (mediaFileLength / 100)) * seekBar.getProgress());
                BackgroundAudioService.mMediaPlayer.seekTo(mPlayAudioPosition);
            } else {
                // note audio: slide seek bar anchor from stop to pause
                isPausedAtSeekerAnchor = true;
                mAnchorPosition = (int) (((float) (mediaFileLength / 100)) * seekBar.getProgress());
                playAudioInPager(act, audioStr, _pager);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // audio player is one time mode in pager
            if (Audio_manager.getAudioPlayMode() == Audio_manager.PAGE_PLAY_MODE)
                Audio_manager.stopAudioPlayer();
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                // show progress change
                int currentPos = mediaFileLength * progress / (seekBar.getMax() + 1);
                int curHour = Math.round((float) (currentPos / 1000 / 60 / 60));
                int curMin = Math.round((float) ((currentPos - curHour * 60 * 60 * 1000) / 1000 / 60));
                int curSec = Math
                        .round((float) ((currentPos - curHour * 60 * 60 * 1000 - curMin * 60 * 1000) / 1000));
                String curr_play_time_str = String.format(Locale.ENGLISH, "%2d", curHour) + ":"
                        + String.format(Locale.ENGLISH, "%02d", curMin) + ":"
                        + String.format(Locale.ENGLISH, "%02d", curSec);
                // set current play time
                TextView audio_curr_pos = (TextView) act.findViewById(R.id.pager_audio_current_pos);
                audio_curr_pos.setText(curr_play_time_str);
            }
        }
    });

}

From source file:edu.stanford.mobisocial.dungbeetle.model.DbObject.java

/**
 * @param v the view to bind/*ww w. j  a va2 s .c  om*/
 * @param context standard activity context
 * @param c the cursor source for the object in the db object table.
 * Must include _id in the projection.
 * 
 * @param allowInteractions controls whether the bound view is
 * allowed to intercept touch events and do its own processing.
 */
public static void bindView(View v, final Context context, Cursor cursor, boolean allowInteractions) {
    TextView nameText = (TextView) v.findViewById(R.id.name_text);
    ViewGroup frame = (ViewGroup) v.findViewById(R.id.object_content);
    frame.removeAllViews();

    // make sure we have all the columns we need
    Long objId = cursor.getLong(cursor.getColumnIndexOrThrow(DbObj.COL_ID));
    String[] projection = null;
    String selection = DbObj.COL_ID + " = ?";
    String[] selectionArgs = new String[] { Long.toString(objId) };
    String sortOrder = null;
    Cursor c = context.getContentResolver().query(DbObj.OBJ_URI, projection, selection, selectionArgs,
            sortOrder);
    if (!c.moveToFirst()) {
        Log.w(TAG, "could not find obj " + objId);
        c.close();
        return;
    }
    DbObj obj = App.instance().getMusubi().objForCursor(c);
    if (obj == null) {
        nameText.setText("Failed to access database.");
        Log.e("DbObject", "cursor was null for bindView of DbObject");
        return;
    }
    DbUser sender = obj.getSender();
    Long timestamp = c.getLong(c.getColumnIndexOrThrow(DbObj.COL_TIMESTAMP));
    Long hash = obj.getHash();
    short deleted = c.getShort(c.getColumnIndexOrThrow(DELETED));
    String feedName = obj.getFeedName();
    String type = obj.getType();
    Date date = new Date(timestamp);
    c.close();
    c = null;

    if (sender == null) {
        nameText.setText("Message from unknown contact.");
        return;
    }
    nameText.setText(sender.getName());

    final ImageView icon = (ImageView) v.findViewById(R.id.icon);
    if (sViewProfileAction == null) {
        sViewProfileAction = new OnClickViewProfile((Activity) context);
    }
    icon.setTag(sender.getLocalId());
    if (allowInteractions) {
        icon.setOnClickListener(sViewProfileAction);
        v.setTag(objId);
    }
    icon.setImageBitmap(sender.getPicture());

    if (deleted == 1) {
        v.setBackgroundColor(sDeletedColor);
    } else {
        v.setBackgroundColor(Color.TRANSPARENT);
    }

    TextView timeText = (TextView) v.findViewById(R.id.time_text);
    timeText.setText(RelativeDate.getRelativeDate(date));

    frame.setTag(objId); // TODO: error prone! This is database id
    frame.setTag(R.id.object_entry, cursor.getPosition()); // this is cursor id
    FeedRenderer renderer = DbObjects.getFeedRenderer(type);
    if (renderer != null) {
        renderer.render(context, frame, obj, allowInteractions);
    }

    if (!allowInteractions) {
        v.findViewById(R.id.obj_attachments_icon).setVisibility(View.GONE);
        v.findViewById(R.id.obj_attachments).setVisibility(View.GONE);
    } else {
        if (!MusubiBaseActivity.isDeveloperModeEnabled(context)) {
            v.findViewById(R.id.obj_attachments_icon).setVisibility(View.GONE);
            v.findViewById(R.id.obj_attachments).setVisibility(View.GONE);
        } else {
            ImageView attachmentCountButton = (ImageView) v.findViewById(R.id.obj_attachments_icon);
            TextView attachmentCountText = (TextView) v.findViewById(R.id.obj_attachments);
            attachmentCountButton.setVisibility(View.VISIBLE);

            if (hash == 0) {
                attachmentCountButton.setVisibility(View.GONE);
            } else {
                //int color = DbObject.colorFor(hash);
                boolean selfPost = false;
                DBHelper helper = new DBHelper(context);
                try {
                    Cursor attachments = obj.getSubfeed().query("type=?", new String[] { LikeObj.TYPE });
                    try {
                        attachmentCountText.setText("+" + attachments.getCount());

                        if (attachments.moveToFirst()) {
                            while (!attachments.isAfterLast()) {
                                if (attachments.getInt(attachments.getColumnIndex(CONTACT_ID)) == -666) {
                                    selfPost = true;
                                    break;
                                }
                                attachments.moveToNext();

                            }
                        }
                    } finally {
                        attachments.close();
                    }
                } finally {
                    helper.close();
                }
                if (selfPost) {
                    attachmentCountButton.setImageResource(R.drawable.ic_menu_love_red);
                } else {
                    attachmentCountButton.setImageResource(R.drawable.ic_menu_love);
                }
                attachmentCountText.setTag(R.id.object_entry, hash);
                attachmentCountText.setTag(R.id.feed_label, Feed.uriForName(feedName));
                attachmentCountText.setOnClickListener(LikeListener.getInstance(context));
            }
        }
    }
}

From source file:fi.tuukka.weather.utils.Utils.java

public static void showImage(Activity activity, View view, Bitmap bmp) {
    final Dialog imageDialog = new Dialog(activity);
    imageDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    imageDialog.setContentView(R.layout.showimage);
    imageDialog.setCancelable(true);/*from  w w  w .  j a  va  2 s .  c om*/

    ImageView imageView = (ImageView) imageDialog.findViewById(R.id.imageView);
    // Getting width & height of the given image.
    DisplayMetrics displayMetrics = activity.getResources().getDisplayMetrics();
    int wn = displayMetrics.widthPixels;
    int hn = displayMetrics.heightPixels;
    int wo = bmp.getWidth();
    int ho = bmp.getHeight();
    Matrix mtx = new Matrix();
    // Setting rotate to 90
    mtx.preRotate(90);
    // Setting resize
    mtx.postScale(((float) 1.3 * wn) / ho, ((float) 1.3 * hn) / wo);
    // Rotating Bitmap
    Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, wo, ho, mtx, true);
    BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);

    imageView.setImageDrawable(bmd);

    imageView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View button) {
            imageDialog.dismiss();
        }
    });

    imageDialog.show();
}

From source file:com.tecnojin.timekiller.activity.StatisticsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ActivityUtil.makeFullScreen(this);
    setContentView(R.layout.option_layout);

    pager = new ViewPager(this);
    ((LinearLayout) findViewById(R.id.statisticLayout)).addView(pager);

    int optionIndex = getIntent().getIntExtra(getPackageName() + ".statistics", -1);

    set = GameManager.instance(this).getGame(optionIndex, this).getStatistics();

    if (set == null) {
        Toast.makeText(this, R.string.noOption, Toast.LENGTH_SHORT).show();
        finish();// w w  w  .j a va  2 s  .co  m
    }
    adapter = new StatisticsAdapter(this, android.R.layout.simple_list_item_single_choice, set);
    pager.setAdapter(adapter);

    ImageView back = (ImageView) findViewById(R.id.back);
    back.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            finish();
        }
    });

}

From source file:ng.uavp.ch.ngusbterminal.AboutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.about, container, false);
    ImageView img = (ImageView) view.findViewById(R.id.imageViewNG);
    img.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setData(Uri.parse("http://ng.uavp.ch"));
            startActivity(intent);/* w w w.  jav a 2 s.  c o m*/
        }
    });

    TextView txt1 = (TextView) view.findViewById(R.id.textView1);
    String versionName = "?";
    try {
        versionName = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(),
                0).versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    txt1.setText(getText(R.string.app_name) + " V" + versionName);

    return view;
}

From source file:com.pasta.mensadd.fragments.ImprintFragment.java

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_imprint, container, false);
    setHasOptionsMenu(true);//from w  w  w  .  j  av a  2 s .com
    mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    TextView baconView = v.findViewById(R.id.imprintLicenseBacon);
    if (mPrefs.getBoolean(getString(R.string.pref_bacon_key), false))
        baconView.setVisibility(View.VISIBLE);
    TextView licenseView = v.findViewById(R.id.imprintLicense);

    licenseView.setMovementMethod(LinkMovementMethod.getInstance());
    licenseView.setText(Html.fromHtml(getString(R.string.imprint_license)));
    ImageView banner = v.findViewById(R.id.banner_imprint);
    banner.setOnClickListener(this);
    MainActivity activity = (MainActivity) getActivity();
    if (activity != null)
        activity.updateToolbar(-1, getString(R.string.pref_imprint));
    Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    return v;
}

From source file:com.seindev.sehal.cookbook.fragments.Openscource.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View layout = inflater.inflate(R.layout.fragment_openscource, container, false);

    RecyclerView rhomepage = (RecyclerView) layout.findViewById(R.id.openscource);
    rhomepage.setHasFixedSize(true);/*from  w  ww  .jav  a2 s .c  om*/
    LinearLayoutManager llm = new LinearLayoutManager(getActivity());
    llm.setOrientation(LinearLayoutManager.VERTICAL);
    rhomepage.setLayoutManager(llm);
    OAdapter oAdapter = new OAdapter(getActivity(), createList(7));
    rhomepage.setAdapter(oAdapter);

    TextView appversion = (TextView) layout.findViewById(R.id.appversion);
    appversion.setText("(v" + BuildConfig.VERSION_NAME + ")");
    ImageView close = (ImageView) layout.findViewById(R.id.close);
    close.setOnClickListener(this);

    manager = getFragmentManager();

    return layout;
}