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:org.zywx.wbpalmstar.plugin.chatkeyboard.ACEChatKeyboardView.java

private void initPagerIndicator(int pagerSize, LinearLayout layout) {
    int childCount = layout.getChildCount();
    if (pagerSize == childCount) {
        return;/* www  . j  a v  a 2s  .c o  m*/
    }
    int width = getResources().getDimensionPixelSize(CRes.plugin_chatkeyboard_pager_indicator_width);
    int left = getResources().getDimensionPixelSize(CRes.plugin_chatkeyboard_pager_indicator_left);
    int top = getResources().getDimensionPixelSize(CRes.plugin_chatkeyboard_pager_indicator_top);
    LinearLayout.LayoutParams viewParams = new LinearLayout.LayoutParams(width, width);
    viewParams.setMargins(left, top, left, top);
    if (pagerSize > childCount) {// ?
        while (childCount < pagerSize) {
            ImageView imageView = new ImageView(getContext());
            layout.addView(imageView, childCount, viewParams);
            childCount++;
        }
    } else {
        while (childCount > pagerSize) {
            layout.removeViewAt(childCount);
            childCount--;
        }
    }
}

From source file:com.irccloud.android.activity.LoginActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= 21) {
        Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name),
                cloud, 0xff0b2e60));//from w  w  w .j  av  a  2  s  . com
        cloud.recycle();
    }

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    setContentView(R.layout.activity_login);

    loading = findViewById(R.id.loading);

    connecting = findViewById(R.id.connecting);
    connectingMsg = (TextView) findViewById(R.id.connectingMsg);
    progressBar = (ProgressBar) findViewById(R.id.connectingProgress);

    loginHint = (LinearLayout) findViewById(R.id.loginHint);
    signupHint = (LinearLayout) findViewById(R.id.signupHint);
    hostHint = (TextView) findViewById(R.id.hostHint);

    login = findViewById(R.id.login);
    name = (EditText) findViewById(R.id.name);
    if (savedInstanceState != null && savedInstanceState.containsKey("name"))
        name.setText(savedInstanceState.getString("name"));
    email = (AutoCompleteTextView) findViewById(R.id.email);
    if (BuildConfig.ENTERPRISE)
        email.setHint(R.string.email_enterprise);
    ArrayList<String> accounts = new ArrayList<String>();
    AccountManager am = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE);
    for (Account a : am.getAccounts()) {
        if (a.name.contains("@") && !accounts.contains(a.name))
            accounts.add(a.name);
    }
    if (accounts.size() > 0)
        email.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                accounts.toArray(new String[accounts.size()])));

    if (savedInstanceState != null && savedInstanceState.containsKey("email"))
        email.setText(savedInstanceState.getString("email"));

    password = (EditText) findViewById(R.id.password);
    password.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                new LoginTask().execute((Void) null);
                return true;
            }
            return false;
        }
    });
    if (savedInstanceState != null && savedInstanceState.containsKey("password"))
        password.setText(savedInstanceState.getString("password"));

    host = (EditText) findViewById(R.id.host);
    if (BuildConfig.ENTERPRISE)
        host.setText(NetworkConnection.IRCCLOUD_HOST);
    else
        host.setVisibility(View.GONE);
    host.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                new LoginTask().execute((Void) null);
                return true;
            }
            return false;
        }
    });
    if (savedInstanceState != null && savedInstanceState.containsKey("host"))
        host.setText(savedInstanceState.getString("host"));
    else
        host.setText(getSharedPreferences("prefs", 0).getString("host", BuildConfig.HOST));

    if (host.getText().toString().equals("api.irccloud.com")
            || host.getText().toString().equals("www.irccloud.com"))
        host.setText("");

    loginBtn = (Button) findViewById(R.id.loginBtn);
    loginBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new LoginTask().execute((Void) null);
        }
    });
    loginBtn.setFocusable(true);
    loginBtn.requestFocus();

    sendAccessLinkBtn = (Button) findViewById(R.id.sendAccessLink);
    sendAccessLinkBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            new ResetPasswordTask().execute((Void) null);
        }
    });

    nextBtn = (Button) findViewById(R.id.nextBtn);
    nextBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (host.getText().length() > 0) {
                NetworkConnection.IRCCLOUD_HOST = host.getText().toString();
                trimHost();

                new EnterpriseConfigTask().execute((Void) null);
            }
        }
    });

    TOS = (TextView) findViewById(R.id.TOS);
    TOS.setMovementMethod(new LinkMovementMethod());

    forgotPassword = (TextView) findViewById(R.id.forgotPassword);
    forgotPassword.setOnClickListener(forgotPasswordClickListener);

    enterpriseLearnMore = (TextView) findViewById(R.id.enterpriseLearnMore);
    enterpriseLearnMore.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (isPackageInstalled("com.irccloud.android", LoginActivity.this)) {
                startActivity(getPackageManager().getLaunchIntentForPackage("com.irccloud.android"));
            } else {
                try {
                    startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("market://details?id=com.irccloud.android")));
                } catch (Exception e) {
                    startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("http://play.google.com/store/apps/details?id=com.irccloud.android")));
                }
            }
        }

        private boolean isPackageInstalled(String packagename, Context context) {
            PackageManager pm = context.getPackageManager();
            try {
                pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
                return true;
            } catch (NameNotFoundException e) {
                return false;
            }
        }
    });
    enterpriseHint = (LinearLayout) findViewById(R.id.enterpriseHint);

    EnterYourEmail = (TextView) findViewById(R.id.enterYourEmail);

    signupHint.setOnClickListener(signupHintClickListener);
    loginHint.setOnClickListener(loginHintClickListener);

    signupBtn = (Button) findViewById(R.id.signupBtn);
    signupBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            new LoginTask().execute((Void) null);
        }
    });

    TextView version = (TextView) findViewById(R.id.version);
    try {
        version.setText("Version " + getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
    } catch (NameNotFoundException e) {
        version.setVisibility(View.GONE);
    }

    Typeface LatoRegular = Typeface.createFromAsset(getAssets(), "Lato-Regular.ttf");
    Typeface LatoLightItalic = Typeface.createFromAsset(getAssets(), "Lato-LightItalic.ttf");

    for (int i = 0; i < signupHint.getChildCount(); i++) {
        View v = signupHint.getChildAt(i);
        if (v instanceof TextView) {
            ((TextView) v).setTypeface(LatoRegular);
        }
    }

    for (int i = 0; i < loginHint.getChildCount(); i++) {
        View v = loginHint.getChildAt(i);
        if (v instanceof TextView) {
            ((TextView) v).setTypeface(LatoRegular);
        }
    }

    LinearLayout IRCCloud = (LinearLayout) findViewById(R.id.IRCCloud);
    for (int i = 0; i < IRCCloud.getChildCount(); i++) {
        View v = IRCCloud.getChildAt(i);
        if (v instanceof TextView) {
            ((TextView) v).setTypeface(LatoRegular);
        }
    }

    notAProblem = (LinearLayout) findViewById(R.id.notAProblem);
    for (int i = 0; i < notAProblem.getChildCount(); i++) {
        View v = notAProblem.getChildAt(i);
        if (v instanceof TextView) {
            ((TextView) v).setTypeface((i == 0) ? LatoRegular : LatoLightItalic);
        }
    }

    loginSignupHint = (LinearLayout) findViewById(R.id.loginSignupHint);
    for (int i = 0; i < loginSignupHint.getChildCount(); i++) {
        View v = loginSignupHint.getChildAt(i);
        if (v instanceof TextView) {
            ((TextView) v).setTypeface(LatoRegular);
            ((TextView) v).setOnClickListener((i == 0) ? loginHintClickListener : signupHintClickListener);
        }
    }

    name.setTypeface(LatoRegular);
    email.setTypeface(LatoRegular);
    password.setTypeface(LatoRegular);
    host.setTypeface(LatoRegular);
    loginBtn.setTypeface(LatoRegular);
    signupBtn.setTypeface(LatoRegular);
    TOS.setTypeface(LatoRegular);
    EnterYourEmail.setTypeface(LatoRegular);
    hostHint.setTypeface(LatoLightItalic);

    if (BuildConfig.ENTERPRISE) {
        name.setVisibility(View.GONE);
        email.setVisibility(View.GONE);
        password.setVisibility(View.GONE);
        loginBtn.setVisibility(View.GONE);
        signupBtn.setVisibility(View.GONE);
        TOS.setVisibility(View.GONE);
        signupHint.setVisibility(View.GONE);
        loginHint.setVisibility(View.GONE);
        forgotPassword.setVisibility(View.GONE);
        loginSignupHint.setVisibility(View.GONE);
        EnterYourEmail.setVisibility(View.GONE);
        sendAccessLinkBtn.setVisibility(View.GONE);
        notAProblem.setVisibility(View.GONE);
        enterpriseLearnMore.setVisibility(View.VISIBLE);
        enterpriseHint.setVisibility(View.VISIBLE);
        host.setVisibility(View.VISIBLE);
        nextBtn.setVisibility(View.VISIBLE);
        hostHint.setVisibility(View.VISIBLE);
        host.requestFocus();
    }

    if (savedInstanceState != null && savedInstanceState.containsKey("signup")
            && savedInstanceState.getBoolean("signup")) {
        signupHintClickListener.onClick(null);
    }

    if (savedInstanceState != null && savedInstanceState.containsKey("login")
            && savedInstanceState.getBoolean("login")) {
        loginHintClickListener.onClick(null);
    }

    if (savedInstanceState != null && savedInstanceState.containsKey("forgotPassword")
            && savedInstanceState.getBoolean("forgotPassword")) {
        forgotPasswordClickListener.onClick(null);
    }

    mResolvingError = savedInstanceState != null && savedInstanceState.getBoolean("resolving_error", false);

    mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Auth.CREDENTIALS_API)
            .addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
}

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

