Java 类android.appwidget.AppWidgetHostView 实例源码

项目:LaunchEnr    文件:Launcher.java   
void addAppWidgetImpl(int appWidgetId, ItemInfo info,
        AppWidgetHostView boundWidget, WidgetAddFlowHandler addFlowHandler, int delay) {
    if (!addFlowHandler.startConfigActivity(this, appWidgetId, info, REQUEST_CREATE_APPWIDGET)) {
        // If the configuration flow was not started, add the widget

        Runnable onComplete = new Runnable() {
            @Override
            public void run() {
                // Exit spring loaded mode if necessary after adding the widget
                exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
                        null);
            }
        };
        completeAddAppWidget(appWidgetId, info, boundWidget, addFlowHandler.getProviderInfo(this));
        mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
    }
}
项目:LaunchEnr    文件:LauncherAppWidgetHostView.java   
public LauncherAppWidgetHostView(Context context) {
    super(context);
    mContext = context;
    mLongPressHelper = new CheckLongPressHelper(this, this);
    mStylusEventHelper = new StylusEventHelper(new SimpleOnStylusPressListener(this), this);
    mInflater = LayoutInflater.from(context);
    setAccessibilityDelegate(Launcher.getLauncher(context).getAccessibilityDelegate());
    setBackgroundResource(R.drawable.widget_internal_focus_bg);

    if (AndroidVersion.isAtLeastOreo()) {
        try {
            Method asyncMethod = AppWidgetHostView.class
                    .getMethod("setExecutor", Executor.class);
            asyncMethod.invoke(this, Utilities.THREAD_POOL_EXECUTOR);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
项目:LaunchEnr    文件:WidgetHostViewLoader.java   
public static Bundle getDefaultOptionsForWidget(Context context, PendingAddWidgetInfo info) {
    Rect rect = new Rect();
    AppWidgetResizeFrame.getWidgetSizeRanges(context, info.spanX, info.spanY, rect);
    Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context,
            info.componentName, null);

    float density = context.getResources().getDisplayMetrics().density;
    int xPaddingDips = (int) ((padding.left + padding.right) / density);
    int yPaddingDips = (int) ((padding.top + padding.bottom) / density);

    Bundle options = new Bundle();
    options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH,
            rect.left - xPaddingDips);
    options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT,
            rect.top - yPaddingDips);
    options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH,
            rect.right - xPaddingDips);
    options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT,
            rect.bottom - yPaddingDips);
    return options;
}
项目:LaunchTime    文件:MainActivity.java   
private void removeDroppedItem(View dragObj) {
    if (mChildLock) return;

    try {
        mDragDropSource.removeView(dragObj);
        db().setAppCategoryOrder(mRevCategoryMap.get(mDragDropSource), mDragDropSource);

        if (mBeingDragged.isLink()) {
            db().deleteApp(mBeingDragged.getComponentName());
        }

        if (mBeingDragged.isWidget()) {

            db().deleteApp(mBeingDragged.getComponentName());
            AppWidgetHostView wid = mLoadedWidgets.remove(mBeingDragged.getActivityName());
            if (wid != null) {
                mWidgetHelper.widgetRemoved(wid.getAppWidgetId());
            }
        }
    } catch (Exception e) {
        Log.e(TAG, e.getMessage(), e);
    }
}
项目:LaunchTime    文件:Widget.java   
private AppWidgetHostView configureWidget(Intent data) {
    // Get the selected widget information
    Bundle extras = data.getExtras();
    int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
    AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
    if (appWidgetInfo.configure != null) {
        // If the widget wants to be configured then start its configuration activity
        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
        intent.setComponent(appWidgetInfo.configure);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        mParent.startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);
    } else {
        // Otherwise simply create it
        return createWidget(data);
    }
    return null;
}
项目:LaunchTime    文件:Widget.java   
public AppWidgetHostView onActivityResult(int requestCode, int resultCode, Intent data) {

        Log.d("LaunchWidgeth", "onActivityResult: requestCode=" + requestCode + " resultCode=" + resultCode);
        // listen for widget manager response
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == REQUEST_PICK_APPWIDGET) {
                Log.d("LaunchWidgeth", "configureWidget");
                return configureWidget(data);
            } else if (requestCode == REQUEST_CREATE_APPWIDGET || requestCode == REQUEST_BIND_APPWIDGET) {
                Log.d("LaunchWidgeth", "createWidget");
                return createWidget(data);
            } else {
                Log.d("LaunchWidgeth", "unknown RESULT_OK");
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            Log.d("LaunchWidgeth", "RESULT_CANCELED");
            if (data!=null) {
                int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
                if (appWidgetId != -1) {
                    mAppWidgetHost.deleteAppWidgetId(appWidgetId);
                }
            }

        }
        return null;
    }
项目:FlickLauncher    文件:Launcher.java   
private void addAppWidgetToWorkspace(
        AppWidgetHostView hostView, LauncherAppWidgetInfo item,
        LauncherAppWidgetProviderInfo appWidgetInfo, boolean insert) {
    hostView.setTag(item);
    item.onBindAppWidget(this, hostView);

    hostView.setFocusable(true);
    hostView.setOnFocusChangeListener(mFocusHandler);

    mWorkspace.addInScreen(hostView, item.container, item.screenId,
            item.cellX, item.cellY, item.spanX, item.spanY, insert);

    if (!item.isCustomWidget()) {
        addWidgetToAutoAdvanceIfNeeded(hostView, appWidgetInfo);
    }
}
项目:FlickLauncher    文件:Launcher.java   
void addAppWidgetImpl(int appWidgetId, ItemInfo info,
        AppWidgetHostView boundWidget, LauncherAppWidgetProviderInfo appWidgetInfo,
        int delay) {
    if (appWidgetInfo.configure != null) {
        setWaitingForResult(PendingRequestArgs.forWidgetInfo(appWidgetId, appWidgetInfo, info));

        // Launch over to configure widget, if needed
        mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
                mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
    } else {
        // Otherwise just add it
        Runnable onComplete = new Runnable() {
            @Override
            public void run() {
                // Exit spring loaded mode if necessary after adding the widget
                exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
                        null);
            }
        };
        completeAddAppWidget(appWidgetId, info, boundWidget, appWidgetInfo);
        mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
    }
}
项目:SimpleUILauncher    文件:Launcher.java   
private void addAppWidgetToWorkspace(
        AppWidgetHostView hostView, LauncherAppWidgetInfo item,
        LauncherAppWidgetProviderInfo appWidgetInfo, boolean insert) {
    hostView.setTag(item);
    item.onBindAppWidget(this, hostView);

    hostView.setFocusable(true);
    hostView.setOnFocusChangeListener(mFocusHandler);

    mWorkspace.addInScreen(hostView, item.container, item.screenId,
            item.cellX, item.cellY, item.spanX, item.spanY, insert);

    if (!item.isCustomWidget()) {
        addWidgetToAutoAdvanceIfNeeded(hostView, appWidgetInfo);
    }
}
项目:SimpleUILauncher    文件:Launcher.java   
void addAppWidgetImpl(int appWidgetId, ItemInfo info,
        AppWidgetHostView boundWidget, LauncherAppWidgetProviderInfo appWidgetInfo,
        int delay) {
    if (appWidgetInfo.configure != null) {
        setWaitingForResult(PendingRequestArgs.forWidgetInfo(appWidgetId, appWidgetInfo, info));

        // Launch over to configure widget, if needed
        mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
                mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
    } else {
        // Otherwise just add it
        Runnable onComplete = new Runnable() {
            @Override
            public void run() {
                // Exit spring loaded mode if necessary after adding the widget
                exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
                        null);
            }
        };
        completeAddAppWidget(appWidgetId, info, boundWidget, appWidgetInfo);
        mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
    }
}
项目:Shortcuts    文件:WidgetHandler.java   
public void createWidgetByID(RelativeLayout widget, int  ID) {
    widget.removeAllViews();

    int appWidgetId = ID;

    int H = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 150, this.getResources().getDisplayMetrics());
    int W = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 300, this.getResources().getDisplayMetrics());

    AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
    AppWidgetHostView hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
    hostView.setAppWidget(appWidgetId, appWidgetInfo);

    widgetWidth = appWidgetInfo.minWidth;
    widgetHeight = appWidgetInfo.minHeight;

    hostView.setMinimumWidth(widgetWidth);
    hostView.setMinimumHeight(widgetHeight);

    widget.addView(hostView);
    System.out.println(appWidgetInfo.provider.getClassName()
            + " Widget WH: " + appWidgetInfo.minWidth + "*" + appWidgetInfo.minHeight);
}
项目:SimplOS    文件:Launcher.java   
void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
        final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo,
        int delay) {
    if (appWidgetInfo.configure != null) {
        mPendingAddWidgetInfo = appWidgetInfo;
        mPendingAddWidgetId = appWidgetId;

        // Launch over to configure widget, if needed
        mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
                mAppWidgetHost, REQUEST_CREATE_APPWIDGET);

    } else {
        // Otherwise just add it
        Runnable onComplete = new Runnable() {
            @Override
            public void run() {
                // Exit spring loaded mode if necessary after adding the widget
                exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
                        null);
            }
        };
        completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
                appWidgetInfo);
        mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
    }
}
项目:SimplOS    文件:WidgetHostViewLoader.java   
public static Bundle getDefaultOptionsForWidget(Launcher launcher, PendingAddWidgetInfo info) {
    Bundle options = null;
    Rect rect = new Rect();
    if (Utilities.ATLEAST_JB_MR1) {
        AppWidgetResizeFrame.getWidgetSizeRanges(launcher, info.spanX, info.spanY, rect);
        Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(launcher,
                info.componentName, null);

        float density = launcher.getResources().getDisplayMetrics().density;
        int xPaddingDips = (int) ((padding.left + padding.right) / density);
        int yPaddingDips = (int) ((padding.top + padding.bottom) / density);

        options = new Bundle();
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH,
                rect.left - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT,
                rect.top - yPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH,
                rect.right - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT,
                rect.bottom - yPaddingDips);
    }
    return options;
}
项目:Trebuchet    文件:WidgetHostViewLoader.java   
public static Bundle getDefaultOptionsForWidget(Launcher launcher, PendingAddWidgetInfo info) {
    Bundle options = null;
    Rect rect = new Rect();
    if (Utilities.ATLEAST_JB_MR1) {
        AppWidgetResizeFrame.getWidgetSizeRanges(launcher, info.spanX, info.spanY, rect);
        Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(launcher,
                info.componentName, null);

        float density = launcher.getResources().getDisplayMetrics().density;
        int xPaddingDips = (int) ((padding.left + padding.right) / density);
        int yPaddingDips = (int) ((padding.top + padding.bottom) / density);

        options = new Bundle();
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH,
                rect.left - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT,
                rect.top - yPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH,
                rect.right - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT,
                rect.bottom - yPaddingDips);
    }
    return options;
}
项目:TurboLauncher    文件:AppsCustomizePagedView.java   
Bundle getDefaultOptionsForWidget(Launcher launcher, PendingAddWidgetInfo info) {
    Bundle options = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        AppWidgetResizeFrame.getWidgetSizeRanges(mLauncher, info.spanX, info.spanY, mTmpRect);
        Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(mLauncher,
                info.componentName, null);

        float density = getResources().getDisplayMetrics().density;
        int xPaddingDips = (int) ((padding.left + padding.right) / density);
        int yPaddingDips = (int) ((padding.top + padding.bottom) / density);

        options = new Bundle();
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH,
                mTmpRect.left - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT,
                mTmpRect.top - yPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH,
                mTmpRect.right - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT,
                mTmpRect.bottom - yPaddingDips);
    }
    return options;
}
项目:FLauncher    文件:Launcher.java   
void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
        final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo,
        int delay) {
    if (appWidgetInfo.configure != null) {
        mPendingAddWidgetInfo = appWidgetInfo;
        mPendingAddWidgetId = appWidgetId;

        // Launch over to configure widget, if needed
        mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
                mAppWidgetHost, REQUEST_CREATE_APPWIDGET);

    } else {
        // Otherwise just add it
        Runnable onComplete = new Runnable() {
            @Override
            public void run() {
                // Exit spring loaded mode if necessary after adding the widget
                exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
                        null);
            }
        };
        completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
                appWidgetInfo);
        mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
    }
}
项目:FLauncher    文件:WidgetHostViewLoader.java   
public static Bundle getDefaultOptionsForWidget(Launcher launcher, PendingAddWidgetInfo info) {
    Bundle options = null;
    Rect rect = new Rect();
    if (Utilities.ATLEAST_JB_MR1) {
        AppWidgetResizeFrame.getWidgetSizeRanges(launcher, info.spanX, info.spanY, rect);
        Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(launcher,
                info.componentName, null);

        float density = launcher.getResources().getDisplayMetrics().density;
        int xPaddingDips = (int) ((padding.left + padding.right) / density);
        int yPaddingDips = (int) ((padding.top + padding.bottom) / density);

        options = new Bundle();
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH,
                rect.left - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT,
                rect.top - yPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH,
                rect.right - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT,
                rect.bottom - yPaddingDips);
    }
    return options;
}
项目:FragmentHomescreen    文件:WidgetFragment.java   
public void addProvider(MainActivity m, AppWidgetHost host, AppWidgetManager manager, AppWidgetProviderInfo provider) {
    int id = host.allocateAppWidgetId();
    boolean success;
    success = manager.bindAppWidgetIdIfAllowed(id, provider.provider);

    if (success) {
        AppWidgetHostView hostView = host.createView(getActivity(), id, provider);
        AppWidgetProviderInfo appWidgetInfo = manager.getAppWidgetInfo(id);

        LauncherAppWidgetInfo info = new LauncherAppWidgetInfo(id);
        info.setHostView(hostView);
        info.getHostView().setAppWidget(id, appWidgetInfo);

        ItemInfo launcherInfo = attachWidget(info);
        if (launcherInfo != null) {
            WidgetPersistance.addDesktopAppWidget(screen, launcherInfo);
        }

    } else {
        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, provider.provider);
        m.startActivityForResult(intent, MainActivity.REQUEST_BIND_APPWIDGET);
    }

}
项目:LB-Launcher    文件:Launcher.java   
void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
        final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
        delay) {
    if (appWidgetInfo.configure != null) {
        mPendingAddWidgetInfo = appWidgetInfo;
        mPendingAddWidgetId = appWidgetId;

        // Launch over to configure widget, if needed
        mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
                mAppWidgetHost, REQUEST_CREATE_APPWIDGET);

    } else {
        // Otherwise just add it
        Runnable onComplete = new Runnable() {
            @Override
            public void run() {
                // Exit spring loaded mode if necessary after adding the widget
                exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
                        null);
            }
        };
        completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
                appWidgetInfo);
        mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
    }
}
项目:LB-Launcher    文件:AppsCustomizePagedView.java   
static Bundle getDefaultOptionsForWidget(Launcher launcher, PendingAddWidgetInfo info) {
    Bundle options = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        AppWidgetResizeFrame.getWidgetSizeRanges(launcher, info.spanX, info.spanY, sTmpRect);
        Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(launcher,
                info.componentName, null);

        float density = launcher.getResources().getDisplayMetrics().density;
        int xPaddingDips = (int) ((padding.left + padding.right) / density);
        int yPaddingDips = (int) ((padding.top + padding.bottom) / density);

        options = new Bundle();
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH,
                sTmpRect.left - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT,
                sTmpRect.top - yPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH,
                sTmpRect.right - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT,
                sTmpRect.bottom - yPaddingDips);
    }
    return options;
}
项目:LeanLauncher    文件:Launcher.java   
void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
                      final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
                              delay) {
    if (appWidgetInfo.configure != null) {
        mPendingAddWidgetInfo = appWidgetInfo;
        mPendingAddWidgetId = appWidgetId;

        // Launch over to configure widget, if needed
        mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
                mAppWidgetHost, REQUEST_CREATE_APPWIDGET);

    } else {
        // Otherwise just add it
        exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
        completeAddAppWidget(appWidgetId, info.container, boundWidget, appWidgetInfo);
    }
}
项目:LeanLauncher    文件:AppsCustomizePagedView.java   
static Bundle getDefaultOptionsForWidget(Launcher launcher, PendingAddWidgetInfo info) {
    Bundle options = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        AppWidgetResizeFrame.getWidgetSizeRanges(launcher, info.spanX, info.spanY, sTmpRect);
        Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(launcher,
                info.componentName, null);

        float density = launcher.getResources().getDisplayMetrics().density;
        int xPaddingDips = (int) ((padding.left + padding.right) / density);
        int yPaddingDips = (int) ((padding.top + padding.bottom) / density);

        options = new Bundle();
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH,
                sTmpRect.left - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT,
                sTmpRect.top - yPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH,
                sTmpRect.right - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT,
                sTmpRect.bottom - yPaddingDips);
    }
    return options;
}
项目:open-gel-plus    文件:Launcher.java   
void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
        AppWidgetProviderInfo appWidgetInfo) {
    if (appWidgetInfo.configure != null) {
        mPendingAddWidgetInfo = appWidgetInfo;

        // Launch over to configure widget, if needed
        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
        intent.setComponent(appWidgetInfo.configure);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
    } else {
        // Otherwise just add it
        completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
                appWidgetInfo);
        // Exit spring loaded mode if necessary after adding the widget
        exitSpringLoadedDragModeDelayed(true, false, null);
    }
}
项目:open-gel-plus    文件:AppsCustomizePagedView.java   
Bundle getDefaultOptionsForWidget(Launcher launcher, PendingAddWidgetInfo info) {
    Bundle options = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        AppWidgetResizeFrame.getWidgetSizeRanges(mLauncher, info.spanX, info.spanY, mTmpRect);
        Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(mLauncher,
                info.componentName, null);

        float density = getResources().getDisplayMetrics().density;
        int xPaddingDips = (int) ((padding.left + padding.right) / density);
        int yPaddingDips = (int) ((padding.top + padding.bottom) / density);

        options = new Bundle();
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH,
                mTmpRect.left - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT,
                mTmpRect.top - yPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH,
                mTmpRect.right - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT,
                mTmpRect.bottom - yPaddingDips);
    }
    return options;
}
项目:Fairphone    文件:Launcher.java   
void addAppWidgetImpl(final int appWidgetId, ItemInfo info,
        AppWidgetHostView boundWidget, AppWidgetProviderInfo appWidgetInfo) {
    if (appWidgetInfo.configure != null) {
        mPendingAddWidgetInfo = appWidgetInfo;

        // Launch over to configure widget, if needed
        Intent intent = new Intent(
                AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
        intent.setComponent(appWidgetInfo.configure);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
    } else {
        // Otherwise just add it
        completeAddAppWidget(appWidgetId, info.container, info.screen,
                boundWidget, appWidgetInfo);
        // Exit spring loaded mode if necessary after adding the widget
        exitSpringLoadedDragModeDelayed(true, false, null);
    }
}
项目:Fairphone    文件:AppsCustomizePagedView.java   
Bundle getDefaultOptionsForWidget(Launcher launcher, PendingAddWidgetInfo info) {
    Bundle options = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        AppWidgetResizeFrame.getWidgetSizeRanges(mLauncher, info.spanX, info.spanY, mTmpRect);
        Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(mLauncher,
                info.componentName, null);

        float density = getResources().getDisplayMetrics().density;
        int xPaddingDips = (int) ((padding.left + padding.right) / density);
        int yPaddingDips = (int) ((padding.top + padding.bottom) / density);

        options = new Bundle();
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH,
                mTmpRect.left - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT,
                mTmpRect.top - yPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH,
                mTmpRect.right - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT,
                mTmpRect.bottom - yPaddingDips);
    }
    return options;
}
项目:widgets    文件:FloatingWidget.java   
public void createWidget(Intent data) {
     Bundle extras = data.getExtras();
     RelativeLayout relativeLayout = relLayout;
     int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
     AppWidgetProviderInfo appWidgetInfo =
             mAppWidgetManager.getAppWidgetInfo(appWidgetId);
     AppWidgetHostView hostView =
             mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
     hostView.setAppWidget(appWidgetId, appWidgetInfo);


     RelativeLayout.LayoutParams rlps = new RelativeLayout.LayoutParams(WRAP_CONTENT,WRAP_CONTENT);
     rlps.addRule(CENTER_IN_PARENT);

     relativeLayout.addView(hostView,rlps);
     mAppWidgetHost.startListening();
     Log.v("WidgetsEvery0", appWidgetInfo.label);
}
项目:Fairphone---DEPRECATED    文件:Launcher.java   
void addAppWidgetImpl(final int appWidgetId, ItemInfo info,
        AppWidgetHostView boundWidget, AppWidgetProviderInfo appWidgetInfo) {
    if (appWidgetInfo.configure != null) {
        mPendingAddWidgetInfo = appWidgetInfo;

        // Launch over to configure widget, if needed
        Intent intent = new Intent(
                AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
        intent.setComponent(appWidgetInfo.configure);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
    } else {
        // Otherwise just add it
        completeAddAppWidget(appWidgetId, info.container, info.screen,
                boundWidget, appWidgetInfo);
        // Exit spring loaded mode if necessary after adding the widget
        exitSpringLoadedDragModeDelayed(true, false, null);
    }
}
项目:Fairphone---DEPRECATED    文件:AppsCustomizePagedView.java   
Bundle getDefaultOptionsForWidget(Launcher launcher, PendingAddWidgetInfo info) {
    Bundle options = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        AppWidgetResizeFrame.getWidgetSizeRanges(mLauncher, info.spanX, info.spanY, mTmpRect);
        Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(mLauncher,
                info.componentName, null);

        float density = getResources().getDisplayMetrics().density;
        int xPaddingDips = (int) ((padding.left + padding.right) / density);
        int yPaddingDips = (int) ((padding.top + padding.bottom) / density);

        options = new Bundle();
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH,
                mTmpRect.left - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT,
                mTmpRect.top - yPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH,
                mTmpRect.right - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT,
                mTmpRect.bottom - yPaddingDips);
    }
    return options;
}
项目:LaunchEnr    文件:Launcher.java   
@Thunk void completeTwoStageWidgetDrop(
        final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) {
    CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId);
    Runnable onCompleteRunnable = null;
    int animationType = 0;

    AppWidgetHostView boundWidget = null;
    if (resultCode == RESULT_OK) {
        animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
        final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
                requestArgs.getWidgetHandler().getProviderInfo(this));
        boundWidget = layout;
        onCompleteRunnable = new Runnable() {
            @Override
            public void run() {
                completeAddAppWidget(appWidgetId, requestArgs, layout, null);
                exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
                        EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
            }
        };
    } else if (resultCode == RESULT_CANCELED) {
        mAppWidgetHost.deleteAppWidgetId(appWidgetId);
        animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
    }
    if (mDragLayer.getAnimatedView() != null) {
        mWorkspace.animateWidgetDrop(requestArgs, cellLayout,
                (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
                animationType, boundWidget, true);
    } else if (onCompleteRunnable != null) {
        // The animated view may be null in the case of a rotation during widget configuration
        onCompleteRunnable.run();
    }
}
项目:LaunchEnr    文件:Launcher.java   
/**
 * Add a widget to the workspace.
 *
 * @param appWidgetId The app widget id
 */
