Java Code Examples for android.widget.ImageView#setAdjustViewBounds()

The following examples show how to use android.widget.ImageView#setAdjustViewBounds() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: ucar-weex-core   File: WXEmbed.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onException(NestedContainer container, String errCode, String msg) {
  if (TextUtils.equals(errCode, WXRenderErrorCode.WX_NETWORK_ERROR) && container instanceof WXEmbed) {
    final WXEmbed comp = ((WXEmbed)container);
    final ImageView imageView = new ImageView(comp.getContext());
    imageView.setImageResource(R.drawable.error);
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ERROR_IMG_WIDTH, ERROR_IMG_HEIGHT);
    layoutParams.gravity = Gravity.CENTER;
    imageView.setLayoutParams(layoutParams);
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    imageView.setAdjustViewBounds(true);
    imageView.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        imageView.setOnClickListener(null);
        imageView.setEnabled(false);
        comp.loadContent();
      }
    });
    FrameLayout hostView = comp.getHostView();
    hostView.removeAllViews();
    hostView.addView(imageView);
    WXLogUtils.e("WXEmbed", "NetWork failure :" + errCode + ",\n error message :" + msg);
  }
}
 
Example 2
public ButtonFloat(Context context, AttributeSet attrs) {
	super(context, attrs);
	setBackgroundResource(R.drawable.background_button_float);
	setBackgroundColor(backgroundColor);
	sizeRadius = 28;
	setDefaultProperties();
	icon = new ImageView(context);
	icon.setAdjustViewBounds(true);
	icon.setScaleType(ScaleType.CENTER_CROP);
	if(drawableIcon != null) {
		icon.setImageDrawable(drawableIcon);
	}
	LayoutParams params = new LayoutParams(Utils.dpToPx(sizeIcon, getResources()),Utils.dpToPx(sizeIcon, getResources()));
	params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
	icon.setLayoutParams(params);
	addView(icon);		
	
}
 
Example 3
Source Project: cannonball-android   File: ImageAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object instantiateItem(ViewGroup container, final int position) {
    if (context.get() != null) {
        final int drawableId = theme.getImageList().get(position + 1);
        final ImageView view = new ImageView(context.get());
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        view.setContentDescription(context.get().getResources().getString(R.string
                .content_desc_poempic));
        view.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view.setAdjustViewBounds(true);
        view.setTag(drawableId);
        container.addView(view, 0);
        view.post(new Runnable() {
            @Override
            public void run() {
                ImageLoader.getImageLoader().load(drawableId, view);
            }
        });
        return view;
    }
    return null;
}
 
Example 4
Source Project: openlauncher   File: ShareUtil.java    License: Apache License 2.0 6 votes vote down vote up
public void showMountSdDialog(@StringRes final int title, @StringRes final int description, @DrawableRes final int mountDescriptionGraphic, final Activity... activityOrNull) {
    Activity activity = greedyGetActivity(activityOrNull);
    if (activity == null) {
        return;
    }

    // Image viewer
    ImageView imv = new ImageView(activity);
    imv.setImageResource(mountDescriptionGraphic);
    imv.setAdjustViewBounds(true);

    AlertDialog.Builder dialog = new AlertDialog.Builder(activity);
    dialog.setView(imv);
    dialog.setTitle(title);
    dialog.setMessage(_context.getString(description) + "\n\n");
    dialog.setNegativeButton(android.R.string.cancel, null);
    dialog.setPositiveButton(android.R.string.yes, (dialogInterface, i) -> requestStorageAccessFramework(activity));
    AlertDialog dialogi = dialog.create();
    dialogi.show();
}
 
Example 5
Source Project: android   File: TutorialActivity.java    License: MIT License 6 votes vote down vote up
/**
 * The last fragment is transparent to enable the swipe-to-finish behaviour seen on
 * Google's apps. So our viewpager circle indicator needs to show NUM_PAGES - 1
 * Source: https://gist.github.com/fiskurgit
 */
