Example usage for android.support.v4.content ContextCompat getDrawable

List of usage examples for android.support.v4.content ContextCompat getDrawable

Introduction

In this page you can find the example usage for android.support.v4.content ContextCompat getDrawable.

Prototype

public static final Drawable getDrawable(Context context, int i) 

Source Link

Usage

From source file:com.amaze.filemanager.activities.MainActivity.java

public void refreshDrawer() {
    List<String> val = DataUtils.getStorages();
    if (val == null)
        val = getStorageDirectories();
    ArrayList<Item> list = new ArrayList<>();
    storage_count = 0;//  w  w w . j  a  va 2  s. c  om
    for (String file : val) {
        File f = new File(file);
        String name;
        Drawable icon1 = ContextCompat.getDrawable(this, R.drawable.ic_sd_storage_white_56dp);
        if ("/storage/emulated/legacy".equals(file) || "/storage/emulated/0".equals(file)) {
            name = getResources().getString(R.string.storage);
        } else if ("/storage/sdcard1".equals(file)) {
            name = getResources().getString(R.string.extstorage);
        } else if ("/".equals(file)) {
            name = getResources().getString(R.string.rootdirectory);
            icon1 = ContextCompat.getDrawable(this, R.drawable.ic_drawer_root_white);
        } else
            name = f.getName();
        if (!f.isDirectory() || f.canExecute()) {
            storage_count++;
            list.add(new EntryItem(name, file, icon1));
        }
    }
    list.add(new SectionItem());
    ArrayList<String[]> Servers = DataUtils.getServers();
    if (Servers != null && Servers.size() > 0) {
        for (String[] file : Servers) {
            list.add(new EntryItem(file[0], file[1],
                    ContextCompat.getDrawable(this, R.drawable.ic_settings_remote_white_48dp)));
        }

        list.add(new SectionItem());
    }
    ArrayList<String[]> accounts = DataUtils.getAccounts();
    if (accounts != null && accounts.size() > 0) {
        for (String[] file : accounts) {
            list.add(new EntryItem(file[0], file[1], ContextCompat.getDrawable(this, R.drawable.drive)));
        }

        list.add(new SectionItem());
    }
    ArrayList<String[]> books = DataUtils.getBooks();
    if (books != null && books.size() > 0) {

        for (String[] file : books) {
            list.add(new EntryItem(file[0], file[1], ContextCompat.getDrawable(this, R.drawable.folder_fab)));
        }
        list.add(new SectionItem());
    }
    list.add(new EntryItem(getResources().getString(R.string.quick), "5",
            ContextCompat.getDrawable(this, R.drawable.ic_star_white_18dp)));
    list.add(new EntryItem(getResources().getString(R.string.recent), "6",
            ContextCompat.getDrawable(this, R.drawable.ic_history_white_48dp)));
    list.add(new EntryItem(getResources().getString(R.string.images), "0",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_image)));
    list.add(new EntryItem(getResources().getString(R.string.videos), "1",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_video_am)));
    list.add(new EntryItem(getResources().getString(R.string.audio), "2",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_audio_am)));
    list.add(new EntryItem(getResources().getString(R.string.documents), "3",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_doc_am)));
    list.add(new EntryItem(getResources().getString(R.string.apks), "4",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_apk_grid)));
    DataUtils.setList(list);
    adapter = new DrawerAdapter(con, list, MainActivity.this, Sp);
    mDrawerList.setAdapter(adapter);

}

From source file:com.filemanager.free.activities.MainActivity.java

public void refreshDrawer() {
    List<String> val = DataUtils.getStorages();
    if (val == null)
        val = getStorageDirectories();
    ArrayList<Item> list = new ArrayList<>();
    storage_count = 0;/* w ww .ja  v a2s  . co  m*/
    for (String file : val) {
        File f = new File(file);
        String name;
        Drawable icon1 = ContextCompat.getDrawable(this, R.drawable.ic_memory_white_24dp);
        if ("/storage/emulated/legacy".equals(file) || "/storage/emulated/0".equals(file)) {
            name = getResources().getString(R.string.storage);
            icon1 = ContextCompat.getDrawable(this, R.drawable.ic_sd_storage_white_24dp);
        } else if ("/storage/sdcard1".equals(file)) {
            name = getResources().getString(R.string.extstorage);
        } else if ("/".equals(file)) {
            name = getResources().getString(R.string.rootdirectory);
            icon1 = ContextCompat.getDrawable(this, R.drawable.ic_security_white_24dp);
        } else
            name = f.getName();
        if (!f.isDirectory() || f.canExecute()) {
            storage_count++;
            list.add(new EntryItem(name, file, icon1));
        }
    }
    list.add(new SectionItem());
    ArrayList<String[]> Servers = DataUtils.getServers();
    if (Servers != null && Servers.size() > 0) {
        for (String[] file : Servers) {
            list.add(new EntryItem(file[0], file[1],
                    ContextCompat.getDrawable(this, R.drawable.ic_settings_remote_white_48dp)));
        }

        list.add(new SectionItem());
    }
    ArrayList<String[]> accounts = DataUtils.getAccounts();
    if (accounts != null && accounts.size() > 0) {
        Collections.sort(accounts, new BookSorter());
        for (String[] file : accounts) {
            list.add(new EntryItem(file[0], file[1], ContextCompat.getDrawable(this, R.drawable.drive)));
        }

        list.add(new SectionItem());
    }
    ArrayList<String[]> books = DataUtils.getBooks();
    if (books != null && books.size() > 0) {
        Collections.sort(books, new BookSorter());
        for (String[] file : books) {
            list.add(new EntryItem(file[0], file[1], ContextCompat.getDrawable(this, R.drawable.folder_fab)));
        }
        list.add(new SectionItem());
    }
    list.add(new EntryItem(getResources().getString(R.string.quick), "5",
            ContextCompat.getDrawable(this, R.drawable.ic_star_white_18dp)));
    list.add(new EntryItem(getResources().getString(R.string.recent), "6",
            ContextCompat.getDrawable(this, R.drawable.ic_history_white_48dp)));
    list.add(new EntryItem(getResources().getString(R.string.images), "0",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_image)));
    list.add(new EntryItem(getResources().getString(R.string.videos), "1",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_video_am)));
    list.add(new EntryItem(getResources().getString(R.string.audio), "2",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_audio_am)));
    list.add(new EntryItem(getResources().getString(R.string.documents), "3",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_doc_am)));
    list.add(new EntryItem(getResources().getString(R.string.apks), "4",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_apk_grid)));
    DataUtils.setList(list);
    adapter = new DrawerAdapter(con, list, MainActivity.this, Sp);
    mDrawerList.setAdapter(adapter);

}

From source file:com.igniva.filemanager.activities.MainActivity.java

public void refreshDrawer() {
    List<String> val = DataUtils.getStorages();
    if (val == null)
        val = getStorageDirectories();
    ArrayList<Item> list = new ArrayList<>();
    storage_count = 0;/* w  w  w  .j  a v  a2 s.  co  m*/
    for (String file : val) {
        File f = new File(file);
        String name;
        Drawable icon1 = ContextCompat.getDrawable(this, R.drawable.ic_sd_storage_white_56dp);
        if ("/storage/emulated/legacy".equals(file) || "/storage/emulated/0".equals(file)) {
            name = getResources().getString(R.string.storage);
        } else if ("/storage/sdcard1".equals(file)) {
            name = getResources().getString(R.string.extstorage);
        } else if ("/".equals(file)) {
            name = getResources().getString(R.string.rootdirectory);
            icon1 = ContextCompat.getDrawable(this, R.drawable.ic_drawer_root_white);
        } else
            name = f.getName();
        if (!f.isDirectory() || f.canExecute()) {
            storage_count++;
            list.add(new EntryItem(name, file, icon1));
        }
    }
    list.add(new SectionItem());
    ArrayList<String[]> Servers = DataUtils.getServers();
    if (Servers != null && Servers.size() > 0) {
        for (String[] file : Servers) {
            list.add(new EntryItem(file[0], file[1],
                    ContextCompat.getDrawable(this, R.drawable.ic_settings_remote_white_48dp)));
        }

        list.add(new SectionItem());
    }
    ArrayList<String[]> accounts = DataUtils.getAccounts();
    if (accounts != null && accounts.size() > 0) {
        Collections.sort(accounts, new BookSorter());
        for (String[] file : accounts) {
            list.add(new EntryItem(file[0], file[1], ContextCompat.getDrawable(this, R.drawable.drive)));
        }

        list.add(new SectionItem());
    }
    ArrayList<String[]> books = DataUtils.getBooks();
    if (books != null && books.size() > 0) {
        Collections.sort(books, new BookSorter());
        for (String[] file : books) {
            list.add(new EntryItem(file[0], file[1], ContextCompat.getDrawable(this, R.drawable.folder_fab)));
        }
        list.add(new SectionItem());
    }
    list.add(new EntryItem(getResources().getString(R.string.quick), "5",
            ContextCompat.getDrawable(this, R.drawable.ic_star_white_18dp)));
    list.add(new EntryItem(getResources().getString(R.string.recent), "6",
            ContextCompat.getDrawable(this, R.drawable.ic_history_white_48dp)));
    list.add(new EntryItem(getResources().getString(R.string.images), "0",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_image)));
    list.add(new EntryItem(getResources().getString(R.string.videos), "1",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_video_am)));
    list.add(new EntryItem(getResources().getString(R.string.audio), "2",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_audio_am)));
    list.add(new EntryItem(getResources().getString(R.string.documents), "3",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_doc_am)));
    list.add(new EntryItem(getResources().getString(R.string.apks), "4",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_apk_grid)));
    DataUtils.setList(list);
    adapter = new DrawerAdapter(con, list, MainActivity.this, Sp);
    mDrawerList.setAdapter(adapter);

}

