Example usage for android.widget LinearLayout getChildAt

List of usage examples for android.widget LinearLayout getChildAt

Introduction

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

Prototype

public View getChildAt(int index) 

Source Link

Document

Returns the view at the specified position in the group.

Usage

From source file:com.zns.comicdroid.dialog.AuthorIllustratorDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    final int comicId = getArguments().getInt("ComicId");
    final String[] names = getArguments().getStringArray("Names");

    LayoutInflater inflater = getActivity().getLayoutInflater();

    final LinearLayout parent = new LinearLayout(getActivity());
    parent.setOrientation(1);/* w  ww .j  a  v  a 2 s  .  c  o m*/
    final View viewHead = inflater.inflate(R.layout.dialog_author_illustrator_head, null);
    parent.addView(viewHead);
    for (String name : names) {
        final View view = inflater.inflate(R.layout.dialog_author_illustrator, null);
        ((TextView) view.findViewById(R.id.tvName)).setText(name);
        parent.addView(view);
    }
    builder.setView(parent);

    builder.setPositiveButton(getResources().getString(R.string.common_save),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String authors = "";
                    String illustrators = "";
                    for (int i = 1; i < parent.getChildCount(); i++) //Start at 1 to skip header
                    {
                        View child = parent.getChildAt(i);
                        TextView tvName = (TextView) child.findViewById(R.id.tvName);
                        RadioButton rbAuthor = (RadioButton) child.findViewById(R.id.rbIsAuthor);
                        RadioButton rbIllustrator = (RadioButton) child.findViewById(R.id.rbIsIllustrator);
                        if (rbAuthor.isChecked())
                            authors += tvName.getText() + ",";
                        if (rbIllustrator.isChecked())
                            illustrators += tvName.getText() + ",";
                    }
                    authors = authors.replaceAll("[,]+$", "");
                    illustrators = illustrators.replaceAll("[,]+$", "");
                    if (mAuthorIllustratorCallback != null)
                        mAuthorIllustratorCallback.onAuthorIllustratorDialogPositiveClick(comicId, authors,
                                illustrators);
                }
            })

            .setNegativeButton(getResources().getString(R.string.common_cancel),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            AuthorIllustratorDialogFragment.this.getDialog().cancel();
                        }
                    });

    AlertDialog dialog = builder.create();
    return dialog;
}

From source file:de.mrapp.android.dialog.decorator.WizardDialogDecorator.java

/**
 * Adapts the enable state of the tab layout, which indicates the currently shown fragment.
 */// w w w. ja v a2s  . c o  m
private void adaptTabLayoutEnableState() {
    if (tabLayout != null) {
        LinearLayout tabStrip = ((LinearLayout) tabLayout.getChildAt(0));
        tabStrip.setEnabled(tabLayoutEnabled);

        for (int i = 0; i < tabStrip.getChildCount(); i++) {
            tabStrip.getChildAt(i).setEnabled(tabLayoutEnabled);
        }
    }
}

From source file:uk.co.droidinactu.ebooklauncher.EBookLauncherActivity.java

