List of usage examples for android.view View getLocationOnScreen
public void getLocationOnScreen(@Size(2) int[] outLocation)
Computes the coordinates of this view on the screen.
From source file:com.android.launcher2.Launcher.java
/** * Launches the intent referred by the clicked shortcut. * * @param v The view representing the clicked shortcut. *///from w w w . ja v a2 s .c o m public void onClick(View v) { // Make sure that rogue clicks don't get through while allapps is launching, or after the // view has detached (it's possible for this to happen if the view is removed mid touch). if (v.getWindowToken() == null) { return; } if (!mWorkspace.isFinishedSwitchingState()) { return; } Object tag = v.getTag(); if (tag instanceof ShortcutInfo) { // Open shortcut final Intent intent = ((ShortcutInfo) tag).intent; int[] pos = new int[2]; v.getLocationOnScreen(pos); intent.setSourceBounds(new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight())); boolean success = startActivitySafely(v, intent, tag); if (success && v instanceof BubbleTextView) { mWaitingForResume = (BubbleTextView) v; mWaitingForResume.setStayPressed(true); } } else if (tag instanceof FolderInfo) { if (v instanceof FolderIcon) { FolderIcon fi = (FolderIcon) v; handleFolderClick(fi); } } else if (v == mAllAppsButton) { if (isAllAppsVisible()) { showWorkspace(true); } else { onClickAllAppsButton(v); } } }
From source file:com.android.launcher3.Launcher.java
private Rect getViewBounds(View v) { int[] pos = new int[2]; v.getLocationOnScreen(pos); return new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight()); }
From source file:com.klinker.android.launcher.launcher3.Launcher.java
@Thunk void startAppShortcutOrInfoActivity(View v) { Object tag = v.getTag();/*from w w w. j ava 2s.c o m*/ final ShortcutInfo shortcut; final Intent intent; if (tag instanceof ShortcutInfo) { shortcut = (ShortcutInfo) tag; intent = shortcut.intent; int[] pos = new int[2]; v.getLocationOnScreen(pos); intent.setSourceBounds(new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight())); } else if (tag instanceof AppInfo) { shortcut = null; intent = ((AppInfo) tag).intent; } else { throw new IllegalArgumentException("Input must be a Shortcut or AppInfo"); } boolean success = startActivitySafely(v, intent, tag); mStats.recordLaunch(v, intent, shortcut); if (success && v instanceof BubbleTextView) { mWaitingForResume = (BubbleTextView) v; mWaitingForResume.setStayPressed(true); } }
From source file:self.philbrown.droidQuery.$.java
/** * Gets the coordinates of {@code v}//from www . j a v a 2s . c o m * @param v * @return the coordinates of the given view */ private Point offset(View v) { int[] loc = new int[2]; v.getLocationOnScreen(loc); return new Point(loc[0], loc[1]); }
From source file:com.farmerbb.taskbar.service.StartMenuService.java
@SuppressLint("RtlHardcoded") private void drawStartMenu() { IconCache.getInstance(this).clearCache(); final SharedPreferences pref = U.getSharedPreferences(this); final boolean hasHardwareKeyboard = getResources() .getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS; switch (pref.getString("show_search_bar", "keyboard")) { case "always": shouldShowSearchBox = true;//from w w w . j ava2 s . c om break; case "keyboard": shouldShowSearchBox = hasHardwareKeyboard; break; case "never": shouldShowSearchBox = false; break; } // Initialize layout params windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); U.setCachedRotation(windowManager.getDefaultDisplay().getRotation()); final WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_PHONE, shouldShowSearchBox ? 0 : WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, PixelFormat.TRANSLUCENT); // Determine where to show the start menu on screen switch (U.getTaskbarPosition(this)) { case "bottom_left": layoutId = R.layout.start_menu_left; params.gravity = Gravity.BOTTOM | Gravity.LEFT; break; case "bottom_vertical_left": layoutId = R.layout.start_menu_vertical_left; params.gravity = Gravity.BOTTOM | Gravity.LEFT; break; case "bottom_right": layoutId = R.layout.start_menu_right; params.gravity = Gravity.BOTTOM | Gravity.RIGHT; break; case "bottom_vertical_right": layoutId = R.layout.start_menu_vertical_right; params.gravity = Gravity.BOTTOM | Gravity.RIGHT; break; case "top_left": layoutId = R.layout.start_menu_top_left; params.gravity = Gravity.TOP | Gravity.LEFT; break; case "top_vertical_left": layoutId = R.layout.start_menu_vertical_left; params.gravity = Gravity.TOP | Gravity.LEFT; break; case "top_right": layoutId = R.layout.start_menu_top_right; params.gravity = Gravity.TOP | Gravity.RIGHT; break; case "top_vertical_right": layoutId = R.layout.start_menu_vertical_right; params.gravity = Gravity.TOP | Gravity.RIGHT; break; } // Initialize views int theme = 0; switch (pref.getString("theme", "light")) { case "light": theme = R.style.AppTheme; break; case "dark": theme = R.style.AppTheme_Dark; break; } ContextThemeWrapper wrapper = new ContextThemeWrapper(this, theme); layout = (StartMenuLayout) LayoutInflater.from(wrapper).inflate(layoutId, null); startMenu = (GridView) layout.findViewById(R.id.start_menu); if ((shouldShowSearchBox && !hasHardwareKeyboard) || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) layout.viewHandlesBackButton(); boolean scrollbar = pref.getBoolean("scrollbar", false); startMenu.setFastScrollEnabled(scrollbar); startMenu.setFastScrollAlwaysVisible(scrollbar); startMenu.setScrollBarStyle(scrollbar ? View.SCROLLBARS_OUTSIDE_INSET : View.SCROLLBARS_INSIDE_OVERLAY); if (pref.getBoolean("transparent_start_menu", false)) startMenu.setBackgroundColor(0); searchView = (SearchView) layout.findViewById(R.id.search); int backgroundTint = U.getBackgroundTint(this); FrameLayout startMenuFrame = (FrameLayout) layout.findViewById(R.id.start_menu_frame); FrameLayout searchViewLayout = (FrameLayout) layout.findViewById(R.id.search_view_layout); startMenuFrame.setBackgroundColor(backgroundTint); searchViewLayout.setBackgroundColor(backgroundTint); if (shouldShowSearchBox) { if (!hasHardwareKeyboard) searchView.setIconifiedByDefault(true); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { if (!hasSubmittedQuery) { ListAdapter adapter = startMenu.getAdapter(); if (adapter != null) { hasSubmittedQuery = true; if (adapter.getCount() > 0) { View view = adapter.getView(0, null, startMenu); LinearLayout layout = (LinearLayout) view.findViewById(R.id.entry); layout.performClick(); } else { if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) LocalBroadcastManager.getInstance(StartMenuService.this) .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_TASKBAR")); else LocalBroadcastManager.getInstance(StartMenuService.this) .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU")); Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, query); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (intent.resolveActivity(getPackageManager()) != null) startActivity(intent); else { Uri uri = new Uri.Builder().scheme("https").authority("www.google.com") .path("search").appendQueryParameter("q", query).build(); intent = new Intent(Intent.ACTION_VIEW); intent.setData(uri); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { startActivity(intent); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } } } } } return true; } @Override public boolean onQueryTextChange(String newText) { searchView.setIconified(false); View closeButton = searchView.findViewById(R.id.search_close_btn); if (closeButton != null) closeButton.setVisibility(View.GONE); refreshApps(newText, false); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) { new Handler().postDelayed(() -> { EditText editText = (EditText) searchView.findViewById(R.id.search_src_text); if (editText != null) { editText.requestFocus(); editText.setSelection(editText.getText().length()); } }, 50); } return true; } }); searchView.setOnQueryTextFocusChangeListener((view, b) -> { if (!hasHardwareKeyboard) { ViewGroup.LayoutParams params1 = startMenu.getLayoutParams(); params1.height = getResources().getDimensionPixelSize(b && !U.isServiceRunning(this, "com.farmerbb.secondscreen.service.DisableKeyboardService") ? R.dimen.start_menu_height_half : R.dimen.start_menu_height); startMenu.setLayoutParams(params1); } if (!b) { if (hasHardwareKeyboard && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) LocalBroadcastManager.getInstance(StartMenuService.this) .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU")); else { InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } } }); searchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI); LinearLayout powerButton = (LinearLayout) layout.findViewById(R.id.power_button); powerButton.setOnClickListener(view -> { int[] location = new int[2]; view.getLocationOnScreen(location); openContextMenu(location); }); powerButton.setOnGenericMotionListener((view, motionEvent) -> { if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) { int[] location = new int[2]; view.getLocationOnScreen(location); openContextMenu(location); } return false; }); searchViewLayout.setOnClickListener(view -> searchView.setIconified(false)); startMenu.setOnItemClickListener((parent, view, position, id) -> { hideStartMenu(); AppEntry entry = (AppEntry) parent.getAdapter().getItem(position); U.launchApp(StartMenuService.this, entry.getPackageName(), entry.getComponentName(), entry.getUserId(StartMenuService.this), null, false, false); }); if (pref.getBoolean("transparent_start_menu", false)) layout.findViewById(R.id.search_view_child_layout).setBackgroundColor(0); } else searchViewLayout.setVisibility(View.GONE); textView = (TextView) layout.findViewById(R.id.no_apps_found); LocalBroadcastManager.getInstance(this).unregisterReceiver(toggleReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(toggleReceiverAlt); LocalBroadcastManager.getInstance(this).unregisterReceiver(hideReceiver); LocalBroadcastManager.getInstance(this).registerReceiver(toggleReceiver, new IntentFilter("com.farmerbb.taskbar.TOGGLE_START_MENU")); LocalBroadcastManager.getInstance(this).registerReceiver(toggleReceiverAlt, new IntentFilter("com.farmerbb.taskbar.TOGGLE_START_MENU_ALT")); LocalBroadcastManager.getInstance(this).registerReceiver(hideReceiver, new IntentFilter("com.farmerbb.taskbar.HIDE_START_MENU")); handler = new Handler(); refreshApps(true); windowManager.addView(layout, params); }
From source file:g7.bluesky.launcher3.Launcher.java
private void startAppShortcutOrInfoActivity(View v) { Object tag = v.getTag();/*from w ww. java2 s . com*/ final ShortcutInfo shortcut; final Intent intent; String prefKey; if (tag instanceof ShortcutInfo) { shortcut = (ShortcutInfo) tag; prefKey = shortcut.getTargetComponent().getClassName(); intent = shortcut.intent; int[] pos = new int[2]; v.getLocationOnScreen(pos); intent.setSourceBounds(new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight())); } else if (tag instanceof AppInfo) { shortcut = null; intent = ((AppInfo) tag).intent; prefKey = ((AppInfo) tag).getComponentName().getClassName(); } else { throw new IllegalArgumentException("Input must be a Shortcut or AppInfo"); } // Count app launch times LauncherUtil.increaseAppLaunchTimes(defaultSharedPref, prefKey); boolean success = startActivitySafely(v, intent, tag); mStats.recordLaunch(intent, shortcut); if (success && v instanceof BubbleTextView) { mWaitingForResume = (BubbleTextView) v; mWaitingForResume.setStayPressed(true); } }
From source file:com.cognizant.trumobi.PersonaLauncher.java
/** * Launches the intent referred by the clicked shortcut. * //from ww w . j a va 2s .com * @param v * The view representing the clicked shortcut. */ public void onClick(View v) { Object tag = v.getTag(); // ADW: Check if the tag is a special action (the app drawer category // navigation) if (tag instanceof Integer) { navigateCatalogs(Integer.parseInt(tag.toString())); return; } // TODO:ADW Check whether to display a toast if clicked mLAB or mRAB // withount binding if (tag == null && v instanceof PersonaActionButton) { Toast t = Toast.makeText(this, R.string.toast_no_application_def, Toast.LENGTH_SHORT); t.show(); return; } if (tag instanceof PersonaApplicationInfo) { // Open shortcut final PersonaApplicationInfo info = (PersonaApplicationInfo) tag; final Intent intent = info.intent; int[] pos = new int[2]; v.getLocationOnScreen(pos); try { intent.setSourceBounds(new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight())); } catch (NoSuchMethodError e) { } ; startActivitySafely(intent); // Close dockbar if setting says so if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_DOCKBAR && isDockBarOpen() && autoCloseDockbar) { mDockBar.close(); } } else if (tag instanceof PersonaFolderInfo) { handleFolderClick((PersonaFolderInfo) tag); } }
From source file:com.android.soma.Launcher.java
/** * Launches the intent referred by the clicked shortcut. * * @param v The view representing the clicked shortcut. *///ww w .ja v a 2 s.co m public void onClick(View v) { // Make sure that rogue clicks don't get through while allapps is launching, or after the // view has detached (it's possible for this to happen if the view is removed mid touch). if (v.getWindowToken() == null) { return; } if (!mWorkspace.isFinishedSwitchingState()) { return; } if (v instanceof Workspace) { if (mWorkspace.isInOverviewMode()) { mWorkspace.exitOverviewMode(true); } return; } if (v instanceof CellLayout) { if (mWorkspace.isInOverviewMode()) { mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true); } } Object tag = v.getTag(); if (tag instanceof ShortcutInfo) { // Open shortcut final ShortcutInfo shortcut = (ShortcutInfo) tag; final Intent intent = shortcut.intent; // Check for special shortcuts if (intent.getComponent() != null) { final String shortcutClass = intent.getComponent().getClassName(); if (shortcutClass.equals(WidgetAdder.class.getName())) { showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true); return; } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) { MemoryDumpActivity.startDump(this); return; } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) { toggleShowWeightWatcher(); return; } } // Start activities int[] pos = new int[2]; v.getLocationOnScreen(pos); intent.setSourceBounds(new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight())); boolean success = startActivitySafely(v, intent, tag); mStats.recordLaunch(intent, shortcut); if (success && v instanceof BubbleTextView) { mWaitingForResume = (BubbleTextView) v; mWaitingForResume.setStayPressed(true); } } else if (tag instanceof FolderInfo) { if (v instanceof FolderIcon) { FolderIcon fi = (FolderIcon) v; handleFolderClick(fi); } } else if (v == mAllAppsButton) { if (isAllAppsVisible()) { showWorkspace(true); } else { onClickAllAppsButton(v); } } }
From source file:android.support.v7.widget.RecyclerViewEx.java
/*** * Touchfling?view?//from w w w . ja v a 2 s .co m */ void adjustPosition(int spanX) { int childCount = getChildCount(); int[] lvLocationOnScreen = new int[2]; int[] childLocationOnScreen = new int[2]; if (childCount > 0) { getLocationOnScreen(lvLocationOnScreen); for (int i = 0; i < childCount; i++) { View child = getChildAt(i); child.getLocationOnScreen(childLocationOnScreen); int xStart = childLocationOnScreen[0]; int xEnd = xStart + child.getWidth(); if (spanX > 0) { if (xEnd >= lvLocationOnScreen[0] + getWidth() / 4 && xStart <= lvLocationOnScreen[0] + getWidth() / 4) { smoothScrollToPosition(getChildPosition(child)); return; } } else { if (xStart <= lvLocationOnScreen[0] + getWidth() * 3 / 4 && xEnd >= lvLocationOnScreen[0] + getWidth() * 3 / 4) { smoothScrollToPosition(getChildPosition(child)); return; } } } smoothScrollToPosition(getCenterXChildPosition()); } else { setScrollState(SCROLL_STATE_IDLE); } }
From source file:android.support.v7.widget.RecyclerViewEx.java
public boolean isChildInCenterX(View view) { int childCount = getChildCount(); int[] lvLocationOnScreen = new int[2]; int[] vLocationOnScreen = new int[2]; getLocationOnScreen(lvLocationOnScreen); int middleX = lvLocationOnScreen[0] + getWidth() / 2; if (childCount > 0) { view.getLocationOnScreen(vLocationOnScreen); if (vLocationOnScreen[0] <= middleX && vLocationOnScreen[0] + view.getWidth() >= middleX) { return true; }/*from w w w .ja v a 2 s .c o m*/ } return false; }