From source file:com.amaze.carbonfilemanager.activities.MainActivity.java

public void refreshDrawer() {

    ArrayList<Item> sectionItems = new ArrayList<>();
    ArrayList<String> storageDirectories = getStorageDirectories();
    ArrayList<String[]> books = new ArrayList<>();
    ArrayList<String[]> servers = new ArrayList<>();
    storage_count = 0;/*from  w  w w  .  j a  v a 2 s  .  c o m*/
    for (String file : storageDirectories) {
        File f = new File(file);
        String name;
        Drawable icon1 = ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_sd_storage_white_56dp);
        if ("/storage/emulated/legacy".equals(file) || "/storage/emulated/0".equals(file)) {
            name = getResources().getString(R.string.storage);
        } else if ("/storage/sdcard1".equals(file)) {
            name = getResources().getString(R.string.extstorage);
        } else if ("/".equals(file)) {
            name = getResources().getString(R.string.rootdirectory);
            icon1 = ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_drawer_root_white);
        } else if (file.contains(OTGUtil.PREFIX_OTG)) {
            name = "OTG";
            icon1 = ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_usb_white_48dp);
        } else
            name = f.getName();
        if (!f.isDirectory() || f.canExecute()) {
            storage_count++;
            sectionItems.add(new EntryItem(name, file, icon1));
        }
    }
    dataUtils.setStorages(storageDirectories);
    sectionItems.add(new SectionItem());
    try {
        for (String[] file : grid.readTableSecondary(DataUtils.SMB))
            servers.add(file);
        dataUtils.setServers(servers);
        if (servers.size() > 0) {
            Collections.sort(servers, new BookSorter());
            for (String[] file : servers)
                sectionItems.add(new EntryItem(file[0], file[1], ContextCompat.getDrawable(MainActivity.this,
                        R.drawable.ic_settings_remote_white_48dp)));
            sectionItems.add(new SectionItem());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    ArrayList<String[]> accountAuthenticationList = new ArrayList<>();

    if (CloudSheetFragment.isCloudProviderAvailable(MainActivity.this)) {

        for (CloudStorage cloudStorage : dataUtils.getAccounts()) {

            if (cloudStorage instanceof Dropbox) {

                sectionItems.add(new EntryItem(CloudHandler.CLOUD_NAME_DROPBOX,
                        CloudHandler.CLOUD_PREFIX_DROPBOX + "/",
                        ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_dropbox_white_24dp)));

                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_DROPBOX,
                        CloudHandler.CLOUD_PREFIX_DROPBOX + "/", });
            } else if (cloudStorage instanceof Box) {

                sectionItems.add(new EntryItem(CloudHandler.CLOUD_NAME_BOX, CloudHandler.CLOUD_PREFIX_BOX + "/",
                        ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_box_white_24dp)));

                accountAuthenticationList.add(
                        new String[] { CloudHandler.CLOUD_NAME_BOX, CloudHandler.CLOUD_PREFIX_BOX + "/", });
            } else if (cloudStorage instanceof OneDrive) {

                sectionItems.add(new EntryItem(CloudHandler.CLOUD_NAME_ONE_DRIVE,
                        CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/",
                        ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_onedrive_white_24dp)));

                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_ONE_DRIVE,
                        CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/", });
            } else if (cloudStorage instanceof GoogleDrive) {

                sectionItems.add(new EntryItem(CloudHandler.CLOUD_NAME_GOOGLE_DRIVE,
                        CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/",
                        ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_google_drive_white_24dp)));

                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_GOOGLE_DRIVE,
                        CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/", });
            }
        }
        Collections.sort(accountAuthenticationList, new BookSorter());

        if (accountAuthenticationList.size() != 0)
            sectionItems.add(new SectionItem());
    }

    if (!sharedPref.contains(FoldersPref.KEY)) {
        for (String[] file : grid.readTableSecondary(DataUtils.BOOKS)) {
            books.add(file);
        }
    } else {
        ArrayList<FoldersPref.Shortcut> booksPref = FoldersPref.castStringListToTrioList(
                TinyDB.getList(sharedPref, String.class, FoldersPref.KEY, new ArrayList<String>()));

        for (FoldersPref.Shortcut t : booksPref) {
            if (t.enabled) {
                books.add(new String[] { t.name, t.directory });
            }
        }
    }
    dataUtils.setBooks(books);
    if (sharedPref.getBoolean(PREFERENCE_SHOW_SIDEBAR_FOLDERS, true)) {
        if (books.size() > 0) {
            if (!sharedPref.contains(FoldersPref.KEY)) {
                Collections.sort(books, new BookSorter());
            }

            for (String[] file : books) {
                sectionItems.add(new EntryItem(file[0], file[1],
                        ContextCompat.getDrawable(MainActivity.this, R.drawable.folder_fab)));
            }
            sectionItems.add(new SectionItem());
        }
    }

    Boolean[] quickAccessPref = TinyDB.getBooleanArray(sharedPref, QuickAccessPref.KEY,
            QuickAccessPref.DEFAULT);

    if (sharedPref.getBoolean(PREFERENCE_SHOW_SIDEBAR_QUICKACCESSES, true)) {
        if (quickAccessPref[0])
            sectionItems.add(new EntryItem(getResources().getString(R.string.quick), "5",
                    ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_star_white_18dp)));
        if (quickAccessPref[1])
            sectionItems.add(new EntryItem(getResources().getString(R.string.recent), "6",
                    ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_history_white_48dp)));
        if (quickAccessPref[2])
            sectionItems.add(new EntryItem(getResources().getString(R.string.images), "0",
                    ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_doc_image)));
        if (quickAccessPref[3])
            sectionItems.add(new EntryItem(getResources().getString(R.string.videos), "1",
                    ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_doc_video_am)));
        if (quickAccessPref[4])
            sectionItems.add(new EntryItem(getResources().getString(R.string.audio), "2",
                    ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_doc_audio_am)));
        if (quickAccessPref[5])
            sectionItems.add(new EntryItem(getResources().getString(R.string.documents), "3",
                    ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_doc_doc_am)));
        if (quickAccessPref[6])
            sectionItems.add(new EntryItem(getResources().getString(R.string.apks), "4",
                    ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_doc_apk_grid)));
    } else {
        sectionItems.remove(sectionItems.size() - 1); //Deletes last divider
    }

    dataUtils.setList(sectionItems);

    adapter = new DrawerAdapter(MainActivity.this, MainActivity.this, sectionItems, MainActivity.this,
            sharedPref);
    mDrawerList.setAdapter(adapter);
}

