Example usage for android.widget RelativeLayout setTag

List of usage examples for android.widget RelativeLayout setTag

Introduction

In this page you can find the example usage for android.widget RelativeLayout setTag.

Prototype

public void setTag(final Object tag) 

Source Link

Document

Sets the tag associated with this view.

Usage

From source file:org.montanafoodhub.app.producer.ProducerDetailFragment.java

private void loadCertifications(View view) {

    LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.certificationLayout);
    linearLayout.removeAllViews();//from  ww w . ja  v a  2s. co m

    ImageCache imageCache = ((HubApplication) getActivity().getApplication()).getImageCache();

    for (Certification cert : _producer.getCertifications()) {
        RelativeLayout relativeLayout = (RelativeLayout) LayoutInflater.from(getActivity())
                .inflate(R.layout.certification, null);
        relativeLayout.setOnClickListener(this);
        relativeLayout.setTag(cert);

        ImageView imageView = (ImageView) relativeLayout.findViewById(R.id.certificationImageview);
        imageCache.loadImage(imageView, cert.getIconUrl(), R.drawable.default_certification);

        TextView textView = (TextView) relativeLayout.findViewById(R.id.certificationText);
        textView.setText(cert.getDisplayName());

        linearLayout.addView(relativeLayout);
    }
}

From source file:ac.robinson.mediaphone.provider.NarrativeAdapter.java

public View newView(Context context, Cursor cursor, ViewGroup parent) {
    final RelativeLayout view = (RelativeLayout) mInflater.inflate(R.layout.frame_browser, parent, false);

    NarrativeViewHolder holder = new NarrativeViewHolder();
    // TODO: soft references to the list view? delete on destroy?
    holder.frameList = (HorizontalListView) view.findViewById(R.id.narrative_list_view);
    view.setTag(holder);

    holder.frameList.setOnItemClickListener(mActivity.getFrameClickListener());
    holder.frameList.setOnItemLongClickListener(mActivity.getFrameLongClickListener());

    return view;/*from  w  ww .  j a  v a 2 s  .com*/
}

From source file:com.mycompany.popularmovies.DetailActivity.DetailFragment.java

