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.lcl.designsnackbar.tsnackbar.TSnackbar.java

/**
 * Set the action to be displayed in this {@link TSnackbar}.
 *
 * @param text     Text to display/*from   w  w w .  j  a v a2 s  .  co m*/
 * @param listener callback to be invoked when the action is clicked
 */
@NonNull
public TSnackbar setAction(CharSequence text, final View.OnClickListener listener) {
    final TextView tv = mView.getActionView();

    if (TextUtils.isEmpty(text) || listener == null) {
        tv.setVisibility(View.GONE);
        tv.setOnClickListener(null);
    } else {
        tv.setVisibility(View.VISIBLE);
        tv.setText(text);
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onClick(view);
                // Now dismiss the Snackbar
                dispatchDismiss(Callback.DISMISS_EVENT_ACTION);
            }
        });
    }
    return this;
}

From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java

private void configureBeginDate(View view) {
    TextView beginDateTextView = (TextView) view.findViewById(R.id.textview_hours_detail_begin_date);
    beginDateTextView.setEnabled(isThisHoursRecordNotActive());
    if (isThisHoursRecordActive()) {
        beginDateTextView//  www  . j  a va2s.c  o  m
                .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.no_border, null));
    } else {
        beginDateTextView
                .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.rounded_border, null));
    }
    beginDateTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FragmentManager fragmentManager = getFragmentManager();
            // If there is already a Date displayed, use that.
            Date dateToUse = (mHours.getBegin() == null) ? new Date() : mHours.getBegin();
            DateTimePickerFragment datePickerFragment = FragmentFactory.createDatePickerFragment(dateToUse,
                    "Begin", DateTimePickerFragment.BOTH);
            datePickerFragment.setTargetFragment(HoursDetailFragment.this, REQUEST_BEGIN_DATE_PICKER);
            datePickerFragment.show(fragmentManager, DateTimePickerFragment.DIALOG_TAG);
        }
    });
    if (mHours.getBegin() != null) {
        LocalDateTime beginDateTime = new LocalDateTime(mHours.getBegin().getTime());
        beginDateTextView.setText(beginDateTime.toString(DATE_FORMAT_PATTERN));
    }
}

From source file:com.soubw.other.WaveformFragment.java

protected void loadGui(View view) {
    DisplayMetrics metrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    mDensity = metrics.density;//from  ww  w  . java  2  s .  co m

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

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

    mPlayButton = (ImageButton) view.findViewById(R.id.play);
    mPlayButton.setOnClickListener(mPlayListener);
    mRewindButton = (ImageButton) view.findViewById(R.id.rew);
    mRewindButton.setOnClickListener(getRewindListener());
    mFfwdButton = (ImageButton) view.findViewById(R.id.ffwd);
    mFfwdButton.setOnClickListener(getFwdListener());

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

    enableDisableButtons();

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

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

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

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

    mStartMarker = (MarkerView) view.findViewById(R.id.startmarker);
    mStartMarker.setListener(this);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        mStartMarker.setImageAlpha(255);
    }
    mStartMarker.setFocusable(true);
    mStartMarker.setFocusableInTouchMode(true);
    mStartVisible = true;

    mEndMarker = (MarkerView) view.findViewById(R.id.endmarker);
    mEndMarker.setListener(this);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        mEndMarker.setImageAlpha(255);
    }
    mEndMarker.setFocusable(true);
    mEndMarker.setFocusableInTouchMode(true);
    mEndVisible = true;

    updateDisplay();
}

From source file:com.conferenceengineer.android.iosched.ui.SessionDetailFragment.java

/**
 * Handle {@link SessionsQuery} {@link Cursor}.
 *///from  ww w.  j  a v  a2s .c  om
private void onSessionQueryComplete(Cursor cursor) {
    mSessionCursor = true;
    if (!cursor.moveToFirst()) {
        if (isAdded()) {
            // TODO: Remove this in favor of a callbacks interface that the activity
            // can implement.
            getActivity().finish();
        }
        return;
    }

    mTitleString = cursor.getString(SessionsQuery.TITLE);

    // Format time block this session occupies
    mType = cursor.getString(SessionsQuery.TYPE);
    mSessionBlockStart = cursor.getLong(SessionsQuery.BLOCK_START);
    mSessionBlockEnd = cursor.getLong(SessionsQuery.BLOCK_END);
    String roomName = cursor.getString(SessionsQuery.ROOM_NAME);
    final String subtitle = UIUtils.formatSessionSubtitle(mTitleString, mSessionBlockStart, mSessionBlockEnd,
            roomName, mBuffer, getActivity());

    mTitle.setText(mTitleString);

    mUrl = cursor.getString(SessionsQuery.URL);
    if (TextUtils.isEmpty(mUrl)) {
        mUrl = "";
    }

    mHashtags = cursor.getString(SessionsQuery.HASHTAGS);
    if (!TextUtils.isEmpty(mHashtags)) {
        enableSocialStreamMenuItemDeferred();
    }

    mRoomId = cursor.getString(SessionsQuery.ROOM_ID);

    setupShareMenuItemDeferred();
    showStarredDeferred(mInitStarred = (cursor.getInt(SessionsQuery.STARRED) != 0), false);

    final String sessionAbstract = cursor.getString(SessionsQuery.ABSTRACT);
    if (!TextUtils.isEmpty(sessionAbstract)) {
        UIUtils.setTextMaybeHtml(mAbstract, sessionAbstract);
        mAbstract.setVisibility(View.VISIBLE);
        mHasSummaryContent = true;
    } else {
        mAbstract.setVisibility(View.GONE);
    }

    final View requirementsBlock = mRootView.findViewById(R.id.session_requirements_block);
    final String sessionRequirements = cursor.getString(SessionsQuery.REQUIREMENTS);
    if (!TextUtils.isEmpty(sessionRequirements)) {
        UIUtils.setTextMaybeHtml(mRequirements, sessionRequirements);
        requirementsBlock.setVisibility(View.VISIBLE);
        mHasSummaryContent = true;
    } else {
        requirementsBlock.setVisibility(View.GONE);
    }

    // Show empty message when all data is loaded, and nothing to show
    if (mSpeakersCursor && !mHasSummaryContent) {
        mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
    }

    // Compile list of links (submit feedback, and normal links)
    ViewGroup linkContainer = (ViewGroup) mRootView.findViewById(R.id.links_container);
    linkContainer.removeAllViews();

    final Context context = mRootView.getContext();

    List<Pair<Integer, Intent>> links = new ArrayList<Pair<Integer, Intent>>();

    // Add session feedback link
    if (getResources().getBoolean(R.bool.has_session_feedback_enabled)) {
        links.add(new Pair<Integer, Intent>(R.string.session_feedback_submitlink,
                new Intent(Intent.ACTION_VIEW, mSessionUri, getActivity(), SessionFeedbackActivity.class)));
    }

    for (int i = 0; i < SessionsQuery.LINKS_INDICES.length; i++) {
        final String linkUrl = cursor.getString(SessionsQuery.LINKS_INDICES[i]);
        if (TextUtils.isEmpty(linkUrl)) {
            continue;
        }

        links.add(new Pair<Integer, Intent>(SessionsQuery.LINKS_TITLES[i],
                new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl))
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)));
    }

    // Render links
    if (links.size() > 0) {
        LayoutInflater inflater = LayoutInflater.from(context);
        int columns = context.getResources().getInteger(R.integer.links_columns);

        LinearLayout currentLinkRowView = null;
        for (int i = 0; i < links.size(); i++) {
            final Pair<Integer, Intent> link = links.get(i);

            // Create link view
            TextView linkView = (TextView) inflater.inflate(R.layout.list_item_session_link, linkContainer,
                    false);
            linkView.setText(getString(link.first));
            linkView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    fireLinkEvent(link.first);
                    try {
                        startActivity(link.second);
                    } catch (ActivityNotFoundException ignored) {
                    }
                }
            });

            // Place it inside a container
            if (columns == 1) {
                linkContainer.addView(linkView);
            } else {
                // create a new link row
                if (i % columns == 0) {
                    currentLinkRowView = (LinearLayout) inflater.inflate(R.layout.include_link_row,
                            linkContainer, false);
                    currentLinkRowView.setWeightSum(columns);
                    linkContainer.addView(currentLinkRowView);
                }

                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).width = 0;
                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).weight = 1;
                currentLinkRowView.addView(linkView);
            }
        }

        mRootView.findViewById(R.id.session_links_header).setVisibility(View.VISIBLE);
        mRootView.findViewById(R.id.links_container).setVisibility(View.VISIBLE);

    } else {
        mRootView.findViewById(R.id.session_links_header).setVisibility(View.GONE);
        mRootView.findViewById(R.id.links_container).setVisibility(View.GONE);
    }

    // Show past/present/future and livestream status for this block.
    UIUtils.updateTimeBlockUI(context, mSessionBlockStart, mSessionBlockEnd, null, mSubtitle, subtitle);

    LOGD("Tracker", "Session: " + mTitleString);
}

