Search in sources :

Example 1 with BlockModel

use of ml.qingsu.fuckview.models.BlockModel in project fuckView by w568w.

the class MainFragment method onContextItemSelected.

@Override
public boolean onContextItemSelected(MenuItem item) {
    final AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    final BlockModel model = models.get(menuInfo.position);
    switch(item.getItemId()) {
        case 1:
            models.remove(menuInfo.position);
            adapter.notifyDataSetChanged();
            saveAll();
            break;
        case 2:
            new AlertDialog.Builder(context).setTitle(R.string.confirm).setMessage("是否要将此项设为不按类名定位?\n这样可能会解决一些无法屏蔽的问题,但是也会增加一些误伤的几率。\n\n注意:此操作不可逆!").setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    model.className = "*";
                    models.set(menuInfo.position, model);
                    adapter.notifyDataSetChanged();
                    saveAll();
                }
            }).setNegativeButton(R.string.cancel, null).show();
            break;
        case 3:
            share(model.toString());
            break;
        case 4:
            ArrayList<BlockModel> arrayList = new ArrayList<>();
            for (Integer postion : deleteList) {
                arrayList.add(models.get(postion));
            }
            models.removeAll(arrayList);
            deleteList.clear();
            adapter.notifyDataSetChanged();
            saveAll();
            break;
        case 5:
            ArrayList<BlockModel> shares = new ArrayList<>();
            for (Integer postion : deleteList) {
                shares.add(models.get(postion));
            }
            deleteList.clear();
            StringBuilder stringBuilder = new StringBuilder();
            for (BlockModel model1 : shares) {
                stringBuilder.append(model1.toString());
                stringBuilder.append("\n");
            }
            share(stringBuilder.toString());
            adapter.notifyDataSetChanged();
            break;
        case 6:
            model.enable = !model.enable;
            models.set(menuInfo.position, model);
            adapter.notifyDataSetChanged();
            saveAll();
            break;
        default:
            break;
    }
    return super.onContextItemSelected(item);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) AdapterView(android.widget.AdapterView) BlockModel(ml.qingsu.fuckview.models.BlockModel)

Example 2 with BlockModel

use of ml.qingsu.fuckview.models.BlockModel in project fuckView by w568w.

the class MainFragment method onCreateContextMenu.

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    BlockModel model = models.get(info.position);
    if (deleteList.size() > 0) {
        menu.add(0, 4, Menu.NONE, R.string.delete_selections);
        menu.add(0, 5, Menu.NONE, R.string.share_selections);
        return;
    }
    menu.add(0, 1, Menu.NONE, R.string.delete_item);
    menu.add(0, 3, Menu.NONE, R.string.share);
    menu.add(0, 6, Menu.NONE, model.enable ? R.string.disable_item : R.string.enable_item);
}
Also used : AdapterView(android.widget.AdapterView) BlockModel(ml.qingsu.fuckview.models.BlockModel)

Example 3 with BlockModel

use of ml.qingsu.fuckview.models.BlockModel in project fuckView by w568w.

