candybar.lib.adapters.IconsAdapter

Here are the examples of the java api candybar.lib.adapters.IconsAdapter taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

19 Source : IconsFragment.java
with Apache License 2.0
from zixpo

public static void reloadIcons() {
    for (IconsAdapter adapter : iconsAdapters) {
        adapter.reloadIcons();
    }
}

17 Source : IconsFragment.java
with Apache License 2.0
from zixpo

/*
 * CandyBar - Material Dashboard
 *
 * Copyright (c) 2014-2016 Dani Mahardhika
 *
 * 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.
 */
public clreplaced IconsFragment extends Fragment {

    private RecyclerView mRecyclerView;

    private RecyclerFastScroller mFastScroll;

    private IconsAdapter mAdapter;

    private List<Icon> mIcons;

    private static final String INDEX = "index";

    private static final List<IconsAdapter> iconsAdapters = new ArrayList<>();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_icons, container, false);
        mRecyclerView = view.findViewById(R.id.icons_grid);
        mFastScroll = view.findViewById(R.id.fastscroll);
        return view;
    }

    public static IconsFragment newInstance(int index) {
        IconsFragment fragment = new IconsFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(INDEX, index);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    @SuppressWarnings("ConstantConditions")
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mIcons = new ArrayList<>();
        int index = getArguments().getInt(INDEX);
        if (CandyBarMainActivity.sSections != null)
            mIcons = CandyBarMainActivity.sSections.get(index).getIcons();
    }

    @Override
    @SuppressWarnings("ConstantConditions")
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.sereplacedemAnimator(new DefaulreplacedemAnimator());
        mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), getActivity().getResources().getInteger(R.integer.icons_column_count)));
        setFastScrollColor(mFastScroll);
        mFastScroll.attachRecyclerView(mRecyclerView);
        mAdapter = new IconsAdapter(getActivity(), mIcons, this);
        mRecyclerView.setAdapter(mAdapter);
        iconsAdapters.add(mAdapter);
    }

    @Override
    public void onDestroy() {
        if (mAdapter != null)
            iconsAdapters.remove(mAdapter);
        super.onDestroy();
    }

    @Override
    @SuppressWarnings("ConstantConditions")
    public void onConfigurationChanged(@NotNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        ViewHelper.resetSpanCount(mRecyclerView, getActivity().getResources().getInteger(R.integer.icons_column_count));
    }

    public static void reloadIcons() {
        for (IconsAdapter adapter : iconsAdapters) {
            adapter.reloadIcons();
        }
    }
}

16 Source : IconsSearchFragment.java
with Apache License 2.0
from zixpo

/*
 * CandyBar - Material Dashboard
 *
 * Copyright (c) 2014-2016 Dani Mahardhika
 *
 * 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.
 */
