improved ugly white border of profile image/fab on 4.x devices

fixed possibly crash in other settings on 4.0 devices
This commit is contained in:
Mariotaku Lee 2015-03-20 01:10:42 +08:00
parent d05423e77c
commit 42532e068c
24 changed files with 138 additions and 87 deletions

View File

@ -261,7 +261,7 @@ public class SettingsWizardActivity extends Activity implements Constants {
@Override
protected int getPreferenceResource() {
return R.xml.settings_cards;
return R.xml.preferences_cards;
}
}
@ -441,7 +441,7 @@ public class SettingsWizardActivity extends Activity implements Constants {
@Override
protected int getPreferenceResource() {
return R.xml.settings_theme;
return R.xml.preferences_theme;
}
}

View File

@ -39,7 +39,7 @@ public class AccountNotificationSettingsFragment extends BaseAccountPreferenceFr
@Override
protected int getPreferencesResource() {
return R.xml.settings_account_notifications;
return R.xml.preferences_account_notifications;
}
@Override

View File

@ -25,7 +25,7 @@ public class AccountRefreshSettingsFragment extends BaseAccountPreferenceFragmen
@Override
protected int getPreferencesResource() {
return R.xml.settings_account_refresh;
return R.xml.preferences_account_refresh;
}
@Override

View File

@ -10,69 +10,74 @@ import android.util.AttributeSet;
public class ComponentStatePreference extends CheckBoxPreference {
private final PackageManager mPackageManager;
private final ComponentName mComponentName;
private final PackageManager mPackageManager;
private final ComponentName mComponentName;
public ComponentStatePreference(final Context context) {
this(context, null);
}
public ComponentStatePreference(final Context context) {
this(context, null);
}
public ComponentStatePreference(final Context context, final AttributeSet attrs) {
this(context, attrs, android.R.attr.checkBoxPreferenceStyle);
}
public ComponentStatePreference(final Context context, final AttributeSet attrs) {
this(context, attrs, android.R.attr.checkBoxPreferenceStyle);
}
public ComponentStatePreference(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
final TypedArray a = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.name });
final String name = a.getString(0);
public ComponentStatePreference(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
final TypedArray a = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.name});
final String name = a.getString(0);
a.recycle();
if (name == null) throw new NullPointerException();
mPackageManager = context.getPackageManager();
mComponentName = new ComponentName(context.getPackageName(), name);
setDefaultValue(isComponentEnabled());
}
if (name == null) throw new NullPointerException();
mPackageManager = context.getPackageManager();
mComponentName = new ComponentName(context.getPackageName(), name);
setDefaultValue(isComponentEnabled());
}
@Override
public boolean shouldDisableDependents() {
final boolean disableDependentsState = getDisableDependentsState();
final boolean value = isComponentEnabled();
return disableDependentsState ? value : !value;
}
@Override
public boolean shouldDisableDependents() {
final boolean disableDependentsState = getDisableDependentsState();
final boolean value = isComponentEnabled();
return disableDependentsState ? value : !value;
}
@Override
protected boolean getPersistedBoolean(final boolean defaultReturnValue) {
return isComponentEnabled();
}
@Override
protected boolean getPersistedBoolean(final boolean defaultReturnValue) {
return isComponentEnabled();
}
@Override
protected Object onGetDefaultValue(final TypedArray a, final int index) {
return isComponentEnabled();
}
@Override
protected Object onGetDefaultValue(final TypedArray a, final int index) {
return isComponentEnabled();
}
@Override
protected void onSetInitialValue(final boolean restoreValue, final Object defaultValue) {
setChecked(getPersistedBoolean(true));
}
@Override
protected void onSetInitialValue(final boolean restoreValue, final Object defaultValue) {
setChecked(getPersistedBoolean(true));
}
@Override
protected boolean persistBoolean(final boolean value) {
final int newState = value ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
mPackageManager.setComponentEnabledSetting(mComponentName, newState, PackageManager.DONT_KILL_APP);
return true;
}
@Override
protected boolean persistBoolean(final boolean value) {
final int newState = value ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
mPackageManager.setComponentEnabledSetting(mComponentName, newState, PackageManager.DONT_KILL_APP);
return true;
}
@Override
protected boolean shouldPersist() {
return true;
}
@Override
protected boolean shouldPersist() {
return true;
}
@SuppressLint("InlinedApi")
private boolean isComponentEnabled() {
final int state = mPackageManager.getComponentEnabledSetting(mComponentName);
return state != PackageManager.COMPONENT_ENABLED_STATE_DISABLED
&& state != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER
&& state != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED;
}
@SuppressLint("InlinedApi")
private boolean isComponentEnabled() {
try {
final int state = mPackageManager.getComponentEnabledSetting(mComponentName);
return state != PackageManager.COMPONENT_ENABLED_STATE_DISABLED
&& state != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER
&& state != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED;
} catch (NullPointerException e) {
// Seems this will thrown on older devices
return false;
}
}
}

