android.support.constraint.ConstraintLayout Java Examples

The following examples show how to use android.support.constraint.ConstraintLayout. 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: ToolbarHelper.java    From WanAndroid with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 将View的top margin 向下偏移一个状态栏的高度
 */
public static void initMarginTopDiffBar(View view) {
    ViewGroup.LayoutParams params = view.getLayoutParams();
    if (params instanceof LinearLayout.LayoutParams) {
        LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) params;
        linearParams.topMargin += ScreenUtils.getStatusHeight(view.getContext());
    } else if (params instanceof FrameLayout.LayoutParams) {
        FrameLayout.LayoutParams frameParams = (FrameLayout.LayoutParams) params;
        frameParams.topMargin += ScreenUtils.getStatusHeight(view.getContext());
    } else if (params instanceof RelativeLayout.LayoutParams) {
        RelativeLayout.LayoutParams relativeParams = (RelativeLayout.LayoutParams) params;
        relativeParams.topMargin += ScreenUtils.getStatusHeight(view.getContext());
    } else if (params instanceof ConstraintLayout.LayoutParams) {
        ConstraintLayout.LayoutParams constraintParams = (ConstraintLayout.LayoutParams) params;
        constraintParams.topMargin += ScreenUtils.getStatusHeight(view.getContext());
    }
    view.setLayoutParams(params);
}
 
Example #2
Source File: MainActivity.java    From journaldev with MIT License 6 votes vote down vote up
private ValueAnimator animatePointer(long orbitDuration) {
    ValueAnimator anim = ValueAnimator.ofInt(0, 359);

    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) imgPointer.getLayoutParams();
            layoutParams.circleAngle = val;
            imgPointer.setLayoutParams(layoutParams);
        }
    });
    anim.setDuration(orbitDuration);
    anim.setInterpolator(new LinearInterpolator());
    anim.setRepeatMode(ValueAnimator.RESTART);
    anim.setRepeatCount(ValueAnimator.INFINITE);

    return anim;
}
 
Example #3
Source File: NewsView.java    From CryptoBuddy with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void inflateComponents(){
    inflate(getContext(), R.layout.row_news_item, this);
    articleTitleTextView = findViewById(R.id.articleTitle);
    ageTextView = findViewById(R.id.age);
    articleImageView = findViewById(R.id.articleImage);
    sourceNameTextView = findViewById(R.id.sourceName);
    setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent browserIntent = new Intent(getContext(), WebViewActivity.class);
            browserIntent.putExtra("url", newsItem.articleURL);
            browserIntent.putExtra("title", "News");
            getContext().startActivity(browserIntent);
        }
    });
    ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.orientation = LayoutParams.VERTICAL;
    setLayoutParams(params);
    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    setBackgroundResource(outValue.resourceId);
    setFocusable(true);
    setClickable(true);
}
 
Example #4
Source File: StaggeredAnimationGroup.java    From StaggeredAnimationGroup with Apache License 2.0 5 votes vote down vote up
public final void show(boolean inReversedOrder) {
    ConstraintLayout parent = getConstraintLayoutParent(this);
    if (notNull(parent)) {
        Transition transition = prepareStaggeredTransition(true, inReversedOrder);
        TransitionManager.beginDelayedTransition(parent, transition);
        setVisibility(View.VISIBLE);
    }
}
 
Example #5
Source File: CustomControlLayoutActivity.java    From android-map-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public void onMapReady(@NonNull NaverMap naverMap) {
    this.<CompassView>findViewById(R.id.compass).setMap(naverMap);
    this.<ZoomControlView>findViewById(R.id.zoom).setMap(naverMap);
    this.<IndoorLevelPickerView>findViewById(R.id.indoor_level_picker).setMap(naverMap);

    ScaleBarView scaleBar = findViewById(R.id.scale_bar);
    scaleBar.setMap(naverMap);

    ConstraintLayout container = findViewById(R.id.container);
    int scaleBarMargin = getResources().getDimensionPixelSize(R.dimen.fab_margin);

    findViewById(R.id.fab).setOnClickListener(v -> {
        boolean right = !scaleBar.isRightToLeftEnabled();

        UiSettings uiSettings = naverMap.getUiSettings();

        ConstraintSet constraintSet = new ConstraintSet();
        constraintSet.clone(container);

        if (right) {
            uiSettings.setLogoGravity(Gravity.START | Gravity.BOTTOM);
            constraintSet.connect(R.id.scale_bar, ConstraintSet.END, R.id.fab, ConstraintSet.START);
            constraintSet.setMargin(R.id.scale_bar, ConstraintSet.END, scaleBarMargin);
            constraintSet.clear(R.id.scale_bar, ConstraintSet.START);
        } else {
            uiSettings.setLogoGravity(Gravity.START | Gravity.TOP);
            constraintSet.connect(R.id.scale_bar, ConstraintSet.START, ConstraintSet.PARENT_ID,
                ConstraintSet.START);
            constraintSet.setMargin(R.id.scale_bar, ConstraintSet.START, scaleBarMargin);
            constraintSet.clear(R.id.scale_bar, ConstraintSet.END);
        }

        constraintSet.applyTo(container);

        scaleBar.setRightToLeftEnabled(right);
    });
}
 
