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:org.chromium.chrome.browser.infobar.AppBannerInfoBarAndroid.java

@Override
protected void setButtons(InfoBarLayout layout, String primaryText, String secondaryText) {
    if (mAppData == null) {
        // The banner for web apps uses standard buttons.
        super.setButtons(layout, primaryText, secondaryText);
    } else {//from w  w  w .  ja va 2s  .c  o m
        // The banner for native apps shows a Play logo in place of a secondary button.
        assert secondaryText == null;
        ImageView playLogo = new ImageView(layout.getContext());
        playLogo.setImageResource(R.drawable.google_play);
        layout.setBottomViews(primaryText, playLogo, DualControlLayout.ALIGN_APART);
    }
}

From source file:com.dreamchen.useful.mouserace.view.sliding.AbSlidingSmoothFixTabView.java

/**
 * Instantiates a new ab sliding smooth fix tab view.
 *
 * @param context the context/*from w  ww  .  j  av a  2 s .  co  m*/
 * @param attrs the attrs
 */
public AbSlidingSmoothFixTabView(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);

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

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

    this.addView(mTabLayout, 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(AbSlidingSmoothFixTabView.class,
                "AbSlidingSmoothTabView?context,FragmentActivity");
    }

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

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

}

From source file:com.renard.ocr.documents.creation.visualisation.LayoutQuestionDialog.java

@NonNull
@Override/*from   w  w  w  .jav a2s.  com*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    getAnalytics().sendScreenView(SCREEN_NAME);
    final Context context = getContext();
    mLayout = null;
    Pair<String, String> language = PreferencesUtils.getOCRLanguage(context);

    final OcrLanguage.InstallStatus installStatus = OcrLanguageDataStore.isLanguageInstalled(language.first,
            context);

    if (!installStatus.isInstalled()) {
        final String defaultLanguage = context.getString(R.string.default_ocr_language);
        final String defaultLanguageDisplay = context.getString(R.string.default_ocr_display_language);
        language = Pair.create(defaultLanguage, defaultLanguageDisplay);
    }
    mLanguage = language.first;

    AlertDialog.Builder builder;

    builder = new AlertDialog.Builder(context);
    builder.setCancelable(false);
    View layout = View.inflate(context, R.layout.dialog_layout_question, null);
    builder.setView(layout);

    final ViewFlipper titleViewFlipper = (ViewFlipper) layout.findViewById(R.id.layout_title);
    final ImageView columnLayout = (ImageView) layout.findViewById(R.id.column_layout);
    final ImageView pageLayout = (ImageView) layout.findViewById(R.id.page_layout);
    final ImageSwitcher fairy = (ImageSwitcher) layout.findViewById(R.id.fairy_layout);
    fairy.setFactory(new ViewSwitcher.ViewFactory() {
        public View makeView() {
            return new ImageView(context);
        }
    });
    fairy.setImageResource(R.drawable.fairy_looks_center);
    fairy.setInAnimation(context, android.R.anim.fade_in);
    fairy.setOutAnimation(context, android.R.anim.fade_out);

    final int color = context.getResources().getColor(R.color.progress_color);

    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.LIGHTEN);

    columnLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mLayout != LayoutKind.COMPLEX) {
                fairy.setImageResource(R.drawable.fairy_looks_left);
                titleViewFlipper.setDisplayedChild(2);
                columnLayout.setColorFilter(colorFilter);
                pageLayout.clearColorFilter();
                mLayout = LayoutKind.COMPLEX;
            }

        }
    });
    pageLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mLayout != LayoutKind.SIMPLE) {
                mLayout = LayoutKind.SIMPLE;
                titleViewFlipper.setDisplayedChild(1);
                fairy.setImageResource(R.drawable.fairy_looks_right);
                pageLayout.setColorFilter(colorFilter);
                columnLayout.clearColorFilter();
            }
        }
    });

    final Spinner langButton = (Spinner) layout.findViewById(R.id.button_language);
    List<OcrLanguage> installedLanguages = OcrLanguageDataStore.getInstalledOCRLanguages(context);

    // actual values uses by tesseract
    final ArrayAdapter<OcrLanguage> adapter = new ArrayAdapter<>(context, R.layout.language_spinner_item,
            installedLanguages);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    langButton.setAdapter(adapter);
    for (int i = 0; i < installedLanguages.size(); i++) {
        OcrLanguage lang = installedLanguages.get(i);
        if (lang.getValue().equals(language.first)) {
            langButton.setSelection(i, false);
            break;
        }
    }
    langButton.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            final OcrLanguage item = adapter.getItem(position);
            mLanguage = item.getValue();
            PreferencesUtils.saveOCRLanguage(context, item);
            getAnalytics().sendOcrLanguageChanged(item);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    builder.setPositiveButton(R.string.start_scan, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            if (mLayout == null) {
                mLayout = LayoutKind.SIMPLE;
            }
            LayoutChoseListener listener = (LayoutChoseListener) getActivity();
            listener.onLayoutChosen(mLayout, mLanguage);
            getAnalytics().sendOcrStarted(mLanguage, mLayout);
            dialog.dismiss();
        }
    });

    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            getActivity().finish();
            dialog.dismiss();
            getAnalytics().sendLayoutDialogCancelled();
        }
    });

    return builder.create();

}

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

/**
 * Instantiates a new ab sliding smooth fix tab view.
 *
 * @param context/*from w ww  .j ava  2  s . co  m*/
 *            the context
 * @param attrs
 *            the attrs
 */
