Example usage for android.view View getLocationOnScreen

List of usage examples for android.view View getLocationOnScreen

Introduction

In this page you can find the example usage for android.view View getLocationOnScreen.

Prototype

public void getLocationOnScreen(@Size(2) int[] outLocation) 

Source Link

Document

Computes the coordinates of this view on the screen.

Usage

From source file:us.phyxsi.gameshelf.ui.HomeActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_sort:
        final SharedPreferences prefs = getApplicationContext()
                .getSharedPreferences(BoardgameComparator.SORT_PREF, Context.MODE_PRIVATE);
        final SharedPreferences.Editor editor = prefs.edit();

        new AlertDialog.Builder(HomeActivity.this).setTitle(getString(R.string.sort_title))
                .setSingleChoiceItems(R.array.sort_options, prefs.getInt(BoardgameComparator.KEY_SORT_ORDER, 0),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                editor.putInt(BoardgameComparator.KEY_SORT_ORDER, which);
                                editor.commit();
                            }/*from  ww  w  .j a v a 2s  . co  m*/
                        })
                .setPositiveButton(getString(R.string.dialog_sort), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        adapter.sort();
                    }
                }).setNegativeButton(getString(R.string.dialog_cancel), null).show();

        return true;
    case R.id.menu_search:
        // get the icon's location on screen to pass through to the search screen
        View searchMenuView = toolbar.findViewById(R.id.menu_search);
        int[] loc = new int[2];
        searchMenuView.getLocationOnScreen(loc);
        startActivityForResult(
                SearchActivity.createStartIntent(this, loc[0], loc[0] + (searchMenuView.getWidth() / 2)),
                RC_SEARCH, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
        searchMenuView.setAlpha(0f);
        return true;
    case R.id.menu_import:
        if (!bggPrefs.isLoggedIn()) {
            startActivityForResult(new Intent(this, BGGLogin.class), RC_IMPORT);

        } else {
            bggPrefs.logout();
            // TODO something better than a toast!!
            Toast.makeText(getApplicationContext(), R.string.bgg_logged_out, Toast.LENGTH_SHORT).show();
        }
        return true;
    case R.id.menu_about:
        startActivity(new Intent(HomeActivity.this, AboutActivity.class),
                ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.tsoliveira.android.listeners.DragDropTouchListener.java

private int[] getViewRawCoords(View locateView) {
    View globalView = activity.findViewById(android.R.id.content);
    int topOffset = displayMetrics.heightPixels - globalView.getMeasuredHeight();
    int[] loc = new int[2];
    locateView.getLocationOnScreen(loc);
    loc[1] = loc[1] - topOffset;// ww w . j  a  v  a  2  s  .c o m
    return loc;
}

From source file:dg.shenm233.drag2expandview.Drag2ExpandView.java

private boolean isViewUnder(View view, int x, int y) {
    if (view == null)
        return false;
    int[] viewLocation = new int[2];
    view.getLocationOnScreen(viewLocation);
    int[] parentLocation = new int[2];
    this.getLocationOnScreen(parentLocation);
    int screenX = parentLocation[0] + x;
    int screenY = parentLocation[1] + y;
    return screenX >= viewLocation[0] && screenX < viewLocation[0] + view.getWidth()
            && screenY >= viewLocation[1] && screenY < viewLocation[1] + view.getHeight();
}

From source file:com.jaspervanriet.huntingthatproduct.Activities.MainActivity.java

private void activityExitAnimation(View v, Product product, Intent i) {
    int[] startingLocation = new int[2];
    v.getLocationOnScreen(startingLocation);
    i.putExtra(CommentsActivity.ARG_DRAWING_START_LOCATION, startingLocation[1]);
    i.putExtra("productId", product.getId());
    i.putExtra("collection", false);
    startActivity(i);//from   ww w  . jav a 2 s  .c o m
    overridePendingTransition(0, 0);
}

From source file:com.scigames.registration.LoginActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {

    View v = getCurrentFocus();//  w ww .  j  a  v a  2 s.  com
    Log.d(TAG, "CLICK DETECTED");
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    //        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION );
    //        v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
    //        Window win = this.getWindow(); // in Activity's onCreate() for instance
    //        win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    //                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    boolean ret = super.dispatchTouchEvent(event);

    if (v instanceof EditText) {
        View w = getCurrentFocus();
        int scrcoords[] = new int[2];
        w.getLocationOnScreen(scrcoords);
        float x = event.getRawX() + w.getLeft() - scrcoords[0];
        float y = event.getRawY() + w.getTop() - scrcoords[1];

        Log.d("Activity",
                "Touch event " + event.getRawX() + "," + event.getRawY() + " " + x + "," + y + " rect "
                        + w.getLeft() + "," + w.getTop() + "," + w.getRight() + "," + w.getBottom() + " coords "
                        + scrcoords[0] + "," + scrcoords[1]);
        if (event.getAction() == MotionEvent.ACTION_UP
                && (x < w.getLeft() || x >= w.getRight() || y < w.getTop() || y > w.getBottom())) {

            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
        }
    }
    return ret;

}

From source file:im.ene.lab.attiq.ui.activities.HomeActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (R.id.action_search == item.getItemId()) {
        // get the icon's location on screen to pass through to the search screen
        View searchMenuView = mToolBar.findViewById(R.id.action_search);
        int[] loc = new int[2];
        searchMenuView.getLocationOnScreen(loc);
        startActivityForResult(//w ww.ja  v a 2  s  . co  m
                SearchActivity.createStartIntent(this, loc[0], loc[0] + (searchMenuView.getWidth() / 2)),
                REQUEST_CODE_SEARCH, ActivityOptionsCompat.makeSceneTransitionAnimation(this).toBundle());
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.prevas.redmine.NewIssueActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    View view = getCurrentFocus();
    boolean ret = super.dispatchTouchEvent(event);

    if (view instanceof EditText) {
        View v = getCurrentFocus();
        int scrcoords[] = new int[2];
        v.getLocationOnScreen(scrcoords);
        float x = event.getRawX() + v.getLeft() - scrcoords[0];
        float y = event.getRawY() + v.getTop() - scrcoords[1];

        if (event.getAction() == MotionEvent.ACTION_UP
                && (x < v.getLeft() || x >= v.getRight() || y < v.getTop() || y > v.getBottom())) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
        }/*from ww  w .  ja v  a 2 s  . co  m*/
    }
    return ret;
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.HandleView.java

private PopupMenu createPopupMenu(View view, int menuId) {
    int[] pos = new int[2];
    view.getLocationOnScreen(pos);
    View moveView = ((HostView) getParent()).getMovableView();
    moveView.layout(pos[0], pos[1], pos[0] + 10, pos[1] + 10);

    PopupMenu popup = new PopupMenu(getContext(), moveView);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(menuId, popup.getMenu());
    return popup;
}

From source file:com.hannesdorfmann.home.HomeActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_filter:
        drawer.openDrawer(GravityCompat.END);
        return true;
    case R.id.menu_search:
        // get the icon's location on screen to pass through to the search screen
        View searchMenuView = toolbar.findViewById(R.id.menu_search);
        int[] loc = new int[2];
        searchMenuView.getLocationOnScreen(loc);
        startActivityForResult(//from  w  ww .  j a va 2  s . c  o m
                SearchActivity.createStartIntent(this, loc[0], loc[0] + (searchMenuView.getWidth() / 2)),
                RC_SEARCH, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
        searchMenuView.setAlpha(0f);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.lastsoft.plog.PlaysFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_plays, container, false);

    rootView.setTag(TAG);/*from  ww w .j ava 2  s.co  m*/

    // BEGIN_INCLUDE(initializeRecyclerView)
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
    mRecyclerView.setBackgroundColor(getResources().getColor(R.color.cardview_initial_background));
    RecyclerFastScroller fastScroller = (RecyclerFastScroller) rootView.findViewById(R.id.fastscroller);

    // Connect the recycler to the scroller (to let the scroller scroll the list)
    fastScroller.attachRecyclerView(mRecyclerView);

    addPlay = (FloatingActionButton) rootView.findViewById(R.id.add_play);
    if (fromDrawer && playListType != 2) {
        addPlay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int viewXY[] = new int[2];
                v.getLocationOnScreen(viewXY);
                /*if (mListener != null) {
                mListener.onFragmentInteraction("add_play", viewXY[0], viewXY[1]);
                }*/
                ((MainActivity) mActivity).usedFAB = true;
                ((MainActivity) mActivity).openGames("", true, 0, getString(R.string.title_games),
                        MainActivity.CurrentYear);
            }
        });
    } else {
        addPlay.setVisibility(View.GONE);
    }

    fabMargin = getResources().getDimensionPixelSize(R.dimen.fab_margin);
    mRecyclerView.addOnScrollListener(new MyRecyclerScroll() {
        @Override
        public void show() {
            addPlay.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
        }

        @Override
        public void hide() {
            addPlay.animate().translationY(addPlay.getHeight() + fabMargin)
                    .setInterpolator(new AccelerateInterpolator(2)).start();
        }
    });

    // Connect the scroller to the recycler (to let the recycler scroll the scroller's handle)
    //mRecyclerView.addOnScrollListener(fastScroller.getOnScrollListener());

    // LinearLayoutManager is used here, this will layout the elements in a similar fashion
    // to the way ListView would layout elements. The RecyclerView.LayoutManager defines how
    // elements are laid out.
    mLayoutManager = new LinearLayoutManager(mActivity);

    mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER;

    if (savedInstanceState != null) {
        // Restore saved layout manager type.
        mCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState.getSerializable(KEY_LAYOUT_MANAGER);
    }
    setRecyclerViewLayoutManager(mCurrentLayoutManagerType);

    //mAdapter = new PlayAdapter(mActivity, this);

    /*if (((MainActivity)mActivity).mPlayAdapter != null) {
    mAdapter = ((MainActivity) mActivity).mPlayAdapter;
    }else{*/
    mAdapter = ((MainActivity) mActivity).initPlayAdapter(mSearchQuery, fromDrawer, playListType, currentYear);
    //}
    // Set CustomAdapter as the adapter for RecyclerView.
    mRecyclerView.setAdapter(mAdapter);
    // END_INCLUDE(initializeRecyclerView)

    if (mSearch != null) {
        mSearch.setHint(
                getString(R.string.filter) + mAdapter.getItemCount() + getString(R.string.filter_plays));
    }

    /*boolean pauseOnScroll = true; // or true
    boolean pauseOnFling = true; // or false
    NewPauseOnScrollListener listener = new NewPauseOnScrollListener(ImageLoader.getInstance(), pauseOnScroll, pauseOnFling);
    mRecyclerView.addOnScrollListener(listener);*/

    if (!fromDrawer) {
        RelativeLayout playsLayout = (RelativeLayout) rootView.findViewById(R.id.playsLayout);
        final SwipeDismissBehavior<LinearLayout> behavior = new SwipeDismissBehavior();
        behavior.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_START_TO_END);
        behavior.setStartAlphaSwipeDistance(1.0f);
        behavior.setSensitivity(0.15f);
        behavior.setListener(new SwipeDismissBehavior.OnDismissListener() {
            @Override
            public void onDismiss(final View view) {
                PlaysFragment myFragC1 = (PlaysFragment) getFragmentManager().findFragmentByTag("plays");
                FragmentTransaction transaction = getFragmentManager().beginTransaction();
                transaction.remove(myFragC1);
                transaction.commitAllowingStateLoss();
                getFragmentManager().executePendingTransactions();
                mActivity.onBackPressed();
            }

            @Override
            public void onDragStateChanged(int i) {

            }
        });

        CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) playsLayout.getLayoutParams();
        params.setBehavior(behavior);
    }

    if (mSearch != null) {
        mSearch.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
                // When user changed the Text
                if (mActivity != null) {
                    mSearchQuery = cs.toString();
                    //initDataset();
                    //mAdapter = new GameAdapter(PlaysFragment.this, mActivity,mSearchQuery);
                    mAdapter = ((MainActivity) mActivity).initPlayAdapter(mSearchQuery, fromDrawer,
                            playListType, currentYear);
                    // Set CustomAdapter as the adapter for RecyclerView.
                    mRecyclerView.setAdapter(mAdapter);
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {
            }

            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            }
        });

        mCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!mSearch.getText().toString().equals("")) {
                    mSearchQuery = "";
                    ((MainActivity) mActivity).initPlayAdapter(mSearchQuery, fromDrawer, playListType,
                            currentYear);
                    mSearch.setText(mSearchQuery);

                    //mActivity.onBackPressed();
                }

                InputMethodManager inputManager = (InputMethodManager) mActivity
                        .getSystemService(Context.INPUT_METHOD_SERVICE);

                inputManager.hideSoftInputFromWindow(mActivity.getCurrentFocus().getWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
                mSearch.clearFocus();
                mRecyclerView.requestFocus();

                refreshDataset();
            }
        });
    }

    return rootView;
}