예제 #1
0
  private void initViews() {
    arrViews = new ArrayList<View>();
    baseView = new FrameLayout(context);
    mViewPager = new ViewPager(context);
    llDots = new LinearLayout(context);
    llDots.setOrientation(RadioGroup.HORIZONTAL);

    llDots.setGravity(Gravity.CENTER_HORIZONTAL);
    LinearLayout.LayoutParams paramsGroup =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, (int) (20 * fDensity));
    paramsGroup.gravity = Gravity.CENTER_HORIZONTAL;
    llDots.setLayoutParams(paramsGroup);
    if (resIds == null) return;
    for (int i = 0; i < resIds.length; i++) {
      ImageView iv = new ImageView(context);
      iv.setId(i);
      iv.setTag(i);
      iv.setOnClickListener(mClick);
      iv.setOnTouchListener(onTouch);
      iv.setBackgroundResource(resIds[i]);
      arrViews.add(iv);
      RelativeLayout rl = new RelativeLayout(context);
      android.widget.RelativeLayout.LayoutParams layoutParam =
          new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
      layoutParam.addRule(RelativeLayout.CENTER_VERTICAL);
      ImageView dot = new ImageView(context);
      dot.setId(i);

      if (i == 0) {
        dot.setImageResource(dotResId1);
      } else {
        dot.setImageResource(dotResId2);
      }
      rl.addView(dot, layoutParam);
      rl.setPadding(0, 0, (int) (13 * fDensity), 0);
      llDots.addView(rl);
    }
    LinearLayout.LayoutParams params =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
    baseView.addView(mViewPager, params);

    pageItemAdapter = new PageItemAdapter(arrViews);
    mViewPager.setAdapter(pageItemAdapter);
    mViewPager.setOnPageChangeListener(mPageChange);

    LayoutParams params2 =
        new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, (int) (20 * fDensity));
    params2.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
    params2.bottomMargin = (int) (10 * fDensity);
    baseView.addView(llDots, params2);
    initPage();
    addContentView();
  }
  @Before
  public void setUp() throws Exception {
    Activity context = Robolectric.buildActivity(Activity.class).create().get();
    relativeLayout = new RelativeLayout(context);
    relativeLayout.setId((int) Utils.generateUniqueId());
    viewGroup = new LinearLayout(context);

    BaseForwardingNativeAd baseForwardingNativeAd = new BaseForwardingNativeAd() {};
    baseForwardingNativeAd.setTitle("test title");
    baseForwardingNativeAd.setText("test text");
    baseForwardingNativeAd.setCallToAction("test call to action");
    baseForwardingNativeAd.setClickDestinationUrl("destinationUrl");

    nativeResponse =
        new NativeResponse(
            context,
            "impressionTrackerUrl",
            "clickTrackerUrl",
            "test ID",
            baseForwardingNativeAd,
            mock(MoPubNative.MoPubNativeListener.class));

    titleView = new TextView(context);
    titleView.setId((int) Utils.generateUniqueId());
    textView = new TextView(context);
    textView.setId((int) Utils.generateUniqueId());
    callToActionView = new Button(context);
    callToActionView.setId((int) Utils.generateUniqueId());
    mainImageView = new ImageView(context);
    mainImageView.setId((int) Utils.generateUniqueId());
    iconImageView = new ImageView(context);
    iconImageView.setId((int) Utils.generateUniqueId());
    badView = new ImageView(context);
    badView.setId((int) Utils.generateUniqueId());

    relativeLayout.addView(titleView);
    relativeLayout.addView(textView);
    relativeLayout.addView(callToActionView);
    relativeLayout.addView(mainImageView);
    relativeLayout.addView(iconImageView);
    relativeLayout.addView(badView);

    viewBinder =
        new ViewBinder.Builder(relativeLayout.getId())
            .titleId(titleView.getId())
            .textId(textView.getId())
            .callToActionId(callToActionView.getId())
            .mainImageId(mainImageView.getId())
            .iconImageId(iconImageView.getId())
            .build();

    subject = new MoPubNativeAdRenderer(viewBinder);
  }
예제 #3
0
 @Override
 public View getView(int position, View convertView, ViewGroup container) {
   String imgurl = imageList.get(position);
   imgurl = imgurl.substring(0, imgurl.indexOf("_"));
   ImageView imageView;
   if (convertView == null) {
     convertView = imageView = new ImageView(IndexActivity.this);
     imageView.setScaleType(ScaleType.FIT_XY);
     imageView.setId(Integer.valueOf(position));
     convertView.setTag(imageView);
   } else {
     imageView = (ImageView) convertView.getTag();
   }
   ImageLoader.getInstance()
       .displayImage(
           UrlContants.GIFTIMGURL + imgurl + File.separator + imageList.get(position),
           imageView);
   imageView.setOnClickListener(
       new OnClickListener() {
         @Override
         public void onClick(View view) {
           int index = Integer.valueOf(view.getId());
           startActivity(
               new Intent(IndexActivity.this, GiftDetailActivity.class)
                   .putExtra("goods_id", specialList.get(index).getGoods_id())
                   .putExtra("saw", specialList.get(index).getGoods_id()));
         }
       });
   return convertView;
 }
예제 #4
0
  private ImageView initializeImageView() {
    ImageView image;
    image = new ImageView(this.activity);
    image.setId(IMAGE_ID);
    image.setAdjustViewBounds(true);
    image.setScaleType(this.style.imageScaleType);

    // set the image drawable if not null
    if (null != this.style.imageDrawable) {
      image.setImageDrawable(this.style.imageDrawable);
    }

    // set the image resource if not 0. This will overwrite the drawable
    // if both are set
    if (this.style.imageResId != 0) {
      image.setImageResource(this.style.imageResId);
    }

    RelativeLayout.LayoutParams imageParams =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    imageParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    imageParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);

    image.setLayoutParams(imageParams);

    return image;
  }
예제 #5
0
  protected void buildView() {
    final Context context = getContext();

    mProgressBar = new ProgressBar(context);
    final LayoutParams progressLayoutParams = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
    progressLayoutParams.gravity = Gravity.CENTER;
    mProgressBar.setLayoutParams(progressLayoutParams);
    mProgressBar.setId(INTERNAL_PROGRESS_ID);
    mProgressBar.setIndeterminate(true);
    mProgressBar.setVisibility(View.GONE);

    addView(mProgressBar);

    mIsLoading = false;

    mImageView = new ImageView(context);
    final LayoutParams imageViewLayoutParams = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
    imageViewLayoutParams.gravity = Gravity.CENTER;
    mImageView.setLayoutParams(imageViewLayoutParams);
    mImageView.setId(INTERNAL_IMAGEVIEW_ID);
    mImageView.setVisibility(View.VISIBLE);

    addView(mImageView);

    setLayoutParams(new LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
  }
  public HierarchyElementView(Context context, HierarchyElement it) {
    super(context);

    setColor(it.getColor());

    mIcon = new ImageView(context);
    mIcon.setImageDrawable(it.getIcon());
    mIcon.setId(1);
    mIcon.setPadding(0, 15, 5, 0);
    addView(
        mIcon,
        new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    mPrimaryTextView = new TextView(context);
    mPrimaryTextView.setTextAppearance(context, android.R.style.TextAppearance_Large);
    mPrimaryTextView.setText(it.getPrimaryText());
    mPrimaryTextView.setPadding(0, 7, 0, 0);
    mPrimaryTextView.setId(2);
    LayoutParams l =
        new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    l.addRule(RelativeLayout.RIGHT_OF, mIcon.getId());
    addView(mPrimaryTextView, l);

    mSecondaryTextView = new TextView(context);
    mSecondaryTextView.setText(it.getSecondaryText());
    mSecondaryTextView.setPadding(0, 0, 0, 7);
    mSecondaryTextView.setTextAppearance(context, android.R.style.TextAppearance_Small);
    LayoutParams lp =
        new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.BELOW, mPrimaryTextView.getId());
    lp.addRule(RelativeLayout.RIGHT_OF, mIcon.getId());
    addView(mSecondaryTextView, lp);
  }
  @Override
  public void onStopTrackingTouch(SeekBar arg0) {

    par.requestImage(par.getRequestUrl(page, "RGB", "small"));

    b = par.getBitmap();

    highRes.setImageBitmap(b);

    highRes.setId(page);
  }
예제 #8
0
  private void initItems() {
    // 避免冲突
    if (getChildCount() > 0) {
      return;
    }

    int screenWidth = wm.getDefaultDisplay().getWidth();
    int initCols =
        screenWidth % rowWidth == 0 ? screenWidth / rowWidth : screenWidth / rowWidth + 1;

    int initLength = Math.min(adapter.getCount(), initCols * 2 * rows);
    for (int i = 0; i < initLength; i++) {
      int left = (i / rows) * (itemWidth + spaceHori);
      int top = (i % rows) * (spaceVert + itemHeight);
      RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(itemWidth, itemHeight);
      if (initLength == 1) {
        rlp.setMargins(left, top, 0, paddingTop * 2);
      } else {
        rlp.setMargins(left, top, 0, 0);
      }

      View child = adapter.getView(i, null, this);
      this.addView(child, rlp);
      int viewId = child.getId();
      if (viewId == -1) {
        viewId = TvUtil.buildId();
        // 此处硬设置id同时建议开发者不用此范围id
      }
      child.setId(viewId);
      itemIds.put(viewId, i);
      bindEventOnChild(child, i);
      layoutFlag = true;
    }
    colCount = itemIds.size() % rows == 0 ? itemIds.size() / rows : itemIds.size() / rows + 1;

    cursor = new ImageView(getContext());
    cursorId = TvUtil.buildId();
    cursor.setId(cursorId);
    cursor.setBackgroundResource(cursorRes);
    this.addView(cursor);
    cursor.setVisibility(View.INVISIBLE);

    if (initFocus) {
      View focus = ((ViewGroup) getParent()).findFocus();
      if (focus == null) {
        View item = getChildAt(0);
        if (item != null) {
          item.requestFocus();
        }
      }
    }
  }
예제 #9
0
 private void addAttribute(Attribute a) {
   View v =
       x.inflater.new Builder(attributesLayout, R.layout.select_entry_simple_minus)
           .withId(R.id.edit_attribute, this)
           .create();
   setAttributeData(v, a);
   ImageView plusImageView = (ImageView) v.findViewById(R.id.plus_minus);
   plusImageView.setId(R.id.remove_attribute);
   plusImageView.setOnClickListener(this);
   plusImageView.setTag(v.getTag());
   v.setTag(a);
   scrollView.fullScroll(ScrollView.FOCUS_DOWN);
 }
예제 #10
0
 public void setMarkCount(int iCount) {
   mImageView = new ImageView[iCount];
   LinearLayout.LayoutParams p =
       new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
   for (int i = 0; i < iCount; i++) {
     ImageView image = new ImageView(context);
     image.setImageResource(R.drawable.d1);
     image.setLayoutParams(p);
     image.setPadding(10, 0, 0, 0);
     mImageView[i] = image;
     image.setId(i);
     addView(image);
   }
 }
예제 #11
0
 @Override
 public Object instantiateItem(ViewGroup container, int position) {
   ImageView imageView = new ImageView(container.getContext());
   ViewGroup.LayoutParams params =
       new ViewGroup.LayoutParams(
           ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
   imageView.setImageResource(imgs[position]);
   imageView.setId(R.id.imageView);
   imageView.setLayoutParams(params);
   imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
   imageView.setOnClickListener(onClickListener);
   container.addView(imageView);
   return imageView;
 }
예제 #12
0
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
      final UserFriend objFriend = vecFreiend.get(position);
      convertView = (LinearLayout) getLayoutInflater().inflate(R.layout.friends_list_cell, null);
      final ImageView ivCheckBox = (ImageView) convertView.findViewById(R.id.ivCheckBox);
      ivCheckBox.setVisibility(ImageView.VISIBLE);
      ImageView ivFriendsListIcon = (ImageView) convertView.findViewById(R.id.ivFriendsListIcon);
      ProgressBar friend_list_progress_bar =
          (ProgressBar) convertView.findViewById(R.id.friend_list_progress_bar);
      TextView tvFriendsListName = (TextView) convertView.findViewById(R.id.tvFriendsListName);
      ivCheckBox.setId(position);
      ivCheckBox.setTag(UNSELECTED);

      if (!objFriend.imagesrc.equals(AppConstants.NOIMAGE)) {
        String friendImageUrl = AppConstants.IMAGE_HOST_URL + objFriend.imagesrc;
        if (!objDrawableManager.fetchDrawableOnThread(
            friendImageUrl,
            ivFriendsListIcon,
            70,
            50,
            objFriend.image_id,
            objFriend.isImageUpdated)) {
          friend_list_progress_bar.setVisibility(View.GONE);
          ivFriendsListIcon.setImageResource(R.drawable.no_image_smal_event);
        }
      } else {
        friend_list_progress_bar.setVisibility(View.GONE);
        ivFriendsListIcon.setImageResource(R.drawable.no_image_smal_event);
      }

      convertView.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              if (ivCheckBox.getTag().equals(UNSELECTED)) {
                String email = objFriend.email;
                vctEmails.add(email);
                ivCheckBox.setTag(SELECTED);
                ivCheckBox.setImageResource(R.drawable.btn_check_on);
              } else if (ivCheckBox.getTag().equals(SELECTED)) {
                String email = objFriend.email;
                ivCheckBox.setTag(UNSELECTED);
                ivCheckBox.setImageResource(R.drawable.btn_check_off);
                vctEmails.remove(email);
              }
            }
          });
      tvFriendsListName.setText(objFriend.firstname + " " + objFriend.lastname);
      return convertView;
    }
