выбрать один из нескольких макетов (в качестве тем) и использовать в удаленном - PullRequest
1 голос
/ 03 апреля 2012

У меня есть многослойный виджет, и здесь несколько макетов (каждый как тема), и мне нужно назначить выбранную тему (макет) с желаемым удаленным просмотром.Как и в topic , я добавил в манифест 2 получателя и создал xml-файлы для разных макетов (тем).Теперь у меня есть несколько виджетов в списке, это нормально, но я не могу понять, как назначить макет с удаленным видом, потому что макет может быть любым.Таким образом, вопрос заключается в следующем: как исправить присвоение желаемого макета («A_Org_Widget» или «A_Org_Widget_right») с приемником, потому что мне нужно создать функциональность, пользователь должен только выбрать тип темы в качестве имени виджета из списка виджетов.Как это нужно сделать правильно?

Теперь мой код: Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.widget.org"
    android:versionCode="1"
    android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7"/>
    <application android:icon="@drawable/android3d_small" android:label="@string/app_name">
        <receiver android:name="A_Org_Widget" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>

            <intent-filter>
                <action android:name="com.widget.org.ACTION_RECEIVER" />
            </intent-filter>

            <intent-filter>
                <action android:name="com.widget.org.FORCE_WIDGET_UPDATE" />
            </intent-filter>
            <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_info" />
        </receiver>

        <service android:name="A_Org_Widget$UpdateService" />

        <receiver android:name="A_Org_Widget_right" android:label="A_Org_Widget_right">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
            <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_right" />
        </receiver>

        <receiver android:name="A_Org_Widget_small" android:label="A_Org_Widget_small">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
            <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_small" />
        </receiver>
    </application>
</manifest>

