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.birdgang.viewpagerheader.indicator.SpringIndicator.java

private void addTabItems() {
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.leftMargin = 30;//  ww  w  .j  ava  2 s  .c  o  m
    layoutParams.rightMargin = 30;

    tabs = new ArrayList<>();

    for (int i = 0; i < viewPager.getAdapter().getCount(); i++) {
        ImageView imageView = new ImageView(getContext());
        imageView.setImageResource(R.drawable.btn_pop_normal);
        imageView.setLayoutParams(layoutParams);
        final int position = i;
        imageView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (tabClickListener == null || tabClickListener.onTabClick(position)) {
                    viewPager.setCurrentItem(position);
                }
            }
        });

        tabs.add(imageView);
        tabContainer.addView(imageView);
    }
}

From source file:com.acceleratedio.pac_n_zoom.DrawSVG.java

public ArrayList<ImageView> DrawSVG(Context context, ImageView orgnlImageView, RelativeLayout rel_anm_lo) {

    paint.setColor(Color.WHITE);/*from w w w. j a v  a2s. com*/
    paint.setStyle(Paint.Style.FILL);
    LoadSVG.SVGData data = AnimActivity.svg_data;
    ArrayList<ImageView> imgViews = new ArrayList<ImageView>();
    imgViews.add(orgnlImageView);

    if (data.symbl != null) {

        ArrayList<String> sprt_ordr = data.svg.ordr;
        int sym_mbr = 0;
        Bitmap bitmap;
        Canvas canvas;

        // - Loop through the sprites 
        int sprt_nmbr = sprt_ordr.size();
        data.svg.initScl = new float[sprt_nmbr];
        float[] initScl = data.svg.initScl;

        for (int sprt_mbr = 1; sprt_mbr < sprt_nmbr; sprt_mbr += 1) {

            String sprt_id = sprt_ordr.get(sprt_mbr); // e.g., id="g2_0"

            if (Integer.parseInt(sprt_id.substring(sprt_id.indexOf('_') + 1)) > 0) {
                // The symbol is already drawn; replicate the view   
                String init_sprt = sprt_id.substring(0, sprt_id.indexOf('_') + 1) + '0';
                String svg_ordr = data.svg.svg_ordr;
                String cnt_str = svg_ordr.substring(0, svg_ordr.indexOf(init_sprt));
                ImageView init_vw = imgViews.get(StringUtils.countMatches(cnt_str, ","));
                Bitmap initBmp = ((BitmapDrawable) init_vw.getDrawable()).getBitmap();

                bitmap = Bitmap.createBitmap(initBmp.getWidth(), initBmp.getHeight(), initBmp.getConfig());

                canvas = new Canvas(bitmap);
                canvas.save(Canvas.MATRIX_SAVE_FLAG);
                xfrmInit crt_sprt = getInitSpriteAttrib(sprt_id);
                canvas.scale(crt_sprt.scl, crt_sprt.scl);
                initScl[sprt_mbr] = crt_sprt.scl;
                canvas.translate(0, 0);
            } else {
                // The symbol needs to be drawn; a new view   is used
                bitmap = getCreatBmp(rel_anm_lo);
                canvas = new Canvas(bitmap);
                canvas.save(Canvas.MATRIX_SAVE_FLAG);

                // - Set the init values
                xfrmInit crt_sprt = getInitSpriteAttrib(sprt_id);
                canvas.scale(crt_sprt.scl, crt_sprt.scl);
                initScl[sprt_mbr] = crt_sprt.scl;
                canvas.translate(0, 0);

                // - Draw the bitmap
                LoadSVG.symbol crt_sym = data.symbl.get(sym_mbr);
                ArrayList<LoadSVG.path> pths = crt_sym.pths;
                int pth_nmbr = pths.size();

                // Loop through the paths
                for (int pth_mbr = 0; pth_mbr < pth_nmbr; pth_mbr += 1) {

                    LoadSVG.path crt_pth = pths.get(pth_mbr);
                    final Path path = new Path();
                    final Paint paint = new Paint();
                    /* Debug
                    if (pth_mbr + 1 == pth_nmbr) {
                            
                       String log_str = "Paths: pth_mbr = " +
                          String.valueOf(pth_mbr) + "; color = " + crt_pth.clr;
                            
                       Log.d("DrawSVG", log_str);
                    }
                    */
                    paint.setColor(Color.parseColor(crt_pth.clr));
                    paint.setAntiAlias(true);
                    paint.setStyle(Paint.Style.FILL_AND_STROKE);
                    ld_pth_pnts(crt_pth.pth, path);
                    path.close();
                    path.setFillType(Path.FillType.EVEN_ODD);
                    canvas.drawPath(path, paint);
                }

                canvas.restore();
                sym_mbr += 1;
            }

            ImageView iv = new ImageView(context);
            iv.setImageBitmap(bitmap);

            RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);

            iv.draw(canvas);
            iv.setLayoutParams(rlp);
            iv.setBackgroundColor(Color.TRANSPARENT);
            imgViews.add(iv);
        } // sprites
    } // if symbol

    return imgViews;
}

From source file:com.me.harris.listviewitemanimations._01_activityAnim.ActivityAnimations.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_animations);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);// w  w  w.  ja v a2 s. c o m
    getSupportActionBar().setTitle("");
    handleStatusBar();
    // Grayscale filter used on all thumbnails
    ColorMatrix grayMatrix = new ColorMatrix();
    grayMatrix.setSaturation(0);
    ColorMatrixColorFilter grayscaleFilter = new ColorMatrixColorFilter(grayMatrix);
    mGridLayout = (GridLayout) findViewById(R.id.gridLayout);
    mGridLayout.setColumnCount(3);
    mGridLayout.setUseDefaultMargins(true);
    // add all photo thumbnails to layout
    Resources resources = getResources();
    ArrayList<PictureData> pictures = mBitmapUtils.loadPhotos(resources);
    for (int i = 0; i < pictures.size(); ++i) {
        PictureData pictureData = pictures.get(i);
        BitmapDrawable thumbnailDrawable = new BitmapDrawable(resources, pictureData.thumbnail);
        thumbnailDrawable.setColorFilter(grayscaleFilter);
        ImageView imageView = new ImageView(this);
        imageView.setOnClickListener(thumbnailClickListener);
        imageView.setImageDrawable(thumbnailDrawable);
        mPicturesData.put(imageView, pictureData);
        mGridLayout.addView(imageView);
    }
}

