Java Code Examples for android.view.ViewGroup#post()

The following examples show how to use android.view.ViewGroup#post() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseActivity.java    From Bailan with Apache License 2.0 6 votes vote down vote up
/**
 * 系统版本4.4或以上才可以设置沉浸式状态栏
 *
 * 设置状态栏的高度
 */
protected void setStatus(){
    bar_layout= (ViewGroup) findViewById(R.id.bar_layout);
    if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.KITKAT){
        //设置状态栏透明
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //设置导航栏透明
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        final int statusBarHeight = getStatusBarHeight();
        bar_layout.post(new Runnable() {
            @Override
            public void run() {
                //标题栏高度
                int height=bar_layout.getHeight();
                android.widget.RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) bar_layout.getLayoutParams();
                //导航栏高度+通知栏高度
                params.height=height+statusBarHeight;
                bar_layout.setLayoutParams(params);
            }
        });
    }
}
 
Example 2
Source File: BaseActivity.java    From Bailan with Apache License 2.0 6 votes vote down vote up
/**
 * 系统版本4.4或以上才可以设置沉浸式状态栏
 *
 * 设置状态栏的高度
 */
protected void setStatus(){
    bar_layout= (ViewGroup) findViewById(R.id.bar_layout);
    if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.KITKAT){
        //设置状态栏透明
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //设置导航栏透明
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        final int statusBarHeight = getStatusBarHeight();
        bar_layout.post(new Runnable() {
            @Override
            public void run() {
                //标题栏高度
                int height=bar_layout.getHeight();
                android.widget.RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) bar_layout.getLayoutParams();
                //导航栏高度+通知栏高度
                params.height=height+statusBarHeight;
                bar_layout.setLayoutParams(params);
            }
        });
    }
}
 
Example 3
Source File: RibbonFickleCoverLayout.java    From android-RibbonViews with MIT License 6 votes vote down vote up
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    if(getChildCount() > 0) {
        if(getChildAt(0) instanceof ViewGroup) {
            ViewGroup childLayout = (ViewGroup) getChildAt(0);
            childLayout.post(new Runnable() {
                @Override
                public void run() {
                    updateCover();
                }
            });

            if(childLayout.getChildCount() > 0) {
                childLayout.getChildAt(0).post(new Runnable() {
                    @Override
                    public void run() {
                        updateCover();
                    }
                });
            }
        }
    }
    updateCover();
}
 
Example 4
Source File: BounceRecyclerView.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Pop stickyView to stack
 */
private void showSticky() {
  WXCell headComponent = headComponentStack.pop();
  headComponentStack.push(headComponent);
  final View headerView = headComponent.getRealView();
  if (headerView == null)
    return;
  headerViewStack.push(headerView);
  headComponent.removeSticky();
  final ViewGroup parent = (ViewGroup) getParent();
  if(parent != null){
    parent.post(WXThread.secure(new Runnable() {
      @Override
      public void run() {
        ViewGroup existedParent;
        if((existedParent = (ViewGroup)headerView.getParent())!= null){
          existedParent.removeView(headerView);
        }
        parent.addView(headerView);
      }
    }));
  }
}
 
Example 5
Source File: BounceRecyclerView.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * remove top stickyView
 * @param component
 */
private void removeSticky(WXComponent component) {
  final WXCell headComponent = headComponentStack.pop();
  if (!component.getRef().equals(headComponent.getRef())) {
    headComponentStack.push(headComponent);
    return;
  }
  final View headerView = headerViewStack.pop();
  final ViewGroup parent = (ViewGroup) getParent();
  if(parent != null){
    parent.post(WXThread.secure(new Runnable() {
      @Override
      public void run() {
        parent.removeView(headerView);
        headComponent.recoverySticky();
      }
    }));
  }

}
 
Example 6
Source File: SimpleRecyclerView.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Pop stickyView to stack
 */
