Commit 7abf321a authored by Donald's avatar Donald

.

parent 2ce39a6a
......@@ -31,13 +31,11 @@ import com.mikepenz.iconics.view.IconicsImageView;
import org.horaapps.leafpic.R;
import org.horaapps.leafpic.activities.base.ThemedActivity;
import org.horaapps.leafpic.util.ColorPalette;
import org.horaapps.leafpic.util.CustomViewPager;
import org.horaapps.leafpic.util.PreferenceUtil;
import org.horaapps.leafpic.util.Security;
import org.horaapps.leafpic.util.StaticMapProvider;
import org.horaapps.leafpic.util.ThemeHelper;
import org.horaapps.leafpic.views.cardviewpager.CardPagerAdapter;
import org.horaapps.leafpic.views.cardviewpager.ShadowTransformer;
import org.horaapps.leafpic.views.cardviewpager.CustomViewPager;
import uz.shift.colorpicker.LineColorPicker;
import uz.shift.colorpicker.OnColorChangedListener;
......@@ -108,6 +106,9 @@ public class SettingsActivity extends ThemedActivity {
}
});
//TODO remove
cardViewDialog();
/*** SECURITY ***/
findViewById(R.id.ll_security).setOnClickListener(new View.OnClickListener() {
@Override
......@@ -407,11 +408,9 @@ public class SettingsActivity extends ThemedActivity {
private void cardViewDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(SettingsActivity.this, getDialogStyle());
View layout = getLayoutInflater().inflate(R.layout.dialog_select_cardview, null);
final CustomViewPager mViewPager = (CustomViewPager) layout.findViewById(R.id.viewPager);
CardPagerAdapter mCardAdapter = new CardPagerAdapter(getBaseContext());
ShadowTransformer mCardShadowTransformer = new ShadowTransformer(mViewPager, mCardAdapter);
mViewPager.setAdapter(mCardAdapter);
mViewPager.setPageTransformer(false, mCardShadowTransformer);
//mViewPager.setAdapter(new MyAdapter(getSupportFragmentManager()));
mViewPager.setOffscreenPageLimit(3);
mViewPager.setCurrentItem(SP.getInt("card_view_style", 0));
......
package org.horaapps.leafpic.util;
import org.horaapps.leafpic.R;
/**
* Created by Jibo on 20/11/2016.
*/
public enum CardViewStyle {
CARD_MATERIAL(0), CARD_FLAT(1), CARD_COMPACT(2);
CARD_MATERIAL(0, R.layout.card_album_material),
CARD_FLAT(1, R.layout.card_album_flat),
CARD_COMPACT(2, R.layout.card_album_compact);
private static final int size = CardViewStyle.values().length;
int value;
int layout;
CardViewStyle(int value, int layout) {
this.value = value;
this.layout = layout;
}
public int getLayout() {
return layout;
}
CardViewStyle(int value) { this.value = value; }
public int getValue() { return value; }
......
package org.horaapps.leafpic.util;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.View;
/**
* Created by Jibo on 25/11/2016.
*/
public class CustomViewPager extends ViewPager {
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = 0;
for(int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int h = child.getMeasuredHeight();
if(h > height) height = h;
}
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
package org.horaapps.leafpic.views.cardviewpager;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
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 java.util.ArrayList;
import java.util.List;
public class CardPagerAdapter extends PagerAdapter {
static int MAX_ELEVATION_FACTOR = 8;
private List<CardView> mViews;
private float mBaseElevation;
private ThemeHelper theme;
public CardPagerAdapter(Context context) {
theme = new ThemeHelper(context);
mViews = new ArrayList<>(CardViewStyle.getSize());
for (int i = 0; i < CardViewStyle.getSize(); i++)
mViews.add(null);
}
float getBaseElevation() {
return mBaseElevation;
}
CardView getCardViewAt(int position) {
return mViews.get(position);
}
@Override
public int getCount() {
return CardViewStyle.getSize();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View v;
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;
}
ImageView img = (ImageView) v.findViewById(org.horaapps.leafpic.R.id.album_preview);
img.setBackgroundColor(theme.getPrimaryColor());
Glide.with(container.getContext())
.load(R.drawable.gilbert_profile)
.into(img);
String hexPrimaryColor = ColorPalette.getHexColor(theme.getPrimaryColor());
String hexAccentColor = ColorPalette.getHexColor(theme.getAccentColor());
if (hexAccentColor.equals(hexPrimaryColor))
hexAccentColor = ColorPalette.getHexColor(ColorPalette.getDarkerColor(theme.getAccentColor()));
String textColor = theme.getBaseTheme() != ThemeHelper.LIGHT_THEME ? "#FAFAFA" : "#2b2b2b";
switch (CardViewStyle.fromValue(position)){
default:
case CARD_MATERIAL:v.findViewById(R.id.linear_card_text).setBackgroundColor(theme.getCardBackgroundColor());break;
case CARD_FLAT:
case CARD_COMPACT:v.findViewById(R.id.linear_card_text).setBackgroundColor(ColorPalette.getTransparentColor(theme.getBackgroundColor(), 150)); break;
}
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) v).getCardElevation();
}
((CardView) v).setMaxCardElevation(mBaseElevation * MAX_ELEVATION_FACTOR);
mViews.set(position, ((CardView) v));
return v;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
mViews.set(position, null);
}
}
package org.horaapps.leafpic.views.cardviewpager;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.CardView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
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 java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import static org.horaapps.leafpic.util.CardViewStyle.CARD_COMPACT;
import static org.horaapps.leafpic.util.CardViewStyle.CARD_FLAT;
import static org.horaapps.leafpic.util.CardViewStyle.CARD_MATERIAL;
/**
* Created by Jibo on 25/11/2016.
*/
public class CustomViewPager extends ViewPager {
int MAX_ELEVATION_FACTOR = 8;
int MAGIC_NUMBER = 21;
private View mCurrentView;
ArrayList<Integer> heightPorcoDio = new ArrayList<>();
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
CardPagerAdapter adapter = new CardPagerAdapter(context);
setAdapter(adapter);
setPageTransformer(false, new ShadowTransformer(this, adapter));
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (mCurrentView == null) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
return;
}
mCurrentView.measure(widthMeasureSpec, MeasureSpec.UNSPECIFIED);
int h = mCurrentView.getMeasuredHeight()/* - (mCurrentView.getPaddingBottom() + MAGIC_NUMBER)*/;
if (!heightPorcoDio.contains(h))
heightPorcoDio.add(h);
//h = getMin(heightPorcoDio);
heightMeasureSpec = MeasureSpec.makeMeasureSpec(h, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
int getMin(ArrayList<Integer> list) {
if (list.isEmpty()) {
return 0;
} else {
ListIterator<Integer> itr = list.listIterator();
int min = itr.next(); // first element as the current minimum
while (itr.hasNext()) {
Integer curr = itr.next();
if (curr.compareTo(min) < 0) min = curr;
}
return min;
}
}
@Override
protected void onPageScrolled(int position, float offset, int offsetPixels) {
super.onPageScrolled(position, offset, offsetPixels);
measureCurrentView(((CardPagerAdapter) getAdapter()).getCardViewAt(position).findViewById(R.id.cont));
}
public void measureCurrentView(View currentView) {
heightPorcoDio.clear();
mCurrentView = currentView;
requestLayout();
}
class CardPagerAdapter extends PagerAdapter {
private List<CardView> mViews;
private float mBaseElevation;
private ThemeHelper theme;
CardPagerAdapter(Context context) {
theme = new ThemeHelper(context);
mViews = new ArrayList<>(CardViewStyle.getSize());
for (int i = 0; i < CardViewStyle.getSize(); i++)
mViews.add(null);
}
float getBaseElevation() {
return mBaseElevation;
}
CardView getCardViewAt(int position) {
return mViews.get(position);
}
@Override
public int getCount() {
return CardViewStyle.getSize();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View v;
switch (CardViewStyle.fromValue(position)){
default:
case CARD_MATERIAL: v = LayoutInflater.from(container.getContext()).inflate(CARD_MATERIAL.getLayout(), container, false ); break;
case CARD_FLAT: v = LayoutInflater.from(container.getContext()).inflate(CARD_FLAT.getLayout(), container, false); break;
case CARD_COMPACT: v = LayoutInflater.from(container.getContext()).inflate(CARD_COMPACT.getLayout(), container, false); break;
}
ImageView img = (ImageView) v.findViewById(org.horaapps.leafpic.R.id.album_preview);
img.setBackgroundColor(theme.getPrimaryColor());
Glide.with(container.getContext())
.load(R.drawable.gilbert_profile)
.into(img);
String hexPrimaryColor = ColorPalette.getHexColor(theme.getPrimaryColor());
String hexAccentColor = ColorPalette.getHexColor(theme.getAccentColor());
if (hexAccentColor.equals(hexPrimaryColor))
hexAccentColor = ColorPalette.getHexColor(ColorPalette.getDarkerColor(theme.getAccentColor()));
String textColor = theme.getBaseTheme() != ThemeHelper.LIGHT_THEME ? "#FAFAFA" : "#2b2b2b";
switch (CardViewStyle.fromValue(position)){
default:
case CARD_MATERIAL:v.findViewById(R.id.linear_card_text).setBackgroundColor(theme.getCardBackgroundColor());break;
case CARD_FLAT:
case CARD_COMPACT:v.findViewById(R.id.linear_card_text).setBackgroundColor(ColorPalette.getTransparentColor(theme.getBackgroundColor(), 150)); break;
}
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);
v.setPadding(20,20,20,20);
container.addView(v);
if (mBaseElevation == 0) {
mBaseElevation = ((CardView) v).getCardElevation();
}
((CardView) v).setMaxCardElevation(mBaseElevation * MAX_ELEVATION_FACTOR);
mViews.set(position, ((CardView) v));
return v;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
mViews.set(position, null);
}
}
public class ShadowTransformer implements ViewPager.OnPageChangeListener, ViewPager.PageTransformer {
private CardPagerAdapter mAdapter;
private float mLastOffset;
ShadowTransformer(ViewPager viewPager, CardPagerAdapter adapter) {
viewPager.addOnPageChangeListener(this);
mAdapter = adapter;
}
@Override
public void transformPage(View page, float position) { }
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
int realCurrentPosition;
int nextPosition;
float baseElevation = mAdapter.getBaseElevation();
float realOffset;
boolean goingLeft = mLastOffset > positionOffset;
// If we're going backwards, onPageScrolled receives the last position
// instead of the current one
if (goingLeft) {
realCurrentPosition = position + 1;
nextPosition = position;
realOffset = 1 - positionOffset;
} else {
nextPosition = position + 1;
realCurrentPosition = position;
realOffset = positionOffset;
}
// Avoid crash on overscroll
if (nextPosition > mAdapter.getCount() - 1
|| realCurrentPosition > mAdapter.getCount() - 1) {
return;
}
CardView currentCard = mAdapter.getCardViewAt(realCurrentPosition);
// This might be null if a fragment is being used
// and the views weren't created yet
if (currentCard != null) {
currentCard.setScaleX((float) (1 + 0.1 * (1 - realOffset)));
currentCard.setScaleY((float) (1 + 0.1 * (1 - realOffset)));
currentCard.setCardElevation((baseElevation + baseElevation
* (MAX_ELEVATION_FACTOR - 1) * (1 - realOffset)));
}
CardView nextCard = mAdapter.getCardViewAt(nextPosition);
// We might be scrolling fast enough so that the next (or previous) card
// was already destroyed or a fragment might not have been created yet
if (nextCard != null) {
nextCard.setScaleX((float) (1 + 0.1 * (realOffset)));
nextCard.setScaleY((float) (1 + 0.1 * (realOffset)));
nextCard.setCardElevation((baseElevation + baseElevation
* (MAX_ELEVATION_FACTOR - 1) * (realOffset)));
}
mLastOffset = positionOffset;
}
@Override
public void onPageSelected(int position) { }
@Override
public void onPageScrollStateChanged(int state) { }
}
}
package org.horaapps.leafpic.views.cardviewpager;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.CardView;
import android.view.View;
public class ShadowTransformer implements ViewPager.OnPageChangeListener, ViewPager.PageTransformer {
private ViewPager mViewPager;
private CardPagerAdapter mAdapter;
private float mLastOffset;
private boolean mScalingEnabled = true;
public ShadowTransformer(ViewPager viewPager, CardPagerAdapter adapter) {
mViewPager = viewPager;
viewPager.addOnPageChangeListener(this);
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;
// }
@Override
public void transformPage(View page, float position) {
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
int realCurrentPosition;
int nextPosition;
float baseElevation = mAdapter.getBaseElevation();
float realOffset;
boolean goingLeft = mLastOffset > positionOffset;
// If we're going backwards, onPageScrolled receives the last position
// instead of the current one
if (goingLeft) {
realCurrentPosition = position + 1;
nextPosition = position;
realOffset = 1 - positionOffset;
} else {
nextPosition = position + 1;
realCurrentPosition = position;
realOffset = positionOffset;
}
// Avoid crash on overscroll
if (nextPosition > mAdapter.getCount() - 1
|| realCurrentPosition > mAdapter.getCount() - 1) {
return;
}
CardView currentCard = mAdapter.getCardViewAt(realCurrentPosition);
// This might be null if a fragment is being used
// and the views weren't created yet
if (currentCard != null) {
if (mScalingEnabled) {
currentCard.setScaleX((float) (1 + 0.1 * (1 - realOffset)));
currentCard.setScaleY((float) (1 + 0.1 * (1 - realOffset)));
}
currentCard.setCardElevation((baseElevation + baseElevation
* (CardPagerAdapter.MAX_ELEVATION_FACTOR - 1) * (1 - realOffset)));
}
CardView nextCard = mAdapter.getCardViewAt(nextPosition);
// We might be scrolling fast enough so that the next (or previous) card
// was already destroyed or a fragment might not have been created yet
if (nextCard != null) {
if (mScalingEnabled) {
nextCard.setScaleX((float) (1 + 0.1 * (realOffset)));
nextCard.setScaleY((float) (1 + 0.1 * (realOffset)));
}
nextCard.setCardElevation((baseElevation + baseElevation
* (CardPagerAdapter.MAX_ELEVATION_FACTOR - 1) * (realOffset)));
}
mLastOffset = positionOffset;
}
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
}
......@@ -9,7 +9,11 @@
app:cardCornerRadius="0dp"
android:foreground="@drawable/ripple"
app:cardElevation="@dimen/cardview_default_elevation">
<RelativeLayout
<LinearLayout
android:id="@+id/cont"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<org.horaapps.leafpic.views.SquareRelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/header_album_card"
......@@ -60,5 +64,6 @@
android:visibility="gone"
/>
</LinearLayout>
</RelativeLayout>
</org.horaapps.leafpic.views.SquareRelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
......@@ -9,7 +9,11 @@
app:cardCornerRadius="0dp"
android:foreground="@drawable/ripple"
app:cardElevation="@dimen/cardview_default_elevation">
<RelativeLayout
<LinearLayout
android:id="@+id/cont"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<org.horaapps.leafpic.views.SquareRelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/header_album_card"
......@@ -64,5 +68,6 @@
android:textSize="14sp"
/>
</LinearLayout>
</RelativeLayout>
</org.horaapps.leafpic.views.SquareRelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
......@@ -9,11 +9,14 @@
app:cardCornerRadius="0dp"
android:foreground="@drawable/ripple"
app:cardElevation="@dimen/cardview_default_elevation">
<LinearLayout
android:id="@+id/cont"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<RelativeLayout
android:layout_height="wrap_content">
<org.horaapps.leafpic.views.SquareRelativeLayout
android:id="@+id/header_album_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
......@@ -36,7 +39,7 @@
android:layout_height="wrap_content"
android:scaleType="centerCrop"
/>
</RelativeLayout>
</org.horaapps.leafpic.views.SquareRelativeLayout>
<View
android:id="@+id/album_card_divider"
android:layout_width="match_parent"
......@@ -77,4 +80,5 @@
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">