Example usage for android.widget RelativeLayout getChildCount

List of usage examples for android.widget RelativeLayout getChildCount

Introduction

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

Prototype

public int getChildCount() 

Source Link

Document

Returns the number of children in the group.

Usage

From source file:Main.java

public static void animateIn(View view) {
    if (view instanceof RelativeLayout) {
        RelativeLayout relativeLayout = (RelativeLayout) view;
        for (int i = 0; i < relativeLayout.getChildCount(); i++) {
            View child = relativeLayout.getChildAt(i);
            child.animate().setStartDelay(100 + i * DELAY).alpha(1).scaleX(1).scaleY(1);
        }//from   w  w w  .j a  v  a 2  s  .co m
    } else {
        LinearLayout linearLayout = (LinearLayout) view;
        for (int i = 0; i < linearLayout.getChildCount(); i++) {
            View child = linearLayout.getChildAt(i);
            child.animate().setStartDelay(100 + i * DELAY).alpha(1).scaleX(1).scaleY(1);
        }
    }
}

From source file:Main.java

public static void animateOut(View view) {
    if (view instanceof RelativeLayout) {
        RelativeLayout relativeLayout = (RelativeLayout) view;
        for (int i = 0; i < relativeLayout.getChildCount(); i++) {
            View child = relativeLayout.getChildAt(i);
            child.animate().setStartDelay(i).alpha(0).scaleX(0f).scaleY(0f);
        }/*ww  w. ja v a  2  s  . com*/
    } else {
        LinearLayout linearLayout = (LinearLayout) view;
        for (int i = 0; i < linearLayout.getChildCount(); i++) {
            View child = linearLayout.getChildAt(i);
            child.animate().setStartDelay(i).alpha(0).scaleX(0f).scaleY(0f);
        }
    }

}

From source file:sysnetlab.android.sdc.test.TestHelper.java

public static void selectSensors(ActivityInstrumentationTestCase2<?> testCase, Activity activity) {
    Assert.assertTrue("The activity must be a CreateExperimentActivity.",
            activity instanceof CreateExperimentActivity);

    // choose to select sensors
    CreateExperimentActivity createExperimentActivity = (CreateExperimentActivity) activity;

    Fragment fragment = createExperimentActivity.getSupportFragmentManager()
            .findFragmentById(R.id.fragment_container);
    Assert.assertNotNull("The ExperimentSetupFragment should not be null.", fragment);
    Assert.assertTrue("The fragment should be an ExperimentSetupFragment.",
            fragment instanceof ExperimentSetupFragment);

    ListView listViewOperations = (ListView) fragment.getView().findViewById(R.id.lv_operations);
    Assert.assertNotNull("The operations ListView should not be null.", listViewOperations);
    Assert.assertEquals("The operations ListView should has 3 items", listViewOperations.getCount(), 3);

    TouchUtils.clickView(testCase, listViewOperations.getChildAt(2));

    testCase.getInstrumentation().waitForIdleSync();

    // select the 1st sensor
    fragment = createExperimentActivity.getSupportFragmentManager().findFragmentById(R.id.fragment_container);
    Assert.assertNotNull("The ExperimentSensorSelectionFragment should not be null.", fragment);
    Assert.assertTrue("The fragment should be an ExperimentSensorListFragment.",
            fragment instanceof ExperimentSensorSelectionFragment);

    RelativeLayout layout = (RelativeLayout) fragment.getView().findViewById(R.id.layout_sensor_selection_list);
    Assert.assertNotNull("The Sensor ListView should not be null.", layout);
    ListView sensorListView = null;
    for (int i = 0; i < layout.getChildCount(); i++) {
        View child = layout.getChildAt(i);
        if (child instanceof ListView)
            sensorListView = (ListView) child;
    }//from w  w w .  jav a2 s . com
    Assert.assertNotNull("The Sensor ListView should not be null", sensorListView);

    int numberOfSensorsToSelect = (int) (Math.random() * sensorListView.getCount()) + 1;
    int numberOfSensorsSelected = 0;
    int sensorPosition = 0;
    while (numberOfSensorsSelected < numberOfSensorsToSelect) {
        double rn = Math.random();
        if ((sensorListView.getCount() - sensorPosition) * rn >= numberOfSensorsToSelect
                - numberOfSensorsSelected) {
            sensorPosition++;
        } else {
            TouchUtils.clickView(testCase, sensorListView.getChildAt(sensorPosition).findViewById(R.id.check));
            sensorPosition++;
            numberOfSensorsSelected++;
        }
    }

    testCase.getInstrumentation().waitForIdleSync();
}

From source file:org.secuso.privacyfriendlydicegame.MainActivity.java

