本文整理汇总了Java中android.appwidget.AppWidgetHostView.setAppWidget方法的典型用法代码示例。如果您正苦于以下问题:Java AppWidgetHostView.setAppWidget方法的具体用法?Java AppWidgetHostView.setAppWidget怎么用?Java AppWidgetHostView.setAppWidget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.appwidget.AppWidgetHostView
的用法示例。
在下文中一共展示了AppWidgetHostView.setAppWidget方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createWidgetByID
import android.appwidget.AppWidgetHostView; //导入方法依赖的package包/类
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);
}
示例2: createWidget
import android.appwidget.AppWidgetHostView; //导入方法依赖的package包/类
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);
}
示例3: createWidgetFromId
import android.appwidget.AppWidgetHostView; //导入方法依赖的package包/类
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;
}
示例4: createWidget
import android.appwidget.AppWidgetHostView; //导入方法依赖的package包/类
public View createWidget(int appWidgetId) {
AppWidgetProviderInfo appWidgetProviderInfo =
appWidgetManager.getAppWidgetInfo(appWidgetId);
AppWidgetHostView hostView = appWidgetHost
.createView(this, appWidgetId, appWidgetProviderInfo);
hostView.setAppWidget(appWidgetId, appWidgetProviderInfo);
return hostView;
}
示例5: createView
import android.appwidget.AppWidgetHostView; //导入方法依赖的package包/类
@Implementation
public AppWidgetHostView createView(Context context, int appWidgetId,
AppWidgetProviderInfo appWidget) {
AppWidgetHostView hostView = new AppWidgetHostView(context);
hostView.setAppWidget(appWidgetId, appWidget);
shadowOf(hostView).setHost(realAppWidgetHost);
return hostView;
}
示例6: loadWidget
import android.appwidget.AppWidgetHostView; //导入方法依赖的package包/类
public AppWidgetHostView loadWidget(AppLauncher app) {
ComponentName cn = new ComponentName(app.getPackageName(), app.getActivityName());
Log.d("LaunchWidgeth", "Loaded from db: " + cn.getClassName() + " - " + cn.getPackageName());
// Check that there actually is a widget in the database
if (cn.getPackageName().isEmpty() && cn.getClassName().isEmpty()) {
Log.d("LaunchWidgeth", "DB was empty");
return null;
}
final List<AppWidgetProviderInfo> infos = mAppWidgetManager.getInstalledProviders();
// Get AppWidgetProviderInfo
AppWidgetProviderInfo appWidgetInfo = null;
// Iterate through all infos, trying to find the desired one
for (final AppWidgetProviderInfo info : infos) {
if (info.provider.getClassName().equals(cn.getClassName()) &&
info.provider.getPackageName().equals(cn.getPackageName())) {
// We found it!
appWidgetInfo = info;
break;
}
}
if (appWidgetInfo == null) {
Log.d("LaunchWidgeth", "app info was null");
return null; // Stop here
}
// Allocate the hosted widget id
int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
if (checkBindPermission(appWidgetId, cn)) return null;
Log.d("LaunchWidgeth", "Allowed to bind");
Log.d("LaunchWidgeth", "creating widget");
// Create the host view
AppWidgetHostView hostView = mAppWidgetHost.createView(mParent, appWidgetId, appWidgetInfo);
// Set the desired widget
hostView.setAppWidget(appWidgetId, appWidgetInfo);
return hostView;
}
示例7: addWidget
import android.appwidget.AppWidgetHostView; //导入方法依赖的package包/类
private void addWidget(int appWidgetId, int cellId, boolean shouldSave) {
AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
final DashboardCell cellLayout = cells.get(cellId);
final AppWidgetHostView hostView = mAppWidgetHost.createView(DashboardService.this, appWidgetId, appWidgetInfo);
hostView.setAppWidget(appWidgetId, appWidgetInfo);
Bundle bundle = new Bundle();
bundle.putInt("cellId", cellId);
hostView.setTag(bundle);
cellLayout.findViewById(R.id.empty).setVisibility(View.GONE);
cellLayout.findViewById(R.id.placeholder).setVisibility(View.GONE);
cellLayout.setOnLongClickListener(olcl);
cellLayout.setOnGenericMotionListener(ogml);
cellLayout.setOnInterceptedLongPressListener(listener);
LinearLayout linearLayout = U.findViewById(cellLayout, R.id.dashboard);
linearLayout.addView(hostView);
Bundle bundle2 = (Bundle) cellLayout.getTag();
bundle2.putInt("appWidgetId", appWidgetId);
cellLayout.setTag(bundle2);
widgets.put(cellId, hostView);
if(shouldSave) {
SharedPreferences pref = U.getSharedPreferences(this);
SharedPreferences.Editor editor = pref.edit();
editor.putInt("dashboard_widget_" + Integer.toString(cellId), appWidgetId);
editor.putString("dashboard_widget_" + Integer.toString(cellId) + "_provider", appWidgetInfo.provider.flattenToString());
editor.remove("dashboard_widget_" + Integer.toString(cellId) + "_placeholder");
editor.apply();
}
new Handler().post(() -> {
ViewGroup.LayoutParams params = hostView.getLayoutParams();
params.width = cellLayout.getWidth();
params.height = cellLayout.getHeight();
hostView.setLayoutParams(params);
hostView.updateAppWidgetSize(null, cellLayout.getWidth(), cellLayout.getHeight(), cellLayout.getWidth(), cellLayout.getHeight());
});
}
示例8: createWidget
import android.appwidget.AppWidgetHostView; //导入方法依赖的package包/类
public void createWidget(Intent data) {
extras = data.getExtras(); System.out.println("EXTRA >> " + extras);
int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); System.out.println("WidgetID >> " + appWidgetId);
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);
if(MainScope.oneW == false){
sharedPrefNum = "1";
widget = widget1; widget1.removeAllViews();
widget1.addView(hostView);
System.out.println(appWidgetInfo.provider.getClassName()
+ " Widget WH: " + appWidgetInfo.minWidth + "*" + appWidgetInfo.minHeight);
saveWidgetInfo(sharedPrefNum, appWidgetId, appWidgetInfo.provider.getPackageName(), appWidgetInfo.provider.getClassName());
MainScope.oneW = true;
}
else if(MainScope.oneW == true){
if(MainScope.twoW == false){
sharedPrefNum = "2";
widget = widget2; widget2.removeAllViews();
widget2.addView(hostView);
System.out.println(appWidgetInfo.provider.getClassName()
+ " Widget WH: " + appWidgetInfo.minWidth + "*" + appWidgetInfo.minHeight);
saveWidgetInfo(sharedPrefNum, appWidgetId, appWidgetInfo.provider.getPackageName(), appWidgetInfo.provider.getClassName());
MainScope.twoW = true;
}
else if(MainScope.twoW == true){
if(MainScope.threeW == false){
sharedPrefNum = "3";
widget = widget3; widget3.removeAllViews();
widget3.addView(hostView);
System.out.println(appWidgetInfo.provider.getClassName()
+ " Widget WH: " + appWidgetInfo.minWidth + "*" + appWidgetInfo.minHeight);
saveWidgetInfo(sharedPrefNum, appWidgetId, appWidgetInfo.provider.getPackageName(), appWidgetInfo.provider.getClassName());
MainScope.threeW = true;
}
else if(MainScope.threeW == true){
Toast.makeText(getApplicationContext(), "Press-Hold on App Name to Remove Widget", Toast.LENGTH_SHORT).show();
}
}
}
}