use of android.content.BroadcastReceiver in project Shuttle by timusus.
the class DrawerHeaderFragment method onResume.
@Override
public void onResume() {
super.onResume();
mStatusListener = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action != null) {
switch(action) {
case MusicService.InternalIntents.META_CHANGED:
updateTrackInfo();
break;
case MusicService.InternalIntents.PLAY_STATE_CHANGED:
updateTrackInfo();
break;
case MusicService.InternalIntents.SERVICE_CONNECTED:
updateTrackInfo();
break;
}
}
}
};
final IntentFilter filter = new IntentFilter();
filter.addAction(MusicService.InternalIntents.META_CHANGED);
filter.addAction(MusicService.InternalIntents.PLAY_STATE_CHANGED);
filter.addAction(MusicService.InternalIntents.SERVICE_CONNECTED);
getActivity().registerReceiver(mStatusListener, filter);
updateTrackInfo();
}
use of android.content.BroadcastReceiver in project coursera-android by aporter.
the class CompoundOrderedBroadcastWithResultReceiver method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
IntentFilter intentFilter = new IntentFilter(CUSTOM_INTENT);
intentFilter.setPriority(3);
registerReceiver(mReceiver1, intentFilter);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
sendOrderedBroadcast(new Intent(CUSTOM_INTENT), null, new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Final Result is " + getResultData(), Toast.LENGTH_LONG).show();
}
}, null, 0, null, null);
}
});
}
use of android.content.BroadcastReceiver in project Talon-for-Twitter by klinker24.
the class MainActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
UpdateUtils.checkUpdate(this);
MainActivity.sendHandler = new Handler();
context = this;
sContext = this;
sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
DrawerActivity.settings = AppSettings.getInstance(context);
try {
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
} catch (Exception e) {
}
sharedPrefs.edit().putBoolean("refresh_me", getIntent().getBooleanExtra("from_notification", false)).commit();
setUpTheme();
setUpWindow();
setContentView(R.layout.main_activity);
mViewPager = (ViewPager) findViewById(R.id.pager);
setUpDrawer(0, getResources().getString(R.string.timeline));
MainActivity.sendLayout = (LinearLayout) findViewById(R.id.send_layout);
MainActivity.sendHandler.postDelayed(showSend, 1000);
MainActivity.sendButton = (ImageButton) findViewById(R.id.send_button);
MainActivity.sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent compose = new Intent(context, ComposeActivity.class);
startActivity(compose);
}
});
actionBar = getActionBar();
if (!settings.isTwitterLoggedIn) {
Intent login = new Intent(context, LoginActivity.class);
startActivity(login);
}
mSectionsPagerAdapter = new TimelinePagerAdapter(getFragmentManager(), context, sharedPrefs, getIntent().getBooleanExtra("from_launcher", false));
int currAccount = sharedPrefs.getInt("current_account", 1);
int defaultPage = sharedPrefs.getInt("default_timeline_page_" + currAccount, 0);
actionBar.setTitle(mSectionsPagerAdapter.getPageTitle(defaultPage));
mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
public void onPageScrollStateChanged(int state) {
}
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
if (!actionBar.isShowing()) {
actionBar.show();
if (translucent) {
statusBar.setVisibility(View.VISIBLE);
}
}
MainActivity.sendHandler.post(showSend);
}
public void onPageSelected(int position) {
String title = "" + mSectionsPagerAdapter.getPageTitle(position);
MainDrawerArrayAdapter.setCurrent(context, position);
drawerList.invalidateViews();
actionBar.setTitle(title);
}
});
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setOverScrollMode(View.OVER_SCROLL_NEVER);
mViewPager.setCurrentItem(defaultPage);
MainDrawerArrayAdapter.setCurrent(this, defaultPage);
drawerList.invalidateViews();
if (getIntent().getBooleanExtra("from_launcher", false)) {
actionBar.setTitle(mSectionsPagerAdapter.getPageTitle(getIntent().getIntExtra("launcher_page", 0)));
}
mViewPager.setOffscreenPageLimit(TimelinePagerAdapter.MAX_EXTRA_PAGES);
if (getIntent().getBooleanExtra("tutorial", false) && !sharedPrefs.getBoolean("done_tutorial", false)) {
getIntent().putExtra("tutorial", false);
sharedPrefs.edit().putBoolean("done_tutorial", true).commit();
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
try {
Log.v("tutorial_activity", "close drawer");
mDrawerLayout.closeDrawer(Gravity.LEFT);
unregisterReceiver(this);
} catch (Exception e) {
e.printStackTrace();
}
}
}, new IntentFilter(TutorialActivity.ACTION_CLOSE_DRAWER));
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
try {
Log.v("tutorial_activity", "open drawer");
mDrawerLayout.openDrawer(Gravity.LEFT);
unregisterReceiver(this);
} catch (Exception e) {
e.printStackTrace();
}
}
}, new IntentFilter(TutorialActivity.ACTION_OPEN_DRAWER));
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
try {
Log.v("tutorial_activity", "page left");
mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1, true);
unregisterReceiver(this);
} catch (Exception e) {
e.printStackTrace();
}
}
}, new IntentFilter(TutorialActivity.ACTION_PAGE_LEFT));
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
try {
Log.v("tutorial_activity", "page right");
mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1, true);
unregisterReceiver(this);
} catch (Exception e) {
e.printStackTrace();
}
}
}, new IntentFilter(TutorialActivity.ACTION_PAGE_RIGHT));
startActivity(new Intent(context, TutorialActivity.class));
overridePendingTransition(0, 0);
}
setLauncherPage();
if (getIntent().getBooleanExtra("from_drawer", false)) {
mViewPager.setCurrentItem(getIntent().getIntExtra("page_to_open", 1));
}
}
use of android.content.BroadcastReceiver in project Shuttle by timusus.
the class PlayerActivity method onStart.
@Override
protected void onStart() {
super.onStart();
mStatusListener = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action != null) {
switch(action) {
case MusicService.InternalIntents.META_CHANGED:
updateTrackInfo();
setPauseButtonImage();
queueNextRefresh(1);
break;
case MusicService.InternalIntents.PLAY_STATE_CHANGED:
setPauseButtonImage();
break;
case MusicService.InternalIntents.REPEAT_CHANGED:
setRepeatButtonImage();
break;
case MusicService.InternalIntents.SHUFFLE_CHANGED:
setShuffleButtonImage();
break;
}
}
}
};
final IntentFilter filter = new IntentFilter();
filter.addAction(MusicService.InternalIntents.PLAY_STATE_CHANGED);
filter.addAction(MusicService.InternalIntents.META_CHANGED);
filter.addAction(MusicService.InternalIntents.SHUFFLE_CHANGED);
filter.addAction(MusicService.InternalIntents.REPEAT_CHANGED);
registerReceiver(mStatusListener, new IntentFilter(filter));
}
use of android.content.BroadcastReceiver in project Shuttle by timusus.
the class ReconnectionService method onCreate.
@Override
public void onCreate() {
LOGD(TAG, "onCreate() is called");
mCastManager = VideoCastManager.getInstance();
if (!mCastManager.isConnected() && !mCastManager.isConnecting()) {
mCastManager.reconnectSessionIfPossible();
}
// register a broadcast receiver to be notified when screen goes on or off
IntentFilter screenOnOffIntentFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
screenOnOffIntentFilter.addAction(Intent.ACTION_SCREEN_OFF);
mScreenOnOffBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
LOGD(TAG, "ScreenOnOffBroadcastReceiver: onReceive(): " + intent.getAction());
long timeLeft = getMediaRemainingTime();
if (timeLeft < EPSILON_MS) {
handleTermination();
}
}
};
registerReceiver(mScreenOnOffBroadcastReceiver, screenOnOffIntentFilter);
// register a wifi receiver that would be notified when the network state changes
IntentFilter networkIntentFilter = new IntentFilter();
networkIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
mWifiBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
boolean connected = info.isConnected();
String networkSsid = connected ? Utils.getWifiSsid(context) : null;
ReconnectionService.this.onWifiConnectivityChanged(connected, networkSsid);
}
}
};
registerReceiver(mWifiBroadcastReceiver, networkIntentFilter);
super.onCreate();
}
Aggregations