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();
}
}
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);
}
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());
}
}
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);
}
}
Aggregations