Example usage for android.widget ImageView setScaleType

List of usage examples for android.widget ImageView setScaleType

Introduction

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

Prototype

public void setScaleType(ScaleType scaleType) 

Source Link

Document

Controls how the image should be resized or moved to match the size of this ImageView.

Usage

From source file:br.edu.ifpb.breath.slidingtabs.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int, int)}.
 */// w w  w . jav a  2 s. c  om
protected View createDefaultTabView(Context context, int type) {
    if (type == 0) {
        TextView textView = new TextView(context);
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
        textView.setTypeface(Typeface.DEFAULT_BOLD);
        textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));

        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
        textView.setAllCaps(true);

        int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
        textView.setPadding(padding, padding, padding, padding);

        return textView;
    } else {
        ImageView iconView = new ImageView(context);
        int iconSize = (int) (TAB_VIEW_ICON_SIZE_DIPS * getResources().getDisplayMetrics().density);
        int padding = (int) (TAB_VIEW_ICON_PADDING_DIPS * getResources().getDisplayMetrics().density);

        iconView.setLayoutParams(new LinearLayout.LayoutParams(iconSize + padding, iconSize + padding));
        iconView.setScaleType(ImageView.ScaleType.FIT_CENTER);
        iconView.setPadding(padding, padding, padding, padding);

        return iconView;
    }
}

From source file:com.cube.storm.ui.view.PagerSlidingTabStrip.java

private void addIconTab(final int position, Bitmap bitmap) {
    ImageView tab = new ImageView(getContext());
    tab.setImageBitmap(bitmap);/*  w  w  w .j  av a 2 s. c om*/
    tab.setColorFilter(tabIconTint);
    tab.setScaleType(ScaleType.FIT_CENTER);

    DisplayMetrics dm = getResources().getDisplayMetrics();
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm);

    tab.setPadding(padding + tabPadding, padding, padding + tabPadding, padding);

    tab.setFocusable(true);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(android.view.View v) {
            pager.setCurrentItem(position);
        }
    });

    tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

From source file:org.lol.reddit.activities.CaptchaActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);
    getSupportActionBar().setTitle(R.string.post_captcha_title);

    super.onCreate(savedInstanceState);

    final LoadingView loadingView = new LoadingView(this, R.string.download_waiting, true, true);
    setContentView(loadingView);/*from  ww  w .j  a v  a  2s.c o m*/

    final RedditAccount selectedAccount = RedditAccountManager.getInstance(this)
            .getAccount(getIntent().getStringExtra("username"));

    final CacheManager cm = CacheManager.getInstance(this);

    RedditAPI.newCaptcha(cm, new APIResponseHandler.NewCaptchaResponseHandler(this) {
        @Override
        protected void onSuccess(final String captchaId) {

            final URI captchaUrl = Constants.Reddit.getUri("/captcha/" + captchaId);

            cm.makeRequest(new CacheRequest(captchaUrl, RedditAccountManager.getAnon(), null,
                    Constants.Priority.CAPTCHA, 0, CacheRequest.DownloadType.FORCE, Constants.FileType.CAPTCHA,
                    false, false, true, CaptchaActivity.this) {
                @Override
                protected void onCallbackException(Throwable t) {
                    BugReportActivity.handleGlobalError(CaptchaActivity.this, t);
                }

                @Override
                protected void onDownloadNecessary() {
                }

                @Override
                protected void onDownloadStarted() {
                    loadingView.setIndeterminate(R.string.download_downloading);
                }

                @Override
                protected void onFailure(RequestFailureType type, Throwable t, StatusLine status,
                        String readableMessage) {
                    final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type, t,
                            status, url.toString());
                    General.showResultDialog(CaptchaActivity.this, error);
                    finish();
                }

                @Override
                protected void onProgress(long bytesRead, long totalBytes) {
                    loadingView.setProgress(R.string.download_downloading,
                            (float) ((double) bytesRead / (double) totalBytes));
                }

                @Override
                protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, long timestamp,
                        UUID session, boolean fromCache, String mimetype) {

                    final Bitmap image;
                    try {
                        image = BitmapFactory.decodeStream(cacheFile.getInputStream());
                    } catch (IOException e) {
                        BugReportActivity.handleGlobalError(CaptchaActivity.this, e);
                        return;
                    }

                    General.UI_THREAD_HANDLER.post(new Runnable() {
                        public void run() {

                            final LinearLayout ll = new LinearLayout(CaptchaActivity.this);
                            ll.setOrientation(LinearLayout.VERTICAL);

                            final ImageView captchaImg = new ImageView(CaptchaActivity.this);
                            ll.addView(captchaImg);
                            final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) captchaImg
                                    .getLayoutParams();
                            layoutParams.setMargins(20, 20, 20, 20);
                            layoutParams.height = General.dpToPixels(context, 100);
                            captchaImg.setScaleType(ImageView.ScaleType.FIT_CENTER);

                            final EditText captchaText = new EditText(CaptchaActivity.this);
                            ll.addView(captchaText);
                            ((LinearLayout.LayoutParams) captchaText.getLayoutParams()).setMargins(20, 0, 20,
                                    20);
                            captchaText.setInputType(android.text.InputType.TYPE_CLASS_TEXT
                                    | android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
                                    | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);

                            captchaImg.setImageBitmap(image);

                            final Button submitButton = new Button(CaptchaActivity.this);
                            submitButton.setText(R.string.post_captcha_submit_button);
                            ll.addView(submitButton);
                            ((LinearLayout.LayoutParams) submitButton.getLayoutParams()).setMargins(20, 0, 20,
                                    20);
                            ((LinearLayout.LayoutParams) submitButton
                                    .getLayoutParams()).gravity = Gravity.RIGHT;
                            ((LinearLayout.LayoutParams) submitButton
                                    .getLayoutParams()).width = LinearLayout.LayoutParams.WRAP_CONTENT;

                            submitButton.setOnClickListener(new View.OnClickListener() {
                                public void onClick(View v) {
                                    final Intent result = new Intent();
                                    result.putExtra("captchaId", captchaId);
                                    result.putExtra("captchaText", captchaText.getText().toString());
                                    setResult(RESULT_OK, result);
                                    finish();
                                }
                            });

                            final ScrollView sv = new ScrollView(CaptchaActivity.this);
                            sv.addView(ll);
                            setContentView(sv);
                        }
                    });

                }
            });
        }

        @Override
        protected void onCallbackException(Throwable t) {
            BugReportActivity.handleGlobalError(CaptchaActivity.this, t);
        }

        @Override
        protected void onFailure(RequestFailureType type, Throwable t, StatusLine status,
                String readableMessage) {
            final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type, t, status,
                    null);
            General.showResultDialog(CaptchaActivity.this, error);
            finish();
        }

        @Override
        protected void onFailure(APIFailureType type) {
            final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type);
            General.showResultDialog(CaptchaActivity.this, error);
            finish();
        }
    }, selectedAccount, this);
}

