Example usage for android.widget TextView setOnClickListener

List of usage examples for android.widget TextView setOnClickListener

Introduction

In this page you can find the example usage for android.widget TextView 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:com.hippo.ehviewer.ui.scene.GalleryDetailScene.java

@SuppressWarnings("deprecation")
private void bindTags(GalleryTagGroup[] tagGroups) {
    Context context = getContext2();
    LayoutInflater inflater = getLayoutInflater2();
    Resources resources = getResources2();
    if (null == context || null == inflater || null == resources || null == mTags || null == mNoTags) {
        return;/*from ww w  .j a  v a  2 s .  co m*/
    }

    mTags.removeViews(1, mTags.getChildCount() - 1);
    if (tagGroups == null || tagGroups.length == 0) {
        mNoTags.setVisibility(View.VISIBLE);
        return;
    } else {
        mNoTags.setVisibility(View.GONE);
    }

    int colorTag = resources.getColor(R.color.colorPrimary);
    int colorName = resources.getColor(R.color.purple_a400);
    for (GalleryTagGroup tg : tagGroups) {
        LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.gallery_tag_group, mTags, false);
        ll.setOrientation(LinearLayout.HORIZONTAL);
        mTags.addView(ll);

        TextView tgName = (TextView) inflater.inflate(R.layout.item_gallery_tag, ll, false);
        ll.addView(tgName);
        tgName.setText(tg.groupName);
        tgName.setBackgroundDrawable(new RoundSideRectDrawable(colorName));

        AutoWrapLayout awl = new AutoWrapLayout(context);
        ll.addView(awl, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        for (int j = 0, z = tg.size(); j < z; j++) {
            TextView tag = (TextView) inflater.inflate(R.layout.item_gallery_tag, awl, false);
            awl.addView(tag);
            String tagStr = tg.getTagAt(j);
            tag.setText(tagStr);
            tag.setBackgroundDrawable(new RoundSideRectDrawable(colorTag));
            tag.setTag(R.id.tag, tg.groupName + ":" + tagStr);
            tag.setOnClickListener(this);
            tag.setOnLongClickListener(this);
        }
    }
}

From source file:com.Beat.RingdroidEditActivity.java

/**
 * Called from both onCreate and onConfigurationChanged
 * (if the user switched layouts)/*from  w ww  .ja va 2  s. c o  m*/
 */
