Commit a2bc6a77 authored by Donald's avatar Donald

Vai Jibo your turn!

parent 2be27075
......@@ -408,7 +408,7 @@ public class SettingsActivity extends ThemedActivity {
private void cardViewDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(SettingsActivity.this);
AlertDialog.Builder builder = new AlertDialog.Builder(SettingsActivity.this, getDialogStyle());
View layout = getLayoutInflater().inflate(R.layout.dialog_selec_cardview, null);
final ViewPager mViewPager = (ViewPager) layout.findViewById(R.id.viewPager);
CardPagerAdapter mCardAdapter = new CardPagerAdapter(getBaseContext());
......
......@@ -18,10 +18,10 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy;
import org.horaapps.leafpic.R;
import org.horaapps.leafpic.model.Album;
import org.horaapps.leafpic.model.Media;
import org.horaapps.leafpic.util.StringUtils;
import org.horaapps.leafpic.util.CardViewStyle;
import org.horaapps.leafpic.util.ColorPalette;
import org.horaapps.leafpic.util.PreferenceUtil;
import org.horaapps.leafpic.util.StringUtils;
import org.horaapps.leafpic.util.ThemeHelper;
import java.util.ArrayList;
......@@ -85,17 +85,11 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
holder.name.setTag(a);
String hexPrimaryColor = String.format("#%06X", (0xFFFFFF & theme.getPrimaryColor()));
String hexAccentColor = String.format("#%06X", (0xFFFFFF & theme.getAccentColor()));
String hexPrimaryColor = ColorPalette.getHexColor(theme.getPrimaryColor());
String hexAccentColor = ColorPalette.getHexColor(theme.getAccentColor());
if (hexAccentColor.equals(hexPrimaryColor)) {
float[] hsv = new float[3];
int color = theme.getAccentColor();
Color.colorToHSV(color, hsv);
hsv[2] *= 0.72f; // value component
color = Color.HSVToColor(hsv);
hexAccentColor= String.format("#%06X", (0xFFFFFF & color));
}
if (hexAccentColor.equals(hexPrimaryColor))
hexAccentColor = ColorPalette.getHexColor(ColorPalette.getDarkerColor(theme.getAccentColor()));
String textColor = theme.getBaseTheme() != ThemeHelper.LIGHT_THEME ? "#FAFAFA" : "#2b2b2b";
......
......@@ -5,11 +5,18 @@ package org.horaapps.leafpic.util;
*/
public enum CardViewStyle {
CARD_MATERIAL(0), CARD_FLAT(1), CARD_COMPACT(2);
private static final int size = CardViewStyle.values().length;
int value;
CardViewStyle(int value) { this.value = value; }
public int getValue() { return value; }
public static int getSize() {
return size;
}
public static CardViewStyle fromValue(int value){
switch (value){
case 0: default: return CARD_MATERIAL;
......
......@@ -43,6 +43,17 @@ public class ColorPalette {
return ColorUtils.setAlphaComponent(color, alpha);
}
public static String getHexColor(int color) {
return String.format("#%06X", (0xFFFFFF & color));
}
public static int getDarkerColor(int color) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
hsv[2] *= 0.72f; // value component
return Color.HSVToColor(hsv);
}
public static int[] getTransparencyShadows(int color) {
int[] shadows = new int[10];
for (int i=0; i<10;i++)
......
......@@ -3,25 +3,26 @@ package org.horaapps.leafpic.views.cardviewpager;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v7.widget.CardView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import org.horaapps.leafpic.R;
import org.horaapps.leafpic.util.CardViewStyle;
import org.horaapps.leafpic.util.ColorPalette;
import org.horaapps.leafpic.util.StringUtils;
import org.horaapps.leafpic.util.ThemeHelper;
import org.horaapps.leafpic.views.SquareImageView;
import java.util.ArrayList;
import java.util.List;
public class CardPagerAdapter extends PagerAdapter {
public static int MAX_ELEVATION_FACTOR = 8;
static int MAX_ELEVATION_FACTOR = 8;
private List<CardView> mViews;
private float mBaseElevation;
......@@ -29,23 +30,23 @@ public class CardPagerAdapter extends PagerAdapter {
public CardPagerAdapter(Context context) {
theme = new ThemeHelper(context);
mViews = new ArrayList<>();
for (int i = 0; i < 3; i++) {
mViews = new ArrayList<>(CardViewStyle.getSize());
for (int i = 0; i < CardViewStyle.getSize(); i++)
mViews.add(null);
}
}
public float getBaseElevation() {
float getBaseElevation() {
return mBaseElevation;
}
public CardView getCardViewAt(int position) {
CardView getCardViewAt(int position) {
return mViews.get(position);
}
@Override
public int getCount() {
return 3;
return CardViewStyle.getSize();
}
@Override
......@@ -55,71 +56,57 @@ public class CardPagerAdapter extends PagerAdapter {
@Override
public Object instantiateItem(ViewGroup container, int position) {
View view = LayoutInflater.from(container.getContext()).inflate(R.layout.card_view_sample, container, false);
View v;
/**OBJECTS**/
final SquareImageView imgPreviewAlbumCardStyle = (SquareImageView) view.findViewById(R.id.preview_album_card_style_image);
imgPreviewAlbumCardStyle.setBackgroundColor(theme.getPrimaryColor());
LinearLayout llPreview = (LinearLayout) view.findViewById(R.id.ll_preview_album_card);
//llPreview.setBackgroundColor(theme.getInvertedBackgroundColor());
switch (CardViewStyle.fromValue(position)){
default:
case CARD_MATERIAL: v = LayoutInflater.from(container.getContext()).inflate(R.layout.card_album_material, container, false); break;
case CARD_FLAT: v = LayoutInflater.from(container.getContext()).inflate(R.layout.card_album_flat, container, false); break;
case CARD_COMPACT: v = LayoutInflater.from(container.getContext()).inflate(R.layout.card_album_compact, container, false); break;
}
final LinearLayout llPreviewFlatCompactText = (LinearLayout) view.findViewById(R.id.preview_album_card_style_linear_card_text2);
final TextView txtPreviewFlatCompactAlbum = (TextView) view.findViewById(R.id.preview_album_card_style_name2);
final TextView txtPreviewFlatCompactMedia = (TextView) view.findViewById(R.id.preview_album_card_style_photos_count2);
final LinearLayout llPreviewMaterialText = (LinearLayout) view.findViewById(R.id.preview_album_card_style_linear_card_text);
final TextView txtPreviewMaterialAlbum = (TextView) view.findViewById(R.id.preview_album_card_style_name);
final TextView txtPreviewMaterialMedia = (TextView) view.findViewById(R.id.preview_album_card_style_photos_count);
Glide.with(container.getContext())
.load(R.drawable.gilbert_profile)
.into(((ImageView) v.findViewById(org.horaapps.leafpic.R.id.album_preview)));
llPreviewMaterialText.setBackgroundColor(theme.getCardBackgroundColor());
llPreviewFlatCompactText.setBackgroundColor(ColorPalette.getTransparentColor(theme.getCardBackgroundColor(), 150));
String hexPrimaryColor = ColorPalette.getHexColor(theme.getPrimaryColor());
String hexAccentColor = ColorPalette.getHexColor(theme.getAccentColor());
int color=theme.getTextColor();
String albumNameHtml = "<i><font color='" + color+ "'>" + container.getContext().getString(R.string.album) + "</font></i>";
txtPreviewFlatCompactAlbum.setTextColor(color);
txtPreviewMaterialAlbum.setTextColor(color);
txtPreviewFlatCompactAlbum.setText(Html.fromHtml(albumNameHtml));
txtPreviewMaterialAlbum.setText(Html.fromHtml(albumNameHtml));
if (hexAccentColor.equals(hexPrimaryColor))
hexAccentColor = ColorPalette.getHexColor(ColorPalette.getDarkerColor(theme.getAccentColor()));
color=theme.getSubTextColor();
String hexAccentColor = String.format("#%06X", (0xFFFFFF & theme.getAccentColor()));
String albumPhotoCountHtml = "<b><font color='" + hexAccentColor + "'>" + "n" + "</font></b>" + "<font " +
"color='" + color + "'> " + container.getContext().getString(R.string.media) + "</font>";
txtPreviewFlatCompactMedia.setTextColor(color);
txtPreviewMaterialMedia.setTextColor(color);
txtPreviewFlatCompactMedia.setText(Html.fromHtml(albumPhotoCountHtml));
txtPreviewMaterialMedia.setText(Html.fromHtml(albumPhotoCountHtml));
String textColor = theme.getBaseTheme() != ThemeHelper.LIGHT_THEME ? "#FAFAFA" : "#2b2b2b";
switch (CardViewStyle.fromValue(position)){
default:
case CARD_MATERIAL:
llPreviewFlatCompactText.setVisibility(View.GONE);
llPreviewMaterialText.setVisibility(View.VISIBLE);
break;
case CARD_MATERIAL:v.findViewById(R.id.linear_card_text).setBackgroundColor(theme.getCardBackgroundColor());break;
case CARD_FLAT:
llPreviewFlatCompactText.setVisibility(View.VISIBLE);
txtPreviewFlatCompactMedia.setVisibility(View.VISIBLE);
llPreviewMaterialText.setVisibility(View.GONE);
break;
case CARD_COMPACT:
llPreviewFlatCompactText.setVisibility(View.VISIBLE);
txtPreviewFlatCompactMedia.setVisibility(View.GONE);
llPreviewMaterialText.setVisibility(View.GONE);
break;
case CARD_COMPACT:v.findViewById(R.id.linear_card_text).setBackgroundColor(ColorPalette.getTransparentColor(theme.getBackgroundColor(), 150)); break;
}
container.addView(view);
CardView cardView = (CardView) view.findViewById(R.id.cardView);
String albumNameHtml = "<i><font color='" + textColor + "'>#PraiseDuarte</font></i>";
String albumPhotoCountHtml = "<b><font color='" + hexAccentColor + "'>420</font></b>" + "<font " +
"color='" + textColor + "'> " + container.getContext().getString(R.string.media) + "</font>";
((TextView) v.findViewById(R.id.album_name)).setText(StringUtils.html(albumNameHtml));
((TextView) v.findViewById(R.id.album_photos_count)).setText(StringUtils.html(albumPhotoCountHtml));
((CardView) v).setUseCompatPadding(true);
((CardView) v).setRadius(2);
container.addView(v);
if (mBaseElevation == 0) {
mBaseElevation = cardView.getCardElevation();
mBaseElevation = ((CardView) v).getCardElevation();
}
cardView.setMaxCardElevation(mBaseElevation * MAX_ELEVATION_FACTOR);
mViews.set(position, cardView);
return view;
((CardView) v).setMaxCardElevation(mBaseElevation * MAX_ELEVATION_FACTOR);
mViews.set(position, ((CardView) v));
return v;
}
@Override
......
......@@ -10,7 +10,7 @@ public class ShadowTransformer implements ViewPager.OnPageChangeListener, ViewPa
private ViewPager mViewPager;
private CardPagerAdapter mAdapter;
private float mLastOffset;
private boolean mScalingEnabled;
private boolean mScalingEnabled = true;
public ShadowTransformer(ViewPager viewPager, CardPagerAdapter adapter) {
mViewPager = viewPager;
......@@ -18,25 +18,25 @@ public class ShadowTransformer implements ViewPager.OnPageChangeListener, ViewPa
mAdapter = adapter;
}
public void enableScaling(boolean enable) {
if (mScalingEnabled && !enable) {
// shrink main card
CardView currentCard = mAdapter.getCardViewAt(mViewPager.getCurrentItem());
if (currentCard != null) {
currentCard.animate().scaleY(1);
currentCard.animate().scaleX(1);
}
}else if(!mScalingEnabled && enable){
// grow main card
CardView currentCard = mAdapter.getCardViewAt(mViewPager.getCurrentItem());
if (currentCard != null) {
currentCard.animate().scaleY(1.1f);
currentCard.animate().scaleX(1.1f);
}
}
mScalingEnabled = enable;
}
// public void enableScaling(boolean enable) {
// if (mScalingEnabled && !enable) {
// // shrink main card
// CardView currentCard = mAdapter.getCardViewAt(mViewPager.getCurrentItem());
// if (currentCard != null) {
// currentCard.animate().scaleY(1);
// currentCard.animate().scaleX(1);
// }
// }else if(!mScalingEnabled && enable){
// // grow main card
// CardView currentCard = mAdapter.getCardViewAt(mViewPager.getCurrentItem());
// if (currentCard != null) {
// currentCard.animate().scaleY(1.1f);
// currentCard.animate().scaleX(1.1f);
// }
// }
//
// mScalingEnabled = enable;
// }
@Override
public void transformPage(View page, float position) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment