Пример #1
0
 public static void a(LinearLayout paramLinearLayout) {
   Display localDisplay =
       ((WindowManager) paramLinearLayout.getContext().getSystemService("window"))
           .getDefaultDisplay();
   paramLinearLayout.setMinimumWidth(localDisplay.getWidth() - 30);
   paramLinearLayout.setMinimumHeight(localDisplay.getHeight() - 40);
 }
Пример #2
0
  private void set_sizes() {
    int button_width =
        (((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth())
            / 3;
    int height =
        ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getHeight();

    LinearLayout ll1 = (LinearLayout) findViewById(R.id.LL_buttons_first);
    ll1.setMinimumHeight(height / 3);
    LinearLayout ll2 = (LinearLayout) findViewById(R.id.LL_buttons_second);
    ll2.setMinimumHeight(height / 3);
    button_rewind.setWidth(button_width);
    button_foward.setWidth(button_width);
    button_stop.setWidth(button_width);
    button_mute.setWidth(button_width);
    button_quit.setWidth(button_width);
    button_fullscreen.setWidth(button_width);
    button_playpause.setWidth(button_width);
  }
Пример #3
0
  private void refreshInterface() {
    if (mAllowFeedback) {
      Resources res = getResources();
      Button btnSend = (Button) findViewById(R.id.btnFeedbackSend);
      Button btnKeepLatest = (Button) findViewById(R.id.btnFeedbackKeepLatest);
      Button btnClearAll = (Button) findViewById(R.id.btnFeedbackClearAll);
      ProgressBar pbSpinner = (ProgressBar) findViewById(R.id.pbFeedbackSpinner);

      int numErrors = mErrorReports.size();
      if (numErrors == 0 || mErrorsSent) {
        if (!mErrorsSent) {
          mLvErrorList.setVisibility(View.GONE);
        }
        btnKeepLatest.setVisibility(View.GONE);
        btnClearAll.setVisibility(View.GONE);
        btnSend.setText(res.getString(R.string.feedback_send_feedback));
      } else {
        mLvErrorList.setVisibility(View.VISIBLE);
        btnKeepLatest.setVisibility(View.VISIBLE);
        btnClearAll.setVisibility(View.VISIBLE);
        btnSend.setText(res.getString(R.string.feedback_send_feedback_and_errors));
        refreshErrorListView();
        if (numErrors == 1) {
          btnKeepLatest.setEnabled(false);
        } else {
          btnKeepLatest.setEnabled(true);
        }
      }

      if (mPostingFeedback) {
        int buttonHeight = btnSend.getHeight();
        btnSend.setVisibility(View.GONE);
        pbSpinner.setVisibility(View.VISIBLE);
        LinearLayout topLine = (LinearLayout) findViewById(R.id.llFeedbackTopLine);
        topLine.setMinimumHeight(buttonHeight);

        mEtFeedbackText.setEnabled(false);
        mImm.hideSoftInputFromWindow(mEtFeedbackText.getWindowToken(), 0);
      } else {
        btnSend.setVisibility(View.VISIBLE);
        pbSpinner.setVisibility(View.GONE);
        mEtFeedbackText.setEnabled(true);
      }
    }
  }
Пример #4
0
  private LinearLayout createProductInfo(com.app.commons.JSONObject jo) {
    JSONArray ja = jo.getJSONArray("settleGoods");
    if (ja == null || ja.length() == 0) {
      return null;
    }
    final String productSku = jo.getString("productSku");
    LinearLayout info = new LinearLayout(CartActivtiy.this);
    int cart_height = Math.round(getResources().getDimension(R.dimen.cart_height));
    info.setLayoutParams(
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    info.setMinimumHeight(cart_height);
    info.setOrientation(LinearLayout.HORIZONTAL);
    info.setGravity(Gravity.CENTER_VERTICAL);
    info.setBackgroundResource(R.drawable.border2);
    info.setPadding(10, 0, 10, 0);
    final CheckBox rb = new CheckBox(CartActivtiy.this);
    rb.setPadding(0, 0, 10, 0);
    rb.setButtonDrawable(R.drawable.checkbox);
    if (jo.getBoolean("checked")) {
      rb.setChecked(true);
      settleNum = settleNum + 1;
    } else {
      rb.setChecked(false);
    }
    rb.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            Map<String, Object> param = new HashMap<>();
            param.put("ids", productSku);
            param.put("checkeds", rb.isChecked() ? "Y" : "N");
            Utils.asyncHttpRequestPost(
                Constants.URL_CART_CHANGESTATUS,
                param,
                new JsonHttpResponseHandler() {
                  @Override
                  public void onSuccess(int statusCode, Header[] headers, JSONObject res) {
                    com.app.commons.JSONObject jo = new com.app.commons.JSONObject(res);
                    if (statusCode == 200) {
                      if (jo.getBoolean("success")) {
                        flushCartInfo();
                      } else {
                        Toast.makeText(
                                CartActivtiy.this, jo.getString("errMsg"), Toast.LENGTH_SHORT)
                            .show();
                        flushCartInfo();
                      }
                    } else {
                      Toast.makeText(CartActivtiy.this, statusCode, Toast.LENGTH_SHORT).show();
                    }
                  }
                });
          }
        });
    info.addView(rb);
    LinearLayout center = new LinearLayout(CartActivtiy.this);
    LinearLayout.LayoutParams centerLP =
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    centerLP.weight = 1;
    center.setOrientation(LinearLayout.VERTICAL);
    center.setLayoutParams(centerLP);
    center.setPadding(10, 0, 0, 0);
    int wh2 = Math.round(getResources().getDimension(R.dimen.btn_cart_height));
    if (ja != null && ja.length() > 0) {
      ImageView iv = new ImageView(CartActivtiy.this);
      int wh = Math.round(getResources().getDimension(R.dimen.cart_img_wh));
      iv.setLayoutParams(new ViewGroup.LayoutParams(wh, wh));
      iv.setImageResource(R.drawable.loading);
      Utils.asyncLoadInternetImageView(
          iv, Constants.URL_IMAGE + "/200X200" + ja.getJSONObject(0).getString("photoUrl"));
      info.addView(iv);
      TextView tv = new TextView(CartActivtiy.this);
      if (ja.length() == 1) {
        tv.setText(ja.getJSONObject(0).getString("goodsName"));
      } else {
        tv.setText(getResources().getString(R.string.goods_set));
      }
      center.addView(tv);
      LinearLayout bottom = new LinearLayout(CartActivtiy.this);
      bottom.setLayoutParams(
          new ViewGroup.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
      bottom.setOrientation(LinearLayout.HORIZONTAL);
      bottom.setPadding(0, 15, 0, 0);
      LinearLayout.LayoutParams wrap = new LinearLayout.LayoutParams(wh2, wh2);
      wrap.setMargins(5, 0, 5, 0);
      final EditText et = new EditText(CartActivtiy.this);
      et.setBackgroundResource(R.drawable.wrapcontent);
      et.setText(jo.getString("number"));
      et.setSingleLine(true);
      et.setKeyListener(new DigitsKeyListener(false, false));
      et.setLayoutParams(wrap);
      et.setGravity(Gravity.RIGHT);
      et.setPadding(5, 2, 5, 2);
      et.setFocusable(true);
      et.addTextChangedListener(
          new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}

            @Override
            public void afterTextChanged(Editable editable) {
              if (editable.length() == 0) {
                editable.append(String.valueOf(def_num));
              } else if (Integer.parseInt(editable.toString()) <= 0) {
                editable.replace(0, 1, String.valueOf(def_num));
              } else if (editable.length() > 2) {
                editable.replace(0, editable.length(), String.valueOf(def_maxnum));
              }
              Map<String, Object> param = new HashMap<>();
              param.put("id", productSku);
              param.put("count", editable.toString());
              Utils.asyncHttpRequestPost(
                  Constants.URL_CART_CHANGENUMBER,
                  param,
                  new JsonHttpResponseHandler() {
                    @Override
                    public void onSuccess(int statusCode, Header[] headers, JSONObject res) {
                      com.app.commons.JSONObject jo = new com.app.commons.JSONObject(res);
                      if (statusCode == 200) {
                        if (jo.getBoolean("success")) {
                          flushCartInfo();
                        } else {
                          Toast.makeText(
                                  CartActivtiy.this, jo.getString("errMsg"), Toast.LENGTH_SHORT)
                              .show();
                          flushCartInfo();
                        }
                      } else {
                        Toast.makeText(CartActivtiy.this, statusCode, Toast.LENGTH_SHORT).show();
                      }
                    }
                  });
            }
          });
      ImageView sub = new ImageView(CartActivtiy.this);
      sub.setScaleType(ImageView.ScaleType.FIT_CENTER);
      sub.setLayoutParams(wrap);
      sub.setImageResource(R.drawable.cart_sub);
      sub.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              int num = Integer.parseInt(et.getText().toString());
              if (num > 1) {
                et.setText(String.valueOf((num - 1)));
              }
            }
          });
      ImageView add = new ImageView(CartActivtiy.this);
      add.setLayoutParams(wrap);
      add.setScaleType(ImageView.ScaleType.FIT_CENTER);
      add.setImageResource(R.drawable.cart_add);
      add.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              Integer num = Integer.parseInt(et.getText().toString());
              et.setText(String.valueOf(num + 1));
            }
          });
      bottom.addView(sub);
      bottom.addView(et);
      bottom.addView(add);
      if (jo.getString("remark") != null) {
        TextView remark = new TextView(CartActivtiy.this);
        remark.setText(jo.getString("remark"));
        remark.setTextColor(getResources().getColor(R.color.red));
        bottom.addView(remark);
      }
      center.addView(bottom);
    }
    LinearLayout right = new LinearLayout(CartActivtiy.this);
    right.setOrientation(LinearLayout.VERTICAL);
    right.setGravity(Gravity.CENTER);
    right.setPadding(0, 0, 0, 5);
    TextView tv2 = new TextView(CartActivtiy.this);
    tv2.setLayoutParams(
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    tv2.setGravity(Gravity.CENTER);
    tv2.setText("¥" + jo.getString("amount"));
    tv2.setTextColor(getResources().getColor(R.color.red));
    right.addView(tv2);
    ImageButton ib = new ImageButton(CartActivtiy.this);
    int cdelw = Math.round(getResources().getDimension(R.dimen.cart_delete_width));
    int cdelh = Math.round(getResources().getDimension(R.dimen.cart_delete_height));
    ib.setLayoutParams(new ViewGroup.LayoutParams(cdelw, cdelh));
    ib.setScaleType(ImageView.ScaleType.FIT_CENTER);
    ib.setBackgroundResource(R.drawable.border3);
    ib.setImageResource(R.drawable.cart_delete);
    ib.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("ids", productSku);
            Utils.asyncHttpRequestPost(
                Constants.URL_CART_DELETEPRODUCTS,
                param,
                new JsonHttpResponseHandler() {
                  @Override
                  public void onSuccess(int statusCode, Header[] headers, JSONObject res) {
                    com.app.commons.JSONObject jo = new com.app.commons.JSONObject(res);
                    if (statusCode == 200) {
                      if (jo.getBoolean("success")) {
                        flushCartInfo();
                      } else {
                        Toast.makeText(
                                CartActivtiy.this, jo.getString("errMsg"), Toast.LENGTH_SHORT)
                            .show();
                        flushCartInfo();
                      }
                    } else {
                      Toast.makeText(CartActivtiy.this, statusCode, Toast.LENGTH_SHORT).show();
                    }
                  }
                });
          }
        });
    right.addView(ib);
    info.addView(center);
    info.addView(right);
    return info;
  }
