Example usage for android.widget ImageView ImageView

List of usage examples for android.widget ImageView ImageView

Introduction

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

Prototype

public ImageView(Context context) 

Source Link

Usage

From source file:com.yanzhenjie.recyclerview.swipe.SwipeMenuView.java

private ImageView createIcon(SwipeMenuItem item) {
    ImageView imageView = new ImageView(getContext());
    imageView.setImageDrawable(item.getImage());
    return imageView;
}

From source file:de.bno.snakingnumbers.tutorial.Tutorial.java

private void updateIndicator(int index) {

    int numberOfPages = pages.length;

    indicatorLayout.removeAllViews();/*from   www.j  ava2s .c  o  m*/
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams((int) Dimension.getDIP(20, this),
            (int) Dimension.getDIP(20, this));

    for (int i = 0; i < numberOfPages; i++) {

        ImageView img = new ImageView(this);

        int padding = (int) Dimension.getDIP(5, this);
        img.setPadding(padding, padding, padding, padding);

        if (i == index) {

            img.setImageDrawable(getResources().getDrawable(R.drawable.page_indicator_active));
        } else {

            img.setImageDrawable(getResources().getDrawable(R.drawable.page_indicator));
        }

        indicatorLayout.addView(img, params);
    }
}

From source file:com.google.android.apps.muzei.render.MuzeiRendererFragment.java

@Override
@TargetApi(Build.VERSION_CODES.KITKAT)//  w  w  w  . jav  a2 s. c  om
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    boolean simpleDemoMode = false;
    if (mDemoMode && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        ActivityManager activityManager = (ActivityManager) getActivity()
                .getSystemService(Context.ACTIVITY_SERVICE);
        if (activityManager.isLowRamDevice()) {
            simpleDemoMode = true;
        }
    }

    if (simpleDemoMode) {
        DisplayMetrics dm = getResources().getDisplayMetrics();
        int targetWidth = dm.widthPixels;
        int targetHeight = dm.heightPixels;
        if (!mDemoFocus) {
            targetHeight = MathUtil.roundMult4(
                    ImageBlurrer.MAX_SUPPORTED_BLUR_PIXELS * 10000 / MuzeiBlurRenderer.DEFAULT_BLUR);
            targetWidth = MathUtil.roundMult4((int) (dm.widthPixels * 1f / dm.heightPixels * targetHeight));
        }

        mSimpleDemoModeImageView = new ImageView(container.getContext());
        mSimpleDemoModeImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        Picasso.with(getActivity()).load("file:///android_asset/starrynight.jpg")
                .resize(targetWidth, targetHeight).centerCrop().into(mSimpleDemoModeLoadedTarget);
        return mSimpleDemoModeImageView;
    } else {
        mView = new MuzeiView(getActivity());
        mView.setPreserveEGLContextOnPause(true);
        return mView;
    }
}

From source file:com.chrslee.csgopedia.app.CardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    //Looks like he did this layout via code this is a layoutparams object
    //it defines the metrics and bounds of a specific view
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    //Creating a FrameLayout a FrameLayout is basically a empty container
    FrameLayout fl = new FrameLayout(context);
    fl.setLayoutParams(params);/*  w  w w  .  j a va 2s .  co  m*/
    //setting the params from above

    // First - image section
    //Building the imageview via code
    LayoutParams imgParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    imgParams.gravity = Gravity.CENTER;
    //setting all centered
    ImageView iv = new ImageView(context);
    iv.setLayoutParams(imgParams);
    iv.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    iv.setAdjustViewBounds(true);
    iv.setBackgroundResource(getActivity().getIntent().getExtras().getInt("iconID"));
    //seting the iconID as the image of this imageView

    // Second - prices section
    //final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources()
    //        .getDisplayMetrics());
    //

    //LinearLayout is another container it just take the
    //widgets inside it and display them in a linear order
    LinearLayout linLayout = new LinearLayout(context);
    linLayout.setOrientation(LinearLayout.VERTICAL);
    linLayout.setLayoutParams(params);
    linLayout.setGravity(Gravity.CENTER);

    // Get prices
    ConnectionDetector cd = new ConnectionDetector(context); //creating a connection detector to check for internet
    String query = getActivity().getIntent().getStringExtra("searchQuery"); //taking the name or whatever he pass from mainactivity from the searchquery arg
    TextView placeholder = new TextView(context); ///this is a textview for the name of the item
    if (cd.isConnectedToInternet()) {//if its connected to internet then
        if (query.equals("-1")) {//if the skin is regular he display is not for sale
            placeholder.setText("Regular skins are not for sale!");
            linLayout.addView(placeholder);
        } else {//else he calls the scrappperAsyncTask with the query
            new ScraperAsyncTask(linLayout).execute(query);
        }
    } else {//if its not connected he display the message here
        placeholder.setText("Please connect to the Internet to view prices.");
        linLayout.addView(placeholder);
    }

    //here he defines which tab he is displaying, Now I see why he used the same fragment,
    //this is a bad practice, he created both widgets before but just displays one of them
    //for each case if its the first tab he display the image if its the second the prices
    if (position == 0) {
        fl.addView(iv);
    } else {
        fl.addView(linLayout);
    }

    //Then he returns the framelayout (container) to display it in the screen
    return fl;
}