private void buildCircles(ViewGroup parent) {

    final float scale = getResources().getDisplayMetrics().density;
    final int padding = (int) (5 * scale + 0.5f);

    for (int i = 0; i < NUM_PAGES; i++) {
        ImageView circle = new ImageView(this);
        circle.setImageResource(R.drawable.circle);
        circle.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        circle.setAdjustViewBounds(true);
        circle.setPadding(padding, 0, padding, 0);
        parent.addView(circle);
    }

    setIndicator(0);
}
 
Example 6
Source Project: Cardboard   File: CardboardOverlayView.java    License: Apache License 2.0 5 votes vote down vote up
public CardboardOverlayEyeView(Context context, AttributeSet attrs) {
    super(context, attrs);
    imageView = new ImageView(context, attrs);
    imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    imageView.setAdjustViewBounds(true);  // Preserve aspect ratio.
    addView(imageView);

    textView = new TextView(context, attrs);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14.0f);
    textView.setTypeface(textView.getTypeface(), Typeface.BOLD);
    textView.setGravity(Gravity.CENTER);
    textView.setShadowLayer(3.0f, 0.0f, 0.0f, Color.DKGRAY);
    addView(textView);
}
 
Example 7
Source Project: SuperDialog   File: SuperDialog.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 标题下方,内容文本上方的图片
 */
private void initImageView(ViewGroup viewRoot) {
    imageView = new ImageView(context);
    imageView.setAdjustViewBounds(true);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(dp2px(15), dp2px(5), dp2px(15), dp2px(5));
    imageView.setLayoutParams(layoutParams);
    viewRoot.addView(imageView);
    if (imageListener != null) {
        imageListener.onInitImageView(imageView);
    }
}
 
Example 8
private View createImageView() {
    ImageView imageView = new ImageView(getContext());
    imageView.setPadding(tabPadding, tabPadding, tabPadding, tabPadding);
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    imageView.setAdjustViewBounds(true);
    return imageView;
}
 
Example 9
Source Project: ImageLoader   File: AlbumAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void convert(@NonNull final BaseViewHolder helper, final Album item) {
    helper.getView(R.id.item_iv).setTag(R.id.item_iv,item);
    ImageView imageView = helper.getView(R.id.item_iv);
    imageView.setAdjustViewBounds(false);
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
    params.height = imageView.getContext().getResources().getDisplayMetrics().widthPixels/2;
    imageView.setLayoutParams(params);

    ImageLoader.with(helper.itemView.getContext())
            .file(item.cover)
            .scale(ScaleMode.CENTER_CROP)
            .loading(R.drawable.iv_loading_trans)
            .error(R.drawable.im_item_list_opt_error)
            .into(imageView);
    helper.setText(R.id.tv_info,item.name);
    helper.getConvertView().setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ImageListView listView = new ImageListView(v.getContext());
            ImageMediaCenterUtil.showViewAsDialog(listView);
            listView.showImagesInAlbum(item);
        }
    });





}
 
Example 10
Source Project: glide-support   File: GeneratingAdapter.java    License: The Unlicense 5 votes vote down vote up
@Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
	ImageView view = new ImageView(parent.getContext());
	int height = parent.getContext().getResources().getDisplayMetrics().heightPixels / 3;
	view.setLayoutParams(new RecyclerView.LayoutParams(MATCH_PARENT, height));
	view.setAdjustViewBounds(true);
	view.setScaleType(ImageView.ScaleType.FIT_CENTER);
	return new RecyclerView.ViewHolder(view) {
	};
}
 
Example 11
Source Project: appinventor-extensions   File: ViewUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the image for an ImageView.
 */
public static void setImage(ImageView view, Drawable drawable) {
  view.setImageDrawable(drawable);
  if (drawable != null) {
    view.setAdjustViewBounds(true);
  }
  view.requestLayout();
}
 
Example 12
public FloatingView(@NonNull Context context, @NonNull FloatingTouchCallback callback) {
    super(context);
    this.callback = callback;
    imageView = new ImageView(context);
    imageView.setAdjustViewBounds(true);
    imageView.setContentDescription(getResources().getString(R.string.app_name));
    setupImageView();
    addView(imageView);
    this.setOnTouchListener(this);
}
 
