Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Dharmendra Pratap Singh dp-singh

🎯
Focusing
View GitHub Profile
@dp-singh
dp-singh / ActivityExt.kt
Created Mar 8, 2021
Auto Grant Requested Permissions to Self if Device Admin is enabled. MDM
View ActivityExt.kt
private fun Activity.autoGrantRequestedPermissionsToSelf(componentName: ComponentName) {
val permissions: List<String> = retrievePermissions(this)
val mDevicePolicyManager = this.getSystemService(AppCompatActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
if (mDevicePolicyManager.isAdminActive(componentName)) {
Log.d("PERMISSION", "Device Admin enabled")
} else {
Log.d("PERMISSION", "Device Admin Disabled")
}
for (permission in permissions) {
val result = mDevicePolicyManager.getPermissionGrantState(componentName, packageName, permission)
@dp-singh
dp-singh / custometype.tx
Last active Jan 18, 2018
Typescript custom type
View custometype.tx
//JSON is way of communication between client and server
//custom type
type Task={
id: number;
title: string;
detail: string;
@dp-singh
dp-singh / loop.tx
Created Jan 18, 2018
Type Script loop
View loop.tx
//declaration of array
var arr: number[];
//initilization of array
arr = [1, 2, 3, 4, 5, 5, 6, 7, 8]
//for loop
@dp-singh
dp-singh / java
Last active Mar 15, 2017
Location Observable using RxJava and retrolambda
View java
import android.app.Application;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Looper;
import rx.Observable;
View RealmFullTextSearch.java
import android.text.TextUtils;
import io.realm.Case;
import io.realm.Realm;
import io.realm.RealmObject;
import io.realm.RealmResults;
public class RealmFullTextSearch {
public static <T extends RealmObject> RealmResults<T> search(Realm realm, Class<T> modelClass, String query, String fieldName, boolean partialSearch){
View Ripple Drawable
public class Drawables {
@NonNull
public static Drawable getSelectableDrawableFor(int color) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(
new int[]{android.R.attr.state_pressed},
new ColorDrawable(lightenOrDarken(color, 0.20D))
);
@dp-singh
dp-singh / 0_reuse_code.js
Created May 10, 2016
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@dp-singh
dp-singh / Setting up retrolamda java problem.groovy
Last active May 10, 2016
It is used to setup retrolambda in android
View Setting up retrolamda java problem.groovy
String java8 = getJavaVersion(8)
String java7 = getJavaVersion(7)
retrolambda {
jdk java8
oldJdk java7
javaVersion JavaVersion.VERSION_1_7
// jvmArgs '-arg1', '-arg2' < if I don't comment this line gradle fails
defaultMethods false
incremental true
@dp-singh
dp-singh / HeaderFooterRecyclerViewAdapter.java
Created Dec 2, 2015 — forked from mheras/HeaderFooterRecyclerViewAdapter.java
Header & footer support for RecyclerView.Adapter
View HeaderFooterRecyclerViewAdapter.java
public abstract class HeaderFooterRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int VIEW_TYPE_MAX_COUNT = 1000;
private static final int HEADER_VIEW_TYPE_OFFSET = 0;
private static final int FOOTER_VIEW_TYPE_OFFSET = HEADER_VIEW_TYPE_OFFSET + VIEW_TYPE_MAX_COUNT;
private static final int CONTENT_VIEW_TYPE_OFFSET = FOOTER_VIEW_TYPE_OFFSET + VIEW_TYPE_MAX_COUNT;
private int headerItemCount;
private int contentItemCount;
private int footerItemCount;
@dp-singh
dp-singh / activity_main.xml
Created Nov 17, 2015 — forked from tsmsogn/activity_main.xml
[android]Google Play Services SDK
View activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />