Example usage for android.widget ImageView getContext

List of usage examples for android.widget ImageView getContext

Introduction

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

Prototype

@ViewDebug.CapturedViewProperty
public final Context getContext() 

Source Link

Document

Returns the context the view is running in, through which it can access the current theme, resources, etc.

Usage

From source file:com.example.imagegallerydemo.photoview.PhotoViewAttacher.java

@Override
public void onFling(float startX, float startY, float velocityX, float velocityY) {
    if (DEBUG) {/*from www  . ja  v a2s . co  m*/
        Log.d(LOG_TAG, "onFling. sX: " + startX + " sY: " + startY + " Vx: " + velocityX + " Vy: " + velocityY);
    }
    ImageView imageView = getImageView();
    mCurrentFlingRunnable = new FlingRunnable(imageView.getContext());
    mCurrentFlingRunnable.fling(getImageViewWidth(imageView), getImageViewHeight(imageView), (int) velocityX,
            (int) velocityY);
    imageView.post(mCurrentFlingRunnable);
}

From source file:com.zxj.androidmvvm.common.view.photoview.PhotoViewAttacher.java

@Override
public void onFling(float startX, float startY, float velocityX, float velocityY) {
    if (DEBUG) {/*from ww w. ja  v  a 2s .co m*/
        ILog.d("onFling. sX: " + startX + " sY: " + startY + " Vx: " + velocityX + " Vy: " + velocityY);
    }
    ImageView imageView = getImageView();
    mCurrentFlingRunnable = new FlingRunnable(imageView.getContext());
    mCurrentFlingRunnable.fling(getImageViewWidth(imageView), getImageViewHeight(imageView), (int) velocityX,
            (int) velocityY);
    imageView.post(mCurrentFlingRunnable);
}

From source file:com.sflib.CustomView.photoview.PhotoViewAttacher.java

@Override
public void onFling(float startX, float startY, float velocityX, float velocityY) {
    if (DEBUG) {//from   w  w  w .  j a  va2  s .c  o m
        L.debug(LOG_TAG,
                "onFling. sX: " + startX + " sY: " + startY + " Vx: " + velocityX + " Vy: " + velocityY);
    }
    ImageView imageView = getImageView();
    mCurrentFlingRunnable = new FlingRunnable(imageView.getContext());
    mCurrentFlingRunnable.fling(getImageViewWidth(imageView), getImageViewHeight(imageView), (int) velocityX,
            (int) velocityY);
    imageView.post(mCurrentFlingRunnable);
}

From source file:com.neo.duan.ui.widget.photoview.PhotoViewAttacher.java

@Override
public void onFling(float startX, float startY, float velocityX, float velocityY) {
    //        if (DEBUG) {
    //            LogManager.getLogger().d(
    //                    LOG_TAG,
    //                    "onFling. sX: " + startX + " sY: " + startY + " Vx: "
    //                            + velocityX + " Vy: " + velocityY);
    //        }/*  w w w . j  ava2s  .  co  m*/
    ImageView imageView = getImageView();
    mCurrentFlingRunnable = new FlingRunnable(imageView.getContext());
    mCurrentFlingRunnable.fling(getImageViewWidth(imageView), getImageViewHeight(imageView), (int) velocityX,
            (int) velocityY);
    imageView.post(mCurrentFlingRunnable);
}

From source file:xue.myapp.common.photoview.PhotoViewAttacher.java

@Override
public void onFling(float startX, float startY, float velocityX, float velocityY) {
    if (DEBUG) {/*  w ww  . j  a va 2s . c om*/
        LogUtil.d(LOG_TAG,
                "onFling. sX: " + startX + " sY: " + startY + " Vx: " + velocityX + " Vy: " + velocityY);
    }
    ImageView imageView = getImageView();
    mCurrentFlingRunnable = new FlingRunnable(imageView.getContext());
    mCurrentFlingRunnable.fling(getImageViewWidth(imageView), getImageViewHeight(imageView), (int) velocityX,
            (int) velocityY);
    imageView.post(mCurrentFlingRunnable);
}

From source file:com.kf5.sdk.system.photoview.PhotoViewAttacher.java

@Override
public void onFling(float startX, float startY, float velocityX, float velocityY) {
    if (DEBUG) {/*w w  w  . j  av  a2  s  .  c o  m*/
    }
    ImageView imageView = getImageView();
    mCurrentFlingRunnable = new FlingRunnable(imageView.getContext());
    mCurrentFlingRunnable.fling(getImageViewWidth(imageView), getImageViewHeight(imageView), (int) velocityX,
            (int) velocityY);
    imageView.post(mCurrentFlingRunnable);
}

From source file:com.rbsoftware.pfm.personalfinancemanager.MainActivity.java

