Example usage for android.widget ImageView getLayoutParams

List of usage examples for android.widget ImageView getLayoutParams

Introduction

In this page you can find the example usage for android.widget ImageView getLayoutParams.

Prototype

@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_")
public ViewGroup.LayoutParams getLayoutParams() 

Source Link

Document

Get the LayoutParams associated with this view.

Usage

From source file:org.telegram.ui.SessionsActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("SessionsTitle", R.string.SessionsTitle));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override// www  .  j  ava 2 s  .  c o  m
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    listAdapter = new ListAdapter(context);

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));

    emptyLayout = new LinearLayout(context);
    emptyLayout.setOrientation(LinearLayout.VERTICAL);
    emptyLayout.setGravity(Gravity.CENTER);
    //emptyLayout.setBackgroundResource(R.drawable.greydivider_bottom);
    emptyLayout.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
            AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight()));

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.devices);
    emptyLayout.addView(imageView);
    LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) imageView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    imageView.setLayoutParams(layoutParams2);

    TextView textView = new TextView(context);
    textView.setTextColor(ContextCompat.getColor(context, R.color.disabled_text) /*0xff8a8a8a*/);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textView.setText(LocaleController.getString("NoOtherSessions", R.string.NoOtherSessions));
    emptyLayout.addView(textView);
    layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
    layoutParams2.topMargin = AndroidUtilities.dp(16);
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.gravity = Gravity.CENTER;
    textView.setLayoutParams(layoutParams2);

    textView = new TextView(context);
    textView.setTextColor(ContextCompat.getColor(context, R.color.disabled_text) /*0xff8a8a8a*/);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
    textView.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0);
    textView.setText(LocaleController.getString("NoOtherSessionsInfo", R.string.NoOtherSessionsInfo));
    emptyLayout.addView(textView);
    layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
    layoutParams2.topMargin = AndroidUtilities.dp(14);
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.gravity = Gravity.CENTER;
    textView.setLayoutParams(layoutParams2);

    FrameLayout progressView = new FrameLayout(context);
    frameLayout.addView(progressView);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    progressView.setLayoutParams(layoutParams);
    progressView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    ProgressBar progressBar = new ProgressBar(context);
    progressView.addView(progressBar);
    layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
    layoutParams.width = LayoutHelper.WRAP_CONTENT;
    layoutParams.height = LayoutHelper.WRAP_CONTENT;
    layoutParams.gravity = Gravity.CENTER;
    progressView.setLayoutParams(layoutParams);

    ListView listView = new ListView(context);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setVerticalScrollBarEnabled(false);
    listView.setDrawSelectorOnTop(true);
    listView.setEmptyView(progressView);
    frameLayout.addView(listView);
    layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.gravity = Gravity.TOP;
    listView.setLayoutParams(layoutParams);
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
            if (i == terminateAllSessionsRow) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setMessage(
                        LocaleController.getString("AreYouSureSessions", R.string.AreYouSureSessions));
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                TLRPC.TL_auth_resetAuthorizations req = new TLRPC.TL_auth_resetAuthorizations();
                                ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                                    @Override
                                    public void run(final TLObject response, final TLRPC.TL_error error) {
                                        AndroidUtilities.runOnUIThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                if (getParentActivity() == null) {
                                                    return;
                                                }
                                                if (error == null && response instanceof TLRPC.TL_boolTrue) {
                                                    Toast toast = Toast.makeText(getParentActivity(),
                                                            LocaleController.getString("TerminateAllSessions",
                                                                    R.string.TerminateAllSessions),
                                                            Toast.LENGTH_SHORT);
                                                    toast.show();
                                                } else {
                                                    Toast toast = Toast
                                                            .makeText(getParentActivity(),
                                                                    LocaleController.getString("UnknownError",
                                                                            R.string.UnknownError),
                                                                    Toast.LENGTH_SHORT);
                                                    toast.show();
                                                }
                                                finishFragment();
                                            }
                                        });
                                        UserConfig.registeredForPush = false;
                                        UserConfig.saveConfig(false);
                                        MessagesController.getInstance().registerForPush(UserConfig.pushString);
                                        ConnectionsManager.getInstance()
                                                .setUserId(UserConfig.getClientUserId());
                                    }
                                });
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i >= otherSessionsStartRow && i < otherSessionsEndRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setMessage(LocaleController.getString("TerminateSessionQuestion",
                        R.string.TerminateSessionQuestion));
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int option) {
                                final ProgressDialog progressDialog = new ProgressDialog(getParentActivity());
                                progressDialog
                                        .setMessage(LocaleController.getString("Loading", R.string.Loading));
                                progressDialog.setCanceledOnTouchOutside(false);
                                progressDialog.setCancelable(false);
                                progressDialog.show();

                                final TLRPC.TL_authorization authorization = sessions
                                        .get(i - otherSessionsStartRow);
                                TLRPC.TL_account_resetAuthorization req = new TLRPC.TL_account_resetAuthorization();
                                req.hash = authorization.hash;
                                ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                                    @Override
                                    public void run(final TLObject response, final TLRPC.TL_error error) {
                                        AndroidUtilities.runOnUIThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                try {
                                                    progressDialog.dismiss();
                                                } catch (Exception e) {
                                                    FileLog.e("tmessages", e);
                                                }
                                                if (error == null) {
                                                    sessions.remove(authorization);
                                                    updateRows();
                                                    if (listAdapter != null) {
                                                        listAdapter.notifyDataSetChanged();
                                                    }
                                                }
                                            }
                                        });
                                    }
                                });
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            }
        }
    });

    return fragmentView;
}

From source file:net.coding.program.third.MyPagerSlidingTabStrip.java

private void addIconTab(final int position, String url) {

    //      ImageButton tab = new ImageButton(getContext());
    ///*  w  w  w  . jav  a2  s. co m*/
    //      tab.setImageResource(resId);
    //
    //      addTab(position, tab);
    View v = mInflater.inflate(net.coding.program.R.layout.imageview_head, tabsContainer, false);
    ImageView head = (ImageView) v.findViewById(net.coding.program.R.id.head);
    if (url.isEmpty()) {
        head.setImageResource(net.coding.program.R.drawable.icon_all_task);
        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) head.getLayoutParams();
        lp.leftMargin += myFirstExtraPdddingLeft;
        head.setLayoutParams(lp);
    } else {
        ImageLoader.getInstance().displayImage(Global.makeSmallUrl(head, url), head, ImageLoadTool.options);
    }

    addTab(position, v);
}

From source file:com.android.contacts.list.MultiSelectContactsListFragment.java

/**
 * Show account icon, count of contacts and account name in the header of the list.
 */// w  ww  . j a v a  2 s . c  o m
protected void bindListHeader(Context context, View listView, View accountFilterContainer,
        AccountWithDataSet accountWithDataSet, int memberCount) {
    if (memberCount < 0) {
        hideHeaderAndAddPadding(context, listView, accountFilterContainer);
        return;
    }

    bindListHeaderCommon(listView, accountFilterContainer);

    final AccountTypeManager accountTypeManager = AccountTypeManager.getInstance(context);
    final AccountType accountType = accountTypeManager.getAccountType(accountWithDataSet.type,
            accountWithDataSet.dataSet);

    // Set text of count of contacts and account name
    final TextView accountFilterHeader = (TextView) accountFilterContainer
            .findViewById(R.id.account_filter_header);
    final String headerText = shouldShowAccountName(accountType)
            ? String.format(context.getResources().getQuantityString(R.plurals.contacts_count_with_account,
                    memberCount), memberCount, accountWithDataSet.name)
            : context.getResources().getQuantityString(R.plurals.contacts_count, memberCount, memberCount);
    accountFilterHeader.setText(headerText);
    accountFilterHeader.setAllCaps(false);

    // Set icon of the account
    final Drawable icon = accountType != null ? accountType.getDisplayIcon(context) : null;
    final ImageView accountFilterHeaderIcon = (ImageView) accountFilterContainer
            .findViewById(R.id.account_filter_icon);

    // If it's a writable Google account, we set icon size as 24dp; otherwise, we set it as
    // 20dp. And we need to change margin accordingly. This is because the Google icon looks
    // smaller when the icons are of the same size.
    if (accountType instanceof GoogleAccountType) {
        accountFilterHeaderIcon.getLayoutParams().height = getResources()
                .getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_size);
        accountFilterHeaderIcon.getLayoutParams().width = getResources()
                .getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_size);

        setMargins(accountFilterHeaderIcon,
                getResources().getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_left_margin),
                getResources().getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_right_margin));
    } else {
        accountFilterHeaderIcon.getLayoutParams().height = getResources()
                .getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_size_alt);
        accountFilterHeaderIcon.getLayoutParams().width = getResources()
                .getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_size_alt);

        setMargins(accountFilterHeaderIcon,
                getResources()
                        .getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_left_margin_alt),
                getResources()
                        .getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_right_margin_alt));
    }
    accountFilterHeaderIcon.requestLayout();

    accountFilterHeaderIcon.setVisibility(View.VISIBLE);
    accountFilterHeaderIcon.setImageDrawable(icon);
}

From source file:io.v.android.apps.syncslides.NavigateFragment.java

private void setThumbBitmap(ImageView thumb, Bitmap bitmap) {
    thumb.setImageBitmap(bitmap);// w  w w .j  a v  a2  s .  c  o  m
    // In landscape, the height is dependent on the image size.  However, if the
    // image was null, the height is hardcoded to 9/16 of the width in setThumbNull.
    // This resets it to the actual image size.
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        ViewGroup.LayoutParams thumbParams = thumb.getLayoutParams();
        thumbParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    }
}

From source file:com.facebook.GraphObjectAdapter.java

String getPictureFieldSpecifier() {
    // How big is our image?
    View view = createGraphObjectView(null, null);
    ImageView picture = (ImageView) view.findViewById(R.id.com_facebook_picker_image);
    if (picture == null) {
        return null;
    }/*  w  w w . j a  va 2  s.co m*/

    // Note: these dimensions are in pixels, not dips
    ViewGroup.LayoutParams layoutParams = picture.getLayoutParams();
    return String.format("picture.height(%d).width(%d)", layoutParams.height, layoutParams.width);
}

From source file:com.cachirulop.moneybox.fragment.MoneyboxFragment.java

/**
 * Create dynamically an android animation for a coin or a bill droping into
 * the moneybox.//  w  w  w  . j av a2s  . c om
 * 
 * @param img
 *            ImageView to receive the animation
 * @param layout
 *            Layout that paint the image
 * @param curr
 *            Currency value of the image
 * @return Set of animations to apply to the image
 */
private AnimationSet createDropAnimation(ImageView img, View layout, CurrencyValueDef curr) {
    AnimationSet result;

    result = new AnimationSet(false);
    result.setFillAfter(true);

    // Fade in
    AlphaAnimation fadeIn;

    fadeIn = new AlphaAnimation(0.0f, 1.0f);
    fadeIn.setDuration(300);
    result.addAnimation(fadeIn);

    // drop
    TranslateAnimation drop;
    int bottom;

    bottom = Math.abs(layout.getHeight() - img.getLayoutParams().height);
    drop = new TranslateAnimation(1.0f, 1.0f, 1.0f, bottom);
    drop.setStartOffset(300);
    drop.setDuration(1500);

    if (curr.getType() == CurrencyValueDef.MoneyType.COIN) {
        drop.setInterpolator(new BounceInterpolator());
    } else {
        // drop.setInterpolator(new DecelerateInterpolator(0.7f));
        drop.setInterpolator(new AnticipateOvershootInterpolator());
    }

    result.addAnimation(drop);

    return result;
}

From source file:com.android.contacts.group.GroupMembersFragment.java

@Override
protected View inflateView(LayoutInflater inflater, ViewGroup container) {
    final View view = inflater.inflate(R.layout.contact_list_content, /* root */ null);
    final View emptyGroupView = inflater.inflate(R.layout.empty_group_view, null);

    final ImageView image = (ImageView) emptyGroupView.findViewById(R.id.empty_group_image);
    final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) image.getLayoutParams();
    final int screenHeight = getResources().getDisplayMetrics().heightPixels;
    params.setMargins(0,/* w w w . jav a 2  s .  c  om*/
            screenHeight / getResources().getInteger(R.integer.empty_group_view_image_margin_divisor), 0, 0);
    params.gravity = Gravity.CENTER_HORIZONTAL;
    image.setLayoutParams(params);

    final FrameLayout contactListLayout = (FrameLayout) view.findViewById(R.id.contact_list);
    contactListLayout.addView(emptyGroupView);

    final Button addContactsButton = (Button) emptyGroupView.findViewById(R.id.add_member_button);
    addContactsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivityForResult(
                    GroupUtil.createPickMemberIntent(getContext(), mGroupMetaData, getMemberContactIds()),
                    RESULT_GROUP_ADD_MEMBER);
        }
    });
    return view;
}

From source file:io.v.android.apps.syncslides.NavigateFragment.java

private void setThumbNull(ImageView thumb) {
    thumb.setImageDrawable(null);//from   w ww  .  j  a v  a  2 s.  c om
    // In landscape, the height is dependent on the image size.  Because we don't have an
    // image, assume all of the images are 16:9.  The width is fixed, so we can calculate
    // the expected height.
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        ViewGroup grandparent = (ViewGroup) thumb.getParent().getParent();
        ViewGroup.LayoutParams thumbParams = thumb.getLayoutParams();
        thumbParams.height = (int) ((9 / 16.0) * grandparent.getMeasuredWidth());
    }
}

From source file:com.eutectoid.dosomething.picker.GraphObjectAdapter.java

String getPictureFieldSpecifier() {
    // How big is our image?
    View view = createGraphObjectView(null);
    ImageView picture = (ImageView) view.findViewById(R.id.com_facebook_picker_image);
    if (picture == null) {
        return null;
    }//from   w ww  .j a v  a2s  . c om

    // Note: these dimensions are in pixels, not dips
    ViewGroup.LayoutParams layoutParams = picture.getLayoutParams();
    return String.format(Locale.US, "picture.height(%d).width(%d)", layoutParams.height, layoutParams.width);
}

From source file:dk.nordfalk.aktivitetsliste.PagerSlidingTabStrip.java

private void addIconTabBdeTekstOgBillede(final int position, int resId, String title) {
    FrameLayout tabfl = new FrameLayout(getContext());
    ImageView tabi = new ImageView(getContext());
    tabi.setContentDescription(title);/*from   w  ww.  j  a v  a  2s  .  co m*/
    tabi.setImageResource(resId);
    tabi.setVisibility(View.INVISIBLE);
    TextView tabt = new TextView(getContext());
    tabt.setText(title);
    tabt.setGravity(Gravity.CENTER);
    tabt.setSingleLine();

    tabfl.addView(tabi);
    tabfl.addView(tabt);

    LayoutParams lp = (LayoutParams) tabi.getLayoutParams();
    lp.gravity = Gravity.CENTER;
    lp = (LayoutParams) tabt.getLayoutParams();
    lp.width = lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
    lp.gravity = Gravity.CENTER;

    addTab(position, tabfl);
}