List of usage examples for android.widget GridLayout LEFT
Alignment LEFT
To view the source code for android.widget GridLayout LEFT.
Click Source Link
From source file:com.android.launcher2.AsyncTaskCallback.java
public void syncWidgetPageItems(final int page, final boolean immediate) { int numItemsPerPage = mWidgetCountX * mWidgetCountY; // Calculate the dimensions of each cell we are giving to each widget final ArrayList<Object> items = new ArrayList<Object>(); int contentWidth = mWidgetSpacingLayout.getContentWidth(); final int cellWidth = ((contentWidth - mPageLayoutPaddingLeft - mPageLayoutPaddingRight - ((mWidgetCountX - 1) * mWidgetWidthGap)) / mWidgetCountX); int contentHeight = mWidgetSpacingLayout.getContentHeight(); final int cellHeight = ((contentHeight - mPageLayoutPaddingTop - mPageLayoutPaddingBottom - ((mWidgetCountY - 1) * mWidgetHeightGap)) / mWidgetCountY); // Prepare the set of widgets to load previews for in the background int offset = (page - mNumAppsPages) * numItemsPerPage; for (int i = offset; i < Math.min(offset + numItemsPerPage, mWidgets.size()); ++i) { items.add(mWidgets.get(i));//w w w.ja v a 2s . co m } // Prepopulate the pages with the other widget info, and fill in the previews later final PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page); layout.setColumnCount(layout.getCellCountX()); for (int i = 0; i < items.size(); ++i) { Object rawInfo = items.get(i); PendingAddItemInfo createItemInfo = null; PagedViewWidget widget = (PagedViewWidget) mLayoutInflater.inflate(R.layout.apps_customize_widget, layout, false); if (rawInfo instanceof AppWidgetProviderInfo) { // Fill in the widget information AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo; createItemInfo = new PendingAddWidgetInfo(info, null, null); // Determine the widget spans and min resize spans. int[] spanXY = Launcher.getSpanForWidget(mLauncher, info); createItemInfo.spanX = spanXY[0]; createItemInfo.spanY = spanXY[1]; int[] minSpanXY = Launcher.getMinSpanForWidget(mLauncher, info); createItemInfo.minSpanX = minSpanXY[0]; createItemInfo.minSpanY = minSpanXY[1]; widget.applyFromAppWidgetProviderInfo(info, -1, spanXY); widget.setTag(createItemInfo); widget.setShortPressListener(this); } else if (rawInfo instanceof ResolveInfo) { // Fill in the shortcuts information ResolveInfo info = (ResolveInfo) rawInfo; createItemInfo = new PendingAddShortcutInfo(info.activityInfo); createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; createItemInfo.componentName = new ComponentName(info.activityInfo.packageName, info.activityInfo.name); widget.applyFromResolveInfo(mPackageManager, info); widget.setTag(createItemInfo); } widget.setOnClickListener(this); widget.setOnLongClickListener(this); widget.setOnTouchListener(this); widget.setOnKeyListener(this); // Layout each widget int ix = i % mWidgetCountX; int iy = i / mWidgetCountX; GridLayout.LayoutParams lp = new GridLayout.LayoutParams(GridLayout.spec(iy, GridLayout.LEFT), GridLayout.spec(ix, GridLayout.TOP)); lp.width = cellWidth; lp.height = cellHeight; lp.setGravity(Gravity.TOP | Gravity.LEFT); if (ix > 0) lp.leftMargin = mWidgetWidthGap; if (iy > 0) lp.topMargin = mWidgetHeightGap; layout.addView(widget, lp); } // wait until a call on onLayout to start loading, because // PagedViewWidget.getPreviewSize() will return 0 if it hasn't been laid out // TODO: can we do a measure/layout immediately? layout.setOnLayoutListener(new Runnable() { public void run() { // Load the widget previews int maxPreviewWidth = cellWidth; int maxPreviewHeight = cellHeight; if (layout.getChildCount() > 0) { PagedViewWidget w = (PagedViewWidget) layout.getChildAt(0); int[] maxSize = w.getPreviewSize(); maxPreviewWidth = maxSize[0]; maxPreviewHeight = maxSize[1]; } if (immediate) { AsyncTaskPageData data = new AsyncTaskPageData(page, items, maxPreviewWidth, maxPreviewHeight, null, null); loadWidgetPreviewsInBackground(null, data); onSyncWidgetPageItems(data); } else { if (mInTransition) { mDeferredPrepareLoadWidgetPreviewsTasks.add(this); } else { prepareLoadWidgetPreviewsTask(page, items, maxPreviewWidth, maxPreviewHeight, mWidgetCountX); } } } }); }