public AbSlidingSmoothFixTabView(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);

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

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

    this.addView(mTabLayout, 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(AbSlidingSmoothFixTabView.class,
                "AbSlidingSmoothTabView?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.chillax.viewpagerindicator.IconPageIndicator.java

public void notifyDataSetChanged() {
    mIconsLayout.removeAllViews();//from  w  w w .j av a 2 s .co  m
    IconPagerAdapter iconAdapter = (IconPagerAdapter) mViewPager.getAdapter();
    int count = iconAdapter.getCount();
    int padding = ScreenUtil.dp2px(context, 10);
    for (int i = 0; i < count; i++) {
        ImageView view = new ImageView(getContext());
        view.setLayoutParams(
                new ViewGroup.LayoutParams(ScreenUtil.dp2px(context, 35), ScreenUtil.dp2px(context, 35)));
        view.setPadding(padding, padding, padding, padding);
        view.setScaleType(ImageView.ScaleType.FIT_XY);
        view.setImageResource(R.drawable.leader_icon);
        mIconsLayout.addView(view);
    }
    if (mSelectedIndex > count) {
        mSelectedIndex = count - 1;
    }
    setCurrentItem(mSelectedIndex);
    requestLayout();
}

From source file:com.viewpagerindicator.TabMovablePageIndicator.java

public TabMovablePageIndicator(Context context, AttributeSet attrs) {
    super(context, attrs);
    mScreenWidth = getScreenDisplayMetrics().widthPixels;
    setHorizontalScrollBarEnabled(false);

    mMainBox = new LinearLayout(context);
    mMainBox.setOrientation(LinearLayout.VERTICAL);
    mMainBox.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, MATCH_PARENT));

    mTabLayout = new IcsLinearLayout(context, R.attr.vpiTabPageIndicatorStyle);
    mMainBox.addView(mTabLayout, new LinearLayout.LayoutParams(WRAP_CONTENT, MATCH_PARENT, 1));

    mIndicator = new ImageView(context);
    LinearLayout.LayoutParams indicatorLp = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    mMainBox.addView(mIndicator, indicatorLp);

    addView(mMainBox, new ViewGroup.LayoutParams(WRAP_CONTENT, MATCH_PARENT));
}