/**
 * Creates navigation drawer/*from  w w w  . j a v  a 2  s  .c o m*/
 *
 * @param savedInstanceState of activity
 * @param toolbar            of activity
 * @param intent             received after login
 */
private void setupNavigationDrawer(final Bundle savedInstanceState, Toolbar toolbar, Intent intent) {
    AccountDocument accountDocument = financeDocumentModel
            .getAccountDocument(AccountDocument.ACCOUNT_DOCUMENT_ID + getUserId());
    if (accountDocument == null) {
        HashMap<String, List<String>> values = new HashMap<>();
        List<String> mainAccount = new ArrayList<>();
        mainAccount.add(getString(R.string.main_wallet));
        values.put(FinanceDocument.MAIN_ACCOUNT, mainAccount);
        accountDocument = new AccountDocument(MainActivity.getUserId(), values);
        MainActivity.financeDocumentModel.createDocument(accountDocument);

    }
    final HashMap<String, List<String>> accountsMap = accountDocument.getAccountsMap();
    ArrayList<ProfileDrawerItem> profiles = new ArrayList<>();
    for (Map.Entry<String, List<String>> entry : accountsMap.entrySet()) {
        ProfileDrawerItem profileDrawerItem;
        if (intent.getStringExtra("photoURL") != null) {
            profileDrawerItem = new ProfileDrawerItem().withName(intent.getStringExtra("name"))
                    .withEmail(entry.getValue().get(0)).withIcon(intent.getStringExtra("photoURL"));
        } else {
            profileDrawerItem = new ProfileDrawerItem().withName(intent.getStringExtra("name"))
                    .withEmail(entry.getValue().get(0));
        }
        profiles.add(profileDrawerItem);
    }
    //Set up image loading through Picasso
    DrawerImageLoader.init(new AbstractDrawerImageLoader() {
        @Override
        public void set(ImageView imageView, Uri uri, Drawable placeholder) {
            if (uri != null) {
                Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
            }
        }

        @Override
        public void cancel(ImageView imageView) {
            Picasso.with(imageView.getContext()).cancelRequest(imageView);
        }

    });
    // Create the AccountHeader
    drawerAccountHeader = new AccountHeaderBuilder().withActivity(this)

            .withHeaderBackground(R.drawable.account_header_background)
            .addProfiles(profiles.toArray(new ProfileDrawerItem[profiles.size()]))
            .withOnlyMainProfileImageVisible(true).withProfileImagesClickable(false)
            .withSavedInstance(savedInstanceState)
            .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
                @Override
                public boolean onProfileChanged(View view, IProfile profile, boolean current) {
                    for (Map.Entry<String, List<String>> entry : getAccountsMap().entrySet()) {
                        if (entry.getValue().get(0).equals(profile.getEmail().toString())) {
                            mActiveAccountId = entry.getKey();
                            break;
                        }
                    }
                    //checking if orientation has been changed
                    //if not reload data
                    int prevState = orientationState;
                    if (savedInstanceState != null) {
                        prevState = savedInstanceState.getInt("screenOrientation");
                        savedInstanceState.putInt("screenOrientation",
                                getResources().getConfiguration().orientation);
                    }
                    if (!Utils.isOrientationChanged(getApplicationContext(), prevState)) {
                        reloadFragmentData();
                    }
                    return false;
                }
            }).build();

    //Setting default account
    for (IProfile profile : profiles) {

        String accountName = getString(R.string.main_wallet);
        if (savedInstanceState != null) {
            accountName = savedInstanceState.getString("activeAccountName");
        }

        if (profile.getEmail().getText().equals(accountName)) {
            drawerAccountHeader.setActiveProfile(profile, true);
        }
    }

    //Build navigation drawer
    DrawerBuilder drawerBuilder = new DrawerBuilder().withActivity(this).withToolbar(toolbar)
            .withAccountHeader(drawerAccountHeader).withDelayDrawerClickEvent(0)
            .addDrawerItems(
                    new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[0])
                            .withIcon(GoogleMaterial.Icon.gmd_dashboard),
                    new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[1])
                            .withIcon(GoogleMaterial.Icon.gmd_book),
                    new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[2])
                            .withIcon(GoogleMaterial.Icon.gmd_monetization_on),
                    new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[3])
                            .withIcon(GoogleMaterial.Icon.gmd_pie_chart),
                    new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[4])
                            .withIcon(GoogleMaterial.Icon.gmd_credit_card),
                    new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[5])
                            .withIcon(GoogleMaterial.Icon.gmd_history),

                    new DividerDrawerItem(),
                    new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[6])
                            .withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_star),
                    new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[7])
                            .withIcon(GoogleMaterial.Icon.gmd_add_circle),
                    new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[8])
                            .withIcon(GoogleMaterial.Icon.gmd_account_balance_wallet),
                    new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[9])
                            .withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_settings),
                    new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[10])
                            .withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_exit_to_app))

            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                    if (position == 11) {
                        Intent i = new Intent(MainActivity.this, SettingsActivity.class);
                        startActivityForResult(i, MainActivity.RESULT_OK);
                        return true;
                    } else if (position == 8) {
                        recommendToFriend();
                    } else if (position == 12) {
                        signout();
                        return true;

                    } else {
                        openFragment(position);
                    }
                    return false;
                }
            })

            .withSavedInstance(savedInstanceState);

    //make multipane layout for tablets in landscape orientation
    if (Utils.isTablet(this)
            && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        drawerBuilder.withTranslucentStatusBar(false).withTranslucentNavigationBar(false);

        mMaterialDrawer = drawerBuilder.buildView();
        ((ViewGroup) findViewById(R.id.nav_tablet)).addView(mMaterialDrawer.getSlider());
    } else {
        mMaterialDrawer = drawerBuilder.build();
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(false);
            mMaterialDrawer.getActionBarDrawerToggle().setDrawerIndicatorEnabled(true);
        }
    }

}

