Skip to content

Instantly share code, notes, and snippets.

View devrath's full-sized avatar
💭
I'm grateful when for one drop in glass. Since I knw exactly what to do with it

Devrath devrath

💭
I'm grateful when for one drop in glass. Since I knw exactly what to do with it
View GitHub Profile
@devrath
devrath / GsonParser
Created November 13, 2014 12:02
Parsing JSON using GSON parser
// Refered Link: http://stackoverflow.com/questions/5490789/json-parsing-using-gson-for-java
// Refered Link: http://stackoverflow.com/a/10593838/1083093
JSONObject refJson;
JSONArray jsonarray= null;
JsonElement gsonJelement;
JsonObject gsonJobject;
try {
// Retrieve JSON Objects from the given URL address
refJson = JSONfunctions.getJSONfromURL(url.trim());
@devrath
devrath / QuitApplicationConditionOnBackpressedInFragments
Created November 19, 2014 09:32
This is used to check onBackpressed if only one fragment is found using backstack count
Checking the backstack works perfectly
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
if (getFragmentManager().getBackStackEntryCount() == 1)
{
// DO something here since there is only one fragment left
@devrath
devrath / ApacheServerGetRequest
Created November 19, 2014 09:51
SimpleApacheServerRequest to get data
package com.findmybuffet.utilities;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
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;
@devrath
devrath / EdiText Hide Keyboard on click outside
Created November 19, 2014 11:58
Hide the keyboard onClick of outside click of edit text
// REFER: http://stackoverflow.com/a/19828165/1083093
//Step1: Add in the root of the layout, if its a scrollview add to the parent(eg:linearlayout) not the scroll view
android:clickable="true"
android:focusableInTouchMode="true"
//Step2: Add this method
public void hideKeyboard(View view) {
InputMethodManager inputMethodManager =(InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
@devrath
devrath / HttpPostJsonPayload
Last active August 29, 2015 14:10
Http post request with no Encoding and reading the stream revieved from the server
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
@devrath
devrath / GetTextFromListAdapter
Created November 24, 2014 06:47
Getting the textview in adapter of listview from the class
listviewone.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
TextView mText = (TextView) view.findViewById(R.id.title);
String value= mText.getText().toString().trim();
String str =(String) ((TextView) view.findViewById(R.id.title)).getText();
Log.d("", "");
}
@devrath
devrath / NameValuePairPost
Created November 24, 2014 10:23
Post Request sending data as header or Name/value pair
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
@devrath
devrath / HttpGetHeaderData
Created November 24, 2014 12:21
Passing data to http GET request as header
private void getRequest(String urlString) {
URL url;
InputStream response = null;
try {
url = new URL(urlString);
HttpURLConnection connection;
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
@devrath
devrath / TimePicker
Created November 25, 2014 05:04
Setting the time in edittext using time picker with dialog fragment
eReminderTime.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Calendar mcurrentTime = Calendar.getInstance();
int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
int minute = mcurrentTime.get(Calendar.MINUTE);
TimePickerDialog mTimePicker;
mTimePicker = new TimePickerDialog(AddReminder.this, new TimePickerDialog.OnTimeSetListener() {
@devrath
devrath / Date Picker
Created November 25, 2014 05:07
Setting the date in edittext using the date picker with dialog
//*****************CALLL THIS FUNCTION CALL IN ON CLICK OF A VIEW*****************//
selectDate(v);
//*****************CALLL THIS FUNCTION CALL IN ON CLICK OF A VIEW*****************//
//*******Date picker implementation******(Start)***//
public void selectDate(View view) {
DialogFragment fragment = new SelectDateFragment();