List of usage examples for android.nfc NdefMessage NdefMessage
public NdefMessage(NdefRecord[] records)
From source file:org.mozilla.gecko.BrowserApp.java
@Override public void onCreate(Bundle savedInstanceState) { final Intent intent = getIntent(); // Note that we're calling GeckoProfile.get *before GeckoApp.onCreate*. // This means we're reliant on the logic in GeckoProfile to correctly // look up our launch intent (via BrowserApp's Activity-ness) and pull // out the arguments. Be careful if you change that! final GeckoProfile p = GeckoProfile.get(this); if (p != null && !p.inGuestMode()) { // This is *only* valid because we never want to use the guest mode // profile concurrently with a normal profile -- no syncing to it, // no dual-profile usage, nothing. BrowserApp startup with a conventional // GeckoProfile will cause the guest profile to be deleted. GeckoProfile.maybeCleanupGuestProfile(this); }// ww w .j a v a2 s .c o m // This has to be prepared prior to calling GeckoApp.onCreate, because // widget code and BrowserToolbar need it, and they're created by the // layout, which GeckoApp takes care of. ((GeckoApplication) getApplication()).prepareLightweightTheme(); super.onCreate(savedInstanceState); final Context appContext = ((GeckoApplication) getApplication()).getContext(); SharedPreferences prefs = GeckoSharedPrefs.forProfile(appContext); // TODO: Prevent if in Guest Mode? if (AppConstants.MOZ_ANDROID_GCM_PUSH) { this.gcmBridge = new GCM(AppConstants.MOZ_ANDROID_GCM_SENDERID); try { this.gcmBridge.onCreate(appContext, getActivity(), savedInstanceState); // A thread has been spawned to put the push endpoint into the preferences. } catch (IOException x) { // could not instantiate the GCM bridge, so fail. Logger.info(LOGTAG, "Google Play not present or available. GCM bridge unavailable."); this.gcmBridge = null; } catch (BridgeException x) { // Some other error caused the bridge to fail. Logger.error(LOGTAG, "Could not create the GCM bridge.", x); this.gcmBridge = null; } /* At this point, we have a GCM endpoint registered with the Push Service, but we need the user to log in so that we can associate the URL and user within the Device Manager. See */ } mBrowserChrome = (ViewGroup) findViewById(R.id.browser_chrome); mActionBarFlipper = (ViewFlipper) findViewById(R.id.browser_actionbar); mActionBar = (ActionModeCompatView) findViewById(R.id.actionbar); mBrowserToolbar = (BrowserToolbar) findViewById(R.id.browser_toolbar); mProgressView = (ToolbarProgressView) findViewById(R.id.progress); mBrowserToolbar.setProgressBar(mProgressView); // Initialize Tab History Controller. tabHistoryController = new TabHistoryController(new OnShowTabHistory() { @Override public void onShowHistory(final List<TabHistoryPage> historyPageList, final int toIndex) { runOnUiThread(new Runnable() { @Override public void run() { final TabHistoryFragment fragment = TabHistoryFragment.newInstance(historyPageList, toIndex); final FragmentManager fragmentManager = getSupportFragmentManager(); GeckoAppShell.vibrateOnHapticFeedbackEnabled( getResources().getIntArray(R.array.long_press_vibrate_msec)); fragment.show(R.id.tab_history_panel, fragmentManager.beginTransaction(), TAB_HISTORY_FRAGMENT_TAG); } }); } }); mBrowserToolbar.setTabHistoryController(tabHistoryController); final String action = intent.getAction(); if (Intent.ACTION_VIEW.equals(action)) { // Show the target URL immediately in the toolbar. mBrowserToolbar.setTitle(intent.getDataString()); showTabQueuePromptIfApplicable(intent); } else if (GuestSession.NOTIFICATION_INTENT.equals(action)) { GuestSession.handleIntent(this, intent); } else if (TabQueueHelper.LOAD_URLS_ACTION.equals(action)) { Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.NOTIFICATION, "tabqueue"); } if (HardwareUtils.isTablet()) { mTabStrip = (Refreshable) (((ViewStub) findViewById(R.id.new_tablet_tab_strip)).inflate()); } ((GeckoApp.MainLayout) mMainLayout).setTouchEventInterceptor(new HideOnTouchListener()); ((GeckoApp.MainLayout) mMainLayout).setMotionEventInterceptor(new MotionEventInterceptor() { @Override public boolean onInterceptMotionEvent(View view, MotionEvent event) { // If we get a gamepad panning MotionEvent while the focus is not on the layerview, // put the focus on the layerview and carry on if (mLayerView != null && !mLayerView.hasFocus() && GamepadUtils.isPanningControl(event)) { if (mHomePager == null) { return false; } if (isHomePagerVisible()) { mLayerView.requestFocus(); } else { mHomePager.requestFocus(); } } return false; } }); mHomePagerContainer = (ViewGroup) findViewById(R.id.home_pager_container); mBrowserSearchContainer = findViewById(R.id.search_container); mBrowserSearch = (BrowserSearch) getSupportFragmentManager().findFragmentByTag(BROWSER_SEARCH_TAG); if (mBrowserSearch == null) { mBrowserSearch = BrowserSearch.newInstance(); mBrowserSearch.setUserVisibleHint(false); } setBrowserToolbarListeners(); mFindInPageBar = (FindInPageBar) findViewById(R.id.find_in_page); mMediaCastingBar = (MediaCastingBar) findViewById(R.id.media_casting); EventDispatcher.getInstance().registerGeckoThreadListener((GeckoEventListener) this, "Menu:Open", "Menu:Update", "LightweightTheme:Update", "Search:Keyword", "Prompt:ShowTop", "Accounts:Exist"); EventDispatcher.getInstance().registerGeckoThreadListener((NativeEventListener) this, "Accounts:Create", "Accounts:CreateFirefoxAccountFromJSON", "CharEncoding:Data", "CharEncoding:State", "Favicon:CacheLoad", "Feedback:LastUrl", "Feedback:MaybeLater", "Feedback:OpenPlayStore", "Menu:Add", "Menu:Remove", "Reader:Share", "Sanitize:ClearHistory", "Sanitize:ClearSyncedTabs", "Settings:Show", "Telemetry:Gather", "Updater:Launch"); Distribution distribution = Distribution.init(this); // Init suggested sites engine in BrowserDB. final SuggestedSites suggestedSites = new SuggestedSites(appContext, distribution); final BrowserDB db = getProfile().getDB(); db.setSuggestedSites(suggestedSites); JavaAddonManager.getInstance().init(appContext); mSharedPreferencesHelper = new SharedPreferencesHelper(appContext); mOrderedBroadcastHelper = new OrderedBroadcastHelper(appContext); mBrowserHealthReporter = new BrowserHealthReporter(); mReadingListHelper = new ReadingListHelper(appContext, getProfile(), this); if (AppConstants.MOZ_ANDROID_BEAM) { NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this); if (nfc != null) { nfc.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() { @Override public NdefMessage createNdefMessage(NfcEvent event) { Tab tab = Tabs.getInstance().getSelectedTab(); if (tab == null || tab.isPrivate()) { return null; } return new NdefMessage(new NdefRecord[] { NdefRecord.createUri(tab.getURL()) }); } }, this); } } if (savedInstanceState != null) { mDynamicToolbar.onRestoreInstanceState(savedInstanceState); mHomePagerContainer.setPadding(0, savedInstanceState.getInt(STATE_ABOUT_HOME_TOP_PADDING), 0, 0); } mDynamicToolbar.setEnabledChangedListener(new DynamicToolbar.OnEnabledChangedListener() { @Override public void onEnabledChanged(boolean enabled) { setDynamicToolbarEnabled(enabled); } }); mDragHelper = new DragHelper(); mRootLayout.setDraggableCallback(mDragHelper); // Set the maximum bits-per-pixel the favicon system cares about. IconDirectoryEntry.setMaxBPP(GeckoAppShell.getScreenDepth()); if (ZOOMED_VIEW_ENABLED) { ViewStub stub = (ViewStub) findViewById(R.id.zoomed_view_stub); mZoomedView = (ZoomedView) stub.inflate(); } }
From source file:com.irccloud.android.activity.MainActivity.java
@Override public void onBufferSelected(int bid) { launchBid = -1;/*from w ww . j a v a 2 s . c om*/ launchURI = null; cidToOpen = -1; bufferToOpen = null; setIntent(new Intent(this, MainActivity.class)); if (suggestionsTimerTask != null) suggestionsTimerTask.cancel(); sortedChannels = null; sortedUsers = null; if (drawerLayout != null) { drawerLayout.closeDrawers(); } if (bid != -1 && conn != null && conn.getUserInfo() != null) { conn.getUserInfo().last_selected_bid = bid; } for (int i = 0; i < backStack.size(); i++) { if (buffer != null && backStack.get(i) == buffer.bid) backStack.remove(i); } if (buffer != null && buffer.bid >= 0 && bid != buffer.bid) { backStack.add(0, buffer.bid); buffer.draft = messageTxt.getText().toString(); } if (buffer == null || buffer.bid == -1 || buffer.cid == -1 || buffer.bid == bid) shouldFadeIn = false; else shouldFadeIn = true; buffer = BuffersDataSource.getInstance().getBuffer(bid); if (buffer != null) { Crashlytics.log(Log.DEBUG, "IRCCloud", "Buffer selected: cid" + buffer.cid + " bid" + bid + " shouldFadeIn: " + shouldFadeIn); server = ServersDataSource.getInstance().getServer(buffer.cid); try { TreeMap<Long, EventsDataSource.Event> events = EventsDataSource.getInstance() .getEventsForBuffer(buffer.bid); if (events != null) { events = (TreeMap<Long, EventsDataSource.Event>) events.clone(); for (EventsDataSource.Event e : events.values()) { if (e != null && e.highlight && e.from != null) { UsersDataSource.User u = UsersDataSource.getInstance().getUser(buffer.bid, e.from); if (u != null && u.last_mention < e.eid) u.last_mention = e.eid; } } } } catch (Exception e) { Crashlytics.logException(e); } try { if (Build.VERSION.SDK_INT >= 16 && buffer != null && server != null) { NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this); if (nfc != null) { String uri = "irc"; if (server.ssl > 0) uri += "s"; uri += "://" + server.hostname + ":" + server.port; if (buffer.type.equals("channel")) { uri += "/" + URLEncoder.encode(buffer.name, "UTF-8"); ChannelsDataSource.Channel c = ChannelsDataSource.getInstance() .getChannelForBuffer(buffer.bid); if (c != null && c.hasMode("k")) uri += "," + c.paramForMode("k"); } nfc.setNdefPushMessage(new NdefMessage(NdefRecord.createUri(uri)), this); } } } catch (Exception e) { } } else { Crashlytics.log(Log.DEBUG, "IRCCloud", "Buffer selected but not found: bid" + bid + " shouldFadeIn: " + shouldFadeIn); server = null; } update_subtitle(); final Bundle b = new Bundle(); if (buffer != null) b.putInt("cid", buffer.cid); b.putInt("bid", bid); b.putBoolean("fade", shouldFadeIn); BuffersListFragment blf = (BuffersListFragment) getSupportFragmentManager() .findFragmentById(R.id.BuffersList); final MessageViewFragment mvf = (MessageViewFragment) getSupportFragmentManager() .findFragmentById(R.id.messageViewFragment); UsersListFragment ulf = (UsersListFragment) getSupportFragmentManager() .findFragmentById(R.id.usersListFragment); UsersListFragment ulf2 = (UsersListFragment) getSupportFragmentManager() .findFragmentById(R.id.usersListFragment2); if (mvf != null) mvf.ready = false; if (blf != null) blf.setSelectedBid(bid); if (ulf != null) ulf.setArguments(b); if (ulf2 != null) ulf2.setArguments(b); if (shouldFadeIn) { Crashlytics.log(Log.DEBUG, "IRCCloud", "Fade Out"); if (Build.VERSION.SDK_INT < 16) { AlphaAnimation anim = new AlphaAnimation(1, 0); anim.setDuration(150); anim.setFillAfter(true); anim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { if (mvf != null) mvf.setArguments(b); messageTxt.setText(""); if (buffer != null && buffer.draft != null) messageTxt.append(buffer.draft); } @Override public void onAnimationRepeat(Animation animation) { } }); try { mvf.getListView().startAnimation(anim); ulf.getListView().startAnimation(anim); } catch (Exception e) { } } else { mvf.getListView().animate().alpha(0).withEndAction(new Runnable() { @Override public void run() { if (mvf != null) mvf.setArguments(b); messageTxt.setText(""); if (buffer != null && buffer.draft != null) messageTxt.append(buffer.draft); } }); ulf.getListView().animate().alpha(0); } mvf.showSpinner(true); } else { if (mvf != null) mvf.setArguments(b); messageTxt.setText(""); if (buffer != null && buffer.draft != null) messageTxt.append(buffer.draft); } updateUsersListFragmentVisibility(); supportInvalidateOptionsMenu(); if (excludeBIDTask != null) excludeBIDTask.cancel(true); excludeBIDTask = new ExcludeBIDTask(); excludeBIDTask.execute(bid); if (drawerLayout != null) new RefreshUpIndicatorTask().execute((Void) null); if (buffer != null && buffer.cid != -1) { if (drawerLayout != null) { drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.LEFT); getSupportActionBar().setHomeButtonEnabled(true); } } update_suggestions(false); }