Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Commit

Permalink
Modernized card layouts to remove depricated widgets (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
idzkowski-google authored Feb 24, 2020
1 parent 5b1e9bb commit 6f39758
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 180 deletions.
14 changes: 3 additions & 11 deletions CardSample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,7 @@ android {

dependencies {
implementation 'com.example.glass.ui:gesture-lib-sample:0.1.0-SNAPSHOT'

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'

testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:4.1'

androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package com.example.android.glass.cardsample;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.example.glass.ui.GlassGestureDetector;
import com.example.glass.ui.GlassGestureDetector.Gesture;
import com.example.glass.ui.GlassGestureDetector.OnGestureListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
package com.example.android.glass.cardsample;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.example.android.glass.cardsample.fragments.BaseFragment;
import com.example.android.glass.cardsample.fragments.ColumnLayoutFragment;
import com.example.android.glass.cardsample.fragments.MainLayoutFragment;
import com.example.glass.ui.GlassGestureDetector.Gesture;
import com.google.android.material.tabs.TabLayout;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -61,7 +61,7 @@ protected void onCreate(Bundle savedInstanceState) {
getString(R.string.empty_string), null));

screenSlidePagerAdapter.notifyDataSetChanged();

final TabLayout tabLayout = findViewById(R.id.page_indicator);
tabLayout.setupWithViewPager(viewPager, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import static android.app.Activity.RESULT_OK;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.widget.Toast;
import androidx.fragment.app.Fragment;
import com.example.android.glass.cardsample.R;
import com.example.android.glass.cardsample.menu.MenuActivity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,18 @@

import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.example.android.glass.cardsample.R;

/**
* Fragment with the two column layout based on the
* <a href="https://developers.google.com/glass/develop/gdk/card-design#left_column_layout">
* Left Column Layout</a>.
* Fragment with the two column layout.
*/
public class ColumnLayoutFragment extends BaseFragment {

Expand All @@ -40,6 +38,7 @@ public class ColumnLayoutFragment extends BaseFragment {
private static final String FOOTER_KEY = "footer_key";
private static final String TIMESTAMP_KEY = "timestamp_key";
private static final int TEXT_SIZE = 30;
private static final int IMAGE_PADDING = 40;

/**
* Returns new instance of {@link ColumnLayoutFragment}.
Expand Down Expand Up @@ -71,17 +70,18 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

if (getArguments() != null) {
final ImageView imageView = new ImageView(getActivity());
imageView.setPadding(IMAGE_PADDING, IMAGE_PADDING, IMAGE_PADDING, IMAGE_PADDING);
imageView.setImageResource(getArguments().getInt(IMAGE_KEY));

final RelativeLayout leftColumn = view.findViewById(R.id.left_column);
final FrameLayout leftColumn = view.findViewById(R.id.left_column);
leftColumn.addView(imageView);

final TextView textView = new TextView(getActivity());
textView.setText(getArguments().getString(TEXT_KEY));
textView.setTextSize(TEXT_SIZE);
textView.setTypeface(Typeface.create(getString(R.string.thin_font), Typeface.NORMAL));

final RelativeLayout rightColumn = view.findViewById(R.id.right_column);
final FrameLayout rightColumn = view.findViewById(R.id.right_column);
rightColumn.addView(textView);

final TextView footer = view.findViewById(R.id.footer);
Expand All @@ -92,12 +92,4 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
}
return view;
}

@Override
public void onSingleTapUp() {
/*
Does nothing intentionally
Overriding this method removes the menu functionality from the fragment.
*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@

import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.example.android.glass.cardsample.R;

/**
* Fragment with the main card layout based on the
* <a href="https://developers.google.com/glass/develop/gdk/card-design#main_layout">
* Main Layout</a>.
* Fragment with the main card layout.
*/
public class MainLayoutFragment extends BaseFragment {

Expand Down Expand Up @@ -73,7 +71,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
textView.setTextSize(BODY_TEXT_SIZE);
textView.setTypeface(Typeface.create(getString(R.string.thin_font), Typeface.NORMAL));

final RelativeLayout bodyLayout = view.findViewById(R.id.body_layout);
final FrameLayout bodyLayout = view.findViewById(R.id.body_layout);
bodyLayout.addView(textView);

final TextView footer = view.findViewById(R.id.footer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package com.example.android.glass.cardsample.menu;

import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.Objects;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.PagerSnapHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.LayoutManager;
import android.support.v7.widget.RecyclerView.OnScrollListener;
import android.support.v7.widget.SnapHelper;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.PagerSnapHelper;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.LayoutManager;
import androidx.recyclerview.widget.RecyclerView.OnScrollListener;
import androidx.recyclerview.widget.SnapHelper;
import com.example.android.glass.cardsample.BaseActivity;
import com.example.android.glass.cardsample.R;
import com.example.glass.ui.GlassGestureDetector.Gesture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package com.example.android.glass.cardsample.menu;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.android.glass.cardsample.databinding.MenuItemBinding;
import java.util.List;

Expand Down
114 changes: 53 additions & 61 deletions CardSample/app/src/main/res/layout/left_column_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,79 +15,71 @@
limitations under the License.
-->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
android:layout_height="match_parent">

<RelativeLayout
<FrameLayout
android:id="@+id/left_column"
android:layout_width="@dimen/glass_card_left_column_width"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:background="#303030"
>
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent=".333">

<!-- Put widgets for the left column inside this RelativeLayout. -->
<!-- Put widgets for the left column inside this FrameLayout. -->

</RelativeLayout>
</FrameLayout>

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="@dimen/glass_card_body_height"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="@dimen/glass_card_two_column_margin"
android:layout_marginRight="@dimen/glass_card_margin"
android:layout_marginTop="@dimen/glass_card_margin"
android:layout_toRightOf="@+id/left_column"
<FrameLayout
android:id="@+id/right_column"
tools:ignore="UselessLeaf"
>
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="@dimen/glass_card_two_column_margin"
android:layout_marginStart="@dimen/glass_card_two_column_margin"
android:layout_marginBottom="@dimen/glass_card_two_column_margin"
android:layout_marginEnd="@dimen/glass_card_margin"
app:layout_constraintBottom_toTopOf="@id/footer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/left_column"
app:layout_constraintTop_toTopOf="parent">

</RelativeLayout>
<!-- Put widgets for the right column inside this FrameLayout. -->

<LinearLayout
android:id="@+id/footer_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|left"
android:layout_marginBottom="@dimen/glass_card_footer_margin"
android:layout_marginLeft="@dimen/glass_card_two_column_margin"
android:layout_marginRight="@dimen/glass_card_margin"
android:layout_toRightOf="@+id/left_column"
android:orientation="horizontal"
>

<!--
The footer view will grow to fit as much content as possible while the
timestamp view keeps a fixed width. If the footer text is too long, it
will be ellipsized with a 40px margin between it and the timestamp.
-->
</FrameLayout>

<TextView
android:id="@+id/footer"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
/>
<!-- The footer view will grow to fit as much content as possible while the
timestamp view keeps its width. If the footer text is too long, it
will be ellipsized with a 40dp margin between it and the timestamp. -->

<TextView
android:id="@+id/timestamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/glass_card_margin"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
/>
<TextView
android:id="@+id/footer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/glass_card_margin"
android:layout_marginEnd="@dimen/glass_card_margin"
android:layout_marginBottom="@dimen/glass_card_margin"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/timestamp"
app:layout_constraintStart_toEndOf="@id/left_column" />

</LinearLayout>
<TextView
android:id="@+id/timestamp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/glass_card_margin"
android:layout_marginBottom="@dimen/glass_card_margin"
android:ellipsize="end"
android:singleLine="true"
android:textAlignment="viewEnd"
android:textAppearance="?android:attr/textAppearanceSmall"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit 6f39758

Please sign in to comment.