Пример #5
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);
  }
  protected void createView() {

    Display display = this.getWindow().getWindowManager().getDefaultDisplay();
    Point size = new Point();

    if (Build.VERSION.SDK_INT > 12) {
      display.getSize(size);
    } else {
      size.y = display.getHeight();
      size.x = display.getWidth();
    }

    int width_times = Math.round((float) size.x / (56.0f * density));
    float dialog_width = ((float) (width_times - 1) * 56.0f * density);

    // add a view to margin the space
    LayoutParams mvParams = new LayoutParams((int) dialog_width, LayoutParams.WRAP_CONTENT);
    LinearLayout messageView = new LinearLayout(this.getContext());
    messageView.setLayoutParams(mvParams);
    messageView.setPadding(view_padding, view_padding, view_padding, view_padding);
    messageView.setGravity(Gravity.TOP | Gravity.CENTER);
    messageView.setOrientation(LinearLayout.VERTICAL);

    // icon
    LayoutParams iconParams =
        new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    iconParams.setMargins(0, 0, 0, view_margin);
    iconParams.gravity = Gravity.CENTER;
    ImageView icon = new ImageView(this.getContext());
    icon.setLayoutParams(iconParams);
    icon.setId(android.R.id.icon);
    icon.setVisibility(View.GONE);

    // title
    LayoutParams titleParams =
        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    titleParams.setMargins(0, 0, 0, view_margin);
    TextView title = new TextView(this.getContext());
    title.setLayoutParams(titleParams);
    title.setTextColor(this.getContext().getResources().getColor(R.color.text_color_dark));
    title.setTextSize(20);
    title.setTypeface(null, Typeface.BOLD);
    title.setId(android.R.id.title);
    title.setVisibility(View.GONE);

    // message
    LayoutParams msgParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    TextView message = new TextView(this.getContext());
    message.setLayoutParams(msgParams);
    message.setTextColor(this.getContext().getResources().getColor(R.color.text_color_dark));
    message.setTextSize(18);
    message.setId(android.R.id.message);
    message.setVisibility(View.GONE);

    // optional choice
    LayoutParams checkBoxParams =
        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    checkBoxParams.setMargins(0, view_margin, 0, 0);
    CheckBox checkBox = new CheckBox(this.getContext());
    checkBox.setLayoutParams(checkBoxParams);
    checkBox.setId(android.R.id.checkbox);
    checkBox.setTextColor(this.getContext().getResources().getColor(R.color.text_color_dark));
    checkBox.setVisibility(View.GONE);

    // add elements to body view
    messageView.addView(icon);
    messageView.addView(title);
    messageView.addView(message);
    messageView.addView(checkBox);

    // button area
    LayoutParams btnsParams = new LayoutParams((int) dialog_width, (int) (52.0f * density));
    LinearLayout buttons = new LinearLayout(this.getContext());
    buttons.setMinimumHeight((int) (52.0f * density));
    buttons.setLayoutParams(btnsParams);
    buttons.setGravity(Gravity.RIGHT | Gravity.CENTER);
    buttons.setId(android.R.id.extractArea);
    buttons.setPadding(0, 0, (int) (8.0f * density), 0);

    contentView.addView(messageView);
    contentView.addView(buttons);

    this.setContentView(contentView);
  }
