Skip to content

Instantly share code, notes, and snippets.

View smyykb's full-sized avatar

Sümeyye Ortagedik smyykb

  • Ziraat Teknoloji
View GitHub Profile
@smyykb
smyykb / DeCryptor.java
Created March 14, 2018 08:08 — forked from JosiasSena/DeCryptor.java
Encryptor and Decryptor for data encryption.decryption using the Android KeyStore.
/**
_____ _____ _
| __ \ / ____| | |
| | | | ___| | _ __ _ _ _ __ | |_ ___ _ __
| | | |/ _ \ | | '__| | | | '_ \| __/ _ \| '__|
| |__| | __/ |____| | | |_| | |_) | || (_) | |
|_____/ \___|\_____|_| \__, | .__/ \__\___/|_|
__/ | |
|___/|_|
*/
@smyykb
smyykb / components-action.csv
Created March 14, 2018 06:45 — forked from AkshayChordiya/components-action.csv
Android Architecture Guidelines Cheatsheet
Component Action
UI Controllers (Activity and Fragment) Only UI related logic
ViewModel Container for data required by UI
Repository Single source of truth for data
Room Local Database
Retrofit Web Service
@smyykb
smyykb / tools:title=”LayoutPreview”
Created March 14, 2018 06:36
tools:title=”LayoutPreview”
<TextView
android:id="@+id/text_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:drawableLeft="@tools:sample/avatars"
tools:text="@tools:sample/full_names"/>
It would look much nicer if we could show the real item used in our RecyclerView, and even more so if that item uses sample texts tools:text=”@tools:sample/lorem” and tools:text=”@tools:sample/lorem/random” for TextViews inside
@smyykb
smyykb / gist:c342f332d3c1017373189de7659caba6
Created March 5, 2018 06:38
Change Author template in Android Studio
You can overwrite the ${USER} variable in the template file with the
#set( $VARIABLE = "value")
function. Go to Settings -> File and Code Templates -> Includes -> File Header prepend the #set() function call, for example:
#set( $USER = "Your name" )
/**
* Created by ${USER} on ${DATE}.
*/
@smyykb
smyykb / android_studio_shortcuts.md
Created February 2, 2018 11:30 — forked from stkent/android_studio_shortcuts.md
Android Studio Shortcuts (Mac)

Android Studio Shortcuts (Mac)

Notes:

  • Two of the most useful shortcuts utilize the Fn (function) keys. It is therefore recommended that you enable the "Use all F1, F2, etc. keys as standard function keys" option [System Preferences > Keyboard].
  • Be sure to enable the Mac OS X 10.5+ keymap in Android Studio [Preferences > Keymap].
  • A fairly complete shortcut list can be found here.

Useful symbols:

@smyykb
smyykb / layout_button.xml
Created January 30, 2018 17:34
Custom attributes in styles.xml
<Button
android:layout_width="wrap_content"
android:layout_height="?attr/defaultButtonHeight"
android:text="Button"
android:textColor="?attr/defaultButtonColor"
/>
READ:
FileInputStream in = openFileInput("filename.txt");
InputStreamReader inputStreamReader = new InputStreamReader(in);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder sb = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
sb.append(line);
@smyykb
smyykb / Serializable vs Parcelable
Last active July 25, 2022 08:21
Serializable vs Parcelable
In Android, if we want to pass the objects to activities then there is a need to implement the Serializable or Parcelable interface.
Serializable and Parcelable are two interfaces:
* Serializable is a standard java interface that implemented by “java.io.Serializable”
* Parcelable is an Android-specific interface that implemented by “android.os.Parcelable”
Serializable interface is easy to implement by overriding the methods but it is a slow process
and it creates a lot of temporary objects and causes quite a bit of garbage collection.
Parcelable interface takes more time to implement in comparison to Serializable because of the code size.
ANR (A pplication N ot R esponding )is due to handling long running task in Main Thread(UI thread).If the main thread is stopped for more than 5 sec you get ANR.
Crash are due to exception and error like Nullpoint,classNotfound, typecast ,parse error etc. ANR also causes crash of application.
ANR and Crash Examples:
ANR:
// this will produce an ANR on your app
int i = 0;
commit() writes the data synchronously (blocking the thread its called from). It then informs you about the success of the operation.
apply() schedules the data to be written asynchronously. It does not inform you about the success of the operation.
If you save with apply() and immediately read via any getX-method, the new value will be returned!
If you called apply() at some point and it's still executing, any calls to commit() will block until all apply-calls and its own commit are finished.
commit() writes its data to persistent storage immediately, whereas apply() will handle it in the background.