Java Code Examples for android.view.View.addOnAttachStateChangeListener()

The following are Jave code examples for showing how to use addOnAttachStateChangeListener() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: windowmanager   File: SDWindowManager.java   Source Code and License Vote up 7 votes
/**
 * 添加view到Window
 *
 * @param view
 * @param params
 */
public void addView(View view, ViewGroup.LayoutParams params)
{
    if (view == null)
    {
        return;
    }
    init(view);
    if (containsView(view))
    {
        return;
    }
    if (params == null)
    {
        params = newLayoutParams();
    }

    getWindowManager().addView(view, params);

    view.removeOnAttachStateChangeListener(mInternalOnAttachStateChangeListener);
    view.addOnAttachStateChangeListener(mInternalOnAttachStateChangeListener);
    mMapView.put(view, 0);
}
 
Example 2
Project: aos-Video   File: NewVideosActionProvider.java   Source Code and License Vote up 7 votes
public DropDownWindow(View anchor, View contentView) {
    super(anchor.getContext());
    mAnchor = anchor;
    final Resources r = anchor.getResources();
    setBackgroundDrawable(r.getDrawable(R.drawable.dialog_full_holo_dark));
    setWidth(r.getDimensionPixelSize(R.dimen.new_videos_action_dropdown_width)); // Takes too much space on tablets when using LayoutParams.WRAP_CONTENT
    setHeight(LayoutParams.WRAP_CONTENT);

    setContentView(contentView);

    setTouchable(true);
    setFocusable(true);

    // listen to anchor getting removed (e.g. activity destroyed)
    // -> dismiss() self so we don't keep this window open
    anchor.addOnAttachStateChangeListener(this);
}
 
Example 3
Project: poper   File: FPoper.java   Source Code and License Vote up 7 votes
/**
 * 设置目标view
 *
 * @param target
 */
public FPoper setTarget(View target)
{
    final View old = getTarget();
    if (old != target)
    {
        if (old != null)
        {
            old.removeOnAttachStateChangeListener(mOnAttachStateChangeListenerTarget);
        }

        if (target != null)
        {
            mTarget = new WeakReference<>(target);
            target.removeOnAttachStateChangeListener(mOnAttachStateChangeListenerTarget);
            target.addOnAttachStateChangeListener(mOnAttachStateChangeListenerTarget);
        } else
        {
            mTarget = null;
            removeUpdateListener();
        }
    }
    return this;
}
 
Example 4
Project: kolibri-android   File: Kolibri.java   Source Code and License Vote up 6 votes
@UiThread
public static void bind(View view, KolibriProvider provider) {
  final KolibriCoordinator coordinator = provider.provideCoordinator(view);
  if (coordinator == null) {
    return;
  }

  View.OnAttachStateChangeListener binding = new Binding(view, coordinator);
  view.addOnAttachStateChangeListener(binding);
  // Sometimes we missed the first attach because the child's already been added.
  // Sometimes we didn't. The binding keeps track to avoid double attachment of the Coordinator,
  // and to guard against attachment to two different views simultaneously.
  binding.onViewAttachedToWindow(view);
}
 
Example 5
Project: Bigbang   File: IMMLeaks.java   Source Code and License Vote up 6 votes
@Override
public void onGlobalFocusChanged(View oldFocus, View newFocus) {
    if (newFocus == null) {
        return;
    }
    if (oldFocus != null) {
        oldFocus.removeOnAttachStateChangeListener(this);
    }
    Looper.myQueue().removeIdleHandler(this);
    newFocus.addOnAttachStateChangeListener(this);
}
 
Example 6
Project: Bigbang   File: IMMLeaks.java   Source Code and License Vote up 6 votes
@TargetApi(Build.VERSION_CODES.KITKAT)
private void clearInputMethodManagerLeak() {
    try {
        Object lock = mHField.get(inputMethodManager);
        // This is highly dependent on the InputMethodManager implementation.
        synchronized (lock) {
            View servedView = (View) mServedViewField.get(inputMethodManager);
            if (servedView != null) {

                boolean servedViewAttached = servedView.getWindowVisibility() != View.GONE;

                if (servedViewAttached) {
                    // The view held by the IMM was replaced without a global focus change. Let's make
                    // sure we get notified when that view detaches.

                    // Avoid double registration.
                    servedView.removeOnAttachStateChangeListener(this);
                    servedView.addOnAttachStateChangeListener(this);
                } else {
                    // servedView is not attached. InputMethodManager is being stupid!
                    Activity activity = extractActivity(servedView.getContext());
                    if (activity == null || activity.getWindow() == null) {
                        // Unlikely case. Let's finish the input anyways.
                        finishInputLockedMethod.invoke(inputMethodManager);
                    } else {
                        View decorView = activity.getWindow().peekDecorView();
                        boolean windowAttached = decorView.getWindowVisibility() != View.GONE;
                        if (!windowAttached) {
                            finishInputLockedMethod.invoke(inputMethodManager);
                        } else {
                            decorView.requestFocusFromTouch();
                        }
                    }
                }
            }
        }
    } catch (IllegalAccessException | InvocationTargetException unexpected) {
        Log.e("IMMLeaks", "Unexpected reflection exception", unexpected);
    }
}
 
Example 7
Project: chromium-for-android-56-debug-video   File: DisplayStyleObserverAdapter.java   Source Code and License Vote up 6 votes
/**
 * @param view the view whose lifecycle is tracked to determine when to not fire the
 *             observer.
 * @param config the {@link UiConfig} object to subscribe to.
 * @param observer the observer to adapt. It's {#onDisplayStyleChanged} will be called when
 *                 the configuration changes, provided that {@code view} is attached to the
 *                 window.
 */
