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:de.grobox.liberario.DirectionsFragment.java

private void setToUI() {
    // To text input
    final AutoCompleteTextView to = (AutoCompleteTextView) mView.findViewById(R.id.to);
    final TextView toText = (TextView) mView.findViewById(R.id.toText);

    OnClickListener toListener = new OnClickListener() {
        @Override/*from   www  .j a  v  a 2 s .c  o  m*/
        public void onClick(View view) {
            if (to.getText().length() > 0) {
                to.showDropDown();
            } else {
                handleInputClick(FavLocation.LOC_TYPE.TO);
            }
        }
    };

    to.setOnClickListener(toListener);
    toText.setOnClickListener(toListener);

    // To Location List for Dropdown
    final LocationAdapter locAdapter = new LocationAdapter(getActivity(), FavLocation.LOC_TYPE.TO);
    locAdapter.setFavs(true);
    locAdapter.setHome(true);
    to.setAdapter(locAdapter);
    to.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
            handleLocationItemClick(locAdapter.getItem(position), view, FavLocation.LOC_TYPE.TO);
        }
    });

    // TODO implement something to allow change of homeLocation

    final ImageView toStatusButton = (ImageView) mView.findViewById(R.id.toStatusButton);
    toStatusButton.setImageDrawable(null);
    toStatusButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            handleInputClick(FavLocation.LOC_TYPE.TO);
        }
    });

    // clear from text button
    final ImageButton toClearButton = (ImageButton) mView.findViewById(R.id.toClearButton);
    toClearButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            to.requestFocus();
            clearLocation(FavLocation.LOC_TYPE.TO);
            toClearButton.setVisibility(View.GONE);
        }
    });

    // To text input changed
    to.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // show clear button
            if (s.length() > 0) {
                toClearButton.setVisibility(View.VISIBLE);
                // clear location
                setLocation(null, FavLocation.LOC_TYPE.TO, null, false);
            } else {
                toClearButton.setVisibility(View.GONE);
                clearLocation(FavLocation.LOC_TYPE.TO);
                // clear drop-down list
                locAdapter.resetList();
            }
        }

        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }
    });
}

From source file:com.gh4a.IssueActivity.java

private void fillData() {
    new LoadCommentsTask(this).execute();

    Typeface boldCondensed = getApplicationContext().boldCondensed;

    ListView lvComments = (ListView) findViewById(R.id.list_view);
    // set details inside listview header
    LayoutInflater infalter = getLayoutInflater();
    LinearLayout mHeader = (LinearLayout) infalter.inflate(R.layout.issue_header, lvComments, false);
    mHeader.setClickable(false);/*from ww  w .j av  a  2 s  .c o  m*/

    lvComments.addHeaderView(mHeader, null, false);

    RelativeLayout rlComment = (RelativeLayout) findViewById(R.id.rl_comment);
    if (!isAuthorized()) {
        rlComment.setVisibility(View.GONE);
    }

    TextView tvCommentTitle = (TextView) mHeader.findViewById(R.id.comment_title);
    mCommentAdapter = new CommentAdapter(IssueActivity.this, new ArrayList<Comment>(), mIssue.getNumber(),
            mIssue.getState(), mRepoOwner, mRepoName);
    lvComments.setAdapter(mCommentAdapter);

    ImageView ivGravatar = (ImageView) mHeader.findViewById(R.id.iv_gravatar);
    aq.id(R.id.iv_gravatar).image(GravatarUtils.getGravatarUrl(mIssue.getUser().getGravatarId()), true, false,
            0, 0, aq.getCachedImage(R.drawable.default_avatar), AQuery.FADE_IN);

    ivGravatar.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            getApplicationContext().openUserInfoActivity(IssueActivity.this, mIssue.getUser().getLogin(), null);
        }
    });

    TextView tvExtra = (TextView) mHeader.findViewById(R.id.tv_extra);
    TextView tvState = (TextView) mHeader.findViewById(R.id.tv_state);
    TextView tvTitle = (TextView) mHeader.findViewById(R.id.tv_title);
    TextView tvDescTitle = (TextView) mHeader.findViewById(R.id.desc_title);
    tvDescTitle.setTypeface(getApplicationContext().boldCondensed);
    tvDescTitle.setTextColor(Color.parseColor("#0099cc"));

    tvCommentTitle.setTypeface(getApplicationContext().boldCondensed);
    tvCommentTitle.setTextColor(Color.parseColor("#0099cc"));
    tvCommentTitle
            .setText(getResources().getString(R.string.issue_comments) + " (" + mIssue.getComments() + ")");

    TextView tvDesc = (TextView) mHeader.findViewById(R.id.tv_desc);
    tvDesc.setMovementMethod(LinkMovementMethod.getInstance());

    TextView tvMilestone = (TextView) mHeader.findViewById(R.id.tv_milestone);

    ImageView ivComment = (ImageView) findViewById(R.id.iv_comment);
    if (Gh4Application.THEME == R.style.DefaultTheme) {
        ivComment.setImageResource(R.drawable.social_send_now_dark);
    }
    ivComment.setBackgroundResource(R.drawable.abs__list_selector_holo_dark);
    ivComment.setPadding(5, 2, 5, 2);
    ivComment.setOnClickListener(this);

    tvExtra.setText(mIssue.getUser().getLogin() + "\n" + pt.format(mIssue.getCreatedAt()));
    tvState.setTextColor(Color.WHITE);
    if ("closed".equals(mIssue.getState())) {
        tvState.setBackgroundResource(R.drawable.default_red_box);
        tvState.setText("C\nL\nO\nS\nE\nD");
    } else {
        tvState.setBackgroundResource(R.drawable.default_green_box);
        tvState.setText("O\nP\nE\nN");
    }
    tvTitle.setText(mIssue.getTitle());
    tvTitle.setTypeface(boldCondensed);

    boolean showInfoBox = false;
    if (mIssue.getAssignee() != null) {
        showInfoBox = true;
        TextView tvAssignee = (TextView) mHeader.findViewById(R.id.tv_assignee);
        tvAssignee.setText(mIssue.getAssignee().getLogin() + " is assigned");
        tvAssignee.setVisibility(View.VISIBLE);
        tvAssignee.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                getApplicationContext().openUserInfoActivity(IssueActivity.this,
                        mIssue.getAssignee().getLogin(), null);
            }
        });

        ImageView ivAssignee = (ImageView) mHeader.findViewById(R.id.iv_assignee);

        aq.id(R.id.iv_assignee).image(GravatarUtils.getGravatarUrl(mIssue.getAssignee().getGravatarId()), true,
                false, 0, 0, aq.getCachedImage(R.drawable.default_avatar), AQuery.FADE_IN);

        ivAssignee.setVisibility(View.VISIBLE);
        ivAssignee.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                getApplicationContext().openUserInfoActivity(IssueActivity.this,
                        mIssue.getAssignee().getLogin(), null);
            }
        });
    }

    if (mIssue.getMilestone() != null) {
        showInfoBox = true;
        tvMilestone.setText(
                getResources().getString(R.string.issue_milestone) + ": " + mIssue.getMilestone().getTitle());
    } else {
        tvMilestone.setVisibility(View.GONE);
    }

    String body = mIssue.getBodyHtml();
    if (!StringUtils.isBlank(body)) {
        HttpImageGetter imageGetter = new HttpImageGetter(this);
        body = HtmlUtils.format(body).toString();
        imageGetter.bind(tvDesc, body, mIssue.getNumber());
    }

    LinearLayout llLabels = (LinearLayout) findViewById(R.id.ll_labels);
    List<Label> labels = mIssue.getLabels();

    if (labels != null && !labels.isEmpty()) {
        showInfoBox = true;
        for (Label label : labels) {
            TextView tvLabel = new TextView(this);
            tvLabel.setSingleLine(true);
            tvLabel.setText(label.getName());
            tvLabel.setTextAppearance(this, R.style.default_text_small);
            tvLabel.setBackgroundColor(Color.parseColor("#" + label.getColor()));
            tvLabel.setPadding(5, 2, 5, 2);
            int r = Color.red(Color.parseColor("#" + label.getColor()));
            int g = Color.green(Color.parseColor("#" + label.getColor()));
            int b = Color.blue(Color.parseColor("#" + label.getColor()));
            if (r + g + b < 383) {
                tvLabel.setTextColor(getResources().getColor(android.R.color.primary_text_dark));
            } else {
                tvLabel.setTextColor(getResources().getColor(android.R.color.primary_text_light));
            }
            llLabels.addView(tvLabel);

            View v = new View(this);
            v.setLayoutParams(new LayoutParams(5, LayoutParams.WRAP_CONTENT));
            llLabels.addView(v);
        }
    } else {
        llLabels.setVisibility(View.GONE);
    }

    TextView tvPull = (TextView) mHeader.findViewById(R.id.tv_pull);
    if (mIssue.getPullRequest() != null && mIssue.getPullRequest().getDiffUrl() != null) {
        showInfoBox = true;
        tvPull.setVisibility(View.VISIBLE);
        tvPull.setOnClickListener(this);
    }

    if (!showInfoBox) {
        RelativeLayout rl = (RelativeLayout) mHeader.findViewById(R.id.info_box);
        rl.setVisibility(View.GONE);
    }
}