private void updateDisplay() {
    // In case it's called too early
    if (mTurnData == null || fragments == null) {
        return;/*from  ww w. j a v a 2 s  . c o m*/
    }
    for (Map.Entry<String, GameState.HandNode> entry : mTurnData.state.hands.entrySet()) {
        fragments.get(entry.getKey()).updateHand(entry.getValue().hand);
    }
    LinearLayout played = (LinearLayout) findViewById(R.id.played_pile);
    for (int i = 1; i < played.getChildCount(); i++) {
        ((TextView) played.getChildAt(i)).setText(String.valueOf(mTurnData.state.played[i - 1]));
    }
    ((TextView) findViewById(R.id.deck)).setText(String.valueOf(mTurnData.state.deck.size()));
    ((TextView) findViewById(R.id.hints)).setText(String.valueOf(mTurnData.state.hintsRemaining));
    ((TextView) findViewById(R.id.misplays)).setText(String.valueOf(mTurnData.state.explosionsRemaining));
    if (mDiscardWidthR1 != 0) {
        displayDiscardPiles();
    }
    // TODO(sdspikes): add log

    String logString = "";
    for (String log : actionLog) {
        logString += log + "\n";
    }
    ((TextView) findViewById(R.id.log)).setText(logString);
}

From source file:com.richtodd.android.quiltdesign.app.QuiltEditActivity.java

