Example usage for android.widget LinearLayout getChildCount

List of usage examples for android.widget LinearLayout getChildCount

Introduction

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

Prototype

public int getChildCount() 

Source Link

Document

Returns the number of children in the group.

Usage

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

/**
 * Adapts the enable state of the tab layout, which indicates the currently shown fragment.
 *//*from  w w  w.  j  a v  a  2 s.  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:org.uoyabause.android.YabauseHandler.java

/** Called when the activity is first created. */
@Override//from   w ww  .j  a v  a2s  .com
public void onCreate(Bundle savedInstanceState) {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(Yabause.this);
    boolean lock_landscape = sharedPref.getBoolean("pref_landscape", false);
    if (lock_landscape == true) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    }

    super.onCreate(savedInstanceState);
    System.gc();

    YabauseApplication application = (YabauseApplication) getApplication();
    mTracker = application.getDefaultTracker();

    setContentView(R.layout.main);
    getWindow().setSustainedPerformanceMode(true);
    getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_FULLSCREEN);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(this);
    if (sharedPref.getBoolean("pref_analog_pad", false) == true) {
        mNavigationView.setCheckedItem(R.id.pad_mode);
    }

    DrawerLayout.DrawerListener drawerListener = new DrawerLayout.DrawerListener() {
        @Override
        public void onDrawerSlide(View view, float v) {

        }

        @Override
        public void onDrawerOpened(View view) {
            if (menu_showing == false) {
                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);
                    }
                }

            }
        }

        @Override
        public void onDrawerClosed(View view) {

            if (waiting_reault == false && menu_showing == true) {
                menu_showing = false;
                YabauseRunnable.resume();
                audio.unmute(audio.SYSTEM);
            }

        }

        @Override
        public void onDrawerStateChanged(int i) {
        }
    };
    this.mDrawerLayout.setDrawerListener(drawerListener);

    audio = new YabauseAudio(this);

    Intent intent = getIntent();
    String game = intent.getStringExtra("org.uoyabause.android.FileName");
    if (game != null && game.length() > 0) {
        YabauseStorage storage = YabauseStorage.getStorage();
        gamepath = storage.getGamePath(game);
    } else
        gamepath = "";

    String exgame = intent.getStringExtra("org.uoyabause.android.FileNameEx");
    if (exgame != null) {
        gamepath = exgame;
    }

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    readPreferences();

    padm = PadManager.getPadManager();
    padm.loadSettings();
    waiting_reault = false;

    handler = new YabauseHandler(this);
    yabauseThread = new YabauseRunnable(this);

    UiModeManager uiModeManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
    if (uiModeManager.getCurrentModeType() != Configuration.UI_MODE_TYPE_TELEVISION) {
        SharedPreferences prefs = getSharedPreferences("private", Context.MODE_PRIVATE);
        Boolean hasDonated = prefs.getBoolean("donated", false);
        if (hasDonated) {
            adView = null;
        } else {
            adView = new AdView(this);
            adView.setAdUnitId(getString(R.string.banner_ad_unit_id2));
            adView.setAdSize(AdSize.BANNER);
            AdRequest adRequest = new AdRequest.Builder().build();
            adView.loadAd(adRequest);
            adView.setAdListener(new AdListener() {
                @Override
                public void onAdOpened() {
                    // Save app state before going to the ad overlay.
                }
            });
        }
    } else {
        adView = null;
    }

}

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

/**
 * // w  w  w. j  a  v a 2 s  . c  om
 */
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:org.linphone.ContactEditorFragment.java

