Skip to content

Commit

Permalink
Compatibility Below v21
Browse files Browse the repository at this point in the history
*There's no reason to show a permissions dialogue below Android M. This library is now compatible down to API 15 because why not. 
*Created nonblurred background fallback for v21 and below due to lack of rounded corners. Renderscript is supported down to v17 but no rounded corners looks terrible.
  • Loading branch information
rayliverified committed Feb 22, 2018
1 parent 82fb6e7 commit f781f9a
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 48 deletions.
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_permissions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:background="@drawable/bg_triangle_color"/>
app:srcCompat="@drawable/bg_triangle_color"/>

<android.support.v7.widget.CardView
android:id="@+id/cardview"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,11 @@ private void initPermissionsRecyclerView(View view) {

float radius = 5;

// ViewGroup rootView = builder.getDecorView().findViewById(android.R.id.content);
// Drawable windowBackground = builder.getDecorView().getBackground();
//
// BlurView blurView = view.findViewById(R.id.blurview);
// blurView.setupWith(rootView)
// .windowBackground(windowBackground)
// .blurAlgorithm(new RenderScriptBlur(mContext))
// .blurRadius(radius);

CustomBlurDialogue blurDialogue = view.findViewById(R.id.blurview);
blurDialogue.create(builder.getDecorView(), radius);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
CustomBlurDialogue blurDialogue = view.findViewById(R.id.blurview);
blurDialogue.create(builder.getDecorView(), radius);
}