From source file:de.tobiasbielefeld.solitaire.ui.GameManager.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_game_manager);

    mAdView = (AdView) findViewById(R.id.adView2);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);//from  www. ja va  2 s .  com

    // load stuff
    layoutGame = (RelativeLayout) findViewById(R.id.mainRelativeLayoutGame);
    mainTextViewTime = (TextView) findViewById(R.id.mainTextViewTime);
    mainTextViewScore = (TextView) findViewById(R.id.mainTextViewScore);
    mainTextViewRedeals = (TextView) findViewById(R.id.textViewRedeals);
    buttonAutoComplete = (Button) findViewById(R.id.buttonMainAutoComplete);

    //initialize my static helper stuff
    final GameManager gm = this;
    recordList = new RecordList(gm);
    movingCards = new MovingCards();
    hint = new Hint();
    scores = new Scores(gm);
    gameLogic = new GameLogic(gm);
    animate = new Animate(gm);
    autoComplete = new AutoComplete(gm);
    timer = new Timer(gm);
    currentGame = lg.loadClass(this, getIntent().getIntExtra("game", 1));
    savedGameData = getSharedPreferences(lg.getSharedPrefName(), MODE_PRIVATE);

    if (savedSharedData == null) {
        savedSharedData = PreferenceManager.getDefaultSharedPreferences(this);
    }

    updateIcons();

    //initialize cards and stacks
    for (int i = 0; i < stacks.length; i++) {
        stacks[i] = new Stack(i);
        stacks[i].view = new ImageView(this);
        stacks[i].view.setBackgroundResource(R.drawable.background_stack);
        layoutGame.addView(stacks[i].view);
    }

    for (int i = 0; i < cards.length; i++) {
        cards[i] = new Card(i);
        cards[i].view = new ImageView(this);
        cards[i].view.setId(i);
        cards[i].view.setOnTouchListener(this);
        layoutGame.addView(cards[i].view);
    }

    currentGame.addOnTouchListener(this);

    scores.output();
    loadCounter++;
    //post, because i need the dimensions of layoutGame to set the cards and stacks
    layoutGame.post(new Runnable() { //post a runnable to set the dimensions of cards and stacks when the layout has loaded
        @Override
        public void run() {
            boolean isLandscape = getResources()
                    .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;

            currentGame.setStacks(layoutGame, isLandscape);

            //if left handed mode is true, mirror all stacks
            if (getSharedBoolean(getString(R.string.pref_key_left_handed_mode), false)) {
                for (Stack stack : stacks)
                    stack.view.setX(layoutGame.getWidth() - stack.view.getX() - Card.width);

                if (currentGame.hasArrow()) {
                    for (Stack stack : stacks) {
                        if (stack.hasArrow() > 0) {
                            if (stack.hasArrow() == 1) {
                                stack.view.setBackgroundResource(R.drawable.arrow_right);
                            } else {
                                stack.view.setBackgroundResource(R.drawable.arrow_left);
                            }
                        }
                    }
                }
            }

            //calculate the spacing for cards on a stack
            Stack.defaultSpacing = Card.width / 2;

            //setup how the cards on the stacks will be stacked (offset to the previous card)
            //there are 4 possible directions. By default, the tableau stacks are stacked down
            //all other stacks don't have a visible offset
            //use setDirections() in a game to change that
            if (currentGame.directions == null) {
                for (int i = 0; i <= currentGame.getLastTableauID(); i++) {
                    stacks[i].setSpacingDirection(1);
                }
            } else {
                for (int i = 0; i < currentGame.directions.length; i++) {
                    stacks[i].setSpacingDirection(currentGame.directions[i]);
                }
            }
            //if there are direction borders set (when cards should'nt overlap another stack)  use it.
            //else set the layout height/widht as maximum
            if (currentGame.directionBorders != null) {
                for (int i = 0; i < currentGame.directionBorders.length; i++) {
                    if (currentGame.directionBorders[i] != -1) //-1 means no border
                        stacks[i].setSpacingMax(currentGame.directionBorders[i]);
                    else
                        stacks[i].setSpacingMax(layoutGame);
                }
            } else {
                for (Stack stack : stacks) {
                    stack.setSpacingMax(layoutGame);
                }
            }

            //load the game
            loadCounter--;
            if (loadCounter < 1) {
                scores.load();
                LoadGameHandler loadGameHandler = new LoadGameHandler(gm);
                loadGameHandler.sendEmptyMessageDelayed(0, 200);
            }
        }
    });

}

From source file:com.tony.selene.sliding.AbSlidingSmoothTabView.java

/**
 * Instantiates a new ab sliding smooth tab view.
 *
 * @param context/*from  ww  w.  j a va 2s  .c  o m*/
 *            the context
 * @param attrs
 *            the attrs
 */