Example 13
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView i = new ImageView(mContext);

    i.setImageResource(mThumbIds[position]);
    i.setAdjustViewBounds(true);
    i.setLayoutParams(new Gallery.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    i.setBackgroundResource(R.drawable.picture_frame);
    return i;
}
 
Example 14
public View getView(int position, View convertView, ViewGroup parent) {
  LinearLayout ll = new LinearLayout(context);
  ll.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.FILL_PARENT,
      LayoutParams.FILL_PARENT));
  ll.setMinimumHeight(50);
  ll.setOrientation(LinearLayout.HORIZONTAL);
  ll.setGravity(Gravity.CENTER_VERTICAL);

  ImageView iv = new ImageView(context);
  iv.setImageResource(attributes.get(position).getIconResId());
  iv.setAdjustViewBounds(true);
  iv.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.WRAP_CONTENT,
      LayoutParams.WRAP_CONTENT));
  if (listView.getCheckedItemPosition() == position) {
    iv.setBackgroundResource(R.drawable.icon_hilight);
  }

  TextView tv = new TextView(context);
  tv.setText(attributes.get(position).getDescriptionShort());
  tv.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.FILL_PARENT,
      LayoutParams.FILL_PARENT));
  tv.setGravity(Gravity.CENTER_VERTICAL);
  tv.setPadding(10, 0, 0, 0);
  tv.setTextSize(14.0f);
  tv.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
  tv.setTextColor(0xFFFFFFFF);
  tv.setMinHeight(46);

  ll.addView(iv);
  ll.addView(tv);

  return ll;
}
 
Example 15
Source Project: BorderMenu   File: IconItem.java    License: Apache License 2.0 5 votes vote down vote up
public IconItem(BorderMenuActivity borderMenuActivity, int id, int idResource) {
	super(borderMenuActivity, id);
	icon = new ImageView(borderMenuActivity);
	setMinimumHeight(Utils.dpToPx(56, getResources()));
	setMinimumWidth(Utils.dpToPx(56, getResources()));
	icon.setAdjustViewBounds(true);
	icon.setScaleType(ScaleType.CENTER_CROP);
	icon.setImageResource(idResource);
	RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(Utils.dpToPx(24, getResources()),Utils.dpToPx(24, getResources()));
	params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
	icon.setLayoutParams(params);
	rippleSpeed = Utils.dpToPx(2, getResources());
	addView(icon);
}
 
Example 16
@Override
public void editItem(final Activity activity, final int position) {

    LayoutInflater inflater = activity.getLayoutInflater();
    View dialogView = inflater.inflate(R.layout.video_dialog_edit_data, null);
    final AlertDialog dialog = new AlertDialog.Builder(activity)
            .setTitle(R.string.info_edit_title)
            .setView(dialogView,
                    activity.getResources().getDimensionPixelSize(R.dimen.spacing_left),
                    activity.getResources().getDimensionPixelSize(R.dimen.spacing_top),
                    activity.getResources().getDimensionPixelSize(R.dimen.spacing_right),
                    activity.getResources().getDimensionPixelSize(R.dimen.spacing_bottom))
            .setPositiveButton(R.string.info_template_ok, null)
            .setNegativeButton(R.string.info_template_cancel, null)
            .create();
    dialog.show();

    final VideoModel data = videoData.get(position);

    final ImageView thumb = (ImageView) dialogView.findViewById(R.id.thumb);
    final EditText title = (EditText) dialogView.findViewById(R.id.video_title);
    final EditText description = (EditText) dialogView.findViewById(R.id.video_description);
    final EditText link = (EditText) dialogView.findViewById(R.id.video_link);

    Picasso.with(mContext)
            .load(data.getThumbnailUrl())
            .transform(new RoundedTransformation(10, 10))
            .fit()
            .centerCrop()
            .into(thumb);

    thumb.setAdjustViewBounds(true);

    title.setText(data.getTitle().trim());
    description.setText(data.getDescription().trim());
    link.setText(data.getLink().trim());

    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (validated(activity, title, description, link)) {

                String titleText = title.getText().toString().trim();
                String descriptionText = description.getText().toString().trim();
                String linkText = link.getText().toString().trim();

                setEmptyView(activity);

                if (linkText.equals(data.getLink())) {
                    data.setTitle(titleText);
                    data.setDescription(descriptionText);
                    adapter.notifyDataSetChanged();

                } else {
                    String convertedLink = convertLink(linkText);

                    if (NetworkUtils.isNetworkAvailable(mContext)) {
                        progress = new ProgressDialog(activity);
                        progress.setCancelable(false);
                        progress.show();
                        new VideoInfoTask().execute(convertedLink, linkText, String.valueOf(position));
                    } else {
                        Toast.makeText(mContext, R.string.network_error, Toast.LENGTH_SHORT).show();
                    }
                }

                dialog.dismiss();
            }

        }
    });
}
 