if (builder.getTitle() != null)
{
Expand Down Expand Up @@ -269,11 +263,10 @@ private void initOptionalPermissionsRecyclerView(View view) {

float radius = 5;

ViewGroup rootView = builder.getDecorView().findViewById(android.R.id.content);
Drawable windowBackground = builder.getDecorView().getBackground();

CustomBlurDialogue blurDialogueOptional = view.findViewById(R.id.blurview_optional);
blurDialogueOptional.create(builder.getDecorView(), radius);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CustomBlurDialogue blurDialogueOptional = view.findViewById(R.id.blurview_optional);
blurDialogueOptional.create(builder.getDecorView(), radius);
}

if (builder.getMessageOptional() != null)
{
Expand Down Expand Up @@ -302,7 +295,13 @@ private void initPermissionsButton(View view) {
if (builder.getRequiredRequestPermissions().size() == 0)
{
mButton.setText("Continue");
mButton.setBackground(ContextCompat.getDrawable(mContext, R.drawable.icon_add_activated_selector));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mButton.setBackground(ContextCompat.getDrawable(mContext, R.drawable.icon_add_activated_selector));
}
else
{
mButton.setBackgroundDrawable((ContextCompat.getDrawable(mContext, R.drawable.icon_add_activated_selector)));
}
if (builder.getOnContinueClicked() != null)
{
mButton.setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -372,7 +371,13 @@ private void refreshPermissionsButton(boolean denied)
if (denied)
{
mButton.setText("DENIED - Open Settings");
mButton.setBackground(ContextCompat.getDrawable(mContext, R.drawable.icon_add_error_selector));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mButton.setBackground(ContextCompat.getDrawable(mContext, R.drawable.icon_add_error_selector));
}
else
{
mButton.setBackgroundDrawable(ContextCompat.getDrawable(mContext, R.drawable.icon_add_error_selector));
}
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand All @@ -389,7 +394,13 @@ public void onClick(View view) {
else if (builder.getRequiredRequestPermissions().size() == 0)
{
mButton.setText("Success!");
mButton.setBackground(ContextCompat.getDrawable(mContext, R.drawable.icon_add_activated_selector));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mButton.setBackground(ContextCompat.getDrawable(mContext, R.drawable.icon_add_activated_selector));
}
else
{
mButton.setBackgroundDrawable(ContextCompat.getDrawable(mContext, R.drawable.icon_add_activated_selector));
}
if (builder.getOnContinueClicked() != null)
{
mButton.setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -426,7 +437,13 @@ public void run() {
}
else {
mButton.setText("Permission Denied");
mButton.setBackground(ContextCompat.getDrawable(mContext, R.drawable.icon_add_error_selector));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mButton.setBackground(ContextCompat.getDrawable(mContext, R.drawable.icon_add_error_selector));
}
else
{
mButton.setBackgroundDrawable(ContextCompat.getDrawable(mContext, R.drawable.icon_add_error_selector));
}
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand All @@ -448,7 +465,13 @@ public void onClick(View view) {
Runnable r = new Runnable() {
public void run() {
mButton.setText("Grant Permissions");
mButton.setBackground(ContextCompat.getDrawable(mContext, R.drawable.icon_add));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mButton.setBackground(ContextCompat.getDrawable(mContext, R.drawable.icon_add));
}
else
{
mButton.setBackgroundDrawable(ContextCompat.getDrawable(mContext, R.drawable.icon_add));
}
}
};
handler.postDelayed(r, 1500);
Expand Down Expand Up @@ -976,6 +999,7 @@ public View getDecorView() {
return decorView;
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Builder setDecorView(View decorView) {

this.decorView = decorView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public void create(View decorView, float radius) {
.blurRadius(radius);
}

/**
* Set Rounded Corners on Lollipop and above. Use rounded drawable and disable blur below Lollipop.
* @param cornerRadius - set corner radius in pixels.
*/
private void setRoundedCorners(int cornerRadius) {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class PermissionUtils {

public static boolean IsPermissionEnabled(Context context, String permission)
{
if (Build.VERSION.SDK_INT >= 23) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
}
else
Expand All @@ -33,7 +33,7 @@ public static boolean IsPermissionsEnabled(Context context, String[] permissionL

public static boolean IsDefaultSMS(Context context)
{
if (Build.VERSION.SDK_INT >= 19) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
String defaultSMSApp = Telephony.Sms.getDefaultSmsPackage(context);
if (!defaultSMSApp.equals(context.getPackageName()))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<stream.custompermissionsdialogue.ui.CustomBlurDialogue
android:id="@+id/blurview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/alert_dialogue_margin_side"
android:layout_marginRight="@dimen/alert_dialogue_margin_side"
android:layout_marginTop="@dimen/alert_dialogue_margin_top"
android:layout_gravity="center_horizontal"
app:blurOverlayColor="@color/colorOverlay">

<LinearLayout
android:id="@+id/permissions_required"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:orientation="vertical">

<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/alert_text_margin_border"
android:layout_marginRight="@dimen/alert_text_margin_border"
android:gravity="center"
android:text="Permissions Manager"
android:textSize="@dimen/alert_text_title_size"
android:textColor="@color/alert_text_default"
android:textStyle="bold"/>

<ImageView
android:id="@+id/icon"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="18dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/icon_blank"
android:scaleType="fitXY"
android:elevation="2dp"/>

<TextView
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/alert_text_message_margin_bottom"
android:layout_marginLeft="@dimen/alert_text_margin_border"
android:layout_marginRight="@dimen/alert_text_margin_border"
android:gravity="center"
android:text="Custom Intro is a Custom app and requires the following permissions: "
android:textSize="@dimen/alert_text_message_size"
android:textColor="@color/alert_text_default"/>

<android.support.v7.widget.RecyclerView
android:id="@+id/permissions_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/alert_text_message_margin_bottom"
android:layout_gravity="center_horizontal"
android:scrollbars="none"
android:overScrollMode="never"/>

<Button
android:id="@+id/permissions_btn"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_marginTop="18dp"
android:layout_marginBottom="18dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_gravity="center_horizontal"
android:text="Grant Permissions"
android:textSize="16sp"
android:textColor="@color/white"
android:fontFamily="sans-serif-medium"
android:background="@drawable/icon_add_selector"
android:elevation="2dp"/>
</LinearLayout>
</stream.custompermissionsdialogue.ui.CustomBlurDialogue>

<stream.custompermissionsdialogue.ui.CustomBlurDialogue
android:id="@+id/blurview_optional"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/alert_dialogue_margin_side"
android:layout_marginRight="@dimen/alert_dialogue_margin_side"
android:layout_marginTop="@dimen/alert_dialogue_margin_top"
android:layout_gravity="center_horizontal"
app:blurOverlayColor="@color/colorOverlay">

<LinearLayout
android:id="@+id/permissions_optional"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:orientation="vertical">

<TextView
android:id="@+id/permissions_optional_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/alert_text_margin_border"
android:layout_marginRight="@dimen/alert_text_margin_border"
android:gravity="center"
android:text="Optional Permissions (enable for full app functionality): "
android:textSize="@dimen/alert_text_message_size"
android:textColor="@color/alert_text_default"/>

<android.support.v7.widget.RecyclerView
android:id="@+id/permissions_list_optional"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/alert_text_message_margin_bottom"
android:layout_gravity="center_horizontal"
android:scrollbars="vertical"
android:overScrollMode="never"/>
</LinearLayout>
</stream.custompermissionsdialogue.ui.CustomBlurDialogue>
</LinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_gravity="center_horizontal"
android:background="@null"
android:orientation="vertical">

<ImageView
android:id="@+id/permission_icon"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center_horizontal"
android:scaleType="fitCenter"
app:srcCompat="@drawable/ic_phone"/>

<TextView
android:id="@+id/permission_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_gravity="center_horizontal"
android:text="Permission"
android:textSize="14sp"
android:textColor="@color/textPrimary"
android:maxLines="1"
android:singleLine="true"
android:ellipsize="end"/>

<TextView
android:id="@+id/permission_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_gravity="center_horizontal"
android:text="Permission is required to send app."
android:textSize="12sp"
android:textColor="@color/textSecondary"/>

<stream.custombutton.CustomButton
android:id="@+id/permission_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:layout_gravity="center_horizontal"
android:text="Enable"
android:textSize="12sp"
android:fontFamily="sans-serif-medium"
android:maxLines="1"
android:singleLine="true"
android:ellipsize="none"
app:btn_cornerRadius="20dp"
app:btn_strokeWidth="1dp"
app:btn_strokeColor="@color/button_pressed"
app:btn_buttonColor="@color/transparent"
app:btn_buttonSelectColor="@color/button_pressed"
app:btn_textColor="@color/button_pressed"
app:btn_textSelectColor="@color/white"/>
</LinearLayout>
Loading

0 comments on commit f781f9a

Please sign in to comment.