private void loadGui() {
    // Inflate our UI from its XML layout description.
    setContentView(R.layout.editor);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    mDensity = metrics.density;

    mMarkerLeftInset = (int) (46 * mDensity);
    mMarkerRightInset = (int) (48 * mDensity);
    mMarkerTopOffset = (int) (10 * mDensity);
    mMarkerBottomOffset = (int) (10 * mDensity);

    mStartText = (TextView) findViewById(R.id.starttext);
    mStartText.addTextChangedListener(mTextWatcher);
    mEndText = (TextView) findViewById(R.id.endtext);
    mEndText.addTextChangedListener(mTextWatcher);

    mPlayButton = (ImageButton) findViewById(R.id.play);
    mPlayButton.setOnClickListener(mPlayListener);
    mRewindButton = (ImageButton) findViewById(R.id.rew);
    mRewindButton.setOnClickListener(mRewindListener);
    mFfwdButton = (ImageButton) findViewById(R.id.ffwd);
    mFfwdButton.setOnClickListener(mFfwdListener);
    mZoomInButton = (ImageButton) findViewById(R.id.zoom_in);
    mZoomInButton.setOnClickListener(mZoomInListener);
    mZoomOutButton = (ImageButton) findViewById(R.id.zoom_out);
    mZoomOutButton.setOnClickListener(mZoomOutListener);
    mSaveButton = (ImageButton) findViewById(R.id.save);
    mSaveButton.setOnClickListener(mSaveListener);

    TextView markStartButton = (TextView) findViewById(R.id.mark_start);
    markStartButton.setOnClickListener(mMarkStartListener);
    TextView markEndButton = (TextView) findViewById(R.id.mark_end);
    markEndButton.setOnClickListener(mMarkStartListener);

    enableDisableButtons();

    mWaveformView = (WaveformView) findViewById(R.id.waveform);
    mWaveformView.setListener(this);

    mInfo = (TextView) findViewById(R.id.info);
    mInfo.setText(mCaption);

    mMaxPos = 0;
    mLastDisplayedStartPos = -1;
    mLastDisplayedEndPos = -1;

    if (mSoundFile != null) {
        mWaveformView.setSoundFile(mSoundFile);
        mWaveformView.recomputeHeights(mDensity);
        mMaxPos = mWaveformView.maxPos();
    }

    mStartMarker = (MarkerView) findViewById(R.id.startmarker);
    mStartMarker.setListener(this);
    mStartMarker.setAlpha(255);
    mStartMarker.setFocusable(true);
    mStartMarker.setFocusableInTouchMode(true);
    mStartVisible = true;

    mEndMarker = (MarkerView) findViewById(R.id.endmarker);
    mEndMarker.setListener(this);
    mEndMarker.setAlpha(255);
    mEndMarker.setFocusable(true);
    mEndMarker.setFocusableInTouchMode(true);
    mEndVisible = true;

    final AlertDialog.Builder nomp3 = new AlertDialog.Builder(this);
    nomp3.setCancelable(true);
    nomp3.setMessage("Filters Only work on wav files at this time");
    nomp3.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            return;
        }
    });

    Button echo = (Button) findViewById(R.id.echobutton);
    echo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View clickedButton) {
            if (mExtension.compareToIgnoreCase(".wav") == 0) {
                audioCode.echo(mFilename,
                        mFilename.substring(0, mFilename.lastIndexOf('.')) + "_echo" + mExtension, 200, .6,
                        false);
                reset(mFilename.substring(0, mFilename.lastIndexOf('.')) + "_echo" + mExtension);
            } else
                nomp3.show();
        }
    });
    Button high = (Button) findViewById(R.id.highbutton);
    high.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View clickedButton) {
            if (mExtension.compareToIgnoreCase(".wav") == 0) {
                audioCode.filter(mFilename,
                        mFilename.substring(0, mFilename.lastIndexOf('.')) + "_high" + mExtension, true, 2000);
                reset(mFilename.substring(0, mFilename.lastIndexOf('.')) + "_high" + mExtension);
            } else
                nomp3.show();
        }
    });
    Button low = (Button) findViewById(R.id.Lowbutton);
    low.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View clickedButton) {
            if (mExtension.compareToIgnoreCase(".wav") == 0) {
                audioCode.filter(mFilename,
                        mFilename.substring(0, mFilename.lastIndexOf('.')) + "_low" + mExtension, false, 2000);
                reset(mFilename.substring(0, mFilename.lastIndexOf('.')) + "_low" + mExtension);
            } else
                nomp3.show();
        }
    });
    Button speedup = (Button) findViewById(R.id.up);
    speedup.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View clickedButton) {
            if (mExtension.compareToIgnoreCase(".wav") == 0) {
                audioCode.decreaseTimescaleIncreasePitch(mFilename,
                        mFilename.substring(0, mFilename.lastIndexOf('.')) + "_sup" + mExtension, 2);
                reset(mFilename.substring(0, mFilename.lastIndexOf('.')) + "_sup" + mExtension);
            } else
                nomp3.show();
        }
    });
    Button speeddown = (Button) findViewById(R.id.down);
    speeddown.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View clickedButton) {
            if (mExtension.compareToIgnoreCase(".wav") == 0) {
                audioCode.increaseTimescaleDecreasePitch(mFilename,
                        mFilename.substring(0, mFilename.lastIndexOf('.')) + "_sdown" + mExtension, 2);
                reset(mFilename.substring(0, mFilename.lastIndexOf('.')) + "_sdown" + mExtension);
            } else
                nomp3.show();
        }
    });
    Button record = (Button) findViewById(R.id.record);
    record.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View clickedButton) {
            Intent i = new Intent();
            i.setClassName("com.Beat", "com.Beat.recordScreen");
            startActivity(i);
            exit();
        }
    });

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    updateDisplay();
}

From source file:fr.eoit.activity.fragment.iteminfo.PricesDialog.java

