Skip to content

Instantly share code, notes, and snippets.

@nahba
nahba / Regex.java
Created May 24, 2017 12:41
Regex Java
1. Replace character(s) other than specified
String name = "android";
name = name.replaceAll("[^an]", "");
Output:: "an"
2. Separate word with space from String
String name = "AndroidIsOpenSource";
name = name.replaceAll("(.)([A-Z])", "$1 $2");
Output:: "Android Is Open Source"
@nahba
nahba / app.gradle
Created March 29, 2017 06:49
Gradle specific tasks
1. If you need to disable all transitive dependencies and apply by yourself
configurations.all {
transitive = false
}
2. How check dependencies tree (Terminal in AndroidStudio)
gradlew/gradlew.bat -q dependencies app:dependencies --configuration compile/testCompile/androidTestCompile
@nahba
nahba / AndroidWithJenkins
Created March 29, 2017 05:47
Android Jenkins (Platform: Windows 7 - 64Bit)
1. Download Jenkins from https://jenkins.io/download/
2. Using CMD, run this command "java -jar jenkins.war". This will create .jenkins folder in C:\Users\(USER_NAME)\.jenkins
- Make sure you have installed JDK and set path
3. Open Jenkins using http://localhost:8080/
4. Go to "Manage Jenkins"
5. Go to "Configure Global Security"
- Enable security
- Security Realm -> Jenkins’ own user database (+ Allow users to sign up)
- Authorization -> Matrix-based security
- Add new User and check all checkboxes
@nahba
nahba / DexCount
Created March 21, 2017 05:49
Enable DexCount In Android
1. Build your project
2. Check "Run" console to see Methods count
Total methods in app-debug.apk: 23265 (35.50% used)
Total fields in app-debug.apk: 11160 (17.03% used)
Methods remaining in app-debug.apk: 42270
Fields remaining in app-debug.apk: 54375
3. To see graph
app/build/outputs/dexcount
@nahba
nahba / ProtoBuf
Last active January 2, 2017 06:33
Protobuf Android
1. Add classpath 'com.squareup.wire:wire-compiler:2.2.0' in project (build.gradle)
2. Add dependency compile 'com.squareup.wire:wire-runtime:2.2.0' in app (build.gradle)
3. Sync project
4. Add "wire-compiler-2.2.0-jar-with-dependencies.jar" to your app folder
5. Create src\main\proto\nahba folder
6. Create .proto files as dinosaur.proto and period.proto
7. In Terminal, from app folder run below command
java -jar wire-compiler-2.2.0-jar-with-dependencies.jar --proto_path=src/main/proto --java_out=src/main/java
8. This will create all required Java Classes
9. Access in your activity/fragment as below
@nahba
nahba / WindowManagerOverlay
Last active June 16, 2016 09:12
Add Overlay - API 23
Build Project Using API 23
Manifest Permission:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams windowParams = new WindowManager.LayoutParams(YOUR_DESIRED_WIDTH, YOUR_DESIRED_HEIGHT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
@nahba
nahba / Studio
Created March 10, 2016 06:26
Android Studio Tips
1. Disable components update on first start
disable.android.first.run=true -> bin/idea.properties
@nahba
nahba / HowToUseGradleProperties
Last active April 8, 2023 13:40
Boost Gradle Build
Put this gradle.properties in your /users/.gradle folder
/home/<username>/.gradle/ (Linux)
/Users/<username>/.gradle/ (Mac)
C:\Users\<username>\.gradle (Windows)
@nahba
nahba / WirelessInstallationOfAPK
Last active March 3, 2016 05:42
Connect Device And Install APK Wirelessly
$adb tcpip 5555
$adb shell netcfg
$adb connect <DEVICE_IP_ADDRESS>:5555
$adb -s <DEVICE_IP_ADDRESS>:5555 install (ApplicationName).apk
$adb -s <DEVICE_IP_ADDRESS>:5555 usb (Back To USB Debugging) !important
@nahba
nahba / WhatToCommitForGradleProject
Last active March 3, 2016 05:45
Gradle Project Import Files
Only commit following folders/files when commiting Gradle based project.
Folders:
=======
1) app -> src, build.gradle, proguard-rules.pro
2) gradle -> wrapper -> gradle-wrapper (both)
Files:
=====
1) build.gradle