Example usage for android.widget ImageView getWidth

List of usage examples for android.widget ImageView getWidth

Introduction

In this page you can find the example usage for android.widget ImageView getWidth.

Prototype

@ViewDebug.ExportedProperty(category = "layout")
public final int getWidth() 

Source Link

Document

Return the width of your view.

Usage

From source file:github.popeen.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) {
        Collections.reverse(entries);
        titleView.setText(podcastName);//from  ww  w  .jav  a 2 s  .  com
        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>();
    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;
            }
        }
    }
    String artistName = "";
    bookDescription = "Could not collect any info about the book at this time";
    try {

        artistName = artists.iterator().next();
        String endpoint = "getBookDirectory";
        if (Util.isTagBrowsing(context)) {
            endpoint = "getBook";
        }
        SharedPreferences prefs = Util.getPreferences(context);
        String url = Util.getRestUrl(context, endpoint) + "&id=" + directory.getId() + "&f=json";

        Log.w("GetInfo", url);
        String artist, title;
        int year = 0;
        artist = title = "";

        try {
            artist = artists.iterator().next();
        } catch (Exception e) {
            Log.w("GetInfoArtist", e.toString());
        }
        try {
            title = titleView.getText().toString();
        } catch (Exception e) {
            Log.w("GetInfoTitle", e.toString());
        }
        try {
            year = years.iterator().next();
        } catch (Exception e) {
            Log.w("GetInfoYear", e.toString());
        }

        BookInfoAPIParams params = new BookInfoAPIParams(url, artist, title, year);
        bookInfo = new BookInfoAPI(context).execute(params).get();
        bookDescription = bookInfo[0];
        bookReader = bookInfo[1];

    } catch (Exception e) {
        Log.w("GetInfoError", e.toString());
    }
    if (bookDescription.equals("noInfo")) {
        bookDescription = "The server has no description for this book";
    }

    final TextView artistView = (TextView) header.findViewById(R.id.select_album_artist);
    if (podcastDescription != null || artistInfo != null || bookDescription != null) {
        artistView.setVisibility(View.VISIBLE);

        String text = "";
        if (bookDescription != null) {
            text = bookDescription;
        }
        if (podcastDescription != null) {
            text = podcastDescription;
        }
        if (artistInfo != null) {
            text = artistInfo.getBiography();
        }
        Spanned spanned = null;
        if (text != null) {
            String newText = "";
            try {
                if (!artistName.equals("")) {
                    newText += "<b>" + context.getResources().getString(R.string.main_artist) + "</b>: "
                            + artistName + "<br/>";
                }
            } catch (Exception e) {
            }
            try {
                if (totalDuration > 0) {
                    newText += "<b>" + context.getResources().getString(R.string.album_book_reader) + "</b>: "
                            + bookReader + "<br/>";
                }
            } catch (Exception e) {
            }
            try {
                if (totalDuration > 0) {
                    newText += "<b>" + context.getResources().getString(R.string.album_book_length) + "</b>: "
                            + Util.formatDuration(totalDuration) + "<br/>";
                }
            } catch (Exception e) {
            }
            try {
                newText += text + "<br/>";
            } catch (Exception e) {
            }
            spanned = Html.fromHtml(newText);
        }

        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) + 1;

                    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.setVisibility(View.GONE);
        songLengthView.setVisibility(View.GONE);
    }
}

From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java