From source file:com.ryan.ryanreader.activities.CaptchaActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);
    getSupportActionBar().setTitle(R.string.post_captcha_title);

    super.onCreate(savedInstanceState);

    final LoadingView loadingView = new LoadingView(this, R.string.download_waiting, true, true);
    setContentView(loadingView);/*from w w w .ja v a 2  s.  c  om*/

    final RedditAccount selectedAccount = RedditAccountManager.getInstance(this)
            .getAccount(getIntent().getStringExtra("username"));

    final CacheManager cm = CacheManager.getInstance(this);

    RedditAPI.newCaptcha(cm, new APIResponseHandler.NewCaptchaResponseHandler(this) {
        @Override
        protected void onSuccess(final String captchaId) {

            final URI captchaUrl = Constants.Reddit.getUri("/captcha/" + captchaId);

            cm.makeRequest(new CacheRequest(captchaUrl, RedditAccountManager.getAnon(), null,
                    Constants.Priority.CAPTCHA, 0, CacheRequest.DownloadType.FORCE, Constants.FileType.CAPTCHA,
                    false, false, true, CaptchaActivity.this) {
                @Override
                protected void onCallbackException(Throwable t) {
                    BugReportActivity.handleGlobalError(CaptchaActivity.this, t);
                }

                @Override
                protected void onDownloadNecessary() {
                }

                @Override
                protected void onDownloadStarted() {
                    loadingView.setIndeterminate(R.string.download_downloading);
                }

                @Override
                protected void onFailure(RequestFailureType type, Throwable t, StatusLine status,
                        String readableMessage) {
                    final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type, t,
                            status);
                    General.showResultDialog(CaptchaActivity.this, error);
                    finish();
                }

                @Override
                protected void onProgress(long bytesRead, long totalBytes) {
                    loadingView.setProgress(R.string.download_downloading,
                            (float) ((double) bytesRead / (double) totalBytes));
                }

                @Override
                protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, long timestamp,
                        UUID session, boolean fromCache, String mimetype) {

                    final Bitmap image;
                    try {
                        image = BitmapFactory.decodeStream(cacheFile.getInputStream());
                    } catch (IOException e) {
                        BugReportActivity.handleGlobalError(CaptchaActivity.this, e);
                        return;
                    }

                    new Handler(Looper.getMainLooper()).post(new Runnable() {
                        public void run() {

                            final LinearLayout ll = new LinearLayout(CaptchaActivity.this);
                            ll.setOrientation(LinearLayout.VERTICAL);

                            final ImageView captchaImg = new ImageView(CaptchaActivity.this);
                            ll.addView(captchaImg);
                            final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) captchaImg
                                    .getLayoutParams();
                            layoutParams.setMargins(20, 20, 20, 20);
                            layoutParams.height = General.dpToPixels(context, 100);
                            captchaImg.setScaleType(ImageView.ScaleType.FIT_CENTER);

                            final EditText captchaText = new EditText(CaptchaActivity.this);
                            ll.addView(captchaText);
                            ((LinearLayout.LayoutParams) captchaText.getLayoutParams()).setMargins(20, 0, 20,
                                    20);
                            captchaText.setInputType(android.text.InputType.TYPE_CLASS_TEXT
                                    | android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
                                    | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);

                            captchaImg.setImageBitmap(image);

                            final Button submitButton = new Button(CaptchaActivity.this);
                            submitButton.setText(R.string.post_captcha_submit_button);
                            ll.addView(submitButton);
                            ((LinearLayout.LayoutParams) submitButton.getLayoutParams()).setMargins(20, 0, 20,
                                    20);
                            ((LinearLayout.LayoutParams) submitButton
                                    .getLayoutParams()).gravity = Gravity.RIGHT;
                            ((LinearLayout.LayoutParams) submitButton
                                    .getLayoutParams()).width = LinearLayout.LayoutParams.WRAP_CONTENT;

                            submitButton.setOnClickListener(new View.OnClickListener() {
                                public void onClick(View v) {
                                    final Intent result = new Intent();
                                    result.putExtra("captchaId", captchaId);
                                    result.putExtra("captchaText", captchaText.getText().toString());
                                    setResult(RESULT_OK, result);
                                    finish();
                                }
                            });

                            final ScrollView sv = new ScrollView(CaptchaActivity.this);
                            sv.addView(ll);
                            setContentView(sv);
                        }
                    });

                }
            });
        }

        @Override
        protected void onCallbackException(Throwable t) {
            BugReportActivity.handleGlobalError(CaptchaActivity.this, t);
        }

        @Override
        protected void onFailure(RequestFailureType type, Throwable t, StatusLine status,
                String readableMessage) {
            final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type, t, status);
            General.showResultDialog(CaptchaActivity.this, error);
            finish();
        }

        @Override
        protected void onFailure(APIFailureType type) {
            final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type);
            General.showResultDialog(CaptchaActivity.this, error);
            finish();
        }
    }, selectedAccount, this);
}

