Java Code Examples for android.widget.Button#setEnabled()

The following examples show how to use android.widget.Button#setEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NewFileDialogInput.java    From GreenDamFileExploere with Apache License 2.0 6 votes vote down vote up
private void init() {
    mView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_new_file_input, null);

    mEtNewFileDialogName = (EditText) mView.findViewById(R.id.mEtNewFileName);
    mBtnNewFileOk = (Button) mView.findViewById(R.id.mBtnNewFileInputDialogOk);
    mBtnNewFileCancel = (Button) mView.findViewById(R.id.mBtnNewFileInputDialogCancel);

    mBtnNewFileOk.setOnClickListener(this);
    mBtnNewFileCancel.setOnClickListener(this);
    mEtNewFileDialogName.addTextChangedListener(this);

    mBtnNewFileOk.setEnabled(false);

    this.setTitle("请选择创建的文件类型");
    this.setContentView(mView);
    this.setCanceledOnTouchOutside(false);

}
 
Example 2
Source File: LinkingDeviceActivity.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
private void setHumidityButton() {
    Button onBtn =  findViewById(R.id.battery_humidity_on);
    if (onBtn != null) {
        onBtn.setOnClickListener((v) -> {
            onClickHumiditySensor(true);
        });
        onBtn.setEnabled(mDevice.isSupportHumidity());
    }
    Button offBtn = findViewById(R.id.battery_humidity_off);
    if (offBtn != null) {
        offBtn.setOnClickListener((v) -> {
            onClickHumiditySensor(false);
        });
        offBtn.setEnabled(mDevice.isSupportHumidity());
    }
}
 
Example 3
Source File: UpdateCommentTask.java    From YiBo with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPostExecute(Comment result) {
	super.onPostExecute(result);

	if (isShowDialog && dialog != null) {
		try {
		    dialog.dismiss();
		} catch(Exception e){}
	}

       if (newComment != null) {
       	if (isShowDialog) {
       	    Toast.makeText(context, R.string.msg_comment_success, Toast.LENGTH_LONG).show();
       	    Intent intent = new Intent();
       	    intent.putExtra("RESULT_COMMENT", newComment);
       	    ((Activity)context).setResult(Constants.RESULT_CODE_SUCCESS, intent);
		    ((Activity)context).finish();
       	}
       } else {
       	if (isShowDialog) {
		    Button btnSend = (Button)((Activity)context).findViewById(R.id.btnOperate);
		    btnSend.setEnabled(true);
       	}
       	Toast.makeText(context, resultMsg, Toast.LENGTH_LONG).show();
       }
}
 
Example 4
Source File: ServiceListActivity.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
/**
 * Searchボタンの有効無効を切り替える.
 * @param running Managerの実行状態
 */
private void setEnableSearchButton(final boolean running) {
    Button btn = findViewById(R.id.activity_service_list_search_button);
    FrameLayout fl = findViewById(R.id.activity_service_no_service);
    if (getManagerService() != null) {
        if (btn != null) {
            btn.setEnabled(running);
        }
        if (fl != null) {
            if (running) {
                fl.setVisibility(View.GONE);
            } else {
                fl.setVisibility(View.VISIBLE);
            }
        }
    }
}
 
Example 5
Source File: MainActivity.java    From android-apps with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	
	start = (Button)findViewById(R.id.button1);
	stop = (Button)findViewById(R.id.button2);
	play = (Button)findViewById(R.id.button3);
	
	stop.setEnabled(false);
    play.setEnabled(false);
    
    outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myRecorded.3gp";
    mediaRecorder = new MediaRecorder();
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    mediaRecorder.setOutputFile(outputFile);
    
	
}
 