From source file:mobisocial.musubi.objects.WebAppObj.java

@Override
public View createView(Context context, ViewGroup parent) {
    LinearLayout frame = new LinearLayout(context);
    frame.setLayoutParams(CommonLayouts.FULL_WIDTH);
    frame.setOrientation(LinearLayout.VERTICAL);

    LinearLayout appBar = new LinearLayout(context);
    appBar.setLayoutParams(CommonLayouts.FULL_WIDTH);
    appBar.setOrientation(LinearLayout.HORIZONTAL);
    frame.addView(appBar);/*from w  w w .  ja  va2 s.c o m*/

    Drawable icon = context.getResources().getDrawable(R.drawable.ic_menu_globe);
    ImageView iv = new ImageView(context);
    iv.setImageDrawable(icon);
    iv.setAdjustViewBounds(true);
    iv.setMaxWidth(60);
    iv.setMaxHeight(60);
    iv.setLayoutParams(CommonLayouts.WRAPPED);
    appBar.addView(iv);

    TextView tv = new TextView(context);
    tv.setLayoutParams(CommonLayouts.WRAPPED);
    tv.setGravity(Gravity.CENTER_VERTICAL);
    appBar.addView(tv);

    LinearLayout actionBar = new LinearLayout(context);
    actionBar.setLayoutParams(CommonLayouts.WRAPPED);
    actionBar.setOrientation(LinearLayout.HORIZONTAL);
    frame.addView(actionBar);

    Button b = new Button(context);
    // required for listview long-press
    b.setLayoutParams(CommonLayouts.WRAPPED);
    b.setFocusable(false);
    b.setText("Run");
    b.setOnClickListener(getRunListener());
    actionBar.addView(b);

    b = new Button(context);
    // required for listview long-press
    b.setLayoutParams(CommonLayouts.WRAPPED);
    b.setFocusable(false);
    b.setOnClickListener(getAddListener());
    actionBar.addView(b);

    return frame;
}

