List of usage examples for android.view View getTag
@ViewDebug.ExportedProperty
public Object getTag()
From source file:com.android.launcher2.Workspace.java
void updateShortcuts(ArrayList<ApplicationInfo> apps) { ArrayList<ShortcutAndWidgetContainer> childrenLayouts = getAllShortcutAndWidgetContainers(); for (ShortcutAndWidgetContainer layout : childrenLayouts) { int childCount = layout.getChildCount(); for (int j = 0; j < childCount; j++) { final View view = layout.getChildAt(j); Object tag = view.getTag(); if (tag instanceof ShortcutInfo) { ShortcutInfo info = (ShortcutInfo) tag; // We need to check for ACTION_MAIN otherwise getComponent() might // return null for some shortcuts (for instance, for shortcuts to // web pages.) final Intent intent = info.intent; final ComponentName name = intent.getComponent(); if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION && Intent.ACTION_MAIN.equals(intent.getAction()) && name != null) { final int appCount = apps.size(); for (int k = 0; k < appCount; k++) { ApplicationInfo app = apps.get(k); if (app.componentName.equals(name)) { BubbleTextView shortcut = (BubbleTextView) view; info.updateIcon(mIconCache); info.title = app.title.toString(); shortcut.applyFromShortcutInfo(info, mIconCache); }//w ww . j a va 2 s .c o m } } } } } }
From source file:com.android.launcher2.Workspace.java
void updateItemLocationsInDatabase(CellLayout cl) { int count = cl.getShortcutsAndWidgets().getChildCount(); int screen = indexOfChild(cl); int container = Favorites.CONTAINER_DESKTOP; if (mLauncher.isHotseatLayout(cl)) { screen = -1;//www. ja v a2s.c o m container = Favorites.CONTAINER_HOTSEAT; } for (int i = 0; i < count; i++) { View v = cl.getShortcutsAndWidgets().getChildAt(i); ItemInfo info = (ItemInfo) v.getTag(); // Null check required as the AllApps button doesn't have an item info if (info != null && info.requiresDbUpdate) { info.requiresDbUpdate = false; LauncherModel.modifyItemInDatabase(mLauncher, info, container, screen, info.cellX, info.cellY, info.spanX, info.spanY); } } }
From source file:com.android.leanlauncher.LauncherTransitionable.java
public boolean onLongClick(View v) { if (!isDraggingEnabled()) return false; if (isWorkspaceLocked()) return false; if (mState != State.WORKSPACE) return false; if (v instanceof Workspace) { if (!mWorkspace.isInOverviewMode()) { if (mWorkspace.enterOverviewMode()) { mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); return true; } else { return false; }/*from w ww. j a v a 2 s . c o m*/ } else { return false; } } CellLayout.CellInfo longClickCellInfo = null; View itemUnderLongClick = null; if (v.getTag() instanceof ItemInfo) { ItemInfo info = (ItemInfo) v.getTag(); longClickCellInfo = new CellLayout.CellInfo(v, info); itemUnderLongClick = longClickCellInfo.cell; resetAddInfo(); } if (!mDragController.isDragging()) { if (itemUnderLongClick == null) { // User long pressed on empty space mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); if (!mWorkspace.isInOverviewMode()) { mWorkspace.enterOverviewMode(); } } else { // User long pressed on an item mWorkspace.startDrag(longClickCellInfo); } } return true; }
From source file:com.android.launcher2.Workspace.java
void removeItems(final ArrayList<String> packages) { final HashSet<String> packageNames = new HashSet<String>(); packageNames.addAll(packages);//w w w .ja v a 2 s .com ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts(); for (final CellLayout layoutParent : cellLayouts) { final ViewGroup layout = layoutParent.getShortcutsAndWidgets(); // Avoid ANRs by treating each screen separately post(new Runnable() { public void run() { final ArrayList<View> childrenToRemove = new ArrayList<View>(); childrenToRemove.clear(); int childCount = layout.getChildCount(); for (int j = 0; j < childCount; j++) { final View view = layout.getChildAt(j); Object tag = view.getTag(); if (tag instanceof ShortcutInfo) { final ShortcutInfo info = (ShortcutInfo) tag; final Intent intent = info.intent; final ComponentName name = intent.getComponent(); if (name != null) { if (packageNames.contains(name.getPackageName())) { LauncherModel.deleteItemFromDatabase(mLauncher, info); childrenToRemove.add(view); } } } else if (tag instanceof FolderInfo) { final FolderInfo info = (FolderInfo) tag; final ArrayList<ShortcutInfo> contents = info.contents; final int contentsCount = contents.size(); final ArrayList<ShortcutInfo> appsToRemoveFromFolder = new ArrayList<ShortcutInfo>(); for (int k = 0; k < contentsCount; k++) { final ShortcutInfo appInfo = contents.get(k); final Intent intent = appInfo.intent; final ComponentName name = intent.getComponent(); if (name != null) { if (packageNames.contains(name.getPackageName())) { appsToRemoveFromFolder.add(appInfo); } } } for (ShortcutInfo item : appsToRemoveFromFolder) { info.remove(item); LauncherModel.deleteItemFromDatabase(mLauncher, item); } } else if (tag instanceof LauncherAppWidgetInfo) { final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) tag; final ComponentName provider = info.providerName; if (provider != null) { if (packageNames.contains(provider.getPackageName())) { LauncherModel.deleteItemFromDatabase(mLauncher, info); childrenToRemove.add(view); } } } } childCount = childrenToRemove.size(); for (int j = 0; j < childCount; j++) { View child = childrenToRemove.get(j); // Note: We can not remove the view directly from CellLayoutChildren as this // does not re-mark the spaces as unoccupied. layoutParent.removeViewInLayout(child); if (child instanceof DropTarget) { mDragController.removeDropTarget((DropTarget) child); } } if (childCount > 0) { layout.requestLayout(); layout.invalidate(); } } }); } // Clean up new-apps animation list final Context context = getContext(); post(new Runnable() { @Override public void run() { String spKey = LauncherApplication.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); Set<String> newApps = sp.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null); // Remove all queued items that match the same package if (newApps != null) { synchronized (newApps) { Iterator<String> iter = newApps.iterator(); while (iter.hasNext()) { try { Intent intent = Intent.parseUri(iter.next(), 0); String pn = ItemInfo.getPackageName(intent); if (packageNames.contains(pn)) { iter.remove(); } // It is possible that we've queued an item to be loaded, yet it has // not been added to the workspace, so remove those items as well. ArrayList<ItemInfo> shortcuts; shortcuts = LauncherModel.getWorkspaceShortcutItemInfosWithIntent(intent); for (ItemInfo info : shortcuts) { LauncherModel.deleteItemFromDatabase(context, info); } } catch (URISyntaxException e) { } } } } } }); }
From source file:cc.flydev.launcher.Page.java
private Runnable createPostDeleteAnimationRunnable(final View dragView) { return new Runnable() { @Override/*ww w. java 2 s . c o m*/ public void run() { int dragViewIndex = indexOfChild(dragView); // For each of the pages around the drag view, animate them from the previous // position to the new position in the layout (as a result of the drag view moving // in the layout) // NOTE: We can make an assumption here because we have side-bound pages that we // will always have pages to animate in from the left getOverviewModePages(mTempVisiblePagesRange); boolean isLastWidgetPage = (mTempVisiblePagesRange[0] == mTempVisiblePagesRange[1]); boolean slideFromLeft = (isLastWidgetPage || dragViewIndex > mTempVisiblePagesRange[0]); // Setup the scroll to the correct page before we swap the views if (slideFromLeft) { snapToPageImmediately(dragViewIndex - 1); } int firstIndex = (isLastWidgetPage ? 0 : mTempVisiblePagesRange[0]); int lastIndex = Math.min(mTempVisiblePagesRange[1], getPageCount() - 1); int lowerIndex = (slideFromLeft ? firstIndex : dragViewIndex + 1); int upperIndex = (slideFromLeft ? dragViewIndex - 1 : lastIndex); ArrayList<Animator> animations = new ArrayList<Animator>(); for (int i = lowerIndex; i <= upperIndex; ++i) { View v = getChildAt(i); // dragViewIndex < pageUnderPointIndex, so after we remove the // drag view all subsequent views to pageUnderPointIndex will // shift down. int oldX = 0; int newX = 0; if (slideFromLeft) { if (i == 0) { // Simulate the page being offscreen with the page spacing oldX = getViewportOffsetX() + getChildOffset(i) - getChildWidth(i) - mPageSpacing; } else { oldX = getViewportOffsetX() + getChildOffset(i - 1); } newX = getViewportOffsetX() + getChildOffset(i); } else { oldX = getChildOffset(i) - getChildOffset(i - 1); newX = 0; } // Animate the view translation from its old position to its new // position AnimatorSet anim = (AnimatorSet) v.getTag(); if (anim != null) { anim.cancel(); } // Note: Hacky, but we want to skip any optimizations to not draw completely // hidden views v.setAlpha(Math.max(v.getAlpha(), 0.01f)); v.setTranslationX(oldX - newX); anim = new AnimatorSet(); anim.playTogether(ObjectAnimator.ofFloat(v, "translationX", 0f), ObjectAnimator.ofFloat(v, "alpha", 1f)); animations.add(anim); v.setTag(ANIM_TAG_KEY, anim); } AnimatorSet slideAnimations = new AnimatorSet(); slideAnimations.playTogether(animations); slideAnimations.setDuration(DELETE_SLIDE_IN_SIDE_PAGE_DURATION); slideAnimations.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mDeferringForDelete = false; onEndReordering(); onRemoveViewAnimationCompleted(); } }); slideAnimations.start(); removeView(dragView); onRemoveView(dragView, true); } }; }
From source file:com.aliyun.homeshell.Folder.java
private void autoMoveIconByScroll(int srcPageIndex, int desPageIndex) { mScrolling = true;/*from www . ja v a 2 s . c o m*/ cancelMoveAnimation(); final CellLayout srcPage = mContentList.get(srcPageIndex); final CellLayout desPage = mContentList.get(desPageIndex); View movedView = null; // scroll left if (srcPageIndex > desPageIndex) { for (int j = desPage.getCountY() - 1; j >= 0; j--) { for (int i = desPage.getCountX() - 1; i >= 0; i--) { if ((movedView = desPage.getChildAt(i, j)) != null) { moveAnim = ObjectAnimator.ofFloat(movedView, TRANSLATION_X, LauncherApplication.getScreenWidth() - movedView.getX() + 100); break; } } if (movedView != null) { break; } } } else { // scroll right for (int j = 0; j < desPage.getCountY(); j++) { for (int i = 0; i < desPage.getCountX(); i++) { if ((movedView = desPage.getChildAt(i, j)) != null) { moveAnim = ObjectAnimator.ofFloat(movedView, TRANSLATION_X, -300); break; } } if (movedView != null) { break; } } } if (movedView == null) return; final ItemInfo movedInfo = (ItemInfo) movedView.getTag(); final View view = movedView; mReorderAlarm.cancelAlarm(); moveAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { view.setTranslationX(0); desPage.removeView(view); ViewParent parent = (view.getParent()); if (parent != null) { String title = ""; if (movedInfo != null) { title = movedInfo.title.toString(); } Log.e(HOR_LOG_TAG, "The icon:" + title + ",has the parent when end on autoScroll,remove"); return; } CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams(); int movedFromX = movedInfo.cellX; int movedFromY = movedInfo.cellY; lp.cellX = movedInfo.cellX = mEmptyCell[0]; lp.cellY = movedInfo.cellY = mEmptyCell[1]; mEmptyCell[0] = movedFromX; mEmptyCell[1] = movedFromY; boolean insert = false; srcPage.addViewToCellLayout(view, insert ? 0 : -1, (int) movedInfo.id, lp, true); // force to reorder // mReorderAlarm.cancelAlarm(); // mReorderAlarm.setOnAlarmListener(mReorderAlarmListener); // mReorderAlarm.setAlarm(150); } }); moveAnim.setDuration(300); moveAnim.start(); }
From source file:com.android.launcher2.Launcher.java
/** * Launches the intent referred by the clicked shortcut. * * @param v The view representing the clicked shortcut. *//*w w w.jav a2s . 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.launcher2.Launcher.java
public boolean onLongClick(View v) { if (!isDraggingEnabled()) return false; if (isWorkspaceLocked()) return false; if (mState != State.WORKSPACE) return false; if (!(v instanceof CellLayout)) { v = (View) v.getParent().getParent(); }//from w ww. j a v a 2 s.c o m resetAddInfo(); CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag(); // This happens when long clicking an item with the dpad/trackball if (longClickCellInfo == null) { return true; } // The hotseat touch handling does not go through Workspace, and we always allow long press // on hotseat items. final View itemUnderLongClick = longClickCellInfo.cell; boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress(); if (allowLongPress && !mDragController.isDragging()) { if (itemUnderLongClick == null) { // User long pressed on empty space mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); startWallpaper(); } else { if (!(itemUnderLongClick instanceof Folder)) { // User long pressed on an item mWorkspace.startDrag(longClickCellInfo); } } } return true; }
From source file:com.nttec.everychan.ui.presentation.BoardFragment.java
@Override public boolean onContextItemSelected(MenuItem item) { //? ? -// w w w . j av a2 s . c om switch (item.getItemId()) { case R.id.context_menu_thumb_load_thumb: bitmapCache.asyncGet( ChanModels.hashAttachmentModel((AttachmentModel) lastContextMenuAttachment.getTag()), ((AttachmentModel) lastContextMenuAttachment.getTag()).thumbnail, resources.getDimensionPixelSize(R.dimen.post_thumbnail_size), chan, null, imagesDownloadTask, (ImageView) lastContextMenuAttachment.findViewById(R.id.post_thumbnail_image), imagesDownloadExecutor, Async.UI_HANDLER, true, R.drawable.thumbnail_error); return true; case R.id.context_menu_thumb_download: downloadFile((AttachmentModel) lastContextMenuAttachment.getTag()); return true; case R.id.context_menu_thumb_copy_url: String url = chan.fixRelativeUrl(((AttachmentModel) lastContextMenuAttachment.getTag()).path); Clipboard.copyText(activity, url); Toast.makeText(activity, resources.getString(R.string.notification_url_copied, url), Toast.LENGTH_LONG) .show(); return true; case R.id.context_menu_thumb_attachment_info: String info = Attachments.getAttachmentInfoString(chan, ((AttachmentModel) lastContextMenuAttachment.getTag()), resources); Toast.makeText(activity, info, Toast.LENGTH_LONG).show(); return true; case R.id.context_menu_thumb_reverse_search: ReverseImageSearch.openDialog(activity, chan.fixRelativeUrl(((AttachmentModel) lastContextMenuAttachment.getTag()).path)); return true; } //? ? ? int position = lastContextMenuPosition; if (item.getMenuInfo() != null && item.getMenuInfo() instanceof AdapterView.AdapterContextMenuInfo) { position = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position; } if (nullAdapterIsSet || position == -1 || adapter.getCount() <= position) return false; switch (item.getItemId()) { case R.id.context_menu_open_in_new_tab: UrlPageModel modelNewTab = new UrlPageModel(); modelNewTab.chanName = chan.getChanName(); modelNewTab.type = UrlPageModel.TYPE_THREADPAGE; modelNewTab.boardName = tabModel.pageModel.boardName; modelNewTab.threadNumber = adapter.getItem(position).sourceModel.parentThread; String tabTitle = null; String subject = adapter.getItem(position).sourceModel.subject; if (subject != null && subject.length() != 0) { tabTitle = subject; } else { Spanned spannedComment = adapter.getItem(position).spannedComment; if (spannedComment != null) { tabTitle = spannedComment.toString().replace('\n', ' '); if (tabTitle.length() > MAX_TITLE_LENGHT) tabTitle = tabTitle.substring(0, MAX_TITLE_LENGHT); } } if (tabTitle != null) tabTitle = resources.getString(R.string.tabs_title_threadpage_loaded, modelNewTab.boardName, tabTitle); UrlHandler.open(modelNewTab, activity, false, tabTitle); return true; case R.id.context_menu_thread_preview: showThreadPreviewDialog(position); return true; case R.id.context_menu_reply_no_reading: UrlPageModel model = new UrlPageModel(); model.chanName = chan.getChanName(); model.type = UrlPageModel.TYPE_THREADPAGE; model.boardName = tabModel.pageModel.boardName; model.threadNumber = adapter.getItem(position).sourceModel.parentThread; openPostForm(ChanModels.hashUrlPageModel(model), presentationModel.source.boardModel, getSendPostModel(model)); return true; case R.id.context_menu_hide: adapter.getItem(position).hidden = true; database.addHidden(tabModel.pageModel.chanName, tabModel.pageModel.boardName, pageType == TYPE_POSTSLIST ? tabModel.pageModel.threadNumber : adapter.getItem(position).sourceModel.number, pageType == TYPE_POSTSLIST ? adapter.getItem(position).sourceModel.number : null); adapter.notifyDataSetChanged(); return true; case R.id.context_menu_reply: openReply(position, false, null); return true; case R.id.context_menu_reply_with_quote: openReply(position, true, null); return true; case R.id.context_menu_select_text: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && lastContextMenuPosition == -1) { int firstPosition = listView.getFirstVisiblePosition() - listView.getHeaderViewsCount(); int wantedChild = position - firstPosition; if (wantedChild >= 0 && wantedChild < listView.getChildCount()) { View v = listView.getChildAt(wantedChild); if (v != null && v.getTag() != null && v.getTag() instanceof PostsListAdapter.PostViewTag) { ((PostsListAdapter.PostViewTag) v.getTag()).commentView.startSelection(); return true; } } } Clipboard.copyText(activity, adapter.getItem(position).spannedComment.toString()); Toast.makeText(activity, resources.getString(R.string.notification_comment_copied), Toast.LENGTH_LONG) .show(); return true; case R.id.context_menu_share: UrlPageModel sharePostUrlPageModel = new UrlPageModel(); sharePostUrlPageModel.chanName = chan.getChanName(); sharePostUrlPageModel.type = UrlPageModel.TYPE_THREADPAGE; sharePostUrlPageModel.boardName = tabModel.pageModel.boardName; sharePostUrlPageModel.threadNumber = tabModel.pageModel.threadNumber; sharePostUrlPageModel.postNumber = adapter.getItem(position).sourceModel.number; Intent sharePostIntent = new Intent(Intent.ACTION_SEND); sharePostIntent.setType("text/plain"); sharePostIntent.putExtra(Intent.EXTRA_SUBJECT, chan.buildUrl(sharePostUrlPageModel)); sharePostIntent.putExtra(Intent.EXTRA_TEXT, adapter.getItem(position).spannedComment.toString()); startActivity(Intent.createChooser(sharePostIntent, resources.getString(R.string.share_via))); return true; case R.id.context_menu_delete: DeletePostModel delModel = new DeletePostModel(); delModel.chanName = chan.getChanName(); delModel.boardName = tabModel.pageModel.boardName; delModel.threadNumber = tabModel.pageModel.threadNumber; delModel.postNumber = adapter.getItem(position).sourceModel.number; runDelete(delModel, adapter.getItem(position).sourceModel.attachments != null && adapter.getItem(position).sourceModel.attachments.length > 0); return true; case R.id.context_menu_report: DeletePostModel reportModel = new DeletePostModel(); reportModel.chanName = chan.getChanName(); reportModel.boardName = tabModel.pageModel.boardName; reportModel.threadNumber = tabModel.pageModel.threadNumber; reportModel.postNumber = adapter.getItem(position).sourceModel.number; runReport(reportModel); return true; case R.id.context_menu_subscribe: String chanName = chan.getChanName(); String board = tabModel.pageModel.boardName; String thread = tabModel.pageModel.threadNumber; String post = adapter.getItem(position).sourceModel.number; if (subscriptions.hasSubscription(chanName, board, thread, post)) { subscriptions.removeSubscription(chanName, board, thread, post); for (int i = position; i < adapter.getCount(); ++i) adapter.getItem(i).onUnsubscribe(post); } else { subscriptions.addSubscription(chanName, board, thread, post); for (int i = position; i < adapter.getCount(); ++i) adapter.getItem(i).onSubscribe(post); } adapter.notifyDataSetChanged(); return true; } return false; }
From source file:com.android.launcher2.Workspace.java
boolean createUserFolderIfNecessary(View newView, long container, CellLayout target, int[] targetCell, float distance, boolean external, DragView dragView, Runnable postAnimationRunnable) { if (distance > mMaxDistanceForFolderCreation) return false; View v = target.getChildAt(targetCell[0], targetCell[1]); boolean hasntMoved = false; if (mDragInfo != null) { CellLayout cellParent = getParentCellLayoutForView(mDragInfo.cell); hasntMoved = (mDragInfo.cellX == targetCell[0] && mDragInfo.cellY == targetCell[1]) && (cellParent == target); }/* www . j a v a2 s .c o m*/ if (v == null || hasntMoved || !mCreateUserFolderOnDrop) return false; mCreateUserFolderOnDrop = false; final int screen = (targetCell == null) ? mDragInfo.screen : indexOfChild(target); boolean aboveShortcut = (v.getTag() instanceof ShortcutInfo); boolean willBecomeShortcut = (newView.getTag() instanceof ShortcutInfo); if (aboveShortcut && willBecomeShortcut) { ShortcutInfo sourceInfo = (ShortcutInfo) newView.getTag(); ShortcutInfo destInfo = (ShortcutInfo) v.getTag(); // if the drag started here, we need to remove it from the workspace if (!external) { getParentCellLayoutForView(mDragInfo.cell).removeView(mDragInfo.cell); } Rect folderLocation = new Rect(); float scale = mLauncher.getDragLayer().getDescendantRectRelativeToSelf(v, folderLocation); target.removeView(v); FolderIcon fi = mLauncher.addFolder(target, container, screen, targetCell[0], targetCell[1]); destInfo.cellX = -1; destInfo.cellY = -1; sourceInfo.cellX = -1; sourceInfo.cellY = -1; // If the dragView is null, we can't animate boolean animate = dragView != null; if (animate) { fi.performCreateAnimation(destInfo, v, sourceInfo, dragView, folderLocation, scale, postAnimationRunnable); } else { fi.addItem(destInfo); fi.addItem(sourceInfo); } return true; } return false; }