private void setupList(final HorizontialListView listview, final SimpleCursorAdapter listAdapter,
        final Cursor cursr) {
    if (cursr == null || cursr != null && cursr.getCount() == 0) {
        Toast.makeText(getApplication(), "No books available", Toast.LENGTH_LONG);
    } else {//  w ww  .j  av  a2  s .c o  m
        listview.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
            @Override
            public void onCreateContextMenu(final ContextMenu conMenu, final View v,
                    final ContextMenuInfo menuInfo) {
                final LinearLayout ll = (LinearLayout) ((HorizontialListView) v)
                        .getChildAt(((AdapterContextMenuInfo) menuInfo).position);
                final Drawable bookCover = ((ImageView) ll.getChildAt(0)).getDrawable();
                final String bookTitle = ((TextView) ll.getChildAt(1)).getText().toString();
                conMenu.setHeaderIcon(bookCover); // set to book cover
                conMenu.setHeaderTitle(bookTitle); // set to book title
                conMenu.add(0, EBookLauncherActivity.CONTEXTMENU_VIEW_DETAILS, 0,
                        R.string.book_grid_context_item_view_book_details);
                conMenu.add(0, EBookLauncherActivity.CONTEXTMENU_OPEN_BOOK, 1,
                        R.string.book_grid_context_item_open_book);
                conMenu.add(0, EBookLauncherActivity.CONTEXTMENU_DELETE_BOOK, 2,
                        R.string.book_grid_context_item_delete_book);
            }
        });
        listview.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(final AdapterView<?> av, final View v, final int pos, final long id) {
                myApp.dataMdl.launchBook(EBookLauncherActivity.this, id);
            }

            @Override
            public void onNothingSelected(final AdapterView<?> arg0) {
            }
        });
        listAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
            @Override
            public boolean setViewValue(final View view, final Cursor cursor, final int columnIndex) {
                boolean retval = false;
                final int idColIndex = cursor.getColumnIndexOrThrow(BaseColumns._ID);
                final int thumbColIndex = cursor.getColumnIndexOrThrow(DeviceFactory.getCoverImgColumnName());

                if (columnIndex == idColIndex) {
                    try {
                        final ImageView coverImg = (ImageView) view;
                        final String thumbnailFilename = cursor.getString(thumbColIndex);
                        final Bitmap bitmap = myApp.dataMdl.getBookCoverImg(EBookLauncherActivity.this,
                                thumbnailFilename);
                        coverImg.setImageDrawable(new BitmapDrawable(bitmap));
                        retval = true;
                    } catch (final Exception e) {
                        Log.e(EBookLauncherApplication.LOG_TAG, EBookLauncherActivity.LOG_TAG + "Exception ",
                                e);
                    }
                    retval = true;
                }
                return retval;
            }
        });
        listview.setAdapter(listAdapter);
        registerForContextMenu(listview);
        startManagingCursor(cursr);
    }
}