private void populateLayoutBlocks() {
    List<BlockContainerEntry> entries;
    try {/*from w  w  w  .java2 s. c  o m*/
        Repository repository = Repository.getDefaultRepository(this);
        BlockContainer blocks = repository.getBlocks();
        entries = blocks.getEntries(true);
    } catch (RepositoryException ex) {
        return;
    }

    LinearLayout layoutRow = null;

    for (BlockContainerEntry entry : entries) {
        View view = QuiltEditActivity.this.getLayoutInflater().inflate(R.layout.listentry_block_selector, null);

        ImageView image_thumbnail = (ImageView) view.findViewById(R.id.image_thumbnail);
        image_thumbnail.setImageBitmap(entry.getThumbnail());

        view.setTag(entry.getBlockName());
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String blockName = (String) v.getTag();
                try {
                    getQuiltEditFragment().setBlock(blockName);
                } catch (Exception e) {
                    Handle.asRuntimeError(e);
                }
            }
        });

        if (m_layout_blocks.getOrientation() == LinearLayout.HORIZONTAL) {
            m_layout_blocks.addView(view);
        } else {
            if (layoutRow != null && layoutRow.getChildCount() == m_layout_blocks.getNumColumns()) {
                layoutRow = null;
            }
            if (layoutRow == null) {
                layoutRow = new LinearLayout(this);
                layoutRow.setOrientation(LinearLayout.HORIZONTAL);
                m_layout_blocks.addView(layoutRow);
            }
            layoutRow.addView(view);
        }
    }
}