From source file:lvge.com.myapp.modules.shop_management.NotAuthenticationFragment.java

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

    cropOptions = new CropOptions.Builder().setAspectX(1).setAspectY(1).setWithOwnCrop(true).create();

    view = inflater.inflate(R.layout.fragment_shop_manage_not_authentication, container, false);
    ctx = getActivity();//from www. ja  v a  2 s .c o  m
    img_business_licence = (ImageView) view.findViewById(R.id.img_business_licence);
    img_business_licence.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            id_iamge = R.id.img_business_licence;
            show(v);
        }
    });

    img_identity_card_positive = (ImageView) view.findViewById(R.id.img_identity_card_positive);
    img_identity_card_positive.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            id_iamge = R.id.img_identity_card_positive;
            show(v);
        }
    });

    img_identity_card_negative = (ImageView) view.findViewById(R.id.img_identity_card_negative);
    img_identity_card_negative.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            id_iamge = R.id.img_identity_card_negative;
            show(v);
        }
    });

    shop_authentication_company_name = (EditText) view.findViewById(R.id.shop_authentication_company_name);

    TextView shop_authentication_confirm_and_submit = (TextView) view
            .findViewById(R.id.shop_authentication_confirm_and_submit);
    shop_authentication_confirm_and_submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            //                HasCommitAuthenticationFragment HasCommit = new HasCommitAuthenticationFragment();
            //                FragmentTransaction transaction =getFragmentManager().beginTransaction();
            //                transaction.replace(R.id.fragment_container_authentication,HasCommit);
            //                transaction.commit();

            L.d("shop_authentication_confirm_and_submit is clicked");
            if (shop_authentication_company_name.getText().toString().isEmpty()) {
                L.d("company_name is null");
                Toast.makeText(ctx, "???", Toast.LENGTH_SHORT).show();
                return;
            }

            //                if (img_business_licence_bool || img_identity_card_positive_bool || img_identity_card_negative_bool)
            //                    startProgerssDialog();
            //                else {
            //                    Toast.makeText(ctx, "", Toast.LENGTH_SHORT).show();
            //                    return;
            //                }

            try {
                if (img_business_licence_bool) {
                    final List<String> filePaths = new ArrayList<>();
                    final Map<String, Object> map = new HashMap<String, Object>();
                    img_business_licence.setDrawingCacheEnabled(true);
                    img_business_licence_bitmap = img_business_licence.getDrawingCache();
                    filePaths.add(saveBitmap("1", img_business_licence_bitmap));

                    new Thread() {
                        public void run() {
                            try {
                                // showProgressDialog();
                                if (img_business_licence.getTag() == null)
                                    post_str(filePaths, ShopManagementParameter.SHOPIMG_BUSINESS_LICENSE,
                                            ShopManagementParameter.SHOPIMG_IDENTITY, "");
                                else
                                    post_str(filePaths, ShopManagementParameter.SHOPIMG_BUSINESS_LICENSE,
                                            ShopManagementParameter.SHOPIMG_IDENTITY,
                                            img_business_licence.getTag().toString());
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }.start();
                    Thread.sleep(1000);
                    img_business_licence_bool = false;
                }
                if (img_identity_card_positive_bool) {
                    final List<String> filePaths = new ArrayList<>();
                    final Map<String, Object> map = new HashMap<String, Object>();
                    img_identity_card_positive.setDrawingCacheEnabled(true);
                    img_identity_card_positive_bitmap = img_identity_card_positive.getDrawingCache();
                    filePaths.add(saveBitmap("2", img_identity_card_positive_bitmap));

                    new Thread() {
                        public void run() {
                            try {
                                // showProgressDialog();
                                if (img_identity_card_positive.getTag() == null)
                                    post_str(filePaths, ShopManagementParameter.SHOPIMG_IDENTITY_CARD_POSITIVE,
                                            ShopManagementParameter.SHOPIMG_IDENTITY, "");
                                else
                                    post_str(filePaths, ShopManagementParameter.SHOPIMG_IDENTITY_CARD_POSITIVE,
                                            ShopManagementParameter.SHOPIMG_IDENTITY,
                                            img_identity_card_positive.getTag().toString());
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }.start();
                    Thread.sleep(1000);
                    img_identity_card_positive_bool = false;
                }
                if (img_identity_card_negative_bool) {
                    final List<String> filePaths = new ArrayList<>();
                    final Map<String, Object> map = new HashMap<String, Object>();
                    img_identity_card_negative.setDrawingCacheEnabled(true);
                    img_identity_card_negative_bitmap = img_identity_card_negative.getDrawingCache();
                    filePaths.add(saveBitmap("3", img_identity_card_negative_bitmap));

                    new Thread() {
                        public void run() {
                            try {
                                // showProgressDialog();
                                if (img_identity_card_negative.getTag() == null)
                                    post_str(filePaths, ShopManagementParameter.SHOPIMG_IDENTITY_CARD_NEGATIVE,
                                            ShopManagementParameter.SHOPIMG_IDENTITY, "");
                                else
                                    post_str(filePaths, ShopManagementParameter.SHOPIMG_IDENTITY_CARD_NEGATIVE,
                                            ShopManagementParameter.SHOPIMG_IDENTITY,
                                            img_identity_card_negative.getTag().toString());
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }.start();
                    Thread.sleep(1000);
                    img_identity_card_negative_bool = false;
                }
            } catch (Exception e) {
                stopProgressDialog();
                Toast.makeText(ctx, "?", Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            }

            try {
                startProgerssDialog();
                TimerTask task = new TimerTask() {
                    @Override
                    public void run() {
                        OkHttpUtils.post()
                                //get 
                                .url("http://www.lvgew.com/obdcarmarket/sellerapp/seller/sellerIdentifycationApply") //?
                                .addParams("companyName", shop_authentication_company_name.getText().toString())
                                .build().execute(new Callback() {

                                    @Override
                                    public Object parseNetworkResponse(Response response, int i)
                                            throws Exception {
                                        String string = response.body().string();//?Json?
                                        //json?
                                        //LoginResultModel??
                                        L.d(string);
                                        result1 = new Gson().fromJson(string, CustomerDetail.class);

                                        return result1;
                                    }

                                    @Override
                                    public void onError(Call call, Exception e, int i) {
                                        stopProgressDialog();
                                    }

                                    @Override
                                    public void onResponse(Object o, int i) {
                                        if (null != o) {
                                            result1 = (CustomerDetail) o;
                                            L.d(String.valueOf(result1.getOperationResult().getResultCode()));
                                            if (result1.getOperationResult().getResultCode() == 0) {
                                                Toast.makeText(ctx, "????",
                                                        Toast.LENGTH_SHORT).show();
                                                mHandler.sendEmptyMessage(1002);
                                            } else {
                                                Toast.makeText(ctx, result1.getOperationResult().getResultMsg(),
                                                        Toast.LENGTH_SHORT).show();
                                            }
                                        }
                                        stopProgressDialog();
                                    }
                                });
                    }
                };
                Timer timer = new Timer();
                timer.schedule(task, 2000);//3?
            } catch (Exception e) {
                stopProgressDialog();
                Toast.makeText(ctx, "?", Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            }
        }
    });

    network_init(view);
    return view;
}

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   w  w w  .  j  a va2s  .  c om

    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:android.melbournehistorymap.MapsActivity.java

/**
 * Manipulates the map once available.//from   w  w w. ja v  a  2 s  .  c o m
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    spinner = (ProgressBar) findViewById(R.id.prograssSpinner);
    //check if permission has been granted
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // Permission has already been granted
        return;
    }
    mMap.setMyLocationEnabled(true);
    mMap.getUiSettings().setZoomControlsEnabled(false);

    double lat;
    double lng;
    final int radius;
    int zoom;

    lat = Double.parseDouble(CurrLat);
    lng = Double.parseDouble(CurrLong);

    //build current location
    LatLng currentLocation = new LatLng(lat, lng);
    final LatLng realLocation = currentLocation;

    if (MELBOURNE.contains(currentLocation)) {
        mMap.getUiSettings().setMyLocationButtonEnabled(true);
        zoom = 17;
    } else {
        mMap.getUiSettings().setMyLocationButtonEnabled(false);
        lat = -37.81161508043379;
        lng = 144.9647320434451;
        zoom = 15;
        currentLocation = new LatLng(lat, lng);
    }

    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentLocation, 13));

    CameraPosition cameraPosition = new CameraPosition.Builder().target(currentLocation) // Sets the center of the map to location user
            .zoom(zoom) // Sets the zoom
            .bearing(0) // Sets the orientation of the camera to east
            .tilt(25) // Sets the tilt of the camera to 30 degrees
            .build(); // Creates a CameraPosition from the builder

    //Animate user to map location, if in Melbourne or outside of Melbourne bounds
    mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition),
            new GoogleMap.CancelableCallback() {
                @Override
                public void onFinish() {
                    updateMap();
                }

                @Override
                public void onCancel() {

                }
            });

    final TextView placeTitle = (TextView) findViewById(R.id.placeTitle);
    final TextView placeVic = (TextView) findViewById(R.id.placeVic);
    final TextView expPlaceTitle = (TextView) findViewById(R.id.expPlaceTitle);
    final TextView expPlaceVic = (TextView) findViewById(R.id.expPlaceVic);
    final TextView expPlaceDescription = (TextView) findViewById(R.id.placeDescription);
    final TextView wikiLicense = (TextView) findViewById(R.id.wikiLicense);
    final TextView expPlaceDistance = (TextView) findViewById(R.id.expPlaceDistance);
    final RelativeLayout tile = (RelativeLayout) findViewById(R.id.tile);
    final TextView fab = (TextView) findViewById(R.id.fab);
    final RelativeLayout distanceCont = (RelativeLayout) findViewById(R.id.distanceContainer);

    //        String license = "Text is available under the <a rel=\"license\" href=\"//en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License\">Creative Commons Attribution-ShareAlike License</a><a rel=\"license\" href=\"//creativecommons.org/licenses/by-sa/3.0/\" style=\"display:none;\"></a>;\n" +
    //                "additional terms may apply.";
    //        wikiLicense.setText(Html.fromHtml(license));
    //        wikiLicense.setMovementMethod(LinkMovementMethod.getInstance());
    //Marker click
    mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(Marker marker) {
            String title = marker.getTitle();
            mMap.setPadding(0, 0, 0, 620);
            //set clicked marker to full opacity
            marker.setAlpha(1f);
            //set previous marker back to partial opac (if there is a prevMarker
            if (dirtyMarker == 1) {
                prevMarker.setAlpha(0.6f);
            }
            prevMarker = marker;
            dirtyMarker = 1;

            //Set DB helper
            DBHelper myDBHelper = new DBHelper(MapsActivity.this, WikiAPI.DB_NAME, null, WikiAPI.VERSION);

            //Only search for Wiki API requests if no place article returned.
            // **
            //Open DB as readable only.
            SQLiteDatabase db = myDBHelper.getReadableDatabase();
            //Set the query
            String dbFriendlyName = title.replace("\'", "\'\'");
            //Limit by 1 rows
            Cursor cursor = db.query(DBHelper.TABLE_NAME, null, "PLACE_NAME = '" + dbFriendlyName + "'", null,
                    null, null, null, "1");

            //move through each row returned in the query results
            while (cursor.moveToNext()) {

                String place_ID = cursor.getString(cursor.getColumnIndex("PLACE_ID"));
                String placeName = cursor.getString(cursor.getColumnIndex("PLACE_NAME"));
                String placeLoc = cursor.getString(cursor.getColumnIndex("PLACE_LOCATION"));
                String placeArticle = cursor.getString(cursor.getColumnIndex("ARTICLE"));
                String placeLat = cursor.getString(cursor.getColumnIndex("LAT"));
                String placeLng = cursor.getString(cursor.getColumnIndex("LNG"));

                //Get Google Place photos
                //Source: https://developers.google.com/places/android-api/photos
                final String placeId = place_ID;
                Places.GeoDataApi.getPlacePhotos(mGoogleApiClient, placeId)
                        .setResultCallback(new ResultCallback<PlacePhotoMetadataResult>() {
                            @Override
                            public void onResult(PlacePhotoMetadataResult photos) {
                                if (!photos.getStatus().isSuccess()) {
                                    return;
                                }
                                ImageView mImageView = (ImageView) findViewById(R.id.imageView);
                                ImageView mImageViewExpanded = (ImageView) findViewById(R.id.headerImage);
                                TextView txtAttribute = (TextView) findViewById(R.id.photoAttribute);
                                TextView expTxtAttribute = (TextView) findViewById(R.id.expPhotoAttribute);
                                PlacePhotoMetadataBuffer photoMetadataBuffer = photos.getPhotoMetadata();
                                if (photoMetadataBuffer.getCount() > 0) {
                                    // Display the first bitmap in an ImageView in the size of the view
                                    photoMetadataBuffer.get(0).getScaledPhoto(mGoogleApiClient, 600, 200)
                                            .setResultCallback(mDisplayPhotoResultCallback);
                                    //get photo attributions
                                    PlacePhotoMetadata photo = photoMetadataBuffer.get(0);
                                    CharSequence attribution = photo.getAttributions();
                                    if (attribution != null) {
                                        txtAttribute.setText(Html.fromHtml(String.valueOf(attribution)));
                                        expTxtAttribute.setText(Html.fromHtml(String.valueOf(attribution)));
                                        //http://stackoverflow.com/questions/4303160/how-can-i-make-links-in-fromhtml-clickable-android
                                        txtAttribute.setMovementMethod(LinkMovementMethod.getInstance());
                                        expTxtAttribute.setMovementMethod(LinkMovementMethod.getInstance());
                                    } else {
                                        txtAttribute.setText(" ");
                                        expTxtAttribute.setText(" ");
                                    }
                                } else {
                                    //Reset image view as no photo was identified
                                    mImageView.setImageResource(android.R.color.transparent);
                                    mImageViewExpanded.setImageResource(android.R.color.transparent);
                                    txtAttribute.setText(R.string.no_photos);
                                    expTxtAttribute.setText(R.string.no_photos);
                                }
                                photoMetadataBuffer.release();
                            }
                        });

                LatLng destLocation = new LatLng(Double.parseDouble(placeLat), Double.parseDouble(placeLng));
                //Work out distance between current location and place location
                //Source Library: https://github.com/googlemaps/android-maps-utils
                double distance = SphericalUtil.computeDistanceBetween(realLocation, destLocation);
                distance = Math.round(distance);
                distance = distance * 0.001;
                String strDistance = String.valueOf(distance);
                String[] arrDistance = strDistance.split("\\.");
                String unit = "km";
                if (arrDistance[0] == "0") {
                    unit = "m";
                    strDistance = arrDistance[1];
                } else {
                    strDistance = arrDistance[0] + "." + arrDistance[1].substring(0, 1);
                }

                placeArticle = placeArticle
                        .replaceAll("(<div class=\"thumb t).*\\s.*\\s.*\\s.*\\s.*\\s<\\/div>\\s<\\/div>", " ");

                Spannable noUnderlineMessage = new SpannableString(Html.fromHtml(placeArticle));

                //http://stackoverflow.com/questions/4096851/remove-underline-from-links-in-textview-android
                for (URLSpan u : noUnderlineMessage.getSpans(0, noUnderlineMessage.length(), URLSpan.class)) {
                    noUnderlineMessage.setSpan(new UnderlineSpan() {
                        public void updateDrawState(TextPaint tp) {
                            tp.setUnderlineText(false);
                        }
                    }, noUnderlineMessage.getSpanStart(u), noUnderlineMessage.getSpanEnd(u), 0);
                }

                placeArticle = String.valueOf(noUnderlineMessage);
                placeArticle = placeArticle.replaceAll("(\\[\\d\\])", " ");

                placeTitle.setText(placeName);
                expPlaceTitle.setText(placeName);
                placeVic.setText(placeLoc);
                expPlaceVic.setText(placeLoc);
                expPlaceDescription.setText(placeArticle);
                if (MELBOURNE.contains(realLocation)) {
                    expPlaceDistance.setText("Distance: " + strDistance + unit);
                    distanceCont.setVisibility(View.VISIBLE);
                }
            }

            tile.setVisibility(View.VISIBLE);
            fab.setVisibility(View.VISIBLE);
            //Set to true to not show default behaviour.
            return false;
        }
    });

    mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
        @Override
        public void onMapClick(LatLng latLng) {
            int viewStatus = tile.getVisibility();
            if (viewStatus == View.VISIBLE) {
                tile.setVisibility(View.INVISIBLE);
                fab.setVisibility(View.INVISIBLE);
                //set previous marker back to partial opac (if there is a prevMarker
                if (dirtyMarker == 1) {
                    prevMarker.setAlpha(0.6f);
                }
            }

            mMap.setPadding(0, 0, 0, 0);
        }
    });

    FloatingActionButton shareIcon = (FloatingActionButton) findViewById(R.id.shareIcon);
    shareIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //https://www.google.com.au/maps/place/Federation+Square/@-37.8179789,144.9668635,15z

            //Build implicit intent by triggering a SENDTO action, which will capture applications that allow for messages
            //that allow for messages to be sent to a specific user with data
            //http://developer.android.com/reference/android/content/Intent.html#ACTION_SENDTO
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            //Build SMS
            String encodedPlace = "empty";
            try {
                encodedPlace = URLEncoder.encode(String.valueOf(expPlaceTitle.getText()), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            intent.putExtra(Intent.EXTRA_TEXT, String.valueOf(expPlaceTitle.getText())
                    + " \n\nhttps://www.google.com.au/maps/place/" + encodedPlace);
            Intent sms = Intent.createChooser(intent, null);
            startActivity(sms);
        }
    });

    TextView fullArticle = (TextView) findViewById(R.id.fullArticle);
    fullArticle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String wikiPlace = WikiPlace.getName(String.valueOf(expPlaceTitle.getText()));
            String url = "https://en.wikipedia.org/wiki/" + wikiPlace;

            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(browserIntent);
        }
    });
}

From source file:com.tony.selene.sliding.AbSlidingSmoothTabView.java

/**
 * ??tab.//from   w  w w .  j  a va  2  s . c om
 *
 * @param tabText
 *            the tab text
 * @param fragment
 *            the fragment
 */
public void addItemView(String tabText, Fragment fragment) {

    tabItemTextList.add(tabText);
    pagerItemList.add(fragment);

    tabItemList.clear();
    mTabLayout.removeAllViews();

    for (int i = 0; i < tabItemTextList.size(); i++) {
        final int index = i;
        String text = tabItemTextList.get(i);
        TextView tv = new TextView(this.context);
        tv.setTextColor(tabColor);
        tv.setTextSize(tabTextSize);
        tv.setText(text);
        tv.setGravity(Gravity.CENTER);
        tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1));
        tv.setPadding(12, 5, 12, 5);
        tv.setFocusable(false);
        tabItemList.add(tv);
        mTabLayout.addView(tv);
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mViewPager.setCurrentItem(index);
            }
        });
    }

    // ?
    AbLogUtil.d(AbSlidingSmoothTabView.class, "addItemView finish");
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);
}

