Skip to content

Commit

Permalink
Better landscape / wide device support for DN story.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbutcher committed Feb 18, 2016
1 parent 3725d1d commit bd64f9c
Show file tree
Hide file tree
Showing 20 changed files with 338 additions and 166 deletions.
34 changes: 17 additions & 17 deletions app/src/main/java/io/plaidapp/ui/DesignerNewsStory.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,27 +171,20 @@ protected void onCreate(Bundle savedInstanceState) {
R.layout.designer_news_story_description, commentsList, false);
bindDescription();

// setup toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.story_toolbar);
if (collapsingToolbar != null) { // portrait: collapsing toolbar
// setup title/toolbar
if (collapsingToolbar != null) { // narrow device: collapsing toolbar
collapsingToolbar.addOnLayoutChangeListener(titlebarLayout);
collapsingToolbar.setTitle(story.title);
} else { // landscape: scroll toolbar with content
toolbar = (Toolbar) header.findViewById(R.id.story_toolbar);
FontTextView title = (FontTextView) toolbar.findViewById(R.id.story_title);
final Toolbar toolbar = (Toolbar) findViewById(R.id.story_toolbar);
toolbar.setNavigationOnClickListener(backClick);
commentsList.addOnScrollListener(headerScrollListener);
} else { // w600dp configuration: content card scrolls over title bar
final TextView title = (TextView) findViewById(R.id.story_title);
title.setText(story.title);
findViewById(R.id.back).setOnClickListener(backClick);
}
commentsList.addOnScrollListener(headerScrollListener);

toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finishAfterTransition();
}
});

View enterCommentView = setupCommentField();

final View enterCommentView = setupCommentField();
if (story.comment_count > 0) {
// flatten the comments from a nested structure {@see Comment#comments} to a
// list appropriate for our adapter (using the depth attribute).
Expand Down Expand Up @@ -288,14 +281,21 @@ public void onCustomTabsConnected() {
@Override public void onCustomTabsDisconnected() { }
};

private RecyclerView.OnScrollListener headerScrollListener
private final RecyclerView.OnScrollListener headerScrollListener
= new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
updateScrollDependentUi();
}
};

private final View.OnClickListener backClick = new View.OnClickListener() {
@Override
public void onClick(View view) {
finishAfterTransition();
}
};

private void updateScrollDependentUi() {
// feed scroll events to the header
if (collapsingToolbar != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
*/
public class CollapsingTitleLayout extends FrameLayout {

private static final float density = 420f / 160f;

// configurable attributes
private int titleInsetStart;
private float titleInsetTop;
Expand Down
80 changes: 80 additions & 0 deletions app/src/main/java/io/plaidapp/ui/widget/DynamicTypeTextView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.plaidapp.ui.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.TypedValue;

import io.plaidapp.R;
import io.plaidapp.util.ViewUtils;

/**
* An extension to {@link android.widget.TextView} which sizes text to grow up to a specified
* maximum size, per the material spec:
* https://www.google.com/design/spec/style/typography.html#typography-other-typographic-guidelines
*/
public class DynamicTypeTextView extends BaselineGridTextView {

// configurable attributes
private final float minTextSize;
private final float maxTextSize;

public DynamicTypeTextView(Context context) {
this(context, null);
}

public DynamicTypeTextView(Context context, AttributeSet attrs) {
this(context, attrs, android.R.attr.textViewStyle);
}

public DynamicTypeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, 0);
}

public DynamicTypeTextView(Context context, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);

/* re-use CollapsingTitleLayout attribs */
final TypedArray a =
context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout);
if (a.hasValue(R.styleable.CollapsingTitleLayout_collapsedTextSize)) {
minTextSize = a.getDimensionPixelSize(
R.styleable.CollapsingTitleLayout_collapsedTextSize, 0);
setTextSize(TypedValue.COMPLEX_UNIT_PX, minTextSize);
} else {
// if not explicitly set then use the default text size as the min
minTextSize = getTextSize();
}
maxTextSize = a.getDimensionPixelSize(
R.styleable.CollapsingTitleLayout_maxExpandedTextSize, Integer.MAX_VALUE);
a.recycle();
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
final float expandedTitleTextSize = Math.max(minTextSize,
ViewUtils.getSingleLineTextSize(getText().toString(), getPaint(),
w - getPaddingStart() - getPaddingEnd(),
minTextSize,
maxTextSize, 0.5f, getResources().getDisplayMetrics()));
setTextSize(TypedValue.COMPLEX_UNIT_PX, expandedTitleTextSize);
}
}
37 changes: 0 additions & 37 deletions app/src/main/res/animator/comment_selection_delayed.xml

This file was deleted.

63 changes: 63 additions & 0 deletions app/src/main/res/animator/selected_comment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2016 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_activated="true">

<set android:ordering="together">

<objectAnimator
android:propertyName="backgroundColor"
android:valueFrom="@color/background_light"
android:valueTo="@color/selected_comment_background"
android:duration="@android:integer/config_shortAnimTime"
android:valueType="colorType" />

<objectAnimator
android:propertyName="translationZ"
android:valueTo="@dimen/z_card"
android:startOffset="300"
android:duration="@android:integer/config_shortAnimTime"
android:interpolator="@android:interpolator/fast_out_slow_in" />

</set>

</item>

<item>

<set android:ordering="together">

<objectAnimator
android:propertyName="backgroundColor"
android:valueFrom="@color/selected_comment_background"
android:valueTo="@color/background_light"
android:duration="@android:integer/config_shortAnimTime"
android:valueType="colorType" />

<objectAnimator
android:propertyName="translationZ"
android:valueTo="0dp"
android:duration="@android:integer/config_shortAnimTime"
android:interpolator="@android:interpolator/fast_out_slow_in" />

</set>

</item>

</selector>
1 change: 1 addition & 0 deletions app/src/main/res/drawable/comment_background.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
android:exitFadeDuration="@android:integer/config_shortAnimTime">

<item android:state_activated="true" android:drawable="@color/selected_comment_background" />
<item android:drawable="@color/designer_news_story_comment_background" />

</selector>
42 changes: 0 additions & 42 deletions app/src/main/res/layout-land/activity_designer_news_story.xml

This file was deleted.

37 changes: 0 additions & 37 deletions app/src/main/res/layout-land/designer_news_story_title_toolbar.xml

This file was deleted.

Loading

0 comments on commit bd64f9c

Please sign in to comment.