From source file:info.tellmetime.TellmetimeActivity.java

private void resizeClock() {
    final LinearLayout mClock = (LinearLayout) findViewById(R.id.clock);

    // Set width of #mClock layout to the screen's shorter edge size, so clock is not
    // expanded in landscape mode, but has rather somewhat a square shape.
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.CENTER_IN_PARENT);
    lp.width = mShorterEdge;//w ww .ja  va2s  .com
    mClock.setLayoutParams(lp);

    final float mItemSize = mShorterEdge / mClock.getChildCount();
    final int mRowMargin = (int) -(mItemSize / 2.2);

    // Scale text size according to shorter edge and set spacing between rows.
    for (int i = 0; i < mClock.getChildCount(); i++) {
        LinearLayout row = (LinearLayout) mClock.getChildAt(i);

        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) row.getLayoutParams();
        params.bottomMargin = mRowMargin;
        row.setLayoutParams(params);

        for (int j = 0; j < row.getChildCount(); j++)
            ((TextView) row.getChildAt(j)).setTextSize(TypedValue.COMPLEX_UNIT_PX, mItemSize);
    }
    LinearLayout lastRow = (LinearLayout) mClock.getChildAt(mClock.getChildCount() - 1);
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) lastRow.getLayoutParams();
    params.bottomMargin = 0;
    lastRow.setLayoutParams(params);

    TextView twenty = (TextView) findViewById(R.id.twenty);
    params = (LinearLayout.LayoutParams) twenty.getLayoutParams();
    params.leftMargin = 0;
    twenty.setLayoutParams(params);

    // Inflates minutes indicators and attaches them to main view.
    FrameLayout minutesLayout = (FrameLayout) findViewById(R.id.minutes_indicators);
    minutesLayout.removeAllViews();
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final boolean isLandscape = getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    inflater.inflate(isLandscape ? R.layout.minutes_land : R.layout.minutes_portrait, minutesLayout);
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            isLandscape ? FrameLayout.LayoutParams.MATCH_PARENT : FrameLayout.LayoutParams.WRAP_CONTENT);
    if (!isLandscape) {
        layoutParams.addRule(RelativeLayout.BELOW, R.id.clock);
        layoutParams.topMargin = (int) -TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize / 3,
                getResources().getDisplayMetrics());
    }
    minutesLayout.setLayoutParams(layoutParams);

    ViewGroup minutesDots = (ViewGroup) findViewById(R.id.minutes_dots);
    for (int i = 0; i < minutesDots.getChildCount(); i++)
        ((TextView) minutesDots.getChildAt(i)).setTextSize(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize);
}

From source file:com.h6ah4i.android.example.materialshadowninepatch.ProgrammaticallyAddDemoFragment.java

