Skip to content

Instantly share code, notes, and snippets.

View PepDevils's full-sized avatar
🎯
Focusing

Pedro Fonseca PepDevils

🎯
Focusing
View GitHub Profile
@PepDevils
PepDevils / Transitions.java
Last active February 21, 2017 16:15
Apoio para transições e shared elements apenas entre Activities
// http://guides.codepath.com/android/shared-element-activity-transition
// https://medium.com/@andkulikov/animate-all-the-things-transitions-in-android-914af5477d50#.1jj56i6dy
//Activity.class
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Helper.MakeActivitiesTransitions(this); //sempre antes de setContent
setContentView(R.layout.activity_tv);
//more on:
// http://www.androidcodesnippets.com
// http://www.androidsnippets.com
// https://github.com/changer/android-utils/blob/master/Utils/app/src/main/java/nl/changer/android/opensource/Utils.java
static void TintDrawable(Context c, int drawable, int color){
//example: HelperUtils.TintDrawable(this, R.drawable.logo,R.color.colorPrimaryDark);
Drawable mDrawable = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
mDrawable = c.getResources().getDrawable(R.drawable.x, null);
//java
static void PepeToast(AppCompatActivity a, String message){
LayoutInflater inflater = a.getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) a.findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText(message);
Toast toast = new Toast(a);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
@PepDevils
PepDevils / gradle.java
Last active February 21, 2018 02:36
Faster gradle compile for android
//link:
// https://medium.com/@kevalpatel2106/how-to-decrease-your-gradle-build-time-by-65-310b572b0c43#.4rmzrcuj9
// https://gradle.org/install
//no terminal depois de ter o device instalado uma vez, usar
./gradlew android:assembleDebug --profile --configure-on-demand --daemon
// or this "app" root file name:
./gradlew app:assembleDebug --profile --configure-on-demand --daemon
//java class
JustifiedTextView id_example = (JustifiedTextView) v.findViewById(R.id.id_example);
//limpar todo o "[" e "]" bem como o que está entre os mesmos.
//Usado quando o html vem com shortcodes tipo:[vc_row].
String clean_string = string_example.replaceAll("\\[.*?\\]", "");
//mostrar string com elemntos do html
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
id_example.setText(Html.fromHtml(newsContent, Html.FROM_HTML_MODE_COMPACT));
@PepDevils
PepDevils / ReactivePrograming.java
Last active March 7, 2017 11:41
Android Connections
// important links
// Retrofit 2 - https://futurestud.io/tutorials/retrofit-getting-started-and-android-client
// Android/Java Pojo Objects for JSON requests - http://www.jsonschema2pojo.org
// +RxJava - https://medium.freecodecamp.com/rxandroid-and-retrofit-2-0-66dc52725fff#.eai8dux4j
// - https://github.com/JakeWharton/retrofit2-rxjava2-adapter
// - http://www.androidauthority.com/reactive-programming-with-rxandroid-711104/
// - https://www.learn2crack.com/2016/11/android-rxjava-2-and-retrofit.html
// - https://www.raywenderlich.com/141980/rxandroid-tutorial
// - https://github.com/kaushikgopal/RxJava-Android-Samples
// res/drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="@android:color/black"
android:centerColor="@color/black_overlay"
android:endColor="@android:color/transparent"
android:angle="90"
/>
@PepDevils
PepDevils / ActivityWithFragments.java
Last active February 20, 2017 17:32
Close all Fragments before the activity in onBackPressed button..
@Override
public void onBackPressed() {
List<Fragment> all_frags = getSupportFragmentManager().getFragments();
if(all_frags != null){
if (all_frags.size() == 0) {
super.onBackPressed();
} else {
for (Fragment frag : all_frags) {
getSupportFragmentManager().beginTransaction().remove(frag).commit();
}
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/colorAccent">
<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
@PepDevils
PepDevils / RunTimePermissons.java
Last active February 13, 2017 11:28
Actividade que vai iniciar o serviço do botão com a runtime autorization
public final static int REQUEST_CODE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_initial);
checkDrawOverlayPermission();
}