mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
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:
parent
41d2082342
commit
7513a4c896
38
android/res/menu/capture.xml
Normal file
38
android/res/menu/capture.xml
Normal 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>
|
|
@ -52,6 +52,7 @@ import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import android.view.SurfaceView;
|
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 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 DEFAULT_INTENT_RESULT_DURATION_MS = 1500L;
|
||||||
private static final long BULK_MODE_SCAN_DELAY_MS = 1000L;
|
private static final long BULK_MODE_SCAN_DELAY_MS = 1000L;
|
||||||
|
|
||||||
|
@ -334,26 +329,9 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
super.onCreateOptionsMenu(menu);
|
MenuInflater menuInflater = getMenuInflater();
|
||||||
menu.add(Menu.NONE, SHARE_ID, Menu.NONE, R.string.menu_share)
|
menuInflater.inflate(R.menu.capture, menu);
|
||||||
.setIcon(android.R.drawable.ic_menu_share);
|
return super.onCreateOptionsMenu(menu);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -361,23 +339,23 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case SHARE_ID:
|
case R.id.menu_share:
|
||||||
intent.setClassName(this, ShareActivity.class.getName());
|
intent.setClassName(this, ShareActivity.class.getName());
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
break;
|
break;
|
||||||
case HISTORY_ID:
|
case R.id.menu_history:
|
||||||
intent.setClassName(this, HistoryActivity.class.getName());
|
intent.setClassName(this, HistoryActivity.class.getName());
|
||||||
startActivityForResult(intent, HISTORY_REQUEST_CODE);
|
startActivityForResult(intent, HISTORY_REQUEST_CODE);
|
||||||
break;
|
break;
|
||||||
case SETTINGS_ID:
|
case R.id.menu_settings:
|
||||||
intent.setClassName(this, PreferencesActivity.class.getName());
|
intent.setClassName(this, PreferencesActivity.class.getName());
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
break;
|
break;
|
||||||
case HELP_ID:
|
case R.id.menu_help:
|
||||||
intent.setClassName(this, HelpActivity.class.getName());
|
intent.setClassName(this, HelpActivity.class.getName());
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
break;
|
break;
|
||||||
case ABOUT_ID:
|
case R.id.menu_about:
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setTitle(getString(R.string.title_about) + versionName);
|
builder.setTitle(getString(R.string.title_about) + versionName);
|
||||||
builder.setMessage(getString(R.string.msg_about) + "\n\n" + getString(R.string.zxing_url));
|
builder.setMessage(getString(R.string.msg_about) + "\n\n" + getString(R.string.zxing_url));
|
||||||
|
|
Loading…
Reference in a new issue