Search in sources :

Example 1 with MainActivity

use of ml.qingsu.fuckview.ui.activities.MainActivity 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 2 with MainActivity

use of ml.qingsu.fuckview.ui.activities.MainActivity in project fuckView by w568w.

the class WelcomeFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.welcome_fragment, null);
    layout.findViewById(R.id.welcome_guide).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://w568.wodemo.net/entry/467891")));
            } catch (ActivityNotFoundException a) {
                a.printStackTrace();
                Toast.makeText(getActivity(), getString(R.string.unsupport_of_package), Toast.LENGTH_SHORT).show();
            }
        }
    });
    layout.findViewById(R.id.welcome_pass).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (getActivity() instanceof MainActivity) {
                ((MainActivity) getActivity()).setFragmentWithoutBack(new SelectAppWizard());
            }
        }
    });
    return layout;
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) RelativeLayout(android.widget.RelativeLayout) Intent(android.content.Intent) MainActivity(ml.qingsu.fuckview.ui.activities.MainActivity) View(android.view.View) SelectAppWizard(ml.qingsu.fuckview.ui.fragments.select_app.SelectAppWizard) Nullable(android.support.annotation.Nullable)

Aggregations

Nullable (android.support.annotation.Nullable)2 View (android.view.View)2 MainActivity (ml.qingsu.fuckview.ui.activities.MainActivity)2 SelectAppWizard (ml.qingsu.fuckview.ui.fragments.select_app.SelectAppWizard)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 RelativeLayout (android.widget.RelativeLayout)1 TextView (android.widget.TextView)1 BlockModel (ml.qingsu.fuckview.models.BlockModel)1