Note that there are some explanatory texts on larger screens.

plurals
  1. POselected one from a few layouts(as themes) and use in remoteview
    text
    copied!<p>I have a multi-layouted widget, and here a few layouts (each as theme) and I need assign selected theme (layout) with desired remoteview. As in <a href="https://stackoverflow.com/questions/2570004/how-to-add-multiple-widgets-in-one-app">topic</a>, I added to manifest 2 receivers and created xml-files for differents layouts(themes). Now I have a few widgets in list, its ok, but can't understood how to assign layout with remoteview, becouse layout may be any selected. So question is follow: how to correct do assignatio desired layout ("A_Org_Widget" or "A_Org_Widget_right") with receiver, becouse I need to create functionality, user should only select type ot theme as widget name from list of widgets. How it need do correct?</p> <p>Now my code is: Manifest.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.widget.org" android:versionCode="1" android:versionName="1.0"&gt; &lt;uses-sdk android:minSdkVersion="7"/&gt; &lt;application android:icon="@drawable/android3d_small" android:label="@string/app_name"&gt; &lt;receiver android:name="A_Org_Widget" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt; &lt;/intent-filter&gt; &lt;intent-filter&gt; &lt;action android:name="com.widget.org.ACTION_RECEIVER" /&gt; &lt;/intent-filter&gt; &lt;intent-filter&gt; &lt;action android:name="com.widget.org.FORCE_WIDGET_UPDATE" /&gt; &lt;/intent-filter&gt; &lt;meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_info" /&gt; &lt;/receiver&gt; &lt;service android:name="A_Org_Widget$UpdateService" /&gt; &lt;receiver android:name="A_Org_Widget_right" android:label="A_Org_Widget_right"&gt; &lt;intent-filter&gt; &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt; &lt;/intent-filter&gt; &lt;meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_right" /&gt; &lt;/receiver&gt; &lt;receiver android:name="A_Org_Widget_small" android:label="A_Org_Widget_small"&gt; &lt;intent-filter&gt; &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt; &lt;/intent-filter&gt; &lt;meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_small" /&gt; &lt;/receiver&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>`</p> <p>and in code, receiver is follow</p> <pre><code> @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 &lt; 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 &lt; 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)); } } } } } ` </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload