示例#1
0
 public void addElementCircles() {
   CircleImageView civ;
   circle_holder.removeAllViewsInLayout();
   circleIndex.clear();
   QData qData;
   for (int i = 0; i < elements.size(); i++) {
     qData = elements.get(i);
     if (qData.isText()) {
       civ = new CircleImageView(this);
       civ.setImageDrawable(getResources().getDrawable(R.drawable.text));
       civ.setBorderColor(getResources().getColor(R.color.blue));
       civ.setBorderWidth(10);
       civ.setOnClickListener(circleClickListener);
       circle_holder.addView(civ, circle_params);
       circleIndex.add(civ);
     } else if (!qData.isText()) {
       civ = new CircleImageView(this);
       //                byte[] array = fragments.get(i).mData.getImage();
       civ.setImageBitmap(elements.get(i).getImageBitmap());
       civ.setBorderColor(getResources().getColor(R.color.blue));
       civ.setBorderWidth(10);
       civ.setOnClickListener(circleClickListener);
       circle_holder.addView(civ, circle_params);
       circleIndex.add(civ);
     }
     if (i == 0) circleIndex.get(i).setBorderColor(Color.WHITE);
   }
 }
 /** 图片循环 */
 private void initViewPager() {
   ViewGroup.LayoutParams mViewPagerlayoutParams = mViewPager.getLayoutParams();
   if (mViewPagerlayoutParams != null) {
     mViewPagerlayoutParams.width = Misc.getScreenDisplay(this)[0];
     mViewPagerlayoutParams.height = (int) (mViewPagerlayoutParams.width);
     mViewPager.setLayoutParams(mViewPagerlayoutParams);
   }
   mViewPager.setAdapter(new ProductDetailPicAdapter2(this, product.getImgList()));
   mViewPager.setOnPageChangeListener(this);
   // 设置布局参数
   LinearLayout.LayoutParams params =
       new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
   int marginParam = Misc.dip2px(this, 10) / 2;
   llytPagerPoiner.removeAllViewsInLayout();
   for (int i = 0; i < product.getImgList().size(); i++) {
     // 设置按钮属性
     View item = new ImageView(this);
     item.setBackgroundResource(R.drawable.recommend_gallery);
     item.setTag(String.valueOf(i));
     // item.setOnClickListener(parentActivity);
     params.setMargins(marginParam, 0, marginParam, 0);
     params.weight = 1;
     llytPagerPoiner.addView(item, params);
   }
   llytPagerPoiner.getChildAt(0).setBackgroundResource(R.drawable.recommend_gallery_select);
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    LinearLayout variableBox = (LinearLayout) findViewById(R.id.contentArea);
    variableBox.removeAllViewsInLayout();

    setActionBar();
  }
  private void populateClientListHeaderView(ClientsHeaderProvider headerProvider) {
    LinearLayout clientsHeaderLayout = (LinearLayout) findViewById(R.id.clients_header_layout);
    clientsHeaderLayout.removeAllViewsInLayout();
    int columnCount = headerProvider.count();
    int[] weights = headerProvider.weights();
    int[] headerTxtResIds = headerProvider.headerTextResourceIds();
    clientsHeaderLayout.setWeightSum(headerProvider.weightSum());

    for (int i = 0; i < columnCount; i++) {
      clientsHeaderLayout.addView(getColumnHeaderView(i, weights, headerTxtResIds));
    }
  }
 @Override
 public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
   int selected = spinner.getSelectedItemPosition();
   tableHeadView.removeAllViewsInLayout();
   switch (selected) {
     case 0:
       tableView.setAdapter(customListFingerprintAdapter);
       tableHeadView.addView(
           getLayoutInflater().inflate(R.layout.testarea_anchors_custom_row, null),
           tableHeadView.getLayoutParams().width,
           tableHeadView.getLayoutParams().height);
       anchorListHandler.sendEmptyMessage(0);
       selectedItem = 0;
       break;
     case 1:
       tableView.setAdapter(customListBeaconAdapter);
       tableHeadView.addView(
           getLayoutInflater().inflate(R.layout.testarea_beacons_custom_row, null),
           tableHeadView.getLayoutParams().width,
           tableHeadView.getLayoutParams().height);
       beaconListHandler.sendEmptyMessage(0);
       selectedItem = 1;
       break;
     case 2:
       tableView.setAdapter(customListMedianAdapter);
       tableHeadView.addView(
           getLayoutInflater().inflate(R.layout.testarea_medians_custom_row, null),
           tableHeadView.getLayoutParams().width,
           tableHeadView.getLayoutParams().height);
       medianListHandler.sendEmptyMessage(0);
       selectedItem = 2;
       break;
     case 3:
       tableView.setAdapter(customListInfoAdapter);
       tableHeadView.addView(
           getLayoutInflater().inflate(R.layout.testarea_info_custom_row, null),
           tableHeadView.getLayoutParams().width,
           tableHeadView.getLayoutParams().height);
       infoListHandler.sendEmptyMessage(0);
       selectedItem = 3;
       break;
     case 4:
       tableView.setAdapter(customListFingerprint_has_medianAdapter);
       tableHeadView.addView(
           getLayoutInflater().inflate(R.layout.testarea_fingerprint_has_median_custom_row, null),
           tableHeadView.getLayoutParams().width,
           tableHeadView.getLayoutParams().height);
       fingerprint_has_medianHandler.sendEmptyMessage(0);
       selectedItem = 4;
       break;
   }
 }
示例#6
0
  public void createScrollView() {
    // LayoutParams (Reuseable)
    LinearLayout.LayoutParams lparams_text =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    LinearLayout.LayoutParams lparams_img =
        new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1000);

    RelativeLayout.LayoutParams rparams_text =
        new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams rparams_img =
        new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1000);

    lparams_text.gravity = Gravity.CENTER_HORIZONTAL;
    lparams_img.gravity = Gravity.CENTER_HORIZONTAL;

    if (questionDataLayout.getChildCount() != 0) {
      questionDataLayout.removeAllViewsInLayout();
    }
    QData data;
    for (int position = 0; position < elements.size(); position++) {
      data = elements.get(position);
      RelativeLayout rl = new RelativeLayout(getApplicationContext());

      if (data.isText()) {
        TextView tv = new TextView(this);
        tv.setLayoutParams(lparams_text);
        tv.setText(data.getText());
        tv.setTextSize(20);
        tv.setTextColor(Color.DKGRAY);
        tv.setOnClickListener(questionItemClickListener);
        tv.setOnLongClickListener(questionItemLongClickListener);
        rl.addView(tv, rparams_text);
        questionDataLayout.addView(rl, lparams_text);
      } else if (!data.isText()) {
        // ADD IMAGEVIEW
        ImageKeepAspectRatio iv = new ImageKeepAspectRatio(this);
        iv.setLayoutParams(lparams_img);
        iv.setImageBitmap(data.getImageBitmap());

        PhotoViewAttacher photoViewAttacher = new PhotoViewAttacher(iv);
        photoViewAttacher.setOnLongClickListener(questionItemLongClickListener);
        photoViewAttacher.setOnViewTapListener(
            new PhotoViewAttacher.OnViewTapListener() {
              @Override
              public void onViewTap(View view, float x, float y) {
                int index = questionDataLayout.indexOfChild(view);
                //                           scrollView.scrollTo(0,
                // questionDataLayout.getChildAt(index).getTop());

                // reset colors/boxes
                for (int i = 0; i < elements.size(); i++) {
                  circleIndex.get(i).setBorderColor(getResources().getColor(R.color.blue));
                  questionDataLayout.getChildAt(i).setBackground(null);
                }
                //                        circleIndex.get(index).setBorderColor(Color.WHITE);
                // TODO: WORKAROUND FOR API 16 CALL BELOW
                view.setBackground(rectShapeDrawable);
                selectedIndex = index;
              }
            });
        photoViewAttacher.update();

        rl.addView(iv, rparams_img);
        questionDataLayout.addView(rl, lparams_img);
      }
    }
  }
