List of usage examples for android.content Context WIFI_SERVICE
String WIFI_SERVICE
To view the source code for android.content Context WIFI_SERVICE.
Click Source Link
From source file:android_network.hetnet.vpn_service.ActivitySettings.java
@Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); final PreferenceScreen screen = getPreferenceScreen(); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); PreferenceGroup cat_options = (PreferenceGroup) ((PreferenceGroup) screen.findPreference("screen_options")) .findPreference("category_options"); PreferenceGroup cat_advanced = (PreferenceGroup) ((PreferenceGroup) screen .findPreference("screen_advanced_options")).findPreference("category_advanced_options"); PreferenceGroup cat_stats = (PreferenceGroup) ((PreferenceGroup) screen.findPreference("screen_stats")) .findPreference("category_stats"); PreferenceGroup cat_backup = (PreferenceGroup) ((PreferenceGroup) screen.findPreference("screen_backup")) .findPreference("category_backup"); // Handle auto enable Preference pref_auto_enable = screen.findPreference("auto_enable"); pref_auto_enable.setTitle(getString(R.string.setting_auto, prefs.getString("auto_enable", "0"))); // Handle screen delay Preference pref_screen_delay = screen.findPreference("screen_delay"); pref_screen_delay.setTitle(getString(R.string.setting_delay, prefs.getString("screen_delay", "0"))); // Handle theme Preference pref_screen_theme = screen.findPreference("theme"); String theme = prefs.getString("theme", "teal"); String[] themeNames = getResources().getStringArray(R.array.themeNames); String[] themeValues = getResources().getStringArray(R.array.themeValues); for (int i = 0; i < themeNames.length; i++) if (theme.equals(themeValues[i])) { pref_screen_theme.setTitle(getString(R.string.setting_theme, themeNames[i])); break; }/* w w w. j a v a 2 s .co m*/ // Wi-Fi home MultiSelectListPreference pref_wifi_homes = (MultiSelectListPreference) screen.findPreference("wifi_homes"); Set<String> ssids = prefs.getStringSet("wifi_homes", new HashSet<String>()); if (ssids.size() > 0) pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, TextUtils.join(", ", ssids))); else pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, "-")); WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); List<CharSequence> listSSID = new ArrayList<>(); List<WifiConfiguration> configs = wm.getConfiguredNetworks(); if (configs != null) for (WifiConfiguration config : configs) listSSID.add(config.SSID == null ? "NULL" : config.SSID); for (String ssid : ssids) if (!listSSID.contains(ssid)) listSSID.add(ssid); pref_wifi_homes.setEntries(listSSID.toArray(new CharSequence[0])); pref_wifi_homes.setEntryValues(listSSID.toArray(new CharSequence[0])); Preference pref_reset_usage = screen.findPreference("reset_usage"); pref_reset_usage.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Util.areYouSure(ActivitySettings.this, R.string.setting_reset_usage, new Util.DoubtListener() { @Override public void onSure() { new AsyncTask<Object, Object, Throwable>() { @Override protected Throwable doInBackground(Object... objects) { try { DatabaseHelper.getInstance(ActivitySettings.this).resetUsage(-1); return null; } catch (Throwable ex) { return ex; } } @Override protected void onPostExecute(Throwable ex) { if (ex == null) Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG) .show(); else Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } }.execute(); } }); return false; } }); // Handle port forwarding Preference pref_forwarding = screen.findPreference("forwarding"); pref_forwarding.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivity(new Intent(ActivitySettings.this, ActivityForwarding.class)); return true; } }); // VPN parameters screen.findPreference("vpn4") .setTitle(getString(R.string.setting_vpn4, prefs.getString("vpn4", "10.1.10.1"))); screen.findPreference("vpn6") .setTitle(getString(R.string.setting_vpn6, prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1"))); EditTextPreference pref_dns1 = (EditTextPreference) screen.findPreference("dns"); EditTextPreference pref_dns2 = (EditTextPreference) screen.findPreference("dns2"); EditTextPreference pref_ttl = (EditTextPreference) screen.findPreference("ttl"); List<String> def_dns = Util.getDefaultDNS(this); pref_dns1.getEditText().setHint(def_dns.get(0)); pref_dns2.getEditText().setHint(def_dns.get(1)); pref_dns1.setTitle(getString(R.string.setting_dns, prefs.getString("dns", def_dns.get(0)))); pref_dns2.setTitle(getString(R.string.setting_dns, prefs.getString("dns2", def_dns.get(1)))); pref_ttl.setTitle(getString(R.string.setting_ttl, prefs.getString("ttl", "259200"))); // SOCKS5 parameters screen.findPreference("socks5_addr") .setTitle(getString(R.string.setting_socks5_addr, prefs.getString("socks5_addr", "-"))); screen.findPreference("socks5_port") .setTitle(getString(R.string.setting_socks5_port, prefs.getString("socks5_port", "-"))); screen.findPreference("socks5_username") .setTitle(getString(R.string.setting_socks5_username, prefs.getString("socks5_username", "-"))); screen.findPreference("socks5_password").setTitle(getString(R.string.setting_socks5_password, TextUtils.isEmpty(prefs.getString("socks5_username", "")) ? "-" : "*****")); // PCAP parameters screen.findPreference("pcap_record_size") .setTitle(getString(R.string.setting_pcap_record_size, prefs.getString("pcap_record_size", "64"))); screen.findPreference("pcap_file_size") .setTitle(getString(R.string.setting_pcap_file_size, prefs.getString("pcap_file_size", "2"))); // Watchdog screen.findPreference("watchdog") .setTitle(getString(R.string.setting_watchdog, prefs.getString("watchdog", "0"))); // Show resolved Preference pref_show_resolved = screen.findPreference("show_resolved"); if (Util.isPlayStoreInstall(this)) cat_advanced.removePreference(pref_show_resolved); else pref_show_resolved.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivity(new Intent(ActivitySettings.this, ActivityDns.class)); return true; } }); // Handle stats if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) cat_stats.removePreference(screen.findPreference("show_top")); EditTextPreference pref_stats_frequency = (EditTextPreference) screen.findPreference("stats_frequency"); EditTextPreference pref_stats_samples = (EditTextPreference) screen.findPreference("stats_samples"); pref_stats_frequency .setTitle(getString(R.string.setting_stats_frequency, prefs.getString("stats_frequency", "1000"))); pref_stats_samples .setTitle(getString(R.string.setting_stats_samples, prefs.getString("stats_samples", "90"))); // Handle export Preference pref_export = screen.findPreference("export"); pref_export.setEnabled(getIntentCreateExport().resolveActivity(getPackageManager()) != null); pref_export.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivityForResult(getIntentCreateExport(), ActivitySettings.REQUEST_EXPORT); return true; } }); // Handle import Preference pref_import = screen.findPreference("import"); pref_import.setEnabled(getIntentOpenExport().resolveActivity(getPackageManager()) != null); pref_import.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivityForResult(getIntentOpenExport(), ActivitySettings.REQUEST_IMPORT); return true; } }); // Hosts file settings Preference pref_block_domains = screen.findPreference("use_hosts"); EditTextPreference pref_rcode = (EditTextPreference) screen.findPreference("rcode"); Preference pref_hosts_import = screen.findPreference("hosts_import"); EditTextPreference pref_hosts_url = (EditTextPreference) screen.findPreference("hosts_url"); final Preference pref_hosts_download = screen.findPreference("hosts_download"); pref_rcode.setTitle(getString(R.string.setting_rcode, prefs.getString("rcode", "3"))); if (Util.isPlayStoreInstall(this)) { Log.i(TAG, "Play store install"); cat_options.removePreference(screen.findPreference("update_check")); cat_advanced.removePreference(pref_block_domains); cat_advanced.removePreference(pref_rcode); cat_advanced.removePreference(pref_forwarding); cat_backup.removePreference(pref_hosts_import); cat_backup.removePreference(pref_hosts_url); cat_backup.removePreference(pref_hosts_download); } else { String last_import = prefs.getString("hosts_last_import", null); String last_download = prefs.getString("hosts_last_download", null); if (last_import != null) pref_hosts_import.setSummary(getString(R.string.msg_import_last, last_import)); if (last_download != null) pref_hosts_download.setSummary(getString(R.string.msg_download_last, last_download)); // Handle hosts import // https://github.com/Free-Software-for-Android/AdAway/wiki/HostsSources pref_hosts_import.setEnabled(getIntentOpenHosts().resolveActivity(getPackageManager()) != null); pref_hosts_import.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivityForResult(getIntentOpenHosts(), ActivitySettings.REQUEST_HOSTS); return true; } }); // Handle hosts file download pref_hosts_url.setSummary(pref_hosts_url.getText()); pref_hosts_download.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { final File tmp = new File(getFilesDir(), "hosts.tmp"); final File hosts = new File(getFilesDir(), "hosts.txt"); EditTextPreference pref_hosts_url = (EditTextPreference) screen.findPreference("hosts_url"); try { new DownloadTask(ActivitySettings.this, new URL(pref_hosts_url.getText()), tmp, new DownloadTask.Listener() { @Override public void onCompleted() { if (hosts.exists()) hosts.delete(); tmp.renameTo(hosts); String last = SimpleDateFormat.getDateTimeInstance() .format(new Date().getTime()); prefs.edit().putString("hosts_last_download", last).apply(); if (running) { pref_hosts_download .setSummary(getString(R.string.msg_download_last, last)); Toast.makeText(ActivitySettings.this, R.string.msg_downloaded, Toast.LENGTH_LONG).show(); } ServiceSinkhole.reload("hosts file download", ActivitySettings.this); } @Override public void onCancelled() { if (tmp.exists()) tmp.delete(); } @Override public void onException(Throwable ex) { if (tmp.exists()) tmp.delete(); if (running) Toast.makeText(ActivitySettings.this, ex.getMessage(), Toast.LENGTH_LONG).show(); } }).execute(); } catch (MalformedURLException ex) { Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } return true; } }); } // Development if (!Util.isDebuggable(this)) screen.removePreference(screen.findPreference("screen_development")); // Handle technical info Preference.OnPreferenceClickListener listener = new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { updateTechnicalInfo(); return true; } }; // Technical info Preference pref_technical_info = screen.findPreference("technical_info"); Preference pref_technical_network = screen.findPreference("technical_network"); Preference pref_technical_subscription = screen.findPreference("technical_subscription"); pref_technical_info.setEnabled(INTENT_VPN_SETTINGS.resolveActivity(this.getPackageManager()) != null); pref_technical_info.setIntent(INTENT_VPN_SETTINGS); pref_technical_info.setOnPreferenceClickListener(listener); pref_technical_network.setOnPreferenceClickListener(listener); pref_technical_subscription.setOnPreferenceClickListener(listener); updateTechnicalInfo(); // markPro(screen.findPreference("theme"), ActivityPro.SKU_THEME); // markPro(screen.findPreference("install"), ActivityPro.SKU_NOTIFY); // markPro(screen.findPreference("show_stats"), ActivityPro.SKU_SPEED); }
From source file:com.mstar.tv.tvplayer.philips.option.OptionFirstFragment.java
private WifiManager getWifiManager() { if (mWifiManager == null) { mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); }//ww w.j a va 2 s . c o m return mWifiManager; }
From source file:com.connectsdk.discovery.DiscoveryManager.java
/** * Create a new instance of DiscoveryManager. * Direct use of this constructor is not recommended. In most cases, * you should use DiscoveryManager.getInstance() instead. *///from w w w . ja v a 2 s. c o m public DiscoveryManager(Context context, ConnectableDeviceStore connectableDeviceStore) { this.context = context; this.connectableDeviceStore = connectableDeviceStore; allDevices = new ConcurrentHashMap<String, ConnectableDevice>(8, 0.75f, 2); compatibleDevices = new ConcurrentHashMap<String, ConnectableDevice>(8, 0.75f, 2); deviceClasses = new ConcurrentHashMap<String, Class<? extends DeviceService>>(4, 0.75f, 2); discoveryProviders = new CopyOnWriteArrayList<DiscoveryProvider>(); discoveryListeners = new CopyOnWriteArrayList<DiscoveryManagerListener>(); WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); multicastLock = wifiMgr.createMulticastLock("Connect SDK"); multicastLock.setReferenceCounted(true); capabilityFilters = new ArrayList<CapabilityFilter>(); pairingLevel = PairingLevel.OFF; receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); switch (networkInfo.getState()) { case CONNECTED: if (mSearching) { for (DiscoveryProvider provider : discoveryProviders) { provider.start(); } } break; case DISCONNECTED: Log.w("Connect SDK", "Network connection is disconnected"); for (DiscoveryProvider provider : discoveryProviders) { provider.reset(); } allDevices.clear(); for (ConnectableDevice device : compatibleDevices.values()) { handleDeviceLoss(device); } compatibleDevices.clear(); for (DiscoveryProvider provider : discoveryProviders) { provider.stop(); } break; case CONNECTING: break; case DISCONNECTING: break; case SUSPENDED: break; case UNKNOWN: break; } } } }; registerBroadcastReceiver(); }
From source file:eu.faircode.adblocker.ActivitySettings.java
@Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); final PreferenceScreen screen = getPreferenceScreen(); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); PreferenceCategory cat_options = (PreferenceCategory) screen.findPreference("category_options"); PreferenceCategory cat_advanced = (PreferenceCategory) screen.findPreference("category_advanced_options"); PreferenceCategory cat_backup = (PreferenceCategory) screen.findPreference("category_backup"); PreferenceCategory cat_development = (PreferenceCategory) screen.findPreference("category_development"); // Handle auto enable Preference pref_auto_enable = screen.findPreference("auto_enable"); pref_auto_enable.setTitle(getString(R.string.setting_auto, prefs.getString("auto_enable", "0"))); // Handle screen delay Preference pref_screen_delay = screen.findPreference("screen_delay"); pref_screen_delay.setTitle(getString(R.string.setting_delay, prefs.getString("screen_delay", "0"))); // Handle theme Preference pref_screen_theme = screen.findPreference("theme"); String theme = prefs.getString("theme", "teal"); String[] themeNames = getResources().getStringArray(R.array.themeNames); String[] themeValues = getResources().getStringArray(R.array.themeValues); for (int i = 0; i < themeNames.length; i++) if (theme.equals(themeValues[i])) { pref_screen_theme.setTitle(getString(R.string.setting_theme, themeNames[i])); break; }/*from w ww. jav a 2s . c o m*/ // Wi-Fi home MultiSelectListPreference pref_wifi_homes = (MultiSelectListPreference) screen.findPreference("wifi_homes"); Set<String> ssid = prefs.getStringSet("wifi_homes", new HashSet<String>()); if (ssid.size() > 0) pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, TextUtils.join(", ", ssid))); else pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, "-")); WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); List<CharSequence> listSSID = new ArrayList<>(); List<WifiConfiguration> configs = wm.getConfiguredNetworks(); if (configs != null) for (WifiConfiguration config : configs) listSSID.add(config.SSID == null ? "NULL" : config.SSID); pref_wifi_homes.setEntries(listSSID.toArray(new CharSequence[0])); pref_wifi_homes.setEntryValues(listSSID.toArray(new CharSequence[0])); // Filtering always enabled // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) // cat_advanced.removePreference(screen.findPreference("filter")); Preference pref_reset_usage = screen.findPreference("reset_usage"); pref_reset_usage.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Util.areYouSure(ActivitySettings.this, R.string.setting_reset_usage, new Util.DoubtListener() { @Override public void onSure() { new AsyncTask<Object, Object, Throwable>() { @Override protected Throwable doInBackground(Object... objects) { try { DatabaseHelper.getInstance(ActivitySettings.this).resetUsage(-1); return null; } catch (Throwable ex) { return ex; } } @Override protected void onPostExecute(Throwable ex) { if (ex == null) Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG) .show(); else Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } }.execute(); } }); return false; } }); // Handle port forwarding Preference pref_forwarding = screen.findPreference("forwarding"); pref_forwarding.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivity(new Intent(ActivitySettings.this, ActivityForwarding.class)); return true; } }); // VPN parameters screen.findPreference("vpn4") .setTitle(getString(R.string.setting_vpn4, prefs.getString("vpn4", "10.1.10.1"))); screen.findPreference("vpn6") .setTitle(getString(R.string.setting_vpn6, prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1"))); EditTextPreference pref_dns = (EditTextPreference) screen.findPreference("dns"); List<String> def_dns = Util.getDefaultDNS(this); pref_dns.getEditText().setHint(def_dns.get(0)); pref_dns.setTitle(getString(R.string.setting_dns, prefs.getString("dns", def_dns.get(0)))); // PCAP parameters screen.findPreference("pcap_record_size") .setTitle(getString(R.string.setting_pcap_record_size, prefs.getString("pcap_record_size", "64"))); screen.findPreference("pcap_file_size") .setTitle(getString(R.string.setting_pcap_file_size, prefs.getString("pcap_file_size", "2"))); // Handle stats EditTextPreference pref_stats_frequency = (EditTextPreference) screen.findPreference("stats_frequency"); EditTextPreference pref_stats_samples = (EditTextPreference) screen.findPreference("stats_samples"); pref_stats_frequency .setTitle(getString(R.string.setting_stats_frequency, prefs.getString("stats_frequency", "1000"))); pref_stats_samples .setTitle(getString(R.string.setting_stats_samples, prefs.getString("stats_samples", "90"))); // Handle export Preference pref_export = screen.findPreference("export"); pref_export.setEnabled(getIntentCreateExport().resolveActivity(getPackageManager()) != null); pref_export.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivityForResult(getIntentCreateExport(), ActivitySettings.REQUEST_EXPORT); return true; } }); // Handle import Preference pref_import = screen.findPreference("import"); pref_import.setEnabled(getIntentOpenExport().resolveActivity(getPackageManager()) != null); pref_import.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivityForResult(getIntentOpenExport(), ActivitySettings.REQUEST_IMPORT); return true; } }); // Hosts file settings Preference pref_block_domains = screen.findPreference("use_hosts"); Preference pref_hosts_import = screen.findPreference("hosts_import"); EditTextPreference pref_hosts_url = (EditTextPreference) screen.findPreference("hosts_url"); final Preference pref_hosts_download = screen.findPreference("hosts_download"); if (Util.isPlayStoreInstall(this)) { cat_options.removePreference(screen.findPreference("update_check")); cat_advanced.removePreference(pref_block_domains); cat_advanced.removePreference(pref_forwarding); cat_backup.removePreference(pref_hosts_import); cat_backup.removePreference(pref_hosts_url); cat_backup.removePreference(pref_hosts_download); } else { try { AssetManager am = getAssets(); InputStream inputStream = getResources().openRawResource(R.raw.hosts); File hfile = createFileFromInputStream(inputStream); pref_block_domains.setEnabled(hfile.exists()); } catch (Exception e) { e.printStackTrace(); } String last_import = prefs.getString("hosts_last_import", null); String last_download = prefs.getString("hosts_last_download", null); if (last_import != null) pref_hosts_import.setSummary(getString(R.string.msg_import_last, last_import)); if (last_download != null) pref_hosts_download.setSummary(getString(R.string.msg_download_last, last_download)); // Handle hosts import // https://github.com/Free-Software-for-Android/AdAway/wiki/HostsSources pref_hosts_import.setEnabled(getIntentOpenHosts().resolveActivity(getPackageManager()) != null); pref_hosts_import.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivityForResult(getIntentOpenHosts(), ActivitySettings.REQUEST_HOSTS); return true; } }); // Handle hosts file download pref_hosts_url.setSummary(pref_hosts_url.getText()); pref_hosts_download.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { final File tmp = new File(getFilesDir(), "hosts.tmp"); final File hosts = new File(getFilesDir(), "host/hosts.txt"); EditTextPreference pref_hosts_url = (EditTextPreference) screen.findPreference("hosts_url"); try { new DownloadTask(ActivitySettings.this, new URL(pref_hosts_url.getText()), tmp, new DownloadTask.Listener() { @Override public void onCompleted() { if (hosts.exists()) hosts.delete(); tmp.renameTo(hosts); String last = SimpleDateFormat.getDateTimeInstance() .format(new Date().getTime()); prefs.edit().putString("hosts_last_download", last).apply(); if (running) { getPreferenceScreen().findPreference("use_hosts").setEnabled(true); pref_hosts_download .setSummary(getString(R.string.msg_download_last, last)); Toast.makeText(ActivitySettings.this, R.string.msg_downloaded, Toast.LENGTH_LONG).show(); } ServiceSinkhole.reload("hosts file download", ActivitySettings.this); } @Override public void onCancelled() { if (tmp.exists()) tmp.delete(); } @Override public void onException(Throwable ex) { if (tmp.exists()) tmp.delete(); if (running) Toast.makeText(ActivitySettings.this, ex.getMessage(), Toast.LENGTH_LONG).show(); } }).execute(); } catch (MalformedURLException ex) { Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } return true; } }); } // Development Preference pref_show_resolved = screen.findPreference("show_resolved"); if (!(Util.isDebuggable(this) || Util.getSelfVersionName(this).contains("beta"))) { screen.removePreference(cat_development); prefs.edit().remove("loglevel").apply(); } else if (!Util.isDebuggable(this)) cat_development.removePreference(pref_show_resolved); // Show resolved pref_show_resolved.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivity(new Intent(ActivitySettings.this, ActivityDns.class)); return true; } }); // Handle technical info Preference.OnPreferenceClickListener listener = new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { updateTechnicalInfo(); return true; } }; // Technical info Preference pref_technical_info = screen.findPreference("technical_info"); Preference pref_technical_network = screen.findPreference("technical_network"); Preference pref_technical_subscription = screen.findPreference("technical_subscription"); pref_technical_info.setEnabled(INTENT_VPN_SETTINGS.resolveActivity(this.getPackageManager()) != null); pref_technical_info.setIntent(INTENT_VPN_SETTINGS); pref_technical_info.setOnPreferenceClickListener(listener); pref_technical_network.setOnPreferenceClickListener(listener); pref_technical_subscription.setOnPreferenceClickListener(listener); updateTechnicalInfo(); }
From source file:net.helff.wificonnector.WifiConnectorActivity.java
protected void startScan() { WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); if (wifiManager != null && wifiManager.isWifiEnabled()) { wifiManager.startScan();//from w w w.j a v a2s . com } }
From source file:com.zrlh.llkc.funciton.Http_Utility.java
public static HttpClient getNewHttpClient(Context context) { try {/*from www . ja va2s .c o m*/ KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); // Set the default socket timeout (SO_TIMEOUT) // in // milliseconds which is the timeout for waiting for data. HttpConnectionParams.setConnectionTimeout(params, Http_Utility.SET_CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, Http_Utility.SET_SOCKET_TIMEOUT); HttpClient client = new DefaultHttpClient(ccm, params); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifiManager.getConnectionInfo(); if (!wifiManager.isWifiEnabled() || -1 == info.getNetworkId()) { // ??APN? Uri uri = Uri.parse("content://telephony/carriers/preferapn"); Cursor mCursor = context.getContentResolver().query(uri, null, null, null, null); if (mCursor != null && mCursor.moveToFirst()) { // ??? String proxyStr = mCursor.getString(mCursor.getColumnIndex("proxy")); if (proxyStr != null && proxyStr.trim().length() > 0) { HttpHost proxy = new HttpHost(proxyStr, 80); client.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy); } mCursor.close(); } } return client; } catch (Exception e) { return new DefaultHttpClient(); } }
From source file:com.realtek.simpleconfig.SCTest.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // ??/*from w w w . ja va 2 s .c o m*/ // Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this)); /* just for test!!! Button button = null; button.setVisibility(View.VISIBLE); */ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); /** For Multiple Page */ setContentView(R.layout.sc_view_pager); SCViewPager = (ViewPager) findViewById(R.id.viewPagerLayout); SCInflater = LayoutInflater.from(this); sc_config_iface = SCInflater.inflate(R.layout.sc_config_iface, null); sc_control_iface = SCInflater.inflate(R.layout.sc_control_iface, null); listViews = new ArrayList<View>(); listViews.add(sc_config_iface); listViews.add(sc_control_iface); SCViewPager.setCurrentItem(0); SCViewPager.setAdapter(new PageAdpt()); SCViewPager.setOnPageChangeListener(PageChangeEvent); /** For Config Page */ scan_wifi = (Button) sc_config_iface.findViewById(R.id.scan_wifi); start_config = (Button) sc_config_iface.findViewById(R.id.start_config); scan_wifi.setTextSize(20); start_config.setTextSize(20); /* Config Button */ scan_wifi.setOnClickListener(new ButtonListener()); start_config.setOnClickListener(new ButtonListener()); /* Config ListView ? */ wifiListView = (ListView) sc_config_iface.findViewById(R.id.all_wifi_network); wifiListView.setOnItemClickListener(wifiItemOnClick); /* Config ListView ? */ wifiListItemAdapter = new listBaseAdapter(this, wifiArrayList); /* ?? */ cfgProgressDialog = new ProgressDialog(this); /** For Control Page */ discov_devs = (Button) sc_control_iface.findViewById(R.id.discov_devs); discov_devs.setTextSize(20); /* Control Button */ discov_devs.setOnClickListener(new ButtonListener()); /* Control ListView ? */ devListView = (ListView) sc_control_iface.findViewById(R.id.all_connected_devs); devListView.setOnItemClickListener(devItemOnClick); /* Control ListView ? */ devListItemAdapter = new listBaseAdapter(this, devArrayList); /* ? */ discovDialog = new ProgressDialog(this); delProfDialog = new ProgressDialog(this); renameDevDialog = new ProgressDialog(this); /** Simple Config ? */ SCLib.rtk_sc_init(); SCLib.TreadMsgHandler = new MsgHandler(); /** ?? */ SCLib.WifiInit(this); wifiMngr = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiInfo = wifiMngr.getConnectionInfo(); fileOps.SetKey(SCLib.WifiGetMacStr()); fileOps.UpgradeSsidPasswdFile(); }
From source file:com.netease.qa.emmagee.service.EmmageeService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i(LOG_TAG, "service onStart"); PendingIntent contentIntent = PendingIntent.getActivity(getBaseContext(), 0, new Intent(this, MainPageActivity.class), 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentIntent(contentIntent).setSmallIcon(R.drawable.icon).setWhen(System.currentTimeMillis()) .setAutoCancel(true).setContentTitle("ETest"); startForeground(startId, builder.build()); HttpUtils.testSuitId = 0;/*from w ww . ja va 2 s.c o m*/ pid = intent.getExtras().getInt("pid"); uid = intent.getExtras().getInt("uid"); processName = intent.getExtras().getString("processName"); packageName = intent.getExtras().getString("packageName"); startActivity = intent.getExtras().getString("startActivity"); appVersion = intent.getExtras().getString("appVersion"); cpuInfo = new CpuInfo(getBaseContext(), pid, Integer.toString(uid)); readSettingInfo(); if (isFloating) { viFloatingWindow = LayoutInflater.from(this).inflate(R.layout.floating, null); txtUnusedMem = (TextView) viFloatingWindow.findViewById(R.id.memunused); txtTotalMem = (TextView) viFloatingWindow.findViewById(R.id.memtotal); txtTraffic = (TextView) viFloatingWindow.findViewById(R.id.traffic); btnWifi = (Button) viFloatingWindow.findViewById(R.id.wifi); wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (wifiManager.isWifiEnabled()) { btnWifi.setText(R.string.close_wifi); } else { btnWifi.setText(R.string.open_wifi); } txtUnusedMem.setText(getString(R.string.calculating)); txtUnusedMem.setTextColor(android.graphics.Color.RED); txtTotalMem.setTextColor(android.graphics.Color.RED); txtTraffic.setTextColor(android.graphics.Color.RED); btnStop = (Button) viFloatingWindow.findViewById(R.id.stop); btnStop.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.putExtra("isServiceStop", true); intent.setAction(SERVICE_ACTION); sendBroadcast(intent); stopSelf(); } }); createFloatingWindow(); } createResultCsv(); if (isRoot) { getlog(); } handler.postDelayed(task, 1000); return START_NOT_STICKY; }
From source file:com.example.zoetablet.BasicFragmentActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Set the orientation //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); //Shapes and Coredx DDS Initialization // magic to enable WiFi multicast to work on some android platforms: WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); mcastLock = wifi.createMulticastLock("Tablet"); mcastLock.acquire();/*ww w . jav a2s. c o m*/ //Tablet variables tablet = new Vector<TabletWriter>(); // open CoreDX DDS license file: BufferedReader br = null; String license = new String("<"); try { Log.i("Debug", "...Opening License"); br = new BufferedReader(new InputStreamReader(this.getAssets().open("coredx_dds.lic"))); } catch (IOException e) { Log.i("Debug", "...License did not open"); Log.e("Tablet", e.getMessage()); } if (br != null) { String ln; try { while ((ln = br.readLine()) != null) { license = new String(license + ln + "\n"); } } catch (IOException e) { // Log.e("Tablet", e.getMessage()); } } license = new String(license + ">"); Log.i("Tablet", "...License seems to be good"); //Initialize Variables XVel = 1; YVel = 2; CompassDir = 3; GPS_LN = 4; GPS_LT = 5; Log_DDS = DateFormat.getDateTimeInstance().format(new Date()); //For the Image, use current image display and String fileName = "/storage/sdcard0/DCIM/no_video.jpg"; Bitmap bmp; bmp = BitmapFactory.decodeFile(fileName); ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 40, baos); buffer = baos.toByteArray(); data_image_DDS = buffer; Log.i("Tablet", "Creating Subscriber"); class TestDataReaderListener implements DataReaderListener { @Override public long get_nil_mask() { return 0; } @Override public void on_requested_deadline_missed(DataReader dr, RequestedDeadlineMissedStatus status) { System.out.println(" @@@@@@@@@@@ REQUESTED DEADLINE MISSED @@@@@"); System.out.println(" @@@@@@@@@@@ @@@@@"); System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); }; @Override public void on_requested_incompatible_qos(DataReader dr, RequestedIncompatibleQosStatus status) { System.out.println(" @@@@@@@@@@@ REQUESTED INCOMPAT QOS @@@@@@@@"); System.out.println(" @@@@@@@@@@@ dr = " + dr); System.out.println(" @@@@@@@@@@@ @@@@@@@@"); System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); }; @Override public void on_sample_rejected(DataReader dr, SampleRejectedStatus status) { }; @Override public void on_liveliness_changed(DataReader dr, LivelinessChangedStatus status) { TopicDescription td = dr.get_topicdescription(); System.out.println(" @@@@@@@@@@@ LIVELINESS CHANGED " + td.get_name() + " @@@@@@@@@@"); } @Override public void on_subscription_matched(DataReader dr, SubscriptionMatchedStatus status) { TopicDescription td = dr.get_topicdescription(); System.out.println(" @@@@@@@@@@@ SUBSCRIPTION MATCHED @@@@@@@@@@"); System.out.println( " @@@@@@@@@@@ topic = " + td.get_name() + " (type: " + td.get_type_name() + ")"); System.out.println(" @@@@@@@@@@@ current = " + status.get_current_count()); System.out.println(" @@@@@@@@@@@ @@@@@@@@@@"); System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); } @Override public void on_sample_lost(DataReader dr, SampleLostStatus status) { System.out.println(" @@@@@@@@@@@ SAMPLE LOST @@@@@@@@@@"); }; @Override public void on_data_available(DataReader dr) { TopicDescription td = dr.get_topicdescription(); dataDDSDataReader data_message = (dataDDSDataReader) dr; System.out.println(" @@@@@@@@@@@ DATA AVAILABLE @@@@@@@@@@"); System.out.println( " @@@@@@@@@@@ topic = " + td.get_name() + " (type: " + td.get_type_name() + ")"); samples = new dataDDSSeq(); SampleInfoSeq si = new SampleInfoSeq(); ReturnCode_t retval = data_message.take(samples, si, 100, coredxConstants.DDS_ANY_SAMPLE_STATE, coredxConstants.DDS_ANY_VIEW_STATE, coredxConstants.DDS_ANY_INSTANCE_STATE); System.out.println(" @@@@@@@@@@@ DR.read() ===> " + retval); if (retval == ReturnCode_t.RETCODE_OK) { if (samples.value == null) System.out.println(" @@@@@@@@@@@ samples.value = null"); else { System.out.println(" @@@@@@@@@@@ samples.value.length= " + samples.value.length); for (int i = 0; i < samples.value.length; i++) { System.out.println(" State : " + (si.value[i].instance_state == coredxConstants.DDS_ALIVE_INSTANCE_STATE ? "ALIVE" : "NOT ALIVE")); System.out.println(" TimeStamp : " + si.value[i].source_timestamp.sec + "." + si.value[i].source_timestamp.nanosec); System.out.println(" Handle : " + si.value[i].instance_handle.value); System.out.println(" WriterHandle: " + si.value[i].publication_handle.value); System.out.println(" SampleRank : " + si.value[i].sample_rank); if (si.value[i].valid_data) System.out.println(" XVel: " + samples.value[i].XVel_DDS); System.out.println(" YVel: " + samples.value[i].YVel_DDS); System.out.println(" CompassDir: " + samples.value[i].CompassDir_DDS); System.out.println(" GPS_LT: " + samples.value[i].GPS_LT_DDS); System.out.println(" GPS_LN: " + samples.value[i].GPS_LN_DDS); System.out.println(" Log_DDS: " + samples.value[i].Log_DDS); //Capture data values for display BasicFragmentActivity.XVel = samples.value[i].XVel_DDS; BasicFragmentActivity.YVel = samples.value[i].YVel_DDS; BasicFragmentActivity.CompassDir = samples.value[i].CompassDir_DDS; BasicFragmentActivity.GPS_LT = samples.value[i].GPS_LT_DDS; BasicFragmentActivity.GPS_LN = samples.value[i].GPS_LN_DDS; BasicFragmentActivity.Log_DDS = samples.value[i].Log_DDS; BasicFragmentActivity.data_image_DDS = samples.value[i].data_image_DDS; } } data_message.return_loan(samples, si); } else { } System.out.println(" @@@@@@@@@@@ @@@@@@@@@@"); System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); }; } ; System.out.println("STARTING -------------------------"); DomainParticipantFactory dpf = DomainParticipantFactory.get_instance(); dpf.set_license(license); dpf.get_default_participant_qos(dp_qos_tablet); DomainParticipant dp = null; System.out.println("CREATE PARTICIPANT ---------------"); dp = dpf.create_participant(0, /* domain Id */ dp_qos_tablet, //null, /* default qos */ null, /* no listener */ 0); if (dp == null) { //failed to create DomainParticipant -- bad license android.util.Log.e("CoreDX DDS", "Unable to create Tablet DomainParticipant."); } SubscriberQos sub_qos_tablet = new SubscriberQos(); Log.i("Tablet", "creating publisher/subscriber"); sub_tablet = dp.create_subscriber(sub_qos_tablet, null, 0); System.out.println("REGISTERING TYPE -----------------"); dataDDSTypeSupport ts = new dataDDSTypeSupport(); ReturnCode_t returnValue = ts.register_type(dp, null); if (returnValue != ReturnCode_t.RETCODE_OK) { System.out.println("ERROR registering type\n"); return; } System.out.println("CREATE TOPIC ---------------------"); /* create a DDS Topic with the FilterMsg data type. */ Topic topics = dp.create_topic("dataDDS", ts.get_type_name(), DDS.TOPIC_QOS_DEFAULT, null, 0); if (topics == null) { System.out.println("Error creating topic"); return; } System.out.println("CREATE SUBSCRIBER ----------------"); SubscriberQos sub_qos = null; SubscriberListener sub_listener = null; Subscriber sub = dp.create_subscriber(sub_qos, sub_listener, 0); System.out.println("READER VARIABLES ----------------"); DataReaderQos dr_qos = new DataReaderQos(); sub.get_default_datareader_qos(dr_qos); dr_qos.entity_name.value = "JAVA_DR"; dr_qos.history.depth = 10; DataReaderListener dr_listener = new TestDataReaderListener(); System.out.println("CREATE DATAREADER ----------------"); //Create DDS Data reader dataDDSDataReader dr = (dataDDSDataReader) sub.create_datareader(topics, DDS.DATAREADER_QOS_DEFAULT, dr_listener, DDS.DATA_AVAILABLE_STATUS); System.out.println("DATAREADER CREATED ----------------"); //Cheack to see if DDS Data Reader worked if (dr == null) { System.out.println("ERROR creating data reader\n"); //return; } // We default to building our Fragment at runtime, but you can switch the layout here // to R.layout.activity_fragment_xml in order to have the Fragment added during the // Activity's layout inflation. setContentView(R.layout.holygrail); Log.i("Tablet", "called set content view"); FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.center_pane_top); // You can find Fragments just like you would with a // View by using FragmentManager. Log.i("Tablet", "...declare fragment"); // If wLog.ie are using activity_fragment_xml.xml then this the fragment will not be // null, otherwise it will be. if (fragment == null) { //Image View Fragment Log.i("Debug", "...calling fragment center pane"); FragmentTransaction ft = fm.beginTransaction(); ft.add(R.id.center_pane_top, new BasicFragment()); ft.addToBackStack(null); //Logging Fragment Log.i("Debug", "...calling fragment left pane top"); //ft.add(R.id.left_pane_top, new LoggingFragment()); ft.add(R.id.left_pane_top, new LoggingFragment()); ft.addToBackStack(null); //Connecting Fragment Log.i("Debug", "...calling fragment left pane bottom"); //ft.add(R.id.left_pane_bottom,new ControllerFragment()); ft.add(R.id.left_pane_bottom, new ConnectionFragment()); ft.addToBackStack(null); //Compass Fragment Log.i("Debug", "...calling fragment right pane top"); //ft.add(R.id.right_pane_top,new BasicFragment2()); ft.add(R.id.right_pane_top, new BasicFragment2()); ft.addToBackStack(null); //Navigation Fragment Log.i("Debug", "...calling fragment right pane bottom"); //ft.add(R.id.center_pane_bottom,new NavigationFragment()); ft.add(R.id.center_pane_bottom, new DualJoystickActivity()); ft.addToBackStack(null); //Datalog Fragment Log.i("Debug", "...calling fragment middle pane bottom"); //ft.add(R.id.right_pane_bottom,new DatalogFragment()); ft.add(R.id.right_pane_bottom, new DatalogFragment()); ft.addToBackStack(null); //Commit the fragment or it will not be added Log.i("Debug", "...comitting"); ft.commit(); } //Joystick variables txtX1 = (TextView) this.findViewById(R.id.TextViewX1); txtY1 = (TextView) this.findViewById(R.id.TextViewY1); txtX2 = (TextView) this.findViewById(R.id.TextViewX2); txtY2 = (TextView) this.findViewById(R.id.TextViewY2); joystick = (DualJoystickView) this.findViewById(R.id.dualjoystickView); JoystickMovedListener _listenerLeft = new JoystickMovedListener() { @Override public void OnMoved(int pan, int tilt) { txtX1.setText(Integer.toString(pan)); txtY1.setText(Integer.toString(tilt)); } @Override public void OnReleased() { txtX1.setText("released"); txtY1.setText("released"); } @Override public void OnReturnedToCenter() { txtX1.setText("stopped"); txtY1.setText("stopped"); }; }; JoystickMovedListener _listenerRight = new JoystickMovedListener() { @Override public void OnMoved(int pan, int tilt) { txtX2.setText(Integer.toString(pan)); txtY2.setText(Integer.toString(tilt)); } @Override public void OnReleased() { txtX2.setText("released"); txtY2.setText("released"); } @Override public void OnReturnedToCenter() { txtX2.setText("stopped"); txtY2.setText("stopped"); }; }; joystick.setOnJostickMovedListener(_listenerLeft, _listenerRight); //Compass Activities compassView = (CompassView) this.findViewById(R.id.compassView); sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); // updateOrientation(new float[] {0, 0, 0}); // updateOrientation(calculateOrientation()); // Hook up button presses to the appropriate event handler. // Quit Button -- not really necessary: The 'Back' button does // the same thing, but we create this just for fun.. ((Button) findViewById(R.id.quitButton)).setOnClickListener(mQuitListener); tv_myAddr = (TextView) findViewById(R.id.myAddress); if (tv_myAddr != null) tv_myAddr.setText("<detecting>"); mHandler.postDelayed(mUpdateMyAddress, 1000); // every 10 sec */ //Updating Datalog fragment view tv_XVel = (TextView) findViewById(R.id.XVel); if (tv_XVel != null) tv_XVel.setText("<detecting>"); tv_YVel = (TextView) findViewById(R.id.YVel); if (tv_YVel != null) tv_YVel.setText("<detecting>"); tv_CompassDir = (TextView) findViewById(R.id.CompassDir); if (tv_CompassDir != null) tv_CompassDir.setText("<detecting>"); tv_GPSLocation = (TextView) findViewById(R.id.GPSLocation); if (tv_GPSLocation != null) tv_GPSLocation.setText("<detecting>"); tv_Log_DDS = (TextView) findViewById(R.id.loggingMessage); if (tv_Log_DDS != null) tv_Log_DDS.setText("<detecting>"); mHandler.postDelayed(mUpdateDatalog, 500); // every 1 sec */ }
From source file:net.helff.wificonnector.WifiConnectivityService.java
protected void checkWifi() throws ConnectionWorkflowException { WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager != null ? wifiManager.getConnectionInfo() : null; if (!TELEFONICA_SSID.equals(this.normalizeSSID(wifiInfo))) { // post error publishProgress(getString(R.string.not_connected), getString(R.string.not_connected_detail), STATUS_NOT_CONNECTED);//from w ww. j av a2 s . c o m throw new ConnectionWorkflowException("No connection to TelefonicaPublic"); } }