use of android.support.v7.view.ActionMode in project PhoneProfilesPlus by henrichg.
the class EditorProfilesActivity method onCreate.
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GlobalGUIRoutines.setTheme(this, false, true, true);
GlobalGUIRoutines.setLanguage(getBaseContext());
instance = this;
savedInstanceStateChanged = (savedInstanceState != null);
createApplicationsCache();
createContactsCache();
createContactGroupsCache();
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) && (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP))
setContentView(R.layout.activity_editor_list_onepane_19);
else
setContentView(R.layout.activity_editor_list_onepane);
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) && (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)) {
// in Activity's onCreate() for instance
Window w = getWindow();
// w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// create our manager instance after the content view is set
SystemBarTintManager tintManager = new SystemBarTintManager(this);
// enable status bar tint
tintManager.setStatusBarTintEnabled(true);
// set a custom tint color for status bar
if (ApplicationPreferences.applicationTheme(getApplicationContext()).equals("material"))
tintManager.setStatusBarTintColor(Color.parseColor("#ff237e9f"));
else
tintManager.setStatusBarTintColor(Color.parseColor("#ff202020"));
}
if (findViewById(R.id.editor_detail_container) != null) {
// The detail container view will be present only in the
// large-screen layouts (res/values-large and
// res/values-sw600dp). If this view is present, then the
// activity should be in two-pane mode.
mTwoPane = true;
if (savedInstanceState == null) {
Fragment fragment = getFragmentManager().findFragmentById(R.id.editor_detail_container);
if (fragment != null) {
getFragmentManager().beginTransaction().remove(fragment).commit();
}
} else {
// for 7 inch tablets layout changed:
// - portrait - one pane
// - landscape - two pane
// onRestartProfilePreferences is called, when user save/not save profile
// preference changes (Back button, or Cancel in ActionMode)
// In this method, editMode and profile_id is saved into shared preferences
// And when orientation changed into landscape mode, profile preferences fragment
// must by recreated due profile preference changes
ApplicationPreferences.getSharedPreferences(this);
int dataType = ApplicationPreferences.preferences.getInt(SP_DATA_DETAILS_DATA_TYPE, EditorProfileListFragment.EDIT_MODE_UNDEFINED);
if (dataType == 1) {
long profile_id = ApplicationPreferences.preferences.getLong(SP_DATA_DETAILS_DATA_ID, 0);
int editMode = ApplicationPreferences.preferences.getInt(SP_DATA_DETAILS_EDIT_MODE, EditorProfileListFragment.EDIT_MODE_UNDEFINED);
int predefinedProfileIndex = ApplicationPreferences.preferences.getInt(SP_DATA_DETAILS_PREDEFINED_PROFILE_INDEX, 0);
Bundle arguments = new Bundle();
arguments.putLong(PPApplication.EXTRA_PROFILE_ID, profile_id);
arguments.putInt(EXTRA_NEW_PROFILE_MODE, editMode);
arguments.putInt(EXTRA_PREDEFINED_PROFILE_INDEX, predefinedProfileIndex);
arguments.putBoolean(EditorProfileListFragment.START_TARGET_HELPS_ARGUMENT, false);
ProfileDetailsFragment fragment = new ProfileDetailsFragment();
fragment.setArguments(arguments);
getFragmentManager().beginTransaction().replace(R.id.editor_detail_container, fragment, "ProfileDetailsFragment").commit();
} else if (dataType == 2) {
long event_id = ApplicationPreferences.preferences.getLong(SP_DATA_DETAILS_DATA_ID, 0);
int editMode = ApplicationPreferences.preferences.getInt(SP_DATA_DETAILS_EDIT_MODE, EditorEventListFragment.EDIT_MODE_UNDEFINED);
int predefinedEventIndex = ApplicationPreferences.preferences.getInt(SP_DATA_DETAILS_PREDEFINED_EVENT_INDEX, 0);
Bundle arguments = new Bundle();
arguments.putLong(PPApplication.EXTRA_EVENT_ID, event_id);
arguments.putInt(EXTRA_NEW_EVENT_MODE, editMode);
arguments.putInt(EXTRA_PREDEFINED_EVENT_INDEX, predefinedEventIndex);
arguments.putBoolean(EditorProfileListFragment.START_TARGET_HELPS_ARGUMENT, false);
EventDetailsFragment fragment = new EventDetailsFragment();
fragment.setArguments(arguments);
getFragmentManager().beginTransaction().replace(R.id.editor_detail_container, fragment, "EventDetailsFragment").commit();
} else {
Fragment fragment = getFragmentManager().findFragmentById(R.id.editor_detail_container);
if (fragment != null) {
getFragmentManager().beginTransaction().remove(fragment).commit();
}
}
}
} else {
mTwoPane = false;
FragmentManager fragmentManager = getFragmentManager();
Fragment fragment = fragmentManager.findFragmentByTag("ProfileDetailsFragment");
if (fragment != null)
fragmentManager.beginTransaction().remove(fragment).commit();
fragment = fragmentManager.findFragmentByTag("EventDetailsFragment");
if (fragment != null)
fragmentManager.beginTransaction().remove(fragment).commit();
fragmentManager.executePendingTransactions();
}
drawerLayout = findViewById(R.id.editor_list_drawer_layout);
drawerRoot = findViewById(R.id.editor_drawer_root);
// set status bar background for Activity body layout
if (ApplicationPreferences.applicationTheme(getApplicationContext()).equals("material"))
drawerLayout.setStatusBarBackground(R.color.primaryDark);
else if (ApplicationPreferences.applicationTheme(getApplicationContext()).equals("dark"))
drawerLayout.setStatusBarBackground(R.color.primaryDark_dark);
else if (ApplicationPreferences.applicationTheme(getApplicationContext()).equals("dlight"))
drawerLayout.setStatusBarBackground(R.color.primaryDark_dark);
drawerListView = findViewById(R.id.editor_drawer_list);
// noinspection ConstantConditions
@SuppressLint("InflateParams") View headerView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.editor_drawer_list_header, null, false);
drawerListView.addHeaderView(headerView, null, false);
drawerHeaderFilterImage = findViewById(R.id.editor_drawer_list_header_icon);
drawerHeaderFilterTitle = findViewById(R.id.editor_drawer_list_header_title);
drawerHeaderFilterSubtitle = findViewById(R.id.editor_drawer_list_header_subtitle);
/*
RelativeLayout headerBackground = findViewById(R.id.editor_drawer_list_header_background);
// set status bar background for Activity body layout
if (ApplicationPreferences.applicationTheme(getApplicationContext()).equals("material"))
headerBackground.setBackgroundResource(R.drawable.editor_drawer_list_header_background);
else
if (ApplicationPreferences.applicationTheme(getApplicationContext()).equals("dark"))
headerBackground.setBackgroundResource(R.drawable.editor_drawer_list_header_background_dark);
else
if (ApplicationPreferences.applicationTheme(getApplicationContext()).equals("dlight"))
headerBackground.setBackgroundResource(R.drawable.editor_drawer_list_header_background);
*/
int drawerShadowId;
if (ApplicationPreferences.applicationTheme(getApplicationContext()).equals("dark"))
drawerShadowId = R.drawable.drawer_shadow_dark;
else
drawerShadowId = R.drawable.drawer_shadow;
drawerLayout.setDrawerShadow(drawerShadowId, GravityCompat.START);
// actionbar titles
drawerItemsTitle = new String[] { getResources().getString(R.string.editor_drawer_title_profiles), getResources().getString(R.string.editor_drawer_title_profiles), getResources().getString(R.string.editor_drawer_title_profiles), getResources().getString(R.string.editor_drawer_title_events), getResources().getString(R.string.editor_drawer_title_events), getResources().getString(R.string.editor_drawer_title_events), getResources().getString(R.string.editor_drawer_title_events), getResources().getString(R.string.editor_drawer_title_events) };
// drawer item titles
drawerItemsSubtitle = new String[] { getResources().getString(R.string.editor_drawer_list_item_profiles_all), getResources().getString(R.string.editor_drawer_list_item_profiles_show_in_activator), getResources().getString(R.string.editor_drawer_list_item_profiles_no_show_in_activator), getResources().getString(R.string.editor_drawer_list_item_events_start_order), getResources().getString(R.string.editor_drawer_list_item_events_all), getResources().getString(R.string.editor_drawer_list_item_events_running), getResources().getString(R.string.editor_drawer_list_item_events_paused), getResources().getString(R.string.editor_drawer_list_item_events_stopped) };
drawerItemsIcon = new Integer[] { R.drawable.ic_events_drawer_profile_filter_2, R.drawable.ic_events_drawer_profile_filter_0, R.drawable.ic_events_drawer_profile_filter_1, R.drawable.ic_events_drawer_event_filter_2, R.drawable.ic_events_drawer_event_filter_2, R.drawable.ic_events_drawer_event_filter_0, R.drawable.ic_events_drawer_event_filter_1, R.drawable.ic_events_drawer_event_filter_3 };
// Pass string arrays to EditorDrawerListAdapter
// use action bar themed context
// drawerAdapter = new EditorDrawerListAdapter(drawerListView, getSupportActionBar().getThemedContext(), drawerItemsTitle, drawerItemsSubtitle, drawerItemsIcon);
EditorDrawerListAdapter drawerAdapter = new EditorDrawerListAdapter(/*drawerListView, */
getBaseContext(), drawerItemsTitle, drawerItemsSubtitle, drawerItemsIcon);
// Set the MenuListAdapter to the ListView
drawerListView.setAdapter(drawerAdapter);
// Capture listview menu item click
drawerListView.setOnItemClickListener(new DrawerItemClickListener());
editorToolbar = findViewById(R.id.editor_tollbar);
setSupportActionBar(editorToolbar);
// Enable ActionBar app icon to behave as action to toggle nav drawer
if (getSupportActionBar() != null) {
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.editor_drawer_open, R.string.editor_drawer_open) {
/*
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
*/
// this disable animation
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
if (drawerView != null && drawerView == drawerRoot) {
super.onDrawerSlide(drawerView, 0);
} else {
super.onDrawerSlide(drawerView, slideOffset);
}
}
};
drawerLayout.addDrawerListener(drawerToggle);
filterStatusBarTitle = findViewById(R.id.editor_filter_title);
filterStatusBarTitle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
drawerLayout.openDrawer(drawerRoot);
}
});
orderSpinner = findViewById(R.id.editor_list_bottom_bar_order);
ArrayAdapter<CharSequence> orderSpinnerAdapter = ArrayAdapter.createFromResource(// getSupportActionBar().getThemedContext(),
getBaseContext(), R.array.drawerOrderEvents, // android.R.layout.simple_spinner_item);
R.layout.editor_drawer_spinner);
// orderSpinnerAdapter.setDropDownViewResource(android.support.v7.appcompat.R.layout.support_simple_spinner_dropdown_item);
orderSpinnerAdapter.setDropDownViewResource(R.layout.editor_drawer_spinner_dropdown);
orderSpinner.setAdapter(orderSpinnerAdapter);
orderSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position != orderSelectedItem)
changeEventOrder(position, false);
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
TextView orderLabel = findViewById(R.id.editor_list_bottom_bar_order_title);
orderLabel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
orderSpinner.performClick();
}
});
eventsRunStopIndicator = findViewById(R.id.editor_list_run_stop_indicator);
eventsRunStopIndicator.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
RunStopIndicatorPopupWindow popup = new RunStopIndicatorPopupWindow(getDataWrapper(), EditorProfilesActivity.this);
View contentView = popup.getContentView();
contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int measuredW = contentView.getMeasuredWidth();
// int measuredH = contentView.getMeasuredHeight();
// Log.d("ActivateProfileActivity.eventsRunStopIndicator.onClick","measuredW="+measuredW);
// Log.d("ActivateProfileActivity.eventsRunStopIndicator.onClick","measuredH="+measuredH);
int[] location = new int[2];
eventsRunStopIndicator.getLocationOnScreen(location);
int x = 0;
int y = 0;
if (location[0] + eventsRunStopIndicator.getWidth() - measuredW < 0)
x = -(location[0] + eventsRunStopIndicator.getWidth() - measuredW);
popup.setClippingEnabled(false);
popup.showOnAnchor(eventsRunStopIndicator, RelativePopupWindow.VerticalPosition.ALIGN_TOP, RelativePopupWindow.HorizontalPosition.ALIGN_RIGHT, x, y, false);
}
});
// set drawer item and order
if ((savedInstanceState != null) || (ApplicationPreferences.applicationEditorSaveEditorState(getApplicationContext()))) {
ApplicationPreferences.getSharedPreferences(this);
drawerSelectedItem = ApplicationPreferences.preferences.getInt(SP_EDITOR_DRAWER_SELECTED_ITEM, 1);
orderSelectedItem = ApplicationPreferences.preferences.getInt(SP_EDITOR_ORDER_SELECTED_ITEM, 0);
}
// first must be set eventsOrderType
changeEventOrder(orderSelectedItem, savedInstanceState != null);
selectDrawerItem(drawerSelectedItem, false, savedInstanceState != null, false);
refreshGUI(false, true);
}
use of android.support.v7.view.ActionMode in project Osmand by osmandapp.
the class AvailableGPXFragment method openSelectionMode.
public void openSelectionMode(final int actionResId, int darkIcon, int lightIcon, final DialogInterface.OnClickListener listener) {
final int actionIconId = !isLightActionBar() ? darkIcon : lightIcon;
String value = app.getString(actionResId);
if (value.endsWith("...")) {
value = value.substring(0, value.length() - 3);
}
final String actionButton = value;
if (allGpxAdapter.getGroupCount() == 0) {
Toast.makeText(getActivity(), app.getString(R.string.local_index_no_items_to_do, actionButton.toLowerCase()), Toast.LENGTH_SHORT).show();
return;
}
enableSelectionMode(true);
selectedItems.clear();
selectedGroups.clear();
actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
enableSelectionMode(true);
MenuItem it = menu.add(actionResId);
if (actionIconId != 0) {
it.setIcon(actionIconId);
}
MenuItemCompat.setShowAsAction(it, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (selectedItems.isEmpty()) {
Toast.makeText(getActivity(), app.getString(R.string.local_index_no_items_to_do, actionButton.toLowerCase()), Toast.LENGTH_SHORT).show();
return true;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(getString(R.string.local_index_action_do, actionButton.toLowerCase(), selectedItems.size()));
builder.setPositiveButton(actionButton, listener);
builder.setNegativeButton(R.string.shared_string_cancel, null);
builder.show();
return true;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
enableSelectionMode(false);
allGpxAdapter.notifyDataSetChanged();
}
});
allGpxAdapter.notifyDataSetChanged();
}
use of android.support.v7.view.ActionMode in project Osmand by osmandapp.
the class OsmEditsFragment method enterUploadMode.
private void enterUploadMode() {
actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(final ActionMode mode, Menu menu) {
enableSelectionMode(true);
MenuItem item = menu.add(R.string.local_openstreetmap_uploadall).setIcon(R.drawable.ic_action_export);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
uploadItems(osmEditsSelected.toArray(new OsmPoint[osmEditsSelected.size()]));
mode.finish();
return true;
}
});
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
osmEditsSelected.clear();
listAdapter.notifyDataSetChanged();
updateSelectionMode(mode);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
enableSelectionMode(false);
listAdapter.notifyDataSetChanged();
}
});
}
use of android.support.v7.view.ActionMode in project Osmand by osmandapp.
the class OsmEditsFragment method enterDeleteMode.
private void enterDeleteMode() {
actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(final ActionMode mode, Menu menu) {
enableSelectionMode(true);
MenuItem item = menu.add(R.string.shared_string_delete_all).setIcon(R.drawable.ic_action_delete_dark);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
deleteItems(osmEditsSelected);
mode.finish();
return true;
}
});
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
osmEditsSelected.clear();
listAdapter.notifyDataSetChanged();
updateSelectionMode(mode);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
enableSelectionMode(false);
listAdapter.notifyDataSetChanged();
}
});
}
use of android.support.v7.view.ActionMode in project Osmand by osmandapp.
the class NotesFragment method enterSelectionMode.
private void enterSelectionMode(final int type) {
actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(final ActionMode mode, Menu menu) {
LOG.debug("onCreateActionMode");
if (type == MODE_SHARE) {
listAdapter.insert(SHARE_LOCATION_FILE, 0);
}
switchSelectionMode(true);
int titleRes = type == MODE_DELETE ? R.string.shared_string_delete_all : R.string.shared_string_share;
int iconRes = type == MODE_DELETE ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_gshare_dark;
MenuItem item = menu.add(titleRes).setIcon(iconRes);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (type == MODE_DELETE) {
deleteItems(selected);
} else if (type == MODE_SHARE) {
shareItems(selected);
}
mode.finish();
return true;
}
});
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
selected.clear();
updateSelectionMode(mode);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
LOG.debug("onPrepareActionMode");
return false;
}
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
LOG.debug("onActionItemClicked");
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
LOG.debug("onDestroyActionMode");
if (type == MODE_SHARE) {
listAdapter.remove(SHARE_LOCATION_FILE);
}
switchSelectionMode(false);
listAdapter.notifyDataSetInvalidated();
}
});
}
Aggregations