Example 17
/**
 * 初始化棋盘状态和格子的实例
 */
private void initChildrenViews(Item.OnItemPressedListener onItemPressedListener) {
    BitmapDrawable unselectedDrawable = getUnselectedDrawable();
    BitmapDrawable selectedDrawable = getSelectedDrawable();
    BitmapDrawable occupiedDrawableLeft = getOccupiedDrawableLeft();
    BitmapDrawable occupiedDrawableRight = getOccupiedDrawableRight();
    BitmapDrawable guideDrawable = getGuideDrawable();

    for (int vertical = 0; vertical < mVerticalCount; vertical++) {
        for (int horizontal = 0; horizontal < mHorizontalCount; horizontal++) {
            Item tmp = new Item(getContext());
            tmp.setPadding(mItemPadding, mItemPadding, mItemPadding, mItemPadding);
            tmp.setOnItemPressedListener(onItemPressedListener);
            tmp.setPositions(horizontal, vertical);
            tmp.setUnSelectedBitmap(unselectedDrawable.getBitmap());
            tmp.setSelectedBitmap(selectedDrawable.getBitmap());
            tmp.setOccupiedBitmapLeft(occupiedDrawableLeft.getBitmap());
            tmp.setOccupiedBitmapRight(occupiedDrawableRight.getBitmap());
            tmp.setGuideBitmap(guideDrawable.getBitmap());
            mItems[vertical][horizontal] = tmp;
            addView(tmp);
        }
    }

    mSelectedView = new ImageView(getContext());
    mSelectedView.setAdjustViewBounds(true);

    mSelectedView.setImageResource(R.drawable.anim_drop_left);
    mDropLeftAnimationDrawable = (AnimationDrawable) mSelectedView.getDrawable();

    mSelectedView.setImageResource(R.drawable.anim_drop_right);
    mDropRightAnimationDrawable = (AnimationDrawable) mSelectedView.getDrawable();

    mSelectedView.setImageResource(R.drawable.anim_run_left);
    mGoLeftAnimationDrawable = (AnimationDrawable) mSelectedView.getDrawable();

    mSelectedView.setImageResource(R.drawable.anim_run_right);
    mGoRightAnimationDrawable = (AnimationDrawable) mSelectedView.getDrawable();

    mSelectedView.setVisibility(INVISIBLE);
    LayoutParams lp = new LayoutParams(selectedDrawable.getBitmap().getWidth(), selectedDrawable.getBitmap().getHeight());
    mSelectedView.setLayoutParams(lp);
    mSelectedView.setImageDrawable(selectedDrawable);
    addView(mSelectedView);

    mOccupiedView = new ImageView(getContext());
    mOccupiedView.setAdjustViewBounds(true);
    mOccupiedView.setScaleType(ImageView.ScaleType.FIT_XY);
    LayoutParams lp2 = new LayoutParams(occupiedDrawableLeft.getBitmap().getWidth(), occupiedDrawableLeft.getBitmap().getHeight());
    mOccupiedView.setLayoutParams(lp2);
    mOccupiedView.setVisibility(INVISIBLE);
    addView(mOccupiedView);

    mDropView = new ImageView(getContext());
    mDropView.setAdjustViewBounds(true);
    mDropView.setScaleType(ImageView.ScaleType.FIT_XY);
    float occupiedScale = getOccupiedScale(new BitmapDrawable(getResources(),
            BitmapFactory.decodeResource(getResources(), R.mipmap.ic_unselected)));
    MyLayoutParams lp3 = new MyLayoutParams((int) (mDropLeftAnimationDrawable.getIntrinsicWidth() * occupiedScale),
            (int) (mDropLeftAnimationDrawable.getIntrinsicHeight() * occupiedScale));
    mDropView.setLayoutParams(lp3);
    mDropView.setVisibility(INVISIBLE);
    addView(mDropView);

    mDropTouchView = new View(getContext());
    mDropTouchView.setLayoutParams(lp);
    mDropTouchView.setOnTouchListener(mDropTouchListener);
    addView(mDropTouchView);
}
 
