Use menu resource instead of hard-coding

git-svn-id: https://zxing.googlecode.com/svn/trunk@2357 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2012-07-22 07:24:01 +00:00
parent 41d2082342
commit 7513a4c896
2 changed files with 47 additions and 31 deletions

View file

@ -0,0 +1,38 @@
<?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_history"
android:title="@string/menu_history"
android:icon="@android:drawable/ic_menu_recent_history"
android:orderInCategory="2"/>
<item android:id="@+id/menu_settings"
android:title="@string/menu_settings"
android:icon="@android:drawable/ic_menu_preferences"
android:orderInCategory="3"/>
<item android:id="@+id/menu_help"
android:title="@string/menu_help"
android:icon="@android:drawable/ic_menu_help"
android:orderInCategory="4"/>
<item android:id="@+id/menu_about"
android:title="@string/menu_about"
android:icon="@android:drawable/ic_menu_info_details"
android:orderInCategory="5"/>
</menu>

View file

@ -52,6 +52,7 @@ import android.util.Log;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
@ -85,12 +86,6 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
private static final String TAG = CaptureActivity.class.getSimpleName();
private static final int SHARE_ID = Menu.FIRST;
private static final int HISTORY_ID = Menu.FIRST + 1;
private static final int SETTINGS_ID = Menu.FIRST + 2;
private static final int HELP_ID = Menu.FIRST + 3;
private static final int ABOUT_ID = Menu.FIRST + 4;
private static final long DEFAULT_INTENT_RESULT_DURATION_MS = 1500L;
private static final long BULK_MODE_SCAN_DELAY_MS = 1000L;
@ -334,26 +329,9 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(Menu.NONE, SHARE_ID, Menu.NONE, R.string.menu_share)
.setIcon(android.R.drawable.ic_menu_share);
menu.add(Menu.NONE, HISTORY_ID, Menu.NONE, R.string.menu_history)
.setIcon(android.R.drawable.ic_menu_recent_history);
menu.add(Menu.NONE, SETTINGS_ID, Menu.NONE, R.string.menu_settings)
.setIcon(android.R.drawable.ic_menu_preferences);
menu.add(Menu.NONE, HELP_ID, Menu.NONE, R.string.menu_help)
.setIcon(android.R.drawable.ic_menu_help);
menu.add(Menu.NONE, ABOUT_ID, Menu.NONE, R.string.menu_about)
.setIcon(android.R.drawable.ic_menu_info_details);
return true;
}
// Don't display the share menu item if the result overlay is showing.
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.findItem(SHARE_ID).setVisible(lastResult == null);
return true;
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.capture, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
@ -361,23 +339,23 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
switch (item.getItemId()) {
case SHARE_ID:
case R.id.menu_share:
intent.setClassName(this, ShareActivity.class.getName());
startActivity(intent);
break;
case HISTORY_ID:
case R.id.menu_history:
intent.setClassName(this, HistoryActivity.class.getName());
startActivityForResult(intent, HISTORY_REQUEST_CODE);
break;
case SETTINGS_ID:
case R.id.menu_settings:
intent.setClassName(this, PreferencesActivity.class.getName());
startActivity(intent);
break;
case HELP_ID:
case R.id.menu_help:
intent.setClassName(this, HelpActivity.class.getName());
startActivity(intent);
break;
case ABOUT_ID:
case R.id.menu_about:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.title_about) + versionName);
builder.setMessage(getString(R.string.msg_about) + "\n\n" + getString(R.string.zxing_url));