@SuppressLint("InflateParams")
private View displayNumberOrAddress(final LinearLayout controls, String numberOrAddress,
        boolean forceAddNumber) {
    boolean isSip = LinphoneUtils.isStrictSipAddress(numberOrAddress)
            || !LinphoneUtils.isNumberAddress(numberOrAddress);

    if (isSip) {/*  w w  w.j  av  a2 s. c o m*/
        if (firstSipAddressIndex == -1) {
            firstSipAddressIndex = controls.getChildCount();
        }
        numberOrAddress = numberOrAddress.replace("sip:", "");
    }
    if ((getResources().getBoolean(R.bool.hide_phone_numbers_in_editor) && !isSip)
            || (getResources().getBoolean(R.bool.hide_sip_addresses_in_editor) && isSip)) {
        if (forceAddNumber)
            isSip = !isSip; // If number can't be displayed because we hide a sort of number, change that category
        else
            return null;
    }

    NewOrUpdatedNumberOrAddress tempNounoa;
    if (forceAddNumber) {
        tempNounoa = new NewOrUpdatedNumberOrAddress(isSip);
    } else {
        if (isNewContact || newSipOrNumberToAdd != null) {
            tempNounoa = new NewOrUpdatedNumberOrAddress(isSip, numberOrAddress);
        } else {
            tempNounoa = new NewOrUpdatedNumberOrAddress(numberOrAddress, isSip);
        }
    }
    final NewOrUpdatedNumberOrAddress nounoa = tempNounoa;
    numbersAndAddresses.add(nounoa);

    final View view = inflater.inflate(R.layout.contact_edit_row, null);

    final EditText noa = (EditText) view.findViewById(R.id.numoraddr);
    noa.setInputType(isSip ? InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS : InputType.TYPE_CLASS_PHONE);
    noa.setText(numberOrAddress);
    noa.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            nounoa.setNewNumberOrAddress(noa.getText().toString());
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    if (forceAddNumber) {
        nounoa.setNewNumberOrAddress(noa.getText().toString());
    }

    ImageView delete = (ImageView) view.findViewById(R.id.delete_field);
    delete.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            nounoa.delete();
            numbersAndAddresses.remove(nounoa);
            view.setVisibility(View.GONE);

        }
    });
    return view;
}

From source file:org.thoughtcrime.securesms.ProfileFragment.java

/**
 * An incoming video media has an attached second image attachment used as preview for the encrypted video file.
 * To detect whether is is a video, we check the next attachment for the same message id and use this as the preview for the encrypted video.
 * To detect whether it is just the second of a video, we check for the same message id as the previous attachment. If yes, we hide it.
 * Not beautiful, but working.../* w  w  w .j av a  2 s  .  c  o  m*/
 */
private void setMediaHistoryImages() {
    String[] mediaHistoryUris = gDataPreferences
            .getMediaUriHistoryForId(GUtil.numberToLong(recipient.getNumber()));
    String[] mediaHistoryIds = gDataPreferences
            .getMediaMessageIdHistoryForContactId(GUtil.numberToLong(recipient.getNumber()));
    String lastMessageId = "noLastMessageId";
    String nextMessageId = "nonextMessageId";
    String currentMessageId = "nocurrentMessageId";
    if (mediaHistoryUris.length > 0) {
        while (historyLayout.getChildCount() >= 1) {
            historyLayout.removeView(historyLayout.getChildAt(0));
        }
        for (int i = 0; i < mediaHistoryUris.length; i++) {
            boolean isVideo = false;
            boolean wasVideo = false;
            nextMessageId = mediaHistoryIds.length > i + 1 ? mediaHistoryIds[i + 1] : "nonextMessageId";
            currentMessageId = mediaHistoryIds.length > i ? mediaHistoryIds[i] : "nocurrentMessageId";
            lastMessageId = i - 1 >= 0 ? mediaHistoryIds[i - 1] : "noLastMessageId";
            if (nextMessageId.equals(currentMessageId)) {
                isVideo = true;
            }
            if (currentMessageId.equals(lastMessageId)) {
                wasVideo = true;
            }
            Slide mediaHistorySlide = ProfileAccessor.getSlideForUri(getActivity(), masterSecret,
                    mediaHistoryUris[i], false);
            VideoSlide videoSlide = null;
            if (mediaHistoryIds.length > i + 1 && isVideo && !wasVideo) {
                Slide nextSlide = ProfileAccessor.getSlideForUri(getActivity(), masterSecret,
                        mediaHistoryUris[i + 1], true);
                videoSlide = nextSlide instanceof VideoSlide ? (VideoSlide) nextSlide : null;
            }
            if (mediaHistorySlide != null && masterSecret != null
                    && !(mediaHistorySlide.getUri() + "").equals("") && !wasVideo) {
                ThumbnailView historyMedia = new ThumbnailView(getActivity());

                android.widget.LinearLayout.LayoutParams layoutParams = new android.widget.LinearLayout.LayoutParams(
                        dpToPx(100), dpToPx(100));
                historyMedia
                        .setBackgroundColor(getResources().getColor(R.color.conversation_list_divider_light));
                layoutParams.setMargins(5, 0, 5, 0);

                historyMedia.setLayoutParams(layoutParams);
                historyMedia.setSlide(mediaHistorySlide);
                historyMedia.setVideoSlide(videoSlide);
                ProfileAccessor.buildEncryptedPartGlideRequest(mediaHistorySlide, masterSecret, getActivity())
                        .into(historyMedia);
                historyLayout.addView(historyMedia);
            }
        }
        LinearLayout ll = ((LinearLayout) historyScrollView.getChildAt(0));
        if (ll.getChildCount() > 0 && historyContentTextView != null && mediaHistoryUris != null
                && mediaHistoryUris.length > 0) {
            historyContentTextView.setVisibility(View.GONE);
        }
        for (int l = 0; l < ll.getChildCount(); l++) {
            ((ThumbnailView) ll.getChildAt(l)).setOnClickListener(mediaOnClickListener);
        }
    }
}

