Sharondohp Sharonas
Sharondohp Sharonas

Reputation: 277

How can i make a text in android-studio to be animated?

For example if i display in a TextView the text "Uploading" now i want it to display the text as "Uploading..." and the 3 points to be delete and show again like it's processing doing something and not just static text.

I have this in the MainActivity onTouch event:

@Override
        public boolean onTouchEvent(MotionEvent event)
        {
            float eventX = event.getX();
            float eventY = event.getY();

            float lastdownx = 0;
            float lastdowny = 0;

            switch (event.getAction())
            {
                case MotionEvent.ACTION_DOWN:
                    lastdownx = eventX;
                    lastdowny = eventY;

                    Thread t = new Thread(new Runnable()
                    {
                        @Override
                        public void run()
                        {
                            byte[] response = null;
                            if (connectedtoipsuccess == true)
                            {

                                if (is_start == true)
                                {
                                    uploadTimerBool = true;
                                    timers.StartTimer(timerValueRecord, "Recording Time: ");
                                    response = Get(iptouse + "start");
                                    is_start = false;
                                } else
                                {
                                    timers.StopTimer(timerValueRecord);
                                    textforthespeacch = "Recording stopped and preparing the file to be shared on youtube";
                                    MainActivity.this.runOnUiThread(new Runnable()
                                    {
                                        @Override
                                        public void run()
                                        {
                                            status1.setText("Preparing the file");
                                        }
                                    });
                                    MainActivity.this.initTTS();
                                    response = Get(iptouse + "stop");
                                    is_start = true;
                                    startuploadstatusthread = true;
                                    servercheckCounter = 0;
                                }
                                if (response != null)
                                {
                                    try
                                    {
                                        a = new String(response, "UTF-8");

                                        MainActivity.this.runOnUiThread(new Runnable()
                                        {
                                            @Override
                                            public void run()
                                            {
                                                if (a.equals("Recording started"))
                                                {
                                                    status1.setText("Recording");
                                                }
                                                if (a.equals("Recording stopped and preparing the file to be shared on youtube"))
                                                {
                                                    status1.setText("Recording Stopped");
                                                }
                                            }
                                        });
                                        textforthespeacch = a;
                                        MainActivity.this.initTTS();
                                    } catch (UnsupportedEncodingException e)
                                    {
                                        e.printStackTrace();
                                    }
                                    Logger.getLogger("MainActivity(inside thread)").info(a);
                                }
                            }
                        }
                    });
                    t.start();
                    return true;
                case MotionEvent.ACTION_MOVE:
                    break;
                case MotionEvent.ACTION_UP:
                    break;
                default:
                    return false;
            }
            return true;
        }

This line:

status1.setText("Preparing the file");

Instead displaying only static text "Preparing the file" i was wondering how to make that it will display something like moving points like "Preparing the file..." then "Preparing the file.." and "Preparing the file." and again "Preparing the file..." then "Preparing the file.." and so on.

Upvotes: 5

Views: 138

Answers (2)

Prakhar
Prakhar

Reputation: 710

Use this awesome library, exactly what you are looking for: https://github.com/tajchert/WaitingDots

Add this to dependencies

 compile 'pl.tajchert:waitingdots:0.2.0'

and you can use the methos. The description is in the link

Upvotes: 2

Rohan Kawade
Rohan Kawade

Reputation: 473

Handler handler = new Handler();

for (int i = 100; i <= 3500; i=i+100) {
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            if(i%300 == 0){
                textView.setText("Uploading.");
            }else if(i%200 == 0){
                textView.setText("Uploading..");
            }else if(i%100 == 0){
                textView.setText("Uploading...");
            }
        }
    }, i);
}

Upvotes: 1

Related Questions