Example #6
Source File: OrderDialogFragment.java    From From-design-to-Android-part1 with Apache License 2.0 5 votes vote down vote up
private static ConstraintLayout.LayoutParams startColorParams(View selectedView) {
    final int colorSize = selectedView.getContext().getResources()
        .getDimensionPixelOffset(R.dimen.product_color_size);

    final ConstraintLayout.LayoutParams layoutParams =
        new ConstraintLayout.LayoutParams(colorSize, colorSize);

    setStartState(selectedView, layoutParams);
    return layoutParams;
}
 
Example #7
Source File: OrderDialogFragment.java    From From-design-to-Android-part1 with Apache License 2.0 5 votes vote down vote up
private static ConstraintLayout.LayoutParams endParams(View v, View targetView) {
    final ConstraintLayout.LayoutParams layoutParams =
        (ConstraintLayout.LayoutParams) v.getLayoutParams();

    final int marginLeft = v.getContext().getResources()
        .getDimensionPixelOffset(R.dimen.spacing_medium);

    layoutParams.setMargins(marginLeft, 0, 0, 0);
    layoutParams.topToTop = targetView.getId();
    layoutParams.startToEnd = targetView.getId();
    layoutParams.bottomToBottom = targetView.getId();

    return layoutParams;
}
 
Example #8
Source File: DotsFragment.java    From android-material-motion with Apache License 2.0 5 votes vote down vote up
@OnClick(R.id.second)
public void revealSecond(FloatingActionButton dot) {
  if (finished) {
    finished = false;
    lastDot = dot;
    ViewGroup.LayoutParams params = top.getLayoutParams();
    int height = params.height;
    params.height = ConstraintLayout.LayoutParams.MATCH_PARENT;
    top.setLayoutParams(params);
    topPanel.setBackgroundColor(dot.getBackgroundTintList().getDefaultColor());
    top.post(() -> {
      Animator animator = createRevealAnimator(lastDot, 0);
      int dotColor = dot.getBackgroundTintList().getDefaultColor();
      if (dotColor == color) {
        backgroundReveal().start();
      }
      AnimatorSet animatorSet = morphParent(duration(R.integer.reveal_duration));
      animatorSet.play(animator);
      addScaleAnimation(0, duration(R.integer.short_delay), animatorSet);
      animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
          super.onAnimationEnd(animation);
          ValueAnimator heightAnimation = ValueAnimator.ofInt(top.getHeight(), height);
          heightAnimation.addUpdateListener(valueAnimator -> {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = top.getLayoutParams();
            layoutParams.height = val;
            top.setLayoutParams(layoutParams);
          });
          heightAnimation.setDuration(duration(R.integer.reveal_duration) / 2);
          finish(heightAnimation);
          heightAnimation.start();
          runCloseAnimation();
        }
      });
      animatorSet.start();
    });
  }
}
 