From source file:org.onebusaway.android.report.ui.Open311ProblemFragment.java

/**
 * Creates open311 question and answer attributes to submit a report
 * Reads from dynamically created UI//from  ww  w.j a  v a 2 s .  com
 *
 * @param serviceDescription contains attribute types
 * @return List of code value pair of attributes
 */
private List<Open311AttributePair> createOpen311Attributes(ServiceDescription serviceDescription) {
    List<Open311AttributePair> attributes = new ArrayList<>();

    for (Open311Attribute open311Attribute : serviceDescription.getAttributes()) {

        if (Boolean.valueOf(open311Attribute.getVariable())) {
            if (Open311DataType.STRING.equals(open311Attribute.getDatatype())
                    || Open311DataType.NUMBER.equals(open311Attribute.getDatatype())
                    || Open311DataType.DATETIME.equals(open311Attribute.getDatatype())) {
                EditText et = (EditText) mDynamicAttributeUIMap.get(open311Attribute.getCode());
                if (et != null) {
                    attributes.add(new Open311AttributePair(open311Attribute.getCode(), et.getText().toString(),
                            open311Attribute.getDatatype()));
                }
            } else if (Open311DataType.SINGLEVALUELIST.equals(open311Attribute.getDatatype())) {
                RadioGroup rg = (RadioGroup) mDynamicAttributeUIMap.get(open311Attribute.getCode());
                if (rg != null) {
                    int count = rg.getChildCount();
                    for (int i = 0; i < count; i++) {
                        RadioButton rb = (RadioButton) rg.getChildAt(i);
                        if (rb.isChecked()) {
                            String attributeKey = mOpen311AttributeKeyNameMap
                                    .get(open311Attribute.getCode() + rb.getText().toString());
                            attributes.add(new Open311AttributePair(open311Attribute.getCode(), attributeKey,
                                    open311Attribute.getDatatype()));
                            break;
                        }
                    }
                }
            } else if (Open311DataType.MULTIVALUELIST.equals(open311Attribute.getDatatype())) {
                LinearLayout ll = (LinearLayout) mDynamicAttributeUIMap.get(open311Attribute.getCode());
                if (ll != null) {
                    int count = ll.getChildCount();
                    for (int i = 0; i < count; i++) {
                        CheckBox cb = (CheckBox) ll.getChildAt(i);
                        if (cb.isChecked()) {
                            String attributeKey = mOpen311AttributeKeyNameMap
                                    .get(open311Attribute.getCode() + cb.getText().toString());
                            attributes.add(new Open311AttributePair(open311Attribute.getCode(), attributeKey,
                                    open311Attribute.getDatatype()));
                        }
                    }
                }
            }
        }
    }
    return attributes;
}

From source file:org.onebusaway.android.report.ui.Open311ProblemFragment.java

/**
 * This method dynamically reads all user inputted the values from the screen and puts into a
 * list//w w  w.ja  v  a  2s  .  c  o  m
 *
 * @param serviceDescription displayed service description
 * @return List of attribute values
 */
private List<AttributeValue> createAttributeValues(ServiceDescription serviceDescription) {
    List<AttributeValue> values = new ArrayList<>();

    if (serviceDescription == null) {
        return values;
    }

    for (Open311Attribute open311Attribute : serviceDescription.getAttributes()) {
        if (Boolean.valueOf(open311Attribute.getVariable())) {
            if (Open311DataType.STRING.equals(open311Attribute.getDatatype())
                    || Open311DataType.NUMBER.equals(open311Attribute.getDatatype())
                    || Open311DataType.DATETIME.equals(open311Attribute.getDatatype())) {
                EditText et = (EditText) mDynamicAttributeUIMap.get(open311Attribute.getCode());
                if (et != null) {
                    AttributeValue value = new AttributeValue(open311Attribute.getCode());
                    value.addValue(et.getText().toString());
                    values.add(value);
                }
            } else if (Open311DataType.SINGLEVALUELIST.equals(open311Attribute.getDatatype())) {
                RadioGroup rg = (RadioGroup) mDynamicAttributeUIMap.get(open311Attribute.getCode());
                if (rg != null) {
                    int count = rg.getChildCount();
                    for (int i = 0; i < count; i++) {
                        RadioButton rb = (RadioButton) rg.getChildAt(i);
                        if (rb.isChecked()) {
                            AttributeValue value = new AttributeValue(open311Attribute.getCode());
                            value.addValue(rb.getText().toString());
                            values.add(value);
                            break;
                        }
                    }
                }
            } else if (Open311DataType.MULTIVALUELIST.equals(open311Attribute.getDatatype())) {
                LinearLayout ll = (LinearLayout) mDynamicAttributeUIMap.get(open311Attribute.getCode());
                if (ll != null) {
                    int count = ll.getChildCount();
                    AttributeValue value = new AttributeValue(open311Attribute.getCode());
                    for (int i = 0; i < count; i++) {
                        CheckBox cb = (CheckBox) ll.getChildAt(i);
                        if (cb.isChecked()) {
                            value.addValue(cb.getText().toString());
                        }
                    }
                    if (value.getValues().size() > 0)
                        values.add(value);
                }
            }
        }
    }
    return values;
}

