当前位置: 首页>>代码示例>>Java>>正文


Java AppWidgetManagerCompat类代码示例

本文整理汇总了Java中com.android.launcher3.compat.AppWidgetManagerCompat的典型用法代码示例。如果您正苦于以下问题:Java AppWidgetManagerCompat类的具体用法?Java AppWidgetManagerCompat怎么用?Java AppWidgetManagerCompat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AppWidgetManagerCompat类属于com.android.launcher3.compat包,在下文中一共展示了AppWidgetManagerCompat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: PendingAddWidgetInfo

import com.android.launcher3.compat.AppWidgetManagerCompat; //导入依赖的package包/类
public PendingAddWidgetInfo(Context context, LauncherAppWidgetProviderInfo i) {
    if (i.isCustomWidget) {
        itemType = LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
    } else {
        itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;
    }
    this.info = i;
    user = AppWidgetManagerCompat.getInstance(context).getUser(i);
    componentName = i.provider;
    previewImage = i.previewImage;
    icon = i.icon;

    spanX = i.spanX;
    spanY = i.spanY;
    minSpanX = i.minSpanX;
    minSpanY = i.minSpanY;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:18,代码来源:PendingAddWidgetInfo.java

示例2: PendingAddWidgetInfo

import com.android.launcher3.compat.AppWidgetManagerCompat; //导入依赖的package包/类
public PendingAddWidgetInfo(Launcher launcher, LauncherAppWidgetProviderInfo i, Parcelable data) {
    if (i.isCustomWidget) {
        itemType = LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
    } else {
        itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;
    }
    this.info = i;
    user = AppWidgetManagerCompat.getInstance(launcher).getUser(i);
    componentName = i.provider;
    previewImage = i.previewImage;
    icon = i.icon;

    spanX = i.spanX;
    spanY = i.spanY;
    minSpanX = i.minSpanX;
    minSpanY = i.minSpanY;
}
 
开发者ID:talentlo,项目名称:Trebuchet,代码行数:18,代码来源:PendingAddWidgetInfo.java

示例3: WidgetItem

import com.android.launcher3.compat.AppWidgetManagerCompat; //导入依赖的package包/类
public WidgetItem(LauncherAppWidgetProviderInfo info, AppWidgetManagerCompat widgetManager) {
    super(info.provider, widgetManager.getUser(info));

    label = Utilities.trim(widgetManager.loadLabel(info));
    widgetInfo = info;
    activityInfo = null;

    InvariantDeviceProfile idv = LauncherAppState.getInstance().getInvariantDeviceProfile();
    spanX = Math.min(info.spanX, idv.numColumns);
    spanY = Math.min(info.spanY, idv.numRows);
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:12,代码来源:WidgetItem.java

示例4: WidgetsModel

import com.android.launcher3.compat.AppWidgetManagerCompat; //导入依赖的package包/类
public WidgetsModel(Context context,  IconCache iconCache, AppFilter appFilter) {
    mAppWidgetMgr = AppWidgetManagerCompat.getInstance(context);
    mAppNameComparator = (new AppNameComparator(context)).getAppInfoComparator();
    mIconCache = iconCache;
    mAppFilter = appFilter;
    mIndexer = new AlphabeticIndexCompat(context);
    mPackageItemInfos = new ArrayList<>();
    mWidgetsList = new HashMap<>();

    mRawList = new ArrayList<>();
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:12,代码来源:WidgetsModel.java

示例5: updateAndClone

import com.android.launcher3.compat.AppWidgetManagerCompat; //导入依赖的package包/类
public WidgetsModel updateAndClone(Context context) {
    Preconditions.assertWorkerThread();

    try {
        final ArrayList<WidgetItem> widgetsAndShortcuts = new ArrayList<>();
        // Widgets
        AppWidgetManagerCompat widgetManager = AppWidgetManagerCompat.getInstance(context);
        for (AppWidgetProviderInfo widgetInfo : widgetManager.getAllProviders()) {
            widgetsAndShortcuts.add(new WidgetItem(
                    LauncherAppWidgetProviderInfo.fromProviderInfo(context, widgetInfo),
                    widgetManager));
        }

        // Shortcuts
        PackageManager pm = context.getPackageManager();
        for (ResolveInfo info :
                pm.queryIntentActivities(new Intent(Intent.ACTION_CREATE_SHORTCUT), 0)) {
            widgetsAndShortcuts.add(new WidgetItem(info, pm));
        }
        setWidgetsAndShortcuts(widgetsAndShortcuts);
    } catch (Exception e) {
        if (!ProviderConfig.IS_DOGFOOD_BUILD &&
                (e.getCause() instanceof TransactionTooLargeException ||
                        e.getCause() instanceof DeadObjectException)) {
            // the returned value may be incomplete and will not be refreshed until the next
            // time Launcher starts.
            // TODO: after figuring out a repro step, introduce a dirty bit to check when
            // onResume is called to refresh the widget provider list.
        } else {
            throw e;
        }
    }
    return clone();
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:35,代码来源:WidgetsModel.java

示例6: WidgetPreviewLoader

import com.android.launcher3.compat.AppWidgetManagerCompat; //导入依赖的package包/类
public WidgetPreviewLoader(Context context, IconCache iconCache) {
    mContext = context;
    mIconCache = iconCache;
    mWidgetManager = AppWidgetManagerCompat.getInstance(context);
    mUserManager = UserManagerCompat.getInstance(context);
    mDb = new CacheDb(context);
    mWorkerHandler = new Handler(LauncherModel.getWorkerLooper());
    mProfileBadgeMargin = context.getResources()
            .getDimensionPixelSize(R.dimen.profile_badge_margin);
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:11,代码来源:WidgetPreviewLoader.java

示例7: widgetsRestored

import com.android.launcher3.compat.AppWidgetManagerCompat; //导入依赖的package包/类
public void widgetsRestored(final ArrayList<LauncherAppWidgetInfo> changedInfo) {
    if (!changedInfo.isEmpty()) {
        DeferredWidgetRefresh widgetRefresh = new DeferredWidgetRefresh(changedInfo,
                mLauncher.getAppWidgetHost());

        LauncherAppWidgetInfo item = changedInfo.get(0);
        final AppWidgetProviderInfo widgetInfo;
        if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
            widgetInfo = AppWidgetManagerCompat
                    .getInstance(mLauncher).findProvider(item.providerName, item.user);
        } else {
            widgetInfo = AppWidgetManagerCompat.getInstance(mLauncher)
                    .getAppWidgetInfo(item.appWidgetId);
        }

        if (widgetInfo != null) {
            // Re-inflate the widgets which have changed status
            widgetRefresh.run();
        } else {
            // widgetRefresh will automatically run when the packages are updated.
            // For now just update the progress bars
            mapOverItems(MAP_NO_RECURSE, new ItemOperator() {
                @Override
                public boolean evaluate(ItemInfo info, View view) {
                    if (view instanceof PendingAppWidgetHostView
                            && changedInfo.contains(info)) {
                        ((LauncherAppWidgetInfo) info).installProgress = 100;
                        ((PendingAppWidgetHostView) view).applyState();
                    }
                    // process all the shortcuts
                    return false;
                }
            });
        }
    }
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:37,代码来源:Workspace.java

示例8: setUp

import com.android.launcher3.compat.AppWidgetManagerCompat; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();

    mResolver = mTargetContext.getContentResolver();
    mWidgetManager = AppWidgetManagerCompat.getInstance(mTargetContext);
    grantWidgetPermission();

    // Clear all existing data
    LauncherSettings.Settings.call(mResolver, LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB);
    LauncherSettings.Settings.call(mResolver, LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG);
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:13,代码来源:BindWidgetTest.java

示例9: WidgetsAndShortcutNameComparator

import com.android.launcher3.compat.AppWidgetManagerCompat; //导入依赖的package包/类
public WidgetsAndShortcutNameComparator(Context context) {
    mManager = AppWidgetManagerCompat.getInstance(context);
    mPackageManager = context.getPackageManager();
    mLabelCache = new HashMap<>();
    mCollator = Collator.getInstance();
    mMainHandle = UserHandleCompat.myUserHandle();
}
 
开发者ID:talentlo,项目名称:Trebuchet,代码行数:8,代码来源:WidgetsAndShortcutNameComparator.java

示例10: WidgetsModel

import com.android.launcher3.compat.AppWidgetManagerCompat; //导入依赖的package包/类
public WidgetsModel(Context context,  IconCache iconCache, AppFilter appFilter) {
    mContext = context;
    mAppWidgetMgr = AppWidgetManagerCompat.getInstance(context);
    mWidgetAndShortcutNameComparator = new WidgetsAndShortcutNameComparator(context);
    mAppNameComparator = (new AppNameComparator(context)).getAppInfoComparator();
    mIconCache = iconCache;
    mAppFilter = appFilter;
    mIndexer = new AlphabeticIndexCompat(context);
}
 
开发者ID:talentlo,项目名称:Trebuchet,代码行数:10,代码来源:WidgetsModel.java

示例11: WidgetPreviewLoader

import com.android.launcher3.compat.AppWidgetManagerCompat; //导入依赖的package包/类
public WidgetPreviewLoader(Context context, IconCache iconCache) {
    mContext = context;
    mIconCache = iconCache;
    mManager = AppWidgetManagerCompat.getInstance(context);
    mUserManager = UserManagerCompat.getInstance(context);
    mDb = new CacheDb(context);
    mWorkerHandler = new Handler(LauncherModel.getWorkerLooper());
    mProfileBadgeMargin = context.getResources()
            .getDimensionPixelSize(R.dimen.profile_badge_margin);
}
 
开发者ID:talentlo,项目名称:Trebuchet,代码行数:11,代码来源:WidgetPreviewLoader.java

示例12: applyFromAppWidgetProviderInfo

import com.android.launcher3.compat.AppWidgetManagerCompat; //导入依赖的package包/类
/**
 * Apply the widget provider info to the view.
 */
public void applyFromAppWidgetProviderInfo(LauncherAppWidgetProviderInfo info,
        WidgetPreviewLoader loader) {

    InvariantDeviceProfile profile =
            LauncherAppState.getInstance().getInvariantDeviceProfile();
    mInfo = info;
    // TODO(hyunyoungs): setup a cache for these labels.
    mWidgetName.setText(AppWidgetManagerCompat.getInstance(getContext()).loadLabel(info));
    int hSpan = Math.min(info.spanX, profile.numColumns);
    int vSpan = Math.min(info.spanY, profile.numRows);
    mWidgetDims.setText(String.format(mDimensionsFormatString, hSpan, vSpan));
    mWidgetPreviewLoader = loader;
}
 
开发者ID:talentlo,项目名称:Trebuchet,代码行数:17,代码来源:WidgetCell.java

示例13: createQsb

import com.android.launcher3.compat.AppWidgetManagerCompat; //导入依赖的package包/类
private View createQsb(LayoutInflater inflater, ViewGroup container) {
    Launcher launcher = Launcher.getLauncher(getActivity());
    mWidgetInfo = getSearchWidgetProvider(launcher);
    if (mWidgetInfo == null) {
        // There is no search provider, just show the default widget.
        return getDefaultView(inflater, container, false);
    }

    SharedPreferences prefs = Utilities.getPrefs(launcher);
    AppWidgetManagerCompat widgetManager = AppWidgetManagerCompat.getInstance(launcher);
    LauncherAppWidgetHost widgetHost = launcher.getAppWidgetHost();
    InvariantDeviceProfile idp = LauncherAppState.getInstance().getInvariantDeviceProfile();

    Bundle opts = new Bundle();
    Rect size = AppWidgetResizeFrame.getWidgetSizeRanges(launcher, idp.numColumns, 1, null);
    opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, size.left);
    opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, size.top);
    opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, size.right);
    opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, size.bottom);

    int widgetId = prefs.getInt(QSB_WIDGET_ID, -1);
    AppWidgetProviderInfo widgetInfo = widgetManager.getAppWidgetInfo(widgetId);
    boolean isWidgetBound = (widgetInfo != null) &&
            widgetInfo.provider.equals(mWidgetInfo.provider);

    if (!isWidgetBound) {
        // widgetId is already bound and its not the correct provider.
        // Delete the widget id.
        if (widgetId > -1) {
            widgetHost.deleteAppWidgetId(widgetId);
            widgetId = -1;
        }

        widgetId = widgetHost.allocateAppWidgetId();
        isWidgetBound = widgetManager.bindAppWidgetIdIfAllowed(widgetId, mWidgetInfo, opts);
        if (!isWidgetBound) {
            widgetHost.deleteAppWidgetId(widgetId);
            widgetId = -1;
        }
    }

    if (isWidgetBound) {
        mQsb = (LauncherAppWidgetHostView)
                widgetHost.createView(launcher, widgetId, mWidgetInfo);
        mQsb.setId(R.id.qsb_widget);
        mQsb.mErrorViewId = R.layout.qsb_default_view;

        if (!Utilities.containsAll(AppWidgetManager.getInstance(launcher)
                .getAppWidgetOptions(widgetId), opts)) {
            mQsb.updateAppWidgetOptions(opts);
        }
        mQsb.setPadding(0, 0, 0, 0);
        return mQsb;
    }

    // Return a default widget with setup icon.
    return getDefaultView(inflater, container, true);
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:59,代码来源:QsbContainerView.java

示例14: preloadWidget

import com.android.launcher3.compat.AppWidgetManagerCompat; //导入依赖的package包/类
/**
 * Start preloading the widget.
 */
public boolean preloadWidget() {
    final LauncherAppWidgetProviderInfo pInfo = mInfo.info;

    if (pInfo.isCustomWidget) {
        return false;
    }
    final Bundle options = getDefaultOptionsForWidget(mLauncher, mInfo);

    // If there is a configuration activity, do not follow thru bound and inflate.
    if (pInfo.configure != null) {
        mInfo.bindOptions = options;
        return false;
    }

    mBindWidgetRunnable = new Runnable() {
        @Override
        public void run() {
            mWidgetLoadingId = mLauncher.getAppWidgetHost().allocateAppWidgetId();
            if (LOGD) {
                Log.d(TAG, "Binding widget, id: " + mWidgetLoadingId);
            }
            if(AppWidgetManagerCompat.getInstance(mLauncher).bindAppWidgetIdIfAllowed(
                    mWidgetLoadingId, pInfo, options)) {

                // Widget id bound. Inflate the widget.
                mHandler.post(mInflateWidgetRunnable);
            }
        }
    };

    mInflateWidgetRunnable = new Runnable() {
        @Override
        public void run() {
            if (LOGD) {
                Log.d(TAG, "Inflating widget, id: " + mWidgetLoadingId);
            }
            if (mWidgetLoadingId == -1) {
                return;
            }
            AppWidgetHostView hostView = mLauncher.getAppWidgetHost().createView(
                    (Context) mLauncher, mWidgetLoadingId, pInfo);
            mInfo.boundWidget = hostView;

            // We used up the widget Id in binding the above view.
            mWidgetLoadingId = -1;

            hostView.setVisibility(View.INVISIBLE);
            int[] unScaledSize = mLauncher.getWorkspace().estimateItemSize(mInfo, false);
            // We want the first widget layout to be the correct size. This will be important
            // for width size reporting to the AppWidgetManager.
            DragLayer.LayoutParams lp = new DragLayer.LayoutParams(unScaledSize[0],
                    unScaledSize[1]);
            lp.x = lp.y = 0;
            lp.customPosition = true;
            hostView.setLayoutParams(lp);
            if (LOGD) {
                Log.d(TAG, "Adding host view to drag layer");
            }
            mLauncher.getDragLayer().addView(hostView);
            mView.setTag(mInfo);
        }
    };

    if (LOGD) {
        Log.d(TAG, "About to bind/inflate widget");
    }
    mHandler.post(mBindWidgetRunnable);
    return true;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:73,代码来源:WidgetHostViewLoader.java

示例15: getOrCreateQsbBar

import com.android.launcher3.compat.AppWidgetManagerCompat; //导入依赖的package包/类
public View getOrCreateQsbBar() {
    if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
        return mLauncherCallbacks.getQsbBar();
    }

    if (mQsb == null) {
        AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this);
        if (searchProvider == null) {
            return null;
        }

        Bundle opts = new Bundle();
        opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
                AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);

        SharedPreferences sp = getSharedPreferences(
                LauncherAppState.getSharedPreferencesKey(), MODE_PRIVATE);
        int widgetId = sp.getInt(QSB_WIDGET_ID, -1);
        AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
        if (!searchProvider.provider.flattenToString().equals(
                sp.getString(QSB_WIDGET_PROVIDER, null))
                || (widgetInfo == null)
                || !widgetInfo.provider.equals(searchProvider.provider)) {
            // A valid widget is not already bound.
            if (widgetId > -1) {
                mAppWidgetHost.deleteAppWidgetId(widgetId);
                widgetId = -1;
            }

            // Try to bind a new widget
            widgetId = mAppWidgetHost.allocateAppWidgetId();

            if (!AppWidgetManagerCompat.getInstance(this)
                    .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) {
                mAppWidgetHost.deleteAppWidgetId(widgetId);
                widgetId = -1;
            }

            sp.edit()
                .putInt(QSB_WIDGET_ID, widgetId)
                .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString())
                .commit();
        }

        mAppWidgetHost.setQsbWidgetId(widgetId);
        if (widgetId != -1) {
            mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider);
            mQsb.setId(R.id.qsb_widget);
            mQsb.updateAppWidgetOptions(opts);
            mQsb.setPadding(0, 0, 0, 0);
            mSearchDropTargetBar.addView(mQsb);
            mSearchDropTargetBar.setQsbSearchBar(mQsb);
        }
    }
    return mQsb;
}
 
开发者ID:talentlo,项目名称:Trebuchet,代码行数:57,代码来源:Launcher.java


注:本文中的com.android.launcher3.compat.AppWidgetManagerCompat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。