@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
    if (cursorLoader == mGeneralInfoLoader) {
        if (cursor != null && cursor.moveToFirst()) {
            int columnIndexPosterPath = cursor.getColumnIndex(MovieContract.MovieTable.COLUMN_POSTER_PATH);
            String posterPath = MovieAdapter.POSTER_BASE_URL_W185 + cursor.getString(columnIndexPosterPath);
            Picasso picasso = Picasso.with(getActivity());
            picasso.load(posterPath).into(mPosterImageView);

            int columnIndexTitle = cursor.getColumnIndex(MovieContract.MovieTable.COLUMN_TITLE);
            String title = cursor.getString(columnIndexTitle);
            mTitleTextView.setText(title);

            int columnIndexIsFavorite = cursor.getColumnIndex(MovieContract.MovieTable.COLUMN_FAVORITED);
            int isFavorite = cursor.getInt(columnIndexIsFavorite);
            mHeartImageView/*w w w .  ja v  a 2s. c o m*/
                    .setImageResource(isFavorite == 1 ? R.drawable.heart_active : R.drawable.heart_inactive);
            mHeartImageView.setOnClickListener(this);

            int columnIndexReleaseDate = cursor.getColumnIndex(MovieContract.MovieTable.COLUMN_RELEASE_DATE);
            String releaseDateText = cursor.getString(columnIndexReleaseDate);
            String releaseYearText = releaseDateText.substring(0, Math.min(releaseDateText.length(), 4));
            mReleaseYearTextView.setText(releaseYearText);

            int columnIndexVoteAverage = cursor.getColumnIndex(MovieContract.MovieTable.COLUMN_VOTE_AVERAGE);
            float vote_average = cursor.getFloat(columnIndexVoteAverage);
            mRatingBar.setRating(vote_average);

            int columnIndexSynopsis = cursor.getColumnIndex(MovieContract.MovieTable.COLUMN_SYNOPSIS);
            mSynopsisTextView.setText(cursor.getString(columnIndexSynopsis));

            // If onCreateOptionsMenu has already happened, we need to update the share intent now.
            if (mShareActionProvider != null) {
                mShareText = title;
                mShareActionProvider.setShareIntent(createShareIntent());
            }
        } else {
            Log.e(LOG_TAG, "Cursor to populate general info was empty or null!");
        }
    } else if (cursorLoader == mTrailerLoader) {
        if (cursor == null || !cursor.moveToFirst()) {
            mTrailerListTitle.setVisibility(View.INVISIBLE);
        } else {
            mTrailerListTitle.setVisibility(View.VISIBLE);
            for (cursor.moveToFirst(); cursor.getPosition() < cursor.getCount(); cursor.moveToNext()) {
                int columnIndexName = cursor.getColumnIndex(MovieContract.TrailersTable.COLUMN_NAME);
                String trailerName = cursor.getString(columnIndexName);

                int columnIndexLanguageCode = cursor
                        .getColumnIndex(MovieContract.TrailersTable.COLUMN_LANGUAGE_CODE);
                String trailerLanguageCode = cursor.getString(columnIndexLanguageCode);

                String trailer_summary = String.format("%s (%s)", trailerName,
                        trailerLanguageCode.toUpperCase());

                int columnIndexSite = cursor.getColumnIndex(MovieContract.TrailersTable.COLUMN_SITE);
                String site = cursor.getString(columnIndexSite);

                int columnIndexKey = cursor.getColumnIndex(MovieContract.TrailersTable.COLUMN_KEY);
                String key = cursor.getString(columnIndexKey);

                String link = null;
                if (site.compareTo("YouTube") == 0) {
                    link = "https://www.youtube.com/watch?v=" + key;
                } else {
                    Log.e(LOG_TAG, "Unsupported site: " + site);
                }

                ImageView trailerThumbnail = (ImageView) mActivity.getLayoutInflater()
                        .inflate(R.layout.detail_fragment_trailer_item, null, false);
                if (site.compareTo("YouTube") == 0) {
                    Picasso picasso = Picasso.with(mActivity);
                    String youtubeThumbnailPath = String.format("http://img.youtube.com/vi/%s/mqdefault.jpg",
                            key);
                    picasso.load(youtubeThumbnailPath).into(trailerThumbnail);
                    trailerThumbnail.setTag(link);
                    trailerThumbnail.setOnClickListener(this);
                }

                mTrailerList.addView(trailerThumbnail);
            }
        }
    } else if (cursorLoader == mReviewLoader) {
        if (cursor == null || !cursor.moveToFirst()) {
            mReviewListTitle.setVisibility(View.INVISIBLE);
        } else {
            mReviewListTitle.setVisibility(View.VISIBLE);
            String colors[] = { "#00BFFF", "#00CED1", "#FF8C00", "#00FA9A", "#9400D3" };
            for (cursor.moveToFirst(); cursor.getPosition() < cursor.getCount(); cursor.moveToNext()) {
                int columnIndexAuthor = cursor.getColumnIndex(MovieContract.ReviewsTable.COLUMN_AUTHOR);
                String author = cursor.getString(columnIndexAuthor);
                String authorAbbreviation = author != null && author.length() >= 1 ? author.substring(0, 1)
                        : "?";

                int columnIndexReviewText = cursor
                        .getColumnIndex(MovieContract.ReviewsTable.COLUMN_REVIEW_TEXT);
                String reviewText = cursor.getString(columnIndexReviewText);

                RelativeLayout review = (RelativeLayout) mActivity.getLayoutInflater()
                        .inflate(R.layout.detail_fragment_review_item, null, false);
                review.setOnClickListener(this);
                review.setTag(TAG_REVIEW_COLLAPSED);

                TextView authorIcon = (TextView) review.findViewById(R.id.author_icon);
                authorIcon.setText(authorAbbreviation);
                int color = Color.parseColor(colors[cursor.getPosition() % colors.length]);
                authorIcon.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY);

                TextView authorFullName = (TextView) review.findViewById(R.id.author_full_name);
                authorFullName.setText(author);

                TextView reviewTextView = (TextView) review.findViewById(R.id.review_text);
                reviewTextView.setText(reviewText);

                mReviewList.addView(review);
            }
        }
    }
}