private void processFrame() {
    long newTime = System.currentTimeMillis();
    long time = newTime - mLastTime;

    boolean end = false;

    if (time > 60) {
        Log.e("LONG", "Frame time took too long! Time: " + time + " Last process frame: " + mLastFrameTime
                + " Count: " + mBackgroundCount + " Level: " + mLevel);
    }/*w ww.  j av a2 s  .  c  o  m*/

    // We don't want to jump too far so, if real time is > 60 treat it as 33.  On screen will seem to slow
    // down instaead of "jump"
    if (time > 60) {
        time = 33;
    }

    // Score is based on time + presents.  Right now 100 point per second played.  No presents yet
    if (mLevel < 6) {
        mScore += time;
    }

    if (mIsTv) {
        mScoreText.setText(mScoreLabel + ": " + NumberFormat.getNumberInstance().format((mScore / 10)));
    } else {
        mScoreText.setText(NumberFormat.getNumberInstance().format((mScore / 10)));
    }

    float scroll = mElfVelX * time;

    // Do collision detection first...
    // The elf can't collide if it is within 2 seconds of colliding previously.
    if (mElfIsHit) {
        if ((newTime - mElfHitTime) > 2000) {
            // Move to next state.
            if (mElfState < 4) {
                mElfState++;
                AnalyticsManager.sendEvent(getString(R.string.analytics_screen_rocket),
                        getString(R.string.analytics_action_rocket_hit), null, mElfState);
                if (mElfState == 4) {
                    mSoundPool.play(mGameOverSound, 1.0f, 1.0f, 2, 0, 1.0f);
                    // No more control...
                    mControlView.setOnTouchListener(null);
                    mElfAccelY = 0.0f;
                    if (mJetThrustStream != 0) {
                        mSoundPool.stop(mJetThrustStream);
                    }
                }
            }
            updateElf(false);
            mElfIsHit = false;
        }
    } else if (mElfState == 4) {
        // Don't do any collision detection for parachute elf.  Just let him fall...
    } else {
        // Find the obstacle(s) we might be colliding with.  It can only be one of the first 3 obstacles.
        for (int i = 0; i < 3; i++) {
            View view = mObstacleLayout.getChildAt(i);
            if (view == null) {
                // No more obstacles...
                break;
            }

            int[] tmp = new int[2];
            view.getLocationOnScreen(tmp);

            // If the start of this view is past the center of the elf, we are done
            if (tmp[0] > mElfPosX) {
                break;
            }

            if (RelativeLayout.class.isInstance(view)) {
                // this is an obstacle layout.
                View topView = view.findViewById(R.id.top_view);
                View bottomView = view.findViewById(R.id.bottom_view);
                if ((topView != null) && topView.getVisibility() == View.VISIBLE) {
                    topView.getLocationOnScreen(tmp);
                    Rect obsRect = new Rect(tmp[0], tmp[1], tmp[0] + topView.getWidth(),
                            tmp[1] + topView.getHeight());
                    if (obsRect.contains((int) mElfPosX, (int) mElfPosY + mElfBitmap.getHeight() / 2)) {
                        handleCollision();
                    }
                }
                if (!mElfIsHit) {
                    if ((bottomView != null) && bottomView.getVisibility() == View.VISIBLE) {
                        bottomView.getLocationOnScreen(tmp);
                        Rect obsRect = new Rect(tmp[0], tmp[1], tmp[0] + bottomView.getWidth(),
                                tmp[1] + bottomView.getHeight());
                        if (obsRect.contains((int) mElfPosX, (int) mElfPosY + mElfBitmap.getHeight() / 2)) {
                            // Special case for the mammoth obstacle...
                            if (bottomView.getTag() != null) {
                                if (((mElfPosX - tmp[0]) / (float) bottomView.getWidth()) > 0.25f) {
                                    // We are over the mammoth not the spike.  lower the top of the rect and test again.
                                    obsRect.top = (int) (tmp[1] + ((float) bottomView.getHeight() * 0.18f));
                                    if (obsRect.contains((int) mElfPosX,
                                            (int) mElfPosY + mElfBitmap.getHeight() / 2)) {
                                        handleCollision();
                                    }
                                }
                            } else {
                                handleCollision();
                            }
                        }
                    }
                }
            } else if (FrameLayout.class.isInstance(view)) {
                // Present view
                FrameLayout frame = (FrameLayout) view;
                if (frame.getChildCount() > 0) {
                    ImageView presentView = (ImageView) frame.getChildAt(0);
                    presentView.getLocationOnScreen(tmp);
                    Rect presentRect = new Rect(tmp[0], tmp[1], tmp[0] + presentView.getWidth(),
                            tmp[1] + presentView.getHeight());
                    mElfLayout.getLocationOnScreen(tmp);
                    Rect elfRect = new Rect(tmp[0], tmp[1], tmp[0] + mElfLayout.getWidth(),
                            tmp[1] + mElfLayout.getHeight());
                    if (elfRect.intersect(presentRect)) {
                        // We got a present!
                        mPresentCount++;
                        if (mPresentCount < 4) {
                            mSoundPool.play(mScoreSmallSound, 1.0f, 1.0f, 2, 0, 1.0f);
                            mScore += 1000; // 100 points.  Score is 10x displayed score.
                            mPlus100.setVisibility(View.VISIBLE);
                            if (mElfPosY > (mScreenHeight / 2)) {
                                mPlus100.setY(mElfPosY - (mElfLayout.getHeight() + mPlus100.getHeight()));
                            } else {
                                mPlus100.setY(mElfPosY + mElfLayout.getHeight());
                            }
                            mPlus100.setX(mElfPosX);
                            if (m100Anim.hasStarted()) {
                                m100Anim.reset();
                            }
                            mPlus100.startAnimation(m100Anim);
                        } else {
                            mSoundPool.play(mScoreBigSound, 1.0f, 1.0f, 2, 0, 1.0f);
                            mScore += 5000; // 500 points.  Score is 10x displayed score.
                            if (!mRainingPresents) {
                                mPresentCount = 0;
                            }
                            mPlus500.setVisibility(View.VISIBLE);
                            if (mElfPosY > (mScreenHeight / 2)) {
                                mPlus500.setY(mElfPosY - (mElfLayout.getHeight() + mPlus100.getHeight()));
                            } else {
                                mPlus500.setY(mElfPosY + mElfLayout.getHeight());
                            }
                            mPlus500.setX(mElfPosX);
                            if (m500Anim.hasStarted()) {
                                m500Anim.reset();
                            }
                            mPlus500.startAnimation(m500Anim);
                            mPresentBonus = true;
                        }
                        frame.removeView(presentView);
                    } else if (elfRect.left > presentRect.right) {
                        mPresentCount = 0;
                    }
                }
            }
        }
    }

    if (mForegroundLayout.getChildCount() > 0) {
        int currentX = mForegroundScroll.getScrollX();
        View view = mForegroundLayout.getChildAt(0);
        int newX = currentX + (int) scroll;
        if (newX > view.getWidth()) {
            newX -= view.getWidth();
            mForegroundLayout.removeViewAt(0);
        }
        mForegroundScroll.setScrollX(newX);
    }

    // Scroll obstacle views
    if (mObstacleLayout.getChildCount() > 0) {
        int currentX = mObstacleScroll.getScrollX();
        View view = mObstacleLayout.getChildAt(0);
        int newX = currentX + (int) scroll;
        if (newX > view.getWidth()) {
            newX -= view.getWidth();
            mObstacleLayout.removeViewAt(0);
        }
        mObstacleScroll.setScrollX(newX);
    }

    // Scroll the background and foreground
    if (mBackgroundLayout.getChildCount() > 0) {
        int currentX = mBackgroundScroll.getScrollX();
        View view = mBackgroundLayout.getChildAt(0);
        int newX = currentX + (int) scroll;
        if (newX > view.getWidth()) {
            newX -= view.getWidth();
            mBackgroundLayout.removeViewAt(0);
            if (view.getTag() != null) {
                Pair<Integer, Integer> pair = (Pair<Integer, Integer>) view.getTag();
                int type = pair.first;
                int level = pair.second;
                if (type == 0) {
                    if (mBackgrounds[level] != null) {
                        mBackgrounds[level].recycle();
                        mBackgrounds[level] = null;
                    } else if (mBackgrounds2[level] != null) {
                        mBackgrounds2[level].recycle();
                        mBackgrounds2[level] = null;
                    }
                } else if (type == 1) {
                    if (mExitTransitions[level] != null) {
                        mExitTransitions[level].recycle();
                        mExitTransitions[level] = null;
                    }
                } else if (type == 2) {
                    if (mEntryTransitions[level] != null) {
                        mEntryTransitions[level].recycle();
                        mEntryTransitions[level] = null;
                    }
                }
            }
            if (mBackgroundCount == 5) {
                if (mLevel < 6) {
                    // Pre-fetch next levels backgrounds
                    // end level uses the index 1 background...
                    int level = (mLevel == 5) ? 1 : (mLevel + 1);
                    BackgroundLoadTask task = new BackgroundLoadTask(getResources(), mLevel + 1,
                            BACKGROUNDS[level], EXIT_TRANSITIONS[mLevel],
                            // Exit transitions are for the current level...
                            ENTRY_TRANSITIONS[level], mScaleX, mScaleY, mBackgrounds, mBackgrounds2,
                            mExitTransitions, mEntryTransitions, mScreenWidth, mScreenHeight);
                    task.execute();
                    addNextImages(mLevel, true);
                    addNextObstacles(mLevel, 2);
                }
                // Fetch first set of obstacles if the next level changes from woods to cave or cave to factory
                if (mLevel == 1) {
                    // Next level will be caves.  Get bitmaps for the first 20 obstacles.
                    ObstacleLoadTask task = new ObstacleLoadTask(getResources(), CAVE_OBSTACLES, mCaveObstacles,
                            mCaveObstacleList, 0, 2, mScaleX, mScaleY);
                    task.execute();
                } else if (mLevel == 3) {
                    // Next level will be factory.  Get bitmaps for the first 20 obstacles.
                    ObstacleLoadTask task = new ObstacleLoadTask(getResources(), FACTORY_OBSTACLES,
                            mFactoryObstacles, mFactoryObstacleList, 0, 2, mScaleX, mScaleY);
                    task.execute();
                }
                mBackgroundCount++;
            } else if (mBackgroundCount == 7) {
                // Add transitions and/or next level
                if (mLevel < 5) {
                    addNextTransitionImages(mLevel + 1);
                    if (mTransitionImagesCount > 0) {
                        addNextObstacleSpacer(mTransitionImagesCount);
                    }
                    addNextImages(mLevel + 1);
                    // First screen of each new level has no obstacles
                    if ((mLevel % 2) == 1) {
                        addNextObstacleSpacer(1);
                        addNextObstacles(mLevel + 1, 1);
                    } else {
                        addNextObstacles(mLevel + 1, 2);
                    }
                } else if (mLevel == 5) {
                    addNextTransitionImages(mLevel + 1);
                    if (mTransitionImagesCount > 0) {
                        addNextObstacleSpacer(mTransitionImagesCount);
                    }
                    addFinalImages();
                }
                mBackgroundCount++;
            } else if (mBackgroundCount == 9) {
                // Either the transition or the next level is showing
                if (this.mTransitionImagesCount > 0) {
                    mTransitionImagesCount--;
                } else {
                    if (mLevel == 1) {
                        // Destroy the wood obstacle bitmaps
                        Thread thread = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                synchronized (mWoodObstacles) {
                                    for (Bitmap bmp : mWoodObstacles.values()) {
                                        bmp.recycle();
                                    }
                                    mWoodObstacles.clear();
                                }
                            }
                        });
                        thread.start();
                    } else if (mLevel == 3) {
                        // Destroy the cave obstacle bitmaps
                        Thread thread = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                synchronized (mCaveObstacles) {
                                    for (Bitmap bmp : mCaveObstacles.values()) {
                                        bmp.recycle();
                                    }
                                    mCaveObstacles.clear();
                                }
                            }
                        });
                        thread.start();
                    } else if (mLevel == 5) {
                        // Destroy the factory obstacle bitmaps
                        Thread thread = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                synchronized (mFactoryObstacles) {
                                    for (Bitmap bmp : mFactoryObstacles.values()) {
                                        bmp.recycle();
                                    }
                                    mFactoryObstacles.clear();
                                }
                            }
                        });
                        thread.start();
                    }
                    mLevel++;

                    // Add an event for clearing this level - note we don't increment mLevel as
                    // it's 0-based and we're tracking the previous level.
                    AnalyticsManager.sendEvent(getString(R.string.analytics_screen_rocket),
                            getString(R.string.analytics_action_rocket_level), null, mLevel);

                    // Achievements
                    if (!mHitLevel) {
                        mCleanLevel = true;
                    }
                    mHitLevel = false;
                    if (mLevel == 5) {
                        mPlus100.setSelected(true);
                        mPlus500.setSelected(true);
                    } else if (mLevel == 6) {
                        mPlus100.setSelected(false);
                        mPlus500.setSelected(false);
                    }
                    if (mLevel < 6) {
                        mSoundPool.play(mLevelUpSound, 1.0f, 1.0f, 2, 0, 1.0f);
                        addNextImages(mLevel);
                        addNextObstacles(mLevel, 2);
                    }
                    mBackgroundCount = 0;
                }
            } else {
                if ((mBackgroundCount % 2) == 1) {
                    if (mLevel < 6) {
                        addNextImages(mLevel);
                        addNextObstacles(mLevel, 2);
                    }
                }
                mBackgroundCount++;
            }
        }
        int current = mBackgroundScroll.getScrollX();
        mBackgroundScroll.setScrollX(newX);
        if ((mLevel == 6) && (mBackgroundScroll.getScrollX() == current)) {
            end = true;
        }
    }

    // Check on the elf
    boolean hitBottom = false;
    boolean hitTop = false;

    float deltaY = mElfVelY * time;
    mElfPosY = mElfLayout.getY() + deltaY;
    if (mElfPosY < 0.0f) {
        mElfPosY = 0.0f;
        mElfVelY = 0.0f;
        hitTop = true;
    } else if (mElfPosY > (mScreenHeight - mElfLayout.getHeight())) {
        mElfPosY = mScreenHeight - mElfLayout.getHeight();
        mElfVelY = 0.0f;
        hitBottom = true;
    } else {
        // Remember -Y is up!
        mElfVelY += (mGravityAccelY * time - mElfAccelY * time);
    }
    mElfLayout.setY(mElfPosY);

    // Rotate the elf to indicate thrust, dive.
    float rot = (float) (Math.atan(mElfVelY / mElfVelX) * 120.0 / Math.PI);
    mElfLayout.setRotation(rot);

    mElf.invalidate();

    // Update the time and spawn the next call to processFrame.
    mLastTime = newTime;
    mLastFrameTime = System.currentTimeMillis() - newTime;
    if (!end) {
        if ((mElfState < 4) || !hitBottom) {
            if (mLastFrameTime < 16) {
                mHandler.postDelayed(mGameLoop, 16 - mLastFrameTime);
            } else {
                mHandler.post(mGameLoop);
            }
        } else {
            endGame();
        }
    } else {
        // Whatever the final stuff is, do it here.
        mPlayPauseButton.setEnabled(false);
        mPlayPauseButton.setVisibility(View.INVISIBLE);
        endGame();
    }
}