Example #9
Source File: AuthFragment.java    From android-login with MIT License 5 votes vote down vote up
@OnClick(R.id.root)
public void unfold() {
  if (!lock) {
    caption.setVerticalText(false);
    caption.requestLayout();
    Rotate transition = new Rotate();
    transition.setStartAngle(-90f);
    transition.setEndAngle(0f);
    transition.addTarget(caption);
    TransitionSet set = new TransitionSet();
    set.setDuration(getResources().getInteger(R.integer.duration));
    ChangeBounds changeBounds = new ChangeBounds();
    set.addTransition(changeBounds);
    set.addTransition(transition);
    TextSizeTransition sizeTransition = new TextSizeTransition();
    sizeTransition.addTarget(caption);
    set.addTransition(sizeTransition);
    set.setOrdering(TransitionSet.ORDERING_TOGETHER);
    caption.post(() -> {
      TransitionManager.beginDelayedTransition(parent, set);
      caption.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.unfolded_size));
      caption.setTextColor(ContextCompat.getColor(getContext(), R.color.color_label));
      caption.setTranslationX(0);
      ConstraintLayout.LayoutParams params = getParams();
      params.rightToRight = ConstraintLayout.LayoutParams.PARENT_ID;
      params.leftToLeft = ConstraintLayout.LayoutParams.PARENT_ID;
      params.verticalBias = 0.78f;
      caption.setLayoutParams(params);
    });
    callback.show(this);
    lock = true;
  }
}
 
Example #10
Source File: SignUpFragment.java    From android-login with MIT License 5 votes vote down vote up
private void foldStuff() {
  caption.setTextSize(TypedValue.COMPLEX_UNIT_PX, caption.getTextSize() / 2f);
  caption.setTextColor(Color.WHITE);
  ConstraintLayout.LayoutParams params = getParams();
  params.rightToRight = ConstraintLayout.LayoutParams.UNSET;
  params.verticalBias = 0.5f;
  caption.setLayoutParams(params);
}
 
Example #11
Source File: OrderDialogFragment.java    From From-design-to-Android-part1 with Apache License 2.0 5 votes vote down vote up
private static ConstraintLayout.LayoutParams startTextParams(View selectedView) {
    final ConstraintLayout.LayoutParams layoutParams =
        new ConstraintLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    setStartState(selectedView, layoutParams);
    return layoutParams;
}
 
Example #12
Source File: StaggeredAnimationGroup.java    From StaggeredAnimationGroup with Apache License 2.0 5 votes vote down vote up
public final void hide(boolean inReversedOrder) {
    ConstraintLayout parent = getConstraintLayoutParent(this);
    if (notNull(parent)) {
        Transition transition = prepareStaggeredTransition(false, inReversedOrder);
        TransitionManager.beginDelayedTransition(parent, transition);
        setVisibility(View.GONE);
    }
}
 
Example #13
Source File: Utils.java    From StaggeredAnimationGroup with Apache License 2.0 5 votes vote down vote up
public static boolean notNull(ConstraintLayout parent) {
    if (parent == null) {
        warning("Trying to run show() on a StaggeredAnimationGroup without (proper) parent.");
        return false;
    }
    return true;
}
 
Example #14
Source File: UtilsTest.java    From StaggeredAnimationGroup with Apache License 2.0 5 votes vote down vote up
@Test
public void getConstraintLayoutParent_returnsParent_ifParent_isConstraintLayout() {
    //given
    StaggeredAnimationGroup spiedGroup = prepareSpiedGroup();
    ViewParent parent = new ConstraintLayout(RuntimeEnvironment.application);
    when(spiedGroup.getParent()).thenReturn(parent);

    //when
    ConstraintLayout result = Utils.getConstraintLayoutParent(spiedGroup);

    //then
    assertThat(result).isEqualTo(parent);
}
 
Example #15
Source File: UtilsTest.java    From StaggeredAnimationGroup with Apache License 2.0 5 votes vote down vote up
@Test
public void getConstraintLayoutParent_returnsNull_ifParent_isNotConstraintLayout() {
    //given
    StaggeredAnimationGroup spiedGroup = prepareSpiedGroup();
    ViewParent parent = new FrameLayout(RuntimeEnvironment.application);
    when(spiedGroup.getParent()).thenReturn(parent);

    //when
    ConstraintLayout result = Utils.getConstraintLayoutParent(spiedGroup);

    //then
    assertThat(result).isNull();
}
 
Example #16
Source File: UtilsTest.java    From StaggeredAnimationGroup with Apache License 2.0 5 votes vote down vote up
@Test
public void getConstraintLayoutParent_returnsNull_ifParent_isNull() {
    //given
    StaggeredAnimationGroup spiedGroup = prepareSpiedGroup();
    when(spiedGroup.getParent()).thenReturn(null);

    //when
    ConstraintLayout result = Utils.getConstraintLayoutParent(spiedGroup);

    //then
    assertThat(result).isNull();
}
 