From source file:com.pentacog.mctracker.ServerListAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    RelativeLayout serverView = null;
    ServerViewHolder holder = null;//w  w  w.ja  v a 2s  .c o  m
    Server server = serverList.get(position);
    server.id = position;
    if (convertView == null) {
        serverView = (RelativeLayout) LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item,
                parent, false);
        holder = new ServerViewHolder((int) getItemId(position), serverView);
        serverView.setTag(holder);
    } else {
        serverView = (RelativeLayout) convertView;
        holder = (ServerViewHolder) serverView.getTag();
        holder.id = (int) getItemId(position);
    }

    //set server name
    holder.serverTitle.setText(server.name);
    //set server IP
    String serverName = server.address.toString();
    if (!serverName.startsWith("/")) {
        int index = serverName.lastIndexOf('/');
        if (index != -1) {
            String tempString;
            tempString = serverName.substring(index + 1);
            serverName = serverName.substring(0, index);
            serverName += " " + tempString;
        }
    } else {
        serverName = serverName.replace("/", "");
    }
    if (server.port != 25565)
        serverName += ":" + server.port;
    holder.serverIp.setText(serverName);

    //set fav icon
    if (server.favorite) {
        holder.favStar.setVisibility(View.VISIBLE);
    } else {
        holder.favStar.setVisibility(View.INVISIBLE);
    }

    if (!server.queried) {
        AlphaAnimation a = new AlphaAnimation(1.0f, 0.2f);
        a.setRepeatCount(Animation.INFINITE);
        a.setRepeatMode(Animation.REVERSE);
        a.setDuration(300);
        holder.statusBar.setBackgroundColor(Color.BLUE);
        holder.statusBar.startAnimation(a);

        //         holder.loading.setVisibility(View.VISIBLE);
        holder.playerCount.setText("" + server.playerCount + "/" + server.maxPlayers);
        holder.serverData.setText(R.string.loading);
        holder.playerCount.setVisibility(View.INVISIBLE);
        holder.ping.setVisibility(View.INVISIBLE);
        new ServerViewUpdater(serverView, server);
    } else {
        setupServerCell(server, holder);
    }

    return serverView;
}

From source file:com.mycompany.popularmovies.DetailActivity.DetailFragment.java

@Override
public void onClick(View v) {
    if (v.getId() == R.id.favorite) {
        Uri uri = MovieContract.MovieTable.CONTENT_URI;
        ContentResolver resolver = mActivity.getContentResolver();
        Cursor favoriteStatusCursor = resolver.query(uri,
                new String[] { MovieContract.MovieTable.COLUMN_FAVORITED },
                MovieContract.MovieTable._ID + "== ?", new String[] { Integer.toString(mMovieId) }, null);
        if (favoriteStatusCursor != null && favoriteStatusCursor.moveToFirst()) {
            Integer favoriteStatus = favoriteStatusCursor
                    .getInt(favoriteStatusCursor.getColumnIndex(MovieContract.MovieTable.COLUMN_FAVORITED));
            Integer flippedFavoriteStatus = favoriteStatus == 0 ? 1 : 0;
            ContentValues updateFavoriteStatusValues = new ContentValues();
            updateFavoriteStatusValues.put(MovieContract.MovieTable.COLUMN_FAVORITED, flippedFavoriteStatus);
            resolver.update(uri, updateFavoriteStatusValues, MovieContract.MovieTable._ID + " == ?",
                    new String[] { Integer.toString(mMovieId) });
            favoriteStatusCursor.close();
        }//from ww w .  j  a v a  2  s.c o m
    } else if (v.getId() == R.id.trailer_thumbnail) {
        String link = (String) v.getTag();
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)));
    } else if (v.getId() == R.id.review) {
        final RelativeLayout reviewItem = (RelativeLayout) v;
        final TextView author = (TextView) v.findViewById(R.id.author_full_name);
        final TextView review = (TextView) v.findViewById(R.id.review_text);

        if (reviewItem.getTag() == DetailFragment.TAG_REVIEW_COLLAPSED) {
            author.setVisibility(View.VISIBLE);
            review.setMaxLines(Integer.MAX_VALUE);
            new Handler().post(new Runnable() {
                @Override
                public void run() {
                    int excess = mReviewList.getTop() + reviewItem.getBottom()
                            - (mScrollView.getScrollY() + mScrollView.getHeight());
                    if (excess > 0) {
                        if (reviewItem.getHeight() <= mScrollView.getHeight()) {
                            mScrollView.smoothScrollBy(0, excess);
                        } else {
                            mScrollView.smoothScrollTo(0, mReviewList.getTop() + reviewItem.getTop());
                        }
                    }
                }
            });
            reviewItem.setTag(DetailFragment.TAG_REVIEW_EXPANDED);
        } else {
            author.setVisibility(View.GONE);
            review.setMaxLines(REVIEW_MAXLINES);
            reviewItem.setTag(DetailFragment.TAG_REVIEW_COLLAPSED);
        }
    }
}