private void listAll() { ViewGroup root = mList; root.removeAllViews(); // 列出所有已经安装的插件 Collection<PluginDescriptor> plugins = PluginLoader.getPlugins(); Iterator<PluginDescriptor> itr = plugins.iterator(); while (itr.hasNext()) { final PluginDescriptor pluginDescriptor = itr.next(); Button button = new Button(this); button.setPadding(10, 10, 10, 10); button.setText("插件id:" + pluginDescriptor.getPackageName() + ",点击查看"); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(PluginListActivity.this, PluginDetailActivity.class); intent.putExtra("plugin_id", pluginDescriptor.getPackageName()); startActivity(intent); } }); LayoutParams layoutParam = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); layoutParam.topMargin = 10; layoutParam.bottomMargin = 10; layoutParam.gravity = Gravity.LEFT; root.addView(button, layoutParam); } }
public void setStopVisibility(boolean visible) { mStop.setVisibility(visible ? View.VISIBLE : View.GONE); mSiteSecurity.setVisibility(mShowSiteSecurity && !visible ? View.VISIBLE : View.GONE); mReader.setVisibility(mShowReader && !visible ? View.VISIBLE : View.GONE); if (!visible && !mShowSiteSecurity && !mShowReader) mAwesomeBar.setPadding(mPadding[0], mPadding[1], mPadding[2], mPadding[3]); else mAwesomeBar.setPadding(mPadding[0], mPadding[1], mPadding[0], mPadding[3]); }
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 initMenuButtons() { final int dividerHeight = (int) (2.0f * density); menuLayout.setOrientation(LinearLayout.VERTICAL); menuLayout.setBackgroundColor(Color.DKGRAY); menuLayout.setPadding(dividerHeight, 0, dividerHeight, 0); final PaintDrawable divider = new PaintDrawable(Color.WHITE); divider.setIntrinsicHeight(dividerHeight); menuLayout.setDividerDrawable(divider); menuLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); saveButton.setText("Save"); saveButton.setTextSize(20); saveButton.setTextColor(this.getResources().getColorStateList(R.color.text_button_color)); saveButton.setGravity(Gravity.LEFT); saveButton.setPadding( (int) (10.0f * density), (int) (2.0f * density), (int) (2.0f * density), (int) (10.0f * density)); saveButton.setBackgroundColor(this.getResources().getColor(R.color.clear)); menuLayout.addView(saveButton); shareButton.setText("Share"); shareButton.setTextSize(20); shareButton.setTextColor(this.getResources().getColorStateList(R.color.text_button_color)); shareButton.setGravity(Gravity.LEFT); shareButton.setPadding( (int) (10.0f * density), (int) (2.0f * density), (int) (2.0f * density), (int) (10.0f * density)); shareButton.setBackgroundColor(this.getResources().getColor(R.color.clear)); menuLayout.addView(shareButton); renameButton.setText("Rename"); renameButton.setTextSize(20); renameButton.setTextColor(this.getResources().getColorStateList(R.color.text_button_color)); renameButton.setGravity(Gravity.LEFT); renameButton.setPadding( (int) (10.0f * density), (int) (2.0f * density), (int) (2.0f * density), (int) (10.0f * density)); renameButton.setBackgroundColor(this.getResources().getColor(R.color.clear)); menuLayout.addView(renameButton); }
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); } }
/** Создаёт новую кнопку элемента меню */ View newView(MenuEntry ent) { Button btn = new Button(st.c()); int pad = (int) st.floatDp(10, st.c()); if (st.kv().isDefaultDesign()) { btn.setBackgroundDrawable(st.kv().m_drwKeyBack.mutate()); } else { try { RectShape clon = st.kv().m_curDesign.m_keyBackground.clone(); btn.setBackgroundDrawable(((GradBack) clon).getStateDrawable()); } catch (Throwable e) { // TODO: handle exception } } // setButtonKeyboardBackground(btn); btn.setHeight(st.kv().m_KeyHeight); btn.setTextColor(st.paint().mainColor); if (st.has(m_state, STAT_TEMPLATES) || st.has(m_state, STAT_CLIPBOARD)) { btn.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); btn.setLongClickable(true); btn.setOnLongClickListener(m_longListener); } btn.setMaxLines(1); btn.setEllipsize(TruncateAt.MARQUEE); btn.setPadding(pad, pad, pad, pad); btn.setTag(ent); btn.setText(ent.text); btn.setOnClickListener(m_listener); return btn; }
/** * Adds one, two, or three buttons to the layout. * * @param primaryText Text for the primary button. * @param secondaryText Text for the secondary button, or null if there isn't a second button. * @param tertiaryText Text for the tertiary button, or null if there isn't a third button. */ public void setButtons(String primaryText, String secondaryText, String tertiaryText) { if (TextUtils.isEmpty(primaryText)) return; mPrimaryButton = new ButtonCompat(getContext(), mAccentColor); mPrimaryButton.setId(R.id.button_primary); mPrimaryButton.setOnClickListener(this); mPrimaryButton.setText(primaryText); mPrimaryButton.setTextColor(Color.WHITE); if (TextUtils.isEmpty(secondaryText)) return; mSecondaryButton = ButtonCompat.createBorderlessButton(getContext()); mSecondaryButton.setId(R.id.button_secondary); mSecondaryButton.setOnClickListener(this); mSecondaryButton.setText(secondaryText); mSecondaryButton.setTextColor(mAccentColor); if (TextUtils.isEmpty(tertiaryText)) return; mTertiaryButton = ButtonCompat.createBorderlessButton(getContext()); mTertiaryButton.setId(R.id.button_tertiary); mTertiaryButton.setOnClickListener(this); mTertiaryButton.setText(tertiaryText); mTertiaryButton.setPadding( mMargin / 2, mTertiaryButton.getPaddingTop(), mMargin / 2, mTertiaryButton.getPaddingBottom()); mTertiaryButton.setTextColor( ApiCompatibilityUtils.getColor( getContext().getResources(), R.color.infobar_tertiary_button_text)); }
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))); } }
public Button createListPageButton( Activity paramActivity, Map<String, Object> paramMap, String paramString, int paramInt) { Button localButton = new Button(paramActivity); localButton.setId(paramInt); localButton.setTag(Integer.valueOf(5)); localButton.setText(paramString); localButton.setGravity(17); localButton.setPadding(3, 0, 3, 0); return localButton; }
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 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); } }
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); }
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); }
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); }
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(); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_grid); this.layout = (GridLayout) findViewById(R.id.activity_grid_root); for (int i = 0; i < chars.length; i++) { Button btn = new Button(this); btn.setText(chars[i]); btn.setTextSize(40); btn.setPadding(5, 35, 5, 35); GridLayout.Spec row = GridLayout.spec(i / 4 + 2); GridLayout.Spec col = GridLayout.spec(i % 4); GridLayout.LayoutParams param = new GridLayout.LayoutParams(row, col); param.setGravity(Gravity.FILL); this.layout.addView(btn, param); } }
/** @param sortBy */ void fillData(JobsCursor.SortBy sortBy) { // Create a new list to track the addition of TextViews lstTable = new ArrayList<View>(); // a list of the TableRow's added // Get all of the rows from the database and create the table // Keep track of the TextViews added in list lstTable cursor = db.getJobs(sortBy); // Create a table row that contains two lists // (one for job titles, one for employers) // Now load the lists with job title and employer name // for (Jobs row : rows) { for (int rowNum = 0; rowNum < cursor.getCount(); rowNum++) { cursor.moveToPosition(rowNum); TableRow tr = new TableRow(this); tr.setLayoutParams( new LayoutParams( android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); // Create a Button for the job title. mjButton btn1 = new mjButton(this); // Button btn1 = new Button(this); btn1.jrow = rowNum; btn1.setText(cursor.getColTitle()); btn1.setPadding(1, 0, 3, 0); btn1.setHeight(40); btn1.setGravity(android.view.Gravity.CENTER); btn1.setBackgroundColor(colorByStatus((int) cursor.getColStatus())); btn1.setOnClickListener(onTitleClick); // Add job title to job list. tr.addView(btn1); Button btn2 = new Button(this); btn2.setPadding(1, 0, 3, 0); btn2.setText(cursor.getColEmployerName()); btn2.setHeight(40); btn2.setGravity(android.view.Gravity.CENTER); btn2.setBackgroundColor(Color.WHITE); /* Add employer name to that list. */ tr.addView(btn2); tblJobs.addView(tr); // lstJobs.add(btn1.getId()); // keep job id to get more info later if needed lstTable.add(tr); // keep track of the rows we've added (to remove later) } }
public ExPrinterWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); TableLayout.LayoutParams params = new TableLayout.LayoutParams(); params.setMargins(7, 5, 7, 5); String appearance = prompt.getAppearanceHint(); String[] attrs = appearance.split(":"); final String intentName = (attrs.length < 2 || attrs[1].length() == 0) ? "org.opendatakit.sensors.ZebraPrinter" : attrs[1]; final String buttonText; final String errorString; String v = mPrompt.getSpecialFormQuestionText("buttonText"); buttonText = (v != null) ? v : context.getString(R.string.launch_printer); v = mPrompt.getSpecialFormQuestionText("noPrinterErrorString"); errorString = (v != null) ? v : context.getString(R.string.no_printer); // set button formatting mLaunchIntentButton = new Button(getContext()); mLaunchIntentButton.setId(QuestionWidget.newUniqueId()); mLaunchIntentButton.setText(buttonText); mLaunchIntentButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mLaunchIntentButton.setPadding(20, 20, 20, 20); mLaunchIntentButton.setLayoutParams(params); mLaunchIntentButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { try { Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex()); firePrintingActivity(intentName); } catch (ActivityNotFoundException e) { Collect.getInstance().getFormController().setIndexWaitingForData(null); Toast.makeText(getContext(), errorString, Toast.LENGTH_SHORT).show(); } } }); // finish complex layout addView(mLaunchIntentButton); }
// create a new ImageView for each item referenced by the Adapter public View getView(int position, View convertView, ViewGroup parent) { // ImageView imageView; Button tempBut; int multiple; String spinnerarray[]; spinnerarray = new String[4]; spinnerarray[0] = "1x"; spinnerarray[1] = "2x"; spinnerarray[2] = "3x"; spinnerarray[3] = "5x"; if (convertView == null) { // if it's not recycled, initialize some attributes tempBut = new Button(mContext); tempBut.setLayoutParams( new GridView.LayoutParams(DigitDexterityActivity.bsize, DigitDexterityActivity.bsize)); tempBut.setOnClickListener(mOnButtonClick); tempBut.setPadding(8, 8, 8, 8); } else { tempBut = (Button) convertView; } tempBut.setId(1000 + DigitDexterityActivity.location[position]); multiple = spinnerarray[((int) Preference.getMultiples(mContext).charAt(0)) - 48].charAt(0) - 48; if (DigitDexterityActivity.butenable[DigitDexterityActivity.location[position]] == 0) { tempBut.setEnabled(false); } else { tempBut.setEnabled(true); } if (Preference.getRoman(mContext)) { tempBut.setText( DigitDexterityActivity.romans[ (DigitDexterityActivity.location[position] + 1) * multiple]); } else { tempBut.setText(Integer.toString((DigitDexterityActivity.location[position] + 1) * multiple)); } tempBut.setTypeface(null, Typeface.BOLD); tempBut.setTextSize(20); return tempBut; }
public void addBtnGotIt(final boolean isFinish) { Button btn = new Button(ctx); btn.setText("我知道了"); btn.setOnClickListener( new android.view.View.OnClickListener() { @Override public void onClick(View v) { cancel(); if (isFinish) { ((Activity) ctx).finish(); } } }); 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); }
private void addAlphabets(LinearLayout mainContainer) { String alphabets[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "_", ".", " ", "<-" }; int length = alphabets.length; 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, 40), 1f); RelativeLayout.LayoutParams verticalDivider_params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1); RelativeLayout.LayoutParams horizontalDivider_params = new RelativeLayout.LayoutParams(1, ViewGroup.LayoutParams.MATCH_PARENT); int i = 0; while (i < length) { LinearLayout row = new LinearLayout(mContext); row.setOrientation(LinearLayout.HORIZONTAL); row.setLayoutParams(row_Params); mainContainer.addView(row); mainContainer.addView(getDivider(verticalDivider_params)); for (int col = 0; col < 5 && i < length; col++, i++) { Button tv = new Button(mContext); tv.setText(alphabets[i]); String tvTag = ALPHABET + DELIMITER + alphabets[i]; tv.setTag(tvTag); tv.setTextColor(Color.BLACK); tv.setBackgroundColor(Color.argb(180, 255, 255, 255)); tv.setGravity(Gravity.CENTER); tv.setPadding(0, ConvertToPx(mContext, 3), 0, 0); tv.setLayoutParams(box_Params); tv.setOnClickListener(Process_Input); row.addView(tv); row.addView(getDivider(horizontalDivider_params)); } } }
ModalScreenLayout(Context context) { super(context); setPadding(PADDING, PADDING, PADDING, PADDING); _content = new ScrollView(context); addView(_content); _content.setPadding(PADDING, PADDING, PADDING, PADDING); _content.setScrollbarFadingEnabled(true); _close_btn = new Button(context); addView(_close_btn); _close_btn.setPadding(PADDING, PADDING, PADDING, PADDING); _close_btn.setText(R.string.screen_menu_close); View.OnClickListener close_listener = new View.OnClickListener() { public void onClick(View v) { close(); } }; _close_btn.setOnClickListener(close_listener); }
public Button createButton(CharSequence text, View.OnClickListener click) { float density = this.getContext().getResources().getDisplayMetrics().density; int button_height = (int) (36.0f * density); int button_margin = (int) (4.0f * density); int button_padding = (int) (8.0f * density); int min_width = (int) (64.0f * density); LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, button_height); params.setMargins(button_margin, 0, 0, 0); Button button = new Button(this.getContext()); button.setLayoutParams(params); button.setPadding(button_padding, 0, button_padding, 0); button.setBackgroundResource(R.drawable.touch_holo_light_round_angle); button.setTextColor(this.getContext().getResources().getColor(R.color.blue)); button.setTextSize(16); button.setMinWidth(min_width); button.setOnClickListener(new OnClick(this, click)); button.setText(text); button.setTypeface(null, Typeface.BOLD); return button; }
public SignatureWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); mInstanceFolder = Collect.getInstance().getFormController().getInstancePath().getParent(); setOrientation(LinearLayout.VERTICAL); TableLayout.LayoutParams params = new TableLayout.LayoutParams(); params.setMargins(7, 5, 7, 5); mErrorTextView = new TextView(context); mErrorTextView.setId(QuestionWidget.newUniqueId()); mErrorTextView.setText("Selected file is not a valid image"); // setup Blank Image Button mSignButton = new Button(getContext()); mSignButton.setId(QuestionWidget.newUniqueId()); mSignButton.setText(getContext().getString(R.string.sign_button)); mSignButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mSignButton.setPadding(20, 20, 20, 20); mSignButton.setEnabled(!prompt.isReadOnly()); mSignButton.setLayoutParams(params); // launch capture intent on click mSignButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Collect.getInstance() .getActivityLogger() .logInstanceAction(this, "signButton", "click", mPrompt.getIndex()); launchSignatureActivity(); } }); // finish complex layout addView(mSignButton); addView(mErrorTextView); // and hide the sign button if read-only if (prompt.isReadOnly()) { mSignButton.setVisibility(View.GONE); } mErrorTextView.setVisibility(View.GONE); // retrieve answer from data model and update ui mBinaryName = prompt.getAnswerText(); // Only add the imageView if the user has signed if (mBinaryName != null) { mImageView = new ImageView(getContext()); mImageView.setId(QuestionWidget.newUniqueId()); Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); int screenWidth = display.getWidth(); int screenHeight = display.getHeight(); File f = new File(mInstanceFolder + File.separator + mBinaryName); if (f.exists()) { Bitmap bmp = FileUtils.getBitmapScaledToDisplay(f, screenHeight, screenWidth); if (bmp == null) { mErrorTextView.setVisibility(View.VISIBLE); } mImageView.setImageBitmap(bmp); } else { mImageView.setImageBitmap(null); } mImageView.setPadding(10, 10, 10, 10); mImageView.setAdjustViewBounds(true); mImageView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Collect.getInstance() .getActivityLogger() .logInstanceAction(this, "viewImage", "click", mPrompt.getIndex()); launchSignatureActivity(); } }); addView(mImageView); } }
/** To dynamically add all the views to the screen for the listview. */ public void displayEverything() { LinearLayout mainll = (LinearLayout) findViewById(R.id.mainll); mainll.removeAllViews(); // Iterate through the projects table and for each item, add a view to the linearlayout Cursor cursor = Login.db.rawQuery( "SELECT pos,name,desc,url FROM " + Login.USERNAME + "_projects WHERE username='******' ORDER BY pos;", null); try { cursor.moveToFirst(); while (true) { final int pos = cursor.getInt(0); final String url = cursor.getString(3); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); ll.setLayoutParams(params); ll.setBackgroundColor(Color.WHITE); ll.setGravity(Gravity.CENTER_HORIZONTAL); ImageView imageButton = new ImageView(this); InputStream is = openFileInput(Login.USERNAME + "_" + pos + ".jpg"); Bitmap bitmap = BitmapFactory.decodeStream(is); imageButton.setImageBitmap(bitmap); imageButton.setScaleType(ImageView.ScaleType.CENTER_CROP); params = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, (int) getResources().getDimension(R.dimen.dp200)); params.setMargins( 0, (int) getResources().getDimension(R.dimen.dp5), 0, (int) getResources().getDimension(R.dimen.dp5)); imageButton.setLayoutParams(params); imageButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this, MyWebView.class); intent.putExtra("url", url); startActivity(intent); } }); ll.addView(imageButton); TextView textView = new TextView(this); textView.setText(cursor.getString(1)); textView.setTextSize(20); params = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.setMargins(0, (int) getResources().getDimension(R.dimen.dp10), 0, 0); textView.setLayoutParams(params); textView.setTextColor(Color.parseColor("#666666")); textView.setTypeface(null, Typeface.BOLD); ll.addView(textView); textView = new TextView(this); textView.setText(cursor.getString(2)); textView.setTextSize(16); textView.setLayoutParams(params); textView.setTextColor(Color.parseColor("#666666")); textView.setGravity(Gravity.CENTER); ll.addView(textView); Button button = new Button(this); params = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, (int) getResources().getDimension(R.dimen.dp1)); params.setMargins( 0, (int) getResources().getDimension(R.dimen.dp20), 0, (int) getResources().getDimension(R.dimen.dp20)); button.setLayoutParams(params); button.setBackgroundColor(Color.parseColor("#cccccc")); button.setPadding( (int) getResources().getDimension(R.dimen.dp10), 0, (int) getResources().getDimension(R.dimen.dp10), 0); ll.addView(button); mainll.addView(ll); cursor.moveToNext(); if (cursor.isAfterLast()) { break; } } } catch (Exception e) { Log.e(e.toString(), e.getMessage()); } cursor.close(); }
public AnnotateWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); mInstanceFolder = Collect.getInstance().getFormController().getInstancePath().getParent(); setOrientation(LinearLayout.VERTICAL); TableLayout.LayoutParams params = new TableLayout.LayoutParams(); params.setMargins(7, 5, 7, 5); mErrorTextView = new TextView(context); mErrorTextView.setId(QuestionWidget.newUniqueId()); mErrorTextView.setText("Selected file is not a valid image"); // setup capture button mCaptureButton = new Button(getContext()); mCaptureButton.setId(QuestionWidget.newUniqueId()); mCaptureButton.setText(getContext().getString(R.string.capture_image)); mCaptureButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mCaptureButton.setPadding(20, 20, 20, 20); mCaptureButton.setEnabled(!prompt.isReadOnly()); mCaptureButton.setLayoutParams(params); // launch capture intent on click mCaptureButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Collect.getInstance() .getActivityLogger() .logInstanceAction(this, "captureButton", "click", mPrompt.getIndex()); mErrorTextView.setVisibility(View.GONE); Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); // We give the camera an absolute filename/path where to put the // picture because of bug: // http://code.google.com/p/android/issues/detail?id=1480 // The bug appears to be fixed in Android 2.0+, but as of feb 2, // 2010, G1 phones only run 1.6. Without specifying the path the // images returned by the camera in 1.6 (and earlier) are ~1/4 // the size. boo. // if this gets modified, the onActivityResult in // FormEntyActivity will also need to be updated. i.putExtra( android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Collect.TMPFILE_PATH))); try { Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex()); ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CAPTURE); } catch (ActivityNotFoundException e) { Toast.makeText( getContext(), getContext().getString(R.string.activity_not_found, "image capture"), Toast.LENGTH_SHORT) .show(); Collect.getInstance().getFormController().setIndexWaitingForData(null); } } }); // setup chooser button mChooseButton = new Button(getContext()); mChooseButton.setId(QuestionWidget.newUniqueId()); mChooseButton.setText(getContext().getString(R.string.choose_image)); mChooseButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mChooseButton.setPadding(20, 20, 20, 20); mChooseButton.setEnabled(!prompt.isReadOnly()); mChooseButton.setLayoutParams(params); // launch capture intent on click mChooseButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Collect.getInstance() .getActivityLogger() .logInstanceAction(this, "chooseButton", "click", mPrompt.getIndex()); mErrorTextView.setVisibility(View.GONE); Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.setType("image/*"); try { Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex()); ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CHOOSER); } catch (ActivityNotFoundException e) { Toast.makeText( getContext(), getContext().getString(R.string.activity_not_found, "choose image"), Toast.LENGTH_SHORT) .show(); Collect.getInstance().getFormController().setIndexWaitingForData(null); } } }); // setup Blank Image Button mAnnotateButton = new Button(getContext()); mAnnotateButton.setId(QuestionWidget.newUniqueId()); mAnnotateButton.setText(getContext().getString(R.string.markup_image)); mAnnotateButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mAnnotateButton.setPadding(20, 20, 20, 20); mAnnotateButton.setEnabled(false); mAnnotateButton.setLayoutParams(params); // launch capture intent on click mAnnotateButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Collect.getInstance() .getActivityLogger() .logInstanceAction(this, "annotateButton", "click", mPrompt.getIndex()); launchAnnotateActivity(); } }); // finish complex layout addView(mCaptureButton); addView(mChooseButton); addView(mAnnotateButton); addView(mErrorTextView); // and hide the capture, choose and annotate button if read-only if (prompt.isReadOnly()) { mCaptureButton.setVisibility(View.GONE); mChooseButton.setVisibility(View.GONE); mAnnotateButton.setVisibility(View.GONE); } mErrorTextView.setVisibility(View.GONE); // retrieve answer from data model and update ui mBinaryName = prompt.getAnswerText(); // Only add the imageView if the user has taken a picture if (mBinaryName != null) { if (!prompt.isReadOnly()) { mAnnotateButton.setEnabled(true); } mImageView = new ImageView(getContext()); mImageView.setId(QuestionWidget.newUniqueId()); Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); int screenWidth = display.getWidth(); int screenHeight = display.getHeight(); File f = new File(mInstanceFolder + File.separator + mBinaryName); if (f.exists()) { Bitmap bmp = FileUtils.getBitmapScaledToDisplay(f, screenHeight, screenWidth); if (bmp == null) { mErrorTextView.setVisibility(View.VISIBLE); } mImageView.setImageBitmap(bmp); } else { mImageView.setImageBitmap(null); } mImageView.setPadding(10, 10, 10, 10); mImageView.setAdjustViewBounds(true); mImageView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Collect.getInstance() .getActivityLogger() .logInstanceAction(this, "viewImage", "click", mPrompt.getIndex()); launchAnnotateActivity(); } }); addView(mImageView); } }
protected void onCreateContent(LinearLayout parent) { SizeHelper.prepare(context); LinearLayout rlCountry = new LinearLayout(context); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, SizeHelper.fromPxWidth(96)); params.setMargins( SizeHelper.fromPx(26), SizeHelper.fromPxWidth(32), SizeHelper.fromPxWidth(26), 0); rlCountry.setLayoutParams(params); rlCountry.setId(Res.id.rl_country); TextView tv = new TextView(context); LinearLayout.LayoutParams tvParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); tvParams.gravity = Gravity.CENTER_VERTICAL; tv.setLayoutParams(tvParams); tv.setPadding(SizeHelper.fromPxWidth(14), 0, SizeHelper.fromPxWidth(14), 0); int resid = R.getStringRes(context, "smssdk_country"); tv.setText(resid); tv.setTextColor(0xff000000); tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25)); rlCountry.addView(tv); TextView tvCountry = new TextView(context); tvCountry.setId(Res.id.tv_country); LinearLayout.LayoutParams tvCountryParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); tvCountryParams.gravity = Gravity.CENTER_VERTICAL; tvCountryParams.weight = 1; tvCountryParams.rightMargin = SizeHelper.fromPxWidth(14); tvCountry.setLayoutParams(tvCountryParams); tvCountry.setGravity(Gravity.RIGHT); tvCountry.setPadding(SizeHelper.fromPxWidth(14), 0, SizeHelper.fromPxWidth(14), 0); tvCountry.setTextColor(0xff45c01a); tvCountry.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25)); rlCountry.addView(tvCountry); parent.addView(rlCountry); View line = new View(context); LinearLayout.LayoutParams lineParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, SizeHelper.fromPxWidth(1)); lineParams.leftMargin = SizeHelper.fromPxWidth(26); lineParams.rightMargin = SizeHelper.fromPxWidth(26); line.setLayoutParams(lineParams); line.setBackgroundColor(Res.color.smssdk_gray_press); parent.addView(line); LinearLayout phoneLayout = new LinearLayout(context); LinearLayout.LayoutParams phoneParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, SizeHelper.fromPxWidth(70)); phoneParams.setMargins( SizeHelper.fromPxWidth(26), SizeHelper.fromPxWidth(30), SizeHelper.fromPxWidth(26), 0); phoneLayout.setLayoutParams(phoneParams); TextView countryNum = new TextView(context); countryNum.setId(Res.id.tv_country_num); LinearLayout.LayoutParams countryNumParams = new LinearLayout.LayoutParams( SizeHelper.fromPxWidth(104), LinearLayout.LayoutParams.MATCH_PARENT); countryNum.setLayoutParams(countryNumParams); countryNum.setGravity(Gravity.CENTER); countryNum.setTextColor(0xff353535); countryNum.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25)); resid = R.getBitmapRes(context, "smssdk_input_bg_focus"); countryNum.setBackgroundResource(resid); phoneLayout.addView(countryNum); LinearLayout wrapperLayout = new LinearLayout(context); LinearLayout.LayoutParams wrapperParams = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT); wrapperParams.weight = 1; wrapperLayout.setLayoutParams(wrapperParams); resid = R.getBitmapRes(context, "smssdk_input_bg_special_focus"); wrapperLayout.setBackgroundResource(resid); EditText writePhone = new EditText(context); writePhone.setId(Res.id.et_write_phone); LinearLayout.LayoutParams writePhoneParams = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT); writePhoneParams.gravity = Gravity.CENTER_VERTICAL; writePhoneParams.setMargins(SizeHelper.fromPxWidth(10), 0, SizeHelper.fromPxWidth(10), 0); writePhoneParams.weight = 1; writePhone.setLayoutParams(writePhoneParams); writePhone.setBackgroundDrawable(null); resid = R.getStringRes(context, "smssdk_write_mobile_phone"); writePhone.setHint(resid); writePhone.setInputType(InputType.TYPE_CLASS_PHONE); writePhone.setTextColor(0xff353535); writePhone.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25)); wrapperLayout.addView(writePhone); ImageView image = new ImageView(context); image.setId(Res.id.iv_clear); LinearLayout.LayoutParams imageParams = new LinearLayout.LayoutParams(SizeHelper.fromPxWidth(24), SizeHelper.fromPxWidth(24)); imageParams.gravity = Gravity.CENTER_VERTICAL; imageParams.rightMargin = SizeHelper.fromPxWidth(20); image.setLayoutParams(imageParams); resid = R.getBitmapRes(context, "smssdk_clear_search"); image.setBackgroundResource(resid); image.setScaleType(ScaleType.CENTER_INSIDE); image.setVisibility(View.GONE); wrapperLayout.addView(image); phoneLayout.addView(wrapperLayout); parent.addView(phoneLayout); Button nextBtn = new Button(context); nextBtn.setId(Res.id.btn_next); LinearLayout.LayoutParams nextParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, SizeHelper.fromPxWidth(72)); nextParams.setMargins( SizeHelper.fromPxWidth(26), SizeHelper.fromPxWidth(36), SizeHelper.fromPxWidth(26), 0); nextBtn.setLayoutParams(nextParams); resid = R.getBitmapRes(context, "smssdk_btn_disenable"); nextBtn.setBackgroundResource(resid); resid = R.getStringRes(context, "smssdk_next"); nextBtn.setText(resid); nextBtn.setTextColor(0xffffffff); nextBtn.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25)); nextBtn.setPadding(0, 0, 0, 0); parent.addView(nextBtn); }
@Override public View getChildView( int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { final Entity ent = (Entity) getChild(groupPosition, childPosition); // Set an id depending on the table ent belongs to int entId; if (ent.getTable() == "homework") { entId = 1; } else if (ent.getTable() == "assignment") { entId = 2; } else if (ent.getTable() == "exam") { entId = 3; } else { entId = 4; } // Depending on the id, do something different. For the first three, the only bit that changes // is the string in the alertDialog and the activity // that's opened when you press the element on the list. I'll comment due homework list, the // other are the same. switch (entId) { // Due homework list case 1: convertView = View.inflate(AgendaDay.this, R.layout.agendaday_dueitem, null); try { Button title = (Button) convertView.findViewById(R.id.title); ImageView remove = (ImageView) convertView.findViewById(R.id.dueremove); TextView dueclass = (TextView) convertView.findViewById(R.id.dueclass); LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.linearLayout1); // When editing this element, get the date it was set, not the date you're viewing. final Calendar c = Calendar.getInstance(); c.setTimeInMillis(ent.getLong("setDate")); // Set text title.setText("- " + ent.getString("title")); // If the homework is done, strike it through. if (ent.getInt("done") == 1) { title.setPaintFlags(title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); layout.setBackgroundColor(getResources().getColor(R.color.grey)); } title.setOnClickListener( new OnClickListener() { // When the element's pressed, open AddHwDialog with all the necessary data to // edit it. public void onClick(View addexam) { Intent i = new Intent(AgendaDay.this, AddHwDialog.class); i.putExtra("homework_id", ent.getId()); i.putExtra("todayCalendar", c.getTimeInMillis()); startActivityForResult(i, ACTIVITY_EDIT); } }); remove.setOnClickListener( new OnClickListener() { public void onClick(View removerecord) { AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this); builder .setMessage(R.string.sureHomework) .setTitle(R.string.sureHomeworkTitle) .setCancelable(true) .setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { dialog.cancel(); } }) .setPositiveButton( R.string.accept, new DialogInterface.OnClickListener() { // Remove the element. public void onClick(DialogInterface dialog, int arg1) { ent.delete(); fillList(); } }); AlertDialog AD = builder.create(); AD.show(); } }); // Get the subject this element is associated with... Entity classEnt = new Entity("class", ent.getLong("class_id")); Entity subject = new Entity("subject", classEnt.getLong("subject_id")); // ...to put it as the name that appears. dueclass.setText(subject.getString("title")); } catch (Exception e) { e.printStackTrace(); } break; // Due assignment list case 2: convertView = View.inflate(AgendaDay.this, R.layout.agendaday_dueitem, null); try { Button title = (Button) convertView.findViewById(R.id.title); ImageView remove = (ImageView) convertView.findViewById(R.id.dueremove); TextView dueclass = (TextView) convertView.findViewById(R.id.dueclass); LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.linearLayout1); final Calendar c = Calendar.getInstance(); c.setTimeInMillis(ent.getLong("setDate")); title.setText("- " + ent.getString("title")); if (ent.getInt("done") == 1) { title.setPaintFlags(title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); layout.setBackgroundColor(getResources().getColor(R.color.grey)); } title.setOnClickListener( new OnClickListener() { public void onClick(View addexam) { Intent i = new Intent(AgendaDay.this, AddAssignDialog.class); i.putExtra("assign_id", ent.getId()); i.putExtra("todayCalendar", c.getTimeInMillis()); startActivityForResult(i, ACTIVITY_EDIT); } }); remove.setOnClickListener( new OnClickListener() { public void onClick(View removerecord) { AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this); builder .setMessage(R.string.sureAssignment) .setTitle(R.string.sureAssignmentTitle) .setCancelable(true) .setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { dialog.cancel(); } }) .setPositiveButton( R.string.accept, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { ent.delete(); fillList(); } }); AlertDialog AD = builder.create(); AD.show(); } }); Entity classEnt = new Entity("class", ent.getLong("class_id")); Entity subject = new Entity("subject", classEnt.getLong("subject_id")); dueclass.setText(subject.getString("title")); } catch (Exception e) { e.printStackTrace(); } break; // Due exam list case 3: convertView = View.inflate(AgendaDay.this, R.layout.agendaday_dueitem, null); try { Button title = (Button) convertView.findViewById(R.id.title); ImageView remove = (ImageView) convertView.findViewById(R.id.dueremove); TextView dueclass = (TextView) convertView.findViewById(R.id.dueclass); final Calendar c = Calendar.getInstance(); c.setTimeInMillis(ent.getLong("setDate")); title.setText("- " + ent.getString("title")); title.setOnClickListener( new OnClickListener() { public void onClick(View addexam) { Intent i = new Intent(AgendaDay.this, AddExamDialog.class); i.putExtra("exam_id", ent.getId()); i.putExtra("todayCalendar", c.getTimeInMillis()); startActivityForResult(i, ACTIVITY_EDIT); } }); remove.setOnClickListener( new OnClickListener() { public void onClick(View removerecord) { AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this); builder .setMessage(R.string.sureExam) .setTitle(R.string.sureExamTitle) .setCancelable(true) .setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { dialog.cancel(); } }) .setPositiveButton( R.string.accept, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { ent.delete(); fillList(); } }); AlertDialog AD = builder.create(); AD.show(); } }); Entity classEnt = new Entity("class", ent.getLong("class_id")); Entity subject = new Entity("subject", classEnt.getLong("subject_id")); dueclass.setText(subject.getString("title")); } catch (Exception e) { e.printStackTrace(); } break; // Today's classes list case 4: convertView = View.inflate(AgendaDay.this, R.layout.agendaday_item, null); try { Long subjectid = (Long) ent.getValue("subject_id"); Entity subjectent = new Entity("subject", subjectid); // Get when the class starts and when it ends to... String starttimehour = ent.getString("starttimehour"); // Add a 0 if it's lower than 10, Java doesn't do it automatically. if (Integer.parseInt(starttimehour) < 10) { starttimehour = "0" + starttimehour; } String starttimeminute = ent.getString("starttimeminute"); if (Integer.parseInt(starttimeminute) < 10) { starttimeminute = "0" + starttimeminute; } String endtimehour = ent.getString("endtimehour"); if (Integer.parseInt(endtimehour) < 10) { endtimehour = "0" + endtimehour; } String endtimeminute = ent.getString("endtimeminute"); if (Integer.parseInt(endtimeminute) < 10) { endtimeminute = "0" + endtimeminute; } // ...display it nicely in a TextView String classLength = " (" + starttimehour + ":" + starttimeminute + "-" + endtimehour + ":" + endtimeminute + ")"; TextView subject = (TextView) convertView.findViewById(R.id.subjectname); TextView classLengthText = (TextView) convertView.findViewById(R.id.classlength); subject.setText(subjectent.getString("title")); classLengthText.setText(classLength); LinearLayout hwlist = (LinearLayout) convertView.findViewById(R.id.homeworkLinearLayout); LinearLayout assignlist = (LinearLayout) convertView.findViewById(R.id.assignmentLinearLayout); LinearLayout examlist = (LinearLayout) convertView.findViewById(R.id.examLinearLayout); try { // Start my three arraylists. entHw = new ArrayList<Entity>(); entExams = new ArrayList<Entity>(); entAssignments = new ArrayList<Entity>(); // Get today's date. Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); c.set(mYear, mMonth, mDay, 0, 0, 0); c.set(Calendar.MILLISECOND, 0); // Get all homework associated to the class you're viewing. List<Entity> entclassHw = db.getEntityList("homework", "class_id = '" + ent.getId() + "'"); Iterator<Entity> iter = entclassHw.iterator(); // Put in entHw only those that are set on the day you're viewing while (iter.hasNext()) { Entity HwEnt = (Entity) iter.next(); Calendar d = Calendar.getInstance(TimeZone.getTimeZone("GMT")); d.setTimeInMillis(HwEnt.getLong("setDate")); if (d.getTimeInMillis() == c.getTimeInMillis()) { entHw.add(HwEnt); } } List<Entity> entclassAssignments = db.getEntityList("assignment", "class_id = '" + ent.getId() + "'"); Iterator<Entity> iter2 = entclassAssignments.iterator(); while (iter2.hasNext()) { Entity AssignEnt = (Entity) iter2.next(); Calendar d = Calendar.getInstance(TimeZone.getTimeZone("GMT")); d.setTimeInMillis(AssignEnt.getLong("setDate")); if (d.get(Calendar.YEAR) == c.get(Calendar.YEAR) && d.get(Calendar.DAY_OF_YEAR) == c.get(Calendar.DAY_OF_YEAR)) { entAssignments.add(AssignEnt); } } List<Entity> entclassExams = db.getEntityList("exam", "class_id = '" + ent.getId() + "'"); Iterator<Entity> iter3 = entclassExams.iterator(); while (iter3.hasNext()) { Entity ExamEnt = (Entity) iter3.next(); Calendar d = Calendar.getInstance(TimeZone.getTimeZone("GMT")); d.setTimeInMillis(ExamEnt.getLong("setDate")); if (d.get(Calendar.YEAR) == c.get(Calendar.YEAR) && d.get(Calendar.DAY_OF_YEAR) == c.get(Calendar.DAY_OF_YEAR)) { entExams.add(ExamEnt); } } } catch (Exception e) { e.printStackTrace(); } // Get a date for the day you're viewing final Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); c.set(mYear, mMonth, mDay, 0, 0, 0); c.set(Calendar.MILLISECOND, 0); // For every homework you have on the day your viewing and the class element the list is // at. for (final Entity ent2 : entHw) { LinearLayout linear = new LinearLayout(getApplicationContext()); linear.setOrientation(LinearLayout.HORIZONTAL); LayoutParams linearLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); linear.setLayoutParams(linearLayoutParams); linear.setBackgroundResource(R.color.purple); Button hwTitle = new Button(getApplicationContext()); hwTitle.setText("- " + ent2.getString("title")); if (ent2.getInt("done") == 1) { hwTitle.setPaintFlags(hwTitle.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); } hwTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 19); hwTitle.setGravity(Gravity.LEFT); hwTitle.setPadding(5, 5, 0, 5); LayoutParams titleButtonLayoutParams = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1); hwTitle.setLayoutParams(titleButtonLayoutParams); hwTitle.setBackgroundColor(android.R.color.transparent); hwTitle.setOnClickListener( new OnClickListener() { public void onClick(View addexam) { Intent i = new Intent(AgendaDay.this, AddHwDialog.class); i.putExtra("homework_id", ent2.getId()); i.putExtra("todayCalendar", c.getTimeInMillis()); startActivityForResult(i, ACTIVITY_EDIT); } }); ImageView remove = new ImageView(getApplicationContext()); LayoutParams removeButtonLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); removeButtonLayoutParams.gravity = Gravity.CENTER_VERTICAL; remove.setBackgroundDrawable(getResources().getDrawable(R.drawable.remove)); remove.setLayoutParams(removeButtonLayoutParams); remove.setOnClickListener( new OnClickListener() { public void onClick(View removerecord) { AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this); builder .setMessage(R.string.sureHomework) .setTitle(R.string.sureHomeworkTitle) .setCancelable(true) .setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { dialog.cancel(); } }) .setPositiveButton( R.string.accept, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { ent2.delete(); fillList(); } }); AlertDialog AD = builder.create(); AD.show(); } }); linear.addView(hwTitle); linear.addView(remove); hwlist.addView(linear); } for (final Entity ent2 : entAssignments) { LinearLayout linear = new LinearLayout(getApplicationContext()); linear.setOrientation(LinearLayout.HORIZONTAL); LayoutParams linearLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); linear.setLayoutParams(linearLayoutParams); linear.setBackgroundResource(R.color.light_green); Button assignTitle = new Button(getApplicationContext()); assignTitle.setText("- " + ent2.getString("title")); if (ent2.getInt("done") == 1) { assignTitle.setPaintFlags( assignTitle.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); } assignTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); assignTitle.setGravity(Gravity.LEFT); assignTitle.setPadding(5, 5, 0, 5); LayoutParams titleButtonLayoutParams = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1); assignTitle.setLayoutParams(titleButtonLayoutParams); assignTitle.setBackgroundColor(android.R.color.transparent); assignTitle.setOnClickListener( new OnClickListener() { public void onClick(View addexam) { Intent i = new Intent(AgendaDay.this, AddAssignDialog.class); i.putExtra("assign_id", ent2.getId()); i.putExtra("todayCalendar", c.getTimeInMillis()); startActivityForResult(i, ACTIVITY_EDIT); } }); ImageView remove = new ImageView(getApplicationContext()); LayoutParams removeButtonLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); removeButtonLayoutParams.gravity = Gravity.CENTER_VERTICAL; remove.setBackgroundDrawable(getResources().getDrawable(R.drawable.remove)); remove.setLayoutParams(removeButtonLayoutParams); remove.setOnClickListener( new OnClickListener() { public void onClick(View removerecord) { AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this); builder .setMessage(R.string.sureAssignment) .setTitle(R.string.sureAssignmentTitle) .setCancelable(true) .setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { dialog.cancel(); } }) .setPositiveButton( R.string.accept, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { ent2.delete(); fillList(); } }); AlertDialog AD = builder.create(); AD.show(); } }); linear.addView(assignTitle); linear.addView(remove); assignlist.addView(linear); } for (final Entity ent2 : entExams) { LinearLayout linear = new LinearLayout(getApplicationContext()); linear.setOrientation(LinearLayout.HORIZONTAL); LayoutParams linearLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); linear.setLayoutParams(linearLayoutParams); linear.setBackgroundResource(R.color.light_orange); Button examTitle = new Button(getApplicationContext()); examTitle.setText("- " + ent2.getString("title")); examTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); examTitle.setGravity(Gravity.LEFT); examTitle.setPadding(5, 5, 0, 5); LayoutParams titleButtonLayoutParams = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1); examTitle.setLayoutParams(titleButtonLayoutParams); examTitle.setBackgroundColor(android.R.color.transparent); examTitle.setOnClickListener( new OnClickListener() { public void onClick(View addexam) { Intent i = new Intent(AgendaDay.this, AddExamDialog.class); i.putExtra("exam_id", ent2.getId()); i.putExtra("todayCalendar", c.getTimeInMillis()); startActivityForResult(i, ACTIVITY_EDIT); } }); ImageView remove = new ImageView(getApplicationContext()); LayoutParams removeButtonLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); removeButtonLayoutParams.gravity = Gravity.CENTER_VERTICAL; remove.setBackgroundDrawable(getResources().getDrawable(R.drawable.remove)); remove.setLayoutParams(removeButtonLayoutParams); remove.setOnClickListener( new OnClickListener() { public void onClick(View removerecord) { AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this); builder .setMessage(R.string.sureExam) .setTitle(R.string.sureExamTitle) .setCancelable(true) .setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { dialog.cancel(); } }) .setPositiveButton( R.string.accept, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { ent2.delete(); fillList(); } }); AlertDialog AD = builder.create(); AD.show(); } }); linear.addView(examTitle); linear.addView(remove); examlist.addView(linear); } ImageView add = (ImageView) convertView.findViewById(R.id.add); add.setOnClickListener( new OnClickListener() { public void onClick(View addsubject) { Intent i = new Intent(AgendaDay.this, AddAssignmentListDialog.class); i.putExtra("class_id", ent.getId()); Calendar c = Calendar.getInstance(); c.set(mYear, mMonth, mDay, 0, 0, 0); c.set(Calendar.MILLISECOND, 0); c.setTimeZone(TimeZone.getTimeZone("GMT")); i.putExtra("todayCalendar", c.getTimeInMillis()); startActivityForResult(i, ACTIVITY_CREATE); } }); } catch (Exception e) { e.printStackTrace(); } break; } return convertView; }
/** * Called when the activity is first created. Sets up the view. * * @param savedInstanceState Um I don't even know. Read the Android documentation. */ @Override public void onCreate(Bundle savedInstanceState) { String TAG = StaticBlob.TAG(); if (android.os.Build.VERSION.SDK_INT >= 11) setTheme(R.style.Default_New); // General create stuff super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); Log.v(TAG, "Launching Activity"); mainListView = new ListView(this); Callisto.build_layout(this, mainListView); // Get the settings for this show currentShow = getIntent().getExtras().getString("current_show"); currentShowAudio = getIntent().getExtras().getString("current_show_audio"); currentShowVideo = getIntent().getExtras().getString("current_show_video"); showSettings = getSharedPreferences(currentShow, 0); filter = showSettings.getBoolean("filter", false); loading = (TextView) findViewById(android.R.id.empty); // If it has been checked before but there are no episodes, show that it is empty, not just // loading. if (StaticBlob.databaseConnector.getShow(currentShow, filter).getCount() == 0) loading.setText(this.getResources().getString(R.string.list_empty)); else loading.setText(this.getResources().getString(R.string.loading)); loading.setGravity(Gravity.CENTER_HORIZONTAL); // If it has never been checked before add a refresh button if (showSettings.getString("last_checked", null) == null) { refresh = new Button(this); refresh.setText(this.getResources().getString(R.string.refresh)); refresh.setTextColor(this.getResources().getColor(R.color.txtClr)); LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); p.setMargins(20, 10, 20, 10); refresh.setLayoutParams(p); ((LinearLayout) loading.getParent()).setGravity(Gravity.CENTER_HORIZONTAL); refresh.setPadding(100, 10, 100, 10); refresh.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { reload(); } }); ((LinearLayout) mainListView.getParent()).addView(refresh, 1); ((LinearLayout) mainListView.getParent()) .setBackgroundColor(this.getResources().getColor(R.color.backClr)); mainListView.setEmptyView(refresh); loading.setVisibility(View.INVISIBLE); } else { mainListView.setEmptyView(loading); } // Finish setting up the listview mainListView.setOnItemClickListener(selectEpisode); mainListView.setBackgroundColor(getResources().getColor(R.color.backClr)); mainListView.setCacheColorHint(getResources().getColor(R.color.backClr)); setTitle(currentShow); // Get the shows from the SQL; make it async because of reasons new GetShowTask().execute((Object[]) null); Cursor r = StaticBlob.databaseConnector.getShow(currentShow, filter); showAdapter = new ShowListCursorAdapter(ShowList.this, R.layout.row, r); mainListView.setAdapter(showAdapter); return; }
public void addButton(ViewGroup layout, final String description, final CommandBuilder builder) { Button button = new Button(this); button.setGravity(Gravity.LEFT); button.setTransformationMethod(null); // or else button text is all upper case 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(); if (description.startsWith("(11.1)")) { if (((OsmandApplication) getApplication()).getSettings().AUDIO_STREAM_GUIDANCE.get() == 0) { Toast.makeText( TestVoiceActivity.this, AbstractPrologCommandPlayer.btScoInit + "\nBT SCO init delay: " + ((OsmandApplication) getApplication()) .getSettings() .BT_SCO_DELAY .get() + " ms", Toast.LENGTH_LONG) .show(); } else { Toast.makeText( TestVoiceActivity.this, "Action only available for Phone Call Audio", Toast.LENGTH_LONG) .show(); } } if (description.startsWith("(11.2)")) { if (((OsmandApplication) getApplication()).getSettings().AUDIO_STREAM_GUIDANCE.get() == 0) { if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 1000) { ((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(1500); } else if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 1500) { ((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(2000); } else if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 2000) { ((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(2500); } else if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 2500) { ((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(1000); } Toast.makeText( TestVoiceActivity.this, "BT SCO init delay changed to " + ((OsmandApplication) getApplication()) .getSettings() .BT_SCO_DELAY .get() + " ms", Toast.LENGTH_LONG) .show(); } else { Toast.makeText( TestVoiceActivity.this, "Action only available for Phone Call Audio", Toast.LENGTH_LONG) .show(); } } if (description.startsWith("(11.3)")) { final String systemVoiceUsed = AbstractPrologCommandPlayer.getCurrentVersion() > 99 ? TTSCommandPlayerImpl.getTtsVoiceName() : "Recorded voice"; Toast.makeText( TestVoiceActivity.this, "System's language availability status and voice actually used:\n\n" + systemVoiceUsed, Toast.LENGTH_LONG) .show(); } } }); }