Example usage for android.widget LinearLayout removeAllViews

List of usage examples for android.widget LinearLayout removeAllViews

Introduction

In this page you can find the example usage for android.widget LinearLayout removeAllViews.

Prototype

public void removeAllViews() 

Source Link

Document

Call this method to remove all child views from the ViewGroup.

Usage

From source file:org.quantumbadger.redreader.activities.ImageViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    final boolean solidblack = PrefsUtility.appearance_solidblack(this, sharedPreferences);

    if (solidblack)
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK));

    final Intent intent = getIntent();

    mUrl = General.uriFromString(intent.getDataString());
    final RedditPost src_post = intent.getParcelableExtra("post");

    if (mUrl == null) {
        General.quickToast(this, "Invalid URL. Trying web browser.");
        revertToWeb();/*  www  .  ja  v  a2 s. co m*/
        return;
    }

    Log.i("ImageViewActivity", "Loading URL " + mUrl.toString());

    final ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);

    final LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(progressBar);

    CacheManager.getInstance(this)
            .makeRequest(mRequest = new CacheRequest(mUrl, RedditAccountManager.getAnon(), null,
                    Constants.Priority.IMAGE_VIEW, 0, CacheRequest.DownloadType.IF_NECESSARY,
                    Constants.FileType.IMAGE, false, false, false, this) {

                private void setContentView(View v) {
                    layout.removeAllViews();
                    layout.addView(v);
                    v.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
                    v.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
                }

                @Override
                protected void onCallbackException(Throwable t) {
                    BugReportActivity.handleGlobalError(context.getApplicationContext(),
                            new RRError(null, null, t));
                }

                @Override
                protected void onDownloadNecessary() {
                    AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                        @Override
                        public void run() {
                            progressBar.setVisibility(View.VISIBLE);
                            progressBar.setIndeterminate(true);
                        }
                    });
                }

                @Override
                protected void onDownloadStarted() {
                }

                @Override
                protected void onFailure(final RequestFailureType type, Throwable t, StatusLine status,
                        final String readableMessage) {

                    final RRError error = General.getGeneralErrorForFailure(context, type, t, status,
                            url.toString());

                    AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                        public void run() {
                            // TODO handle properly
                            mRequest = null;
                            progressBar.setVisibility(View.GONE);
                            layout.addView(new ErrorView(ImageViewActivity.this, error));
                        }
                    });
                }

                @Override
                protected void onProgress(final boolean authorizationInProgress, final long bytesRead,
                        final long totalBytes) {
                    AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                        @Override
                        public void run() {
                            progressBar.setVisibility(View.VISIBLE);
                            progressBar.setIndeterminate(authorizationInProgress);
                            progressBar.setProgress((int) ((100 * bytesRead) / totalBytes));
                        }
                    });
                }

                @Override
                protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, long timestamp,
                        UUID session, boolean fromCache, final String mimetype) {

                    if (mimetype == null
                            || (!Constants.Mime.isImage(mimetype) && !Constants.Mime.isVideo(mimetype))) {
                        revertToWeb();
                        return;
                    }

                    final InputStream cacheFileInputStream;
                    try {
                        cacheFileInputStream = cacheFile.getInputStream();
                    } catch (IOException e) {
                        notifyFailure(RequestFailureType.PARSE, e, null,
                                "Could not read existing cached image.");
                        return;
                    }

                    if (cacheFileInputStream == null) {
                        notifyFailure(RequestFailureType.CACHE_MISS, null, null, "Could not find cached image");
                        return;
                    }

                    if (Constants.Mime.isVideo(mimetype)) {

                        AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                            public void run() {

                                if (mIsDestroyed)
                                    return;
                                mRequest = null;

                                try {
                                    final RelativeLayout layout = new RelativeLayout(context);
                                    layout.setGravity(Gravity.CENTER);

                                    final VideoView videoView = new VideoView(ImageViewActivity.this);

                                    videoView.setVideoURI(cacheFile.getUri());
                                    layout.addView(videoView);
                                    setContentView(layout);

                                    layout.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
                                    layout.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
                                    videoView.setLayoutParams(
                                            new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                                    ViewGroup.LayoutParams.MATCH_PARENT));

                                    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                                        @Override
                                        public void onPrepared(MediaPlayer mp) {
                                            mp.setLooping(true);
                                            videoView.start();
                                        }
                                    });

                                    videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                                        @Override
                                        public boolean onError(final MediaPlayer mediaPlayer, final int i,
                                                final int i1) {
                                            revertToWeb();
                                            return true;
                                        }
                                    });

                                    videoView.setOnTouchListener(new View.OnTouchListener() {
                                        @Override
                                        public boolean onTouch(final View view, final MotionEvent motionEvent) {
                                            finish();
                                            return true;
                                        }
                                    });

                                } catch (OutOfMemoryError e) {
                                    General.quickToast(context, R.string.imageview_oom);
                                    revertToWeb();

                                } catch (Throwable e) {
                                    General.quickToast(context, R.string.imageview_invalid_video);
                                    revertToWeb();
                                }
                            }
                        });

                    } else if (Constants.Mime.isImageGif(mimetype)) {

                        final PrefsUtility.GifViewMode gifViewMode = PrefsUtility
                                .pref_behaviour_gifview_mode(context, sharedPreferences);

                        if (gifViewMode == PrefsUtility.GifViewMode.INTERNAL_BROWSER) {
                            revertToWeb();
                            return;

                        } else if (gifViewMode == PrefsUtility.GifViewMode.EXTERNAL_BROWSER) {
                            AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                                @Override
                                public void run() {
                                    LinkHandler.openWebBrowser(ImageViewActivity.this,
                                            Uri.parse(mUrl.toString()));
                                    finish();
                                }
                            });

                            return;
                        }

                        if (AndroidApi.isIceCreamSandwichOrLater()
                                && gifViewMode == PrefsUtility.GifViewMode.INTERNAL_MOVIE) {

                            AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                                public void run() {

                                    if (mIsDestroyed)
                                        return;
                                    mRequest = null;

                                    try {
                                        final GIFView gifView = new GIFView(ImageViewActivity.this,
                                                cacheFileInputStream);
                                        setContentView(gifView);
                                        gifView.setOnClickListener(new View.OnClickListener() {
                                            public void onClick(View v) {
                                                finish();
                                            }
                                        });

                                    } catch (OutOfMemoryError e) {
                                        General.quickToast(context, R.string.imageview_oom);
                                        revertToWeb();

                                    } catch (Throwable e) {
                                        General.quickToast(context, R.string.imageview_invalid_gif);
                                        revertToWeb();
                                    }
                                }
                            });

                        } else {

                            gifThread = new GifDecoderThread(cacheFileInputStream,
                                    new GifDecoderThread.OnGifLoadedListener() {

                                        public void onGifLoaded() {
                                            AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                                                public void run() {

                                                    if (mIsDestroyed)
                                                        return;
                                                    mRequest = null;

                                                    imageView = new ImageView(context);
                                                    imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                                                    setContentView(imageView);
                                                    gifThread.setView(imageView);

                                                    imageView.setOnClickListener(new View.OnClickListener() {
                                                        public void onClick(View v) {
                                                            finish();
                                                        }
                                                    });
                                                }
                                            });
                                        }

                                        public void onOutOfMemory() {
                                            General.quickToast(context, R.string.imageview_oom);
                                            revertToWeb();
                                        }

                                        public void onGifInvalid() {
                                            General.quickToast(context, R.string.imageview_invalid_gif);
                                            revertToWeb();
                                        }
                                    });

                            gifThread.start();

                        }

                    } else {

                        final ImageTileSource imageTileSource;
                        try {

                            final long bytes = cacheFile.getSize();
                            final byte[] buf = new byte[(int) bytes];

                            try {
                                new DataInputStream(cacheFileInputStream).readFully(buf);
                            } catch (IOException e) {
                                throw new RuntimeException(e);
                            }

                            try {
                                imageTileSource = new ImageTileSourceWholeBitmap(buf);

                            } catch (Throwable t) {
                                Log.e("ImageViewActivity", "Exception when creating ImageTileSource", t);
                                General.quickToast(context, R.string.imageview_decode_failed);
                                revertToWeb();
                                return;
                            }

                        } catch (OutOfMemoryError e) {
                            General.quickToast(context, R.string.imageview_oom);
                            revertToWeb();
                            return;
                        }

                        AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                            public void run() {

                                if (mIsDestroyed)
                                    return;
                                mRequest = null;
                                mImageViewDisplayerManager = new ImageViewDisplayListManager(imageTileSource,
                                        ImageViewActivity.this);
                                surfaceView = new RRGLSurfaceView(ImageViewActivity.this,
                                        mImageViewDisplayerManager);
                                setContentView(surfaceView);

                                surfaceView.setOnClickListener(new View.OnClickListener() {
                                    public void onClick(View v) {
                                        finish();
                                    }
                                });

                                if (mIsPaused) {
                                    surfaceView.onPause();
                                } else {
                                    surfaceView.onResume();
                                }
                            }
                        });
                    }
                }
            });

    final RedditPreparedPost post = src_post == null ? null
            : new RedditPreparedPost(this, CacheManager.getInstance(this), 0, src_post, -1, false, false, false,
                    false, RedditAccountManager.getInstance(this).getDefaultAccount(), false);

    final FrameLayout outerFrame = new FrameLayout(this);
    outerFrame.addView(layout);

    if (post != null) {

        final SideToolbarOverlay toolbarOverlay = new SideToolbarOverlay(this);

        final BezelSwipeOverlay bezelOverlay = new BezelSwipeOverlay(this,
                new BezelSwipeOverlay.BezelSwipeListener() {

                    public boolean onSwipe(BezelSwipeOverlay.SwipeEdge edge) {

                        toolbarOverlay.setContents(
                                post.generateToolbar(ImageViewActivity.this, false, toolbarOverlay));
                        toolbarOverlay.show(edge == BezelSwipeOverlay.SwipeEdge.LEFT
                                ? SideToolbarOverlay.SideToolbarPosition.LEFT
                                : SideToolbarOverlay.SideToolbarPosition.RIGHT);
                        return true;
                    }

                    public boolean onTap() {

                        if (toolbarOverlay.isShown()) {
                            toolbarOverlay.hide();
                            return true;
                        }

                        return false;
                    }
                });

        outerFrame.addView(bezelOverlay);
        outerFrame.addView(toolbarOverlay);

        bezelOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
        bezelOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;

        toolbarOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
        toolbarOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;

    }

    setContentView(outerFrame);
}

