Example usage for android.widget RelativeLayout getTag

List of usage examples for android.widget RelativeLayout getTag

Introduction

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

Prototype

@ViewDebug.ExportedProperty
public Object getTag() 

Source Link

Document

Returns this view's tag.

Usage

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 w w 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);
        }
    }
}

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

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

    RelativeLayout serverView = null;
    ServerViewHolder holder = null;/*from ww  w.jav a2  s . 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;
}