Example #17
Source File: TransitionActivity.java    From layout-pancake with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_transition_1);
    mSceneOne.clone(this, R.layout.layout_transition_1);
    mSceneTwo.clone(this, R.layout.layout_transition_2);

    mConstraintLayout = (ConstraintLayout) findViewById(R.id.constraintLayout);
    findViewById(R.id.button_next).setOnClickListener(this);
    findViewById(R.id.button_cancel).setOnClickListener(this);
}
 
Example #18
Source File: ContextInstrumentationTests.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void mainActivityLayoutShouldHaveConstraintLayoutAsRoot() throws Exception {
    //
    LayoutInflater layoutInflater = appContext.getSystemService(LayoutInflater.class);
    View inflate = layoutInflater.inflate(R.layout.activity_main, null, false);
    assertThat(inflate, instanceOf(ConstraintLayout.class));
}
 
Example #19
Source File: MainActivity.java    From WanAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
    public void onBinding(@NonNull ActivityMainBinding binding) {
//        ToolbarHelper.initPaddingTopDiffBar(binding.navMenu.extrasNav);
        ConstraintLayout layout = binding.navMenu.extrasNav.getHeaderView(0).findViewById(R.id.navAccHolder);
        layout.post(() -> {
            int topHeight = ScreenUtils.getStatusHeight(MainActivity.this) + ScreenUtils.dipTopx(MainActivity.this, 100);
            ViewGroup.LayoutParams params1 = layout.getLayoutParams();
            params1.height = topHeight;
            layout.setLayoutParams(params1);

            NavigationView.LayoutParams params2 = (NavigationView.LayoutParams) binding.navMenu.navDown.getLayoutParams();
            params2.topMargin = topHeight;
            binding.navMenu.navDown.setLayoutParams(params2);
        });
        ToolbarHelper.initFullBar(binding.includeBar.toolbar, this);
        initDrawer(binding.drawer, binding.includeBar.toolbar);
        binding.navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
        binding.navMenu.drawerViewPager.setAdapter(mDrawerPagerAdapter);
        binding.navMenu.drawerTabLayout.setupWithViewPager(binding.navMenu.drawerViewPager);
//        binding.fab.setOnClickListener(v -> {
//            if (App.Login.isOK()) {
//                launchTodo();
//            } else {
//                LoginActivity.launch(MainActivity.this);
//            }
//        });
    }
 
Example #20
Source File: PlayerAdapter.java    From YTPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
    if (squarePage)
        container.removeView((ConstraintLayout)object);
    else
        container.removeView((LinearLayout)object);
}
 
Example #21
Source File: MainActivity.java    From AlipayPullRefresh with Apache License 2.0 5 votes vote down vote up
/**
 * 沉浸式状态栏
 */
private void adjustStatusBar() {
    boolean immerse = Utils.immerseStatusBar(this);
    View statusBarView = findViewById(R.id.home_status_view);
    if (immerse) {
        ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) statusBarView.getLayoutParams();
        lp.height = Utils.getStatusBarHeight(this);
        statusBarView.setLayoutParams(lp);
    } else {
        statusBarView.setVisibility(View.GONE);
    }
}
 
Example #22
Source File: PlaybackView.java    From justaline-android with Apache License 2.0 5 votes vote down vote up
private void init() {

        inflate(getContext(), R.layout.view_playback, this);

        setBackgroundColor(Color.BLACK);

        mAnalytics = Fa.get();

        TextureView mVideoTextureView = findViewById(R.id.video);
        mVideoTextureView.setSurfaceTextureListener(this);

        findViewById(R.id.close_button).setOnClickListener(this);
        findViewById(R.id.layout_share).setOnClickListener(this);
        findViewById(R.id.layout_save).setOnClickListener(this);

        // set margin of bottom icons to be appropriate size for screen
        View saveLayout = findViewById(R.id.layout_save);
        ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) saveLayout
                .getLayoutParams();
        layoutParams.bottomMargin = getHeightOfNavigationBar();
        saveLayout.setLayoutParams(layoutParams);

        View shareLayout = findViewById(R.id.layout_share);
        layoutParams = (ConstraintLayout.LayoutParams) shareLayout.getLayoutParams();
        layoutParams.bottomMargin = getHeightOfNavigationBar();
        shareLayout.setLayoutParams(layoutParams);

        mAudioAttributes = new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_MEDIA)
                .setContentType(AudioAttributes.CONTENT_TYPE_MOVIE)
                .build();

    }
 