@Override
public void onLoadFinished(Cursor cursor) {

    if (DbUtil.hasAtLeastOneRow(cursor)) {

        if (chosenPriceId == Integer.MIN_VALUE)
            chosenPriceId = cursor.getInt(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_CHOSEN_PRICE_ID));
        int categoryId = cursor.getInt(cursor.getColumnIndexOrThrow(Groups.COLUMN_NAME_CATEGORIE_ID));

        double buyPrice = PricesUtils.getPriceOrNaN(cursor, Prices.COLUMN_NAME_BUY_PRICE);
        double sellPrice = PricesUtils.getPriceOrNaN(cursor, Prices.COLUMN_NAME_SELL_PRICE);
        producePrice = PricesUtils.getPriceOrNaN(cursor, Prices.COLUMN_NAME_PRODUCE_PRICE);
        if (Double.isNaN(fixedPrice)) {
            fixedPrice = PricesUtils.getPriceOrNaN(cursor, Prices.COLUMN_NAME_OWN_PRICE);
            if (Double.isNaN(fixedPrice)) {
                fixedPrice = 0;//from  ww w  .j a  v  a  2s. com
            }
        }

        TextView bTv = ((TextView) inflatedLayout.findViewById(R.id.buy_price));
        TextView sTv = ((TextView) inflatedLayout.findViewById(R.id.sell_price));
        TextView pTv = ((TextView) inflatedLayout.findViewById(R.id.produce_price));
        EditText fTv = ((EditText) inflatedLayout.findViewById(R.id.fixed_price));
        TextView prTv = ((TextView) inflatedLayout.findViewById(R.id.profit_sell_produce));

        prTv.setVisibility(View.VISIBLE);

        PricesUtils.setPriceWithDefault(bTv, buyPrice, false, DEFAULT_UNKNOWN_PRICE);
        PricesUtils.setPriceWithDefault(sTv, sellPrice, false, DEFAULT_UNKNOWN_PRICE);
        PricesUtils.setPriceWithDefault(pTv, producePrice, false, DEFAULT_UNKNOWN_PRICE);
        NumberFormat nf = new DecimalFormat(EOITConst.VALUES_PATTERN);
        fTv.setText(nf.format(fixedPrice));

        double sellProduceProfit = 0;
        if (categoryId == EOITConst.Categories.ASTEROID_CATEGORIE_ID && buyPrice > 0 && producePrice > 0
                && !Double.isNaN(producePrice)) {
            sellProduceProfit = (buyPrice - producePrice) / producePrice;
        } else if (sellPrice > 0 && producePrice > 0 && !Double.isNaN(producePrice)) {
            sellProduceProfit = (sellPrice - producePrice) / producePrice;
        } else {
            changeSellProduceProfitVisibility(View.GONE);
        }
        prTv.setText(nfPercent.format(sellProduceProfit));

        if (fixedPrice > 0 && producePrice > 0 && !Double.isNaN(producePrice)) {
            updateFixedProduceProfit();
        } else {
            changeFixedProduceProfitVisibility(View.GONE);
        }

        if (producePrice < 0.01) {
            pTv.setText(DEFAULT_UNKNOWN_PRICE);
        }

        positionPriceIndicator();
        bTv.setOnClickListener(new PriceIndicatorOnClickListener(EOITConst.BUY_PRICE_ID));
        sTv.setOnClickListener(new PriceIndicatorOnClickListener(EOITConst.SELL_PRICE_ID));
        pTv.setOnClickListener(new PriceIndicatorOnClickListener(EOITConst.PRODUCE_PRICE_ID));
        fTv.setOnClickListener(new PriceIndicatorOnClickListener(EOITConst.OWN_PRICE_ID));
        fTv.setOnKeyListener(new FixedPriceOnKeyListener());
    }
}

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

private void setRobotMenuMessageLayout(LinearLayout parentView, JSONArray jsonArr) {
    try {/*from  w w  w  . ja  va2  s  .c o m*/
        parentView.removeAllViews();
        for (int i = 0; i < jsonArr.length(); i++) {
            final String itemStr = jsonArr.getString(i);
            final TextView textView = new TextView(context);
            textView.setText(itemStr);
            textView.setTextSize(15);
            try {
                XmlPullParser xrp = context.getResources().getXml(R.drawable.menu_msg_text_color);
                textView.setTextColor(ColorStateList.createFromXml(context.getResources(), xrp));
            } catch (Exception e) {
                e.printStackTrace();
            }
            textView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    ((ChatMessage) context).sendText(itemStr);
                }
            });
            LinearLayout.LayoutParams llLp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            llLp.bottomMargin = DensityUtil.dip2px(context, 3);
            llLp.topMargin = DensityUtil.dip2px(context, 3);
            parentView.addView(textView, llLp);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

}

From source file:es.usc.citius.servando.calendula.fragments.ScheduleImportFragment.java

private void setupScheduleEntrySpinners(final View entryView, ScheduleItem scheduleItem,
        String[] routineNames) {// w  w  w .j  ava2s  .c  o m

    final Spinner routineSpinner = (Spinner) entryView.findViewById(R.id.entry_routine_spinner);
    final TextView doseTv = (TextView) entryView.findViewById(R.id.entry_dose_textview);
    //        final Spinner doseSpinner = (Spinner) entryView.findViewById(R.id.entry_dose_spinner);

    doseTv.setTag(scheduleItem);
    routineSpinner.setTag(scheduleItem);

    // set up the routine selection adapter
    updateRoutineSelectionAdapter(entryView, routineSpinner, routineNames);

    if (scheduleItem != null && scheduleItem.routine() != null) {
        String routineName = scheduleItem.routine().name();
        int index = Arrays.asList(routineNames).indexOf(routineName);
        routineSpinner.setSelection(index);
    } else {
        routineSpinner.setSelection(routineNames.length - 1);
    }

    doseTv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDosePickerDialog((ScheduleItem) v.getTag(), (TextView) v);
        }
    });

    doseTv.setText(scheduleItem.displayDose());

    // setup listeners
    routineSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            String selected = (String) adapterView.getItemAtPosition(i);
            Routine r = Routine.findByName(selected);
            ScheduleItem item = ((ScheduleItem) routineSpinner.getTag());

            if (r != null) {
                updateEntryTime(r, entryView);
            } else {
                updateEntryTime(null, entryView);
                showAddNewRoutineDialog(entryView);
            }
            Log.d(TAG, "Updated routine to " + (r != null ? r.name() : "NULL") + " on item " + item.getId());
            item.setRoutine(r);

            logScheduleItems();
        }

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

    routineSpinner.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_UP) {

                if (((String) routineSpinner.getSelectedItem())
                        .equalsIgnoreCase(getString(R.string.create_new_routine))) {
                    showAddNewRoutineDialog(entryView);
                    return true;
                }
            }
            return false;
        }
    });
}

From source file:github.daneren2005.dsub.fragments.SelectDirectoryFragment.java