예제 #13
0
 /**
  * 通用右侧图标 最大3个
  *
  * @param resIds 图标资源数组
  * @param onRightImagesClickListener 点击的回调
  */
 public void initRightImages(int[] resIds, View.OnClickListener onRightImagesClickListener) {
   LinearLayout rightLl = (LinearLayout) findViewById(R.id.ll_common_right);
   LinearLayout.LayoutParams params =
       new LinearLayout.LayoutParams(
           ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
   params.leftMargin = 10;
   rightLl.setOrientation(LinearLayout.HORIZONTAL); // 默认为横向
   for (int i = 0; i < resIds.length; i++) {
     ImageView image = new ImageView(this);
     image.setImageResource(resIds[i]);
     image.setId(resIds[i]);
     image.setOnClickListener(onRightImagesClickListener);
     rightLl.addView(image, params);
   }
 }
예제 #14
0
  /**
   * ����������Ӧ��ͼƬ
   *
   * @param resId
   */
  private void setWeatherImage(int resId) {

    // �Ƴ�֮ǰ��ͼƬ
    if (layout != null) {
      layout.removeAllViews();
    }
    ImageView item = new ImageView(getParentFragment().getActivity());
    item.setImageResource(resId); // ����ͼƬ
    RelativeLayout.LayoutParams lp =
        new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.CENTER_IN_PARENT); // �븸������������
    lp.topMargin = 10;
    item.setId(1); // �������View ��id
    item.setLayoutParams(lp); // ���ò��ֲ���
    layout.addView(item); // RelativeLayout�����View
  }
예제 #15
0
 public ImageView createImageView(int i, String url) {
   LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
   lp.weight = 1;
   ImageView image = new ImageView(getContext());
   image.setLayoutParams(lp);
   image.setScaleType(ScaleType.CENTER_CROP);
   image.setId(i);
   image.setTag(i);
   image.setOnClickListener(imgClick);
   image.setOnLongClickListener(longClick);
   if (imgList.size() < 3 || (imgList.size() < 4 && i == 0)) {
     ImageLoader.getInstance().displayImage(url + StaticFactory._600x600, image, options_defalut);
   } else {
     ImageLoader.getInstance().displayImage(url + StaticFactory._320x320, image, options_defalut);
   }
   return image;
 }
  private RelativeLayout createImage(String path, int id, final String bigPath) {
    RelativeLayout relativeLayout = new RelativeLayout(context);
    LayoutParams layoutParams =
        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    layoutParams.gravity = Gravity.CENTER;
    layoutParams.leftMargin = width / 55;
    layoutParams.weight = 1;
    relativeLayout.setLayoutParams(layoutParams);
    ImageView imageView = new ImageView(context);
    imageView.setId(id);
    imageView.setOnLongClickListener(this);
    imageView.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // 展示大图片
            BigImageActivity.setViewData(bigPath);
            startActivity(new Intent(CaseTestActivity.this, BigImageActivity.class));
          }
        });
    LayoutParams imageViewParams = new LayoutParams(width / 15 * 4, width / 15 * 4);
    imageView.setLayoutParams(imageViewParams);
    imageView.setScaleType(ScaleType.CENTER_CROP);
    if (!"null".equals(path) && !"".equals(path)) {
      if (path.startsWith("http:")) {
        imageView.setTag(path);
        imageView.setImageResource(R.anim.loading_anim_test);
        ImageListener listener =
            ImageLoader.getImageListener(imageView, 0, android.R.drawable.ic_menu_delete);
        mImageLoader.get(path, listener, 200, 200);
      } else {
        Bitmap bitmap = CommonUtil.readBitMap(200, path);
        imageView.setImageBitmap(bitmap);
      }
    }
    relativeLayout.addView(imageView);
    return relativeLayout;
  }
예제 #17
0
  @Override
  public Object instantiateItem(ViewGroup container, final int position) {
    final ImageView view = new ImageView(container.getContext());
    view.setScaleType(ImageView.ScaleType.CENTER);
    view.setId(position);
    // 加载图片
    if (iInfiniteStatePagerAdapter != null) {
      iInfiniteStatePagerAdapter.loadImg(view, fragments.get(position));
    }

    view.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            if (iInfiniteStatePagerAdapter != null) {
              iInfiniteStatePagerAdapter.onImageItemClick(position);
            }
          }
        });
    container.addView(view);
    return view;
  }
예제 #18
0
  public ImageView getGlowingBorder(Bitmap bitmap) {
    ImageView imageView = new ImageView(getContext());
    imageView.setBackgroundColor(DRAG_BACKGROUND_COLOR);
    imageView.setId(R.id.drag_and_drop_list_view_image_view);

    Bitmap glowingBitmap =
        Bitmap.createBitmap(
            bitmap.getWidth() + 30, bitmap.getHeight() + 30, Bitmap.Config.ARGB_8888);
    Canvas glowingCanvas = new Canvas(glowingBitmap);
    Bitmap alpha = bitmap.extractAlpha();
    Paint paintBlur = new Paint();
    paintBlur.setColor(Color.WHITE);
    glowingCanvas.drawBitmap(alpha, 15, 15, paintBlur);
    BlurMaskFilter blurMaskFilter = new BlurMaskFilter(15.0f, BlurMaskFilter.Blur.OUTER);
    paintBlur.setMaskFilter(blurMaskFilter);
    glowingCanvas.drawBitmap(alpha, 15, 15, paintBlur);
    paintBlur.setMaskFilter(null);
    glowingCanvas.drawBitmap(bitmap, 15, 15, paintBlur);

    imageView.setImageBitmap(glowingBitmap);

    return imageView;
  }
예제 #19
0
  @Override
  public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
    RelativeLayout relativeLayout = new RelativeLayout(mContext);
    RelativeLayout.LayoutParams layoutParams =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);

    relativeLayout.setLayoutParams(layoutParams);

    ImageView imageView = new ImageView(mContext);
    relativeLayout.addView(imageView);
    relativeLayout.setPadding(EmojConstant.dp(10), 0, EmojConstant.dp(10), 0);

    imageView.setId(R.id.image_micro_thumb);

    RelativeLayout.LayoutParams imageLP = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
    imageLP.width = RelativeLayout.LayoutParams.MATCH_PARENT;
    imageLP.height = RelativeLayout.LayoutParams.MATCH_PARENT;
    imageLP.addRule(RelativeLayout.CENTER_HORIZONTAL);
    imageLP.addRule(RelativeLayout.CENTER_VERTICAL);

    return new Holder(relativeLayout, imageView);
  }
예제 #20
0
  private void setupViews(Context context, AttributeSet attrs) {
    mImg = new ImageView(context);
    LayoutParams lp0 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    //		lp0.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    //		lp0.addRule(RelativeLayout.CENTER_VERTICAL);
    //		mImg.setPadding(0, 0, 10, 0);
    mImg.setImageResource(R.drawable.iphone_clean_icon);
    mImg.setVisibility(View.GONE);
    mImg.setId(R.id.iphonecontact_clear_edittext);
    addView(mImg, lp0);

    mImg.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            mEdt.setText("");
          }
        });

    mEdt = new EditText(context);
    mEdt.setBackgroundResource(android.R.color.transparent);
    if (mbg != null) {
      setBackgroundDrawable(mbg);
    }
    mEdt.setPadding(mEdtTextPaddingLeft, 0, 0, 0);
    mEdt.setTextSize(mEdtTextSize);
    mEdt.setGravity(Gravity.CENTER_VERTICAL);
    if (mEdtTextColor != 0) {
      mEdt.setTextColor(mEdtTextColor);
    }
    mEdt.setHint(mEdtHint);
    mEdt.setSingleLine(true);
    LayoutParams lp1 = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    addView(mEdt, lp1);
    mEdt.addTextChangedListener(new EditTextWatcher());
  }
