레이블이 widget인 게시물을 표시합니다. 모든 게시물 표시
레이블이 widget인 게시물을 표시합니다. 모든 게시물 표시

2011년 6월 14일 화요일

Android - 어느 Widget에서 Configuration (Activity)를 호출하였나?

위젯을 생성할때 설정 화면(activity) 로 넘어가서 필요 한 데이터들을 설정한 다음에 위젯을 생성하는 경우가 있다.

manifast에

<activity android:name=".Configuration" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


그리고 앱 위젯 프로바이더에

<appwidget-provider
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="294dip"
    android:minHeight="146dip"
    android:initialLayout="@layout/biorhythm_clock_widget"
    android:configure="jh.project.widget.digital.biorhythm.Configuration"/>

이렇게 설정 해주면 된다.

하지만 다양한 종류의 위젯에서 하나의 설정 화면을 호출하는경우, 필요에 따라서 어느 앱 위젯 프로바이더에서 설정 화면을 호출하였는가가 중요할 때도 있다.

이런 경우에는

설정 화면(activity)의 onCreate(Bundle savedInstanceState) 함수 안에


Intent intent = getIntent();
Bundle extras = intent.getExtras();
   if (extras != null) {
    widgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,AppWidgetManager.INVALID_APPWIDGET_ID);


      AppWidgetManager manager = AppWidgetManager.getInstance(this);
      String className = manager.getAppWidgetInfo(widgetId).provider.getClassName();
    }
해주면 어느 프로바이더를 통해서 해당 activity가 호출 되었는지 알 수 있다.

2011년 5월 18일 수요일

Android - Widget(Remoteview)에 onClick 적용하기

AndroidManifest.xml - intent-filter에 해당 액션을 정의 해준다.

<intent-filter>

                <action android:name="jh.project.widget.digital.third.action.CLICK" />
</intent-filter>



source.java (AppWidgetProvider 에서 돌릴 service) - Remoteview에 onClick시 Pending Intent를 정의하고, onStart에 구현한다.

        static final String ACTION_CLICK = "jh.project.widget.digital.third.action.CLICK";

    public void onCreate() {
        RemoteViews views = new RemoteViews(getPackageName(), R.layout.main);

        Intent newIntent = new Intent();
        newIntent.setAction(ACTION_CLICK);
        PendingIntent pIntent = PendingIntent.getService(this, 0, newIntent, 0);
        views.setOnClickPendingIntent(R.id.imgin /*(event를 적용할 componet - e.g. ImageView)*/, pIntent);
    }


    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
     
        if (ACTION_CLICK.equals(intent.getAction())) {
         updateWidget();
        }
     
     
    }


맞나?? ㅋㅋ