From source file:com.orange.essentials.otb.ui.OtbContainerFragment.java

/**
 * Add the policy buttons ont appropriate layout
 *//*from w w  w  .ja v a 2  s  .  c  o m*/
private void buildCards() {
    Log.d(TAG, "buildCards");
    LinearLayout dataLayout = null;
    LinearLayout usageLayout = null;
    View containerData = this.getActivity().findViewById(R.id.otb_home_data_card);
    if (null != containerData) {
        containerData.setVisibility(TrustBadgeManager.INSTANCE.hasData() ? View.VISIBLE : View.GONE);
        dataLayout = (LinearLayout) containerData.findViewById(R.id.otb_home_data_card_ll_container);
    }
    View containerUsage = this.getActivity().findViewById(R.id.otb_home_usage_card);
    if (null != containerUsage) {
        containerUsage.setVisibility(TrustBadgeManager.INSTANCE.hasUsage() ? View.VISIBLE : View.GONE);
        usageLayout = (LinearLayout) containerUsage.findViewById(R.id.otb_home_data_card_ll_container);
    }
    View containerTerms = this.getActivity().findViewById(R.id.otb_home_terms_card);
    if (null != containerTerms) {
        containerTerms.setVisibility(TrustBadgeManager.INSTANCE.hasTerms() ? View.VISIBLE : View.GONE);
    }

    if (dataLayout != null && usageLayout != null) {
        dataLayout.removeAllViews();
        usageLayout.removeAllViews();

        List<TrustBadgeElement> trustBadgeElements = TrustBadgeManager.INSTANCE.getTrustBadgeElements();
        if (trustBadgeElements != null) {
            for (TrustBadgeElement trustBadgeElement : trustBadgeElements) {
                Log.d(TAG, trustBadgeElement.toString());

                if (trustBadgeElement.getElementType() == ElementType.MAIN
                        || trustBadgeElement.getElementType() == ElementType.USAGE) {

                    LayoutInflater inflater = (LayoutInflater) getContext()
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    View view = inflater.inflate(R.layout.otb_custom_toggle_button, null);

                    ImageView icon = (ImageView) view.findViewById(R.id.otb_custom_toggle_button_iv_id);
                    icon.setContentDescription(trustBadgeElement.getNameKey());

                    TextView buttonText = (TextView) view.findViewById(R.id.otb_custom_toggle_button_tv_id);
                    if (trustBadgeElement.getGroupType() != GroupType.PEGI) {
                        if ((trustBadgeElement.getAppUsesPermission() == AppUsesPermission.TRUE)
                                || (trustBadgeElement
                                        .getAppUsesPermission() == AppUsesPermission.NOT_SIGNIFICANT)) {
                            if (trustBadgeElement.getUserPermissionStatus() == UserPermissionStatus.GRANTED
                                    || trustBadgeElement
                                            .getUserPermissionStatus() == UserPermissionStatus.MANDATORY) {

                                buttonText
                                        .setText(getResources().getString(R.string.otb_toggle_button_granted));
                                buttonText.setTextColor(getResources().getColor(R.color.colorAccent));
                                icon.setImageDrawable(
                                        getResources().getDrawable(trustBadgeElement.getEnabledIconId()));
                            } else {
                                buttonText.setText(
                                        getResources().getString(R.string.otb_toggle_button_not_granted));
                                buttonText.setTextColor(getResources().getColor(R.color.otb_black));
                                icon.setImageDrawable(
                                        getResources().getDrawable(trustBadgeElement.getDisabledIconId()));
                            }
                        } else {
                            buttonText
                                    .setText(getResources().getString(R.string.otb_toggle_button_not_granted));
                            icon.setImageDrawable(
                                    getResources().getDrawable(trustBadgeElement.getDisabledIconId()));
                        }
                    } else {
                        icon.setImageDrawable(getResources().getDrawable(trustBadgeElement.getEnabledIconId()));
                        buttonText.setText(TrustBadgeManager.INSTANCE.getPegiAge(trustBadgeElement)
                                .concat(getString(R.string.otb_home_usage_pegi_age)));
                        buttonText.setTextColor(getResources().getColor(R.color.otb_black));
                    }

                    if (trustBadgeElement.getElementType() == ElementType.MAIN) {
                        dataLayout.addView(view);
                        view.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                mListener.onDataClick();
                            }
                        });
                    } else {
                        usageLayout.addView(view);
                        view.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                mListener.onUsageClick();
                            }
                        });
                    }
                }
            }
        } else {
            Log.d(TAG, "TrustBadgeElements is null, please add TrustBadgeElements to list");
        }
    }
    Log.d(TAG, "buildCards");
}

