Esempio n. 1
0
  /** 设置赞的布局,包括数字和头像 */
  public void setGreetLayout(DynamicGreetInfo greetInfo) {

    // llGreetPhoto原本有两个View,所以删除要从第三个view开始删
    llGreetPhoto.removeViews(2, llGreetPhoto.getChildCount() - 2);

    int PicCount = greetInfo.greetList.size();
    String str = PicCount + "个赞";
    tvGreetTitle.setText(str);

    if (PicCount <= 0) {
      return;
    }

    // 对第一行的头像插入
    int rowCount = PicCount / MAX_COUNT_PER_ROW + (PicCount % MAX_COUNT_PER_ROW > 0 ? 1 : 0);

    for (int row = 0; row < rowCount; row++) {
      LinearLayout llRow = new LinearLayout(getContext());
      llRow.setLayoutParams(rowPara);
      llGreetPhoto.addView(llRow);

      int columnCount =
          PicCount % MAX_COUNT_PER_ROW == 0 ? MAX_COUNT_PER_ROW : PicCount % MAX_COUNT_PER_ROW;
      if (row != rowCount - 1) {
        columnCount = MAX_COUNT_PER_ROW;
      }
      int rowOffset = row * MAX_COUNT_PER_ROW; // 行偏移
      for (int column = 0; column < columnCount; column++) {

        int picIndex = rowOffset + column;
        String name = greetInfo.greetList.get(picIndex);
        int avaterRes = MultiUtils.getAvaterResource(name);

        ImageView ivPic = new ImageView(getContext());
        ivPic.setScaleType(ScaleType.CENTER_CROP);
        ivPic.setLayoutParams(onePicPara);
        ivPic.setImageResource(avaterRes);

        ivPic.setOnClickListener(userPicOnClickListener);

        llRow.addView(ivPic);
      }
    }
  }
Esempio n. 2
0
  private void setPreviewColor(int Color, int Width, int ColorShadow, double ShadowRadius) {
    if (mView == null) return;

    ImageView iView = new ImageView(getContext());
    LinearLayout widgetFrameView = ((LinearLayout) mView.findViewById(android.R.id.widget_frame));
    if (widgetFrameView == null) return;
    widgetFrameView.setVisibility(View.VISIBLE);
    int count = widgetFrameView.getChildCount();
    if (count > 0) {
      widgetFrameView.removeViews(0, count);
    }
    widgetFrameView.addView(iView);
    widgetFrameView.setMinimumWidth(0);

    final Drawable dr = new TrackStyleDrawable(Color, Width, ColorShadow, ShadowRadius);
    final Drawable[] d = {getContext().getResources().getDrawable(R.drawable.track_background), dr};
    LayerDrawable ld = new LayerDrawable(d);
    iView.setBackgroundDrawable(ld);
  }
 private void setPreviewColor() {
   if (mView == null) return;
   ImageView iView = new ImageView(getContext());
   LinearLayout widgetFrameView = ((LinearLayout) mView.findViewById(android.R.id.widget_frame));
   if (widgetFrameView == null) return;
   widgetFrameView.setVisibility(View.VISIBLE);
   widgetFrameView.setPadding(
       widgetFrameView.getPaddingLeft(),
       widgetFrameView.getPaddingTop(),
       (int) (mDensity * 8),
       widgetFrameView.getPaddingBottom());
   // remove already create preview image
   int count = widgetFrameView.getChildCount();
   if (count > 0) {
     widgetFrameView.removeViews(0, count);
   }
   widgetFrameView.addView(iView);
   iView.setBackgroundDrawable(new AlphaPatternDrawable((int) (5 * mDensity)));
   iView.setImageBitmap(getPreviewBitmap());
 }
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.linearLayoutdashboard:
        startActivity(new Intent(getApplicationContext(), Home.class));
        break;
      case R.id.linearLayoutsettings:
        startActivity(new Intent(getApplicationContext(), Settings.class));
        break;
      case R.id.imageViewLogout:
        showMessage();
        break;
      case R.id.btneditusername:
        changeusername();
        break;
      case R.id.btneditpassword:
        changePassword();
        break;
      case R.id.btneditemail:
        changeemail();
        break;
      case R.id.btneditmobileNo:
        changemobile();
        break;
      case R.id.btnreportsarrow:
        break;
      case R.id.linearLayoutaddcontacts:
        linearLayout = (LinearLayout) findViewById(R.id.linearLayout20);
        linearLayout1 = (LinearLayout) findViewById(R.id.linearLayout29);
        linearLayoutroot = (LinearLayout) findViewById(R.id.root);
        String[] emergencyContact = {"alex", "angaya", "musera"};
        if (!addcontacts) {
          for (int i = 0; i < emergencyContact.length; i++) {
            linearLayout1 = new LinearLayout(this);
            linearLayout1.setOrientation((LinearLayout.HORIZONTAL));
            LinearLayout.LayoutParams param =
                new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 2);
            linearLayout1.setLayoutParams(param);
            linearLayout1.setGravity(Gravity.RIGHT);
            linearLayout1.setBackgroundDrawable(
                getResources().getDrawable(R.drawable.profile_advance_bg));
            linearLayout1.setWeightSum(100);

            linearLayout5 = new LinearLayout(this);
            linearLayout5.setOrientation((LinearLayout.HORIZONTAL));
            LinearLayout.LayoutParams param5 =
                new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 70);
            param5.setMargins(30, 0, 0, 0);
            linearLayout5.setLayoutParams(param5);
            linearLayout5.setGravity(Gravity.CENTER);

            linearLayout1.addView(linearLayout5);

            textView = new TextView(this);
            textView.setText(emergencyContact[i]);
            LinearLayout.LayoutParams paramTextView =
                new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            textView.setLayoutParams(paramTextView);
            linearLayout5.addView(textView);

            linearLayout6 = new LinearLayout(this);
            linearLayout6.setOrientation((LinearLayout.HORIZONTAL));
            LinearLayout.LayoutParams param6 =
                new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 30);
            param6.setMargins(30, 0, 0, 0);
            linearLayout6.setLayoutParams(param6);
            linearLayout6.setGravity(Gravity.CENTER);

            linearLayout1.addView(linearLayout6);

            button2 = new Button(this);
            button2.setText("edit");
            LinearLayout.LayoutParams paramButton =
                new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); // width, height
            button2.setLayoutParams(paramButton);
            button2.setOnClickListener(
                new OnClickListener() {

                  @Override
                  public void onClick(View v) {
                    addContact();
                  }
                });

            button2.setBackgroundDrawable(getResources().getDrawable(R.layout.buttonedit));
            linearLayout6.addView(button2);

            linearLayoutroot.addView(linearLayout1);
          }

          linearLayout.setBackgroundDrawable(
              getResources().getDrawable(R.drawable.profile_advance_bg));
          linearLayout.setVisibility(View.VISIBLE);
          Button button = new Button(this);
          button.setLayoutParams(
              new LayoutParams(
                  ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
          button.setText("Add Contacts");
          button.setOnClickListener(
              new OnClickListener() {

                @Override
                public void onClick(View v) {
                  addContact();
                }
              });

          button.setBackgroundDrawable(getResources().getDrawable(R.layout.buttonedit));
          linearLayout.addView(button);
          btnarrow.setBackgroundDrawable(getResources().getDrawable(R.drawable.arrow_down));
          addcontacts = true;
        } else {
          int childViews, emergencyContactLength, start;
          childViews = linearLayoutroot.getChildCount();
          emergencyContactLength = emergencyContact.length;
          start = childViews - emergencyContactLength;
          linearLayoutroot.removeViews(start, emergencyContactLength);
          btnarrow.setBackgroundDrawable(getResources().getDrawable(R.drawable.arrow));
          addcontacts = false;
          linearLayout.removeAllViewsInLayout();
          linearLayout.setVisibility(View.GONE);
        }
        break;

      default:
        break;
    }
  }