From source file:info.tellmetime.TellmetimeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_tellmetime);

    mDensity = getResources().getDisplayMetrics().density;
    mScreenWidth = getResources().getDisplayMetrics().widthPixels;
    mScreenHeight = getResources().getDisplayMetrics().heightPixels;
    mShorterEdge = Math.min(mScreenWidth, mScreenHeight);
    mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop();
    mBacklightLight = getResources().getColor(R.color.backlight_light);
    mBacklightDark = getResources().getColor(R.color.backlight_dark);

    // Restore background and highlight colors from saved values or set defaults.
    mSettings = getSharedPreferences("PREFS", Context.MODE_PRIVATE);
    mHighlightColor = mSettings.getInt(HIGHLIGHT, Color.WHITE);
    mBacklightColor = mSettings.getInt(BACKLIGHT, mBacklightLight);
    mBackgroundColor = mSettings.getInt(BACKGROUND, getResources().getColor(R.color.background));
    mBackgroundMode = mSettings.getInt(BACKGROUND_MODE, MODE_BACKGROUND_SOLID);
    mHighlightPosition = mSettings.getFloat(POSITION, 0.0f);
    mMinutesSize = mSettings.getInt(MINUTES_SIZE, 36);
    isNightMode = mSettings.getBoolean(NIGHTMODE, false);

    // Dim the navigation bar.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
        getWindow().getDecorView().setSystemUiVisibility(isNightMode ? View.SYSTEM_UI_FLAG_LOW_PROFILE : 0);

    mSurface = (RelativeLayout) findViewById(R.id.surface);
    mSurface.setBackgroundColor(mBackgroundColor);

    resizeClock();/*from w w w  . j  a v a2  s  .  co m*/

    Typeface mTypefaceBold = Typeface.createFromAsset(getAssets(), "Roboto-BoldCondensed.ttf");

    // Set typeface of all items in the clock to Roboto and dim each one and drop shadow on them.
    final LinearLayout mClock = (LinearLayout) findViewById(R.id.clock);
    for (int i = 0; i < mClock.getChildCount(); i++) {
        LinearLayout row = (LinearLayout) mClock.getChildAt(i);

        for (int j = 0; j < row.getChildCount(); j++) {
            TextView tv = (TextView) row.getChildAt(j);

            tv.setTypeface(mTypefaceBold);
            tv.setTextColor(mBacklightColor);
            tv.setShadowLayer(mShorterEdge / 200 * mDensity, 0, 0, mBacklightColor);
        }
    }

    ViewGroup minutesDots = (ViewGroup) findViewById(R.id.minutes_dots);
    for (int i = 0; i < minutesDots.getChildCount(); i++) {
        TextView m = (TextView) minutesDots.getChildAt(i);

        m.setTypeface(mTypefaceBold);
        m.setTextColor(mBacklightColor);
        m.setShadowLayer(mShorterEdge / 200 * mDensity, 0, 0, mBacklightColor);
    }

    // Set Roboto font on TextView where it isn't default.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        Typeface mTypefaceItalic = Typeface.createFromAsset(getAssets(), "Roboto-CondensedItalic.ttf");

        ((TextView) findViewById(R.id.labelBackground)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.info_background)).setTypeface(mTypefaceItalic);
        ((TextView) findViewById(R.id.info_image)).setTypeface(mTypefaceItalic);
        ((TextView) findViewById(R.id.labelHighlight)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.labelBackground)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.radio_backlight_light)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.radio_backlight_dark)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.radio_backlight_highlight)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.labelMinutes)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.m1)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.m2)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.m3)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.m4)).setTypeface(mTypefaceBold);
    }

    FrameLayout mTouchZone = (FrameLayout) findViewById(R.id.touchZone);
    mTouchZone.setOnTouchListener(this);
    mTouchZone.setBackgroundColor(
            getResources().getColor(isNightMode ? R.color.night_mode_overlay : android.R.color.transparent));

    mBackgroundImage = (ImageView) findViewById(R.id.background_image);
    switchBackgroundMode(mBackgroundMode);

    RelativeLayout mPanel = (RelativeLayout) findViewById(R.id.panel);
    mPanel.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            mHider.delayedHide(4000);
            return true;
        }
    });

    mHider = new PanelHider(mPanel, this);

    Spinner spinnerBackgroundMode = (Spinner) findViewById(R.id.spinnerBackgroundMode);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.backgrounds_modes,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerBackgroundMode.setAdapter(adapter);
    spinnerBackgroundMode.setOnItemSelectedListener(this);
    spinnerBackgroundMode.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            mHider.showNoAutoHide();
            return false;
        }
    });
    spinnerBackgroundMode.setSelection(mBackgroundMode);

    mSeekBarHighlight = (SeekBar) findViewById(R.id.highlightValue);
    mSeekBarHighlight.setOnSeekBarChangeListener(this);

    // Draw rainbow gradient on #mSeekBarHighlight and set position.
    drawRainbow();

    if (mBacklightColor == mBacklightLight)
        ((RadioButton) findViewById(R.id.radio_backlight_light)).setChecked(true);
    else if (mBacklightColor == mBacklightDark)
        ((RadioButton) findViewById(R.id.radio_backlight_dark)).setChecked(true);
    else
        ((RadioButton) findViewById(R.id.radio_backlight_highlight)).setChecked(true);

    SeekBar mSeekBarMinutes = (SeekBar) findViewById(R.id.minutesSize);
    mSeekBarMinutes.setOnSeekBarChangeListener(this);
    mSeekBarMinutes.setProgress(mMinutesSize);

    mHider.hideNow();

    Color.colorToHSV(mBackgroundColor, mHSV);
    mHSV[1] = 1.0f;

    //Trigger initial tick.
    mClockAlgorithm.tickTock();

    // Schedule the clock algorithm to tick every round minute.
    Calendar time = Calendar.getInstance();
    time.set(Calendar.MILLISECOND, 0);
    time.set(Calendar.SECOND, 0);
    time.add(Calendar.MINUTE, 1);

    Timer timer = new Timer();
    timer.schedule(mClockTask, time.getTime(), 60 * 1000);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mSurface.setAlpha(0.0f);
        mSurface.animate().alpha(1.0f).setDuration(1500);
    }

    // If it is first run, hint to user that panel is available.
    if (!mSettings.contains(HIGHLIGHT))
        showToast(R.string.info_first_run);
}

