List of usage examples for android.widget Toast show
public void show()
From source file:net.homelinux.penecoptero.android.citybikes.app.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);// ww w . j a v a 2 s .co m PreferenceManager.setDefaultValues(this, R.xml.preferences, false); mapView = (MapView) findViewById(R.id.mapview); mSlidingDrawer = (StationSlidingDrawer) findViewById(R.id.drawer); infoLayer = (InfoLayer) findViewById(R.id.info_layer); scale = getResources().getDisplayMetrics().density; //Log.i("CityBikes","ON CREATEEEEEEEEE!!!!!"); infoLayerPopulator = new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == InfoLayer.POPULATE) { infoLayer.inflateStation(stations.getCurrent()); } if (msg.what == CityBikes.BOOKMARK_CHANGE) { int id = msg.arg1; boolean bookmarked; if (msg.arg2 == 0) { bookmarked = false; } else { bookmarked = true; } StationOverlay station = stations.getById(id); try { BookmarkManager bm = new BookmarkManager(getApplicationContext()); bm.setBookmarked(station.getStation(), !bookmarked); } catch (Exception e) { Log.i("CityBikes", "Error bookmarking station"); e.printStackTrace(); } if (!view_all) { view_near(); } mapView.postInvalidate(); } } }; infoLayer.setHandler(infoLayerPopulator); RelativeLayout.LayoutParams zoomControlsLayoutParams = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); zoomControlsLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); zoomControlsLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL); mapView.addView(mapView.getZoomControls(), zoomControlsLayoutParams); modeButton = (ToggleButton) findViewById(R.id.mode_button); modeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { changeMode(!getBike); } }); applyMapViewLongPressListener(mapView); settings = getSharedPreferences(CityBikes.PREFERENCES_NAME, 0); List<Overlay> mapOverlays = mapView.getOverlays(); locator = new Locator(this, new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == Locator.LOCATION_CHANGED) { GeoPoint point = new GeoPoint(msg.arg1, msg.arg2); hOverlay.moveCenter(point); mapView.getController().animateTo(point); mDbHelper.setCenter(point); // Location has changed try { mDbHelper.updateDistances(point); infoLayer.update(); if (!view_all) { view_near(); } } catch (Exception e) { } ; } } }); hOverlay = new HomeOverlay(locator.getCurrentGeoPoint(), new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == HomeOverlay.MOTION_CIRCLE_STOP) { try { if (!view_all) { view_near(); } mapView.postInvalidate(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }); stations = new StationOverlayList(mapOverlays, new Handler() { @Override public void handleMessage(Message msg) { //Log.i("CityBikes","Message: "+Integer.toString(msg.what)+" "+Integer.toString(msg.arg1)); if (msg.what == StationOverlay.TOUCHED && msg.arg1 != -1) { // One station has been touched stations.setCurrent(msg.arg1, getBike); infoLayer.inflateStation(stations.getCurrent()); //Log.i("CityBikes","Station touched: "+Integer.toString(msg.arg1)); } } }); stations.addOverlay(hOverlay); mNDBAdapter = new NetworksDBAdapter(getApplicationContext()); mDbHelper = new StationsDBAdapter(this, mapView, new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case StationsDBAdapter.FETCH: break; case StationsDBAdapter.UPDATE_MAP: progressDialog.dismiss(); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("reload_network", false); editor.commit(); case StationsDBAdapter.UPDATE_DATABASE: StationOverlay current = stations.getCurrent(); if (current == null) { infoLayer.inflateMessage(getString(R.string.no_bikes_around)); } if (current != null) { infoLayer.inflateStation(current); if (view_all) view_all(); else view_near(); } else { } mapView.invalidate(); infoLayer.update(); ////Log.i("openBicing", "Database updated"); break; case StationsDBAdapter.NETWORK_ERROR: ////Log.i("openBicing", "Network error, last update from " + mDbHelper.getLastUpdated()); Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.network_error) + " " + mDbHelper.getLastUpdated(), Toast.LENGTH_LONG); toast.show(); break; } } }, stations); mDbHelper.setCenter(locator.getCurrentGeoPoint()); mSlidingDrawer.setHandler(new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case StationSlidingDrawer.ITEMCLICKED: StationOverlay clicked = (StationOverlay) msg.obj; stations.setCurrent(msg.arg1, getBike); Message tmp = new Message(); tmp.what = InfoLayer.POPULATE; tmp.arg1 = msg.arg1; infoLayerPopulator.dispatchMessage(tmp); mapView.getController().animateTo(clicked.getCenter()); } } }); if (savedInstanceState != null) { locator.unlockCenter(); hOverlay.setRadius(savedInstanceState.getInt("homeRadius")); this.view_all = savedInstanceState.getBoolean("view_all"); } else { updateHome(); } try { mDbHelper.loadStations(); if (savedInstanceState == null) { String strUpdated = mDbHelper.getLastUpdated(); Boolean dirty = settings.getBoolean("reload_network", false); if (strUpdated == null || dirty) { this.fillData(view_all); } else { Toast toast = Toast.makeText(this.getApplicationContext(), "Last Updated: " + mDbHelper.getLastUpdated(), Toast.LENGTH_LONG); toast.show(); Calendar cal = Calendar.getInstance(); long now = cal.getTime().getTime(); if (Math.abs(now - mDbHelper.getLastUpdatedTime()) > 60000 * 5) this.fillData(view_all); } } } catch (Exception e) { ////Log.i("openBicing", "SHIT ... SUCKS"); } ; if (view_all) view_all(); else view_near(); ////Log.i("openBicing", "CREATE!"); }
From source file:com.ccxt.whl.activity.SettingsFragmentCopy.java
/** * ?uri?//from w w w . j a v a 2 s. co m * * @param selectedImage */ private void sendPicByUri(Uri selectedImage) { // String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getActivity().getContentResolver().query(selectedImage, null, null, null, null); if (cursor != null) { cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex("_data"); String picturePath = cursor.getString(columnIndex); cursor.close(); cursor = null; if (picturePath == null || picturePath.equals("null")) { Toast toast = Toast.makeText(getActivity(), "?", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return; } copyFile(picturePath, imageUri.getPath()); cropImageUri(imageUri, 150, 150, USERPIC_REQUEST_CODE_CUT); //sendPicture(picturePath); } else { File file = new File(selectedImage.getPath()); if (!file.exists()) { Toast toast = Toast.makeText(getActivity(), "?", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return; } copyFile(selectedImage.getPath(), imageUri.getPath()); cropImageUri(imageUri, 150, 150, USERPIC_REQUEST_CODE_CUT); //sendPicture(file.getAbsolutePath()); } /*if(getpathfromUri(uri)!=null&&getpathfromUri(imageUri)!=null){ copyFile(getpathfromUri(uri),getpathfromUri(imageUri)); }else{ return; }*/ //cropImageUri(selectedImage, 150, 150, USERPIC_REQUEST_CODE_CUT); }
From source file:jp.ne.sakura.kkkon.java.net.inetaddress.testapp.android.NetworkConnectionCheckerTestApp.java
/** Called when the activity is first created. */ @Override/*from w ww . ja va2 s. c o m*/ public void onCreate(Bundle savedInstanceState) { final Context context = this.getApplicationContext(); { NetworkConnectionChecker.initialize(); } super.onCreate(savedInstanceState); /* Create a TextView and set its content. * the text is retrieved by calling a native * function. */ LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setText("reachable="); layout.addView(tv); this.textView = tv; Button btn1 = new Button(this); btn1.setText("invoke Exception"); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final int count = 2; int[] array = new int[count]; int value = array[count]; // invoke IndexOutOfBOundsException } }); layout.addView(btn1); { Button btn = new Button(this); btn.setText("disp isReachable"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final boolean isReachable = NetworkConnectionChecker.isReachable(); Toast toast = Toast.makeText(context, "IsReachable=" + isReachable, Toast.LENGTH_LONG); toast.show(); } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("upload http AsyncTask"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AsyncTask<String, Void, Boolean> asyncTask = new AsyncTask<String, Void, Boolean>() { @Override protected Boolean doInBackground(String... paramss) { Boolean result = true; Log.d(TAG, "upload AsyncTask tid=" + android.os.Process.myTid()); try { //$(BRAND)/$(PRODUCT)/$(DEVICE)/$(BOARD):$(VERSION.RELEASE)/$(ID)/$(VERSION.INCREMENTAL):$(TYPE)/$(TAGS) Log.d(TAG, "fng=" + Build.FINGERPRINT); final List<NameValuePair> list = new ArrayList<NameValuePair>(16); list.add(new BasicNameValuePair("fng", Build.FINGERPRINT)); HttpPost httpPost = new HttpPost(paramss[0]); //httpPost.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, new Integer(5*1000) ); httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8)); DefaultHttpClient httpClient = new DefaultHttpClient(); Log.d(TAG, "socket.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1)); Log.d(TAG, "connection.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1)); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, new Integer(5 * 1000)); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, new Integer(5 * 1000)); Log.d(TAG, "socket.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1)); Log.d(TAG, "connection.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1)); // <uses-permission android:name="android.permission.INTERNET"/> // got android.os.NetworkOnMainThreadException, run at UI Main Thread HttpResponse response = httpClient.execute(httpPost); Log.d(TAG, "response=" + response.getStatusLine().getStatusCode()); } catch (Exception e) { Log.d(TAG, "got Exception. msg=" + e.getMessage(), e); result = false; } Log.d(TAG, "upload finish"); return result; } }; asyncTask.execute("http://kkkon.sakura.ne.jp/android/bug"); asyncTask.isCancelled(); } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(0.0.0.0)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { try { destHost = InetAddress.getByName("0.0.0.0"); if (null != destHost) { try { if (destHost.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + destHost.toString() + " reachable"); } else { Log.d(TAG, "destHost=" + destHost.toString() + " not reachable"); } } catch (IOException e) { } } } catch (UnknownHostException e) { } Log.d(TAG, "destHost=" + destHost); } }); thread.start(); try { thread.join(1000); } catch (InterruptedException e) { } } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(www.google.com)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { Log.d(TAG, "start"); try { InetAddress dest = InetAddress.getByName("www.google.com"); if (null == dest) { dest = destHost; } if (null != dest) { final String[] uris = new String[] { "http://www.google.com/", "https://www.google.com/" }; for (final String destURI : uris) { URI uri = null; try { uri = new URI(destURI); } catch (URISyntaxException e) { //Log.d( TAG, e.toString() ); } if (null != uri) { URL url = null; try { url = uri.toURL(); } catch (MalformedURLException ex) { Log.d(TAG, "got exception:" + ex.toString(), ex); } URLConnection conn = null; if (null != url) { Log.d(TAG, "openConnection before"); try { conn = url.openConnection(); if (null != conn) { conn.setConnectTimeout(3 * 1000); conn.setReadTimeout(3 * 1000); } } catch (IOException e) { //Log.d( TAG, "got Exception" + e.toString(), e ); } Log.d(TAG, "openConnection after"); if (conn instanceof HttpURLConnection) { HttpURLConnection httpConn = (HttpURLConnection) conn; int responceCode = -1; try { Log.d(TAG, "getResponceCode before"); responceCode = httpConn.getResponseCode(); Log.d(TAG, "getResponceCode after"); } catch (IOException ex) { Log.d(TAG, "got exception:" + ex.toString(), ex); } Log.d(TAG, "responceCode=" + responceCode); if (0 < responceCode) { isReachable = true; destHost = dest; } Log.d(TAG, " HTTP ContentLength=" + httpConn.getContentLength()); httpConn.disconnect(); Log.d(TAG, " HTTP ContentLength=" + httpConn.getContentLength()); } } } // if uri if (isReachable) { //break; } } // for uris } else { } } catch (UnknownHostException e) { Log.d(TAG, "dns error" + e.toString()); destHost = null; } { if (null != destHost) { Log.d(TAG, "destHost=" + destHost); } } Log.d(TAG, "end"); } }); thread.start(); try { thread.join(); { final String addr = (null == destHost) ? ("") : (destHost.toString()); final String reachable = (isReachable) ? ("reachable") : ("not reachable"); Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable, Toast.LENGTH_LONG); toast.show(); } } catch (InterruptedException e) { } } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(kkkon.sakura.ne.jp)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { Log.d(TAG, "start"); try { InetAddress dest = InetAddress.getByName("kkkon.sakura.ne.jp"); if (null == dest) { dest = destHost; } if (null != dest) { try { if (dest.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + dest.toString() + " reachable"); isReachable = true; } else { Log.d(TAG, "destHost=" + dest.toString() + " not reachable"); } destHost = dest; } catch (IOException e) { } } else { } } catch (UnknownHostException e) { Log.d(TAG, "dns error" + e.toString()); destHost = null; } { if (null != destHost) { Log.d(TAG, "destHost=" + destHost); } } Log.d(TAG, "end"); } }); thread.start(); try { thread.join(); { final String addr = (null == destHost) ? ("") : (destHost.toString()); final String reachable = (isReachable) ? ("reachable") : ("not reachable"); Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable, Toast.LENGTH_LONG); toast.show(); } } catch (InterruptedException e) { } } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(kkkon.sakura.ne.jp) support proxy"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { try { String target = null; { ProxySelector proxySelector = ProxySelector.getDefault(); Log.d(TAG, "proxySelector=" + proxySelector); if (null != proxySelector) { URI uri = null; try { uri = new URI("http://www.google.com/"); } catch (URISyntaxException e) { Log.d(TAG, e.toString()); } List<Proxy> proxies = proxySelector.select(uri); if (null != proxies) { for (final Proxy proxy : proxies) { Log.d(TAG, " proxy=" + proxy); if (null != proxy) { if (Proxy.Type.HTTP == proxy.type()) { final SocketAddress sa = proxy.address(); if (sa instanceof InetSocketAddress) { final InetSocketAddress isa = (InetSocketAddress) sa; target = isa.getHostName(); break; } } } } } } } if (null == target) { target = "kkkon.sakura.ne.jp"; } InetAddress dest = InetAddress.getByName(target); if (null == dest) { dest = destHost; } if (null != dest) { try { if (dest.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + dest.toString() + " reachable"); isReachable = true; } else { Log.d(TAG, "destHost=" + dest.toString() + " not reachable"); { ProxySelector proxySelector = ProxySelector.getDefault(); //Log.d( TAG, "proxySelector=" + proxySelector ); if (null != proxySelector) { URI uri = null; try { uri = new URI("http://www.google.com/"); } catch (URISyntaxException e) { //Log.d( TAG, e.toString() ); } if (null != uri) { List<Proxy> proxies = proxySelector.select(uri); if (null != proxies) { for (final Proxy proxy : proxies) { //Log.d( TAG, " proxy=" + proxy ); if (null != proxy) { if (Proxy.Type.HTTP == proxy.type()) { URL url = uri.toURL(); URLConnection conn = null; if (null != url) { try { conn = url.openConnection(proxy); if (null != conn) { conn.setConnectTimeout( 3 * 1000); conn.setReadTimeout(3 * 1000); } } catch (IOException e) { Log.d(TAG, "got Exception" + e.toString(), e); } if (conn instanceof HttpURLConnection) { HttpURLConnection httpConn = (HttpURLConnection) conn; if (0 < httpConn .getResponseCode()) { isReachable = true; } Log.d(TAG, " HTTP ContentLength=" + httpConn .getContentLength()); Log.d(TAG, " HTTP res=" + httpConn .getResponseCode()); //httpConn.setInstanceFollowRedirects( false ); //httpConn.setRequestMethod( "HEAD" ); //conn.connect(); httpConn.disconnect(); Log.d(TAG, " HTTP ContentLength=" + httpConn .getContentLength()); Log.d(TAG, " HTTP res=" + httpConn .getResponseCode()); } } } } } } } } } } destHost = dest; } catch (IOException e) { Log.d(TAG, "got Excpetion " + e.toString()); } } else { } } catch (UnknownHostException e) { Log.d(TAG, "dns error" + e.toString()); destHost = null; } { if (null != destHost) { Log.d(TAG, "destHost=" + destHost); } } } }); thread.start(); try { thread.join(); { final String addr = (null == destHost) ? ("") : (destHost.toString()); final String reachable = (isReachable) ? ("reachable") : ("not reachable"); Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable, Toast.LENGTH_LONG); toast.show(); } } catch (InterruptedException e) { } } }); layout.addView(btn); } setContentView(layout); }
From source file:com.kircherelectronics.accelerationfilter.activity.AccelerationPlotActivity.java
/** * Write the logged data out to a persisted file. *//*from ww w.j a va2 s .c o m*/ private void writeLogToFile() { Calendar c = Calendar.getInstance(); String filename = "AccelerationFilter-" + c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH) + 1) + "-" + c.get(Calendar.DAY_OF_MONTH) + "-" + c.get(Calendar.HOUR) + "-" + c.get(Calendar.MINUTE) + "-" + c.get(Calendar.SECOND) + ".csv"; File dir = new File(Environment.getExternalStorageDirectory() + File.separator + "AccelerationFilter" + File.separator + "Logs"); if (!dir.exists()) { dir.mkdirs(); } File file = new File(dir, filename); FileOutputStream fos; byte[] data = log.getBytes(); try { fos = new FileOutputStream(file); fos.write(data); fos.flush(); fos.close(); CharSequence text = "Log Saved"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(this, text, duration); toast.show(); } catch (FileNotFoundException e) { CharSequence text = e.toString(); int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(this, text, duration); toast.show(); } catch (IOException e) { // handle exception } finally { // Update the MediaStore so we can view the file without rebooting. // Note that it appears that the ACTION_MEDIA_MOUNTED approach is // now blocked for non-system apps on Android 4.4. MediaScannerConnection.scanFile(this, new String[] { file.getPath() }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(final String path, final Uri uri) { } }); } }
From source file:com.scooter1556.sms.lib.android.service.AudioPlayerService.java
public void initialiseTrack(int position) { // Get settings final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); // Get media element to play final MediaElement mediaElement = mediaElementList.get(position); if (mediaElement == null) { Toast error = Toast.makeText(getApplicationContext(), getString(R.string.error_media_playback), Toast.LENGTH_SHORT);/*from w w w . j ava2s . com*/ error.show(); return; } // Initialise Stream restService.initialiseStream(getApplicationContext(), mediaElement.getID(), SUPPORTED_FILES, SUPPORTED_CODECS, null, null, Integer.parseInt(settings.getString("pref_audio_quality", "0")), MAX_SAMPLE_RATE, null, null, settings.getBoolean("pref_direct_play", false), new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, cz.msebera.android.httpclient.Header[] headers, JSONObject response) { // Initialise player player = new SMSAudioPlayer(); // Update state mediaState = PlaybackStateCompat.STATE_CONNECTING; updatePlaybackState(); // Parse profile Gson parser = new Gson(); TranscodeProfile profile = parser.fromJson(response.toString(), TranscodeProfile.class); // Setup Player player.setID(mediaElement.getID()); player.setDuration(mediaElement.getDuration()); player.setTranscodeProfile(profile); player.setQuality(Integer.parseInt(settings.getString("pref_audio_quality", "0"))); // Streaming status if (profile.getType() == TranscodeProfile.StreamType.FILE) { player.setStreaming(false); } else { player.setStreaming(true); } try { preparePlayer(); isPaused = false; // Update metadata mediaSession.setMetadata(MediaUtils.getMediaMetadata(mediaElement, null)); // Attempt to get album art Glide.with(getApplicationContext()) .load(RESTService.getInstance().getConnection().getUrl() + "/image/" + mediaElement.getID() + "/cover/300") .asBitmap().into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap image, GlideAnimation<? super Bitmap> glideAnimation) { // Update metadata with artwork mediaSession .setMetadata(MediaUtils.getMediaMetadata(mediaElement, image)); } }); // Update listeners for (AudioPlayerListener listener : listeners) { listener.PlaybackStateChanged(); listener.PlaylistPositionChanged(); } } catch (Exception e) { cleanupPlayer(); } } @Override public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers, Throwable throwable, JSONObject response) { error(); } private void error() { Toast error = Toast.makeText(getApplicationContext(), getString(R.string.error_media_playback), Toast.LENGTH_SHORT); error.show(); currentListPosition = 0; // Update state mediaState = PlaybackStateCompat.STATE_ERROR; updatePlaybackState(); // Update listeners for (AudioPlayerListener listener : listeners) { listener.PlaybackStateChanged(); listener.PlaylistPositionChanged(); } } }); }
From source file:org.openremote.android.console.AppSettingsActivity.java
/** * Initializes the SSL related UI widget properties and event handlers to deal with user * interactions./*from www.jav a 2 s . co m*/ */ private void initSSLState() { // Get UI Widget references... final ToggleButton sslToggleButton = (ToggleButton) findViewById(R.id.ssl_toggle); final EditText sslPortEditField = (EditText) findViewById(R.id.ssl_port); final TextView pin = (TextView) findViewById(R.id.ssl_clientcert_pin); // Configure UI to current settings state... boolean sslEnabled = AppSettingsModel.isSSLEnabled(this); sslToggleButton.setChecked(sslEnabled); sslPortEditField.setText("" + AppSettingsModel.getSSLPort(this)); // If SSL is off, disable the port edit field by default... if (!sslEnabled) { sslPortEditField.setEnabled(false); sslPortEditField.setFocusable(false); sslPortEditField.setFocusableInTouchMode(false); } // Manage state changes to SSL toggle... sslToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isEnabled) { // If SSL is being disabled, and the user had soft keyboard open, close it... if (!isEnabled) { InputMethodManager input = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); input.hideSoftInputFromWindow(sslPortEditField.getWindowToken(), 0); } // Set SSL state in config model accordingly... AppSettingsModel.enableSSL(AppSettingsActivity.this, isEnabled); // Enable/Disable SSL Port text field according to SSL toggle on/off state... sslPortEditField.setEnabled(isEnabled); sslPortEditField.setFocusable(isEnabled); sslPortEditField.setFocusableInTouchMode(isEnabled); } }); pin.setText("..."); final Handler pinHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); pin.setText(msg.getData().getString("pin")); } }; new Thread() { public void run() { String pin = ORKeyPair.getInstance().getPIN(getApplicationContext()); Bundle bundle = new Bundle(); bundle.putString("pin", pin); Message msg = pinHandler.obtainMessage(); msg.setData(bundle); msg.sendToTarget(); } }.start(); sslPortEditField.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { //TODO not very user friendly if (keyCode == KeyEvent.KEYCODE_ENTER) { String sslPortStr = ((EditText) v).getText().toString(); try { int sslPort = Integer.parseInt(sslPortStr.trim()); AppSettingsModel.setSSLPort(AppSettingsActivity.this, sslPort); } catch (NumberFormatException ex) { Toast toast = Toast.makeText(getApplicationContext(), "SSL port format is not correct.", 1); toast.show(); return false; } catch (IllegalArgumentException e) { Toast toast = Toast.makeText(getApplicationContext(), e.getMessage(), 2); toast.show(); sslPortEditField.setText("" + AppSettingsModel.getSSLPort(AppSettingsActivity.this)); return false; } } return false; } }); }
From source file:com.kircherelectronics.accelerationfilter.activity.AccelerationPlotActivity.java
/** * Begin logging data to an external .csv file. *//*from www.ja v a 2 s. c o m*/ private void startDataLog() { if (logData == false) { generation = 0; stdDevMaginitudeMeanZAxis.clear(); CharSequence text = "Logging Data"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(this, text, duration); toast.show(); String headers = "Generation" + ","; headers += "Timestamp" + ","; headers += this.plotAccelXAxisTitle + ","; headers += this.plotAccelYAxisTitle + ","; headers += this.plotAccelZAxisTitle + ","; if (lpfActive) { headers += this.plotLPFXAxisTitle + ","; headers += this.plotLPFYAxisTitle + ","; headers += this.plotLPFZAxisTitle + ","; } if (meanFilterActive) { headers += this.plotMeanXAxisTitle + ","; headers += this.plotMeanYAxisTitle + ","; headers += this.plotMeanZAxisTitle + ","; headers += this.plotStdDevMeanZAxisTitle + ","; } log = headers; log += System.getProperty("line.separator"); iconLogger.setVisibility(View.VISIBLE); logData = true; } else { iconLogger.setVisibility(View.INVISIBLE); logData = false; writeLogToFile(); } }
From source file:com.moonpi.swiftnotes.MainActivity.java
protected void deleteNote(Context context, final int position) { try {//ww w. ja va 2 s .c om new AlertDialog.Builder(context).setTitle(R.string.dialog_delete_title) .setMessage(getResources().getString(R.string.dialog_delete) + " '" + notes.getJSONObject(position).getString("title") + "'?") .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { JSONArray newArray = new JSONArray(); // Copy contents to new array, without the removed item for (int i = 0; i < notes.length(); i++) { if (i != position) { try { newArray.put(notes.get(i)); } catch (JSONException e) { e.printStackTrace(); } } } notes = newArray; adapter.adapterData = notes; adapter.notifyDataSetChanged(); try { root.put("notes", notes); } catch (JSONException e) { e.printStackTrace(); } writeToJSON(); // If no notes, show 'Press + to add new note' text, invisible otherwise if (notes.length() == 0) noNotes.setVisibility(View.VISIBLE); else noNotes.setVisibility(View.INVISIBLE); Toast toast = Toast.makeText(getApplicationContext(), getResources().getString(R.string.toast_deleted), Toast.LENGTH_SHORT); toast.show(); } }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).show(); } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.owncloud.android.ui.fragment.FileDetailFragment.java
private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) { boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; getActivity().dismissDialog(/* ww w. j a v a2 s .c o m*/ (inDisplayActivity) ? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); if (result.isSuccess()) { updateFileDetails(((RenameFileOperation) operation).getFile(), mAccount); mContainerActivity.onFileStateChanged(); } else { if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) { Toast msg = Toast.makeText(getActivity(), R.string.rename_local_fail_msg, Toast.LENGTH_LONG); msg.show(); // TODO throw again the new rename dialog } else { Toast msg = Toast.makeText(getActivity(), R.string.rename_server_fail_msg, Toast.LENGTH_LONG); msg.show(); if (result.isSslRecoverableException()) { // TODO show the SSL warning dialog } } } }
From source file:com.owncloud.android.ui.fragment.FileDetailFragment.java
private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) {/*w w w .ja v a 2s . co m*/ boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; getActivity().dismissDialog( (inDisplayActivity) ? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); if (!result.isSuccess()) { if (result.getCode() == ResultCode.SYNC_CONFLICT) { Intent i = new Intent(getActivity(), ConflictsResolveActivity.class); i.putExtra(ConflictsResolveActivity.EXTRA_FILE, mFile); i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, mAccount); startActivity(i); } else { Toast msg = Toast.makeText(getActivity(), R.string.sync_file_fail_msg, Toast.LENGTH_LONG); msg.show(); } if (mFile.isDown()) { setButtonsForDown(); } else { setButtonsForRemote(); } } else { if (operation.transferWasRequested()) { mContainerActivity.onFileStateChanged(); // this is not working; FileDownloader won't do NOTHING at all until this method finishes, so // checking the service to see if the file is downloading results in FALSE } else { Toast msg = Toast.makeText(getActivity(), R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG); msg.show(); if (mFile.isDown()) { setButtonsForDown(); } else { setButtonsForRemote(); } } } }