private void populateSecondForm(LinearLayout formLayout) {
    formLayout.addView(createTitle(mContext.getString(R.string.account_create_password_title)));
    EditText passwordEditText =
        createEditText(
            mContext.getString(R.string.account_create_password_hint),
            InputType.TYPE_CLASS_TEXT,
            EditorInfo.IME_ACTION_DONE,
            false,
            PASSWORD_KEY);
    passwordEditText.setTransformationMethod(new PasswordTransformationMethod());

    formLayout.addView(passwordEditText);
    formLayout.addView(createErrorView(PASSWORD_KEY));

    formLayout.addView(createTitle(mContext.getString(R.string.account_create_gender_title)));
    Spinner spinner = new Spinner(mContext);
    LinearLayout.LayoutParams params =
        new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    params.bottomMargin = 17;
    spinner.setLayoutParams(params);

    final ArrayAdapter<CharSequence> adapter =
        ArrayAdapter.createFromResource(
            mContext, R.array.sexes_array, android.R.layout.simple_spinner_item);
    spinner.setAdapter(adapter);
    spinner.setPrompt(mContext.getString(R.string.account_create_sex_spinner_prompt));
    spinner.setOnItemSelectedListener(
        new OnItemSelectedListener() {

          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

            mFormData.put(GENDER_KEY, adapter.getItem(pos).toString());
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {}
        });

    if (mFormData.get(GENDER_KEY) != null) {
      spinner.setSelection(adapter.getPosition(mFormData.get(GENDER_KEY)));
    }

    formLayout.addView(spinner);
  }
 public FormBuilder addSpinner(String fieldName, String tag, SpinnerAdapter da) {
   TextView tv = new TextView(context);
   tv.setTextColor(theme.getTextColor());
   tv.setLayoutParams(new LayoutParams(theme.getLabelWidth(), theme.getLabelHeight()));
   ll.addView(tv);
   Spinner s = new Spinner(context);
   s.setTag(tag);
   s.setLayoutParams(new LayoutParams(theme.getLabelWidth(), theme.getLabelHeight()));
   s.setAdapter(da);
   ll.addView(s);
   return this;
 }
  private void populateThirdForm(LinearLayout formLayout) {
    formLayout.addView(createTitle(mContext.getString(R.string.account_create_city_title)));
    EditText cityEditText =
        createEditText(
            mContext.getString(R.string.account_create_city_hint),
            InputType.TYPE_CLASS_TEXT,
            EditorInfo.IME_ACTION_DONE,
            false,
            CITY_KEY);

    if (mFormData.get(CITY_KEY) != null) {
      cityEditText.setText(mFormData.get(CITY_KEY));
    }

    formLayout.addView(cityEditText);
    formLayout.addView(createErrorView(CITY_KEY));

    formLayout.addView(createTitle(mContext.getString(R.string.account_create_country_title)));

    Spinner spinner = new Spinner(mContext);
    LinearLayout.LayoutParams params =
        new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    params.bottomMargin = 17;
    spinner.setLayoutParams(params);

    final ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(
            mContext, android.R.layout.simple_spinner_item, Countries.COUNTRIES);
    spinner.setAdapter(adapter);
    spinner.setPrompt(mContext.getString(R.string.account_create_country_spinner_prompt));
    spinner.setOnItemSelectedListener(
        new OnItemSelectedListener() {

          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

            mFormData.put(COUNTRY_KEY, Countries.COUNTRY_CODES[pos]);
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {}
        });

    if (mFormData.get(COUNTRY_KEY) != null) {
      List<String> array = Arrays.asList(Countries.COUNTRY_CODES);
      spinner.setSelection(array.indexOf(mFormData.get(COUNTRY_KEY)));
    }

    formLayout.addView(spinner);
  }