Example 6
Source File: X8GimbalItemController.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void setViewEnabled(boolean isEnabled) {
    if (this.rlFcItem != null) {
        float f;
        this.btnHorizontalTrim.setEnabled(isEnabled);
        this.sbPitchSpeed.setViewEnable(isEnabled);
        this.vsbGimbalGain.setViewEnable(isEnabled);
        boolean isOngroud = StateManager.getInstance().getX8Drone().isOnGround();
        Button button = this.btnRestParams;
        boolean z = isOngroud && isEnabled;
        button.setEnabled(z);
        button = this.btnRestParams;
        if (isOngroud && isEnabled) {
            f = 1.0f;
        } else {
            f = 0.4f;
        }
        button.setAlpha(f);
        if (isEnabled) {
            this.btnHorizontalTrim.setAlpha(1.0f);
        } else {
            this.btnHorizontalTrim.setAlpha(0.4f);
        }
    }
}
 
Example 7
Source File: HelloworldActivity.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPostExecute(String result) {
  try {
    channel.shutdown().awaitTermination(1, TimeUnit.SECONDS);
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
  }
  Activity activity = activityReference.get();
  if (activity == null) {
    return;
  }
  TextView resultText = (TextView) activity.findViewById(R.id.grpc_response_text);
  Button sendButton = (Button) activity.findViewById(R.id.send_button);
  resultText.setText(result);
  sendButton.setEnabled(true);
}
 
Example 8
Source File: ActivityGenerateSelf.java    From ploggy with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_generate_self);

    mAvatarImage = (ImageView)findViewById(R.id.generate_self_avatar_image);
    mAvatarImage.setImageResource(R.drawable.ic_unknown_avatar);
    mNicknameEdit = (EditText)findViewById(R.id.generate_self_nickname_edit);
    mNicknameEdit.addTextChangedListener(getNicknameTextChangedListener());
    mNicknameEdit.setEnabled(false);
    mFingerprintText = (TextView)findViewById(R.id.generate_self_fingerprint_text);
    mRegenerateButton = (Button)findViewById(R.id.generate_self_regenerate_button);
    mRegenerateButton.setEnabled(false);
    mRegenerateButton.setVisibility(View.GONE);
    mRegenerateButton.setOnClickListener(this);
    mSaveButton = (Button)findViewById(R.id.generate_self_save_button);
    mSaveButton.setEnabled(false);
    mSaveButton.setVisibility(View.GONE);
    mSaveButton.setOnClickListener(this);
    mProgressDialog = new ProgressDialog(this);
    mProgressDialog.setMessage(getText(R.string.prompt_generate_self_progress));
    mProgressDialog.setCancelable(false);
    mAvatarTimer = new Timer();
}
 
Example 9
Source File: LogViewerActivity.java    From PressureNet with GNU General Public License v3.0 6 votes vote down vote up
public void getRecents(long numHoursAgo) {
	this.hoursAgo = numHoursAgo;
	// disable buttons
	oneHour = (Button) findViewById(R.id.buttonOneHour);
	sixHours = (Button) findViewById(R.id.buttonSixHours);
	oneDay = (Button) findViewById(R.id.buttonOneDay);
	oneWeek = (Button) findViewById(R.id.buttonOneWeek);

	oneHour.setEnabled(false);
	oneHour.setTextColor(Color.GRAY);
	sixHours.setEnabled(false);
	sixHours.setTextColor(Color.GRAY);
	oneDay.setEnabled(false);
	oneDay.setTextColor(Color.GRAY);
	oneWeek.setEnabled(false);
	oneWeek.setTextColor(Color.GRAY);

	if (mBound) {
		MessageSender message = new MessageSender();
		message.execute("");
	} else {
		// log("error: not bound");
	}
}
 
Example 10
Source File: MainActivity.java    From android-midisuite with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Log.i(TAG, "app started ========================");
    Button bluetoothScanButton = (Button) findViewById(R.id.bluetooth_scan);
    bluetoothScanButton.setOnClickListener(mBluetoothScanListener);

    ListView listView = (ListView) findViewById(R.id.open_device_list);
    listView.setEmptyView(findViewById(R.id.empty));

    // Initializes list view adapter.
    mOpenDeviceListAdapter = new OpenDeviceListAdapter();
    listView.setAdapter(mOpenDeviceListAdapter);

    if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI)) {
        setupMidi();
    } else {
        Toast.makeText(MainActivity.this, "MIDI not supported!",
                Toast.LENGTH_LONG).show();
        bluetoothScanButton.setEnabled(false);
    }
}
 