예제 #21
0
  public SignatureWidget(Context context, FormEntryPrompt prompt) {
    super(context, prompt);

    mInstanceFolder = Collect.getInstance().getFormController().getInstancePath().getParent();

    setOrientation(LinearLayout.VERTICAL);

    TableLayout.LayoutParams params = new TableLayout.LayoutParams();
    params.setMargins(7, 5, 7, 5);

    mErrorTextView = new TextView(context);
    mErrorTextView.setId(QuestionWidget.newUniqueId());
    mErrorTextView.setText("Selected file is not a valid image");

    // setup Blank Image Button
    mSignButton = new Button(getContext());
    mSignButton.setId(QuestionWidget.newUniqueId());
    mSignButton.setText(getContext().getString(R.string.sign_button));
    mSignButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
    mSignButton.setPadding(20, 20, 20, 20);
    mSignButton.setEnabled(!prompt.isReadOnly());
    mSignButton.setLayoutParams(params);
    // launch capture intent on click
    mSignButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Collect.getInstance()
                .getActivityLogger()
                .logInstanceAction(this, "signButton", "click", mPrompt.getIndex());
            launchSignatureActivity();
          }
        });

    // finish complex layout
    addView(mSignButton);
    addView(mErrorTextView);

    // and hide the sign button if read-only
    if (prompt.isReadOnly()) {
      mSignButton.setVisibility(View.GONE);
    }
    mErrorTextView.setVisibility(View.GONE);

    // retrieve answer from data model and update ui
    mBinaryName = prompt.getAnswerText();

    // Only add the imageView if the user has signed
    if (mBinaryName != null) {
      mImageView = new ImageView(getContext());
      mImageView.setId(QuestionWidget.newUniqueId());
      Display display =
          ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
              .getDefaultDisplay();
      int screenWidth = display.getWidth();
      int screenHeight = display.getHeight();

      File f = new File(mInstanceFolder + File.separator + mBinaryName);

      if (f.exists()) {
        Bitmap bmp = FileUtils.getBitmapScaledToDisplay(f, screenHeight, screenWidth);
        if (bmp == null) {
          mErrorTextView.setVisibility(View.VISIBLE);
        }
        mImageView.setImageBitmap(bmp);
      } else {
        mImageView.setImageBitmap(null);
      }

      mImageView.setPadding(10, 10, 10, 10);
      mImageView.setAdjustViewBounds(true);
      mImageView.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              Collect.getInstance()
                  .getActivityLogger()
                  .logInstanceAction(this, "viewImage", "click", mPrompt.getIndex());
              launchSignatureActivity();
            }
          });

      addView(mImageView);
    }
  }
    @SuppressWarnings("unchecked")
    public ListMultiWidget(Context context, FormEntryPrompt prompt, boolean displayLabel) {
        super(context, prompt);

        mItems = prompt.getSelectChoices();
        mCheckboxes = new ArrayList<CheckBox>();
        mPrompt = prompt;

        // Layout holds the horizontal list of buttons
        LinearLayout buttonLayout = new LinearLayout(context);

        Vector<Selection> ve = new Vector<Selection>();
        if (prompt.getAnswerValue() != null) {
            ve = (Vector<Selection>) prompt.getAnswerValue().getValue();
        }

        if (mItems != null) {
            for (int i = 0; i < mItems.size(); i++) {
                CheckBox c = new CheckBox(getContext());
                c.setTag(Integer.valueOf(i));
                c.setId(QuestionWidget.newUniqueId());
                c.setFocusable(!prompt.isReadOnly());
                c.setEnabled(!prompt.isReadOnly());
                for (int vi = 0; vi < ve.size(); vi++) {
                    // match based on value, not key
                    if (mItems.get(i).getValue().equals(ve.elementAt(vi).getValue())) {
                        c.setChecked(true);
                        break;
                    }

                }
                mCheckboxes.add(c);

                // when clicked, check for readonly before toggling
                c.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (!mCheckboxInit && mPrompt.isReadOnly()) {
                            if (buttonView.isChecked()) {
                                buttonView.setChecked(false);
                               	Collect.getInstance().getActivityLogger().logInstanceAction(this, "onItemClick.deselect",
                            			mItems.get((Integer)buttonView.getTag()).getValue(), mPrompt.getIndex());
                            } else {
                                buttonView.setChecked(true);
                               	Collect.getInstance().getActivityLogger().logInstanceAction(this, "onItemClick.select",
                            			mItems.get((Integer)buttonView.getTag()).getValue(), mPrompt.getIndex());
                            }
                        }
                    }
                });

                String imageURI = null;
                imageURI =
                    prompt.getSpecialFormSelectChoiceText(mItems.get(i),
                        FormEntryCaption.TEXT_FORM_IMAGE);

                // build image view (if an image is provided)
                ImageView mImageView = null;
                TextView mMissingImage = null;

                final int labelId = QuestionWidget.newUniqueId();

                // Now set up the image view
                String errorMsg = null;
                if (imageURI != null) {
                    try {
                        String imageFilename =
                            ReferenceManager._().DeriveReference(imageURI).getLocalURI();
                        final File imageFile = new File(imageFilename);
                        if (imageFile.exists()) {
                            Bitmap b = null;
                            try {
                                Display display =
                                    ((WindowManager) getContext().getSystemService(
                                        Context.WINDOW_SERVICE)).getDefaultDisplay();
                                int screenWidth = display.getWidth();
                                int screenHeight = display.getHeight();
                                b =
                                    FileUtils.getBitmapScaledToDisplay(imageFile, screenHeight,
                                        screenWidth);
                            } catch (OutOfMemoryError e) {
                                errorMsg = "ERROR: " + e.getMessage();
                            }

                            if (b != null) {
                                mImageView = new ImageView(getContext());
                                mImageView.setPadding(2, 2, 2, 2);
                                mImageView.setAdjustViewBounds(true);
                                mImageView.setImageBitmap(b);
                                mImageView.setId(labelId);
                            } else if (errorMsg == null) {
                                // An error hasn't been logged and loading the image failed, so it's
                                // likely
                                // a bad file.
                                errorMsg = getContext().getString(R.string.file_invalid, imageFile);

                            }
                        } else if (errorMsg == null) {
                            // An error hasn't been logged. We should have an image, but the file
                            // doesn't
                            // exist.
                            errorMsg = getContext().getString(R.string.file_missing, imageFile);
                        }

                        if (errorMsg != null) {
                            // errorMsg is only set when an error has occured
                            Log.e(t, errorMsg);
                            mMissingImage = new TextView(getContext());
                            mMissingImage.setText(errorMsg);

                            mMissingImage.setPadding(2, 2, 2, 2);
                            mMissingImage.setId(labelId);
                        }
                    } catch (InvalidReferenceException e) {
                        Log.e(t, "image invalid reference exception");
                        e.printStackTrace();
                    }
                } else {
                    // There's no imageURI listed, so just ignore it.
                }

                // build text label. Don't assign the text to the built in label to he
                // button because it aligns horizontally, and we want the label on top
                TextView label = new TextView(getContext());
                label.setText(prompt.getSelectChoiceText(mItems.get(i)));
                label.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
                label.setGravity(Gravity.CENTER_HORIZONTAL);
                if (!displayLabel) {
                    label.setVisibility(View.GONE);
                }

                // answer layout holds the label text/image on top and the radio button on bottom
                RelativeLayout answer = new RelativeLayout(getContext());
                RelativeLayout.LayoutParams headerParams =
                        new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                headerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                headerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
                
                RelativeLayout.LayoutParams buttonParams =
                        new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                buttonParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

                if (mImageView != null) {
                	mImageView.setScaleType(ScaleType.CENTER);
                    if (!displayLabel) {
                        mImageView.setVisibility(View.GONE);
                    }
                    answer.addView(mImageView, headerParams);
                } else if (mMissingImage != null) {
                    answer.addView(mMissingImage, headerParams);
                } else {
                    if (displayLabel) {
                    	label.setId(labelId);
                        answer.addView(label, headerParams);
                    }

                }
                if (displayLabel) {
                	buttonParams.addRule(RelativeLayout.BELOW, labelId);
                }
                answer.addView(c, buttonParams);
                answer.setPadding(4, 0, 4, 0);

                // /Each button gets equal weight
                LinearLayout.LayoutParams answerParams =
                    new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                            LayoutParams.WRAP_CONTENT);
                answerParams.weight = 1;

                buttonLayout.addView(answer, answerParams);

            }
        }

        // Align the buttons so that they appear horizonally and are right justified
        // buttonLayout.setGravity(Gravity.RIGHT);
        buttonLayout.setOrientation(LinearLayout.HORIZONTAL);
        // LinearLayout.LayoutParams params = new
        // LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        // buttonLayout.setLayoutParams(params);

        // The buttons take up the right half of the screen
        LinearLayout.LayoutParams buttonParams =
            new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
        buttonParams.weight = 1;

        questionLayout.addView(buttonLayout, buttonParams);
        addView(questionLayout);

    }
  public AnnotateWidget(Context context, FormEntryPrompt prompt) {
    super(context, prompt);

    mInstanceFolder = Collect.getInstance().getFormController().getInstancePath().getParent();

    setOrientation(LinearLayout.VERTICAL);

    TableLayout.LayoutParams params = new TableLayout.LayoutParams();
    params.setMargins(7, 5, 7, 5);

    mErrorTextView = new TextView(context);
    mErrorTextView.setId(QuestionWidget.newUniqueId());
    mErrorTextView.setText("Selected file is not a valid image");

    // setup capture button
    mCaptureButton = new Button(getContext());
    mCaptureButton.setId(QuestionWidget.newUniqueId());
    mCaptureButton.setText(getContext().getString(R.string.capture_image));
    mCaptureButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
    mCaptureButton.setPadding(20, 20, 20, 20);
    mCaptureButton.setEnabled(!prompt.isReadOnly());
    mCaptureButton.setLayoutParams(params);

    // launch capture intent on click
    mCaptureButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Collect.getInstance()
                .getActivityLogger()
                .logInstanceAction(this, "captureButton", "click", mPrompt.getIndex());
            mErrorTextView.setVisibility(View.GONE);
            Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            // We give the camera an absolute filename/path where to put the
            // picture because of bug:
            // http://code.google.com/p/android/issues/detail?id=1480
            // The bug appears to be fixed in Android 2.0+, but as of feb 2,
            // 2010, G1 phones only run 1.6. Without specifying the path the
            // images returned by the camera in 1.6 (and earlier) are ~1/4
            // the size. boo.

            // if this gets modified, the onActivityResult in
            // FormEntyActivity will also need to be updated.
            i.putExtra(
                android.provider.MediaStore.EXTRA_OUTPUT,
                Uri.fromFile(new File(Collect.TMPFILE_PATH)));
            try {
              Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex());
              ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CAPTURE);
            } catch (ActivityNotFoundException e) {
              Toast.makeText(
                      getContext(),
                      getContext().getString(R.string.activity_not_found, "image capture"),
                      Toast.LENGTH_SHORT)
                  .show();
              Collect.getInstance().getFormController().setIndexWaitingForData(null);
            }
          }
        });

    // setup chooser button
    mChooseButton = new Button(getContext());
    mChooseButton.setId(QuestionWidget.newUniqueId());
    mChooseButton.setText(getContext().getString(R.string.choose_image));
    mChooseButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
    mChooseButton.setPadding(20, 20, 20, 20);
    mChooseButton.setEnabled(!prompt.isReadOnly());
    mChooseButton.setLayoutParams(params);

    // launch capture intent on click
    mChooseButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Collect.getInstance()
                .getActivityLogger()
                .logInstanceAction(this, "chooseButton", "click", mPrompt.getIndex());
            mErrorTextView.setVisibility(View.GONE);
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.setType("image/*");

            try {
              Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex());
              ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CHOOSER);
            } catch (ActivityNotFoundException e) {
              Toast.makeText(
                      getContext(),
                      getContext().getString(R.string.activity_not_found, "choose image"),
                      Toast.LENGTH_SHORT)
                  .show();
              Collect.getInstance().getFormController().setIndexWaitingForData(null);
            }
          }
        });

    // setup Blank Image Button
    mAnnotateButton = new Button(getContext());
    mAnnotateButton.setId(QuestionWidget.newUniqueId());
    mAnnotateButton.setText(getContext().getString(R.string.markup_image));
    mAnnotateButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
    mAnnotateButton.setPadding(20, 20, 20, 20);
    mAnnotateButton.setEnabled(false);
    mAnnotateButton.setLayoutParams(params);
    // launch capture intent on click
    mAnnotateButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Collect.getInstance()
                .getActivityLogger()
                .logInstanceAction(this, "annotateButton", "click", mPrompt.getIndex());
            launchAnnotateActivity();
          }
        });

    // finish complex layout
    addView(mCaptureButton);
    addView(mChooseButton);
    addView(mAnnotateButton);
    addView(mErrorTextView);

    // and hide the capture, choose and annotate button if read-only
    if (prompt.isReadOnly()) {
      mCaptureButton.setVisibility(View.GONE);
      mChooseButton.setVisibility(View.GONE);
      mAnnotateButton.setVisibility(View.GONE);
    }
    mErrorTextView.setVisibility(View.GONE);

    // retrieve answer from data model and update ui
    mBinaryName = prompt.getAnswerText();

    // Only add the imageView if the user has taken a picture
    if (mBinaryName != null) {
      if (!prompt.isReadOnly()) {
        mAnnotateButton.setEnabled(true);
      }
      mImageView = new ImageView(getContext());
      mImageView.setId(QuestionWidget.newUniqueId());
      Display display =
          ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
              .getDefaultDisplay();
      int screenWidth = display.getWidth();
      int screenHeight = display.getHeight();

      File f = new File(mInstanceFolder + File.separator + mBinaryName);

      if (f.exists()) {
        Bitmap bmp = FileUtils.getBitmapScaledToDisplay(f, screenHeight, screenWidth);
        if (bmp == null) {
          mErrorTextView.setVisibility(View.VISIBLE);
        }
        mImageView.setImageBitmap(bmp);
      } else {
        mImageView.setImageBitmap(null);
      }

      mImageView.setPadding(10, 10, 10, 10);
      mImageView.setAdjustViewBounds(true);
      mImageView.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              Collect.getInstance()
                  .getActivityLogger()
                  .logInstanceAction(this, "viewImage", "click", mPrompt.getIndex());
              launchAnnotateActivity();
            }
          });

      addView(mImageView);
    }
  }
