@Override protected void onCreate() { // inflate layout LayoutInflater inflater = (LayoutInflater) this.anchor.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); ViewGroup root = (ViewGroup) inflater.inflate(R.layout.popup_grid_layout, null); // setup button events for (int i = 0, icount = root.getChildCount(); i < icount; i++) { View v = root.getChildAt(i); if (v instanceof TableRow) { TableRow row = (TableRow) v; for (int j = 0, jcount = row.getChildCount(); j < jcount; j++) { View item = row.getChildAt(j); if (item instanceof Button) { Button b = (Button) item; b.setOnClickListener(this); } } } } // set the inflated view as what we want to display this.setContentView(root); }
/** * * Get move with coords relative to the view supplied * * @param view : is a ImageView (cell) in a rowView in a TableLayout * @return move coordinates */ private Move getMoveFromCase(ImageView view) { Move move = null; for (int j = 0; j < tableLayout.getChildCount(); j++) { TableRow rowView = (TableRow) tableLayout.getChildAt(j); for (int i = 0; i < rowView.getChildCount(); i++) { if (view.equals(rowView.getChildAt(i))) { // verifier la comparaison move = new Move(j, i); } } } return move; }
public void altTableRow(int alt_row) { int childViewCount = tablelayout.getChildCount(); for (int i = 0; i < childViewCount; i++) { TableRow row = (TableRow) tablelayout.getChildAt(i); for (int j = 0; j < row.getChildCount(); j++) { TextView tv = (TextView) row.getChildAt(j); if (i % alt_row != 0) { tv.setBackground(getResources().getDrawable(R.drawable.alt_row_color)); } else { tv.setBackground(getResources().getDrawable(R.drawable.row_color)); } } } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_remote_control, container, false); mSelectedTextView = (TextView) v.findViewById(R.id.fragment_remote_control_selectedTextView); mWorkingTextView = (TextView) v.findViewById(R.id.fragment_remote_control_workingTextView); View.OnClickListener numberButtonListener = new View.OnClickListener() { @Override public void onClick(View view) { TextView textView = (TextView) view; String working = mWorkingTextView.getText().toString(); String text = textView.getText().toString(); if (working.equals("0")) { mWorkingTextView.setText(text); } else { mWorkingTextView.setText(working + text); } } }; TableLayout tableLayout = (TableLayout) v.findViewById(R.id.fragment_remote_control_tablelayout); int number = 1; for (int i = 2; i < tableLayout.getChildCount() - 1; i++) { TableRow tableRow = (TableRow) tableLayout.getChildAt(i); for (int j = 0; j < tableRow.getChildCount(); j++) { Button button = (Button) tableRow.getChildAt(j); button.setText("" + number); button.setOnClickListener(numberButtonListener); number++; } } // Now lets handle the Delete and the Enter Button TableRow buttonRow = (TableRow) tableLayout.getChildAt(tableLayout.getChildCount() - 1); Button deleteButton = (Button) buttonRow.getChildAt(0); deleteButton.setText("Delete"); deleteButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { mWorkingTextView.setText("0"); } }); Button zeroButton = (Button) buttonRow.getChildAt(1); zeroButton.setText("0"); zeroButton.setOnClickListener(numberButtonListener); Button enterButton = (Button) buttonRow.getChildAt(2); enterButton.setText("Enter"); enterButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { CharSequence working = mWorkingTextView.getText(); if (working.length() > 0) mSelectedTextView.setText(working); mWorkingTextView.setText("0"); } }); return v; }
private void disableButtons() { for (int row = 0; row < buttonTableLayout.getChildCount(); ++row) { TableRow tableRow = (TableRow) buttonTableLayout.getChildAt(row); for (int i = 0; i < tableRow.getChildCount(); ++i) tableRow.getChildAt(i).setEnabled(false); } }
@Override public void onStart() { formulaEditorKeyboard.setClickable(true); getView().requestFocus(); View.OnTouchListener touchListener = new View.OnTouchListener() { private Handler handler; private Runnable deleteAction; private boolean handleLongClick(final View view, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { if (handler == null) { return true; } handler.removeCallbacks(deleteAction); handler = null; } if (event.getAction() == MotionEvent.ACTION_DOWN) { deleteAction = new Runnable() { @Override public void run() { handler.postDelayed(this, 100); if (formulaEditorEditText.isThereSomethingToDelete()) { formulaEditorEditText.handleKeyEvent(view.getId(), ""); } } }; if (handler != null) { return true; } handler = new Handler(); handler.postDelayed(deleteAction, 400); } return true; } @Override public boolean onTouch(View view, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { updateButtonsOnKeyboardAndInvalidateOptionsMenu(); view.setPressed(false); handleLongClick(view, event); return true; } if (event.getAction() == MotionEvent.ACTION_DOWN) { view.setPressed(true); switch (view.getId()) { case R.id.formula_editor_keyboard_compute: InternFormulaParser internFormulaParser = formulaEditorEditText.getFormulaParser(); FormulaElement formulaElement = internFormulaParser.parseFormula(); if (formulaElement == null) { if (internFormulaParser.getErrorTokenIndex() >= 0) { formulaEditorEditText.setParseErrorCursorAndSelection(); } return false; } Formula formulaToCompute = new Formula(formulaElement); FormulaEditorComputeDialog computeDialog = new FormulaEditorComputeDialog(context); computeDialog.setFormula(formulaToCompute); computeDialog.show(); return true; case R.id.formula_editor_keyboard_function: showFormularEditorCategorylistFragment( FormulaEditorCategoryListFragment.FUNCTION_TAG, R.string.formula_editor_functions); return true; case R.id.formula_editor_keyboard_logic: showFormularEditorCategorylistFragment( FormulaEditorCategoryListFragment.LOGIC_TAG, R.string.formula_editor_logic); return true; case R.id.formula_editor_keyboard_object: showFormularEditorCategorylistFragment( FormulaEditorCategoryListFragment.OBJECT_TAG, R.string.formula_editor_choose_object_variable); return true; case R.id.formula_editor_keyboard_sensors: showFormularEditorCategorylistFragment( FormulaEditorCategoryListFragment.SENSOR_TAG, R.string.formula_editor_device); return true; case R.id.formula_editor_keyboard_data: showFormulaEditorDataFragment( FormulaEditorDataFragment.USER_DATA_TAG, R.string.formula_editor_data); return true; case R.id.formula_editor_keyboard_ok: endFormulaEditor(); return true; case R.id.formula_editor_keyboard_string: FragmentManager fragmentManager = ((Activity) context).getFragmentManager(); Fragment dialogFragment = fragmentManager.findFragmentByTag(NewStringDialog.DIALOG_FRAGMENT_TAG); if (dialogFragment == null) { dialogFragment = NewStringDialog.newInstance(); } ((NewStringDialog) dialogFragment) .show(fragmentManager, NewStringDialog.DIALOG_FRAGMENT_TAG); return true; case R.id.formula_editor_keyboard_delete: formulaEditorEditText.handleKeyEvent(view.getId(), ""); return handleLongClick(view, event); default: formulaEditorEditText.handleKeyEvent(view.getId(), ""); return true; } } return false; } }; for (int index = 0; index < formulaEditorKeyboard.getChildCount(); index++) { View tableRow = formulaEditorKeyboard.getChildAt(index); if (tableRow instanceof TableRow) { TableRow row = (TableRow) tableRow; for (int indexRow = 0; indexRow < row.getChildCount(); indexRow++) { row.getChildAt(indexRow).setOnTouchListener(touchListener); } } } updateButtonsOnKeyboardAndInvalidateOptionsMenu(); super.onStart(); }
@Override protected void onPostExecute(List<Action> actions) { if (actions == null) { statusLabel.setText("Unable to get actions"); return; } // all is ok, replace start pane LinearLayout contentPane = (LinearLayout) findViewById(R.id.contentPane); contentPane.removeView(startPane); LinearLayout buttonsLayout = new LinearLayout(getApplicationContext()); buttonsLayout.setGravity(Gravity.CENTER); TableLayout buttonsTable = new TableLayout(getApplicationContext()); TableRow currentTableRow = new TableRow(getApplicationContext()); TableRow.LayoutParams buttonMarginParams = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); int marginPx = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics()); buttonMarginParams.setMargins(marginPx, marginPx, marginPx, marginPx); for (final Action action : actions) { ImageButton actionButton = new ImageButton(getApplicationContext()); int drawableId = getResources().getIdentifier(action.icon, "drawable", getPackageName()); actionButton.setImageDrawable(getResources().getDrawable(drawableId)); actionButton.setContentDescription(action.description); actionButton.setLayoutParams(buttonMarginParams); actionButton.setBackgroundResource(R.drawable.button); actionButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { new PerformActionAsyncTask().execute(action.name); } }); currentTableRow.addView(actionButton); if (currentTableRow.getChildCount() == 3) { buttonsTable.addView(currentTableRow); currentTableRow = new TableRow(getApplicationContext()); } } if (currentTableRow.getChildCount() > 0) { buttonsTable.addView(currentTableRow); } buttonsLayout.addView(buttonsTable); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); contentPane.addView(buttonsLayout, params); runStatusUpdateTimer(); }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mLockObect = new Object(); mPreference = getPreferences(MODE_PRIVATE); mOppacity = mPreference.getInt(PREFERENCE_OPPACITY_KEY, 0); mVerticalLogLinesWeight = mPreference.getInt(PREFERENCE_VERTICAL_WEIGHT_KEY, 0); mVerticalLogLinesOffset = mPreference.getInt(PREFERENCE_VERTICAL_OFFSET_KEY, 0); mHorizontalLogLinesWeight = mPreference.getInt(PREFERENCE_HORIZONTAL_WEIGHT_KEY, 0); mHorizontalLogLinesOffset = mPreference.getInt(PREFERENCE_HOZITONTAL_OFFSET_KEY, 0); mSelectedFontSizePosition = mPreference.getInt(PREFERENCE_SELECTED_FONT_SIZE_POSITION_KEY, 0); mSelectedFontColorPosition = mPreference.getInt(PREFERENCE_SELECTED_FONT_COLOR_POSITION_KEY, 0); mDisplayContentsCheckBoxState = mPreference.getInt(PREFERENCE_DISPLAY_CONTENTS_CHECKBOX_STATE_KEY, 0); mGrepEnable = mPreference.getBoolean(PREFERENCE_GREP_ENABLE_KEY, false); mGrepText = mPreference.getString(PREFERENCE_GREP_TEXT_KEY, ""); ToggleButton tb = (ToggleButton) findViewById(R.id.enableButton); tb.setChecked(LoggerService.isRunning(this)); tb.setOnCheckedChangeListener(mEnableButtonListener); Spinner fontSizeSpinner = (Spinner) findViewById(R.id.fontSizeSpinner); fontSizeSpinner.setSelection(mSelectedFontSizePosition); fontSizeSpinner.setOnItemSelectedListener(mFontsizeSpinnerListener); mFontSize = getResources().obtainTypedArray(R.array.fontsize).getInt(mSelectedFontSizePosition, 8); Spinner fontColorSpinner = (Spinner) findViewById(R.id.fontColorSpinner); fontColorSpinner.setOnItemSelectedListener(mFontColorSpinnerListener); fontColorSpinner.setSelection(mSelectedFontColorPosition); mFontColor = getResources() .obtainTypedArray(R.array.fontcolor_value) .getIndex(mSelectedFontColorPosition); TableLayout tblLayout = (TableLayout) findViewById(R.id.logContentCheckBox); int checkBoxCount = 0; for (int i = 0; i < tblLayout.getChildCount(); i++) { TableRow row = (TableRow) tblLayout.getChildAt(i); final int rowChildCound = row.getChildCount(); for (int j = 0; j < rowChildCound; j++) { CheckBox checkBox = (CheckBox) row.getChildAt(j); checkBox.setOnCheckedChangeListener(mContentsCheckBoxListener); checkBox.setTag(checkBoxCount); if ((mDisplayContentsCheckBoxState & (1 << checkBoxCount)) != 0) { mDisplayContents |= (1 << LOGCAT_COLUMN_POS[checkBoxCount]); checkBox.setChecked(true); } checkBoxCount++; } } ToggleButton grepEnableButton = (ToggleButton) findViewById(R.id.grepEnableButton); grepEnableButton.setOnCheckedChangeListener(mGrepEnableButtonListener); grepEnableButton.setChecked(mGrepEnable); EditText grepEditText = (EditText) findViewById(R.id.grepEditText); grepEditText.addTextChangedListener(mGrepTextWatcher); grepEditText.setText(mGrepText); SeekBar horizontalLogLinesWeightSB = (SeekBar) findViewById(R.id.horizontalSizeSlider); horizontalLogLinesWeightSB.setOnSeekBarChangeListener(mHorizontalLogLinesWeightSliderListener); horizontalLogLinesWeightSB.setProgress(mHorizontalLogLinesWeight); SeekBar verticalLogLinesWeightSB = (SeekBar) findViewById(R.id.logLinesSlider); verticalLogLinesWeightSB.setOnSeekBarChangeListener(mVerticalLogLinesWeightSliderListener); verticalLogLinesWeightSB.setProgress(mVerticalLogLinesWeight); SeekBar horizontalLogLinesOffsetSB = (SeekBar) findViewById(R.id.horizontalOffsetSlider); horizontalLogLinesOffsetSB.setOnSeekBarChangeListener(mHorizontalLogLinesOffsetSliderListener); horizontalLogLinesOffsetSB.setProgress(mHorizontalLogLinesOffset); SeekBar verticalLogLinesOffsetSB = (SeekBar) findViewById(R.id.verticalOffsetSlider); verticalLogLinesOffsetSB.setOnSeekBarChangeListener(mVerticalLogLinesOffsetSliderListener); verticalLogLinesOffsetSB.setProgress(mVerticalLogLinesOffset); SeekBar sb = (SeekBar) findViewById(R.id.opacitySlider); sb.setOnSeekBarChangeListener(mOpacitySliderListener); sb.setProgress(mOppacity); }