Example #23
Source File: AlbumItemsAdapter.java    From imsdk-android with MIT License 5 votes vote down vote up
AlbumItemsViewHolder(View itemView) {
    super(itemView);
    this.ivAlbumCover = (ImageView) itemView.findViewById(R.id.iv_album_cover);
    this.tvAlbumName = (TextView) itemView.findViewById(R.id.tv_album_name);
    this.tvAlbumPhotosCount = (TextView) itemView.findViewById(R.id.tv_album_photos_count);
    this.ivSelected = (ImageView) itemView.findViewById(R.id.iv_selected);
    this.mRoot = (ConstraintLayout) itemView.findViewById(R.id.m_root_view);
}
 
Example #24
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //setContentView(R.layout.activity_main);
    //ConstraintLayout layout = findViewById(R.id.layout);
    
    ConstraintLayout layout = new ConstraintLayout(this);
    DatePicker datePicker = new DatePicker(this);
    layout.addView(datePicker);
    setContentView(layout);
}
 
Example #25
Source File: InstructionView.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
/**
 * Adjust the banner text layout {@link ConstraintLayout} vertical bias.
 *
 * @param percentBias to be set to the text layout
 */
private void adjustBannerTextVerticalBias(float percentBias) {
  int orientation = getContext().getResources().getConfiguration().orientation;
  if (orientation == Configuration.ORIENTATION_PORTRAIT) {
    ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) instructionLayoutText.getLayoutParams();
    params.verticalBias = percentBias;
    instructionLayoutText.setLayoutParams(params);
  }
}
 
Example #26
Source File: InstructionViewHolder.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void adjustBannerVerticalBias(float percentBias) {
  int orientation = itemView.getResources().getConfiguration().orientation;
  if (orientation == Configuration.ORIENTATION_PORTRAIT) {
    ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) instructionLayoutText.getLayoutParams();
    params.verticalBias = percentBias;
    instructionLayoutText.setLayoutParams(params);
  }
}
 
Example #27
Source File: EndNavigationActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void updateUiNavigationFinished() {
  navigationView.retrieveNavigationMapboxMap().retrieveMap().removeMarker(paella);
  navigationView.setVisibility(View.GONE);
  message.setText("Launch Navigation");
  message.setLayoutParams(new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT,
    ConstraintLayout.LayoutParams.MATCH_PARENT));
  launchNavigationFab.show();
}
 
Example #28
Source File: LoginActivity.java    From secure-quick-reliable-login with MIT License 5 votes vote down vote up
private void showPasswordLayout() {
    final LinearLayout rescueCodeLayout = findViewById(R.id.rescueCodeLayout);
    final ConstraintLayout passwordInputLayout = findViewById(R.id.txtLoginPasswordLayout);

    rescueCodeLayout.setVisibility(View.GONE);
    passwordInputLayout.setVisibility(View.VISIBLE);
}
 
Example #29
Source File: LoginActivity.java    From secure-quick-reliable-login with MIT License 5 votes vote down vote up
private void showRescueCodeLayout() {
    final LinearLayout rescueCodeLayout = findViewById(R.id.rescueCodeLayout);
    final ConstraintLayout passwordInputLayout = findViewById(R.id.txtLoginPasswordLayout);

    rescueCodeLayout.setVisibility(View.VISIBLE);
    passwordInputLayout.setVisibility(View.GONE);

}
 
Example #30
Source File: MainActivity.java    From AlipayPullRefresh with Apache License 2.0 5 votes vote down vote up
/**
 * 沉浸式状态栏
 */
private void adjustStatusBar() {
    boolean immerse = Utils.immerseStatusBar(this);
    View statusBarView = findViewById(R.id.home_status_view);
    if (immerse) {
        ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) statusBarView.getLayoutParams();
        lp.height = Utils.getStatusBarHeight(this);
        statusBarView.setLayoutParams(lp);
    } else {
        statusBarView.setVisibility(View.GONE);
    }
}