예제 #24
0
    public LabelWidget(Context context, FormEntryPrompt prompt) {
        super(context, prompt);

        mItems = prompt.getSelectChoices();
        mPrompt = prompt;

        buttonLayout = new LinearLayout(context);

        if (prompt.getSelectChoices() != null) {
            for (int i = 0; i < mItems.size(); i++) {

                String imageURI = null;
                imageURI =
                    prompt.getSpecialFormSelectChoiceText(mItems.get(i),
                        FormEntryCaption.TEXT_FORM_IMAGE);

                // build image view (if an image is provided)
                mImageView = null;
                mMissingImage = null;

                // Now set up the image view
                String errorMsg = null;
                if (imageURI != null) {
                    try {
                        String imageFilename =
                            ReferenceManager._().DeriveReference(imageURI).getLocalURI();
                        final File imageFile = new File(imageFilename);
                        if (imageFile.exists()) {
                            Bitmap b = null;
                            try {
                                Display display =
                                    ((WindowManager) getContext().getSystemService(
                                        Context.WINDOW_SERVICE)).getDefaultDisplay();
                                int screenWidth = display.getWidth();
                                int screenHeight = display.getHeight();
                                b =
                                    FileUtils.getBitmapScaledToDisplay(imageFile, screenHeight,
                                        screenWidth);
                            } catch (OutOfMemoryError e) {
                                errorMsg = "ERROR: " + e.getMessage();
                            }

                            if (b != null) {
                                mImageView = new ImageView(getContext());
                                mImageView.setPadding(2, 2, 2, 2);
                                mImageView.setAdjustViewBounds(true);
                                mImageView.setImageBitmap(b);
                                mImageView.setId(23423534);
                            } else if (errorMsg == null) {
                                // An error hasn't been logged and loading the image failed, so it's
                                // likely
                                // a bad file.
                                errorMsg = getContext().getString(R.string.file_invalid, imageFile);

                            }
                        } else if (errorMsg == null) {
                            // An error hasn't been logged. We should have an image, but the file
                            // doesn't
                            // exist.
                            errorMsg = getContext().getString(R.string.file_missing, imageFile);
                        }

                        if (errorMsg != null) {
                            // errorMsg is only set when an error has occured
                            Log.e(t, errorMsg);
                            mMissingImage = new TextView(getContext());
                            mMissingImage.setText(errorMsg);

                            mMissingImage.setPadding(2, 2, 2, 2);
                            mMissingImage.setId(234873453);
                        }
                    } catch (InvalidReferenceException e) {
                        Log.e(t, "image invalid reference exception");
                        e.printStackTrace();
                    }
                } else {
                    // There's no imageURI listed, so just ignore it.
                }

                // build text label. Don't assign the text to the built in label to he
                // button because it aligns horizontally, and we want the label on top
                label = new TextView(getContext());
                label.setText(prompt.getSelectChoiceText(mItems.get(i)));
                label.setTextSize(TypedValue.COMPLEX_UNIT_DIP, TEXTSIZE);

                // answer layout holds the label text/image on top and the radio button on bottom
                LinearLayout answer = new LinearLayout(getContext());
                answer.setOrientation(LinearLayout.VERTICAL);
                LinearLayout.LayoutParams params =
                    new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                            LayoutParams.WRAP_CONTENT);
                params.gravity = Gravity.TOP;
                answer.setLayoutParams(params);

                if (mImageView != null) {
                    answer.addView(mImageView);
                } else if (mMissingImage != null) {
                    answer.addView(mMissingImage);
                } else {
                    answer.addView(label);
                }
                answer.setPadding(4, 0, 4, 0);

                // Each button gets equal weight
                LinearLayout.LayoutParams answerParams =
                    new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                            LayoutParams.WRAP_CONTENT);
                answerParams.weight = 1;

                buttonLayout.addView(answer, answerParams);

            }
        }

        // Align the buttons so that they appear horizonally and are right justified
        // buttonLayout.setGravity(Gravity.RIGHT);
        buttonLayout.setOrientation(LinearLayout.HORIZONTAL);
        // LinearLayout.LayoutParams params = new
        // LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
        // buttonLayout.setLayoutParams(params);

        // The buttons take up the right half of the screen
        LinearLayout.LayoutParams buttonParams =
            new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
        buttonParams.weight = 1;

        questionLayout.addView(buttonLayout, buttonParams);
        addView(questionLayout);

    }