private void showSticky() {
  WXCell headComponent = headComponentStack.pop();
  headComponentStack.push(headComponent);
  final View headerView = headComponent.getRealView();
  if (headerView == null)
    return;
  headerViewStack.push(headerView);
  headComponent.removeSticky();
  final ViewGroup parent = (ViewGroup) getParent();
  if(parent != null){
    parent.post(WXThread.secure(new Runnable() {
      @Override
      public void run() {
        ViewGroup existedParent;
        if((existedParent = (ViewGroup)headerView.getParent())!= null){
          existedParent.removeView(headerView);
        }
        parent.addView(headerView);
      }
    }));
  }
}
 
Example 7
Source File: SimpleRecyclerView.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * remove top stickyView
 * @param component
 */
private void removeSticky(WXComponent component) {
  final WXCell headComponent = headComponentStack.pop();
  if (!component.getRef().equals(headComponent.getRef())) {
    headComponentStack.push(headComponent);
    return;
  }
  final View headerView = headerViewStack.pop();
  final ViewGroup parent = (ViewGroup) getParent();
  if(parent != null){
    parent.post(WXThread.secure(new Runnable() {
      @Override
      public void run() {
        parent.removeView(headerView);
        headComponent.recoverySticky();
      }
    }));
  }

}
 
Example 8
Source File: MainActivity.java    From ViewToImage with Apache License 2.0 6 votes vote down vote up
private void initViews() {
    mCaptureView = (ViewGroup) findViewById(R.id.capture_layout);
    mListView = (ListView) findViewById(R.id.listView);
    mImageView = (ImageView) findViewById(R.id.imageView);
    final List<String> list = new ArrayList<>();
    for (int i = 0; i < 35; i++) {
        list.add("item " + i);
    }
    MainAdapter adapter = new MainAdapter(this, list);
    mListView.setAdapter(adapter);
    mCaptureView.post(new Runnable() {
        @Override
        public void run() {
            LogUtils.i(String.format("width=%s, height=%s, measureWidth=%s, measureHeight=%s", mCaptureView.getWidth(), mCaptureView.getHeight(), mCaptureView.getMeasuredWidth(), mCaptureView.getMeasuredHeight()));
        }
    });
}
 
Example 9
Source File: AmenityInformation.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mViews = FragmentAmenityInformationBinding.inflate(inflater, container, false);
    final ViewGroup rootView = (ViewGroup) mViews.getRoot();
    rootView.post(() -> {
        updatePeekHeight(rootView, false);
        int panelState = BottomSheetBehavior.STATE_COLLAPSED;
        if (savedInstanceState != null) {
            panelState = savedInstanceState.getInt("panelState", panelState);
            View dragHandle = rootView.findViewById(R.id.dragHandle);
            dragHandle.setAlpha(panelState == BottomSheetBehavior.STATE_EXPANDED ? 0f : 1f);
        }
        mBottomSheetBehavior.setState(panelState);
        // Workaround for panel partially drawn on first slide
        // TODO Try to put transparent view above map
        if (Configuration.getHideSystemUI())
            rootView.requestLayout();
    });
    mMapHolder.updateMapViewArea();

    return rootView;
}
 
Example 10
Source File: StickerModel.java    From imsdk-android with MIT License 5 votes vote down vote up
public void setCanvasSize(final Bitmap b, final ViewGroup imageGroup) {
    if (imageGroup.getMeasuredWidth() == 0) {
        imageGroup.post(new Runnable() {
            @Override
            public void run() {
                setSize(b, imageGroup);
            }
        });
    } else {
        setSize(b, imageGroup);
    }
}
 
Example 11
Source File: Screenplay.java    From screenplay with MIT License 5 votes vote down vote up
private void removeFromParent(final View view) {

        // If we don't include the post() call, the following error occurs:
        // Attempt to read from field 'int android.view.View.mViewFlags' on a null object reference
        // So far I haven't been able to isolate the cause of this -- I think it might be related
        // to removing the view immediately after an animation ends, but I haven't been able to
        // reproduce it under controlled conditions.
        final ViewGroup parent = (ViewGroup) view.getParent();
        parent.post(new Runnable() {
            @Override
            public void run() {
                parent.removeView(view);
            }
        });
    }
 