From source file:com.xperia64.timidityae.SettingsActivity.java

public void setUpNestedScreen(PreferenceScreen preferenceScreen) {
    final Dialog dialog = preferenceScreen.getDialog();

    Toolbar bar;//from w w  w  .ja va 2  s  .c  o m

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent();
        bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);
        bar.setElevation(abElevation);
        root.addView(bar, 0);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent();
        bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);
        root.addView(bar, 0); // insert at top
    } else {
        ViewGroup root = (ViewGroup) dialog.findViewById(android.R.id.content);
        ListView content = (ListView) root.getChildAt(0);

        root.removeAllViews();

        bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);

        int height;
        TypedValue tv = new TypedValue();
        if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
            height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
        } else {
            height = bar.getHeight();
        }

        content.setPadding(0, height, 0, 0);

        root.addView(content);
        root.addView(bar);
    }

    bar.setTitle(preferenceScreen.getTitle());

    bar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
}

From source file:maimeng.yodian.app.client.android.chat.adapter.MessageAdapter.java

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

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

}

From source file:net.movelab.cmlibrary.MapMyData.java

private void drawDateSelector(long min, long max, Context context) {

    final long barMax = max;
    final long barMin = min;
    final long selectedMax;
    final long selectedMin;

    if (thumbMin == -1 || thumbMin < min)
        selectedMin = Long.valueOf(min);
    else//from  ww  w. java  2s .  co  m
        selectedMin = Long.valueOf(thumbMin);
    if (thumbMax == -1 || thumbMax > max)
        selectedMax = Long.valueOf(max);
    else
        selectedMax = Long.valueOf(thumbMax);

    drawFixes(mPoints, selectedMin, selectedMax, satToggle, true, true);

    if (PropertyHolder.getLimitEndDate())
        dateRangeText
                .setText(Util.userDate(new Date(selectedMin)) + " - " + Util.userDate(new Date(selectedMax)));
    else
        dateRangeText.setText(
                Util.userDate(new Date(selectedMin)) + " - " + getResources().getString(R.string.present));

    if (Build.VERSION.SDK_INT >= 5) {
        RangeSeekBar<Long> seekBar = new RangeSeekBar<Long>(min, max, context);

        seekBar.setSelectedMinValue(selectedMin);
        seekBar.setSelectedMaxValue(selectedMax);

        seekBar.setNotifyWhileDragging(true);

        seekBar.setOnRangeSeekBarChangeListener(new OnRangeSeekBarChangeListener<Long>() {
            @Override
            public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Long minValue, Long maxValue) {

                drawFixes(mPoints, minValue, maxValue, satToggle, true, false);

                if (maxValue < barMax) {
                    thumbMax = Long.valueOf(maxValue);
                    dateRangeText.setText(
                            Util.userDate(new Date(minValue)) + " - " + Util.userDate(new Date(maxValue)));
                } else {
                    thumbMax = -1;
                    if (PropertyHolder.getLimitEndDate())
                        dateRangeText.setText(
                                Util.userDate(new Date(minValue)) + " - " + Util.userDate(new Date(maxValue)));
                    else
                        dateRangeText.setText(Util.userDate(new Date(minValue)) + " - "
                                + getResources().getString(R.string.present));
                }
            }
        });

        // add RangeSeekBar to pre-defined layout
        LinearLayout dateSelectorArea = (LinearLayout) findViewById(R.id.dateSelectorArea);
        dateSelectorArea.removeAllViews();
        dateSelectorArea.addView(seekBar);

    } else {
        RangeSeekBarDonut<Long> seekBar = new RangeSeekBarDonut<Long>(min, max, context);

        seekBar.setSelectedMinValue(selectedMin);
        seekBar.setSelectedMaxValue(selectedMax);

        seekBar.setNotifyWhileDragging(true);

        seekBar.setOnRangeSeekBarDonutChangeListener(new OnRangeSeekBarDonutChangeListener<Long>() {
            @Override
            public void onRangeSeekBarDonutValuesChanged(RangeSeekBarDonut<?> bar, Long minValue,
                    Long maxValue) {

                drawFixes(mPoints, minValue, maxValue, satToggle, true, false);

                if (maxValue < barMax) {
                    thumbMax = Long.valueOf(maxValue);
                    dateRangeText.setText(
                            Util.userDate(new Date(minValue)) + " - " + Util.userDate(new Date(maxValue)));
                } else {
                    thumbMax = -1;
                    if (PropertyHolder.getLimitEndDate())
                        dateRangeText.setText(
                                Util.userDate(new Date(minValue)) + " - " + Util.userDate(new Date(maxValue)));
                    else
                        dateRangeText.setText(Util.userDate(new Date(minValue)) + " - "
                                + getResources().getString(R.string.present));
                }
            }
        });

        // add RangeSeekBar to pre-defined layout
        LinearLayout dateSelectorArea = (LinearLayout) findViewById(R.id.dateSelectorArea);
        dateSelectorArea.removeAllViews();
        dateSelectorArea.addView(seekBar);

    }
}

