@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); LinearLayout myLayout = new LinearLayout(this); myLayout.setOrientation(LinearLayout.VERTICAL); input1 = new EditText(this); output1 = new TextView(this); button1 = new Button(this); bannerText = new TextView(this); myLayout.setOrientation(LinearLayout.VERTICAL); myLayout.setGravity(Gravity.CENTER_HORIZONTAL); myLayout.setBackgroundColor(Color.LTGRAY); bannerText.setWidth(300); bannerText.setGravity(Gravity.CENTER_HORIZONTAL); bannerText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 50); bannerText.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD); bannerText.setText(" Currency Converter from Dollar $ to Birr"); bannerText.setTextColor(Color.BLUE); bannerText.setPadding(0, 0, 0, 10); input1.setHint("Enter Dollar amount"); button1.setText("Convert to Birr!"); output1.setText("0"); output1.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30); output1.setPadding(0, 20, 0, 20); output1.setWidth(150); output1.setGravity(Gravity.CENTER_HORIZONTAL); output1.setTextColor(Color.WHITE); // button1.setOnClickListener(myListener); button1.setOnClickListener(this); myLayout.addView(bannerText); myLayout.addView(input1); myLayout.addView(output1); myLayout.addView(button1); LinearLayout.LayoutParams parm = new RadioGroup.LayoutParams(300, 100); input1.setLayoutParams(parm); output1.setLayoutParams(parm); button1.setLayoutParams(parm); setContentView(myLayout); input1.setLayoutParams(new LinearLayout.LayoutParams(225, 50)); button1.setLayoutParams(new LinearLayout.LayoutParams(170, 50)); // button2.setLayoutParams(new LinearLayout.LayoutParams(170, 50)); }
private void initBarButtons() { final LinearLayout.LayoutParams llButtonParams = new LinearLayout.LayoutParams(buttonWidth, buttonWidth); llButtonParams.setMargins(0, 0, buttonMargin, 0); undoButton.setBackgroundResource(R.drawable.undo_button_selector); undoButton.setPadding(0, 0, 0, 0); undoButton.setLayoutParams(llButtonParams); this.addView(undoButton); redoButton.setBackgroundResource(R.drawable.redo_button_selector); redoButton.setPadding(0, 0, 0, 0); redoButton.setLayoutParams(llButtonParams); this.addView(redoButton); // Tool radio group LayoutParams radioGroupParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); radioGroupParams.setMargins(0, 0, 0, 0); final RadioGroup toolRadioGroup = new RadioGroup(this.getContext()); toolRadioGroup.setOrientation(RadioGroup.HORIZONTAL); toolRadioGroup.setLayoutParams(radioGroupParams); toolRadioGroup.setPadding(0, 0, 0, 0); final RadioGroup.LayoutParams rgButtonParams = new RadioGroup.LayoutParams(buttonWidth, buttonWidth); rgButtonParams.setMargins(0, 0, buttonMargin, 0); selectButton.setButtonDrawable(R.drawable.select_button_selector); selectButton.setLayoutParams(rgButtonParams); toolRadioGroup.addView(selectButton); eraserButton.setButtonDrawable(R.drawable.erase_button_selector); eraserButton.setLayoutParams(rgButtonParams); toolRadioGroup.addView(eraserButton); for (int i = 0; i < 8; i++) { penButtons[i] = new PenRadioButton(this.getContext()); penButtons[i].setLayoutParams(rgButtonParams); toolRadioGroup.addView(penButtons[i]); } this.addView(toolRadioGroup); menuButtonSpacer.setLayoutParams( new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f)); this.addView(menuButtonSpacer); menuButton.setBackgroundResource(R.drawable.ic_action_overflow); menuButton.setPadding(0, 0, 0, 0); menuButton.setLayoutParams(llButtonParams); menuButton.setOnClickListener(menuButtonListener); this.addView(menuButton); }
private void showInvitations() { GridLayout.Spec row; GridLayout.Spec column; GridLayout.LayoutParams params; for (Invitation i : invitations) { final TextView tempText = new TextView(getApplicationContext()); tempText.setText(i.getNomFoyer()); tempText.setTextSize(18); row = GridLayout.spec(mainLayout.getRowCount()); column = GridLayout.spec(0); params = new GridLayout.LayoutParams(row, column); params.setGravity(Gravity.FILL_HORIZONTAL); tempText.setLayoutParams(params); mainLayout.addView(tempText); Button tempAcceptButton = new Button(getApplicationContext(), null, android.R.attr.buttonStyleSmall); tempAcceptButton.setText(R.string.show_invitations_accept); column = GridLayout.spec(1); params = new GridLayout.LayoutParams(row, column); tempAcceptButton.setLayoutParams(params); tempAcceptButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { accept(tempText.getText().toString(), mainLayout.getFocusedChild()); } }); mainLayout.addView(tempAcceptButton); Button tempRefuseButton = new Button(getApplicationContext(), null, android.R.attr.buttonStyleSmall); tempRefuseButton.setText(R.string.show_invitations_refuse); column = GridLayout.spec(2); params = new GridLayout.LayoutParams(row, column); tempRefuseButton.setLayoutParams(params); tempRefuseButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { refuse(tempText.getText().toString(), mainLayout.getFocusedChild()); } }); mainLayout.addView(tempRefuseButton); } }
private void setMarginsOnBtns(int midScreen) { Button btn = (Button) this.findViewById(R.id.playBtn); RelativeLayout.LayoutParams playParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); playParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); playParams.setMargins(midScreen + 100, 0, 0, 0); btn.setLayoutParams(playParams); Button btn2 = (Button) this.findViewById(R.id.passBtn); RelativeLayout.LayoutParams passParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); passParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); passParams.setMargins(midScreen - 100 - btn2.getWidth(), 0, 0, 0); btn2.setLayoutParams(passParams); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DBHelper dbHelper = DBHelper.getInstance(getApplicationContext()); setContentView(R.layout.activity_buoc); LinearLayout gardenLayout = (LinearLayout) findViewById(R.id.gardenLayoutLinear); // create buttons to put inside linear layout int counter = 1; for (int rows = 0; rows < 10; rows++) { LinearLayout currentLinear = new LinearLayout(this); currentLinear.setOrientation(LinearLayout.HORIZONTAL); for (int cols = 0; cols < 3; cols++) { final Button currButton = new Button(this); LinearLayout.LayoutParams param; param = new LinearLayout.LayoutParams( Toolbar.LayoutParams.WRAP_CONTENT, Toolbar.LayoutParams.WRAP_CONTENT, 1.0f); currButton.setLayoutParams(param); currButton.setWidth(50); currButton.setHeight(125); currButton.setGravity(Gravity.CENTER); currButton.setId(counter); currButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { redirectToBedOptions(currButton); } }); currButton.setText("" + currButton.getId()); currentLinear.addView(currButton); counter++; } gardenLayout.addView(currentLinear); } // Grab the first five garden notes and display them in the notes section // for now we will mock up data to show. final ListView gardenNotePreviewList = (ListView) findViewById(R.id.gardenNotePreviewList); Note mock_up_data[] = null; try { mock_up_data = new Note[5]; mock_up_data[0] = new Note("Warning signs around garden", ""); mock_up_data[1] = new Note("Cleaned around garden.", ""); mock_up_data[2] = new Note("Created new Garden Worksheet.", ""); mock_up_data[3] = new Note("subject 4", ""); mock_up_data[4] = new Note("subject 5", ""); } catch (Exception ex) { ex.printStackTrace(); } GardenLayoutNotePreviewListAdapter adapter = new GardenLayoutNotePreviewListAdapter(this, R.layout.custom_garden_note, mock_up_data); gardenNotePreviewList.setAdapter(adapter); }
void initControl(Context ctx) { this.setBackground(ctx.getResources().getDrawable(R.drawable.sticky_note_background)); this.setWeightSum(1.0f); this.setOrientation(LinearLayout.VERTICAL); writingCanvas = new NoteWritingCanvas(ctx); LinearLayout.LayoutParams writingCanvasLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 0.95f); writingCanvasLayoutParams.topMargin = 5; writingCanvasLayoutParams.leftMargin = 2; writingCanvasLayoutParams.rightMargin = 2; writingCanvas.setLayoutParams(writingCanvasLayoutParams); writingCanvas.setWritingEventListener(this); this.addView(writingCanvas); okButton = new Button(ctx); okButton.setBackgroundResource(R.drawable.ok_button); LinearLayout.LayoutParams buttonLayoutParams = new LinearLayout.LayoutParams(75, 75); buttonLayoutParams.gravity = Gravity.BOTTOM | Gravity.END; okButton.setLayoutParams(buttonLayoutParams); okButton.setEnabled(false); okButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub okButton.setEnabled(false); if (contentSubmittedListener != null) { contentSubmittedListener.contentSubmittedEventHandler(myself); } } }); this.addView(okButton); }
public static void addButton( final Fragment fragment, ViewGroup layout, final String title, final String onClick, final Class<?>[] parameters, final Object[] objects) { Button button = new Button(fragment.getActivity()); LayoutParams params = new LayoutParams(); params.width = 200 * getDensity(fragment.getActivity()); params.height = 100; button.setLayoutParams(params); button.setText(title); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (parameters == null) { invoke(fragment, onClick); } else { invoke(fragment, onClick, parameters, objects); } } }); layout.addView(button); }
private void addButtons(LinearLayout mainContainer, int id) { int identifier[] = {BUTTON_CLEAR, BUTTON_OK, BUTTON_CANCEL}; LinearLayout.LayoutParams row_Params = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams box_Params = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ConvertToPx(mContext, 45), 1f); box_Params.setMargins( ConvertToPx(mContext, 4), ConvertToPx(mContext, 9), ConvertToPx(mContext, 4), ConvertToPx(mContext, 9)); LinearLayout row = new LinearLayout(mContext); row.setOrientation(LinearLayout.HORIZONTAL); row.setLayoutParams(row_Params); mainContainer.addView(row); for (int i = 0; i < 3; i++) { Button tv = new Button(mContext); tv.setText(getText(identifier[i])); String tvTag; if (identifier[i] == BUTTON_OK) tvTag = id + DELIMITER + getText(identifier[i]); else tvTag = identifier[i] + DELIMITER + getText(identifier[i]); tv.setTag(tvTag); tv.setTextColor(Color.BLACK); tv.setBackgroundResource(R.drawable.btn_white_transparency_20); tv.setGravity(Gravity.CENTER); tv.setPadding(0, ConvertToPx(mContext, 2), 0, 0); tv.setLayoutParams(box_Params); tv.setOnClickListener(Process_Input); row.addView(tv); } }
private void init() { setHardwareAccelerated(true); boolean hasShot = getContext() .getSharedPreferences(PREFS_SHOWCASE_INTERNAL, Context.MODE_PRIVATE) .getBoolean("hasShot" + getConfigOptions().showcaseId, false); if (hasShot && mOptions.shotType == TYPE_ONE_SHOT) { // The showcase has already been shot once, so we don't need to do anything setVisibility(View.GONE); mIsRedundant = true; return; } mShowcaseRadius = mMetricScale * INNER_CIRCLE_RADIUS; setOnTouchListener(this); if (!mOptions.noButton && mEndButton.getParent() == null) { RelativeLayout.LayoutParams lps = getConfigOptions().buttonLayoutParams; if (lps == null) { lps = (LayoutParams) generateDefaultLayoutParams(); lps.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); lps.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); int margin = ((Number) (mMetricScale * 12)).intValue(); lps.setMargins(margin, margin, margin, margin); } mEndButton.setLayoutParams(lps); mEndButton.setText(mButtonText != null ? mButtonText : getResources().getString(R.string.ok)); if (!mHasCustomClickListener) { mEndButton.setOnClickListener(this); } addView(mEndButton); } }
// shared image container private RelativeLayout getThumbView() { rlThumb = new RelativeLayout(getContext()); rlThumb.setId(1); int dp_82 = dipToPx(getContext(), 82); int dp_98 = dipToPx(getContext(), 98); LayoutParams lpThumb = new LayoutParams(dp_82, dp_98); rlThumb.setLayoutParams(lpThumb); ivImage = new ImageView(getContext()); int resId = getBitmapRes(activity, "btn_back_nor"); if (resId > 0) { ivImage.setBackgroundResource(resId); } ivImage.setScaleType(ScaleType.CENTER_INSIDE); ivImage.setImageBitmap(image); int dp_4 = dipToPx(getContext(), 4); ivImage.setPadding(dp_4, dp_4, dp_4, dp_4); int dp_74 = dipToPx(getContext(), 74); RelativeLayout.LayoutParams lpImage = new RelativeLayout.LayoutParams(dp_74, dp_74); int dp_16 = dipToPx(getContext(), 16); int dp_8 = dipToPx(getContext(), 8); lpImage.setMargins(0, dp_16, dp_8, 0); ivImage.setLayoutParams(lpImage); ivImage.setOnClickListener( new OnClickListener() { public void onClick(View v) { if (image != null && !image.isRecycled()) { PicViewer pv = new PicViewer(); pv.setImageBitmap(image); pv.show(activity, null); } } }); rlThumb.addView(ivImage); Button btn = new Button(getContext()); btn.setOnClickListener( new OnClickListener() { public void onClick(View v) { // remove the photo to share rlThumb.setVisibility(View.GONE); ivPin.setVisibility(View.GONE); removeImage(imgInfo); } }); resId = getBitmapRes(activity, "img_cancel"); if (resId > 0) { btn.setBackgroundResource(resId); } int dp_20 = dipToPx(getContext(), 20); RelativeLayout.LayoutParams lpBtn = new RelativeLayout.LayoutParams(dp_20, dp_20); lpBtn.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); lpBtn.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); btn.setLayoutParams(lpBtn); rlThumb.addView(btn); rlThumb.setVisibility(View.GONE); return rlThumb; }
@Override public View onCreateView( LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { drawer = (MaterialNavigationDrawer) getActivity(); Button button = new Button(this.getActivity()); button.setText("start child fragment"); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); button.setLayoutParams(params); button.setGravity(Gravity.CENTER); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { drawer.changeFragment(new ChildFragment(), "Child Title"); // normally currentSection gets unselect on setCustomFragment call // in the next relase, i will add a new method without unselect drawer.getCurrentSectionFragment().select(); // call on current git head. drawer.getCurrentSectionFragment().select(); is not needed // drawer.setCustomFragment(drawer.getCurrentSectionFragment().getTargetFragment(), // drawer.getCurrentSectionFragment().getFragmentTitle(), true, false); } }); return button; }
/** * BATTLEボタンを画面に設定する * * @param type */ public void setDealButton() { Button button = new Button(this.activity); button.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // 戦闘シーンへ移動するため、値を戻す BattleSceneCardSelection.threeCardselected = false; // 戦闘シーンへ移動 callChangeNexrScene(); } }); BattleLayout.LayoutParams params = new BattleLayout.LayoutParams( BattleLayout.LayoutParams.MATCH_PARENT, this.activity.baseLayout.getHeight() * 1 / 3); params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); params.addRule(RelativeLayout.ALIGN_PARENT_TOP); params.setMargins((int) (0), (int) (this.activity.baseLayout.getHeight() * 2 / 3), 0, 0); button.setLayoutParams(params); button.setBackgroundResource(R.drawable.battle_battle_button); // 戦闘ベース部品にcard追加する this.activity.baseLayout.addView(button, params); }
/** * Zooms in or out of the board by scalling the size of each Box * * @param big increase or decrease the size */ public void resizeMe(int big) { double resizeButton = 0.0; double resizeText = 0.0; boolean myCondition = false; if (big == 0) { resizeButton = 1.25; resizeText = 0.3125; myCondition = true; } else { resizeButton = 0.8; resizeText = 0.3125; myCondition = false; } for (int x = 0; x < this.getX(); ++x) { for (int y = 0; y < this.getY(); ++y) { Button change = this.board[x][y]; LayoutParams params = change.getLayoutParams(); if (((change.getHeight() * resizeButton > 70.0) && !myCondition) || ((change.getHeight() * resizeButton < 130.0) && myCondition)) { params.height = (int) (change.getHeight() * resizeButton); params.width = (int) (change.getWidth() * resizeButton); change.setLayoutParams(params); change.setTextSize((float) (params.height * resizeText)); } } } }
private void fillUI() { // add logic in order not to set twice values, loader get's called twice. Picasso.with(getContext()).load(mMovie.getPosterUri()).into(mImageView); mTitle.setText(mMovie.getTitle()); mDate.setText(mMovie.getReleaseDate().trim().substring(0, 4)); if (mMovie.getVoteAverage() != null) mVote.setText(String.valueOf(mMovie.getVoteAverage()) + "/10"); mPlot.setText(mMovie.getOverview()); if (!(mReviews == null || mReviews.isEmpty())) { for (Reviews.Result review : mReviews) { TextView textView = new TextView(getContext()); textView.setLayoutParams( new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); textView.setText( getResources().getString(R.string.icon_video) + "\n" + review.getContent()); textView.setTypeface(mFont); textView.setPadding(2, 2, 2, 2); // textView.setTextAppearance(R.s); mReviewsll.addView(textView); } } if (!(mVideos == null || mVideos.isEmpty())) { for (final Videos.Result video : mVideos) { Button button = new Button(getActivity()); button.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); button.setText(getResources().getString(R.string.icon_youtube)); button.setTypeface(mFont); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (mVideos != null) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(video.getUri()))); } } }); button.setPadding(2, 2, 2, 2); mTrailersll.addView(button); } } Log.d(LOG_TAG, getActivity().getLocalClassName().trim()); if (getActivity().getLocalClassName().equalsIgnoreCase("DetailActivity")) { Log.d(LOG_TAG, "insidePhone"); Resources r = getResources(); float width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 185, r.getDisplayMetrics()); float height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 262, r.getDisplayMetrics()); mImageView.setLayoutParams( new LinearLayout.LayoutParams(new ViewGroup.LayoutParams((int) width, (int) height))); } }
/* * add extra bonus button for lay_extra * param 1.text of the button 2.information of the button */ private void addExtraButton(String name, String info) { Button btn_extra = new Button(getActivity()); btn_extra.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); btn_extra.setText(name); btn_extra.setOnClickListener(extraOnClick(name, info)); lay_extra.addView(btn_extra); }
private void setHwView() { int displayHeight = ((XiwaoApplication) getApplication()).getDisplayHeight(); int displayWidth = ((XiwaoApplication) getApplication()).getDisplayWidth(); // title高度 RelativeLayout title = (RelativeLayout) findViewById(R.id.header); LinearLayout.LayoutParams titleParams = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, (int) (displayHeight * 0.08f + 0.5f)); title.setLayoutParams(titleParams); // 所在网点 RelativeLayout websitInfo = (RelativeLayout) findViewById(R.id.websit); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, (int) (displayHeight * 0.08f + 0.5f)); params.setMargins(0, (int) (displayHeight * 0.04f + 0.5f), 0, 0); websitInfo.setLayoutParams(params); // 详细地址 RelativeLayout detailAddress = (RelativeLayout) findViewById(R.id.address); params = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, (int) (displayHeight * 0.08f + 0.5f)); params.setMargins(0, (int) (displayHeight * 0.001f + 0.5f), 0, 0); detailAddress.setLayoutParams(params); // 按钮 LinearLayout buttonGroup = (LinearLayout) findViewById(R.id.button_group); LinearLayout.LayoutParams sureBtnParams = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, (int) (displayHeight * 0.12f + 0.5f)); sureBtnParams.setMargins(0, (int) (displayHeight * 0.04f + 0.5f), 0, 0); buttonGroup.setLayoutParams(sureBtnParams); LinearLayout.LayoutParams btnParams = new LinearLayout.LayoutParams( (int) (displayWidth * 0.4f + 0.5f), (int) (displayHeight * 0.08f + 0.5f)); btnParams.setMargins((int) (displayWidth * 0.05f + 0.5f), 0, 0, 0); cancelBtn.setLayoutParams(btnParams); btnParams = new LinearLayout.LayoutParams( (int) (displayWidth * 0.9f + 0.5f), (int) (displayHeight * 0.08f + 0.5f)); btnParams.setMargins( (int) (displayWidth * 0.05f + 0.5f), 0, (int) (displayWidth * 0.05f + 0.5f), 0); sureBtn.setLayoutParams(btnParams); }
@Override public View getView(Context context) { LinearLayout l = new LinearLayout(context); l.setGravity(Gravity.CENTER_VERTICAL); LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, weightOfDescription); LinearLayout.LayoutParams p2 = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, weightOfInputText); TextView t = new TextView(context); t.setLayoutParams(p); t.setText(this.getVarName()); l.addView(t); editButton = new Button(context); editButton.setLayoutParams(p2); editButton.setText(loadDurationAsString()); pickerDialog = new DurationPickerDialog( context, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { int minutes = (hourOfDay * 60) + minute; setDurationInMinues(minutes); updateEditText(); } }, getHours(), getMinutes()); editButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { pickerDialog.show(); } }); l.addView(editButton); l.setPadding(DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING); if (myDecorator != null) { int level = myDecorator.getCurrentLevel(); myDecorator.decorate(context, t, level + 1, UiDecorator.TYPE_INFO_TEXT); myDecorator.decorate(context, editButton, level + 1, UiDecorator.TYPE_EDIT_TEXT); } return l; }
private void init() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { setLayerType(LAYER_TYPE_SOFTWARE, null); } else { setDrawingCacheEnabled(true); } boolean hasShot = getContext() .getSharedPreferences(PREFS_SHOWCASE_INTERNAL, Context.MODE_PRIVATE) .getBoolean("hasShot" + getConfigOptions().showcaseId, false); if (hasShot && mOptions.shotType == TYPE_ONE_SHOT) { // The showcase has already been shot once, so we don't need to do anything setVisibility(View.GONE); isRedundant = true; return; } showcase = getContext().getResources().getDrawable(R.drawable.cling); showcaseRadius = metricScale * INNER_CIRCLE_RADIUS; PorterDuffXfermode mBlender = new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY); setOnTouchListener(this); mPaintTitle = new Paint(); mPaintTitle.setColor(titleTextColor); mPaintTitle.setShadowLayer(2.0f, 0f, 2.0f, Color.DKGRAY); mPaintTitle.setTextSize(24 * metricScale); mPaintTitle.setAntiAlias(true); mPaintDetail = new TextPaint(); mPaintDetail.setColor(detailTextColor); mPaintDetail.setShadowLayer(2.0f, 0f, 2.0f, Color.DKGRAY); mPaintDetail.setTextSize(16 * metricScale); mPaintDetail.setAntiAlias(true); mEraser = new Paint(); mEraser.setColor(0xFFFFFF); mEraser.setAlpha(0); mEraser.setXfermode(mBlender); mEraser.setAntiAlias(true); if (!mOptions.noButton && mEndButton.getParent() == null) { RelativeLayout.LayoutParams lps = (LayoutParams) generateDefaultLayoutParams(); lps.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); lps.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); int margin = ((Number) (metricScale * 12)).intValue(); lps.setMargins(margin, margin, margin, margin); lps.height = LayoutParams.WRAP_CONTENT; lps.width = LayoutParams.WRAP_CONTENT; mEndButton.setLayoutParams(lps); mEndButton.setText(buttonText != null ? buttonText : getResources().getString(R.string.ok)); if (!hasCustomClickListener) mEndButton.setOnClickListener(this); addView(mEndButton); } }
private View onCreateContextView() { RelativeLayout root = new RelativeLayout(this); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT); root.setLayoutParams(params); Button button01 = new Button(this); params = new RelativeLayout.LayoutParams( DipUtils.getInstance().fromMediumDensityPixel(100), DipUtils.getInstance().fromMediumDensityPixel(100)); button01.setLayoutParams(params); button01.setId(ID_BUTTON01); button01.setText("fromMedium 100px"); Button button02 = new Button(this); params = new RelativeLayout.LayoutParams( DipUtils.getInstance().fromHightDensityPixel(100), DipUtils.getInstance().fromHightDensityPixel(100)); params.addRule(RelativeLayout.RIGHT_OF, ID_BUTTON01); button02.setLayoutParams(params); button02.setId(ID_BUTTON02); button02.setText("fromHight 100px"); Button button03 = new Button(this); params = new RelativeLayout.LayoutParams( DipUtils.getInstance().fromLowDensityPixel(100), DipUtils.getInstance().fromLowDensityPixel(100)); params.addRule(RelativeLayout.RIGHT_OF, ID_BUTTON02); button03.setId(ID_BUTTON03); button03.setLayoutParams(params); button03.setText("fromLow 100px"); root.addView(button01); root.addView(button02); root.addView(button03); return root; }
public void addBtn(String text, android.view.View.OnClickListener onClick) { Button btn = new Button(ctx); btn.setText(text); btn.setOnClickListener(onClick); LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1); btn.setLayoutParams(llp); btn.setBackgroundResource(R.drawable.btn_blue); btn.setTextColor(0xFFFFFFFF); btn.setPadding(0, 10, 0, 10); layoutBtns.addView(btn); }
public BearingWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); setOrientation(LinearLayout.VERTICAL); TableLayout.LayoutParams params = new TableLayout.LayoutParams(); params.setMargins(7, 5, 7, 5); mGetBearingButton = new Button(getContext()); mGetBearingButton.setId(QuestionWidget.newUniqueId()); mGetBearingButton.setPadding(20, 20, 20, 20); mGetBearingButton.setText(getContext().getString(R.string.get_bearing)); mGetBearingButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mGetBearingButton.setEnabled(!prompt.isReadOnly()); mGetBearingButton.setLayoutParams(params); if (prompt.isReadOnly()) { mGetBearingButton.setVisibility(View.GONE); } mStringAnswer = new TextView(getContext()); mStringAnswer.setId(QuestionWidget.newUniqueId()); mAnswerDisplay = new TextView(getContext()); mAnswerDisplay.setId(QuestionWidget.newUniqueId()); mAnswerDisplay.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mAnswerDisplay.setGravity(Gravity.CENTER); String s = prompt.getAnswerText(); if (s != null && !s.equals("")) { mGetBearingButton.setText(getContext().getString(R.string.replace_bearing)); setBinaryData(s); } // when you press the button mGetBearingButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Collect.getInstance() .getActivityLogger() .logInstanceAction(this, "recordBearing", "click", mPrompt.getIndex()); Intent i = null; i = new Intent(getContext(), BearingActivity.class); Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex()); ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.BEARING_CAPTURE); } }); addView(mGetBearingButton); addView(mAnswerDisplay); }
public void setCustomButton(final CustomButtonVO dataVO) { CustomButtonResultVO resultVO = new CustomButtonResultVO(); resultVO.setId(dataVO.getId()); if (!isAlreadyAdded(dataVO.getId())) { FrameLayout.LayoutParams lpParams = new FrameLayout.LayoutParams(dataVO.getWidth(), dataVO.getHeight()); lpParams.leftMargin = dataVO.getX(); lpParams.topMargin = dataVO.getY(); Button btn = new Button(this); btn.setLayoutParams(lpParams); btn.setPadding(0, 0, 0, 0); if (!TextUtils.isEmpty(dataVO.getTitle())) { btn.setText(dataVO.getTitle()); } if (dataVO.getTextSize() > 0) { btn.setTextSize(dataVO.getTextSize()); } if (!TextUtils.isEmpty(dataVO.getTitleColor())) { btn.setTextColor(BUtility.parseColor(dataVO.getTitleColor())); } if (!TextUtils.isEmpty(dataVO.getBgImage())) { Drawable bg = new BitmapDrawable(GaodeUtils.getImage(this, dataVO.getBgImage())); int version = Build.VERSION.SDK_INT; if (version < 16) { btn.setBackgroundDrawable(bg); } else { btn.setBackground(bg); } } mContent.addView(btn); btn.setVisibility(View.GONE); btn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (mListener != null) { EUExGaodeMap gaodeMap = mButtons.get(dataVO.getId()).getGaodeMap(); mListener.onButtonClick(dataVO.getId(), gaodeMap); } } }); CustomButtonBean button = new CustomButtonBean(); button.setButton(btn); mButtons.put(dataVO.getId(), button); resultVO.setIsSuccess(true); } else { resultVO.setIsSuccess(false); } if (mListener != null) { mListener.cbSetCustomButton(resultVO); } }
private void initPageView() { flPage = new FrameLayout(getContext()); flPage.setOnClickListener(this); // 宫格列表的容器,为了“下对齐”,在外部包含了一个FrameLayout LinearLayout llPage = new LinearLayout(getContext()) { public boolean onTouchEvent(MotionEvent event) { return true; } }; llPage.setOrientation(LinearLayout.VERTICAL); int resId = getBitmapRes(getContext(), "share_vp_back"); if (resId > 0) { llPage.setBackgroundResource(resId); } FrameLayout.LayoutParams lpLl = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); lpLl.gravity = Gravity.BOTTOM; llPage.setLayoutParams(lpLl); flPage.addView(llPage); // 宫格列表 grid = new PlatformGridView(getContext()); grid.setEditPageBackground(bgView); LinearLayout.LayoutParams lpWg = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); grid.setLayoutParams(lpWg); llPage.addView(grid); // 取消按钮 btnCancel = new Button(getContext()); btnCancel.setTextColor(0xffffffff); btnCancel.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); resId = getStringRes(getContext(), "cancel"); if (resId > 0) { btnCancel.setText(resId); } btnCancel.setPadding(0, 0, 0, cn.sharesdk.framework.utils.R.dipToPx(getContext(), 5)); resId = getBitmapRes(getContext(), "btn_cancel_back"); if (resId > 0) { btnCancel.setBackgroundResource(resId); } LinearLayout.LayoutParams lpBtn = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, cn.sharesdk.framework.utils.R.dipToPx(getContext(), 45)); int dp_10 = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 10); lpBtn.setMargins(dp_10, dp_10, dp_10, dp_10); btnCancel.setLayoutParams(lpBtn); llPage.addView(btnCancel); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Button _buttonCreateShortcut = new Button(this); _buttonCreateShortcut.setText("install shortcut"); _buttonCreateShortcut.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); setContentView(_buttonCreateShortcut); _buttonCreateShortcut.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent returnIntent = new Intent(); returnIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); returnIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Todeath"); // returnIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, // Intent.ShortcutIconResource.fromContext(AppWidgetSampleActivity.this, // R.drawable.icon)); returnIntent.putExtra( Intent.EXTRA_SHORTCUT_INTENT, new Intent(AppWidgetSampleActivity.this, AppWidgetSampleActivity.class)); // sendBroadcast(returnIntent, "com.android.launcher.permission.INSTALL_SHORTCUT") ; sendBroadcast(returnIntent); } }); /* if(getIntent().getAction().equals(Intent.ACTION_CREATE_SHORTCUT)) { Intent returnIntent = new Intent() ; returnIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Todeath") ; returnIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon)); returnIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this,AppWidgetSampleActivity.class)) ; setResult(RESULT_OK,returnIntent) ; finish(); }else if(getIntent().getAction().equals(LiveFolders.ACTION_CREATE_LIVE_FOLDER)) { Intent returnIntent = new Intent() ; returnIntent.setData(ContactsContract.Contacts.CONTENT_URI) ; returnIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "TodeathLiveFolder") ; returnIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon)); returnIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this,AppWidgetSampleActivity.class)) ; setResult(RESULT_OK,returnIntent) ; finish(); }*/ }
private void centerButton(Button button) { LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) button.getLayoutParams(); params.gravity = Gravity.CENTER_HORIZONTAL; params.weight = 0.5f; button.setLayoutParams(params); View leftSpacer = mWindow.findViewById(R.id.leftSpacer); if (leftSpacer != null) { leftSpacer.setVisibility(View.VISIBLE); } View rightSpacer = mWindow.findViewById(R.id.rightSpacer); if (rightSpacer != null) { rightSpacer.setVisibility(View.VISIBLE); } }
private void initOtherViews() { RelativeLayout.LayoutParams captureButtonParams = new RelativeLayout.LayoutParams(3 * screenWidth / 10, screenHeight / 8); captureButtonParams.addRule(RelativeLayout.CENTER_HORIZONTAL); captureButtonParams.topMargin = screenHeight / 30; captureButton.setLayoutParams(captureButtonParams); captureText.setLayoutParams(captureButtonParams); captureText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, screenHeight / 40); RelativeLayout.LayoutParams nameEditParams = new RelativeLayout.LayoutParams(3 * screenWidth / 10, screenHeight / 8); nameEditParams.addRule(RelativeLayout.CENTER_HORIZONTAL); nameEditParams.addRule(RelativeLayout.BELOW, captureButton.getId()); nameEditParams.topMargin = screenHeight / 30; nameEdit.setLayoutParams(nameEditParams); nameEdit.setTextSize(TypedValue.COMPLEX_UNIT_DIP, screenHeight / 42); nameEdit.setTextColor(Color.BLACK); RelativeLayout.LayoutParams saveButtonParams = new RelativeLayout.LayoutParams(3 * screenWidth / 10, screenHeight / 8); saveButtonParams.addRule(RelativeLayout.CENTER_HORIZONTAL); saveButtonParams.addRule(RelativeLayout.BELOW, nameEdit.getId()); saveButtonParams.topMargin = screenHeight / 30; saveButton.setLayoutParams(saveButtonParams); saveButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, screenHeight / 40); if (!isTraining) { deleteButtonFirstPos = screenHeight / 8 + screenHeight / 15; deleteButtonSecondPos = 3 * screenHeight / 8 + 2 * screenHeight / 15; RelativeLayout.LayoutParams deleteButtonParams = new RelativeLayout.LayoutParams(3 * screenWidth / 10, screenHeight / 8); deleteButtonParams.topMargin = deleteButtonFirstPos; deleteButtonParams.addRule(RelativeLayout.CENTER_HORIZONTAL); deleteButton.setLayoutParams(deleteButtonParams); deleteButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, screenHeight / 42); } }
@Override public void onSizeChanged(int width, int height) { // this is called whenever size of the BlinkIDView changes // we will use this callback in this example to adjust the margins of buttons int horizontalMargin = (int) (width * 0.07); int verticalMargin = (int) (height * 0.07); // set margins for back button FrameLayout.LayoutParams backButtonParams = (FrameLayout.LayoutParams) mBackButton.getLayoutParams(); if (backButtonParams.leftMargin != horizontalMargin && backButtonParams.topMargin != verticalMargin) { backButtonParams.setMargins( horizontalMargin, verticalMargin, horizontalMargin, verticalMargin); mBackButton.setLayoutParams(backButtonParams); } // set margins for torch button FrameLayout.LayoutParams torchButtonParams = (FrameLayout.LayoutParams) mTorchButton.getLayoutParams(); if (torchButtonParams.leftMargin != horizontalMargin && torchButtonParams.topMargin != verticalMargin) { torchButtonParams.setMargins( horizontalMargin, verticalMargin, horizontalMargin, verticalMargin); mTorchButton.setLayoutParams(torchButtonParams); } // set margins for text view FrameLayout.LayoutParams statusViewParams = (FrameLayout.LayoutParams) mStatusTextView.getLayoutParams(); if (statusViewParams.bottomMargin != verticalMargin) { if (android.os.Build.VERSION.SDK_INT <= 7) { statusViewParams.setMargins(0, verticalMargin, 0, verticalMargin); } else { statusViewParams.setMargins( horizontalMargin, verticalMargin, horizontalMargin, verticalMargin); } mStatusTextView.setLayoutParams(statusViewParams); } }
public UrlWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); setOrientation(LinearLayout.VERTICAL); TableLayout.LayoutParams params = new TableLayout.LayoutParams(); params.setMargins(7, 5, 7, 5); // set button formatting mOpenUrlButton = new Button(getContext()); mOpenUrlButton.setId(QuestionWidget.newUniqueId()); mOpenUrlButton.setText(getContext().getString(R.string.open_url)); mOpenUrlButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mOpenUrlButton.setPadding(20, 20, 20, 20); mOpenUrlButton.setEnabled(!prompt.isReadOnly()); mOpenUrlButton.setLayoutParams(params); mOpenUrlButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Collect.getInstance() .getActivityLogger() .logInstanceAction(this, "openUrl", "click", mPrompt.getIndex()); if (mStringAnswer != null & mStringAnswer.getText() != null && !"".equalsIgnoreCase((String) mStringAnswer.getText())) { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse((String) mStringAnswer.getText())); getContext().startActivity(i); } else { Toast.makeText(getContext(), "No URL set", Toast.LENGTH_SHORT).show(); } } }); // set text formatting mStringAnswer = new TextView(getContext()); mStringAnswer.setId(QuestionWidget.newUniqueId()); mStringAnswer.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mStringAnswer.setGravity(Gravity.CENTER); String s = prompt.getAnswerText(); if (s != null) { mStringAnswer.setText(s); } // finish complex layout addView(mOpenUrlButton); addView(mStringAnswer); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_diary); Bundle bundle = getIntent().getExtras(); TimeLineModel tlm = (TimeLineModel) bundle.getSerializable(ARG_KEY); String title = tlm.getTitle(); String content = tlm.getContent(); String date = tlm.getDate(); String audio = tlm.getAudio(); TextView titleView = (TextView) findViewById(R.id.diary_title); TextView contentView = (TextView) findViewById(R.id.diary_content); TextView dateView = (TextView) findViewById(R.id.diary_date); LinearLayout audioButtons = (LinearLayout) findViewById(R.id.diary_audio); titleView.setText(title); contentView.setText(content); dateView.setText(date); LayoutParams lparams = new LayoutParams(200, 110); lparams.setMargins(10, 10, 10, 10); String[] audios = new String[] {}; if (!audio.isEmpty()) audios = audio.split("\n"); for (int i = 0; i < audios.length; i++) { String rawAudioInfo = audios[i]; String[] audioInfo = rawAudioInfo.split(","); // array[0]: duration, array[1]: path // Button btn = new AudioPlayButton(this, audioInfo[0], audioInfo[1]); Button btn = new Button(this); btn.setLayoutParams(lparams); btn.setText(audioInfo[0]); btn.setTag(audioInfo[1]); btn.setBackgroundResource(R.color.mainRed); btn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { play((String) v.getTag()); } }); audioButtons.addView(btn, lparams); } }
public void addButton(ViewGroup layout, String description, final CommandBuilder builder) { Button button = new Button(this); button.setText(description); button.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(10, 5, 10, 2); layout.addView(button); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { builder.play(); } }); }