Skip to content

Commit

Permalink
Display error messages on empty result and failed connection.
Browse files Browse the repository at this point in the history
  • Loading branch information
phw committed Jun 3, 2012
1 parent 3dd9ef4 commit d53bc4a
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 9 deletions.
15 changes: 15 additions & 0 deletions res/drawable/errorbox.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<solid android:color="@color/errorBackgroundColor" />

<stroke android:width="1dp" android:color="@color/errorColor"/>

<corners
android:bottomLeftRadius="7dp"
android:bottomRightRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp" />

</shape>
12 changes: 12 additions & 0 deletions res/layout/activity_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
android:orientation="vertical"
android:padding="@dimen/window_padding" >

<TextView
android:id="@+id/label_connection_error"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/label_connection_error"
android:background="@drawable/errorbox"
android:padding="@dimen/messagebox_padding"
android:textColor="@color/errorColor"
android:layout_marginBottom="@dimen/content_padding"
android:visibility="gone"
/>

<TextView
android:id="@+id/description_connect"
android:layout_width="fill_parent"
Expand Down
1 change: 1 addition & 0 deletions res/layout/activity_result.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
android:padding="@dimen/window_padding" >

<TextView
android:id="@+id/description_search_result"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/description_result" />
Expand Down
2 changes: 2 additions & 0 deletions res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@
<color name="background">#FFF</color>
<color name="text">#000</color>
<color name="lightText">#999</color>
<color name="errorColor">#B94A48</color>
<color name="errorBackgroundColor">#F2DEDE</color>

</resources>
3 changes: 2 additions & 1 deletion res/values/geometry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@

<dimen name="window_padding">16dp</dimen>
<dimen name="content_padding">12dp</dimen>

<dimen name="messagebox_padding">6dp</dimen>

</resources>
4 changes: 3 additions & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@

<string name="app_name">Picard Barcode Scanner</string>
<string name="actionbar_title">Picard Barcode Scanner</string>
<string name="description_connect">In order to send scanned barcodes to Picard you have to connect your phone with Picard.\n\nPlease enter the IP address and port number shown by the Picard Barcode Scanner plugin into the input field below.</string>
<string name="description_connect">In order to send scanned barcodes to Picard you have to connect your phone to the same network as the computer running Picard. Enter the IP address of the computer and Picard\'s port number below.</string>
<string name="label_connection_error">Could not connect to Picard. Please check the connection settings and your WiFi connection.</string>
<string name="picard_ip_address">IP address:</string>
<string name="picard_port">Port:</string>
<string name="btn_picard_connect">Connect with Picard</string>
<string name="description_scanner">Use your phone\'s camera to scan the barcode of a CD or other music media. If MusicBrainz knows about the media it will automatically be loaded into MusicBrainz Picard.</string>
<string name="btn_scan_barcode">Scan barcode</string>
<string name="description_result">MusicBrainz has found the following results for this barcode and sent them to Picard.</string>
<string name="description_no_result">MusicBrainz has not found any release for this barcode.</string>
<string name="loading_musicbrainz_text">Consulting MusicBrainz&#8230;</string>
<string name="loading_picard_text">Sending data to Picard&#8230;</string>
<string name="btn_save_preferences">Save settings</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ protected void setSubView(int subView) {
actionBar.setHomeAction(new ActionBar.IntentAction(this, homeIntent, R.drawable.ic_menu_tags));
actionBar.addAction(new ActionBar.IntentAction(this, new Intent(
this, PreferencesActivity.class), R.drawable.ic_menu_settings));

handleIntents();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void onCreate(Bundle savedInstanceState) {
mLoadingTextView = (TextView) findViewById(R.id.loading_text);
mLoadingTextView.setText(R.string.loading_musicbrainz_text);

handleIntents();
search();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class PreferencesActivity extends BaseActivity {

Expand All @@ -48,13 +49,16 @@ public void onCreate(Bundle savedInstanceState) {
mPortInput = (EditText) findViewById(R.id.picard_port);
mConnectBtn = (Button) findViewById(R.id.btn_picard_connect);

if (mBarcode != null) {
mConnectBtn.setText(R.string.btn_picard_connect);
}

handleIntents();
registerEventListeners();
loadFormDataFromPreferences();
checkConnectButtonEnabled();

if (mBarcode != null) {
TextView errorMsg = (TextView) findViewById(R.id.label_connection_error);
errorMsg.setVisibility(View.VISIBLE);
mConnectBtn.setText(R.string.btn_picard_connect);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@
import android.widget.TextView;

public class ResultActivity extends BaseActivity {
TextView descriptionTextView;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setSubView(R.layout.activity_result);

descriptionTextView = (TextView) findViewById(R.id.description_search_result);

Button connectBtn = (Button) findViewById(R.id.btn_scan_barcode);
connectBtn.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -50,11 +54,14 @@ public void onClick(View v) {
startActivity(resultIntent);
}
});

handleIntents();
}

@Override
protected void handleIntents() {
super.handleIntents();
int numberOfReleases = 0;

Bundle extras = getIntent().getExtras();
if (extras != null) {
Expand All @@ -65,7 +72,7 @@ protected void handleIntents() {
String[] releaseDates = extras
.getStringArray(Constants.INTENT_EXTRA_RELEASE_DATES);

int numberOfReleases = Math.min(
numberOfReleases = Math.min(
Math.min(releaseTitles.length, releaseArtists.length),
releaseDates.length);

Expand All @@ -80,6 +87,10 @@ protected void handleIntents() {
releaseArtists[i], releaseDates[i]);
}
}

if (numberOfReleases == 0) {
descriptionTextView.setText(R.string.description_no_result);
}
}

private void setViewText(View view, int fieldId, String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setSubView(R.layout.activity_scanner);

handleIntents();

if (!checkIfSettingsAreComplete()) {
Intent configurePicard = new Intent(ScannerActivity.this,
PreferencesActivity.class);
Expand Down

0 comments on commit d53bc4a

Please sign in to comment.