Skip to content

Instantly share code, notes, and snippets.

View msomu's full-sized avatar
🏠
Working from home

Somasundaram M msomu

🏠
Working from home
View GitHub Profile
@msomu
msomu / volley_string.java
Last active August 29, 2015 14:07
Volley Request for String on Android
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
String url ="http://www.google.com";
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET,url,new Response.Listener<String>() {
@Override
public void onResponse(String s) {
Log.d("Response:", s.toString());
pDialog.hide();
}
@msomu
msomu / splash.java
Created October 6, 2014 13:34
Splash Screen on Android
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(SplashActivity.this,HomeActivity.class);
startActivity(i);
finish();
}
},1000);
@msomu
msomu / build.gradle
Created October 6, 2014 15:27
Add Volley to Android Studio Project
dependencies {
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
}
@msomu
msomu / AppController.java
Created October 6, 2014 15:52
Volley Singleton Class for Application Globally
public class AppController extends Application {
public static final String TAG = AppController.class
.getSimpleName();
private RequestQueue mRequestQueue;
private ImageLoader mImageLoader;
private static AppController mInstance;
@msomu
msomu / volley_json_object_request.java
Created October 6, 2014 16:02
Making JSON object Request
// Tag used to cancel the request
String tag_json_obj = "json_obj_req";
String url = "http://api.androidhive.info/volley/person_object.json";
final ProgressDialog pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.show();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
@msomu
msomu / CustomAuthenticator.java
Created October 6, 2014 16:59
Java Authentication for urls protected with User Name and Passwords
public static class CustomAuthenticator extends Authenticator {
// Called when password authorization is needed
protected PasswordAuthentication getPasswordAuthentication() {
// Get information about the request
String prompt = getRequestingPrompt();
String hostname = getRequestingHost();
InetAddress ipaddr = getRequestingSite();
int port = getRequestingPort();
@msomu
msomu / jsonparsing.java
Created October 12, 2014 05:52
JSON Parsing For Android
try{
JSONObject jsonObject = new JSONObject(s);
JSONObject propertiesObject = jsonObject.getJSONObject("properties");
JSONObject idObject = propertiesObject.getJSONObject("id");
String s1 = idObject.getString("type");
Log.d("Type",s1);
}
@msomu
msomu / jsonArrayParse.java
Last active August 29, 2015 14:07
JSON Array Parsing in android
try {
JSONArray flimsJSON = new JSONArray(s);
int numVideos = flimsJSON.length();
for(int i =0; i<numVideos;i++){
JSONObject titleJSON = (JSONObject) flimsJSON.get(i);
String titleString = titleJSON.getString("title");
Log.d("TITLE:",titleString);
}
Log.d("Number of MOVIES FETCHED","is"+numVideos);
} catch (JSONException e) {
@msomu
msomu / HelloWorld.java
Created October 31, 2014 10:50
This was my first Java Code
public class HelloWorld {
public static void main(String[] args) {
System.out.print("Hello World");
}
}
@msomu
msomu / Variables.java
Last active August 29, 2015 14:08
Variable in Java
public class Variables {
public static void main(String[] args) {
int i=5;
System.out.print("The number is ");
System.out.print(i);
System.out.println(".");
System.out.print("It can also be written as this "+i);
}