From source file:org.quantumbadger.redreader.activities.CaptchaActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);
    getSupportActionBar().setTitle(R.string.post_captcha_title);

    super.onCreate(savedInstanceState);

    final LoadingView loadingView = new LoadingView(this, R.string.download_waiting, true, true);
    setContentView(loadingView);/* w w w . jav  a  2 s. c  o  m*/

    final RedditAccount selectedAccount = RedditAccountManager.getInstance(this)
            .getAccount(getIntent().getStringExtra("username"));

    final CacheManager cm = CacheManager.getInstance(this);

    RedditAPI.newCaptcha(cm, new APIResponseHandler.NewCaptchaResponseHandler(this) {
        @Override
        protected void onSuccess(final String captchaId) {

            final URI captchaUrl = Constants.Reddit.getUri("/captcha/" + captchaId);

            cm.makeRequest(new CacheRequest(captchaUrl, RedditAccountManager.getAnon(), null,
                    Constants.Priority.CAPTCHA, 0, CacheRequest.DownloadType.FORCE, Constants.FileType.CAPTCHA,
                    false, false, true, CaptchaActivity.this) {
                @Override
                protected void onCallbackException(Throwable t) {
                    BugReportActivity.handleGlobalError(CaptchaActivity.this, t);
                }

                @Override
                protected void onDownloadNecessary() {
                }

                @Override
                protected void onDownloadStarted() {
                    loadingView.setIndeterminate(R.string.download_downloading);
                }

                @Override
                protected void onFailure(RequestFailureType type, Throwable t, StatusLine status,
                        String readableMessage) {
                    final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type, t,
                            status, url.toString());
                    General.showResultDialog(CaptchaActivity.this, error);
                    finish();
                }

                @Override
                protected void onProgress(long bytesRead, long totalBytes) {
                    loadingView.setProgress(R.string.download_downloading,
                            (float) ((double) bytesRead / (double) totalBytes));
                }

                @Override
                protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, long timestamp,
                        UUID session, boolean fromCache, String mimetype) {

                    final Bitmap image;
                    try {
                        image = BitmapFactory.decodeStream(cacheFile.getInputStream());
                    } catch (IOException e) {
                        BugReportActivity.handleGlobalError(CaptchaActivity.this, e);
                        return;
                    }

                    new Handler(Looper.getMainLooper()).post(new Runnable() {
                        public void run() {

                            final LinearLayout ll = new LinearLayout(CaptchaActivity.this);
                            ll.setOrientation(LinearLayout.VERTICAL);

                            final ImageView captchaImg = new ImageView(CaptchaActivity.this);
                            ll.addView(captchaImg);
                            final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) captchaImg
                                    .getLayoutParams();
                            layoutParams.setMargins(20, 20, 20, 20);
                            layoutParams.height = General.dpToPixels(context, 100);
                            captchaImg.setScaleType(ImageView.ScaleType.FIT_CENTER);

                            final EditText captchaText = new EditText(CaptchaActivity.this);
                            ll.addView(captchaText);
                            ((LinearLayout.LayoutParams) captchaText.getLayoutParams()).setMargins(20, 0, 20,
                                    20);
                            captchaText.setInputType(android.text.InputType.TYPE_CLASS_TEXT
                                    | android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
                                    | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);

                            captchaImg.setImageBitmap(image);

                            final Button submitButton = new Button(CaptchaActivity.this);
                            submitButton.setText(R.string.post_captcha_submit_button);
                            ll.addView(submitButton);
                            ((LinearLayout.LayoutParams) submitButton.getLayoutParams()).setMargins(20, 0, 20,
                                    20);
                            ((LinearLayout.LayoutParams) submitButton
                                    .getLayoutParams()).gravity = Gravity.RIGHT;
                            ((LinearLayout.LayoutParams) submitButton
                                    .getLayoutParams()).width = LinearLayout.LayoutParams.WRAP_CONTENT;

                            submitButton.setOnClickListener(new View.OnClickListener() {
                                public void onClick(View v) {
                                    final Intent result = new Intent();
                                    result.putExtra("captchaId", captchaId);
                                    result.putExtra("captchaText", captchaText.getText().toString());
                                    setResult(RESULT_OK, result);
                                    finish();
                                }
                            });

                            final ScrollView sv = new ScrollView(CaptchaActivity.this);
                            sv.addView(ll);
                            setContentView(sv);
                        }
                    });

                }
            });
        }

        @Override
        protected void onCallbackException(Throwable t) {
            BugReportActivity.handleGlobalError(CaptchaActivity.this, t);
        }

        @Override
        protected void onFailure(RequestFailureType type, Throwable t, StatusLine status,
                String readableMessage) {
            final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type, t, status,
                    null);
            General.showResultDialog(CaptchaActivity.this, error);
            finish();
        }

        @Override
        protected void onFailure(APIFailureType type) {
            final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type);
            General.showResultDialog(CaptchaActivity.this, error);
            finish();
        }
    }, selectedAccount, this);
}

