Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexandr luck-alex13

  • Russia
View GitHub Profile
@luck-alex13
luck-alex13 / TriangleLabelView.java
Last active Sep 2, 2019
TriangleLabelView for CardView
View TriangleLabelView.java
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.*;
import android.os.Build;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.StringRes;
import androidx.core.content.ContextCompat;
View UIExtensions.swift
import UIKit
public extension UIViewController {
func setTitle(title:String) {
self.title = title
}
func setEmptyBackArrow(){
// удаляет текст возле кнопки назад
@luck-alex13
luck-alex13 / ValidationHelper.java
Created Mar 5, 2019
Email and password validation helper
View ValidationHelper.java
package com.example.user.testapphandh;
import android.util.Patterns;
import java.util.regex.Pattern;
public class ValidationHelper {
/*
( # Start of group
@luck-alex13
luck-alex13 / back_button.xml
Created Apr 14, 2018
default android back arrow button
View back_button.xml
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="?attr/homeAsUpIndicator"
android:background="?attr/selectableItemBackgroundBorderless"/>
@luck-alex13
luck-alex13 / build.gradle
Created Apr 14, 2018
Автоматическое именование apk при сборке
View build.gradle
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "${variant.flavorName}-${variant.buildType.name}-${variant.versionCode}.apk"
}
}
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "appName-${variant.buildType.name}-vCode-${variant.versionCode}-vName-${variant.versionName}.apk"
}
}
View AbstractFragment.java
public class AbstractFragment extends Fragment {
protected int fragmentId, toolbarTitle;
private FragmentActivity activity;
public AbstractFragment() {
}
@luck-alex13
luck-alex13 / sendImplicitIntent
Created Mar 28, 2018
Стартует сервис у которого в <intent-filter> прописан ACTION_CUSTOM_EVENT. Таким же образом можно стартануть активити
View sendImplicitIntent
public static Intent convertImplicitIntentToExplicitIntent(Intent implicitIntent, Context context) {
PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolveInfoList = pm.queryIntentServices(implicitIntent, 0);
if (resolveInfoList == null || resolveInfoList.size() != 1) {
return null;
}
ResolveInfo serviceInfo = resolveInfoList.get(0);
ComponentName component = new ComponentName(serviceInfo.serviceInfo.packageName, serviceInfo.serviceInfo.name);
Intent explicitIntent = new Intent(implicitIntent);
explicitIntent.setComponent(component);
@luck-alex13
luck-alex13 / sendImplicitBroadcast
Created Mar 28, 2018
Отправляет кастомный броадкаст (для Android 8)
View sendImplicitBroadcast
private static void sendImplicitBroadcast(Context ctxt, Intent i) {
PackageManager pm = ctxt.getPackageManager();
List<ResolveInfo> matches = pm.queryBroadcastReceivers(i, 0);
for (ResolveInfo resolveInfo : matches) {
Intent explicit = new Intent(i);
ComponentName cn =
new ComponentName(resolveInfo.activityInfo.applicationInfo.packageName,
resolveInfo.activityInfo.name);
@luck-alex13
luck-alex13 / SomeClass
Last active Mar 1, 2018
Default html and links support in TextView
View SomeClass
textView.setText(fromHtml(text));
textView.setMovementMethod(LinkMovementMethod.getInstance());
public static Spanned fromHtml(String html) {
Spanned result;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
result = Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
} else {
result = Html.fromHtml(html);
@luck-alex13
luck-alex13 / PopupMenu
Created Feb 19, 2018
Show Android Popup Menu
View PopupMenu
public static PopupMenu buildPopupMenu(View view, int menuRes) {
PopupMenu popup = new PopupMenu(view.getContext(), view);
popup.inflate(menuRes);
return popup;
}
public static PopupMenu showPopupMenuOn(View view, int menuRes, PopupMenu.OnMenuItemClickListener listener){
PopupMenu menu = buildPopupMenu(view, menuRes);
menu.setOnMenuItemClickListener(listener);
menu.show();
You can’t perform that action at this time.