Search in sources :

Example 1 with NewAction

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());
}
Also used : NewAction(net.osmand.plus.quickaction.actions.NewAction)

Example 2 with NewAction

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;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) FragmentActivity(androidx.fragment.app.FragmentActivity) Activity(android.app.Activity) ImageView(android.widget.ImageView) R.id.imageView(net.osmand.plus.R.id.imageView) View(android.view.View) TextView(android.widget.TextView) FragmentManager(androidx.fragment.app.FragmentManager) FragmentActivity(androidx.fragment.app.FragmentActivity) GridLayout(androidx.gridlayout.widget.GridLayout) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) NewAction(net.osmand.plus.quickaction.actions.NewAction)

Example 3 with NewAction

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());
}
Also used : NewAction(net.osmand.plus.quickaction.actions.NewAction)

Example 4 with NewAction

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;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) FragmentActivity(androidx.fragment.app.FragmentActivity) Activity(android.app.Activity) ImageView(android.widget.ImageView) R.id.imageView(net.osmand.plus.R.id.imageView) View(android.view.View) TextView(android.widget.TextView) FragmentManager(androidx.fragment.app.FragmentManager) FragmentActivity(androidx.fragment.app.FragmentActivity) GridLayout(androidx.gridlayout.widget.GridLayout) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) NewAction(net.osmand.plus.quickaction.actions.NewAction)

Aggregations

NewAction (net.osmand.plus.quickaction.actions.NewAction)4 Activity (android.app.Activity)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 FragmentManager (androidx.fragment.app.FragmentManager)2 GridLayout (androidx.gridlayout.widget.GridLayout)2 OsmandApplication (net.osmand.plus.OsmandApplication)2 R.id.imageView (net.osmand.plus.R.id.imageView)2