From source file:com.android.launcher3.Launcher.java

/**
 * Finds all the views we need and configure them properly.
 *///www .ja  v  a2s. c  o  m
private void setupViews() {
    mLauncherView = findViewById(R.id.launcher);
    mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
    mFocusHandler = mDragLayer.getFocusIndicatorHelper();
    mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
    mQsbContainer = mDragLayer.findViewById(
            mDeviceProfile.isVerticalBarLayout() ? R.id.workspace_blocked_row : R.id.qsb_container);
    mWorkspace.initParentViews(mDragLayer);

    mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);

    // Setup the drag layer
    mDragLayer.setup(this, mDragController, mAllAppsController);

    // Setup the hotseat
    mHotseat = (Hotseat) findViewById(R.id.hotseat);
    if (mHotseat != null) {
        mHotseat.setOnLongClickListener(this);
    }

    // Setup the overview panel
    setupOverviewPanel();

    setuphome();

    // Setup the workspace
    mWorkspace.setHapticFeedbackEnabled(false);
    mWorkspace.setOnLongClickListener(this);
    mWorkspace.setup(mDragController);
    // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the
    // default state, otherwise we will update to the wrong offsets in RTL
    mWorkspace.lockWallpaperToDefaultPage();
    mDragController.addDragListener(mWorkspace);

    // Get the search/delete/uninstall bar
    mDropTargetBar = (DropTargetBar) mDragLayer.findViewById(R.id.drop_target_bar);

    // Setup Apps and Widgets
    mAppsView = (AllAppsContainerView) findViewById(R.id.apps_view);
    mWidgetsView = (WidgetsContainerView) findViewById(R.id.widgets_view);
    if (mLauncherCallbacks != null && mLauncherCallbacks.getAllAppsSearchBarController() != null) {
        mAppsView.setSearchBarController(mLauncherCallbacks.getAllAppsSearchBarController());
    } else {
        mAppsView.setSearchBarController(new DefaultAppSearchController());
    }

    // Setup the drag controller (drop targets have to be added in reverse order in priority)
    mDragController.setDragScoller(mWorkspace);
    mDragController.setScrollView(mDragLayer);
    mDragController.setMoveTarget(mWorkspace);
    mDragController.addDropTarget(mWorkspace);
    mDropTargetBar.setup(mDragController);

    if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP) {
        mAllAppsController.setupViews(mAppsView, mHotseat, mWorkspace);
    }

    if (TestingUtils.MEMORY_DUMP_ENABLED) {
        TestingUtils.addWeightWatcher(this);
    }

    FrameLayout gBar = (FrameLayout) findViewById(R.id.g_bar);

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        FrameLayout.LayoutParams gBarLayout = (FrameLayout.LayoutParams) gBar.getLayoutParams();
        gBarLayout.width = Utils.getScreenXDimension(this) - Utils.getScreenXDimension(this) / 6;
        gBar.setLayoutParams(gBarLayout);
    } else {
        FrameLayout.LayoutParams gBarLayout = (FrameLayout.LayoutParams) gBar.getLayoutParams();
        gBarLayout.width = Utils.getScreenYDimension(this) - Utils.getScreenYDimension(this) / 12;
        gBar.setLayoutParams(gBarLayout);
    }

    gBar.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            startSearch("", false, null, true);
        }
    });

    ImageView gSearch = (ImageView) findViewById(R.id.g_search);
    gSearch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            startSearch("", false, null, true);
        }
    });

    FrameLayout.LayoutParams gSearchLayout = (FrameLayout.LayoutParams) gSearch.getLayoutParams();
    gSearchLayout.leftMargin = 30;
    gSearch.setLayoutParams(gSearchLayout);

    ImageView gSearchMic = (ImageView) findViewById(R.id.g_search_mic);
    if (IS_ALLOW_MIC) {
        gSearchMic.setVisibility(View.VISIBLE);
        gSearchMic.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
                startActivityForResult(intent, RECOGNIZER_REQ_CODE);
            }
        });
    } else {
        gSearchMic.setVisibility(View.GONE);
    }

    FrameLayout.LayoutParams gSearchMicLayout = (FrameLayout.LayoutParams) gSearchMic.getLayoutParams();
    gSearchMicLayout.rightMargin = 30;
    gSearchMic.setLayoutParams(gSearchMicLayout);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (Utilities.isAllowNightModePrefEnabled(getApplicationContext())) {
            gBar.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.shape_night));
            gSearch.setImageDrawable(
                    ContextCompat.getDrawable(getApplicationContext(), R.drawable.g_icon_night));
            gSearch.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.night_color));
            gSearchMic
                    .setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.mic_night));
            gSearchMic.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.night_color));
        } else {
            gBar.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.shape));
            gSearch.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.g_icon));
            gSearch.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), android.R.color.white));
            gSearchMic.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.mic));
            gSearchMic
                    .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), android.R.color.white));
        }
    }

    if (!Utilities.isAllowPersisentSearchBarPrefEnabled(getApplicationContext())) {
        gBar.setVisibility(View.GONE);
        gSearch.setVisibility(View.GONE);
        gSearchMic.setVisibility(View.GONE);
    } else {
        gBar.setVisibility(View.VISIBLE);
        gSearch.setVisibility(View.VISIBLE);
        if (IS_ALLOW_MIC) {
            gSearchMic.setVisibility(View.VISIBLE);
        } else {
            gSearchMic.setVisibility(View.GONE);
        }
    }

}

