Skip to content

Instantly share code, notes, and snippets.

View spidergears's full-sized avatar

Deepak Singh spidergears

View GitHub Profile

Commit Message Guidelines

Short (72 chars or less) summary

More detailed explanatory text. Wrap it to 72 characters. The blank
line separating the summary from the body is critical (unless you omit
the body entirely).

Write your commit message in the imperative: "Fix bug" and not "Fixed
bug" or "Fixes bug." This convention matches up with commit messages
private final int WRITE_EXTERNAL_STORAGE_REQUEST_CODE = 123
pricate final String writeExternalStorageRationale = "You haven't given us permission to use Storage, please enable the permission to store images.";
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode){
case WRITE_EXTERNAL_STORAGE_REQUEST_CODE:
if (grantResults[0] != PackageManager.PERMISSION_GRANTED)
captureImage();
else{
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == WRITE_EXTERNAL_STORAGE_REQUEST_CODE){
if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
captureImage();
else{
if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE))
showRationaleDialog();
else
Toast.makeText(MainActivity.this, "You need to allow permission to Write to External Storage", Toast.LENGTH_LONG).show();
checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
=> ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
requestPermissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_EXTERNAL_STORAGE_REQUEST_CODE);
=> ActivityCompat.requestPermissions(MainActivity.this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_EXTERNAL_STORAGE_REQUEST_CODE);
shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)
=> ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
private final int WRITE_EXTERNAL_STORAGE_REQUEST_CODE = 123
private void takePhoto() {
//Make sure we have permission to write to external storage
int hasWriteExternalStoragePermission = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (hasWriteExternalStoragePermission == PackageManager.PERMISSION_GRANTED)
captureImage()
else
requestPermissionWriteToLocalStorage();
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 10
targetSdkVersion 23
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application ...>
...
</application>
chrome.extension.onMessage.addListener(function(message, sender, sendResponse) {
if(message.action == "toggle_playback"){
play_pause_button = document.getElementsByClassName('ytp-play-button ytp-button')[0]
if(play_pause_button){
play_pause_button.click();
}
}
});
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.query({}, function(tabs){
for (var i=0; i < tabs.length; i++) {
if (/https?:\/\/www\.youtube\.com/.test(tabs[i].url)) {
chrome.tabs.sendMessage(tabs[i].id, {action: "toggle_playback"}, function(response) {});
}
}
})
});
{
"manifest_version": 2,
"name": "YTPP",
"short_name": "YTPP",
"version": "0.1",
"description": "YTPP: YouTube Play/Pause without switching tabs",
"icons": {"128": "icon.png", "48": "icon_48.png", "16": "icon_16.png" },
"author": {"name": "spidergears", "twitter_handle": "spider_gears", "github": "http://github.com/spidergears"},
"browser_action": { "default_icon": "icon.png", "default_title": "YTPP"},