public DisplayStyleObserverAdapter(View view, UiConfig config, DisplayStyleObserver observer) {
    mObserver = observer;

    // TODO(dgn): getParent() is not a good way to test that, but isAttachedToWindow()
    // requires API 19.
    mIsViewAttached = view.getParent() != null;

    view.addOnAttachStateChangeListener(this);

    // This call will also assign the initial value to |mCurrentDisplayStyle|
    config.addObserver(this);
}
 
Example 8
Project: OSchina_resources_android   File: BranchPopupWindow.java   Source Code and License Vote up 6 votes
@SuppressLint("InflateParams")
public BranchPopupWindow(Context context, long mProjectId, Callback callback) {
    super(LayoutInflater.from(context).inflate(R.layout.popup_window_branch, null),
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    mCallback = callback;
    this.mProjectId = mProjectId;

    setAnimationStyle(R.style.popup_anim_style_alpha);
    setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    setOutsideTouchable(true);
    setFocusable(true);

    View content = getContentView();
    content.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    content.addOnAttachStateChangeListener(this);
    RecyclerView mRecyclerView = (RecyclerView) content.findViewById(R.id.rv_branch);
    mAdapter = new BranchAdapter(context);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
    mRecyclerView.setAdapter(mAdapter);
    mAdapter.setOnItemClickListener(this);
    mPresenter = new BranchPresenter(this);
    mPresenter.getBranches(mProjectId);
}
 
Example 9
Project: OSchina_resources_android   File: ImageFolderPopupWindow.java   Source Code and License Vote up 6 votes
@SuppressLint("InflateParams")
 ImageFolderPopupWindow(Context context, Callback callback) {
    super(LayoutInflater.from(context).inflate(R.layout.popup_window_folder, null),
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

    mCallback = callback;

    // init
    setAnimationStyle(R.style.popup_anim_style_alpha);
    setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    setOutsideTouchable(true);
    setFocusable(true);

    // content
    View content = getContentView();
    content.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    content.addOnAttachStateChangeListener(this);

    mFolderView = (RecyclerView) content.findViewById(R.id.rv_popup_folder);
    mFolderView.setLayoutManager(new LinearLayoutManager(context));

}
 
Example 10
Project: diycode   File: IMMLeaks.java   Source Code and License Vote up 6 votes
@Override public void onGlobalFocusChanged(View oldFocus, View newFocus) {
  if (newFocus == null) {
    return;
  }
  if (oldFocus != null) {
    oldFocus.removeOnAttachStateChangeListener(this);
  }
  Looper.myQueue().removeIdleHandler(this);
  newFocus.addOnAttachStateChangeListener(this);
}
 
Example 11
Project: diycode   File: IMMLeaks.java   Source Code and License Vote up 6 votes
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void clearInputMethodManagerLeak() {
  try {
    Object lock = mHField.get(inputMethodManager);
    // This is highly dependent on the InputMethodManager implementation.
    synchronized (lock) {
      View servedView = (View) mServedViewField.get(inputMethodManager);
      if (servedView != null) {

        boolean servedViewAttached = servedView.getWindowVisibility() != View.GONE;

        if (servedViewAttached) {
          // The view held by the IMM was replaced without a global focus change. Let's make
          // sure we get notified when that view detaches.

          // Avoid double registration.
          servedView.removeOnAttachStateChangeListener(this);
          servedView.addOnAttachStateChangeListener(this);
        } else {
          // servedView is not attached. InputMethodManager is being stupid!
          Activity activity = extractActivity(servedView.getContext());
          if (activity == null || activity.getWindow() == null) {
            // Unlikely case. Let's finish the input anyways.
            finishInputLockedMethod.invoke(inputMethodManager);
          } else {
            View decorView = activity.getWindow().peekDecorView();
            boolean windowAttached = decorView.getWindowVisibility() != View.GONE;
            if (!windowAttached) {
              finishInputLockedMethod.invoke(inputMethodManager);
            } else {
              decorView.requestFocusFromTouch();
            }
          }
        }
      }
    }
  } catch (IllegalAccessException | InvocationTargetException unexpected) {
    Log.e("IMMLeaks", "Unexpected reflection exception", unexpected);
  }
}
 
Example 12
Project: GitHub   File: FragmentStatePagerAdapter.java   Source Code and License Vote up 5 votes
public FragmentViewHolder(View itemView) {
    super(itemView);
    itemView.addOnAttachStateChangeListener(this);
}
 
Example 13
Project: EvolvingNetLib   File: CCBaseLazyRxFragment.java   Source Code and License Vote up 5 votes
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    view.addOnAttachStateChangeListener(this);
}
 
Example 14
Project: kolibri-android   File: Kolibri.java   Source Code and License Vote up 5 votes
@UiThread
public static void bind(View view, KolibriCoordinator coordinator) {
  view.addOnAttachStateChangeListener(new Binding(view, coordinator));
}
 
Example 15
Project: ScaleViewPager   File: FragmentStatePagerAdapter.java   Source Code and License Vote up 5 votes
public FragmentViewHolder(View itemView) {
    super(itemView);
    itemView.addOnAttachStateChangeListener(this);
}
 
Example 16
Project: GCSApp   File: FragmentStatePagerAdapter.java   Source Code and License Vote up 5 votes
public FragmentViewHolder(View itemView) {
    super(itemView);
    itemView.addOnAttachStateChangeListener(this);
}