Loading src/com/cyanogenmod/filemanager/controllers/NavigationDrawerController.java +15 −2 Original line number Diff line number Diff line Loading @@ -17,8 +17,11 @@ package com.cyanogenmod.filemanager.controllers; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.ProviderInfo; import android.content.res.ColorStateList; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Environment; import android.os.storage.StorageVolume; import android.support.design.widget.NavigationView; Loading @@ -36,6 +39,7 @@ import com.cyanogenmod.filemanager.console.storageapi.StorageApiConsole; import com.cyanogenmod.filemanager.model.Bookmark; import com.cyanogenmod.filemanager.preferences.AccessMode; import com.cyanogenmod.filemanager.util.StorageHelper; import com.cyanogenmod.filemanager.util.StorageProviderUtils; import java.util.ArrayList; import java.util.HashMap; Loading Loading @@ -199,6 +203,14 @@ public class NavigationDrawerController } } private void addMenuItemToDrawer(int hash, String title, Drawable iconDrawable) { if (mNavigationDrawer.getMenu().findItem(hash) == null) { mNavigationDrawer.getMenu() .add(R.id.navigation_group_roots, hash, 0, title) .setIcon(iconDrawable); } } public void removeMenuItemFromDrawer(int hash) { mNavigationDrawer.getMenu().removeItem(hash); } Loading @@ -218,9 +230,10 @@ public class NavigationDrawerController // Concatenate title and summary // TODO: Change to two line menu items String title = providerInfo.getTitle() + " " + providerInfo.getSummary(); Drawable icon = StorageProviderUtils.loadPackageIcon(mCtx, providerInfo.getAuthority(), providerInfo.getIcon()); mProvidersMap.put(providerHashCode, providerInfo); addMenuItemToDrawer(providerHashCode, title, R.drawable.ic_remote_drawable); addMenuItemToDrawer(providerHashCode, title, icon); } public StorageProviderInfo getProviderInfoFromMenuItem(int key) { Loading src/com/cyanogenmod/filemanager/util/StorageProviderUtils.java 0 → 100644 +51 −0 Original line number Diff line number Diff line /* * Copyright (C) 2015 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.cyanogenmod.filemanager.util; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.ProviderInfo; import android.graphics.drawable.Drawable; /** * A helper class with useful methods for dealing with Storage Providers. */ public final class StorageProviderUtils { private static final String TAG = StorageProviderUtils.class.getSimpleName(); /** * Return the Drawable for this Storage Provider * @param context * @param authority * @param icon */ public static Drawable loadPackageIcon(Context context, String authority, int icon) { if (icon != 0) { if (authority != null) { final PackageManager pm = context.getPackageManager(); final ProviderInfo info = pm.resolveContentProvider(authority, 0); if (info != null) { return pm.getDrawable(info.packageName, icon, info.applicationInfo); } } else { return context.getDrawable(icon); } } return null; } } Loading
src/com/cyanogenmod/filemanager/controllers/NavigationDrawerController.java +15 −2 Original line number Diff line number Diff line Loading @@ -17,8 +17,11 @@ package com.cyanogenmod.filemanager.controllers; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.ProviderInfo; import android.content.res.ColorStateList; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Environment; import android.os.storage.StorageVolume; import android.support.design.widget.NavigationView; Loading @@ -36,6 +39,7 @@ import com.cyanogenmod.filemanager.console.storageapi.StorageApiConsole; import com.cyanogenmod.filemanager.model.Bookmark; import com.cyanogenmod.filemanager.preferences.AccessMode; import com.cyanogenmod.filemanager.util.StorageHelper; import com.cyanogenmod.filemanager.util.StorageProviderUtils; import java.util.ArrayList; import java.util.HashMap; Loading Loading @@ -199,6 +203,14 @@ public class NavigationDrawerController } } private void addMenuItemToDrawer(int hash, String title, Drawable iconDrawable) { if (mNavigationDrawer.getMenu().findItem(hash) == null) { mNavigationDrawer.getMenu() .add(R.id.navigation_group_roots, hash, 0, title) .setIcon(iconDrawable); } } public void removeMenuItemFromDrawer(int hash) { mNavigationDrawer.getMenu().removeItem(hash); } Loading @@ -218,9 +230,10 @@ public class NavigationDrawerController // Concatenate title and summary // TODO: Change to two line menu items String title = providerInfo.getTitle() + " " + providerInfo.getSummary(); Drawable icon = StorageProviderUtils.loadPackageIcon(mCtx, providerInfo.getAuthority(), providerInfo.getIcon()); mProvidersMap.put(providerHashCode, providerInfo); addMenuItemToDrawer(providerHashCode, title, R.drawable.ic_remote_drawable); addMenuItemToDrawer(providerHashCode, title, icon); } public StorageProviderInfo getProviderInfoFromMenuItem(int key) { Loading
src/com/cyanogenmod/filemanager/util/StorageProviderUtils.java 0 → 100644 +51 −0 Original line number Diff line number Diff line /* * Copyright (C) 2015 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.cyanogenmod.filemanager.util; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.ProviderInfo; import android.graphics.drawable.Drawable; /** * A helper class with useful methods for dealing with Storage Providers. */ public final class StorageProviderUtils { private static final String TAG = StorageProviderUtils.class.getSimpleName(); /** * Return the Drawable for this Storage Provider * @param context * @param authority * @param icon */ public static Drawable loadPackageIcon(Context context, String authority, int icon) { if (icon != 0) { if (authority != null) { final PackageManager pm = context.getPackageManager(); final ProviderInfo info = pm.resolveContentProvider(authority, 0); if (info != null) { return pm.getDrawable(info.packageName, icon, info.applicationInfo); } } else { return context.getDrawable(icon); } } return null; } }