예제 #25
0
  /**
   * Method to add the image by setting and creating the views dynamically with delete and zoom
   * option.
   */
  @SuppressWarnings("deprecation")
  private void getImageLayout(Bitmap p_bitmap) {
    ViewsVo m_signVo;
    // Check for images count .Set the count for limiting the number of images to add on screen.
    if (m_ImageCount < 1) {
      m_viewsAddedHeightEmotions = m_viewsAddedHeightEmotions + 90;
      m_ImageCount++;
    } /*
       * else { Toast.makeText(m_context, "No enough space for images.",
       * Toast.LENGTH_LONG).show(); }
       */
    m_btnSDeleteImage = new Button(m_context);
    m_btnZoom = new Button(m_context);
    m_ivtmpImage = new ImageView(m_context);

    setViewsHeightDynamically();
    // System.err.println("Height of Layout------" + m_absHeight);
    m_btnSDeleteImage.setLayoutParams(m_layoutparamsDelete);
    m_btnSDeleteImage.setBackgroundDrawable(getResources().getDrawable(R.drawable.ic_deletered));
    m_btnSDeleteImage.setId(0);
    m_btnSDeleteImage.setOnClickListener(new ImageDeleteListener());

    m_btnZoom.setLayoutParams(m_layoutParamsEdit);
    m_btnZoom.setBackgroundDrawable(getResources().getDrawable(R.drawable.right_arrow));
    m_btnZoom.setId(0);

    m_absTextlayout = new AbsoluteLayout(m_context);
    m_absZoomlayout = new AbsoluteLayout(m_context);
    m_ivtmpImage.setImageBitmap(Bitmap.createScaledBitmap(p_bitmap, 400, 180, true));
    m_absTextlayout.setLayoutParams(
        new AbsoluteLayout.LayoutParams(
            AbsoluteLayout.LayoutParams.WRAP_CONTENT,
            AbsoluteLayout.LayoutParams.WRAP_CONTENT,
            0,
            0));
    m_absZoomlayout.setLayoutParams(
        new AbsoluteLayout.LayoutParams(
            AbsoluteLayout.LayoutParams.WRAP_CONTENT,
            AbsoluteLayout.LayoutParams.WRAP_CONTENT,
            0,
            0));

    if (m_absHeight >= 900) m_ivtmpImage.setLayoutParams(new FrameLayout.LayoutParams(400, 200));
    else m_ivtmpImage.setLayoutParams(new FrameLayout.LayoutParams(80, 80));

    m_ivtmpImage.setBackgroundColor(Color.TRANSPARENT);
    m_absTextlayout.addView(m_btnSDeleteImage);
    if (m_absHeight >= 900) m_absZoomlayout.setPadding(0, 0, 0, 0);
    else m_absZoomlayout.setPadding(0, 0, 0, 0);

    m_absZoomlayout.setBackgroundResource(R.drawable.dashedbordersmall);
    m_absZoomlayout.addView(m_ivtmpImage);

    m_absTextlayout.addView(m_absZoomlayout);
    m_absTextlayout.addView(m_btnZoom);
    m_absTextlayout.setDrawingCacheEnabled(true);
    m_absTextlayout.setClickable(true);
    m_absTextlayout.setId(0);
    m_ivtmpImage.setId(0);

    m_vtoTree = m_absTextlayout.getViewTreeObserver();
    m_vtoTree.addOnGlobalLayoutListener(
        new OnGlobalLayoutListener() {

          @Override
          public void onGlobalLayout() {
            m_absTextlayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
          }
        });

    /**
     * Add all the views into arraylist which are added into the screen for further to perform
     * deletion of each views.
     */
    m_signVo = new ViewsVo();
    m_arrSignObjects.add(0, m_signVo);
    m_absolutelayout.addView(m_absTextlayout);

    // Image touch listener to move image onTouch event on screen.
    m_touchImagListener =
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction() & MotionEvent.ACTION_MASK) {
              case MotionEvent.ACTION_DOWN:
                m_oldX = event.getX();
                m_oldY = event.getY();
                break;
              case MotionEvent.ACTION_UP:

              case MotionEvent.ACTION_POINTER_UP:
                break;

              case MotionEvent.ACTION_MOVE:
                m_dX = event.getX() - m_oldX;
                m_dY = event.getY() - m_oldY;

                m_posX = m_prevX + m_dX;
                m_posY = m_prevY + m_dY;

                if (m_posX > 0
                    && m_posY > 0
                    && (m_posX + v.getWidth()) < m_absolutelayout.getWidth()
                    && (m_posY + v.getHeight()) < m_absolutelayout.getHeight()) {
                  v.setLayoutParams(
                      new AbsoluteLayout.LayoutParams(
                          v.getMeasuredWidth(), v.getMeasuredHeight(), (int) m_posX, (int) m_posY));

                  m_prevX = m_posX;
                  m_prevY = m_posY;
                }
                break;
            }
            return false;
          }
        };

    // Listener for the arrow ontouch of arrow ZoomIn and ZoomOut the image.
    m_strecthArrowListener =
        new OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {

            View view;
            // RemoveBorders();
            view = v;
            v.setClickable(true);
            v.setDrawingCacheEnabled(true);
            AbsoluteLayout m_absLayout = null;
            switch (event.getAction() & MotionEvent.ACTION_MASK) {
              case MotionEvent.ACTION_DOWN:
                m_oldX = event.getX();
                m_oldY = event.getY();
                break;
              case MotionEvent.ACTION_UP:

              case MotionEvent.ACTION_POINTER_UP:
                break;

              case MotionEvent.ACTION_MOVE:
                m_newX = event.getX();
                m_newY = event.getY();

                float newDist = m_newX - m_oldX;
                if (m_newX > m_oldX && m_newY > m_oldY) {
                  if (newDist > 0.0f) {
                    m_scale = 1;
                    m_absLayout = (AbsoluteLayout) v.getParent();
                    int m_hightOfImage =
                        (int)
                            (m_scale
                                + (((ImageView)
                                        ((AbsoluteLayout) m_absLayout.getChildAt(1)).getChildAt(0))
                                    .getHeight()));
                    int m_widthOfImage =
                        (int)
                            (m_scale
                                + (((ImageView)
                                        ((AbsoluteLayout) m_absLayout.getChildAt(1)).getChildAt(0))
                                    .getWidth()));
                    m_widthDelete =
                        (int)
                            (m_scale + ((((AbsoluteLayout) m_absLayout.getChildAt(1))).getWidth()));
                    m_heightDelete =
                        (int)
                            (m_scale
                                + ((((AbsoluteLayout) m_absLayout.getChildAt(1)).getHeight())));
                    if (m_absLayout.getBottom() <= (m_ivImage.getBottom())
                        && m_absLayout.getRight() <= (m_DisplayWidth)) {
                      m_layoutparams =
                          new AbsoluteLayout.LayoutParams(m_widthOfImage, m_hightOfImage, 0, 0);
                      ((ImageView) ((AbsoluteLayout) m_absLayout.getChildAt(1)).getChildAt(0))
                          .setLayoutParams(m_layoutparams);

                      m_layoutparams =
                          new AbsoluteLayout.LayoutParams(
                              AbsoluteLayout.LayoutParams.WRAP_CONTENT,
                              AbsoluteLayout.LayoutParams.WRAP_CONTENT,
                              m_absLayout.getLeft(),
                              m_absLayout.getTop());
                      m_absLayout.setLayoutParams(m_layoutparams);
                      ((Button) m_absLayout.getChildAt(0))
                          .setLayoutParams(
                              new AbsoluteLayout.LayoutParams(
                                  m_deleteEditHeightwidth,
                                  m_deleteEditHeightwidth,
                                  m_widthDelete,
                                  0));
                      ((Button) m_absLayout.getChildAt(2))
                          .setLayoutParams(
                              new AbsoluteLayout.LayoutParams(
                                  m_deleteEditHeightwidth,
                                  m_deleteEditHeightwidth,
                                  m_widthDelete,
                                  m_heightDelete));

                      m_hightOfImage =
                          (int)
                              (m_scale
                                  + (((AbsoluteLayout) m_absLayout.getChildAt(1)).getHeight()));
                      m_widthOfImage =
                          (int)
                              (m_scale + (((AbsoluteLayout) m_absLayout.getChildAt(1)).getWidth()));
                      m_layoutparams =
                          new AbsoluteLayout.LayoutParams(
                              m_widthOfImage,
                              m_hightOfImage,
                              ((AbsoluteLayout) m_absLayout.getChildAt(1)).getLeft(),
                              ((AbsoluteLayout) m_absLayout.getChildAt(1)).getTop());
                      ((AbsoluteLayout) m_absLayout.getChildAt(1)).setLayoutParams(m_layoutparams);
                    }
                  }
                }
                if (m_newX < m_oldX && m_newY < m_oldY) {
                  m_absLayout = (AbsoluteLayout) view.getParent();

                  int m_hightOfImage =
                      (int)
                          (((ImageView) ((AbsoluteLayout) m_absLayout.getChildAt(1)).getChildAt(0))
                                  .getHeight()
                              - m_scale);
                  int m_widthOfImage =
                      (int)
                          (((ImageView) ((AbsoluteLayout) m_absLayout.getChildAt(1)).getChildAt(0))
                                  .getWidth()
                              - m_scale);

                  m_widthDelete =
                      (int) (((AbsoluteLayout) m_absLayout.getChildAt(1)).getWidth() - m_scale);
                  m_layoutparams =
                      new AbsoluteLayout.LayoutParams(m_widthOfImage, m_hightOfImage, 0, 0);
                  ((ImageView) ((AbsoluteLayout) m_absLayout.getChildAt(1)).getChildAt(0))
                      .setLayoutParams(m_layoutparams);

                  m_layoutparams =
                      new AbsoluteLayout.LayoutParams(
                          AbsoluteLayout.LayoutParams.WRAP_CONTENT,
                          AbsoluteLayout.LayoutParams.WRAP_CONTENT,
                          m_absLayout.getLeft(),
                          m_absLayout.getTop());
                  m_absLayout.setLayoutParams(m_layoutparams);

                  ((Button) m_absLayout.getChildAt(0))
                      .setLayoutParams(
                          new AbsoluteLayout.LayoutParams(
                              m_deleteEditHeightwidth, m_deleteEditHeightwidth, m_widthDelete, 0));
                  ((Button) m_absLayout.getChildAt(2))
                      .setLayoutParams(
                          new AbsoluteLayout.LayoutParams(
                              m_deleteEditHeightwidth,
                              m_deleteEditHeightwidth,
                              m_widthDelete,
                              m_widthDelete));

                  m_hightOfImage =
                      (int) ((((AbsoluteLayout) m_absLayout.getChildAt(1)).getHeight()) - m_scale);
                  m_widthOfImage =
                      (int) ((((AbsoluteLayout) m_absLayout.getChildAt(1)).getWidth()) - m_scale);
                  m_layoutparams =
                      new AbsoluteLayout.LayoutParams(
                          m_widthOfImage,
                          m_hightOfImage,
                          ((AbsoluteLayout) m_absLayout.getChildAt(1)).getLeft(),
                          ((AbsoluteLayout) m_absLayout.getChildAt(1)).getTop());
                  ((AbsoluteLayout) m_absLayout.getChildAt(1)).setLayoutParams(m_layoutparams);
                }

                break;
            }

            return false;
          }
        };
    m_absTextlayout.setOnTouchListener(m_touchImagListener);
    m_btnZoom.setOnTouchListener(m_strecthArrowListener);
  }
