Commit cffc8724 authored by kirk's avatar kirk

fix screen rotation bugs

parent e357aa8e
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/two_fragments_horizontal"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/single_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/left_fragment"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</FrameLayout>
<FrameLayout
android:id="@+id/right_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/left_fragment" >
</FrameLayout>
</RelativeLayout>
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" />
......@@ -198,7 +198,8 @@ public final class MainActivity extends FragmentActivity implements
case R.id.share_qr_item:
return shareQrCode();
shareQrCode();
return true;
default:
......@@ -306,32 +307,7 @@ public final class MainActivity extends FragmentActivity implements
}
}
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
if (findViewById(R.id.single_fragment) != null) {
transaction.add(R.id.single_fragment,
WifiSettingsFragment.newInstance(settings));
qrCodeFragment = null;
} else if (findViewById(R.id.two_fragments_vertical) != null) {
transaction.add(R.id.top_fragment,
WifiSettingsFragment.newInstance(settings));
qrCodeFragment = QrCodeFragment.newInstance(settings);
transaction.add(R.id.bottom_fragment, qrCodeFragment);
} else {
transaction.add(R.id.left_fragment,
WifiSettingsFragment.newInstance(settings));
qrCodeFragment = QrCodeFragment.newInstance(settings);
transaction.add(R.id.right_fragment, qrCodeFragment);
}
transaction.commit();
setFragments(savedInstanceState);
}
......@@ -508,15 +484,88 @@ public final class MainActivity extends FragmentActivity implements
}
/**
* Initialize the UI {@link Fragment} instances according to the current
* screen layout
*
* @param savedInstanceState
* saved state or <code>null</code>
*/
private void setFragments(Bundle savedInstanceState) {
if (findViewById(R.id.single_fragment) != null) {
if (savedInstanceState != null) {
return;
}
setSinglePane();
} else if (findViewById(R.id.two_fragments_vertical) != null) {
setPortrait();
} else {
setLandscape();
}
}
/**
* Initialize the two-pane landscape layout
*/
private void setLandscape() {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.left_fragment,
WifiSettingsFragment.newInstance(settings));
qrCodeFragment = QrCodeFragment.newInstance(settings);
transaction.replace(R.id.right_fragment, qrCodeFragment);
transaction.commit();
}
/**
* Initialize the two-pane portrait layout
*/
private void setPortrait() {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.top_fragment,
WifiSettingsFragment.newInstance(settings));
qrCodeFragment = QrCodeFragment.newInstance(settings);
transaction.replace(R.id.bottom_fragment, qrCodeFragment);
transaction.commit();
}
/**
* Initialize the single-pane layout
*/
private void setSinglePane() {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.single_fragment,
WifiSettingsFragment.newInstance(settings));
qrCodeFragment = null;
transaction.commit();
}
/**
* Handle "Share QR..." menu item
*
* This shows {@link QrCodeFragment} in single-pane mode, or invokes
* {@link QrCodeFragment#shareQrCode()} in two-pane mode
*
* @return <code>true</code>
*/
private boolean shareQrCode() {
private void shareQrCode() {
if (qrCodeFragment == null) {
......@@ -532,9 +581,6 @@ public final class MainActivity extends FragmentActivity implements
qrCodeFragment.shareQrCode();
}
return true;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment