Example usage for android.view ViewGroup indexOfChild

List of usage examples for android.view ViewGroup indexOfChild

Introduction

In this page you can find the example usage for android.view ViewGroup indexOfChild.

Prototype

public int indexOfChild(View child) 

Source Link

Document

Returns the position in the group of the specified child view.

Usage

From source file:gr.plushost.prototypeapp.widgets.LabelView.java

public void remove() {
    if (getParent() == null || _labelViewContainerID == -1) {
        return;/*from w ww .  j av  a2  s  .c om*/
    }

    ViewGroup frameContainer = (ViewGroup) getParent();
    assert (frameContainer.getChildCount() == 2);
    View target = frameContainer.getChildAt(0);

    ViewGroup parentContainer = (ViewGroup) frameContainer.getParent();
    int groupIndex = parentContainer.indexOfChild(frameContainer);
    if (frameContainer.getParent() instanceof RelativeLayout) {
        for (int i = 0; i < parentContainer.getChildCount(); i++) {
            if (i == groupIndex) {
                continue;
            }
            View view = parentContainer.getChildAt(i);
            RelativeLayout.LayoutParams para = (RelativeLayout.LayoutParams) view.getLayoutParams();
            for (int j = 0; j < para.getRules().length; j++) {
                if (para.getRules()[j] == _labelViewContainerID) {
                    para.getRules()[j] = target.getId();
                }
            }
            view.setLayoutParams(para);
        }
    }

    ViewGroup.LayoutParams frameLayoutParam = frameContainer.getLayoutParams();
    target.setLayoutParams(frameLayoutParam);
    parentContainer.removeViewAt(groupIndex);
    frameContainer.removeView(target);
    frameContainer.removeView(this);
    parentContainer.addView(target, groupIndex);
    _labelViewContainerID = -1;
}

From source file:pro.dbro.bart.ViewCountDownTimer.java

@Override
public void onTick(long millisUntilFinished) {
    // Prevent timer from ticking within MINIMUM_TICK_MS of beginning
    // Prevents unnecessary view re-drawing, assuming UI initial data is updated before timer set
    if (COUNTDOWN_TIME_MS - millisUntilFinished < MINIMUM_TICK_MS) {
        return;/*from  w  w  w  .j ava  2 s  . c om*/
    }
    // Get current time in MS since '70
    long now = new Date().getTime();

    for (int x = 0; x < timerViews.size(); x++) {
        // ETA tagged on TimerView is ms since '70
        long eta = (Long) ((TextView) timerViews.get(x)).getTag();

        // If train was scheduled to leave more than DEPARTING_TRAIN_PADDING_MS ago, remove it from view
        if ((eta + DEPARTING_TRAIN_PADDING_MS - now) < 0) {
            // If an etd or route countdown has expired, hide it's view
            try {
                if (request.compareTo("route") == 0) {

                    View parent = ((View) ((TextView) timerViews.get(x)).getParent());
                    route thisRoute = (route) parent.getTag();
                    parent.setVisibility(View.GONE);
                    if (thisRoute.isExpanded) {
                        ViewGroup grandparent = (ViewGroup) parent.getParent();
                        //if route view is expanded, the next row in Table will be route detail
                        grandparent.getChildAt((grandparent.indexOfChild(parent) + 1)).setVisibility(View.GONE);
                    }
                    //tableLayout.removeView((View)((View)timerViews.get(x)).getParent());
                } else if (request.compareTo("etd") == 0) {
                    ((TextView) timerViews.get(x)).setVisibility(View.GONE);
                }
            } catch (Throwable t) {
                // removing departed trains is a 'garnish' so let's not 
                // worry TOO much if some weird casting exception crops up
            }

        }
        // Else if train was scheduled to leave less than DEPARTING_TRAIN_PADDING_MS ago, show it in view, but set eta = 0
        // set eta = 0 tied to display "<1m". Due to integer division time between 0 and 60*1000-1 ms will be displayed as 0
        else if ((eta - now) <= 60 * 1000) {
            eta = 0;
        } else {
            eta = eta - now;
        }
        // Display 0 eta as "<1"
        if (eta == 0)
            ((TextView) timerViews.get(x)).setText("<1");
        else
            ((TextView) timerViews.get(x)).setText(String.valueOf((eta) / (1000 * 60)));
    }
}

From source file:com.csumax.maxgithubclient.fragment.ProgressFragment.java

public void setContentView(View view) {
    ensureContent();/*from w  w  w  .  j  ava2s  .co  m*/
    if (view == null) {
        throw new IllegalArgumentException("Content view can't be null");
    }
    if (mContentContainer instanceof ViewGroup) {
        ViewGroup contentContainer = (ViewGroup) mContentContainer;
        if (mContentView == null) {
            contentContainer.addView(view);
        } else {
            int index = contentContainer.indexOfChild(mContentView);
            // replace content view
            contentContainer.removeView(mContentView);
            contentContainer.addView(view, index);
        }
        mContentView = view;
    } else {
        throw new IllegalStateException("Can't be used with a custom content view");
    }
}

