下面列出了android.widget.ImageButton# setEnabled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_save, container, false);
view.findViewById(R.id.background).setBackgroundColor(SettingsActivity.getPrimaryColor(getActivity()));
mCancel = (ImageButton) view.findViewById(android.R.id.button2);
mCancel.setOnClickListener(this);
mDisplayName = (EditText) view.findViewById(android.R.id.title);
mDisplayName.addTextChangedListener(mDisplayNameWatcher);
mDisplayName.setText(getArguments().getString(EXTRA_DISPLAY_NAME));
mSave = (ImageButton) view.findViewById(android.R.id.button1);
mSave.setOnClickListener(this);
mSave.setEnabled(false);
mProgress = (ProgressBar) view.findViewById(android.R.id.progress);
return view;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_paint);
mPaintView = (PaintView)findViewById(R.id.view_paint);
mPaintView.setColorFromRes(R.color.paint_color_red);
mPaintView.setTextColorFromRes(R.color.paint_color_red);
mPaintView.setBgColor(Color.WHITE);
mPaintView.setStrokeWidth(WIDTH_WRITE);
mPaintView.setOnDrawListener(this);
Uri uri = getIntent().getParcelableExtra(BITMAP_URI);
Bitmap bitmap = ImageUtil.getBitmapByUri(this, uri);
if (bitmap != null) {
mPaintView.setBitmap(bitmap);
}
mBtnColor = (ImageButton)findViewById(R.id.btn_color);
mBtnColor.setOnClickListener(this);
mBtnStroke = (ImageButton)findViewById(R.id.btn_stroke);
mBtnStroke.setOnClickListener(this);
mBtnUndo = (ImageButton)findViewById(R.id.btn_undo);
mBtnUndo.setEnabled(false);
mBtnUndo.setOnClickListener(this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
shouldShowLatencyChart = getBooleanPreference(getContext(), R.string.preference_show_tap_histogram, true);
if (getBooleanPreference(getContext(), R.string.preference_systrace, true)) {
traceLogger = TraceLogger.getInstance();
}
waltDevice = WaltDevice.getInstance(getContext());
logger = SimpleLogger.getInstance(getContext());
// Inflate the layout for this fragment
final View view = inflater.inflate(R.layout.fragment_tap_latency, container, false);
restartButton = (ImageButton) view.findViewById(R.id.button_restart_tap);
finishButton = (ImageButton) view.findViewById(R.id.button_finish_tap);
tapCatcherView = (TextView) view.findViewById(R.id.tap_catcher);
logTextView = (TextView) view.findViewById(R.id.txt_log_tap_latency);
tapCountsView = (TextView) view.findViewById(R.id.txt_tap_counts);
moveCountsView = (TextView) view.findViewById(R.id.txt_move_count);
latencyChart = (HistogramChart) view.findViewById(R.id.latency_chart);
logTextView.setMovementMethod(new ScrollingMovementMethod());
finishButton.setEnabled(false);
return view;
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
LinearLayout widgetFrameView = ((LinearLayout) view.findViewById(android.R.id.widget_frame));
mBtnAppIcon = new ImageButton(mContext);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(mAppIconPreviewSizePx, mAppIconPreviewSizePx);
lp.gravity = Gravity.CENTER;
mBtnAppIcon.setLayoutParams(lp);
mBtnAppIcon.setScaleType(ScaleType.CENTER_CROP);
mBtnAppIcon.setImageDrawable(mAppInfo.icon);
mBtnAppIcon.setFocusable(false);
if (mIconPickerEnabled) {
mBtnAppIcon.setOnClickListener(this);
mBtnAppIcon.setOnLongClickListener(this);
} else {
mBtnAppIcon.setEnabled(false);
}
widgetFrameView.addView(mBtnAppIcon);
widgetFrameView.setVisibility(View.VISIBLE);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_save, container, false);
view.findViewById(R.id.background).setBackgroundColor(SettingsActivity.getPrimaryColor(getActivity()));
mCancel = (ImageButton) view.findViewById(android.R.id.button2);
mCancel.setOnClickListener(this);
mDisplayName = (EditText) view.findViewById(android.R.id.title);
mDisplayName.addTextChangedListener(mDisplayNameWatcher);
mDisplayName.setText(getArguments().getString(EXTRA_DISPLAY_NAME));
mSave = (ImageButton) view.findViewById(android.R.id.button1);
mSave.setOnClickListener(this);
mSave.setEnabled(false);
mProgress = (ProgressBar) view.findViewById(android.R.id.progress);
return view;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//final Context context = inflater.getContext();
final View view = inflater.inflate(R.layout.fragment_move, container, false);
view.findViewById(R.id.background).setBackgroundColor(SettingsActivity.getPrimaryColor(getActivity()));
mCancel = (ImageButton) view.findViewById(android.R.id.button2);
mCancel.setOnClickListener(this);
mMoveInfo = (TextView) view.findViewById(android.R.id.title);
mMoveInfo.setText("Paste " + FileUtils.formatFileCount(docs.size()) + " in ");
mMoveInfo.setEnabled(false);
mRootInfo = (TextView) view.findViewById(android.R.id.text1);
mSave = (ImageButton) view.findViewById(android.R.id.button1);
mSave.setOnClickListener(this);
mSave.setEnabled(false);
mProgress = (MaterialProgressBar) view.findViewById(android.R.id.progress);
mProgress.setColor(SettingsActivity.getAccentColor());
return view;
}
/** Enables the {@code button} and removes the grey-out effect. */
private static void enableImageButton(@Nullable ImageButton button) {
if (button == null) {
return;
}
button.setEnabled(true);
// Set focusable to true to receive focus.
button.setFocusable(true);
// Remove grey out effect.
button.setImageAlpha(0xFF);
}
/**
* Builds an {@link ImageButton} from the data in this params. Generated buttons should be
* placed on the bottom bar. The button's tag will be its id.
* @param parent The parent that the inflated {@link ImageButton}.
* @param listener {@link OnClickListener} that should be used with the button.
* @return Parsed list of {@link CustomButtonParams}, which is empty if the input is invalid.
*/
ImageButton buildBottomBarButton(Context context, ViewGroup parent, OnClickListener listener) {
if (mIsOnToolbar) return null;
ImageButton button = (ImageButton) LayoutInflater.from(context)
.inflate(R.layout.custom_tabs_bottombar_item, parent, false);
button.setId(mId);
button.setImageBitmap(mIcon);
button.setContentDescription(mDescription);
if (mPendingIntent == null) {
button.setEnabled(false);
} else {
button.setOnClickListener(listener);
}
button.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
final int screenWidth = view.getResources().getDisplayMetrics().widthPixels;
final int screenHeight = view.getResources().getDisplayMetrics().heightPixels;
final int[] screenPos = new int[2];
view.getLocationOnScreen(screenPos);
final int width = view.getWidth();
Toast toast = Toast.makeText(
view.getContext(), view.getContentDescription(), Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM | Gravity.END,
screenWidth - screenPos[0] - width / 2,
screenHeight - screenPos[1]);
toast.show();
return true;
}
});
return button;
}
private void toggleNavigationButtoms(boolean enabled) {
ImageButton deleteValue = ((CollectActivity) getContext()).getDeleteValue();
ImageView traitLeft = ((CollectActivity) getContext()).getTraitLeft();
ImageView traitRight = ((CollectActivity) getContext()).getTraitRight();
ImageView rangeLeft = ((CollectActivity) getContext()).getRangeLeft();
ImageView rangeRight = ((CollectActivity) getContext()).getRangeRight();
rangeLeft.setEnabled(enabled);
rangeRight.setEnabled(enabled);
traitLeft.setEnabled(enabled);
traitRight.setEnabled(enabled);
deleteValue.setEnabled(enabled);
}
public void setEnabled(boolean enabled) {
boolean z = true;
if (this.mPauseButton != null) {
this.mPauseButton.setEnabled(enabled);
}
if (this.mFfwdButton != null) {
this.mFfwdButton.setEnabled(enabled);
}
if (this.mRewButton != null) {
this.mRewButton.setEnabled(enabled);
}
if (this.mNextButton != null) {
ImageButton imageButton = this.mNextButton;
boolean z2 = enabled && this.mNextListener != null;
imageButton.setEnabled(z2);
}
if (this.mPrevButton != null) {
ImageButton imageButton2 = this.mPrevButton;
if (!enabled || this.mPrevListener == null) {
z = false;
}
imageButton2.setEnabled(z);
}
if (this.mProgress != null) {
this.mProgress.setEnabled(enabled);
}
disableUnsupportedButtons();
super.setEnabled(enabled);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStatusBar();
setContentView(R.layout.activity_clock);
Intent intent = getIntent();
clockTitle = intent.getStringExtra("clocktitle");
workLength = intent.getIntExtra("workLength",ClockApplication.DEFAULT_WORK_LENGTH);
shortBreak = intent.getIntExtra("shortBreak",ClockApplication.DEFAULT_SHORT_BREAK);
longBreak = intent.getIntExtra("longBreak",ClockApplication.DEFAULT_LONG_BREAK);
id = intent.getLongExtra("id",1);
mApplication = (ClockApplication)getApplication();
mBtnStart = (Button)findViewById(R.id.btn_start);
mBtnPause = (Button)findViewById(R.id.btn_pause);
mBtnResume = (Button)findViewById(R.id.btn_resume);
mBtnStop = (Button)findViewById(R.id.btn_stop);
mBtnSkip = (Button)findViewById(R.id.btn_skip);
mTextCountDown = (TextView)findViewById(R.id.text_count_down);
mTextTimeTile = (TextView)findViewById(R.id.text_time_title);
mProgressBar = (ClockProgressBar)findViewById(R.id.tick_progress_bar);
mRippleWrapper = (RippleWrapper)findViewById(R.id.ripple_wrapper);
focus_tint = (TextView)findViewById(R.id.focus_hint);
bt_music = (ImageButton) findViewById(R.id.bt_music);
clock_bg = (ImageView) findViewById(R.id.clock_bg);
if(isSoundOn()){
bt_music.setEnabled(true);
bt_music.setImageDrawable(getResources().getDrawable(R.drawable.ic_music));
} else {
bt_music.setEnabled(false);
bt_music.setImageDrawable(getResources().getDrawable(R.drawable.ic_music_off));
}
SPUtils.put(this,"music_id",R.raw.river);
Toasty.normal(this, "双击界面打开或关闭白噪音", Toast.LENGTH_SHORT).show();
initActions();
initBackgroundImage();
}
/**
* Inflates the view
*/
private void inflate() {
((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.ebm__menu, this, true);
mOverlay = findViewById(R.id.ebm__menu_overlay);
mMidContainer = findViewById(R.id.ebm__menu_middle_container);
mLeftContainer = findViewById(R.id.ebm__menu_left_container);
mRightContainer = findViewById(R.id.ebm__menu_right_container);
mMidText = (TextView) findViewById(R.id.ebm__menu_middle_text);
mLeftText = (TextView) findViewById(R.id.ebm__menu_left_text);
mRightText = (TextView) findViewById(R.id.ebm__menu_right_text);
mCloseBtn = (ImageButton) findViewById(R.id.ebm__menu_close_image);
mMidBtn = (ImageButton) findViewById(R.id.ebm__menu_middle_image);
mRightBtn = (ImageButton) findViewById(R.id.ebm__menu_right_image);
mLeftBtn = (ImageButton) findViewById(R.id.ebm__menu_left_image);
sWidth = ScreenHelper.getScreenWidth(getContext());
sHeight = ScreenHelper.getScreenHeight(getContext());
mMidBtn.setEnabled(false);
mRightBtn.setEnabled(false);
mLeftBtn.setEnabled(false);
mCloseBtn.setOnClickListener(this);
mMidBtn.setOnClickListener(this);
mRightBtn.setOnClickListener(this);
mLeftBtn.setOnClickListener(this);
mOverlay.setOnClickListener(this);
}
/** Disables the {@code button} and applies the grey-out effect. */
private static void disableImageButton(@Nullable ImageButton button) {
if (button == null) {
return;
}
button.setEnabled(false);
// Set focusable to false to prevent receiving focus.
button.setFocusable(false);
// Apply grey out effect.
button.setImageAlpha(0x50);
}
/**
* Enables a button that has already been initialized.
*/
public void enableButton(int buttonId)
{
// If Camera Button is blocked, ignore the request.
if (buttonId == BUTTON_CAMERA && mIsCameraButtonBlocked)
{
return;
}
ImageButton button;
// Manual exposure uses a regular image button instead of a
// MultiToggleImageButton, so it requires special handling.
// TODO: Redesign ButtonManager's button getter methods into one method.
if (buttonId == BUTTON_EXPOSURE_COMPENSATION)
{
button = getImageButtonOrError(buttonId);
} else
{
button = getButtonOrError(buttonId);
}
if (!button.isEnabled())
{
button.setEnabled(true);
if (mListener != null)
{
mListener.onButtonEnabledChanged(this, buttonId);
}
}
button.setTag(R.string.tag_enabled_id, buttonId);
}
public void setDisable(){
mLeftButton = (ImageButton)view.findViewById(R.id.leftButton);
mRightButton = (ImageButton)view.findViewById(R.id.rightButton);
mSpeedButton = (ImageButton)view.findViewById(R.id.speedButton);
mSpeedLabel = (TextView)view.findViewById(R.id.speedLabel);
mPortLabel = (TextView)view.findViewById(R.id.textPort);
mLeftButton.setClickable(false);
mRightButton.setClickable(false);
mLeftButton.setEnabled(false);
mRightButton.setEnabled(false);
mSpeedButton.setClickable(false);
mSpeedButton.setEnabled(false);
mSpeedLabel.setText("Speed:"+motorSpeed);
mPortLabel.setText((port>8?("M"+(port-8)):("PORT "+port)));
}
private void setButtonEnabled(ImageButton button, boolean enabled) {
button.setEnabled(enabled);
button.setColorFilter(enabled ? Color.argb(255, 255, 255, 255) : Color.argb(255, 128, 128, 128));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audio_mix);
AudioMixActivity.alive = true;
img_btn_play_pause = (ImageButton) findViewById(R.id.img_btn_play_pause);
img_btn_stop = (ImageButton) findViewById(R.id.img_btn_stop);
btn_select_music = (Button) findViewById(R.id.btn_select_music);
btn_change_mode = (Button) findViewById(R.id.btn_change_mode);
sb_mix_local_vol = (SeekBar) findViewById(R.id.sb_mix_local_vol);
sb_mix_remote_vol = (SeekBar) findViewById(R.id.sb_mix_remote_vol);
sb_mic_vol = (SeekBar) findViewById(R.id.sb_mic_vol);
tv_mix_local_vol = (TextView) findViewById(R.id.tv_mix_local_vol);
tv_mix_remote_vol = (TextView) findViewById(R.id.tv_mix_remote_vol);
tv_mic_vol = (TextView) findViewById(R.id.tv_mic_vol);
img_btn_stop.setEnabled(mixing);
img_btn_play_pause.setSelected(mixing);
sb_mic_vol.setOnSeekBarChangeListener(this);
sb_mix_remote_vol.setOnSeekBarChangeListener(this);
sb_mix_local_vol.setOnSeekBarChangeListener(this);
tv_mic_vol.setText("0");
int mixRemoteVol = RCRTCAudioMixer.getInstance().getMixingVolume();
tv_mix_remote_vol.setText(String.valueOf(mixRemoteVol));
sb_mix_remote_vol.setProgress(mixRemoteVol);
int mixLocalVol = RCRTCAudioMixer.getInstance().getPlaybackVolume();
tv_mix_local_vol.setText(String.valueOf(mixLocalVol));
sb_mix_local_vol.setProgress(mixLocalVol);
int recordingVol = RongRTCCapture.getInstance().getRecordingVolume();
tv_mic_vol.setText(String.valueOf(recordingVol));
sb_mic_vol.setProgress(recordingVol);
mixModes[0] = getResources().getString(R.string.mix_mode_play_mix);
mixModes[1] = getResources().getString(R.string.mix_mode_mix_only);
mixModes[2] = getResources().getString(R.string.mix_mode_play_only);
mixModes[3] = getResources().getString(R.string.mix_mode_replace);
btn_select_music.setText(getFileName(audioPath));
btn_change_mode.setText(mixModes[mixMode]);
}
private void setButtonEnabled(ImageButton button, boolean enabled) {
button.setEnabled(enabled);
button.setColorFilter(enabled ? Color.argb(255, 255, 255, 255) : Color.argb(255, 128, 128, 128));
}
private void initView()
{
cid = getIntent().getExtras().getString("avsCid");
isCloudVideo = getIntent().getBooleanExtra("isCloudVideo", false);
videodata = getIntent().getStringExtra("videodate");
TextView title = (TextView) findViewById(R.id.video_title);
title.setText(videodata);
camera_title = (LinearLayout) findViewById(R.id.camera_title);
wait_relayout = (RelativeLayout) findViewById(R.id.wait_relayout);
progressBar_relayout = (RelativeLayout) findViewById(R.id.progressBar_relayout);
progressBar_relayout_params = (MarginLayoutParams) progressBar_relayout.getLayoutParams();
progressBar_relayout_params.height = CommUtil.getPixelsWidth(this) * 3 / 4;
progressBar_relayout.setLayoutParams(progressBar_relayout_params);
relayout_play_control = (RelativeLayout) findViewById(R.id.relayout_play_control);
relayout_play_control_params = (MarginLayoutParams) relayout_play_control.getLayoutParams();
relayout_play_control.setOnClickListener(this);
pause = (ImageButton) findViewById(R.id.pause);
pause.setOnClickListener(this);
full_screen = (ImageButton) findViewById(R.id.full_screen);
pause_image = (ImageButton) findViewById(R.id.pause_image);
pause_image.setOnClickListener(this);
play_time = (TextView) findViewById(R.id.play_time);
total_time = (TextView) findViewById(R.id.total_time);
video_seek = (SeekBar) findViewById(R.id.video_seek);
relayout_camera_bg = (RelativeLayout) findViewById(R.id.relayout_camera_bg);
camera_bg_params = (MarginLayoutParams) relayout_camera_bg.getLayoutParams();
int totaltime = getIntent().getIntExtra("filetime", 0);
video_seek.setMax(totaltime);
showTime(totaltime, total_time);
video_seek.setEnabled(false);
pause.setEnabled(false);
full_screen.setEnabled(false);
full_screen.setOnClickListener(this);
findViewById(R.id.back_linlayout).setOnClickListener(this);
findViewById(R.id.ipc_warn_img).setOnClickListener(this);
video_seek.setOnSeekBarChangeListener(this);
surfaceViewLayout = (RelativeLayout) findViewById(R.id.glsurfaceviewlayout);
connectUrl = "rtsp://127.0.01:554/record?recordtype=" + getIntent().getIntExtra("filetype", 0) + "&filename=" + videodata;
animation_alpha_in = AnimationUtils.loadAnimation(this, R.anim.alpha_in);
// adViewContent = (AdViewContent) findViewById(R.id.adView_layout);
load_relayout = (RelativeLayout) findViewById(R.id.load_relayout);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Project project = mProjects.get(position);
if(convertView == null) {
LayoutInflater inflater = LayoutInflater.from(MBApp.getApp());
convertView = inflater.inflate(R.layout.project_items, null);
}
Button appNameButton = (Button) convertView.findViewById(R.id.appNameButton);
appNameButton.setTypeface(MBApp.getApp().getRobotoTypeface());
ExtendedEditText appNameEdit = (ExtendedEditText) convertView.findViewById(R.id.appNameEdit);
appNameEdit.setTypeface(MBApp.getApp().getRobotoTypeface());
LinearLayout actionBarLayout = (LinearLayout) convertView.findViewById(R.id.actionBarForProgram);
if(actionBarLayout != null) {
if(project.actionBarExpanded) {
actionBarLayout.setVisibility(View.VISIBLE);
appNameButton.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(MBApp.getApp()
, R.drawable.ic_arrow_down), null);
} else {
actionBarLayout.setVisibility(View.GONE);
appNameButton.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(MBApp.getApp()
, R.drawable.ic_arrow_left), null);
}
}
appNameButton.setText(project.name);
appNameButton.setTag(R.id.positionId, position);
appNameButton.setTag(R.id.textEdit, appNameEdit);
appNameButton.setOnClickListener(appNameClickListener);
appNameButton.setOnLongClickListener(appNameLongClickListener);
appNameEdit.setTag(R.id.positionId, position);
appNameEdit.setTag(R.id.editbutton, appNameButton);
appNameEdit.setOnEditorActionListener(editorOnActionListener);
appNameEdit.setFilters(new InputFilter[]{renameFilter});
if(project.inEditMode) {
appNameEdit.setVisibility(View.VISIBLE);
appNameEdit.setText(project.name);
appNameEdit.setSelection(project.name.length());
appNameEdit.requestFocus();
appNameButton.setVisibility(View.INVISIBLE);
} else {
appNameEdit.setVisibility(View.INVISIBLE);
appNameButton.setVisibility(View.VISIBLE);
//dismissKeyBoard(appNameEdit, false);
}
//appNameEdit.setOnClickListener(appNameClickListener);
TextView flashBtnText = (TextView) convertView.findViewById(R.id.project_item_text);
flashBtnText.setTypeface(MBApp.getApp().getRobotoTypeface());
LinearLayout sendBtnLayout = (LinearLayout) convertView.findViewById(R.id.sendBtn);
sendBtnLayout.setTag(position);
sendBtnLayout.setOnClickListener(sendBtnClickListener);
ImageButton deleteBtn = (ImageButton) convertView.findViewById(R.id.deleteBtn);
deleteBtn.setTag(position);
deleteBtn.setOnClickListener(deleteBtnClickListener);
deleteBtn.setEnabled(true);
Drawable myIcon;
if(project.runStatus) {
flashBtnText.setText("");
myIcon = convertView.getResources().getDrawable(R.drawable.green_btn);
} else {
flashBtnText.setText(R.string.flash);
myIcon = convertView.getResources().getDrawable(R.drawable.blue_btn);
}
sendBtnLayout.setBackground(myIcon);
sendBtnLayout.setClickable(true);
return convertView;
}