Search in sources :

Example 71 with Pair

use of org.apache.commons.math3.util.Pair in project SharedPreferenceInspector by PrashamTrivedi.

the class SharedPreferencesItem method onItemClick.

/**
 * Callback method to be invoked when an item in this AdapterView has been clicked.
 * <p/>
 * Implementers can call getItemAtPosition(position) if they need to access the data associated with the selected item.
 *
 * @param parent
 * 		The AdapterView where the click happened.
 * @param view
 * 		The view within the AdapterView that was clicked (this will be a view provided by the adapter)
 * @param position
 * 		The position of the view in the adapter.
 * @param id
 * 		The row id of the item that was clicked.
 */
@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
    String cancel = "Cancel";
    /**
     * Checks if entered in test mode. If not, clicking on preferences will prompt user to enter test mode first. If already entered in
     * test mode,
     * it will present the UI to change the value. Once it's changed, it will store original value
     */
    if (preferenceUtils.getBoolean(testModeOpened, false)) {
        final Pair<String, Object> keyValue = (Pair<String, Object>) parent.getItemAtPosition(position);
        Object second = keyValue.second;
        final String valueType = second.getClass().getSimpleName();
        AlertDialog.Builder builder = new Builder(getActivity());
        View editView = LayoutInflater.from(getActivity()).inflate(R.layout.edit_mode, null);
        final EditText et_value = (EditText) editView.findViewById(R.id.value);
        final SwitchCompat booleanSwitch = (SwitchCompat) editView.findViewById(R.id.switchBoolean);
        Spinner type = (Spinner) editView.findViewById(R.id.type);
        final String value = second.toString();
        et_value.setText(value);
        OnItemSelectedListener listener = new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (typePosition != position) {
                    et_value.setText("");
                    typePosition = position;
                }
                booleanSwitch.setVisibility(View.GONE);
                et_value.setVisibility(View.VISIBLE);
                if (typePosition == SharedPreferenceUtils.SPINNER_STRING) {
                    et_value.setInputType(InputType.TYPE_CLASS_TEXT);
                } else if (typePosition == SharedPreferenceUtils.SPINNER_INT || typePosition == SharedPreferenceUtils.SPINNER_LONG) {
                    et_value.setInputType(InputType.TYPE_CLASS_NUMBER);
                } else if (typePosition == SharedPreferenceUtils.SPINNER_FLOAT) {
                    et_value.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
                } else if (typePosition == SharedPreferenceUtils.SPINNER_BOOLEAN) {
                    et_value.setVisibility(View.GONE);
                    booleanSwitch.setVisibility(View.VISIBLE);
                    boolean isPreferenceTrue = !ConstantMethods.isEmptyString(value) && value.equalsIgnoreCase("true");
                    booleanSwitch.setText(isPreferenceTrue ? "true" : "false");
                    booleanSwitch.setChecked(isPreferenceTrue);
                    booleanSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            buttonView.setText(isChecked ? "true" : "false");
                        }
                    });
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                typePosition = 0;
            }
        };
        type.setOnItemSelectedListener(listener);
        OnClickListener listener2 = new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
            // TODO: Hell nothing right now.
            }
        };
        OnClickListener clearListener = new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                storeOriginal(keyValue);
                preferenceUtils.clear(keyValue.first);
                refreshKeyValues();
            }
        };
        if (valueType.equalsIgnoreCase(SharedPreferenceUtils.INT)) {
            typePosition = SharedPreferenceUtils.SPINNER_INT;
            type.setSelection(SharedPreferenceUtils.SPINNER_INT);
        } else if (valueType.equalsIgnoreCase(SharedPreferenceUtils.LONG)) {
            typePosition = SharedPreferenceUtils.SPINNER_LONG;
            type.setSelection(SharedPreferenceUtils.SPINNER_LONG);
        } else if (valueType.equalsIgnoreCase(SharedPreferenceUtils.FLOAT)) {
            typePosition = SharedPreferenceUtils.SPINNER_FLOAT;
            type.setSelection(SharedPreferenceUtils.SPINNER_FLOAT);
        } else if (valueType.equalsIgnoreCase(SharedPreferenceUtils.BOOLEAN)) {
            typePosition = SharedPreferenceUtils.SPINNER_BOOLEAN;
            type.setSelection(SharedPreferenceUtils.SPINNER_BOOLEAN);
        } else if (valueType.equalsIgnoreCase(SharedPreferenceUtils.STRING)) {
            typePosition = SharedPreferenceUtils.SPINNER_STRING;
            type.setSelection(SharedPreferenceUtils.SPINNER_STRING);
        }
        final AlertDialog dialog = builder.setTitle("Change Value").setView(editView).setPositiveButton("Set", null).setNegativeButton(cancel, listener2).setNeutralButton("Clear", clearListener).create();
        dialog.setOnShowListener(new DialogInterface.OnShowListener() {

            @Override
            public void onShow(DialogInterface dialog1) {
                Button b = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
                b.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        storeOriginal(keyValue);
                        Editable text = et_value.getText();
                        switch(typePosition) {
                            case SharedPreferenceUtils.SPINNER_STRING:
                                preferenceUtils.putString(keyValue.first, String.valueOf(text));
                                dialog.dismiss();
                                break;
                            case SharedPreferenceUtils.SPINNER_INT:
                                int number = SharedPreferenceUtils.getNumber(text);
                                preferenceUtils.putInt(keyValue.first, number);
                                dialog.dismiss();
                                break;
                            case SharedPreferenceUtils.SPINNER_LONG:
                                long numberLong = SharedPreferenceUtils.getNumberLong(text);
                                preferenceUtils.putLong(keyValue.first, numberLong);
                                dialog.dismiss();
                                break;
                            case SharedPreferenceUtils.SPINNER_BOOLEAN:
                                boolean value = booleanSwitch.isChecked();
                                preferenceUtils.putBoolean(keyValue.first, value);
                                dialog.dismiss();
                                break;
                            case SharedPreferenceUtils.SPINNER_FLOAT:
                                float numberFloat = SharedPreferenceUtils.getNumberFloat(text);
                                preferenceUtils.putFloat(keyValue.first, numberFloat);
                                dialog.dismiss();
                                break;
                        }
                        refreshKeyValues();
                    }
                });
            }
        });
        dialog.show();
    } else {
        AlertDialog.Builder builder = new Builder(getActivity());
        builder.setTitle("Test mode not enabled").setMessage("If you want to edit value for testing, testing mode should be enabled. It's available in options menu").setPositiveButton("Enable test mode", new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                getActivity().supportInvalidateOptionsMenu();
                changeTestMode();
                onItemClick(parent, view, position, id);
            }
        }).setNegativeButton(cancel, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                dialog.cancel();
            }
        }).show();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) Builder(android.support.v7.app.AlertDialog.Builder) Builder(android.support.v7.app.AlertDialog.Builder) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) Editable(android.text.Editable) Pair(android.support.v4.util.Pair) EditText(android.widget.EditText) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) SearchView(android.support.v7.widget.SearchView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) OnClickListener(android.content.DialogInterface.OnClickListener) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 72 with Pair