From source file:com.ashlikun.badgeview.BadgeView.java

public void setTargetView(View target) {
    if (getParent() != null) {
        ((ViewGroup) getParent()).removeView(this);
    }//  w  w w . ja v  a 2s  .c  o m

    if (target == null) {
        return;
    }

    if (target.getParent() instanceof FrameLayout) {
        ((FrameLayout) target.getParent()).addView(this);

    } else if (target.getParent() instanceof ViewGroup) {
        // use a new Framelayout container for adding badge
        ViewGroup parentContainer = (ViewGroup) target.getParent();
        int groupIndex = parentContainer.indexOfChild(target);
        parentContainer.removeView(target);

        FrameLayout badgeContainer = new FrameLayout(getContext());
        ViewGroup.LayoutParams parentLayoutParams = target.getLayoutParams();

        badgeContainer.setLayoutParams(parentLayoutParams);
        target.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));

        parentContainer.addView(badgeContainer, groupIndex, parentLayoutParams);
        badgeContainer.addView(target);

        badgeContainer.addView(this);
    } else if (target.getParent() == null) {
        Log.e(getClass().getSimpleName(), "ParentView is needed");
    }

}

From source file:org.digitalcampus.oppia.widgets.FeedbackWidget.java

public void showResults() {

    if (!isOnResultsPage) {
        // log the activity as complete
        isOnResultsPage = true;/*from  w  ww . j  a  va 2s .  c  om*/
        this.saveTracker();

        // save results ready to send back to the quiz server
        String data = feedback.getResultObject().toString();
        DbHelper db = new DbHelper(super.getActivity());
        long userId = db.getUserId(prefs.getString(PrefsActivity.PREF_USER_NAME, ""));

        QuizAttempt qa = new QuizAttempt();
        qa.setCourseId(course.getCourseId());
        qa.setUserId(userId);
        qa.setData(data);
        qa.setActivityDigest(activity.getDigest());
        qa.setScore(feedback.getUserscore());
        qa.setMaxscore(feedback.getMaxscore());
        qa.setPassed(this.getActivityCompleted());

        db.insertQuizAttempt(qa);
        DatabaseManager.getInstance().closeDatabase();
    }

    //Check if feedback results layout is already loaded
    View feedbackResultsLayout = getView().findViewById(R.id.widget_feedback_results);
    if (feedbackResultsLayout == null) {
        View view = getView().findViewById(R.id.quiz_progress);
        ViewGroup parent = (ViewGroup) view.getParent();
        int index = parent.indexOfChild(view);
        parent.removeView(view);
        view = super.getActivity().getLayoutInflater().inflate(R.layout.widget_feedback_results, parent, false);
        parent.addView(view, index);
    }
}

From source file:org.orange.querysystem.content.ListPostsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View layout = super.onCreateView(inflater, container, savedInstanceState);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        View lv = layout.findViewById(android.R.id.list);
        ViewGroup parent = (ViewGroup) lv.getParent();
        // Remove ListView and add CustomView  in its place
        int lvIndex = parent.indexOfChild(lv);
        parent.removeViewAt(lvIndex);/*from  www.  j a  v  a 2s .  c  om*/

        mLinearLayout = new LinearLayout(getActivity());
        mLinearLayout.setOrientation(LinearLayout.VERTICAL);
        if (mFilter != null) {
            insertSearchEditText().setText(mFilter);
        }
        mLinearLayout.addView(lv);
        parent.addView(mLinearLayout, lvIndex, lv.getLayoutParams());
    }
    return layout;
}

From source file:com.devspark.progressfragment.ProgressFragment.java

/**
 * Set the content view to an explicit view. If the content view was installed earlier,
 * the content will be replaced with a new view.
 *
 * @param view The desired content to display. Value can't be null.
 * @see #setContentView(int)/*from   ww  w.  j a  v  a 2s  . c om*/
 * @see #getContentView()
 */
public void setContentView(View view) {
    ensureContent();
    if (view == null) {
        throw new IllegalArgumentException("Content view can't be null");
    }
    if (mContentContainer instanceof ViewGroup) {
        ViewGroup contentContainer = (ViewGroup) mContentContainer;
        if (mContentView == null) {
            contentContainer.addView(view);
        } else {
            int index = contentContainer.indexOfChild(mContentView);
            // replace content view
            contentContainer.removeView(mContentView);
            contentContainer.addView(view, index);
        }
        mContentView = view;
    } else {
        throw new IllegalStateException("Can't be used with a custom content view");
    }
}

From source file:gr.plushost.prototypeapp.widgets.LabelView.java