Example #4
0
  @SuppressLint("NewApi")
  private void setSpinner(Spinner spinner, List<String> data) {
    LayoutParams lpView = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lpView.setMargins(50, 10, 10, 10);
    spinner.setLayoutParams(lpView);
    // Drawable d = mContext.getResources().getDrawable(
    //		R.drawable.dropdown_selector);
    // spinner.setBackground(d); // API Level 16
    // spinner.setBackgroundResource(R.drawable.dropdown_selector);
    spinner.setOnItemSelectedListener(itemSelectedListener);
    // TestAdapter adapter = new TestAdapter(mContext, data);
    ArrayAdapter<String> nameAdapter =
        new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item, data);

    nameAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    spinner.setAdapter(nameAdapter);
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(LT, "App created.");

    Events.intEnableDebug(1);

    // disable the titlebar
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    // create a basic user interface
    LinearLayout panel = new LinearLayout(this);
    panel.setOrientation(LinearLayout.VERTICAL);
    setContentView(panel);
    // --
    Button b = new Button(this);
    b.setText("Scan Input Devs");
    b.setId(idButScan);
    b.setOnClickListener(this);
    panel.addView(b);
    // --
    m_lvDevices = new ListView(this);
    m_lvDevices.setLayoutParams(
        new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    m_lvDevices.setId(idLVDevices);
    m_lvDevices.setDividerHeight(0);
    m_lvDevices.setFadingEdgeLength(0);
    m_lvDevices.setCacheColorHint(0);
    m_lvDevices.setAdapter(null);
    panel.addView(m_lvDevices);
    // --
    LinearLayout panelH = new LinearLayout(this);
    panelH.setOrientation(LinearLayout.HORIZONTAL);
    panel.addView(panelH);
    // --
    m_selDevSpinner = new Spinner(this);
    m_selDevSpinner.setLayoutParams(
        new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    m_selDevSpinner.setId(idSelSpin);
    m_selDevSpinner.setOnItemSelectedListener((OnItemSelectedListener) this);
    panelH.addView(m_selDevSpinner);
    // -- simulate key event
    b = new Button(this);
    b.setText(">Key");
    b.setId(idButInjectKey);
    b.setOnClickListener(this);
    panelH.addView(b);
    // -- simulate touch event
    b = new Button(this);
    b.setText(">Tch");
    b.setId(idButInjectTouch);
    b.setOnClickListener(this);
    panelH.addView(b);

    // --
    m_tvMonitor = new TextView(this);
    m_tvMonitor.setText("Event Monitor stopped.");
    panel.addView(m_tvMonitor);
    // --
    panelH = new LinearLayout(this);
    panelH.setOrientation(LinearLayout.HORIZONTAL);
    panel.addView(panelH);
    // --
    b = new Button(this);
    b.setText("Monitor Start");
    b.setId(idButMonitorStart);
    b.setOnClickListener(this);
    panelH.addView(b);
    // --
    b = new Button(this);
    b.setText("Monitor Stop");
    b.setId(idButMonitorStop);
    b.setOnClickListener(this);
    panelH.addView(b);
    // -- simulate test event
    b = new Button(this);
    b.setText(">Test");
    b.setId(idButTest);
    b.setOnClickListener(this);
    panelH.addView(b);
  }
Example #6
0
  protected void onCreate(Bundle savedInstanceState) {
    final FotoBot fb = (FotoBot) getApplicationContext();
    super.onCreate(savedInstanceState);
    fb.LoadSettings();

    // fb.logger.fine("Tab_Foto_Activity");

    Log.d(LOG_TAG, "Tab3: onCreate");
    //      final FotoBot fb = (FotoBot) getApplicationContext();
    Display display = getWindowManager().getDefaultDisplay();
    screenWidth = display.getWidth();
    screenHeight = display.getHeight();

    // Main Container (Vertical LinearLayout)
    LinearLayout FullFrame = new LinearLayout(this);
    FullFrame.setOrientation(LinearLayout.VERTICAL);
    FullFrame.setPadding(5, 5, 5, 5);
    FullFrame.setBackgroundColor(Color.rgb(192, 192, 192));
    LinearLayout.LayoutParams lpFull_Frame =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
    FullFrame.setLayoutParams(lpFull_Frame);
    FullFrame.setMinimumHeight(fb.Working_Area_Height - fb.menuheight);
    // FullFrame.setBackgroundColor(Color.WHITE);
    //  setContentView(FullFrame);

    // ------------------------------------------------------------------------------------------------

    // JPEG сжатие

    // Контейнер для JPG сжатие
    RelativeLayout linLayout_JPEG_Compression = new RelativeLayout(this);
    //   linLayout_JPEG_Compression.setOrientation(LinearLayout.HORIZONTAL);
    RelativeLayout.LayoutParams lpView =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams lpView_m =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    LinearLayout.LayoutParams lpView_et =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    linLayout_JPEG_Compression.setBackgroundColor(Color.rgb(192, 192, 192));

    // Контейнер для пояснение
    LinearLayout linLayout_JPEG_Compression_notes = new LinearLayout(this);
    linLayout_JPEG_Compression_notes.setOrientation(LinearLayout.HORIZONTAL);
    linLayout_JPEG_Compression_notes.setBackgroundColor(Color.rgb(192, 192, 192));

    // Контейнер для разделителя
    LinearLayout linLayout_JPEG_Compression_divider = new LinearLayout(this);
    linLayout_JPEG_Compression_divider.setOrientation(LinearLayout.HORIZONTAL);
    linLayout_JPEG_Compression_divider.setPadding(5, 9, 5, 9);

    // Название
    TextView tv_JPEG_Compression = new TextView(this);
    tv_JPEG_Compression.setTypeface(Typeface.DEFAULT_BOLD);
    tv_JPEG_Compression.setTextSize(TypedValue.COMPLEX_UNIT_SP, fb.Config_Font_Size);
    tv_JPEG_Compression.setTextColor(Color.BLACK);
    tv_JPEG_Compression.setText(getResources().getString(R.string.jpeg_compression));
    tv_JPEG_Compression.setWidth((screenWidth - padding) / 100 * 80);
    tv_JPEG_Compression.setLayoutParams(lpView);
    tv_JPEG_Compression.setTypeface(Typeface.DEFAULT_BOLD);

    lpView.addRule(RelativeLayout.ALIGN_PARENT_LEFT, tv_JPEG_Compression.getId());
    tv_JPEG_Compression.setLayoutParams(lpView);
    linLayout_JPEG_Compression.addView(tv_JPEG_Compression);

    // Ввод данных

    editText_JPEG_Compression = new EditText(this);
    editText_JPEG_Compression.setLayoutParams(lpView_et);
    String jpg = Integer.toString(fb.JPEG_Compression);
    editText_JPEG_Compression.setText(jpg);
    editText_JPEG_Compression.setTextColor(Color.rgb(50, 100, 150));
    ViewGroup.LayoutParams lp = editText_JPEG_Compression.getLayoutParams();
    lp.width = (screenWidth - padding) / 100 * 20;
    editText_JPEG_Compression.setLayoutParams(lp);
    //   editText_JPEG_Compression.setGravity(Gravity.RIGHT);

    lpView_m.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, editText_JPEG_Compression.getId());
    editText_JPEG_Compression.setLayoutParams(lpView_m);
    linLayout_JPEG_Compression.addView(editText_JPEG_Compression);

    // Заметка для JPEG сжатия
    TextView tv_JPEG_Compression_note = new TextView(this);
    tv_JPEG_Compression_note.setTypeface(null, Typeface.NORMAL);
    tv_JPEG_Compression_note.setTextSize(TypedValue.COMPLEX_UNIT_SP, fb.Config_Font_Size - 2);
    tv_JPEG_Compression_note.setTextColor(Color.BLACK);
    tv_JPEG_Compression_note.setText(
        getResources().getString(R.string.jpeg_compression_description));
    // tv_Channels_notes.setWidth((screenWidth - padding) / 100 * 99);
    tv_JPEG_Compression_note.setLayoutParams(lpView);
    //  tv_JPEG_Compression_note.setTextColor(Color.GRAY);
    tv_JPEG_Compression_note.setPadding(5, 9, 5, 9);
    linLayout_JPEG_Compression_notes.addView(tv_JPEG_Compression_note);

    // Разделитель
    View line_JPEG_Compression = new View(this);
    line_JPEG_Compression.setLayoutParams(
        new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 1));
    line_JPEG_Compression.setBackgroundColor(Color.rgb(210, 210, 210));
    line_JPEG_Compression.getLayoutParams().height = 3;
    linLayout_JPEG_Compression_divider.addView(line_JPEG_Compression);

    // ------------------------------------------------------------------------------------------------

    // Метод обработки фото

    // Контейнер для метода
    RelativeLayout linLayout_Photo_Processing_Method = new RelativeLayout(this);
    //   linLayout_Photo_Processing_Method.setOrientation(LinearLayout.HORIZONTAL);
    linLayout_Photo_Processing_Method.setBackgroundColor(Color.rgb(192, 192, 192));
    RelativeLayout.LayoutParams lpView_m1 =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams lpView_m2 =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

    //        LinearLayout.LayoutParams lpView = new
    // LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
    // LinearLayout.LayoutParams.WRAP_CONTENT);
    //      LinearLayout.LayoutParams lpView_et = new
    // LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
    // LinearLayout.LayoutParams.WRAP_CONTENT);

    // Контейнер для пояснение
    LinearLayout linLayout_Photo_Processing_Method_notes = new LinearLayout(this);
    linLayout_Photo_Processing_Method_notes.setOrientation(LinearLayout.HORIZONTAL);
    linLayout_Photo_Processing_Method_notes.setBackgroundColor(Color.rgb(192, 192, 192));

    // Контейнер для разделителя
    LinearLayout linLayout_Photo_Processing_Method_divider = new LinearLayout(this);
    linLayout_Photo_Processing_Method_divider.setOrientation(LinearLayout.HORIZONTAL);
    linLayout_Photo_Processing_Method_divider.setPadding(5, 9, 5, 9);

    // Название
    TextView tv_Photo_Processing_Method = new TextView(this);
    tv_Photo_Processing_Method.setTypeface(Typeface.DEFAULT_BOLD);
    tv_Photo_Processing_Method.setTextSize(TypedValue.COMPLEX_UNIT_SP, fb.Config_Font_Size);
    tv_Photo_Processing_Method.setTextColor(Color.BLACK);
    tv_Photo_Processing_Method.setText(getResources().getString(R.string.photo_processing_method));
    //   tv_Photo_Processing_Method.setWidth((screenWidth - padding) / 100 * 80);
    //   tv_Photo_Processing_Method.setLayoutParams(lpView);
    tv_Photo_Processing_Method.setTypeface(Typeface.DEFAULT_BOLD);

    lpView_m1.addRule(RelativeLayout.ALIGN_PARENT_LEFT, tv_Photo_Processing_Method.getId());
    lpView_m1.width = (screenWidth - padding) / 100 * 60;
    tv_Photo_Processing_Method.setLayoutParams(lpView_m1);
    linLayout_Photo_Processing_Method.addView(tv_Photo_Processing_Method);

    // Список
    spinnerArray_ppm = new ArrayList<String>();
    spinnerArray_ppm.add("Hardware");
    spinnerArray_ppm.add("Software");

    spinner_ppm = new Spinner(this);
    ArrayAdapter<String> spinnerArrayAdapter_ppm =
        new ArrayAdapter<String>(this, R.layout.spinner_item, spinnerArray_ppm);
    spinner_ppm.setAdapter(spinnerArrayAdapter_ppm);
    spinner_ppm.setSelection(getIndex(spinner_ppm, fb.Photo_Post_Processing_Method));
    spinner_ppm.setMinimumWidth((screenWidth - padding) / 100 * 50);
    spinner_ppm.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {

          public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

            if (spinnerArray_ppm.get(i) == "Hardware") {
              tv_Photo_Size_s.setVisibility(View.GONE);
              spinner_Software.setVisibility(View.GONE);
              tv_Photo_Size_h.setVisibility(View.VISIBLE);
              spinner_Hardware.setVisibility(View.VISIBLE);
              linLayout_Photo_Size_h_notes.setVisibility(View.VISIBLE);
              linLayout_Photo_Size_s_notes.setVisibility(View.GONE);
            } else {
              tv_Photo_Size_s.setVisibility(View.VISIBLE);
              spinner_Software.setVisibility(View.VISIBLE);
              tv_Photo_Size_h.setVisibility(View.GONE);
              spinner_Hardware.setVisibility(View.GONE);
              linLayout_Photo_Size_h_notes.setVisibility(View.GONE);
              linLayout_Photo_Size_s_notes.setVisibility(View.VISIBLE);
            }
          }

          // If no option selected
          public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

          }
        });

    lpView_m2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, spinner_ppm.getId());
    lpView_m2.width = (screenWidth - padding) / 100 * 40;
    spinner_ppm.setLayoutParams(lpView_m2);
    linLayout_Photo_Processing_Method.addView(spinner_ppm);

    // Заметка для метода
    TextView tv_Photo_Processing_Method_note = new TextView(this);
    tv_Photo_Processing_Method_note.setTypeface(null, Typeface.NORMAL);
    tv_Photo_Processing_Method_note.setTextSize(
        TypedValue.COMPLEX_UNIT_SP, fb.Config_Font_Size - 2);
    tv_Photo_Processing_Method_note.setTextColor(Color.BLACK);
    tv_Photo_Processing_Method_note.setText(
        getResources().getString(R.string.photo_processing_method_dscription));
    // tv_Channels_notes.setWidth((screenWidth - padding) / 100 * 99);
    tv_Photo_Processing_Method_note.setLayoutParams(lpView);
    //   tv_Photo_Processing_Method_note.setTextColor(Color.GRAY);
    tv_Photo_Processing_Method_note.setPadding(5, 9, 5, 9);
    linLayout_Photo_Processing_Method_notes.addView(tv_Photo_Processing_Method_note);

    // ------------------------------------------------------------------------------------------------

    // Параметры изображения

    // Контейнер для метода
    RelativeLayout linLayout_Photo_Size = new RelativeLayout(this);
    // linLayout_Photo_Size.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout.LayoutParams lpView_photo_size =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    LinearLayout.LayoutParams lpView_photo_size_et =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    RelativeLayout.LayoutParams lpView_m3 =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams lpView_m4 =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams lpView_m5 =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams lpView_m6 =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

    linLayout_Photo_Size.setBackgroundColor(Color.rgb(192, 192, 192));

    // Контейнер для пояснение
    linLayout_Photo_Size_h_notes = new LinearLayout(this);
    linLayout_Photo_Size_h_notes.setOrientation(LinearLayout.HORIZONTAL);
    linLayout_Photo_Size_h_notes.setBackgroundColor(Color.rgb(192, 192, 192));

    // Контейнер для пояснение
    linLayout_Photo_Size_s_notes = new LinearLayout(this);
    linLayout_Photo_Size_s_notes.setOrientation(LinearLayout.HORIZONTAL);
    linLayout_Photo_Size_s_notes.setBackgroundColor(Color.rgb(192, 192, 192));

    // Контейнер для разделителя
    LinearLayout linLayout_Photo_Size_divider = new LinearLayout(this);
    linLayout_Photo_Processing_Method_divider.setOrientation(LinearLayout.HORIZONTAL);
    linLayout_Photo_Processing_Method_divider.setPadding(5, 9, 5, 9);

    // Масштаб фото
    tv_Photo_Size_h = new TextView(this);
    tv_Photo_Size_h.setTypeface(Typeface.DEFAULT_BOLD);
    tv_Photo_Size_h.setTextSize(14);
    tv_Photo_Size_h.setTextColor(Color.BLACK);
    tv_Photo_Size_h.setText(getResources().getString(R.string.photo_scale));
    // tv_Photo_Size_h.setWidth((screenWidth - padding) / 100 * 80);
    tv_Photo_Size_h.setLayoutParams(lpView_photo_size);

    lpView_m3.addRule(RelativeLayout.ALIGN_PARENT_LEFT, tv_Photo_Size_h.getId());
    lpView_m3.width = (screenWidth - padding) / 100 * 60;
    tv_Photo_Size_h.setLayoutParams(lpView_m3);
    linLayout_Photo_Size.addView(tv_Photo_Size_h);

    // Коэффициенты масштабирования
    ArrayList<String> spinnerArray_Hardware = new ArrayList<String>();
    spinnerArray_Hardware.add("1/16");
    spinnerArray_Hardware.add("1/8");
    spinnerArray_Hardware.add("1/4");
    spinnerArray_Hardware.add("1/2");
    spinnerArray_Hardware.add("1");

    spinner_Hardware = new Spinner(this);
    spinnerArrayAdapter_Hardware =
        new ArrayAdapter<String>(this, R.layout.spinner_item, spinnerArray_Hardware);
    spinner_Hardware.setAdapter(spinnerArrayAdapter_Hardware);
    spinner_Hardware.setSelection(getIndex(spinner_Hardware, fb.Image_Scale));
    //  spinner_Hardware.setMinimumWidth((screenWidth - padding) / 100 * 20);
    // spinner_Hardware.setGravity(Gravity.RIGHT);

    lpView_m4.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, spinner_Hardware.getId());
    lpView_m4.width = (screenWidth - padding) / 100 * 40;
    spinner_Hardware.setLayoutParams(lpView_m4);
    linLayout_Photo_Size.addView(spinner_Hardware);

    // Размер фото
    tv_Photo_Size_s = new TextView(this);
    tv_Photo_Size_s.setTypeface(Typeface.DEFAULT_BOLD);
    tv_Photo_Size_s.setTextSize(TypedValue.COMPLEX_UNIT_SP, fb.Config_Font_Size);
    tv_Photo_Size_s.setTextColor(Color.BLACK);
    tv_Photo_Size_s.setText(getResources().getString(R.string.photo_resolution));
    //  tv_Photo_Size_s.setWidth((screenWidth - padding) / 100 * 80);
    tv_Photo_Size_s.setLayoutParams(lpView_photo_size);

    lpView_m5.addRule(RelativeLayout.ALIGN_PARENT_LEFT, tv_Photo_Size_s.getId());
    lpView_m5.width = (screenWidth - padding) / 100 * 60;
    tv_Photo_Size_s.setLayoutParams(lpView_m5);
    linLayout_Photo_Size.addView(tv_Photo_Size_s);

    // Доступные разрешения
    ArrayList<String> spinnerArray = new ArrayList<String>();

    Camera.Size mSize = null;

    int fe_w = (int) fb.camera_resolutions.get(0).width;
    int fe_h = (int) fb.camera_resolutions.get(0).height;
    float fe_s, fe_z;

    fe_z = (float) fe_w / (float) fe_h;

    for (Camera.Size size : fb.camera_resolutions) {
      fe_w = (int) size.width;
      fe_h = (int) size.height;
      fe_s = (float) fe_w / (float) fe_h;

      if (Math.abs(fe_s - fe_z) < 0.01f) {
        spinnerArray.add(size.width + "x" + size.height);
      }
    }

    spinner_Software = new Spinner(this);
    spinnerArrayAdapter1 = new ArrayAdapter<String>(this, R.layout.spinner_item, spinnerArray);
    spinner_Software.setAdapter(spinnerArrayAdapter1);

    spinner_Software.setSelection(getIndex(spinner_Software, fb.Image_Size));
    //   spinner_Software.setMinimumWidth((screenWidth - padding) / 100 * 20);
    //  spinner_Software.setGravity(Gravity.RIGHT);

    lpView_m6.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, spinner_Software.getId());
    lpView_m6.width = (screenWidth - padding) / 100 * 40;
    spinner_Software.setLayoutParams(lpView_m6);

    linLayout_Photo_Size.addView(spinner_Software);

    // Заметка для Hardware
    TextView tv_Photo_Size_h_note = new TextView(this);
    tv_Photo_Size_h_note.setTypeface(null, Typeface.NORMAL);
    tv_Photo_Size_h_note.setTextSize(TypedValue.COMPLEX_UNIT_SP, fb.Config_Font_Size - 2);
    tv_Photo_Size_h_note.setTextColor(Color.BLACK);
    tv_Photo_Size_h_note.setText("Hardware");
    // tv_Channels_notes.setWidth((screenWidth - padding) / 100 * 99);
    tv_Photo_Size_h_note.setLayoutParams(lpView);
    // tv_Photo_Size_h_note.setTextColor(Color.GRAY);
    tv_Photo_Size_h_note.setPadding(5, 9, 5, 9);
    linLayout_Photo_Size_h_notes.addView(tv_Photo_Size_h_note);

    // Заметка для Software
    TextView tv_Photo_Size_s_note = new TextView(this);
    tv_Photo_Size_s_note.setTypeface(null, Typeface.NORMAL);
    tv_Photo_Size_s_note.setTextSize(TypedValue.COMPLEX_UNIT_SP, fb.Config_Font_Size - 2);
    tv_Photo_Size_s_note.setTextColor(Color.BLACK);
    tv_Photo_Size_s_note.setText("Software");
    // tv_Channels_notes.setWidth((screenWidth - padding) / 100 * 99);
    tv_Photo_Size_s_note.setLayoutParams(lpView);
    //   tv_Photo_Size_s_note.setTextColor(Color.GRAY);
    tv_Photo_Size_s_note.setPadding(5, 9, 5, 9);
    linLayout_Photo_Size_s_notes.addView(tv_Photo_Size_s_note);

    // Разделитель
    View line_Photo_Size = new View(this);
    line_Photo_Size.setLayoutParams(
        new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 1));
    line_Photo_Size.setBackgroundColor(Color.rgb(210, 210, 210));
    line_Photo_Size.getLayoutParams().height = 3;
    linLayout_Photo_Size_divider.addView(line_Photo_Size);

    // ------------------------------------------------------------------------------------------------

    // Вспышка

    // Flash Container
    RelativeLayout linLayout_Flash = new RelativeLayout(this);
    // linLayout_Flash.setOrientation(LinearLayout.HORIZONTAL);
    RelativeLayout.LayoutParams lpView_Flash =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams lpView_Flash_m =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    LinearLayout.LayoutParams lpView_et_Flash =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    linLayout_Flash.setBackgroundColor(Color.rgb(192, 192, 192));

    // Flash TextView
    TextView tv_Flash = new TextView(this);
    tv_Flash.setText(getResources().getString(R.string.flash));
    tv_Flash.setWidth((screenWidth - padding) / 100 * 90);
    tv_Flash.setLayoutParams(lpView_Flash);
    tv_Flash.setTypeface(Typeface.DEFAULT_BOLD);
    tv_Flash.setTextSize(TypedValue.COMPLEX_UNIT_SP, fb.Config_Font_Size);
    tv_Flash.setTextColor(Color.BLACK);

    lpView_Flash.addRule(RelativeLayout.ALIGN_PARENT_LEFT, tv_Flash.getId());
    tv_Flash.setLayoutParams(lpView_Flash);
    linLayout_Flash.addView(tv_Flash);

    // CheckBox
    checkBox_Flash = new CheckBox(this);
    checkBox_Flash.setChecked(fb.Use_Flash);

    lpView_Flash_m.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, checkBox_Flash.getId());
    checkBox_Flash.setLayoutParams(lpView_Flash_m);
    linLayout_Flash.addView(checkBox_Flash);

    // Second Container (Horizontal LinearLayout)
    LinearLayout linLayout2 = new LinearLayout(this);
    linLayout2.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout.LayoutParams lpView2 =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    LinearLayout.LayoutParams lpViewbutton =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    linLayout2.setGravity(Gravity.BOTTOM | Gravity.CENTER);

    // linLayout2.setLayoutParams(lpView2);

    // ------------------------------------------------------------------------------------------------

    // Buttons

    // Container
    LinearLayout linLayout_Buttons = new LinearLayout(this);
    linLayout_Buttons.setOrientation(LinearLayout.HORIZONTAL);
    linLayout_Buttons.setGravity(Gravity.BOTTOM | Gravity.CENTER);
    LinearLayout.LayoutParams lpViewbutton1 =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
    LinearLayout.LayoutParams lpViewbutton2 =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
    lpViewbutton1.setMargins(0, 0, 5, 0);
    LinearLayout.LayoutParams lpView3 =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
    linLayout_Buttons.setLayoutParams(lpView3);
    linLayout_Buttons.setBackgroundColor(Color.rgb(192, 192, 192));
    linLayout_Buttons.setPadding(15, 15, 15, 15);

    linLayout_Buttons.setBaselineAligned(false);
    linLayout_Buttons.setGravity(Gravity.BOTTOM);

    // Apply Button
    btn = new Button(this);
    btn.setText(getResources().getString(R.string.apply_button));
    btn.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    btn.setBackgroundColor(Color.rgb(90, 89, 91));
    btn.setTextColor(Color.rgb(250, 250, 250));
    btn.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);

    btn.setOnTouchListener(
        new View.OnTouchListener() {

          @Override
          public boolean onTouch(View view, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
              btn.setBackgroundColor(Color.rgb(90, 90, 90));
            } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
              btn.setBackgroundColor(Color.rgb(128, 128, 128));
            }
            return false;
          }
        });

    btn.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            SharedPreferences pref =
                getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE);
            SharedPreferences.Editor editor = pref.edit();

            if (checkBox_Flash.isChecked()) {
              editor.putBoolean("Use_Flash", true);
            } else {
              editor.putBoolean("Use_Flash", false);
            }

            String input = editText_JPEG_Compression.getText().toString();
            editor.putString(
                "Photo_Post_Processing_Method", spinner_ppm.getSelectedItem().toString());
            editor.putInt(
                "JPEG_Compression",
                Integer.parseInt(editText_JPEG_Compression.getText().toString()));
            editor.putString("Image_Scale", spinner_Hardware.getSelectedItem().toString());
            editor.putString("Image_Size", spinner_Software.getSelectedItem().toString());

            // Save the changes in SharedPreferences
            editor.commit(); // commit changes
          }
        });

    // GoTo Main Page Button
    btn_mp = new Button(this);
    btn_mp.setText(getResources().getString(R.string.back_button));
    btn_mp.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    btn_mp.setBackgroundColor(Color.rgb(90, 89, 91));
    btn_mp.setTextColor(Color.rgb(250, 250, 250));
    // lpViewbutton2.setMargins(5,5,5,5);
    btn_mp.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);

    btn_mp.setOnTouchListener(
        new View.OnTouchListener() {

          @Override
          public boolean onTouch(View view, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
              btn_mp.setBackgroundColor(Color.rgb(90, 90, 90));
            } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
              btn_mp.setBackgroundColor(Color.rgb(128, 128, 128));
            }
            return false;
          }
        });

    btn_mp.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Intent intent;
            intent = new Intent(v.getContext(), MainActivity.class);
            startActivity(intent);
          }
        });

    linLayout_Buttons.addView(btn, lpViewbutton1);
    linLayout_Buttons.addView(btn_mp, lpViewbutton2);

    FullFrame.addView(linLayout_JPEG_Compression);
    FullFrame.addView(linLayout_JPEG_Compression_notes);
    //   FullFrame.addView(linLayout_JPEG_Compression_divider);

    FullFrame.addView(linLayout_Photo_Processing_Method);
    FullFrame.addView(linLayout_Photo_Processing_Method_notes);

    FullFrame.addView(linLayout_Photo_Size);
    FullFrame.addView(linLayout_Photo_Size_h_notes);
    FullFrame.addView(linLayout_Photo_Size_s_notes);
    //        FullFrame.addView(linLayout_Photo_Size_divider);

    FullFrame.addView(linLayout_Flash);

    FullFrame.addView(linLayout_Buttons);

    ScrollView m_Scroll = new ScrollView(this);
    m_Scroll.setLayoutParams(
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
    m_Scroll.addView(
        FullFrame,
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));

    setContentView(m_Scroll);
  }