@Thunk void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo,
        AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {

    if (appWidgetInfo == null) {
        appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
    }

    if (appWidgetInfo.isCustomWidget) {
        appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
    }

    LauncherAppWidgetInfo launcherInfo;
    launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
    launcherInfo.spanX = itemInfo.spanX;
    launcherInfo.spanY = itemInfo.spanY;
    launcherInfo.minSpanX = itemInfo.minSpanX;
    launcherInfo.minSpanY = itemInfo.minSpanY;
    launcherInfo.user = appWidgetInfo.getUser();

    getModelWriter().addItemToDatabase(launcherInfo,
            itemInfo.container, itemInfo.screenId, itemInfo.cellX, itemInfo.cellY);

    if (hostView == null) {
        // Perform actual inflation because we're live
        hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
    }
    hostView.setVisibility(View.VISIBLE);
    prepareAppWidget(hostView, launcherInfo);
    mWorkspace.addInScreen(hostView, launcherInfo);
}
项目:LaunchEnr    文件:Launcher.java   
/**
 * Process a widget drop.
 */
private void addAppWidgetFromDrop(PendingAddWidgetInfo info) {
    AppWidgetHostView hostView = info.boundWidget;
    int appWidgetId;
    WidgetAddFlowHandler addFlowHandler = info.getHandler();
    if (hostView != null) {
        // In the case where we've prebound the widget, we remove it from the DragLayer
        getDragLayer().removeView(hostView);

        appWidgetId = hostView.getAppWidgetId();
        addAppWidgetFromDropImpl(appWidgetId, info, hostView, addFlowHandler);

        // Clear the boundWidget so that it doesn't get destroyed.
        info.boundWidget = null;
    } else {
        // In this case, we either need to start an activity to get permission to bind
        // the widget, or we need to start an activity to configure the widget, or both.
        appWidgetId = getAppWidgetHost().allocateAppWidgetId();
        Bundle options = info.bindOptions;

        boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
                appWidgetId, info.info, options);
        if (success) {
            addAppWidgetFromDropImpl(appWidgetId, info, null, addFlowHandler);
        } else {
            addFlowHandler.startBindFlow(this, appWidgetId, info, REQUEST_BIND_APPWIDGET);
        }
    }
}
项目:LaunchEnr    文件:LauncherAppWidgetProviderInfo.java   
void initSpans(Context context) {
    InvariantDeviceProfile idp = LauncherAppState.getIDP(context);

    Point paddingLand = idp.landscapeProfile.getTotalWorkspacePadding();
    Point paddingPort = idp.portraitProfile.getTotalWorkspacePadding();

    // Always assume we're working with the smallest span to make sure we
    // reserve enough space in both orientations.
    float smallestCellWidth = DeviceProfile.calculateCellWidth(Math.min(
            idp.landscapeProfile.widthPx - paddingLand.x,
            idp.portraitProfile.widthPx - paddingPort.x),
            idp.numColumns);
    float smallestCellHeight = DeviceProfile.calculateCellWidth(Math.min(
            idp.landscapeProfile.heightPx - paddingLand.y,
            idp.portraitProfile.heightPx - paddingPort.y),
            idp.numRows);

    // We want to account for the extra amount of padding that we are adding to the widget
    // to ensure that it gets the full amount of space that it has requested.
    Rect widgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(
            context, provider, null);
    spanX = Math.max(1, (int) Math.ceil(
                    (minWidth + widgetPadding.left + widgetPadding.right) / smallestCellWidth));
    spanY = Math.max(1, (int) Math.ceil(
            (minHeight + widgetPadding.top + widgetPadding.bottom) / smallestCellHeight));

    minSpanX = Math.max(1, (int) Math.ceil(
            (minResizeWidth + widgetPadding.left + widgetPadding.right) / smallestCellWidth));
    minSpanY = Math.max(1, (int) Math.ceil(
            (minResizeHeight + widgetPadding.top + widgetPadding.bottom) / smallestCellHeight));
}
项目:LaunchEnr    文件:LauncherAppWidgetHost.java   
public AppWidgetHostView createView(Context context, int appWidgetId,
        LauncherAppWidgetProviderInfo appWidget) {
    if (appWidget.isCustomWidget) {
        LauncherAppWidgetHostView lahv = new LauncherAppWidgetHostView(context);
        LayoutInflater inflater = (LayoutInflater)
                context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(appWidget.initialLayout, lahv);
        lahv.setAppWidget(0, appWidget);
        lahv.updateLastInflationOrientation();
        return lahv;
    } else {
        try {
            return super.createView(context, appWidgetId, appWidget);
        } catch (Exception e) {
            if (!Utilities.isBinderSizeError(e)) {
                throw new RuntimeException(e);
            }

            // If the exception was thrown while fetching the remote views, let the view stay.
            // This will ensure that if the widget posts a valid update later, the view
            // will update.
            LauncherAppWidgetHostView view = mViews.get(appWidgetId);
            if (view == null) {
                view = onCreateView(mLauncher, appWidgetId, appWidget);
            }
            view.setAppWidget(appWidgetId, appWidget);
            view.switchToErrorView();
            return  view;
        }
    }
}
项目:LaunchEnr    文件:LauncherAppWidgetInfo.java   
/**
 * When we bind the widget, we should notify the widget that the size has changed if we have not
 * done so already (only really for default workspace widgets).
 */