use of org.apache.commons.math3.util.Pair in project Shuttle by timusus.

the class BaseDetailFragment method pushDetailController.

void pushDetailController(BaseDetailFragment detailFragment, String tag, View transitionView) {
    List<Pair<View, String>> transitions = new ArrayList<>();
    String transitionName = ViewCompat.getTransitionName(transitionView);
    transitions.add(new Pair<>(transitionView, transitionName));
    transitions.add(new Pair<>(toolbar, "toolbar"));
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        Transition moveTransition = TransitionInflater.from(getContext()).inflateTransition(R.transition.image_transition);
        detailFragment.setSharedElementEnterTransition(moveTransition);
        detailFragment.setSharedElementReturnTransition(moveTransition);
    }
    getNavigationController().pushViewController(detailFragment, tag, transitions);
}
Also used : ArrayList(java.util.ArrayList) Transition(android.transition.Transition) Pair(android.support.v4.util.Pair)

Example 73 with Pair

use of org.apache.commons.math3.util.Pair in project Shuttle by timusus.

the class AestheticCoordinatorLayout method onAttachedToWindow.

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();
    // Find the toolbar and color view used to blend the scroll transition
    if (getChildCount() > 0 && getChildAt(0) instanceof AppBarLayout) {
        appBarLayout = (AppBarLayout) getChildAt(0);
        if (appBarLayout.getChildCount() > 0 && appBarLayout.getChildAt(0) instanceof CollapsingToolbarLayout) {
            collapsingToolbarLayout = (CollapsingToolbarLayout) appBarLayout.getChildAt(0);
            for (int i = 0; i < collapsingToolbarLayout.getChildCount(); i++) {
                if (this.toolbar != null && this.colorView != null) {
                    break;
                }
                View child = collapsingToolbarLayout.getChildAt(i);
                if (child instanceof AestheticToolbar) {
                    this.toolbar = (AestheticToolbar) child;
                } else if (child.getBackground() != null && child.getBackground() instanceof ColorDrawable) {
                    this.colorView = child;
                }
            }
        }
    }
    if (toolbar != null && colorView != null) {
        this.appBarLayout.addOnOffsetChangedListener(this);
        toolbarColorSubscription = Observable.combineLatest(toolbar.colorUpdated(), Aesthetic.get(getContext()).colorIconTitle(toolbar.colorUpdated()), new BiFunction<Integer, ActiveInactiveColors, Pair<Integer, ActiveInactiveColors>>() {

            @Override
            public Pair<Integer, ActiveInactiveColors> apply(Integer integer, ActiveInactiveColors activeInactiveColors) {
                return Pair.create(integer, activeInactiveColors);
            }
        }).compose(Rx.<Pair<Integer, ActiveInactiveColors>>distinctToMainThread()).subscribe(new Consumer<Pair<Integer, ActiveInactiveColors>>() {

            @Override
            public void accept(@NonNull Pair<Integer, ActiveInactiveColors> result) {
                toolbarColor = result.first;
                iconTextColors = result.second;
                invalidateColors();
            }
        }, onErrorLogAndRethrow());
    }
    if (collapsingToolbarLayout != null) {
        statusBarColorSubscription = Aesthetic.get(getContext()).colorStatusBar().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {

            @Override
            public void accept(@io.reactivex.annotations.NonNull Integer color) {
                collapsingToolbarLayout.setContentScrimColor(color);
                collapsingToolbarLayout.setStatusBarScrimColor(color);
            }
        }, onErrorLogAndRethrow());
    }
}
Also used : ActionMenuView(android.support.v7.widget.ActionMenuView) ActionMenuItemView(android.support.v7.view.menu.ActionMenuItemView) View(android.view.View) ColorDrawable(android.graphics.drawable.ColorDrawable) Consumer(io.reactivex.functions.Consumer) BiFunction(io.reactivex.functions.BiFunction) NonNull(android.support.annotation.NonNull) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) AppBarLayout(android.support.design.widget.AppBarLayout) Pair(android.support.v4.util.Pair)

