Search in sources :

Example 31 with Handler

use of android.os.Handler in project Talon-for-Twitter by klinker24.

the class SettingsDrawerClickListener method onItemClick.

@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            mDrawerLayout.closeDrawer(Gravity.START);
        }
    }, 300);
    viewPager.setCurrentItem(position, true);
}
Also used : Handler(android.os.Handler)

Example 32 with Handler

use of android.os.Handler in project Talon-for-Twitter by klinker24.

the class SendTweet method onStartCommand.

@Override
public int onStartCommand(Intent intent, int i, int x) {
    final Context context = this;
    final AppSettings settings = AppSettings.getInstance(this);
    try {
        if (intent == null) {
            return START_NOT_STICKY;
        }
    } catch (Exception e) {
    // null pointer... what the hell
    }
    // set up the tweet from the intent
    message = intent.getStringExtra("message");
    tweetId = intent.getLongExtra("tweet_id", 0l);
    remainingChars = intent.getIntExtra("char_remaining", 0);
    pwiccer = intent.getBooleanExtra("pwiccer", false);
    attachedUri = intent.getStringExtra("attached_uri");
    secondAcc = intent.getBooleanExtra("second_account", false);
    if (attachedUri == null) {
        attachedUri = "";
    }
    sendingNotification();
    new Thread(new Runnable() {

        @Override
        public void run() {
            boolean sent = sendTweet(settings, context);
            if (sent) {
                finishedTweetingNotification();
            } else {
                makeFailedNotification(message, settings);
            }
            finished = true;
            stopSelf();
        }
    }).start();
    // if it takes longer than 2 mins to preform the sending, then something is wrong and we will just shut it down.
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            if (!finished) {
                stopForeground(true);
                makeFailedNotification(message, settings);
                stopSelf();
            }
        }
    }, 120000);
    return START_STICKY;
}
Also used : Context(android.content.Context) AppSettings(com.klinker.android.twitter.settings.AppSettings) Handler(android.os.Handler) IOException(java.io.IOException)

Example 33 with Handler

use of android.os.Handler in project glitch-hq-android by tinyspeck.

the class HomeScreen method onResume.

@Override
protected void onResume() {
    super.onResume();
    if (m_newPage != null) {
        if (m_curPage == m_newPage) {
            clearFragmentStack();
        } else {
            m_curPage = m_newPage;
            Handler handler = new Handler();
            Runnable runnable = new Runnable() {

                public void run() {
                    switch(m_curPage) {
                        case Profile:
                            setCurrentFragment(m_profileFrm, false);
                            break;
                        case Activity:
                            setCurrentFragment(m_activityFrm, false);
                            break;
                        case Skills:
                            setCurrentFragment(m_skillFrm, false);
                            break;
                        case Quests:
                            setCurrentFragment(m_questsFrm, false);
                            break;
                        case Friends:
                            setCurrentFragment(m_friendsFrm, false);
                            break;
                        case Encyclopedia:
                            setCurrentFragment(m_encyclopediaFrm, false);
                            break;
                        case RecentSnaps:
                            setCurrentFragment(m_recentSnapsFrm, false);
                            break;
                        case Achievements:
                            setCurrentFragment(m_achievementsFrm, false);
                            break;
                        case Mailbox:
                            setCurrentFragment(m_mailboxFrm, false);
                            break;
                        case Settings:
                            setCurrentFragment(m_settingsFrm, false);
                            break;
                        default:
                            break;
                    }
                }
            };
            handler.postDelayed(runnable, 1);
        }
    }
    m_newPage = null;
}
Also used : Handler(android.os.Handler)

Example 34 with Handler

use of android.os.Handler in project sticky-headers-recyclerview by timehop.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
    Button button = (Button) findViewById(R.id.button_update);
    final ToggleButton isReverseButton = (ToggleButton) findViewById(R.id.button_is_reverse);
    // Set adapter populated with example dummy data
    final AnimalsHeadersAdapter adapter = new AnimalsHeadersAdapter();
    adapter.add("Animals below!");
    adapter.addAll(getDummyDataSet());
    recyclerView.setAdapter(adapter);
    // Set button to update all views one after another (Test for the "Dance")
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Handler handler = new Handler(Looper.getMainLooper());
            for (int i = 0; i < adapter.getItemCount(); i++) {
                final int index = i;
                handler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        adapter.notifyItemChanged(index);
                    }
                }, 50);
            }
        }
    });
    // Set layout manager
    int orientation = getLayoutManagerOrientation(getResources().getConfiguration().orientation);
    final LinearLayoutManager layoutManager = new LinearLayoutManager(this, orientation, isReverseButton.isChecked());
    recyclerView.setLayoutManager(layoutManager);
    // Add the sticky headers decoration
    final StickyRecyclerHeadersDecoration headersDecor = new StickyRecyclerHeadersDecoration(adapter);
    recyclerView.addItemDecoration(headersDecor);
    // Add decoration for dividers between list items
    recyclerView.addItemDecoration(new DividerDecoration(this));
    // Add touch listeners
    StickyRecyclerHeadersTouchListener touchListener = new StickyRecyclerHeadersTouchListener(recyclerView, headersDecor);
    touchListener.setOnHeaderClickListener(new StickyRecyclerHeadersTouchListener.OnHeaderClickListener() {

        @Override
        public void onHeaderClick(View header, int position, long headerId) {
            Toast.makeText(MainActivity.this, "Header position: " + position + ", id: " + headerId, Toast.LENGTH_SHORT).show();
        }
    });
    recyclerView.addOnItemTouchListener(touchListener);
    recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, new RecyclerItemClickListener.OnItemClickListener() {

        @Override
        public void onItemClick(View view, int position) {
            adapter.remove(adapter.getItem(position));
        }
    }));
    adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {

        @Override
        public void onChanged() {
            headersDecor.invalidateHeaders();
        }
    });
    isReverseButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean isChecked = isReverseButton.isChecked();
            isReverseButton.setChecked(isChecked);
            layoutManager.setReverseLayout(isChecked);
            adapter.notifyDataSetChanged();
        }
    });
}
Also used : ToggleButton(android.widget.ToggleButton) Handler(android.os.Handler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) StickyRecyclerHeadersTouchListener(com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersTouchListener) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) StickyRecyclerHeadersDecoration(com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration) Button(android.widget.Button) ToggleButton(android.widget.ToggleButton) RecyclerView(android.support.v7.widget.RecyclerView)

Example 35 with Handler

use of android.os.Handler in project ExpandableLayout by traex.

the class ExpandableLayout method hide.

public void hide() {
    if (!isAnimationRunning) {
        collapse(contentLayout);
        isAnimationRunning = true;
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                isAnimationRunning = false;
            }
        }, duration);
    }
}
Also used : Handler(android.os.Handler)

Aggregations

Handler (android.os.Handler)1904 Message (android.os.Message)254 View (android.view.View)207 Intent (android.content.Intent)174 HandlerThread (android.os.HandlerThread)156 TextView (android.widget.TextView)118 MediumTest (android.test.suitebuilder.annotation.MediumTest)116 ArrayList (java.util.ArrayList)97 Test (org.junit.Test)85 Context (android.content.Context)71 IntentFilter (android.content.IntentFilter)69 RemoteException (android.os.RemoteException)63 IOException (java.io.IOException)63 ComponentName (android.content.ComponentName)57 ImageView (android.widget.ImageView)57 Bundle (android.os.Bundle)56 RecyclerView (android.support.v7.widget.RecyclerView)54 Looper (android.os.Looper)53 File (java.io.File)46 ContentObserver (android.database.ContentObserver)44