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);
}
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;
}
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;
}
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();
}
});
}
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);
}
}
Aggregations