From source file:de.uulm.graphicalpasswords.openuyi.UYICreatePasswordActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_uyi_create_password);
    // Show the Up button in the action bar.
    setupActionBar();//w w w  . j  av  a  2 s.  c o m

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    length = Integer.parseInt(sharedPref.getString("uyi_length", "10"));

    originalViews = new ImageView[length];
    distortedViews = new ImageView[length];
    selectedPictures = new Picture[length];

    Bundle bundle = new Bundle();
    bundle.putInt("length", length);
    DialogFragment intro = new IntroDialogFragment();
    intro.setArguments(bundle);
    intro.show(getFragmentManager(), "intro");

    vibrator = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);

    Arrays.fill(selectedPictures, null);

    gallery = (Gallery) findViewById(R.id.uyi_gallery_originals);
    gallery.setAdapter(new UYIImageAdapter(this));

    gallery.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            ImageView viewOriginal = new ImageView(UYICreatePasswordActivity.this);
            ImageView viewDistorted = new ImageView(UYICreatePasswordActivity.this);

            int i = 0;
            for (; i < selectedPictures.length; i++) {
                if (i == selectedPictures.length - 1 && selectedPictures[i] != null) {
                    removePicture(i);
                }
                if (selectedPictures[i] == null || i == selectedPictures.length - 1) {
                    viewOriginal = originalViews[i];
                    viewDistorted = distortedViews[i];
                    selectedPictures[i] = ((UYIImageAdapter) parent.getAdapter()).getPicture(position);
                    vibrator.vibrate(100);

                    ScrollView sv = (ScrollView) findViewById(R.id.uyi_choosepi_scrollview);
                    int height = originalViews[0].getMeasuredHeight();
                    sv.scrollTo(0, (i * height) - 200);

                    break;
                }
            }

            int originalImageResource = ((UYIImageAdapter) parent.getAdapter()).getImageResource(position);
            viewOriginal.setImageResource(originalImageResource);
            viewDistorted.setImageResource(
                    ((UYIImageAdapter) parent.getAdapter()).getDistortedImageResource(position));
            ((UYIImageAdapter) parent.getAdapter()).removePicture(position);

            OnLongClickListener listener = new OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    vibrator.vibrate(200);
                    int viewid = v.getId();
                    int index = -1;

                    for (int i = 0; i < originalViews.length; i++) {
                        if (originalViews[i].getId() == viewid) {
                            index = i;
                            break;
                        } else if (distortedViews[i].getId() == viewid) {
                            index = i;
                            break;
                        }
                    }
                    Bundle bundle = new Bundle();
                    bundle.putInt("index", index);
                    DialogFragment dialog = new DeleteImageDialogFragment();
                    dialog.setArguments(bundle);
                    dialog.show(getFragmentManager(), "delete");
                    return false;
                }
            };

            viewOriginal.setOnLongClickListener(listener);
            viewDistorted.setOnLongClickListener(listener);

            // Check
            int count = 0;
            for (int j = 0; j < selectedPictures.length; j++) {
                if (selectedPictures[j] != null) {
                    count++;
                }
            }
            if (count == selectedPictures.length) {
                findViewById(R.id.uyi_save).setClickable(true);
                findViewById(R.id.uyi_save).setEnabled(true);
            }
        }
    });

    table = (TableLayout) findViewById(R.id.uyi_choosepi_tablelayout);
    LayoutParams params = new LayoutParams(android.widget.TableRow.LayoutParams.WRAP_CONTENT,
            android.widget.TableRow.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.CENTER;
    for (int i = 0; i < length; i++) {
        TableRow row = new TableRow(table.getContext());

        originalViews[i] = new ImageView(row.getContext());
        originalViews[i].setAdjustViewBounds(true);
        originalViews[i].setScaleType(ScaleType.FIT_XY);
        originalViews[i].setPadding(3, 3, 3, 3);
        originalViews[i].setImageResource(R.drawable.oempty);
        originalViews[i].setId(100 + i);

        distortedViews[i] = new ImageView(row.getContext());
        distortedViews[i].setAdjustViewBounds(true);
        distortedViews[i].setScaleType(ScaleType.FIT_XY);
        distortedViews[i].setPadding(3, 3, 3, 3);
        distortedViews[i].setImageResource(R.drawable.wempty);
        distortedViews[i].setId(1000 + i);

        ImageView arrow = new ImageView(row.getContext());
        arrow.setAdjustViewBounds(true);
        arrow.setScaleType(ScaleType.FIT_XY);
        arrow.setMaxWidth(80);
        arrow.setPadding(3, 3, 3, 3);
        arrow.setImageResource(R.drawable.arrow_active);
        arrow.setLayoutParams(params);

        row.addView(originalViews[i]);
        row.addView(arrow);
        row.addView(distortedViews[i]);
        table.addView(row);
    }
}

From source file:io.imoji.sdk.grid.ui.ResultView.java

