Fixes crash on android version Lollipop and earlier due to an unsupported way vector drawable icons were assigned to radio buttons.
This commit is contained in:
parent
24b7e4db4c
commit
bd687fb45d
5 changed files with 44 additions and 11 deletions
|
@ -16,9 +16,15 @@
|
|||
package com.keylesspalace.tusky;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.BottomSheetDialogFragment;
|
||||
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||
import android.support.v4.graphics.drawable.DrawableCompat;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -85,8 +91,16 @@ public class ComposeOptionsFragment extends BottomSheetDialogFragment {
|
|||
}
|
||||
radio.check(radioCheckedId);
|
||||
|
||||
RadioButton publicButton = (RadioButton) rootView.findViewById(R.id.radio_public);
|
||||
RadioButton unlistedButton = (RadioButton) rootView.findViewById(R.id.radio_unlisted);
|
||||
RadioButton privateButton = (RadioButton) rootView.findViewById(R.id.radio_private);
|
||||
RadioButton directButton = (RadioButton) rootView.findViewById(R.id.radio_direct);
|
||||
setRadioButtonDrawable(getContext(), publicButton, R.drawable.ic_public_24dp);
|
||||
setRadioButtonDrawable(getContext(), unlistedButton, R.drawable.ic_lock_open_24dp);
|
||||
setRadioButtonDrawable(getContext(), privateButton, R.drawable.ic_lock_outline_24dp);
|
||||
setRadioButtonDrawable(getContext(), directButton, R.drawable.ic_email_24dp);
|
||||
|
||||
if (isReply) {
|
||||
RadioButton publicButton = (RadioButton) rootView.findViewById(R.id.radio_public);
|
||||
publicButton.setEnabled(false);
|
||||
}
|
||||
|
||||
|
@ -132,4 +146,27 @@ public class ComposeOptionsFragment extends BottomSheetDialogFragment {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void setRadioButtonDrawable(Context context, RadioButton button,
|
||||
@DrawableRes int id) {
|
||||
ColorStateList list = new ColorStateList(new int[][] {
|
||||
new int[] { -android.R.attr.state_checked },
|
||||
new int[] { android.R.attr.state_checked }
|
||||
}, new int[] {
|
||||
ThemeUtils.getColor(context, R.attr.compose_image_button_tint),
|
||||
ThemeUtils.getColor(context, R.attr.colorAccent)
|
||||
});
|
||||
Drawable drawable = VectorDrawableCompat.create(context.getResources(), id,
|
||||
context.getTheme());
|
||||
if (drawable == null) {
|
||||
return;
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
button.setButtonTintList(list);
|
||||
} else {
|
||||
drawable = DrawableCompat.wrap(drawable);
|
||||
DrawableCompat.setTintList(drawable, list);
|
||||
}
|
||||
button.setButtonDrawable(drawable);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@ import android.os.PersistableBundle;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
|
@ -274,7 +274,8 @@ public class MainActivity extends BaseActivity implements SFragment.OnUserRemove
|
|||
}
|
||||
});
|
||||
|
||||
Drawable muteDrawable = ContextCompat.getDrawable(this, R.drawable.ic_mute_24dp);
|
||||
VectorDrawableCompat muteDrawable = VectorDrawableCompat.create(getResources(),
|
||||
R.drawable.ic_mute_24dp, getTheme());
|
||||
ThemeUtils.setDrawableTint(this, muteDrawable, R.attr.toolbar_icon_tint);
|
||||
|
||||
drawer = new DrawerBuilder()
|
||||
|
|
|
@ -15,48 +15,40 @@
|
|||
|
||||
<RadioButton
|
||||
android:text="@string/visibility_public"
|
||||
android:button="@drawable/ic_public_24dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/radio_public"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:buttonTint="@color/drawer_visibility_panel_item"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<RadioButton
|
||||
android:text="@string/visibility_unlisted"
|
||||
android:button="@drawable/ic_lock_open_24dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/radio_unlisted"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:buttonTint="@color/drawer_visibility_panel_item"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<RadioButton
|
||||
android:text="@string/visibility_private"
|
||||
android:button="@drawable/ic_lock_outline_24dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/radio_private"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:buttonTint="@color/drawer_visibility_panel_item"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<RadioButton
|
||||
android:text="@string/visibility_direct"
|
||||
android:button="@drawable/ic_email_24dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/radio_direct"
|
||||
android:layout_marginTop="5dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:buttonTint="@color/drawer_visibility_panel_item"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</RadioGroup>
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
<attr name="compose_content_warning_bar_background" format="reference" />
|
||||
<attr name="compose_nsfw_button_color" format="reference|color" />
|
||||
<attr name="compose_nsfw_button_selected_color" format="reference|color" />
|
||||
<attr name="compose_image_button_tint" format="reference|color" />
|
||||
<attr name="report_status_background_color" format="reference|color" />
|
||||
<attr name="report_status_divider_drawable" format="reference" />
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
<item name="compose_content_warning_bar_background">@drawable/border_background_dark</item>
|
||||
<item name="compose_nsfw_button_color">@color/image_button_dark</item>
|
||||
<item name="compose_nsfw_button_selected_color">@color/color_accent_dark</item>
|
||||
<item name="compose_image_button_tint">@color/image_button_dark</item>
|
||||
<item name="report_status_background_color">@color/color_background_dark</item>
|
||||
<item name="report_status_divider_drawable">@drawable/status_divider_dark</item>
|
||||
|
||||
|
@ -148,6 +149,7 @@
|
|||
<item name="compose_content_warning_bar_background">@drawable/border_background_light</item>
|
||||
<item name="compose_nsfw_button_color">@color/image_button_light</item>
|
||||
<item name="compose_nsfw_button_selected_color">@color/color_accent_light</item>
|
||||
<item name="compose_image_button_tint">@color/image_button_light</item>
|
||||
<item name="report_status_background_color">@color/report_status_background_light</item>
|
||||
<item name="report_status_divider_drawable">@drawable/report_status_divider_light</item>
|
||||
|
||||
|
|
Loading…
Reference in a new issue