From source file:com.nike.plusgps.nikeplusgallery.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    dbHelper = new DBHelper(this); // Creates the database
    dbHelper.deleteAllResponse(); // Clears the JSON response cache
    dbHelper.deleteAllMedia(); // Clears the JSON images cache

    // Get memory class of this device, exceeding this amount will throw an
    // OutOfMemory exception.
    final int memClass = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    // Use 1/8th of the available memory for this memory cache.
    final int cacheSize = 1024 * 1024 * memClass / 8;
    mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override/* w ww  . ja  va2 s . c om*/
        protected int sizeOf(String key, Bitmap bitmap) {
            // The cache size will be measured in bytes rather than number of items.
            return bitmap.getByteCount();
        }
    };

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {

        setContentView(R.layout.activity_main_port);
        GridView view = (GridView) findViewById(R.id.gridView);
        flickrFeedList = new ArrayList<FlickrFeed>();
        new JSONParser()
                .execute("http://api.flickr.com/services/feeds/photos_public.gne?tags=nike&format=json");
        adapter = new FlickrFeedAdapter(getApplicationContext(), R.layout.single_elem_port, flickrFeedList,
                dbHelper, mMemoryCache);
        view.setAdapter(adapter);

    } else {

        setContentView(R.layout.activity_main_land);
        carouselElement = (LinearLayout) findViewById(R.id.carousel);
        // Compute width of a carousel item based on screen width and initial item count
        final DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        final int imageWidth = (int) (displayMetrics.widthPixels / INITIAL_ITEMS_COUNT);

        ImageView imageItem;
        String imgURL;
        for (int i = 0; i < flickrFeedList.size(); ++i) {
            imageItem = new ImageView(this);
            imgURL = flickrFeedList.get(i).getMedia();
            new DownloadImageTask(imageItem).execute(imgURL);
            imageItem.setLayoutParams(new LinearLayout.LayoutParams(imageWidth, imageWidth));
            carouselElement.addView(imageItem);
        }
    }
}

From source file:com.example.hllut.app.Deprecated.MainActivity.java

/**
 * Fills "amount of planets" textView as well as drawing the planets
 *//*from   ww  w .ja  v  a  2 s.  c  o  m*/
private void drawPlanets() {
    //TODO use the bundle
    int numberOfPlanets = (int) (TOTAL_CO2 / MAX_CO2_PER_PERSON);
    TextView need = (TextView) findViewById(R.id.planetsTextView);
    need.setText("We would need " + numberOfPlanets + " planets");

    TableLayout layout = (TableLayout) findViewById(R.id.planetContainer);

    TableRow tbr = new TableRow(this);

    LinearLayout linearLayout = new LinearLayout(this);

    linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); //TODO

    tbr.setLayoutParams(
            new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT));
    tbr.setPadding(10, 10, 10, 10);

    for (int i = 1; i < numberOfPlanets + 1; i++) {
        // TODO: Too many planets fuck up formatting
        // Create images
        ImageView im = new ImageView(this);
        im.setImageResource(R.drawable.earth);
        im.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));
        im.setPadding(10, 10, 10, 10);

        //planets per row = 5
        if (i % 5 == 0) {
            // if you have gone 5 laps
            // print what you have
            linearLayout.addView(im);
            tbr.addView(linearLayout,
                    new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1f));

            layout.addView(tbr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
                    TableLayout.LayoutParams.MATCH_PARENT));

            tbr = new TableRow(this);
            linearLayout = new LinearLayout(this);

            linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.MATCH_PARENT, 1f));

            tbr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
                    TableRow.LayoutParams.MATCH_PARENT));
            tbr.setPadding(10, 10, 10, 10);
        } else {
            linearLayout.addView(im);
        }

    }

    tbr.addView(linearLayout,
            new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1f)); //

    layout.addView(tbr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
            TableLayout.LayoutParams.MATCH_PARENT));
}