Пример #7
0
  private View setCurrentUserRow() {
    View header1 = getLayoutInflater().inflate(R.layout.leaderboarditem, null, false);
    header1
        .findViewById(R.id.alliance)
        .setVisibility(View.GONE); // alliance in user not implemented now

    TextView p = (TextView) header1.findViewById(R.id.position);
    p.setTextColor(Color.WHITE);
    p.setText(currentUser.position);
    TextView nickname = (TextView) header1.findViewById(R.id.nickname);
    nickname.setText(currentUser.name);
    TextView score = (TextView) header1.findViewById(R.id.score);

    NumberFormat nf = NumberFormat.getInstance(Locale.getDefault());
    String formattedScore = nf.format(Double.parseDouble(currentUser.score));

    if (currentUser.feed == null)
      score.setText(currentContext.getString(R.string.leadScore) + "\n" + formattedScore);
    else score.setText(currentUser.feed + ":\n" + formattedScore);

    header1.findViewById(R.id.image).setVisibility(LinearLayout.GONE);
    header1.findViewById(R.id.whiteline).setVisibility(LinearLayout.GONE);
    try {
      if (currentUser.imageUrl != null) {
        ImageView imageView = new ImageView(currentContext);
        imageView.setTag(currentUser.imageUrl);
        int size = (int) (50 * currentContext.getResources().getDisplayMetrics().density + 0.5f);
        imageView.setLayoutParams(new LinearLayout.LayoutParams(size, size));
        imageManager.displayImage(currentUser.imageUrl, currentContext, imageView);

        LinearLayout a = (LinearLayout) header1.findViewById(R.id.item);
        a.addView(imageView, 0);
      } else {
        header1
            .findViewById(R.id.item)
            .setPadding((int) (ratio * 5), (int) (ratio * 5), 0, (int) (ratio * 5));
      }
    } catch (Exception e) {
    }

    LinearLayout positionView = (LinearLayout) header1.findViewById(R.id.post);
    LinearLayout.LayoutParams params =
        new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, (int) (ratio * 35));
    params.setMargins(0, 0, (int) (ratio * 10), 0);
    positionView.setLayoutParams(params);
    positionView.setPadding((int) (ratio * 5), 0, (int) (ratio * 5), 0);
    positionView.setMinimumHeight((int) (ratio * 35));
    positionView.setMinimumWidth((int) (ratio * 35));

    positionView.setBackgroundDrawable(
        new BDrawableGradient(0, (int) (ratio * 35), BDrawableGradient.HIGH_GRAY_GRADIENT));
    header1
        .findViewById(R.id.item)
        .setBackgroundDrawable(
            new BDrawableGradient(0, (int) (ratio * 60), BDrawableGradient.LIGHT_GRAY_GRADIENT));

    LinearLayout spacer = (LinearLayout) header1.findViewById(R.id.space);
    spacer.setVisibility(LinearLayout.VISIBLE);

    return header1;
  }