void onBindAppWidget(Launcher launcher, AppWidgetHostView hostView) {
    if (!mHasNotifiedInitialWidgetSizeChanged) {
        AppWidgetResizeFrame.updateWidgetSizeRanges(hostView, launcher, spanX, spanY);
        mHasNotifiedInitialWidgetSizeChanged = true;
    }
}
项目:LaunchTime    文件:Widget.java   
private AppWidgetHostView createWidget(Intent data) {
    // Get the widget id
    Bundle extras = data.getExtras();
    int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);

    return createWidgetFromId(appWidgetId);
}
项目:LaunchTime    文件:Widget.java   
private AppWidgetHostView createWidgetFromId(int widget_id) {
    AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widget_id);

   // if (checkBindPermission(widget_id, appWidgetInfo.provider)) return null;

    // Create the host view
    AppWidgetHostView hostView = mAppWidgetHost.createView(mParent, widget_id, appWidgetInfo);
    hostView.setAppWidget(widget_id, appWidgetInfo);

    return hostView;
}
项目:FlickLauncher    文件:Launcher.java   
@Thunk void completeTwoStageWidgetDrop(
        final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) {
    CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId);
    Runnable onCompleteRunnable = null;
    int animationType = 0;

    AppWidgetHostView boundWidget = null;
    if (resultCode == RESULT_OK) {
        animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
        final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
                requestArgs.getWidgetProvider());
        boundWidget = layout;
        onCompleteRunnable = new Runnable() {
            @Override
            public void run() {
                completeAddAppWidget(appWidgetId, requestArgs, layout, null);
                exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
                        EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
            }
        };
    } else if (resultCode == RESULT_CANCELED) {
        mAppWidgetHost.deleteAppWidgetId(appWidgetId);
        animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
    }
    if (mDragLayer.getAnimatedView() != null) {
        mWorkspace.animateWidgetDrop(requestArgs, cellLayout,
                (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
                animationType, boundWidget, true);
    } else if (onCompleteRunnable != null) {
        // The animated view may be null in the case of a rotation during widget configuration
        onCompleteRunnable.run();
    }
}
项目:FlickLauncher    文件:Launcher.java   
/**
 * Add a widget to the workspace.
 *
 * @param appWidgetId The app widget id
 */
@Thunk void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo,
        AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {

    if (appWidgetInfo == null) {
        appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
    }

    if (appWidgetInfo.isCustomWidget) {
        appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
    }

    LauncherAppWidgetInfo launcherInfo;
    launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
    launcherInfo.spanX = itemInfo.spanX;
    launcherInfo.spanY = itemInfo.spanY;
    launcherInfo.minSpanX = itemInfo.minSpanX;
    launcherInfo.minSpanY = itemInfo.minSpanY;
    launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);

    LauncherModel.addItemToDatabase(this, launcherInfo,
            itemInfo.container, itemInfo.screenId, itemInfo.cellX, itemInfo.cellY);

    if (hostView == null) {
        // Perform actual inflation because we're live
        hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
    }
    hostView.setVisibility(View.VISIBLE);
    addAppWidgetToWorkspace(hostView, launcherInfo, appWidgetInfo, isWorkspaceLocked());
}
项目:FlickLauncher    文件:Launcher.java   
void addAppWidgetFromDropImpl(int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
        LauncherAppWidgetProviderInfo appWidgetInfo) {
    if (LOGD) {
        Log.d(TAG, "Adding widget from drop");
    }
    addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
}