use of android.widget.ToggleButton in project WordPress-Android by wordpress-mobile.
the class EditorFragmentTest method testFormatBarToggledOnSelectedFieldChanged.
public void testFormatBarToggledOnSelectedFieldChanged() {
Map<String, String> selectionArgs = new HashMap<>();
selectionArgs.put("id", "zss_field_title");
mFragment.onSelectionChanged(selectionArgs);
waitFor(100);
View view = mFragment.getView();
if (view == null) {
throw (new IllegalStateException("Fragment view is empty"));
}
// The formatting buttons should be disabled while the title field is selected
ToggleButton mediaButton = (ToggleButton) view.findViewById(R.id.format_bar_button_media);
ToggleButton boldButton = (ToggleButton) view.findViewById(R.id.format_bar_button_bold);
ToggleButton italicButton = (ToggleButton) view.findViewById(R.id.format_bar_button_italic);
ToggleButton quoteButton = (ToggleButton) view.findViewById(R.id.format_bar_button_quote);
ToggleButton ulButton = (ToggleButton) view.findViewById(R.id.format_bar_button_ul);
ToggleButton olButton = (ToggleButton) view.findViewById(R.id.format_bar_button_ol);
ToggleButton linkButton = (ToggleButton) view.findViewById(R.id.format_bar_button_link);
ToggleButton strikethroughButton = (ToggleButton) view.findViewById(R.id.format_bar_button_strikethrough);
assertFalse(mediaButton.isEnabled());
assertFalse(boldButton.isEnabled());
assertFalse(italicButton.isEnabled());
assertFalse(quoteButton.isEnabled());
assertFalse(ulButton.isEnabled());
assertFalse(olButton.isEnabled());
assertFalse(linkButton.isEnabled());
if (strikethroughButton != null) {
assertFalse(strikethroughButton.isEnabled());
}
// The HTML button should always be enabled
ToggleButton htmlButton = (ToggleButton) view.findViewById(R.id.format_bar_button_html);
assertTrue(htmlButton.isEnabled());
selectionArgs.clear();
selectionArgs.put("id", "zss_field_content");
mFragment.onSelectionChanged(selectionArgs);
waitFor(500);
// The formatting buttons should be enabled while the content field is selected
assertTrue(mediaButton.isEnabled());
assertTrue(boldButton.isEnabled());
assertTrue(italicButton.isEnabled());
assertTrue(quoteButton.isEnabled());
assertTrue(ulButton.isEnabled());
assertTrue(olButton.isEnabled());
assertTrue(linkButton.isEnabled());
if (strikethroughButton != null) {
assertTrue(strikethroughButton.isEnabled());
}
// The HTML button should always be enabled
assertTrue(htmlButton.isEnabled());
}
use of android.widget.ToggleButton in project WordPress-Android by wordpress-mobile.
the class EditorFragment method onClick.
@Override
public void onClick(View v) {
if (!isAdded()) {
return;
}
int id = v.getId();
if (id == R.id.format_bar_button_html) {
checkForFailedUploadAndSwitchToHtmlMode((ToggleButton) v);
} else if (id == R.id.format_bar_button_media) {
mEditorFragmentListener.onTrackableEvent(TrackableEvent.MEDIA_BUTTON_TAPPED);
((ToggleButton) v).setChecked(false);
if (isActionInProgress()) {
ToastUtils.showToast(getActivity(), R.string.alert_action_while_uploading, ToastUtils.Duration.LONG);
return;
}
if (mSourceView.getVisibility() == View.VISIBLE) {
ToastUtils.showToast(getActivity(), R.string.alert_insert_image_html_mode, ToastUtils.Duration.LONG);
} else {
mEditorFragmentListener.onAddMediaClicked();
getActivity().openContextMenu(mTagToggleButtonMap.get(TAG_FORMAT_BAR_BUTTON_MEDIA));
}
} else if (id == R.id.format_bar_button_link) {
if (!((ToggleButton) v).isChecked()) {
// The link button was checked when it was pressed; remove the current link
mWebView.execJavaScriptFromString("ZSSEditor.unlink();");
mEditorFragmentListener.onTrackableEvent(TrackableEvent.UNLINK_BUTTON_TAPPED);
return;
}
mEditorFragmentListener.onTrackableEvent(TrackableEvent.LINK_BUTTON_TAPPED);
((ToggleButton) v).setChecked(false);
displayLinkDialog();
} else {
if (v instanceof ToggleButton) {
onFormattingButtonClicked((ToggleButton) v);
}
}
}
use of android.widget.ToggleButton in project WordPress-Android by wordpress-mobile.
the class EditorFragment method onConfigurationChanged.
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (getView() != null) {
// Reload the format bar to make sure the correct one for the new screen width is being used
View formatBar = getView().findViewById(R.id.format_bar);
if (formatBar != null) {
// Remember the currently active format bar buttons so they can be re-activated after the reload
ArrayList<String> activeTags = new ArrayList<>();
for (Map.Entry<String, ToggleButton> entry : mTagToggleButtonMap.entrySet()) {
if (entry.getValue().isChecked()) {
activeTags.add(entry.getKey());
}
}
ViewGroup parent = (ViewGroup) formatBar.getParent();
parent.removeView(formatBar);
formatBar = getActivity().getLayoutInflater().inflate(R.layout.format_bar, parent, false);
formatBar.setId(R.id.format_bar);
parent.addView(formatBar);
setupFormatBarButtonMap(formatBar);
if (mIsFormatBarDisabled) {
updateFormatBarEnabledState(false);
}
// Restore the active format bar buttons
for (String tag : activeTags) {
mTagToggleButtonMap.get(tag).setChecked(true);
}
if (mSourceView.getVisibility() == View.VISIBLE) {
ToggleButton htmlButton = (ToggleButton) formatBar.findViewById(R.id.format_bar_button_html);
htmlButton.setChecked(true);
}
}
// Reload HTML mode margins
View sourceViewTitle = getView().findViewById(R.id.sourceview_title);
View sourceViewContent = getView().findViewById(R.id.sourceview_content);
if (sourceViewTitle != null && sourceViewContent != null) {
int sideMargin = (int) getActivity().getResources().getDimension(R.dimen.sourceview_side_margin);
ViewGroup.MarginLayoutParams titleParams = (ViewGroup.MarginLayoutParams) sourceViewTitle.getLayoutParams();
ViewGroup.MarginLayoutParams contentParams = (ViewGroup.MarginLayoutParams) sourceViewContent.getLayoutParams();
titleParams.setMargins(sideMargin, titleParams.topMargin, sideMargin, titleParams.bottomMargin);
contentParams.setMargins(sideMargin, contentParams.topMargin, sideMargin, contentParams.bottomMargin);
}
}
// Toggle action bar auto-hiding for the new orientation
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE && !getResources().getBoolean(R.bool.is_large_tablet_landscape)) {
mHideActionBarOnSoftKeyboardUp = true;
hideActionBarIfNeeded();
} else {
mHideActionBarOnSoftKeyboardUp = false;
showActionBarIfNeeded();
}
}
use of android.widget.ToggleButton in project ExpandTabView by yueyueniao2012.
the class ExpandTabView method setValue.
/**
* 设置tabitem的个数和初始值
*/
public void setValue(ArrayList<String> textArray, ArrayList<View> viewArray) {
if (mContext == null) {
return;
}
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mTextArray = textArray;
for (int i = 0; i < viewArray.size(); i++) {
final RelativeLayout r = new RelativeLayout(mContext);
int maxHeight = (int) (displayHeight * 0.7);
RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, maxHeight);
rl.leftMargin = 10;
rl.rightMargin = 10;
r.addView(viewArray.get(i), rl);
mViewArray.add(r);
r.setTag(SMALL);
ToggleButton tButton = (ToggleButton) inflater.inflate(R.layout.toggle_button, this, false);
addView(tButton);
View line = new TextView(mContext);
line.setBackgroundResource(R.drawable.choosebar_line);
if (i < viewArray.size() - 1) {
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(2, LinearLayout.LayoutParams.FILL_PARENT);
addView(line, lp);
}
mToggleButton.add(tButton);
tButton.setTag(i);
tButton.setText(mTextArray.get(i));
r.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onPressBack();
}
});
r.setBackgroundColor(mContext.getResources().getColor(R.color.popup_main_background));
tButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
// initPopupWindow();
ToggleButton tButton = (ToggleButton) view;
if (selectedButton != null && selectedButton != tButton) {
selectedButton.setChecked(false);
}
selectedButton = tButton;
selectPosition = (Integer) selectedButton.getTag();
startAnimation();
if (mOnButtonClickListener != null && tButton.isChecked()) {
mOnButtonClickListener.onClick(selectPosition);
}
}
});
}
}
use of android.widget.ToggleButton in project android_frameworks_base by AOSPA.
the class EnvReverbTest method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Log.d(TAG, "onCreate");
SeekBar seekBar;
TextView textView;
ToggleButton button;
setContentView(R.layout.envreverbtest);
ImageView playPause = (ImageView) findViewById(R.id.playPause1);
ImageView stop = (ImageView) findViewById(R.id.stop1);
textView = (TextView) findViewById(R.id.sessionText);
if (sPlayerController == null) {
sPlayerController = new SimplePlayer(this, R.id.playPause1, playPause, R.id.stop1, stop, textView, R.raw.mp3_sample, AudioManager.STREAM_MUSIC, 0);
} else {
sPlayerController.set(this, R.id.playPause1, playPause, R.id.stop1, stop, textView, AudioManager.STREAM_MUSIC, 0);
}
// send level
mSendLevelSeekBar = (SeekBar) findViewById(R.id.sendLevelSeekBar);
mSendLevelDisplay = (TextView) findViewById(R.id.sendLevelValue);
mSendLevelSeekBar.setMax(100);
mSendLevelSeekBar.setOnSeekBarChangeListener(this);
mSendLevelSeekBar.setProgress(expToLin(sSendLevel, 100));
sPlayerController.setAuxEffectSendLevel(sSendLevel);
mOnOffButton = (ToggleButton) findViewById(R.id.rvbOnOff);
mReleaseButton = (ToggleButton) findViewById(R.id.rvbReleaseButton);
mAttachButton = (ToggleButton) findViewById(R.id.attachButton);
getEffect(0);
if (mReverb != null) {
mOnOffButton.setOnCheckedChangeListener(this);
mReleaseButton.setOnCheckedChangeListener(this);
mAttachButton.setOnCheckedChangeListener(this);
// button = (ToggleButton)findViewById(R.id.rvbBypass);
// button.setChecked(false);
// button.setOnCheckedChangeListener(this);
// Room level
seekBar = (SeekBar) findViewById(R.id.rvbParam1SeekBar);
textView = (TextView) findViewById(R.id.rvbParam1Value);
mParameters[0] = new RoomLevelParam(mReverb, seekBar, textView);
seekBar.setOnSeekBarChangeListener(mParameters[0]);
// Room HF level
seekBar = (SeekBar) findViewById(R.id.rvbParam2SeekBar);
textView = (TextView) findViewById(R.id.rvbParam2Value);
mParameters[1] = new RoomHFLevelParam(mReverb, seekBar, textView);
seekBar.setOnSeekBarChangeListener(mParameters[1]);
// Decay time
seekBar = (SeekBar) findViewById(R.id.rvbParam3SeekBar);
textView = (TextView) findViewById(R.id.rvbParam3Value);
mParameters[2] = new DecayTimeParam(mReverb, seekBar, textView);
seekBar.setOnSeekBarChangeListener(mParameters[2]);
// Decay HF ratio
seekBar = (SeekBar) findViewById(R.id.rvbParam4SeekBar);
textView = (TextView) findViewById(R.id.rvbParam4Value);
mParameters[3] = new DecayHFRatioParam(mReverb, seekBar, textView);
seekBar.setOnSeekBarChangeListener(mParameters[3]);
// Reflections level
seekBar = (SeekBar) findViewById(R.id.rvbParam5SeekBar);
textView = (TextView) findViewById(R.id.rvbParam5Value);
mParameters[4] = new ReflectionsLevelParam(mReverb, seekBar, textView);
seekBar.setOnSeekBarChangeListener(mParameters[4]);
// Reflections delay
seekBar = (SeekBar) findViewById(R.id.rvbParam6SeekBar);
textView = (TextView) findViewById(R.id.rvbParam6Value);
mParameters[5] = new ReflectionsDelayParam(mReverb, seekBar, textView);
seekBar.setOnSeekBarChangeListener(mParameters[5]);
// Reverb level
seekBar = (SeekBar) findViewById(R.id.rvbParam7SeekBar);
textView = (TextView) findViewById(R.id.rvbParam7Value);
mParameters[6] = new ReverbLevelParam(mReverb, seekBar, textView);
seekBar.setOnSeekBarChangeListener(mParameters[6]);
// Reverb delay
seekBar = (SeekBar) findViewById(R.id.rvbParam8SeekBar);
textView = (TextView) findViewById(R.id.rvbParam8Value);
mParameters[7] = new ReverbDelayParam(mReverb, seekBar, textView);
seekBar.setOnSeekBarChangeListener(mParameters[7]);
// Diffusion
seekBar = (SeekBar) findViewById(R.id.rvbParam9SeekBar);
textView = (TextView) findViewById(R.id.rvbParam9Value);
mParameters[8] = new DiffusionParam(mReverb, seekBar, textView);
seekBar.setOnSeekBarChangeListener(mParameters[8]);
// Density
seekBar = (SeekBar) findViewById(R.id.rvbParam10SeekBar);
textView = (TextView) findViewById(R.id.rvbParam10Value);
mParameters[9] = new DensityParam(mReverb, seekBar, textView);
seekBar.setOnSeekBarChangeListener(mParameters[9]);
}
}
Aggregations