List of usage examples for android.app Activity getApplicationContext
@Override
public Context getApplicationContext()
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.FavouriteStopsFragment.java
/** * {@inheritDoc}/*from w w w . ja va 2 s. c o m*/ */ @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Cache the Activity instance. final Activity activity = getActivity(); // Get an instance of the SettingsDatabase. sd = SettingsDatabase.getInstance(activity.getApplicationContext()); // Determine the mode this Fragment should be in. isCreateShortcut = getArguments().getBoolean(ARG_CREATE_SHORTCUT); // Create the ListAdapter. if (isCreateShortcut) { ca = new FavouritesCursorAdapter(activity, android.R.layout.simple_list_item_2, null, new String[] { SettingsDatabase.FAVOURITE_STOPS_STOPNAME }, new int[] { android.R.id.text1 }, null); } else { ca = new FavouritesCursorAdapter(activity, R.layout.favouritestops_list_item, null, new String[] { SettingsDatabase.FAVOURITE_STOPS_STOPNAME }, new int[] { android.R.id.text1 }, this); } }
From source file:com.bilibili.boxing.utils.CameraPickerHelper.java
private void startCameraIntent(final Activity activity, final Fragment fragment, String subFolder, final String action, final int requestCode) { final String cameraOutDir = BoxingFileHelper.getExternalDCIM(subFolder); try {//from w w w . j av a 2s.c o m if (BoxingFileHelper.createFile(cameraOutDir)) { mOutputFile = new File(cameraOutDir, String.valueOf(System.currentTimeMillis()) + ".jpg"); mSourceFilePath = mOutputFile.getPath(); Intent intent = new Intent(action); Uri uri = getFileUri(activity.getApplicationContext(), mOutputFile); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); try { startActivityForResult(activity, fragment, intent, requestCode); } catch (ActivityNotFoundException ignore) { callbackError(); } } } catch (ExecutionException | InterruptedException e) { BoxingLog.d("create file" + cameraOutDir + " error."); } }
From source file:org.jboss.aerogear.android.authorization.oauth2.OAuth2AuthzModule.java
@Override public void requestAccess(final Activity activity, final Callback<String> callback) { final String state = UUID.randomUUID().toString(); final OAuth2AuthzService.AGAuthzServiceConnection connection = new OAuth2AuthzService.AGAuthzServiceConnection() { @Override/*from www . j av a 2s.c om*/ public void onServiceConnected(ComponentName className, IBinder iBinder) { super.onServiceConnected(className, iBinder); doRequestAccess(state, activity, callback, this); } }; activity.bindService(new Intent(activity.getApplicationContext(), OAuth2AuthzService.class), connection, Context.BIND_AUTO_CREATE); }
From source file:com.vinexs.eeb.receiver.BaseReceiverGCM.java
public void requestDeviceRegisterId(Activity activity, final String gcmSenderId) { ArrayList<String> permissionList = new ArrayList<>(); permissionList.add(Manifest.permission.INTERNET); permissionList.add(Manifest.permission.WAKE_LOCK); permissionList.add(Manifest.permission.GET_ACCOUNTS); permissionList.add(Manifest.permission.VIBRATE); permissionList.add("com.google.android.c2dm.permission.RECEIVE"); permissionList.add(activity.getPackageName() + ".permission.C2D_MESSAGE"); if (Utility.hasPermission(activity, permissionList)) { gcm = GoogleCloudMessaging.getInstance(activity.getApplicationContext()); String register_id;/* ww w. ja va2 s. c o m*/ try { register_id = gcm.register(gcmSenderId); if (!register_id.equals("")) { Log.d("GoogleCloudMessaging", "Register ID: " + register_id); handleReceivedRegisterId(register_id); } } catch (Exception e) { e.printStackTrace(); } } SharedPreferences setting = PreferenceManager.getDefaultSharedPreferences(activity); if (setting.getInt("notifyId", 0) == 0) { setting.edit().putInt("notifyId", new Random().nextInt(65535)).apply(); } }
From source file:com.roodie.materialmovies.views.activities.SettingsActivity.java
protected void setupBasicSettings(final Activity activity, final Intent intent, Preference themePreference, Preference onlyWiFiPreference, Preference animationsPreference) { themePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override//from w w w . j a va2 s . co m public boolean onPreferenceChange(Preference preference, Object newValue) { if (KEY_THEME.equals(preference.getKey())) { Utils.updateTheme(activity.getApplicationContext(), (String) newValue); TaskStackBuilder.create(activity).addNextIntent(new Intent(activity, WatchlistActivity.class)) .addNextIntent(intent).startActivities(); } return true; } }); setListPreferenceSummary((ListPreference) themePreference); ((CheckBoxPreference) onlyWiFiPreference) .setChecked(MMoviesPreferences.isLargeDataOverWifiOnly(activity.getApplicationContext())); ((CheckBoxPreference) animationsPreference) .setChecked(MMoviesPreferences.areAnimationsEnabled(activity.getApplicationContext())); }
From source file:org.deviceconnect.android.deviceplugin.demo.DemoSettingFragment.java
private void createShortcut() { Activity activity = getActivity(); if (activity == null) { return;//from w ww . j av a 2 s .c om } Context context = activity.getApplicationContext(); Intent shortcut = createDemoPageIntent(); ShortcutInfoCompat.Builder builder = new ShortcutInfoCompat.Builder(context, CAMERA_DEMO_SHORTCUT_ID) .setIcon(IconCompat.createWithResource(context, getShortcutIconResource(mDemoInstaller))) .setShortLabel(getShortcutShortLabel(mDemoInstaller)) .setLongLabel(getShortcutLongLabel(mDemoInstaller)).setIntent(shortcut); ComponentName mainActivity = getMainActivity(context); if (mainActivity != null) { builder.setActivity(mainActivity); } ShortcutInfoCompat info = builder.build(); boolean result = ShortcutManagerCompat.requestPinShortcut(context, info, null); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { // OS 8???OS??????????? if (result) { showShurtcutResult(getString(R.string.demo_page_settings_button_create_shortcut_success)); } else { showShurtcutResult(getString(R.string.demo_page_settings_button_create_shortcut_error)); } } }
From source file:com.mbientlab.metawear.tutorial.starter.DeviceSetupActivityFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Activity owner = getActivity(); if (!(owner instanceof FragmentSettings)) { throw new ClassCastException("Owning activity must implement the FragmentSettings interface"); }//from w w w .j ava 2 s. c om settings = (FragmentSettings) owner; owner.getApplicationContext().bindService(new Intent(owner, BtleService.class), this, Context.BIND_AUTO_CREATE); ctx = owner.getApplicationContext(); }
From source file:com.granita.tasks.ViewTaskFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); if (!(activity instanceof Callback)) { throw new IllegalStateException("Activity must implement TaskViewDetailFragment callback."); }//from w w w .j av a2s.com mCallback = (Callback) activity; mAppContext = activity.getApplicationContext(); }
From source file:com.apptentive.android.sdk.Apptentive.java
/** * Call this method from each of your Activities' onStop() methods. * * @param activity The Activity from which this method is called. *///w w w . ja v a2s . c om public static void onStop(Activity activity) { try { ActivityLifecycleManager.activityStopped(activity); runningActivities--; if (runningActivities < 0) { Log.e("Incorrect number of running Activities encountered. Resetting to 0. Did you make sure to call Apptentive.onStart() and Apptentive.onStop() in all your Activities?"); runningActivities = 0; } // If there are no running activities, wake the thread so it can stop immediately and gracefully. if (runningActivities == 0) { PayloadSendWorker.appWentToBackground(); MessagePollingWorker.appWentToBackground(); } } catch (Exception e) { Log.w("Error stopping Apptentive Activity.", e); MetricModule.sendError(activity.getApplicationContext(), e, null, null); } }
From source file:org.gluu.super_gluu.app.MainActivityFragment.java
private void showDialog(String message) { Activity activity = getActivity(); String textSuccess = getActivity().getApplicationContext().getString(R.string.auth_result_success); String textDeny = getActivity().getApplicationContext().getString(R.string.deny_result_success); String finalMessage = message; String finalTitle = ""; if (message.equalsIgnoreCase(textSuccess)) { finalMessage = activity.getApplicationContext().getString(R.string.auth_result_success); finalTitle = activity.getApplicationContext().getString(R.string.success); } else if (message.equalsIgnoreCase(textDeny)) { finalMessage = activity.getApplicationContext().getString(R.string.deny_result_success); finalTitle = activity.getApplicationContext().getString(R.string.failed); }/*from w ww . j a v a 2 s.c o m*/ final CustomGluuAlert gluuAlert = new CustomGluuAlert(activity); gluuAlert.setMessage(finalTitle); gluuAlert.setSub_title(finalMessage); gluuAlert.setYesTitle(activity.getApplicationContext().getString(R.string.ok)); gluuAlert.type = NotificationType.DEFAULT; gluuAlert.setmListener(new GluuMainActivity.GluuAlertCallback() { @Override public void onPositiveButton() { //Skip here } @Override public void onNegativeButton() { //Skip here } }); gluuAlert.show(); }