Commit 8a3319f7 authored by Amit Kumar's avatar Amit Kumar
Browse files

Fix number of rows and folder bug

parent ad50e8d5
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -25,12 +25,18 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.0.0'
compile 'com.android.support:gridlayout-v7:26.0.0'
compile 'com.github.droidlibrarian:horizontalpager:v2.0'
compile 'me.relex:circleindicator:1.2.2@aar'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:gridlayout-v7:26.1.0'
compile('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
transitive = true;
transitive = true
}
compile files('libs/bruce-utils.jar')
testCompile 'junit:junit:4.12'
compile 'org.lucasr.dspec:dspec:0.1.1'
}
apply plugin: 'com.jakewharton.hugo'
......@@ -2,31 +2,35 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.indin.blisslaunchero">
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".BlissLauncher"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name=".BlissLauncher">
<activity android:name=".MainActivity"
android:theme="@style/HomeScreenTheme"
android:theme="@style/AppTheme">
<activity
android:name=".DesktopActivity"
android:clearTaskOnLaunch="true"
android:launchMode="singleTask"
android:screenOrientation="nosensor">
android:screenOrientation="nosensor"
android:stateNotNeeded="true"
android:theme="@style/HomeScreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<meta-data
android:name="io.fabric.ApiKey"
android:value="8fcf342f1b8ac74d6980872082b7216ef4682a29"
/>
android:value="8fcf342f1b8ac74d6980872082b7216ef4682a29" />
</application>
</manifest>
package org.indin.blisslaunchero;
import android.graphics.Canvas;
import android.graphics.Point;
import android.view.View;
/**
* Created by falcon on 15/2/18.
*/
public class BlissDragShadowBuilder extends View.DragShadowBuilder {
private Point mScaleFactor;
// Defines the constructor for myDragShadowBuilder
public BlissDragShadowBuilder(View v) {
// Stores the View parameter passed to myDragShadowBuilder.
super(v);
}
// Defines a callback that sends the drag shadow dimensions and touch point back to the
// system.
@Override
public void onProvideShadowMetrics (Point size, Point touch) {
// Defines local variables
int width;
int height;
// Sets the width of the shadow to half the width of the original View
width = (int) (getView().getWidth() * 1.2);
// Sets the height of the shadow to half the height of the original View
height = (int) (getView().getHeight() * 1.2);
// Sets the size parameter's width and height values. These get back to the system
// through the size parameter.
size.set(width, height);
// Sets size parameter to member that will be used for scaling shadow image.
mScaleFactor = size;
// Sets the touch point's position to be in the middle of the drag shadow
touch.set(width/2, height/2);
}
@Override
public void onDrawShadow(Canvas canvas) {
// Draws the ColorDrawable in the Canvas passed in from the system.
canvas.scale(mScaleFactor.x/(float)getView().getWidth(), mScaleFactor.y/(float)getView().getHeight());
getView().draw(canvas);
}
}
......@@ -51,7 +51,7 @@ public class GraphicsUtil {
Log.d(TAG, "Unknown type of icon found");
return context.getResources().getDrawable(R.mipmap.ic_folder, null);
}
int width = context.getResources().getDimensionPixelSize(R.dimen.iconSize);
int width = context.getResources().getDimensionPixelSize(R.dimen.iconSize) * 3/4;
int height = width; // Square icons
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
......
package org.indin.blisslaunchero;
/**
* Created by falcon on 11/2/18.
*/
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.Scroller;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
public class HorizontalPager extends ViewGroup {
public static final String TAG = "HorizontalPager";
private static final int INVALID_SCREEN = -1;
public static final int SPEC_UNDEFINED = -1;
private static final int SNAP_VELOCITY = 1000;
private int pageWidthSpec, pageWidth;
private boolean firstLayout = true;
private int currentPage;
private int nextPage = INVALID_SCREEN;
private Scroller mScroller;
private VelocityTracker mVelocityTracker;
private int mTouchSlop;
private int mMaximumVelocity;
private float mLastMotionX;
private float mLastMotionY;
private final static int TOUCH_STATE_REST = 0;
private final static int TOUCH_STATE_SCROLLING = 1;
private int mTouchState = TOUCH_STATE_REST;
private boolean mAllowLongPress;
private Set<OnScrollListener> mListeners = new HashSet<>();
private boolean mIsUiCreated;
public HorizontalPager(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public HorizontalPager(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HorizontalPager);
pageWidthSpec = a.getDimensionPixelSize(R.styleable.HorizontalPager_pageWidth,
SPEC_UNDEFINED);
a.recycle();
init();
}
private void init() {
mScroller = new Scroller(getContext());
currentPage = 0;
mIsUiCreated = false;
final ViewConfiguration configuration = ViewConfiguration.get(getContext());
mTouchSlop = configuration.getScaledTouchSlop();
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}
int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = Math.max(0, Math.min(currentPage, getChildCount()));
scrollTo(getScrollXForPage(this.currentPage), 0);
invalidate();
}
public int getPageWidth() {
return pageWidth;
}
public void setPageWidth(int pageWidth) {
this.pageWidthSpec = pageWidth;
}
/**
* Gets the value that getScrollX() should return if the specified page is the current page (and
* no other scrolling is occurring).
* Use this to pass a value to scrollTo(), for example.
*/
private int getScrollXForPage(int whichPage) {
return (whichPage * pageWidth) - pageWidthPadding();
}
@Override
public void computeScroll() {
if (mScroller.computeScrollOffset()) {
scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
postInvalidate();
} else if (nextPage != INVALID_SCREEN) {
currentPage = nextPage;
nextPage = INVALID_SCREEN;
}
}
@Override
protected void dispatchDraw(Canvas canvas) {
final long drawingTime = getDrawingTime();
// todo be smarter about which children need drawing
final int count = getChildCount();
for (int i = 0; i < count; i++) {
drawChild(canvas, getChildAt(i), drawingTime);
}
for (OnScrollListener mListener : mListeners) {
int adjustedScrollX = getScrollX() + pageWidthPadding();
mListener.onScroll(adjustedScrollX);
if (adjustedScrollX % pageWidth == 0) {
mListener.onViewScrollFinished(adjustedScrollX / pageWidth);
}
}
}
int pageWidthPadding() {
return ((getMeasuredWidth() - pageWidth) / 2);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
pageWidth = pageWidthSpec == SPEC_UNDEFINED ? getMeasuredWidth() : pageWidthSpec;
pageWidth = Math.min(pageWidth, getMeasuredWidth());
final int count = getChildCount();
for (int i = 0; i < count; i++) {
getChildAt(i).measure(MeasureSpec.makeMeasureSpec(pageWidth, MeasureSpec.EXACTLY),
heightMeasureSpec);
}
if (firstLayout) {
scrollTo(getScrollXForPage(currentPage), 0);
firstLayout = false;
}
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
int childLeft = 0;
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != View.GONE) {
final int childWidth = child.getMeasuredWidth();
child.layout(childLeft, 0, childLeft + childWidth, child.getMeasuredHeight());
childLeft += childWidth;
}
}
}
@Override
public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
int screen = indexOfChild(child);
if (screen != currentPage || !mScroller.isFinished()) {
return true;
}
return false;
}
@Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
if (getChildCount() <= 1) {
return false;
}
int focusableScreen;
if (nextPage != INVALID_SCREEN) {
focusableScreen = nextPage;
} else {
focusableScreen = currentPage;
}
getChildAt(focusableScreen).requestFocus(direction, previouslyFocusedRect);
return false;
}
@Override
public boolean dispatchUnhandledMove(View focused, int direction) {
if (direction == View.FOCUS_LEFT) {
if (getCurrentPage() > 0) {
snapToPage(getCurrentPage() - 1);
return true;
}
} else if (direction == View.FOCUS_RIGHT) {
if (getCurrentPage() < getChildCount() - 1) {
snapToPage(getCurrentPage() + 1);
return true;
}
}
return super.dispatchUnhandledMove(focused, direction);
}
@Override
public void addFocusables(ArrayList<View> views, int direction) {
getChildAt(currentPage).addFocusables(views, direction);
if (direction == View.FOCUS_LEFT) {
if (currentPage > 0) {
getChildAt(currentPage - 1).addFocusables(views, direction);
}
} else if (direction == View.FOCUS_RIGHT) {
if (currentPage < getChildCount() - 1) {
getChildAt(currentPage + 1).addFocusables(views, direction);
}
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
//Log.d(TAG, "onInterceptTouchEvent::action=" + ev.getAction());
/*
* This method JUST determines whether we want to intercept the motion.
* If we return true, onTouchEvent will be called and we do the actual
* scrolling there.
*/
/*
* Shortcut the most recurring case: the user is in the dragging
* state and he is moving his finger. We want to intercept this
* motion.
*/
final int action = ev.getAction();
if ((action == MotionEvent.ACTION_MOVE) && (mTouchState != TOUCH_STATE_REST)) {
Log.d(TAG, "onInterceptTouchEvent::shortcut=true");
return true;
}
final float x = ev.getX();
final float y = ev.getY();
switch (action) {
case MotionEvent.ACTION_MOVE:
/*
* mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
* whether the user has moved far enough from his original down touch.
*/
if (mTouchState == TOUCH_STATE_REST) {
checkStartScroll(x, y);
}
break;
case MotionEvent.ACTION_DOWN:
// Remember location of down touch
mLastMotionX = x;
mLastMotionY = y;
mAllowLongPress = true;
/*
* If being flinged and user touches the screen, initiate drag;
* otherwise don't. mScroller.isFinished should be false when
* being flinged.
*/
mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING;
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
mTouchState = TOUCH_STATE_REST;
break;
}
/*
* The only time we want to intercept motion events is if we are in the
* drag mode.
*/
return mTouchState != TOUCH_STATE_REST;
}
private void checkStartScroll(float x, float y) {
/*
* Locally do absolute value. mLastMotionX is set to the y value
* of the down event.
*/
final int xDiff = (int) Math.abs(x - mLastMotionX);
final int yDiff = (int) Math.abs(y - mLastMotionY);
boolean xMoved = xDiff > mTouchSlop;
boolean yMoved = yDiff > mTouchSlop;
if (xMoved || yMoved) {
if (xMoved) {
// Scroll if the user moved far enough along the X axis
mTouchState = TOUCH_STATE_SCROLLING;
enableChildrenCache();
}
// Either way, cancel any pending longpress
if (mAllowLongPress) {
mAllowLongPress = false;
// Try canceling the long press. It could also have been scheduled
// by a distant descendant, so use the mAllowLongPress flag to block
// everything
final View currentScreen = getChildAt(currentPage);
if (currentScreen != null) {
currentScreen.cancelLongPress();
}
}
}
}
void enableChildrenCache() {
setChildrenDrawingCacheEnabled(true);
}
public void setUiCreated(boolean isUiCreated) {
mIsUiCreated = isUiCreated;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
}
mVelocityTracker.addMovement(ev);
final int action = ev.getAction();
final float x = ev.getX();
final float y = ev.getY();
if (mIsUiCreated) {
switch (action) {
case MotionEvent.ACTION_DOWN:
/*
* If being flinged and user touches, stop the fling. isFinished
* will be false if being flinged.
*/
if (!mScroller.isFinished()) {
mScroller.abortAnimation();
}
// Remember where the motion event started
mLastMotionX = x;
break;
case MotionEvent.ACTION_MOVE:
if (mTouchState == TOUCH_STATE_REST) {
checkStartScroll(x, y);
} else if (mTouchState == TOUCH_STATE_SCROLLING) {
// Scroll to follow the motion event
int deltaX = (int) (mLastMotionX - x);
mLastMotionX = x;
// Apply friction to scrolling past boundaries.
if (getScrollX() < 0 || getScrollX() > getChildAt(
getChildCount() - 1).getLeft()) {
deltaX /= 2;
}
scrollBy(deltaX, 0);
}
break;
case MotionEvent.ACTION_UP:
if (mTouchState == TOUCH_STATE_SCROLLING) {
final VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
int velocityX = (int) velocityTracker.getXVelocity();
if (velocityX > SNAP_VELOCITY && currentPage > 0) {
// Fling hard enough to move left
snapToPage(currentPage - 1);
} else if (velocityX < -SNAP_VELOCITY
&& currentPage < getChildCount() - 1) {
// Fling hard enough to move right
snapToPage(currentPage + 1);
} else {
snapToDestination();
}
if (mVelocityTracker != null) {
mVelocityTracker.recycle();
mVelocityTracker = null;
}
}
mTouchState = TOUCH_STATE_REST;
break;
case MotionEvent.ACTION_CANCEL:
mTouchState = TOUCH_STATE_REST;
}
}
return true;
}
private void snapToDestination() {
final int startX = getScrollXForPage(currentPage);
int whichPage = currentPage;
if (getScrollX() < startX - getWidth() / 8) {
whichPage = Math.max(0, whichPage - 1);
} else if (getScrollX() > startX + getWidth() / 8) {
whichPage = Math.min(getChildCount() - 1, whichPage + 1);
}
snapToPage(whichPage);
}
public void snapToPage(int whichPage) {
enableChildrenCache();
boolean changingPages = whichPage != currentPage;
nextPage = whichPage;
View focusedChild = getFocusedChild();
if (focusedChild != null && changingPages && focusedChild == getChildAt(currentPage)) {
focusedChild.clearFocus();
}
final int newX = getScrollXForPage(whichPage);
final int delta = newX - getScrollX();
//mScroller.startScroll(getScrollX(), 0, delta, 0, Math.abs(delta) * 2);
mScroller.startScroll(getScrollX(), 0, delta, 0, 400);
invalidate();
}
@Override
protected Parcelable onSaveInstanceState() {