If you think the Android project arcgis-runtime-samples-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.esri.arcgis.android.samples.offlineeditor;
/*fromwww.java2s.com*//* Copyright 2014 ESRI
*
* All rights reserved under the copyright laws of the United States
* and applicable international laws, treaties, and conventions.
*
* You may freely redistribute and use this sample code, with or
* without modification, provided you include the original copyright
* notice and use restrictions.
*
* See the sample code usage restrictions document for further information.
*
*/import android.content.Context;
import android.view.ActionMode;
import android.view.ActionMode.Callback;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
publicclass OfflineActions implements Callback {
privatestaticfinalint MENU_DELETE = 0;
privatestaticfinalint MENU_UNDO = 1;
privatestaticfinalint MENU_SAVE = 2;
privatestaticfinalint MENU_SYNC = 3;
privatestaticfinalint MENU_TEMPLATES = 4;
Context mContext;
public OfflineActions(final OfflineEditorActivity activity) {
mContext = activity;
}
@Override
publicboolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case MENU_DELETE:
((OfflineEditorActivity) mContext).clear();
break;
case MENU_UNDO:
((OfflineEditorActivity) mContext).undo();
break;
case MENU_SAVE:
try {
((OfflineEditorActivity) mContext).save();
} catch (Exception e) {
Toast.makeText(mContext,
"This edit is outside the replica extent. You are limited to edits inside your replicated extent",
Toast.LENGTH_LONG).show();
}
break;
case MENU_SYNC:
((OfflineEditorActivity) mContext).syncGdb();
break;
case MENU_TEMPLATES:
((OfflineEditorActivity) mContext).showEditTemplatePicker();
break;
default:
break;
}
return false;
}
@Override
publicboolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuItem item;
item = menu.add(Menu.NONE, MENU_UNDO, 2, "undo");
item.setIcon(android.R.drawable.ic_menu_revert);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
item = menu.add(Menu.NONE, MENU_DELETE, 3, "discard");
item.setIcon(R.drawable.ic_action_content_discard);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
item = menu.add(Menu.NONE, MENU_SAVE, 1, "save");
item.setIcon(R.drawable.ic_action_save);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
item = menu.add(Menu.NONE, MENU_SYNC, 4, "sync");
item.setIcon(R.drawable.ic_action_sync);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
item = menu.add(Menu.NONE, MENU_TEMPLATES, 5, "show templates");
item.setIcon(R.drawable.ic_action_edit_template);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
@Override
publicvoid onDestroyActionMode(ActionMode mode) {
mContext = null;
}
@Override
publicboolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
}