app/src/main/java/fr/neamar/kiss/forwarder/Widgets.java
/**
     * Display all widgets based on state
     */
Display all widgets based on state
Display all widgets based on state
@SuppressWarnings("StringSplitter")
    private void restoreWidgets() {
        if (!prefs.getBoolean("history-hide", false)) {
            return;
        }
        mainActivity.emptyListView.setVisibility(View.GONE);
        widgetArea.removeAllViews();
        String widgetsConfString = prefs.getString(WIDGET_PREF_KEY, "");
        String[] widgetsConf = widgetsConfString.split(";");
        Set<Integer> idsUsed = new HashSet<>();
        for (String widgetConf : widgetsConf) {
            if (widgetConf.isEmpty()) {
                continue;
            }
            String[] conf = widgetConf.split("-");
            int id = Integer.parseInt(conf[0]);
            int lineSize = Integer.parseInt(conf[1]);
            idsUsed.add(id);
            AppWidgetHostView widget = getWidget(id, lineSize);
            if (widget != null) {
                widgetArea.addView(widget, LinearLayout.LayoutParams.MATCH_PARENT, widget.getLayoutParams().height);
            }
        }
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            int[] hostWidgetIds = mAppWidgetHost.getAppWidgetIds();
            for (int hostWidgetId : hostWidgetIds) {
                if (!idsUsed.contains(hostWidgetId)) {
                    mAppWidgetHost.deleteAppWidgetId(hostWidgetId);
                }
            }
        }
    }
@ SuppressWarnings ( "StringSplitter" ) private void restoreWidgets ( ) { if ( ! prefs . getBoolean ( "history-hide" , false ) ) { return ; } mainActivity . emptyListView . setVisibility ( View . GONE ) ; widgetArea . removeAllViews ( ) ; String widgetsConfString = prefs . getString ( WIDGET_PREF_KEY , "" ) ; String [ ] widgetsConf = widgetsConfString . split ( ";" ) ; Set < Integer > idsUsed = new HashSet < > ( ) ; for ( String widgetConf : widgetsConf ) { if ( widgetConf . isEmpty ( ) ) { continue ; } String [ ] conf = widgetConf . split ( "-" ) ; int id = Integer . parseInt ( conf [ 0 ] ) ; int lineSize = Integer . parseInt ( conf [ 1 ] ) ; idsUsed . add ( id ) ; AppWidgetHostView widget = getWidget ( id , lineSize ) ; if ( widget != null ) { widgetArea . addView ( widget , LinearLayout . LayoutParams . MATCH_PARENT , widget . getLayoutParams ( ) . height ) ; } } if ( android . os . Build . VERSION . SDK_INT >= android . os . Build . VERSION_CODES . O ) { int [ ] hostWidgetIds = mAppWidgetHost . getAppWidgetIds ( ) ; for ( int hostWidgetId : hostWidgetIds ) { if ( ! idsUsed . contains ( hostWidgetId ) ) { mAppWidgetHost . deleteAppWidgetId ( hostWidgetId ) ; } } } }
Display all widgets based on state
Display all widgets based on state
// only add widgets if in minimal mode // remove empty list view when using widgets, this would block touches on the widget // Add the widget into the linearlayout. LayoutParams as specified in getWidget() will be erased, so specify them again // kill zombie widgets