private void setupTextDisplay(final View header) {
    final TextView titleView = (TextView) header.findViewById(R.id.select_album_title);
    if (playlistName != null) {
        titleView.setText(playlistName);
    } else if (podcastName != null) {
        titleView.setText(podcastName);/*from www  . ja v a  2  s . c  o m*/
        titleView.setPadding(0, 6, 4, 8);
    } else if (name != null) {
        titleView.setText(name);

        if (artistInfo != null) {
            titleView.setPadding(0, 6, 4, 8);
        }
    } else if (share != null) {
        titleView.setVisibility(View.GONE);
    }

    int songCount = 0;

    Set<String> artists = new HashSet<String>();
    Set<Integer> years = new HashSet<Integer>();
    Integer totalDuration = 0;
    for (Entry entry : entries) {
        if (!entry.isDirectory()) {
            songCount++;
            if (entry.getArtist() != null) {
                artists.add(entry.getArtist());
            }
            if (entry.getYear() != null) {
                years.add(entry.getYear());
            }
            Integer duration = entry.getDuration();
            if (duration != null) {
                totalDuration += duration;
            }
        }
    }

    final TextView artistView = (TextView) header.findViewById(R.id.select_album_artist);
    if (podcastDescription != null || artistInfo != null) {
        artistView.setVisibility(View.VISIBLE);
        String text = podcastDescription != null ? podcastDescription : artistInfo.getBiography();
        Spanned spanned = null;
        if (text != null) {
            spanned = Html.fromHtml(text);
        }
        artistView.setText(spanned);
        artistView.setSingleLine(false);
        final int minLines = context.getResources().getInteger(R.integer.TextDescriptionLength);
        artistView.setLines(minLines);
        artistView.setTextAppearance(context, android.R.style.TextAppearance_Small);

        final Spanned spannedText = spanned;
        artistView.setOnClickListener(new View.OnClickListener() {
            @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
            @Override
            public void onClick(View v) {
                if (artistView.getMaxLines() == minLines) {
                    // Use LeadingMarginSpan2 to try to make text flow around image
                    Display display = context.getWindowManager().getDefaultDisplay();
                    ImageView coverArtView = (ImageView) header.findViewById(R.id.select_album_art);
                    coverArtView.measure(display.getWidth(), display.getHeight());

                    int height, width;
                    ViewGroup.MarginLayoutParams vlp = (ViewGroup.MarginLayoutParams) coverArtView
                            .getLayoutParams();
                    if (coverArtView.getDrawable() != null) {
                        height = coverArtView.getMeasuredHeight() + coverArtView.getPaddingBottom();
                        width = coverArtView.getWidth() + coverArtView.getPaddingRight();
                    } else {
                        height = coverArtView.getHeight();
                        width = coverArtView.getWidth() + coverArtView.getPaddingRight();
                    }
                    float textLineHeight = artistView.getPaint().getTextSize();
                    int lines = (int) Math.ceil(height / textLineHeight);

                    SpannableString ss = new SpannableString(spannedText);
                    ss.setSpan(new MyLeadingMarginSpan2(lines, width), 0, ss.length(),
                            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

                    View linearLayout = header.findViewById(R.id.select_album_text_layout);
                    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) linearLayout
                            .getLayoutParams();
                    int[] rules = params.getRules();
                    rules[RelativeLayout.RIGHT_OF] = 0;
                    params.leftMargin = vlp.rightMargin;

                    artistView.setText(ss);
                    artistView.setMaxLines(100);

                    vlp = (ViewGroup.MarginLayoutParams) titleView.getLayoutParams();
                    vlp.leftMargin = width;
                } else {
                    artistView.setMaxLines(minLines);
                }
            }
        });
        artistView.setMovementMethod(LinkMovementMethod.getInstance());
    } else if (topTracks) {
        artistView.setText(R.string.menu_top_tracks);
        artistView.setVisibility(View.VISIBLE);
    } else if (showAll) {
        artistView.setText(R.string.menu_show_all);
        artistView.setVisibility(View.VISIBLE);
    } else if (artists.size() == 1) {
        String artistText = artists.iterator().next();
        if (years.size() == 1) {
            artistText += " - " + years.iterator().next();
        }
        artistView.setText(artistText);
        artistView.setVisibility(View.VISIBLE);
    } else {
        artistView.setVisibility(View.GONE);
    }

    TextView songCountView = (TextView) header.findViewById(R.id.select_album_song_count);
    TextView songLengthView = (TextView) header.findViewById(R.id.select_album_song_length);
    if (podcastDescription != null || artistInfo != null) {
        songCountView.setVisibility(View.GONE);
        songLengthView.setVisibility(View.GONE);
    } else {
        String s = context.getResources().getQuantityString(R.plurals.select_album_n_songs, songCount,
                songCount);
        songCountView.setText(s.toUpperCase());
        songLengthView.setText(Util.formatDuration(totalDuration));
    }
}

From source file:com.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java

private void showAdvancedOrderItemDetail(final int position, final AdvancedOrderCategoryItemRow row) {
    if (mDetailDialog != null && mDetailDialog.isShowing())
        return;//from   w  w w  .j a v a2s.  c o  m
    mCurrentItemDetail = position;
    final View v = mLayoutInFlater.inflate(R.layout.widget_advanced_order_item_detail, this, false);

    mDetailDialog = new Dialog(mActivity);
    mDetailDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mDetailDialog.setContentView(v);
    mDetailDialog.setCanceledOnTouchOutside(true);
    mDetailDialog.setCancelable(true);

    final TextView nameLbl = (TextView) v.findViewById(R.id.name);
    final TextView priceLbl = (TextView) v.findViewById(R.id.price);
    final TextView descriptionLbl = (TextView) v.findViewById(R.id.description);
    final Resizable16by9ImageView imageView = (Resizable16by9ImageView) v.findViewById(R.id.image);
    final TextView minValueBtn = (TextView) v.findViewById(R.id.value_min);
    final TextView valueLbl = (TextView) v.findViewById(R.id.value);
    final TextView plusValueBtn = (TextView) v.findViewById(R.id.value_plus);

    final Button dismissBtn = (Button) v.findViewById(R.id.dismiss);

    nameLbl.setText(row.name);
    nameLbl.setTextColor(ContextCompat.getColor(mActivity, android.R.color.black));

    if (row.hasPrice) {
        priceLbl.setVisibility(View.VISIBLE);
        priceLbl.setText(getPriceStringForRow(row));
        priceLbl.setTextColor(ContextCompat.getColor(mActivity, R.color.mc_divider_gray));
    } else {
        priceLbl.setVisibility(View.GONE);
    }

    if (TextUtils.isEmptyOrWhitespace(row.description)) {
        descriptionLbl.setVisibility(View.GONE);
    } else {
        descriptionLbl.setVisibility(View.VISIBLE);
        descriptionLbl.setText(row.description);
        descriptionLbl.setTextColor(ContextCompat.getColor(mActivity, android.R.color.black));
    }

    minValueBtn.setText(R.string.fa_minus_circle);
    minValueBtn.setTypeface(mFontAwesomeTypeFace);
    minValueBtn.setTextColor(ContextCompat.getColor(mActivity, R.color.mc_red_divider));

    minValueBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            long value = excecuteMinValuePress(row);
            AdvancedOrderCategoryItemRow tmpRow = (AdvancedOrderCategoryItemRow) mData.get(position);
            tmpRow.value = value;
            mData.set(position, tmpRow);
            valueLbl.setText(getValueStringForRow(tmpRow));
            mListAdapter.notifyDataSetChanged();
        }
    });

    valueLbl.setText(getValueStringForRow(row));

    plusValueBtn.setText(R.string.fa_plus_circle);
    plusValueBtn.setTypeface(mFontAwesomeTypeFace);
    plusValueBtn.setTextColor(ContextCompat.getColor(mActivity, R.color.mc_divider_green));

    plusValueBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            long value = excecutePlusValuePress(row);
            AdvancedOrderCategoryItemRow tmpRow = (AdvancedOrderCategoryItemRow) mData.get(position);
            tmpRow.value = value;
            mData.set(position, tmpRow);
            valueLbl.setText(getValueStringForRow(tmpRow));
            mListAdapter.notifyDataSetChanged();
        }
    });

    dismissBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mDetailDialog.dismiss();
        }
    });

    if (!TextUtils.isEmptyOrWhitespace(row.imageUrl)) {
        new DownloadImageTask(mCachedDownloader, mActivity).execute(row.imageUrl);
    }

    mActivity.getMainService().postOnUIHandler(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            setDetailScrollViewHeight();
        }
    });

    mDetailDialog.show();
}

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

private void makeFavoriteServer() {
    linearFavorites.removeAllViews();//from   ww w .j av a2 s.  c om

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

        if (spGlobal.getBoolean(server, false)) {
            final 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);
            ImageView imgFavorite = (ImageView) viewItem.findViewById(R.id.imgFavorite);

            imgFavorite.setImageResource(
                    getResources().getIdentifier("drawable/icon_favorite", null, getPackageName()));
            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);

            imgFavorite.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    edGlobal.putBoolean(server, false);
                    edGlobal.commit();
                    linearFavorites.removeView(viewItem);
                    makeAvaiableServer();
                }
            });

            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();
                     }*/
                }
            });
            linearFavorites.addView(viewItem);
        }
    }
}

From source file:group.pals.android.lib.ui.filechooser.FragmentFiles.java

/**
 * As the name means.//from  www.  ja  v  a  2  s.c o m
 */
private void buildAddressBar(final Uri path) {
    if (path == null)
        return;

    mViewAddressBar.removeAllViews();

    new LoadingDialog<Void, Cursor, Void>(getActivity(), false) {

        LinearLayout.LayoutParams lpBtnLoc;
        LinearLayout.LayoutParams lpDivider;
        LayoutInflater inflater = getLayoutInflater(null);
        final int dim = getResources().getDimensionPixelSize(R.dimen.afc_5dp);
        int count = 0;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();

            lpBtnLoc = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            lpBtnLoc.gravity = Gravity.CENTER;
        }// onPreExecute()

        @Override
        protected Void doInBackground(Void... params) {
            Cursor cursor = getActivity().getContentResolver().query(path, null, null, null, null);
            while (cursor != null) {
                if (cursor.moveToFirst()) {
                    publishProgress(cursor);
                    cursor.close();
                } else
                    break;

                /*
                 * Process the parent directory.
                 */
                Uri uri = Uri.parse(cursor.getString(cursor.getColumnIndex(BaseFile.COLUMN_URI)));
                cursor = getActivity().getContentResolver()
                        .query(BaseFile.genContentUriApi(uri.getAuthority()).buildUpon()
                                .appendPath(BaseFile.CMD_GET_PARENT)
                                .appendQueryParameter(BaseFile.PARAM_SOURCE, uri.getLastPathSegment()).build(),
                                null, null, null, null);
            } // while

            return null;
        }// doInBackground()

        @Override
        protected void onProgressUpdate(Cursor... progress) {
            /*
             * Add divider.
             */
            if (mViewAddressBar.getChildCount() > 0) {
                View divider = inflater.inflate(R.layout.afc_view_locations_divider, null);

                if (lpDivider == null) {
                    lpDivider = new LinearLayout.LayoutParams(dim, dim);
                    lpDivider.gravity = Gravity.CENTER;
                    lpDivider.setMargins(dim, dim, dim, dim);
                }
                mViewAddressBar.addView(divider, 0, lpDivider);
            }

            Uri lastUri = Uri.parse(progress[0].getString(progress[0].getColumnIndex(BaseFile.COLUMN_URI)));

            TextView btnLoc = (TextView) inflater.inflate(R.layout.afc_button_location, null);
            String name = BaseFileProviderUtils.getFileName(progress[0]);
            btnLoc.setText(TextUtils.isEmpty(name) ? getString(R.string.afc_root) : name);
            btnLoc.setTag(lastUri);
            btnLoc.setOnClickListener(mBtnLocationOnClickListener);
            btnLoc.setOnLongClickListener(mBtnLocationOnLongClickListener);
            mViewAddressBar.addView(btnLoc, 0, lpBtnLoc);

            if (count++ == 0) {
                Rect r = new Rect();
                btnLoc.getPaint().getTextBounds(name, 0, name.length(), r);
                if (r.width() >= getResources().getDimensionPixelSize(R.dimen.afc_button_location_max_width)
                        - btnLoc.getPaddingLeft() - btnLoc.getPaddingRight()) {
                    mTextFullDirName
                            .setText(progress[0].getString(progress[0].getColumnIndex(BaseFile.COLUMN_NAME)));
                    mTextFullDirName.setVisibility(View.VISIBLE);
                } else
                    mTextFullDirName.setVisibility(View.GONE);
            } // if
        }// onProgressUpdate()

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);

            /*
             * Sometimes without delay time, it doesn't work...
             */
            mViewLocationsContainer.postDelayed(new Runnable() {

                public void run() {
                    mViewLocationsContainer.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
                }// run()
            }, DisplayPrefs.DELAY_TIME_FOR_VERY_SHORT_ANIMATION);
        }// onPostExecute()

    }.execute();
}

From source file:ca.ualberta.cs.drivr.RequestsListAdapter.java

/**
 * Called when the view holder is wants to bind the request at a certain position in the list.
 * @param viewHolder/*from w ww . jav a 2 s  .  com*/
 * @param position
 */
@Override
public void onBindViewHolder(final RequestsListAdapter.ViewHolder viewHolder, final int position) {
    final Request request = requestsToDisplay.get(position);

    // Get the views to update
    final TextView otherUserNameTextView = viewHolder.otherUserNameTextView;
    final TextView descriptionTextView = viewHolder.descriptionTextView;
    final TextView fareTextView = viewHolder.fareTextView;
    final TextView routeTextView = viewHolder.routeTextView;
    final TextView statusTextView = viewHolder.statusTextView;
    final ImageView callImageView = viewHolder.callImageView;
    final ImageView emailImageView = viewHolder.emailImageView;
    final ImageView checkImageView = viewHolder.checkMarkImageView;
    final ImageView deleteImageView = viewHolder.xMarkImageView;

    // Todo Hide Image Views until correct Request State
    if (request.getRequestState() != RequestState.CONFIRMED) {
        checkImageView.setVisibility(View.INVISIBLE);
    }

    if (request.getRequestState() != RequestState.PENDING) {
        deleteImageView.setVisibility(View.INVISIBLE);
    }

    // Show the other person's name
    final DriversList drivers = request.getDrivers();

    // Get the username of the other user
    if (userManager.getUserMode() == UserMode.RIDER) {
        final String multipleDrivers = "Multiple Drivers Accepted";
        final String driverUsername = drivers.size() == 1 ? drivers.get(0).getUsername() : "No Driver Yet";
        otherUserNameTextView.setText(drivers.size() > 1 ? multipleDrivers : driverUsername);
    } else {
        otherUserNameTextView.setText(request.getRider().getUsername());
    }

    // If the request has a description, show it. Otherwise, hide te description
    if (Strings.isNullOrEmpty(request.getDescription()))
        descriptionTextView.setVisibility(View.GONE);
    else
        descriptionTextView.setText(request.getDescription());

    // Show the fare
    fareTextView.setText("$" + request.getFareString());

    // Show the route
    routeTextView.setText(request.getRoute());

    // Driver User
    otherUserNameTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final String otherUsername = otherUserNameTextView.getText().toString();
            // there exists drivers
            if (otherUsername != "No Driver Yet") {
                if (otherUsername != "Multiple Drivers Accepted") {
                    Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();

                    ElasticSearch elasticSearch = new ElasticSearch(
                            UserManager.getInstance().getConnectivityManager());
                    User user = elasticSearch.loadUser(otherUsername);

                    String driverString = gson.toJson(user, User.class);
                    Intent intent = new Intent(context, DriverProfileActivity.class);
                    intent.putExtra(DriverProfileActivity.DRIVER, driverString);
                    context.startActivity(intent);
                } else {
                    startMultipleDriverIntent(request);
                }
            }
        }
    });

    routeTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();
            String requestString = gson.toJson(request, Request.class);
            Intent intent = new Intent(context, RequestActivity.class);
            intent.putExtra("UniqueID", "From_RequestListActivity");
            intent.putExtra(RequestActivity.EXTRA_REQUEST, requestString);
            context.startActivity(intent);
        }
    });

    // Show the status text
    statusTextView.setText(request.getRequestState().toString());

    // Add a listener to the call image
    callImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (drivers.size() == 0) {
                Toast.makeText(context, "No driver number available at this time", Toast.LENGTH_SHORT).show();

            }
            // Start Dialer
            else if (drivers.size() == 1) {
                Intent intent = new Intent(Intent.ACTION_CALL);
                String number;
                if (UserManager.getInstance().getUserMode().equals(UserMode.RIDER)) {
                    number = drivers.get(0).getPhoneNumber();
                } else {
                    number = request.getRider().getPhoneNumber();
                }
                number = "tel:" + number;
                intent.setData(Uri.parse(number));
                if (ActivityCompat.checkSelfPermission(context,
                        Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

                    return;
                }
                context.startActivity(intent);

            } else {

                startMultipleDriverIntent(request);
            }
        }
    });

    // Add a listener to the email image
    emailImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (drivers.size() == 0) {
                Toast.makeText(context, "No driver email available at this time", Toast.LENGTH_SHORT).show();

            }
            //http://stackoverflow.com/questions/8701634/send-email-intent
            else if (drivers.size() == 1) {

                Intent intent = new Intent();
                ComponentName emailApp = intent.resolveActivity(context.getPackageManager());
                ComponentName unsupportedAction = ComponentName
                        .unflattenFromString("com.android.fallback/.Fallback");
                boolean hasEmailApp = emailApp != null && !emailApp.equals(unsupportedAction);
                String email;

                if (UserManager.getInstance().getUserMode().equals(UserMode.RIDER)) {
                    email = drivers.get(0).getEmail();
                } else {
                    email = request.getRider().getEmail();
                }
                String subject = "Drivr Request: " + request.getId();
                String body = "Drivr user " + drivers.get(0).getUsername();

                if (hasEmailApp) {
                    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + email));
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
                    emailIntent.putExtra(Intent.EXTRA_TEXT, body);
                    context.startActivity(Intent.createChooser(emailIntent, "Chooser Title"));
                } else {
                    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", email, null));
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "");
                    emailIntent.putExtra(Intent.EXTRA_TEXT, "");
                    context.startActivity(Intent.createChooser(emailIntent, "Send email..."));
                }
            } else {
                startMultipleDriverIntent(request);

            }
        }
    });

    // Complete The Request
    checkImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(context, RequestCompletedActivity.class);
            intent.putExtra(RequestCompletedActivity.REQUEST_ID_EXTRA, request.getId());
            context.startActivity(intent);
        }
    });

    deleteImageView.setOnClickListener(new View.OnClickListener() {

        // Todo Delete the Request
        @Override
        public void onClick(View v) {
            v.getContext();
            ElasticSearch elasticSearch = new ElasticSearch(
                    (ConnectivityManager) v.getContext().getSystemService(Context.CONNECTIVITY_SERVICE));
            elasticSearch.deleteRequest(request.getId());
            UserManager userManager = UserManager.getInstance();
            userManager.getRequestsList().removeById(request);
            userManager.notifyObservers();
            requestsToDisplay.remove(request);
            notifyItemRemoved(viewHolder.getAdapterPosition());
        }
    });
}