public void expandOrContractButton(View view) { ImageButton expandOrContract = (ImageButton) findViewById(view.getId()); Drawable expandImage = getResources().getDrawable(R.drawable.ic_expand_more_black); Drawable contractImage = getResources().getDrawable(R.drawable.ic_expand_less_black); // Use Icons to RepresentState if (expandOrContract .getTag() .toString() .equals(getResources().getString(R.string.expand))) { // if Expand, then contract expandOrContract.setImageDrawable(contractImage); expandOrContract.setTag(getResources().getString(R.string.contract)); if (expandOrContract.getId() == R.id.settings_general_image_button) { RelativeLayout layout = (RelativeLayout) findViewById(R.id.settings_general_views_layout); layout.setVisibility(View.VISIBLE); } else if (expandOrContract.getId() == R.id.settings_synchronisation_image_button) { RelativeLayout layout = (RelativeLayout) findViewById(R.id.settings_synchronisation_views); layout.setVisibility(View.VISIBLE); } } else { expandOrContract.setImageDrawable(expandImage); expandOrContract.setTag(getResources().getString(R.string.expand)); if (expandOrContract.getId() == R.id.settings_general_image_button) { RelativeLayout layout = (RelativeLayout) findViewById(R.id.settings_general_views_layout); layout.setVisibility(View.GONE); } else if (expandOrContract.getId() == R.id.settings_synchronisation_image_button) { RelativeLayout layout = (RelativeLayout) findViewById(R.id.settings_synchronisation_views); layout.setVisibility(View.GONE); } } }
public void onClick(View v) { if (elements.containsKey(v)) { ElementState es = elements.get(v); ImageButton tab = (ImageButton) v; if (!es.isFocused()) { // tab.setBackgroundResource(es.getFocusedIcon()); // es.setFocused(true); // unFocusOtherTab(v); Log.e("tab", tab.getId() + ""); // Right tab get user article if (tab.getId() == R.id.my_teams_tab1) { pabIndex = 1; if (act.getTeamList() == null | act.getTeamList().size() == 0) { act.displayNoGamesDialog(); } else { tab.setBackgroundResource(es.getFocusedIcon()); es.setFocused(true); unFocusOtherTab(v); act.setGameScore(); } } // Left Tab get score else if (tab.getId() == R.id.my_teams_tab2) { pabIndex = 2; tab.setBackgroundResource(es.getFocusedIcon()); es.setFocused(true); unFocusOtherTab(v); act.setArticles(); } } } }
@Override public void onClick(View v) { if (v.getId() == colorView.getId()) { ColorPickerDialog dialog = ColorPickerDialog.build(this); commandInterface.showDialog(dialog); } else { super.onClick(v); } }
@Override public void onClick(View v) { boolean continueModule = true; ActivityBeanCommunicator communicator = new ActivityBeanCommunicator(selectedBean.getId(), selectedBean.getFirst_name()); if (selectedBean.getIdAccount() == null) { Message.showShortExt("Este Contacto no Tiene Cuentas Asociadas", this); return; } Modules module = null; if (v.getId() == imageButtonAccounts.getId()) { ActivitiesMediator.getInstance() .showActivity( ContactActivity.this, Modules.ACCOUNTS, new ActivityBeanCommunicator(selectedBean.getIdAccount(), "")); return; } else if (v.getId() == imageButtonOpps.getId()) { module = Modules.OPPORTUNITIES; } else if (v.getId() == imageButtonTasks.getId()) { module = Modules.TASKS; } else if (v.getId() == imageButtonCalls.getId()) { module = Modules.CALLS; } else if (v.getId() == btnMakeCall.getId()) { continueModule = false; communicator.setAction(ActionActivity.MAKE_CALL); communicator.setAdditionalInfo(this.getPhoneNumer()); ActivitiesMediator.getInstance().setActualID(communicator, MODULE); ActivitiesMediator.getInstance().showEditActivity(this, Modules.CALLS, false); } if (continueModule) { ActivitiesMediator.getInstance() .setActualID( new ActivityBeanCommunicator(selectedBean.getIdAccount(), ""), Modules.ACCOUNTS); ActivitiesMediator.getInstance().setActualID(communicator, MODULE); ActivitiesMediator.getInstance().showList(ContactActivity.this, module, MODULE); } }
/** * This adds a divider at the bottom of this layout. Used to separate fields in lists. * * @param v */ public void addDivider(ImageView v) { RelativeLayout.LayoutParams dividerParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); if (mImageView != null) { dividerParams.addRule(RelativeLayout.BELOW, mImageView.getId()); } else if (mMissingImage != null) { dividerParams.addRule(RelativeLayout.BELOW, mMissingImage.getId()); } else if (mVideoButton != null) { dividerParams.addRule(RelativeLayout.BELOW, mVideoButton.getId()); } else if (mAudioButton != null) { dividerParams.addRule(RelativeLayout.BELOW, mAudioButton.getId()); } else if (mView_Text != null) { // No picture dividerParams.addRule(RelativeLayout.BELOW, mView_Text.getId()); } else { Log.e(t, "Tried to add divider to uninitialized ATVWidget"); return; } addView(v, dividerParams); }
@Override public void onClick(View view) { if (view.getId() == productName.getId()) { Bundle bundle = new Bundle(); bundle.putString("selectedJobNo", productName.getText().toString()); Fragment productIssue = new F_ProductIssue(); productIssue.setArguments(bundle); ((A_Entry) getActivity()).transferTo(productIssue, true); } else if (view.getId() == jobCompany.getId()) { Bundle bundle = new Bundle(); bundle.putString("comName", jobCompany.getText().toString()); Fragment companyDetails = new F_CompanyDetails(); companyDetails.setArguments(bundle); ((A_Entry) getActivity()).transferTo(companyDetails, true); } else if (view.getId() == btn_photo.getId()) { try { ((BitmapDrawable) image_preview.getDrawable()).getBitmap().recycle(); } catch (NullPointerException e) { } Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // fileURI = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); fileURI = getImageUri(); intent.putExtra(MediaStore.EXTRA_OUTPUT, fileURI); // set the image file name startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); } else if (view.getId() == btn_postpone.getId()) { for (int i = 0; i < jobStatusItem.length; i++) if (jobStatusItem[i].equals("postponed")) { jobStatus.setSelection(i); DatabaseView.exec( "UPDATE ServiceJob SET jobStatus = 'postponed' WHERE jobNo ='" + jobNo.getText().toString() + "'"); Toast.makeText( getActivity(), "Successful change the status to postpone!", Toast.LENGTH_SHORT) .show(); } } else if (view.getId() == btn_cancelJob.getId()) { for (int i = 0; i < jobStatusItem.length; i++) if (jobStatusItem[i].equals("cancelled")) { jobStatus.setSelection(i); DatabaseView.exec( "UPDATE ServiceJob SET jobStatus = 'cancelled' WHERE jobNo ='" + jobNo.getText().toString() + "'"); Toast.makeText( getActivity(), "Successful change the status to cancel!", Toast.LENGTH_SHORT) .show(); } } else if (view.getId() == btn_viewImage.getId()) { final AlertDialog.Builder ab = new AlertDialog.Builder(getActivity()); final ImageView iv = new ImageView(getActivity()); try { final Bitmap bm = convertJPG(getImageUri()); if (bm == null) return; iv.setImageBitmap(bm); ab.setView(iv); ab.setPositiveButton( "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) {} }); ab.show(); } catch (OutOfMemoryError e) { try { ((BitmapDrawable) iv.getDrawable()).getBitmap().recycle(); Toast.makeText(getActivity(), "Sorry, try again", Toast.LENGTH_SHORT).show(); e.printStackTrace(); } catch (Exception ee) { } } } else if (view.getId() == btn_viewSign.getId()) { final AlertDialog.Builder ab = new AlertDialog.Builder(getActivity()); final ImageView iv = new ImageView(getActivity()); try { final Bitmap bm = _signView.loadFromStorage(getActivity(), getSignViewFileName()); if (bm == null) return; iv.setImageBitmap(bm); ab.setView(iv); ab.setPositiveButton( "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) {} }); ab.show(); } catch (OutOfMemoryError e) { try { ((BitmapDrawable) iv.getDrawable()).getBitmap().recycle(); Toast.makeText(getActivity(), "Sorry, try again", Toast.LENGTH_SHORT).show(); e.printStackTrace(); } catch (Exception ee) { } } } }
private void init() { mCurrentDirectory = Environment.getExternalStorageDirectory(); mInitialDirectory = Environment.getExternalStorageDirectory(); this.setBackgroundResource(R.drawable.bg_pathbar); this.setInAnimation(getContext(), R.anim.fade_in); this.setOutAnimation(getContext(), R.anim.fade_out); // RelativeLayout1 RelativeLayout standardModeLayout = new RelativeLayout(getContext()); { // I use a block here so that layoutParams can be used as a variable name further down. android.widget.ViewFlipper.LayoutParams layoutParams = new android.widget.ViewFlipper.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); standardModeLayout.setLayoutParams(layoutParams); this.addView(standardModeLayout); } // ImageButton -- GONE. Kept this code in case we need to use an right-aligned button in the // future. mSwitchToManualModeButton = new ImageButton(getContext()); { android.widget.RelativeLayout.LayoutParams layoutParams = new android.widget.RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); mSwitchToManualModeButton.setLayoutParams(layoutParams); mSwitchToManualModeButton.setId(10); mSwitchToManualModeButton.setImageResource(R.drawable.ic_navbar_edit); mSwitchToManualModeButton.setBackgroundResource(R.drawable.bg_navbar_btn); mSwitchToManualModeButton.setVisibility(View.GONE); standardModeLayout.addView(mSwitchToManualModeButton); } // ImageButton -- GONE. Kept this code in case we need to use an left-aligned button in the // future. ImageButton cdToRootButton = new ImageButton(getContext()); { android.widget.RelativeLayout.LayoutParams layoutParams = new android.widget.RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); cdToRootButton.setLayoutParams(layoutParams); cdToRootButton.setId(11); cdToRootButton.setBackgroundResource(R.drawable.bg_navbar_btn); cdToRootButton.setImageResource(R.drawable.ic_navbar_home); cdToRootButton.setScaleType(ScaleType.CENTER_INSIDE); cdToRootButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { cd("/"); } }); cdToRootButton.setVisibility(View.GONE); standardModeLayout.addView(cdToRootButton); } // Horizontal ScrollView container mPathButtonsContainer = new HorizontalScrollView(getContext()); { android.widget.RelativeLayout.LayoutParams layoutParams = new android.widget.RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); layoutParams.addRule(RelativeLayout.LEFT_OF, mSwitchToManualModeButton.getId()); layoutParams.addRule(RelativeLayout.RIGHT_OF, cdToRootButton.getId()); layoutParams.alignWithParent = true; mPathButtonsContainer.setLayoutParams(layoutParams); mPathButtonsContainer.setHorizontalScrollBarEnabled(false); mPathButtonsContainer.setHorizontalFadingEdgeEnabled(true); standardModeLayout.addView(mPathButtonsContainer); } // PathButtonLayout mPathButtons = new PathButtonLayout(getContext()); { android.widget.LinearLayout.LayoutParams layoutParams = new android.widget.LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); mPathButtons.setLayoutParams(layoutParams); mPathButtons.setNavigationBar(this); mPathButtonsContainer.addView(mPathButtons); } // RelativeLayout2 RelativeLayout manualModeLayout = new RelativeLayout(getContext()); { android.widget.ViewFlipper.LayoutParams layoutParams = new android.widget.ViewFlipper.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); manualModeLayout.setLayoutParams(layoutParams); this.addView(manualModeLayout); } // ImageButton mGoButton = new ImageButton(getContext()); { android.widget.RelativeLayout.LayoutParams layoutParams = new android.widget.RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); mGoButton.setLayoutParams(layoutParams); mGoButton.setId(20); mGoButton.setBackgroundResource(R.drawable.bg_navbar_btn); mGoButton.setImageResource(R.drawable.ic_navbar_accept); mGoButton.setScaleType(ScaleType.CENTER_INSIDE); mGoButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { manualInputCd(mPathEditText.getText().toString()); } }); manualModeLayout.addView(mGoButton); } // EditText mPathEditText = new EditText(getContext()); { android.widget.RelativeLayout.LayoutParams layoutParams = new android.widget.RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); layoutParams.alignWithParent = true; layoutParams.addRule(RelativeLayout.LEFT_OF, mGoButton.getId()); mPathEditText.setLayoutParams(layoutParams); mPathEditText.setBackgroundResource(R.drawable.bg_navbar_textfield); mPathEditText.setTextColor(Color.BLACK); mPathEditText.setInputType(InputType.TYPE_TEXT_VARIATION_URI); mPathEditText.setImeOptions(EditorInfo.IME_ACTION_GO); mPathEditText.setOnEditorActionListener( new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_GO || (event.getAction() == KeyEvent.ACTION_DOWN && (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER || event.getKeyCode() == KeyEvent.KEYCODE_ENTER))) { if (manualInputCd(v.getText().toString())) // Since we have successfully navigated. return true; } return false; } }); manualModeLayout.addView(mPathEditText); } }
/** Animates the pause button to a play button. */ private void animatePauseToPlay() { // Check to make sure the current icon is the pause icon. if (mPlayPauseButton.getId() != R.drawable.pause_light) return; // Scale out the pause button. final ScaleAnimation scaleOut = new ScaleAnimation( 1.0f, 0.0f, 1.0f, 0.0f, mPlayPauseButton.getWidth() / 2, mPlayPauseButton.getHeight() / 2); scaleOut.setDuration(150); scaleOut.setInterpolator(new AccelerateInterpolator()); // Scale in the play button. final ScaleAnimation scaleIn = new ScaleAnimation( 0.0f, 1.0f, 0.0f, 1.0f, mPlayPauseButton.getWidth() / 2, mPlayPauseButton.getHeight() / 2); scaleIn.setDuration(150); scaleIn.setInterpolator(new DecelerateInterpolator()); scaleOut.setAnimationListener( new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) {} @Override public void onAnimationEnd(Animation animation) { mPlayPauseButton.setImageResource(R.drawable.play_light); mPlayPauseButton.setPadding(0, 0, -5, 0); mPlayPauseButton.startAnimation(scaleIn); } @Override public void onAnimationRepeat(Animation animation) {} }); scaleIn.setAnimationListener( new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) {} @Override public void onAnimationEnd(Animation animation) { mPlayPauseButton.setScaleX(1.0f); mPlayPauseButton.setScaleY(1.0f); mPlayPauseButton.setId(R.drawable.play_light); } @Override public void onAnimationRepeat(Animation animation) {} }); mPlayPauseButton.startAnimation(scaleOut); }
/** the only OnClickListener's method * our own send button or tab button pressed */ @Override public void onClick(View v) { if (v.getId() == uiSend.getId()) sendMessage(); else if (v.getId() == uiTab.getId()) tryTabComplete(); }
@Override public void onClick(View v) { if (v.getId() == tv_fullname.getId() || v.getId() == tv_username.getId()) { // GOTO PROFILE WHEN NAME OR USERNAME IS CLICKED Intent i = new Intent(context, ProfileActivity.class); i.putExtra("UserId", userId); context.startActivity(i); } else if (v.getId() == R.id.pt_commentBtn) { Intent i = new Intent(context, CommentActivity.class); i.putExtra("PostId", postId); i.putExtra("FullName", tv_fullname.getText().toString()); i.putExtra("isOwned", owned); context.startActivity(i); ((Activity) context).overridePendingTransition(R.animator.animate3, R.animator.animate2); } else if (v.getId() == R.id.pt_shareBtn) { Intent i = new Intent(context, ShareActivity.class); if (share_postId.equals("")) i.putExtra("PostId", postId); else i.putExtra("PostId", share_postId); i.putExtra("OwnerId", schoolId); context.startActivity(i); ((Activity) context).overridePendingTransition(R.animator.animate3, R.animator.animate2); } else if (v.getId() == upvote.getId()) { upvote.setVisibility(View.INVISIBLE); upvote2.setVisibility(View.VISIBLE); Intent intent = new Intent(context, UpvoteService.class); intent.putExtra("userId", schoolId); intent.putExtra("postId", postId); context.startService(intent); } else if (v.getId() == upvote2.getId()) { upvote2.setVisibility(View.INVISIBLE); upvote.setVisibility(View.VISIBLE); Intent intent = new Intent(context, UpvoteService.class); intent.putExtra("userId", schoolId); intent.putExtra("postId", postId); context.startService(intent); } else if (v.getId() == options.getId()) { // Creating the instance of PopupMenu PopupMenu popup = new PopupMenu(context, options); // Inflating the Popup using xml file if (owned) { popup.getMenuInflater().inflate(R.menu.menu_options, popup.getMenu()); } else { popup.getMenuInflater().inflate(R.menu.menu_options2, popup.getMenu()); } // registering popup with OnMenuItemClickListener popup.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { if (item.getTitle().equals("Report")) { Intent i = new Intent(context, ReportActivity.class); i.putExtra("PostId", postId); i.putExtra("ReporterId", schoolId); i.putExtra("ReferenceTable", "post"); context.startActivity(i); } else if (item.getTitle().equals("Edit")) { Intent i = new Intent(context, EditPostActivity.class); i.putExtra("PostId", postId); context.startActivity(i); } else { Intent i = new Intent(context, DeleteService.class); i.putExtra("PostId", postId); i.putExtra("Action", "post"); context.startService(i); } return true; } }); popup.show(); // showing popup menu } else if (v.getId() == fileCV.getId()) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(fileUrl)); context.startActivity(browserIntent); } else if (v.getId() == share_file_name.getId()) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(shareFileUrl)); context.startActivity(browserIntent); } else { // GOTO VIEW POST Intent i = new Intent(context, PostViewActivity.class); i.putExtra("PostId", postId); context.startActivity(i); } }
public void setAVT(FormIndex index, String selectionDesignator, TextView text, String audioURI, String imageURI, String videoURI, final String bigImageURI) { mSelectionDesignator = selectionDesignator; mIndex = index; mView_Text = text; mView_Text.setId(QuestionWidget.newUniqueId()); mVideoURI = videoURI; // Layout configurations for our elements in the relative layout RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams audioParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams videoParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); // First set up the audio button if (audioURI != null) { // An audio file is specified mAudioButton = new AudioButton(getContext(), mIndex, mSelectionDesignator, audioURI); mAudioButton.setId(QuestionWidget.newUniqueId()); // random ID to be used by the // relative layout. } else { // No audio file specified, so ignore. } // Then set up the video button if (videoURI != null) { // An video file is specified mVideoButton = new ImageButton(getContext()); Bitmap b = BitmapFactory.decodeResource(getContext().getResources(), android.R.drawable.ic_media_play); mVideoButton.setImageBitmap(b); mVideoButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Collect.getInstance().getActivityLogger().logInstanceAction(this, "onClick", "playVideoPrompt"+mSelectionDesignator, mIndex); MediaLayout.this.playVideo(); } }); mVideoButton.setId(QuestionWidget.newUniqueId()); } else { // No video file specified, so ignore. } // Now set up the image view String errorMsg = null; final int imageId = QuestionWidget.newUniqueId(); if (imageURI != null) { try { String imageFilename = ReferenceManager._().DeriveReference(imageURI).getLocalURI(); final File imageFile = new File(imageFilename); if (imageFile.exists()) { Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); int screenWidth = display.getWidth(); int screenHeight = display.getHeight(); Bitmap b = FileUtils.getBitmapScaledToDisplay(imageFile, screenHeight, screenWidth); if (b != null) { mImageView = new ImageView(getContext()); mImageView.setPadding(2, 2, 2, 2); mImageView.setBackgroundColor(Color.WHITE); mImageView.setImageBitmap(b); mImageView.setId(imageId); if (bigImageURI != null) { mImageView.setOnClickListener(new OnClickListener() { String bigImageFilename = ReferenceManager._() .DeriveReference(bigImageURI).getLocalURI(); File bigImage = new File(bigImageFilename); @Override public void onClick(View v) { Collect.getInstance().getActivityLogger().logInstanceAction(this, "onClick", "showImagePromptBigImage"+mSelectionDesignator, mIndex); Intent i = new Intent("android.intent.action.VIEW"); i.setDataAndType(Uri.fromFile(bigImage), "image/*"); try { getContext().startActivity(i); } catch (ActivityNotFoundException e) { Toast.makeText( getContext(), getContext().getString(R.string.activity_not_found, "view image"), Toast.LENGTH_SHORT).show(); } } }); } } else { // Loading the image failed, so it's likely a bad file. errorMsg = getContext().getString(R.string.file_invalid, imageFile); } } else { // We should have an image, but the file doesn't exist. errorMsg = getContext().getString(R.string.file_missing, imageFile); } if (errorMsg != null) { // errorMsg is only set when an error has occurred Log.e(t, errorMsg); mMissingImage = new TextView(getContext()); mMissingImage.setText(errorMsg); mMissingImage.setPadding(10, 10, 10, 10); mMissingImage.setId(imageId); } } catch (InvalidReferenceException e) { Log.e(t, "image invalid reference exception"); e.printStackTrace(); } } else { // There's no imageURI listed, so just ignore it. } // e.g., for TextView that flag will be true boolean isNotAMultipleChoiceField = !RadioButton.class.isAssignableFrom(text.getClass()) && !CheckBox.class.isAssignableFrom(text.getClass()); // Determine the layout constraints... // Assumes LTR, TTB reading bias! if (mView_Text.getText().length() == 0 && (mImageView != null || mMissingImage != null)) { // No text; has image. The image is treated as question/choice icon. // The Text view may just have a radio button or checkbox. It // needs to remain in the layout even though it is blank. // // The image view, as created above, will dynamically resize and // center itself. We want it to resize but left-align itself // in the resized area and we want a white background, as otherwise // it will show a grey bar to the right of the image icon. if (mImageView != null) { mImageView.setScaleType(ScaleType.FIT_START); } // // In this case, we have: // Text upper left; image upper, left edge aligned with text right edge; // audio upper right; video below audio on right. textParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); textParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); if (isNotAMultipleChoiceField) { imageParams.addRule(RelativeLayout.CENTER_HORIZONTAL); } else { imageParams.addRule(RelativeLayout.RIGHT_OF, mView_Text.getId()); } imageParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); if (mAudioButton != null && mVideoButton == null) { audioParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); imageParams.addRule(RelativeLayout.LEFT_OF, mAudioButton.getId()); } else if (mAudioButton == null && mVideoButton != null) { videoParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); imageParams.addRule(RelativeLayout.LEFT_OF, mVideoButton.getId()); } else if (mAudioButton != null && mVideoButton != null) { audioParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); imageParams.addRule(RelativeLayout.LEFT_OF, mAudioButton.getId()); videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); videoParams.addRule(RelativeLayout.BELOW, mAudioButton.getId()); imageParams.addRule(RelativeLayout.LEFT_OF, mVideoButton.getId()); } else { // the image will implicitly scale down to fit within parent... // no need to bound it by the width of the parent... if (!isNotAMultipleChoiceField) { imageParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } } imageParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); } else { // We have a non-blank text label -- image is below the text. // In this case, we want the image to be centered... if (mImageView != null) { mImageView.setScaleType(ScaleType.FIT_START); } // // Text upper left; audio upper right; video below audio on right. // image below text, audio and video buttons; left-aligned with text. textParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); textParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); if (mAudioButton != null && mVideoButton == null) { audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); textParams.addRule(RelativeLayout.LEFT_OF, mAudioButton.getId()); } else if (mAudioButton == null && mVideoButton != null) { videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); textParams.addRule(RelativeLayout.LEFT_OF, mVideoButton.getId()); } else if (mAudioButton != null && mVideoButton != null) { audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); textParams.addRule(RelativeLayout.LEFT_OF, mAudioButton.getId()); videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); videoParams.addRule(RelativeLayout.BELOW, mAudioButton.getId()); } else { textParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } if (mImageView != null || mMissingImage != null) { imageParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); imageParams.addRule(RelativeLayout.CENTER_HORIZONTAL); imageParams.addRule(RelativeLayout.BELOW, mView_Text.getId()); } else { textParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); } } addView(mView_Text, textParams); if (mAudioButton != null) addView(mAudioButton, audioParams); if (mVideoButton != null) addView(mVideoButton, videoParams); if (mImageView != null) addView(mImageView, imageParams); else if (mMissingImage != null) addView(mMissingImage, imageParams); }