private boolean replaceLayout(View target) {
    if (getParent() != null || target == null || target.getParent() == null || _labelViewContainerID != -1) {
        return false;
    }//  w w  w  .  j av a  2 s.  c o  m

    ViewGroup parentContainer = (ViewGroup) target.getParent();

    if (target.getParent() instanceof FrameLayout) {
        ((FrameLayout) target.getParent()).addView(this);
    } else if (target.getParent() instanceof ViewGroup) {

        int groupIndex = parentContainer.indexOfChild(target);
        _labelViewContainerID = generateViewId();

        // relativeLayout need copy rule
        if (target.getParent() instanceof RelativeLayout) {
            for (int i = 0; i < parentContainer.getChildCount(); i++) {
                if (i == groupIndex) {
                    continue;
                }
                View view = parentContainer.getChildAt(i);
                RelativeLayout.LayoutParams para = (RelativeLayout.LayoutParams) view.getLayoutParams();
                for (int j = 0; j < para.getRules().length; j++) {
                    if (para.getRules()[j] == target.getId()) {
                        para.getRules()[j] = _labelViewContainerID;
                    }
                }
                view.setLayoutParams(para);
            }
        }
        parentContainer.removeView(target);

        // new dummy layout
        FrameLayout labelViewContainer = new FrameLayout(getContext());
        ViewGroup.LayoutParams targetLayoutParam = target.getLayoutParams();
        labelViewContainer.setLayoutParams(targetLayoutParam);
        target.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));

        // add target and label in dummy layout
        labelViewContainer.addView(target);
        labelViewContainer.addView(this);
        labelViewContainer.setId(_labelViewContainerID);

        // add dummy layout in parent container
        parentContainer.addView(labelViewContainer, groupIndex, targetLayoutParam);
    }
    return true;
}

From source file:wseemann.media.demo.FMMRFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View layout = super.onCreateView(inflater, container, savedInstanceState);
    ListView lv = (ListView) layout.findViewById(android.R.id.list);
    ViewGroup parent = (ViewGroup) lv.getParent();

    View v = inflater.inflate(R.layout.fragment, container, false);

    // Remove ListView and add my view in its place
    int lvIndex = parent.indexOfChild(lv);
    parent.removeViewAt(lvIndex);/* www .ja  va  2s.c o  m*/
    parent.addView(v, lvIndex, lv.getLayoutParams());

    final EditText uriText = (EditText) v.findViewById(R.id.uri);
    // Uncomment for debugging
    //uriText.setText("http://...");
    //uriText.setText("http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_1080p_60fps_stereo_abl.mp4");
    //https://ia700401.us.archive.org/19/items/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4

    Intent intent = getActivity().getIntent();

    // Populate the edit text field with the intent uri, if available
    Uri uri = intent.getData();

    if (intent.getExtras() != null && intent.getExtras().getCharSequence(Intent.EXTRA_TEXT) != null) {
        uri = Uri.parse(intent.getExtras().getCharSequence(Intent.EXTRA_TEXT).toString());
    }

    if (uri != null) {
        try {
            uriText.setText(URLDecoder.decode(uri.toString(), "UTF-8"));
        } catch (UnsupportedEncodingException e1) {
        }
    }

    getActivity().setIntent(null);

    Button goButton = (Button) v.findViewById(R.id.go_button);
    goButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // Clear the error message
            uriText.setError(null);

            // Hide the keyboard
            InputMethodManager imm = (InputMethodManager) FMMRFragment.this.getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(uriText.getWindowToken(), 0);

            String uri = uriText.getText().toString();

            if (uri.equals("")) {
                uriText.setError(getString(R.string.uri_error));
                return;
            }

            // Start out with a progress indicator.
            setListShown(false);

            String uriString = uriText.getText().toString();

            Bundle bundle = new Bundle();
            try {
                bundle.putString("uri", URLDecoder.decode(uriString, "UTF-8"));
                mId++;
                FMMRFragment.this.getLoaderManager().initLoader(mId, bundle, FMMRFragment.this);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            //   mAdapter.add(new Metadata("test", "test"));
            //   mAdapter.notifyDataSetChanged();
        }
    });

    return layout;
}

From source file:org.sufficientlysecure.keychain.remote.ui.AccountsListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View layout = super.onCreateView(inflater, container, savedInstanceState);
    ListView lv = (ListView) layout.findViewById(android.R.id.list);
    ViewGroup parent = (ViewGroup) lv.getParent();

    /*// w w  w .j a  v a 2 s. com
     * http://stackoverflow.com/a/15880684
     * Remove ListView and add FixedListView in its place.
     * This is done here programatically to be still able to use the progressBar of ListFragment.
     *
     * We want FixedListView to be able to put this ListFragment inside a ScrollView
     */
    int lvIndex = parent.indexOfChild(lv);
    parent.removeViewAt(lvIndex);
    FixedListView newLv = new FixedListView(getActivity());
    newLv.setId(android.R.id.list);
    parent.addView(newLv, lvIndex, lv.getLayoutParams());
    return layout;
}