예제 #26
0
  /** Updates status */
  private void updateStatus() {
    // process if the wheels run separately
    if (!wheel1.isScrollingPerformed()
        && !wheel2.isScrollingPerformed()
        && wheel3.isScrollingPerformed()) {
      wheelScrolled = true;
      if (soundPool != null) {
        soundPool.stop(soundSpinning);
      }

      if (checkTheResult()) {
        if (soundPool != null) {
          if (receivedReward.getType().equalsIgnoreCase("OOS")) {
            soundPool.play(soundMissedGift, 0.99f, 0.99f, 0, 0, 1);
          } else {
            soundPool.play(soundWinning, 0.99f, 0.99f, 0, 0, 1);
          }
        }
        AlertDialog.Builder winDialog = new AlertDialog.Builder(SlotMachineActivity.this);
        LayoutInflater factory = LayoutInflater.from(this);
        final View view;
        LinearLayout giftListLayout;
        if (receivedReward.getGifts().size() == 0) {
          view = factory.inflate(R.layout.win_item_bg_layout, null);
          ImageView giftIcon = (ImageView) view.findViewById(R.id.giftIcon);

          if (receivedReward.getType().equalsIgnoreCase(REWARD.free_ticket.toString())) {
            receive_free_ticket = true;
            giftIcon.setImageResource(R.drawable.bonus_free_spin2x);
          } else if (receivedReward.getType().equalsIgnoreCase(REWARD.gold_ticket.toString())) {
            giftIcon.setImageResource(R.drawable.bonus_gold_ticket2x);
          } else if (receivedReward.getType().equalsIgnoreCase(REWARD.purple_tym.toString())) {
            giftIcon.setImageResource(R.drawable.reward_6_2x);
          } else if (receivedReward.getType().equalsIgnoreCase(REWARD.yellow_tym.toString())) {
            giftIcon.setImageResource(R.drawable.reward_5_2x);
          }
          if (receivedReward.getType().contains("card")) {
            RelativeLayout giftCodeLayOut = (RelativeLayout) view.findViewById(R.id.giftCodeLayOut);
            giftCodeLayOut.setVisibility(View.VISIBLE);
            TextView giftCode = (TextView) view.findViewById(R.id.giftCode);
            giftCode.setText(receivedReward.getCode());
            giftCode.setTextColor(Color.BLUE);
            final String msg = getResources().getString(R.string.copyCode);
            giftCode.setOnClickListener(
                new View.OnClickListener() {

                  @Override
                  public void onClick(View v) {
                    // TODO Auto-generated method stub

                    ClipboardManager clipboard =
                        (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                    clipboard.setText(receivedReward.getCode());
                    Toast info = Toast.makeText(getContext(), msg, Toast.LENGTH_LONG);
                    info.show();
                  }
                });
          }

        } else {
          view = factory.inflate(R.layout.win_items_bg_layout, null);
          giftListLayout = (LinearLayout) view.findViewById(R.id.giftListLayout);
          for (int i = 0; i < receivedReward.getGifts().size(); i++) {
            LinearLayout fLayout = new LinearLayout(SlotMachineActivity.this);
            fLayout.setLayoutParams(
                new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.FILL_PARENT, 1f));
            RelativeLayout rel = new RelativeLayout(SlotMachineActivity.this);
            RelativeLayout.LayoutParams rlp =
                new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            rel.setBackgroundResource(R.drawable.gift_bordert);
            rel.setLayoutParams(rlp);
            ImageView icon = new ImageView(SlotMachineActivity.this);
            icon.setImageResource(receivedReward.getGifts().get(i).getSrc());
            icon.setId(i);
            ImageView cardbg = new ImageView(SlotMachineActivity.this);
            cardbg.setImageResource(R.drawable.card_bg2x);
            rlp.addRule(RelativeLayout.BELOW, i);
            rlp.addRule(RelativeLayout.CENTER_HORIZONTAL);
            rlp.addRule(RelativeLayout.CENTER_VERTICAL);
            TextView cardNo = new TextView(SlotMachineActivity.this);
            cardNo.setTextColor(Color.BLUE);
            cardNo.setText(receivedReward.getGifts().get(i).getValue() + "");
            cardbg.setLayoutParams(rlp);
            cardNo.setLayoutParams(rlp);
            rlp =
                new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            rlp.addRule(RelativeLayout.CENTER_HORIZONTAL);
            rlp.addRule(RelativeLayout.CENTER_VERTICAL);
            icon.setLayoutParams(rlp);
            rel.addView(icon);
            if (receivedReward.getGifts().get(i).getType().contains("card")) {
              rel.addView(cardbg);
              rel.addView(cardNo);
            }
            TextView giftDescription = new TextView(SlotMachineActivity.this);
            if (receivedReward.getGifts().get(i).getType().equalsIgnoreCase("apple_giftcard")
                || receivedReward.getGifts().get(i).getType().equalsIgnoreCase("google_giftcard")
                || receivedReward.getGifts().get(i).getType().equalsIgnoreCase("viettel_phonecard")
                || receivedReward
                    .getGifts()
                    .get(i)
                    .getType()
                    .equalsIgnoreCase("vinaphone_phonecard")
                || receivedReward
                    .getGifts()
                    .get(i)
                    .getType()
                    .equalsIgnoreCase("mobifone_phonecard")) {
              giftDescription.setText(
                  receivedReward.getGifts().get(i).getType().replace('_', ' ')
                      + " : "
                      + receivedReward.getValue()
                      + ".");
            } else {
              giftDescription.setText(
                  receivedReward.getGifts().get(i).getValue()
                      + " "
                      + receivedReward.getGifts().get(i).getType().replace('_', ' '));
            }

            LinearLayout.LayoutParams linear =
                new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            giftDescription.setLayoutParams(linear);
            fLayout.setOrientation(LinearLayout.VERTICAL);
            fLayout.setGravity(Gravity.CENTER_HORIZONTAL);
            fLayout.addView(rel);
            fLayout.addView(giftDescription);
            giftListLayout.addView(fLayout);
          }
        }

        TextView giftDescription = (TextView) view.findViewById(R.id.giftDescription);

        Button continue_btn = (Button) view.findViewById(R.id.continueBtn);
        continue_btn.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                // TODO Auto-generated method stub
                dialog.dismiss();
                Log.e("SlotMachineActivity", "onClick-Continue Btn");
                Intent i = new Intent();
                if (spinned) {
                  i.putExtra("is_used_free_spin", receive_free_ticket);
                  if (receivedReward != null) {
                    i.putExtra("new_purple_tym", receivedReward.getNew_purple_tym());
                    i.putExtra("new_green_tym", receivedReward.getNew_green_tym());
                    i.putExtra("new_yellow_tym", receivedReward.getNew_yellow_tym());
                  }
                } else {
                  i.putExtra("is_used_free_spin", false);
                }
                setResult(RESULT_OK, i);
                Log.e("receive_free_ticket", receive_free_ticket + "");
                finish();
              }
            });
        Button shareBtn = (Button) view.findViewById(R.id.sharebtn);
        shareBtn.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                // TODO Auto-generated method stub
                progressDialog.setMessage(getResources().getString(R.string.sharing_on_facebook));
                progressDialog.show();
                final ArrayList<String> permis = new ArrayList<String>();
                final JSONObject pram = new JSONObject();
                try {
                  //							if(receivedReward.getGifts().size()>0)
                  //							{
                  //								String allGifts=receivedReward.getDescription()+"(";
                  //								for(int i=0;i<receivedReward.getGifts().size();i++)
                  //								{
                  //
                  //	if(receivedReward.getGifts().get(i).getType().equalsIgnoreCase("apple_giftcard")||receivedReward.getGifts().get(i).getType().equalsIgnoreCase("google_giftcard")||receivedReward.getGifts().get(i).getType().equalsIgnoreCase("viettel_phonecard")||receivedReward.getGifts().get(i).getType().equalsIgnoreCase("vinaphone_phonecard")||receivedReward.getGifts().get(i).getType().equalsIgnoreCase("mobifone_phonecard"))
                  //									{
                  //										allGifts+=receivedReward.getGifts()
                  //												.get(i).getType().replace('_', ' ')+" : "+receivedReward.getValue()
                  // +".";
                  //									}else
                  //									{
                  //										allGifts+=receivedReward.getGifts()
                  //												.get(i).getValue() +" "+ receivedReward.getGifts()
                  //												.get(i).getType().replace('_', ' ');
                  //									}
                  //								}
                  //								allGifts+=")";
                  //								pram.put("message", allGifts);
                  //							}else
                  //							{
                  //								pram.put("message", receivedReward.getDescription());
                  //							}
                  pram.put("message", receivedReward.getDescription());
                  pram.put(
                      "link", "https://play.google.com/store/apps/details?id=com.appstoregp.vn");
                } catch (JSONException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }

                permis.add("publish_actions");
                permis.add("publish_stream");
                if (Session.getActiveSession() == null || Session.getActiveSession().isClosed()) {
                  Log.e(
                      "openActiveSession because it is null or is closed",
                      "openActiveSession because it is null or is closed");
                  Session.openActiveSession(
                      SlotMachineActivity.this,
                      true,
                      new Session.StatusCallback() {

                        @Override
                        public void call(Session session, SessionState state, Exception exception) {
                          // TODO Auto-generated method stub
                          if (exception == null) {
                            if (!session.getPermissions().contains("publish_actions")
                                || !session.getPermissions().contains("publish_stream")) {
                              try {
                                session.requestNewPublishPermissions(
                                    new Session.NewPermissionsRequest(
                                        SlotMachineActivity.this, permis));
                                Log.e("REQUESTPUBLISHpermission", "REQUESTPUBLISHpermission");
                                Toast.makeText(
                                        SlotMachineActivity.this,
                                        getResources()
                                            .getString(R.string.getting_permission_at_first),
                                        Toast.LENGTH_LONG)
                                    .show();
                              } catch (Exception e) {
                                // TODO: handle exception
                                e.printStackTrace();
                              }
                              Log.e("REQUESTPUBLISHpermission2", "REQUESTPUBLISHpermission2");
                              return;
                            }
                            Request a =
                                Request.newPostRequest(
                                    Session.getActiveSession(),
                                    "/me/feed",
                                    GraphObject.Factory.create(pram),
                                    new Request.Callback() {
                                      @Override
                                      public void onCompleted(Response response) {
                                        showPublishOnWallResult(
                                            response.getGraphObject(), response.getError());
                                      }
                                    });
                            a.executeAsync();
                          }
                        }
                      });

                } else {
                  //				        	session.requestNewPublishPermissions(new
                  // Session.NewPermissionsRequest(
                  //									SlotMachineActivity.this, permis));
                  Request a =
                      Request.newPostRequest(
                          Session.getActiveSession(),
                          "/me/feed",
                          GraphObject.Factory.create(pram),
                          new Request.Callback() {
                            @Override
                            public void onCompleted(Response response) {
                              showPublishOnWallResult(
                                  response.getGraphObject(), response.getError());
                            }
                          });
                  a.executeAsync();
                }
              }
            });
        if (receivedReward.getGifts().size() == 0
            && !receivedReward.getType().contains("card")
            && !receivedReward.getType().equalsIgnoreCase("OOS")) {
          String tym_type = "";
          if (receivedReward.getType().replace('_', ' ').contains("purple")) {
            tym_type = getResources().getString(R.string.tym_purple);
          } else if (receivedReward.getType().replace('_', ' ').contains("green")) {
            tym_type = getResources().getString(R.string.tym_purple);
          } else if (receivedReward.getType().replace('_', ' ').contains("yellow")) {
            tym_type = getResources().getString(R.string.tym_yellow);
          }
          giftDescription.setText(receivedReward.getValue() + " " + tym_type);
        } else if (receivedReward.getGifts().size() == 0
            && receivedReward.getType().contains("card")) {

          giftDescription.setText(
              receivedReward.getDescription() + " " + receivedReward.getValue());
        } else if (receivedReward.getType().equalsIgnoreCase("OOS")) {
          giftDescription.setText(getResources().getString(R.string.oos));
          RelativeLayout forOOS = (RelativeLayout) view.findViewById(R.id.forOOS);
          forOOS.setVisibility(View.GONE);
          shareBtn.setEnabled(false);
        }
        //				view.setBackgroundColor(android.graphics.Color.TRANSPARENT);
        winDialog.setView(view);
        dialog = winDialog.create();
        //				dialog.getWindow().setBackgroundDrawable(new
        // ColorDrawable(android.graphics.Color.TRANSPARENT));
        dialog.setCancelable(false);
        dialog.show();
      } else {
        AlertDialog.Builder info = new AlertDialog.Builder(SlotMachineActivity.this);
        info.setTitle(getResources().getString(R.string.message_title_dialog));
        info.setMessage(getResources().getString(R.string.message_not_win));
        info.setPositiveButton(
            getResources().getString(R.string.ok),
            new DialogInterface.OnClickListener() {

              @Override
              public void onClick(DialogInterface arg0, int arg1) {}
            });
        info.show();
      }
    }
    if (!_onPause) {
      soundPool.play(soundEndOfSpinning, 0.99f, 0.99f, 0, 0, 1);
    }
  }
