Skip to content

Instantly share code, notes, and snippets.

View nieldeokar's full-sized avatar

Nilesh Deokar nieldeokar

View GitHub Profile
@nieldeokar
nieldeokar / SimpleVibrateDemoActivity.java
Last active September 1, 2023 11:04
Android Vibrate & VibrationEffect class demo Usage
package com.example.nileshdeokar.simplevibratedemo;
import android.os.Build;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
/*
@nieldeokar
nieldeokar / DemoVibrateAndroid
Created November 13, 2017 11:18
Using Vibrate in android demo snippet
<uses-permission android:name="android.permission.VIBRATE"/>
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator.hasVibrator()) {
vibrator.vibrate(500); // for 500 ms
}
@nieldeokar
nieldeokar / OneShotVibration.java
Last active November 13, 2017 11:24
This method would create a one shot vibration using VibrationEffects
@RequiresApi(api = Build.VERSION_CODES.O)
private void createOneShotVibrationUsingVibrationEffect() {
// 1000 : Vibrate for 1 sec
// VibrationEffect.DEFAULT_AMPLITUDE - would perform vibration at full strength
VibrationEffect effect = VibrationEffect.createOneShot(1000, VibrationEffect.DEFAULT_AMPLITUDE);
vibrator.vibrate(effect);
}
@nieldeokar
nieldeokar / WaveFormVibration.java
Last active November 13, 2017 11:33
This method would create wave form vibration using vibration effect
@RequiresApi(api = Build.VERSION_CODES.O)
private void createWaveFormVibrationUsingVibrationEffectAndAmplitude() {
long[] mVibratePattern = new long[]{0, 400, 800, 600, 800, 800, 800, 1000};
int[] mAmplitudes = new int[]{0, 255, 0, 255, 0, 255, 0, 255};
// -1 : Play exactly once
if (vibrator.hasAmplitudeControl()) {
VibrationEffect effect = VibrationEffect.createWaveform(mVibratePattern, mAmplitudes, -1);
vibrator.vibrate(effect);
}
@nieldeokar
nieldeokar / VibratePattern.java
Last active November 13, 2017 11:37
This would create a custom vibrate pattern.
private void customVibratePatternNoRepeat() {
// 0 : Start without a delay
// 400 : Vibrate for 400 milliseconds
// 200 : Pause for 200 milliseconds
// 400 : Vibrate for 400 milliseconds
long[] mVibratePattern = new long[]{0, 400, 200, 400};
// -1 : Do not repeat this pattern
// pass 0 if you want to repeat this pattern from 0th index
vibrator.vibrate(mVibratePattern, -1);
@nieldeokar
nieldeokar / CreateOneshotVibration.java
Last active November 13, 2017 11:41
It would create one shot vibration using VibrationEffect
@RequiresApi(api = Build.VERSION_CODES.O)
private void createOneShotVibrationUsingVibrationEffect() {
// 1000 : Vibrate for 1 sec
// VibrationEffect.DEFAULT_AMPLITUDE - would perform vibration at full strength
VibrationEffect effect = VibrationEffect.createOneShot(1000, VibrationEffect.DEFAULT_AMPLITUDE);
vibrator.vibrate(effect);
}
@nieldeokar
nieldeokar / copyandroiddbfile.py
Last active September 17, 2022 16:22
Python script for copying database file from android devices. Works only with debuggable apps since no other process has permission to access files stored in private storage of an app.
import sys
import subprocess
import re
#/
# Created by @nieldeokar on 25/05/2018.
#/
# 1. Python script which will copy database file of debuggable apps from the android device to your computer using ADB.
@nieldeokar
nieldeokar / AppUpdateCheckerUsingBitwiseShiftOperation.java
Last active May 31, 2018 17:39
Demonstration of how to use 1 Integer object to store 32 boolean values
public class AppUpdateCheckerUsingBitwiseShiftOperation {
private int mUpdateValue = 0;
private static final int UPDATE_AVAILABLE = 1;
private static final int UPDATE_COMPULSORY = 2;
public void setValue(int position){
mUpdateValue = mUpdateValue | (1 << position);
@nieldeokar
nieldeokar / GetAppUpdateAvailable.java
Last active May 30, 2018 13:31
Used for storing multiple boolean values into one int variable. This snippet checks the bit values set in SetAppUpdateAvailable.java
package com.nileshdeokar.healthapp;
public class GetAppUpdateAvailable {
private int updateValue = 0b0110;
private static final int UPDATE_AVAILABLE = 1;
private static final int UPDATE_COMPULSORY = 2;
public void getUpdateAvailable(){
@nieldeokar
nieldeokar / SetAppUpdateAvailable.java
Last active May 30, 2018 13:30
Used for storing multiple boolean values into one int variable.
public class SetAppUpdateAvailable {
private int mUpdateValue = 0;
private static final int UPDATE_AVAILABLE = 1;
private static final int UPDATE_COMPULSORY = 2;
public void setUpdateAvailable(){
mUpdateValue = mUpdateValue | (1 << UPDATE_AVAILABLE);