List of usage examples for android.nfc NdefRecord createUri
public static NdefRecord createUri(String uriString)
Use this method to encode a URI (or URL) into an NDEF Record.
Uses the well known URI type representation: #TNF_WELL_KNOWN and #RTD_URI .
From source file:org.bohrmeista.chan.ui.activity.BaseActivity.java
/** * Set the url that Android Beam and the share action will send. * * @param url//w w w . j av a 2 s. com */ public void setShareUrl(String url) { shareUrl = url; NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); if (adapter != null) { NdefRecord record = null; try { record = NdefRecord.createUri(url); } catch (IllegalArgumentException e) { e.printStackTrace(); return; } NdefMessage message = new NdefMessage(new NdefRecord[] { record }); try { adapter.setNdefPushMessage(message, this); } catch (Exception e) { } } Intent share = new Intent(android.content.Intent.ACTION_SEND); share.putExtra(android.content.Intent.EXTRA_TEXT, url); share.setType("text/plain"); if (shareActionProvider != null) { shareActionProvider.setShareIntent(share); } else { pendingShareActionProviderIntent = share; } }
From source file:org.mariotaku.twidere.fragment.support.StatusFragment.java
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final View view = getView(); if (view == null) throw new AssertionError(); final Context context = view.getContext(); final boolean compact = Utils.isCompactCards(context); Utils.setNdefPushMessageCallback(getActivity(), new CreateNdefMessageCallback() { @Override/* w w w .ja va2s . co m*/ public NdefMessage createNdefMessage(NfcEvent event) { final ParcelableStatus status = getStatus(); if (status == null) return null; return new NdefMessage(new NdefRecord[] { NdefRecord .createUri(LinkCreator.getTwitterStatusLink(status.user_screen_name, status.id)), }); } }); mLayoutManager = new StatusListLinearLayoutManager(context, mRecyclerView); mItemDecoration = new DividerItemDecoration(context, mLayoutManager.getOrientation()); if (compact) { mRecyclerView.addItemDecoration(mItemDecoration); } mLayoutManager.setRecycleChildrenOnDetach(true); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setClipToPadding(false); mStatusAdapter = new StatusAdapter(this, compact); mStatusAdapter.setEventListener(this); mRecyclerView.setAdapter(mStatusAdapter); mRecyclerViewNavigationHelper = new RecyclerViewNavigationHelper(mRecyclerView, mLayoutManager, mStatusAdapter, null); setState(STATE_LOADING); getLoaderManager().initLoader(LOADER_ID_DETAIL_STATUS, getArguments(), this); }
From source file:org.getlantern.firetweet.fragment.support.UserListFragment.java
@Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setHasOptionsMenu(true);/* ww w . j a v a 2s .c o m*/ final FragmentActivity activity = getActivity(); Utils.setNdefPushMessageCallback(activity, new CreateNdefMessageCallback() { @Override public NdefMessage createNdefMessage(NfcEvent event) { final ParcelableUserList userList = getUserList(); if (userList == null) return null; return new NdefMessage(new NdefRecord[] { NdefRecord.createUri( LinkCreator.getTwitterUserListLink(userList.user_screen_name, userList.name)), }); } }); mHeaderDrawerLayout.setDrawerCallback(this); mPagerAdapter = new SupportTabsAdapter(activity, getChildFragmentManager()); mViewPager.setAdapter(mPagerAdapter); mPagerIndicator.setViewPager(mViewPager); mPagerIndicator.setTabDisplayOption(TabPagerIndicator.LABEL); if (activity instanceof IThemedActivity) { mPagerIndicator.setStripColor(((IThemedActivity) activity).getCurrentThemeColor()); } else { } mTwitterWrapper = getApplication().getTwitterWrapper(); mProfileImageLoader = getApplication().getMediaLoaderWrapper(); mProfileImageView.setOnClickListener(this); mUserListDetails.setOnClickListener(this); mRetryButton.setOnClickListener(this); getUserListInfo(false); setupUserPages(); }
From source file:org.getlantern.firetweet.fragment.support.StatusFragment.java
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final View view = getView(); if (view == null) throw new AssertionError(); final Context context = view.getContext(); final boolean compact = Utils.isCompactCards(context); Utils.setNdefPushMessageCallback(getActivity(), new CreateNdefMessageCallback() { @Override/*ww w. j a v a 2 s . c o m*/ public NdefMessage createNdefMessage(NfcEvent event) { final ParcelableStatus status = getStatus(); if (status == null) return null; return new NdefMessage(new NdefRecord[] { NdefRecord .createUri(LinkCreator.getTwitterStatusLink(status.user_screen_name, status.id)), }); } }); mLayoutManager = new StatusListLinearLayoutManager(context, mRecyclerView); mItemDecoration = new DividerItemDecoration(context, mLayoutManager.getOrientation()); if (compact) { mRecyclerView.addItemDecoration(mItemDecoration); } mLayoutManager.setRecycleChildrenOnDetach(true); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setClipToPadding(false); mStatusAdapter = new StatusAdapter(this, compact); mStatusAdapter.setEventListener(this); mRecyclerView.setAdapter(mStatusAdapter); setState(STATE_LOADING); getLoaderManager().initLoader(LOADER_ID_DETAIL_STATUS, getArguments(), this); }
From source file:com.irccloud.android.activity.ImageViewerActivity.java
private void loadImage(String urlStr) { try {// w w w. j a v a2 s.c om if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB && urlStr.startsWith("https://")) { GingerbreadImageProxy proxy = new GingerbreadImageProxy(); proxy.init(); proxy.start(); urlStr = String.format("http://127.0.0.1:%d/%s", proxy.getPort(), urlStr); } URL url = new URL(urlStr); mImage.loadDataWithBaseURL(null, "<!DOCTYPE html>\n" + "<html><head><style>html, body, table { height: 100%; width: 100%; background-color: #000;}</style></head>\n" + "<body>\n" + "<table><tr><td>" + "<img src='" + url.toString() + "' width='100%' onerror='Android.imageFailed()' onclick='Android.imageClicked()' style='background-color: #fff;'/>\n" + "</td></tr></table>" + "</body>\n" + "</html>", "text/html", "UTF-8", null); try { if (Build.VERSION.SDK_INT >= 16) { NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this); if (nfc != null) { nfc.setNdefPushMessage(new NdefMessage(NdefRecord.createUri(urlStr)), this); } } } catch (Exception e) { } } catch (Exception e) { fail(); } }
From source file:com.example.multi_ndef.Frag_Write.java
/** * Format a tag and write our NDEF message *//*from w ww. ja v a2s .com*/ //@SuppressLint("NewApi") private boolean writeTag(Tag tag) { // record to launch Play Store if app is not installed NdefRecord appRecord = NdefRecord.createApplicationRecord("com.example.multi_ndef"); try { ENGLISH = Locale.ENGLISH; encodeInUtf8 = true; } catch (Exception e) { Toast toast = Toast.makeText(getApplicationContext(), "Locale Error " + e.toString(), Toast.LENGTH_SHORT); toast.show(); } try { textRecord = createTextRecord(getText(), ENGLISH, encodeInUtf8); } catch (Exception e) { Toast toast = Toast.makeText(getApplicationContext(), "Text Conversion error " + e.toString(), Toast.LENGTH_SHORT); toast.show(); } try { uriRecord = NdefRecord.createUri(getUri()); } catch (Exception e) { Toast toast = Toast.makeText(getApplicationContext(), "Uri Conversion error " + e.toString(), Toast.LENGTH_SHORT); toast.show(); } byte[] mimeBytes = MimeType.AppName.getBytes(Charset.forName("US-ASCII")); byte[] mimeBytesBT = MimeType.AppNameBT.getBytes(Charset.forName("US-ASCII")); byte[] v_data = VCard(); // Here data is written byte[] payload = data(); // payload in hex //Comments by neha - 3 Jul 2014 byte[] payloadBT = btData(); NdefRecord VcardRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, "text/x-vcard".getBytes(), new byte[0], v_data); NdefRecord BTcardRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytesBT, new byte[0], payloadBT); NdefRecord cardRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], payload); NdefRecord SMSRecord = NdefRecord.createUri(SMSpayload); NdefRecord MailRecord = NdefRecord.createUri(Mailpayload); NdefRecord TeleRecord = NdefRecord.createUri(Telepayload); NdefRecord LocationRecord = NdefRecord.createUri(Locationpayload); NdefMessage message = new NdefMessage(new NdefRecord[] { cardRecord, textRecord, uriRecord, BTcardRecord, VcardRecord, SMSRecord, MailRecord, TeleRecord, LocationRecord, appRecord }); // ringProgressDialog.dismiss(); try { // see if tag is already NDEF formatted Ndef ndef = Ndef.get(tag); if (ndef != null) { ndef.connect(); if (!ndef.isWritable()) { displayMessage("Read-only tag."); return false; } // work out how much space we need for the data int size = message.toByteArray().length; if (ndef.getMaxSize() < size) { displayMessage("Tag doesn't have enough free space."); return false; } ndef.writeNdefMessage(message); displayMessage("Multiple NDEF Records written to tag successfully."); return true; } else { // attempt to format tag NdefFormatable format = NdefFormatable.get(tag); if (format != null) { try { format.connect(); format.format(message); displayMessage("Tag written successfully!\nClose this app and scan tag."); return true; } catch (IOException e) { displayMessage("Unable to format tag to NDEF."); return false; } } else { displayMessage("Tag doesn't appear to support NDEF format."); return false; } } } catch (Exception e) { displayMessage("Failed to write tag"); } return false; }
From source file:org.getlantern.firetweet.fragment.support.UserFragment.java
@Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final FragmentActivity activity = getActivity(); setHasOptionsMenu(true);//from w w w . j a v a 2s .c o m getSharedPreferences(USER_COLOR_PREFERENCES_NAME, Context.MODE_PRIVATE) .registerOnSharedPreferenceChangeListener(this); getSharedPreferences(USER_NICKNAME_PREFERENCES_NAME, Context.MODE_PRIVATE) .registerOnSharedPreferenceChangeListener(this); mLocale = getResources().getConfiguration().locale; mCardBackgroundColor = ThemeUtils.getCardBackgroundColor(activity); mProfileImageLoader = getApplication().getMediaLoaderWrapper(); final Bundle args = getArguments(); long accountId = -1, userId = -1; String screenName = null; if (savedInstanceState != null) { args.putAll(savedInstanceState); } else { accountId = args.getLong(EXTRA_ACCOUNT_ID, -1); userId = args.getLong(EXTRA_USER_ID, -1); screenName = args.getString(EXTRA_SCREEN_NAME); } Utils.setNdefPushMessageCallback(activity, new CreateNdefMessageCallback() { @Override public NdefMessage createNdefMessage(NfcEvent event) { final ParcelableUser user = getUser(); if (user == null) return null; return new NdefMessage(new NdefRecord[] { NdefRecord.createUri(LinkCreator.getTwitterUserLink(user.screen_name)), }); } }); activity.setEnterSharedElementCallback(new SharedElementCallback() { @Override public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) { final int idx = sharedElementNames.indexOf(TRANSITION_NAME_PROFILE_IMAGE); if (idx != -1) { final View view = sharedElements.get(idx); int[] location = new int[2]; final RectF bounds = new RectF(0, 0, view.getWidth(), view.getHeight()); view.getLocationOnScreen(location); bounds.offsetTo(location[0], location[1]); mProfileImageView.setTransitionSource(bounds); } super.onSharedElementStart(sharedElementNames, sharedElements, sharedElementSnapshots); } @Override public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) { int idx = sharedElementNames.indexOf(TRANSITION_NAME_PROFILE_IMAGE); if (idx != -1) { final View view = sharedElements.get(idx); int[] location = new int[2]; final RectF bounds = new RectF(0, 0, view.getWidth(), view.getHeight()); view.getLocationOnScreen(location); bounds.offsetTo(location[0], location[1]); mProfileImageView.setTransitionDestination(bounds); } super.onSharedElementEnd(sharedElementNames, sharedElements, sharedElementSnapshots); } }); ViewCompat.setTransitionName(mProfileImageView, TRANSITION_NAME_PROFILE_IMAGE); ViewCompat.setTransitionName(mProfileTypeView, TRANSITION_NAME_PROFILE_TYPE); // ViewCompat.setTransitionName(mCardView, TRANSITION_NAME_CARD); mHeaderDrawerLayout.setDrawerCallback(this); mPagerAdapter = new SupportTabsAdapter(activity, getChildFragmentManager()); mViewPager.setOffscreenPageLimit(3); mViewPager.setAdapter(mPagerAdapter); mPagerIndicator.setViewPager(mViewPager); mPagerIndicator.setTabDisplayOption(TabPagerIndicator.LABEL); mFollowButton.setOnClickListener(this); mProfileImageView.setOnClickListener(this); mProfileBannerView.setOnClickListener(this); mListedContainer.setOnClickListener(this); mFollowersContainer.setOnClickListener(this); mFriendsContainer.setOnClickListener(this); mRetryButton.setOnClickListener(this); mProfileBannerView.setOnSizeChangedListener(this); mProfileBannerSpace.setOnTouchListener(this); mProfileNameBackground.setBackgroundColor(mCardBackgroundColor); mProfileDetailsContainer.setBackgroundColor(mCardBackgroundColor); mPagerIndicator.setBackgroundColor(mCardBackgroundColor); mUuckyFooter.setBackgroundColor(mCardBackgroundColor); getUserInfo(accountId, userId, screenName, false); final float actionBarElevation = ThemeUtils.getSupportActionBarElevation(activity); ViewCompat.setElevation(mPagerIndicator, actionBarElevation); setupBaseActionBar(); setupUserPages(); }
From source file:org.mariotaku.twidere.fragment.support.UserFragment.java
@Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final FragmentActivity activity = getActivity(); setHasOptionsMenu(true);/*from ww w . j a v a 2 s. com*/ getSharedPreferences(USER_COLOR_PREFERENCES_NAME, Context.MODE_PRIVATE) .registerOnSharedPreferenceChangeListener(this); getSharedPreferences(USER_NICKNAME_PREFERENCES_NAME, Context.MODE_PRIVATE) .registerOnSharedPreferenceChangeListener(this); mUserColorNameManager = UserColorNameManager.getInstance(activity); mPreferences = SharedPreferencesWrapper.getInstance(activity, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE, SharedPreferenceConstants.class); mNameFirst = mPreferences.getBoolean(KEY_NAME_FIRST); mLocale = getResources().getConfiguration().locale; mCardBackgroundColor = ThemeUtils.getCardBackgroundColor(activity, ThemeUtils.getThemeBackgroundOption(activity), ThemeUtils.getUserThemeBackgroundAlpha(activity)); mActionBarShadowColor = 0xA0000000; final TwidereApplication app = TwidereApplication.getInstance(activity); mProfileImageLoader = app.getMediaLoaderWrapper(); final Bundle args = getArguments(); long accountId = -1, userId = -1; String screenName = null; if (savedInstanceState != null) { args.putAll(savedInstanceState); } else { accountId = args.getLong(EXTRA_ACCOUNT_ID, -1); userId = args.getLong(EXTRA_USER_ID, -1); screenName = args.getString(EXTRA_SCREEN_NAME); } Utils.setNdefPushMessageCallback(activity, new CreateNdefMessageCallback() { @Override public NdefMessage createNdefMessage(NfcEvent event) { final ParcelableUser user = getUser(); if (user == null) return null; return new NdefMessage(new NdefRecord[] { NdefRecord.createUri(LinkCreator.getTwitterUserLink(user.screen_name)), }); } }); activity.setEnterSharedElementCallback(new SharedElementCallback() { @Override public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) { final int idx = sharedElementNames.indexOf(TRANSITION_NAME_PROFILE_IMAGE); if (idx != -1) { final View view = sharedElements.get(idx); int[] location = new int[2]; final RectF bounds = new RectF(0, 0, view.getWidth(), view.getHeight()); view.getLocationOnScreen(location); bounds.offsetTo(location[0], location[1]); mProfileImageView.setTransitionSource(bounds); } super.onSharedElementStart(sharedElementNames, sharedElements, sharedElementSnapshots); } @Override public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) { int idx = sharedElementNames.indexOf(TRANSITION_NAME_PROFILE_IMAGE); if (idx != -1) { final View view = sharedElements.get(idx); int[] location = new int[2]; final RectF bounds = new RectF(0, 0, view.getWidth(), view.getHeight()); view.getLocationOnScreen(location); bounds.offsetTo(location[0], location[1]); mProfileImageView.setTransitionDestination(bounds); } super.onSharedElementEnd(sharedElementNames, sharedElements, sharedElementSnapshots); } }); ViewCompat.setTransitionName(mProfileImageView, TRANSITION_NAME_PROFILE_IMAGE); ViewCompat.setTransitionName(mProfileTypeView, TRANSITION_NAME_PROFILE_TYPE); // ViewCompat.setTransitionName(mCardView, TRANSITION_NAME_CARD); mHeaderDrawerLayout.setDrawerCallback(this); mPagerAdapter = new SupportTabsAdapter(activity, getChildFragmentManager()); mViewPager.setOffscreenPageLimit(3); mViewPager.setAdapter(mPagerAdapter); mPagerIndicator.setViewPager(mViewPager); mPagerIndicator.setTabDisplayOption(TabPagerIndicator.LABEL); mPagerIndicator.setOnPageChangeListener(this); mFollowButton.setOnClickListener(this); mProfileImageView.setOnClickListener(this); mProfileBannerView.setOnClickListener(this); mListedContainer.setOnClickListener(this); mFollowersContainer.setOnClickListener(this); mFriendsContainer.setOnClickListener(this); mHeaderErrorIcon.setOnClickListener(this); mProfileBannerView.setOnSizeChangedListener(this); mProfileBannerSpace.setOnTouchListener(this); mProfileNameBackground.setBackgroundColor(mCardBackgroundColor); mProfileDetailsContainer.setBackgroundColor(mCardBackgroundColor); mPagerIndicator.setBackgroundColor(mCardBackgroundColor); mUuckyFooter.setBackgroundColor(mCardBackgroundColor); final float actionBarElevation = ThemeUtils.getSupportActionBarElevation(activity); ViewCompat.setElevation(mPagerIndicator, actionBarElevation); if (activity instanceof IThemedActivity) { ViewSupport.setBackground(mPagerOverlay, ThemeUtils.getNormalWindowContentOverlay(activity, ((IThemedActivity) activity).getCurrentThemeResourceId())); ViewSupport.setBackground(mErrorOverlay, ThemeUtils.getNormalWindowContentOverlay(activity, ((IThemedActivity) activity).getCurrentThemeResourceId())); } setupBaseActionBar(); setupUserPages(); if (activity instanceof IThemedActivity) { setUiColor(((IThemedActivity) activity).getCurrentThemeColor()); } getUserInfo(accountId, userId, screenName, false); }
From source file:org.mariotaku.twidere.fragment.UserFragment.java
@Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final FragmentActivity activity = getActivity(); mUserColorNameManager.registerColorChangedListener(this); mUserColorNameManager.registerNicknameChangedListener(this); mNameFirst = mPreferences.getBoolean(KEY_NAME_FIRST); mLocale = getResources().getConfiguration().locale; mCardBackgroundColor = ThemeUtils.getCardBackgroundColor(activity, ThemeUtils.getThemeBackgroundOption(activity), ThemeUtils.getUserThemeBackgroundAlpha(activity)); mActionBarShadowColor = 0xA0000000;//from w w w .j a v a 2s. c om final Bundle args = getArguments(); UserKey accountId = null; UserKey userId = null; String screenName = null; if (savedInstanceState != null) { args.putAll(savedInstanceState); } else { accountId = args.getParcelable(EXTRA_ACCOUNT_KEY); userId = args.getParcelable(EXTRA_USER_KEY); screenName = args.getString(EXTRA_SCREEN_NAME); } Utils.setNdefPushMessageCallback(activity, new CreateNdefMessageCallback() { @Override public NdefMessage createNdefMessage(NfcEvent event) { final ParcelableUser user = getUser(); if (user == null) return null; return new NdefMessage( new NdefRecord[] { NdefRecord.createUri(LinkCreator.getUserWebLink(user)), }); } }); mTintedStatusFrameLayout.setWindowInsetsListener(new TintedStatusFrameLayout.WindowInsetsListener() { @Override public void onApplyWindowInsets(int left, int top, int right, int bottom) { mProfileContentContainer.setPadding(0, top, 0, 0); mProfileBannerSpace.setStatusBarHeight(top); if (mProfileBannerSpace.getToolbarHeight() == 0) { int toolbarHeight = mToolbar.getMeasuredHeight(); if (toolbarHeight == 0) { toolbarHeight = ThemeUtils.getActionBarHeight(getContext()); } mProfileBannerSpace.setToolbarHeight(toolbarHeight); } } }); mProfileContentContainer.setOnSizeChangedListener(new OnSizeChangedListener() { @Override public void onSizeChanged(View view, int w, int h, int oldw, int oldh) { final int toolbarHeight = mToolbar.getMeasuredHeight(); mHeaderDrawerLayout.setPadding(0, toolbarHeight, 0, 0); mProfileBannerSpace.setToolbarHeight(toolbarHeight); } }); mHeaderDrawerLayout.setDrawerCallback(this); mPagerAdapter = new SupportTabsAdapter(activity, getChildFragmentManager()); mViewPager.setOffscreenPageLimit(3); mViewPager.setAdapter(mPagerAdapter); mPagerIndicator.setViewPager(mViewPager); mPagerIndicator.setTabDisplayOption(TabPagerIndicator.LABEL); mPagerIndicator.setOnPageChangeListener(this); mFollowButton.setOnClickListener(this); mProfileImageView.setOnClickListener(this); mProfileBannerView.setOnClickListener(this); mListedContainer.setOnClickListener(this); mGroupsContainer.setOnClickListener(this); mFollowersContainer.setOnClickListener(this); mFriendsContainer.setOnClickListener(this); mHeaderErrorIcon.setOnClickListener(this); mProfileBirthdayBannerView.setOnClickListener(this); mProfileBannerView.setOnSizeChangedListener(this); mProfileBannerSpace.setOnTouchListener(this); mProfileNameBackground.setBackgroundColor(mCardBackgroundColor); mProfileDetailsContainer.setBackgroundColor(mCardBackgroundColor); mPagerIndicator.setBackgroundColor(mCardBackgroundColor); final float actionBarElevation = ThemeUtils.getSupportActionBarElevation(activity); ViewCompat.setElevation(mPagerIndicator, actionBarElevation); setupBaseActionBar(); setupUserPages(); getUserInfo(accountId, userId, screenName, false); }
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); }/*from www .j a va 2 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(); } }