From source file:com.cube.storm.ui.view.PagerSlidingTabStrip.java

private void addIconTab(final int position, Bitmap bitmap) {
    ImageView tab = new ImageView(getContext());
    tab.setImageBitmap(bitmap);//from w ww. ja v a2s  .c  o  m
    tab.setColorFilter(tabIconTint);
    tab.setScaleType(ScaleType.FIT_CENTER);

    DisplayMetrics dm = getResources().getDisplayMetrics();
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm);

    tab.setPadding(padding + tabPadding, padding, padding + tabPadding, padding);

    tab.setFocusable(true);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(android.view.View v) {
            pager.setCurrentItem(position);
        }
    });

    tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

From source file:de.grobox.liberario.DirectionsFragment.java

private void setFromUI() {
    // From text input
    final AutoCompleteTextView from = (AutoCompleteTextView) mView.findViewById(R.id.from);
    final TextView fromText = (TextView) mView.findViewById(R.id.fromText);

    OnClickListener fromListener = new OnClickListener() {
        @Override/*from   w  w  w . j  a  v a2  s  .  c om*/
        public void onClick(View view) {
            if (from.getText().length() > 0) {
                from.showDropDown();
            } else {
                handleInputClick(FavLocation.LOC_TYPE.FROM);
            }
        }
    };

    from.setOnClickListener(fromListener);
    fromText.setOnClickListener(fromListener);

    // From Location List for Dropdown
    final LocationAdapter locAdapter = new LocationAdapter(getActivity(), FavLocation.LOC_TYPE.FROM);
    locAdapter.setFavs(true);
    locAdapter.setHome(true);
    locAdapter.setGPS(true);
    from.setAdapter(locAdapter);
    from.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
            handleLocationItemClick(locAdapter.getItem(position), view, FavLocation.LOC_TYPE.FROM);
        }
    });

    // TODO itemLongClickListener to change homeLocation

    final ImageView fromStatusButton = (ImageView) mView.findViewById(R.id.fromStatusButton);
    fromStatusButton.setImageDrawable(null);
    fromStatusButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            handleInputClick(FavLocation.LOC_TYPE.FROM);
        }
    });

    // clear from text button
    final ImageButton fromClearButton = (ImageButton) mView.findViewById(R.id.fromClearButton);
    fromClearButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            from.requestFocus();
            clearLocation(FavLocation.LOC_TYPE.FROM);
            fromClearButton.setVisibility(View.GONE);
        }
    });

    // From text input changed
    from.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // show clear button
            if (s.length() > 0) {
                fromClearButton.setVisibility(View.VISIBLE);
                // clear location
                setLocation(null, FavLocation.LOC_TYPE.FROM, null, false);
            } else {
                fromClearButton.setVisibility(View.GONE);
                clearLocation(FavLocation.LOC_TYPE.FROM);
                // clear drop-down list
                locAdapter.resetList();
            }

            cancelGpsButton();
        }

        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }
    });
}