From source file:org.fdroid.fdroid.privileged.views.AppSecurityPermissions.java

/**
 * Utility method that displays permissions from a map containing group name and
 * list of permission descriptions./*from  w  w w .j a v a 2  s  .c o  m*/
 */
private void displayPermissions(List<MyPermissionGroupInfo> groups, LinearLayout permListView, int which) {
    permListView.removeAllViews();

    int spacing = (int) (8 * context.getResources().getDisplayMetrics().density);

    for (MyPermissionGroupInfo grp : groups) {
        final List<MyPermissionInfo> perms = getPermissionList(grp, which);
        for (int j = 0; j < perms.size(); j++) {
            MyPermissionInfo perm = perms.get(j);
            View view = getPermissionItemView(grp, perm, j == 0, which != WHICH_NEW ? newPermPrefix : null);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            if (j == 0) {
                lp.topMargin = spacing;
            }
            if (j == grp.allPermissions.size() - 1) {
                lp.bottomMargin = spacing;
            }
            if (permListView.getChildCount() == 0) {
                lp.topMargin *= 2;
            }
            permListView.addView(view, lp);
        }
    }
}

From source file:org.zywx.wbpalmstar.plugin.chatkeyboard.ACEChatKeyboardView.java

private void updateCurrentPage(int index, LinearLayout layout) {
    for (int i = 0; i < layout.getChildCount(); i++) {
        View view = layout.getChildAt(i);
        if (i == index) {
            view.setBackgroundResource(CRes.plugin_chatkeyboard_pages_pointer_focus);
        } else {//w w w.j a v a  2 s.c om
            view.setBackgroundResource(CRes.plugin_chatkeyboard_pages_pointer_normal);
        }
    }
}

From source file:com.juick.android.ThreadFragment.java

public void showThread(JuickMessage jmsg, boolean keepShow) {
    if (jmsg.getReplyTo() != 0) {
        JuickMessage reply = jmsg;//from w w  w . j  a  v  a2  s.  c  o m
        LinearLayout ll = new LinearLayout(getActivity());
        ll.setOrientation(LinearLayout.VERTICAL);
        ll.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
        int totalCount = 0;
        while (reply != null) {
            totalCount += reply.Text.length();
            if (totalCount > 500 || ll.getChildCount() > 10)
                break;
            JuickMessagesAdapter.ParsedMessage parsedMessage = JuickMessagesAdapter
                    .formatMessageText(getActivity(), reply, true);
            TextView child = new TextView(getActivity());
            ll.addView(child, 0);
            child.setText(parsedMessage.textContent);
            if (reply.getReplyTo() < 1)
                break;
            reply = findReply(getListView(), reply.getReplyTo());
        }
        if (ll.getChildCount() != 0) {
            int xy[] = new int[2];
            getListView().getLocationOnScreen(xy);
            int windowHeight = getActivity().getWindow().getWindowManager().getDefaultDisplay().getHeight();
            int listBottom = getListView().getHeight() + xy[1];
            int bottomSize = windowHeight - listBottom;
            ll.setPressed(true);
            MainActivity.restyleChildrenOrWidget(ll);
            if (!keepShow || shownThreadToast.getView().getParent() == null) { // new or already hidden
                shownThreadToast = new Toast(getActivity());
                shownThreadToast.setView(ll);
                shownThreadToast.setGravity(Gravity.BOTTOM | Gravity.LEFT, 0, bottomSize);
                shownThreadToast.setDuration(Toast.LENGTH_LONG);
            }
            shownThreadToast.show();
        }
    }
}