Can also use proper menu resource for other menus

git-svn-id: https://zxing.googlecode.com/svn/trunk@2358 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2012-07-22 10:09:32 +00:00
parent 7513a4c896
commit 99c99f7314
4 changed files with 68 additions and 21 deletions

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2012 ZXing authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_share"
android:title="@string/menu_share"
android:icon="@android:drawable/ic_menu_share"
android:orderInCategory="1"/>
<item android:id="@+id/menu_encode"
android:title="@string/menu_encode_vcard"
android:icon="@android:drawable/ic_menu_sort_alphabetically"
android:orderInCategory="2"/>
</menu>

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2012 ZXing authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_history_send"
android:title="@string/history_send"
android:icon="@android:drawable/ic_menu_share"
android:orderInCategory="1"/>
<item android:id="@+id/menu_history_clear_text"
android:title="@string/history_clear_text"
android:icon="@android:drawable/ic_menu_delete"
android:orderInCategory="2"/>
</menu>

View file

@ -17,6 +17,7 @@
package com.google.zxing.client.android.encode;
import android.view.Display;
import android.view.MenuInflater;
import android.view.WindowManager;
import com.google.zxing.WriterException;
import com.google.zxing.client.android.FinishListener;
@ -52,8 +53,6 @@ public final class EncodeActivity extends Activity {
private static final String TAG = EncodeActivity.class.getSimpleName();
private static final int SHARE_MENU = Menu.FIRST;
private static final int ENCODE_FORMAT_MENU = Menu.FIRST + 1;
private static final int MAX_BARCODE_FILENAME_LENGTH = 24;
private static final Pattern NOT_ALPHANUMERIC = Pattern.compile("[^A-Za-z0-9]");
private static final String USE_VCARD_KEY = "USE_VCARD";
@ -78,22 +77,22 @@ public final class EncodeActivity extends Activity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(Menu.NONE, SHARE_MENU, Menu.NONE, R.string.menu_share).setIcon(android.R.drawable.ic_menu_share);
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.encode, menu);
boolean useVcard = qrCodeEncoder != null && qrCodeEncoder.isUseVCard();
int encodeNameResource = useVcard ? R.string.menu_encode_mecard : R.string.menu_encode_vcard;
menu.add(Menu.NONE, ENCODE_FORMAT_MENU, Menu.NONE, encodeNameResource)
.setIcon(android.R.drawable.ic_menu_sort_alphabetically);
return true;
MenuItem encodeItem = menu.getItem(1);
encodeItem.setTitle(encodeNameResource);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case SHARE_MENU:
case R.id.menu_share:
share();
return true;
case ENCODE_FORMAT_MENU:
case R.id.menu_encode:
Intent intent = getIntent();
intent.putExtra(USE_VCARD_KEY, !qrCodeEncoder.isUseVCard());
startActivity(getIntent());
@ -205,10 +204,10 @@ public final class EncodeActivity extends Activity {
TextView contents = (TextView) findViewById(R.id.contents_text_view);
if (intent.getBooleanExtra(Intents.Encode.SHOW_CONTENTS, true)) {
contents.setText(qrCodeEncoder.getDisplayContents());
setTitle(getString(R.string.app_name) + " - " + qrCodeEncoder.getTitle());
setTitle(qrCodeEncoder.getTitle());
} else {
contents.setText("");
setTitle(getString(R.string.app_name));
setTitle("");
}
} catch (WriterException e) {
Log.w(TAG, "Could not encode barcode", e);

View file

@ -25,6 +25,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
@ -37,9 +38,6 @@ import java.util.List;
public final class HistoryActivity extends ListActivity {
private static final int SEND_ID = Menu.FIRST;
private static final int CLEAR_ID = Menu.FIRST + 1;
private HistoryManager historyManager;
private HistoryItemAdapter adapter;
@ -96,19 +94,17 @@ public final class HistoryActivity extends ListActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
if (historyManager.hasHistoryItems()) {
menu.add(0, SEND_ID, 0, R.string.history_send).setIcon(android.R.drawable.ic_menu_share);
menu.add(0, CLEAR_ID, 0, R.string.history_clear_text).setIcon(android.R.drawable.ic_menu_delete);
return true;
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.history, menu);
}
return false;
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case SEND_ID:
case R.id.menu_history_send:
CharSequence history = historyManager.buildHistory();
Uri historyFile = HistoryManager.saveHistory(history.toString());
if (historyFile == null) {
@ -127,7 +123,7 @@ public final class HistoryActivity extends ListActivity {
startActivity(intent);
}
break;
case CLEAR_ID:
case R.id.menu_history_clear_text:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.msg_sure);
builder.setCancelable(true);