Example 12
Source File: AmenityInformation.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public void setAmenity(long id) {
    mAmenity = MapTrekDatabaseHelper.getAmenityData(mLang, id, MapTrek.getApplication().getDetailedMapDatabase());
    if (isVisible()) {
        mMapHolder.showMarker(mAmenity.coordinates, mAmenity.name, true);
        updateAmenityInformation(mLatitude, mLongitude);
        final ViewGroup rootView = (ViewGroup) getView();
        if (rootView != null)
            rootView.post(() -> updatePeekHeight(rootView, true));
    }
}
 
Example 13
Source File: WaypointInformation.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public void setWaypoint(Waypoint waypoint) {
    mWaypoint = waypoint;
    if (isVisible()) {
        if (mEditorMode)
            setEditorMode(false);
        mListener.onWaypointFocus(mWaypoint);
        updateWaypointInformation(mLatitude, mLongitude);
        final ViewGroup rootView = (ViewGroup) getView();
        if (rootView != null)
            rootView.post(() -> updatePeekHeight(rootView, true));
    }
}
 
Example 14
Source File: PickerUIBlurHelper.java    From PickerUI with Apache License 2.0 5 votes vote down vote up
/**
 * Create a ImageView with width and height MATCH_PARENT, which will host the blurred snapshot.
 */
private void createImageViewBlur() {

    if (mUseBlur) {
        mRootView = (ViewGroup) ((Activity) mContext).getWindow().getDecorView()
                .findViewById(android.R.id.content);

        mBlurredImageView = new ImageView(mContext);

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);

        Log.d("YYYYY width", "" + mRootView.getWidth());
        Log.d("YYYYY height", "" + mRootView.getHeight());
        mBlurredImageView.setLayoutParams(params);
        mBlurredImageView.setClickable(false);
        mBlurredImageView.setVisibility(View.GONE);
        mBlurredImageView.setScaleType(ImageView.ScaleType.FIT_XY);

        mRootView.post(new Runnable() {
            @Override
            public void run() {
                // Add the ImageView with blurred view
                ((ViewGroup) mRootView.getChildAt(0))
                        .addView(mBlurredImageView, mRootView.getChildCount());
            }
        });
    }
}
 
Example 15
Source File: MainActivity.java    From ViewToImage with Apache License 2.0 5 votes vote down vote up
/**
 * 截屏inflate视图
 */
private void captureInflateView() {
    View rootView = LayoutInflater.from(this).inflate(R.layout.layout_listview, null, false);
    rootView.setLayoutParams(new LinearLayout.LayoutParams(ScreenUtil.getScreenWidth(this), LinearLayout.LayoutParams.WRAP_CONTENT));
    // rootView.getLayoutParams().width = ScreenUtil.getScreenWidth(this);
    rootView.requestLayout();

    final ViewGroup mCaptureView = (ViewGroup) rootView.findViewById(R.id.capture_layout);
    ListView mListView = (ListView) rootView.findViewById(R.id.listView);
    final List<String> list = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        list.add("item " + i);
    }
    MainAdapter adapter = new MainAdapter(this, list);
    mListView.setAdapter(adapter);

    mCaptureView.post(new Runnable() {
        @Override
        public void run() {
            LogUtils.i(String.format("width=%s, height=%s, measureWidth=%s, measureHeight=%s", mCaptureView.getWidth(), mCaptureView.getHeight(), mCaptureView.getMeasuredWidth(), mCaptureView.getMeasuredHeight()));
        }
    });

    int width = ScreenUtil.getScreenWidth(this);
    ViewToImageUtil.generateImage(mCaptureView, width, 0xfff8f8f8, new ViewToImageUtil.OnImageSavedCallback() {
        @Override
        public void onFinishCallback(String path) {
            Toast.makeText(MainActivity.this, path, Toast.LENGTH_SHORT).show();
            LogUtils.d(path);
        }
    });
}
 
Example 16
Source File: TransitionMakeActivity.java    From PLDroidShortVideo with Apache License 2.0 5 votes vote down vote up
private void initTransitions() {
    final PLVideoEncodeSetting setting = new PLVideoEncodeSetting(TransitionMakeActivity.this);
    setting.setEncodingSizeLevel(PLVideoEncodeSetting.VIDEO_ENCODING_SIZE_LEVEL.VIDEO_ENCODING_SIZE_LEVEL_720P_3);
    for (int i = 0; i < mTransitions.length; i++) {
        final ViewGroup viewGroup = (ViewGroup) findViewById(getResources().getIdentifier("transition_container" + i, "id", getPackageName()));
        final int index = i;
        viewGroup.post(new Runnable() {
            @Override
            public void run() {
                try {
                    Constructor constructor = TRANSITION_CLASS[index].getConstructor(ViewGroup.class, PLVideoEncodeSetting.class);
                    TransitionBase transition = (TransitionBase) constructor.newInstance(viewGroup, setting);

                    mTransitions[index] = transition;

                    //default show first transition
                    if (index == 0) {
                        transition.setVisibility(View.VISIBLE);
                        mCurTransition = transition;
                        mTransEditView.setTransition(mCurTransition);
                    } else {
                        transition.setVisibility(View.INVISIBLE);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    ToastUtils.s(TransitionMakeActivity.this, "Can not init Transition : " + "Transition" + index);
                }
            }
        });
    }
}
 
Example 17
Source File: StickerModel.java    From EasyPhotos with Apache License 2.0 5 votes vote down vote up
public void setCanvasSize(final Bitmap b, final ViewGroup imageGroup) {
    if (imageGroup.getMeasuredWidth() == 0) {
        imageGroup.post(new Runnable() {
            @Override
            public void run() {
                setSize(b, imageGroup);
            }
        });
    } else {
        setSize(b, imageGroup);
    }
}
 
Example 18
Source File: WaypointInformation.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_waypoint_information, container, false);
    final ImageButton editButton = rootView.findViewById(R.id.editButton);
    final ImageButton shareButton = rootView.findViewById(R.id.shareButton);
    final ImageButton deleteButton = rootView.findViewById(R.id.deleteButton);

    editButton.setOnClickListener(v -> setEditorMode(true));
    shareButton.setOnClickListener(v -> {
        mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
        mListener.onWaypointShare(mWaypoint);
    });
    deleteButton.setOnClickListener(v -> {
        Animation shake = AnimationUtils.loadAnimation(getContext(), R.anim.shake);
        v.startAnimation(shake);
    });
    deleteButton.setOnLongClickListener(v -> {
        mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
        mListener.onWaypointDelete(mWaypoint);
        return true;
    });

    mEditorMode = false;
    mPopAll = false;

    rootView.post(() -> {
        updatePeekHeight(rootView, false);
        mBottomSheetBehavior.setSkipCollapsed(mExpanded);
        int panelState = mExpanded ? BottomSheetBehavior.STATE_EXPANDED : BottomSheetBehavior.STATE_COLLAPSED;
        if (savedInstanceState != null) {
            panelState = savedInstanceState.getInt("panelState", panelState);
            View dragHandle = rootView.findViewById(R.id.dragHandle);
            dragHandle.setAlpha(panelState == BottomSheetBehavior.STATE_EXPANDED ? 0f : 1f);
        }
        mBottomSheetBehavior.setState(panelState);
        // Workaround for panel partially drawn on first slide
        // TODO Try to put transparent view above map
        if (Configuration.getHideSystemUI())
            rootView.requestLayout();
    });

    return rootView;
}
 
