Skip to content

Commit b081ffb

Browse files
committed
Updated with cardview!
1 parent 3bf4a5e commit b081ffb

4 files changed

Lines changed: 61 additions & 38 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ dependencies {
2525
compile 'com.android.support:appcompat-v7:22.1.0'
2626
compile 'com.android.support:support-annotations:22.1.0'
2727
compile 'com.android.support:gridlayout-v7:22.1.0'
28+
compile 'com.android.support:cardview-v7:22.1.1'
2829
compile 'com.google.android.gms:play-services-gcm:7.0.0'
2930
}

app/src/main/java/com/example/android/sunshine/app/DetailFragment.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.support.v4.content.CursorLoader;
2525
import android.support.v4.content.Loader;
2626
import android.support.v7.app.AppCompatActivity;
27+
import android.support.v7.widget.CardView;
2728
import android.support.v7.widget.ShareActionProvider;
2829
import android.support.v7.widget.Toolbar;
2930
import android.view.LayoutInflater;
@@ -32,6 +33,7 @@
3233
import android.view.MenuItem;
3334
import android.view.View;
3435
import android.view.ViewGroup;
36+
import android.view.ViewParent;
3537
import android.widget.ImageView;
3638
import android.widget.TextView;
3739

@@ -177,14 +179,20 @@ public Loader<Cursor> onCreateLoader(int id, Bundle args) {
177179
null
178180
);
179181
}
180-
getView().setVisibility(View.INVISIBLE);
182+
ViewParent vp = getView().getParent();
183+
if ( vp instanceof CardView ) {
184+
((View)vp).setVisibility(View.INVISIBLE);
185+
}
181186
return null;
182187
}
183188

