List of usage examples for android.view ViewTreeObserver removeGlobalOnLayoutListener
@Deprecated public void removeGlobalOnLayoutListener(OnGlobalLayoutListener victim)
From source file:com.actionbarsherlock.widget.ActivityChooserView.java
/** * Dismisses the popup window with activities. * * @return True if dismissed, false if already dismissed. *///from w w w. ja v a 2 s. c o m public boolean dismissPopup() { if (isShowingPopup()) { getListPopupWindow().dismiss(); ViewTreeObserver viewTreeObserver = getViewTreeObserver(); if (viewTreeObserver.isAlive()) { viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener); } } return true; }
From source file:com.nearnotes.NoteEdit.java
@Override public void onStart() { super.onStart(); mTitleText = (EditText) getActivity().findViewById(R.id.title_edit); mCallback.setActionItems(NOTE_EDIT); if (mRowId == null) { Bundle extras = getArguments();/*from w ww . j a v a 2 s . co m*/ mRowId = extras.containsKey(NotesDbAdapter.KEY_ROWID) ? extras.getLong(NotesDbAdapter.KEY_ROWID) : null; } getActivity().setTitle(R.string.edit_note); Bundle bundle = getArguments(); mLongitude = bundle.getDouble("longitude"); mLatitude = bundle.getDouble("latitude"); mTitleText = (EditText) getActivity().findViewById(R.id.title_edit); mBodyText = (EditText) getView().findViewById(R.id.body); mTblAddLayout = (TableLayout) getActivity().findViewById(R.id.checkbody); mTblAddLayout.setPadding(0, 0, 0, 0); acAdapter = new PlacesAutoCompleteAdapter(getActivity(), R.layout.list_item); mCheckBox = (CheckBox) getActivity().findViewById(R.id.checkbox_on_top); mCheckBox.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (((CheckBox) v).isChecked() && mRowId != null) { mDbHelper.updateSetting(mRowId); } else if (mRowId != null) { mDbHelper.removeSetting(); } } }); autoCompView = (DelayAutoCompleteTextView) getView().findViewById(R.id.autoCompleteTextView1); autoCompView.setAdapter(acAdapter); //int height = autoCompView.getDropDownHeight(); //autoCompView.setDropDownHeight(height + 20); autoCompView.setOnItemClickListener(this); autoCompView.setLoadingIndicator((ProgressBar) getView().findViewById(R.id.progressAPI), (ImageView) getView().findViewById(R.id.location_icon)); autoCompView.setCompletionHint(""); if (mRowId != null) { autoCompView.setTextColor(getResources().getColor(R.color.deepgreen)); } else { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); boolean checklistPref = sharedPref.getBoolean("pref_key_note_checklist", false); if (checklistPref) { mChecklist = true; } } mBodyText.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { //This listener is added to make sure the globalLayout has been displayed // before accessing getLayout().getLineEnd() ViewTreeObserver obs = mBodyText.getViewTreeObserver(); obs.removeGlobalOnLayoutListener(this); if (!mChecklist) { return; } mBodyText.addTextChangedListener(bodyTextWatcher); // Run the code below just once on startup to populate the global listArray mRealRow String tempBoxes = mBodyText.getText().toString(); if (mBodyText.getLayout() != null) { mRealRow = populateBoxes(tempBoxes); int row = 0; for (NoteRow line : mRealRow) { switch (line.getType()) { case 0: TableRow inflate = (TableRow) View.inflate(getActivity(), R.layout.table_row_invisible, null); mTblAddLayout.addView(inflate); break; case 1: TableRow checkRow = (TableRow) View.inflate(getActivity(), R.layout.table_row, null); CheckBox temp = (CheckBox) checkRow.getChildAt(0); temp.setTag(Integer.valueOf(row)); mTblAddLayout.addView(checkRow); temp.setOnClickListener(checkBoxListener); break; case 2: TableRow checkRow1 = (TableRow) View.inflate(getActivity(), R.layout.table_row, null); CheckBox temp1 = (CheckBox) checkRow1.getChildAt(0); temp1.setTag(Integer.valueOf(row)); temp1.setChecked(true); mTblAddLayout.addView(checkRow1); temp1.setOnClickListener(checkBoxListener); break; } for (int k = 1; line.getSize() > k; k++) { TableRow inflate = (TableRow) View.inflate(getActivity(), R.layout.table_row_invisible, null); mTblAddLayout.addView(inflate); } row++; } } } }); }
From source file:org.puder.trs80.EmulatorActivity.java
private void initKeyboardView() { stopAccelerometer();/* ww w. ja v a 2 s. c om*/ keyboardContainer = (ViewGroup) findViewById(R.id.keyboard_container); keyboardContainer.removeAllViews(); final KeyboardLayout keyboardType = getKeyboardType(); showKeyboardHint(keyboardType); if (keyboardType == KEYBOARD_GAME_CONTROLLER || keyboardType == KEYBOARD_EXTERNAL) { keyboardContainer.getRootView().findViewById(R.id.switch_keyboard).setVisibility(View.GONE); return; } keyboardContainer.getRootView().findViewById(R.id.switch_keyboard).setVisibility(View.VISIBLE); // if (android.os.Build.VERSION.SDK_INT >= // Build.VERSION_CODES.HONEYCOMB) { // root.setMotionEventSplittingEnabled(true); // } currentHardware.computeKeyDimensions(windowRect, getKeyboardType()); int layoutId = 0; switch (keyboardType) { case KEYBOARD_LAYOUT_COMPACT: layoutId = R.layout.keyboard_compact; break; case KEYBOARD_LAYOUT_ORIGINAL: layoutId = R.layout.keyboard_original; break; case KEYBOARD_LAYOUT_JOYSTICK: layoutId = R.layout.keyboard_joystick; break; case KEYBOARD_TILT: layoutId = R.layout.keyboard_tilt; break; } getLayoutInflater().inflate(layoutId, keyboardContainer, true); /* * The following code is a hack to work around a problem with the * keyboard layout in Android. The second keyboard should have * visibility GONE initially when the keyboard layout is inflated. * However, doing so messes up the layout of the second keyboard * (R.id.keyboard_view_2). This does not happen when visibility is * VISIBLE. So, to work around this issue, the initial visibility in the * keyboard layout is VISIBLE and we use a layout listener to make it * GONE after the layout has been computed and just before it will be * rendered. */ ViewTreeObserver vto = keyboardContainer.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { View kb2 = keyboardContainer.findViewById(R.id.keyboard_view_2); if (kb2 != null) { kb2.setVisibility(View.GONE); } ViewTreeObserver obs = keyboardContainer.getViewTreeObserver(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obs.removeOnGlobalLayoutListener(this); } else { //noinspection deprecation obs.removeGlobalOnLayoutListener(this); } } }); keyboardContainer.requestLayout(); if (keyboardType == KEYBOARD_TILT) { startAccelerometer(); } }
From source file:suntai.ditudome.utils.photoview.PhotoViewAttacher.java
public void cleanup() { if (null == mImageView) { return; // cleanup already done }/*from ww w. j a v a 2s . c om*/ final ImageView imageView = mImageView.get(); if (null != imageView) { // Remove this as a global layout listener ViewTreeObserver observer = imageView.getViewTreeObserver(); if (null != observer && observer.isAlive()) { observer.removeGlobalOnLayoutListener(this); } // Remove the ImageView's reference to this imageView.setOnTouchListener(null); // make sure a pending fling runnable won't be run cancelFling(); } if (null != mGestureDetector) { mGestureDetector.setOnDoubleTapListener(null); } // Clear listeners too mMatrixChangeListener = null; mPhotoTapListener = null; mViewTapListener = null; // Finally, clear ImageView mImageView = null; }
From source file:com.andrada.sitracker.ui.fragment.PublicationInfoFragment.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override/* ww w . j a v a 2s . c o m*/ public void onDestroyView() { super.onDestroyView(); if (mScrollView == null) { return; } ViewTreeObserver vto = mScrollView.getViewTreeObserver(); if (vto.isAlive()) { //noinspection deprecation if (UIUtils.hasJellyBean()) { vto.removeOnGlobalLayoutListener(mGlobalLayoutListener); } else { vto.removeGlobalOnLayoutListener(mGlobalLayoutListener); } } }
From source file:org.ciasaboark.tacere.activity.fragment.EventsFragment.java
private void showFirstRunWizardIfNeeded() { if (prefs.isFirstRun()) { prefs.disableFirstRun();//from w w w .j a v a 2s . c o m final ViewTreeObserver viewTreeObserver = ((Activity) context).getWindow().getDecorView() .getViewTreeObserver(); viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (!showingTutorial) { showingTutorial = true; startActivity(new Intent(context.getApplicationContext(), TutorialActivity.class)); } if (viewTreeObserver.isAlive()) { if (Build.VERSION.SDK_INT >= 16) { viewTreeObserver.removeOnGlobalLayoutListener(this); } else { viewTreeObserver.removeGlobalOnLayoutListener(this); } } } }); } }
From source file:com.cylan.jiafeigou.support.photoview.PhotoViewAttacher.java
/** * Clean-up the resources attached to this object. This needs to be called when the ImageView is * no longer used. A good example is from {@link View#onDetachedFromWindow()} or * from {@link android.app.Activity#onDestroy()}. This is automatically called if you are using * {@link PhotoView}./*from w w w .j av a 2s . c om*/ */ @SuppressWarnings("deprecation") public void cleanup() { if (null == mImageView) { return; // cleanup already done } final ImageView imageView = mImageView.get(); if (null != imageView) { // Remove this as a global layout listener ViewTreeObserver observer = imageView.getViewTreeObserver(); if (null != observer && observer.isAlive()) { observer.removeGlobalOnLayoutListener(this); } // Remove the ImageView'account reference to this imageView.setOnTouchListener(null); // make sure a pending fling runnable won't be run cancelFling(); } if (null != mGestureDetector) { mGestureDetector.setOnDoubleTapListener(null); } // Clear listeners too mMatrixChangeListener = null; mPhotoTapListener = null; mViewTapListener = null; // Finally, clearLocal ImageView mImageView = null; }
From source file:com.github.lakeshire.photoview.PhotoViewAttacher.java
@SuppressWarnings("deprecation") public void cleanup() { if (null == mImageView) { return; // cleanup already done }//from www . j a v a 2s.c o m final ImageView imageView = mImageView.get(); if (null != imageView) { // Remove this as a global layout listener ViewTreeObserver observer = imageView.getViewTreeObserver(); if (null != observer && observer.isAlive()) { observer.removeGlobalOnLayoutListener(this); } // Remove the ImageView's reference to this imageView.setOnTouchListener(null); // make sure a pending fling runnable won't be run cancelFling(); } if (null != mGestureDetector) { mGestureDetector.setOnDoubleTapListener(null); } // Clear listeners too mMatrixChangeListener = null; mPhotoTapListener = null; mViewTapListener = null; // Finally, clear ImageView mImageView = null; }
From source file:com.google.samples.apps.iosched.ui.CurrentSessionActivity.java
@Override protected void onDestroy() { super.onDestroy(); if (mScrollView == null) { return;/*from www.java 2 s . c om*/ } ViewTreeObserver vto = mScrollView.getViewTreeObserver(); if (vto.isAlive()) { vto.removeGlobalOnLayoutListener(mGlobalLayoutListener); } }
From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java
/** * Clean-up the resources attached to this object. This needs to be called when the ImageView is * no longer used. A good example is from {@link View#onDetachedFromWindow()} or * from {@link android.app.Activity#onDestroy()}. This is automatically called if you are using *///w ww. j av a 2 s .c om @SuppressWarnings("deprecation") public void cleanup() { if (null == mImageView) { return; // cleanup already done } final ImageView imageView = mImageView.get(); if (null != imageView) { // Remove this as a global layout listener ViewTreeObserver observer = imageView.getViewTreeObserver(); if (null != observer && observer.isAlive()) { observer.removeGlobalOnLayoutListener(this); } // Remove the ImageView's reference to this imageView.setOnTouchListener(null); // make sure a pending fling runnable won't be run cancelFling(); } if (null != mGestureDetector) { mGestureDetector.setOnDoubleTapListener(null); } // Clear listeners too mMatrixChangeListener = null; mPhotoTapListener = null; mViewTapListener = null; // Finally, clear ImageView mImageView = null; }