Пример #8
0
  private void buildView(final Context context, TypedArray ta) {
    int thumbnailBackground = ta.getColor(R.styleable.PostView_thumbnail_background, 0);
    int replyCountColor = ta.getColor(R.styleable.PostView_reply_count_color, 0);

    int iconPadding = ta.getDimensionPixelSize(R.styleable.PostView_icon_padding, 0);
    int iconWidth = ta.getDimensionPixelSize(R.styleable.PostView_icon_width, 0);
    int iconHeight = ta.getDimensionPixelSize(R.styleable.PostView_icon_height, 0);
    int gridHeight = ta.getDimensionPixelSize(R.styleable.PostView_grid_height, 0);
    int optionsSpacing = ta.getDimensionPixelSize(R.styleable.PostView_options_spacing, 0);
    int titleSize = ta.getDimensionPixelSize(R.styleable.PostView_title_size, 0);
    int optionsLeftPadding = ta.getDimensionPixelSize(R.styleable.PostView_options_left_padding, 0);
    int optionsTopPadding = ta.getDimensionPixelSize(R.styleable.PostView_options_top_padding, 0);
    int optionsRightPadding =
        ta.getDimensionPixelSize(R.styleable.PostView_options_right_padding, 0);
    int optionsBottomPadding =
        ta.getDimensionPixelSize(R.styleable.PostView_options_bottom_padding, 0);
    int lastSeenHeight = ta.getDimensionPixelSize(R.styleable.PostView_last_seen_height, 0);

    int postListMaxHeight =
        ta.getDimensionPixelSize(R.styleable.PostView_list_comment_max_height, 0);

    int postCommentSize = 0;
    int commentPadding = 0;
    int postPadding = 0;
    int imageSize = 0;
    int repliesCountSize = 0;
    if (isList()) {
      postCommentSize =
          (int)
              TypedValue.applyDimension(
                  TypedValue.COMPLEX_UNIT_SP,
                  ThemeHelper.getInstance().getFontSize(),
                  getResources().getDisplayMetrics());
      commentPadding = ta.getDimensionPixelSize(R.styleable.PostView_list_comment_padding, 0);
      postPadding = ta.getDimensionPixelSize(R.styleable.PostView_list_padding, 0);
      imageSize = ta.getDimensionPixelSize(R.styleable.PostView_list_image_size, 0);
      repliesCountSize = ta.getDimensionPixelSize(R.styleable.PostView_list_replies_count_size, 0);
    } else if (isGrid()) {
      postCommentSize =
          (int)
              TypedValue.applyDimension(
                  TypedValue.COMPLEX_UNIT_SP,
                  ThemeHelper.getInstance().getFontSize() - 1,
                  getResources().getDisplayMetrics());
      commentPadding = ta.getDimensionPixelSize(R.styleable.PostView_grid_comment_padding, 0);
      postPadding = ta.getDimensionPixelSize(R.styleable.PostView_grid_padding, 0);
      imageSize = ta.getDimensionPixelSize(R.styleable.PostView_grid_image_size, 0);
      repliesCountSize = ta.getDimensionPixelSize(R.styleable.PostView_grid_replies_count_size, 0);
    }

    RelativeLayout wrapper = new RelativeLayout(context);
    wrapper.setLayoutParams(matchParams);

    full = new LinearLayout(context);
    if (isList()) {
      full.setOrientation(HORIZONTAL);
      wrapper.addView(full, matchParams);
    } else if (isGrid()) {
      full.setOrientation(VERTICAL);
      wrapper.addView(full, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, gridHeight));
    }

    LinearLayout imageContainer = new LinearLayout(context);
    imageContainer.setOrientation(VERTICAL);
    imageContainer.setBackgroundColor(thumbnailBackground);

    // Create thumbnail
    imageView = new CustomNetworkImageView(context);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setFadeIn(100);

    imageView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            manager.onThumbnailClicked(post);
          }
        });

    if (isList()) {
      imageContainer.addView(imageView, new LinearLayout.LayoutParams(imageSize, imageSize));
      full.addView(imageContainer, wrapMatchParams);
      full.setMinimumHeight(imageSize);
    } else if (isGrid()) {
      imageContainer.addView(
          imageView, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, imageSize));
      full.addView(imageContainer, matchWrapParams);
    }

    contentContainer = new LinearLayout(context);
    contentContainer.setOrientation(VERTICAL);

    LinearLayout titleContainer = new LinearLayout(context);
    titleContainer.setOrientation(HORIZONTAL);

    if (isList()) {
      // 25 padding to give optionsView some space
      titleContainer.setPadding(0, 0, optionsSpacing, 0);
    }

    titleView = new TextView(context);
    titleView.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
    titleView.setPadding(postPadding, postPadding, postPadding, 0);

    titleContainer.addView(titleView, wrapParams);

    contentContainer.addView(titleContainer, matchWrapParams);

    iconsView = new LinearLayout(context);
    iconsView.setOrientation(HORIZONTAL);
    iconsView.setPadding(postPadding, iconPadding, postPadding, 0);

    stickyView = new ImageView(context);
    stickyView.setImageDrawable(IconCache.stickyIcon);
    iconsView.addView(stickyView, new LinearLayout.LayoutParams(iconWidth, iconHeight));

    closedView = new ImageView(context);
    closedView.setImageDrawable(IconCache.closedIcon);
    iconsView.addView(closedView, new LinearLayout.LayoutParams(iconWidth, iconHeight));

    deletedView = new ImageView(context);
    deletedView.setImageDrawable(IconCache.trashIcon);
    iconsView.addView(deletedView, new LinearLayout.LayoutParams(iconWidth, iconHeight));

    archivedView = new ImageView(context);
    archivedView.setImageDrawable(IconCache.archivedIcon);
    iconsView.addView(archivedView, new LinearLayout.LayoutParams(iconWidth, iconHeight));

    countryView = new NetworkImageView(context);
    countryView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    iconsView.addView(countryView, new LinearLayout.LayoutParams(iconWidth, iconHeight));

    contentContainer.addView(iconsView, matchWrapParams);

    commentView = new TextView(context);
    commentView.setTextSize(TypedValue.COMPLEX_UNIT_PX, postCommentSize);

    if (isList()) {
      commentView.setPadding(postPadding, commentPadding, postPadding, commentPadding);

      if (manager.getLoadable().isBoardMode() || manager.getLoadable().isCatalogMode()) {
        commentView.setMaxHeight(postListMaxHeight);
      }
    } else if (isGrid()) {
      commentView.setPadding(postPadding, commentPadding, postPadding, 0);
      // So that is fills up all the height using weight later on
      commentView.setMinHeight(10000);
    }

    if (isList()) {
      contentContainer.addView(commentView, matchWrapParams);
    } else if (isGrid()) {
      contentContainer.addView(
          commentView, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1f));
    }

    repliesCountView = new TextView(context);
    Utils.setPressedDrawable(repliesCountView);
    repliesCountView.setTextColor(replyCountColor);
    repliesCountView.setPadding(postPadding, postPadding, postPadding, postPadding);
    repliesCountView.setTextSize(TypedValue.COMPLEX_UNIT_PX, repliesCountSize);
    repliesCountView.setSingleLine();

    contentContainer.addView(repliesCountView, wrapParams);

    lastSeen = new View(context);
    lastSeen.setBackgroundColor(0xffff0000);
    contentContainer.addView(lastSeen, new LayoutParams(LayoutParams.MATCH_PARENT, lastSeenHeight));

    if (!manager.getLoadable().isThreadMode()) {
      Utils.setPressedDrawable(contentContainer);
    }

    full.addView(contentContainer, matchWrapParams);

    optionsView = new ImageView(context);
    optionsView.setImageResource(R.drawable.ic_overflow);
    Utils.setPressedDrawable(optionsView);
    optionsView.setPadding(
        optionsLeftPadding, optionsTopPadding, optionsRightPadding, optionsBottomPadding);
    optionsView.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(final View v) {
            PopupMenu popupMenu = new PopupMenu(context, v);
            manager.showPostOptions(post, popupMenu);
            popupMenu.show();
            if (ThemeHelper.getInstance().getTheme().isLightTheme) {
              optionsView.setImageResource(R.drawable.ic_overflow_black);
              popupMenu.setOnDismissListener(
                  new PopupMenu.OnDismissListener() {
                    @Override
                    public void onDismiss(final PopupMenu menu) {
                      optionsView.setImageResource(R.drawable.ic_overflow);
                    }
                  });
            }
          }
        });
    wrapper.addView(optionsView, wrapParams);
    RelativeLayout.LayoutParams optionsParams =
        (RelativeLayout.LayoutParams) optionsView.getLayoutParams();
    optionsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    optionsParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    optionsView.setLayoutParams(optionsParams);

    addView(wrapper, matchParams);

    wrapper.setOnClickListener(this);
  }