private void updateButtonsAndProgress() { // Title buttons boolean showTitleButtonsContainer = (leftTitleButtonController != null || rightTitleButtonController != null); final View titleButtonsContainer = view.findViewById(R.id.title_button_container); titleButtonsContainer.setVisibility(showTitleButtonsContainer ? View.VISIBLE : View.GONE); // Left title button final Button leftTitleButton = (Button) view.findViewById(R.id.title_button); final TextView titleButtonRightText = (TextView) view.findViewById(R.id.title_button_right_text); if (leftTitleButtonController != null) { leftTitleButton.setText(leftTitleButtonController.caption); leftTitleButton.setVisibility(leftTitleButtonController.visible ? View.VISIBLE : View.GONE); Drawable leftIcon = leftTitleButtonController.getLeftIcon(); if (leftIcon != null) { leftTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null); leftTitleButton.setCompoundDrawablePadding(dpToPx(4f)); } if (leftTitleButtonController.needRightText) { titleButtonRightText.setText(leftTitleButtonController.rightTextCaption); titleButtonRightText.setVisibility(View.VISIBLE); } else { titleButtonRightText.setVisibility(View.GONE); } } else { leftTitleButton.setVisibility(View.GONE); titleButtonRightText.setVisibility(View.GONE); } // Right title button final Button rightTitleButton = (Button) view.findViewById(R.id.title_button_right); if (rightTitleButtonController != null) { rightTitleButton.setText(rightTitleButtonController.caption); rightTitleButton.setVisibility(rightTitleButtonController.visible ? View.VISIBLE : View.GONE); Drawable leftIcon = rightTitleButtonController.getLeftIcon(); rightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null); rightTitleButton.setCompoundDrawablePadding(dpToPx(4f)); } else { rightTitleButton.setVisibility(View.GONE); } // Top Right title button final Button topRightTitleButton = (Button) view.findViewById(R.id.title_button_top_right); if (topRightTitleButtonController != null) { topRightTitleButton.setText(topRightTitleButtonController.caption); topRightTitleButton.setVisibility( topRightTitleButtonController.visible ? View.VISIBLE : View.INVISIBLE); Drawable leftIcon = topRightTitleButtonController.getLeftIcon(); topRightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null); topRightTitleButton.setCompoundDrawablePadding(dpToPx(4f)); } else { topRightTitleButton.setVisibility(View.GONE); } }
public void updatePhoneRotationButtonState(int state) { if (btnTogglePhoneRotationSettings == null) return; if (state == 1) { btnTogglePhoneRotationSettings.setCompoundDrawablesWithIntrinsicBounds( 0, R.drawable.ic_auto_rotation_on, 0, 0); } else { btnTogglePhoneRotationSettings.setCompoundDrawablesWithIntrinsicBounds( 0, R.drawable.ic_auto_rotation_off, 0, 0); } }
@Override public void run() { if (isRecord) { if (count) { recordButton.setCompoundDrawablesWithIntrinsicBounds(recIconRed, null, null, null); } else { recordButton.setCompoundDrawablesWithIntrinsicBounds(recIconWhite, null, null, null); } count = !count; recTime += 1000; updateTime(recTime); recordButton.postDelayed(recordAnim, 1000); } }
/** Reset the ordering buttons to their default state */ private void resetOrderingButtons() { Button hourlyButton = (Button) findViewById(R.id.hourly_button); Button ratingButton = (Button) findViewById(R.id.rating_button); Drawable noArrow = ContextCompat.getDrawable(this, R.drawable.ic_remove_black_24dp); hourlyButton.setCompoundDrawablesWithIntrinsicBounds(null, null, noArrow, null); ratingButton.setCompoundDrawablesWithIntrinsicBounds(null, null, noArrow, null); setButtonTint( hourlyButton, ColorStateList.valueOf(ContextCompat.getColor(this, R.color.button_material_light))); setButtonTint( ratingButton, ColorStateList.valueOf(ContextCompat.getColor(this, R.color.button_material_light))); }
@Override public void initView() { fm = getSupportFragmentManager(); ft = fm.beginTransaction(); bt_home = (Button) findViewById(R.id.bt_home); bt_search = (Button) findViewById(R.id.bt_search); bt_message = (Button) findViewById(R.id.bt_message); bt_user = (Button) findViewById(R.id.bt_user); unreadLabel = (TextView) findViewById(R.id.unread_msg_number); // if (fm.findFragmentByTag("HOME") == null) { ft.add(R.id.rl_fragment_contanier, (HomeFragment) FragmentFactory.getFragment(HOME), "HOME") .add( R.id.rl_fragment_contanier, (MessageFragment) FragmentFactory.getFragment(MESSAGE), "MESSAGE") .hide((MessageFragment) FragmentFactory.getFragment(MESSAGE)) .add( R.id.rl_fragment_contanier, (FindFragment) FragmentFactory.getFragment(LOOKINGFORTEACHER), "LOOKINGFORTEACHER") .hide((FindFragment) FragmentFactory.getFragment(LOOKINGFORTEACHER)) .add(R.id.rl_fragment_contanier, FragmentFactory.getFragment(MYINFO), "MYINFO") .hide(((MyFragment) FragmentFactory.getFragment(MYINFO))); ft.show((HomeFragment) FragmentFactory.getFragment(HOME)).commit(); bt_home.setCompoundDrawablesWithIntrinsicBounds( null, getResources().getDrawable(R.mipmap.tab_ico_home_pre), null, null); // bt_home.setSelected(true); showLogD("=============================================="); }
/** * 配置右按钮2 * * @param iconResId 图标资源id,没有传0 * @param textResId 文字资源id,没有传0 * @return 当前标题栏对象 */ private TitleBar setRightButton2(int iconResId, int textResId) { mBtnRight2.setText(0 == textResId ? "" : getResources().getText(textResId)); mBtnRight2.setCompoundDrawablesWithIntrinsicBounds(0, 0, iconResId, 0); mBtnRight2.setVisibility(VISIBLE); if (VISIBLE != mBtnLeft.getVisibility()) { mBtnLeft2.setVisibility(INVISIBLE); } return this; }
/** * Sets the background resource of the Button in a BUTTON type SuperCardToast. <br> * * @param buttonResource Use SuperToast.Icon constants */ public void setButtonResource(int buttonResource) { this.mButtonResource = buttonResource; if (mToastButton != null) { mToastButton.setCompoundDrawablesWithIntrinsicBounds( mContext.getResources().getDrawable(buttonResource), null, null, null); } }
public void displayFavoriteStatut() { Cursor statutCursor = null; Drawable icon = getActivity().getResources().getDrawable(R.drawable.ic_favorite); Drawable statut = null; try { Account acc = SessionUtils.getAccount(getActivity()); Boolean hasSynchroActive = GeneralPreferences.hasActivateSync(getActivity(), acc); if (hasSynchroActive && acc != null) { statutCursor = getActivity() .getContentResolver() .query( SynchroProvider.CONTENT_URI, SynchroSchema.COLUMN_ALL, SynchroProvider.getAccountFilter(acc) + " AND " + SynchroSchema.COLUMN_STATUS + " == " + SyncOperation.STATUS_REQUEST_USER, null, null); if (statutCursor.getCount() > 0) { statut = getActivity().getResources().getDrawable(R.drawable.ic_warning_light); } statutCursor.close(); if (menuSlidingFavorites != null) { menuSlidingFavorites.setCompoundDrawablesWithIntrinsicBounds(icon, null, statut, null); } menuFavorites.setCompoundDrawablesWithIntrinsicBounds(icon, null, statut, null); } } catch (Exception e) { } finally { if (statutCursor != null) { statutCursor.close(); } } }
/** * Repopulate the search result list displayed to the user according to the specified ordering by * rating * * @param view */ public void onRatingClick(View view) { Button hourlyButton = (Button) findViewById(R.id.hourly_button); Button ratingButton = (Button) findViewById(R.id.rating_button); Drawable downArrow = ContextCompat.getDrawable(this, R.drawable.ic_keyboard_arrow_down_black_24dp); Drawable upArrow = ContextCompat.getDrawable(this, R.drawable.ic_keyboard_arrow_up_black_24dp); Drawable noArrow = ContextCompat.getDrawable(this, R.drawable.ic_remove_black_24dp); setButtonTint( ratingButton, ColorStateList.valueOf(ContextCompat.getColor(this, R.color.orderingButtonClicked))); setButtonTint( hourlyButton, ColorStateList.valueOf(ContextCompat.getColor(this, R.color.button_material_light))); hourlyButton.setCompoundDrawablesWithIntrinsicBounds(null, null, noArrow, null); // Get the image Drawable currentOrdering = ratingButton.getCompoundDrawables()[2]; // From default to down if (currentOrdering.getConstantState().equals(noArrow.getConstantState())) { ratingButton.setCompoundDrawablesWithIntrinsicBounds(null, null, downArrow, null); usersToRatings = orderList(usersToRatings, "ratingDescending"); if (usersToRatings != null) populateResults((ArrayList) usersToRatings); } // From down to up else if (currentOrdering.getConstantState().equals(downArrow.getConstantState())) { ratingButton.setCompoundDrawablesWithIntrinsicBounds(null, null, upArrow, null); usersToRatings = orderList(usersToRatings, "ratingAscending"); if (usersToRatings != null) populateResults((ArrayList) usersToRatings); } // From up to down else if (currentOrdering.getConstantState().equals(upArrow.getConstantState())) { ratingButton.setCompoundDrawablesWithIntrinsicBounds(null, null, downArrow, null); usersToRatings = orderList(usersToRatings, "ratingDescending"); if (usersToRatings != null) populateResults((ArrayList) usersToRatings); } }
/** * Sets the emergency button visibility based on isEmergencyCallCapable(). * * <p>If the emergency button is visible, sets the text on the emergency button to indicate what * action will be taken. * * <p>If there's currently a call in progress, the button will take them to the call * * @param button the button to update * @param the phone state: {@link TelephonyManager#CALL_STATE_IDLE} {@link * TelephonyManager#CALL_STATE_RINGING} {@link TelephonyManager#CALL_STATE_OFFHOOK} * @param shown indicates whether the given screen wants the emergency button to show at all */ public void updateEmergencyCallButtonState(Button button, int phoneState, boolean shown) { if (isEmergencyCallCapable() && shown) { button.setVisibility(View.VISIBLE); } else { button.setVisibility(View.GONE); return; } int textId; if (phoneState == TelephonyManager.CALL_STATE_OFFHOOK) { // show "return to call" text and show phone icon textId = R.string.lockscreen_return_to_call; int phoneCallIcon = R.drawable.stat_sys_phone_call; button.setCompoundDrawablesWithIntrinsicBounds(phoneCallIcon, 0, 0, 0); } else { textId = R.string.lockscreen_emergency_call; int emergencyIcon = R.drawable.ic_emergency; button.setCompoundDrawablesWithIntrinsicBounds(emergencyIcon, 0, 0, 0); } button.setText(textId); }
@Override public void stop() { if (mediaRecorder != null) { mediaRecorder.stop(); mediaRecorder.release(); recordButton.setText("Rec"); isRecord = false; mediaRecorder = null; recTime = 0; recordButton.setCompoundDrawablesWithIntrinsicBounds(recIconWhite, null, null, null); } }
/** Setup and load the notification specific button icons. */ private void setupButtonIcons( boolean usingImageButtons, int notificationType, String buttonDisplayStyle) { if (_debug) Log.v("ThemeView.setupButtonIcons()"); try { if (buttonDisplayStyle.equals(Constants.BUTTON_DISPLAY_TEXT_ONLY)) { return; } Drawable dismissButtonIcon = null; Drawable deleteButtonIcon = null; Drawable replySMSButtonIcon = null; // Load the theme specific icons. if (_themePackageName.startsWith(Constants.DARK_TRANSLUCENT_THEME)) { dismissButtonIcon = _resources.getDrawable(R.drawable.ic_dismiss); deleteButtonIcon = _resources.getDrawable(R.drawable.ic_delete); replySMSButtonIcon = _resources.getDrawable(R.drawable.ic_conversation); } else { dismissButtonIcon = _resources.getDrawable( _resources.getIdentifier(_themePackageName + ":drawable/ic_dismiss", null, null)); deleteButtonIcon = _resources.getDrawable( _resources.getIdentifier(_themePackageName + ":drawable/ic_delete", null, null)); replySMSButtonIcon = _resources.getDrawable( _resources.getIdentifier( _themePackageName + ":drawable/ic_conversation", null, null)); } if (usingImageButtons) { _dismissImageButton.setImageDrawable(dismissButtonIcon); _deleteImageButton.setImageDrawable(deleteButtonIcon); _replyImageButton.setImageDrawable(replySMSButtonIcon); } else { _dismissButton.setCompoundDrawablesWithIntrinsicBounds(dismissButtonIcon, null, null, null); _deleteButton.setCompoundDrawablesWithIntrinsicBounds(deleteButtonIcon, null, null, null); _replyButton.setCompoundDrawablesWithIntrinsicBounds(replySMSButtonIcon, null, null, null); } } catch (Exception ex) { Log.e("ThemeView.setupButtonIcons() ERROR: " + ex.toString()); } }
@Override public void setCompoundDrawablesWithIntrinsicBounds( Drawable left, Drawable top, Drawable right, Drawable bottom) { super.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom); if (null != left) { drawableWidth = left.getIntrinsicWidth(); drawablePosition = DrawablePositions.LEFT; } else if (null != right) { drawableWidth = right.getIntrinsicWidth(); drawablePosition = DrawablePositions.RIGHT; } else { drawablePosition = DrawablePositions.NONE; } requestLayout(); }
/** * Checks and updates all status indicators, updates current image's status indicators. If all * checks are passed, the bundle is allowed to save. */ private void updateStatus() { String userOrigin = User.getInstance().getOriginName(); boolean originOk = userOrigin != null && userOrigin.equals(mOriginName.getText().toString().trim()); applyStatus(mOriginStatus, originOk); boolean bundleNameOk = mBundleNameText != null && mBundleNameText.equals(mBundleName.getText().toString().trim()); applyStatus(mBundleNameStatus, bundleNameOk); boolean bitmapsOk = mSelectedBitmaps.size() > 0 && mBitmapsSelectCount == 0; applyStatus(mBitmapsStatus, bitmapsOk); boolean imageInformationOk = getCompletedImageDataCount() == mSelectedBitmaps.size() && mSelectedBitmaps.size() > 0; applyStatus(mImageStatus, imageInformationOk); boolean allOk = originOk && bundleNameOk && bitmapsOk && imageInformationOk; mSave.setEnabled(allOk); if (allOk) { if (mSaveResult == ImageXmlWriter.RESULT_SUCCESS) { mProgressText.setText(R.string.bundle_creator_progress_saved); } else if (mSaveResult == ImageXmlWriter.RESULT_NONE) { mProgressText.setText(R.string.bundle_creator_progress_ready_to_save); } else { mProgressText.setText( mProgressText .getResources() .getString(R.string.bundle_creator_progress_error_result, mSaveResult)); } mSave.setCompoundDrawablesWithIntrinsicBounds(0, 0, ACCEPT_RESOURCE, 0); } else { mSaving = false; mSave.setCompoundDrawablesWithIntrinsicBounds(0, 0, REFUSE_RESOURCE, 0); mProgressText.setText(R.string.bundle_creator_progress_info_missing); } updateCurrentImageStatus(); fillImageHeaderData(); }
public void setProvider(TransportDroidIL.Provider provider) { Button submitButton = (Button) findViewById(R.id.submit); int newIconId = 0; switch (provider) { case MOT: newIconId = R.drawable.mot; break; case EGGED: newIconId = R.drawable.egged; break; default: throw new IllegalArgumentException("Got invalid provider " + provider); } submitButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, newIconId, 0); }
protected void setFavoriteBtnOn(Button fav) { fav.setCompoundDrawablesWithIntrinsicBounds( getResources().getDrawable(R.drawable.btn_star_big_on), null, null, null); fav.setOnClickListener( new OnClickListener() { public void onClick(View v) { myVib.vibrate(35); GazeAction act = new GazeAction( getApplicationContext(), gaze.id, Installation.id(getApplicationContext()), "unlike"); act.execute(); } }); }
protected void updateMenu() { Button flipCameraButton = (Button) findViewById(R.id.flipCameraButton); if (camera.getCameraCount() > 1) { flipCameraButton.setVisibility(View.VISIBLE); if (camera.isFront()) { flipCameraButton.setCompoundDrawablesWithIntrinsicBounds( R.drawable.ic_camera_front_white_24dp, 0, 0, 0); flipCameraButton.setText(getString(R.string.camera_front)); } else { flipCameraButton.setCompoundDrawablesWithIntrinsicBounds( R.drawable.ic_camera_rear_white_24dp, 0, 0, 0); flipCameraButton.setText(getString(R.string.camera_rear)); } } else { flipCameraButton.setVisibility(View.GONE); } Button thresholdDisplayButton = (Button) findViewById(R.id.thresholdDisplayButton); if (detector.shouldDrawThreshold()) { thresholdDisplayButton.setText(getString(R.string.threshold_on)); thresholdDisplayButton.setCompoundDrawablesWithIntrinsicBounds( R.drawable.ic_filter_b_and_w_white_24dp, 0, 0, 0); } else { thresholdDisplayButton.setText(getString(R.string.threshold_off)); thresholdDisplayButton.setCompoundDrawablesWithIntrinsicBounds( R.drawable.ic_filter_b_and_w_off_white_24dp, 0, 0, 0); } Button markerDisplayButton = (Button) findViewById(R.id.markerDisplayButton); if (detector.getMarkerDrawMode() == MarkerDetector.MarkerDrawMode.off) { markerDisplayButton.setCompoundDrawablesWithIntrinsicBounds( R.drawable.ic_border_clear_white_24dp, 0, 0, 0); markerDisplayButton.setText(getString(R.string.marker_off)); } else if (detector.getMarkerDrawMode() == MarkerDetector.MarkerDrawMode.outline) { markerDisplayButton.setCompoundDrawablesWithIntrinsicBounds( R.drawable.ic_border_outer_white_24dp, 0, 0, 0); markerDisplayButton.setText(getString(R.string.marker_outline)); } else { markerDisplayButton.setCompoundDrawablesWithIntrinsicBounds( R.drawable.ic_border_all_white_24dp, 0, 0, 0); markerDisplayButton.setText(getString(R.string.marker_on)); } // private ImageView autoOpenIcon; // private TextView autoOpenLabel; }
private boolean setupCameraButton() { if (!GalleryUtils.isCameraAvailable(mActivity)) return false; RelativeLayout galleryRoot = (RelativeLayout) ((Activity) mActivity).findViewById(R.id.gallery_root); if (galleryRoot == null) return false; mCameraButton = new Button(mActivity); mCameraButton.setText(R.string.camera_label); mCameraButton.setCompoundDrawablesWithIntrinsicBounds( 0, R.drawable.frame_overlay_gallery_camera, 0, 0); mCameraButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { GalleryUtils.startCameraActivity(mActivity); } }); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.CENTER_IN_PARENT); galleryRoot.addView(mCameraButton, lp); return true; }
/** * Novo m�todo para criar o painel din�mico para os bot�es de selec��o da turma * * @author Thiago */ @SuppressLint("NewApi") private void makeTabela() { // Cria o objecto da base de dados LetrinhasDB db = new LetrinhasDB(this); // ************* Mudar este select de all para por ID de turma // (ALEXANDRE!!) List<Estudante> alunos = db.getAllStudentsByTurmaId(idTurma); // ******************************************************************************* int nAlunos = alunos.size(); int[] idAluno = new int[nAlunos]; String nomeAluno[] = new String[nAlunos]; String fotoAluno[] = new String[nAlunos]; // preenche os arrays s� com a informa��o necess�ria for (int i = 0; i < nAlunos; i++) { idAluno[i] = alunos.get(i).getIdEstudante(); nomeAluno[i] = alunos.get(i).getNome(); fotoAluno[i] = alunos.get(i).getNomefoto(); } for (Estudante cn : alunos) { String storage = cn.getNome() + "," + cn.getIdEstudante() + "," + cn.getNomefoto() + "," + cn.getEstado() + "," + cn.getIdTurma(); Log.d("letrinhas-Alunos", storage.toString()); } /** Scroll view com uma tabela de 4 colunas(max) */ // tabela a editar TableLayout tabela = (TableLayout) findViewById(R.id.tblEscolheAl); // linha da tabela a editar TableRow linha = (TableRow) findViewById(R.id.escAllinha01); // 1� bot�o Button bt = (Button) findViewById(R.id.AlBtOriginal); bt.setText("teste alunos"); // Contador de controlo int cont = 0; // criar o n� de linhas a dividir por 4 colunas for (int i = 0; i < nAlunos / 4; i++) { // nova linha da tabela TableRow linha1 = new TableRow(getBaseContext()); // Copiar os parametros da 1� linha linha1.setLayoutParams(linha.getLayoutParams()); // criar os 4 bot�es da linha for (int j = 0; j < 4; j++) { // ********************************** // Nome, id e foto do aluno final String alumni = nomeAluno[cont]; final int idAL = idAluno[cont]; final String alunFot = fotoAluno[cont]; // *********************************** // novo bot�o Button bt1 = new Button(bt.getContext()); // copiar os parametros do bot�o original bt1.setLayoutParams(bt.getLayoutParams()); // se o aluno tiver foto, vou busca-la if (fotoAluno[cont] != null) { String imageInSD = Environment.getExternalStorageDirectory().getAbsolutePath() + "/School-Data/Students/" + fotoAluno[cont]; Bitmap bitmap = BitmapFactory.decodeFile(imageInSD); ImageView imageView = new ImageView(this); // ajustar o tamanho da imagem imageView.setImageBitmap(Bitmap.createScaledBitmap(bitmap, 210, 200, false)); // enviar para o bot�o bt1.setCompoundDrawablesWithIntrinsicBounds(null, imageView.getDrawable(), null, null); } else { // sen�o copia a imagem do bot�o original bt1.setCompoundDrawables(null, bt.getCompoundDrawablesRelative()[1], null, null); } // addicionar o nome bt1.setText(nomeAluno[cont]); // Defenir o que faz o bot�o ao clicar bt1.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { // Entrar na activity Bundle wrap = new Bundle(); wrap.putString("Escola", Escola); wrap.putInt("Escola_ID", idEscola); wrap.putString("Professor", Professor); wrap.putInt("Professor_ID", idProfessor); wrap.putString("Foto_professor", FotoProf); wrap.putString("Turma", Turma); wrap.putInt("Turma_ID", idTurma); wrap.putString("Aluno", alumni); wrap.putInt("Aluno_ID", idAL); wrap.putString("Foto_Aluno", alunFot); Intent it = new Intent(getApplicationContext(), EscModo.class); it.putExtras(wrap); startActivity(it); } }); // inserir o bot�o na linha linha1.addView(bt1); // incrementar o contador de controlo cont++; } // inserir a linha criada tabela.addView(linha1); } // resto if (nAlunos % 4 != 0) { TableRow linha1 = new TableRow(getBaseContext()); linha1.setLayoutParams(linha.getLayoutParams()); for (int j = 0; j < nAlunos % 4; j++) { // ********************************** // Nome, id e foto do aluno final String alumni = nomeAluno[cont]; final int idAL = idAluno[cont]; final String alunFot = fotoAluno[cont]; // *********************************** // novo bot�o Button bt1 = new Button(bt.getContext()); // copiar os parametros do bot�o original bt1.setLayoutParams(bt.getLayoutParams()); // se o aluno tiver foto, vou busca-la if (fotoAluno[cont] != null) { String imageInSD = Environment.getExternalStorageDirectory().getAbsolutePath() + "/School-Data/Students/" + fotoAluno[cont]; Bitmap bitmap = BitmapFactory.decodeFile(imageInSD); ImageView imageView = new ImageView(this); // ajustar o tamanho da imagem imageView.setImageBitmap(Bitmap.createScaledBitmap(bitmap, 240, 240, false)); // enviar para o bot�o bt1.setCompoundDrawablesWithIntrinsicBounds(null, imageView.getDrawable(), null, null); } else { // sen�o copia a imagem do bot�o original bt1.setCompoundDrawables(null, bt.getCompoundDrawablesRelative()[1], null, null); } // addicionar o nome bt1.setText(nomeAluno[cont]); // Defenir o que faz o bot�o ao clicar bt1.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { // Entrar na activity Bundle wrap = new Bundle(); wrap.putString("Escola", Escola); wrap.putInt("Escola_ID", idEscola); wrap.putString("Professor", Professor); wrap.putInt("Professor_ID", idProfessor); wrap.putString("Foto_professor", FotoProf); wrap.putString("Turma", Turma); wrap.putInt("Turma_ID", idTurma); wrap.putString("Aluno", alumni); wrap.putInt("Aluno_ID", idAL); wrap.putString("Foto_Aluno", alunFot); Intent it = new Intent(getApplicationContext(), EscModo.class); it.putExtras(wrap); startActivity(it); } }); // inserir o bot�o na linha linha1.addView(bt1); // incrementar o contador de controlo cont++; } // inserir a linha criada tabela.addView(linha1); } // por fim escondo a 1� linha tabela.removeView(linha); }
private void setTopDrawable(Button v, int resId) { v.setCompoundDrawablesWithIntrinsicBounds( null, mContext.getResources().getDrawable(resId), null, null); }
/** * 首页底部四个按钮的事件 * * @param v */ public void showFragment(View v) { switch (v.getId()) { case R.id.bt_home: fm.beginTransaction() .hide(FragmentFactory.getFragment(MESSAGE)) .hide(FragmentFactory.getFragment(LOOKINGFORTEACHER)) .hide(FragmentFactory.getFragment(MYINFO)) .show(FragmentFactory.getFragment(HOME)) .commit(); bt_home.setCompoundDrawablesWithIntrinsicBounds( null, getResources().getDrawable(R.mipmap.tab_ico_home_pre), null, null); bt_search.setCompoundDrawablesWithIntrinsicBounds( null, getResources().getDrawable(R.mipmap.tab_ico_faxian), null, null); bt_message.setCompoundDrawablesWithIntrinsicBounds( null, getResources().getDrawable(R.mipmap.tab_ico_xiaoxi), null, null); bt_user.setCompoundDrawablesWithIntrinsicBounds( null, getResources().getDrawable(R.mipmap.tab_ico_me), null, null); break; case R.id.bt_search: fm.beginTransaction() .hide(FragmentFactory.getFragment(HOME)) .hide(FragmentFactory.getFragment(MESSAGE)) .hide(FragmentFactory.getFragment(MYINFO)) .show(FragmentFactory.getFragment(LOOKINGFORTEACHER)) .commit(); // startActivity(new Intent(this, SubjectFirstCategoryActivity.class)); bt_home.setCompoundDrawablesWithIntrinsicBounds( null, getResources().getDrawable(R.mipmap.tab_ico_home), null, null); bt_search.setCompoundDrawablesWithIntrinsicBounds( null, getResources().getDrawable(R.mipmap.tab_ico_faxian_pre), null, null); bt_message.setCompoundDrawablesWithIntrinsicBounds( null, getResources().getDrawable(R.mipmap.tab_ico_xiaoxi), null, null); bt_user.setCompoundDrawablesWithIntrinsicBounds( null, getResources().getDrawable(R.mipmap.tab_ico_me), null, null); break; case R.id.bt_user: // Intent intent = new Intent(this, LoginAndRightActivity.class); // startActivity(intent); fm.beginTransaction() .hide(FragmentFactory.getFragment(HOME)) .hide(FragmentFactory.getFragment(MESSAGE)) .hide(FragmentFactory.getFragment(LOOKINGFORTEACHER)) .show(FragmentFactory.getFragment(MYINFO)) .commit(); bt_home.setCompoundDrawablesWithIntrinsicBounds( null, getResources().getDrawable(R.mipmap.tab_ico_home), null, null); bt_search.setCompoundDrawablesWithIntrinsicBounds( null, getResources().getDrawable(R.mipmap.tab_ico_faxian), null, null); bt_message.setCompoundDrawablesWithIntrinsicBounds( null, getResources().getDrawable(R.mipmap.tab_ico_xiaoxi), null, null); bt_user.setCompoundDrawablesWithIntrinsicBounds( null, getResources().getDrawable(R.mipmap.tab_ico_me_pre), null, null); break; case R.id.bt_message: fm.beginTransaction() .hide(FragmentFactory.getFragment(HOME)) .hide(FragmentFactory.getFragment(LOOKINGFORTEACHER)) .hide(FragmentFactory.getFragment(MYINFO)) .show(FragmentFactory.getFragment(MESSAGE)) .commit(); bt_home.setCompoundDrawablesWithIntrinsicBounds( null, getResources().getDrawable(R.mipmap.tab_ico_home), null, null); bt_search.setCompoundDrawablesWithIntrinsicBounds( null, getResources().getDrawable(R.mipmap.tab_ico_faxian), null, null); bt_message.setCompoundDrawablesWithIntrinsicBounds( null, getResources().getDrawable(R.mipmap.tab_ico_xiaoxi_pre), null, null); bt_user.setCompoundDrawablesWithIntrinsicBounds( null, getResources().getDrawable(R.mipmap.tab_ico_me), null, null); break; } }
// Method to create a button, giving different functionality dependent on mode public void createButton( String name, final BluetoothDevice device, final BluetoothSocket socket, String mode, Boolean prox) { Button b = new Button(this); b.setAlpha(0f); b.setMinimumWidth(300); b.setMinimumHeight(80); b.setText(name); b.setTextColor(Color.argb(255, 0, 162, 232)); Button.OnClickListener btnclick = null; // If device is an IA if (mode.equals("IA")) { // Check if device should be activated on proximity if (prox) { OutputStream outStream; try { outStream = socket.getOutputStream(); String message = "1"; byte[] toSend = message.getBytes(); outStream.write(toSend); } catch (IOException e) { e.printStackTrace(); } } b.setCompoundDrawablesWithIntrinsicBounds(R.drawable.light_off, 0, 0, 0); btnclick = new Button.OnClickListener() { @Override public void onClick(View v) { final InputStream inStream; final OutputStream outStream; try { // Request current output level outStream = socket.getOutputStream(); String message = "r"; byte[] toSend = message.getBytes(); outStream.write(toSend); inStream = socket.getInputStream(); // Data collection is pending gotData = 1; // Run timer in thread to prevent stalling Thread getInput = new Thread( new Runnable() { @Override public void run() { try { // Give small delay Thread.sleep(100); byte byt[] = new byte[1]; // Check if reply from IA if (inStream.available() > 0) { int received = inStream.read(byt, 0, 1); inStream.read(); inStream.read(); if (received == 1) { // Toggle output power level if (((int) byt[0] & 0xff) == '0') { String message = "1"; byte[] toSend = message.getBytes(); outStream.write(toSend); } else if (((int) byt[0] & 0xff) == '1') { String message = "0"; byte[] toSend = message.getBytes(); outStream.write(toSend); } } // Data received gotData = 2; // Else no reply, IA has lost connection } else { // No data received gotData = 0; } } catch (Exception e) { e.getLocalizedMessage(); } } }); getInput.start(); // Wait until gotData is 0 or 2 while (gotData == 1) {} // If not data then notify and refresh if (gotData == 0) { Toast.makeText(getBaseContext(), R.string.no_data, Toast.LENGTH_LONG).show(); refresh(); } } catch (IOException e) { e.printStackTrace(); } } }; // Or if device is TA } else if (mode.equals("TA")) { b.setCompoundDrawablesWithIntrinsicBounds(R.drawable.tv_icon, 0, 0, 0); btnclick = new Button.OnClickListener() { @Override public void onClick(View v) { television(device.getAddress()); } }; } b.setOnClickListener(btnclick); final Button settingsButton = new Button(this); settingsButton.setHeight(60); settingsButton.setWidth(60); settingsButton.setBackgroundResource(R.drawable.settings); settingsButton.setTextColor(Color.argb(255, 0, 162, 232)); // Set associated variables settingsButton.setTag(R.string.zero, device.getAddress()); settingsButton.setTag(R.string.one, b); Button.OnClickListener popup = null; // TA settings if (mode.equals("TA")) { popup = new Button.OnClickListener() { @Override public void onClick(final View v) { PopupMenu popup = new PopupMenu(getApplicationContext(), settingsButton); // Use layout for TA settings popup.getMenuInflater().inflate(R.menu.device_options, popup.getMenu()); popup.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { // If rename button was pressed if (item.getTitle().equals("Rename")) { rename(v.getTag(R.string.zero), v.getTag(R.string.one)); } return true; } }); popup.show(); } }; // IA settings } else if (mode.equals("IA")) { popup = new Button.OnClickListener() { @Override public void onClick(final View v) { PopupMenu popup = new PopupMenu(getApplicationContext(), settingsButton); popup.getMenuInflater().inflate(R.menu.ia_device_options, popup.getMenu()); popup.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { if (item.getTitle().equals("Rename")) { rename(v.getTag(R.string.zero), v.getTag(R.string.one)); } SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); if (item.getTitle().equals("Activate on proximity")) { editor.putBoolean(device.getAddress() + "prox", true); editor.commit(); } if (item.getTitle().equals("Do not activate on proximity")) { editor.putBoolean(device.getAddress() + "prox", false); editor.commit(); } return true; } }); popup.show(); } }; } settingsButton.setOnClickListener(popup); // Add button to list and animate ViewGroup layout = (ViewGroup) findViewById(R.id.home_page); RelativeLayout LL = new RelativeLayout(this); LL.setMinimumHeight(90); settingsButton.setX(310); settingsButton.setY(10); Button cover = new Button(this); cover.setBackgroundResource(R.drawable.scroll_cover); cover.setX(10); cover.setHeight(80); Button block = new Button(this); block.setBackgroundColor(Color.BLACK); block.setX(10); block.setHeight(80); b.setAlpha(1f); appear(b); appearAndSlide(cover); appearAndHide(block); deleteObject(cover, 2000); deleteObject(block, 1000); delayedAppear(settingsButton); LL.addView(b); LL.addView(settingsButton); LL.addView(block); LL.addView(cover); layout.addView(LL); }
public void onClick(View v) { // Check if the answer is correct or not if (Integer.parseInt(v.getTag().toString()) == 1) { /*Toast.makeText(getBaseContext(), String.valueOf("Correct !"), Toast.LENGTH_SHORT).show(); */ Button btn = (Button) v; // cast the view to a button btn.setClickable(false); btn.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.correct, 0); CorrectAnswerListCounter--; if (CorrectAnswerListCounter < 1) { BtnContinue.setVisibility(View.VISIBLE); if (CorrectAnswerReasonInHTML != null && CorrectAnswerReasonInHTML.length() > 0) { BtnReason.setVisibility(View.VISIBLE); } // disable all the buttons for (int i = 0; i < ButtonArray.size(); i++) { Button btn_all = ButtonArray.get(i); btn_all.setEnabled(false); } cache.setYourCorrectAnswerResult(1); // Add one to result // Sound for right Answer OtherPreferences sharedPrefs = new OtherPreferences(this.getBaseContext()); if (sharedPrefs.getPreference("sound").equalsIgnoreCase("on")) { LocalCache cache = ((LocalCache) getApplicationContext()); cache.PlaySound(this, R.raw.clapping); } } else { Toast.makeText( getBaseContext(), String.valueOf("Select " + CorrectAnswerListCounter.toString() + " more"), Toast.LENGTH_SHORT) .show(); } } else if (Integer.parseInt(v.getTag().toString()) == 0) { /*Toast.makeText(getBaseContext(), String.valueOf("Wrong !"), Toast.LENGTH_SHORT).show(); */ for (int i = 0; i < ButtonArray.size(); i++) { Button btn = ButtonArray.get(i); Object tag = btn.getTag(); if (Integer.parseInt(tag.toString()) == 1) { String LastText = CorrectAnswerInHTMLList.get(CorrectAnswerInHTMLListCounter - 1).toString(); CorrectAnswerInHTMLListCounter--; // String LastText = CorrectAnswerInHTML; //+ " " + "✓"; btn.setText(Html.fromHtml(LastText)); btn.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.correct, 0); btn.setEnabled(false); } else { btn.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.wrong, 0); btn.setEnabled(false); } } BtnContinue.setVisibility(View.VISIBLE); if (CorrectAnswerReasonInHTML != null && CorrectAnswerReasonInHTML.length() > 0) { BtnReason.setVisibility(View.VISIBLE); } // Buzz for Wrong Answer OtherPreferences sharedPrefs = new OtherPreferences(this.getBaseContext()); if (sharedPrefs.getPreference("sound").equalsIgnoreCase("on")) { LocalCache cache = ((LocalCache) getApplicationContext()); cache.PlaySound(this, R.raw.cough); } } else if (Integer.parseInt(v.getTag().toString()) == 3) { showDialog(1); } else { NextQuestion(); } }
private void initBottomButton() { newsButton.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.tab1_normal, 0, 0); newsButton.setTextColor(getResources().getColor(R.color.calendar_header)); gameButton.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.tab2_normal, 0, 0); gameButton.setTextColor(getResources().getColor(R.color.calendar_header)); threadButton.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.tab3_normal, 0, 0); threadButton.setTextColor(getResources().getColor(R.color.calendar_header)); dataButton.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.tab4_normal, 0, 0); dataButton.setTextColor(getResources().getColor(R.color.calendar_header)); if (majorTeamGsonModel == null || TextUtils.isEmpty(majorTeamGsonModel.avatar)) { if (AppSharePreferences.getFollowFlag(getApplicationContext())) { majorImageView.setImageResource(R.drawable.tab_center_notset_normal); } else { majorImageView.setImageResource(R.drawable.tab_center_normal); } } else { File file = DiskCacheUtils.findInCache(majorTeamGsonModel.avatar, imageLoader.getDiskCache()); if (file == null || !file.exists()) { imageLoader.displayImage(majorTeamGsonModel.avatar, majorImageView, options); } else { majorImageView.setImageBitmap(BitmapFactory.decodeFile(file.getAbsolutePath())); } } mTitleView.setLeftButton(0); majorImageView.setBackgroundResource(R.drawable.main_tab_center); switch (index) { case 0: { mTitleView.setTitle(null); newsButton.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.tab1_selected, 0, 0); newsButton.setTextColor(getResources().getColor(R.color.title)); break; } case 1: { mTitleView.setTitle(getString(R.string.top_toolbar_small_online)); gameButton.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.tab2_selected, 0, 0); gameButton.setTextColor(getResources().getColor(R.color.title)); break; } case 2: { mTitleView.setTitle(null); // ((Button)v).setCompoundDrawablesWithIntrinsicBounds(0, // R.drawable.tab2_selected, 0, 0); if (majorTeamGsonModel == null || TextUtils.isEmpty(majorTeamGsonModel.avatar)) { if (AppSharePreferences.getFollowFlag(getApplicationContext())) { majorImageView.setImageResource(R.drawable.tab_center_notset_pressed); } else { majorImageView.setImageResource(R.drawable.tab_center_selected); } majorImageView.setBackgroundColor(getResources().getColor(R.color.title)); } else { if (!TextUtils.isEmpty(majorTeamGsonModel.color)) majorImageView.setBackgroundColor(Color.parseColor(majorTeamGsonModel.color)); else majorImageView.setBackgroundColor(getResources().getColor(R.color.title)); } if (AppSharePreferences.getFollowFlag(getApplicationContext())) mTitleView.setLeftButton(getString(R.string.feed_edit)); break; } case 3: { mTitleView.setTitle(getString(R.string.title_football_group)); threadButton.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.tab3_selected, 0, 0); threadButton.setTextColor(getResources().getColor(R.color.title)); break; } case 4: { mTitleView.setTitle(getString(R.string.title_football_top)); dataButton.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.tab4_selected, 0, 0); dataButton.setTextColor(getResources().getColor(R.color.title)); break; } } }
public void pressButtonById(int nIdPressed, boolean bSwitchActivity) { boolean bFoundButton = false; // Unpress all the buttons except the one we passed in for (Button bt : buttons) { if (nIdPressed == bt.getId()) { bFoundButton = true; // bt.setBackgroundResource(R.color.activity_bar_button_selected); // bt.setCompoundDrawablesWithIntrinsicBounds(null, drawableTop, null, null); System.out.println("nIdPressed: " + nIdPressed + ", bt Id: " + bt.getText()); if (bt.getText().equals("Haberler")) drawableTop = parentActivity.getResources().getDrawable(R.drawable.icon_haber_selected); else if (bt.getText().equals("Kurumsal")) drawableTop = parentActivity.getResources().getDrawable(R.drawable.icon_kurumsal_selected); else if (bt.getText().equals("Yönetim")) drawableTop = parentActivity.getResources().getDrawable(R.drawable.icon_yonetim_selected); else { // WEB TV drawableTop = parentActivity.getResources().getDrawable(R.drawable.icon_webtv_selected); } bt.setCompoundDrawablesWithIntrinsicBounds(null, drawableTop, null, null); } else { bt.setPressed(false); bt.setBackgroundResource(android.R.color.transparent); } } // If we asked to switch activities and the button passed in was good, do it if (bSwitchActivity && bFoundButton && nIdPressed != currentBtnId && parentActivity != null) { switch (nIdPressed) { case R.id.btnHaber: switchActivity(new Intent(parentActivity, Haberler.class)); break; case R.id.btnKurumsal: switchActivity(new Intent(parentActivity, Kurumsal.class)); break; case R.id.btnYonetim: switchActivity(new Intent(parentActivity, Yoneticiler.class)); break; case R.id.btnWebTv: // switchActivity(new Intent(parentActivity, WebTv.class)); /* Intent intent= new Intent(); intent.setAction("android.intent.action.VIEW"); Uri content_url = Uri.parse("http://www.chp.org.tr/custom-scripts/webtv.html"); intent.setData(content_url); intent.setClassName("com.android.chrome","com.android.chrome.mai"); startActivity(intent);*/ try { Intent i = new Intent("android.intent.action.MAIN"); i.setComponent( ComponentName.unflattenFromString("com.android.chrome/com.android.chrome.Main")); i.addCategory("android.intent.category.LAUNCHER"); i.setData(Uri.parse("http://www.chp.org.tr/custom-scripts/webtv.html")); parentActivity.startActivity(i); } catch (ActivityNotFoundException e) { // Chrome is probably not installed } /* Intent myIntent; PackageManager pm = parentActivity.getPackageManager(); try{ myIntent = pm.getLaunchIntentForPackage("com.mxtech.videoplayer.pro"); myIntent.setComponent(new ComponentName("com.mxtech.videoplayer.pro", "com.mxtech.videoplayer.ActivityScreen")); myIntent.setDataAndType(Uri.parse("http://www.chp.org.tr/custom-scripts/webtv.html"), "application/x-mpegURL"); myIntent.putExtra("secure_uri", true); //myIntent.putExtra(parentActivity.EXTRA_DECODE_MODE, (byte)2); if (null != myIntent) parentActivity.startActivity(myIntent); } catch (ActivityNotFoundException e) { Toast.makeText(parentActivity, " stream not working ", Toast.LENGTH_LONG).show(); }*/ break; } } currentBtnId = bFoundButton ? nIdPressed : -1; }