private void addItem() {
    LinearLayout parent = mItemsContainer;
    Context context = parent.getContext();
    float density = context.getResources().getDisplayMetrics().density;

    AppCompatTextView itemView = new AppCompatTextView(context);

    // Need to specify type of the shadow. Specify one of the following to the fourth parameter.
    ////  w  w  w  . j  a v  a2  s .c o m
    // - R.style.ms9_DefaultShadowStyle[Z6|Z9|Z18]
    // - R.style.ms9_DefaultShadowStyle[Z6|Z9|Z18]CompatOnly
    // - R.style.ms9_NoDisplayedPositionAffectShadowStyle[Z6|Z9|Z18]
    // - R.style.ms9_NoDisplayedPositionAffectShadowStyle[Z6|Z9|Z18]CompatOnly
    // - R.style.ms9_CompositeShadowStyle[Z6|Z9|Z18]
    // - R.style.ms9_CompositeShadowStyle[Z6|Z9|Z18]CompatOnly
    MaterialShadowContainerView shadowView = new MaterialShadowContainerView(context, null, 0,
            R.style.ms9_DefaultShadowStyle);

    // Setup the itemView
    {
        MaterialShadowContainerView.LayoutParams layoutParams = new MaterialShadowContainerView.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, (int) (density * 56));

        // Need to set background color and margins
        itemView.setBackgroundColor(Color.WHITE);
        layoutParams.setMargins((int) (8 * density), (int) (8 * density), (int) (8 * density),
                (int) (8 * density));
        itemView.setLayoutParams(layoutParams);

        itemView.setText("Item " + (parent.getChildCount() + 1));
        itemView.setGravity(Gravity.CENTER);

    }

    // Setup the shadowView
    {
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        shadowView.setLayoutParams(layoutParams);

        shadowView.setShadowElevation(density * 4);
        shadowView.setForceUseCompatShadow(mCheckBoxForceUseCompatMode.isChecked());
    }

    // Add views
    shadowView.addView(itemView);
    parent.addView(shadowView);
}

From source file:foam.opensauces.StarwispBuilder.java

public String WalkDraggable(StarwispActivity ctx, String name, String ctxname, int id) {
    View v = ctx.findViewById(id);
    Class c = v.getClass();// w  w  w .  ja  v  a  2  s  .co m
    String ret = "(";
    if (c == LinearLayout.class) {
        LinearLayout l = (LinearLayout) v;

        ret += m_Scheme.eval("(widget-callback \"" + ctxname + "\" " + id + " '())") + " ";

        for (int i = 0; i < l.getChildCount(); i++) {
            View cv = l.getChildAt(i);
            Class cc = cv.getClass();
            if (cc == LinearLayout.class) {
                ret += WalkDraggable(ctx, name, ctxname, cv.getId());
            }
        }
    }
    ret += ")";

    return ret;
}

From source file:com.fvd.nimbus.PaintActivity.java

void setToolSelected(int id) {
    LinearLayout ll = (LinearLayout) findViewById(R.id.flTools);
    for (int i = 0; i < ll.getChildCount(); i++) {
        ll.getChildAt(i).setSelected(id == ll.getChildAt(i).getId());
    }//from  w w  w  .  jav a2  s  . c  o m

}

From source file:com.fvd.nimbus.PaintActivity.java

void setLandToolSelected(int id) {
    LinearLayout ll = (LinearLayout) findViewById(R.id.tool_edit_land);
    for (int i = 0; i < ll.getChildCount(); i++) {
        ll.getChildAt(i).setSelected(id == ll.getChildAt(i).getId());
    }//from   ww w .j  av  a  2 s  .com

}

From source file:org.linphone.ContactEditorFragment.java

private LinearLayout initNumbersFields(final Contact contact) {
    LinearLayout controls = (LinearLayout) view.findViewById(R.id.controls_numbers);
    controls.removeAllViews();//from w  ww  . j a va 2  s  .c  o m

    if (contact != null) {
        for (String numberOrAddress : contact.getNumbersOrAddresses()) {
            boolean isSip = LinphoneUtils.isStrictSipAddress(numberOrAddress)
                    || !LinphoneUtils.isNumberAddress(numberOrAddress);
            if (!isSip) {
                View view = displayNumberOrAddress(controls, numberOrAddress);
                if (view != null)
                    controls.addView(view);
            }
        }
    }

    if (newSipOrNumberToAdd != null) {
        boolean isSip = LinphoneUtils.isStrictSipAddress(newSipOrNumberToAdd)
                || !LinphoneUtils.isNumberAddress(newSipOrNumberToAdd);
        if (!isSip) {
            View view = displayNumberOrAddress(controls, newSipOrNumberToAdd);
            if (view != null)
                controls.addView(view);
        }
    }

    if (controls.getChildCount() == 0) {
        addEmptyRowToAllowNewNumberOrAddress(controls, false);
    }

    return controls;
}