Example #7
0
  private void createNewContactObject(String type, View my_contact_view) {
    if (my_contact_view == null) {
      my_contact_view = fragment_mycontact.getView();
    }

    if (my_contact_view == null) return;

    LinearLayout ll_data;
    List<String> list = new ArrayList<String>();
    int it = android.text.InputType.TYPE_CLASS_TEXT;
    int hint = 0;

    // Typen setzen:
    List<Integer> list_number = new ArrayList<Integer>();

    for (int i = 0; i < array_en_type.length; i++) {
      if (array_en_type[i].equals(type)) {
        list_number.add(i);
      }
    }

    for (int i = 0; i < list_number.size(); i++) {
      list.add((array_en_name[list_number.get(i)]));
    }

    final String[] spinnerArray = list.toArray(new String[list.size()]);

    // -----------

    LinearLayout ll_telephone =
        (LinearLayout) my_contact_view.findViewById(R.id.mycontact_ll_data_telephone);
    LinearLayout ll_email =
        (LinearLayout) my_contact_view.findViewById(R.id.mycontact_ll_data_email);
    LinearLayout ll_other =
        (LinearLayout) my_contact_view.findViewById(R.id.mycontact_ll_data_other);

    // new row
    LinearLayout row = new LinearLayout(this);
    row.setOrientation(LinearLayout.HORIZONTAL);

    DisplayMetrics tmp_metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(tmp_metrics);
    int resolution_width = tmp_metrics.widthPixels;

    final boolean large_screen = (resolution_width >= 720);

    final EditText et = new EditText(this);
    LayoutParams lp_et;
    lp_et = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1);

    if (type.equals("number")) {
      ll_data = ll_telephone;

      it = InputType.TYPE_CLASS_PHONE;

      hint = R.string.telephone;

    } else if (type.equals("email")) {
      ll_data = ll_email;

      it = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;

      hint = R.string.email;

    } else {
      ll_data = ll_other;

      if (type.equals("address")) {

        et.setMinLines(1);
        et.setMaxLines(3);
        et.setLines(2);

        hint = R.string.address;
        it =
            InputType.TYPE_CLASS_TEXT
                | InputType
                    .TYPE_TEXT_FLAG_MULTI_LINE; // android.text.InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS;
        lp_et = new LayoutParams(LayoutParams.WRAP_CONTENT, large_screen ? 130 : 90, 1);

        row.setLayoutParams(
            new LayoutParams(LayoutParams.MATCH_PARENT, (large_screen ? 130 : 90) + 20));

        et.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
        // et.setGravity(Gravity.LEFT | Gravity.TOP );

      } else if (type.equals("website")) {
        hint = R.string.website;
        it = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
      }
    }

    ((LinearLayout) ll_data.getParent()).setVisibility(LinearLayout.VISIBLE);

    et.setTextSize(large_screen ? 16 : 14); // EditText-Textgr��e
    et.setEms(10);
    et.setHint(hint);

    et.setInputType(it);

    lp_et.setMargins(0, 3, 0, 0);
    et.setLayoutParams(lp_et);

    Spinner spinner = new Spinner(this);
    LayoutParams lp_spinner =
        new LayoutParams(
            large_screen ? Functions.dpsToPx(this, 100) : Functions.dpsToPx(this, 80), /*300 : 200*/
            LayoutParams.MATCH_PARENT);

    lp_spinner.setMargins(0, 3, 0, 0);

    MySpinnerArrayAdapter dataAdapter = new MySpinnerArrayAdapter(this, list, large_screen);

    dataAdapter.setDropDownViewResource(
        android.support.v7.appcompat.R.layout.support_simple_spinner_dropdown_item);

    spinner.setAdapter(dataAdapter);
    spinner.setLayoutParams(lp_spinner);

    spinner.setOnItemSelectedListener(
        new OnItemSelectedListener() {

          @Override
          public void onItemSelected(
              final AdapterView<?> adapterView, final View view, int arg2, long arg3) {
            final Spinner spinner = (Spinner) adapterView;
            MySpinnerArrayAdapter adapter = (MySpinnerArrayAdapter) spinner.getAdapter();
            if (adapter
                .getItem(arg2)
                .toLowerCase(new Locale("en"))
                .equals(getString(R.string.en_custom).toLowerCase(new Locale("en")))) {

              LinearLayout ll = new LinearLayout(MainActivity.this);
              final EditText et = new EditText(MainActivity.this);

              LinearLayout.LayoutParams layoutParams =
                  new LinearLayout.LayoutParams(
                      LinearLayout.LayoutParams.MATCH_PARENT,
                      LinearLayout.LayoutParams.WRAP_CONTENT);
              layoutParams.setMargins(0, 20, 0, 0);

              et.setTextColor(Color.BLACK);
              et.requestFocus();

              // et.setHint(R.string.place);

              ll.addView(et, layoutParams);

              AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
              builder
                  .setView(ll)
                  .setTitle(R.string.message_custom_en)
                  .setPositiveButton(
                      android.R.string.ok,
                      new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                          String[] newItems = new String[spinnerArray.length + 1];
                          System.arraycopy(spinnerArray, 0, newItems, 0, spinnerArray.length);
                          newItems[newItems.length - 1] = et.getText().toString();

                          MySpinnerArrayAdapter adapter =
                              new MySpinnerArrayAdapter(
                                  getApplicationContext(),
                                  newItems,
                                  ((MySpinnerArrayAdapter) spinner.getAdapter()).getLargeScreen());
                          spinner.setAdapter(adapter);
                          spinner.setSelection(newItems.length - 1);
                        }
                      })
                  .setNegativeButton(
                      android.R.string.cancel,
                      new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {}
                      })
                  .create()
                  .show();
            }
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

          }
        });

    Button btn = new Button(this);
    btn.setText("x");
    LayoutParams lp_btn = new LayoutParams(Functions.dpsToPx(this, 32), LayoutParams.WRAP_CONTENT);
    lp_btn.setMargins(-10, 0, -10, 0);
    btn.setLayoutParams(lp_btn);
    btn.setBackgroundColor(Color.TRANSPARENT);

    btn.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            if (((LinearLayout) v.getParent().getParent()).getChildCount() == 1) {
              ((LinearLayout) v.getParent().getParent().getParent()).setVisibility(View.GONE);
            }
            ((LinearLayout) v.getParent().getParent()).removeView((LinearLayout) v.getParent());
          }
        });

    row.addView(et);
    row.addView(spinner);
    row.addView(btn);

    row.setTag(type);

    ll_data.addView(row);
  }