From source file:com.wms.opensource.shopfast.fragment.ProductsInCollectionFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (layout != null) {
        ViewGroup parent = (ViewGroup) layout.getParent();
        parent.removeView(layout);//  w  ww.j  a v a2s .  c o m
        return layout;
    }

    if (listView == null) {
        layout = new RelativeLayout(getActivity());

        listView = new ListView(getActivity());

        layout.addView(listView);

        imageViewPreview = new ImageView(getActivity());
        RelativeLayout.LayoutParams imageViewParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        imageViewParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        imageViewPreview.setLayoutParams(imageViewParams);
        imageViewPreview.setVisibility(View.INVISIBLE);
        imageViewPreview.setOnClickListener(new ImageView.OnClickListener() {

            @Override
            public void onClick(View v) {
                // Dismiss the image view
                v.setVisibility(View.INVISIBLE);
                Animation myAnim = AnimationUtils.loadAnimation(ProductsInCollectionFragment.this.getActivity(),
                        R.anim.fadeout);
                v.startAnimation(myAnim);
            }

        });
        layout.addView(imageViewPreview);

        progressBar = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge);

        RelativeLayout.LayoutParams progressBarBarams = new RelativeLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        progressBarBarams.addRule(RelativeLayout.CENTER_IN_PARENT);
        progressBar.setLayoutParams(progressBarBarams);
        progressBar.setVisibility(View.INVISIBLE);
        layout.addView(progressBar);

        // Before reloading products, display products if they have been saved before.
        String productsFilePath = StorageUtil.getTempDirectoryPath(getActivity()) + "/"
                + PersistFileNameProvider.getProductsFileName(collectionID, page);
        boolean productsFileExists = FileUtil.fileExist(productsFilePath);
        if (productsFileExists) {
            loadProductsFromLocalTask = new LoadCachedProductsInCollectionTask(getActivity(),
                    loadProductsHandler, progressBar, page);
            loadProductsFromLocalTask.execute(collectionID);
        } else {
            NetworkStatus networkStatus = NetworkUtil.getNetworkConnection(getActivity());
            if (networkStatus.equals(NetworkStatus.WIFI_CONNECTED)
                    || networkStatus.equals(NetworkStatus.MOBILE_CONNECTED)) {
                loadShopifyProductsTask = new LoadProductsInCollectionTask(getActivity(), loadProductsHandler,
                        progressBar, page);
                loadShopifyProductsTask.execute(collectionID);
            } else {
                Toast.makeText(getActivity(), getString(R.string.noNetworkAvailable), Toast.LENGTH_LONG).show();
            }
        }
    }
    return layout;
}

From source file:com.amagi82.kerbalspaceapp.MissionPlanner.java

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

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    getActionBar().setTitle(R.string.title_activity_mission_planner);

    if (savedInstanceState == null) {
        // Load saved missionData if available.
        try {/*from  w  w w . java2s  .  com*/
            FileInputStream inStream = new FileInputStream(
                    Environment.getExternalStorageDirectory() + File.separator + "MissionData");
            ObjectInputStream objectInStream = new ObjectInputStream(inStream);
            int count = objectInStream.readInt();
            for (int i = 0; i < count; i++)
                missionData.add((MissionData) objectInStream.readObject());
            objectInStream.close();
        } catch (OptionalDataException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        // if the list is empty, add the default planet
        if (missionData.size() == 0) {
            missionData = setFirstMissionData();
        }
    } else {
        missionData = savedInstanceState.getParcelableArrayList("key");
    }

    mBackgroundContainer = (BackgroundContainer) findViewById(R.id.listViewBackground);
    mListView = (ListView) findViewById(R.id.list);
    tvTotalDeltaV = (TextView) findViewById(R.id.tvTotalDeltaV);
    mAdapter = new StableArrayAdapter(this, missionData, mTouchListener);

    // add the newDestination button as a footer below the listview
    ImageView newDestination = new ImageView(this);
    newDestination.setImageResource(R.drawable.ic_plus);
    mListView.addFooterView(newDestination);
    newDestination.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int possibleIconState = 0; // Lets MissionDestination know which icons it's allowed to use
            if (missionData.size() < 1) {
                possibleIconState = 1;
            }
            Intent intent = new Intent(MissionPlanner.this, MissionDestination.class);
            intent.putExtra("possibleIconState", possibleIconState);
            intent.putExtra("isNewItem", true); // Places the result as a new item in the listview
            startActivityForResult(intent, 0);
        }
    });
    mListView.setAdapter(mAdapter);
}