Search in sources :

Example 1 with ViewModel

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

the class DumpViewerPopupView method onCreateView.

@Override
protected View onCreateView(final Context context) {
    LinearLayout layout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.dump_viewer_view, null);
    mRefresh = (Button) layout.findViewById(R.id.dump_refresh);
    mInfo = (TextView) layout.findViewById(R.id.dump_info);
    final Button close = (Button) layout.findViewById(R.id.dump_close);
    final Button top = (Button) layout.findViewById(R.id.dump_top);
    setFocusable(false);
    mRefresh.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // 一个null会被误认为Runnable
            new RefreshTask().execute(null, null);
        }
    });
    close.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mFullScreenPopupWindow != null) {
                mFullScreenPopupWindow.hide();
            }
            hide();
            try {
                ShellUtils.killProcess(mPackageName);
                MainActivity.writePreferences("", MainActivity.PACKAGE_NAME_NAME);
                appContext.unregisterReceiver(mReceiver);
            } catch (IllegalArgumentException | IOException e) {
                e.printStackTrace();
            }
        }
    });
    top.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mGravity = (mGravity == Gravity.TOP ? Gravity.BOTTOM : Gravity.TOP);
            updateLayout();
        }
    });
    mInfo.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                ViewModel model = (ViewModel) mInfo.getTag();
                model.save();
                // 發送,以使View接收隱藏廣播
                appContext.sendBroadcast(new Intent(ViewReceiver.ACTION).putExtra("path", model.getPath()));
                Toast.makeText(appContext, R.string.rule_saved, Toast.LENGTH_SHORT).show();
                mInfo.setTag(null);
                mInfo.setText("");
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }
        }
    });
    return layout;
}
Also used : Button(android.widget.Button) Intent(android.content.Intent) ViewModel(ml.qingsu.fuckview.models.ViewModel) View(android.view.View) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 2 with ViewModel

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

the class FullScreenListPopupWindow method init.

private void init(final Context context) {
    listView.setFocusableInTouchMode(true);
    listView.setAdapter(new BaseAdapter() {

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, final ViewGroup parent) {
            TextView textView;
            if (convertView == null || convertView instanceof TextView) {
                textView = new TextView(context);
            } else {
                textView = (TextView) convertView;
            }
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
            textView.setPadding(0, 12, 0, 12);
            final ViewDumper.ViewItem item = (ViewDumper.ViewItem) getItem(position);
            // 文字前空格
            textView.setText(tab(item.level) + item.simpleClassName);
            textView.setClickable(true);
            textView.setLongClickable(true);
            textView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    hide();
                    // 红框
                    final RedBoundPopupWindow redBound = new RedBoundPopupWindow(getActivity(), item.bounds, item.wh);
                    redBound.show();
                    v.postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            redBound.hide();
                            show();
                        }
                    }, 1000);
                }
            });
            textView.setOnLongClickListener(new View.OnLongClickListener() {

                @Override
                public boolean onLongClick(View v) {
                    PopupMenu popupMenu = new PopupMenu(context, v);
                    popupMenu.getMenu().add(R.string.popup_mark_it);
                    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            if (item.getTitle().equals(context.getString(R.string.popup_mark_it))) {
                                ViewDumper.ViewItem item1 = list.get(position);
                                Point p = item1.bounds;
                                MainActivity.appendPreferences("\n" + new ViewModel(pkg, " " + MainActivity.ALL_SPLIT + " " + MainActivity.ALL_SPLIT + p.x + "," + p.y + "$$", "", "*").toString(), MainActivity.LIST_NAME);
                                Toast.makeText(getActivity(), R.string.rule_saved, Toast.LENGTH_SHORT).show();
                            }
                            return true;
                        }
                    });
                    popupMenu.show();
                    return true;
                }
            });
            return textView;
        }

        private String tab(int num) {
            String tab = "";
            for (int i = 0; i < num; i++) {
                tab += " ";
            }
            return tab;
        }
    });
    listView.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                hide();
                popupView.show();
                return true;
            }
            return false;
        }
    });
}
Also used : ViewDumper(ml.qingsu.fuckview.utils.dumper.ViewDumper) ViewGroup(android.view.ViewGroup) MenuItem(android.view.MenuItem) Point(android.graphics.Point) ViewModel(ml.qingsu.fuckview.models.ViewModel) TextView(android.widget.TextView) View(android.view.View) Point(android.graphics.Point) KeyEvent(android.view.KeyEvent) TextView(android.widget.TextView) BaseAdapter(android.widget.BaseAdapter) PopupMenu(android.support.v7.widget.PopupMenu)