the class MainFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) {
    context = getActivity();
    pm = context.getPackageManager();
    FrameLayout layout = (FrameLayout) inflater.inflate(R.layout.main_fragment, null);
    listView = (ListView) layout.findViewById(R.id.listView);
    models = MainActivity.read();
    try {
        Collections.sort(models, new Comparator<BlockModel>() {

            @Override
            public int compare(BlockModel blockModel, BlockModel t1) {
                String s1 = getAppTitle(pm, blockModel.packageName);
                String s2 = getAppTitle(pm, t1.packageName);
                // Synopsis: Updated sort behavior for Arrays and Collections may throw an IllegalArgumentException
                if (s1.equals(s2)) {
                    return 0;
                }
                return Collator.getInstance(Locale.CHINA).compare(s1, s2);
            }
        });
    } catch (IllegalArgumentException e) {
        // So we will not sort them,OK?
        e.printStackTrace();
    }
    adapter = new AppAdapter();
    listView.setAdapter(adapter);
    registerForContextMenu(listView);
    final FloatingActionButton button = (FloatingActionButton) layout.findViewById(R.id.fab);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            SelectAppWizard tw = new SelectAppWizard();
            Bundle bundle = new Bundle();
            if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("system_app", false)) {
                bundle.putBoolean("sys", true);
            }
            tw.setArguments(bundle);
            if (context instanceof MainActivity) {
                ((MainActivity) context).setFragment(tw);
            }
        }
    });
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            BlockModel model = models.get(i);
            Bundle bundle = new Bundle();
            bundle.putString("pkg", model.packageName);
            bundle.putString("record", model.record);
            bundle.putString("className", model.className);
            InfoFragment infoFragment = new InfoFragment();
            infoFragment.setArguments(bundle);
            if (context instanceof MainActivity) {
                ((MainActivity) context).setFragment(infoFragment);
            }
        }
    });
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {

        /* 标记是否滑动 */
        boolean scrollFlag = false;

        /* 标记第一次进入,因为第一次进来lastVisibleItemPosition默认为0, */
        boolean isFirst = true;

        /*
            此时如果listview的第一个显示的条目不是第一个(下表为0),则往下滑也会出现firstVisibleItem>lastVisibleItemPosition的情况
            所以第一次进入时不做操作,第二次进来已经给lastVisibleItemPosition赋值,就可以判断了
            */
        /* 标记上次的显示位置 */
        int lastVisibleItemPosition;

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            scrollFlag = scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL || scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING;
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (!isFirst) {
                if (firstVisibleItem < lastVisibleItemPosition) {
                    button.show();
                // 执行向上滑动时要做的逻辑
                } else if (firstVisibleItem > lastVisibleItemPosition) {
                    button.hide();
                }
                // 记录当前条目
                lastVisibleItemPosition = firstVisibleItem;
            }
            isFirst = false;
        }
    });
    return layout;
}
Also used : Bundle(android.os.Bundle) AbsListView(android.widget.AbsListView) MainActivity(ml.qingsu.fuckview.ui.activities.MainActivity) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ListView(android.widget.ListView) FrameLayout(android.widget.FrameLayout) FloatingActionButton(android.support.design.widget.FloatingActionButton) AdapterView(android.widget.AdapterView) BlockModel(ml.qingsu.fuckview.models.BlockModel) SelectAppWizard(ml.qingsu.fuckview.ui.fragments.select_app.SelectAppWizard) Nullable(android.support.annotation.Nullable)

Example 4 with BlockModel

use of ml.qingsu.fuckview.models.BlockModel in project fuckView by w568w.

the class MainActivity method read.

public static ArrayList<BlockModel> read() {
    ArrayList<BlockModel> list = new ArrayList<>();
    ArrayList<String> lines = readPreferenceByLine(LIST_NAME);
    for (String str : lines) {
        BlockModel model = BlockModel.fromString(str);
        if (model == null) {
            continue;
        }
        if (model.record.contains(ALL_SPLIT)) {
            model = ViewModel.fromString(str);
        } else {
            // 轉換老版(0.8.5-)規則到新版
            model = ViewModel.fromString(ConvertUtils.oldToNew(model).toString());
        }
        if (model != null) {
            list.add(model);
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) BlockModel(ml.qingsu.fuckview.models.BlockModel)

Aggregations

BlockModel (ml.qingsu.fuckview.models.BlockModel)4 AdapterView (android.widget.AdapterView)3 ArrayList (java.util.ArrayList)2 DialogInterface (android.content.DialogInterface)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 AlertDialog (android.support.v7.app.AlertDialog)1 View (android.view.View)1 AbsListView (android.widget.AbsListView)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 MainActivity (ml.qingsu.fuckview.ui.activities.MainActivity)1 SelectAppWizard (ml.qingsu.fuckview.ui.fragments.select_app.SelectAppWizard)1