View File

@ -31,19 +31,19 @@ import org.mariotaku.twidere.fragment.SettingsDetailsFragment;
public class SecretCodeBroadcastReceiver extends BroadcastReceiver implements IntentConstants {
@Override
public void onReceive(final Context context, final Intent intent) {
final Intent testIntent = new Intent(context, SettingsActivity.class);
final String cls = SettingsDetailsFragment.class.getName();
final String title = context.getString(R.string.hidden_settings);
final Bundle args = new Bundle();
args.putInt(EXTRA_RESID, R.xml.settings_hidden);
testIntent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, cls);
testIntent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
testIntent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, title);
testIntent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_SHORT_TITLE, title);
testIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(testIntent);
}
@Override
public void onReceive(final Context context, final Intent intent) {
final Intent testIntent = new Intent(context, SettingsActivity.class);
final String cls = SettingsDetailsFragment.class.getName();
final String title = context.getString(R.string.hidden_settings);
final Bundle args = new Bundle();
args.putInt(EXTRA_RESID, R.xml.preferences_hidden);
testIntent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, cls);
testIntent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
testIntent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, title);
testIntent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_SHORT_TITLE, title);
testIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(testIntent);
}
}

View File

@ -24,7 +24,6 @@ import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
@ -166,6 +165,7 @@ public class HomeActionButtonCompat extends FrameLayout implements IHomeActionBu
super.onBoundsChange(bounds);
mBounds.set(bounds);
updateBitmap();
invalidateSelf();
}
@Override
@ -180,6 +180,7 @@ public class HomeActionButtonCompat extends FrameLayout implements IHomeActionBu
public void setColor(int color) {
mColorPaint.setColor(color);
updateBitmap();
invalidateSelf();
}
@ -187,9 +188,9 @@ public class HomeActionButtonCompat extends FrameLayout implements IHomeActionBu
final Rect bounds = mBounds;
if (bounds.isEmpty()) return;
mBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Config.ARGB_8888);
Canvas canvas = new Canvas(mBitmap);
final Canvas canvas = new Canvas(mBitmap);
final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);
paint.setColor(0xFF000000 | mColorPaint.getColor());
final float radius = mRadius;
paint.setShadowLayer(radius, 0, radius * 1.5f / 2, SHADOW_START_COLOR);
final RectF rect = new RectF(mView.getPaddingLeft(), mView.getPaddingTop(),
@ -198,7 +199,6 @@ public class HomeActionButtonCompat extends FrameLayout implements IHomeActionBu
paint.setShadowLayer(0, 0, 0, 0);
paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
canvas.drawOval(rect, paint);
invalidateSelf();
}
}

View File