Example 18
Source Project: FakeWeather   File: WeatherChartView.java    License: Apache License 2.0 4 votes vote down vote up
private void letItGo() {
    removeAllViews();
    final LinearLayout dateTitleView = new LinearLayout(getContext());
    dateTitleView.setLayoutParams(rowParams);
    dateTitleView.setOrientation(HORIZONTAL);
    dateTitleView.setLayoutTransition(transition);
    dateTitleView.removeAllViews();

    final LinearLayout iconView = new LinearLayout(getContext());
    iconView.setLayoutParams(rowParams);
    iconView.setOrientation(HORIZONTAL);
    iconView.setLayoutTransition(transition);
    iconView.removeAllViews();

    final LinearLayout weatherStrView = new LinearLayout(getContext());
    weatherStrView.setLayoutParams(rowParams);
    weatherStrView.setOrientation(HORIZONTAL);
    weatherStrView.setLayoutTransition(transition);
    weatherStrView.removeAllViews();

    List<Integer> minTemp = new ArrayList<>();
    List<Integer> maxTemp = new ArrayList<>();
    for (int i = 0; i < dailyForecastList.size(); i++) {
        final TextView tvDate = new TextView(getContext());
        tvDate.setGravity(Gravity.CENTER);
        tvDate.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
        tvDate.setTextColor(getResources().getColor(R.color.colorTextDark));
        tvDate.setVisibility(INVISIBLE);
        final TextView tvWeather = new TextView((getContext()));
        tvWeather.setGravity(Gravity.CENTER);
        tvWeather.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
        tvWeather.setTextColor(getResources().getColor(R.color.colorTextDark));
        tvWeather.setVisibility(INVISIBLE);
        final ImageView ivIcon = new ImageView(getContext());
        ivIcon.setAdjustViewBounds(true);
        ivIcon.setScaleType(ImageView.ScaleType.FIT_CENTER);
        int padding = SizeUtils.dp2px(getContext(), 10);
        int width = SizeUtils.getScreenWidth(getContext()) / dailyForecastList.size();
        LayoutParams ivParam = new LayoutParams(width, width);
        ivParam.weight = 1;
        ivIcon.setLayoutParams(ivParam);
        ivIcon.setPadding(padding, padding, padding, padding);
        ivIcon.setVisibility(INVISIBLE);
        tvDate.setText(dailyForecastList.get(i).getDate());
        tvWeather.setText(dailyForecastList.get(i).getTxt());
        WeatherUtil.getInstance().getWeatherDict(dailyForecastList.get(i).getCode()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SimpleSubscriber<WeatherBean>() {
            @Override
            public void onNext(WeatherBean weatherBean) {
                Glide.with(getContext()).load(weatherBean.getIcon()).diskCacheStrategy(DiskCacheStrategy.ALL).into(ivIcon);
            }
        });
        minTemp.add(Integer.valueOf(dailyForecastList.get(i).getMinTemp()));
        maxTemp.add(Integer.valueOf(dailyForecastList.get(i).getMaxTemp()));
        weatherStrView.addView(tvWeather, cellParams);
        dateTitleView.addView(tvDate, cellParams);
        iconView.addView(ivIcon);
        this.postDelayed(new Runnable() {
            @Override
            public void run() {
                tvDate.setVisibility(VISIBLE);
                tvWeather.setVisibility(VISIBLE);
                ivIcon.setVisibility(VISIBLE);
            }
        }, 200 * i);
    }
    addView(dateTitleView);
    addView(iconView);
    addView(weatherStrView);
    final ChartView chartView = new ChartView(getContext());
    chartView.setData(minTemp, maxTemp);
    chartView.setPadding(0, SizeUtils.dp2px(getContext(), 16), 0, SizeUtils.dp2px(getContext(), 16));
    addView(chartView, chartParams);
}
 