From source file:com.example.linhdq.test.documents.creation.visualisation.LayoutQuestionDialog.java

@NonNull
@Override/*w  ww. ja v  a 2 s . co  m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getContext();
    mLayout = null;
    Pair<String, String> language = PreferencesUtils.getOCRLanguage(context);

    final InstallStatus installStatus = OcrLanguageDataStore.isLanguageInstalled(language.first, context);

    if (!installStatus.isInstalled()) {
        final String defaultLanguage = context.getString(R.string.default_ocr_language);
        final String defaultLanguageDisplay = context.getString(R.string.default_ocr_display_language);
        language = Pair.create(defaultLanguage, defaultLanguageDisplay);
    }
    mLanguage = language.first;

    AlertDialog.Builder builder;

    builder = new AlertDialog.Builder(context);
    builder.setCancelable(false);
    View layout = View.inflate(context, R.layout.dialog_layout_question, null);
    builder.setView(layout);

    final ViewFlipper titleViewFlipper = (ViewFlipper) layout.findViewById(R.id.layout_title);
    final ImageView columnLayout = (ImageView) layout.findViewById(R.id.column_layout);
    final ImageView pageLayout = (ImageView) layout.findViewById(R.id.page_layout);
    final ImageSwitcher fairy = (ImageSwitcher) layout.findViewById(R.id.fairy_layout);
    fairy.setFactory(new ViewSwitcher.ViewFactory() {
        public View makeView() {
            return new ImageView(context);
        }
    });
    fairy.setImageResource(R.drawable.fairy_looks_center);
    fairy.setInAnimation(context, android.R.anim.fade_in);
    fairy.setOutAnimation(context, android.R.anim.fade_out);

    final int color = context.getResources().getColor(R.color.progress_color);

    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.LIGHTEN);

    columnLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mLayout != LayoutKind.COMPLEX) {
                fairy.setImageResource(R.drawable.fairy_looks_left);
                titleViewFlipper.setDisplayedChild(2);
                columnLayout.setColorFilter(colorFilter);
                pageLayout.clearColorFilter();
                mLayout = LayoutKind.COMPLEX;
            }

        }
    });
    pageLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mLayout != LayoutKind.SIMPLE) {
                mLayout = LayoutKind.SIMPLE;
                titleViewFlipper.setDisplayedChild(1);
                fairy.setImageResource(R.drawable.fairy_looks_right);
                pageLayout.setColorFilter(colorFilter);
                columnLayout.clearColorFilter();
            }
        }
    });

    final Spinner langButton = (Spinner) layout.findViewById(R.id.button_language);
    List<OcrLanguage> installedLanguages = OcrLanguageDataStore.getInstalledOCRLanguages(context);

    // actual values uses by tesseract
    final ArrayAdapter<OcrLanguage> adapter = new ArrayAdapter<>(context, R.layout.item_spinner_language,
            installedLanguages);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    langButton.setAdapter(adapter);
    for (int i = 0; i < installedLanguages.size(); i++) {
        OcrLanguage lang = installedLanguages.get(i);
        if (lang.getValue().equals(language.first)) {
            langButton.setSelection(i, false);
            break;
        }
    }
    langButton.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            final OcrLanguage item = adapter.getItem(position);
            mLanguage = item.getValue();
            PreferencesUtils.saveOCRLanguage(context, item);
        }

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

        }
    });

    builder.setPositiveButton(R.string.start_scan, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            if (mLayout == null) {
                mLayout = LayoutKind.SIMPLE;
            }
            LayoutChoseListener listener = (LayoutChoseListener) getActivity();
            listener.onLayoutChosen(mLayout, mLanguage);
            dialog.dismiss();
        }
    });

    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            getActivity().finish();
            dialog.dismiss();
        }
    });

    return builder.create();

}

From source file:com.brodev.socialapp.view.MarketPlaceDetail.java

private void initView() {

    ImageView userImage = (ImageView) this.findViewById(R.id.image_user);

    if (!"".equals(marketPlace.getUser_image_path())) {
        networkUntil.drawImageUrl(userImage, marketPlace.getUser_image_path(), R.drawable.loading);
    }//from w ww  . java2  s  . c  o  m

    userImage.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Intent intent = new Intent(MarketPlaceDetail.this, FriendTabsPager.class);
            intent.putExtra("user_id", marketPlace.getUser_id());
            startActivity(intent);
            return false;
        }
    });

    // set title
    TextView title = (TextView) this.findViewById(R.id.title);
    title.setText(marketPlace.getTitle());
    colorView.changeColorText(title, user.getColor());

    // set content
    TextView content = (TextView) this.findViewById(R.id.content);

    // interesting part starts from here here:
    Html.ImageGetter ig = imageGetter.create(0, marketPlace.getText(), content);

    content.setTag(0);
    content.setText(Html.fromHtml(marketPlace.getText(), ig, null));

    TextView timestampTxt = (TextView) findViewById(R.id.txtTimestamp);
    timestampTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.posted_on"));
    TextView timestamp = (TextView) findViewById(R.id.time_stamp);
    timestamp.setText(marketPlace.getTime_stamp());
    TextView price = (TextView) this.findViewById(R.id.price);

    if (marketPlace.getPrice() == 0) {
        price.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.free"));
    } else {
        price.setText(marketPlace.getCurrency() + " " + marketPlace.getPrice());
    }

    TextView locationTxt = (TextView) findViewById(R.id.txtLocation);
    locationTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.location"));
    TextView txtLocation = (TextView) this.findViewById(R.id.location);
    String location = marketPlace.getCountry_name();

    if (!marketPlace.getCountry_child_name().equals("")) {
        location += " > " + marketPlace.getCountry_child_name();
    }
    if (!marketPlace.getCity_name().equals("")) {
        location += " > " + marketPlace.getCity_name();
    }

    txtLocation.setText(location);
    // set short text
    TextView fullnameTxt = (TextView) findViewById(R.id.txtFullname);
    fullnameTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.posted_by"));

    TextView shortText = (TextView) findViewById(R.id.fullName);
    shortText.setText(marketPlace.getFull_name());
    colorView.changeColorText(shortText, user.getColor());

    shortText.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Intent intent = new Intent(MarketPlaceDetail.this, FriendTabsPager.class);
            intent.putExtra("user_id", marketPlace.getUser_id());
            startActivity(intent);
            return false;
        }
    });

    TextView total_like = (TextView) findViewById(R.id.total_like);
    total_like.setText(String.valueOf(marketPlace.getTotal_like()));
    colorView.changeColorText(total_like, user.getColor());

    TextView total_comment = (TextView) findViewById(R.id.total_comment);
    total_comment.setText(String.valueOf(marketPlace.getTotal_comment()));
    colorView.changeColorText(total_comment, user.getColor());

    ImageView likeImg = (ImageView) this.findViewById(R.id.likes_feed_txt);
    ImageView commentImg = (ImageView) this.findViewById(R.id.comments_feed_txt);
    colorView.changeColorLikeCommnent(likeImg, commentImg, user.getColor());

    //get list images
    if (!marketPlace.getImages().equals("")) {
        LinearLayout listImages = (LinearLayout) findViewById(R.id.listImages);
        JSONObject objOutputImage = null;
        try {
            JSONArray objImages = new JSONArray(marketPlace.getImages());
            for (int i = 0; i < objImages.length(); i++) {
                objOutputImage = objImages.getJSONObject(i);
                ImageView imageView = new ImageView(getApplicationContext());

                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                        (int) getResources().getDimension(R.dimen.marketplace_image),
                        (int) getResources().getDimension(R.dimen.marketplace_image));

                lp.setMargins(5, 5, 5, 0);

                imageView.setLayoutParams(lp);

                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                final String imagePath = objOutputImage.getString("image_path");
                networkUntil.drawImageUrl(imageView, imagePath, R.drawable.loading);

                imageView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getApplicationContext(), ImageActivity.class);
                        intent.putExtra("image", imagePath);
                        intent.putExtra("title", marketPlace.getTitle());
                        startActivity(intent);
                    }
                });

                listImages.addView(imageView);

            }

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        this.findViewById(R.id.horizontalScrollView1).setVisibility(View.GONE);
        this.findViewById(R.id.marketplace_list_image_view).setVisibility(View.GONE);
    }

}

From source file:de.blinkt.openvpn.ActivityServerList.java

private void makeAvaiableServer() {
    linearAvailableServers.removeAllViews();

    for (int i = 0; i < mServerList.size(); i++) {
        final String server = mServerList.get(i);

        View viewItem = LayoutInflater.from(this).inflate(R.layout.itemserver, linearSelectedServer, false);
        ImageView imgViewFlag = (ImageView) viewItem.findViewById(R.id.imgViewFlag);
        TextView txtCountry = (TextView) viewItem.findViewById(R.id.txtViewCountryName);
        final ImageView imgFavorite = (ImageView) viewItem.findViewById(R.id.imgFavorite);

        if (!spGlobal.getBoolean(server, false)) {
            imgFavorite.setImageResource(
                    getResources().getIdentifier("drawable/icon_unfavorite", null, getPackageName()));
            imgFavorite.setOnClickListener(new View.OnClickListener() {
                @Override//from w  ww.j  a  va  2 s .c om
                public void onClick(View v) {
                    edGlobal.putBoolean(server, true);
                    edGlobal.commit();
                    imgFavorite.setImageResource(
                            getResources().getIdentifier("drawable/icon_favorite", null, getPackageName()));
                    makeFavoriteServer();
                }
            });
        } else {
            imgFavorite.setImageResource(
                    getResources().getIdentifier("drawable/icon_favorite", null, getPackageName()));
            imgFavorite.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    edGlobal.putBoolean(server, false);
                    edGlobal.commit();
                    imgFavorite.setImageResource(
                            getResources().getIdentifier("drawable/icon_unfavorite", null, getPackageName()));
                    makeFavoriteServer();
                }
            });
        }
        imgViewFlag.setVisibility(View.GONE);
        for (int j = 0; j < countryList.length; j++) {
            String country = countryList[j];
            if (server.toLowerCase().contains(country.toLowerCase())) {
                String resourceName = country.toLowerCase().replace(" ", "_");

                int checkExistence = getResources().getIdentifier(resourceName, "drawable", getPackageName());
                if (checkExistence != 0) { // the resouce exists...
                    imgViewFlag.setVisibility(View.VISIBLE);
                    imgViewFlag.setImageResource(
                            getResources().getIdentifier("drawable/" + resourceName, null, getPackageName()));
                }
                break;
            }
        }
        txtCountry.setText(server);

        txtCountry.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if ((ActivityDashboard.m_status == ActivityDashboard.Status.Connected)
                        || (ActivityDashboard.m_status == ActivityDashboard.Status.Connecting)) {
                    if (ActivityDashboard.lolstring.equals(server)) {

                    } else {
                        DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                switch (which) {
                                case DialogInterface.BUTTON_POSITIVE:
                                    dialog.dismiss();
                                    ActivityDashboard.lolstring = server;

                                    if (VpnStatus.isVPNActive()) {

                                        if (ActivityDashboard.mService != null) {
                                            try {
                                                ActivityDashboard.mService.stopVPN(false);
                                            } catch (RemoteException e) {
                                                VpnStatus.logException(e);
                                            }
                                        }
                                    }
                                    ActivityDashboard.DISCONNECT_VPN_SERVERLIST = 1;
                                    finish();
                                    break;

                                case DialogInterface.BUTTON_NEGATIVE:
                                    dialog.dismiss();
                                    break;
                                }
                            }
                        };

                        AlertDialog.Builder builder = new AlertDialog.Builder(ActivityServerList.this);
                        if ((ActivityDashboard.m_status == ActivityDashboard.Status.Connecting)) {
                            builder.setMessage(
                                    "Currently connecting to another VPN server. Are you sure you want to change the server?")
                                    .setPositiveButton("Yes", dialogClickListener)
                                    .setNegativeButton("No", dialogClickListener).show();
                        } else {
                            builder.setMessage(
                                    "Currently connected to another VPN server. Are you sure you want to change the server?")
                                    .setPositiveButton("Yes", dialogClickListener)
                                    .setNegativeButton("No", dialogClickListener).show();
                        }
                    }
                } else {
                    ActivityDashboard.lolstring = server;
                    finish();
                }
                /*if(VpnStatus.isVPNActive() && ActivityDashboard.m_status.equals(Status.Connected) ) {
                DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        switch (which){
                            case DialogInterface.BUTTON_POSITIVE:
                                dialog.dismiss();
                                ActivityDashboard.lolstring = server;
                                finish();
                                break;
                        
                            case DialogInterface.BUTTON_NEGATIVE:
                                dialog.dismiss();
                                break;
                        }
                    }
                };
                        
                AlertDialog.Builder builder = new AlertDialog.Builder(ActivityServerList.this);
                builder.setMessage("Currently connected to another VPN server. Are you sure you want to change the server?").setPositiveButton("Yes", dialogClickListener)
                        .setNegativeButton("No", dialogClickListener).show();
                }else{
                ActivityDashboard.lolstring = server;
                finish();
                }*/
            }
        });
        linearAvailableServers.addView(viewItem);

    }
}

