List of usage examples for android.app Activity getApplicationContext
@Override
public Context getApplicationContext()
From source file:Main.java
public static File createFile(Activity activity, String name, boolean isThumbnail) { // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. String subDir;/*from www . j ava2 s .c om*/ String fileType; if (isThumbnail) { subDir = "/thumbnails"; fileType = "thumbnail_"; } else { subDir = "/backgrounds"; fileType = "background_"; } File storageDir = new File(Environment.getExternalStorageDirectory() + "/Android/data/" + activity.getApplicationContext().getPackageName() + subDir); // Create the storage directory if it does not exist if (!storageDir.exists()) { if (!storageDir.mkdirs()) { return null; } } File thumbnailFile; String thumbnailName = fileType + name; thumbnailFile = new File(storageDir.getPath() + File.separator + thumbnailName); return thumbnailFile; }
From source file:de.uni_koblenz_landau.apow.PatientListActivity.java
/** * Start scanning for NFC tags.//from w w w . ja va 2 s .c om * @param activity The Activity requesting to the foreground dispatch. * @param adapter The NfcAdapter used for the foreground dispatch. */ private static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) { if (adapter != null) { // Add intents for NFC. final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass()); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0); IntentFilter[] filters = new IntentFilter[1]; String[][] techList = new String[][] {}; filters[0] = new IntentFilter(); filters[0].addAction(NfcAdapter.ACTION_TAG_DISCOVERED); filters[0].addCategory(Intent.CATEGORY_DEFAULT); adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList); } }
From source file:de.baumann.browser.helper.helper_webView.java
@SuppressLint("SetJavaScriptEnabled") public static void webView_Settings(final Activity from, final WebView webView) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from); String fontSizeST = sharedPref.getString("font", "100"); int fontSize = Integer.parseInt(fontSizeST); webView.getSettings().setAppCachePath(from.getApplicationContext().getCacheDir().getAbsolutePath()); webView.getSettings().setAppCacheEnabled(true); webView.getSettings().setMixedContentMode(MIXED_CONTENT_COMPATIBILITY_MODE); webView.getSettings().setAllowFileAccess(true); webView.getSettings().setAllowContentAccess(true); webView.getSettings().setBuiltInZoomControls(true); webView.getSettings().setDisplayZoomControls(false); webView.getSettings().setDomStorageEnabled(true); webView.getSettings().setTextZoom(fontSize); webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING); webView.getSettings().setUseWideViewPort(true); webView.getSettings().setLoadWithOverviewMode(true); from.registerForContextMenu(webView); if (sharedPref.getString("nav", "2").equals("1") || sharedPref.getString("nav", "2").equals("3")) { helper_webView.webView_Touch(from, webView); }// w ww .j a v a 2s .c om if (sharedPref.getString("cookie", "1").equals("2") || sharedPref.getString("cookie", "1").equals("3")) { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptThirdPartyCookies(webView, true); } else { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptThirdPartyCookies(webView, false); } if (sharedPref.getString("started", "").equals("yes")) { if (sharedPref.getString("java_string", "True").equals(from.getString(R.string.app_yes))) { webView.getSettings().setJavaScriptEnabled(true); sharedPref.edit().putString("java_string", from.getString(R.string.app_yes)).apply(); } else { webView.getSettings().setJavaScriptEnabled(false); sharedPref.edit().putString("java_string", from.getString(R.string.app_no)).apply(); } if (sharedPref.getString("pictures_string", "True").equals(from.getString(R.string.app_yes))) { webView.getSettings().setLoadsImagesAutomatically(true); sharedPref.edit().putString("pictures_string", from.getString(R.string.app_yes)).apply(); } else { webView.getSettings().setLoadsImagesAutomatically(false); sharedPref.edit().putString("pictures_string", from.getString(R.string.app_no)).apply(); } if (sharedPref.getString("loc_string", "True").equals(from.getString(R.string.app_yes))) { webView.getSettings().setGeolocationEnabled(true); helper_main.grantPermissionsLoc(from); sharedPref.edit().putString("loc_string", from.getString(R.string.app_yes)).apply(); } else { webView.getSettings().setGeolocationEnabled(false); sharedPref.edit().putString("loc_string", from.getString(R.string.app_no)).apply(); } if (sharedPref.getString("cookie_string", "True").equals(from.getString(R.string.app_yes))) { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); sharedPref.edit().putString("cookie_string", from.getString(R.string.app_yes)).apply(); } else { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(false); sharedPref.edit().putString("cookie_string", from.getString(R.string.app_no)).apply(); } } else { if (sharedPref.getBoolean("java", false)) { webView.getSettings().setJavaScriptEnabled(true); sharedPref.edit().putString("java_string", from.getString(R.string.app_yes)).apply(); } else { webView.getSettings().setJavaScriptEnabled(false); sharedPref.edit().putString("java_string", from.getString(R.string.app_no)).apply(); } if (sharedPref.getBoolean("pictures", false)) { webView.getSettings().setLoadsImagesAutomatically(true); sharedPref.edit().putString("pictures_string", from.getString(R.string.app_yes)).apply(); } else { webView.getSettings().setLoadsImagesAutomatically(false); sharedPref.edit().putString("pictures_string", from.getString(R.string.app_no)).apply(); } if (sharedPref.getBoolean("loc", false)) { webView.getSettings().setGeolocationEnabled(true); helper_main.grantPermissionsLoc(from); sharedPref.edit().putString("loc_string", from.getString(R.string.app_yes)).apply(); } else { webView.getSettings().setGeolocationEnabled(false); sharedPref.edit().putString("loc_string", from.getString(R.string.app_no)).apply(); } if (sharedPref.getString("cookie", "1").equals("1") || sharedPref.getString("cookie", "1").equals("3")) { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); sharedPref.edit().putString("cookie_string", from.getString(R.string.app_yes)).apply(); } else { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(false); sharedPref.edit().putString("cookie_string", from.getString(R.string.app_no)).apply(); } } }
From source file:com.example.mynsocial.BluetoothChat.java
public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) { Log.i(TAG, "---------------------------------------"); final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass()); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);/*from w ww .j a v a 2s .c o m*/ String[][] techList = new String[][] {}; adapter.enableForegroundDispatch(activity, pendingIntent, null, techList); }
From source file:com.desno365.mods.DesnoUtils.java
public static void changeStartAnimations(Activity activity) { Context currentContext = activity.getApplicationContext(); switch (Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(currentContext) .getString("selected_animations", "0"))) { case 0://ww w . j av a 2s. c o m break; case 1: overrideStartActivityAnimation(activity, R.anim.abc_slide_in_bottom); break; case 2: overrideStartActivityAnimation(activity, R.anim.scale_from_corner); break; case 3: overrideStartActivityAnimation(activity, R.anim.shrink_and_rotate_enter); break; } }
From source file:com.desno365.mods.DesnoUtils.java
public static void changeFinishAnimations(Activity activity) { Context currentContext = activity.getApplicationContext(); switch (Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(currentContext) .getString("selected_animations", "0"))) { case 0:/*from w ww . j a v a 2s.c o m*/ break; case 1: overrideFinishActivityAnimation(activity, R.anim.push_down_out); break; case 2: overrideFinishActivityAnimation(activity, R.anim.scale_towards_corner); break; case 3: overrideFinishActivityAnimation(activity, R.anim.shrink_and_rotate_exit); break; } }
From source file:ru.appsm.inapphelp.IAHHelpDesk.java
/** * * Open support for push data. Special cordova method. * * @param data//from w w w . ja v a 2s.c om * @param activity */ public static void OpenSupportForData(JSONObject data, Activity activity) { Log.i(TAG, "handle push"); if (data != null && data.has("secretkey") && data.has("userid") && data.has("appkey") && data.has("appid") && data.has("email") && data.has("message") && data.has("title") && data.has("notId") && data.has("msgId")) { try { Intent notificationIntent = new Intent(activity.getApplicationContext(), IssueDetailActivity.class); notificationIntent.putExtra("fromPush", true); notificationIntent.putExtra("userid", data.getString("userid")); notificationIntent.putExtra("appid", data.getString("appid")); notificationIntent.putExtra("appkey", data.getString("appkey")); notificationIntent.putExtra("secretkey", data.getString("secretkey")); notificationIntent.putExtra("email", data.getString("email")); notificationIntent.putExtra("msgId", data.getString("msgId")); activity.startActivity(notificationIntent); } catch (JSONException e) { Log.i(TAG, "Fail to parse push data"); } } else { Log.i(TAG, "Empty or wrong push data"); } }
From source file:net.kourlas.voipms_sms.activities.ConversationActivity.java
public static void sendMessage(Activity sourceActivity, long databaseId) { Context applicationContext = sourceActivity.getApplicationContext(); Database database = Database.getInstance(applicationContext); Preferences preferences = Preferences.getInstance(applicationContext); Message message = database.getMessageWithDatabaseId(preferences.getDid(), databaseId); SendMessageTask task = new SendMessageTask(sourceActivity.getApplicationContext(), message, sourceActivity); if (preferences.getEmail().equals("") || preferences.getPassword().equals("") || preferences.getDid().equals("")) { // Do not show an error; this method should never be called unless the email, password and DID are set task.cleanup(false);/*from ww w . j av a 2s . c om*/ return; } if (!Utils.isNetworkConnectionAvailable(applicationContext)) { Toast.makeText(applicationContext, applicationContext.getString(R.string.conversation_send_error_network), Toast.LENGTH_SHORT) .show(); task.cleanup(false); return; } try { String voipUrl = "https://www.voip.ms/api/v1/rest.php?" + "api_username=" + URLEncoder.encode(preferences.getEmail(), "UTF-8") + "&" + "api_password=" + URLEncoder.encode(preferences.getPassword(), "UTF-8") + "&" + "method=sendSMS" + "&" + "did=" + URLEncoder.encode(preferences.getDid(), "UTF-8") + "&" + "dst=" + URLEncoder.encode(message.getContact(), "UTF-8") + "&" + "message=" + URLEncoder.encode(message.getText(), "UTF-8"); task.start(voipUrl); } catch (UnsupportedEncodingException ex) { // This should never happen since the encoding (UTF-8) is hardcoded throw new Error(ex); } }
From source file:de.baumann.hhsmoodle.helper.helper_main.java
public static void makeToast(Activity activity, String Text) { LayoutInflater inflater = activity.getLayoutInflater(); View toastLayout = inflater.inflate(R.layout.toast, (ViewGroup) activity.findViewById(R.id.toast_root_view)); TextView header = (TextView) toastLayout.findViewById(R.id.toast_message); header.setText(Text);/*ww w . j a v a2 s . c o m*/ Toast toast = new Toast(activity.getApplicationContext()); toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(toastLayout); toast.show(); }
From source file:de.uni_koblenz_landau.apow.LoginActivity.java
/** * Start scanning for NFC tags./*from www. j a v a2 s.c o m*/ * @param activity The Activity requesting to the foreground dispatch. * @param adapter The NfcAdapter used for the foreground dispatch. */ private static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) { if (adapter != null) { // Add intents for NFC. final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass()); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0); IntentFilter[] filters = new IntentFilter[1]; String[][] techList = new String[][] {}; filters[0] = new IntentFilter(); filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED); filters[0].addCategory(Intent.CATEGORY_DEFAULT); try { filters[0].addDataType(MIME_TEXT_PLAIN); } catch (MalformedMimeTypeException e) { e.printStackTrace(); } adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList); } }