List of usage examples for android.view ViewGroup indexOfChild
public int indexOfChild(View child)
From source file:widgets.QuizWidget.java
private void restart() { this.setStartTime(System.currentTimeMillis() / 1000); quiz = new Quiz(); quiz.load(quizContent);/*from w w w . j a v a 2 s . com*/ isOnResultsPage = false; // reload quiz layout View C = getView().findViewById(R.id.widget_quiz_results); ViewGroup parent = (ViewGroup) C.getParent(); int index = parent.indexOfChild(C); parent.removeView(C); C = super.getActivity().getLayoutInflater().inflate(R.layout.widget_quiz, parent, false); parent.addView(C, index); prevBtn = (Button) getView().findViewById(R.id.mquiz_prev_btn); nextBtn = (Button) getView().findViewById(R.id.mquiz_next_btn); qText = (TextView) getView().findViewById(R.id.question_text); questionImage = (LinearLayout) getView().findViewById(R.id.question_image); questionImage.setVisibility(View.GONE); this.showQuestion(); }
From source file:com.dabay6.libraries.androidshared.ui.fragments.LoadingFragment.java
/** * @param view// w ww. ja va 2 s.c o m */ public void setContentView(final View view) { afterViews(); if (view == null) { throw new IllegalArgumentException("Content view can't be null"); } if (contentContainer instanceof ViewGroup) { final ViewGroup container = (ViewGroup) contentContainer; if (content == null) { container.addView(view); } else { final int index = container.indexOfChild(content); // replace content view container.removeView(content); container.addView(view, index); } content = view; } else { throw new IllegalStateException("Can't be used with a custom content view"); } }
From source file:com.hayukleung.app.BaseFragment.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./* w w w .java 2 s .c o m*/ * * @param view The desired content to display. Value can't be null. * @see #setContentView(int) * @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; ViewParent contentViewParent = view.getParent(); if (contentViewParent == null) { if (mContentView == null) { contentContainer.addView(view); } else { int index = contentContainer.indexOfChild(mContentView); // replace content view contentContainer.removeView(mContentView); contentContainer.addView(view, index); } } else if (contentViewParent != mContentContainer) { throw new IllegalArgumentException("Content view can't be in other ViewGroup"); } mContentView = view; } else { throw new IllegalStateException("Can't be used with a custom content view"); } }
From source file:widgets.QuizWidget.java
public void showResults() { // log the activity as complete isOnResultsPage = true;/* w w w . ja v a 2s. com*/ this.saveTracker(); // save results ready to send back to the quiz server String data = quiz.getResultObject().toString(); DbHelper db = new DbHelper(super.getActivity()); db.insertQuizResult(data, course.getModId()); db.close(); Log.d(TAG, data); // load new layout View C = getView().findViewById(R.id.quiz_progress); ViewGroup parent = (ViewGroup) C.getParent(); int index = parent.indexOfChild(C); parent.removeView(C); C = super.getActivity().getLayoutInflater().inflate(R.layout.widget_quiz_results, parent, false); parent.addView(C, index); TextView title = (TextView) getView().findViewById(R.id.quiz_results_score); title.setText(super.getActivity().getString(R.string.widget_quiz_results_score, this.getPercent())); if (this.isBaseline) { TextView baselineExtro = (TextView) getView().findViewById(R.id.quiz_results_baseline); baselineExtro.setVisibility(View.VISIBLE); baselineExtro.setText(super.getActivity().getString(R.string.widget_quiz_baseline_completed)); } // TODO add TextView here to give overall feedback if it's in the quiz // Show the detail of which questions were right/wrong ListView questionFeedbackLV = (ListView) getView().findViewById(R.id.quiz_results_feedback); ArrayList<QuizFeedback> quizFeedback = new ArrayList<QuizFeedback>(); List<QuizQuestion> questions = this.quiz.getQuestions(); for (QuizQuestion q : questions) { if (!(q instanceof Description)) { QuizFeedback qf = new QuizFeedback(); qf.setScore(q.getScoreAsPercent()); qf.setQuestionText(q.getTitle()); qf.setUserResponse(q.getUserResponses()); qf.setFeedbackText(q.getFeedback()); quizFeedback.add(qf); } } QuizFeedbackAdapter qfa = new QuizFeedbackAdapter(super.getActivity(), quizFeedback); questionFeedbackLV.setAdapter(qfa); // Show restart or continue button Button restartBtn = (Button) getView().findViewById(R.id.quiz_results_button); if (this.isBaseline) { restartBtn.setText(super.getActivity().getString(R.string.widget_quiz_baseline_goto_course)); restartBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { QuizWidget.this.getActivity().finish(); } }); } else { restartBtn.setText(super.getActivity().getString(R.string.widget_quiz_results_restart)); restartBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { QuizWidget.this.restart(); } }); } }
From source file:com.rowland.hashtrace.ui.fragments.subfragment.TweetListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The ArrayAdapter will take data from a source and use it to populate the ListView it's attached to. mTweetListAdapter = new TweetListAdapter(getActivity(), null, 0); creator = new SwipeMenuCreator() { @Override/* ww w .ja v a2 s. c om*/ public void create(SwipeMenu menu) { // create "share" item SwipeMenuItem shareItem = new SwipeMenuItem(getActivity().getApplicationContext()); // set item background shareItem.setBackground(new ColorDrawable(Color.rgb(211, 214, 219))); // set item width shareItem.setWidth(Utility.convertDpToPixel(100, getResources().getDisplayMetrics())); // set icon resource shareItem.setIcon(R.drawable.selector_swipemenuitem_share); // set item title shareItem.setTitle("Share"); // set item title fontsize shareItem.setTitleSize(18); // set item title font color shareItem.setTitleColor(Color.WHITE); // add to menu menu.addMenuItem(shareItem); // create "favour" item SwipeMenuItem favourItem = new SwipeMenuItem(getActivity().getApplicationContext()); // set item background favourItem.setBackground(new ColorDrawable(Color.rgb(211, 214, 219))); // set item width favourItem.setWidth(Utility.convertDpToPixel(100, getResources().getDisplayMetrics())); // set icon resource favourItem.setIcon(R.drawable.selector_swipemenuitem_favorite); // set item title favourItem.setTitle("Like"); // set item title fontsize favourItem.setTitleSize(18); // set item title font color favourItem.setTitleColor(Color.WHITE); // add to menu menu.addMenuItem(favourItem); } }; View rootView = inflater.inflate(R.layout.fragment_tweet_list, container, false); mListView = (SwipeMenuListView) rootView.findViewById(android.R.id.list); ViewGroup parent = (ViewGroup) mListView.getParent(); int lvIndex = parent.indexOfChild(mListView); if (mListView.getParent() != null) { parent.removeViewAt(lvIndex); } mListView.setVisibility(View.GONE); mPullToRefreshListView = new PullToRefreshSwipeMenuListView(getActivity()); mPullToRefreshListView.setLayoutParams(mListView.getLayoutParams()); parent.addView(mPullToRefreshListView, lvIndex, mListView.getLayoutParams()); View emptyView = rootView.findViewById(R.id.empty_text_view); mPullToRefreshListView.setEmptyView(emptyView); mPullToRefreshListView.setAdapter(mTweetListAdapter); mPullToRefreshListView.setMenuCreator(creator); mPullToRefreshListView.setVerticalFadingEdgeEnabled(true); mPullToRefreshListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<SwipeMenuListView>() { @Override public void onRefresh(final PullToRefreshBase<SwipeMenuListView> refreshView) { // Do work to refresh the list here. updateTweet(); // Call onRefreshComplete when the list has been refreshed. refreshView.onRefreshComplete(); //mPullToRefreshListView.onRefreshComplete(); } }); //This somehow refuses to work , I really have no idea why /* mPullToRefreshListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long rowId) { Cursor cursor = mTweetListAdapter.getCursor(); if (cursor != null && cursor.moveToPosition(position)) { ((onTweetItemSelectedCallback) getActivity()).onTweetItemSelected(cursor.getString(COL_TWEET_TEXT_DATE)); Log.d("ROWSELECT", "" + rowId ); } mPosition = position; } });*/ mPullToRefreshListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long rowId) { // Do the onItemLongClick action mPullToRefreshListView.smoothOpenMenu(position); return true; } }); mPullToRefreshListView.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(int position, SwipeMenu menu, int index) { switch (index) { case 0: // Share shareTweet(); break; case 1: // Favourite favouriteTweet(); break; } // false : close the menu; true : not close the menu return false; } }); /** * Add Sound Event Listener */ SoundPullEventListener<SwipeMenuListView> soundListener = new SoundPullEventListener<SwipeMenuListView>( getActivity()); soundListener.addSoundEvent(State.PULL_TO_REFRESH, R.raw.pull_event_mp3); soundListener.addSoundEvent(State.RESET, R.raw.reset_sound_mp3); soundListener.addSoundEvent(State.REFRESHING, R.raw.refreshing_sound_mp3); mPullToRefreshListView.setOnPullEventListener(soundListener); mPullToRefreshListView.setCloseInterpolator(new BounceInterpolator()); // If there's instance state, mine it for useful information. The end-goal here is that // the user never knows that turning their device sideways does crazy lifecycle related things. if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) { // The listview probably hasn't even been populated yet. Actually // perform the swapout in onLoadFinished. mPosition = savedInstanceState.getInt(SELECTED_KEY); } return rootView; }
From source file:org.digitalcampus.oppia.widgets.QuizWidget.java
private void restart() { this.setStartTime(System.currentTimeMillis() / 1000); this.quiz = new Quiz(); this.quiz.load(quizContent, prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage())); this.isOnResultsPage = false; // reload quiz layout View C = getView().findViewById(R.id.widget_quiz_results); ViewGroup parent = (ViewGroup) C.getParent(); int index = parent.indexOfChild(C); parent.removeView(C);// www . jav a 2 s. co m C = super.getActivity().getLayoutInflater().inflate(R.layout.widget_quiz, parent, false); parent.addView(C, index); this.prevBtn = (Button) getView().findViewById(R.id.mquiz_prev_btn); this.nextBtn = (Button) getView().findViewById(R.id.mquiz_next_btn); this.qText = (TextView) getView().findViewById(R.id.question_text); this.questionImage = (LinearLayout) getView().findViewById(R.id.question_image); this.questionImage.setVisibility(View.GONE); this.showQuestion(); }
From source file:com.l4digital.fastscroll.FastScrollRecyclerView.java
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); mFastScroller.attachRecyclerView(this); final ViewParent parent = getParent(); if (parent instanceof ViewGroup) { final ViewGroup viewGroup = (ViewGroup) parent; if ((viewGroup instanceof CoordinatorLayout) || (viewGroup instanceof FrameLayout) || (viewGroup instanceof RelativeLayout)) { if (mFastScroller.getParent() == null) { viewGroup.addView(mFastScroller); mFastScroller.setLayoutParams(viewGroup); }// w w w . j av a2 s. c o m } else { if (viewGroup instanceof SwipeRefreshLayout) { mFastScroller.swipeRefreshLayout = (SwipeRefreshLayout) viewGroup; } final int index = viewGroup.indexOfChild(this); viewGroup.removeView(this); final FrameLayout fr = new FrameLayout(getContext()); fr.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); fr.addView(this); fr.addView(mFastScroller); mFastScroller.setLayoutParams(fr); viewGroup.addView(fr, index); } } }
From source file:org.digitalcampus.oppia.widgets.QuizWidget.java
public void showResults() { // log the activity as complete isOnResultsPage = true;//w ww. ja va 2 s . c o m quiz.mark(prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage())); // save results ready to send back to the quiz server String data = quiz.getResultObject().toString(); Log.d(TAG, data); 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(quiz.getUserscore()); qa.setMaxscore(quiz.getMaxscore()); qa.setPassed(this.getActivityCompleted()); qa.setSent(false); db.insertQuizAttempt(qa); DatabaseManager.getInstance().closeDatabase(); //Check if quiz results layout is already loaded View quizResultsLayout = getView().findViewById(R.id.widget_quiz_results); if (quizResultsLayout == null) { // load new layout View C = getView().findViewById(R.id.quiz_progress); ViewGroup parent = (ViewGroup) C.getParent(); int index = parent.indexOfChild(C); parent.removeView(C); C = super.getActivity().getLayoutInflater().inflate(R.layout.widget_quiz_results, parent, false); parent.addView(C, index); } TextView title = (TextView) getView().findViewById(R.id.quiz_results_score); title.setText(super.getActivity().getString(R.string.widget_quiz_results_score, this.getPercent())); if (this.isBaseline) { TextView baselineExtro = (TextView) getView().findViewById(R.id.quiz_results_baseline); baselineExtro.setVisibility(View.VISIBLE); baselineExtro.setText(super.getActivity().getString(R.string.widget_quiz_baseline_completed)); } // TODO add TextView here to give overall feedback if it's in the quiz // Show the detail of which questions were right/wrong if (quiz.getShowFeedback() == Quiz.SHOW_FEEDBACK_ALWAYS || quiz.getShowFeedback() == Quiz.SHOW_FEEDBACK_ATEND) { ListView questionFeedbackLV = (ListView) getView().findViewById(R.id.quiz_results_feedback); ArrayList<QuizFeedback> quizFeedback = new ArrayList<QuizFeedback>(); List<QuizQuestion> questions = this.quiz.getQuestions(); for (QuizQuestion q : questions) { if (!(q instanceof Description)) { QuizFeedback qf = new QuizFeedback(); qf.setScore(q.getScoreAsPercent()); qf.setQuestionText(q.getTitle( prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage()))); qf.setUserResponse(q.getUserResponses()); qf.setFeedbackText(q.getFeedback( prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage()))); quizFeedback.add(qf); } } QuizFeedbackAdapter qfa = new QuizFeedbackAdapter(super.getActivity(), quizFeedback); questionFeedbackLV.setAdapter(qfa); } // Show restart or continue button Button restartBtn = (Button) getView().findViewById(R.id.quiz_results_button); if (this.isBaseline) { restartBtn.setText(super.getActivity().getString(R.string.widget_quiz_baseline_goto_course)); restartBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { QuizWidget.this.getActivity().finish(); } }); } else { restartBtn.setText(super.getActivity().getString(R.string.widget_quiz_results_restart)); restartBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { QuizWidget.this.restart(); } }); } }
From source file:android.support.v7.app.AlertController.java
private void setupContent(ViewGroup contentPanel) { mScrollView = (NestedScrollView) mWindow.findViewById(R.id.scrollView); mScrollView.setFocusable(false);//w w w . j a v a 2 s . co m mScrollView.setNestedScrollingEnabled(false); // Special case for users that only want to display a String mMessageView = (TextView) contentPanel.findViewById(android.R.id.message); if (mMessageView == null) { return; } if (mMessage != null) { mMessageView.setText(mMessage); } else { mMessageView.setVisibility(View.GONE); mScrollView.removeView(mMessageView); if (mListView != null) { final ViewGroup scrollParent = (ViewGroup) mScrollView.getParent(); final int childIndex = scrollParent.indexOfChild(mScrollView); scrollParent.removeViewAt(childIndex); scrollParent.addView(mListView, childIndex, new LayoutParams(MATCH_PARENT, MATCH_PARENT)); } else { contentPanel.setVisibility(View.GONE); } } }
From source file:Main.java
private static void expandInner(final View view, final View parentView, final ViewGroup rootContainer, final int targtetHeight) { setHeight(view, 0);/*from w w w . j a v a 2 s. co m*/ view.setVisibility(View.VISIBLE); final Animation animation = new Animation() { private final Rect rect = new Rect(); private final Rect parentVisibleRect = new Rect(); ViewTreeObserver.OnGlobalLayoutListener globalLayoutListener; private final Runnable checkViewRunnable = new Runnable() { @Override public void run() { checkForViewInsideVisibleArea(); } }; @Override protected void applyTransformation(float interpolatedTime, Transformation t) { int neededHeight = interpolatedTime == 1 ? LayoutParams.WRAP_CONTENT : (int) (targtetHeight * interpolatedTime); setHeight(view, neededHeight); final ViewTreeObserver viewTreeObserver = view.getViewTreeObserver(); if (globalLayoutListener == null) { globalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (globalLayoutListener == null) { removeGlobalLayoutListener(viewTreeObserver, this); } checkForViewInsideVisibleArea(); } }; viewTreeObserver.addOnGlobalLayoutListener(globalLayoutListener); } if (globalLayoutListener != null && interpolatedTime == 1) { runInUIThread(checkViewRunnable); globalLayoutListener = null; } view.requestLayout(); } @Override public boolean willChangeBounds() { return true; } private void checkForViewInsideVisibleArea() { if (rootContainer.indexOfChild(parentView) == -1) { return; } parentVisibleRect.left = 0; parentVisibleRect.top = 0; parentVisibleRect.right = parentView.getWidth(); parentVisibleRect.bottom = parentView.getHeight(); rootContainer.offsetDescendantRectToMyCoords(parentView, parentVisibleRect); if (parentVisibleRect.top < 0 || parentVisibleRect.bottom > rootContainer.getHeight()) { rect.left = parentView.getLeft(); rect.top = parentView.getTop(); rect.right = parentView.getRight(); rect.bottom = parentView.getBottom(); parentView.requestRectangleOnScreen(rect, true); } } }; animation.setDuration(ANIMATION_DURATION); view.startAnimation(animation); }