Example 19
Source Project: commcare-android   File: MediaLayout.java    License: Apache License 2.0 4 votes vote down vote up
private View setupImage(String imageURI, String bigImageURI) {
    View mediaPane = null;
    try {
        int[] maxBounds = getMaxCenterViewBounds();
        final String imageFilename = ReferenceManager.instance().DeriveReference(imageURI).getLocalURI();
        final File imageFile = new File(imageFilename);
        if (imageFile.exists()) {
            Bitmap b = MediaUtil.inflateDisplayImage(getContext(), imageURI, maxBounds[0],
                    maxBounds[1]);
            if (b != null) {
                ImageView mImageView = new ImageView(getContext());
                if (useResizingImageView()) {
                    mImageView = new ResizingImageView(getContext(), imageURI, bigImageURI);
                    mImageView.setAdjustViewBounds(true);
                    mImageView.setMaxWidth(maxBounds[0]);
                    mImageView.setMaxHeight(maxBounds[1]);
                } else {
                    mImageView.setScaleType(ImageView.ScaleType.CENTER);
                }
                mImageView.setPadding(10, 10, 10, 10);
                if (imageFilename.toLowerCase().endsWith(IMAGE_GIF_EXTENSION)) {
                    Glide.with(mImageView).asGif()
                            .override(b.getWidth(), b.getHeight())
                            .load(imageFilename)
                            .into(mImageView);
                    b.recycle();
                } else {
                    mImageView.setImageBitmap(b);
                }
                mImageView.setId(IMAGE_VIEW_ID);
                mediaPane = mImageView;
            }
        } else {
            // An error hasn't been logged. We should have an image, but the file doesn't
            // exist.
            mediaPane = getMissingMediaView(imageURI,
                    StringUtils.getStringRobust(getContext(), R.string.video_download_prompt),
                    true);
        }
    } catch (InvalidReferenceException e) {
        Log.e(TAG, "image invalid reference exception");
        e.printStackTrace();
    }
    return mediaPane;
}
 
Example 20
public SignatureWidget(Context context, FormEntryPrompt prompt, PendingCalloutInterface pic) {
    super(context, prompt);

    this.pendingCalloutInterface = pic;

    mInstanceFolder =
            FormEntryInstanceState.mFormRecordPath.substring(0,
                    FormEntryInstanceState.mFormRecordPath.lastIndexOf("/") + 1);

    setOrientation(LinearLayout.VERTICAL);

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

    // setup Blank Image Button
    mSignButton = new Button(getContext());
    WidgetUtils.setupButton(mSignButton,
            StringUtils.getStringSpannableRobust(getContext(), R.string.sign_button),
            mAnswerFontSize,
            !prompt.isReadOnly());

    // launch capture intent on click
    final FormIndex questionIndex = prompt.getIndex();
    mSignButton.setOnClickListener(v -> launchSignatureActivity(questionIndex));


    // 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());
        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 = MediaUtil.getBitmapScaledToContainer(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(v -> launchSignatureActivity(questionIndex));

        addView(mImageView);
    }
}