Skip to content

Instantly share code, notes, and snippets.

todorBG

Block or report user

Report or block todorBG

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Permissions.java
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == REQUEST_PERMISSION) {
// for each permission check if the user granted/denied them
// you may want to group the rationale in a single dialog,
// this is just an example
for (int i = 0, len = permissions.length; i < len; i++) {
String permission = permissions[i];
if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
// user rejected the permission
View CustomSerializable.java
private void writeObject(java.io.ObjectOutputStream out)
throws IOException;
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException;
private void readObjectNoData()
throws ObjectStreamException;
@todorBG
todorBG / Person.java
Created Apr 23, 2017
A Person POJO with Serializable interface.
View Person.java
import java.io.Serializable;
public class Person implements Serializable {
private String firstName;
private String lastName;
private int age;
public Person(String firstName, String lastName, int age) {
@todorBG
todorBG / Person.java
Created Apr 23, 2017
A Person POJO with Parcelable interface.
View Person.java
import android.os.Parcel;
import android.os.Parcelable;
public class Person implements Parcelable {
private String firstName;
private String lastName;
private int age;
View styles.xml
<style name="CustomButtonStyleWaikawaGrey" parent="Theme.AppCompat">
<item name="colorButtonNormal">@color/waikawa_grey</item>
</style>
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kostovtd.appshortcuts">
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
View shortcuts.xml
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<!-- SETTINGS SHORTCUT -->
<shortcut
android:shortcutId="settings"
android:enabled="true"
android:shortcutShortLabel="@string/settings_shortcut_short_label"
android:shortcutLongLabel="@string/settings_shortcut_long_label"
android:shortcutDisabledMessage="@string/settings_shortcut_disabled_msg">
View MainActivity.java
package com.kostovtd.appshortcuts;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
View DeviceProtecteStorage.java
// GET DEVICE PROTECTED CONTEXT
Context applicationContext = getApplicationContext();
Context safeContext = ContextCompat.createDeviceProtectedStorageContext(appicationContext);
// MOVE DATA FROM CREDENTIAL TO DEVICE STORAGE
Context.moveSharedPreferencesFrom();
Context.moveDatabaseFrom();
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.directboot">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
You can’t perform that action at this time.