Search in sources :

Example 11 with MenuAdapter

use of android.support.v7.view.menu.MenuAdapter in project Osmand by osmandapp.

the class AvailableGPXFragment method moveGpx.

private void moveGpx(final GpxInfo info) {
    final ContextMenuAdapter menuAdapter = new ContextMenuAdapter();
    ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder();
    final List<File> dirs = new ArrayList<>();
    collectDirs(app.getAppPath(IndexConstants.GPX_INDEX_DIR), dirs, info.file.getParentFile());
    if (!info.file.getParentFile().equals(app.getAppPath(IndexConstants.GPX_INDEX_DIR))) {
        dirs.add(0, app.getAppPath(IndexConstants.GPX_INDEX_DIR));
    }
    String gpxDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getPath();
    int i = 0;
    for (File dir : dirs) {
        String dirName = dir.getPath();
        if (dirName.startsWith(gpxDir)) {
            if (dirName.length() == gpxDir.length()) {
                dirName = dir.getName();
            } else {
                dirName = dirName.substring(gpxDir.length() + 1);
            }
        }
        menuAdapter.addItem(itemBuilder.setTitle(Algorithms.capitalizeFirstLetter(dirName)).setIcon(R.drawable.ic_action_folder_stroke).setTag(i).createItem());
        i++;
    }
    menuAdapter.addItem(itemBuilder.setTitleId(R.string.add_new_folder, app).setIcon(R.drawable.map_zoom_in).setTag(-1).createItem());
    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    final ArrayAdapter<ContextMenuItem> listAdapter = menuAdapter.createListAdapter(getActivity(), app.getSettings().isLightContent());
    builder.setTitle(R.string.select_gpx_folder);
    builder.setAdapter(listAdapter, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            ContextMenuItem item = menuAdapter.getItem(which);
            int index = item.getTag();
            if (index == -1) {
                Activity a = getActivity();
                AlertDialog.Builder b = new AlertDialog.Builder(a);
                b.setTitle(R.string.add_new_folder);
                final EditText editText = new EditText(a);
                editText.addTextChangedListener(new TextWatcher() {

                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    }

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                    }

                    @Override
                    public void afterTextChanged(Editable s) {
                        Editable text = editText.getText();
                        if (text.length() >= 1) {
                            if (ILLEGAL_PATH_NAME_CHARACTERS.matcher(text).find()) {
                                editText.setError(app.getString(R.string.file_name_containes_illegal_char));
                            }
                        }
                    }
                });
                int leftPadding = AndroidUtils.dpToPx(a, 24f);
                int topPadding = AndroidUtils.dpToPx(a, 4f);
                b.setView(editText, leftPadding, topPadding, leftPadding, topPadding);
                // Behaviour will be overwritten later;
                b.setPositiveButton(R.string.shared_string_ok, null);
                b.setNegativeButton(R.string.shared_string_cancel, null);
                final AlertDialog alertDialog = b.create();
                alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {

                    @Override
                    public void onShow(DialogInterface dialog) {
                        alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                String newName = editText.getText().toString();
                                if (ILLEGAL_PATH_NAME_CHARACTERS.matcher(newName).find()) {
                                    Toast.makeText(app, R.string.file_name_containes_illegal_char, Toast.LENGTH_LONG).show();
                                    return;
                                }
                                File destFolder = new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), newName);
                                if (destFolder.exists()) {
                                    Toast.makeText(app, R.string.file_with_name_already_exists, Toast.LENGTH_LONG).show();
                                    return;
                                } else if (destFolder.mkdirs()) {
                                    File dest = new File(destFolder, info.fileName);
                                    if (info.file.renameTo(dest)) {
                                        app.getGpxDatabase().rename(info.file, dest);
                                        asyncLoader = new LoadGpxTask();
                                        asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
                                    } else {
                                        Toast.makeText(app, R.string.file_can_not_be_moved, Toast.LENGTH_LONG).show();
                                    }
                                } else {
                                    Toast.makeText(app, R.string.file_can_not_be_moved, Toast.LENGTH_LONG).show();
                                }
                                alertDialog.dismiss();
                            }
                        });
                    }
                });
                alertDialog.show();
            } else {
                File dir = dirs.get(index);
                File dest = new File(dir, info.file.getName());
                if (dest.exists()) {
                    Toast.makeText(app, R.string.file_with_name_already_exists, Toast.LENGTH_LONG).show();
                } else {
                    if (info.file.renameTo(dest)) {
                        app.getGpxDatabase().rename(info.file, dest);
                        asyncLoader = new LoadGpxTask();
                        asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
                    } else {
                        Toast.makeText(app, R.string.file_can_not_be_moved, Toast.LENGTH_LONG).show();
                    }
                }
            }
        }
    });
    builder.setNegativeButton(R.string.shared_string_cancel, null);
    builder.create().show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) OsmandActionBarActivity(net.osmand.plus.activities.OsmandActionBarActivity) TrackActivity(net.osmand.plus.activities.TrackActivity) Activity(android.app.Activity) MapActivity(net.osmand.plus.activities.MapActivity) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) EditText(android.widget.EditText) ContextMenuItem(net.osmand.plus.ContextMenuItem) SearchView(android.support.v7.widget.SearchView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AbsListView(android.widget.AbsListView) ExpandableListView(android.widget.ExpandableListView) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File)

Example 12 with MenuAdapter

use of android.support.v7.view.menu.MenuAdapter in project RvBindAdapter by sswukang.

the class MainActivity method initRightMenuPop.

