Skip to content

Instantly share code, notes, and snippets.

View msomu's full-sized avatar

Somasundaram M msomu

View GitHub Profile
@msomu
msomu / Adapter.java
Created November 3, 2015 17:35
This gist will show you how to make staggeredgridlayout with images height fixed.
@Override
public void onBindViewHolder(ViewHolderDetail holder, int position) {
DataModel item = items.get(position);
if (item.getHeight() != 0 && item.getWidth() != 0) {
float width = activity.getWindowManager().getDefaultDisplay().getWidth();
float margin = ConvertionUtil.convertDpToPixel(8, activity);
width = (width - (3 * margin)) / 2;
float i = width / ((float) item.getWidth());
float imageHeight = i * (item.getHeight());
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.image.getLayoutParams();
@msomu
msomu / class.java
Created October 28, 2015 14:38
make a textview link
String str_text = "<a href=http://www.google.com >Google</a>";
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setText(Html.fromHtml(str_text));
textView.setLinkTextColor(Color.BLUE);
@msomu
msomu / layout.xml
Created October 7, 2015 12:06
Edit Text will automatically make the first letter capital
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:focusable="true"
android:gravity="top"
android:hint="@string/post_update"
android:inputType="textCapSentences"
@msomu
msomu / URIBuilder.java
Created October 6, 2015 18:43
this is how url should be appended
// Will contain the raw JSON response as a string.
String forecastJsonStr = null;
String format = "json";
String units = "metric";
int numDays = 7;
// Construct the URL for the OpenWeatherMap query
// Possible parameters are avaiable at OWM's forecast API page, at
// http://openweathermap.org/API#forecast
@msomu
msomu / Class.java
Created September 25, 2015 20:09
A small time util to convert TimeStamp into momments ago
public void setTime(String time) {
if (!TextUtils.isEmpty(time)) {
CharSequence relativeTimeSpanString = DateUtils.getRelativeTimeSpanString(Long.valueOf(time), System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE);
this.time = relativeTimeSpanString.toString();
} else {
this.time = "";
}
}
@msomu
msomu / actionbar_gradient_dark.xml
Created September 25, 2015 18:27
A gist for showing textview on the Image view, this util is for giving grey background to the image
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="90"
android:endColor="@android:color/transparent"
android:startColor="@android:color/black" />
<corners android:radius="0dp" />
</shape>
@msomu
msomu / fragments.java
Created April 21, 2015 10:31
This is used to find the number of fragments that are on the current activity
@Override
public void onBackPressed() {
//for testing purpose
//returns the number of fragments on the Activity
int count = fragmentManager.getBackStackEntryCount();
//displays the fragments that are present on the activity with their names
for (int i=count-1;i>=0;i--){
String name = fragmentManager.getBackStackEntryAt(i).getName();
Config.l("Count :"+i+" name :"+name);
}
@msomu
msomu / gist:d4ac5d4eb36872db07f3
Created April 19, 2015 17:06
Horizontal Line
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#c0c0c0"/>
@msomu
msomu / Jackson.java
Created April 2, 2015 06:54
simple example of Jackson on an Activity
ObjectMapper mapper = new ObjectMapper();
int one = 0;
try {
one = mapper.readValue("1", int.class);
} catch (IOException e) {
e.printStackTrace();
}
Config.t(getBaseContext()," "+one);
@msomu
msomu / person.json
Created April 1, 2015 06:38
Jackson Java Example
{
"name" : {
"first" : "Joe"
, "last" : "Sixpack"
}
, "gender" : "MALE"
, "verified" : false
, "userImage" : "Rm9vYmFyIQ=="
}