Skip to content

Instantly share code, notes, and snippets.

View omegasoft7's full-sized avatar
🎯

Farhad Sanaei omegasoft7

🎯
  • Germany, Hamburg
View GitHub Profile
@omegasoft7
omegasoft7 / change_strings.gradle
Created December 19, 2018 15:06
Change String Resources from Gradle
applicationVariants.all { variant ->
variant.mergeResources.doLast {
def dir = new File("${buildDir}/intermediates/res/merged/${variant.dirName}") //iterating through resources, prepared for including to APK (merged resources)
println("Resources dir " + dir)
dir.eachFileRecurse { file ->
if(file.name.endsWith(".xml")) { //processing only files, which names and with .xml
String content = file.getText('UTF-8')
if(content != null && content.contains("Bill")) {
println("Replacing name in " + file)
content = content.replace("Bill", "Will") //replacing all Bill words with Will word in files
@omegasoft7
omegasoft7 / gist:ec2285ae5a873d6f780b
Last active January 12, 2018 13:27
Change Android Emulator Storage Size
# Navigate to AVD
cd ~/.android/avd/Nexus5
# Delete old image
#rm userdata-qemu.*
# Re-size the image
e2fsck -f userdata-qemu.img
resize2fs userdata.img 512M
@omegasoft7
omegasoft7 / SetID to View Programmatically
Created January 9, 2015 09:52
SetID to a View Programmatically
Google finally realized the need of generating unique IDs for programmatically created views...
From API level 17 and above, you can call
View.generateViewId()
Then use View.setId(int).
In case you need it for targets lower than level 17, here is its internal implementation in View.java you can use directly in your project, put it in your util class or somewhere:
@omegasoft7
omegasoft7 / ExpandableVerticalLinearLayout.java
Created March 2, 2016 15:30
Make expandable Vertical LinearLayout.Height of view can be wrap content.open/close/toggle can be animated or without animation
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
/**
* Created by farhad on 16.2.3.
* this is an expandable linear Layout with orientation of Vertivally
* it will handle whole calculations and animations for height of View
* Your view can have wrap content, it will calculate exact height after adding views to the layout
@omegasoft7
omegasoft7 / createObservable RxJava
Created February 9, 2016 12:38
createObservable RxJava
public static Observable<String> createObservable(){
return Observable.create((Subscriber<? super String> subscriber) -> {
subscriber.onNext(Thread.currentThread().getName());
subscriber.onCompleted();
}
);
}
@omegasoft7
omegasoft7 / build.gradle
Created January 20, 2015 12:07
Tweet from Gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'org.twitter4j', name: 'twitter4j-core', version: '3.0.2'
}
}
import twitter4j.*
@omegasoft7
omegasoft7 / ActivitySwipeDetector.java
Created January 15, 2015 11:15
SwipeDetectorIt should set as ontouch event of a View
import android.app.Activity;
import android.view.MotionEvent;
import android.view.View;
public abstract class ActivitySwipeDetector implements View.OnTouchListener {
private Activity activity;
static final int MIN_DISTANCE = 100;
private float downX, downY, upX, upY;
@omegasoft7
omegasoft7 / ScrollView
Created January 15, 2015 08:18
What we can do to make ScrollView to fill Parent
Sometimes ScrollView doesn't fill parent 100%. in this case simply just add:
android:fillViewport="true"
to scrollview and that is it. :)
@omegasoft7
omegasoft7 / Logger.java
Created January 14, 2015 14:36
This is best logger for Android EVER
public class Logger {
//Variables------------------------------------------------------------------------
private static boolean LOGGING_ENABLED = true;
private static final int STACK_TRACE_LEVELS_UP = 5;
private static String TAG = "YourTag";
@omegasoft7
omegasoft7 / IsAppDebuggable.java
Created January 12, 2015 08:03
Check if the app is debuggable
/**
* Returns true if the application is debuggable.
*
* @return true if the application is debuggable.
*/
static boolean isDebuggable() {
PackageManager pm = mApplication.getPackageManager();
try {
return ((pm.getApplicationInfo(mApplication.getPackageName(), 0).flags & ApplicationInfo.FLAG_DEBUGGABLE) > 0);
} catch (NameNotFoundException e) {