List of usage examples for android.app Activity getApplicationContext
@Override
public Context getApplicationContext()
From source file:com.dabay6.libraries.androidshared.ui.fragments.BaseFragment.java
/** * {@inheritDoc}//w w w . j av a2 s. c o m */ @Override public void onAttach(final Activity activity) { super.onAttach(activity); if (activity instanceof FragmentLifeCycleListener) { onFragmentLifeCycleListener = (FragmentLifeCycleListener) activity; onFragmentLifeCycleListener.onFragmentAttached(this); } context = activity.getApplicationContext(); }
From source file:com.android.settings.aoip.WidgetsConfiguration.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); mContext = activity.getApplicationContext(); IntentFilter filter = new IntentFilter(ACTION_SEND_ID); mContext.registerReceiver(mWidgetIdReceiver, filter); mAppWidgetManager = AppWidgetManager.getInstance(mContext); }
From source file:com.example.aula20141117.util.AmUtil.java
public String testarSuporteGooglePlayServicesNoDispositivo(Activity activityGeradoraDoPedido) { //implica import com.google.android.gms.common.GooglePlayServicesUtil; int resultado = GooglePlayServicesUtil .isGooglePlayServicesAvailable(activityGeradoraDoPedido.getApplicationContext()); String ret = ""; switch (resultado) { case ConnectionResult.API_UNAVAILABLE: ret = "API_UNAVAILABLE"; break;//from w ww .ja va2 s .co m case ConnectionResult.CANCELED: ret = "CANCELED"; break; case ConnectionResult.DEVELOPER_ERROR: ret = "DEVELOPER_ERROR"; break; case ConnectionResult.DRIVE_EXTERNAL_STORAGE_REQUIRED: ret = "DRIVE_EXTERNAL_STORAGE_REQUIRED"; break; case ConnectionResult.INTERNAL_ERROR: ret = "INTERNAL_ERROR"; break; case ConnectionResult.INTERRUPTED: ret = "INTERRUPTED"; break; case ConnectionResult.INVALID_ACCOUNT: ret = "INVALID_ACCOUNT"; break; case ConnectionResult.LICENSE_CHECK_FAILED: ret = "LICENSE_CHECK_FAILED"; break; case ConnectionResult.NETWORK_ERROR: ret = "NETWORK_ERROR"; break; case ConnectionResult.RESOLUTION_REQUIRED: ret = "RESOLUTION_REQUIRED"; break; case ConnectionResult.SERVICE_DISABLED: ret = "SERVICE_DISABLED"; break; case ConnectionResult.SERVICE_INVALID: ret = "SERVICE_INVALID"; break; case ConnectionResult.SERVICE_MISSING: ret = "SERVICE_MISSING"; break; case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: ret = "SERVICE_VERSION_UPDATE_REQUIRED"; break; case ConnectionResult.SIGN_IN_REQUIRED: ret = "SIGN_IN_REQUIRED"; break; case ConnectionResult.SUCCESS: ret = "SUCCESS"; break; case ConnectionResult.TIMEOUT: ret = "TIMEOUT"; break; default: ret = "UNKNOWN SITUATION !!"; break; }//switch return ret; }
From source file:uk.co.threeonefour.android.snowball.activities.game.LoadGameStateDialogFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); // Verify that the host activity implements the callback interface try {/*from w w w . j a v a 2 s . c om*/ // Instantiate the NoticeDialogListener so we can send events to the host listener = (LoadGameStateDialogListener) activity; gameStateDao = new FileGameStateDao(activity); dateFormat = android.text.format.DateFormat.getDateFormat(activity.getApplicationContext()); timeFormat = android.text.format.DateFormat.getTimeFormat(activity.getApplicationContext()); } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception throw new ClassCastException(activity.toString() + " must implement NoticeDialogListener"); } }
From source file:com.example.accountkitsample.ReverbUIManager.java
@Override @Nullable/*from w w w . j av a2 s. co m*/ public Fragment getFooterFragment(final LoginFlowState state) { final int progress; switch (state) { case PHONE_NUMBER_INPUT: case EMAIL_INPUT: progress = 1; break; case SENDING_CODE: case SENT_CODE: progress = 2; break; case CODE_INPUT: case EMAIL_VERIFY: progress = 3; break; case VERIFYING_CODE: progress = 4; break; case VERIFIED: progress = 5; break; case RESEND: case ERROR: case NONE: default: return null; } final ReverbFooterFragment fragment = new ReverbFooterFragment(); if (progress == 1) { fragment.setLoginType(loginType); fragment.setOnSwitchLoginTypeListener(new ReverbFooterFragment.OnSwitchLoginTypeListener() { @Override public void onSwitchLoginType() { if (listener == null) { return; } listener.onCancel(); final Activity activity = fragment.getActivity(); if (activity == null) { return; } final Context applicationContext = activity.getApplicationContext(); final LoginType newLoginType; switch (loginType) { case EMAIL: newLoginType = LoginType.PHONE; break; case PHONE: newLoginType = LoginType.EMAIL; break; default: return; } LocalBroadcastManager.getInstance(applicationContext).sendBroadcast( new Intent(SWITCH_LOGIN_TYPE_EVENT).putExtra(LOGIN_TYPE_EXTRA, newLoginType.name())); } }); } if (themeResourceId == R.style.AppLoginTheme_Reverb_A) { fragment.setProgressType(ReverbFooterFragment.ProgressType.BAR); } else if (themeResourceId == R.style.AppLoginTheme_Reverb_B || themeResourceId == R.style.AppLoginTheme_Reverb_C) { fragment.setProgressType(ReverbFooterFragment.ProgressType.DOTS); } fragment.setProgress(progress); return fragment; }
From source file:com.marpies.ane.facedetection.functions.DetectFacesFunction.java
@Override public FREObject call(FREContext context, FREObject[] args) { super.call(context, args); AIR.log("FaceDetection::detect"); final int callbackId = FREObjectUtils.getInt(args[1]); final Bitmap image; try {/*from www . j a va2 s. co m*/ image = BitmapDataUtils.getBitmap((FREBitmapData) args[0]); } catch (Exception e) { e.printStackTrace(); AIR.log("Error creating Bitmap out of FREBitmapData"); AIR.dispatchEvent(FaceDetectionEvent.FACE_DETECTION_ERROR, StringUtils.getEventErrorJSON(callbackId, "Error creating Bitmap out of FREBitmapData")); return null; } /* Mode (accuracy) */ final int accuracy = FREObjectUtils.getInt(args[2]); // Comes in as a ready-to-use value boolean detectOpenEyes = FREObjectUtils.getBoolean(args[3]); boolean detectSmile = FREObjectUtils.getBoolean(args[4]); final boolean prominentFaceOnly = FREObjectUtils.getBoolean(args[5]); /* Classification type (detect open eyes, detect smile) */ final int classification = (detectOpenEyes || detectSmile) ? FaceDetector.ALL_CLASSIFICATIONS : FaceDetector.NO_CLASSIFICATIONS; final Activity activity = AIR.getContext().getActivity(); new Thread(new Runnable() { @Override public void run() { AIR.log("Running FaceDetection in new thread"); FaceDetector.Builder fb = new FaceDetector.Builder(activity.getApplicationContext()); fb.setClassificationType(classification).setMode(accuracy).setTrackingEnabled(false) .setLandmarkType(FaceDetector.ALL_LANDMARKS) // We want to know about eye/mouth positions .setProminentFaceOnly(prominentFaceOnly); /* Wrap the detector in SafeFaceDetector */ final FaceDetector detector = fb.build(); Detector<Face> sd = new SafeFaceDetector(detector); if (!sd.isOperational()) { sd.release(); AIR.log("Error, detector is not operational."); AIR.dispatchEvent(FaceDetectionEvent.FACE_DETECTION_ERROR, "Detector is not operational. Dependencies may have not been downloaded yet. Please, try again later."); return; } /* Create Frame with bitmap */ final Frame frame = new Frame.Builder().setBitmap(image).build(); SparseArray<Face> faces = sd.detect(frame); /* Build faces JSONArray */ JSONArray facesResult = getFacesJSONArray(faces); dispatchResponse(facesResult, callbackId); sd.release(); } }).start(); return null; }
From source file:com.facebook.samples.loginsample.accountkit.ReverbUIManager.java
@Override @Nullable/*from w w w. j a v a2s. co m*/ public Fragment getFooterFragment(final LoginFlowState state) { final int progress; switch (state) { case PHONE_NUMBER_INPUT: case EMAIL_INPUT: progress = 1; break; case SENDING_CODE: case SENT_CODE: progress = 2; break; case CODE_INPUT: case EMAIL_VERIFY: case CONFIRM_ACCOUNT_VERIFIED: progress = 3; break; case VERIFYING_CODE: case CONFIRM_INSTANT_VERIFICATION_LOGIN: progress = 4; break; case VERIFIED: progress = 5; break; case RESEND: case ERROR: case NONE: default: return null; } final ReverbFooterFragment fragment = new ReverbFooterFragment(); if (progress == 1) { fragment.setLoginType(loginType); fragment.setOnSwitchLoginTypeListener(new ReverbFooterFragment.OnSwitchLoginTypeListener() { @Override public void onSwitchLoginType() { if (listener == null) { return; } listener.onCancel(); final Activity activity = fragment.getActivity(); if (activity == null) { return; } final Context applicationContext = activity.getApplicationContext(); final LoginType newLoginType; switch (loginType) { case EMAIL: newLoginType = LoginType.PHONE; break; case PHONE: newLoginType = LoginType.EMAIL; break; default: return; } LocalBroadcastManager.getInstance(applicationContext).sendBroadcast( new Intent(SWITCH_LOGIN_TYPE_EVENT).putExtra(LOGIN_TYPE_EXTRA, newLoginType.name())); } }); } if (themeResourceId == R.style.AppLoginTheme_Reverb_A) { fragment.setProgressType(ReverbFooterFragment.ProgressType.BAR); } else if (themeResourceId == R.style.AppLoginTheme_Reverb_B || themeResourceId == R.style.AppLoginTheme_Reverb_C) { fragment.setProgressType(ReverbFooterFragment.ProgressType.DOTS); } fragment.setProgress(progress); return fragment; }
From source file:com.tenforwardconsulting.cordova.bgloc.BackgroundGeolocationPlugin.java
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) { Activity activity = this.cordova.getActivity(); Context context = activity.getApplicationContext(); if (ACTION_START.equals(action)) { if (config == null) { callbackContext.error("Plugin not configured. Please call configure method first."); } else {//from w w w . jav a 2 s .co m registerActionReceiver(); startBackgroundService(); // startRecording(); callbackContext.success(); } return true; } else if (ACTION_STOP.equals(action)) { // stopRecording(); unregisterActionReceiver(); stopBackgroundService(); callbackContext.success(); return true; } else if (ACTION_CONFIGURE.equals(action)) { try { this.callbackContext = callbackContext; config = Config.fromJSONArray(data); persistConfiguration(config); Log.d(TAG, "bg service configured: " + config.toString()); // callbackContext.success(); //we cannot do this } catch (JSONException e) { callbackContext.error("Configuration error: " + e.getMessage()); } return true; } else if (ACTION_LOCATION_ENABLED_CHECK.equals(action)) { Log.d(TAG, "location services enabled check"); try { int isLocationEnabled = BackgroundGeolocationPlugin.isLocationEnabled(context) ? 1 : 0; callbackContext.success(isLocationEnabled); } catch (SettingNotFoundException e) { callbackContext.error("Location setting error occured"); } return true; } else if (ACTION_SHOW_LOCATION_SETTINGS.equals(action)) { showLocationSettings(); // TODO: call success/fail callback return true; } else if (REGISTER_MODE_CHANGED_RECEIVER.equals(action)) { this.locationModeChangeCallbackContext = callbackContext; registerLocationModeChangeReceiver(); // TODO: call success/fail callback return true; } else if (UNREGISTER_MODE_CHANGED_RECEIVER.equals(action)) { unregisterLocationModeChangeReceiver(); this.locationModeChangeCallbackContext = null; // TODO: call success/fail callback return true; } else if (ACTION_GET_ALL_LOCATIONS.equals(action)) { try { callbackContext.success(getAllLocations()); } catch (JSONException e) { callbackContext.error("Converting locations to JSON failed."); } return true; } else if (ACTION_DELETE_LOCATION.equals(action)) { try { deleteLocation(data.getInt(0)); callbackContext.success(); } catch (JSONException e) { callbackContext.error("Configuration error: " + e.getMessage()); } return true; } else if (ACTION_DELETE_ALL_LOCATIONS.equals(action)) { deleteAllLocations(); callbackContext.success(); return true; } else if (ACTION_GET_CONFIG.equals(action)) { try { callbackContext.success(retrieveConfiguration()); } catch (JSONException e) { callbackContext.error("Configuration error: " + e.getMessage()); } return true; } return false; }
From source file:org.openremote.android.console.util.AsyncResourceLoader.java
public AsyncResourceLoader(Activity activity) { this.activity = activity; /**/*from w w w. j a va2s . co m*/ * Start the retrieving our group from the ORB */ this.groupLoader = new AsyncGroupLoader(activity.getApplicationContext()); this.groupLoader.start(); this.orKeyStore = ORKeyStore.getInstance(activity); }
From source file:com.amazonaws.mobile.auth.google.GoogleSignInProvider.java
private boolean getPermissionsIfNecessary(final Activity activity) { if (ContextCompat.checkSelfPermission(activity.getApplicationContext(), Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) { this.activityWeakReference = new WeakReference<Activity>(activity); ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.GET_ACCOUNTS }, GET_ACCOUNTS_PERMISSION_REQUEST_CODE); return true; }// w ww . ja va 2 s. c o m return false; }