From source file:self.philbrown.droidQuery.Example.ExampleActivity.java

/**
 * Refreshes the list of cells containing App.net messages. This <em>ListView</em> is actually
 * a <em>scrollable LinearLayout</em>, and is assembled in much the same way a layout would be
 * made using <em>JavaScript</em>, with the <em>CSS3</em> attribute <em>overscroll-y: scroll</em>.
 * <br>/*  w ww .j  a v a2 s . com*/
 * For this example, the public stream is retrieved using <em>ajax</em>, and for each message
 * received, a new cell is created. For each cell, a new <em>ajax</em> request is started to
 * retrieve the thumbnail image for the user. As all these events occur on a background thread, the
 * main ScrollView is populated with cells and displayed to the user.
 * <br>
 * The stream <em>JSON</em> request is performed in a <em>global ajax</em> request, which will
 * trigger the global start and stop events (which show a progress indicator, using a droidQuery
 * extension). The image get requests are not global, so they will not trigger global events.
 */
public void refresh() {
    $.ajax(new AjaxOptions().url("https://alpha-api.app.net/stream/0/posts/stream/global").dataType("json")
            .type("GET").error(new Function() {
                @Override
                public void invoke($ droidQuery, Object... params) {
                    //Object error, int status, String reason
                    Object error = params[0];
                    int status = (Integer) params[1];
                    String reason = (String) params[2];
                    Log.w("app.net Client", "Could not complete request: " + reason);
                }
            }).success(new Function() {
                @Override
                public void invoke($ droidQuery, Object... params) {
                    //Object, reason
                    JSONObject json = (JSONObject) params[0];
                    String reason = (String) params[1];
                    try {
                        Map<String, ?> map = $.map(json);
                        JSONArray datas = (JSONArray) map.get("data");

                        if (datas.length() != 0) {
                            //clear old subviews in layout
                            $.with(ExampleActivity.this, R.id.example_layout).selectChildren().remove();

                            //get each message infos and create a cell
                            for (int i = 0; i < datas.length(); i++) {
                                JSONObject jdata = (JSONObject) datas.get(i);
                                Map<String, ?> data = $.map(jdata);

                                String text = data.get("text").toString();

                                Map<String, ?> user = $.map((JSONObject) data.get("user"));

                                String username = user.get("username").toString();
                                String avatarURL = ((JSONObject) user.get("avatar_image")).getString("url");

                                //get Avatar image in a new task (but go ahead and create the cell for now)
                                LinearLayout cell = new LinearLayout(ExampleActivity.this);
                                LinearLayout.LayoutParams cell_params = new LinearLayout.LayoutParams(
                                        LinearLayout.LayoutParams.MATCH_PARENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                cell_params.bottomMargin = 5;
                                cell.setLayoutParams(cell_params);
                                cell.setOrientation(LinearLayout.HORIZONTAL);
                                cell.setWeightSum(8);
                                cell.setPadding(5, 5, 5, 5);
                                cell.setBackgroundColor(Color.parseColor("#333333"));
                                final LinearLayout fcell = cell;

                                //contains the image location
                                ImageView image = new ImageView(ExampleActivity.this);
                                image.setId(99);
                                LinearLayout.LayoutParams ip_params = new LinearLayout.LayoutParams(0,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                ip_params.weight = 2;
                                image.setLayoutParams(ip_params);
                                image.setPadding(0, 0, 5, 0);
                                $.with(image).attr("alpha", 0.0f);
                                cell.addView(image);
                                final ImageView fimage = image;

                                //the text location in the cell
                                LinearLayout body = new LinearLayout(ExampleActivity.this);
                                LinearLayout.LayoutParams body_params = new LinearLayout.LayoutParams(0,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                body_params.weight = 5;
                                body.setLayoutParams(body_params);
                                body.setOrientation(LinearLayout.VERTICAL);
                                body.setGravity(Gravity.CENTER_VERTICAL);
                                cell.addView(body);

                                //the username
                                TextView name = new TextView(ExampleActivity.this);
                                LinearLayout.LayoutParams name_params = new LinearLayout.LayoutParams(
                                        LinearLayout.LayoutParams.WRAP_CONTENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                name.setLayoutParams(name_params);
                                name.setTextColor(Color.GRAY);
                                name.setText(username);
                                body.addView(name);

                                //the message
                                TextView message = new TextView(ExampleActivity.this);
                                LinearLayout.LayoutParams msg_params = new LinearLayout.LayoutParams(
                                        LinearLayout.LayoutParams.WRAP_CONTENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                message.setLayoutParams(msg_params);
                                message.setTextColor(Color.WHITE);
                                message.setTextSize(18);
                                message.setText(text);
                                body.addView(message);

                                CheckBox checkbox = new CheckBox(ExampleActivity.this);
                                LinearLayout.LayoutParams box_params = new LinearLayout.LayoutParams(0,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                box_params.weight = 1;
                                checkbox.setLayoutParams(box_params);

                                cell.addView(checkbox);

                                $.with(ExampleActivity.this, R.id.example_layout).add(cell);
                                //$.with(fimage).image(avatarURL, 200, 200, $.noop());
                                $.ajax(new AjaxOptions(avatarURL).type("GET").dataType("image").imageHeight(200)
                                        .imageWidth(200).global(false).success(new Function() {
                                            @Override
                                            public void invoke($ droidQuery, Object... params) {
                                                //Object, reason
                                                Bitmap src = (Bitmap) params[0];
                                                String reason = (String) params[1];
                                                $.with(fimage).val(src);
                                                try {
                                                    $.with(fimage)
                                                            .fadeIn(new AnimationOptions("{ duration: 400 }"));
                                                } catch (Throwable e) {
                                                    e.printStackTrace();
                                                }
                                                LinearLayout.LayoutParams lparams = (LinearLayout.LayoutParams) fcell
                                                        .getLayoutParams();
                                                try {
                                                    lparams.height = Math.min(src.getWidth(),
                                                            fimage.getWidth());
                                                } catch (Throwable t) {
                                                    //ignore NPE
                                                }

                                                fcell.setLayoutParams(lparams);
                                            }
                                        }).error(new Function() {
                                            @Override
                                            public void invoke($ droidQuery, Object... params) {
                                                //Object error, int status, String reason
                                                Object error = params[0];
                                                int status = (Integer) params[1];
                                                String reason = (String) params[2];
                                                Log.w("app.net Client",
                                                        "Could not complete image request: " + reason);
                                            }
                                        }));

                            }
                        } else {
                            Log.w("app.net client", "could not update data");
                        }
                    } catch (Throwable t) {
                        t.printStackTrace();
                    }
                }
            }));
}