If you think the Android project pixel-art listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.jaween.pixelart.tools.options;
/*fromwww.java2s.com*/import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.SeekBar;
import com.jaween.pixelart.R;
import com.jaween.pixelart.tools.attributes.MagicWandToolAttributes;
import com.jaween.pixelart.tools.attributes.ToolAttributes;
publicclass MagicWandOptionsView extends ToolOptionsView implements
SeekBar.OnSeekBarChangeListener {
private EditText thresholdEditText;
private SeekBar thresholdSeekBar;
privateint initialThreshold;
public MagicWandOptionsView(Context context) {
super(context);
initialiseViews(context);
}
public MagicWandOptionsView(Context context, AttributeSet attrs) {
super(context, attrs);
initialiseViews(context);
}
public MagicWandOptionsView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initialiseViews(context);
}
privatevoid initialiseViews(Context context) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
viewGroup = (ViewGroup) inflater.inflate(R.layout.tool_options_magic_wand, null);
initialThreshold = context.getResources().getInteger(R.integer.tool_magic_wand_initial_threshold);
thresholdEditText = (EditText) viewGroup.findViewById(R.id.et_threshold);
thresholdEditText.setText(Integer.toString(initialThreshold));
addTextWatchers();
thresholdSeekBar = (SeekBar) viewGroup.findViewById(R.id.sb_threshold);
thresholdSeekBar.setProgress(initialThreshold);
thresholdSeekBar.setOnSeekBarChangeListener(this);
addView(viewGroup);
}
@Override
publicvoid onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
switch (seekBar.getId()) {
// Must offset the progress by 1 as seekbars begin at 0
case R.id.sb_threshold:
((MagicWandToolAttributes) toolAttributes).setThreshold(progress + 1);
break;
}
}
@Override
publicvoid onStartTrackingTouch(SeekBar seekBar) {
// No implementation
}
@Override
publicvoid onStopTrackingTouch(SeekBar seekBar) {
switch (seekBar.getId()) {
case R.id.sb_threshold:
thresholdEditText.setText(Integer.valueOf(seekBar.getProgress()).toString());
break;
}
}
privatevoid addTextWatchers() {
thresholdEditText.addTextChangedListener(new TextWatcher() {
@Override
publicvoid beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
// No implementation
}
@Override
publicvoid onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
if (charSequence.toString().isEmpty()) {
thresholdEditText.setText("0");
} else {
thresholdSeekBar.setProgress(Integer.parseInt(charSequence.toString()));
}
}
@Override
publicvoid afterTextChanged(Editable editable) {
// No implementation
}
});
}
@Override
publicvoid setToolAttributes(ToolAttributes toolToolAttributes) {
super.setToolAttributes(toolToolAttributes);
((MagicWandToolAttributes) toolToolAttributes).setThreshold(initialThreshold);
}
}