From source file:co.mrktplaces.android.ui.views.smarttablayout.SmartTabLayout.java

private void populateTabStrip() {
    final TabAdapter adapter = (TabAdapter) viewPager.getAdapter();

    for (int i = 0; i < adapter.getCount(); i++) {

        ImageView tabIconView = null;

        final View tabView = (tabProvider == null) ? createDefaultTabView(adapter.getDrawableId(i))
                : tabProvider.createTabView(tabStrip, i, adapter);

        if (tabView == null) {
            throw new IllegalStateException("tabView is null.");
        }/*  w w w. j  a  va 2  s  .c om*/

        if (distributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        if (ImageView.class.isInstance(tabView)) {
            tabIconView = (ImageView) tabView;
        }

        if (tabIconView != null) {
            tabIconView.setImageResource(adapter.getDrawableId(i));
            if (viewPager.getCurrentItem() == i) {
                tabIconView.setSelected(true);
            }
        }

        if (internalTabClickListener != null) {
            tabView.setOnClickListener(internalTabClickListener);
        }

        if (i == 1) {
            View view = LayoutInflater.from(getContext()).inflate(R.layout.counter, tabStrip, false);
            FrameLayout counterLayout = (FrameLayout) view.findViewById(R.id.counter_layout);
            messageBackground = (ImageView) view.findViewById(R.id.message_background);
            counter = (TextView) view.findViewById(R.id.counter);
            counter.setText(String.valueOf(messageCount));
            ImageView imageView = new ImageView(getContext());
            imageView.setImageResource(adapter.getDrawableId(i));
            imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            counterLayout.addView(imageView, 0);
            if (internalTabClickListener != null) {
                view.setOnClickListener(internalTabClickListener);
            }
            if (messageCount > 0) {
                messageBackground.setVisibility(VISIBLE);
                counter.setVisibility(VISIBLE);
            } else {
                messageBackground.setVisibility(GONE);
                counter.setVisibility(GONE);
            }
            tabStrip.addView(view);
        } else {
            tabStrip.addView(tabView);
        }

        if (i == viewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }

    }
}

From source file:com.android.camera.v2.uimanager.SettingManager.java

private void initializeSettings() {
    if (mSettingLayout == null) {
        mSettingLayout = (ViewGroup) mActivity.getLayoutInflater().inflate(R.layout.setting_container_v2,
                mSettingViewLayer, false);
        mTabHost = (TabHost) mSettingLayout.findViewById(R.id.tab_title);
        mTabHost.setup();//  w  w w.  jav a  2  s.  c om
        String action = mIntent.getAction();
        LogHelper.i(TAG, "intent.action:" + action);
        List<Holder> list = new ArrayList<Holder>();
        // default setting
        int commonKeys[] = SettingKeys.SETTING_GROUP_COMMON_FOR_TAB;
        int cameraKeys[] = SettingKeys.SETTING_GROUP_CAMERA_FOR_TAB;
        int videoKeys[] = SettingKeys.SETTING_GROUP_VIDEO_FOR_TAB;

        if (FeatureSwitcher.isSubSettingEnabled()) {
            // For tablet
            commonKeys = SettingKeys.SETTING_GROUP_MAIN_COMMON_FOR_TAB;
        } else if (FeatureSwitcher.isLomoEffectEnabled()) {
            commonKeys = SettingKeys.SETTING_GROUP_COMMON_FOR_LOMOEFFECT;
        }
        // image capture setting, compared to default setting,
        // common settings and video setting may be different.
        if (MediaStore.ACTION_IMAGE_CAPTURE.equals(action)) {
            videoKeys = null;
        }
        // image capture setting, compared to default setting,
        // common settings and video setting
        // may be different.
        if (MediaStore.ACTION_VIDEO_CAPTURE.equals(action)) {
            cameraKeys = null;
        }

        if (commonKeys != null) {
            list.add(new Holder(TAB_INDICATOR_KEY_COMMON, R.drawable.ic_tab_common_setting, commonKeys));
        }
        if (cameraKeys != null) {
            list.add(new Holder(TAB_INDICATOR_KEY_CAMERA, R.drawable.ic_tab_camera_setting, cameraKeys));
        }
        if (videoKeys != null) {
            list.add(new Holder(TAB_INDICATOR_KEY_VIDEO, R.drawable.ic_tab_video_setting, videoKeys));
        }

        int size = list.size();
        List<SettingListLayout> pageViews = new ArrayList<SettingListLayout>();
        for (int i = 0; i < size; i++) {
            Holder holder = list.get(i);
            // new page view
            SettingListLayout pageView = (SettingListLayout) mActivity.getLayoutInflater()
                    .inflate(R.layout.setting_list_layout_v2, mSettingViewLayer, false);
            ArrayList<ListPreference> listItems = new ArrayList<ListPreference>();
            pageView.setRootView(mSettingViewLayer);
            pageView.initialize(getListPreferences(holder.mSettingKeys, i == 0));
            pageView.setSettingChangedListener(SettingManager.this);
            pageViews.add(pageView);
            // new indicator view
            ImageView indicatorView = new ImageView(mActivity);
            if (indicatorView != null) {
                indicatorView.setBackgroundResource(R.drawable.bg_tab_title);
                indicatorView.setImageResource(holder.mIndicatorIconRes);
                indicatorView.setScaleType(ScaleType.CENTER);
            }
            mTabHost.addTab(mTabHost.newTabSpec(holder.mIndicatorKey).setIndicator(indicatorView)
                    .setContent(android.R.id.tabcontent));
        }

        mAdapter = new MyPagerAdapter(pageViews);
        mPager = (ViewPager) mSettingLayout.findViewById(R.id.pager);
        mPager.setAdapter(mAdapter);
        mPager.setOnPageChangeListener(mAdapter);
        mTabHost.setOnTabChangedListener(this);
    }
    int orientation = (Integer) mSettingViewLayer.getTag();
    CameraUtil.setOrientation(mSettingLayout, orientation, false);
}

From source file:org.ayo.robot.anim.transitioneverywhere.ImageTransformSample.java

@Nullable
@Override//  ww  w .  j  a v a  2s . c o m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_image_transform, container, false);

    final ViewGroup transitionsContainer = (ViewGroup) view.findViewById(R.id.transitions_container);
    final ImageView imageView = (ImageView) transitionsContainer.findViewById(R.id.image);

    imageView.setOnClickListener(new View.OnClickListener() {

        boolean mExpanded;

        @Override
        public void onClick(View v) {
            mExpanded = !mExpanded;

            TransitionManager.beginDelayedTransition(transitionsContainer, new TransitionSet()
                    .addTransition(new ChangeBounds()).addTransition(new ChangeImageTransform()));

            ViewGroup.LayoutParams params = imageView.getLayoutParams();
            params.height = mExpanded ? ViewGroup.LayoutParams.MATCH_PARENT
                    : ViewGroup.LayoutParams.WRAP_CONTENT;
            imageView.setLayoutParams(params);

            imageView
                    .setScaleType(mExpanded ? ImageView.ScaleType.CENTER_CROP : ImageView.ScaleType.FIT_CENTER);
        }
    });

    return view;
}