From source file:org.uoyabause.android.YabauseHandler.java

private void showBottomMenu() {
    if (menu_showing == true) {
        menu_showing = false;/*from   w w  w .j a v  a2s .co  m*/
        View mainview = (View) findViewById(R.id.yabause_view);
        mainview.requestFocus();
        YabauseRunnable.resume();
        audio.unmute(audio.SYSTEM);
        this.mDrawerLayout.closeDrawer(GravityCompat.START);
    } else {
        menu_showing = true;
        YabauseRunnable.pause();
        audio.mute(audio.SYSTEM);
        String name = YabauseRunnable.getGameTitle();
        TextView tx = (TextView) findViewById(R.id.menu_title);
        if (tx != null) {
            tx.setText(name);
        }
        if (adView != null) {
            LinearLayout lp = (LinearLayout) findViewById(R.id.navilayer);
            if (lp != null) {
                final int mCount = lp.getChildCount();
                boolean find = false;
                for (int i = 0; i < mCount; ++i) {
                    final View mChild = lp.getChildAt(i);
                    if (mChild == adView) {
                        find = true;
                    }
                }
                if (find == false) {
                    lp.addView(adView);
                }
                AdRequest adRequest = new AdRequest.Builder().addTestDevice("303A789B146C169D4BDB5652D928FF8E")
                        .build();
                adView.loadAd(adRequest);
            }
        }
        this.mDrawerLayout.openDrawer(GravityCompat.START);
    }
}

From source file:no.barentswatch.fiskinfo.MapActivity.java

/**
 * // ww w. j a va2  s .c o m
 */
public void showMapLayersDialog() {
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
    dialog.setContentView(R.layout.dialog_select_map_layers);

    final LinearLayout mapLayerLayout = (LinearLayout) dialog.findViewById(R.id.map_layers_checkbox_layout);
    Button okButton = (Button) dialog.findViewById(R.id.dismiss_dialog_button);
    Button cancelButton = (Button) dialog.findViewById(R.id.go_to_map_button);

    for (int i = 0; i < 5; i++) {
        View mapLayerRow = getMapLayerCheckBoxRow(getContext(), Integer.toString(i));
        mapLayerLayout.addView(mapLayerRow);
    }

    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            for (int i = 0; i < mapLayerLayout.getChildCount(); i++) {
                if (((CheckBox) ((TableRow) mapLayerLayout.getChildAt(i)).getChildAt(0)).isChecked()) {
                    // TODO: Add layer to list

                }
            }
            // TODO: Implement logic for adding map layers here.            

            dialog.dismiss();
        }
    });

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

    dialog.setTitle(R.string.choose_map_layers);
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
}

From source file:com.arkami.myidkey.activity.KeyCardEditActivity.java

/**
 * Sets screen components edit mode/* w  w  w.  ja va 2  s  .  c  o m*/
 *
 * @param editable if the components are editable or not.
 */
private void setEditable(boolean editable) {

    this.keyCardName.setEnabled(editable);
    this.favourite.setEnabled(editable);
    if (editable) {
        this.tagSpinner.setVisibility(View.VISIBLE);
    } else {
        this.tagSpinner.setVisibility(View.INVISIBLE);
    }
    for (int i = 0; i < this.photosLinearLayout.getChildCount(); i++) {
        RelativeLayout photoLayout = (RelativeLayout) this.photosLinearLayout.getChildAt(i);
        if (editable) {
            photoLayout.getChildAt(1).setVisibility(View.VISIBLE);
        } else {
            photoLayout.getChildAt(1).setVisibility(View.GONE);
        }
    }

    for (int i = 0; i < this.audioLinearLayout.getChildCount(); i++) {
        RelativeLayout audioLayout = (RelativeLayout) this.audioLinearLayout.getChildAt(i);
        if (editable) {
            audioLayout.getChildAt(1).setVisibility(View.VISIBLE);
        } else {
            audioLayout.getChildAt(1).setVisibility(View.GONE);
        }
    }

    for (int i = 0; i < this.selectedTags.getChildCount(); i++) {
        LinearLayout tag = (LinearLayout) this.selectedTags.getChildAt(i);
        RelativeLayout tagLayout = (RelativeLayout) tag.getChildAt(0);
        if (editable) {
            tagLayout.getChildAt(1).setVisibility(View.VISIBLE);
        } else {
            tagLayout.getChildAt(1).setVisibility(View.GONE);
        }
    }

    for (CustomViewComponent component : this.componentHolder.getCustomComponents()) {
        component.setEditable(editable);
    }

}

