Archivi tag: snippet

[ANDROID] Screen always turned on How to

This android code snippet is for keep alive the screen of your android device during the execution of your app, please read the note also.

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
wl.acquire();

..screen will stay on during this section..

wl.release();

IMPORTANT: Remember to RELEASE the WakeLock when you have finished to use it, otherwise the screen will be ever turned on! 🙂

Android Color List

if you write android code you will need as soon as possible of a list of colors, i’ve found this that i think is very exaustive, you don’t think so? 🙂

 


< ?xml version="1.0" encoding="utf-8"?>

#FFFFFF #FFFFF0 #FFFFE0 #FFFF00 #FFFAFA #FFFAF0 #FFFACD #FFF8DC #FFF5EE #FFF0F5 #FFEFD5 #FFEBCD #FFE4E1 #FFE4C4 #FFE4B5 #FFDEAD #FFDAB9 #FFD700 #FFC0CB #FFB6C1 #FFA500 #FFA07A #FF8C00 #FF7F50 #FF69B4 #FF6347 #FF4500 #FF1493 #FF00FF #FF00FF #FF0000 #FDF5E6 #FAFAD2 #FAF0E6 #FAEBD7 #FA8072 #F8F8FF #F5FFFA #F5F5F5 #F5F5DC #F5DEB3 #F4A460 #F0FFFF #F0FFF0 #F0F8FF #F0E68C #F08080 #EEE8AA #EE82EE #E9967A #E6E6FA #E0FFFF #DEB887 #DDA0DD #DCDCDC #DC143C #DB7093 #DAA520 #DA70D6 #D8BFD8 #D3D3D3 #D2B48C #D2691E #CD853F #CD5C5C #C71585 #C0C0C0 #BDB76B #BC8F8F #BA55D3 #B8860B #B22222 #B0E0E6 #B0C4DE #AFEEEE #ADFF2F #ADD8E6 #A9A9A9 #A52A2A #A0522D #9ACD32 #9932CC #98FB98 #9400D3 #9370DB #90EE90 #8FBC8F #8B4513 #8B008B #8B0000 #8A2BE2 #87CEFA #87CEEB #808080 #808000 #800080 #800000 #7FFFD4 #7FFF00 #7CFC00 #7B68EE #778899 #708090 #6B8E23 #6A5ACD #696969 #66CDAA #6495ED #5F9EA0 #556B2F #4B0082 #48D1CC #483D8B #4682B4 #4169E1 #40E0D0 #3CB371 #32CD32 #2F4F4F #2E8B57 #228B22 #20B2AA #1E90FF #191970 #00FFFF #00FFFF #00FF7F #00FF00 #00FA9A #00CED1 #00BFFF #008B8B #008080 #008000 #006400 #0000FF #0000CD #00008B #000080 #000000

Download Files and AsyncTask in Android

This code snippet found here complete my previous snippet that i’ve used to grab a single file on a remote server


import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.Toast;

public class SimpleWebGrab extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

grabURL("http://android.com");
}

public void grabURL(String url) {
new GrabURL().execute(url);
}

private class GrabURL extends AsyncTask {
private final HttpClient Client = new DefaultHttpClient();
private String Content;
private String Error = null;
private ProgressDialog Dialog = new ProgressDialog(SimpleWebGrab.this);

protected void onPreExecute() {
Dialog.setMessage("Downloading source..");
Dialog.show();
}

protected Void doInBackground(String... urls) {
try {
HttpGet httpget = new HttpGet(urls[0]);
ResponseHandler responseHandler = new BasicResponseHandler();
Content = Client.execute(httpget, responseHandler);
} catch (ClientProtocolException e) {
Error = e.getMessage();
cancel(true);
} catch (IOException e) {
Error = e.getMessage();
cancel(true);
}

return null;
}

protected void onPostExecute(Void unused) {
Dialog.dismiss();
if (Error != null) {
Toast.makeText(SimpleWebGrab.this, Error, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(SimpleWebGrab.this, "Source: " + Content, Toast.LENGTH_LONG).show();
}
}

}
}

[VB.NET] – How to get version at runtime

How to get our sw version at runtime

Private Function GetVersion() As String
Dim versione As String = String.Empty
Dim gi As FileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly.Location)
versione = gi.FileMajorPart & "." & gi.FileMinorPart & "." & gi.FileBuildPart & "." & gi.FilePrivatePart
Return versione
End Function