Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c403178e authored by Richard MacGregor's avatar Richard MacGregor Committed by Raj Yengisetty
Browse files

Use icon from provider for navigation drawer

Now using provider supplied icon instead of random icon from resources.

Change-Id: I6d17f3df0bf5b2c5251217171e072f5d9c1fdb45
parent 15f7c59f
Loading
Loading
Loading
Loading
+15 −2
Original line number Original line Diff line number Diff line
@@ -17,8 +17,11 @@
package com.cyanogenmod.filemanager.controllers;
package com.cyanogenmod.filemanager.controllers;


import android.content.Context;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.res.ColorStateList;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Environment;
import android.os.Environment;
import android.os.storage.StorageVolume;
import android.os.storage.StorageVolume;
import android.support.design.widget.NavigationView;
import android.support.design.widget.NavigationView;
@@ -36,6 +39,7 @@ import com.cyanogenmod.filemanager.console.storageapi.StorageApiConsole;
import com.cyanogenmod.filemanager.model.Bookmark;
import com.cyanogenmod.filemanager.model.Bookmark;
import com.cyanogenmod.filemanager.preferences.AccessMode;
import com.cyanogenmod.filemanager.preferences.AccessMode;
import com.cyanogenmod.filemanager.util.StorageHelper;
import com.cyanogenmod.filemanager.util.StorageHelper;
import com.cyanogenmod.filemanager.util.StorageProviderUtils;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashMap;
@@ -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) {
    public void removeMenuItemFromDrawer(int hash) {
        mNavigationDrawer.getMenu().removeItem(hash);
        mNavigationDrawer.getMenu().removeItem(hash);
    }
    }
@@ -218,9 +230,10 @@ public class NavigationDrawerController
        // Concatenate title and summary
        // Concatenate title and summary
        // TODO: Change to two line menu items
        // TODO: Change to two line menu items
        String title = providerInfo.getTitle() + " " + providerInfo.getSummary();
        String title = providerInfo.getTitle() + " " + providerInfo.getSummary();

        Drawable icon = StorageProviderUtils.loadPackageIcon(mCtx, providerInfo.getAuthority(),
                providerInfo.getIcon());
        mProvidersMap.put(providerHashCode, providerInfo);
        mProvidersMap.put(providerHashCode, providerInfo);
        addMenuItemToDrawer(providerHashCode, title, R.drawable.ic_remote_drawable);
        addMenuItemToDrawer(providerHashCode, title, icon);
    }
    }


    public StorageProviderInfo getProviderInfoFromMenuItem(int key) {
    public StorageProviderInfo getProviderInfoFromMenuItem(int key) {
+51 −0
Original line number Original line 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;
    }
}