public ResultView(Context context, @ResultViewSize int viewSize) {
    super(context);
    this.context = context;

    this.viewSize = viewSize;

    int resultWidth = getDimension(0);
    int resultHeight = getDimension(1);
    setLayoutParams(new StaggeredGridLayoutManager.LayoutParams(resultWidth, resultHeight));

    placeholder = new ImageView(context);
    int placeholderSide = getDimension(4);
    RelativeLayout.LayoutParams placeholderParams = new LayoutParams(placeholderSide, placeholderSide);
    placeholderParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    placeholder.setLayoutParams(placeholderParams);
    addView(placeholder);//  w  w  w.ja  v  a 2  s. c  o m

    container = new RelativeLayout(context);
    addView(container, new LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
            RelativeLayout.LayoutParams.MATCH_PARENT));

    final Animation pressedAnimation = AnimationUtils.loadAnimation(context, R.anim.search_result_pressed);
    final Animation releasedAnimation = AnimationUtils.loadAnimation(context, R.anim.search_result_released);
    imageView = new GifImageView(context) {

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if (searchResult != null && !searchResult.isCategory()) {
                    imageView.startAnimation(pressedAnimation);
                }
                break;
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                if (searchResult != null && !searchResult.isCategory()) {
                    imageView.startAnimation(releasedAnimation);
                }
                break;
            }
            return super.onTouchEvent(event);
        }
    };

    RelativeLayout.LayoutParams imageParams = new LayoutParams(resultWidth, resultWidth);
    imageParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    imageView.setLayoutParams(imageParams);
    container.addView(imageView);

    textView = new TextView(context);
    int titleHeight = getDimension(2);
    RelativeLayout.LayoutParams titleParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            titleHeight);
    titleParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    textView.setLayoutParams(titleParams);
    textView.setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/Montserrat-Light.otf"));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getDimension(3));
    //TODO // FIXME: 5/2/16
    textView.setTextColor(getResources().getColor(R.color.search_result_category_title));
    textView.setGravity(Gravity.CENTER);
    container.addView(textView);

    imageView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            listener.onTap(searchResult);
        }
    });

}

From source file:net.quduo.pixel.interfaces.android.activity.GuideActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_guide);

    // ?????DisplayMetrics?
    DisplayMetrics DM = new DisplayMetrics();
    // ???,???,getDefaultDisplay()???DM,?getMetrics(DM)?
    getWindowManager().getDefaultDisplay().getMetrics(DM);

    int wdip = px2dip(getApplicationContext(),
            getApplicationContext().getResources().getDisplayMetrics().widthPixels);
    int hdip = px2dip(getApplicationContext(),
            getApplicationContext().getResources().getDisplayMetrics().heightPixels);

    LayoutInflater inflater = getLayoutInflater();

    views = new ArrayList<View>();
    views.add(inflater.inflate(R.layout.layout_guide_item_01, null));
    views.add(inflater.inflate(R.layout.layout_guide_item_02, null));
    views.add(inflater.inflate(R.layout.layout_guide_item_03, null));
    views.add(inflater.inflate(R.layout.layout_guide_item_04, null));
    views.add(inflater.inflate(R.layout.layout_guide_item_05, null));

    indicators = new ImageView[views.size()];

    mViewGroup = (ViewGroup) findViewById(R.id.viewGroup);
    mViewPager = (ViewPager) findViewById(R.id.view_pager);

    for (int i = 0; i < views.size(); i++) {
        mImageView = new ImageView(this);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(20, 20);
        layoutParams.setMargins(8, 0, 8, 20);
        mImageView.setLayoutParams(layoutParams);
        indicators[i] = mImageView;/*from w w  w .  j a v  a  2  s.  c  o  m*/
        mImageView.setBackgroundResource(R.drawable.selector_indicator_view);
        mImageView.setEnabled(false);
        if (i == 0) {
            mImageView.setEnabled(true);
        }
        mViewGroup.addView(mImageView);
    }

    mViewPager.setAdapter(new PagerAdapter() {

        @Override
        public int getCount() {
            return Integer.MAX_VALUE;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public int getItemPosition(Object object) {
            return super.getItemPosition(object);
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ((ViewPager) container).addView(views.get(position % views.size()), 0);
            return views.get(position % views.size());
        }

        @Override
        public void restoreState(Parcelable arg0, ClassLoader arg1) {

        }

        @Override
        public Parcelable saveState() {
            return null;
        }

        @Override
        public void startUpdate(ViewGroup container) {
            super.startUpdate(container);
        }

        @Override
        public void finishUpdate(ViewGroup container) {
            super.finishUpdate(container);
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView(views.get(position % views.size()));
        }

    });
    mViewPager.setOnPageChangeListener(this);
    mViewPager.setCurrentItem(0);

    mLoginButton = (Button) findViewById(R.id.login_button);
    mRegisterButton = (Button) findViewById(R.id.register_button);

    mLoginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent intent = new Intent(GuideActivity.this, LoginActivity.class);
            GuideActivity.this.startActivity(intent);
            // ?
            overridePendingTransition(R.anim.activity_open_enter, R.anim.activity_close_exit);
            GuideActivity.this.finish();
        }
    });

    mRegisterButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent intent = new Intent(GuideActivity.this, RegisterActivity.class);
            GuideActivity.this.startActivity(intent);
            // ?
            overridePendingTransition(R.anim.activity_open_enter, R.anim.activity_close_exit);
            GuideActivity.this.finish();
        }
    });
}

