List of usage examples for android.preference PreferenceManager setDefaultValues
public static void setDefaultValues(Context context, @XmlRes int resId, boolean readAgain)
From source file:org.appspot.apprtc.CallActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Thread.setDefaultUncaughtExceptionHandler(new UnhandledExceptionHandler(this)); // Set window styles for fullscreen-window size. Needs to be done before // adding content. requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON | LayoutParams.FLAG_DISMISS_KEYGUARD | LayoutParams.FLAG_SHOW_WHEN_LOCKED | LayoutParams.FLAG_TURN_SCREEN_ON); getWindow().getDecorView()/*from w w w. j a v a 2s.c om*/ .setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); setContentView(R.layout.activity_call); mIntentFilter = new IntentFilter(); mIntentFilter.addAction(WebsocketService.ACTION_BYE); mIntentFilter.addAction(WebsocketService.ACTION_USER_ENTERED); mIntentFilter.addAction(WebsocketService.ACTION_USER_LEFT); mIntentFilter.addAction(WebsocketService.ACTION_SCREENSHARE); mIntentFilter.addAction(CustomPhoneStateListener.ACTION_HOLD_ON); mIntentFilter.addAction(CustomPhoneStateListener.ACTION_HOLD_OFF); mIntentFilter.addAction(WebsocketService.ACTION_CHAT_MESSAGE); mIntentFilter.addAction(WebsocketService.ACTION_FILE_MESSAGE); registerReceiver(mReceiver, mIntentFilter); // Get setting keys. PreferenceManager.setDefaultValues(this, R.xml.webrtc_preferences, false); sharedPref = PreferenceManager.getDefaultSharedPreferences(this); keyprefVideoCallEnabled = getString(R.string.pref_videocall_key); keyprefScreencapture = getString(R.string.pref_screencapture_key); keyprefCamera2 = getString(R.string.pref_camera2_key); keyprefResolution = getString(R.string.pref_resolution_key); keyprefFps = getString(R.string.pref_fps_key); keyprefCaptureQualitySlider = getString(R.string.pref_capturequalityslider_key); keyprefVideoBitrateType = getString(R.string.pref_maxvideobitrate_key); keyprefVideoBitrateValue = getString(R.string.pref_maxvideobitratevalue_key); keyprefVideoCodec = getString(R.string.pref_videocodec_key); keyprefHwCodecAcceleration = getString(R.string.pref_hwcodec_key); keyprefCaptureToTexture = getString(R.string.pref_capturetotexture_key); keyprefFlexfec = getString(R.string.pref_flexfec_key); keyprefAudioBitrateType = getString(R.string.pref_startaudiobitrate_key); keyprefAudioBitrateValue = getString(R.string.pref_startaudiobitratevalue_key); keyprefAudioCodec = getString(R.string.pref_audiocodec_key); keyprefNoAudioProcessingPipeline = getString(R.string.pref_noaudioprocessing_key); keyprefAecDump = getString(R.string.pref_aecdump_key); keyprefOpenSLES = getString(R.string.pref_opensles_key); keyprefDisableBuiltInAec = getString(R.string.pref_disable_built_in_aec_key); keyprefDisableBuiltInAgc = getString(R.string.pref_disable_built_in_agc_key); keyprefDisableBuiltInNs = getString(R.string.pref_disable_built_in_ns_key); keyprefEnableLevelControl = getString(R.string.pref_enable_level_control_key); keyprefDisplayHud = getString(R.string.pref_displayhud_key); keyprefTracing = getString(R.string.pref_tracing_key); keyprefRoomServerUrl = getString(R.string.pref_room_server_url_key); keyprefEnableDataChannel = getString(R.string.pref_enable_datachannel_key); keyprefOrdered = getString(R.string.pref_ordered_key); keyprefMaxRetransmitTimeMs = getString(R.string.pref_max_retransmit_time_ms_key); keyprefMaxRetransmits = getString(R.string.pref_max_retransmits_key); keyprefDataProtocol = getString(R.string.pref_data_protocol_key); keyprefNegotiated = getString(R.string.pref_negotiated_key); keyprefDataId = getString(R.string.pref_data_id_key); readPrefs(); final Intent intent = getIntent(); if (intent.getAction().equals(WebsocketService.ACTION_REMOTE_ICE_CANDIDATE)) { finish(); // don't start the activity on this intent } else if (intent.getAction().equals(WebsocketService.ACTION_REMOTE_DESCRIPTION)) { SerializableSessionDescription sdp = (SerializableSessionDescription) intent .getSerializableExtra(WebsocketService.EXTRA_REMOTE_DESCRIPTION); mVideoCallEnabled = sdp.description.contains("m=video"); } iceConnected = false; signalingParameters = new SignalingParameters(WebsocketService.getIceServers(), initiator, "", "", "", null, null); scalingType = ScalingType.SCALE_ASPECT_FILL; // Create UI controls. localRender = (SurfaceViewRenderer) findViewById(R.id.local_video_view); screenshareRender = (SurfaceViewRenderer) findViewById(R.id.screenshare_video_view); remoteRenderScreen = (SurfaceViewRenderer) findViewById(R.id.remote_video_view); remoteRenderScreen2 = (SurfaceViewRenderer) findViewById(R.id.remote_video_view2); remoteRenderScreen3 = (SurfaceViewRenderer) findViewById(R.id.remote_video_view3); remoteRenderScreen4 = (SurfaceViewRenderer) findViewById(R.id.remote_video_view4); remoteVideoLabel = (TextView) findViewById(R.id.remote_video_label); remoteVideoLabel2 = (TextView) findViewById(R.id.remote_video_label2); remoteVideoLabel3 = (TextView) findViewById(R.id.remote_video_label3); remoteVideoLabel4 = (TextView) findViewById(R.id.remote_video_label4); remoteUserImage = (ImageView) findViewById(R.id.remote_user_image1); remoteUserImage2 = (ImageView) findViewById(R.id.remote_user_image2); remoteUserImage3 = (ImageView) findViewById(R.id.remote_user_image3); remoteUserImage4 = (ImageView) findViewById(R.id.remote_user_image4); remoteUserHoldStatus = (ImageView) findViewById(R.id.remote_user_hold_status); remoteUserHoldStatus2 = (ImageView) findViewById(R.id.remote_user_hold_status2); remoteUserHoldStatus3 = (ImageView) findViewById(R.id.remote_user_hold_status3); remoteUserHoldStatus4 = (ImageView) findViewById(R.id.remote_user_hold_status4); localRenderLayout = (PercentFrameLayout) findViewById(R.id.local_video_layout); screenshareRenderLayout = (PercentFrameLayout) findViewById(R.id.screenshare_video_layout); remoteRenderLayout = (PercentFrameLayout) findViewById(R.id.remote_video_layout); remoteRenderLayout2 = (PercentFrameLayout) findViewById(R.id.remote_video_layout2); remoteRenderLayout3 = (PercentFrameLayout) findViewById(R.id.remote_video_layout3); remoteRenderLayout4 = (PercentFrameLayout) findViewById(R.id.remote_video_layout4); initiateCallFragment = new InitiateCallFragment(); callListFragment = new CallListFragment(); callFragment = new CallFragment(); hudFragment = new HudFragment(); chatFragment = new ChatFragment(); screenshareRemoteView = new RemoteConnectionViews("screenshare", screenshareRenderLayout, screenshareRender, null, null, null); remoteViewsInUseList.add(new RemoteConnectionViews("remote 1", remoteRenderLayout, remoteRenderScreen, remoteUserImage, remoteVideoLabel, remoteUserHoldStatus)); // first one is always in use remoteViewsList.add(new RemoteConnectionViews("remote 2", remoteRenderLayout2, remoteRenderScreen2, remoteUserImage2, remoteVideoLabel2, remoteUserHoldStatus2)); remoteViewsList.add(new RemoteConnectionViews("remote 3", remoteRenderLayout3, remoteRenderScreen3, remoteUserImage3, remoteVideoLabel3, remoteUserHoldStatus3)); remoteViewsList.add(new RemoteConnectionViews("remote 4", remoteRenderLayout4, remoteRenderScreen4, remoteUserImage4, remoteVideoLabel4, remoteUserHoldStatus4)); // Show/hide call control fragment on view click. View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View view) { toggleCallControlFragmentVisibility(); } }; View.OnClickListener screenshareListener = new View.OnClickListener() { @Override public void onClick(View view) { maximizeScreenshare = !maximizeScreenshare; updateVideoView(); } }; localRender.setOnClickListener(listener); screenshareRender.setOnClickListener(screenshareListener); remoteRenderScreen.setOnClickListener(listener); remoteRenderScreen2.setOnClickListener(listener); remoteRenderScreen3.setOnClickListener(listener); remoteRenderScreen4.setOnClickListener(listener); remoteRenderers.add(remoteRenderScreen); // Create video renderers. if (rootEglBase == null) { rootEglBase = EglBase.create(); } localRender.init(rootEglBase.getEglBaseContext(), null); screenshareRender.init(rootEglBase.getEglBaseContext(), null); String saveRemoteVideoToFile = intent.getStringExtra(EXTRA_SAVE_REMOTE_VIDEO_TO_FILE); // When saveRemoteVideoToFile is set we save the video from the remote to a file. if (saveRemoteVideoToFile != null) { int videoOutWidth = intent.getIntExtra(EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_WIDTH, 0); int videoOutHeight = intent.getIntExtra(EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_HEIGHT, 0); try { videoFileRenderer = new VideoFileRenderer(saveRemoteVideoToFile, videoOutWidth, videoOutHeight, rootEglBase.getEglBaseContext()); remoteRenderers.add(videoFileRenderer); } catch (IOException e) { throw new RuntimeException("Failed to open video file for output: " + saveRemoteVideoToFile, e); } } remoteRenderScreen.init(rootEglBase.getEglBaseContext(), null); remoteRenderScreen2.init(rootEglBase.getEglBaseContext(), null); remoteRenderScreen3.init(rootEglBase.getEglBaseContext(), null); remoteRenderScreen4.init(rootEglBase.getEglBaseContext(), null); localRender.setZOrderMediaOverlay(true); localRender.setEnableHardwareScaler(true /* enabled */); screenshareRender.getHolder().setFormat(PixelFormat.TRANSLUCENT); screenshareRenderLayout.setVisibility(View.GONE); screenshareRender.setVisibility(View.GONE); if (intent.getAction().equals(ACTION_RESUME_CALL)) { iceConnected = true; } updateVideoView(); // If capturing format is not specified for screencapture, use screen resolution. if (screencaptureEnabled && mVideoWidth == 0 && mVideoHeight == 0) { DisplayMetrics displayMetrics = new DisplayMetrics(); WindowManager windowManager = (WindowManager) getApplication().getSystemService(Context.WINDOW_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { windowManager.getDefaultDisplay().getRealMetrics(displayMetrics); } mVideoWidth = displayMetrics.widthPixels; mVideoHeight = displayMetrics.heightPixels; } DataChannelParameters dataChannelParameters = null; if (mDataChannelEnabled) { dataChannelParameters = new DataChannelParameters(mOrdered, mMaxRetrMs, mMaxRetr, mProtocol, mNegotiated, mId); } peerConnectionParameters = new PeerConnectionParameters(mVideoCallEnabled, false, false, mVideoWidth, mVideoHeight, mCameraFps, mVideoStartBitrate, mVideoCodec, mHwCodecEnabled, mFlexfecEnabled, mAudioStartBitrate, mAudioCodec, mNoAudioProcessing, mAecDump, mUseOpenSLES, mDisableBuiltInAEC, mDisableBuiltInAGC, mDisableBuiltInNS, mEnableLevelControl, dataChannelParameters); commandLineRun = intent.getBooleanExtra(EXTRA_CMDLINE, false); runTimeMs = intent.getIntExtra(EXTRA_RUNTIME, 0); Log.d(TAG, "VIDEO_FILE: '" + intent.getStringExtra(EXTRA_VIDEO_FILE_AS_CAMERA) + "'"); // Create connection client. Use DirectRTCClient if room name is an IP otherwise use the // standard WebSocketRTCClient. //if (loopback || !DirectRTCClient.IP_PATTERN.matcher(roomId).matches()) { // appRtcClient = new WebSocketRTCClient(this); // } else { // Log.i(TAG, "Using DirectRTCClient because room name looks like an IP."); // appRtcClient = new DirectRTCClient(this); // } // Create connection parameters. //roomConnectionParameters = new RoomConnectionParameters(roomUri.toString(), roomId, loopback); // Create CPU monitor //cpuMonitor = new CpuMonitor(this); //hudFragment.setCpuMonitor(cpuMonitor); Bundle extras = intent.getExtras(); extras.putBoolean(CallActivity.EXTRA_VIDEO_CALL, mVideoCallEnabled); // Send intent arguments to fragments. chatFragment.setArguments(getIntent().getExtras()); initiateCallFragment.setArguments(extras); callFragment.setArguments(extras); callListFragment.setArguments(extras); hudFragment.setArguments(intent.getExtras()); // Activate call and HUD fragments and start the call. remoteUserImage.setVisibility(View.INVISIBLE); FragmentTransaction ft = getFragmentManager().beginTransaction(); if (intent.getAction().equals(ACTION_RESUME_CALL)) { ft.add(R.id.call_fragment_container, callFragment); } else { ft.add(R.id.call_fragment_container, initiateCallFragment); } ft.add(R.id.hud_fragment_container, hudFragment); ft.commit(); // For command line execution run connection for <runTimeMs> and exit. if (commandLineRun && runTimeMs > 0) { (new Handler()).postDelayed(new Runnable() { @Override public void run() { disconnect(); } }, runTimeMs); } if (!intent.getAction().equals(ACTION_RESUME_CALL)) { peerConnectionClient = PeerConnectionClient.getInstance(); PeerConnectionFactory.Options options = new PeerConnectionFactory.Options(); options.disableNetworkMonitor = true; peerConnectionClient.setPeerConnectionFactoryOptions(options); if (mForceTurn) { peerConnectionParameters.forceTurn = true; } peerConnectionClient.createPeerConnectionFactory(CallActivity.this, peerConnectionParameters, CallActivity.this); peerConnectionClient.setDataChannelCallback(this); ThumbnailsCacheManager.ThumbnailsCacheManagerInit(this); handleIntent(intent); if (screencaptureEnabled) { /*MediaProjectionManager mediaProjectionManager = (MediaProjectionManager) getApplication().getSystemService( Context.MEDIA_PROJECTION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { startActivityForResult( mediaProjectionManager.createScreenCaptureIntent(), CAPTURE_PERMISSION_REQUEST_CODE); }*/ } else { startCall(); } } else { mPeerId = intent.getStringExtra(EXTRA_PEER_ID); iceConnected = true; if (peerConnectionClient != null) { peerConnectionClient.updateActivity(this, this); peerConnectionClient.updateLocalRenderer(localRender); peerConnectionClient.updateRemoteRenderers(remoteRenderers); } } AddRunningIntent(); }
From source file:com.edible.ocr.CaptureActivity.java
/** * Gets values from shared preferences and sets the corresponding data members in this activity. *//*from w w w . ja v a 2s. c o m*/ private void retrievePreferences() { prefs = PreferenceManager.getDefaultSharedPreferences(this); // Retrieve from preferences, and set in this Activity, the language preferences PreferenceManager.setDefaultValues(this, R.xml.preferences, false); setSourceLanguage(prefs.getString(PreferencesActivity.KEY_SOURCE_LANGUAGE_PREFERENCE, CaptureActivity.DEFAULT_SOURCE_LANGUAGE_CODE)); setTargetLanguage(prefs.getString(PreferencesActivity.KEY_TARGET_LANGUAGE_PREFERENCE, CaptureActivity.DEFAULT_TARGET_LANGUAGE_CODE)); isTranslationActive = prefs.getBoolean(PreferencesActivity.KEY_TOGGLE_TRANSLATION, false); // Retrieve from preferences, and set in this Activity, the capture mode preference if (prefs.getBoolean(PreferencesActivity.KEY_CONTINUOUS_PREVIEW, CaptureActivity.DEFAULT_TOGGLE_CONTINUOUS)) { isContinuousModeActive = true; } else { isContinuousModeActive = false; } // Retrieve from preferences, and set in this Activity, the page segmentation mode preference String[] pageSegmentationModes = getResources().getStringArray(R.array.pagesegmentationmodes); String pageSegmentationModeName = prefs.getString(PreferencesActivity.KEY_PAGE_SEGMENTATION_MODE, pageSegmentationModes[0]); if (pageSegmentationModeName.equals(pageSegmentationModes[0])) { pageSegmentationMode = TessBaseAPI.PageSegMode.PSM_AUTO_OSD; } else if (pageSegmentationModeName.equals(pageSegmentationModes[1])) { pageSegmentationMode = TessBaseAPI.PageSegMode.PSM_AUTO; } else if (pageSegmentationModeName.equals(pageSegmentationModes[2])) { pageSegmentationMode = TessBaseAPI.PageSegMode.PSM_SINGLE_BLOCK; } else if (pageSegmentationModeName.equals(pageSegmentationModes[3])) { pageSegmentationMode = TessBaseAPI.PageSegMode.PSM_SINGLE_CHAR; } else if (pageSegmentationModeName.equals(pageSegmentationModes[4])) { pageSegmentationMode = TessBaseAPI.PageSegMode.PSM_SINGLE_COLUMN; } else if (pageSegmentationModeName.equals(pageSegmentationModes[5])) { pageSegmentationMode = TessBaseAPI.PageSegMode.PSM_SINGLE_LINE; } else if (pageSegmentationModeName.equals(pageSegmentationModes[6])) { pageSegmentationMode = TessBaseAPI.PageSegMode.PSM_SINGLE_WORD; } else if (pageSegmentationModeName.equals(pageSegmentationModes[7])) { pageSegmentationMode = TessBaseAPI.PageSegMode.PSM_SINGLE_BLOCK_VERT_TEXT; } else if (pageSegmentationModeName.equals(pageSegmentationModes[8])) { pageSegmentationMode = TessBaseAPI.PageSegMode.PSM_SPARSE_TEXT; } // Retrieve from preferences, and set in this Activity, the OCR engine mode String[] ocrEngineModes = getResources().getStringArray(R.array.ocrenginemodes); String ocrEngineModeName = prefs.getString(PreferencesActivity.KEY_OCR_ENGINE_MODE, ocrEngineModes[0]); if (ocrEngineModeName.equals(ocrEngineModes[0])) { ocrEngineMode = TessBaseAPI.OEM_TESSERACT_ONLY; } else if (ocrEngineModeName.equals(ocrEngineModes[1])) { ocrEngineMode = TessBaseAPI.OEM_CUBE_ONLY; } else if (ocrEngineModeName.equals(ocrEngineModes[2])) { ocrEngineMode = TessBaseAPI.OEM_TESSERACT_CUBE_COMBINED; } // Retrieve from preferences, and set in this Activity, the character blacklist and whitelist characterBlacklist = OcrCharacterHelper.getBlacklist(prefs, sourceLanguageCodeOcr); characterWhitelist = OcrCharacterHelper.getWhitelist(prefs, sourceLanguageCodeOcr); prefs.registerOnSharedPreferenceChangeListener(listener); beepManager.updatePrefs(); }