public void resetInterface() {
    roundCounter = 0;//from   www. j a  v a  2 s  . c  om
    TextView roundCounterTextView = (TextView) findViewById(R.id.roundTextView);
    roundCounterTextView.setText(Integer.toString(roundCounter));

    for (int k = 0; k < isLocked.length; k++) {
        isLocked[k] = false;
    }

    for (int i = 0; i < dice.length; i++) {
        dice[i].setBackgroundDrawable(getResources().getDrawable(R.drawable.dice));
    }

    RelativeLayout diceContainer = (RelativeLayout) findViewById(R.id.dice_frame);
    RelativeLayout diceRowTwo = (RelativeLayout) findViewById(R.id.dice_frame_second);

    if (diceContainer.getChildCount() > 0)
        diceContainer.removeAllViews();
    if (diceRowTwo.getChildCount() > 0)
        diceRowTwo.removeAllViews();

    for (int i = 0; i < dice.length; i++) {
        dice[i].setBackground(getResources().getDrawable(R.drawable.invisible_button));
    }

    hints(0);

}

From source file:ca.ualberta.cmput301w14t08.geochan.fragments.ThreadViewFragment.java

/**
 * When a comment is clicked, this method deflates the additional 
 * (location and button) layout of other comments in the list.
 * //  w  ww  .jav  a 2  s.co  m
 * TODO: make it also deflate the layouts of comments off the screen.
 * 
 * @param position The position of the Comment that will not be deflated.
 */
private void resetOtherCommentLayouts(int position) {
    for (int i = 2; i < threadView.getCount() + 1; ++i) {

        if (i == position + 1) {
            continue;
        }
        View v = threadView.getChildAt(i);
        if (v == null) {
            continue;
        }
        RelativeLayout relativeInflater = (RelativeLayout) v.findViewById(R.id.relative_inflater);
        if (relativeInflater != null && relativeInflater.getChildCount() > 0) {
            relativeInflater.removeAllViews();
        }
    }

}

From source file:com.frostwire.android.gui.activities.MainActivity2.java

private void updateHeader(Fragment fragment) {
    try {//from   ww w .  ja va 2  s.  c o  m
        RelativeLayout placeholder = (RelativeLayout) getActionBar().getCustomView();
        if (placeholder != null && placeholder.getChildCount() > 0) {
            placeholder.removeAllViews();
        }

        if (fragment instanceof MainFragment) {
            View header = ((MainFragment) fragment).getHeader(this);
            if (placeholder != null && header != null) {
                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                        LayoutParams.WRAP_CONTENT);
                params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
                placeholder.addView(header, params);
            }
        }
    } catch (Throwable e) {
        LOG.error("Error updating main header", e);
    }
}

From source file:com.bt.download.android.gui.activities.MainActivity.java

private void updateHeader(Fragment fragment) {
    try {/*w  w  w. jav a 2s.  co  m*/
        RelativeLayout placeholder = (RelativeLayout) getActionBar().getCustomView();//findView(R.id.activity_main_layout_header_placeholder);
        if (placeholder != null && placeholder.getChildCount() > 0) {
            placeholder.removeAllViews();
        }

        if (fragment instanceof MainFragment) {
            View header = ((MainFragment) fragment).getHeader(this);
            if (placeholder != null && header != null) {
                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                        LayoutParams.WRAP_CONTENT);
                params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
                placeholder.addView(header, params);
            }
        }
    } catch (Throwable e) {
        LOG.error("Error updating main header", e);
    }
}

From source file:org.dkf.jmule.activities.MainActivity.java

private void updateHeader(Fragment fragment) {
    try {//  ww w.j  a  va2 s. c o  m
        RelativeLayout placeholder = (RelativeLayout) getActionBar().getCustomView();
        if (placeholder != null && placeholder.getChildCount() > 0) {
            placeholder.removeAllViews();
        }

        if (fragment instanceof MainFragment) {
            View header = ((MainFragment) fragment).getHeader(this);
            if (placeholder != null && header != null) {
                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                        LayoutParams.WRAP_CONTENT);
                params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
                placeholder.addView(header, params);
            }
        }
    } catch (Exception e) {
        log.error("Error updating main header", e);
    }
}

From source file:ch.uzh.supersede.feedbacklibrary.AnnotateImageActivity.java