From source file:com.tjw.selectimage.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView) {
    mImageView = imageView;//  w ww . java2  s.  com
    imageView.setOnTouchListener(this);
    imageView.addOnLayoutChangeListener(this);

    if (imageView.isInEditMode()) {
        return;
    }

    mBaseRotation = 0.0f;

    // Create Gesture Detectors...
    mScaleDragDetector = new CustomGestureDetector(imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (mLongClickListener != null) {
                        mLongClickListener.onLongClick(mImageView);
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    mGestureDetector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (mOnClickListener != null) {
                mOnClickListener.onClick(mImageView);
            }
            final RectF displayRect = getDisplayRect();

            if (displayRect != null) {
                final float x = e.getX(), y = e.getY();

                // Check to see if the user tapped on the photo
                if (displayRect.contains(x, y)) {

                    float xResult = (x - displayRect.left) / displayRect.width();
                    float yResult = (y - displayRect.top) / displayRect.height();

                    if (mPhotoTapListener != null) {
                        mPhotoTapListener.onPhotoTap(mImageView, xResult, yResult);
                    }
                    return true;
                } else {
                    if (mOutsidePhotoTapListener != null) {
                        mOutsidePhotoTapListener.onOutsidePhotoTap(mImageView);
                    }
                }
            }
            return false;
        }

        @Override
        public boolean onDoubleTap(MotionEvent ev) {
            try {
                float scale = getScale();
                float x = ev.getX();
                float y = ev.getY();

                if (scale < getMediumScale()) {
                    setScale(getMediumScale(), x, y, true);
                } else if (scale >= getMediumScale() && scale < getMaximumScale()) {
                    setScale(getMaximumScale(), x, y, true);
                } else {
                    setScale(getMinimumScale(), x, y, true);
                }
            } catch (ArrayIndexOutOfBoundsException e) {
                // Can sometimes happen when getX() and getY() is called
            }

            return true;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            // Wait for the confirmed onDoubleTap() instead
            return false;
        }
    });
}

From source file:com.cylan.jiafeigou.support.photoview.PhotoViewAttacher.java

@Override
public void onFling(float startX, float startY, float velocityX, float velocityY) {
    if (DEBUG) {//  w w  w  . j  a v a2 s  .  c  o m
        //            LogManager.getLogger().d(
        //                    LOG_TAG,
        //                    "onFling. sX: " + startX + " sY: " + startY + " Vx: "
        //                            + velocityX + " Vy: " + velocityY);
    }
    ImageView imageView = getImageView();
    mCurrentFlingRunnable = new FlingRunnable(imageView.getContext());
    mCurrentFlingRunnable.fling(getImageViewWidth(imageView), getImageViewHeight(imageView), (int) velocityX,
            (int) velocityY);
    imageView.post(mCurrentFlingRunnable);
}

From source file:com.github.lakeshire.photoview.PhotoViewAttacher.java

@Override
public void onFling(float startX, float startY, float velocityX, float velocityY) {
    if (DEBUG) {/*ww w  . j  a va 2 s.  c  o m*/
        //            LogManager.getLogger().d(LOG_TAG, "onFling. sX: " + startX + " sY: " + startY + " Vx: " + velocityX + " Vy: " + velocityY);
    }
    ImageView imageView = getImageView();
    mCurrentFlingRunnable = new FlingRunnable(imageView.getContext());
    mCurrentFlingRunnable.fling(getImageViewWidth(imageView), getImageViewHeight(imageView), (int) velocityX,
            (int) velocityY);
    imageView.post(mCurrentFlingRunnable);
}