Skip to content

Instantly share code, notes, and snippets.

View Bramengton's full-sized avatar

Konstantin Bramengton

  • Ukraine, Mykolaiv city
View GitHub Profile
@Bramengton
Bramengton / message
Created January 28, 2019 14:13
Android, startActivityForResult <-> onActivityResult() in fragment
Одна из самых раздражающих недоработок Android проявляется когда нужно из фрагмента получить
изображение с камеры или выбрать из готовых.
Для этого используется Fragment.startActivityForResult(), а результат приходит в Fragment.onActivityResult().
Всё бы хорошо, но если фрагмент является потомком другого фрагмента, onActivityResult() не вызывается.
Решается не очень тривиально:
startActivityForResult() вызываем не для текущего фрагмента, а для родителя:
private Fragment getActivityStarterFragment() {
if (getParentFragment() != null) {
return getParentFragment();
LTR We will send an SMS with a confirmation code to your phone number: %s
On screen: We will send an SMS with a confirmation code to your phone number: +380123456789
RTL \u202Cאנו נשלח הודעת SMS עם קוד אישור למספר הטלפון שלך:\u202A %s
You can embed bidi regions using unicode format control codepoints:
Left-to-right embedding (U+202A)
Right-to-left embedding (U+202B)
Pop directional formatting (U+202C)
So in java, to embed a RTL language like Arabic in an LTR language like English, you would do
@Bramengton
Bramengton / Android Logcat Color
Created December 20, 2018 10:24
Custom Android Logcat Color
#####Logcat Colors for IntelliJ Darcula Theme ([original post](http://stackoverflow.com/questions/19933731/colored-logcat-in-android-studio-by-colorpid))
- Preferences -> Editor -> Android Logcat
- "Save As" scheme
- Uncheck "Use inherited attributes" option
- Edit foreground color with the following
```
Debug : #E5AD06
Info : #8AF990
@Bramengton
Bramengton / FileUtil.java
Created November 19, 2018 08:53 — forked from suweya/FileUtil.java
OkHttp download file by Okio
import android.os.Environment;
import android.support.annotation.NonNull;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.TimeUnit;
@Bramengton
Bramengton / VideoDownloader.java
Created November 19, 2018 08:52 — forked from fnk0/VideoDownloader.java
Example of how to download a video using Okhttp and show a progress bar to the user
class VideoDownloader extends AsyncTask<Void, Long, Boolean> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Boolean doInBackground(Void... params) {
As Dave Webb mentions, the Android Developer Blog has an article that covers this. Their preferred solution is to track app installs rather than devices, and that will work well for most use cases. The blog post will show you the necessary code to make that work, and I recommend you check it out.
However, the blog post goes on to discuss solutions if you need a device identifier rather than an app installation identifier. I spoke with someone at Google to get some additional clarification on a few items in the event that you need to do so. Here's what I discovered about device identifiers that's NOT mentioned in the aforementioned blog post:
ANDROID_ID is the preferred device identifier. ANDROID_ID is perfectly reliable on versions of Android <=2.1 or >=2.3. Only 2.2 has the problems mentioned in the post.
Several devices by several manufacturers are affected by the ANDROID_ID bug in 2.2.
As far as I've been able to determine, all affected devices have the same ANDROID_ID, which is 9774d56d682e549c. Which i
@Bramengton
Bramengton / gist:7ef11d1cf5affa18c5337656986cda67
Created October 2, 2018 22:00
Mac address in Android 6.0
There is a work-around to get the Mac address in Android 6.0.
First you need to add Internet user permission.
<uses-permission android:name="android.permission.INTERNET" />
Then you can find the mac over the NetworkInterfaces API.
public static String getMacAddr() {
try {
List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
@Bramengton
Bramengton / Postman.desktop
Created August 20, 2018 06:45 — forked from aviskase/Postman.desktop
Install Postman
[Desktop Entry]
Encoding=UTF-8
Name=Postman
Exec=postman
Icon=/opt/Postman/resources/app/assets/icon.png
Terminal=false
Type=Application
Categories=Development;
@Bramengton
Bramengton / NavigationApps.java
Last active December 9, 2020 11:37
Open navigation app and build route by coordinates (google map, waze, maps.me, navitel. city guide, osmand, yandex navigation, 2gis)
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
@Bramengton
Bramengton / test
Created August 3, 2018 10:42
Google map in CoordinatorLayout drag/tap/multi touch - work!
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();
AppBarLayout.Behavior behavior = new AppBarLayout.Behavior();
behavior.setDragCallback(new AppBarLayout.Behavior.DragCallback() {
@Override
public boolean canDrag(@NonNull AppBarLayout appBarLayout) {
return false;
}
});
params.setBehavior(behavior);