`

и в коде получатель следует

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        //context.startService(new Intent(context, UpdateService.class));
        //this.widget_update(context, appWidgetManager, appWidgetIds);

        if (true==A_Org_Widget.DBG) Log.d(LOG_TAG, "  ===== onUpdate   appWidgetIds.length="+appWidgetIds.length);
        //for (int j = 0; j < appWidgetIds.length; j++)
        {

            if (0==AlreadyWasInited)
            { 
                AlreadyWasInited=1;

                if (true==A_Org_Widget.DBG) Log.d(LOG_TAG, "  ===== onUpdate INIT  " );
                //Toast.makeText(context,"Updating onUpdate()", Toast.LENGTH_LONG).show();
                //LappWidgetManager = appWidgetManager;
                final AppWidgetManager LappWidgetManager=AppWidgetManager.getInstance(context);

                //LappWidgetIds = appWidgetIds;
                /*ComponentName*/ componentName=new ComponentName(context, A_Org_Widget.class);
                LappWidgetIds=appWidgetManager.getAppWidgetIds(componentName);
                ////LappWidgetIds = Arrays.copyOf(appWidgetIds, appWidgetIds.length);


                super.onUpdate(context, LappWidgetManager, LappWidgetIds);
                if ("grey_bot"==A_Org_Widget.theme)
                    BasicView=BasicViewHorBott;
                if ("grey_left"==A_Org_Widget.theme)
                    BasicView=BasicViewVerLeft;

                String sptxt = context.getTheme().toString();
                if (true==A_Org_Widget.DBG) Log.d(LOG_TAG, "  ======= sptxt: " + sptxt);

                Intent IntentCalls = new Intent(context, A_Org_Widget.class);

                IntentCalls.setAction(ACTION_PHONECALLS);


                // Get the layout for the App Widget and attach an on-click listener to the button
                RView.setOnClickPendingIntent(R.id.ImageButton06, pIntentCalls);


                RView.setViewVisibility(R.id.ImageArrowCalls,   View.VISIBLE);



                Collector.NumStringsToShow = 36;
                //Collector.theme = "grey_left";

                // INITIALISATION
                if (0==Collector.ArrayInited)
                {
                    Collector.ArrayInited++;
                    if (null!=Collector.ACalls)
                    {
                        for (int i=0; i < Collector.NumStringsToShow; i++)
                        {
                            Collector.ACalls[i] = new Struct_TP_String();
                            Collector.ASMS[i]   = new Struct_TP_String();
                            Collector.AClndr[i] = new Struct_TP_String();
            //if (Emulator.IF_NEW) RView.addView( R.id.STR00+i, Collector.ACalls[i].RViewSt );
            //if (Emulator.IF_NEW) RView.setViewVisibility(R.id.STR00+i, View.VISIBLE);
                        }
                    }
                    Emulator.Prepare_Data_For_Emulate(context, RView);
                } else {
                    if (true==A_Org_Widget.DBG) Log.d(LOG_TAG, "  ======= ArrStrTmplStrings is already INITIALED!");
                }

                Collector.prev_key=0;
                Collector.curr_key=1;
                Emulator.ArabicStr=false;
                Collector.Selector(context, RView, R.id.ImageButton06, LappWidgetIds, "");
                Emulator.Prepare_Data_For_Emulate(context, RView);
                Emulator.ShowFromEmulator(context, RView);

//appWidgetManager.updateAppWidget(appWidgetIds, RView);
                context.sendBroadcast(new Intent(A_Org_Widget.FORCE_WIDGET_UPDATE));
                //appWidgetManager.updateAppWidget(appWidgetIds/*[j]*/, RView);
            } 
            // end of Init
            else
            // Ordinary tasks will be here in this block
            { 
                // Show must go on...
                if (true==A_Org_Widget.DBG) Log.d(LOG_TAG, "  ======= onUpdate JOB! ");
            }

        }
    }


    @Override
    public void onReceive(Context context, Intent intent) {
        // v1.5 fix that doesn't call onDelete Action
        final String action = intent.getAction();
            final AppWidgetManager LappWidgetManager=AppWidgetManager.getInstance(context);

            super.onReceive(context, intent);

            AppWidgetProviderInfo appWidgetProviderInfo = new AppWidgetProviderInfo();
            //String 
            int wwww=appWidgetProviderInfo.initialLayout;
        Log.d(LOG_TAG, "  ===== wwww=" +wwww);
        if (1==AlreadyWasInited)
        {
            if (FORCE_WIDGET_UPDATE.equals(intent.getAction())) {
                // TODO Обновить пользовательский интерфейс виджета.
                Log.d(LOG_TAG, "  ===== onReceive === FORCE_WIDGET_UPDATE" );
                LappWidgetManager.updateAppWidget(A_Org_Widget.LappWidgetIds, RView);
            }


            if (true==A_Org_Widget.DBG)
                Log.d(LOG_TAG, "  ===== onReceive " );

            if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action))
            {
                if (true==A_Org_Widget.DBG) Log.d(LOG_TAG, "  ======= onReceive: ACTION_APPWIDGET_DELETED");
                final int appWidgetId 
                    = intent.getExtras().getInt( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID );
                if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID)
                {
                    this.onDeleted(context, new int[] { appWidgetId } );
                }
            } 
            else
            {
                int id_button=0;
                //Collector.prev_key=Collector.curr_key;

                if (intent.getAction().equals(ACTION_PHONECALLS) ) {
                    id_button = R.id.ImageButton06;
                    Collector.curr_key=1;
                    Emulator.ArabicStr=false;
                }
    .....
                    if (0!=id_button){
                        if (Collector.curr_key != Collector.prev_key){
                            Emulator.now_date=Calendar.getInstance();
                            Emulator.date1=Emulator.now_date.getTimeInMillis();
                            Log.d(LOG_TAG, "  ======= KEY PRESSED, CALC TIME..."); 

                        Collector.Selector(context, RView, id_button, LappWidgetIds, "");
                        Emulator.Prepare_Data_For_Emulate(context, RView);
                        Emulator.ShowFromEmulator(context, RView);

                        //LappWidgetManager.updateAppWidget(A_Org_Widget.LappWidgetIds, RView);
                        context.sendBroadcast(new Intent(A_Org_Widget.FORCE_WIDGET_UPDATE));
                    }
                }
            }
        }
    }
`
...