From source file:com.renard.ocr.documents.creation.visualisation.LayoutQuestionDialog.java

@NonNull
@Override//from w  w w  . j a  v a 2  s.c  om
public Dialog onCreateDialog(Bundle savedInstanceState) {
    getAnalytics().sendScreenView(SCREEN_NAME);
    final Context context = getContext();
    mLayout = null;
    Pair<String, String> language = PreferencesUtils.getOCRLanguage(context);

    final OcrLanguage.InstallStatus installStatus = OcrLanguageDataStore.isLanguageInstalled(language.first,
            context);

    if (!installStatus.isInstalled()) {
        final String defaultLanguage = context.getString(R.string.default_ocr_language);
        final String defaultLanguageDisplay = context.getString(R.string.default_ocr_display_language);
        language = Pair.create(defaultLanguage, defaultLanguageDisplay);
    }
    mLanguage = language.first;

    AlertDialog.Builder builder;

    builder = new AlertDialog.Builder(context);
    builder.setCancelable(false);
    View layout = View.inflate(context, R.layout.dialog_layout_question, null);
    builder.setView(layout);

    final ViewFlipper titleViewFlipper = (ViewFlipper) layout.findViewById(R.id.layout_title);
    final ImageView columnLayout = (ImageView) layout.findViewById(R.id.column_layout);
    final ImageView pageLayout = (ImageView) layout.findViewById(R.id.page_layout);
    final ImageSwitcher fairy = (ImageSwitcher) layout.findViewById(R.id.fairy_layout);
    fairy.setFactory(new ViewSwitcher.ViewFactory() {
        public View makeView() {
            return new ImageView(context);
        }
    });
    fairy.setImageResource(R.drawable.fairy_looks_center);
    fairy.setInAnimation(context, android.R.anim.fade_in);
    fairy.setOutAnimation(context, android.R.anim.fade_out);

    final int color = context.getResources().getColor(R.color.progress_color);

    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.LIGHTEN);

    columnLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mLayout != LayoutKind.COMPLEX) {
                fairy.setImageResource(R.drawable.fairy_looks_left);
                titleViewFlipper.setDisplayedChild(2);
                columnLayout.setColorFilter(colorFilter);
                pageLayout.clearColorFilter();
                mLayout = LayoutKind.COMPLEX;
            }

        }
    });
    pageLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mLayout != LayoutKind.SIMPLE) {
                mLayout = LayoutKind.SIMPLE;
                titleViewFlipper.setDisplayedChild(1);
                fairy.setImageResource(R.drawable.fairy_looks_right);
                pageLayout.setColorFilter(colorFilter);
                columnLayout.clearColorFilter();
            }
        }
    });

    final Spinner langButton = (Spinner) layout.findViewById(R.id.button_language);
    List<OcrLanguage> installedLanguages = OcrLanguageDataStore.getInstalledOCRLanguages(context);

    // actual values uses by tesseract
    final ArrayAdapter<OcrLanguage> adapter = new ArrayAdapter<>(context, R.layout.language_spinner_item,
            installedLanguages);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    langButton.setAdapter(adapter);
    for (int i = 0; i < installedLanguages.size(); i++) {
        OcrLanguage lang = installedLanguages.get(i);
        if (lang.getValue().equals(language.first)) {
            langButton.setSelection(i, false);
            break;
        }
    }
    langButton.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            final OcrLanguage item = adapter.getItem(position);
            mLanguage = item.getValue();
            PreferencesUtils.saveOCRLanguage(context, item);
            getAnalytics().sendOcrLanguageChanged(item);
        }

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

        }
    });

    builder.setPositiveButton(R.string.start_scan, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            if (mLayout == null) {
                mLayout = LayoutKind.SIMPLE;
            }
            LayoutChoseListener listener = (LayoutChoseListener) getActivity();
            listener.onLayoutChosen(mLayout, mLanguage);
            getAnalytics().sendOcrStarted(mLanguage, mLayout);
            dialog.dismiss();
        }
    });

    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            getActivity().finish();
            dialog.dismiss();
            getAnalytics().sendLayoutDialogCancelled();
        }
    });

    return builder.create();

}