public AbSlidingSmoothTabView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    layoutParamsFW = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    layoutParamsFF = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    layoutParamsWW = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    mTabScrollView = new AbHorizontalScrollView(context);
    mTabScrollView.setHorizontalScrollBarEnabled(false);
    mTabLayout = new LinearLayout(context);
    mTabLayout.setOrientation(LinearLayout.HORIZONTAL);
    mTabLayout.setGravity(Gravity.CENTER);
    // mTabLayout
    mTabScrollView.addView(mTabLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    // Tab?
    tabItemList = new ArrayList<TextView>();
    tabItemTextList = new ArrayList<String>();

    this.addView(mTabScrollView, layoutParamsFW);

    // ?
    mTabImg = new ImageView(context);
    this.addView(mTabImg, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, tabSlidingHeight));

    // View?
    mViewPager = new ViewPager(context);
    // ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();

    this.addView(mViewPager, layoutParamsFF);

    // ?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        AbLogUtil.e(AbSlidingSmoothTabView.class,
                "AbSlidingSmoothTabView?context,FragmentActivity");
    }

    FragmentManager mFragmentManager = ((FragmentActivity) this.context).getFragmentManager();
    mFragmentPagerAdapter = new AbFragmentPagerAdapter(mFragmentManager, pagerItemList);
    mViewPager.setAdapter(mFragmentPagerAdapter);
    mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
    mViewPager.setOffscreenPageLimit(3);

    mTabScrollView.setSmoothScrollingEnabled(true);

    mTabScrollView.setOnScrollListener(new AbOnScrollListener() {

        @Override
        public void onScrollToRight() {
            AbLogUtil.d(AbSlidingSmoothTabView.class, "onScrollToRight");
        }

        @Override
        public void onScrollToLeft() {
            AbLogUtil.d(AbSlidingSmoothTabView.class, "onScrollToLeft");
        }

        @Override
        public void onScrollStoped() {
            AbLogUtil.d(AbSlidingSmoothTabView.class, "onScrollStoped");
        }

        @Override
        public void onScroll(int arg1) {
            scrollX = arg1;
            View view = mTabLayout.getChildAt(mSelectedTabIndex);
            int toX = view.getLeft() - scrollX;

            AbLogUtil.d(AbSlidingSmoothTabView.class, "X" + startX + "to" + toX);
            imageSlide(mTabImg, startX, toX, 0, 0);
            startX = toX;
        }
    });
}

From source file:com.zt.hackman.model.HackmanModel.java

/**
 * ?/*from   w  w w.ja va 2s  .c  o  m*/
 */
public void changeImage(ImageItem item, int current, RelativeLayout btn) {

    btn.removeAllViews();
    ImageView imageView = new ImageView(ac);
    imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    btn.addView(imageView);
    ImageLoader.getInstance().displayImage("file://" + item.path, imageView, BaseApp.options);
    switch (current) {
    case 1:
        response.idenFrontImage = new File(item.path);
        break;
    case 2:
        response.idenReserveImage = new File(item.path);
        break;
    case 3:
        response.driveImage = new File(item.path);
        break;
    case 4:
        response.driveImage2 = new File(item.path);
        break;
    case 5:
        response.doBusinessImage = new File(item.path);
        break;
    case 6:
        response.vehicleImg = new File(item.path);
        break;
    case 7:
        response.vehicleLicenseImg = new File(item.path);
        break;
    case 8:
        response.vehicleLicenseImg2 = new File(item.path);
        break;
    case 9:
        response.operationLicenseImg = new File(item.path);
        break;

    }

}

From source file:cn.org.eshow.framwork.view.sliding.AbBottomTabView.java

/**
 * Instantiates a new ab bottom tab view.
 *
 * @param context the context//from w w w  .  j ava 2s.c o  m
 * @param attrs the attrs
 */
