diff options
Diffstat (limited to 'src/com/android/launcher3/graphics/GridCustomizationsProvider.java')
-rw-r--r-- | src/com/android/launcher3/graphics/GridCustomizationsProvider.java | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/com/android/launcher3/graphics/GridCustomizationsProvider.java b/src/com/android/launcher3/graphics/GridCustomizationsProvider.java index fc8d855801..e4f5539dbd 100644 --- a/src/com/android/launcher3/graphics/GridCustomizationsProvider.java +++ b/src/com/android/launcher3/graphics/GridCustomizationsProvider.java @@ -9,6 +9,7 @@ import android.annotation.TargetApi; import android.content.ContentProvider; import android.content.ContentValues; import android.content.pm.PackageManager; +import android.content.res.XmlResourceParser; import android.database.Cursor; import android.database.MatrixCursor; import android.net.Uri; @@ -22,13 +23,23 @@ import android.os.Message; import android.os.Messenger; import android.util.ArrayMap; import android.util.Log; +import android.util.Xml; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.InvariantDeviceProfile.GridOption; +import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.util.Executors; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + /** * Exposes various launcher grid options and allows the caller to change them. * APIs: @@ -83,7 +94,7 @@ public class GridCustomizationsProvider extends ContentProvider { MatrixCursor cursor = new MatrixCursor(new String[] { KEY_NAME, KEY_ROWS, KEY_COLS, KEY_PREVIEW_COUNT, KEY_IS_DEFAULT}); InvariantDeviceProfile idp = InvariantDeviceProfile.INSTANCE.get(getContext()); - for (GridOption gridOption : idp.parseAllGridOptions(getContext())) { + for (GridOption gridOption : parseAllGridOptions()) { cursor.newRow() .add(KEY_NAME, gridOption.name) .add(KEY_ROWS, gridOption.numRows) @@ -105,6 +116,25 @@ public class GridCustomizationsProvider extends ContentProvider { } } + private List<GridOption> parseAllGridOptions() { + List<GridOption> result = new ArrayList<>(); + try (XmlResourceParser parser = getContext().getResources().getXml(R.xml.device_profiles)) { + final int depth = parser.getDepth(); + int type; + while (((type = parser.next()) != XmlPullParser.END_TAG || + parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { + if ((type == XmlPullParser.START_TAG) + && GridOption.TAG_NAME.equals(parser.getName())) { + result.add(new GridOption(getContext(), Xml.asAttributeSet(parser))); + } + } + } catch (IOException | XmlPullParserException e) { + Log.e(TAG, "Error parsing device profile", e); + return Collections.emptyList(); + } + return result; + } + @Override public String getType(Uri uri) { return "vnd.android.cursor.dir/launcher_grid"; @@ -125,10 +155,9 @@ public class GridCustomizationsProvider extends ContentProvider { switch (uri.getPath()) { case KEY_DEFAULT_GRID: { String gridName = values.getAsString(KEY_NAME); - InvariantDeviceProfile idp = InvariantDeviceProfile.INSTANCE.get(getContext()); // Verify that this is a valid grid option GridOption match = null; - for (GridOption option : idp.parseAllGridOptions(getContext())) { + for (GridOption option : parseAllGridOptions()) { if (option.name.equals(gridName)) { match = option; break; @@ -138,7 +167,8 @@ public class GridCustomizationsProvider extends ContentProvider { return 0; } - idp.setCurrentGrid(getContext(), gridName); + InvariantDeviceProfile.INSTANCE.get(getContext()) + .setCurrentGrid(getContext(), gridName); return 1; } case ICON_THEMED: |