List of usage examples for android.content Intent getAction
public @Nullable String getAction()
From source file:com.app.uafeed.activity.EditFeedActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { UiUtils.setPreferenceTheme(this); super.onCreate(savedInstanceState); getActionBar().setDisplayHomeAsUpEnabled(true); setContentView(R.layout.activity_feed_edit); setResult(RESULT_CANCELED);/*from w w w.j a va 2s.co m*/ Intent intent = getIntent(); mTabHost = (TabHost) findViewById(R.id.tabHost); mNameEditText = (EditText) findViewById(R.id.feed_title); mUrlEditText = (EditText) findViewById(R.id.feed_url); mRetrieveFulltextCb = (CheckBox) findViewById(R.id.retrieve_fulltext); mFiltersListView = (ListView) findViewById(android.R.id.list); View tabWidget = findViewById(android.R.id.tabs); View buttonLayout = findViewById(R.id.button_layout); mTabHost.setup(); mTabHost.addTab(mTabHost.newTabSpec("feedTab").setIndicator(getString(R.string.tab_feed_title)) .setContent(R.id.feed_tab)); mTabHost.addTab(mTabHost.newTabSpec("filtersTab").setIndicator(getString(R.string.tab_filters_title)) .setContent(R.id.filters_tab)); mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String s) { invalidateOptionsMenu(); } }); if (savedInstanceState != null) { mTabHost.setCurrentTab(savedInstanceState.getInt(STATE_CURRENT_TAB)); } if (intent.getAction().equals(Intent.ACTION_INSERT) || intent.getAction().equals(Intent.ACTION_SEND)) { setTitle(R.string.new_feed_title); tabWidget.setVisibility(View.GONE); if (intent.hasExtra(Intent.EXTRA_TEXT)) { mUrlEditText.setText(intent.getStringExtra(Intent.EXTRA_TEXT)); } } else if (intent.getAction().equals(Intent.ACTION_EDIT)) { setTitle(R.string.edit_feed_title); buttonLayout.setVisibility(View.GONE); mFiltersCursorAdapter = new FiltersCursorAdapter(this, null); mFiltersListView.setAdapter(mFiltersCursorAdapter); mFiltersListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { startActionMode(mFilterActionModeCallback); mFiltersCursorAdapter.setSelectedFilter(position); mFiltersListView.invalidateViews(); return true; } }); getLoaderManager().initLoader(0, null, this); if (savedInstanceState == null) { Cursor cursor = getContentResolver().query(intent.getData(), FEED_PROJECTION, null, null, null); if (cursor.moveToNext()) { mPreviousName = cursor.getString(0); mNameEditText.setText(mPreviousName); mUrlEditText.setText(cursor.getString(1)); mRetrieveFulltextCb.setChecked(cursor.getInt(2) == 1); cursor.close(); } else { cursor.close(); Toast.makeText(EditFeedActivity.this, R.string.error, Toast.LENGTH_SHORT).show(); finish(); } } } }
From source file:org.deviceconnect.android.deviceplugin.host.HostDeviceService.java
@Override public int onStartCommand(final Intent intent, final int flags, final int startId) { if (intent == null) { return START_STICKY; }/*from w w w . java 2 s . c o m*/ String action = intent.getAction(); if (Intent.ACTION_BATTERY_CHANGED.equals(action) || Intent.ACTION_BATTERY_LOW.equals(action) || Intent.ACTION_BATTERY_OKAY.equals(action)) { // ???? mHostBatteryManager.setBatteryRequest(intent); List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostBatteryProfile.PROFILE_NAME, null, HostBatteryProfile.ATTRIBUTE_ON_BATTERY_CHANGE); for (int i = 0; i < events.size(); i++) { Event event = events.get(i); Intent mIntent = EventManager.createEventMessage(event); HostBatteryProfile.setAttribute(mIntent, HostBatteryProfile.ATTRIBUTE_ON_BATTERY_CHANGE); Bundle battery = new Bundle(); HostBatteryProfile.setLevel(battery, mHostBatteryManager.getBatteryLevel()); getContext().sendBroadcast(mIntent); } return START_STICKY; } else if (Intent.ACTION_POWER_CONNECTED.equals(action) || Intent.ACTION_POWER_DISCONNECTED.equals(action)) { // ???? mHostBatteryManager.setBatteryRequest(intent); List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostBatteryProfile.PROFILE_NAME, null, HostBatteryProfile.ATTRIBUTE_ON_CHARGING_CHANGE); for (int i = 0; i < events.size(); i++) { Event event = events.get(i); Intent mIntent = EventManager.createEventMessage(event); HostBatteryProfile.setAttribute(mIntent, HostBatteryProfile.ATTRIBUTE_ON_CHARGING_CHANGE); Bundle charging = new Bundle(); if (Intent.ACTION_POWER_CONNECTED.equals(action)) { HostBatteryProfile.setCharging(charging, true); } else { HostBatteryProfile.setCharging(charging, false); } HostBatteryProfile.setBattery(mIntent, charging); getContext().sendBroadcast(mIntent); } return START_STICKY; } else if (action.equals("android.intent.action.NEW_OUTGOING_CALL")) { // Phone List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostPhoneProfile.PROFILE_NAME, null, HostPhoneProfile.ATTRIBUTE_ON_CONNECT); for (int i = 0; i < events.size(); i++) { Event event = events.get(i); Intent mIntent = EventManager.createEventMessage(event); HostPhoneProfile.setAttribute(mIntent, HostPhoneProfile.ATTRIBUTE_ON_CONNECT); Bundle phoneStatus = new Bundle(); HostPhoneProfile.setPhoneNumber(phoneStatus, intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER)); HostPhoneProfile.setState(phoneStatus, CallState.START); HostPhoneProfile.setPhoneStatus(mIntent, phoneStatus); getContext().sendBroadcast(mIntent); } return START_STICKY; } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action) || WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { // Wifi List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostConnectProfile.PROFILE_NAME, null, HostConnectProfile.ATTRIBUTE_ON_WIFI_CHANGE); for (int i = 0; i < events.size(); i++) { Event event = events.get(i); Intent mIntent = EventManager.createEventMessage(event); HostConnectProfile.setAttribute(mIntent, HostConnectProfile.ATTRIBUTE_ON_WIFI_CHANGE); Bundle wifiConnecting = new Bundle(); WifiManager wifiMgr = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE); HostConnectProfile.setEnable(wifiConnecting, wifiMgr.isWifiEnabled()); HostConnectProfile.setConnectStatus(mIntent, wifiConnecting); getContext().sendBroadcast(mIntent); } return START_STICKY; } else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) { List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostConnectProfile.PROFILE_NAME, null, HostConnectProfile.ATTRIBUTE_ON_BLUETOOTH_CHANGE); for (int i = 0; i < events.size(); i++) { Event event = events.get(i); Intent mIntent = EventManager.createEventMessage(event); HostConnectProfile.setAttribute(mIntent, HostConnectProfile.ATTRIBUTE_ON_BLUETOOTH_CHANGE); Bundle bluetoothConnecting = new Bundle(); BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); HostConnectProfile.setEnable(bluetoothConnecting, mBluetoothAdapter.isEnabled()); HostConnectProfile.setConnectStatus(mIntent, bluetoothConnecting); getContext().sendBroadcast(mIntent); } return START_STICKY; } return super.onStartCommand(intent, flags, startId); }
From source file:com.fvd.nimbus.BrowseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up ); //overridePendingTransition(R.anim.carbon_slide_in,R.anim.carbon_slide_out); //overridePendingTransition(R.anim.activity_open_scale,R.anim.activity_close_translate); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); try {/*from w w w .j a v a 2s. c om*/ requestWindowFeature(Window.FEATURE_NO_TITLE); } catch (Exception e) { e.printStackTrace(); } clipData = new DataExchange(); isInitNow = true; setContentView(R.layout.screen_browser); serverHelper.getInstance().setCallback(this, this); prefs = PreferenceManager.getDefaultSharedPreferences(this); lastUrl = prefs.getString("LAST_URL", ""); saveCSS = prefs.getString("clipStyle", "1").equals("1"); ctx = this; //adapter = new TextAdapter(this); /*Uri data = getIntent().getData(); if(data!=null){ lastUrl=data.toString(); }*/ Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_VIEW.equals(action) /*&& type != null*/) { Uri data = intent.getData(); if (data != null) { lastUrl = data.toString(); appSettings.appendLog("browse:onCreate " + lastUrl); } } else if (Intent.ACTION_SEND.equals(action) /*&& type != null*/) { if ("text/plain".equals(type)) { String surl = intent.getStringExtra(Intent.EXTRA_TEXT); if (surl.contains(" ")) { String[] arr = surl.replace("\t", " ").split(" "); for (String s : arr) { if (s.contains("://")) { lastUrl = s.trim(); break; } } } else if (surl.contains("://")) lastUrl = surl.trim(); appSettings.appendLog("browse:onCreate " + lastUrl); } } drawer = (DrawerLayout) findViewById(R.id.root); View v = findViewById(R.id.wv); wv = (fvdWebView) findViewById(R.id.wv); wv.setEventsHandler(this); //registerForContextMenu(wv); urlField = (AutoCompleteTextView) findViewById(R.id.etAddess); urlField.setSelectAllOnFocus(true); urlField.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { /*InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0);*/ onNavButtonClicked(); return true; } else if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { onNavButtonClicked(); return true; } return false; } }); onViewCreated(); handler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case 0: findViewById(R.id.bZoomStack).setVisibility(View.VISIBLE); findViewById(R.id.bToggleMenu).setVisibility(View.GONE); break; default: break; } } }; navButton = (ImageButton) findViewById(R.id.ibReloadWebPage); navButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //Toast.makeText(getApplicationContext(), "You made a mess", Toast.LENGTH_LONG).show(); onNavButtonClicked(); } }); findViewById(R.id.bSavePageFragment).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //toggleTools(); floatMenu.collapse(); if (!wv.getInjected()) Toast.makeText(ctx, getString(R.string.wait_load), Toast.LENGTH_LONG).show(); clipMode = 2; if (wv.getInjected()/* && !v.isSelected()*/) { wv.setCanClip(true); v.setSelected(true); Toast.makeText(ctx, ctx.getString(R.string.use_longtap), Toast.LENGTH_LONG).show(); } } }); (findViewById(R.id.bSaveFullPage)).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { floatMenu.collapse(); if (wv.getInjected()) { wv.setCanClip(false); wv.saveArticle(); clipMode = 1; progressDialog = ProgressDialog.show(v.getContext(), "Nimbus Clipper", getString(R.string.please_wait), true, false); } else { Toast.makeText(ctx, getString(R.string.wait_load), Toast.LENGTH_LONG).show(); } } }); findViewById(R.id.bTakeScreenshot).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //toggleTools(); floatMenu.collapse(); findViewById(R.id.bSaveFullPage).setVisibility(View.GONE); findViewById(R.id.bSavePageFragment).setVisibility(View.GONE); findViewById(R.id.bTakeScreenshot).setVisibility(View.GONE); if (wv.getInjected()) { wv.setCanClip(false); } findViewById(R.id.bToggleMenu).setVisibility(View.GONE); /*screenCapture(); findViewById(R.id.bToggleMenu).setVisibility(View.VISIBLE);*/ findViewById(R.id.bTakeScreenshot).postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub screenCapture(); findViewById(R.id.bToggleMenu).setVisibility(View.VISIBLE); finish(); } }, 10); //showDialog(DIALOG_CAPTURE); } }); (findViewById(R.id.bDone)).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { { try { wv.setCanClip(false); wv.endSelectionMode(); //findViewById(R.id.bSavePageFragment).setSelected(false); clipMode = 2; wv.endSelectionMode(); String selHtml = clipData.getContent(); if (selHtml.length() > 0) { String ss = selHtml.substring(0, selHtml.indexOf(">") + 1).toLowerCase(); int j = ss.indexOf("<div"); if (j == 0) { j = ss.indexOf("style"); if (j > 0) { int k = ss.indexOf("\"", j + 11); if (k > 0) selHtml = selHtml.replace(selHtml.substring(j, k + 1), ""); } //selHtml="<DIV>"+selHtml.substring(ss.length()); } clipData.setContent(selHtml); clipData.setTitle(wv.getTitle()); /*if (true){ if(sessionId.length() == 0 || userPass.length()==0) showSettings(); else { if(prefs.getBoolean("check_fast", false)){ sendNote(wv.getTitle(), clipData.getContent(), parent, tag); clipData.setContent(""); } else { //serverHelper.getInstance().setCallback(this,this); if(appSettings.sessionId.length()>0) { serverHelper.getInstance().sendRequest("notes:getFolders", "",""); } } } wv.endSelectionMode(); } */ Intent i = new Intent(getApplicationContext(), previewActivity.class); i.putExtra("content", clipData); startActivityForResult(i, 5); //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up ); overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out); } //clipData.setContent(""); } catch (Exception e) { BugReporter.Send("onEndSelection", e.getMessage()); } } //showDialog(DIALOG_CAPTURE); } }); findViewById(R.id.bZoomIn).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { wv.ZoomInSelection(); } }); findViewById(R.id.bZoomOut).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { wv.ZoomOutSelection(); } }); setNavButtonState(NavButtonState.NBS_GO); progressBar = (ProgressBar) findViewById(R.id.progressbar); //CookieSyncManager.createInstance(this); //webSettings.setLoadsImagesAutomatically(imgOn); userMail = prefs.getString("userMail", ""); userPass = prefs.getString("userPass", ""); sessionId = prefs.getString("sessionId", ""); appSettings.sessionId = sessionId; appSettings.userMail = userMail; appSettings.userPass = userPass; if ("1".equals(prefs.getString("userAgent", "1"))) { wv.setUserAgent(null); } else wv.setUserAgent(deskAgent); final Activity activity = this; //lastUrl="file:///android_asset/android.html"; if (lastUrl.length() > 0) { //wv.navigate(lastUrl); //if(!urlField.getText().toString().equals(wv.getUrl())) urlField.setText(lastUrl); openURL(); } isInitNow = false; urlField.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { // TODO Auto-generated method stub /*String item = (String)parent.getItemAtPosition(position); Toast.makeText( getApplicationContext(), " " + item, Toast.LENGTH_SHORT).show();*/ openURL(); } }); urlField.addTextChangedListener(this); parent = prefs.getString("remFolderId", "default"); /*ListView listView = (ListView) findViewById(R.id.left_drawer); listView.setAdapter(new DrawerMenuAdapter(this,getResources().getStringArray(R.array.lmenu_browser))); listView.setOnItemClickListener(this);*/ }
From source file:net.peterkuterna.android.apps.devoxxfrsched.service.CfpSyncService.java
@Override protected void doSync(Intent intent) throws Exception { Log.d(TAG, "Start sync"); final Context context = this; final SharedPreferences settings = Prefs.get(context); final int localVersion = settings.getInt(DevoxxPrefs.CFP_LOCAL_VERSION, VERSION_NONE); final long startLocal = System.currentTimeMillis(); final boolean localParse = localVersion < VERSION_CURRENT; Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_CURRENT=" + VERSION_CURRENT); if (localParse) { // Parse values from local cache first mLocalExecutor.execute(R.xml.search_suggest, new SearchSuggestHandler()); mLocalExecutor.execute(R.xml.rooms, new RoomsHandler()); mLocalExecutor.execute(R.xml.tracks, new TracksHandler()); mLocalExecutor.execute(R.xml.presentationtypes, new SessionTypesHandler()); mLocalExecutor.execute(context, "cache-speakers.json", new SpeakersHandler()); mLocalExecutor.execute(context, "cache-presentations.json", new SessionsHandler()); mLocalExecutor.execute(context, "cache-schedule.json", new ScheduleHandler()); // Save local parsed version settings.edit().putInt(DevoxxPrefs.CFP_LOCAL_VERSION, VERSION_CURRENT).commit(); final ContentValues values = new ContentValues(); values.put(Sessions.SESSION_NEW, 0); getContentResolver().update(Sessions.CONTENT_NEW_URI, values, null, null); }//from w ww . j av a2s . c om Log.d(TAG, "Local sync took " + (System.currentTimeMillis() - startLocal) + "ms"); final CfpSyncManager syncManager = new CfpSyncManager(context); if (syncManager.shouldPerformRemoteSync(Intent.ACTION_SYNC.equals(intent.getAction()))) { Log.d(TAG, "Should perform remote sync"); final long startRemote = System.currentTimeMillis(); Editor prefsEditor = syncManager.hasRemoteContentChanged(mHttpClient); if (prefsEditor != null) { Log.d(TAG, "Remote content was changed"); mRemoteExecutor.executeGet(SPEAKERS_URL, new SpeakersHandler()); mRemoteExecutor.executeGet(PRESENTATIONS_URL, new SessionsHandler()); mRemoteExecutor.executeGet(SCHEDULE_URL, new ScheduleHandler()); prefsEditor.commit(); } Log.d(TAG, "Remote sync took " + (System.currentTimeMillis() - startRemote) + "ms"); } else { Log.d(TAG, "Should not perform remote sync"); } final CfpDatabase database = new CfpDatabase(this); database.cleanupLinkTables(); if (!localParse) { final NotifierManager notifierManager = new NotifierManager(this); notifierManager.notifyNewSessions(); } Log.d(TAG, "Sync finished"); }
From source file:com.xorcode.andtweet.AndTweetService.java
@Override public IBinder onBind(Intent intent) { // Select the interface to return. If your service only implements // a single interface, you can just return it here without checking // the Intent. if (IAndTweetService.class.getName().equals(intent.getAction())) { return mBinder; }//from w w w. ja v a 2 s.c om return null; }
From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java
/** * *///from w w w .j a v a2 s. c om @Override public void onCreate(final Bundle savedInstanceState) { //Log.i("MAIN ACTIVITY", "onCreate"); restoreInstance(savedInstanceState); super.onCreate(savedInstanceState); NetworkInfoCollector.init(this); networkInfoCollector = NetworkInfoCollector.getInstance(); preferencesUpdate(); setContentView(R.layout.main_with_navigation_drawer); if (VIEW_HIERARCHY_SERVER_ENABLED) { ViewServer.get(this).addWindow(this); } ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE); actionBar.setDisplayUseLogoEnabled(true); // initialize the navigation drawer with the main menu list adapter: String[] mainTitles = getResources().getStringArray(R.array.navigation_main_titles); int[] navIcons = new int[] { R.drawable.ic_action_home, R.drawable.ic_action_history, R.drawable.ic_action_map, R.drawable.ic_action_stat, R.drawable.ic_action_help, R.drawable.ic_action_about, R.drawable.ic_action_settings, R.drawable.ic_action_about }; MainMenuListAdapter mainMenuAdapter = new MainMenuListAdapter(this, mainTitles, navIcons); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerList = (ListView) findViewById(R.id.left_drawer); drawerLayout.setBackgroundResource(R.drawable.ic_drawer); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.page_title_title_page, R.string.page_title_title_page) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); //refreshActionBar(null); exitAfterDrawerClose = false; } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); } }; drawerLayout.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (KeyEvent.KEYCODE_BACK == event.getKeyCode() && exitAfterDrawerClose) { onBackPressed(); return true; } return false; } }); drawerLayout.setDrawerListener(drawerToggle); drawerList.setAdapter(mainMenuAdapter); drawerList.setOnItemClickListener(new OnItemClickListener() { final int[] menuIds = new int[] { R.id.action_title_page, R.id.action_history, R.id.action_map, R.id.action_stats, R.id.action_help, R.id.action_info, R.id.action_settings, R.id.action_netstat, R.id.action_log }; @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { selectMenuItem(menuIds[position]); drawerLayout.closeDrawers(); } }); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); // Do something against banding effect in gradients // Dither flag might mess up on certain devices?? final Window window = getWindow(); window.setFormat(PixelFormat.RGBA_8888); window.addFlags(WindowManager.LayoutParams.FLAG_DITHER); // Setzt Default-Werte, wenn noch keine Werte vorhanden PreferenceManager.setDefaultValues(this, R.xml.preferences, false); final String uuid = ConfigHelper.getUUID(getApplicationContext()); fm = getFragmentManager(); final Fragment fragment = fm.findFragmentById(R.id.fragment_content); if (!ConfigHelper.isTCAccepted(this)) { if (fragment != null && fm.getBackStackEntryCount() >= 1) // clear fragment back stack fm.popBackStack(fm.getBackStackEntryAt(0).getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE); getActionBar().hide(); setLockNavigationDrawer(true); showTermsCheck(); } else { currentMapOptions.put("highlight", uuid); if (fragment == null) { if (false) // deactivated for si // ! ConfigHelper.isNDTDecisionMade(this)) { showTermsCheck(); showNdtCheck(); } else initApp(true); } } geoLocation = new MainGeoLocation(getApplicationContext()); mNetworkStateChangedFilter = new IntentFilter(); mNetworkStateChangedFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); mNetworkStateIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(final Context context, final Intent intent) { if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { final boolean connected = !intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); final boolean isFailover = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false); if (connected) { if (networkInfoCollector != null) { networkInfoCollector.setHasConnectionFromAndroidApi(true); } } else { if (networkInfoCollector != null) { networkInfoCollector.setHasConnectionFromAndroidApi(false); } } Log.i(DEBUG_TAG, "CONNECTED: " + connected + " FAILOVER: " + isFailover); } } }; }
From source file:net.peterkuterna.android.apps.devoxxsched.service.CfpSyncService.java
@Override protected void doSync(Intent intent) throws Exception { Log.d(TAG, "Start sync"); Thread.sleep(5000);//from w w w. ja v a 2s . c om final Context context = this; final SharedPreferences settings = Prefs.get(context); final int localVersion = settings.getInt(DevoxxPrefs.CFP_LOCAL_VERSION, VERSION_NONE); final long startLocal = System.currentTimeMillis(); final boolean localParse = localVersion < VERSION_CURRENT; Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_CURRENT=" + VERSION_CURRENT); if (localParse) { // Parse values from local cache first mLocalExecutor.execute(R.xml.search_suggest, new SearchSuggestHandler()); mLocalExecutor.execute(R.xml.rooms, new RoomsHandler()); mLocalExecutor.execute(R.xml.tracks, new TracksHandler()); mLocalExecutor.execute(R.xml.presentationtypes, new SessionTypesHandler()); mLocalExecutor.execute(context, "cache-speakers.json", new SpeakersHandler()); mLocalExecutor.execute(context, "cache-presentations.json", new SessionsHandler()); mLocalExecutor.execute(context, "cache-schedule.json", new ScheduleHandler()); mLocalExecutor.execute(context, "cache-parleys-presentations.json", new ParleysPresentationsHandler()); // Save local parsed version settings.edit().putInt(DevoxxPrefs.CFP_LOCAL_VERSION, VERSION_CURRENT).commit(); final ContentValues values = new ContentValues(); values.put(Sessions.SESSION_NEW, 0); getContentResolver().update(Sessions.CONTENT_NEW_URI, values, null, null); } Log.d(TAG, "Local sync took " + (System.currentTimeMillis() - startLocal) + "ms"); final CfpSyncManager syncManager = new CfpSyncManager(context); if (syncManager.shouldPerformRemoteSync(Intent.ACTION_SYNC.equals(intent.getAction()))) { Log.d(TAG, "Should perform remote sync"); final long startRemote = System.currentTimeMillis(); Editor prefsEditor = syncManager.hasRemoteContentChanged(mHttpClient); if (prefsEditor != null) { Log.d(TAG, "Remote content was changed"); mRemoteExecutor.executeGet(SPEAKERS_URL, new SpeakersHandler()); mRemoteExecutor.executeGet(PRESENTATIONS_URL, new SessionsHandler()); mRemoteExecutor.executeGet(SCHEDULE_URL, new ScheduleHandler()); prefsEditor.commit(); } Log.d(TAG, "Remote sync took " + (System.currentTimeMillis() - startRemote) + "ms"); } else { Log.d(TAG, "Should not perform remote sync"); } final CfpDatabase database = new CfpDatabase(this); database.cleanupLinkTables(); final NotifierManager notifierManager = new NotifierManager(this); notifierManager.notifyNewSessions(); Log.d(TAG, "Sync finished"); }
From source file:com.ichi2.anki.DeckPicker.java
/** * Show a message when the SD card is ejected *///w w w. jav a 2 s . c om private void registerExternalStorageListener() { if (mUnmountReceiver == null) { mUnmountReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(SdCardReceiver.MEDIA_EJECT)) { onSdCardNotMounted(); } else if (intent.getAction().equals(SdCardReceiver.MEDIA_MOUNT)) { restartActivity(); } } }; IntentFilter iFilter = new IntentFilter(); iFilter.addAction(SdCardReceiver.MEDIA_EJECT); iFilter.addAction(SdCardReceiver.MEDIA_MOUNT); registerReceiver(mUnmountReceiver, iFilter); } }
From source file:com.hichinaschool.flashcards.anki.CardEditor.java
@Override protected void onCreate(Bundle savedInstanceState) { // Log.i(AnkiDroidApp.TAG, "CardEditor: onCreate"); Themes.applyTheme(this); super.onCreate(savedInstanceState); this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); Intent intent = getIntent(); if (savedInstanceState != null) { mCaller = savedInstanceState.getInt("caller"); mAddNote = savedInstanceState.getBoolean("addFact"); } else {/*from w ww. j ava 2 s. c om*/ mCaller = intent.getIntExtra(EXTRA_CALLER, CALLER_NOCALLER); if (mCaller == CALLER_NOCALLER) { String action = intent.getAction(); if (action != null && (ACTION_CREATE_FLASHCARD.equals(action) || ACTION_CREATE_FLASHCARD_SEND.equals(action))) { mCaller = CALLER_INDICLASH; } } } // Log.i(AnkiDroidApp.TAG, "CardEditor: caller: " + mCaller); SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext()); if (mCaller == CALLER_INDICLASH && preferences.getBoolean("intentAdditionInstantAdd", false)) { // save information without showing card editor fetchIntentInformation(intent); MetaDB.saveIntentInformation(CardEditor.this, Utils.joinFields(mSourceText)); Themes.showThemedToast(CardEditor.this, getResources().getString(R.string.app_name) + ": " + getResources().getString(R.string.CardEditorLaterMessage), false); finish(); return; } mCol = AnkiDroidApp.getCol(); if (mCol == null) { reloadCollection(savedInstanceState); return; } registerExternalStorageListener(); View mainView = getLayoutInflater().inflate(R.layout.card_editor, null); setContentView(mainView); Themes.setWallpaper(mainView); Themes.setContentStyle(mainView, Themes.CALLER_CARD_EDITOR); mFieldsLayoutContainer = (LinearLayout) findViewById(R.id.CardEditorEditFieldsLayout); mSave = (Button) findViewById(R.id.CardEditorSaveButton); mCancel = (Button) findViewById(R.id.CardEditorCancelButton); mLater = (Button) findViewById(R.id.CardEditorLaterButton); mDeckButton = (TextView) findViewById(R.id.CardEditorDeckText); mModelButton = (TextView) findViewById(R.id.CardEditorModelText); mTagsButton = (TextView) findViewById(R.id.CardEditorTagText); mSwapButton = (Button) findViewById(R.id.CardEditorSwapButton); mSwapButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { swapText(false); } }); mAedictIntent = false; switch (mCaller) { case CALLER_NOCALLER: // Log.i(AnkiDroidApp.TAG, "CardEditor: no caller could be identified, closing"); finish(); return; case CALLER_REVIEWER: mCurrentEditedCard = Reviewer.getEditorCard(); if (mCurrentEditedCard == null) { finish(); return; } mEditorNote = mCurrentEditedCard.note(); mAddNote = false; break; case CALLER_STUDYOPTIONS: case CALLER_DECKPICKER: mAddNote = true; break; case CALLER_BIGWIDGET_EDIT: // Card widgetCard = AnkiDroidWidgetBig.getCard(); // if (widgetCard == null) { // finish(); // return; // } // mEditorNote = widgetCard.getFact(); // mAddNote = false; break; case CALLER_BIGWIDGET_ADD: mAddNote = true; break; case CALLER_CARDBROWSER_EDIT: mCurrentEditedCard = CardBrowser.sCardBrowserCard; if (mCurrentEditedCard == null) { finish(); return; } mEditorNote = mCurrentEditedCard.note(); mAddNote = false; break; case CALLER_CARDBROWSER_ADD: mAddNote = true; break; case CALLER_CARDEDITOR: mAddNote = true; break; case CALLER_CARDEDITOR_INTENT_ADD: mAddNote = true; break; case CALLER_INDICLASH: fetchIntentInformation(intent); if (mSourceText == null) { finish(); return; } if (mSourceText[0].equals("Aedict Notepad") && addFromAedict(mSourceText[1])) { finish(); return; } mAddNote = true; break; } setNote(mEditorNote); if (mAddNote) { setTitle(R.string.cardeditor_title_add_note); // set information transferred by intent String contents = null; if (mSourceText != null) { if (mAedictIntent && (mEditFields.size() == 3) && mSourceText[1].contains("[")) { contents = mSourceText[1].replaceFirst("\\[", "\u001f"); contents = contents.substring(0, contents.length() - 1); } else { mEditFields.get(0).setText(mSourceText[0]); mEditFields.get(1).setText(mSourceText[1]); } } else { contents = intent.getStringExtra(EXTRA_CONTENTS); } if (contents != null) { setEditFieldTexts(contents); } LinearLayout modelButton = ((LinearLayout) findViewById(R.id.CardEditorModelButton)); modelButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showDialog(DIALOG_MODEL_SELECT); } }); modelButton.setVisibility(View.VISIBLE); mSave.setText(getResources().getString(R.string.add)); mCancel.setText(getResources().getString(R.string.close)); mLater.setVisibility(View.VISIBLE); mLater.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String content = getFieldsText(); if (content.length() > mEditFields.size() - 1) { MetaDB.saveIntentInformation(CardEditor.this, content); populateEditFields(); mSourceText = null; Themes.showThemedToast(CardEditor.this, getResources().getString(R.string.CardEditorLaterMessage), false); } if (mCaller == CALLER_INDICLASH || mCaller == CALLER_CARDEDITOR_INTENT_ADD) { closeCardEditor(); } } }); } else { setTitle(R.string.cardeditor_title_edit_card); mSwapButton.setVisibility(View.GONE); mSwapButton = (Button) findViewById(R.id.CardEditorLaterButton); mSwapButton.setVisibility(View.VISIBLE); mSwapButton.setText(getResources().getString(R.string.fact_adder_swap)); mSwapButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { swapText(false); } }); } ((LinearLayout) findViewById(R.id.CardEditorDeckButton)).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showDialog(DIALOG_DECK_SELECT); } }); mPrefFixArabic = preferences.getBoolean("fixArabicText", false); // if Arabic reshaping is enabled, disable the Save button to avoid // saving the reshaped string to the deck if (mPrefFixArabic && !mAddNote) { mSave.setEnabled(false); } ((LinearLayout) findViewById(R.id.CardEditorTagButton)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showDialog(DIALOG_TAGS_SELECT); } }); mSave.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (duplicateCheck(true)) { return; } boolean modified = false; for (FieldEditText f : mEditFields) { modified = modified | f.updateField(); } if (mAddNote) { DeckTask.launchDeckTask(DeckTask.TASK_TYPE_ADD_FACT, mSaveFactHandler, new DeckTask.TaskData(mEditorNote)); } else { // added tag? for (String t : mCurrentTags) { modified = modified || !mEditorNote.hasTag(t); } // removed tag? modified = modified || mEditorNote.getTags().size() > mCurrentTags.size(); // changed did? boolean changedDid = mCurrentEditedCard.getDid() != mCurrentDid; modified = modified || changedDid; if (modified) { mEditorNote.setTags(mCurrentTags); // set did for card if (changedDid) { mCurrentEditedCard.setDid(mCurrentDid); } mChanged = true; } closeCardEditor(); // if (mCaller == CALLER_BIGWIDGET_EDIT) { // // DeckTask.launchDeckTask(DeckTask.TASK_TYPE_UPDATE_FACT, // // mSaveFactHandler, new // // DeckTask.TaskData(Reviewer.UPDATE_CARD_SHOW_QUESTION, // // mDeck, AnkiDroidWidgetBig.getCard())); // } else if (!mCardReset) { // // Only send result to save if something was actually // // changed // if (mModified) { // setResult(RESULT_OK); // } else { // setResult(RESULT_CANCELED); // } // closeCardEditor(); // } } } }); mCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { closeCardEditor(); } }); }