From source file:com.bridgeconn.autographago.ui.customviews.TabLayoutHelper.java

protected int determineTabMode(@NonNull TabLayout tabLayout) {
    LinearLayout slidingTabStrip = (LinearLayout) tabLayout.getChildAt(0);

    int childCount = slidingTabStrip.getChildCount();

    // NOTE: slidingTabStrip.getMeasuredWidth() method does not return correct width!
    // Need to measure each tabs and calculate the sum of them.

    int tabLayoutWidth = tabLayout.getMeasuredWidth() - tabLayout.getPaddingLeft()
            - tabLayout.getPaddingRight();
    int tabLayoutHeight = tabLayout.getMeasuredHeight() - tabLayout.getPaddingTop()
            - tabLayout.getPaddingBottom();

    if (childCount == 0) {
        return TabLayout.MODE_FIXED;
    }//from w w  w  .j  a v a  2  s  .  c o  m

    int stripWidth = 0;
    int maxWidthTab = 0;
    int tabHeightMeasureSpec = View.MeasureSpec.makeMeasureSpec(tabLayoutHeight, View.MeasureSpec.EXACTLY);

    for (int i = 0; i < childCount; i++) {
        View tabView = slidingTabStrip.getChildAt(i);
        tabView.measure(View.MeasureSpec.UNSPECIFIED, tabHeightMeasureSpec);
        int tabWidth = tabView.getMeasuredWidth();
        stripWidth += tabWidth;
        maxWidthTab = Math.max(maxWidthTab, tabWidth);
    }

    return ((stripWidth < tabLayoutWidth) && (maxWidthTab < (tabLayoutWidth / childCount)))
            ? TabLayout.MODE_FIXED
            : TabLayout.MODE_SCROLLABLE;
}

From source file:com.qiscus.sdk.filepicker.util.TabLayoutHelper.java

private int determineTabMode(@NonNull TabLayout tabLayout) {
    LinearLayout slidingTabStrip = (LinearLayout) tabLayout.getChildAt(0);

    int childCount = slidingTabStrip.getChildCount();

    // NOTE: slidingTabStrip.getMeasuredWidth() method does not return correct width!
    // Need to measure each tabs and calculate the sum of them.

    int tabLayoutWidth = tabLayout.getMeasuredWidth() - tabLayout.getPaddingLeft()
            - tabLayout.getPaddingRight();
    int tabLayoutHeight = tabLayout.getMeasuredHeight() - tabLayout.getPaddingTop()
            - tabLayout.getPaddingBottom();

    if (childCount == 0) {
        return TabLayout.MODE_FIXED;
    }//w w  w  . j a v a2s .  c  om

    int stripWidth = 0;
    int maxWidthTab = 0;
    int tabHeightMeasureSpec = View.MeasureSpec.makeMeasureSpec(tabLayoutHeight, View.MeasureSpec.EXACTLY);

    for (int i = 0; i < childCount; i++) {
        View tabView = slidingTabStrip.getChildAt(i);
        tabView.measure(View.MeasureSpec.UNSPECIFIED, tabHeightMeasureSpec);
        int tabWidth = tabView.getMeasuredWidth();
        stripWidth += tabWidth;
        maxWidthTab = Math.max(maxWidthTab, tabWidth);
    }

    return ((stripWidth < tabLayoutWidth) && (maxWidthTab < (tabLayoutWidth / childCount)))
            ? TabLayout.MODE_FIXED
            : TabLayout.MODE_SCROLLABLE;
}

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

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

    Toolbar bar;/* ww w .  j  av  a  2s  .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();
        }
    });
}