@SuppressLint("RestrictedApi")
private void initRightMenuPop() {
    MenuBuilder menuBuilder = new MenuBuilder(getContext());
    menuBuilder.setOptionalIconsVisible(true);
    menuBuilder.add(R.string.main_asc).setIcon(R.drawable.ic_main_asc);
    menuBuilder.add(R.string.main_desc).setIcon(R.drawable.ic_main_desc);
    menuBuilder.add(R.string.main_shuffle).setIcon(R.drawable.ic_main_shuffle);
    rightMenuPop = new ListPopupWindow(getContext());
    rightMenuPop.setAdapter(new MenuAdapter(menuBuilder, getLayoutInflater(), true));
    rightMenuPop.setWidth(getResources().getDisplayMetrics().widthPixels / 2);
    rightMenuPop.setHeight(ListPopupWindow.WRAP_CONTENT);
    rightMenuPop.setAnchorView(getDataBinding().topToolbar);
    rightMenuPop.setDropDownGravity(Gravity.END);
    // 设置是否是模式
    rightMenuPop.setModal(true);
    rightMenuPop.setOnItemClickListener((parent, view, position, id) -> {
        switch(// 调用排序方法
        position) {
            case 0:
                fragmentAdapter.getItem(getDataBinding().mainViewPager.getCurrentItem()).asc();
                break;
            case 1:
                fragmentAdapter.getItem(getDataBinding().mainViewPager.getCurrentItem()).desc();
                break;
            case 2:
                fragmentAdapter.getItem(getDataBinding().mainViewPager.getCurrentItem()).shuffle();
                break;
        }
        rightMenuPop.dismiss();
    });
}
Also used : ListPopupWindow(android.support.v7.widget.ListPopupWindow) MenuAdapter(android.support.v7.view.menu.MenuAdapter) MenuBuilder(android.support.v7.view.menu.MenuBuilder) SuppressLint(android.annotation.SuppressLint)

Example 13 with MenuAdapter

use of android.support.v7.view.menu.MenuAdapter in project RvBindAdapter by sswukang.

the class MainActivity method initLeftMenuPop.

@SuppressLint("RestrictedApi")
private void initLeftMenuPop() {
    MenuBuilder menuBuilder = new MenuBuilder(getContext());
    menuBuilder.setOptionalIconsVisible(true);
    menuBuilder.add(R.string.main_single).setIcon(R.drawable.ic_main_single);
    menuBuilder.add(R.string.main_multi).setIcon(R.drawable.ic_main_multi);
    menuBuilder.add(R.string.main_sticky).setIcon(R.drawable.ic_main_sticky);
    menuBuilder.add(R.string.main_sticky_side).setIcon(R.drawable.ic_main_sticky_side);
    leftMenuPop = new ListPopupWindow(getContext());
    leftMenuPop.setAdapter(new MenuAdapter(menuBuilder, getLayoutInflater(), true));
    leftMenuPop.setWidth(getResources().getDisplayMetrics().widthPixels / 2);
    leftMenuPop.setHeight(ListPopupWindow.WRAP_CONTENT);
    leftMenuPop.setAnchorView(getDataBinding().topToolbar);
    leftMenuPop.setDropDownGravity(Gravity.START);
    // 设置是否是模式
    leftMenuPop.setModal(true);
    leftMenuPop.setOnItemClickListener((parent, view, position, id) -> {
        getDataBinding().setCurrentItem(position);
        leftMenuPop.dismiss();
    });
}
Also used : ListPopupWindow(android.support.v7.widget.ListPopupWindow) MenuAdapter(android.support.v7.view.menu.MenuAdapter) MenuBuilder(android.support.v7.view.menu.MenuBuilder) SuppressLint(android.annotation.SuppressLint)

Example 14 with MenuAdapter

use of android.support.v7.view.menu.MenuAdapter in project Fragmentation by YoKeyword.

the class MenuListFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    LinearLayoutManager manager = new LinearLayoutManager(_mActivity);
    mRecy.setLayoutManager(manager);
    mAdapter = new MenuAdapter(_mActivity);
    mRecy.setAdapter(mAdapter);
    mAdapter.setDatas(mMenus);
    mAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(int position, View view, RecyclerView.ViewHolder vh) {
            showContent(position);
        }
    });
    if (savedInstanceState != null) {
        mCurrentPosition = savedInstanceState.getInt(SAVE_STATE_POSITION);
        mAdapter.setItemChecked(mCurrentPosition);
    } else {
        mCurrentPosition = 0;
        mAdapter.setItemChecked(0);
    }
}
Also used : OnItemClickListener(me.yokeyword.sample.demo_zhihu.listener.OnItemClickListener) MenuAdapter(me.yokeyword.sample.demo_zhihu.adapter.MenuAdapter) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)10 ListViewDecoration (com.yanzhenjie.swiperecyclerview.view.ListViewDecoration)9 Toolbar (android.support.v7.widget.Toolbar)8 MenuAdapter (com.yanzhenjie.swiperecyclerview.adapter.MenuAdapter)8 SwipeMenuRecyclerView (com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView)5 ActionBar (android.support.v7.app.ActionBar)4 View (android.view.View)3 SuppressLint (android.annotation.SuppressLint)2 MenuAdapter (android.support.v7.view.menu.MenuAdapter)2 MenuBuilder (android.support.v7.view.menu.MenuBuilder)2 ListPopupWindow (android.support.v7.widget.ListPopupWindow)2 RecyclerView (android.support.v7.widget.RecyclerView)2 ArrayList (java.util.ArrayList)2 Activity (android.app.Activity)1 DialogInterface (android.content.DialogInterface)1 AlertDialog (android.support.v7.app.AlertDialog)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 SearchView (android.support.v7.widget.SearchView)1 Editable (android.text.Editable)1