Example #8
0
  private View getView(int mId, cl.tdc.felipe.tdc.objects.Relevar.Item item) {
    String type = item.getType();
    List<String> values = item.getValues();
    LinearLayout contenido = new LinearLayout(this);
    LinearLayout.LayoutParams params =
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    contenido.setLayoutParams(params);
    params.setMargins(0, 6, 0, 0);
    contenido.setOrientation(LinearLayout.VERTICAL);
    contenido.setGravity(Gravity.CENTER_HORIZONTAL);
    String comment = "";

    if (type.equals("SELECT")) {
      Spinner s = new Spinner(this);
      s.setBackgroundResource(R.drawable.spinner_bg);
      s.setLayoutParams(
          new LinearLayout.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
      ArrayAdapter<String> adapter =
          new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, values);
      s.setAdapter(adapter);
      String id = mId + item.getId() + item.getName() + values.toString();
      s.setId(Funciones.str2int(id));
      String Selected = reg.getString("SELECT" + s.getId());
      s.setSelection(adapter.getPosition(Selected));
      contenido.addView(s);
      item.setVista(s);

      comment = reg.getString("COMMENTSELECT" + s.getId());

    } else if (type.equals("CHECK")) {
      LinearLayout checkboxLayout = new LinearLayout(this);
      checkboxLayout.setLayoutParams(
          new LinearLayout.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
      checkboxLayout.setOrientation(LinearLayout.VERTICAL);
      ArrayList<CheckBox> checkBoxes = new ArrayList<>();
      int count = 0;
      while (count < values.size()) {
        LinearLayout dump = new LinearLayout(this);
        dump.setOrientation(LinearLayout.HORIZONTAL);
        dump.setGravity(Gravity.CENTER_HORIZONTAL);
        dump.setLayoutParams(
            new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        for (int p = 0; p < 3; p++) {
          if (count < values.size()) {
            String state = values.get(count);
            CheckBox cb = new CheckBox(this);
            String id = mId + item.getId() + item.getName() + values.get(count);
            cb.setId(Funciones.str2int(id));
            cb.setChecked(reg.getBoolean("CHECK" + cb.getId()));
            cb.setText(state);

            checkBoxes.add(cb);
            dump.addView(cb);
            if (count == 0) comment = reg.getString("COMMENTCHECK" + cb.getId());
            count++;
            vistas.add(cb);
          }
        }
        checkboxLayout.addView(dump);
      }
      makeOnlyOneCheckable(checkBoxes);
      item.setCheckBoxes(checkBoxes);
      contenido.addView(checkboxLayout);
    } else if (type.equals("NUM")) {
      EditText e = new EditText(this);
      e.setBackgroundResource(R.drawable.fondo_edittext);
      e.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);

      String id = mId + item.getId() + item.getName();
      e.setId(Funciones.str2int(id));
      e.setText(reg.getString("TEXT" + e.getId()));
      e.setLayoutParams(new LinearLayout.LayoutParams(100, ViewGroup.LayoutParams.WRAP_CONTENT));
      e.setGravity(Gravity.CENTER_HORIZONTAL);
      vistas.add(e);
      item.setVista(e);
      contenido.addView(e);

      comment = reg.getString("COMMENTTEXT" + e.getId());
    } else if (type.equals("VARCHAR")) {
      EditText e = new EditText(this);
      e.setBackgroundResource(R.drawable.fondo_edittext);
      e.setInputType(InputType.TYPE_CLASS_TEXT);
      e.setLines(2);
      e.setGravity(Gravity.LEFT | Gravity.TOP);

      String id = mId + item.getId() + item.getName();
      e.setId(Funciones.str2int(id));
      e.setText(reg.getString("TEXT" + e.getId()));
      vistas.add(e);
      item.setVista(e);
      contenido.addView(e);
      comment = reg.getString("COMMENTTEXT" + e.getId());
    }

    if (!item.getName().equals("COMENTARIOS")) {
      EditText comentario = new EditText(this);
      comentario.setLayoutParams(params);
      comentario.setBackgroundResource(R.drawable.fondo_edittext);
      comentario.setLines(3);
      comentario.setText(comment);
      comentario.setHint("Observaciones");
      item.setDescription(comentario);
      contenido.addView(comentario);
    }
    return contenido;
  }
Example #9
0
  public void displayAccounts() {
    accounts = b2evolution.DB.getAccounts(this);
    HashMap<?, ?> notificationOptions = b2evolution.DB.getNotificationOptions(this);
    boolean sound = false, vibrate = false, light = false, taglineValue = false;
    String tagline = "";

    if (notificationOptions != null) {
      if (notificationOptions.get("sound").toString().equals("1")) {
        sound = true;
      }
      if (notificationOptions.get("vibrate").toString().equals("1")) {
        vibrate = true;
      }
      if (notificationOptions.get("light").toString().equals("1")) {
        light = true;
      }
      if (notificationOptions.get("tagline_flag").toString().equals("1")) {
        taglineValue = true;
      }
      tagline = notificationOptions.get("tagline").toString();
    }

    if (accounts.size() > 0) {
      ScrollView sv = new ScrollView(this);
      sv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
      sv.setBackgroundColor(Color.parseColor("#FFFFFFFF"));
      LinearLayout layout = new LinearLayout(this);

      layout.setPadding(14, 14, 14, 14);
      layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

      layout.setOrientation(LinearLayout.VERTICAL);
      layout.setGravity(Gravity.LEFT);

      final LinearLayout cbLayout = new LinearLayout(this);

      cbLayout.setLayoutParams(
          new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

      cbLayout.setOrientation(LinearLayout.VERTICAL);

      LinearLayout.LayoutParams section1Params =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

      section1Params.setMargins(0, 0, 0, 20);

      LinearLayout section1 = new LinearLayout(this);
      section1.setBackgroundDrawable(getResources().getDrawable(R.drawable.content_bg));
      section1.setLayoutParams(section1Params);
      section1.setOrientation(LinearLayout.VERTICAL);

      LinearLayout.LayoutParams headerParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      headerParams.setMargins(1, 1, 1, 0);
      TextView textView = new TextView(this);
      textView.setLayoutParams(headerParams);
      textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      textView.setTypeface(Typeface.DEFAULT_BOLD);
      textView.setPadding(0, 4, 0, 4);
      textView.setShadowLayer(1, 0, 2, Color.parseColor("#FFFFFFFF"));
      textView.setBackgroundDrawable(getResources().getDrawable(R.drawable.content_bg_header));
      textView.setText("  " + getResources().getText(R.string.comment_notifications));

      section1.addView(textView);

      LinearLayout.LayoutParams cbParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      cbParams.setMargins(4, 0, 0, 6);

      for (int i = 0; i < accounts.size(); i++) {

        HashMap<?, ?> curHash = (HashMap<?, ?>) accounts.get(i);
        String curBlogName = curHash.get("blogName").toString();
        String accountID = curHash.get("id").toString();
        int runService = Integer.valueOf(curHash.get("runService").toString());
        accountNames.add(i, curBlogName);

        final CheckBox checkBox = new CheckBox(this);
        checkBox.setTextColor(Color.parseColor("#444444"));
        checkBox.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        checkBox.setText(EscapeUtils.unescapeHtml(curBlogName));
        checkBox.setId(Integer.valueOf(accountID));
        checkBox.setLayoutParams(cbParams);

        if (runService == 1) {
          checkBox.setChecked(true);
        }

        cbLayout.addView(checkBox);
      }

      if (cbLayout.getChildCount() > 0) {
        section1.addView(cbLayout);
      }

      // add spinner and buttons
      TextView textView2 = new TextView(this);
      LinearLayout.LayoutParams labelParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      labelParams.setMargins(8, 0, 0, 0);
      textView2.setLayoutParams(labelParams);
      textView2.setTextColor(Color.parseColor("#444444"));
      textView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      textView2.setText(getResources().getText(R.string.notifications_interval));

      section1.addView(textView2);

      final Spinner sInterval = new Spinner(this);
      LinearLayout.LayoutParams spinnerParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      spinnerParams.setMargins(4, 0, 4, 10);
      sInterval.setLayoutParams(spinnerParams);
      ArrayAdapter<Object> sIntervalArrayAdapter =
          new ArrayAdapter<Object>(
              this,
              R.layout.spinner_textview,
              new String[] {
                "5 Minutes",
                "10 Minutes",
                "15 Minutes",
                "30 Minutes",
                "1 Hour",
                "3 Hours",
                "6 Hours",
                "12 Hours",
                "Daily"
              });
      sIntervalArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      sInterval.setAdapter(sIntervalArrayAdapter);
      String interval = b2evolution.DB.getInterval(this);

      if (interval != "") {
        sInterval.setSelection(sIntervalArrayAdapter.getPosition(interval));
      }

      section1.addView(sInterval);

      final LinearLayout nOptionsLayout = new LinearLayout(this);

      nOptionsLayout.setLayoutParams(
          new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

      nOptionsLayout.setOrientation(LinearLayout.VERTICAL);

      CheckBox soundCB = new CheckBox(this);
      soundCB.setTag("soundCB");
      soundCB.setTextColor(Color.parseColor("#444444"));
      soundCB.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      soundCB.setText(getResources().getText(R.string.notification_sound));
      soundCB.setLayoutParams(cbParams);
      soundCB.setChecked(sound);

      nOptionsLayout.addView(soundCB);

      CheckBox vibrateCB = new CheckBox(this);
      vibrateCB.setTag("vibrateCB");
      vibrateCB.setTextColor(Color.parseColor("#444444"));
      vibrateCB.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      vibrateCB.setText(getResources().getText(R.string.notification_vibrate));
      vibrateCB.setLayoutParams(cbParams);
      vibrateCB.setChecked(vibrate);

      nOptionsLayout.addView(vibrateCB);

      CheckBox lightCB = new CheckBox(this);
      lightCB.setTag("lightCB");
      lightCB.setTextColor(Color.parseColor("#444444"));
      lightCB.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      lightCB.setText(getResources().getText(R.string.notification_blink));
      lightCB.setLayoutParams(cbParams);
      lightCB.setChecked(light);

      nOptionsLayout.addView(lightCB);

      section1.addView(nOptionsLayout);

      layout.addView(section1);

      final LinearLayout section2 = new LinearLayout(this);
      section2.setBackgroundDrawable(getResources().getDrawable(R.drawable.content_bg));
      section2.setOrientation(LinearLayout.VERTICAL);
      LinearLayout.LayoutParams section2Params =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      section2Params.setMargins(0, 0, 0, 20);
      section2.setLayoutParams(section2Params);
      section2.setPadding(0, 0, 0, 10);

      TextView section2lbl = new TextView(this);
      section2lbl.setLayoutParams(headerParams);
      section2lbl.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      section2lbl.setTypeface(Typeface.DEFAULT_BOLD);
      section2lbl.setShadowLayer(1, 0, 2, Color.parseColor("#FFFFFFFF"));
      section2lbl.setPadding(0, 4, 0, 4);
      section2lbl.setText("  " + getResources().getText(R.string.post_signature));
      section2lbl.setBackgroundDrawable(getResources().getDrawable(R.drawable.content_bg_header));

      section2.addView(section2lbl);

      CheckBox taglineCB = new CheckBox(this);
      taglineCB.setTag("taglineCB");
      taglineCB.setTextColor(Color.parseColor("#444444"));
      taglineCB.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      taglineCB.setText(getResources().getText(R.string.add_tagline));
      taglineCB.setLayoutParams(cbParams);
      taglineCB.setChecked(taglineValue);

      section2.addView(taglineCB);

      EditText taglineET = new EditText(this);
      LinearLayout.LayoutParams taglineParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      taglineParams.setMargins(4, 0, 4, 4);
      taglineET.setLayoutParams(taglineParams);
      if (tagline != null) {
        if (tagline.equals("")) {
          if (BlackBerryUtils.getInstance().isBlackBerry())
            taglineET.setText(getResources().getText(R.string.posted_from_blackberry));
          else taglineET.setText(getResources().getText(R.string.posted_from));
        } else {
          taglineET.setText(tagline);
        }
      }
      taglineET.setMinLines(2);
      section2.addView(taglineET);

      layout.addView(section2);

      final LinearLayout section3 = new LinearLayout(this);
      section3.setOrientation(LinearLayout.HORIZONTAL);
      section3.setGravity(Gravity.RIGHT);
      LinearLayout.LayoutParams section3Params =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      section3Params.setMargins(0, 0, 0, 20);
      section3.setLayoutParams(section3Params);

      final Button cancel = new Button(this);

      LinearLayout.LayoutParams cancelParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      cancelParams.setMargins(0, 0, 10, 0);
      cancel.setLayoutParams(cancelParams);
      cancel.setBackgroundDrawable(getResources().getDrawable(R.drawable.b2evo_button_small));
      cancel.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
      cancel.setText(getResources().getText(R.string.cancel));
      cancel.setOnClickListener(
          new Button.OnClickListener() {
            public void onClick(View v) {
              finish();
            }
          });
      section3.addView(cancel);

      final Button save = new Button(this);

      save.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
      save.setBackgroundDrawable(getResources().getDrawable(R.drawable.b2evo_button_small));
      save.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
      save.setText(getResources().getText(R.string.save));

      save.setOnClickListener(
          new Button.OnClickListener() {
            public void onClick(View v) {

              boolean sound = false, vibrate = false, light = false, tagValue = false;
              checkCtr = 0;

              int listItemCount = cbLayout.getChildCount();
              for (int i = 0; i < listItemCount; i++) {
                CheckBox cbox = (CheckBox) cbLayout.getChildAt(i);
                int id = cbox.getId();
                if (cbox.isChecked()) {
                  checkCtr++;
                  b2evolution.DB.updateNotificationFlag(id, true);
                  Log.i("CommentService", "Service enabled for " + cbox.getText());
                } else {
                  b2evolution.DB.updateNotificationFlag(id, false);
                }
              }

              int noOptionsItemCount = nOptionsLayout.getChildCount();
              for (int i = 0; i < noOptionsItemCount; i++) {
                CheckBox cbox = (CheckBox) nOptionsLayout.getChildAt(i);
                if (cbox.getTag().equals("soundCB")) {
                  sound = cbox.isChecked();
                } else if (cbox.getTag().equals("vibrateCB")) {
                  vibrate = cbox.isChecked();
                } else if (cbox.getTag().equals("lightCB")) {
                  light = cbox.isChecked();
                }
              }

              CheckBox tagFlag = (CheckBox) section2.getChildAt(1);
              tagValue = tagFlag.isChecked();

              EditText taglineET = (EditText) section2.getChildAt(2);
              String taglineText = taglineET.getText().toString();

              b2evolution.DB.updateNotificationSettings(
                  sInterval.getSelectedItem().toString(),
                  sound,
                  vibrate,
                  light,
                  tagValue,
                  taglineText);

              if (checkCtr > 0) {

                String updateInterval = sInterval.getSelectedItem().toString();
                int UPDATE_INTERVAL = 3600000;

                // configure time interval
                if (updateInterval.equals("5 Minutes")) {
                  UPDATE_INTERVAL = 300000;
                } else if (updateInterval.equals("10 Minutes")) {
                  UPDATE_INTERVAL = 600000;
                } else if (updateInterval.equals("15 Minutes")) {
                  UPDATE_INTERVAL = 900000;
                } else if (updateInterval.equals("30 Minutes")) {
                  UPDATE_INTERVAL = 1800000;
                } else if (updateInterval.equals("1 Hour")) {
                  UPDATE_INTERVAL = 3600000;
                } else if (updateInterval.equals("3 Hours")) {
                  UPDATE_INTERVAL = 10800000;
                } else if (updateInterval.equals("6 Hours")) {
                  UPDATE_INTERVAL = 21600000;
                } else if (updateInterval.equals("12 Hours")) {
                  UPDATE_INTERVAL = 43200000;
                } else if (updateInterval.equals("Daily")) {
                  UPDATE_INTERVAL = 86400000;
                }

                Intent intent = new Intent(Preferences.this, CommentBroadcastReceiver.class);
                PendingIntent pIntent = PendingIntent.getBroadcast(Preferences.this, 0, intent, 0);

                AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

                alarmManager.setRepeating(
                    AlarmManager.RTC_WAKEUP,
                    System.currentTimeMillis() + (5 * 1000),
                    UPDATE_INTERVAL,
                    pIntent);

              } else {
                Intent stopIntent = new Intent(Preferences.this, CommentBroadcastReceiver.class);
                PendingIntent stopPIntent =
                    PendingIntent.getBroadcast(Preferences.this, 0, stopIntent, 0);
                AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
                alarmManager.cancel(stopPIntent);

                Intent service = new Intent(Preferences.this, CommentService.class);
                stopService(service);
              }

              finish();
            }
          });

      section3.addView(save);
      layout.addView(section3);

      sv.addView(layout);

      setContentView(sv);
    }
  }