184189
@Override
185190
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
186191
if (data != null && data.moveToFirst()) {
187-
getView().setVisibility(View.VISIBLE);
192+
ViewParent vp = getView().getParent();
193+
if ( vp instanceof CardView ) {
194+
((View)vp).setVisibility(View.VISIBLE);
195+
}
188196

189197
// Read weather condition ID from cursor
190198
int weatherId = data.getInt(COL_WEATHER_CONDITION_ID);

app/src/main/res/layout-sw600dp-port/activity_main.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@
5252
android:layout_width="match_parent"
5353
android:layout_height="@dimen/details_app_bar_overlap" />
5454

55-
<FrameLayout
55+
<android.support.v7.widget.CardView
5656
android:id="@+id/weather_detail_container"
5757
android:layout_height="wrap_content"
5858
android:layout_width="match_parent"
59-
android:elevation="@dimen/appbar_elevation"
6059
android:layout_below="@id/sunshine_logo_imageview"
61-
android:paddingLeft="@dimen/abc_list_item_padding_horizontal_material"
62-
android:paddingRight="@dimen/abc_list_item_padding_horizontal_material"
60+
android:layout_marginLeft="@dimen/abc_list_item_padding_horizontal_material"
61+
android:layout_marginRight="@dimen/abc_list_item_padding_horizontal_material"
62+
app:cardElevation="@dimen/detail_card_elevation"
63+
app:cardPreventCornerOverlap="false"
6364
/>
6465

6566
<fragment

app/src/main/res/layout-sw600dp/activity_main.xml

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
-->
16-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
16+
<RelativeLayout
17+
xmlns:android="http://schemas.android.com/apk/res/android"
1718
xmlns:app="http://schemas.android.com/apk/res-auto"
1819
xmlns:tools="http://schemas.android.com/tools"
1920
android:layout_width="match_parent"
2021
android:layout_height="match_parent">
2122

22-
<LinearLayout
23+
<RelativeLayout
2324
android:id="@+id/appbar"
2425
android:layout_width="match_parent"
2526
android:layout_height="wrap_content"
@@ -32,33 +33,34 @@
3233
android:id="@+id/toolbar"
3334
android:layout_width="match_parent"
3435
android:layout_height="?attr/actionBarSize"
36+
android:layout_alignParentTop="true"
37+
android:layout_alignParentLeft="true"
38+
3539
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
3640

37-
<!-- These FrameLayouts are only there to line the image up with the keyline correctly, since
38-
we cannot do addition of dimensions/attributes otherwise -->
39-
<FrameLayout
40-
android:layout_width="wrap_content"
41-
android:layout_height="wrap_content"
41+
<!-- This Space is only there to line the image up with the
42+
keyline correctly, since we cannot do addition of
43+
dimensions/attributes otherwise -->
44+
<android.support.v4.widget.Space
45+
android:id="@+id/sunshineLogoAlign"
46+
android:layout_width="@dimen/list_icon"
47+
android:layout_height="0dp"
4248
android:layout_marginLeft="@dimen/abc_list_item_padding_horizontal_material"
4349
android:layout_marginStart="@dimen/abc_list_item_padding_horizontal_material"
44-
>
45-
<FrameLayout
46-
android:layout_width="wrap_content"
47-
android:layout_height="wrap_content"
48-
android:layout_marginLeft="@dimen/list_icon"
49-
android:layout_marginStart="@dimen/list_icon"
50-
android:paddingLeft="@dimen/abc_list_item_padding_horizontal_material"
51-
android:paddingStart="@dimen/abc_list_item_padding_horizontal_material">
50+
android:layout_alignParentLeft="true"
51+
android:layout_below="@id/toolbar"/>
5252

53-
<ImageView
54-
android:layout_width="wrap_content"
55-
android:layout_height="?attr/listPreferredItemHeight"
56-
android:layout_gravity="center_vertical"
57-
android:src="@drawable/ic_logo"
58-
android:contentDescription="@string/app_name"/>
59-
</FrameLayout>
60-
</FrameLayout>
61-
</LinearLayout>
53+
<ImageView
54+
android:layout_width="wrap_content"
55+
android:layout_height="?attr/listPreferredItemHeight"
56+
android:layout_gravity="center_vertical"
57+
android:layout_below="@id/sunshineLogoAlign"
58+
android:layout_marginLeft="@dimen/abc_list_item_padding_horizontal_material"
59+
android:layout_marginStart="@dimen/abc_list_item_padding_horizontal_material"
60+
android:layout_toRightOf="@id/sunshineLogoAlign"
61+
android:src="@drawable/ic_logo"
62+
android:contentDescription="@string/app_name"/>
63+
</RelativeLayout>
6264

6365
<!-- This is used as a strut to create two columns in our RelativeLayout -->
6466
<android.support.v4.widget.Space
@@ -79,11 +81,11 @@
7981
android:layout_below="@id/appbar"
8082
tools:layout="@android:layout/list_content" />
8183

82-
<!-- We set elevation here only so the detail view doesn't get occluded
83-
by the AppBar -->
84-
85-
<FrameLayout
86-
android:id="@+id/weather_detail_container"
84+
<!-- This is used to give the card the appropriate margin
85+
list_item_extra_padding +
86+
abc_list_item_padding_horizontal_material -->
87+
<android.support.v7.widget.Space
88+
android:id="@+id/cardviewAligner"
8789
android:layout_width="match_parent"
8890
android:layout_height="match_parent"
8991
android:layout_alignLeft="@id/layout_center"
@@ -94,9 +96,20 @@
9496
android:elevation="@dimen/appbar_elevation"
9597
android:layout_marginRight="@dimen/list_item_extra_padding"
9698
android:layout_marginEnd="@dimen/list_item_extra_padding"
97-
android:paddingRight="@dimen/abc_list_item_padding_horizontal_material"
98-
android:paddingEnd="@dimen/abc_list_item_padding_horizontal_material"
99-
android:paddingBottom="@dimen/detail_container_bottom_margin"
10099
/>
100+
<android.support.v7.widget.CardView
101+
android:id="@+id/weather_detail_container"
102+
android:layout_width="match_parent"
103+
android:layout_height="match_parent"
104+
android:layout_alignLeft="@id/cardviewAligner"
105+
android:layout_alignRight="@id/cardviewAligner"
106+
android:layout_alignTop="@id/cardviewAligner"
107+
android:layout_alignBottom="@id/cardviewAligner"
108+
android:layout_marginRight="@dimen/abc_list_item_padding_horizontal_material"
109+
android:layout_marginEnd="@dimen/abc_list_item_padding_horizontal_material"
110+
android:layout_marginBottom="@dimen/detail_container_bottom_margin"
111+
app:cardElevation="@dimen/detail_card_elevation"
112+
app:cardPreventCornerOverlap="false"
113+
/>
101114

102115
</RelativeLayout>

0 commit comments

Comments
 (0)