`
wang_peng1
  • 浏览: 3959637 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

更新appwight桌面小控件

阅读更多

一个小控件转换图片

private static int layoutId;

// onReceive should be something like this
@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();

    if (bundle != null) {
        int newLayoutId = bundle.getInt("layout_id");
              layoutId = newLayoutId;
        initViews(context);
    } else {
        initViews(context);
    }
}


private void initViews(Context context) {
    RemoteViews views = null;

    // Set the initial layout   
    if (layoutId == 0) {
        Intent layoutIntent = new Intent("android.appwidget.action.APPWIDGET_UPDATE");
        Bundle layoutBundle = new Bundle();

              layoutBundle.putInt("layout_id", 1);

        PendingIntent lPendingIntent = PendingIntent.getBroadcast(context, 0,
                layoutIntent, PendingIntent.FLAG_ONE_SHOT);

               views = new RemoteViews(context.getPackageName(), R.layout.layout_zero);

              views.setOnClickPendingIntent(R.id.btnNext, lPendingIntent);
    } // Else if there's some trigger to change the layout...
    else if (layoutId == 1) {
        Intent layoutIntent = new Intent("android.appwidget.action.APPWIDGET_UPDATE");
        Bundle layoutBundle = new Bundle();

        // Since I only have two layouts, I put here the id of the previous layout
        layoutBundle.putInt("layout_id", 0);

        PendingIntent lPendingIntent = PendingIntent.getBroadcast(context, 0,
                layoutIntent, PendingIntent.FLAG_ONE_SHOT);

              views = new RemoteViews(context.getPackageName(), R.layout.layout_one);
        views.setOnClickPendingIntent(R.id.btnPrev, lPendingIntent);
    }
}

2 其实简单的实践   widget_flame_with_border_off.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/main"
   android:gravity="center"
   android:background="@drawable/widget_frame_portrait1x1_black"
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_height="74dip"
   android:layout_width="74dip">

   <LinearLayout
      android:id="@+id/btn_led"
      android:layout_width="52dip"
      android:layout_height="52dip"
      android:background="@drawable/appwidget_button_center"
      android:clickable="true"
      android:focusable="true"
      android:gravity="center">

      <ImageView
          android:id="@+id/img_led"
          android:layout_height="40dip"
          android:layout_gravity="center"
          android:layout_width="40dip"
          android:src="@drawable/mototorch_led_off"
          android:scaleType="fitXY" />

   </LinearLayout>
</LinearLayout>

 

widget_flame_with_border_on.xml

<pre><?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/main"
   android:gravity="center"
   android:background="@drawable/widget_frame_portrait1x1_black"
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_height="74dip"
   android:layout_width="74dip">

   <LinearLayout
      android:id="@+id/btn_led"
      android:layout_width="52dip"
      android:layout_height="52dip"
      android:background="@drawable/appwidget_button_center"
      android:clickable="true"
      android:focusable="true"
      android:gravity="center">

      <ImageView
          android:id="@+id/img_led"
          android:layout_height="40dip"
          android:layout_gravity="center"
          android:layout_width="40dip"
          android:src="@drawable/mototorch_led_on"
          android:scaleType="fitXY" />

   </LinearLayout>
</LinearLayout>

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds){
     RemoteViews views = null;

     int layoutID = 0;

     if (ledIsOn){
         layoutID = R.layout.widget_flame_with_border_on;
     }
     else {
         layoutID = R.layout.widget_flame_with_border_off;
     }

     // the layoutID that is passed in the constructor of the
     //   RemoteViews object is the layout that will be loaded
     //   when the widget is updated.
     views = new RemoteViews(context.getPackageName(), layoutID);

     for (int i = 0; i < appWidgetIds.length; i++) {
          appWidgetManager.updateAppWidget(appWidgetIds[i], views);
     }
}

 

 

分享到:
评论

相关推荐

    桌面小控件

    【桌面小控件】是一种基于Eclipse开发环境创建的自定义UI组件,它可以在用户的桌面上提供便捷的功能或展示信息。这种小控件通常体积小巧,功能实用,能够提高用户的工作效率,为日常电脑操作增添便利。 在Windows...

    微软的远程桌面ActiveX控件 - msrdp.ocx

    微软的远程桌面ActiveX控件 微软的远程桌面ActiveX控件 微软的远程桌面ActiveX控件

    桌面时间控件.zip

    这种桌面时间控件通常以小部件或独立窗口的形式出现在计算机屏幕上,允许用户自定义显示样式、设置提醒或者与其他时间管理功能集成。 【描述】提到的"horloger安装包"可能是这个桌面时钟应用的主要程序文件,...

    安卓Launcher桌面相关-使用eclipse开发工具自己写的一个桌面小控件.rar

    本教程将基于 Eclipse 开发环境,讲解如何创建一个基本的自定义桌面小控件。 1. **Eclipse 环境搭建** - 首先,确保你已经安装了 Eclipse IDE for Java Developers,这是 Android 应用开发的基础。 - 安装 ADT...

    Window显示桌面控件

    在Windows操作系统中,“显示桌面”控件是一个非常实用的功能,它允许用户快速隐藏所有打开的窗口,以便查看桌面。这个功能对于需要频繁切换工作环境或者清理屏幕空间的用户来说尤其方便。下面我们将深入探讨“显示...

    桌面日历控件

    "桌面日历控件"是一种在个人电脑桌面上使用的应用程序,它为用户提供了方便的日程管理、时间跟踪以及节日和生日提醒等功能。这种控件通常作为一个小型的独立窗口或者集成在操作系统界面中,使得用户无需打开专门的...

    安卓桌面控件源码

    `AppWidgetProvider` 是一个广播接收器,负责监听和响应来自系统的事件,如用户添加、删除或更新桌面小部件。而`RemoteViews`则用来定义小部件在主屏幕上的布局和行为。 1. **AppWidgetProvider**: - 定义:...

    时间控件,timer controller, 桌面小时间控件,简单的时间控件

    时间控件,timer controller, 桌面小时间控件,简单的时间控件,

    c#多线程利用委托更新控件内容

    C# 多线程利用委托更新控件内容 在 C# 编程中,多线程编程是常见的场景之一,特别是在需要实时更新控件内容的情况下。为了解决多线程之间的数据更新问题,本文将介绍如何使用委托(delegate)来更新控件的内容。 ...

    Android之AppWidget(桌面小部件)开发浅析

    AppWidget 即桌面小部件,也叫桌面控件,就是能直接显示在Android系统桌面上的小程序,先看图:   图中我用黄色箭头指示的即为AppWidget,一些用户使用比较频繁的程序,可以做成AppWidget,这样能方便地使用。典型...

    android launcher桌面数字时钟控件

    这种控件通常作为桌面小部件供用户添加到主屏幕上,使得用户无需解锁设备就能快速查看时间。 Android的数字时钟控件设计灵活,开发者可以根据需求自定义样式和功能。它通常由两部分组成:小时和分钟,有时还包括秒...

    C++调用微软actieX控件实现远程桌面实例

    本文将深入探讨如何利用C++调用微软的ActiveX控件来实现远程桌面功能,这在系统管理和远程支持场景中非常实用。 首先,我们需要理解什么是ActiveX控件。ActiveX是微软提出的一种组件对象模型(COM),它允许开发者...

    android 桌面时钟控件开发代码

    这个代码是桌面时钟的控件代码,欢迎大家参考。

    C# 桌面桌面程序表格控件,带示例

    早先在github上下载的一个C#做桌面程序的表格控件资源,类似DevExpress里面的一些控件,当时主要是为了实现透明背景的表格,所以找的这个资源,里面有各种表格在winform和wpf上的应用示例

    c# 动态改变控件位置、控件大小、拖动控件

    首先,在`MouseDown`事件中记录鼠标点击时的相对位置,然后在`MouseMove`事件中计算新的位置并更新控件的位置。在`MouseUp`事件中停止移动。以下是一个简单的示例: ```csharp private Point dragOffset; ...

    delphi小键盘控件

    "delphi小键盘控件"是一个专为Delphi编程环境设计的组件,它允许开发者为应用程序添加类似于QQ小键盘的功能。这个控件提供了丰富的自定义选项,以满足各种界面设计需求。 Delphi是一种基于Object Pascal的集成开发...

    23.7 桌面集成控件.mp4

    23.7 桌面集成控件.mp4

    mfc根据窗口大小自动调整所有控件大小

    - 调整控件大小时,应考虑控件的最小和最大尺寸限制,以避免过小或过大影响用户体验。 - 要注意控件之间的相互依赖关系,比如两个控件的宽度或高度是相互关联的,需要确保这些关系在布局调整时得到正确处理。 ...

    原创C#Winform桌面应用中实用又美观的开关控件源码

    在C# Winform桌面应用程序开发中,用户界面的交互性和美观性是提升用户体验的关键因素之一。本主题将深入探讨如何创建一个既实用又美观的开关控件,这在很多应用场景中都非常常见,如设置界面、选项配置等。通过提供...

    C#控件拖动与改变大小

    通过这种方式,我们可以实现控件的拖动和改变大小,非常适合在 .Net 下开发桌面应用程序时使用。同时,这种技术也可以应用于窗体打印功能,动态生成非常漂亮和规整的报表来。 本文讨论了如何在 C# 中实现控件的拖动...

Global site tag (gtag.js) - Google Analytics