Example 11
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final Button button1 = findViewById(R.id.button1);
    button1.setEnabled(false);
    final Button button2 = findViewById(R.id.button2);
    button2.setEnabled(false);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        createSoundPoolNew();
    } else {
        createSoundPoolOld();
    }
    mSoundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            button1.setEnabled(true);
            button2.setEnabled(true);
        }
    });
    mHashMap = new HashMap<>();
    mHashMap.put(1, mSoundPool.load(this, R.raw.sound_1, 1));
    mHashMap.put(2, mSoundPool.load(this, R.raw.sound_2, 1));
}
 
Example 12
Source File: MusicSelectionFragment.java    From android-play-games-in-motion with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.menu_music_selection, container, false);
    mReadyButton = (Button) rootView.findViewById(R.id.start_mission_button);
    mReadyButton.setEnabled(true);
    mReadyButton.setText(R.string.start_mission_button);
    return rootView;
}
 
Example 13
Source File: BotScriptEditorActivity.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
public void resetView(){
	this.source = (ScriptSourceConfig)MainActivity.script;
	this.instance = (InstanceConfig)MainActivity.instance;

	TextView title = (TextView)findViewById(R.id.title);
	title.setText(Utils.stripTags(this.instance.name));

	String script = source.source;

	EditText editScript = (EditText)findViewById(R.id.scriptSource);
	Button saveButton = (Button)findViewById(R.id.saveScriptButton);

	if (script != null && !script.equals("")) {
		editScript.setText(script);
	}
	else {
		editScript.setText("");
	}

	boolean isAdmin = (MainActivity.user != null) && instance.isAdmin;
	if (!isAdmin || instance.isExternal) {
		editScript.setFocusable(false);
		saveButton.setEnabled(false);
		saveButton.setVisibility(View.INVISIBLE);
	} else {
		editScript.setFocusableInTouchMode(true);
		saveButton.setEnabled(true);
	}
}
 
Example 14
Source File: FastAccessDurationDialog.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
private void updateTextFields(boolean updateValueField) {
    int hours = mSeekBarHours.getProgress();
    int minutes = mSeekBarMinutes.getProgress();
    int seconds = mSeekBarSeconds.getProgress();

    int iValue = (hours * 3600 + minutes * 60 + seconds);
    if (iValue < mMin) iValue = mMin;
    if (iValue > mMax) iValue = mMax;

    if(mDialog!=null && mDialog.getButton(DialogInterface.BUTTON_POSITIVE).isEnabled()) {
        mEnds.setText(GlobalGUIRoutines.getEndsAtString(iValue));
    } else {
        mEnds.setText("--");
    }

    if (mDialog != null) {
        afterDurationLabel.setEnabled(iValue > mMin);
        afterDoSpinner.setEnabled(iValue > mMin);
        updateProfileView();
        Button button = mDialog.getButton(DialogInterface.BUTTON_POSITIVE);
        button.setEnabled(iValue > mMin);
    }

    if(updateValueField) {
        mValue.setText(GlobalGUIRoutines.getDurationString(iValue));
    }
}
 
Example 15
Source File: WidgetUtils.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
public static void setupButton(Button btn, Spannable text, int fontSize, boolean enabled) {
    btn.setText(text);
    int verticalPadding = (int)btn.getResources().getDimension(R.dimen.widget_button_padding);
    btn.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize);
    btn.setPadding(20, verticalPadding, 20, verticalPadding);
    btn.setEnabled(enabled);
    btn.setLayoutParams(WidgetUtils.params);
}
 
Example 16
Source File: SslErrorDialogFragment.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
private void showExtendedMessage(@NonNull AlertDialog alertDialog) {
    TextView textView = (TextView) alertDialog.findViewById(android.R.id.message);
    Button neutralButton = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL);
    if (textView != null) {
        textView.setText(R.string.ssl_error_display_message_extended);
        neutralButton.setEnabled(false);
    }
}
 