private void removeOutOfBoundsAnnotations() {
    RelativeLayout relativeLayout = (RelativeLayout) findViewById(
            R.id.supersede_feedbacklibrary_annotate_image_layout);
    if (relativeLayout != null) {
        List<View> toRemove = new ArrayList<>();
        int newBitmapWidth = annotateImageView.getBitmapWidth();
        int newBitmapHeight = annotateImageView.getBitmapHeight();
        float fraction = 0.5f;
        for (int i = 0; i < relativeLayout.getChildCount(); ++i) {
            View child = relativeLayout.getChildAt(i);
            if (child instanceof StickerAnnotationView || child instanceof TextAnnotationView) {
                // A fraction the sticker should be visible, if not the sticker will be removed
                float deleteThresholdX = child.getWidth() * fraction;
                float deleteThresholdY = child.getHeight() * fraction;
                float x = child.getX();
                float y = child.getY();

                boolean xOk = true;
                boolean yOk = true;
                if (x < 0) {
                    xOk = Math.abs(x) < deleteThresholdX;
                } else if (x > 0 && !(x < 0)) {
                    xOk = x + deleteThresholdX < newBitmapWidth;
                }/* w  ww.  j  av  a 2 s  . c o  m*/
                if (y < 0) {
                    yOk = Math.abs(y) < deleteThresholdY;
                } else if (y > 0 && !(y < 0)) {
                    yOk = y + deleteThresholdY < newBitmapHeight;
                }

                if (!(xOk && yOk)) {
                    toRemove.add(child);
                }
            }
        }

        for (int i = 0; i < toRemove.size(); ++i) {
            relativeLayout.removeView(toRemove.get(i));
        }
        toRemove.clear();

        textAnnotationCounter = 1;
        for (int i = 0; i < relativeLayout.getChildCount(); ++i) {
            View child = relativeLayout.getChildAt(i);
            if (child instanceof TextAnnotationView) {
                String newAnnotationNumber = Integer.toString(textAnnotationCounter);
                ((TextAnnotationImageView) child).getAnnotationNumberView().setText(newAnnotationNumber);
                textAnnotationCounter++;
            }
            if (textAnnotationCounter > textAnnotationCounterMaximum) {
                break;
            }
        }
    }
}

From source file:org.secuso.privacyfriendlydicegame.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from  ww  w.  j  a  va 2s  .  c  o m

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    hints(0);

    Display display = getWindowManager().getDefaultDisplay();
    setSizes(display.getWidth() / 40, Math.round(display.getWidth() / 4));

    final TextView finalResult = (TextView) findViewById(R.id.resultTextView);

    Button rollDiceButtonNotFinal = (Button) findViewById(R.id.button);
    rollDiceButtonNotFinal.setText(getString(R.string.roll_button));

    dice = new Button[5];
    dice[0] = (Button) findViewById(R.id.button_dice_one);
    dice[1] = (Button) findViewById(R.id.button_dice_two);
    dice[2] = (Button) findViewById(R.id.button_dice_three);
    dice[3] = (Button) findViewById(R.id.button_dice_four);
    dice[4] = (Button) findViewById(R.id.button_dice_five);

    for (int i = 0; i < dice.length; i++) {
        dice[i].setWidth(Math.round(diceSize));
        dice[i].setHeight(Math.round(diceSize));
    }

    isLocked = new boolean[5];
    for (int k = 0; k < isLocked.length; k++) {
        isLocked[k] = false;
    }

    for (int i = 0; i < dice.length; i++) {
        dice[i].setBackground(getResources().getDrawable(R.drawable.invisible_button));
    }

    oldResults = new int[] { 1, 2, 3, 4, 5 };
    backResults = new int[] { 1, 2, 3, 4, 5 };

    roundCounter = 0;

    final RelativeLayout diceContainer = (RelativeLayout) findViewById(R.id.dice_frame);
    final RelativeLayout diceRowTwo = (RelativeLayout) findViewById(R.id.dice_frame_second);

    //buttons
    final Button rollDiceButton = (Button) findViewById(R.id.button);
    rollDiceButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            if (allTrue(isLocked)) {
                for (int k = 0; k < dice.length; k++) {
                    dice[k].setBackground(getResources().getDrawable(R.drawable.dice_final));
                }
                finalResult.setVisibility(View.VISIBLE);
                rollDiceButton.setText(getString(R.string.new_round_button));
                roundCounter = 3;
                for (int k = 0; k < isLocked.length; k++) {
                    isLocked[k] = false;
                }
            } else {

                if (diceContainer.getChildCount() > 0)
                    diceContainer.removeAllViews();
                if (diceRowTwo.getChildCount() > 0)
                    diceRowTwo.removeAllViews();
                setDice(rollDice(5));

                if (roundCounter == 0) {
                    for (int k = 0; k < dice.length; k++) {
                        dice[k].setBackground(getResources().getDrawable(R.drawable.dice));
                    }
                }

                if (roundCounter == 2) {
                    for (int k = 0; k < dice.length; k++) {
                        dice[k].setBackground(getResources().getDrawable(R.drawable.dice_final));
                    }
                    finalResult.setVisibility(View.VISIBLE);
                    rollDiceButton.setText(getString(R.string.new_round_button));
                }

                if (roundCounter == 3) {
                    resetInterface();
                    finalResult.setVisibility(View.INVISIBLE);
                    rollDiceButton.setText(getString(R.string.roll_button));

                } else {
                    roundCounter++;
                }
                TextView roundCounterTextView = (TextView) findViewById(R.id.roundTextView);
                roundCounterTextView.setText(Integer.toString(roundCounter));
                flashResult();
            }
        }
    });

    Button resetButton = (Button) findViewById(R.id.resetButton);
    resetButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (roundCounter != 0) {
                resetInterface();
                finalResult.setVisibility(View.INVISIBLE);
            }

        }
    });

    for (int j = 0; j < dice.length; j++) {
        final int finalJ = j;
        dice[j].setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (roundCounter == 0) {
                } else if (roundCounter != 3) {
                    setLock(finalJ, v);
                }
            }
        });
    }

}