示例#7
0
  // set isi tampilan barang di kategori yang sedang dipilih
  private void setContentItemsBarang(JSONArray jsonArray) {
    LinearLayout ll = (LinearLayout) findViewById(R.id.wrapperbarang);
    ll.removeAllViewsInLayout();

    try {
      for (int i = 0; i < jsonArray.length(); i++) {
        final JSONObject jsonObject = jsonArray.getJSONObject(i);

        LinearLayout lytContainer = new LinearLayout(this);
        lytContainer.setOrientation(LinearLayout.VERTICAL);
        if (i % 2 == 1) {
          lytContainer.setBackgroundColor(Color.WHITE);
        } else {
          lytContainer.setBackgroundColor(Color.DKGRAY);
        }

        Drawable image =
            JSON_Response.ImageOperations(this, jsonObject.getString("path_gambar"), "image.jpg");
        ImageView iv = new ImageView(this);
        iv.setAdjustViewBounds(true);
        iv.setMaxHeight(50);
        iv.setMaxWidth(50);
        iv.setImageDrawable(image);
        iv.setPadding(0, 10, 0, 0);
        lytContainer.addView(iv);

        TextView t = new TextView(this);
        t.setText(jsonObject.getString("nama"));
        t.setGravity(Gravity.CENTER);
        t.setTypeface(null, Typeface.BOLD);
        if (i % 2 == 1) {
          t.setTextColor(Color.BLACK);
        } else {
          t.setTextColor(Color.WHITE);
        }
        lytContainer.addView(t);

        TextView t2 = new TextView(this);
        t2.setGravity(Gravity.CENTER);
        t2.setText("Jumlah produk yang tersedia : " + jsonObject.getString("jumlah"));
        if (i % 2 == 1) {
          t2.setTextColor(Color.BLACK);
        } else {
          t2.setTextColor(Color.WHITE);
        }
        t2.setPadding(0, 0, 0, 10);
        lytContainer.addView(t2);

        lytContainer.setOnClickListener(
            new OnClickListener() {

              public void onClick(View arg0) {
                // TODO Auto-generated method stub

                try {
                  System.gc();

                  Intent intent =
                      new Intent(LihatBarangActivity.this, LihatItemBarangActivity.class);
                  intent.putExtra("id", jsonObject.getInt("id"));
                  intent.putExtra("kategori_id", jsonObject.getInt("kategori_id"));
                  intent.putExtra("nama", jsonObject.getString("nama"));
                  intent.putExtra("deskripsi", jsonObject.getString("deskripsi"));
                  intent.putExtra("jumlah", jsonObject.getString("jumlah"));
                  intent.putExtra("harga", jsonObject.getString("harga_satuan"));
                  intent.putExtra("path_gambar", jsonObject.getString("path_gambar"));
                  startActivity(intent);
                } catch (JSONException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
              }
            });

        ll.addView(lytContainer);
      }
    } catch (Exception e) {
      Log.d("ancret", e.toString());
      e.printStackTrace();
    }
  }
  @Override
  public void setObject(Item item) {
    try {
      dobroitem = (DobroPostItem) item;
    } catch (ClassCastException e) {
      e.printStackTrace();
      return;
    }
    if (dobroitem == null || dobroitem.post == null) return;
    dobroitem.post.setLastContext(getContext());
    this.board = dobroitem.post.getBoardName();
    this.thread = dobroitem.post.getThreadDisplay_id();
    ((HorizontalScrollView) findViewById(R.id.horizScroll)).scrollTo(0, 0);

    CharSequence txt = dobroitem.post.getFormattedText();
    if (txt.length() > 800) {
      Pattern p1 = Pattern.compile("\\.|\n");
      Matcher m1 = p1.matcher(txt);
      Pattern p2 = Pattern.compile("\\b");
      Matcher m2 = p2.matcher(txt);
      if (m1.find(500) && m1.end() < 700) txt = txt.subSequence(0, m1.end());
      else if (m2.find(500) && m2.start() < 700) txt = txt.subSequence(0, m2.start());
      else txt = txt.subSequence(0, 500);
      messageView.setText(txt, BufferType.SPANNABLE);
      SpannableStringBuilder builder =
          new SpannableStringBuilder("\nСообщение слишком длинное. Полная версия");
      builder.setSpan(
          new ClickableSpan() {
            @Override
            public void onClick(View widget) {
              try {
                messageView.setText(dobroitem.post.getFormattedText(), BufferType.SPANNABLE);
              } catch (IndexOutOfBoundsException e) {

              }
            }
          },
          1,
          builder.length(),
          0);
      messageView.append(builder.subSequence(0, builder.length()));
    } else messageView.setText(txt, BufferType.SPANNABLE);
    // FIXME
    messageView.setMovementMethod(LinkMovementMethod.getInstance());
    messageView.setClickable(false);
    messageView.setFocusable(false);
    messageView.setFocusableInTouchMode(false);
    /*
    refsView.setMovementMethod(LinkMovementMethod.getInstance());
    refsView.setClickable(false);
    refsView.setFocusable(false);
    refsView.setFocusableInTouchMode(false);
    */
    //
    imagesLayout.removeAllViewsInLayout();
    if (dobroitem.post.isOp()) {
      numberView.setVisibility(GONE);
      titleView.setText(
          dobroitem.post.getSubject().length() == 0
              ? getContext().getString(R.string.untitled)
              : dobroitem.post.getSubject());
      titleView.setVisibility(VISIBLE);
    } else {
      int pos = dobroitem.post.getNumber();
      if (pos > 0) {
        numberView.setVisibility(VISIBLE);
        numberView.setText(String.valueOf(pos));
      } else numberView.setVisibility(GONE);
      titleView.setText("");
      titleView.setVisibility(GONE);
    }

    TypedValue backgroundRef = new TypedValue();
    getContext().getTheme().resolveAttribute(R.attr.dcPicrelatedColor, backgroundRef, true);
    int backgroundColor = getContext().getResources().getColor(backgroundRef.resourceId);
    SharedPreferences prefs = DobroApplication.getApplicationStatic().getDefaultPrefs();
    boolean show_info = prefs.getBoolean("show_fileinfo", true);
    boolean force_op_load = prefs.getBoolean("op_pictures_force", false);

    if (dobroitem.post.getFiles().length > 0) {
      for (DobroFile file : dobroitem.post.getFiles()) {
        CachedAsyncImageView imageView = new CachedAsyncImageView(getContext());
        VerticalTextView textView = null;
        String fname1 = file.getThumb().substring(file.getThumb().lastIndexOf("/") + 1);
        int e = fname1.lastIndexOf("s.");
        if (e > 0)
          fname1 = fname1.substring(0, e) + file.getSrc().substring(file.getSrc().lastIndexOf("."));
        String fname2 = file.getSrc().substring(file.getSrc().lastIndexOf("/") + 1);
        String size = humanReadableByteCount(file.getSize(), true);
        String date = getThumbnailDate(file.getThumb());
        if (date == null)
          try {
            date = file.getSrc().split("/")[2];
            date = date.substring(2) + "." + date.substring(0, 2);
          } catch (Exception ex) {
            date = "?";
          }
        imageView.setInfo(
            getContext()
                .getString(
                    R.string.file_info_parretn,
                    fname1,
                    fname2,
                    size,
                    date,
                    file.getRating(),
                    getMetadataText(file.getMetadata())));
        if (file.getMetadata().width != null)
          imageView.setSize(file.getMetadata().height, file.getMetadata().width);
        if (show_info) {
          textView = new VerticalTextView(getContext(), null);
          textView.setLinkedImageView(imageView);
          String text = "";
          if (dobroitem.post.getBoardName().equals("b")
              || dobroitem.post.getBoardName().equals("rf")) text += fname1;
          else text += fname2;
          text += "\n" + size;
          if (file.getMetadata() != null
              && file.getMetadata().width != null
              && file.getMetadata().height != null) {
            text +=
                ", "
                    + String.valueOf(file.getMetadata().width)
                    + "x"
                    + String.valueOf(file.getMetadata().height);
          }
          textView.setText(text);
          textView.setGravity(Gravity.BOTTOM);
          textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
        }
        imageView.setRating(file.getRat());
        imageView.setForceLoad(force_op_load && dobroitem.post.isOp());
        imageView.setUrl(file.getThumb());
        final String urlTag = file.getSrc();
        imageView.setTag(urlTag);
        imageView.setPadding(2, 2, 2, 2);
        imageView.setAdjustViewBounds(true);
        imageView.setMaxHeight(mImageHeight);
        imageView.setMaxWidth(mImageHeight);
        imageView.setBackgroundColor(backgroundColor);
        imageView.setScaleType(ScaleType.CENTER);
        imageView.setOnCreateContextMenuListener(imageView);
        float h = mImageHeight;
        int w =
            Math.min(
                Math.round((h / (float) file.getThumb_height()) * file.getThumb_width()),
                file.getThumb_width());
        imageView.setLayoutParams(new LayoutParams(w + 4, mImageHeight + 4));
        if (show_info) {
          textView.setWidth(mImageHeight + 4);
          textView.setLinkedImageView(imageView);
          imagesLayout.addView(textView);
        }
        imagesLayout.addView(imageView);
      }
      imagesLayout.setVisibility(VISIBLE);
    } else {
      imagesLayout.setVisibility(GONE);
    }
    if (prefs.getBoolean("youtube", true)) {
      Spanned s = null;
      boolean cast_ok = false;
      try {
        s = (Spanned) dobroitem.post.getFormattedText();
        cast_ok = true;
      } catch (ClassCastException e) {
        cast_ok = false;
      }
      if (cast_ok) {
        URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
        for (URLSpan span : spans) {
          String url = span.getURL();
          Pattern p = Pattern.compile("(youtube\\.com/watch\\?v=|youtu\\.be/)(\\S{11})");
          Matcher m = p.matcher(url);
          if (!m.find()) continue;
          String yt_id = m.group(2);
          String text = s.subSequence(s.getSpanStart(span), s.getSpanEnd(span)).toString();
          CachedAsyncImageView imageView = new CachedAsyncImageView(getContext());
          imageView.setLayoutParams(
              new LayoutParams((int) ((mImageHeight + 4) / 0.75), mImageHeight + 4));

          imageView.setRating(Rating.SWF);
          imageView.setForceLoad(false);
          imageView.setTag(url);
          imageView.setPadding(2, 2, 2, 2);
          imageView.setAdjustViewBounds(true);
          imageView.setMaxHeight(mImageHeight);
          imageView.setMaxWidth((int) ((mImageHeight + 4) / 0.75));

          imageView.setUrl("http://img.youtube.com/vi/" + yt_id + "/0.jpg");

          imageView.setBackgroundColor(backgroundColor);
          imageView.setScaleType(ScaleType.CENTER);

          VerticalTextView textView = new VerticalTextView(getContext(), null);
          textView.setGravity(Gravity.BOTTOM);
          textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
          textView.setText(text);
          textView.setLinkedImageView(imageView);
          textView.setWidth(mImageHeight + 4);

          if (show_info) imagesLayout.addView(textView);
          imagesLayout.addView(imageView);
          imagesLayout.setVisibility(VISIBLE);
        }
      }
    }
    metadataRightView.setText(
        getContext()
            .getString(
                R.string.post_date, String.valueOf(dobroitem.post.getDate().replace(' ', '\n'))));
    metadataLeftView.setText(
        dobroitem.post.getName()
            + "\n"
            + getContext()
                .getString(R.string.post_id, String.valueOf(dobroitem.post.getDisplay_id())));
    List<String> refs = dobroitem.post.getRefs();
    if (!refs.isEmpty()) {
      /*
      CharSequence seq = getContext().getText(R.string.answers);
      SpannableStringBuilder s = new SpannableStringBuilder(seq);
      s.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, seq.length(), 0);
      s.append(" ");
      for (String ref : refs) {
      	int start = s.length();
      	s.append(ref + ", ");
      	s.setSpan(
      			new DobroLinkSpan(dobroitem.post.getBoardName(), ref
      					.substring(2), getContext(), null), start, start
      					+ ref.length(), 0);
      }
      refsView.setText(s.subSequence(0, s.length() - 2),
      		BufferType.SPANNABLE);
       */
      refsButton.setText(String.format("/%d", refs.size()));
      refsButton.setVisibility(View.VISIBLE);
    } else refsButton.setVisibility(View.GONE);
    checkSpells();
  }
  @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;
    }
  }