Java Code Examples for android.widget.TextView#setOnDragListener()

The following examples show how to use android.widget.TextView#setOnDragListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SortingActivity.java    From Primary with GNU General Public License v3.0 4 votes vote down vote up
@Override
    protected void onShowProbImpl() {
        GridLayout sortArea = findViewById(R.id.sort_area);
        sortArea.removeAllViews();

        sortArea.setOnDragListener(this);

        Set<Integer> nums = new TreeSet<>();
        SortingLevel level = ((SortingLevel) getLevel());

        String numliststr = getSavedLevelValue("numlist", (String) null);
        if (numliststr == null || numliststr.length() == 0) {
            int tries = 0;
            do {
                nums.add(getRand(level.getMaxNum()));
            } while (tries++ < 100 && nums.size() < level.getNumItems());

            numlist = new ArrayList<>(nums);

            do {
                Collections.shuffle(numlist);
            } while (isSorted(numlist));

        } else {
            numlist = splitInts(",", numliststr);
            deleteSavedLevelValue("numlist");
        }

        int mlen = (level.getMaxNum() + "").length();
//        int xsize = getScreenSize().x;
//
//        int tsize = xsize*2/3 / numcolumns / 4 - 5;
//        if (tsize>30) tsize = 30;
        int tsize = 30 - mlen;

        for (int num : numlist) {
            String spaces = "";
            for (int i = 0; i < Math.max(3, mlen) - (num + "").length(); i++) {
                spaces += " ";
            }

            final String numstr = spaces + num;

            TextView item = new TextView(this);
            item.setText(numstr);
            item.setTag(num);
            item.setOnTouchListener(this);
            item.setOnDragListener(this);


            item.setMaxLines(1);
            item.setTextSize(tsize);
            item.setTypeface(Typeface.MONOSPACE);
            //item.setWidth(xsize*2/3 / numcolumns -10);
            //item.setEms(mlen);

            item.setGravity(Gravity.END);

            GridLayout.LayoutParams lp = new GridLayout.LayoutParams();

            lp.setMargins(1, 1, 1, 1);
            lp.setGravity(Gravity.CENTER);
            item.setLayoutParams(lp);
            item.setBackgroundColor(BACKGROUND_COLOR);
            item.setPadding(16, 12, 16, 12);

            sortArea.addView(item);
        }
        problemDone = false;
        moves = 0;

        setFasttimes(level.getNumItems()*300, level.getNumItems()*500, level.getNumItems()*750);

        startHint(level.getNumItems());
    }
 
Example 2
Source File: SecondActivity.java    From MultiWindow with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_activity2);
    setTitle("Second Activity");
    mTextView = (TextView) findViewById(R.id.textview);
    mScrollView = (ScrollView) findViewById(R.id.scrollview);
    mScrollView.post(new Runnable() {
        @Override
        public void run() {
            mScrollView.fullScroll(View.FOCUS_DOWN);
        }
    });
    mDrawTextView = (TextView) findViewById(R.id.drag_textview);
    mDrawImageView = (ImageView) findViewById(R.id.drag_imageview);
    mDrawTextView.setOnDragListener(new View.OnDragListener() {
        @Override
        public boolean onDrag(View view, DragEvent dragEvent) {
            switch (dragEvent.getAction()) {
                case DragEvent.ACTION_DRAG_STARTED:
                    log("ACTION_DRAG_STARTED");
                    break;
                case DragEvent.ACTION_DRAG_ENTERED:
                    log("ACTION_DRAG_ENTERED");
                    break;
                case DragEvent.ACTION_DRAG_EXITED:
                    log("ACTION_DRAG_EXITED");
                    break;
                case DragEvent.ACTION_DRAG_LOCATION:
                    log("ACTION_DRAG_LOCATION");
                    break;
                case DragEvent.ACTION_DRAG_ENDED:
                    log("ACTION_DRAG_ENDED");
                    break;
                case DragEvent.ACTION_DROP:
                    log("ACTION_DROP");
                    mDrawTextView.setVisibility(View.GONE);
                    mDrawImageView.setVisibility(View.VISIBLE);
                    ClipData clipData = dragEvent.getClipData();
                    mDrawImageView.setImageURI(clipData.getItemAt(1).getUri());
                    Toast.makeText(mActivity, clipData.getItemAt(0).getText(), Toast.LENGTH_LONG).show();
                    break;
                default:
                    break;
            }
            return true;
        }
    });
    print("onCreate", "#ff0000", false);
}
 
Example 3
Source File: DragAndDropDemo.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.drag_layout);

    TextView text = (TextView) findViewById(R.id.drag_text);
    DraggableDot dot = (DraggableDot) findViewById(R.id.drag_dot_1);
    dot.setReportView(text);
    dot = (DraggableDot) findViewById(R.id.drag_dot_2);
    dot.setReportView(text);
    dot = (DraggableDot) findViewById(R.id.drag_dot_3);
    dot.setReportView(text);

    mHiddenDot = (DraggableDot) findViewById(R.id.drag_dot_hidden);
    mHiddenDot.setReportView(text);

    mResultText = (TextView) findViewById(R.id.drag_result_text);
    mResultText.setOnDragListener(new View.OnDragListener() {
        public boolean onDrag(View v, DragEvent event) {
            final int action = event.getAction();
            switch (action) {
                case DragEvent.ACTION_DRAG_STARTED: {
                    // Bring up a fourth draggable dot on the fly. Note that it
                    // is properly notified about the ongoing drag, and lights up
                    // to indicate that it can handle the current content.
                    mHiddenDot.setVisibility(View.VISIBLE);
                } break;

                case DragEvent.ACTION_DRAG_ENDED: {
                    // Hide the surprise again
                    mHiddenDot.setVisibility(View.INVISIBLE);

                    // Report the drop/no-drop result to the user
                    final boolean dropped = event.getResult();
                    mResultText.setText(dropped ? "Dropped!" : "No drop");
                } break;
            }
            return false;
        }
    });
}