From source file:com.forum.fiend.osp.SettingsFragment.java

private void setupUserCard() {

    if (getActivity() == null) {
        return;/* w w  w.j av a 2 s .  c om*/
    }

    LinearLayout userLayout = (LinearLayout) getActivity().findViewById(R.id.settings_user_box);

    if (application.getSession().getServer().serverUserId.contentEquals("0")) {
        userLayout.setVisibility(View.GONE);
    } else {
        ImageView ivAvatar = (ImageView) getActivity().findViewById(R.id.settings_user_avatar);
        TextView tvUsername = (TextView) getActivity().findViewById(R.id.settings_user_name);
        ImageView ivLogout = (ImageView) getActivity().findViewById(R.id.settings_user_logout);

        tvUsername.setText(application.getSession().getServer().serverUserName);

        if (application.getSession().getServer().serverAvatar.contains("http")) {
            ImageLoader.getInstance().displayImage(application.getSession().getServer().serverAvatar, ivAvatar);
        } else {
            ivAvatar.setImageResource(R.drawable.no_avatar);
        }

        ivLogout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                logOut();
            }
        });

        userLayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                loadMyWall();
            }
        });
    }
}

From source file:com.android.mail.photo.MailPhotoViewController.java

/**
 * Updates the empty views of the fragment based upon the current
 * state of the attachment.//from ww w.ja va  2 s.c  om
 * @param fragment the current fragment
 */
private void updateProgressAndEmptyViews(final PhotoViewFragment fragment, final Attachment attachment) {
    final ProgressBarWrapper progressBar = fragment.getPhotoProgressBar();
    final TextView emptyText = fragment.getEmptyText();
    final ImageView retryButton = fragment.getRetryButton();

    // update the progress
    if (attachment.shouldShowProgress()) {
        progressBar.setMax(attachment.size);
        progressBar.setProgress(attachment.downloadedSize);
        progressBar.setIndeterminate(false);
    } else if (fragment.isProgressBarNeeded()) {
        progressBar.setIndeterminate(true);
    }

    // If the download failed, show the empty text and retry button
    if (attachment.isDownloadFailed()) {
        emptyText.setText(R.string.photo_load_failed);
        emptyText.setVisibility(View.VISIBLE);
        retryButton.setVisibility(View.VISIBLE);
        retryButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                redownloadAttachment();
                emptyText.setVisibility(View.GONE);
                retryButton.setVisibility(View.GONE);
            }
        });
        progressBar.setVisibility(View.GONE);
    }
}