Example 17
Source File: AutofillProfileEditor.java    From delion with Apache License 2.0 4 votes vote down vote up
private void setSaveButtonEnabled(boolean enabled) {
    if (getView() != null) {
        Button button = (Button) getView().findViewById(R.id.button_primary);
        button.setEnabled(enabled);
    }
}
 
Example 18
Source File: FaBoServiceListActivity.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
                         final Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_service_list_remover, container, false);

    mListAdapter = new ServiceListAdapter(getActivity(), getProvider(), true);
    mListAdapter.setOnStatusChangeListener(this);

    ListView listView = root.findViewById(R.id.activity_fabo_service_list_view);
    listView.setAdapter(mListAdapter);
    listView.setItemsCanFocus(true);
    listView.setClickable(true);
    listView.setOnItemClickListener((parent, view, position, id) -> {
        Object service = mListAdapter.getItem(position);
        if (service instanceof VirtualService) {
            VirtualService vs = (VirtualService) service;
            if (vs.isOnline()) {
                showOnlineDialog();
            } else {
                mListAdapter.toggleCheckBox((DConnectService) service);
                CheckBox checkBox = view.findViewById(R.id.activity_fabo_service_removal_checkbox);
                if (checkBox != null) {
                    checkBox.toggle();
                }
            }
        } else {
            showImmortalDialog();
        }
    });

    Button cancelButton = root.findViewById(R.id.activity_fabo_service_cancel_btn);
    cancelButton.setOnClickListener((v) -> {
        showViewerFragment();
    });

    mRemoveBtn = (Button) root.findViewById(R.id.activity_fabo_service_remove_btn);
    mRemoveBtn.setOnClickListener((v) -> {
        showRemovalConfirmation();
    });
    mRemoveBtn.setEnabled(false);

    return root;
}
 
Example 19
Source File: MessageAdapter.java    From smartcard-reader with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = mLayoutInflater.inflate(R.layout.parsed_msg, parent,
                false);
    }
    Button btn = (Button) convertView
            .findViewById(R.id.list_item_btn);
    ImageView img = (ImageView) convertView
            .findViewById(R.id.list_item_img);
    View separator = convertView
            .findViewById(R.id.separator);

    Message msg = (Message)getItem(position);

    // handling for separator/break
    if (msg.type == MSG_BREAK) {
        btn.setVisibility(View.GONE);
        img.setVisibility(View.GONE);
        separator.setVisibility(View.VISIBLE);
        return convertView;
    }

    btn.setText(msg.text);
    btn.setVisibility(View.VISIBLE);
    // img visibility handled below
    separator.setVisibility(View.GONE);

    // handling based on presence of parsed message contents
    if (msg.parsed.isEmpty()) {
        btn.setEnabled(false);
        btn.setBackground(null);
        img.setVisibility(View.GONE);
    } else {
        btn.setEnabled(true);
        btn.setBackground(mContext.getResources().
                getDrawable(R.drawable.parsed_msg_bg_states));
        img.setVisibility(View.VISIBLE);
        btn.setOnClickListener(new MessageClickListener(position));
    }
    // default style
    int color = android.R.color.black;
    // specific message type styles
    switch (msg.type) {
    case MSG_SEND:
        color = R.color.msg_send;
        break;
    case MSG_RCV:
        color = R.color.msg_rcv;
        break;
    case MSG_OKAY:
        color = R.color.msg_okay;
        break;
    case MSG_ERROR:
        color = R.color.msg_err;
        break;
    }
    btn.setTextColor(mContext.getResources().getColor(color));
    return convertView;
}
 
Example 20
Source File: ActivityShare.java    From XPrivacy with GNU General Public License v3.0 4 votes vote down vote up
private void showFileName() {
	TextView tvDescription = (TextView) findViewById(R.id.tvDescription);
	tvDescription.setText(mFileName);
	Button btnOk = (Button) findViewById(R.id.btnOk);
	btnOk.setEnabled(true);
}