List of usage examples for android.content Intent removeExtra
public void removeExtra(String name)
From source file:org.mozilla.gecko.BrowserApp.java
@Override public boolean onPrepareOptionsMenu(Menu aMenu) { if (aMenu == null) return false; // Hide the tab history panel when hardware menu button is pressed. TabHistoryFragment frag = (TabHistoryFragment) getSupportFragmentManager() .findFragmentByTag(TAB_HISTORY_FRAGMENT_TAG); if (frag != null) { frag.dismiss();/*w w w . j ava2 s . c o m*/ } if (!GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoRunning)) { aMenu.findItem(R.id.settings).setEnabled(false); aMenu.findItem(R.id.help).setEnabled(false); } Tab tab = Tabs.getInstance().getSelectedTab(); final MenuItem bookmark = aMenu.findItem(R.id.bookmark); final MenuItem reader = aMenu.findItem(R.id.reading_list); final MenuItem back = aMenu.findItem(R.id.back); final MenuItem forward = aMenu.findItem(R.id.forward); final MenuItem share = aMenu.findItem(R.id.share); final MenuItem quickShare = aMenu.findItem(R.id.quickshare); final MenuItem saveAsPDF = aMenu.findItem(R.id.save_as_pdf); final MenuItem charEncoding = aMenu.findItem(R.id.char_encoding); final MenuItem findInPage = aMenu.findItem(R.id.find_in_page); final MenuItem desktopMode = aMenu.findItem(R.id.desktop_mode); final MenuItem enterGuestMode = aMenu.findItem(R.id.new_guest_session); final MenuItem exitGuestMode = aMenu.findItem(R.id.exit_guest_session); // Only show the "Quit" menu item on pre-ICS, television devices, // or if the user has explicitly enabled the clear on shutdown pref. // (We check the pref last to save the pref read.) // In ICS+, it's easy to kill an app through the task switcher. final boolean visible = Versions.preICS || HardwareUtils.isTelevision() || !PrefUtils .getStringSet(GeckoSharedPrefs.forProfile(this), ClearOnShutdownPref.PREF, new HashSet<String>()) .isEmpty(); aMenu.findItem(R.id.quit).setVisible(visible); aMenu.findItem(R.id.logins).setVisible(AppConstants.NIGHTLY_BUILD); if (tab == null || tab.getURL() == null) { bookmark.setEnabled(false); reader.setEnabled(false); back.setEnabled(false); forward.setEnabled(false); share.setEnabled(false); quickShare.setEnabled(false); saveAsPDF.setEnabled(false); findInPage.setEnabled(false); // NOTE: Use MenuUtils.safeSetEnabled because some actions might // be on the BrowserToolbar context menu. if (Versions.feature11Plus) { // There is no page menu prior to v11 resources. MenuUtils.safeSetEnabled(aMenu, R.id.page, false); } MenuUtils.safeSetEnabled(aMenu, R.id.subscribe, false); MenuUtils.safeSetEnabled(aMenu, R.id.add_search_engine, false); MenuUtils.safeSetEnabled(aMenu, R.id.site_settings, false); MenuUtils.safeSetEnabled(aMenu, R.id.add_to_launcher, false); return true; } final boolean inGuestMode = GeckoProfile.get(this).inGuestMode(); final boolean isAboutReader = AboutPages.isAboutReader(tab.getURL()); bookmark.setEnabled(!isAboutReader); bookmark.setVisible(!inGuestMode); bookmark.setCheckable(true); bookmark.setChecked(tab.isBookmark()); bookmark.setIcon(resolveBookmarkIconID(tab.isBookmark())); bookmark.setTitle(resolveBookmarkTitleID(tab.isBookmark())); reader.setEnabled(isAboutReader || !AboutPages.isAboutPage(tab.getURL())); reader.setVisible(!inGuestMode); reader.setCheckable(true); final boolean isPageInReadingList = tab.isInReadingList(); reader.setChecked(isPageInReadingList); reader.setIcon(resolveReadingListIconID(isPageInReadingList)); reader.setTitle(resolveReadingListTitleID(isPageInReadingList)); back.setEnabled(tab.canDoBack()); forward.setEnabled(tab.canDoForward()); desktopMode.setChecked(tab.getDesktopMode()); desktopMode.setIcon( tab.getDesktopMode() ? R.drawable.ic_menu_desktop_mode_on : R.drawable.ic_menu_desktop_mode_off); View backButtonView = MenuItemCompat.getActionView(back); if (backButtonView != null) { backButtonView.setOnLongClickListener(new Button.OnLongClickListener() { @Override public boolean onLongClick(View view) { Tab tab = Tabs.getInstance().getSelectedTab(); if (tab != null) { closeOptionsMenu(); return tabHistoryController.showTabHistory(tab, TabHistoryController.HistoryAction.BACK); } return false; } }); } View forwardButtonView = MenuItemCompat.getActionView(forward); if (forwardButtonView != null) { forwardButtonView.setOnLongClickListener(new Button.OnLongClickListener() { @Override public boolean onLongClick(View view) { Tab tab = Tabs.getInstance().getSelectedTab(); if (tab != null) { closeOptionsMenu(); return tabHistoryController.showTabHistory(tab, TabHistoryController.HistoryAction.FORWARD); } return false; } }); } String url = tab.getURL(); if (AboutPages.isAboutReader(url)) { String urlFromReader = ReaderModeUtils.getUrlFromAboutReader(url); if (urlFromReader != null) { url = urlFromReader; } } // Disable share menuitem for about:, chrome:, file:, and resource: URIs final boolean shareVisible = RestrictedProfiles.isAllowed(this, Restriction.DISALLOW_SHARE); share.setVisible(shareVisible); final boolean shareEnabled = StringUtils.isShareableUrl(url) && shareVisible; share.setEnabled(shareEnabled); MenuUtils.safeSetEnabled(aMenu, R.id.downloads, RestrictedProfiles.isAllowed(this, Restriction.DISALLOW_DOWNLOADS)); // NOTE: Use MenuUtils.safeSetEnabled because some actions might // be on the BrowserToolbar context menu. if (Versions.feature11Plus) { MenuUtils.safeSetEnabled(aMenu, R.id.page, !isAboutHome(tab)); } MenuUtils.safeSetEnabled(aMenu, R.id.subscribe, tab.hasFeeds()); MenuUtils.safeSetEnabled(aMenu, R.id.add_search_engine, tab.hasOpenSearch()); MenuUtils.safeSetEnabled(aMenu, R.id.site_settings, !isAboutHome(tab)); MenuUtils.safeSetEnabled(aMenu, R.id.add_to_launcher, !isAboutHome(tab)); // Action providers are available only ICS+. if (Versions.feature14Plus) { quickShare.setVisible(shareVisible); quickShare.setEnabled(shareEnabled); // This provider also applies to the quick share menu item. final GeckoActionProvider provider = ((GeckoMenuItem) share).getGeckoActionProvider(); if (provider != null) { Intent shareIntent = provider.getIntent(); // For efficiency, the provider's intent is only set once if (shareIntent == null) { shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); provider.setIntent(shareIntent); } // Replace the existing intent's extras shareIntent.putExtra(Intent.EXTRA_TEXT, url); shareIntent.putExtra(Intent.EXTRA_SUBJECT, tab.getDisplayTitle()); shareIntent.putExtra(Intent.EXTRA_TITLE, tab.getDisplayTitle()); shareIntent.putExtra(ShareDialog.INTENT_EXTRA_DEVICES_ONLY, true); // Clear the existing thumbnail extras so we don't share an old thumbnail. shareIntent.removeExtra("share_screenshot_uri"); // Include the thumbnail of the page being shared. BitmapDrawable drawable = tab.getThumbnail(); if (drawable != null) { Bitmap thumbnail = drawable.getBitmap(); // Kobo uses a custom intent extra for sharing thumbnails. if (Build.MANUFACTURER.equals("Kobo") && thumbnail != null) { File cacheDir = getExternalCacheDir(); if (cacheDir != null) { File outFile = new File(cacheDir, "thumbnail.png"); try { java.io.FileOutputStream out = new java.io.FileOutputStream(outFile); thumbnail.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (FileNotFoundException e) { Log.e(LOGTAG, "File not found", e); } shareIntent.putExtra("share_screenshot_uri", Uri.parse(outFile.getPath())); } } } } } final boolean privateTabVisible = RestrictedProfiles.isAllowed(this, Restriction.DISALLOW_PRIVATE_BROWSING); MenuUtils.safeSetVisible(aMenu, R.id.new_private_tab, privateTabVisible); // Disable save as PDF for about:home and xul pages. saveAsPDF.setEnabled(!(isAboutHome(tab) || tab.getContentType().equals("application/vnd.mozilla.xul+xml") || tab.getContentType().startsWith("video/"))); // Disable find in page for about:home, since it won't work on Java content. findInPage.setEnabled(!isAboutHome(tab)); charEncoding.setVisible(GeckoPreferences.getCharEncodingState()); if (mProfile.inGuestMode()) { exitGuestMode.setVisible(true); } else { enterGuestMode.setVisible(true); } if (!RestrictedProfiles.isAllowed(this, Restriction.DISALLOW_GUEST_BROWSING)) { MenuUtils.safeSetVisible(aMenu, R.id.new_guest_session, false); } if (!RestrictedProfiles.isAllowed(this, Restriction.DISALLOW_INSTALL_EXTENSION)) { MenuUtils.safeSetVisible(aMenu, R.id.addons, false); } return true; }
From source file:com.localytics.android.LocalyticsSession.java
public void handlePushReceived(final Intent intent, final List<String> customDimensions) { if (intent == null || intent.getExtras() == null) return;//w ww. j a v a 2s . c o m // Tag an event indicating the push was opened String llString = intent.getExtras().getString("ll"); if (llString != null) { try { JSONObject llObject = new JSONObject(llString); String campaignId = llObject.getString("ca"); String creativeId = llObject.getString("cr"); if (campaignId != null && creativeId != null) { HashMap<String, String> attributes = new HashMap<String, String>(); attributes.put(CAMPAIGN_ID_ATTRIBUTE, campaignId); attributes.put(CREATIVE_ID_ATTRIBUTE, creativeId); tagEvent(PUSH_OPENED_EVENT, attributes, customDimensions); } // Remove the extra so we don't tag the same event a second time intent.removeExtra("ll"); } catch (JSONException e) { if (Constants.IS_LOGGABLE) { Log.w(Constants.LOG_TAG, "Failed to get campaign id or creatve id from payload"); //$NON-NLS-1$ } } } }
From source file:im.vector.activity.VectorHomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_vector_home); if (CommonActivityUtils.shouldRestartApp(this)) { Log.e(LOG_TAG, "Restart the application."); CommonActivityUtils.restartApp(this); return;/*from ww w. j ava2s . com*/ } if (CommonActivityUtils.isGoingToSplash(this)) { Log.d(LOG_TAG, "onCreate : Going to splash screen"); return; } sharedInstance = this; mWaitingView = findViewById(R.id.listView_spinner_views); mVectorPendingCallView = (VectorPendingCallView) findViewById(R.id.listView_pending_callview); mVectorPendingCallView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { IMXCall call = VectorCallViewActivity.getActiveCall(); if (null != call) { final Intent intent = new Intent(VectorHomeActivity.this, VectorCallViewActivity.class); intent.putExtra(VectorCallViewActivity.EXTRA_MATRIX_ID, call.getSession().getCredentials().userId); intent.putExtra(VectorCallViewActivity.EXTRA_CALL_ID, call.getCallId()); VectorHomeActivity.this.runOnUiThread(new Runnable() { @Override public void run() { VectorHomeActivity.this.startActivity(intent); } }); } } }); // use a toolbar instead of the actionbar mToolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.home_toolbar); this.setSupportActionBar(mToolbar); mToolbar.setTitle(R.string.title_activity_home); this.setTitle(R.string.title_activity_home); mRoomCreationFab = (FloatingActionButton) findViewById(R.id.listView_create_room_view); mRoomCreationFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // ignore any action if there is a pending one if (View.VISIBLE != mWaitingView.getVisibility()) { Context context = VectorHomeActivity.this; AlertDialog.Builder dialog = new AlertDialog.Builder(context); CharSequence items[] = new CharSequence[] { context.getString(R.string.room_recents_start_chat), context.getString(R.string.room_recents_create_room) }; dialog.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface d, int n) { d.cancel(); if (0 == n) { invitePeopleToNewRoom(); } else { createRoom(); } } }); dialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { invitePeopleToNewRoom(); } }); dialog.setNegativeButton(R.string.cancel, null); dialog.show(); } } }); mSession = Matrix.getInstance(this).getDefaultSession(); // process intent parameters final Intent intent = getIntent(); if (intent.hasExtra(EXTRA_CALL_SESSION_ID) && intent.hasExtra(EXTRA_CALL_ID)) { startCall(intent.getStringExtra(EXTRA_CALL_SESSION_ID), intent.getStringExtra(EXTRA_CALL_ID)); } // the activity could be started with a spinner // because there is a pending action (like universalLink processing) if (intent.getBooleanExtra(EXTRA_WAITING_VIEW_STATUS, VectorHomeActivity.WAITING_VIEW_STOP)) { showWaitingView(); } else { stopWaitingView(); } mAutomaticallyOpenedRoomParams = (Map<String, Object>) intent .getSerializableExtra(EXTRA_JUMP_TO_ROOM_PARAMS); mUniversalLinkToOpen = intent.getParcelableExtra(EXTRA_JUMP_TO_UNIVERSAL_LINK); // the home activity has been launched with an universal link if (intent.hasExtra(VectorUniversalLinkReceiver.EXTRA_UNIVERSAL_LINK_URI)) { Log.d(LOG_TAG, "Has an universal link"); final Uri uri = intent.getParcelableExtra(VectorUniversalLinkReceiver.EXTRA_UNIVERSAL_LINK_URI); intent.removeExtra(VectorUniversalLinkReceiver.EXTRA_UNIVERSAL_LINK_URI); // detect the room could be opened without waiting the next sync HashMap<String, String> params = VectorUniversalLinkReceiver.parseUniversalLink(uri); if ((null != params) && params.containsKey(VectorUniversalLinkReceiver.ULINK_ROOM_ID_KEY)) { Log.d(LOG_TAG, "Has a valid universal link"); final String roomIdOrAlias = params.get(VectorUniversalLinkReceiver.ULINK_ROOM_ID_KEY); // it is a room ID ? if (roomIdOrAlias.startsWith("!")) { Log.d(LOG_TAG, "Has a valid universal link to the room ID " + roomIdOrAlias); Room room = mSession.getDataHandler().getRoom(roomIdOrAlias, false); if (null != room) { Log.d(LOG_TAG, "Has a valid universal link to a known room"); // open the room asap mUniversalLinkToOpen = uri; } else { Log.d(LOG_TAG, "Has a valid universal link but the room is not yet known"); // wait the next sync intent.putExtra(VectorUniversalLinkReceiver.EXTRA_UNIVERSAL_LINK_URI, uri); } } else { Log.d(LOG_TAG, "Has a valid universal link of the room Alias " + roomIdOrAlias); // it is a room alias // convert the room alias to room Id mSession.getDataHandler().roomIdByAlias(roomIdOrAlias, new SimpleApiCallback<String>() { @Override public void onSuccess(String roomId) { Log.d(LOG_TAG, "Retrieve the room ID " + roomId); getIntent().putExtra(VectorUniversalLinkReceiver.EXTRA_UNIVERSAL_LINK_URI, uri); // the room exists, opens it if (null != mSession.getDataHandler().getRoom(roomId, false)) { Log.d(LOG_TAG, "Find the room from room ID : process it"); processIntentUniversalLink(); } else { Log.d(LOG_TAG, "Don't know the room"); } } }); } } } else { Log.d(LOG_TAG, "create with no universal link"); } if (intent.hasExtra(EXTRA_SHARED_INTENT_PARAMS)) { final Intent sharedFilesIntent = intent.getParcelableExtra(EXTRA_SHARED_INTENT_PARAMS); if (mSession.getDataHandler().getStore().isReady()) { this.runOnUiThread(new Runnable() { @Override public void run() { CommonActivityUtils.sendFilesTo(VectorHomeActivity.this, sharedFilesIntent); } }); } else { mSharedFilesIntent = sharedFilesIntent; } // ensure that it should be called once intent.removeExtra(EXTRA_SHARED_INTENT_PARAMS); } // check if there is some valid session // the home activity could be relaunched after an application crash // so, reload the sessions before displaying the history Collection<MXSession> sessions = Matrix.getMXSessions(VectorHomeActivity.this); if (sessions.size() == 0) { Log.e(LOG_TAG, "Weird : onCreate : no session"); if (null != Matrix.getInstance(this).getDefaultSession()) { Log.e(LOG_TAG, "No loaded session : reload them"); // start splash activity and stop here startActivity(new Intent(VectorHomeActivity.this, SplashActivity.class)); VectorHomeActivity.this.finish(); return; } } FragmentManager fm = getSupportFragmentManager(); mRecentsListFragment = (VectorRecentsListFragment) fm.findFragmentByTag(TAG_FRAGMENT_RECENTS_LIST); if (mRecentsListFragment == null) { // this fragment displays messages and handles all message logic //String matrixId, int layoutResId) mRecentsListFragment = VectorRecentsListFragment.newInstance(mSession.getCredentials().userId, R.layout.fragment_vector_recents_list); fm.beginTransaction() .add(R.id.home_recents_list_anchor, mRecentsListFragment, TAG_FRAGMENT_RECENTS_LIST).commit(); } // clear the notification if they are not anymore valid // i.e the event has been read from another client // or deleted it // + other actions which require a background listener mLiveEventListener = new MXEventListener() { @Override public void onLiveEventsChunkProcessed() { // treat any pending URL link workflow, that was started previously processIntentUniversalLink(); if (mClearCacheRequired) { mClearCacheRequired = false; Matrix.getInstance(VectorHomeActivity.this).reloadSessions(VectorHomeActivity.this); } } @Override public void onStoreReady() { if (null != mSharedFilesIntent) { VectorHomeActivity.this.runOnUiThread(new Runnable() { @Override public void run() { CommonActivityUtils.sendFilesTo(VectorHomeActivity.this, mSharedFilesIntent); mSharedFilesIntent = null; } }); } } }; mSession.getDataHandler().addListener(mLiveEventListener); // initialize the public rooms list PublicRoomsManager.setSession(mSession); PublicRoomsManager.refresh(null); }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String StrtUpdtOMatic(String sPkgName, String sPkgFileName, String sCallBackIP, String sCallBackPort) { String sRet = ""; Context ctx = contextWrapper.getApplicationContext(); PackageManager pm = ctx.getPackageManager(); Intent prgIntent = new Intent(); prgIntent.setPackage("com.mozilla.watcher"); try {//from ww w. j a v a 2 s. c om PackageInfo pi = pm.getPackageInfo("com.mozilla.watcher", PackageManager.GET_SERVICES | PackageManager.GET_INTENT_FILTERS); ServiceInfo[] si = pi.services; for (int i = 0; i < si.length; i++) { ServiceInfo s = si[i]; if (s.name.length() > 0) { prgIntent.setClassName(s.packageName, s.name); break; } } } catch (NameNotFoundException e) { e.printStackTrace(); sRet = sErrorPrefix + "watcher is not properly installed"; return (sRet); } prgIntent.putExtra("command", "updt"); prgIntent.putExtra("pkgName", sPkgName); prgIntent.putExtra("pkgFile", sPkgFileName); prgIntent.putExtra("reboot", true); try { if ((sCallBackIP != null) && (sCallBackPort != null) && (sCallBackIP.length() > 0) && (sCallBackPort.length() > 0)) { FileOutputStream fos = ctx.openFileOutput("update.info", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE); String sBuffer = sCallBackIP + "," + sCallBackPort + "\rupdate started " + sPkgName + " " + sPkgFileName + "\r"; fos.write(sBuffer.getBytes()); fos.flush(); fos.close(); fos = null; prgIntent.putExtra("outFile", ctx.getFilesDir() + "/update.info"); } else { if (prgIntent.hasExtra("outFile")) { System.out.println("outFile extra unset from intent"); prgIntent.removeExtra("outFile"); } } ComponentName cn = contextWrapper.startService(prgIntent); if (cn != null) sRet = "exit"; else sRet = sErrorPrefix + "Unable to use watcher service"; } catch (ActivityNotFoundException anf) { sRet = sErrorPrefix + "Activity Not Found Exception [updt] call failed"; anf.printStackTrace(); } catch (FileNotFoundException e) { sRet = sErrorPrefix + "File creation error [updt] call failed"; e.printStackTrace(); } catch (IOException e) { sRet = sErrorPrefix + "File error [updt] call failed"; e.printStackTrace(); } ctx = null; return (sRet); }
From source file:im.neon.activity.VectorHomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_vector_home); if (CommonActivityUtils.shouldRestartApp(this)) { Log.e(LOG_TAG, "Restart the application."); CommonActivityUtils.restartApp(this); return;//from w w w. jav a2 s .c om } if (CommonActivityUtils.isGoingToSplash(this)) { Log.d(LOG_TAG, "onCreate : Going to splash screen"); return; } sharedInstance = this; mWaitingView = findViewById(R.id.listView_spinner_views); mVectorPendingCallView = (VectorPendingCallView) findViewById(R.id.listView_pending_callview); mSyncInProgressView = findViewById(R.id.home_recents_sync_in_progress); mVectorPendingCallView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { IMXCall call = VectorCallViewActivity.getActiveCall(); if (null != call) { final Intent intent = new Intent(VectorHomeActivity.this, VectorCallViewActivity.class); intent.putExtra(VectorCallViewActivity.EXTRA_MATRIX_ID, call.getSession().getCredentials().userId); intent.putExtra(VectorCallViewActivity.EXTRA_CALL_ID, call.getCallId()); VectorHomeActivity.this.runOnUiThread(new Runnable() { @Override public void run() { VectorHomeActivity.this.startActivity(intent); } }); } } }); // use a toolbar instead of the actionbar mToolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.home_toolbar); this.setSupportActionBar(mToolbar); mToolbar.setTitle(R.string.title_activity_home); this.setTitle(R.string.title_activity_home); mRoomCreationFab = (FloatingActionButton) findViewById(R.id.listView_create_room_view); mRoomCreationFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // ignore any action if there is a pending one if (View.VISIBLE != mWaitingView.getVisibility()) { Context context = VectorHomeActivity.this; AlertDialog.Builder dialog = new AlertDialog.Builder(context); CharSequence items[] = new CharSequence[] { context.getString(R.string.room_recents_start_chat), context.getString(R.string.room_recents_create_room) }; dialog.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface d, int n) { d.cancel(); if (0 == n) { invitePeopleToNewRoom(); } else { createRoom(); } } }); dialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { invitePeopleToNewRoom(); } }); dialog.setNegativeButton(R.string.cancel, null); dialog.show(); } } }); mSession = Matrix.getInstance(this).getDefaultSession(); // track if the application update SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); int version = preferences.getInt("VERSION_BUILD", 0); if (version != VectorApp.VERSION_BUILD) { Log.d(LOG_TAG, "The application has been updated from version " + version + " to version " + VectorApp.VERSION_BUILD); // TODO add some dedicated actions here SharedPreferences.Editor editor = preferences.edit(); editor.putInt("VERSION_BUILD", VectorApp.VERSION_BUILD); editor.commit(); } // process intent parameters final Intent intent = getIntent(); if (intent.hasExtra(EXTRA_CALL_SESSION_ID) && intent.hasExtra(EXTRA_CALL_ID)) { startCall(intent.getStringExtra(EXTRA_CALL_SESSION_ID), intent.getStringExtra(EXTRA_CALL_ID), (MXUsersDevicesMap<MXDeviceInfo>) intent.getSerializableExtra(EXTRA_CALL_UNKNOWN_DEVICES)); intent.removeExtra(EXTRA_CALL_SESSION_ID); intent.removeExtra(EXTRA_CALL_ID); intent.removeExtra(EXTRA_CALL_UNKNOWN_DEVICES); } // the activity could be started with a spinner // because there is a pending action (like universalLink processing) if (intent.getBooleanExtra(EXTRA_WAITING_VIEW_STATUS, WAITING_VIEW_STOP)) { showWaitingView(); } else { stopWaitingView(); } intent.removeExtra(EXTRA_WAITING_VIEW_STATUS); mAutomaticallyOpenedRoomParams = (Map<String, Object>) intent .getSerializableExtra(EXTRA_JUMP_TO_ROOM_PARAMS); intent.removeExtra(EXTRA_JUMP_TO_ROOM_PARAMS); mUniversalLinkToOpen = intent.getParcelableExtra(EXTRA_JUMP_TO_UNIVERSAL_LINK); intent.removeExtra(EXTRA_JUMP_TO_UNIVERSAL_LINK); mMemberIdToOpen = intent.getStringExtra(EXTRA_MEMBER_ID); intent.removeExtra(EXTRA_MEMBER_ID); // the home activity has been launched with an universal link if (intent.hasExtra(VectorUniversalLinkReceiver.EXTRA_UNIVERSAL_LINK_URI)) { Log.d(LOG_TAG, "Has an universal link"); final Uri uri = intent.getParcelableExtra(VectorUniversalLinkReceiver.EXTRA_UNIVERSAL_LINK_URI); intent.removeExtra(VectorUniversalLinkReceiver.EXTRA_UNIVERSAL_LINK_URI); // detect the room could be opened without waiting the next sync HashMap<String, String> params = VectorUniversalLinkReceiver.parseUniversalLink(uri); if ((null != params) && params.containsKey(VectorUniversalLinkReceiver.ULINK_ROOM_ID_OR_ALIAS_KEY)) { Log.d(LOG_TAG, "Has a valid universal link"); final String roomIdOrAlias = params.get(VectorUniversalLinkReceiver.ULINK_ROOM_ID_OR_ALIAS_KEY); // it is a room ID ? if (MXSession.isRoomId(roomIdOrAlias)) { Log.d(LOG_TAG, "Has a valid universal link to the room ID " + roomIdOrAlias); Room room = mSession.getDataHandler().getRoom(roomIdOrAlias, false); if (null != room) { Log.d(LOG_TAG, "Has a valid universal link to a known room"); // open the room asap mUniversalLinkToOpen = uri; } else { Log.d(LOG_TAG, "Has a valid universal link but the room is not yet known"); // wait the next sync intent.putExtra(VectorUniversalLinkReceiver.EXTRA_UNIVERSAL_LINK_URI, uri); } } else if (MXSession.isRoomAlias(roomIdOrAlias)) { Log.d(LOG_TAG, "Has a valid universal link of the room Alias " + roomIdOrAlias); // it is a room alias // convert the room alias to room Id mSession.getDataHandler().roomIdByAlias(roomIdOrAlias, new SimpleApiCallback<String>() { @Override public void onSuccess(String roomId) { Log.d(LOG_TAG, "Retrieve the room ID " + roomId); getIntent().putExtra(VectorUniversalLinkReceiver.EXTRA_UNIVERSAL_LINK_URI, uri); // the room exists, opens it if (null != mSession.getDataHandler().getRoom(roomId, false)) { Log.d(LOG_TAG, "Find the room from room ID : process it"); processIntentUniversalLink(); } else { Log.d(LOG_TAG, "Don't know the room"); } } }); } } } else { Log.d(LOG_TAG, "create with no universal link"); } if (intent.hasExtra(EXTRA_SHARED_INTENT_PARAMS)) { final Intent sharedFilesIntent = intent.getParcelableExtra(EXTRA_SHARED_INTENT_PARAMS); if (mSession.getDataHandler().getStore().isReady()) { this.runOnUiThread(new Runnable() { @Override public void run() { CommonActivityUtils.sendFilesTo(VectorHomeActivity.this, sharedFilesIntent); } }); } else { mSharedFilesIntent = sharedFilesIntent; } // ensure that it should be called once intent.removeExtra(EXTRA_SHARED_INTENT_PARAMS); } // check if there is some valid session // the home activity could be relaunched after an application crash // so, reload the sessions before displaying the history Collection<MXSession> sessions = Matrix.getMXSessions(VectorHomeActivity.this); if (sessions.size() == 0) { Log.e(LOG_TAG, "Weird : onCreate : no session"); if (null != Matrix.getInstance(this).getDefaultSession()) { Log.e(LOG_TAG, "No loaded session : reload them"); // start splash activity and stop here startActivity(new Intent(VectorHomeActivity.this, SplashActivity.class)); VectorHomeActivity.this.finish(); return; } } FragmentManager fm = getSupportFragmentManager(); mRecentsListFragment = (VectorRecentsListFragment) fm.findFragmentByTag(TAG_FRAGMENT_RECENTS_LIST); if (mRecentsListFragment == null) { // this fragment displays messages and handles all message logic //String matrixId, int layoutResId) mRecentsListFragment = VectorRecentsListFragment.newInstance(mSession.getCredentials().userId, R.layout.fragment_vector_recents_list); fm.beginTransaction() .add(R.id.home_recents_list_anchor, mRecentsListFragment, TAG_FRAGMENT_RECENTS_LIST).commit(); } // clear the notification if they are not anymore valid // i.e the event has been read from another client // or deleted it // + other actions which require a background listener mLiveEventListener = new MXEventListener() { @Override public void onLiveEventsChunkProcessed(String fromToken, String toToken) { // treat any pending URL link workflow, that was started previously processIntentUniversalLink(); if (mClearCacheRequired) { mClearCacheRequired = false; Matrix.getInstance(VectorHomeActivity.this).reloadSessions(VectorHomeActivity.this); } } @Override public void onStoreReady() { if (null != mSharedFilesIntent) { VectorHomeActivity.this.runOnUiThread(new Runnable() { @Override public void run() { CommonActivityUtils.sendFilesTo(VectorHomeActivity.this, mSharedFilesIntent); mSharedFilesIntent = null; } }); } } }; mSession.getDataHandler().addListener(mLiveEventListener); // initialize the public rooms list PublicRoomsManager.setSession(mSession); PublicRoomsManager.refreshPublicRoomsCount(null); }
From source file:org.de.jmg.learn.MainActivity.java
@SuppressLint("InlinedApi") public void SaveVokAs(boolean blnUniCode, boolean blnNew) throws Exception { boolean blnActionCreateDocument = false; try {//w ww . j a v a 2s . c o m if (fPA.fragMain != null && fPA.fragMain.mainView != null) fPA.fragMain.EndEdit(false); if (!libString.IsNullOrEmpty(vok.getFileName()) || vok.getURI() == null || Build.VERSION.SDK_INT < 19) { boolean blnSuccess; for (int i = 0; i < 2; i++) { try { String key = "AlwaysStartExternalProgram"; int AlwaysStartExternalProgram = prefs.getInt(key, 999); lib.YesNoCheckResult res; if (AlwaysStartExternalProgram == 999 && !(vok.getURI() != null && i == 1)) { res = lib.ShowMessageYesNoWithCheckbox(this, "", getString(R.string.msgStartExternalProgram), getString(R.string.msgRememberChoice), false); if (res != null) { if (res.res == yesnoundefined.undefined) return; if (res.checked) prefs.edit().putInt(key, res.res == yesnoundefined.yes ? -1 : 0).commit(); } else { yesnoundefined par = yesnoundefined.undefined; res = new lib.YesNoCheckResult(par, true); } } else { yesnoundefined par = yesnoundefined.undefined; if (AlwaysStartExternalProgram == -1) par = yesnoundefined.yes; if (AlwaysStartExternalProgram == 0) par = yesnoundefined.no; res = new lib.YesNoCheckResult(par, true); } if ((vok.getURI() != null && i == 1) || res.res == yesnoundefined.no) { Intent intent = new Intent(this, AdvFileChooser.class); ArrayList<String> extensions = new ArrayList<>(); extensions.add(".k??"); extensions.add(".v??"); extensions.add(".K??"); extensions.add(".V??"); extensions.add(".KAR"); extensions.add(".VOK"); extensions.add(".kar"); extensions.add(".vok"); extensions.add(".dic"); extensions.add(".DIC"); if (libString.IsNullOrEmpty(vok.getFileName())) { if (vok.getURI() != null) { intent.setData(vok.getURI()); } } else { File F = new File(vok.getFileName()); Uri uri = Uri.fromFile(F); intent.setData(uri); } intent.putExtra("URIName", vok.getURIName()); intent.putStringArrayListExtra("filterFileExtension", extensions); intent.putExtra("blnUniCode", blnUniCode); intent.putExtra("DefaultDir", new File(JMGDataDirectory).exists() ? JMGDataDirectory : Environment.getExternalStorageDirectory().getPath()); intent.putExtra("selectFolder", false); intent.putExtra("blnNew", blnNew); if (_blnUniCode) _oldUniCode = yesnoundefined.yes; else _oldUniCode = yesnoundefined.no; _blnUniCode = blnUniCode; this.startActivityForResult(intent, FILE_CHOOSERADV); blnSuccess = true; } else if (Build.VERSION.SDK_INT < 19) { //org.openintents.filemanager Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setData(vok.getURI()); intent.putExtra("org.openintents.extra.WRITEABLE_ONLY", true); intent.putExtra("org.openintents.extra.TITLE", getString(R.string.SaveAs)); intent.putExtra("org.openintents.extra.BUTTON_TEXT", getString(R.string.btnSave)); intent.setType("*/*"); Intent chooser = Intent.createChooser(intent, getString(R.string.SaveAs)); if (intent.resolveActivity(context.getPackageManager()) != null) { startActivityForResult(chooser, FILE_OPENINTENT); blnSuccess = true; } else { lib.ShowToast(this, getString(R.string.InstallFilemanager)); intent.setData(null); intent.removeExtra("org.openintents.extra.WRITEABLE_ONLY"); intent.removeExtra("org.openintents.extra.TITLE"); intent.removeExtra("org.openintents.extra.BUTTON_TEXT"); startActivityForResult(chooser, FILE_OPENINTENT); blnSuccess = true; } } else { blnActionCreateDocument = true; blnSuccess = true; } } catch (Exception ex) { blnSuccess = false; Log.e("SaveAs", ex.getMessage(), ex); if (i == 1) { lib.ShowException(this, ex); } } if (blnSuccess) break; } } else if (Build.VERSION.SDK_INT >= 19) { blnActionCreateDocument = true; } if (blnActionCreateDocument) { /** * Open a file for writing and append some text to it. */ // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's // file browser. Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); // Create a file with the requested MIME type. String defaultURI = prefs.getString("defaultURI", ""); if (!libString.IsNullOrEmpty(defaultURI)) { String FName = ""; if (vok.getURI() != null) { String path2 = lib.dumpUriMetaData(this, vok.getURI()); if (path2.contains(":")) path2 = path2.split(":")[0]; FName = path2.substring(path2.lastIndexOf("/") + 1); } else if (!libString.IsNullOrEmpty(vok.getFileName())) { FName = new File(vok.getFileName()).getName(); } intent.putExtra(Intent.EXTRA_TITLE, FName); //defaultURI = (!defaultURI.endsWith("/")?defaultURI.substring(0,defaultURI.lastIndexOf("/")+1):defaultURI); Uri def = Uri.parse(defaultURI); intent.setData(def); } else { Log.d("empty", "empty"); //intent.setType("file/*"); } // Filter to only show results that can be "opened", such as a // file (as opposed to a list of contacts or timezones). intent.addCategory(Intent.CATEGORY_OPENABLE); // Filter to show only text files. intent.setType("*/*"); startActivityForResult(intent, EDIT_REQUEST_CODE); } } catch (Exception ex) { libLearn.gStatus = "SaveVokAs"; lib.ShowException(this, ex); } }
From source file:im.vector.activity.VectorRoomActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_vector_room); if (CommonActivityUtils.shouldRestartApp(this)) { Log.e(LOG_TAG, "onCreate : Restart the application."); CommonActivityUtils.restartApp(this); return;//from ww w. ja v a2 s . co m } final Intent intent = getIntent(); if (!intent.hasExtra(EXTRA_ROOM_ID)) { Log.e(LOG_TAG, "No room ID extra."); finish(); return; } mSession = getSession(intent); if (mSession == null) { Log.e(LOG_TAG, "No MXSession."); finish(); return; } String roomId = intent.getStringExtra(EXTRA_ROOM_ID); // ensure that the preview mode is really expected if (!intent.hasExtra(EXTRA_ROOM_PREVIEW_ID)) { sRoomPreviewData = null; Matrix.getInstance(this).clearTmpStoresList(); } if (CommonActivityUtils.isGoingToSplash(this, mSession.getMyUserId(), roomId)) { Log.d(LOG_TAG, "onCreate : Going to splash screen"); return; } // bind the widgets of the room header view. The room header view is displayed by // clicking on the title of the action bar mRoomHeaderView = (RelativeLayout) findViewById(R.id.action_bar_header); mActionBarHeaderRoomTopic = (TextView) findViewById(R.id.action_bar_header_room_topic); mActionBarHeaderRoomName = (TextView) findViewById(R.id.action_bar_header_room_title); mActionBarHeaderActiveMembers = (TextView) findViewById(R.id.action_bar_header_room_members); mActionBarHeaderRoomAvatar = (ImageView) mRoomHeaderView.findViewById(R.id.avatar_img); mActionBarHeaderInviteMemberView = mRoomHeaderView.findViewById(R.id.action_bar_header_invite_members); mRoomPreviewLayout = findViewById(R.id.room_preview_info_layout); mVectorPendingCallView = (VectorPendingCallView) findViewById(R.id.room_pending_call_view); mVectorOngoingConferenceCallView = (VectorOngoingConferenceCallView) findViewById( R.id.room_ongoing_conference_call_view); // hide the header room as soon as the bottom layout (text edit zone) is touched findViewById(R.id.room_bottom_layout).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { enableActionBarHeader(HIDE_ACTION_BAR_HEADER); return false; } }); // use a toolbar instead of the actionbar // to be able to display an expandable header mToolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.room_toolbar); this.setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // set the default custom action bar layout, // that will be displayed from the custom action bar layout setActionBarDefaultCustomLayout(); mCallId = intent.getStringExtra(EXTRA_START_CALL_ID); mEventId = intent.getStringExtra(EXTRA_EVENT_ID); mDefaultRoomName = intent.getStringExtra(EXTRA_DEFAULT_NAME); mDefaultTopic = intent.getStringExtra(EXTRA_DEFAULT_TOPIC); // the user has tapped on the "View" notification button if ((null != intent.getAction()) && (intent.getAction().startsWith(NotificationUtils.TAP_TO_VIEW_ACTION))) { // remove any pending notifications NotificationManager notificationsManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationsManager.cancelAll(); } Log.d(LOG_TAG, "Displaying " + roomId); mEditText = (EditText) findViewById(R.id.editText_messageBox); // hide the header room as soon as the message input text area is touched mEditText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { enableActionBarHeader(HIDE_ACTION_BAR_HEADER); } }); // IME's DONE button is treated as a send action mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { int imeActionId = actionId & EditorInfo.IME_MASK_ACTION; if (EditorInfo.IME_ACTION_DONE == imeActionId) { sendTextMessage(); } return false; } }); mSendingMessagesLayout = findViewById(R.id.room_sending_message_layout); mSendImageView = (ImageView) findViewById(R.id.room_send_image_view); mSendButtonLayout = findViewById(R.id.room_send_layout); mSendButtonLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!TextUtils.isEmpty(mEditText.getText())) { sendTextMessage(); } else { // hide the header room enableActionBarHeader(HIDE_ACTION_BAR_HEADER); FragmentManager fm = getSupportFragmentManager(); IconAndTextDialogFragment fragment = (IconAndTextDialogFragment) fm .findFragmentByTag(TAG_FRAGMENT_ATTACHMENTS_DIALOG); if (fragment != null) { fragment.dismissAllowingStateLoss(); } final Integer[] messages = new Integer[] { R.string.option_send_files, R.string.option_take_photo, }; final Integer[] icons = new Integer[] { R.drawable.ic_material_file, // R.string.option_send_files R.drawable.ic_material_camera, // R.string.option_take_photo }; fragment = IconAndTextDialogFragment.newInstance(icons, messages, null, ContextCompat.getColor(VectorRoomActivity.this, R.color.vector_text_black_color)); fragment.setOnClickListener(new IconAndTextDialogFragment.OnItemClickListener() { @Override public void onItemClick(IconAndTextDialogFragment dialogFragment, int position) { Integer selectedVal = messages[position]; if (selectedVal == R.string.option_send_files) { VectorRoomActivity.this.launchFileSelectionIntent(); } else if (selectedVal == R.string.option_take_photo) { if (CommonActivityUtils.checkPermissions( CommonActivityUtils.REQUEST_CODE_PERMISSION_TAKE_PHOTO, VectorRoomActivity.this)) { launchCamera(); } } } }); fragment.show(fm, TAG_FRAGMENT_ATTACHMENTS_DIALOG); } } }); mEditText.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(android.text.Editable s) { if (null != mRoom) { MXLatestChatMessageCache latestChatMessageCache = VectorRoomActivity.this.mLatestChatMessageCache; String textInPlace = latestChatMessageCache.getLatestText(VectorRoomActivity.this, mRoom.getRoomId()); // check if there is really an update // avoid useless updates (initializations..) if (!mIgnoreTextUpdate && !textInPlace.equals(mEditText.getText().toString())) { latestChatMessageCache.updateLatestMessage(VectorRoomActivity.this, mRoom.getRoomId(), mEditText.getText().toString()); handleTypingNotification(mEditText.getText().length() != 0); } manageSendMoreButtons(); refreshCallButtons(); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); mVectorPendingCallView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { IMXCall call = VectorCallViewActivity.getActiveCall(); if (null != call) { final Intent intent = new Intent(VectorRoomActivity.this, VectorCallViewActivity.class); intent.putExtra(VectorCallViewActivity.EXTRA_MATRIX_ID, call.getSession().getCredentials().userId); intent.putExtra(VectorCallViewActivity.EXTRA_CALL_ID, call.getCallId()); VectorRoomActivity.this.runOnUiThread(new Runnable() { @Override public void run() { VectorRoomActivity.this.startActivity(intent); } }); } else { // if the call is no more active, just remove the view mVectorPendingCallView.onCallTerminated(); } } }); mActionBarHeaderInviteMemberView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { launchRoomDetails(VectorRoomDetailsActivity.PEOPLE_TAB_INDEX); } }); // notifications area mNotificationsArea = findViewById(R.id.room_notifications_area); mNotificationIconImageView = (ImageView) mNotificationsArea.findViewById(R.id.room_notification_icon); mNotificationTextView = (TextView) mNotificationsArea.findViewById(R.id.room_notification_message); mCanNotPostTextView = findViewById(R.id.room_cannot_post_textview); mStartCallLayout = findViewById(R.id.room_start_call_layout); mStartCallLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isUserAllowedToStartConfCall()) { displayVideoCallIpDialog(); } else { displayConfCallNotAllowed(); } } }); mStopCallLayout = findViewById(R.id.room_end_call_layout); mStopCallLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { IMXCall call = mSession.mCallsManager.getCallWithRoomId(mRoom.getRoomId()); if (null != call) { call.hangup(null); } } }); mMyUserId = mSession.getCredentials().userId; CommonActivityUtils.resumeEventStream(this); mRoom = mSession.getDataHandler().getRoom(roomId, false); FragmentManager fm = getSupportFragmentManager(); mVectorMessageListFragment = (VectorMessageListFragment) fm .findFragmentByTag(TAG_FRAGMENT_MATRIX_MESSAGE_LIST); if (mVectorMessageListFragment == null) { Log.d(LOG_TAG, "Create VectorMessageListFragment"); // this fragment displays messages and handles all message logic mVectorMessageListFragment = VectorMessageListFragment.newInstance(mMyUserId, roomId, mEventId, (null == sRoomPreviewData) ? null : VectorMessageListFragment.PREVIEW_MODE_READ_ONLY, org.matrix.androidsdk.R.layout.fragment_matrix_message_list_fragment); fm.beginTransaction().add(R.id.anchor_fragment_messages, mVectorMessageListFragment, TAG_FRAGMENT_MATRIX_MESSAGE_LIST).commit(); } else { Log.d(LOG_TAG, "Reuse VectorMessageListFragment"); } mVectorRoomMediasSender = new VectorRoomMediasSender(this, mVectorMessageListFragment, Matrix.getInstance(this).getMediasCache()); mVectorRoomMediasSender.onRestoreInstanceState(savedInstanceState); manageRoomPreview(); addRoomHeaderClickListeners(); // in timeline mode (i.e search in the forward and backward room history) // or in room preview mode // the edition items are not displayed if (!TextUtils.isEmpty(mEventId) || (null != sRoomPreviewData)) { mNotificationsArea.setVisibility(View.GONE); findViewById(R.id.bottom_separator).setVisibility(View.GONE); findViewById(R.id.room_notification_separator).setVisibility(View.GONE); findViewById(R.id.room_notifications_area).setVisibility(View.GONE); View v = findViewById(R.id.room_bottom_layout); ViewGroup.LayoutParams params = v.getLayoutParams(); params.height = 0; v.setLayoutParams(params); } mLatestChatMessageCache = Matrix.getInstance(this).getDefaultLatestChatMessageCache(); // some medias must be sent while opening the chat if (intent.hasExtra(EXTRA_ROOM_INTENT)) { final Intent mediaIntent = intent.getParcelableExtra(EXTRA_ROOM_INTENT); // sanity check if (null != mediaIntent) { mEditText.postDelayed(new Runnable() { @Override public void run() { intent.removeExtra(EXTRA_ROOM_INTENT); sendMediasIntent(mediaIntent); } }, 1000); } } mVectorOngoingConferenceCallView.initRoomInfo(mSession, mRoom); mVectorOngoingConferenceCallView .setCallClickListener(new VectorOngoingConferenceCallView.ICallClickListener() { private void startCall(boolean isVideo) { if (CommonActivityUtils.checkPermissions( isVideo ? CommonActivityUtils.REQUEST_CODE_PERMISSION_VIDEO_IP_CALL : CommonActivityUtils.REQUEST_CODE_PERMISSION_AUDIO_IP_CALL, VectorRoomActivity.this)) { startIpCall(isVideo); } } @Override public void onVoiceCallClick() { startCall(false); } @Override public void onVideoCallClick() { startCall(true); } }); View avatarLayout = findViewById(R.id.room_self_avatar); if (null != avatarLayout) { mAvatarImageView = (ImageView) avatarLayout.findViewById(R.id.avatar_img); } refreshSelfAvatar(); // in case a "Send as" dialog was in progress when the activity was destroyed (life cycle) mVectorRoomMediasSender.resumeResizeMediaAndSend(); // header visibility has launched enableActionBarHeader(intent.getBooleanExtra(EXTRA_EXPAND_ROOM_HEADER, false) ? SHOW_ACTION_BAR_HEADER : HIDE_ACTION_BAR_HEADER); // the both flags are only used once intent.removeExtra(EXTRA_EXPAND_ROOM_HEADER); Log.d(LOG_TAG, "End of create"); }
From source file:im.neon.activity.VectorRoomActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_vector_room); if (CommonActivityUtils.shouldRestartApp(this)) { Log.e(LOG_TAG, "onCreate : Restart the application."); CommonActivityUtils.restartApp(this); return;//from www . j a v a 2s . c o m } final Intent intent = getIntent(); if (!intent.hasExtra(EXTRA_ROOM_ID)) { Log.e(LOG_TAG, "No room ID extra."); finish(); return; } mSession = MXCActionBarActivity.getSession(this, intent); if (mSession == null) { Log.e(LOG_TAG, "No MXSession."); finish(); return; } String roomId = intent.getStringExtra(EXTRA_ROOM_ID); // ensure that the preview mode is really expected if (!intent.hasExtra(EXTRA_ROOM_PREVIEW_ID)) { sRoomPreviewData = null; Matrix.getInstance(this).clearTmpStoresList(); } if (CommonActivityUtils.isGoingToSplash(this, mSession.getMyUserId(), roomId)) { Log.d(LOG_TAG, "onCreate : Going to splash screen"); return; } //setDragEdge(SwipeBackLayout.DragEdge.LEFT); // bind the widgets of the room header view. The room header view is displayed by // clicking on the title of the action bar mRoomHeaderView = (RelativeLayout) findViewById(R.id.action_bar_header); mActionBarHeaderRoomTopic = (TextView) findViewById(R.id.action_bar_header_room_topic); mActionBarHeaderRoomName = (TextView) findViewById(R.id.action_bar_header_room_title); mActionBarHeaderActiveMembers = (TextView) findViewById(R.id.action_bar_header_room_members); mActionBarHeaderRoomAvatar = (ImageView) mRoomHeaderView.findViewById(R.id.avatar_img); mActionBarHeaderInviteMemberView = mRoomHeaderView.findViewById(R.id.action_bar_header_invite_members); mRoomPreviewLayout = findViewById(R.id.room_preview_info_layout); mVectorPendingCallView = (VectorPendingCallView) findViewById(R.id.room_pending_call_view); mVectorOngoingConferenceCallView = (VectorOngoingConferenceCallView) findViewById( R.id.room_ongoing_conference_call_view); mE2eImageView = (ImageView) findViewById(R.id.room_encrypted_image_view); // hide the header room as soon as the bottom layout (text edit zone) is touched findViewById(R.id.room_bottom_layout).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { enableActionBarHeader(HIDE_ACTION_BAR_HEADER); return false; } }); // use a toolbar instead of the actionbar // to be able to display an expandable header mToolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.room_toolbar); this.setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // set the default custom action bar layout, // that will be displayed from the custom action bar layout setActionBarDefaultCustomLayout(); mCallId = intent.getStringExtra(EXTRA_START_CALL_ID); mEventId = intent.getStringExtra(EXTRA_EVENT_ID); mDefaultRoomName = intent.getStringExtra(EXTRA_DEFAULT_NAME); mDefaultTopic = intent.getStringExtra(EXTRA_DEFAULT_TOPIC); // the user has tapped on the "View" notification button if ((null != intent.getAction()) && (intent.getAction().startsWith(NotificationUtils.TAP_TO_VIEW_ACTION))) { // remove any pending notifications NotificationManager notificationsManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationsManager.cancelAll(); } Log.d(LOG_TAG, "Displaying " + roomId); mEditText = (EditText) findViewById(R.id.editText_messageBox); // hide the header room as soon as the message input text area is touched mEditText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { enableActionBarHeader(HIDE_ACTION_BAR_HEADER); } }); // IME's DONE button is treated as a send action mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { int imeActionId = actionId & EditorInfo.IME_MASK_ACTION; if (EditorInfo.IME_ACTION_DONE == imeActionId) { sendTextMessage(); } return false; } }); mSendingMessagesLayout = findViewById(R.id.room_sending_message_layout); mSendImageView = (ImageView) findViewById(R.id.room_send_image_view); mSendButtonLayout = findViewById(R.id.room_send_layout); mSendButtonLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!TextUtils.isEmpty(mEditText.getText())) { sendTextMessage(); } else { // hide the header room enableActionBarHeader(HIDE_ACTION_BAR_HEADER); FragmentManager fm = getSupportFragmentManager(); IconAndTextDialogFragment fragment = (IconAndTextDialogFragment) fm .findFragmentByTag(TAG_FRAGMENT_ATTACHMENTS_DIALOG); if (fragment != null) { fragment.dismissAllowingStateLoss(); } final Integer[] messages = new Integer[] { R.string.option_send_files, R.string.option_take_photo_video, }; final Integer[] icons = new Integer[] { R.drawable.ic_material_file, // R.string.option_send_files R.drawable.ic_material_camera, // R.string.option_take_photo }; fragment = IconAndTextDialogFragment.newInstance(icons, messages, null, ContextCompat.getColor(VectorRoomActivity.this, R.color.vector_text_black_color)); fragment.setOnClickListener(new IconAndTextDialogFragment.OnItemClickListener() { @Override public void onItemClick(IconAndTextDialogFragment dialogFragment, int position) { Integer selectedVal = messages[position]; if (selectedVal == R.string.option_send_files) { VectorRoomActivity.this.launchFileSelectionIntent(); } else if (selectedVal == R.string.option_take_photo_video) { if (CommonActivityUtils.checkPermissions( CommonActivityUtils.REQUEST_CODE_PERMISSION_TAKE_PHOTO, VectorRoomActivity.this)) { launchCamera(); } } } }); fragment.show(fm, TAG_FRAGMENT_ATTACHMENTS_DIALOG); } } }); mEditText.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(android.text.Editable s) { if (null != mRoom) { MXLatestChatMessageCache latestChatMessageCache = VectorRoomActivity.this.mLatestChatMessageCache; String textInPlace = latestChatMessageCache.getLatestText(VectorRoomActivity.this, mRoom.getRoomId()); // check if there is really an update // avoid useless updates (initializations..) if (!mIgnoreTextUpdate && !textInPlace.equals(mEditText.getText().toString())) { latestChatMessageCache.updateLatestMessage(VectorRoomActivity.this, mRoom.getRoomId(), mEditText.getText().toString()); handleTypingNotification(mEditText.getText().length() != 0); } manageSendMoreButtons(); refreshCallButtons(); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); mVectorPendingCallView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { IMXCall call = VectorCallViewActivity.getActiveCall(); if (null != call) { final Intent intent = new Intent(VectorRoomActivity.this, VectorCallViewActivity.class); intent.putExtra(VectorCallViewActivity.EXTRA_MATRIX_ID, call.getSession().getCredentials().userId); intent.putExtra(VectorCallViewActivity.EXTRA_CALL_ID, call.getCallId()); VectorRoomActivity.this.runOnUiThread(new Runnable() { @Override public void run() { VectorRoomActivity.this.startActivity(intent); } }); } else { // if the call is no more active, just remove the view mVectorPendingCallView.onCallTerminated(); } } }); mActionBarHeaderInviteMemberView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { launchRoomDetails(VectorRoomDetailsActivity.PEOPLE_TAB_INDEX); } }); // notifications area mNotificationsArea = findViewById(R.id.room_notifications_area); mNotificationIconImageView = (ImageView) mNotificationsArea.findViewById(R.id.room_notification_icon); mNotificationTextView = (TextView) mNotificationsArea.findViewById(R.id.room_notification_message); mCanNotPostTextView = findViewById(R.id.room_cannot_post_textview); // increase the clickable area to open the keyboard. // when there is no text, it is quite small and some user thought the edition was disabled. findViewById(R.id.room_sending_message_layout).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mEditText.requestFocus()) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT); } } }); mStartCallLayout = findViewById(R.id.room_start_call_layout); mStartCallLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if ((null != mRoom) && mRoom.isEncrypted() && (mRoom.getActiveMembers().size() > 2)) { // display the dialog with the info text AlertDialog.Builder permissionsInfoDialog = new AlertDialog.Builder(VectorRoomActivity.this); Resources resource = getResources(); permissionsInfoDialog .setMessage(resource.getString(R.string.room_no_conference_call_in_encrypted_rooms)); permissionsInfoDialog.setIcon(android.R.drawable.ic_dialog_alert); permissionsInfoDialog.setPositiveButton(resource.getString(R.string.ok), null); permissionsInfoDialog.show(); } else if (isUserAllowedToStartConfCall()) { displayVideoCallIpDialog(); } else { displayConfCallNotAllowed(); } } }); mStopCallLayout = findViewById(R.id.room_end_call_layout); mStopCallLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { IMXCall call = mSession.mCallsManager.getCallWithRoomId(mRoom.getRoomId()); if (null != call) { call.hangup(null); } } }); findViewById(R.id.room_button_margin_right).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // extend the right side of right button // to avoid clicking in the void if (mStopCallLayout.getVisibility() == View.VISIBLE) { mStopCallLayout.performClick(); } else if (mStartCallLayout.getVisibility() == View.VISIBLE) { mStartCallLayout.performClick(); } else if (mSendButtonLayout.getVisibility() == View.VISIBLE) { mSendButtonLayout.performClick(); } } }); mMyUserId = mSession.getCredentials().userId; CommonActivityUtils.resumeEventStream(this); mRoom = mSession.getDataHandler().getRoom(roomId, false); FragmentManager fm = getSupportFragmentManager(); mVectorMessageListFragment = (VectorMessageListFragment) fm .findFragmentByTag(TAG_FRAGMENT_MATRIX_MESSAGE_LIST); if (mVectorMessageListFragment == null) { Log.d(LOG_TAG, "Create VectorMessageListFragment"); // this fragment displays messages and handles all message logic mVectorMessageListFragment = VectorMessageListFragment.newInstance(mMyUserId, roomId, mEventId, (null == sRoomPreviewData) ? null : VectorMessageListFragment.PREVIEW_MODE_READ_ONLY, org.matrix.androidsdk.R.layout.fragment_matrix_message_list_fragment); fm.beginTransaction().add(R.id.anchor_fragment_messages, mVectorMessageListFragment, TAG_FRAGMENT_MATRIX_MESSAGE_LIST).commit(); } else { Log.d(LOG_TAG, "Reuse VectorMessageListFragment"); } mVectorRoomMediasSender = new VectorRoomMediasSender(this, mVectorMessageListFragment, Matrix.getInstance(this).getMediasCache()); mVectorRoomMediasSender.onRestoreInstanceState(savedInstanceState); manageRoomPreview(); addRoomHeaderClickListeners(); // in timeline mode (i.e search in the forward and backward room history) // or in room preview mode // the edition items are not displayed if (!TextUtils.isEmpty(mEventId) || (null != sRoomPreviewData)) { mNotificationsArea.setVisibility(View.GONE); findViewById(R.id.bottom_separator).setVisibility(View.GONE); findViewById(R.id.room_notification_separator).setVisibility(View.GONE); findViewById(R.id.room_notifications_area).setVisibility(View.GONE); View v = findViewById(R.id.room_bottom_layout); ViewGroup.LayoutParams params = v.getLayoutParams(); params.height = 0; v.setLayoutParams(params); } mLatestChatMessageCache = Matrix.getInstance(this).getDefaultLatestChatMessageCache(); // some medias must be sent while opening the chat if (intent.hasExtra(EXTRA_ROOM_INTENT)) { final Intent mediaIntent = intent.getParcelableExtra(EXTRA_ROOM_INTENT); // sanity check if (null != mediaIntent) { mEditText.postDelayed(new Runnable() { @Override public void run() { intent.removeExtra(EXTRA_ROOM_INTENT); sendMediasIntent(mediaIntent); } }, 1000); } } mVectorOngoingConferenceCallView.initRoomInfo(mSession, mRoom); mVectorOngoingConferenceCallView .setCallClickListener(new VectorOngoingConferenceCallView.ICallClickListener() { private void startCall(boolean isVideo) { if (CommonActivityUtils.checkPermissions( isVideo ? CommonActivityUtils.REQUEST_CODE_PERMISSION_VIDEO_IP_CALL : CommonActivityUtils.REQUEST_CODE_PERMISSION_AUDIO_IP_CALL, VectorRoomActivity.this)) { startIpCall(isVideo); } } @Override public void onVoiceCallClick() { startCall(false); } @Override public void onVideoCallClick() { startCall(true); } }); View avatarLayout = findViewById(R.id.room_self_avatar); if (null != avatarLayout) { mAvatarImageView = (ImageView) avatarLayout.findViewById(R.id.avatar_img); } refreshSelfAvatar(); // in case a "Send as" dialog was in progress when the activity was destroyed (life cycle) mVectorRoomMediasSender.resumeResizeMediaAndSend(); // header visibility has launched enableActionBarHeader(intent.getBooleanExtra(EXTRA_EXPAND_ROOM_HEADER, false) ? SHOW_ACTION_BAR_HEADER : HIDE_ACTION_BAR_HEADER); // the both flags are only used once intent.removeExtra(EXTRA_EXPAND_ROOM_HEADER); Log.d(LOG_TAG, "End of create"); }