Skip to content

Instantly share code, notes, and snippets.

View girish3's full-sized avatar
🎯
Focusing

Girish Budhwani girish3

🎯
Focusing
View GitHub Profile
@girish3
girish3 / LaunchMode.md
Last active June 17, 2019 03:38
[Activity Launch Mode] Understanding Activity's launch mode #android #android_tutorial #tutorial

Since each Activity is made to work in different purpose. Some is designed to work separately with each Intent sent for example an Activity for email composing in email client. While some is designed to work as a singleton for example an email's inbox Activity. That's why it does matter to specify whether Activity is needed to be created a new one or to use the existed one. launchMode is designed for this specifically.

launchMode can be assigned directly as an attribute tag

<activity
    android:name=".SingleTaskActivity"
    android:label="singleTask launchMode"
    android:launchMode="singleTask">
@girish3
girish3 / markdown.md
Last active May 31, 2019 13:50
[Markdown basics] #tutorial
  1. The following line is bold
    Hi, I am Bold (**Hi, I am Bold**)

  2. The following line is given emphasis
    I am cooool. (*I am cooool.*)

  3. To write something on the new line, give two spaces and hit enter
    Yay! we are on the next line

  4. Now comes the Headline

@girish3
girish3 / basics.md
Last active May 31, 2019 13:51
[Regex and Grep tool] #tutorial

regex for finding text with 2 substrings

Ex. 'git' and 'rm'

grep "git.*rm"

@girish3
girish3 / SpannableString.java
Last active November 11, 2018 05:07
[Spannable String] #android_snippet #android
// https://stackoverflow.com/questions/10696986/how-to-set-the-part-of-the-text-view-is-clickable
SpannableString ss = new SpannableString("Android is a Software stack");
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
startActivity(new Intent(MyActivity.this, NextActivity.class));
}
};
// 0 is the start index and 7 is the end index
ss.setSpan(clickableSpan, 0, 7, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
@girish3
girish3 / LayoutInflater.java
Last active November 11, 2018 05:07
[Layout Inflater] Ways to get layout inflator object and inflate the view. #android_snippet #android
// if you are in an activity
LayoutInflater inflater = getLayoutInflater();
// If you have the context
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// or in a cleaner way, from() uses system service interally so its the same inflater
LayoutInflater inflater = LayoutInflater.from(context);
// inflating a view
// if you need to attach the inflated to rootView, returned view will be rootView.
// 3rd parameter is attach_to_root
@girish3
girish3 / Intent.java
Last active November 11, 2018 05:07
[Intent] Intent snippets to start Activity, Service or sending broadcast. #android_snippet #android
// starting an activity from another activity
// this is a Activity context
Intent intent = new Intent(this, AnotherActivity.java);
intent.putExtra(Intent.EXTRA_TEXT, "some text");
intent.putExtra("id", 4);
startActivity(intent);
// Receiving intent in AnotherActivity
Bundle extras = getIntent().getExtras();
@girish3
girish3 / alert_dialog.java
Last active November 11, 2018 05:07
[Alert Dialog] Alert dialog is created using a builder pattern #android_snippet #android
// this is a context
AlertDialog.Builder builder = new AlertDialog.Builder(this);
// Check other builder methods like setCancelable, setIcon..
builder.setTitle("Set Title");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// do something
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@girish3
girish3 / MyKeyboardBindings.mkd
Last active March 25, 2018 17:49
My customised IDE keyboard bindings
  • File structure (Navigate to functions, variables of the same class)

    cmd + r

  • Navigate Back to last cursor position

    cmd + [

  • Navigate Forward

    cmd + ]

  • Move Line/Lines up/down

// Taking the same Go example as above
// Human and Student structs ....
human := Human{"John"}
// human will be passed by value, new copy will be created.
student := Student{human, 1}
public class Human {
public String name;
public Human(String name) {
this.name = name;
}
}
public class Student {
private Human human;