use of net.osmand.plus.quickaction.actions.NewAction in project Osmand by osmandapp.
the class QuickActionsWidget method setActions.
public void setActions(List<QuickAction> actions) {
this.actions = actions;
this.actions.add(new NewAction());
removeAllViews();
setupLayout(getContext(), countPage());
}
use of net.osmand.plus.quickaction.actions.NewAction in project Osmand by osmandapp.
the class QuickActionsWidget method createPageView.
private View createPageView(ViewGroup container, int position) {
OsmandApplication application = ((OsmandApplication) getContext().getApplicationContext());
boolean light = application.getSettings().isLightContent() && !application.getDaynightHelper().isNightMode();
LayoutInflater li = getLayoutInflater(light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
View page = li.inflate(R.layout.quick_action_widget_page, container, false);
GridLayout gridLayout = (GridLayout) page.findViewById(R.id.grid);
final boolean land = !AndroidUiHelper.isOrientationPortrait((Activity) getContext());
final int maxItems = actions.size() == 1 ? 1 : ELEMENT_PER_PAGE;
for (int i = 0; i < maxItems; i++) {
View view = li.inflate(R.layout.quick_action_widget_item, gridLayout, false);
if (i + (position * ELEMENT_PER_PAGE) < actions.size()) {
final QuickAction action = QuickActionRegistry.produceAction(actions.get(i + (position * ELEMENT_PER_PAGE)));
((ImageView) view.findViewById(imageView)).setImageResource(action.getIconRes(getContext()));
((TextView) view.findViewById(R.id.title)).setText(action.getActionText(application));
if (action.isActionWithSlash(application)) {
((ImageView) view.findViewById(R.id.imageSlash)).setImageResource(light ? R.drawable.ic_action_icon_hide_white : R.drawable.ic_action_icon_hide_dark);
}
view.setOnClickListener(v -> {
if (selectionListener != null) {
selectionListener.onActionSelected(action);
}
});
// if (action.isActionEditable()) {
view.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
FragmentActivity activity = (AppCompatActivity) getContext();
FragmentManager fragmentManager = activity.getSupportFragmentManager();
if (action instanceof NewAction) {
QuickActionListFragment.showInstance(activity);
} else {
CreateEditActionDialog.showInstance(fragmentManager, action);
}
return true;
}
});
// }
if (!action.isActionEnable(application)) {
view.setEnabled(false);
view.setAlpha(0.5f);
}
}
if (land) {
view.findViewById(R.id.dividerBot).setVisibility(GONE);
view.findViewById(R.id.dividerRight).setVisibility(VISIBLE);
} else {
view.findViewById(R.id.dividerBot).setVisibility(i < ELEMENT_PER_PAGE / 2 ? VISIBLE : GONE);
view.findViewById(R.id.dividerRight).setVisibility(((i + 1) % 3) == 0 ? GONE : VISIBLE);
}
gridLayout.addView(view);
}
return gridLayout;
}
use of net.osmand.plus.quickaction.actions.NewAction in project OsmAnd by osmandapp.
the class QuickActionsWidget method setActions.
public void setActions(List<QuickAction> actions) {
this.actions = actions;
this.actions.add(new NewAction());
removeAllViews();
setupLayout(getContext(), countPage());
}
use of net.osmand.plus.quickaction.actions.NewAction in project OsmAnd by osmandapp.
the class QuickActionsWidget method createPageView.
private View createPageView(ViewGroup container, int position) {
OsmandApplication application = ((OsmandApplication) getContext().getApplicationContext());
boolean light = application.getSettings().isLightContent() && !application.getDaynightHelper().isNightMode();
LayoutInflater li = getLayoutInflater(light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
View page = li.inflate(R.layout.quick_action_widget_page, container, false);
GridLayout gridLayout = (GridLayout) page.findViewById(R.id.grid);
final boolean land = !AndroidUiHelper.isOrientationPortrait((Activity) getContext());
final int maxItems = actions.size() == 1 ? 1 : ELEMENT_PER_PAGE;
for (int i = 0; i < maxItems; i++) {
View view = li.inflate(R.layout.quick_action_widget_item, gridLayout, false);
if (i + (position * ELEMENT_PER_PAGE) < actions.size()) {
final QuickAction action = QuickActionRegistry.produceAction(actions.get(i + (position * ELEMENT_PER_PAGE)));
((ImageView) view.findViewById(imageView)).setImageResource(action.getIconRes(getContext()));
((TextView) view.findViewById(R.id.title)).setText(action.getActionText(application));
if (action.isActionWithSlash(application)) {
((ImageView) view.findViewById(R.id.imageSlash)).setImageResource(light ? R.drawable.ic_action_icon_hide_white : R.drawable.ic_action_icon_hide_dark);
}
view.setOnClickListener(v -> {
if (selectionListener != null) {
selectionListener.onActionSelected(action);
}
});
// if (action.isActionEditable()) {
view.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
FragmentActivity activity = (AppCompatActivity) getContext();
FragmentManager fragmentManager = activity.getSupportFragmentManager();
if (action instanceof NewAction) {
QuickActionListFragment.showInstance(activity);
} else {
CreateEditActionDialog.showInstance(fragmentManager, action);
}
return true;
}
});
// }
if (!action.isActionEnable(application)) {
view.setEnabled(false);
view.setAlpha(0.5f);
}
}
if (land) {
view.findViewById(R.id.dividerBot).setVisibility(GONE);
view.findViewById(R.id.dividerRight).setVisibility(VISIBLE);
} else {
view.findViewById(R.id.dividerBot).setVisibility(i < ELEMENT_PER_PAGE / 2 ? VISIBLE : GONE);
view.findViewById(R.id.dividerRight).setVisibility(((i + 1) % 3) == 0 ? GONE : VISIBLE);
}
gridLayout.addView(view);
}
return gridLayout;
}
Aggregations