From source file:com.android.contacts.common.list.ContactListItemView.java

/**
 * Set drawable resources directly for the drawable resource of the photo view.
 *
 * @param drawableId Id of drawable resource.
 *///from  w  ww .j  av  a2s  . co m
public void setDrawableResource(int drawableId) {
    ImageView photo = getPhotoView();
    photo.setScaleType(ImageView.ScaleType.CENTER);
    final Drawable drawable = ContextCompat.getDrawable(getContext(), drawableId);
    final int iconColor = ContextCompat.getColor(getContext(), R.color.search_shortcut_icon_color);
    if (CompatUtils.isLollipopCompatible()) {
        photo.setImageDrawable(drawable);
        photo.setImageTintList(ColorStateList.valueOf(iconColor));
    } else {
        final Drawable drawableWrapper = DrawableCompat.wrap(drawable).mutate();
        DrawableCompat.setTint(drawableWrapper, iconColor);
        photo.setImageDrawable(drawableWrapper);
    }
}

From source file:com.filemanager.free.activities.MainActivity.java

public void bbar(final Main main) {
    final String text = main.CURRENT_PATH;
    try {//w ww . ja  v a 2s .c  o m
        buttons.removeAllViews();
        buttons.setMinimumHeight(pathbar.getHeight());
        Drawable arrow = ContextCompat.getDrawable(con, R.drawable.abc_ic_ab_back_holo_dark);
        Bundle b = utils.getPaths(text, this);
        ArrayList<String> names = b.getStringArrayList("names");
        ArrayList<String> rnames = new ArrayList<String>();

        assert names != null;
        for (int i = names.size() - 1; i >= 0; i--) {
            rnames.add(names.get(i));
        }

        ArrayList<String> paths = b.getStringArrayList("paths");
        final ArrayList<String> rpaths = new ArrayList<String>();

        assert paths != null;
        for (int i = paths.size() - 1; i >= 0; i--) {
            rpaths.add(paths.get(i));
        }
        View view = new View(this);
        LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(toolbar.getContentInsetLeft(),
                LinearLayout.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(params1);
        buttons.addView(view);
        for (int i = 0; i < names.size(); i++) {
            final int k = i;
            ImageView v = new ImageView(this);
            v.setImageDrawable(arrow);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.gravity = Gravity.CENTER_VERTICAL;
            v.setLayoutParams(params);
            final int index = i;
            if (rpaths.get(i).equals("/")) {
                ImageButton ib = new ImageButton(this);
                ib.setImageDrawable(icons.getRootDrawable());
                ib.setBackgroundColor(Color.parseColor("#00ffffff"));
                ib.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View p1) {
                        main.loadlist(("/"), false, main.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                ib.setLayoutParams(params);
                buttons.addView(ib);
                if (names.size() - i != 1)
                    buttons.addView(v);
            } else if (isStorage(rpaths.get(i))) {
                ImageButton ib = new ImageButton(this);
                ib.setImageDrawable(icons.getSdDrawable());
                ib.setBackgroundColor(Color.parseColor("#00ffffff"));
                ib.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View p1) {
                        main.loadlist((rpaths.get(k)), false, main.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                ib.setLayoutParams(params);
                buttons.addView(ib);
                if (names.size() - i != 1)
                    buttons.addView(v);
            } else {
                Button button = new Button(this);
                button.setText(rnames.get(index));
                button.setTextColor(ContextCompat.getColor(con, android.R.color.white));
                button.setTextSize(13);
                button.setLayoutParams(params);
                button.setBackgroundResource(0);
                button.setOnClickListener(new Button.OnClickListener() {

                    public void onClick(View p1) {
                        main.loadlist((rpaths.get(k)), false, main.openMode);
                        main.loadlist((rpaths.get(k)), false, main.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                button.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View view) {
                        File file1 = new File(rpaths.get(index));
                        copyToClipboard(MainActivity.this, file1.getPath());
                        Toast.makeText(MainActivity.this, getResources().getString(R.string.pathcopied),
                                Toast.LENGTH_SHORT).show();
                        return false;
                    }
                });

                buttons.addView(button);
                if (names.size() - i != 1)
                    buttons.addView(v);
            }
        }

        scroll.post(new Runnable() {
            @Override
            public void run() {
                sendScroll(scroll);
                sendScroll(scroll1);
            }
        });

        if (buttons.getVisibility() == View.VISIBLE) {
            timer.cancel();
            timer.start();
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("button view not available");
    }
}

From source file:com.amsterdam.marktbureau.makkelijkemarkt.DagvergunningFragment.java

/**
 * Set the state of the buttons of the wizard menu depending on the selected tab
 * @param tabPosition position of the tab
 *///from w  w w.ja v  a 2 s.c o  m
private void setWizardMenu(int tabPosition) {

    // button background colors
    int accentColor = ContextCompat.getColor(getContext(), R.color.accent);
    int whiteColor = ContextCompat.getColor(getContext(), android.R.color.white);
    int primaryDarkColor = ContextCompat.getColor(getContext(), R.color.primary_dark);
    int primaryColor = ContextCompat.getColor(getContext(), R.color.primary);
    int redColor = ContextCompat.getColor(getContext(), R.color.dagvergunning_melding_background);

    // button icons
    Drawable leftDrawable = ContextCompat.getDrawable(getContext(), R.drawable.chevron_left_primary_dark);
    Drawable trashDrawable = ContextCompat.getDrawable(getContext(), R.drawable.delete_white);
    Drawable rightDrawable = ContextCompat.getDrawable(getContext(), R.drawable.chevron_right_primary_dark);
    Drawable checkDrawable = ContextCompat.getDrawable(getContext(), R.drawable.check_primary_dark);

    // get previous button left drawable bounds
    Drawable[] previousButtonDrawables = mWizardPreviousButton.getCompoundDrawables();
    Drawable previousButtonLeftDrawable = previousButtonDrawables[0];

    // get next button right drawable bounds
    Drawable[] nextButtonDrawables = mWizardNextButton.getCompoundDrawables();
    Drawable nextButtonRightDrawable = nextButtonDrawables[2];

    switch (tabPosition) {

    // koopman tab
    case 0:

        // previous
        if (mId == -1) {

            // new dagvergunning, so hide the delete button
            mWizardPreviousButton.setVisibility(View.INVISIBLE);
            mWizardPreviousButton.setBackgroundColor(whiteColor);
            mWizardPreviousButton.setText("");
            mWizardPreviousButton.setTextColor(primaryDarkColor);
            if (leftDrawable != null) {
                leftDrawable.setBounds(previousButtonLeftDrawable.getBounds());
                mWizardPreviousButton.setCompoundDrawables(leftDrawable, null, null, null);
            }
        } else {

            // existing dagvergunning, so show the delete button
            mWizardPreviousButton.setVisibility(View.VISIBLE);
            mWizardPreviousButton.setBackgroundColor(redColor);
            mWizardPreviousButton.setText(getString(R.string.delete));
            mWizardPreviousButton.setTextColor(whiteColor);
            if (trashDrawable != null) {
                trashDrawable.setBounds(previousButtonLeftDrawable.getBounds());
                mWizardPreviousButton.setCompoundDrawables(trashDrawable, null, null, null);
            }
        }

        // next
        mWizardNextButton.setVisibility(View.VISIBLE);
        mWizardNextButton.setBackgroundColor(accentColor);
        mWizardNextButton.setText(getString(R.string.product));
        if (rightDrawable != null) {
            rightDrawable.setBounds(nextButtonRightDrawable.getBounds());
            mWizardNextButton.setCompoundDrawables(null, null, rightDrawable, null);
        }
        break;

    // product tab
    case 1:

        // previous
        mWizardPreviousButton.setVisibility(View.VISIBLE);
        mWizardPreviousButton.setBackgroundColor(whiteColor);
        mWizardPreviousButton.setText(getString(R.string.koopman));
        mWizardPreviousButton.setTextColor(primaryDarkColor);
        if (leftDrawable != null) {
            leftDrawable.setBounds(previousButtonLeftDrawable.getBounds());
            mWizardPreviousButton.setCompoundDrawables(leftDrawable, null, null, null);
        }

        // next
        mWizardNextButton.setVisibility(View.VISIBLE);
        mWizardNextButton.setBackgroundColor(accentColor);
        mWizardNextButton.setText(getString(R.string.overzicht));
        if (rightDrawable != null) {
            rightDrawable.setBounds(nextButtonRightDrawable.getBounds());
            mWizardNextButton.setCompoundDrawables(null, null, rightDrawable, null);
        }
        break;

    // overzicht tab
    case 2:

        // previous
        mWizardPreviousButton.setVisibility(View.VISIBLE);
        mWizardPreviousButton.setBackgroundColor(whiteColor);
        mWizardPreviousButton.setText(getString(R.string.product));
        mWizardPreviousButton.setTextColor(primaryDarkColor);
        if (leftDrawable != null) {
            leftDrawable.setBounds(previousButtonLeftDrawable.getBounds());
            mWizardPreviousButton.setCompoundDrawables(leftDrawable, null, null, null);
        }

        // next
        mWizardNextButton.setVisibility(View.VISIBLE);
        mWizardNextButton.setBackgroundColor(primaryColor);
        mWizardNextButton.setTextColor(primaryDarkColor);
        mWizardNextButton.setText(getString(R.string.save));
        if (checkDrawable != null) {
            checkDrawable.setBounds(nextButtonRightDrawable.getBounds());
            mWizardNextButton.setCompoundDrawables(null, null, checkDrawable, null);
        }
        break;

    default:
        break;
    }
}

From source file:com.android.launcher3.Launcher.java

@Override
public boolean onLongClick(View v) {
    if (!isDraggingEnabled())
        return false;
    if (isWorkspaceLocked())
        return false;
    if (mState != State.WORKSPACE)
        return false;

    if (creation != null)
        creation.clearAllLayout();/*from   ww w . jav a  2  s .com*/

    if ((FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && v instanceof PageIndicator)
            || (v == mAllAppsButton && mAllAppsButton != null)) {
        onLongClickAllAppsButton(v);
        return true;
    }

    if (v instanceof Workspace) {
        if (!mWorkspace.isInOverviewMode()) {
            if (!mWorkspace.isTouchActive()) {
                showOverviewMode(true);
                mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
                        HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    CellLayout.CellInfo longClickCellInfo = null;
    View itemUnderLongClick = null;
    if (v.getTag() instanceof ItemInfo) {
        ItemInfo info = (ItemInfo) v.getTag();
        longClickCellInfo = new CellLayout.CellInfo(v, info);
        itemUnderLongClick = longClickCellInfo.cell;
        mPendingRequestArgs = null;
    }

    // The hotseat touch handling does not go through Workspace, and we always allow long press
    // on hotseat items.
    if (!mDragController.isDragging()) {
        if (itemUnderLongClick == null) {
            // User long pressed on empty space
            mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
                    HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
            if (mWorkspace.isInOverviewMode()) {
                mWorkspace.startReordering(v);
            } else {
                showOverviewMode(true);
            }
        } else {
            final boolean isAllAppsButton = !FeatureFlags.NO_ALL_APPS_ICON && isHotseatLayout(v)
                    && mDeviceProfile.inv.isAllAppsButtonRank(
                            mHotseat.getOrderInHotseat(longClickCellInfo.cellX, longClickCellInfo.cellY));
            if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
                // User long pressed on an item
                DragOptions dragOptions = new DragOptions();
                if (itemUnderLongClick instanceof BubbleTextView) {
                    BubbleTextView icon = (BubbleTextView) itemUnderLongClick;
                    if (icon.hasDeepShortcuts()) {
                        DeepShortcutsContainer dsc = DeepShortcutsContainer.showForIcon(icon);
                        if (dsc != null) {
                            dragOptions.deferDragCondition = dsc.createDeferDragCondition(null);
                        }
                    }
                }

                int positionInGrid = mHotseat.getOrderInHotseat(longClickCellInfo.cellX,
                        longClickCellInfo.cellY);

                List<Shortcuts> shortcutses = new ArrayList<Shortcuts>();

                if (creation != null)
                    creation.clearAllLayout();

                mWorkspace.startDrag(longClickCellInfo, dragOptions);

                //Get selected app info
                final Object tag = v.getTag();
                final ShortcutInfo shortcut;
                try {
                    shortcut = (ShortcutInfo) tag;
                    Drawable icon;
                    if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(),
                            shortcut.getTargetComponent().getPackageName()) != null) {
                        icon = new BitmapDrawable(activity.getResources(), Utilities.loadBitmapPref(activity,
                                shortcut.getTargetComponent().getPackageName()));
                    } else {
                        icon = new BitmapDrawable(activity.getResources(),
                                shortcut.getIcon(new IconCache(Launcher.this, getDeviceProfile().inv)));
                    }

                    shortcutses = ShortcutsManager.getShortcutsBasedOnTag(Launcher.this.getApplicationContext(),
                            Launcher.this, shortcut, icon);
                    ShortcutsBuilder builder = new ShortcutsBuilder.Builder(this, masterLayout)
                            .launcher3Shortcuts(gridSize, positionInGrid, (int) v.getY(), v.getBottom(),
                                    Hotseat.isHotseatTouched,
                                    Utilities.getDockSizeDefaultValue(getApplicationContext()))
                            .setOptionLayoutStyle(StyleOption.NONE).setPackageImage(icon)
                            .setShortcutsList(shortcutses).build();

                    creation = new ShortcutsCreation(builder);

                    creation.init();

                    Hotseat.isHotseatTouched = false;

                } catch (ClassCastException e) {
                    Log.e(TAG, "Clicked on Folder/Widget!");
                    positionInGrid = mHotseat.getOrderInHotseat(longClickCellInfo.cellX,
                            longClickCellInfo.cellY);
                    try {
                        //Get selected folder info
                        final View f = v;
                        final Object tagF = v.getTag();
                        final FolderInfo folder;
                        folder = (FolderInfo) tagF;

                        shortcutses = new ArrayList<Shortcuts>();
                        shortcutses.add(new Shortcuts(R.drawable.ic_folder_open_black_24dp,
                                getString(R.string.folder_open), new OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        if (f instanceof FolderIcon) {
                                            onClickFolderIcon(f);
                                            creation.clearAllLayout();
                                        }
                                    }
                                }));
                        shortcutses.add(new Shortcuts(R.drawable.ic_title_black_24dp,
                                getString(R.string.folder_rename), new OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        if (f instanceof FolderIcon) {
                                            AlertDialog.Builder alert = new AlertDialog.Builder(
                                                    new ContextThemeWrapper(Launcher.this,
                                                            R.style.AlertDialogCustom));
                                            LinearLayout layout = new LinearLayout(getApplicationContext());
                                            layout.setOrientation(LinearLayout.VERTICAL);
                                            layout.setPadding(100, 50, 100, 100);

                                            final EditText titleBox = new EditText(Launcher.this);

                                            titleBox.getBackground().mutate()
                                                    .setColorFilter(
                                                            ContextCompat.getColor(getApplicationContext(),
                                                                    R.color.colorPrimary),
                                                            PorterDuff.Mode.SRC_ATOP);
                                            alert.setMessage(getString(R.string.folder_title));
                                            alert.setTitle(getString(R.string.folder_enter_title));

                                            layout.addView(titleBox);
                                            alert.setView(layout);

                                            alert.setPositiveButton(getString(R.string.ok),
                                                    new DialogInterface.OnClickListener() {
                                                        public void onClick(DialogInterface dialog,
                                                                int whichButton) {
                                                            folder.setTitle(titleBox.getText().toString());
                                                            LauncherModel.updateItemInDatabase(
                                                                    Launcher.getLauncherActivity(), folder);
                                                        }
                                                    });

                                            alert.setNegativeButton(getString(R.string.cancel),
                                                    new DialogInterface.OnClickListener() {
                                                        public void onClick(DialogInterface dialog,
                                                                int whichButton) {
                                                            creation.clearAllLayout();
                                                        }
                                                    });
                                            alert.show();
                                            creation.clearAllLayout();
                                        }
                                    }
                                }));

                        ShortcutsBuilder builder = new ShortcutsBuilder.Builder(this, masterLayout)
                                .launcher3Shortcuts(gridSize, positionInGrid, (int) v.getY(), v.getBottom(),
                                        Hotseat.isHotseatTouched,
                                        Utilities.getDockSizeDefaultValue(getApplicationContext()))
                                .setOptionLayoutStyle(0)
                                .setPackageImage(
                                        ContextCompat.getDrawable(Launcher.this, R.mipmap.ic_launcher_home))
                                .setShortcutsList(shortcutses).build();

                        creation = new ShortcutsCreation(builder);

                        creation.init();
                    } catch (ClassCastException ee) {
                    }
                }
            }
        }
    }
    return true;
}