From source file:com.example.fan.horizontalscrollview.PagerSlidingTabStrip.java

public TextView getTextTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    tab.setText(title);//w w  w .j a  v  a 2 s  .com
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tab.setTextColor(getResources().getColorStateList(
            mTextChangeable ? R.color.pst_tab_changeable_text_selector : R.color.pst_tab_text_selector));
    tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18.0f);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != mOnPageClickedLisener) {
                mOnPageClickedLisener.onPageClicked(position);
            }
            pager.setCurrentItem(position);
        }
    });

    return tab;
}

From source file:com.jiandanbaoxian.fragment.DialogFragmentCreater.java

/**
 * ?=item ?//from   w  w w .  j  a  v  a 2  s  . c  om
 *
 * @param mContext
 * @return
 */
private Dialog showConfirmOrCancelDialog(final Context mContext) {
    View convertView = LayoutInflater.from(mContext).inflate(R.layout.dialog_double_choice, null);
    final Dialog dialog = new Dialog(mContext, R.style.mystyle);
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.tv_cancel:
                if (onDialogClickLisenter != null)
                    onDialogClickLisenter.viewClick(StringConstant.tv_cancel);
                dismiss();
                break;
            case R.id.tv_confirm:
                if (onDialogClickLisenter != null)
                    onDialogClickLisenter.viewClick(StringConstant.tv_confirm);
                dismiss();
                break;
            default:
                break;
            }
        }
    };
    TextView tv_cancel = (TextView) convertView.findViewById(R.id.tv_cancel);
    TextView tv_confirm = (TextView) convertView.findViewById(R.id.tv_confirm);
    TextView tv_title = (TextView) convertView.findViewById(R.id.tv_title);
    TextView tv_content = (TextView) convertView.findViewById(R.id.tv_content);

    if (onDialogClickLisenter != null) {
        onDialogClickLisenter.controlView(tv_confirm, tv_cancel, tv_title, tv_content);
    }
    tv_cancel.setOnClickListener(listener);
    tv_confirm.setOnClickListener(listener);
    dialog.setContentView(convertView);
    dialog.getWindow().setWindowAnimations(R.style.dialog_right_control_style);
    return dialog;
}