public clreplaced IconsSearchFragment extends Fragment {

    private RecyclerView mRecyclerView;

    private RecyclerFastScroller mFastScroll;

    private TextView mSearchResult;

    private SearchView mSearchView;

    private final Fragment mFragment = this;

    private IconsAdapter mAdapter;

    private AsyncTask<Void, Void, ?> mAsyncTask;

    public static final String TAG = "icons_search";

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_icons_search, container, false);
        mRecyclerView = view.findViewById(R.id.icons_grid);
        mFastScroll = view.findViewById(R.id.fastscroll);
        mSearchResult = view.findViewById(R.id.search_result);
        return view;
    }

    @Override
    @SuppressWarnings("ConstantConditions")
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setHasOptionsMenu(true);
        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.sereplacedemAnimator(new DefaulreplacedemAnimator());
        mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), getActivity().getResources().getInteger(R.integer.icons_column_count)));
        setFastScrollColor(mFastScroll);
        mFastScroll.attachRecyclerView(mRecyclerView);
        mAsyncTask = new IconsLoader().execute();
    }

    @Override
    @SuppressWarnings("ConstantConditions")
    public void onCreateOptionsMenu(@NotNull Menu menu, @NotNull MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.menu_icons_search, menu);
        MenuItem search = menu.findItem(R.id.menu_search);
        MenuItem iconShape = menu.findItem(R.id.menu_icon_shape);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O || !getActivity().getResources().getBoolean(R.bool.includes_adaptive_icons)) {
            iconShape.setVisible(false);
        }
        mSearchView = (SearchView) search.getActionView();
        mSearchView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_SEARCH);
        mSearchView.setQueryHint(getActivity().getResources().getString(R.string.search_icon));
        mSearchView.setMaxWidth(Integer.MAX_VALUE);
        search.expandActionView();
        mSearchView.setIconifiedByDefault(false);
        mSearchView.clearFocus();
        int color = ColorHelper.getAttributeColor(getActivity(), R.attr.toolbar_icon);
        ViewHelper.setSearchViewTextColor(mSearchView, color);
        ViewHelper.setSearchViewBackgroundColor(mSearchView, Color.TRANSPARENT);
        ViewHelper.setSearchViewCloseIcon(mSearchView, R.drawable.ic_toolbar_close);
        ViewHelper.setSearchViewSearchIcon(mSearchView, null);
        search.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {

            @Override
            public boolean onMenuItemActionExpand(MenuItem item) {
                return true;
            }

            @Override
            public boolean onMenuItemActionCollapse(MenuItem item) {
                getActivity().onBackPressed();
                return true;
            }
        });
        mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

            @Override
            public boolean onQueryTextChange(String string) {
                filterSearch(string);
                return true;
            }

            @Override
            public boolean onQueryTextSubmit(String string) {
                mSearchView.clearFocus();
                return true;
            }
        });
    }

    @Override
    @SuppressWarnings("ConstantConditions")
    public void onConfigurationChanged(@NotNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        ViewHelper.resetSpanCount(mRecyclerView, getActivity().getResources().getInteger(R.integer.icons_column_count));
    }

    @Override
    public void onDestroy() {
        if (mAsyncTask != null)
            mAsyncTask.cancel(true);
        super.onDestroy();
    }

    @SuppressLint("StringFormatInvalid")
    @SuppressWarnings("ConstantConditions")
    private void filterSearch(String query) {
        try {
            mAdapter.search(query);
            if (mAdapter.gereplacedemCount() == 0) {
                String text = String.format(getActivity().getResources().getString(R.string.search_noresult), query);
                mSearchResult.setText(text);
                mSearchResult.setVisibility(View.VISIBLE);
            } else
                mSearchResult.setVisibility(View.GONE);
        } catch (Exception e) {
            LogUtil.e(Log.getStackTraceString(e));
        }
    }

    @SuppressLint("StaticFieldLeak")
    private clreplaced IconsLoader extends AsyncTask<Void, Void, Boolean> {

        private List<Icon> icons;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            icons = new ArrayList<>();
        }

        @Override
        @SuppressWarnings("ConstantConditions")
        protected Boolean doInBackground(Void... voids) {
            if (!isCancelled()) {
                try {
                    Thread.sleep(1);
                    if (CandyBarMainActivity.sSections == null) {
                        CandyBarMainActivity.sSections = IconsHelper.getIconsList(getActivity());
                        for (Icon section : CandyBarMainActivity.sSections) {
                            if (getActivity().getResources().getBoolean(R.bool.show_icon_name)) {
                                for (Icon icon : section.getIcons()) {
                                    String name;
                                    if ((icon.getCustomName() != null) && (!icon.getCustomName().contentEquals(""))) {
                                        name = icon.getCustomName();
                                    } else {
                                        name = IconsHelper.replaceName(getActivity(), getActivity().getResources().getBoolean(R.bool.enable_icon_name_replacer), icon.getreplacedle());
                                    }
                                    icon.setreplacedle(name);
                                }
                            }
                        }
                        if (CandyBarApplication.getConfiguration().isShowTabAllIcons()) {
                            List<Icon> icons = IconsHelper.getTabAllIcons();
                            CandyBarMainActivity.sSections.add(new Icon(CandyBarApplication.getConfiguration().getTabAllIconsreplacedle(), icons));
                        }
                    }
                    for (Icon icon : CandyBarMainActivity.sSections) {
                        if (CandyBarApplication.getConfiguration().isShowTabAllIcons()) {
                            if (!icon.getreplacedle().equals(CandyBarApplication.getConfiguration().getTabAllIconsreplacedle())) {
                                icons.addAll(icon.getIcons());
                            }
                        } else {
                            icons.addAll(icon.getIcons());
                        }
                    }
                    Collections.sort(icons, new AlphanumComparator() {

                        @Override
                        public int compare(Object o1, Object o2) {
                            String s1 = ((Icon) o1).getreplacedle();
                            String s2 = ((Icon) o2).getreplacedle();
                            return super.compare(s1, s2);
                        }
                    });
                    return true;
                } catch (Exception e) {
                    LogUtil.e(Log.getStackTraceString(e));
                    return false;
                }
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            if (getActivity() == null)
                return;
            if (getActivity().isFinishing())
                return;
            mAsyncTask = null;
            if (aBoolean) {
                mAdapter = new IconsAdapter(getActivity(), icons, mFragment);
                mRecyclerView.setAdapter(mAdapter);
                filterSearch("");
                mSearchView.requestFocus();
                SoftKeyboardHelper.openKeyboard(getActivity());
            } else {
                // Unable to load all icons
                Toast.makeText(getActivity(), R.string.icons_load_failed, Toast.LENGTH_LONG).show();
            }
        }
    }
}