This commit is contained in:
Mariotaku Lee 2016-03-16 12:11:29 +08:00
parent 7c8c73a152
commit 5e2bfa6660
6 changed files with 49 additions and 20 deletions

View File

@ -121,11 +121,15 @@ public class TwidereApplication extends Application implements Constants,
StrictModeUtils.detectAllVmPolicy();
}
ATE.registerViewProcessor(TabPagerIndicator.class, new TabPagerIndicatorViewProcessor());
final SharedPreferences preferences = getSharedPreferences();
if (!ATE.config(this, null).isConfigured()) {
final int accentColor = ThemeUtils.getUserAccentColor(this);
ATE.config(this, null).primaryColor(accentColor).accentColor(accentColor).commit();
final int themeColor = preferences.getInt(KEY_THEME_COLOR, ContextCompat.getColor(this,
R.color.branding_color));
ATE.config(this, "light").primaryColor(themeColor).accentColor(themeColor).coloredActionBar(true).commit();
ATE.config(this, "dark").accentColor(themeColor).coloredActionBar(false).commit();
ATE.config(this, null).primaryColor(themeColor).accentColor(themeColor).commit();
}
resetTheme(getSharedPreferences());
resetTheme(preferences);
super.onCreate();
initializeAsyncTask();
initDebugMode();
@ -268,8 +272,8 @@ public class TwidereApplication extends Application implements Constants,
}
case KEY_THEME_COLOR: {
final int themeColor = preferences.getInt(key, ContextCompat.getColor(this, R.color.branding_color));
ATE.config(this, "light").primaryColor(themeColor).accentColor(themeColor).commit();
ATE.config(this, "dark").accentColor(themeColor).commit();
ATE.config(this, "light").primaryColor(themeColor).accentColor(themeColor).coloredActionBar(true).commit();
ATE.config(this, "dark").accentColor(themeColor).coloredActionBar(false).commit();
break;
}
}

View File

@ -27,11 +27,13 @@ import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.internal.widget.PreferenceImageView;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
@ -113,6 +115,9 @@ public abstract class AccountsListPreference extends PreferenceCategory implemen
mAccount = account;
mSwitchPreference = context.getSharedPreferences(switchPreferenceName, Context.MODE_PRIVATE);
mSwitchPreference.registerOnSharedPreferenceChangeListener(this);
setTitle(mAccount.name);
setSummary(String.format("@%s", mAccount.screen_name));
mImageLoader.loadProfileImage(mAccount, this);
}
@Override
@ -123,7 +128,9 @@ public abstract class AccountsListPreference extends PreferenceCategory implemen
@Override
public void onLoadingComplete(final String imageUri, final View view, final Bitmap loadedImage) {
final Bitmap roundedBitmap = BitmapUtils.getCircleBitmap(loadedImage);
setIcon(new BitmapDrawable(getContext().getResources(), roundedBitmap));
final BitmapDrawable icon = new BitmapDrawable(getContext().getResources(), roundedBitmap);
icon.setGravity(Gravity.FILL);
setIcon(icon);
}
@Override
@ -141,21 +148,18 @@ public abstract class AccountsListPreference extends PreferenceCategory implemen
notifyChanged();
}
@Override
protected void onAttachedToHierarchy(@NonNull final PreferenceManager preferenceManager) {
super.onAttachedToHierarchy(preferenceManager);
setTitle(mAccount.name);
setSummary(String.format("@%s", mAccount.screen_name));
// setIcon(R.drawable.ic_profile_image_default);
mImageLoader.loadProfileImage(mAccount.profile_image_url, this);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
final View iconView = holder.findViewById(android.R.id.icon);
if (iconView instanceof ImageView) {
final ImageView imageView = (ImageView) iconView;
if (iconView instanceof PreferenceImageView) {
final PreferenceImageView imageView = (PreferenceImageView) iconView;
final int maxSize = getContext().getResources().getDimensionPixelSize(R.dimen.element_size_normal);
imageView.setMinimumWidth(maxSize);
imageView.setMinimumHeight(maxSize);
imageView.setMaxWidth(maxSize);
imageView.setMaxHeight(maxSize);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
final View titleView = holder.findViewById(android.R.id.title);

View File

@ -220,6 +220,15 @@ public class MediaLoaderWrapper implements Constants {
mImageLoader.displayImage(url, view, mProfileImageDisplayOptions, listener);
}
public void loadProfileImage(final ParcelableAccount account, final ImageLoadingListener listener) {
if (account.account_user != null && account.account_user.extras != null
&& !TextUtils.isEmpty(account.account_user.extras.profile_image_url_profile_size)) {
loadProfileImage(account.account_user.extras.profile_image_url_profile_size, listener);
} else {
loadProfileImage(account.profile_image_url, listener);
}
}
public void loadProfileImage(final String url, final ImageLoadingListener listener) {
mImageLoader.loadImage(url, mProfileImageDisplayOptions, listener);
}

View File

@ -1,9 +1,11 @@
package org.mariotaku.twidere.util.theme;
import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import com.afollestad.appthemeengine.Config;
import com.afollestad.appthemeengine.util.ATEUtil;
import com.afollestad.appthemeengine.viewprocessors.ViewProcessor;
import org.mariotaku.twidere.view.TabPagerIndicator;
@ -14,6 +16,16 @@ import org.mariotaku.twidere.view.TabPagerIndicator;
public class TabPagerIndicatorViewProcessor implements ViewProcessor<TabPagerIndicator, Object> {
@Override
public void process(@NonNull Context context, String key, TabPagerIndicator view, Object extra) {
final int primaryColor = Config.primaryColor(context, key);
final boolean isDark = !ATEUtil.isColorLight(primaryColor);
final int primaryColorDependent = isDark ? Color.WHITE : Color.BLACK;
view.setIconColor(primaryColorDependent);
view.setLabelColor(primaryColorDependent);
if (Config.coloredActionBar(context, key)) {
view.setStripColor(primaryColorDependent);
} else {
view.setStripColor(Config.accentColor(context, key));
}
view.updateAppearance();
}
}

View File

@ -37,7 +37,6 @@
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:elevation="@dimen/toolbar_elevation"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp">
@ -58,7 +57,7 @@
android:layout_margin="@dimen/element_spacing_large"
android:clickable="true"
android:src="@drawable/ic_action_status_compose"
app:backgroundTint="?colorPrimary"
android:tag="background|primary_color,tint|primary_color_dependent"
app:elevation="6dp"
app:pressedTranslationZ="12dp"/>

View File

@ -26,4 +26,5 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"/>
android:singleLine="true"
android:textColor="?colorAccent"/>