@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); }
/** Создаёт новую кнопку элемента меню */ 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; }
private void initGameBoard() { mTableLayout = (TableLayout) findViewById(R.id.table_layout); mTableLayout.setStretchAllColumns(true); // mTableLayout.setBackgroundResource(R.color.blue); int counter = 1; for (int row = 0; row < 3; row++) { TableRow tableRow = new TableRow(this); for (int col = 0; col < 3; col++) { Button button = new Button(this); button.setTag(counter); // button.setText(row+","+col+"\nTag:"+button.getTag()); button.setOnClickListener(this); button.setWidth(300); button.setHeight(300); button.setTextSize(40); tableRow.addView(button); counter++; } mTableLayout.addView(tableRow, new TableLayout.LayoutParams(FP, WC)); } }
@Override protected void onCreate(Bundle savedInstanceState) { // TODO 自動生成されたメソッド・スタブ super.onCreate(savedInstanceState); setContentView(R.layout.private_status); linear = (LinearLayout) findViewById(R.id.linear); Bundle list; list = getIntent().getExtras(); Name = (TextView) findViewById(R.id.name); color4 = getResources().getColor(R.color.color4); if (list != null) { name = list.getString("name"); status = list.getInt("status"); position = list.getInt("position"); } linear.setBackgroundColor(color4); Name.setText(name); Display display = getWindowManager().getDefaultDisplay(); Point p = new Point(); display.getSize(p); Button button1 = (Button) findViewById(R.id.lab); button1.setOnClickListener(this); button1.setWidth(p.x / 3); button1.setHeight(p.y / 4); Button button2 = (Button) findViewById(R.id.campus); button2.setOnClickListener(this); button2.setWidth(p.x / 3); button2.setHeight(p.y / 4); Button button3 = (Button) findViewById(R.id.home); button3.setOnClickListener(this); button3.setWidth(p.x / 3); button3.setHeight(p.y / 4); Button button4 = (Button) findViewById(R.id.back); button4.setOnClickListener(this); button4.setWidth(p.x / 3); button4.setHeight(p.y / 4); Button button5 = (Button) findViewById(R.id.Contact); button5.setOnClickListener(this); button5.setWidth(p.x / 3); button5.setHeight(p.y / 4); ImageView imageView = (ImageView) findViewById(R.id.imageview1); // imageView.setImageBitmap(CustomAdapter.circle(position)); }
void createButtons() { for (int i = 0; i < 9; i++) { Button a = new Button(this); a.setWidth(50); a.setHeight(20); a.setText("9"); a.setTag(i); a.setOnClickListener(this); buttons.add(a); } }
public void setTitleAndRightImageButton( CharSequence title, int backid, onRightImageButtonClickListener onRightImageButtonClickListener) { setDefaultTitle(title); mLayoutRightContainer.setVisibility(View.VISIBLE); if (mRightImageButton != null && backid > 0) { mRightImageButton.setWidth(PixelUtil.dp2px(30)); mRightImageButton.setHeight(PixelUtil.dp2px(30)); mRightImageButton.setTextColor(getResources().getColor(R.color.transparent)); mRightImageButton.setBackgroundResource(backid); setOnRightImageButtonClickListener(onRightImageButtonClickListener); } }
public void setTitleAndRightButton( CharSequence title, int backid, String text, onRightImageButtonClickListener onRightImageButtonClickListener) { setDefaultTitle(title); mLayoutRightContainer.setVisibility(View.VISIBLE); if (mRightImageButton != null && backid > 0) { mRightImageButton.setWidth(PixelUtil.dp2px(45)); mRightImageButton.setHeight(PixelUtil.dp2px(40)); mRightImageButton.setBackgroundResource(backid); mRightImageButton.setText(text); setOnRightImageButtonClickListener(onRightImageButtonClickListener); } }
private void af(int paramInt, String paramString) { switch (9.hMp[(paramInt - 1)]) { } for (;;) { if ((paramInt != b.hMv) && (paramInt != b.hMx)) { break label225; } dEQ.setOnTouchListener(hMg); deK.setOnClickListener(hMh); return; if (be.kf(paramString)) { paramInt = b.hMx; paramString = null; break; } hLS.setVisibility(0); hLQ.setVisibility(8); hLU.setVisibility(4); hLR.setVisibility(8); hLT.setText(paramString); fw(true); continue; hLS.setVisibility(0); hLQ.setVisibility(0); hLU.setVisibility(0); if (paramString != null) { hLT.setText(paramString); fw(false); continue; hLS.setVisibility(8); hLQ.setVisibility(8); hLU.setHeight(0); hLU.setVisibility(8); hLR.setVisibility(0); } } label225: dEQ.setOnTouchListener(null); deK.setOnClickListener(null); }
void testPositioning() { for (int i = 0; i < 9; i++) { Button a = new Button(this); a.setWidth(50); a.setHeight(20); a.setText("9"); buttons.add(a); } firstTop.addView(buttons.get(0)); secondTop.addView(buttons.get(1)); thirdTop.addView(buttons.get(2)); firstBottom.addView(buttons.get(3)); secondBottom.addView(buttons.get(4)); thirdBottom.addView(buttons.get(5)); firstCenter.addView(buttons.get(6)); secondCenter.addView(buttons.get(7)); thirdCenter.addView(buttons.get(8)); }
/** @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) } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); LinearLayout ll = new LinearLayout(getActivity()); ll.setOrientation(LinearLayout.VERTICAL); ll.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP); Button label = new Button(getActivity()); label.setText("Toggle Skybox"); label.setTextSize(20); label.setGravity(Gravity.CENTER_HORIZONTAL); label.setHeight(100); ll.addView(label); label.setOnClickListener((SkyboxRenderer) mRenderer); mLayout.addView(ll); return mLayout; }
@Override public View getView(int position, View convertView, ViewGroup parent) { Button button; if (convertView == null) { button = new Button(ctx); button.setText("" + (data[position])); } else { button = (Button) convertView; } if (position >= levelMax) { button.setEnabled(false); button.setAlpha(0.5f); } button.setId(data[position]); button.setTextSize(diametr * 0.2f); button.setWidth(diametr); button.setHeight(diametr); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { button.setBackground( ctx.getApplicationContext().getResources().getDrawable(R.drawable.button_sm)); } button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { int lv = v.getId(); Intent intent = new Intent(ctx, GameActivity.class); SharedPreferences spref = ctx.getSharedPreferences("MyPref", Context.MODE_PRIVATE); SharedPreferences.Editor ed = spref.edit(); ed.putInt("Level", lv); ed.putBoolean("start", true); for (int i = 1; i <= 4; i++) { ed.putInt("figure" + i + "position", 0); ed.putInt("figure" + i + "rotation", 1); } ed.commit(); ctx.startActivity(intent); } }); return button; }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Interface graphique final float scale = this.getResources().getDisplayMetrics().density; int pad = (int) (5 * scale + 0.5f); // 5dp to px. LinearLayout linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setBackgroundColor(0xFF34495e); linearLayout.setPadding(10 * pad, 10 * pad, 10 * pad, pad); TextView textView = new TextView(this); textView.setText("Application test pour API NFC"); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25); textView.setGravity(Gravity.CENTER_HORIZONTAL); textView.setPadding(pad, pad, pad, 6 * pad); textView.setTextColor(0xFFecf0f1); // textView.setLayoutParams(lp); linearLayout.addView(textView); Button button = new Button(this); button.setClickable(true); button.setText("Read a TAG"); button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25); button.setHeight(300); button.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Test.this, ReadActivity.class); Test.this.startActivity(intent); } }); linearLayout.addView(button); Button buttonWrite = new Button(this); buttonWrite.setClickable(true); buttonWrite.setText("Write On TAG"); buttonWrite.setHeight(300); buttonWrite.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25); buttonWrite.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Test.this, WriteActivity.class); Test.this.startActivity(intent); } }); linearLayout.addView(buttonWrite); setContentView(linearLayout); // FIN Interface graphique mAdapter = NfcAdapter.getDefaultAdapter(this); // mPendingIntent = PendingIntent.getActivity( this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED); try { ndef.addDataType("*/*"); } catch (MalformedMimeTypeException e) { throw new RuntimeException("fail", e); } mFilters = new IntentFilter[] { ndef, }; // Setup a tech list for all MifareClassic tags mTechLists = new String[][] {new String[] {MifareClassic.class.getName()}}; Intent intent = getIntent(); onNewIntent(intent); }
// Method to create a button, giving different functionality dependent on mode public void createButton( String name, final BluetoothDevice device, final BluetoothSocket socket, String mode, Boolean prox) { Button b = new Button(this); b.setAlpha(0f); b.setMinimumWidth(300); b.setMinimumHeight(80); b.setText(name); b.setTextColor(Color.argb(255, 0, 162, 232)); Button.OnClickListener btnclick = null; // If device is an IA if (mode.equals("IA")) { // Check if device should be activated on proximity if (prox) { OutputStream outStream; try { outStream = socket.getOutputStream(); String message = "1"; byte[] toSend = message.getBytes(); outStream.write(toSend); } catch (IOException e) { e.printStackTrace(); } } b.setCompoundDrawablesWithIntrinsicBounds(R.drawable.light_off, 0, 0, 0); btnclick = new Button.OnClickListener() { @Override public void onClick(View v) { final InputStream inStream; final OutputStream outStream; try { // Request current output level outStream = socket.getOutputStream(); String message = "r"; byte[] toSend = message.getBytes(); outStream.write(toSend); inStream = socket.getInputStream(); // Data collection is pending gotData = 1; // Run timer in thread to prevent stalling Thread getInput = new Thread( new Runnable() { @Override public void run() { try { // Give small delay Thread.sleep(100); byte byt[] = new byte[1]; // Check if reply from IA if (inStream.available() > 0) { int received = inStream.read(byt, 0, 1); inStream.read(); inStream.read(); if (received == 1) { // Toggle output power level if (((int) byt[0] & 0xff) == '0') { String message = "1"; byte[] toSend = message.getBytes(); outStream.write(toSend); } else if (((int) byt[0] & 0xff) == '1') { String message = "0"; byte[] toSend = message.getBytes(); outStream.write(toSend); } } // Data received gotData = 2; // Else no reply, IA has lost connection } else { // No data received gotData = 0; } } catch (Exception e) { e.getLocalizedMessage(); } } }); getInput.start(); // Wait until gotData is 0 or 2 while (gotData == 1) {} // If not data then notify and refresh if (gotData == 0) { Toast.makeText(getBaseContext(), R.string.no_data, Toast.LENGTH_LONG).show(); refresh(); } } catch (IOException e) { e.printStackTrace(); } } }; // Or if device is TA } else if (mode.equals("TA")) { b.setCompoundDrawablesWithIntrinsicBounds(R.drawable.tv_icon, 0, 0, 0); btnclick = new Button.OnClickListener() { @Override public void onClick(View v) { television(device.getAddress()); } }; } b.setOnClickListener(btnclick); final Button settingsButton = new Button(this); settingsButton.setHeight(60); settingsButton.setWidth(60); settingsButton.setBackgroundResource(R.drawable.settings); settingsButton.setTextColor(Color.argb(255, 0, 162, 232)); // Set associated variables settingsButton.setTag(R.string.zero, device.getAddress()); settingsButton.setTag(R.string.one, b); Button.OnClickListener popup = null; // TA settings if (mode.equals("TA")) { popup = new Button.OnClickListener() { @Override public void onClick(final View v) { PopupMenu popup = new PopupMenu(getApplicationContext(), settingsButton); // Use layout for TA settings popup.getMenuInflater().inflate(R.menu.device_options, popup.getMenu()); popup.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { // If rename button was pressed if (item.getTitle().equals("Rename")) { rename(v.getTag(R.string.zero), v.getTag(R.string.one)); } return true; } }); popup.show(); } }; // IA settings } else if (mode.equals("IA")) { popup = new Button.OnClickListener() { @Override public void onClick(final View v) { PopupMenu popup = new PopupMenu(getApplicationContext(), settingsButton); popup.getMenuInflater().inflate(R.menu.ia_device_options, popup.getMenu()); popup.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { if (item.getTitle().equals("Rename")) { rename(v.getTag(R.string.zero), v.getTag(R.string.one)); } SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); if (item.getTitle().equals("Activate on proximity")) { editor.putBoolean(device.getAddress() + "prox", true); editor.commit(); } if (item.getTitle().equals("Do not activate on proximity")) { editor.putBoolean(device.getAddress() + "prox", false); editor.commit(); } return true; } }); popup.show(); } }; } settingsButton.setOnClickListener(popup); // Add button to list and animate ViewGroup layout = (ViewGroup) findViewById(R.id.home_page); RelativeLayout LL = new RelativeLayout(this); LL.setMinimumHeight(90); settingsButton.setX(310); settingsButton.setY(10); Button cover = new Button(this); cover.setBackgroundResource(R.drawable.scroll_cover); cover.setX(10); cover.setHeight(80); Button block = new Button(this); block.setBackgroundColor(Color.BLACK); block.setX(10); block.setHeight(80); b.setAlpha(1f); appear(b); appearAndSlide(cover); appearAndHide(block); deleteObject(cover, 2000); deleteObject(block, 1000); delayedAppear(settingsButton); LL.addView(b); LL.addView(settingsButton); LL.addView(block); LL.addView(cover); layout.addView(LL); }
private void GetAnswers(Integer _id) { openDatabaseConnection(); String WhereStatement = "QUESTIONITEM " + "= " + String.valueOf(_id); String[] Columns = {"CORRECT", "ANSWERTEXT", "REASON"}; Cursor c = myDbHelper.query("ANSWERS", Columns, WhereStatement, null, null, null, null); if (c.getCount() > 0) { c.moveToFirst(); List<Answer> list = new ArrayList<Answer>(); CorrectAnswerList = new ArrayList<Answer>(); CorrectAnswerInHTMLList = new ArrayList<String>(); do { Answer ans = new Answer(); ans.set_Correct(c.getInt(c.getColumnIndex("CORRECT"))); ans.set_AnswerText(c.getString(c.getColumnIndex("ANSWERTEXT"))); ans.set_Reason(c.getString(c.getColumnIndex("REASON"))); list.add(ans); // if the answer is correct keep the string in HTML if (ans.get_Correct() == 1) { String CorrectAnswerInHTML = ans.get_AnswerText(); CorrectAnswerReasonInHTML = ans.get_Reason(); CorrectAnswerList.add(ans); // Collection of correct answers CorrectAnswerInHTMLList.add(CorrectAnswerInHTML); CorrectAnswerInHTMLListCounter++; } } while (c.moveToNext()); c.close(); myDbHelper.close(); // Add the number of Answer to the CorrectAnswerListCounter CorrectAnswerListCounter = CorrectAnswerList.size(); // Initialize button array ButtonArray = new ArrayList<Button>(); for (int current = 0; current < list.size(); current++) { Answer ThisAns = list.get(current); // Create a table row TableRow tr = new TableRow(this); tr.setId(1000 + current); tr.setGravity(Gravity.CENTER); tr.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); /*TextView Tv = new TextView(this); Tv.setId(1000+current); Tv.setText(Html.fromHtml(ThisAns.get_AnswerText())); Tv.setTextColor(Color.WHITE); tr.addView(Tv); Table.addView(tr);*/ // Configure each button and add to row and then add row to table Button bt = new Button(this); bt.setId(1000 + current); bt.setText(Html.fromHtml(ThisAns.get_AnswerText())); bt.setTextColor(Color.BLACK); bt.setGravity(Gravity.CENTER); bt.setWidth(420); bt.setHeight(LayoutParams.WRAP_CONTENT); bt.setTextSize(12); // Add the correct answer to the button bt.setTag(ThisAns.get_Correct()); bt.setOnClickListener(this); // Add button the button array ButtonArray.add(bt); tr.addView(bt); Table.addView(tr); } } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); try { // try to get matrix config String fname = "battleship"; File file = getBaseContext().getFileStreamPath(fname); if (file.exists()) { // read from file DataInputStream in = new DataInputStream(openFileInput(fname)); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { P1[i][j] = Integer.parseInt(in.readUTF()); } } for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { P2[i][j] = Integer.parseInt(in.readUTF()); } } in.close(); } } catch (IOException e) { Log.i("Data Input Sample", "I/O Error"); } RelativeLayout hugelay = new RelativeLayout(this); ScrollView largelay = new ScrollView(this); largelay.setId(10000); TableLayout layout = new TableLayout(this); layout.setLayoutParams(new TableLayout.LayoutParams(300, 300)); layout.setPadding(1, 1, 1, 1); int i, j; for (i = 0; i <= 9; i++) { TableRow tr = new TableRow(this); for (j = 0; j <= 9; j++) { ImageButton b = new ImageButton(this); if (P2[i][j] == 0) { b.setImageResource(R.drawable.water); } else if (P2[i][j] == 99) { b.setImageResource(R.drawable.explosion); } else if (P2[i][j] == 88) { b.setImageResource(R.drawable.x); } else { b.setImageResource(R.drawable.water2); } b.setId(i * 10 + j); b.setOnClickListener(this); tr.addView(b, 72, 72); } // for layout.addView(tr); } // for largelay.addView(layout); hugelay.setBackgroundResource(R.drawable.battleshipbg); Button btn = new Button(this); btn.setText("MY MAP"); btn.setBackgroundResource(R.color.transparent); btn.setHeight(134); btn.setWidth(134); btn.setId(1000); btn.setOnClickListener(this); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.RIGHT_OF, largelay.getId()); lp.addRule(RelativeLayout.CENTER_VERTICAL); hugelay.addView(largelay); hugelay.addView(btn, lp); super.setContentView(hugelay); } // ()