This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Here, thisActivity is the current activity | |
if (ContextCompat.checkSelfPermission(thisActivity, | |
Manifest.permission.READ_CONTACTS) | |
!= PackageManager.PERMISSION_GRANTED) { | |
// Should we show an explanation? | |
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity, | |
Manifest.permission.READ_CONTACTS)) { | |
// Show an expanation to the user *asynchronously* -- don't block | |
// this thread waiting for the user's response! After the user | |
// sees the explanation, try again to request the permission. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void firstTimeAskingPermission(Context context, String permission, boolean isFirstTime){ | |
SharedPreferences sharedPreference = context.getSharedPreferences(PREFS_FILE_NAME, MODE_PRIVATE; | |
sharedPreference.edit().putBoolean(permission, isFirstTime).apply(); | |
} | |
public static boolean isFirstTimeAskingPermission(Context context, String permission){ | |
return context.getSharedPreferences(PREFS_FILE_NAME, MODE_PRIVATE).getBoolean(permission, true); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Here, thisActivity is the current activity | |
if (ContextCompat.checkSelfPermission(thisActivity, | |
Manifest.permission.READ_CONTACTS) | |
!= PackageManager.PERMISSION_GRANTED) { | |
// Should we show an explanation? | |
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity, | |
Manifest.permission.READ_CONTACTS)) { | |
// Show an expanation to the user *asynchronously* -- don't block | |
// this thread waiting for the user's response! After the user | |
// sees the explanation, try again to request the permission. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PermissionUtil { | |
/* | |
* Check if version is marshmallow and above. | |
* Used in deciding to ask runtime permission | |
* */ | |
public static boolean shouldAskPermission() { | |
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M); | |
} | |
private static boolean shouldAskPermission(Context context, String permission){ | |
if (shouldAskPermission()) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PermissionUtil.checkPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE, | |
new PermissionUtil.PermissionAskListener() { | |
@Override | |
public void onNeedPermission() { | |
ActivityCompat.requestPermissions( | |
thisActivity, | |
new String[]{Manifest.permission.READ_CONTACTS}, | |
REQUEST_EXTERNAL_STORAGE | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<FrameLayout | |
android:id="@+id/speaker_avatar_container" | |
android:layout_width="40dp" | |
android:layout_height="40dp" | |
android:layout_gravity="center_vertical"> | |
<TextView | |
android:id="@+id/placeholder" | |
android:layout_width="40dp" | |
android:layout_height="40dp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<shape xmlns:android="http://schemas.android.com/apk/res/android" | |
android:shape="rectangle"> | |
<corners android:radius="20dp" /> | |
<solid android:color="@color/grey" /> | |
<size | |
android:width="40dp" | |
android:height="40dp" /> | |
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
placeholder.setText(getInitials()); | |
ViewUtil.setVisibility(avatar, View.GONE); | |
Glide.with(context) | |
.load(member.getAvatar()) | |
.asBitmap() | |
.into(new SimpleTarget<Bitmap>() { | |
@Override | |
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { | |
avatar.setImageBitmap(resource); | |
ViewUtil.setVisibility(placeholder, View.GONE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<shape xmlns:android="http://schemas.android.com/apk/res/android" | |
android:shape="rectangle"> | |
<solid android:color="@color/grey" /> | |
<size | |
android:width="40dp" | |
android:height="40dp" /> | |
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<FrameLayout | |
android:id="@+id/speaker_avatar_container" | |
android:layout_width="40dp" | |
android:layout_height="40dp" | |
android:layout_gravity="center_vertical"> | |
<TextView | |
android:id="@+id/placeholder" | |
android:layout_width="40dp" | |
android:layout_height="40dp" |
OlderNewer