Example 3 with ViewModel

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

the class FullScreenPopupWindow method onCreateView.

@Override
protected View onCreateView(final Context context) {
    absoluteLayout = new AbsoluteLayout(context);
    absoluteLayout.setBackgroundColor(Color.argb(120, 0, 0, 0));
    absoluteLayout.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() != MotionEvent.ACTION_UP) {
                return false;
            }
            // 获得点击的View
            View v = getTouchView((int) motionEvent.getX(), (int) motionEvent.getY());
            if (v != null) {
                // 调用点击处理
                onClick(v);
            }
            return true;
        }

        private void onClick(final View view) {
            // 确定为红框标识
            if (view.getTag() instanceof ViewDumper.ViewItem) {
                System.out.println(getPath((ViewDumper.ViewItem) view.getTag()));
                // 先储存它原有的样式
                final Drawable drawable = view.getBackground();
                // 弹出菜单
                android.support.v7.widget.PopupMenu popupMenu = new android.support.v7.widget.PopupMenu(view.getContext(), view);
                popupMenu.getMenu().add(R.string.popup_mark_it);
                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        if (item.getTitle().equals(context.getString(R.string.popup_mark_it))) {
                            ViewDumper.ViewItem item1 = (ViewDumper.ViewItem) view.getTag();
                            Point p = item1.bounds;
                            MainActivity.appendPreferences("\n" + new ViewModel(pkg, " " + MainActivity.ALL_SPLIT + " " + MainActivity.ALL_SPLIT + p.x + "," + p.y + "$$", "", "*").toString(), MainActivity.LIST_NAME);
                            Toast.makeText(getActivity(), R.string.rule_saved, Toast.LENGTH_SHORT).show();
                        }
                        return true;
                    }
                });
                popupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {

                    @Override
                    public void onDismiss(PopupMenu menu) {
                        view.setBackgroundDrawable(drawable);
                        params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
                        updateLayout();
                    }
                });
                popupMenu.setGravity(Gravity.CENTER);
                view.setBackgroundColor(Color.argb(120, 255, 0, 0));
                updateLayout();
                popupMenu.show();
            }
        }
    });
    absoluteLayout.setFocusableInTouchMode(true);
    absoluteLayout.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                hide();
                popupView.show();
                return true;
            }
            return false;
        }
    });
    return absoluteLayout;
}
Also used : ViewDumper(ml.qingsu.fuckview.utils.dumper.ViewDumper) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) PopupMenu(android.support.v7.widget.PopupMenu) MenuItem(android.view.MenuItem) Point(android.graphics.Point) ViewModel(ml.qingsu.fuckview.models.ViewModel) TextView(android.widget.TextView) View(android.view.View) AbsoluteLayout(android.widget.AbsoluteLayout) Point(android.graphics.Point) MotionEvent(android.view.MotionEvent) KeyEvent(android.view.KeyEvent) PopupMenu(android.support.v7.widget.PopupMenu)

Example 4 with ViewModel

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

the class MainActivity method dealWithIntent.

private void dealWithIntent() {
    writePreferences("", PACKAGE_NAME_NAME);
    // 此处详见Hook.java
    // 是否从通知栏里点过来
    boolean isDialog = getIntent().getBooleanExtra("Dialog", false);
    String cache = getIntent().getStringExtra("cache");
    if (cache == null) {
        return;
    }
    if (isDialog) {
        final ViewModel blockInfo = ViewModel.fromString(cache);
        if (blockInfo == null) {
            return;
        }
        blockInfo.save();
    } else {
        appendPreferences(cache, LIST_NAME);
    }
    Toast.makeText(this, R.string.rule_saved, Toast.LENGTH_SHORT).show();
}
Also used : ViewModel(ml.qingsu.fuckview.models.ViewModel)

Aggregations

ViewModel (ml.qingsu.fuckview.models.ViewModel)4 View (android.view.View)3 TextView (android.widget.TextView)3 Point (android.graphics.Point)2 PopupMenu (android.support.v7.widget.PopupMenu)2 KeyEvent (android.view.KeyEvent)2 MenuItem (android.view.MenuItem)2 ViewDumper (ml.qingsu.fuckview.utils.dumper.ViewDumper)2 Intent (android.content.Intent)1 Drawable (android.graphics.drawable.Drawable)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 MotionEvent (android.view.MotionEvent)1 ViewGroup (android.view.ViewGroup)1 AbsoluteLayout (android.widget.AbsoluteLayout)1 BaseAdapter (android.widget.BaseAdapter)1 Button (android.widget.Button)1 LinearLayout (android.widget.LinearLayout)1