예제 #27
0
  protected void onCreateContent(LinearLayout parent) {
    SizeHelper.prepare(context);

    LinearLayout rlCountry = new LinearLayout(context);
    LinearLayout.LayoutParams params =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, SizeHelper.fromPxWidth(96));
    params.setMargins(
        SizeHelper.fromPx(26), SizeHelper.fromPxWidth(32), SizeHelper.fromPxWidth(26), 0);
    rlCountry.setLayoutParams(params);
    rlCountry.setId(Res.id.rl_country);

    TextView tv = new TextView(context);
    LinearLayout.LayoutParams tvParams =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    tvParams.gravity = Gravity.CENTER_VERTICAL;
    tv.setLayoutParams(tvParams);
    tv.setPadding(SizeHelper.fromPxWidth(14), 0, SizeHelper.fromPxWidth(14), 0);
    int resid = R.getStringRes(context, "smssdk_country");
    tv.setText(resid);
    tv.setTextColor(0xff000000);
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25));
    rlCountry.addView(tv);

    TextView tvCountry = new TextView(context);
    tvCountry.setId(Res.id.tv_country);
    LinearLayout.LayoutParams tvCountryParams =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    tvCountryParams.gravity = Gravity.CENTER_VERTICAL;
    tvCountryParams.weight = 1;
    tvCountryParams.rightMargin = SizeHelper.fromPxWidth(14);
    tvCountry.setLayoutParams(tvCountryParams);
    tvCountry.setGravity(Gravity.RIGHT);
    tvCountry.setPadding(SizeHelper.fromPxWidth(14), 0, SizeHelper.fromPxWidth(14), 0);
    tvCountry.setTextColor(0xff45c01a);
    tvCountry.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25));
    rlCountry.addView(tvCountry);

    parent.addView(rlCountry);

    View line = new View(context);
    LinearLayout.LayoutParams lineParams =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, SizeHelper.fromPxWidth(1));
    lineParams.leftMargin = SizeHelper.fromPxWidth(26);
    lineParams.rightMargin = SizeHelper.fromPxWidth(26);
    line.setLayoutParams(lineParams);
    line.setBackgroundColor(Res.color.smssdk_gray_press);
    parent.addView(line);

    LinearLayout phoneLayout = new LinearLayout(context);
    LinearLayout.LayoutParams phoneParams =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, SizeHelper.fromPxWidth(70));
    phoneParams.setMargins(
        SizeHelper.fromPxWidth(26), SizeHelper.fromPxWidth(30), SizeHelper.fromPxWidth(26), 0);
    phoneLayout.setLayoutParams(phoneParams);

    TextView countryNum = new TextView(context);
    countryNum.setId(Res.id.tv_country_num);
    LinearLayout.LayoutParams countryNumParams =
        new LinearLayout.LayoutParams(
            SizeHelper.fromPxWidth(104), LinearLayout.LayoutParams.MATCH_PARENT);
    countryNum.setLayoutParams(countryNumParams);
    countryNum.setGravity(Gravity.CENTER);
    countryNum.setTextColor(0xff353535);
    countryNum.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25));
    resid = R.getBitmapRes(context, "smssdk_input_bg_focus");
    countryNum.setBackgroundResource(resid);
    phoneLayout.addView(countryNum);

    LinearLayout wrapperLayout = new LinearLayout(context);
    LinearLayout.LayoutParams wrapperParams =
        new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT);
    wrapperParams.weight = 1;
    wrapperLayout.setLayoutParams(wrapperParams);
    resid = R.getBitmapRes(context, "smssdk_input_bg_special_focus");
    wrapperLayout.setBackgroundResource(resid);

    EditText writePhone = new EditText(context);
    writePhone.setId(Res.id.et_write_phone);
    LinearLayout.LayoutParams writePhoneParams =
        new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT);
    writePhoneParams.gravity = Gravity.CENTER_VERTICAL;
    writePhoneParams.setMargins(SizeHelper.fromPxWidth(10), 0, SizeHelper.fromPxWidth(10), 0);
    writePhoneParams.weight = 1;
    writePhone.setLayoutParams(writePhoneParams);
    writePhone.setBackgroundDrawable(null);
    resid = R.getStringRes(context, "smssdk_write_mobile_phone");
    writePhone.setHint(resid);
    writePhone.setInputType(InputType.TYPE_CLASS_PHONE);
    writePhone.setTextColor(0xff353535);
    writePhone.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25));
    wrapperLayout.addView(writePhone);

    ImageView image = new ImageView(context);
    image.setId(Res.id.iv_clear);
    LinearLayout.LayoutParams imageParams =
        new LinearLayout.LayoutParams(SizeHelper.fromPxWidth(24), SizeHelper.fromPxWidth(24));
    imageParams.gravity = Gravity.CENTER_VERTICAL;
    imageParams.rightMargin = SizeHelper.fromPxWidth(20);
    image.setLayoutParams(imageParams);
    resid = R.getBitmapRes(context, "smssdk_clear_search");
    image.setBackgroundResource(resid);
    image.setScaleType(ScaleType.CENTER_INSIDE);
    image.setVisibility(View.GONE);
    wrapperLayout.addView(image);
    phoneLayout.addView(wrapperLayout);
    parent.addView(phoneLayout);

    Button nextBtn = new Button(context);
    nextBtn.setId(Res.id.btn_next);
    LinearLayout.LayoutParams nextParams =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, SizeHelper.fromPxWidth(72));
    nextParams.setMargins(
        SizeHelper.fromPxWidth(26), SizeHelper.fromPxWidth(36), SizeHelper.fromPxWidth(26), 0);
    nextBtn.setLayoutParams(nextParams);
    resid = R.getBitmapRes(context, "smssdk_btn_disenable");
    nextBtn.setBackgroundResource(resid);
    resid = R.getStringRes(context, "smssdk_next");
    nextBtn.setText(resid);
    nextBtn.setTextColor(0xffffffff);
    nextBtn.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25));
    nextBtn.setPadding(0, 0, 0, 0);
    parent.addView(nextBtn);
  }
