Skip to content

Instantly share code, notes, and snippets.

@laaptu
laaptu / DialogFragment.java
Created June 20, 2014 05:52
Using dialog fragment to show dialog
DialogFragment dg = new DialogFragment() {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setMessage(R.string.submit_confirm_message)
.setPositiveButton(R.string.submit_confirm_button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
/*---THIS IS ADDED EXTRA--------*/
postInfoToServer();
@laaptu
laaptu / GetImagePathFromCamera
Created June 17, 2014 23:02
Method to get image path from Camera Intent
Cursor cursor = getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[]{Media.DATA, Media.DATE_ADDED, MediaStore.Images.ImageColumns.ORIENTATION}, Media.DATE_ADDED, null, "date_added ASC");
if(cursor != null && cursor.moveToFirst())
{
do {
uri = Uri.parse(cursor.getString(cursor.getColumnIndex(Media.DATA)));
photoPath = uri.toString();
}while(cursor.moveToNext());
cursor.close();
}
@laaptu
laaptu / BitmapToInputStream.java
Created June 12, 2014 09:26
Convert Bitmap to InputStream
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
byte[] bitmapdata = bos.toByteArray();
ByteArrayInputStream bs = new ByteArrayInputStream(bitmapdata);
@laaptu
laaptu / BaseEditText.java
Last active August 29, 2015 14:02
How to apply themes to the Custom Views in Android
public class BaseEditText extends EditText {
public BaseEditText(Context context) {
this(context, null);
}
public BaseEditText(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public BaseEditText(Context context, AttributeSet attrs, int defStyle) {
{
"following": [
{
"name" : "john doe",
"following" : true,
"created_at" : "1 hour ago",
"picture" : "http://i.imgur.com/DA8VXak.jpg"
},
{
"name" : "john doe",
@laaptu
laaptu / main_bg.xml
Created June 4, 2014 04:35
Drop shadow box i.e. shape with drop shadows
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Drop Shadow Stack -->
<item>
<shape>
<corners android:radius="10dp" />
<padding
android:bottom="1dp"
@laaptu
laaptu / TextViewClickableUnderlineColorChange.java
Last active August 29, 2015 14:02
How to make a Texview clickable, underline and change color to certain portion
//Terms of Service
String tobeClickable = getString(R.string.tos);
int index = getString(R.string.terms_of_service).indexOf(tobeClickable);
int length = index + tobeClickable.length();
//I agree to FireSonar's Terms of Service
Spannable spannableString = new SpannableString(
getString(R.string.terms_of_service));
ClickableSpan clickableSpan = new ClickableSpan() {
@laaptu
laaptu / HideKeyboard.java
Last active August 29, 2015 14:02
Hiding soft keyboard programmatically. The view passed should not be null and it doesn't matter that the view is to be the current edittext where there is focus. It can be any view until and unless it is present in the layout
public void hideSoftInputKeyBoard(View view) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null && view != null) {
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
@laaptu
laaptu / CheckingTheme.java
Last active September 13, 2019 15:56
How to get theme id
TypedValue outValue = new TypedValue();
getTheme().resolveAttribute(R.attr.themeName, outValue, true);
if(outValue.equals(getString(R.string.custom_title_theme))){
//you have applied this theme else not
}
//http://stackoverflow.com/questions/7267852/android-how-to-obtain-the-resource-id-of-the-current-theme
public class SomeFragment extends Fragment {
MapView mapView;
GoogleMap map;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.some_layout, container, false);