本文整理汇总了Java中android.appwidget.AppWidgetHost类的典型用法代码示例。如果您正苦于以下问题:Java AppWidgetHost类的具体用法?Java AppWidgetHost怎么用?Java AppWidgetHost使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AppWidgetHost类属于android.appwidget包,在下文中一共展示了AppWidgetHost类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createWorkspaceLoaderFromAppRestriction
import android.appwidget.AppWidgetHost; //导入依赖的package包/类
/**
* Creates workspace loader from an XML resource listed in the app restrictions.
*
* @return the loader if the restrictions are set and the resource exists; null otherwise.
*/
private AutoInstallsLayout createWorkspaceLoaderFromAppRestriction(AppWidgetHost widgetHost) {
Context ctx = getContext();
UserManager um = (UserManager) ctx.getSystemService(Context.USER_SERVICE);
Bundle bundle = um.getApplicationRestrictions(ctx.getPackageName());
if (bundle == null) {
return null;
}
String packageName = bundle.getString(RESTRICTION_PACKAGE_NAME);
if (packageName != null) {
try {
Resources targetResources = ctx.getPackageManager()
.getResourcesForApplication(packageName);
return AutoInstallsLayout.get(ctx, packageName, targetResources,
widgetHost, mOpenHelper);
} catch (NameNotFoundException e) {
e.printStackTrace();
return null;
}
}
return null;
}
示例2: setupWidget
import android.appwidget.AppWidgetHost; //导入依赖的package包/类
private boolean setupWidget() {
LauncherAppWidgetProviderInfo widgetInfo = LauncherAppWidgetProviderInfo
.fromProviderInfo(this, mRequest.getAppWidgetProviderInfo(this));
if (widgetInfo.minSpanX > mIdp.numColumns || widgetInfo.minSpanY > mIdp.numRows) {
// Cannot add widget
return false;
}
mWidgetCell.setPreview(PinItemDragListener.getPreview(mRequest));
mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
mAppWidgetHost = new AppWidgetHost(this, Launcher.APPWIDGET_HOST_ID);
mPendingWidgetInfo = new PendingAddWidgetInfo(widgetInfo);
mPendingWidgetInfo.spanX = Math.min(mIdp.numColumns, widgetInfo.spanX);
mPendingWidgetInfo.spanY = Math.min(mIdp.numRows, widgetInfo.spanY);
mWidgetOptions = WidgetHostViewLoader.getDefaultOptionsForWidget(this, mPendingWidgetInfo);
WidgetItem item = new WidgetItem(widgetInfo, getPackageManager(), mIdp);
mWidgetCell.getWidgetView().setTag(mPendingWidgetInfo);
mWidgetCell.applyFromCellItem(item, mApp.getWidgetCache());
mWidgetCell.ensurePreview();
return true;
}
示例3: AutoInstallsLayout
import android.appwidget.AppWidgetHost; //导入依赖的package包/类
AutoInstallsLayout(Context context, AppWidgetHost appWidgetHost,
LayoutParserCallback callback, Resources res,
int layoutId, String rootTag) {
mContext = context;
mAppWidgetHost = appWidgetHost;
mCallback = callback;
mPackageManager = context.getPackageManager();
mValues = new ContentValues();
mRootTag = rootTag;
mSourceRes = res;
mLayoutId = layoutId;
mIdp = LauncherAppState.getIDP(context);
mRowCount = mIdp.numRows;
mColumnCount = mIdp.numColumns;
}
示例4: onEmptyDbCreated
import android.appwidget.AppWidgetHost; //导入依赖的package包/类
/**
* Overriden in tests.
*/
protected void onEmptyDbCreated() {
// Database was just created, so wipe any previous widgets
if (mWidgetHostResetHandler != null) {
new AppWidgetHost(mContext, Launcher.APPWIDGET_HOST_ID).deleteHost();
mWidgetHostResetHandler.sendMessage(Message.obtain(
mWidgetHostResetHandler,
ChangeListenerWrapper.MSG_APP_WIDGET_HOST_RESET,
mContext
));
}
// Set the flag for empty DB
Utilities.getPrefs(mContext).edit().putBoolean(EMPTY_DATABASE_CREATED, true).commit();
// When a new DB is created, remove all previously stored managed profile information.
ManagedProfileHeuristic.processAllUsers(Collections.<UserHandleCompat>emptyList(),
mContext);
}
示例5: AutoInstallsLayout
import android.appwidget.AppWidgetHost; //导入依赖的package包/类
public AutoInstallsLayout(Context context, AppWidgetHost appWidgetHost,
LayoutParserCallback callback, Resources res,
int layoutId, String rootTag) {
mContext = context;
mAppWidgetHost = appWidgetHost;
mCallback = callback;
mPackageManager = context.getPackageManager();
mValues = new ContentValues();
mRootTag = rootTag;
mSourceRes = res;
mLayoutId = layoutId;
mIdp = LauncherAppState.getInstance().getInvariantDeviceProfile();
mRowCount = mIdp.numRows;
mColumnCount = mIdp.numColumns;
}
示例6: onReceive
import android.appwidget.AppWidgetHost; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
mAppWidgetManager = AppWidgetManager.getInstance(context);
mAppWidgetHost = new AppWidgetHost(context, intent.getIntExtra("appWidgetId", -1));
cellId = intent.getIntExtra("cellId", -1);
int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
try {
startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
} catch (ActivityNotFoundException e) {
U.showToast(DashboardActivity.this, R.string.lock_device_not_supported);
finish();
}
shouldFinish = false;
}
示例7: DatabaseHelper
import android.appwidget.AppWidgetHost; //导入依赖的package包/类
DatabaseHelper(Context context) {
super(context, LauncherFiles.LAUNCHER_DB, null, DATABASE_VERSION);
mContext = context;
mAppWidgetHost = new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID);
// Table creation sometimes fails silently, which leads to a crash loop.
// This way, we will try to create a table every time after crash, so the device
// would eventually be able to recover.
if (!tableExists(TABLE_FAVORITES) || !tableExists(TABLE_WORKSPACE_SCREENS)) {
Log.e(TAG, "Tables are missing after onCreate has been called. Trying to recreate");
// This operation is a no-op if the table already exists.
addFavoritesTable(getWritableDatabase(), true);
addWorkspacesTable(getWritableDatabase(), true);
}
// In the case where neither onCreate nor onUpgrade gets called, we read the maxId from
// the DB here
if (mMaxItemId == -1) {
mMaxItemId = initializeMaxItemId(getWritableDatabase());
}
if (mMaxScreenId == -1) {
mMaxScreenId = initializeMaxScreenId(getWritableDatabase());
}
}
示例8: AutoInstallsLayout
import android.appwidget.AppWidgetHost; //导入依赖的package包/类
public AutoInstallsLayout(Context context, AppWidgetHost appWidgetHost,
LayoutParserCallback callback, Resources res,
int layoutId, String rootTag) {
mContext = context;
mAppWidgetHost = appWidgetHost;
mCallback = callback;
mPackageManager = context.getPackageManager();
mValues = new ContentValues();
mRootTag = rootTag;
mSourceRes = res;
mLayoutId = layoutId;
InvariantDeviceProfile idp = LauncherAppState.getInstance().getInvariantDeviceProfile();
mHotseatAllAppsRank = idp.hotseatAllAppsRank;
mRowCount = idp.numRows;
mColumnCount = idp.numColumns;
}
示例9: addProvider
import android.appwidget.AppWidgetHost; //导入依赖的package包/类
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);
}
}
示例10: get
import android.appwidget.AppWidgetHost; //导入依赖的package包/类
static AutoInstallsLayout get(Context context, AppWidgetHost appWidgetHost,
LayoutParserCallback callback) {
Pair<String, Resources> customizationApkInfo = Utilities.findSystemApk(
ACTION_LAUNCHER_CUSTOMIZATION, context.getPackageManager());
if (customizationApkInfo == null) {
return null;
}
String pkg = customizationApkInfo.first;
Resources res = customizationApkInfo.second;
int layoutId = res.getIdentifier(LAYOUT_RES, "xml", pkg);
if (layoutId == 0) {
Log.e(TAG, "Layout definition not found in package: " + pkg);
return null;
}
return new AutoInstallsLayout(context, appWidgetHost, callback, res, layoutId,
TAG_WORKSPACE);
}
示例11: AutoInstallsLayout
import android.appwidget.AppWidgetHost; //导入依赖的package包/类
public AutoInstallsLayout(Context context, AppWidgetHost appWidgetHost,
LayoutParserCallback callback, Resources res,
int layoutId, String rootTag) {
mContext = context;
mAppWidgetHost = appWidgetHost;
mCallback = callback;
mPackageManager = context.getPackageManager();
mValues = new ContentValues();
mRootTag = rootTag;
mSourceRes = res;
mLayoutId = layoutId;
mHotseatAllAppsRank = LauncherAppState.getInstance()
.getDynamicGrid().getDeviceProfile().hotseatAllAppsRank;
}
示例12: startConfigActivity
import android.appwidget.AppWidgetHost; //导入依赖的package包/类
@Override
public void startConfigActivity(AppWidgetProviderInfo info, int widgetId, Activity activity,
AppWidgetHost host, int requestCode) {
try {
host.startAppWidgetConfigureActivityForResult(activity, widgetId, 0, requestCode, null);
} catch (ActivityNotFoundException | SecurityException e) {
Toast.makeText(activity, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
}
}
示例13: get
import android.appwidget.AppWidgetHost; //导入依赖的package包/类
static AutoInstallsLayout get(Context context, AppWidgetHost appWidgetHost,
LayoutParserCallback callback) {
Pair<String, Resources> customizationApkInfo = Utilities.findSystemApk(
ACTION_LAUNCHER_CUSTOMIZATION, context.getPackageManager());
if (customizationApkInfo == null) {
return null;
}
return get(context, customizationApkInfo.first, customizationApkInfo.second,
appWidgetHost, callback);
}
示例14: startConfigActivity
import android.appwidget.AppWidgetHost; //导入依赖的package包/类
@Override
public void startConfigActivity(AppWidgetProviderInfo info, int widgetId, Activity activity,
AppWidgetHost host, int requestCode) {
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
intent.setComponent(info.configure);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
Utilities.startActivityForResultSafely(activity, intent, requestCode);
}
示例15: createWorkspaceLoaderFromAppRestriction
import android.appwidget.AppWidgetHost; //导入依赖的package包/类
/**
* Creates workspace loader from an XML resource listed in the app restrictions.
*
* @return the loader if the restrictions are set and the resource exists; null otherwise.
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private AutoInstallsLayout createWorkspaceLoaderFromAppRestriction(AppWidgetHost widgetHost) {
// UserManager.getApplicationRestrictions() requires minSdkVersion >= 18
if (!Utilities.ATLEAST_JB_MR2) {
return null;
}
Context ctx = getContext();
UserManager um = (UserManager) ctx.getSystemService(Context.USER_SERVICE);
Bundle bundle = um.getApplicationRestrictions(ctx.getPackageName());
if (bundle == null) {
return null;
}
String packageName = bundle.getString(RESTRICTION_PACKAGE_NAME);
if (packageName != null) {
try {
Resources targetResources = ctx.getPackageManager()
.getResourcesForApplication(packageName);
return AutoInstallsLayout.get(ctx, packageName, targetResources,
widgetHost, mOpenHelper);
} catch (NameNotFoundException e) {
Log.e(TAG, "Target package for restricted profile not found", e);
return null;
}
}
return null;
}