예제 #28
0
  public void getreportinbox() {
    int i = 0;

    TableRow tr1 = new TableRow(this);
    tr1.setId(100 + i);
    tr1.layout(2, 0, 0, 0);

    // Create a TextView to house the name of the province
    final TextView label2 = new TextView(this);

    label2.setId(300 + i);
    label2.setText("     ");
    label2.setTextColor(Color.BLACK);
    label2.setPadding(20, 0, 0, 0);
    tr1.setPadding(0, 1, 0, 1);
    tr1.addView(label2);

    // Create a TextView to house the name of the province
    final TextView labeltitle2 = new TextView(this);

    labeltitle2.setId(300 + i);
    labeltitle2.setText("Status  ");
    labeltitle2.setTextColor(Color.BLACK);
    labeltitle2.setPadding(20, 0, 0, 0);
    tr1.setPadding(0, 1, 0, 1);

    tr1.addView(labeltitle2);

    // Create a TextView to house the value of the after-tax income
    final TextView labelrec2 = new TextView(this);

    labelrec2.setId(400 + i);
    labelrec2.setText("Subject");
    labelrec2.setTextColor(Color.BLACK);
    labelrec2.setPadding(20, 0, 0, 0);
    tr1.setPadding(0, 1, 0, 1);

    tr1.addView(labelrec2);

    // Create a TextView to house the name of the province
    final TextView labelsend2 = new TextView(this);

    labelsend2.setId(500 + i);
    labelsend2.setText("From");
    labelsend2.setTextColor(Color.BLACK);
    labelsend2.setPadding(20, 0, 0, 0);
    tr1.setPadding(0, 1, 0, 1);

    tr1.addView(labelsend2);

    // Create a TextView to house the value of the after-tax income
    final TextView labeldt2 = new TextView(this);

    labeldt2.setId(600 + i);
    labeldt2.setText("Date");
    labeldt2.setTextColor(Color.BLACK);
    labeldt2.setPadding(20, 0, 0, 0);
    tr1.setPadding(0, 1, 0, 1);

    tr1.addView(labeldt2);

    // Add the TableRow to the TableLayout
    tbl2.addView(
        tr1, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    for (int i1 = 0; i1 < rec1.length; i1++) {

      try {
        TableRow tr = new TableRow(this);
        tr.setId(100 + i);
        tr.layout(2, 0, 0, 0);

        // Create a TextView to house the name of the province
        CheckBox chk = new CheckBox(this);
        ;

        chk.setId(200 + i);
        chk.setText("");
        chk.setPadding(20, 0, 0, 0);
        tr.setPadding(0, 1, 0, 1);

        tr.addView(chk);

        // Create a TextView to house the name of the province
        ImageView imageviewed = new ImageView(this);

        imageviewed.setId(200 + i);
        if (viewed1[i1].equals("0")) {
          imageviewed.setImageResource(R.drawable.mail);
        } else {
          imageviewed.setImageResource(R.drawable.chkmail);
        }
        imageviewed.setPadding(20, 0, 0, 0);
        tr.setPadding(0, 1, 0, 1);

        tr.addView(imageviewed);

        // Create a TextView to house the name of the province
        final TextView labeltitle = new TextView(this);

        labeltitle.setId(300 + i);
        labeltitle.setText(title1[i1]);
        labeltitle.setTextColor(Color.BLACK);
        labeltitle.setPadding(20, 0, 0, 0);
        tr.setPadding(0, 1, 0, 1);

        tr.addView(labeltitle);

        // Create a TextView to house the name of the province
        final TextView labelsend = new TextView(this);

        labelsend.setId(500 + i);
        labelsend.setText(send1[i1]);
        labelsend.setTextColor(Color.BLACK);
        labelsend.setPadding(20, 0, 0, 0);
        tr.setPadding(0, 1, 0, 1);

        tr.addView(labelsend);

        /*// Create a TextView to house the value of the after-tax income
        final TextView labelrec = new TextView(this);




        labelrec.setId(400+i);
        labelrec.setText(""+rec1[i1]);
        labelrec.setTextColor(Color.BLACK);

        tr.addView(labelrec);*/

        int date1 = Integer.parseInt(dt1[i1]);

        Date date = new Date(date1 * 1000L);

        SimpleDateFormat postFormater = new SimpleDateFormat("dd-MM-yyyy");

        String newDateStr = postFormater.format(date);

        // Create a TextView to house the value of the after-tax income
        final TextView labeldt = new TextView(this);

        labeldt.setId(600 + i);
        labeldt.setText("" + newDateStr);
        labeldt.setTextColor(Color.BLACK);
        labeldt.setPadding(20, 0, 0, 0);
        tr.setPadding(0, 1, 0, 1);

        tr.addView(labeldt);

        final TextView labelbody = new TextView(this);

        labelbody.setId(700 + i);
        labelbody.setText("" + body1[i1]);
        labelbody.setTextColor(Color.BLACK);
        labelbody.setVisibility(View.GONE);
        labelbody.setPadding(20, 0, 0, 0);
        tr.setPadding(0, 1, 0, 1);

        tr.addView(labelbody);

        // Add the TableRow to the TableLayout
        tbl2.addView(
            tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        i++;

        labeltitle.setOnClickListener(
            new TextView.OnClickListener() {

              public void onClick(View v) {

                System.out.println("Hi Clicked");
                myDialog1 = new Dialog(mailbox.this);
                myDialog1.setContentView(R.layout.showmail);
                myDialog1.setTitle("Inbox");
                myDialog1.setCancelable(true);

                TextView from = (TextView) myDialog1.findViewById(R.id.txtfrom);
                TextView date = (TextView) myDialog1.findViewById(R.id.txtdate);
                TextView to = (TextView) myDialog1.findViewById(R.id.txtto);
                TextView title = (TextView) myDialog1.findViewById(R.id.txttitle);
                EditText body = (EditText) myDialog1.findViewById(R.id.editto);
                Button button = (Button) myDialog1.findViewById(R.id.btnback);

                // String rec1=labelrec.getText().toString();

                String date1 = labeldt.getText().toString();

                String send1 = labelsend.getText().toString();

                String title1 = labeltitle.getText().toString();

                String body1 = labelbody.getText().toString();

                from.setText(send1);
                date.setText(date1);
                // to.setText(rec1);
                title.setText(title1);
                body.setText(body1);
                button.setText("Back To Inbox");

                button.setOnClickListener(
                    new OnClickListener() {
                      public void onClick(View v) {
                        myDialog1.dismiss();
                      }
                    });

                myDialog1.show();
              }
            });
      } catch (Exception e) {
        tv.setText(e.getMessage());
      }
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_friend_in_game);
    toolbar = (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(toolbar);

    // start media
    if (mediaPlayer == null) {
      mediaPlayer = MediaPlayer.create(this, R.raw.carefree);
      mediaPlayer.isLooping();
      mediaPlayer.start();
    }

    levelNumberString = getIntent().getExtras().getString("LevelNumber");
    setTitle(levelNumberString);
    String numberString = levelNumberString.substring(levelNumberString.length() - 1);
    levelNumberInt = Integer.parseInt(numberString);

    /** setup the map */
    boardHoles();

    int blocksize = blockSize(levelWidth);

    LinearLayout llHorizontal = (LinearLayout) findViewById(R.id.linearlayout_main);
    llHorizontal.setBackgroundColor(R.color.bgBlue);
    for (int c = 1; c < levelWidth + 1; c++) {
      LinearLayout llVertical = new LinearLayout(this);
      llVertical.setOrientation(LinearLayout.VERTICAL);

      // add 5 blocks
      for (int r = 1; r < levelLength + 1; r++) {
        if (!arrayD.contains(r * 10 + c)) {

          ImageView ib = new ImageView(this);
          Bitmap b =
              decodeSampledBitmapFromResource(
                  getResources(), R.drawable.empty_block, blocksize, blocksize);
          BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), b);
          ib.setImageDrawable(bitmapDrawable);

          // set border
          final int sdk = android.os.Build.VERSION.SDK_INT;
          if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            ib.setBackgroundDrawable(getResources().getDrawable(R.drawable.border));
          } else {
            ib.setBackground(getResources().getDrawable(R.drawable.border));
          }
          int id = r * 10 + c;
          ib.setOnClickListener(onClickListener);
          ib.setId(id);
          llVertical.addView(ib);
          blockNumbers++;
        } else {
          ImageView ib = new ImageView(this);
          Bitmap b =
              decodeSampledBitmapFromResource(
                  getResources(), R.drawable.block_black, blocksize, blocksize);
          BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), b);
          ib.setImageDrawable(bitmapDrawable);
          // set border
          final int sdk = android.os.Build.VERSION.SDK_INT;
          if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            ib.setBackgroundDrawable(getResources().getDrawable(R.drawable.border));
          } else {
            ib.setBackground(getResources().getDrawable(R.drawable.border));
          }
          int id = 1000 + r * 10 + c;
          ib.setId(id);
          llVertical.addView(ib);
          blockNumbers++;
        }
      }

      llHorizontal.addView(llVertical);

      // turn
      TextView tv = (TextView) findViewById(R.id.playerAB);
      if (turn == 0) {
        tv.setText("Orange");
        tv.setTextColor(Color.parseColor("#ff9000"));
      }
    }
  }
  /** Display the custom ad. */
  public void displayCustom() {
    AdFlakeLayout adFlakeLayout = _adFlakeLayoutReference.get();
    if (adFlakeLayout == null) {
      return;
    }

    Activity activity = adFlakeLayout.activityReference.get();
    if (activity == null) {
      return;
    }

    // This may be incorrect and need to be adjusted for density.
    double density = AdFlakeUtil.getDensity(activity);
    double px320 = AdFlakeUtil.convertToScreenPixels(320, density);
    double px50 = AdFlakeUtil.convertToScreenPixels(50, density);

    // NOTE: FILL_PARENT (renamed MATCH_PARENT in API Level 8 and
    // higher),
    // which means that the view wants to be as big as its parent
    // (minus padding)
    @SuppressWarnings("deprecation")
    final int layoutTypeFillParent = android.view.ViewGroup.LayoutParams.FILL_PARENT;

    switch (adFlakeLayout.currentCustom.type) {
      case AdFlakeUtil.CUSTOM_TYPE_BANNER:
        Log.d(AdFlakeUtil.ADFLAKE, "Serving custom type: banner");

        if (adFlakeLayout.currentCustom.image == null) {
          adFlakeLayout.rotateThreadedNow();
          return;
        }

        RelativeLayout bannerView = new RelativeLayout(activity);
        bannerView.setLayoutParams(new LayoutParams((int) px320, (int) px50));

        ImageView bannerImageView = new ImageView(activity);
        bannerImageView.setImageDrawable(adFlakeLayout.currentCustom.image);

        RelativeLayout.LayoutParams viewParams =
            new RelativeLayout.LayoutParams(layoutTypeFillParent, layoutTypeFillParent);
        bannerView.addView(bannerImageView, viewParams);

        adFlakeLayout.pushSubView(bannerView);
        break;

      case AdFlakeUtil.CUSTOM_TYPE_ICON:
        Log.d(AdFlakeUtil.ADFLAKE, "Serving custom type: icon");
        RelativeLayout iconView = new RelativeLayout(activity);
        if (adFlakeLayout.currentCustom.image == null) {
          adFlakeLayout.rotateThreadedNow();
          return;
        }

        double px4 = AdFlakeUtil.convertToScreenPixels(4, density);
        double px6 = AdFlakeUtil.convertToScreenPixels(6, density);

        // This may be incorrect and need to be adjusted for density.
        iconView.setLayoutParams(new LayoutParams((int) px320, (int) px50));

        int gradientBottomColor =
            Color.rgb(
                adFlakeLayout.extra.bgRed, adFlakeLayout.extra.bgGreen, adFlakeLayout.extra.bgBlue);
        int gradientTopColor = Color.WHITE;

        ImageView blendView = new ImageView(activity);
        GradientDrawable blend =
            new GradientDrawable(
                Orientation.TOP_BOTTOM,
                new int[] {
                  gradientTopColor, gradientBottomColor, gradientBottomColor, gradientBottomColor
                });

        // NOTE: This method was deprecated in API level 16. Use
        // setBackground(Drawable) instead
        try {
          // blendView.setBackgroundDrawable(blend);
          blendView
              .getClass()
              .getMethod(
                  android.os.Build.VERSION.SDK_INT >= 16
                      ? "setBackground"
                      : "setBackgroundDrawable",
                  Drawable.class)
              .invoke(blendView, blend);
        } catch (Exception ex) {
          // do nothing
        }
        RelativeLayout.LayoutParams blendViewParams =
            new RelativeLayout.LayoutParams(layoutTypeFillParent, layoutTypeFillParent);
        iconView.addView(blendView, blendViewParams);

        ImageView iconImageView = new ImageView(activity);
        iconImageView.setImageDrawable(adFlakeLayout.currentCustom.image);
        iconImageView.setId(10);
        iconImageView.setPadding((int) px4, 0, (int) px6, 0);
        iconImageView.setScaleType(ScaleType.CENTER);

        RelativeLayout.LayoutParams iconViewParams =
            new RelativeLayout.LayoutParams(
                android.view.ViewGroup.LayoutParams.WRAP_CONTENT, layoutTypeFillParent);
        iconView.addView(iconImageView, iconViewParams);

        ImageView frameImageView = new ImageView(activity);
        InputStream drawableStream =
            getClass().getResourceAsStream("/com/adflake/assets/ad_frame.gif");

        Drawable adFrameDrawable = new BitmapDrawable(activity.getResources(), drawableStream);
        frameImageView.setImageDrawable(adFrameDrawable);
        frameImageView.setPadding((int) px4, 0, (int) px6, 0);
        frameImageView.setScaleType(ScaleType.CENTER);

        RelativeLayout.LayoutParams frameViewParams =
            new RelativeLayout.LayoutParams(
                android.view.ViewGroup.LayoutParams.WRAP_CONTENT, layoutTypeFillParent);
        iconView.addView(frameImageView, frameViewParams);
        TextView iconTextView = new TextView(activity);
        iconTextView.setText(adFlakeLayout.currentCustom.description);
        iconTextView.setTypeface(Typeface.DEFAULT_BOLD, 1);
        iconTextView.setTextColor(
            Color.rgb(
                adFlakeLayout.extra.fgRed,
                adFlakeLayout.extra.fgGreen,
                adFlakeLayout.extra.fgBlue));

        RelativeLayout.LayoutParams textViewParams =
            new RelativeLayout.LayoutParams(layoutTypeFillParent, layoutTypeFillParent);
        textViewParams.addRule(RelativeLayout.RIGHT_OF, iconImageView.getId());
        textViewParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        textViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        textViewParams.addRule(RelativeLayout.CENTER_VERTICAL);
        textViewParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        iconTextView.setGravity(Gravity.CENTER_VERTICAL);
        iconView.addView(iconTextView, textViewParams);
        adFlakeLayout.pushSubView(iconView);
        break;

      default:
        Log.w(AdFlakeUtil.ADFLAKE, "Unknown custom type!");
        adFlakeLayout.rotateThreadedNow();
        return;
    }

    adFlakeLayout.adFlakeManager.resetRollover();
    adFlakeLayout.rotateThreadedDelayed();
  }