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

Commit

Permalink
5.09 Build Two Pane Tablet UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyla committed Mar 4, 2015
1 parent 5da9899 commit 1ea4116
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 24 deletions.
Expand Up @@ -30,7 +30,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_detail);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new DetailFragment())
.add(R.id.weather_detail_container, new DetailFragment())
.commit();
}
}
Expand Down
Expand Up @@ -145,7 +145,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
Log.v(LOG_TAG, "In onCreateLoader");
Intent intent = getActivity().getIntent();
if (intent == null) {
if (intent == null || intent.getData() == null) {
return null;
}

Expand Down
Expand Up @@ -26,19 +26,32 @@
public class MainActivity extends ActionBarActivity {

private final String LOG_TAG = MainActivity.class.getSimpleName();
private final String FORECASTFRAGMENT_TAG = "FFTAG";
private static final String DETAILFRAGMENT_TAG = "DFTAG";

private boolean mTwoPane;
private String mLocation;

@Override
protected void onCreate(Bundle savedInstanceState) {
mLocation = Utility.getPreferredLocation(this);
super.onCreate(savedInstanceState);
mLocation = Utility.getPreferredLocation(this);

setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new ForecastFragment(), FORECASTFRAGMENT_TAG)
.commit();
if (findViewById(R.id.weather_detail_container) != null) {
// The detail container view will be present only in the large-screen layouts
// (res/layout-sw600dp). If this view is present, then the activity should be
// in two-pane mode.
mTwoPane = true;
// In two-pane mode, show the detail view in this activity by
// adding or replacing the detail fragment using a
// fragment transaction.
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.weather_detail_container, new DetailFragment(), DETAILFRAGMENT_TAG)
.commit();
}
} else {
mTwoPane = false;
}
}

Expand Down Expand Up @@ -94,8 +107,8 @@ protected void onResume() {
super.onResume();
String location = Utility.getPreferredLocation( this );
// update the location in our second pane using the fragment manager
if (location != null && !location.equals(mLocation)) {
ForecastFragment ff = (ForecastFragment)getSupportFragmentManager().findFragmentByTag(FORECASTFRAGMENT_TAG);
if (location != null && !location.equals(mLocation)) {
ForecastFragment ff = (ForecastFragment)getSupportFragmentManager().findFragmentById(R.id.fragment_forecast);
if ( null != ff ) {
ff.onLocationChanged();
}
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/res/layout-sw600dp/activity_main.xml
@@ -0,0 +1,28 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
android:orientation="horizontal"
tools:context="com.example.android.sunshine.app.MainActivity">

<!--
This layout is a two-pane layout for the Items master/detail flow.
-->

<fragment
android:id="@+id/fragment_forecast"
android:name="com.example.android.sunshine.app.ForecastFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
tools:layout="@android:layout/list_content" />

<FrameLayout
android:id="@+id/weather_detail_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4" />

</LinearLayout>
10 changes: 6 additions & 4 deletions app/src/main/res/layout/activity_detail.xml
@@ -1,5 +1,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="com.example.android.sunshine.app.DetailActivity" tools:ignore="MergeRootFrame" />

xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/weather_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.sunshine.app.DetailActivity"
tools:ignore="MergeRootFrame" />
14 changes: 10 additions & 4 deletions app/src/main/res/layout/activity_main.xml
@@ -1,4 +1,10 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity" tools:ignore="MergeRootFrame" />
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_forecast"
android:name="com.example.android.sunshine.app.ForecastFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
tools:context="com.example.android.sunshine.app.ForecastFragment"
tools:layout="@android:layout/list_content" />
6 changes: 0 additions & 6 deletions app/src/main/res/values-w820dp/dimens.xml

This file was deleted.

4 comments on commit 1ea4116

@salmankhan2424
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, I am using an emulator for this to try out the two pane UI, the device being used is nexus 7 but i'm still not getting a two pane UI.
The line in MainAcitivty.java "if (findViewById(R.id.weather_detail_container) != null)" always returns a null. Can someone help me out here?

@whatIsBest99
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also have this question before,but you may use the nexus 9 to test or change the value of “layout-600dp” a bit smaller,like“layout-400dp” or even smaller

@pratu16x7
Copy link

@pratu16x7 pratu16x7 commented on 1ea4116 Jul 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had this too. The skin definition AVD configuration seems to be the cause: http://stackoverflow.com/a/32722831 As a result noticed a 'skin not large enough to view entire screen' warning when the skin definition is a default 'nexus_7_2013'.
screen shot 2016-07-11 at 6 25 06 pm
That may explain the emulator screen being apparently less than 600dp and hence showing the phone layout. However, it looks like the warning is present in all default configured AVDs. Setting the skin to 'No Skin' resolves it nevertheless.

@vagnerr
Copy link

@vagnerr vagnerr commented on 1ea4116 Aug 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HEADS UP - BLANK FORECAST FRAGMENT
Is your tablet showing nothing on your forecast view?

Chances are like me you spun up a fresh tablet VM, to test your hard work was successful. This will result in a blank forecast because you have not yet downloaded any forecast data from the server and saved it locally to your sqlite db.

Currently there is no logic built to detect that you have an empty database, and force a call to updateWeather(). Just use the refresh control in the menu. After the first run it will always have some data to display.

(/me spend 20 mins trying to figure out what I had done wrong until I <facepalmed> :) )

Please sign in to comment.