From source file:com.brodev.socialapp.view.MarketPlaceDetail.java

private void initView() {

    ImageView userImage = (ImageView) this.findViewById(R.id.image_user);

    if (!"".equals(marketPlace.getUser_image_path())) {
        networkUntil.drawImageUrl(userImage, marketPlace.getUser_image_path(), R.drawable.loading);
    }//from   w  w w .ja va  2  s.  c  o m

    userImage.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Intent intent = new Intent(MarketPlaceDetail.this, FriendTabsPager.class);
            intent.putExtra("user_id", marketPlace.getUser_id());
            startActivity(intent);
            return false;
        }
    });

    // set title
    TextView title = (TextView) this.findViewById(R.id.title);
    title.setText(marketPlace.getTitle());
    colorView.changeColorText(title, user.getColor());

    // set content
    TextView content = (TextView) this.findViewById(R.id.content);

    // interesting part starts from here here:
    Html.ImageGetter ig = imageGetter.create(0, marketPlace.getText(), content);

    content.setTag(0);
    content.setText(Html.fromHtml(marketPlace.getText(), ig, null));

    TextView timestampTxt = (TextView) findViewById(R.id.txtTimestamp);
    timestampTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.posted_on"));
    TextView timestamp = (TextView) findViewById(R.id.time_stamp);
    timestamp.setText(marketPlace.getTime_stamp());
    TextView price = (TextView) this.findViewById(R.id.price);

    if (marketPlace.getPrice() == 0) {
        price.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.free"));
    } else {
        price.setText(marketPlace.getCurrency() + " " + marketPlace.getPrice());
    }

    TextView locationTxt = (TextView) findViewById(R.id.txtLocation);
    locationTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.location"));
    TextView txtLocation = (TextView) this.findViewById(R.id.location);
    String location = marketPlace.getCountry_name();

    if (!marketPlace.getCountry_child_name().equals("")) {
        location += " > " + marketPlace.getCountry_child_name();
    }
    if (!marketPlace.getCity_name().equals("")) {
        location += " > " + marketPlace.getCity_name();
    }

    txtLocation.setText(location);
    // set short text
    TextView fullnameTxt = (TextView) findViewById(R.id.txtFullname);
    fullnameTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.posted_by"));

    TextView shortText = (TextView) findViewById(R.id.fullName);
    shortText.setText(marketPlace.getFull_name());
    colorView.changeColorText(shortText, user.getColor());

    shortText.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Intent intent = new Intent(MarketPlaceDetail.this, FriendTabsPager.class);
            intent.putExtra("user_id", marketPlace.getUser_id());
            startActivity(intent);
            return false;
        }
    });

    TextView total_like = (TextView) findViewById(R.id.total_like);
    total_like.setText(String.valueOf(marketPlace.getTotal_like()));
    colorView.changeColorText(total_like, user.getColor());

    TextView total_comment = (TextView) findViewById(R.id.total_comment);
    total_comment.setText(String.valueOf(marketPlace.getTotal_comment()));
    colorView.changeColorText(total_comment, user.getColor());

    ImageView likeImg = (ImageView) this.findViewById(R.id.likes_feed_txt);
    ImageView commentImg = (ImageView) this.findViewById(R.id.comments_feed_txt);
    colorView.changeColorLikeCommnent(likeImg, commentImg, user.getColor());

    //get list images
    if (!marketPlace.getImages().equals("")) {
        LinearLayout listImages = (LinearLayout) findViewById(R.id.listImages);
        JSONObject objOutputImage = null;
        try {
            JSONArray objImages = new JSONArray(marketPlace.getImages());
            for (int i = 0; i < objImages.length(); i++) {
                objOutputImage = objImages.getJSONObject(i);
                ImageView imageView = new ImageView(getApplicationContext());

                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                        (int) getResources().getDimension(R.dimen.marketplace_image),
                        (int) getResources().getDimension(R.dimen.marketplace_image));

                lp.setMargins(5, 5, 5, 0);

                imageView.setLayoutParams(lp);

                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                final String imagePath = objOutputImage.getString("image_path");
                networkUntil.drawImageUrl(imageView, imagePath, R.drawable.loading);

                imageView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getApplicationContext(), ImageActivity.class);
                        intent.putExtra("image", imagePath);
                        intent.putExtra("title", marketPlace.getTitle());
                        startActivity(intent);
                    }
                });

                listImages.addView(imageView);

            }

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        this.findViewById(R.id.horizontalScrollView1).setVisibility(View.GONE);
        this.findViewById(R.id.marketplace_list_image_view).setVisibility(View.GONE);
    }

}

