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


Java AppWidgetHostView.setAppWidget方法代码示例

本文整理汇总了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);
}
 
开发者ID:GeeksEmpireNet,项目名称:Shortcuts,代码行数:23,代码来源:WidgetHandler.java

示例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);
}
 
开发者ID:sakchhams,项目名称:widgets,代码行数:19,代码来源:FloatingWidget.java

示例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;
}
 
开发者ID:quaap,项目名称:LaunchTime,代码行数:12,代码来源:Widget.java

示例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;
}
 
开发者ID:SpiritCroc,项目名称:Modular-Remote,代码行数:9,代码来源:MainActivity.java

示例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;
}
 
开发者ID:qx,项目名称:FullRobolectricTestSample,代码行数:9,代码来源:ShadowAppWidgetHost.java

示例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;
}
 
开发者ID:quaap,项目名称:LaunchTime,代码行数:47,代码来源:Widget.java

示例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());
    });
}
 
开发者ID:farmerbb,项目名称:Taskbar,代码行数:44,代码来源:DashboardService.java

示例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();
            }
        }
    }
}
 
开发者ID:GeeksEmpireNet,项目名称:Shortcuts,代码行数:60,代码来源:WidgetHandler.java


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