Example 74 with Pair

use of org.apache.commons.math3.util.Pair in project knime-core by knime.

the class WorkflowCoachView method updateFrequencyColumnHeadersAndToolTips.

/**
 * Updates the names and tooltips of the frequency column headers.
 */
private void updateFrequencyColumnHeadersAndToolTips() {
    m_namesAndToolTips = NodeRecommendationManager.getInstance().getNodeTripleProviders().stream().filter(p -> p.isEnabled()).map(p -> new Pair<>(p.getName(), p.getDescription())).collect(Collectors.toList());
    if (m_namesAndToolTips == null || m_namesAndToolTips.isEmpty()) {
        updateInputNoProvider();
        return;
    }
    // reset table sorter
    IElementComparer sorter = m_viewer.getComparer();
    if (sorter != null && sorter instanceof TableColumnSorter) {
        ((TableColumnSorter) sorter).setColumn(null);
    }
    // enforce to change the viewer state to update the headers
    m_viewerState = null;
    m_lastSelection = "";
    changeViewerStateTo(ViewerState.RECOMMENDATIONS);
    // get current selection from the workbench and update the recommendation list
    IEditorPart activeEditor = getViewSite().getPage().getActiveEditor();
    if (activeEditor == null) {
        // if no workflow is opened
        updateInput(NO_WORKFLOW_OPENED_MESSAGE);
    } else {
        IWorkbenchPartSite site = activeEditor.getSite();
        if (site != null) {
            ISelectionProvider selectionProvider = site.getSelectionProvider();
            if (selectionProvider != null) {
                ISelection selection = selectionProvider.getSelection();
                if (selection != null && selection instanceof IStructuredSelection) {
                    updateInput(selection);
                    return;
                }
            }
        }
        updateInput(StructuredSelection.EMPTY);
    }
}
Also used : Arrays(java.util.Arrays) IUpdateListener(org.knime.workbench.workflowcoach.NodeRecommendationManager.IUpdateListener) TableViewer(org.eclipse.jface.viewers.TableViewer) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) DND(org.eclipse.swt.dnd.DND) TableColumn(org.eclipse.swt.widgets.TableColumn) IToolBarManager(org.eclipse.jface.action.IToolBarManager) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) NodeContainer(org.knime.core.node.workflow.NodeContainer) IStatus(org.eclipse.core.runtime.IStatus) ISelectionListener(org.eclipse.ui.ISelectionListener) Composite(org.eclipse.swt.widgets.Composite) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) Cursor(org.eclipse.swt.graphics.Cursor) IEditorPart(org.eclipse.ui.IEditorPart) NodeProvider(org.knime.workbench.core.nodeprovider.NodeProvider) KNIMEJob(org.knime.core.util.KNIMEJob) CommunityTripleProvider(org.knime.workbench.workflowcoach.data.CommunityTripleProvider) PlatformUI(org.eclipse.ui.PlatformUI) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) Display(org.eclipse.swt.widgets.Display) ScopedPreferenceStore(org.eclipse.ui.preferences.ScopedPreferenceStore) NodeModel(org.knime.core.node.NodeModel) Collectors(java.util.stream.Collectors) WorkflowCoachPreferenceInitializer(org.knime.workbench.workflowcoach.prefs.WorkflowCoachPreferenceInitializer) RepositoryManager(org.knime.workbench.repository.RepositoryManager) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Transfer(org.eclipse.swt.dnd.Transfer) IElementComparer(org.eclipse.jface.viewers.IElementComparer) MouseEvent(org.eclipse.swt.events.MouseEvent) List(java.util.List) MouseListener(org.eclipse.swt.events.MouseListener) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) Wrapper(org.knime.core.ui.wrapper.Wrapper) SWT(org.eclipse.swt.SWT) Optional(java.util.Optional) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) MouseAdapter(org.eclipse.swt.events.MouseAdapter) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) ViewPart(org.eclipse.ui.part.ViewPart) WorkflowEditor(org.knime.workbench.editor2.WorkflowEditor) LocalDateTime(java.time.LocalDateTime) Table(org.eclipse.swt.widgets.Table) AtomicReference(java.util.concurrent.atomic.AtomicReference) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) Pair(org.knime.core.util.Pair) HashSet(java.util.HashSet) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) UpdateJob(org.knime.workbench.workflowcoach.prefs.UpdateJob) UpdatableNodeTripleProvider(org.knime.workbench.workflowcoach.data.UpdatableNodeTripleProvider) NodeLogger(org.knime.core.node.NodeLogger) GridData(org.eclipse.swt.layout.GridData) NodeRecommendationManager(org.knime.workbench.workflowcoach.NodeRecommendationManager) HeadlessPreferencesConstants(org.knime.workbench.core.preferences.HeadlessPreferencesConstants) NodeFactory(org.knime.core.node.NodeFactory) CombinatoricsUtils(org.apache.commons.math3.util.CombinatoricsUtils) Iterator(java.util.Iterator) Job(org.eclipse.core.runtime.jobs.Job) KNIMECorePlugin(org.knime.workbench.core.KNIMECorePlugin) NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) ChronoUnit(java.time.temporal.ChronoUnit) UpdateListener(org.knime.workbench.workflowcoach.prefs.UpdateJob.UpdateListener) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) NodeRecommendation(org.knime.workbench.workflowcoach.NodeRecommendationManager.NodeRecommendation) Comparator(java.util.Comparator) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) IElementComparer(org.eclipse.jface.viewers.IElementComparer) ISelection(org.eclipse.jface.viewers.ISelection) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

Pair (android.support.v4.util.Pair)38 ArrayList (java.util.ArrayList)22 View (android.view.View)16 Collectors (java.util.stream.Collectors)16 IntStream (java.util.stream.IntStream)16 ActivityOptionsCompat (android.support.v4.app.ActivityOptionsCompat)13 Logger (org.apache.logging.log4j.Logger)12 ParamUtils (org.broadinstitute.hellbender.utils.param.ParamUtils)12 Intent (android.content.Intent)11 Pair (org.apache.commons.math3.util.Pair)11 IOException (java.io.IOException)10 java.util (java.util)10 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)10 Pair (org.apache.commons.lang3.tuple.Pair)10 RealMatrix (org.apache.commons.math3.linear.RealMatrix)10 File (java.io.File)9 List (java.util.List)9 Array2DRowRealMatrix (org.apache.commons.math3.linear.Array2DRowRealMatrix)8 UserException (org.broadinstitute.hellbender.exceptions.UserException)8 org.broadinstitute.hellbender.tools.exome (org.broadinstitute.hellbender.tools.exome)8