From source file:com.yojiokisoft.japanesecalc.activity.SkinActivity.java

/**
 * ??/*from w ww . jav a2 s.  c om*/
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_skin);

    int imageW = MyResource.dpi2Px(53);
    int imageH = MyResource.dpi2Px(80);
    int margin7 = MyResource.dpi2Px(7);
    int margin3 = MyResource.dpi2Px(3);

    mSkinResName = SettingDao.getInstance().getSkin();

    int orientation = getResources().getConfiguration().orientation;
    if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
        CustomScrollView scrollView = (CustomScrollView) findViewById(R.id.horizontal_scrollview);
        scrollView.setScrollStateListener(mImageVScrolled);
    } else {
        CustomHorizontalScrollView scrollView = (CustomHorizontalScrollView) findViewById(
                R.id.horizontal_scrollview);
        scrollView.setScrollStateListener(mImageHScrolled);
    }
    LinearLayout imageContainer = (LinearLayout) findViewById(R.id.image_container);
    mLeftArrow = (ImageView) findViewById(R.id.left_arrow);
    mRightArrow = (ImageView) findViewById(R.id.right_arrow);
    mPager = (ViewPager) findViewById(R.id.pager);
    mUseButton = (Button) findViewById(R.id.use_button);

    mUseButton.setOnClickListener(mUseButtonClicked);

    BackImageDao backImageDao = new BackImageDao();
    List<BackImageEntity> items = backImageDao.queryForAll();
    int resId;
    int size = items.size();
    ImageView[] images = new ImageView[size];
    for (int i = 0; i < size; i++) {
        images[i] = new ImageView(this);
        resId = MyResource.getResourceIdByName("s_" + items.get(i).resourceName);
        images[i].setImageResource(resId);
        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            images[i].setLayoutParams(new LayoutParams(imageH, imageW + margin7));
            images[i].setPadding(0, margin3, 0, margin3);
        } else {
            images[i].setLayoutParams(new LayoutParams(imageW + margin7, imageH));
            images[i].setPadding(margin3, 0, margin3, 0);
        }
        images[i].setTag(i);
        images[i].setOnClickListener(mImageClicked);
        imageContainer.addView(images[i]);
    }

    SkinPagerAdapter adapter = new SkinPagerAdapter(this, items);
    mPager.setAdapter(adapter);
    mPager.setOnPageChangeListener(mPageChanged);
    setUseButtonText(items.get(0).resourceName);
}

From source file:com.ght.cerberus.StatusFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);//from   w ww .  j  ava 2 s .  co m
    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
        FragmentActivity activity = getActivity();
        Toast.makeText(activity, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        activity.finish();
    }
    mRobot = new ImageView(getContext());
    mStateText = new TextView(getContext());
}