From source file:ca.ualberta.cs.swapmyride.View.AddInventoryActivity.java

/**
 * In this function (prescribed by Android), we collect all information
 * about the new vehicle and input it into a vehicle object.
 * This is then saved./*from  w w w  . ja  v  a  2  s  .  c  o  m*/
 *
 * @param savedInstanceState
 */

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addinventory);
    toolbar = (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(toolbar);
    uController = new UserController(getApplicationContext());
    // TODO: Needs to smell more MVCish
    //vehicleImage = (ImageButton) findViewById(R.id.vehicleImage);
    gallery = (LinearLayout) findViewById(R.id.addinventorygallery);
    delete = (Button) findViewById(R.id.delete);
    vehicleName = (EditText) findViewById(R.id.vehicleField);
    vehicleQuantity = (EditText) findViewById(R.id.quantityField);
    vehicleComments = (EditText) findViewById(R.id.commentsField);
    vehiclePublic = (Switch) findViewById(R.id.ispublic);
    done = (Button) findViewById(R.id.button);
    location = (EditText) findViewById(R.id.locationField);
    vehicle = new Vehicle();

    //Assign and display the current location
    geolocation = new Geolocation();
    try {
        current = geolocation.getCurrentLocation(getApplicationContext(), this);
        location.setText(current.getPostalCode());
    } catch (IllegalArgumentException e) {
        location.setText("Geolocation cannot be determined.");
    }

    /**
     * Using spinners to select category and quality of a vehicle - taking from the enumeration
     * classes we have elsewhere. This function was adapted from Biraj Zalavadia on StackOverflow
     * Accessed 2015-11-01
     * @see <a href="http://stackoverflow.com/questions/21600781/onitemclicklistener-of-spinner">stackOverflow</a>
     */
    categorySpinner = (Spinner) findViewById(R.id.categorySpinner);
    categorySpinner.setAdapter(new ArrayAdapter<VehicleCategory>(this,
            android.R.layout.simple_spinner_dropdown_item, VehicleCategory.values()));
    categorySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            vehicleCategory = (VehicleCategory) categorySpinner.getSelectedItem();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // What if nothing selected?
        }
    });

    /**
     * Using spinners to select category and quality of a vehicle - taking from the enumeration
     * classes we have elsewhere. This function was adapted from Biraj Zalavadia on StackOverflow
     * Accessed 2015-11-01
     * @see <a href="http://stackoverflow.com/questions/21600781/onitemclicklistener-of-spinner">stackOverflow</a>
     */
    qualitySpinner = (Spinner) findViewById(R.id.qualitySpinner);
    qualitySpinner.setAdapter(new ArrayAdapter<VehicleQuality>(this,
            android.R.layout.simple_spinner_dropdown_item, VehicleQuality.values()));
    qualitySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            vehicleQuality = (VehicleQuality) qualitySpinner.getSelectedItem();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // What if nothing selected?
        }
    });

    final boolean loadVehicle = getIntent().hasExtra("vehiclePosition");
    Vehicle loaded;
    if (loadVehicle) {
        position = getIntent().getIntExtra("vehiclePosition", 0);
        loaded = UserSingleton.getCurrentUser().getInventory().getList().get(position);

        //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE
        //load the picture from the first
        vehicle.setPhotoIds(loaded.getPhotoIds());

        vehicleName.setText(loaded.getName());
        vehicleQuantity.setText(loaded.getQuantity().toString());
        vehicleComments.setText(loaded.getComments());
        vehiclePublic.setChecked(loaded.getPublic());
        qualitySpinner.setSelection(loaded.getQuality().getPosition());
        categorySpinner.setSelection(loaded.getCategory().getPosition());
        // TODO: Fix null error issue
        //location.setText(loaded.getLocation().getPostalCode());
        LocalDataManager ldm = new LocalDataManager(getApplicationContext());
        for (UniqueID uid : vehicle.getPhotoIds()) {
            photos.add(ldm.loadPhoto(uid.getID()));
        }
        for (Photo photo : photos) {
            ImageView newImage = new ImageView(getApplicationContext());
            newImage.setImageBitmap(photo.getImage());
            newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            newImage.setAdjustViewBounds(true);
            gallery.addView(newImage);
        }

    }

    //default the photo to a new photo if we are not loading a vehicle
    else {
        // TODO: Default photo? Here or set in Vehicle?
        Photo photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto();
        ImageView newImage = new ImageView(getApplicationContext());
        newImage.setImageBitmap(photo.getImage());
        newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        newImage.setAdjustViewBounds(true);
        gallery.addView(newImage);
        vehicle.deletePhotoArrayList(getApplicationContext());
    }

    LocalDataManager ldm = new LocalDataManager(getApplicationContext());

    //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE
    //load the picture from the first
    for (UniqueID uid : vehicle.getPhotoIds()) {
        Photo photo;
        if (UserSingleton.getDownloadPhotos()) {
            photo = ldm.loadPhoto(uid.getID());
        } else {
            photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto();
        }
        ImageView newImage = new ImageView(getApplicationContext());
        newImage.setImageBitmap(photo.getImage());
        newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        newImage.setAdjustViewBounds(true);
        gallery.addView(newImage);
    }
    /**
     * This onClick listener implements the function that clicking on the default
     * image box at the top of the vehicle page will open the camera and allow the
     * user to take a photo which will be saved directly to the vehicle object
     */
    gallery.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            dispatchTakePictureIntent();

        }
    });

    /**
     * This onClick listener occurs when someone clicks delete. This will delete the photo
     * that is initialized in the view.
     */
    delete.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //vehicle.setPhoto(new Photo(getApplicationContext()));
            //vehicleImage.setBackground(new BitmapDrawable(getResources(), vehicle.getPhoto().getImage()));
            vehicle.deletePhotoArrayList(getApplicationContext());
            gallery.removeAllViews();
            Photo photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto();
            ImageView newImage = new ImageView(getApplicationContext());
            newImage.setImageBitmap(photo.getImage());
            newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            newImage.setAdjustViewBounds(true);
            gallery.addView(newImage);
            LocalDataManager ldm = new LocalDataManager(getApplicationContext());
            for (Photo photo1 : photos) {
                ldm.deletePhoto(photo1.getUid().getID());
            }
            photos.clear();

            //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE
            //load the picture from the first
            if (vehicle.getPhotoIds().size() > 0 && UserSingleton.getDownloadPhotos()) {
                gallery.removeAllViews();
            }

            for (UniqueID uid : vehicle.getPhotoIds()) {
                if (UserSingleton.getDownloadPhotos()) {
                    photo = ldm.loadPhoto(uid.getID());
                }
                newImage = new ImageView(getApplicationContext());
                newImage.setImageBitmap(photo.getImage());
                newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                newImage.setAdjustViewBounds(true);
                gallery.addView(newImage);
            }
        }
    });

    /**
     * This onClick listener occurs after done button is clicked. This would save
     * the object to inventory -- which then makes it appear in the inventory tab.
     *
     * Taken from Oracle Documentation - we found we were required to catch the
     * possibility that a number might be the wrong format, or not even a number
     * at all. Accessed November 3, 2015.
     *
     * @see <a href="http://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#parseInt-java.lang.String-int-">Oracle</a>
     */

    done.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // vehicle.setPhoto(vehicleImage);
            Geolocation geolocation1 = new Geolocation();
            LocalDataManager ldm = new LocalDataManager(getApplicationContext());

            if (vehicleName.getText().toString().equals("")) {
                Toast.makeText(AddInventoryActivity.this, "Please enter name", Toast.LENGTH_SHORT).show();
                return;
            }

            if (vehicleQuantity.getText().toString().equals("0")
                    || vehicleQuantity.getText().toString().equals("")) {
                Toast.makeText(AddInventoryActivity.this, "Quantity cannot be 0", Toast.LENGTH_SHORT).show();
                return;
            }
            vehicle.setName(vehicleName.getText().toString());

            vehicle.setCategory(vehicleCategory);
            vehicle.setQuality(vehicleQuality);
            vehicle.setLocation(geolocation1.setSpecificLocation(getApplicationContext(),
                    AddInventoryActivity.this, location.getText().toString()));

            //http://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#parseInt-java.lang.String-int-
            //Nov. 3/ 2015
            //the error should never occur as we force the user to input a numeric value, but
            //we are required to catch it anyway
            try {
                vehicle.setQuantity(Integer.parseInt(vehicleQuantity.getText().toString()));
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
            vehicle.setComments(vehicleComments.getText().toString());
            vehicle.setPublic(vehiclePublic.isChecked());
            vehicle.setBelongsTo(UserSingleton.getCurrentUser().getUserName());

            for (Photo photo : photos) {
                vehicle.addPhoto(photo.getUid());
                ldm.savePhoto(photo);
            }

            //add the vehicle to our current user.
            if (loadVehicle) {
                //UserSingleton.getCurrentUser().getInventory().getList().add(position, vehicle);
                uController.getUserInventoryItems().add(position, vehicle);
                //UserSingleton.getCurrentUser().getInventory().getList().remove(position+1);
                uController.getUserInventoryItems().remove(position + 1);
            } else {
                //UserSingleton.getCurrentUser().addItem(vehicle);
                uController.getCurrentUser().addItem(vehicle);
            }
            //save the user to ensure all changes are updated
            uController.saveCurrentUser();
            Gson gson = new Gson();
            String s = gson.toJson(vehicle);
            Log.i("SizeOfCar", Integer.toString(s.length()));

            /*
            //dont start a new activity if we are editing a vehicle
            if(!loadVehicle) {
            Intent intent = new Intent(AddInventoryActivity.this, MainMenu.class);
            startActivity(intent);
            }*/
            finish();
        }
    });

    gallery.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            vehicle.deletePhotoArrayList(getApplicationContext());
            gallery.removeAllViews();
            LocalDataManager ldm = new LocalDataManager(getApplicationContext());

            //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE
            //load the picture from the first
            for (UniqueID uid : vehicle.getPhotoIds()) {
                Photo photo;
                if (UserSingleton.getDownloadPhotos()) {
                    photo = ldm.loadPhoto(uid.getID());
                } else {
                    photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto();
                }
                ImageView newImage = new ImageView(getApplicationContext());
                newImage.setImageBitmap(photo.getImage());
                newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                newImage.setAdjustViewBounds(true);
                gallery.addView(newImage);
            }
            return true;
        }
    });

}