Skip to content

Instantly share code, notes, and snippets.

View elfefe's full-sized avatar
💭
Mmmmh... Ah !

elfefe elfefe

💭
Mmmmh... Ah !
View GitHub Profile
@elfefe
elfefe / DetectFocused.java
Created October 28, 2019 08:14
Detect wich view(edittext here) is focused
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
View v = getCurrentFocus();
if (v != null) imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
if (v instanceof EditText) {
Rect outRect = new Rect();
v.getGlobalVisibleRect(outRect);
if (!outRect.contains((int) event.getRawX(), (int) event.getRawY())) {
v.clearFocus();
@elfefe
elfefe / hidekb.java
Created October 28, 2019 08:15
Always hide the keyboard
getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(findViewById(android.R.id.content).getWindowToken(), 0);
@elfefe
elfefe / commands.java
Last active October 28, 2019 10:02
Some adb commands and how to use them in an application.
/************************************************/
// To uninstall any application from the device use "pm uninstall -k --user 0 com.default.yourapp"
// @ATTENTION uninstall app with this command disalow the possibility to reinstall it, you'll need to refactory the phone to get it back !
// To search a package name "adb shell pm list packages | grep <search-term>"
/************************************************/
// To use this command in terminal start it by first "adb root"
// Then "adb shell" + "yourCOMMAND"
@elfefe
elfefe / LogFilter.java
Last active May 27, 2020 08:17
Options to filter the logcat
/*** Pour filtrer ce qu'on ne veux pas voir*/
// ^(?!.*(Ce que|je veux | pas voir *)).*$
@elfefe
elfefe / ExportDbToDevice.java
Created November 4, 2019 16:30
Export database to device
public void onExportDataButtonClick(View view) {
Log.d(TAG, "onExportDataButtonClick: " + checkIfUsbKeyExists());
if (checkIfUsbKeyExists()) {
exportDB();
new convertDBToCSV().execute(tables);
}
}
public boolean checkIfUsbKeyExists() {
@elfefe
elfefe / DateManager.java
Last active January 3, 2020 13:30
A simple date manager using the original android date system.
package com.elfefe.X.utils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class DateManager {
private int year;
private int month;
private int day;
@elfefe
elfefe / qr.html
Created November 7, 2019 10:36
Create a qrcode
<--! <content> is your url -->
https://chart.apis.google.com/chart?chs=150x150&cht=qr&chl=<content>&choe=UTF-8
@elfefe
elfefe / restart.java
Created November 13, 2019 07:34
Restart app
Intent i = context.getPackageManager().
getLaunchIntentForPackage(context.getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
@elfefe
elfefe / ArrayListUtil.java
Last active January 3, 2020 13:32
Initialise ArrayList simplifier
private ArrayList<String> initTable(String... strings){
return new ArrayList<>(Arrays.asList(strings));
}
@elfefe
elfefe / docker_bash.sh
Last active May 18, 2020 14:24
Access docker bash. + as root
docker exec -it YOUR_CONTAINER_TAG bash
docker exec -itu 0 YOUR_CONTAINER_TAG bash