public AbBottomTabView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    mTabLayout = new LinearLayout(context);
    mTabLayout.setOrientation(LinearLayout.HORIZONTAL);
    mTabLayout.setGravity(Gravity.CENTER);

    //View?
    mViewPager = new AbViewPager(context);
    //ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();
    this.addView(mViewPager, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1));

    //?
    mTabImg = new ImageView(context);
    mTabImg.setBackgroundColor(tabSlidingColor);
    this.addView(mTabImg, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, tabSlidingHeight));

    this.addView(mTabLayout,
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    //Tab?
    tabItemList = new ArrayList<AbTabItemView>();
    tabItemTextList = new ArrayList<String>();
    tabItemDrawableList = new ArrayList<Drawable>();
    //?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        AbLogUtil.e(AbBottomTabView.class,
                "AbSlidingTabView?context,FragmentActivity");
    }

    DisplayMetrics mDisplayMetrics = AbAppUtil.getDisplayMetrics(context);
    mWidth = mDisplayMetrics.widthPixels;

    FragmentManager mFragmentManager = ((FragmentActivity) this.context).getFragmentManager();
    mFragmentPagerAdapter = new AbFragmentPagerAdapter(mFragmentManager, pagerItemList);
    mViewPager.setAdapter(mFragmentPagerAdapter);
    mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
    mViewPager.setOffscreenPageLimit(3);

}

From source file:com.bangqu.eshow.view.sliding.ESBottomTabView.java

/**
 * Instantiates a new ab bottom tab view.
 *
 * @param context the context//from  w  ww  . j  a  v  a 2s . c o  m
 * @param attrs the attrs
 */
public ESBottomTabView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    mTabLayout = new LinearLayout(context);
    mTabLayout.setOrientation(LinearLayout.HORIZONTAL);
    mTabLayout.setGravity(Gravity.CENTER);

    //View?
    mViewPager = new ESViewPager(context);
    //ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();
    this.addView(mViewPager, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1));

    //?
    mTabImg = new ImageView(context);
    mTabImg.setBackgroundColor(tabSlidingColor);
    this.addView(mTabImg, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, tabSlidingHeight));

    this.addView(mTabLayout,
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    //Tab?
    tabItemList = new ArrayList<ESTabItemView>();
    tabItemTextList = new ArrayList<String>();
    tabItemDrawableList = new ArrayList<Drawable>();
    //?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        ESLogUtil.e(ESBottomTabView.class,
                "AbSlidingTabView?context,FragmentActivity");
    }

    DisplayMetrics mDisplayMetrics = ESAppUtil.getDisplayMetrics(context);
    mWidth = mDisplayMetrics.widthPixels;

    FragmentManager mFragmentManager = ((FragmentActivity) this.context).getFragmentManager();
    mFragmentPagerAdapter = new ESFragmentPagerAdapter(mFragmentManager, pagerItemList);
    mViewPager.setAdapter(mFragmentPagerAdapter);
    mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
    mViewPager.setOffscreenPageLimit(3);

}

From source file:es.eucm.eadandroid.utils.ViewPagerIndicator.java

/**
 * Add drawables for arrows//w w w. j  av  a2  s.  c om
 * 
 * @param prev Left pointing arrow
 * @param next Right pointing arrow
 */
public void setArrows(Drawable prev, Drawable next) {
    this.mPrevArrow = new ImageView(getContext());
    this.mPrevArrow.setImageDrawable(prev);
    if (this.startPos == 0)
        this.mPrevArrow.setVisibility(INVISIBLE);

    this.mNextArrow = new ImageView(getContext());
    this.mNextArrow.setImageDrawable(next);

    LinearLayout.LayoutParams arrowLayoutParams = new LinearLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    arrowLayoutParams.gravity = Gravity.CENTER;

    mPreviousGroup.removeAllViews();
    mPreviousGroup.addView(mPrevArrow, arrowLayoutParams);
    mPreviousGroup.addView(mPrevious, arrowLayoutParams);

    mPrevious.setPadding(PADDING, 0, 0, 0);
    mNext.setPadding(0, 0, PADDING, 0);

    mArrowPadding = PADDING + prev.getIntrinsicWidth();

    mNextGroup.addView(mNextArrow, arrowLayoutParams);
}

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

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

    ImageView imageView = new ImageView(context);
    imageView.setBackgroundResource(android.R.drawable.picture_frame);
    imageView.setPadding(6, 4, 8, 9);/*  www . j a v  a2 s  .c  o m*/
    frame.addView(imageView);

    TextView textView = new TextView(context);
    frame.addView(textView);

    return frame;
}