@ -475,7 +475,7 @@ public class ShapedImageView extends ImageView {
mShadowBitmap = Bitmap.createBitmap(size, Math.round(size + dy), Config.ARGB_8888);
Canvas canvas = new Canvas(mShadowBitmap);
final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);
paint.setColor(0xFF000000 | mBackgroundPaint.getColor());
paint.setShadowLayer(radius, 0, radius * 1.5f / 2, SHADOW_START_COLOR);
final RectF rect = new RectF(radius, radius, size - radius, size - radius);
if (getStyle() == SHAPE_CIRCLE) {

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Twidere - Twitter client for Android
~
~ Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/element_spacing_normal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/usage_statistics_header_summary"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:textColorPrimary"/>
</LinearLayout>

View File

@ -730,5 +730,6 @@
<string name="designed_by">Designed by</string>
<string name="designer_name">Uucky Lee</string>
<string name="import_export_settings">Import/Export settings</string>
<string name="usage_statistics_header_summary">Twidere took part in some research project, join these projects will make Twidere and some other application better.</string>
</resources>

View File

@ -40,7 +40,7 @@
android:title="@string/data_profiling">
<extra
android:name="resid"
android:value="@xml/settings_usage_statistics"/>
android:value="@xml/preferences_usage_statistics"/>
</Preference>
<org.mariotaku.twidere.preference.SettingsImportExportPreference

View File

@ -20,4 +20,14 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference android:layout="@layout/header_usage_statistics"/>
<org.mariotaku.twidere.preference.ResourceIconPreference
android:order="11"
android:title="@string/research_ucdavis_earlybird"/>
<org.mariotaku.twidere.preference.ResourceIconPreference
android:order="12"
android:title="@string/research_tsinghua_spice"/>
</PreferenceScreen>

View File

@ -8,7 +8,7 @@
android:title="@string/theme">
<extra
android:name="resid"
android:value="@xml/settings_theme"/>
android:value="@xml/preferences_theme"/>
</header>
<header
android:fragment="org.mariotaku.twidere.fragment.SettingsDetailsFragment"
@ -16,7 +16,7 @@
android:title="@string/settings_interface">
<extra
android:name="resid"
android:value="@xml/settings_interface"/>
android:value="@xml/preferences_interface"/>
</header>
<header
android:fragment="org.mariotaku.twidere.fragment.SettingsDetailsFragment"
@ -24,7 +24,7 @@
android:title="@string/cards">
<extra
android:name="resid"
android:value="@xml/settings_cards"/>
android:value="@xml/preferences_cards"/>
</header>
<header android:title="@string/function"/>
<header
@ -41,7 +41,7 @@
android:title="@string/network">
<extra
android:name="resid"
android:value="@xml/settings_network"/>
android:value="@xml/preferences_network"/>
</header>
<header
android:fragment="org.mariotaku.twidere.fragment.SettingsDetailsFragment"
@ -49,7 +49,7 @@
android:title="@string/content">
<extra
android:name="resid"
android:value="@xml/settings_content"/>
android:value="@xml/preferences_content"/>
</header>
<header
android:fragment="org.mariotaku.twidere.fragment.SettingsDetailsFragment"
@ -57,7 +57,7 @@
android:title="@string/storage">
<extra
android:name="resid"
android:value="@xml/settings_storage"/>
android:value="@xml/preferences_storage"/>
</header>
<header
android:fragment="org.mariotaku.twidere.fragment.SettingsDetailsFragment"
@ -65,7 +65,7 @@
android:title="@string/refresh">
<extra
android:name="resid"
android:value="@xml/settings_refresh"/>
android:value="@xml/preferences_refresh"/>
</header>
<header
android:fragment="org.mariotaku.twidere.fragment.SettingsDetailsFragment"
@ -73,7 +73,7 @@
android:title="@string/notifications">
<extra
android:name="resid"
android:value="@xml/settings_notifications"/>
android:value="@xml/preferences_notifications"/>
</header>
<header
android:fragment="org.mariotaku.twidere.fragment.SettingsDetailsFragment"
@ -81,7 +81,7 @@
android:title="@string/other_settings">
<extra
android:name="resid"
android:value="@xml/settings_other"/>
android:value="@xml/preferences_other"/>
</header>
<header android:title="@string/about"/>
<header
@ -90,7 +90,7 @@
android:title="@string/about">
<extra
android:name="resid"
android:value="@xml/about"/>
android:value="@xml/preferences_about"/>
</header>
<header
android:fragment="org.mariotaku.twidere.fragment.BrowserFragment"