まず、フロントエンド用のウィジェットを定義しました。私は2つの簡単な質問 設定を使用してウィジェットのプロパティを設定する
を持っている私は、これはその前端に添加した場合に、設定クラスをロードする必要がありますマニフェストXML<receiver android:name=".Widget" android:label="My Widget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget" />
</receiver>
これに追加します。もうウィジェットリストには表示されません。アクションをAPPWIDGET_CONFIGUREに変更してから
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="146dip"
android:minHeight="146dip"
android:updatePeriodMillis="0"
android:initialLayout="@layout/widget"
android:configure="com.deliveryninja.yourclock.configuration.Configure"
android:icon="@drawable/icon"
/>
これはウィジェットのxmlです。現在、私は単純な時計を使用しています。
設定クラスでは、私はWidgetModelに値を設定し、クロック属性のパスを共有属性に追加します。
構成クラスを使用してパスを取得し、ウィジェットを更新したいと考えています。
<?xml version="1.0" encoding="utf-8" ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Widget" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center">
<AnalogClock android:id="@+id/AnalogClock"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:hand_hour="@drawable/widgethour"
android:hand_minute="@drawable/widgetminute"
/>
</RelativeLayout>
ユーザーが選択した特定のリソースのパスにandroid:dialプロパティを設定できます。
これは私が苦労しているところです.AttributeSetでプロパティを設定し、RemoteViewsを使って新しいAnalogClockをウィジェットに追加する方法、またはウィジェットxmlの既存のAnalogClockのプロパティを編集する方法はありますか?
public static void updateOne(Context context, int appWidgetId){
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
WidgetModel widgetData = WidgetModel.getWidgetData(context, appWidgetId);
widgetData.getClockFacePath();
AnalogClock clock = new AnalogClock(context);
AttributeSet attributes = new //?? how do i make the AttributeSet
//RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
//views.setString(R.id.AnalogClock, , value)
}
私はこれをAnalogClockクラス描画可能なリソースのセッターとゲッターを公開します。私は、別の質問からコードを取得してURLを取得し、それから描画可能なリソースを作成します。その後、新しいMyClockを作成してセッターを使用するだけのケースです。うまくいけばそれはうまくいくはずです。 – DeliveryNinja