Example 19
Source File: PullToRefreshAttacher.java    From Klyph with MIT License 4 votes vote down vote up
protected PullToRefreshAttacher(Activity activity, Options options) {
    if (activity == null) {
        throw new IllegalArgumentException("activity cannot be null");
    }
    if (options == null) {
        Log.i(LOG_TAG, "Given null options so using default options.");
        options = new Options();
    }

    mActivity = activity;
    mRefreshableViews = new WeakHashMap<View, ViewDelegate>();

    // Copy necessary values from options
    mRefreshScrollDistance = options.refreshScrollDistance;
    mRefreshOnUp = options.refreshOnUp;
    mRefreshMinimizeDelay = options.refreshMinimizeDelay;
    mRefreshMinimize = options.refreshMinimize;

    // EnvironmentDelegate
    mEnvironmentDelegate = options.environmentDelegate != null
            ? options.environmentDelegate
            : createDefaultEnvironmentDelegate();

    // Header Transformer
    mHeaderTransformer = options.headerTransformer != null
            ? options.headerTransformer
            : createDefaultHeaderTransformer();

    // Get touch slop for use later
    mTouchSlop = ViewConfiguration.get(activity).getScaledTouchSlop();

    // Get Window Decor View
    final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();

    // Create Header view and then add to Decor View
    mHeaderView = LayoutInflater.from(
            mEnvironmentDelegate.getContextForInflater(activity)).inflate(
            options.headerLayout, decorView, false);
    if (mHeaderView == null) {
        throw new IllegalArgumentException("Must supply valid layout id for header.");
    }
    // Make Header View invisible so it still gets a layout pass
    mHeaderView.setVisibility(View.INVISIBLE);

    // Notify transformer
    mHeaderTransformer.onViewCreated(activity, mHeaderView);

    // Now HeaderView to Activity
    decorView.post(new Runnable() {
        @Override
        public void run() {
            if (decorView.getWindowToken() != null) {
                // The Decor View has a Window Token, so we can add the HeaderView!
                addHeaderViewToActivity(mHeaderView);
            } else {
                // The Decor View doesn't have a Window Token yet, post ourselves again...
                decorView.post(this);
            }
        }
    });
}
 
Example 20
Source File: PullToRefreshAttacher.java    From KlyphMessenger with MIT License 4 votes vote down vote up
protected PullToRefreshAttacher(Activity activity, Options options) {
    if (activity == null) {
        throw new IllegalArgumentException("activity cannot be null");
    }
    if (options == null) {
        Log.i(LOG_TAG, "Given null options so using default options.");
        options = new Options();
    }

    mActivity = activity;
    mRefreshableViews = new WeakHashMap<View, ViewDelegate>();

    // Copy necessary values from options
    mRefreshScrollDistance = options.refreshScrollDistance;
    mRefreshOnUp = options.refreshOnUp;
    mRefreshMinimizeDelay = options.refreshMinimizeDelay;
    mRefreshMinimize = options.refreshMinimize;

    // EnvironmentDelegate
    mEnvironmentDelegate = options.environmentDelegate != null
            ? options.environmentDelegate
            : createDefaultEnvironmentDelegate();

    // Header Transformer
    mHeaderTransformer = options.headerTransformer != null
            ? options.headerTransformer
            : createDefaultHeaderTransformer();

    // Get touch slop for use later
    mTouchSlop = ViewConfiguration.get(activity).getScaledTouchSlop();

    // Get Window Decor View
    final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();

    // Create Header view and then add to Decor View
    mHeaderView = LayoutInflater.from(
            mEnvironmentDelegate.getContextForInflater(activity)).inflate(
            options.headerLayout, decorView, false);
    if (mHeaderView == null) {
        throw new IllegalArgumentException("Must supply valid layout id for header.");
    }
    // Make Header View invisible so it still gets a layout pass
    mHeaderView.setVisibility(View.INVISIBLE);

    // Notify transformer
    mHeaderTransformer.onViewCreated(activity, mHeaderView);

    // Now HeaderView to Activity
    decorView.post(new Runnable() {
        @Override
        public void run() {
            if (decorView.getWindowToken() != null) {
                // The Decor View has a Window Token, so we can add the HeaderView!
                addHeaderViewToActivity(mHeaderView);
            } else {
                // The Decor View doesn't have a Window Token yet, post ourselves again...
                decorView.post(this);
            }
        }
    });
}