Commit e357aa8e authored by kirk's avatar kirk

add support for landscape mode; fix more bugs in screen updates

parent 6aa2d6ae
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="us.rader.wyfy"
android:versionCode="17"
android:versionName="1.17" >
android:versionCode="18"
android:versionName="1.18" >
<uses-sdk
android:minSdkVersion="10"
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/two_fragments_horizontal"
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>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/two_fragments_horizontal"
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>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/two_fragments"
android:id="@+id/two_fragments_vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/first_fragment"
android:id="@+id/top_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
......@@ -15,12 +15,12 @@
</FrameLayout>
<FrameLayout
android:id="@+id/second_fragment"
android:id="@+id/bottom_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="@id/first_fragment"
android:layout_below="@id/top_fragment"
android:layout_gravity="center" >
</FrameLayout>
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="main" type="layout">@layout/two_panes</item>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="main" type="layout">@layout/two_panes</item>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="main" type="layout">@layout/one_pane</item>
</resources>
\ No newline at end of file
......@@ -228,6 +228,43 @@ public final class MainActivity extends FragmentActivity implements
}
}
/**
* Handle the response from another activity started by this one for its
* result
*
* @param requestCode
* the request code to which this is the response
*
* @param resultCode
* the result code for the response
*
* @param resultData
* the result data from the response
*
* @see android.support.v4.app.FragmentActivity#onActivityResult(int, int,
* android.content.Intent)
*/
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent resultData) {
super.onActivityResult(requestCode, resultCode, resultData);
switch (requestCode) {
case REQUEST_WRITE_TAG:
onTagWritten(resultCode, resultData);
break;
default:
alert(getString(R.string.unrecognized_request));
break;
}
}
/**
* Prepare this instance to be displayed
*
......@@ -269,12 +306,6 @@ public final class MainActivity extends FragmentActivity implements
}
}
if (savedInstanceState != null) {
return;
}
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
......@@ -284,81 +315,24 @@ public final class MainActivity extends FragmentActivity implements
WifiSettingsFragment.newInstance(settings));
qrCodeFragment = null;
} else {
} else if (findViewById(R.id.two_fragments_vertical) != null) {
transaction.add(R.id.first_fragment,
transaction.add(R.id.top_fragment,
WifiSettingsFragment.newInstance(settings));
qrCodeFragment = QrCodeFragment.newInstance(settings);
transaction.add(R.id.second_fragment, qrCodeFragment);
}
transaction.commit();
}
/**
* Initialize from a legacy {@link NdefMessage}
*
* Provide backward compatibility for tags written with older versions of
* this app
*
* @param ndefMessage
* legacy {@link NdefMessage}
*/
private void initialize(NdefMessage ndefMessage) {
try {
NdefRecord[] records = ndefMessage.getRecords();
if (records.length > 0) {
NdefRecord record = records[0];
if (record.getTnf() != NdefRecord.TNF_MIME_MEDIA) {
return;
}
String type = new String(record.getType(), "US-ASCII"); //$NON-NLS-1$
if ("application/x-wyfy".equals(type)) { //$NON-NLS-1$
String payload = new String(record.getPayload(), "US-ASCII"); //$NON-NLS-1$
initialize(payload);
}
}
transaction.add(R.id.bottom_fragment, qrCodeFragment);
} catch (Exception e) {
} else {
Log.e(getClass().getName(), "initializeNdefMessage", e); //$NON-NLS-1$
transaction.add(R.id.left_fragment,
WifiSettingsFragment.newInstance(settings));
qrCodeFragment = QrCodeFragment.newInstance(settings);
transaction.add(R.id.right_fragment, qrCodeFragment);
}
}
/**
* Initialize {@link #settings} from the given WIFI: {@link Uri}
*
* @param uri
* WIFI: {@link Uri}
*/
private void initialize(String uri) {
try {
settings = WifiSettings.parse(uri);
if (settings != null) {
connectOnStart = true;
}
} catch (Exception e) {
Log.e(getClass().getName(), "error parsing URI", e); //$NON-NLS-1$
transaction.commit();
}
}
/**
......@@ -408,67 +382,65 @@ public final class MainActivity extends FragmentActivity implements
}
/**
* Handle "Share QR..." menu item
* Initialize from a legacy {@link NdefMessage}
*
* This shows {@link QrCodeFragment} in single-pane mode, or invokes
* {@link QrCodeFragment#shareQrCode()} in two-pane mode
* Provide backward compatibility for tags written with older versions of
* this app
*
* @return <code>true</code>
* @param ndefMessage
* legacy {@link NdefMessage}
*/
private boolean shareQrCode() {
private void initialize(NdefMessage ndefMessage) {
if (qrCodeFragment == null) {
try {
NdefRecord[] records = ndefMessage.getRecords();
if (records.length > 0) {
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.single_fragment,
QrCodeFragment.newInstance(settings));
transaction.addToBackStack(null);
transaction.commit();
NdefRecord record = records[0];
} else {
if (record.getTnf() != NdefRecord.TNF_MIME_MEDIA) {
qrCodeFragment.shareQrCode();
return;
}
}
return true;
String type = new String(record.getType(), "US-ASCII"); //$NON-NLS-1$
if ("application/x-wyfy".equals(type)) { //$NON-NLS-1$
String payload = new String(record.getPayload(), "US-ASCII"); //$NON-NLS-1$
initialize(payload);
}
}
} catch (Exception e) {
Log.e(getClass().getName(), "initializeNdefMessage", e); //$NON-NLS-1$
}
}
/**
* Handle the response from another activity started by this one for its
* result
*
* @param requestCode
* the request code to which this is the response
*
* @param resultCode
* the result code for the response
*
* @param resultData
* the result data from the response
* Initialize {@link #settings} from the given WIFI: {@link Uri}
*
* @see android.support.v4.app.FragmentActivity#onActivityResult(int, int,
* android.content.Intent)
* @param uri
* WIFI: {@link Uri}
*/
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent resultData) {
private void initialize(String uri) {
try {
super.onActivityResult(requestCode, resultCode, resultData);
settings = WifiSettings.parse(uri);
switch (requestCode) {
if (settings != null) {
case REQUEST_WRITE_TAG:
connectOnStart = true;
onTagWritten(resultCode, resultData);
break;
}
default:
} catch (Exception e) {
alert(getString(R.string.unrecognized_request));
break;
Log.e(getClass().getName(), "error parsing URI", e); //$NON-NLS-1$
}
}
......@@ -536,6 +508,35 @@ public final class MainActivity extends FragmentActivity implements
}
/**
* 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() {
if (qrCodeFragment == null) {
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.single_fragment,
QrCodeFragment.newInstance(settings));
transaction.addToBackStack(null);
transaction.commit();
} else {
qrCodeFragment.shareQrCode();
}
return true;
}
/**
* Start {@Link WriteTagActivity}
*
......
......@@ -38,8 +38,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.google.zxing.WriterException;
/**
* {link Fragment} to display the QR code representation of the current WIFI:
* URI
......@@ -95,7 +93,7 @@ public final class QrCodeFragment extends Fragment {
}
} catch (WriterException e) {
} catch (Exception e) {
Log.e(getClass().getName(), "doInBackground", e); //$NON-NLS-1$
......@@ -353,8 +351,23 @@ public final class QrCodeFragment extends Fragment {
*/
private int getQrCodeSize() {
View view = getView().findViewById(R.id.qr_code_layout);
int size = Math.min(view.getWidth(), view.getHeight());
View view = getView();
if (view == null) {
return 0;
}
View qrView = view.findViewById(R.id.qr_code_layout);
if (qrView == null) {
return 0;
}
int size = Math.min(qrView.getWidth(), qrView.getHeight());
return size;
}
......
......@@ -132,13 +132,6 @@ public final class WriteTagActivity extends NdefWriterActivity {
setContentView(R.layout.write_tag_activity);
// Show the Up button in the action bar.
setupActionBar();
if (savedInstanceState != null) {
return;
}
Intent intent;
if (uri == null) {
......
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