From source file:com.sdspikes.fireworks.FireworksActivity.java

private void displayDiscardPiles() {
    LinearLayout currRow = ((LinearLayout) findViewById(R.id.discard_pile_row_1));
    LinearLayout row2 = ((LinearLayout) findViewById(R.id.discard_pile_row_2));
    currRow.removeAllViews();
    row2.removeAllViews();/*from   w  ww.  j  av a  2s . c om*/
    int maxInTopRow = mDiscardWidthR1 / MIN_CARD_WIDTH;

    int rowDivision = mTurnData.state.discarded.length;
    int totalDiscarded = 0;
    int topRow = 0;
    for (int i = 0; i < mTurnData.state.discarded.length; i++) {
        totalDiscarded += mTurnData.state.discarded[i].size();
        if (totalDiscarded <= maxInTopRow) {
            topRow = totalDiscarded;
        }
        if (totalDiscarded > maxInTopRow && rowDivision == mTurnData.state.discarded.length) {
            rowDivision = i;
        }
    }
    if (rowDivision == mTurnData.state.discarded.length) {
        row2.setVisibility(View.GONE);
    }
    if (totalDiscarded == 0) {
        return;
    }
    int width = mDiscardWidthR1 / topRow;
    for (int i = 0; i < mTurnData.state.discarded.length; i++) {
        for (int j = 0; j < mTurnData.state.discarded[i].size(); j++) {
            if (i == rowDivision) {
                currRow = row2;
                row2.setVisibility(View.VISIBLE);
                width = mDiscardWidthR2 / (totalDiscarded - topRow);
            }
            currRow.addView(makeNewCardTextView(width, mTurnData.state.discarded[i].get(j)));
        }
    }
}

From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java

private void displayWidget(LinearLayout widgetLayout, BrandingResult br) {
    final String type = (String) mCurrentMessage.form.get("type");

    widgetLayout.removeAllViews();

    final Widget widget = (Widget) getLayoutInflater().inflate(Widget.RESOURCES.get(type), null, false);
    if (br != null) {
        widget.setColorScheme(br.scheme);
    }/*from  w  w  w  .ja v  a  2 s.co m*/
    widget.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    widget.setEnabled(widgetLayout.isEnabled());
    widget.loadMessage(mCurrentMessage, this, widgetLayout);

    if (!widgetLayout.isEnabled()) {
        for (int i = 0; i < widget.getChildCount(); i++) {
            View v = widget.getChildAt(i);
            v.setEnabled(false);
        }
    }
    widgetLayout.addView(widget);
}

From source file:com.todoroo.astrid.activity.TaskEditFragment.java

private void loadEditPageOrder(boolean removeViews) {
    LinearLayout basicControls = (LinearLayout) getView().findViewById(R.id.basic_controls);
    if (removeViews) {
        basicControls.removeAllViews();
        moreControls.removeAllViews();/* w  w w  .java  2s. c  om*/
    }

    ArrayList<String> controlOrder = BeastModePreferences.constructOrderedControlList(getActivity());
    String[] itemOrder = controlOrder.toArray(new String[controlOrder.size()]);

    String moreSectionTrigger = getString(R.string.TEA_ctrl_more_pref);
    String hideAlwaysTrigger = getString(R.string.TEA_ctrl_hide_section_pref);
    LinearLayout section = basicControls;

    moreSectionHasControls = false;

    Class<?> openControl = (Class<?>) getActivity().getIntent().getSerializableExtra(TOKEN_OPEN_CONTROL);

    for (int i = 0; i < itemOrder.length; i++) {
        String item = itemOrder[i];
        if (item.equals(hideAlwaysTrigger)) {
            break; // As soon as we hit the hide section, we're done
        } else if (item.equals(moreSectionTrigger)) {
            section = moreControls;
        } else {
            View controlSet = null;
            TaskEditControlSet curr = controlSetMap.get(item);

            if (curr != null)
                controlSet = (LinearLayout) curr.getDisplayView();

            if (controlSet != null) {
                if ((i + 1 >= itemOrder.length || itemOrder[i + 1].equals(moreSectionTrigger))) {
                    removeTeaSeparator(controlSet);
                }
                section.addView(controlSet);
                if (section == moreControls)
                    moreSectionHasControls = true;
            }

            if (curr != null && curr.getClass().equals(openControl) && curr instanceof PopupControlSet) {
                ((PopupControlSet) curr).getDisplayView().performClick();
            }
        }
    }

    getActivity().getIntent().removeExtra(TOKEN_OPEN_CONTROL);
}

From source file:cn.hbm.superwechat.adapter.MessageAdapter.java

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

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

}

From source file:cn.ucai.fulicenter.adapter.MessageAdapter.java

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

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

}