Commit 5eeecb53 authored by Amit Kumar's avatar Amit Kumar
Browse files

Fix icon size

parent 14de28bc
......@@ -12,6 +12,7 @@ import android.content.IntentFilter;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.Uri;
......@@ -21,11 +22,14 @@ import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.DragEvent;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.EditorInfo;
......@@ -50,7 +54,7 @@ public class DesktopActivity extends AppCompatActivity {
private HorizontalPager pager;
private View workspace;
private LinearLayout dock;
private GridLayout dock;
private LinearLayout indicator;
private ViewGroup folderWindowContainer;
private GridLayout folderApps;
......@@ -106,6 +110,8 @@ public class DesktopActivity extends AppCompatActivity {
private int maxWidth;
private boolean isDragging;
private int screenHeight;
private int mWidthPixels;
private int mHeightPixels;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -275,24 +281,32 @@ public class DesktopActivity extends AppCompatActivity {
}
private void prepareResources() {
iconSize = getResources().getDimensionPixelSize(R.dimen.iconSize);
float appHeight = iconSize
+ 2 * getResources().getDimensionPixelSize(R.dimen.app_icon_margin)
+ getResources().getDimensionPixelSize(R.dimen.labelHeight) + Utils.dp2Px(12,
this);
float topH = screenHeight - getResources().getDimensionPixelSize(R.dimen.dockHeight)
- Utils.dp2Px(32, this)
- getResources().getDimensionPixelSize(R.dimen.pager_margin);
Log.i(TAG, "prepareResources: hieht = " + topH + " " + appHeight);
nRows = (int) Math.floor(screenHeight / appHeight);
setRealDeviceSizeInPixels();
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
double x = Math.pow(mWidthPixels / dm.xdpi, 2);
double y = Math.pow(mHeightPixels / dm.ydpi, 2);
double screenInches = Math.sqrt(x + y);
Log.d("debug", "Screen inches : " + screenInches);
if (screenInches <= 4.7) {
nRows = 4;
} else if (screenInches <= 5.4) {
nRows = 5;
} else {
nRows = 6;
}
Log.i(TAG, "prepareResources: " + nRows);
nCols = getResources().getInteger(R.integer.col_count);
maxAppsPerPage = nRows * nCols;
screenWidth = Resources.getSystem().getDisplayMetrics().widthPixels;
maxDistanceForFolderCreation = getResources()
.getDimensionPixelSize(R.dimen.maxDistanceForFolderCreation);
.getDimensionPixelSize(R.dimen.maxDistanceForFolderCreation) * screenWidth / 480;
hotBackground = getResources().getDrawable(R.drawable.rounded_corners_icon_hot, null);
defaultBackground = getResources().getDrawable(R.drawable.rounded_corners_icon, null);
scrollCorner = getResources().getDimensionPixelSize(R.dimen.scrollCorner);
......@@ -303,6 +317,38 @@ public class DesktopActivity extends AppCompatActivity {
(InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
}
private void setRealDeviceSizeInPixels() {
WindowManager windowManager = getWindowManager();
Display display = windowManager.getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getMetrics(displayMetrics);
// since SDK_INT = 1;
mWidthPixels = displayMetrics.widthPixels;
mHeightPixels = displayMetrics.heightPixels;
// includes window decorations (statusbar bar/menu bar)
if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17) {
try {
mWidthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
mHeightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
} catch (Exception ignored) {
}
}
// includes window decorations (statusbar bar/menu bar)
if (Build.VERSION.SDK_INT >= 17) {
try {
Point realSize = new Point();
Display.class.getMethod("getRealSize", Point.class).invoke(display, realSize);
mWidthPixels = realSize.x;
mHeightPixels = realSize.y;
} catch (Exception ignored) {
}
}
}
private void createLauncher() {
progressBar.setVisibility(View.VISIBLE);
AsyncTask.execute(new Runnable() {
......@@ -654,13 +700,14 @@ public class DesktopActivity extends AppCompatActivity {
}
private void addAppToPage(GridLayout page, View view) {
GridLayout.Spec spec = GridLayout.spec(GridLayout.UNDEFINED);
GridLayout.Spec rowSpec = GridLayout.spec(GridLayout.UNDEFINED);
GridLayout.Spec colSpec = GridLayout.spec(GridLayout.UNDEFINED);
GridLayout.LayoutParams iconLayoutParams = new GridLayout.LayoutParams(spec, colSpec);
GridLayout.LayoutParams iconLayoutParams = new GridLayout.LayoutParams(rowSpec, colSpec);
iconLayoutParams.setMargins(getResources().getDimensionPixelSize(R.dimen.app_col_margin),
getResources().getDimensionPixelSize(R.dimen.app_icon_margin),
0,
getResources().getDimensionPixelSize(R.dimen.app_col_margin),
getResources().getDimensionPixelSize(R.dimen.app_icon_margin));
0);
iconLayoutParams.height = (screenHeight) / nRows;
iconLayoutParams.width =
((screenWidth - 10 * getResources().getDimensionPixelSize(
R.dimen.app_col_margin))
......@@ -672,13 +719,14 @@ public class DesktopActivity extends AppCompatActivity {
}
private void addAppToPage(GridLayout page, View view, int index) {
GridLayout.Spec spec = GridLayout.spec(GridLayout.UNDEFINED);
GridLayout.Spec rowSpec = GridLayout.spec(GridLayout.UNDEFINED);
GridLayout.Spec colSpec = GridLayout.spec(GridLayout.UNDEFINED);
GridLayout.LayoutParams iconLayoutParams = new GridLayout.LayoutParams(spec, colSpec);
GridLayout.LayoutParams iconLayoutParams = new GridLayout.LayoutParams(rowSpec, colSpec);
iconLayoutParams.setMargins(getResources().getDimensionPixelSize(R.dimen.app_col_margin),
getResources().getDimensionPixelSize(R.dimen.app_icon_margin),
0,
getResources().getDimensionPixelSize(R.dimen.app_col_margin),
getResources().getDimensionPixelSize(R.dimen.app_icon_margin));
0);
iconLayoutParams.height = (screenHeight) / nRows;
iconLayoutParams.width =
((screenWidth - 10 * getResources().getDimensionPixelSize(
R.dimen.app_col_margin))
......@@ -749,7 +797,19 @@ public class DesktopActivity extends AppCompatActivity {
*/
private View prepareApp(final AppItem app) {
final View v = getLayoutInflater().inflate(R.layout.app_view, null);
final ImageView icon = v.findViewById(R.id.app_icon);
final SquareImageView icon = v.findViewById(R.id.app_icon);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) icon.getLayoutParams();
int margin = 0;
if (nRows == 4) {
margin = getResources().getDimensionPixelSize(R.dimen.margin_inch1);
} else if (nRows == 5) {
margin = getResources().getDimensionPixelSize(R.dimen.margin_inch2);
} else if (nRows == 6) {
margin = getResources().getDimensionPixelSize(R.dimen.margin_inch3);
}
layoutParams.leftMargin = margin;
layoutParams.rightMargin = margin;
final TextView label = v.findViewById(R.id.app_label);
final Intent intent = app.getIntent();
icon.setImageDrawable(app.getIcon());
......@@ -1213,7 +1273,7 @@ public class DesktopActivity extends AppCompatActivity {
AppItem item = activeFolder.getSubApps().get(0);
activeFolder.getSubApps().remove(item);
item.setBelongsToFolder(false);
View view = prepareApp(item);
View view = prepareApp(item);
addAppToPage(pages.get(getCurrentAppsPageNumber()), view);
((ViewGroup) activeFolderView.getParent()).removeView(activeFolderView);
......@@ -1248,12 +1308,20 @@ public class DesktopActivity extends AppCompatActivity {
* not violated.
*/
private void addToDock(View view, int index) {
// Hide label in dock
GridLayout.Spec rowSpec = GridLayout.spec(GridLayout.UNDEFINED);
GridLayout.Spec colSpec = GridLayout.spec(GridLayout.UNDEFINED);
GridLayout.LayoutParams iconLayoutParams = new GridLayout.LayoutParams(rowSpec, colSpec);
iconLayoutParams.setMargins(getResources().getDimensionPixelSize(R.dimen.app_col_margin),
0,
getResources().getDimensionPixelSize(R.dimen.app_col_margin),
0);
iconLayoutParams.height = (screenHeight) / nRows;
iconLayoutParams.width =
((screenWidth - 10 * getResources().getDimensionPixelSize(
R.dimen.app_col_margin))
/ dock.getColumnCount());
view.findViewById(R.id.app_label).setVisibility(View.GONE);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, ViewGroup
.LayoutParams.MATCH_PARENT, 1);
view.setLayoutParams(layoutParams);
view.setLayoutParams(iconLayoutParams);
if (index != INVALID) {
dock.addView(view, index);
} else {
......
......@@ -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) * 3/4;
int width = sources[0].getIntrinsicWidth() * 3/4;
int height = width; // Square icons
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
......@@ -127,10 +127,10 @@ public class GraphicsUtil {
if ((image == null) || !(image instanceof BitmapDrawable)) {
return image;
}
double scale = 0.83;
double scale = 0.8;
Bitmap original = Bitmap.createScaledBitmap(((BitmapDrawable)image).getBitmap(),
(int)(context.getResources().getDimensionPixelSize(R.dimen.iconSize) * scale),
(int)(context.getResources().getDimensionPixelSize(R.dimen.iconSize) * scale), true);
(int)(image.getIntrinsicWidth() * scale),
(int)(image.getIntrinsicWidth() * scale), true);
Bitmap mask = ((BitmapDrawable)IconPackUtil.getIconMask()).getBitmap();
Bitmap result = Bitmap.createBitmap(mask.getWidth(), mask.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
......
package org.indin.blisslaunchero;
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.ImageView;
/**
* Created by falcon on 16/2/18.
*/
public class SquareImageView extends ImageView {
public SquareImageView(Context context) {
super(context);
}
public SquareImageView(Context context,
@Nullable AttributeSet attrs) {
super(context, attrs);
}
public SquareImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getMeasuredWidth();
setMeasuredDimension(width, width);
}
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.security.acl.Group;
import java.util.List;
public class Storage {
......@@ -31,7 +32,7 @@ public class Storage {
* @param pages
* @param dock
*/
public void save(final List<GridLayout> pages, final LinearLayout dock) {
public void save(final List<GridLayout> pages, final GridLayout dock) {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
......
......@@ -2,6 +2,6 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:innerRadius="0dp"
android:thickness="8dp">
android:thickness="6dp">
<solid android:color="@color/dot_off_color"/>
</shape>
\ No newline at end of file
......@@ -2,6 +2,6 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:innerRadius="0dp"
android:thickness="8dp">
android:thickness="6dp">
<solid android:color="@color/dot_on_color"/>
</shape>
\ No newline at end of file
......@@ -5,6 +5,7 @@
android:id="@+id/workspace"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="org.indin.blisslaunchero.DesktopActivity">
<org.indin.blisslaunchero.HorizontalPager
......@@ -12,16 +13,15 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/page_indicator"
android:layout_alignParentTop="true"
android:layout_marginTop="@dimen/pager_margin" />
android:layout_alignParentTop="true" />
<LinearLayout
android:id="@+id/page_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/dock"
android:layout_marginBottom="12dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:divider="@drawable/gap"
android:gravity="center_horizontal"
android:orientation="horizontal"
......@@ -29,19 +29,19 @@
</LinearLayout>
<LinearLayout
<GridLayout
android:id="@+id/dock"
android:layout_width="match_parent"
android:layout_height="@dimen/dockHeight"
android:layout_alignParentBottom="true"
android:animateLayoutChanges="false"
android:background="@color/dockColor"
android:gravity="center"
android:paddingLeft="@dimen/app_col_margin"
android:paddingRight="@dimen/app_col_margin"
android:orientation="horizontal">
android:columnCount="@integer/col_count"
android:rowCount="1"
android:paddingLeft="@dimen/app_grid_padding"
android:paddingRight="@dimen/app_grid_padding">
</LinearLayout>
</GridLayout>
<RelativeLayout
android:id="@+id/folder_window_container"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:layout_marginLeft="@dimen/app_col_margin"
android:layout_marginRight="@dimen/app_col_margin"
android:orientation="vertical">
<ImageView
<org.indin.blisslaunchero.SquareImageView
android:id="@+id/app_icon"
android:layout_width="@dimen/iconSize"
android:layout_height="@dimen/iconSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@drawable/rounded_corners_icon"
android:foreground="?attr/selectableItemBackground"
......@@ -20,10 +18,10 @@
android:id="@+id/app_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:layout_marginTop="4dp"
android:textColor="@color/app_label_color"
android:textSize="@dimen/labelSize" />
......
......@@ -5,5 +5,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="@integer/col_count"
android:rowCount="6"
android:paddingLeft="@dimen/app_grid_padding"
android:paddingRight="@dimen/app_grid_padding"/>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="maxDistanceForFolderCreation">20dp</dimen>
<dimen name="iconSize">56dp</dimen>
<dimen name="labelSize">14sp</dimen>
<dimen name="dotSize">12dp</dimen>
<dimen name="hitBoxSize">60dp</dimen>
<dimen name="scrollCorner">8dp</dimen>
<dimen name="iconPadding">12dp</dimen>
<dimen name="dockHeight">104dp</dimen>
<dimen name="pager_margin">32dp</dimen>
<dimen name="labelHeight">14dp</dimen>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="row_count">4</integer>
<integer name="col_count">4</integer>
<integer name="dock_column_count">@integer/col_count</integer>
<integer name="dock_row_count">1</integer>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="maxDistanceForFolderCreation">20dp</dimen>
<dimen name="iconSize">60dp</dimen>
<dimen name="labelSize">16sp</dimen>
<dimen name="dotSize">12dp</dimen>
<dimen name="hitBoxSize">60dp</dimen>
<dimen name="scrollCorner">8dp</dimen>
<dimen name="iconPadding">12dp</dimen>
<dimen name="dockHeight">104dp</dimen>
<dimen name="pager_margin">32dp</dimen>
<dimen name="labelHeight">16dp</dimen>
<dimen name="app_icon_margin">14dp</dimen>
<dimen name="app_col_margin">12dp</dimen>
<dimen name="app_grid_padding">15dp</dimen>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="row_count">5</integer>
<integer name="col_count">4</integer>
<integer name="dock_column_count">@integer/col_count</integer>
<integer name="dock_row_count">1</integer>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="maxDistanceForFolderCreation">20dp</dimen>
<dimen name="iconSize">64dp</dimen>
<dimen name="labelSize">16sp</dimen>
<dimen name="dotSize">12dp</dimen>
<dimen name="hitBoxSize">60dp</dimen>
<dimen name="scrollCorner">8dp</dimen>
<dimen name="iconPadding">12dp</dimen>
<dimen name="dockHeight">104dp</dimen>
<dimen name="pager_margin">32dp</dimen>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="row_count">5</integer>
<integer name="col_count">4</integer>
<integer name="dock_column_count">@integer/col_count</integer>
<integer name="dock_row_count">1</integer>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="maxDistanceForFolderCreation">20dp</dimen>
<dimen name="iconSize">68dp</dimen>
<dimen name="labelSize">16sp</dimen>
<dimen name="dotSize">12dp</dimen>
<dimen name="hitBoxSize">60dp</dimen>
<dimen name="scrollCorner">8dp</dimen>
<dimen name="iconPadding">12dp</dimen>
<dimen name="dockHeight">104dp</dimen>
<dimen name="pager_margin">32dp</dimen>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="row_count">5</integer>
<integer name="col_count">4</integer>
<integer name="dock_column_count">@integer/col_count</integer>
<integer name="dock_row_count">1</integer>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="maxDistanceForFolderCreation">20dp</dimen>
<dimen name="iconSize">72dp</dimen>
<dimen name="labelSize">18sp</dimen>
<dimen name="dotSize">12dp</dimen>
<dimen name="hitBoxSize">60dp</dimen>
<dimen name="scrollCorner">8dp</dimen>
<dimen name="iconPadding">12dp</dimen>
<dimen name="dockHeight">104dp</dimen>
<dimen name="pager_margin">32dp</dimen>
<dimen name="labelHeight">20dp</dimen>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="row_count">6</integer>
<integer name="col_count">4</integer>
<integer name="dock_column_count">@integer/col_count</integer>
<integer name="dock_row_count">1</integer>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="maxDistanceForFolderCreation">20dp</dimen>
<dimen name="iconSize">80dp</dimen>
<dimen name="labelSize">18sp</dimen>
<dimen name="dotSize">6dp</dimen>
<dimen name="hitBoxSize">60dp</dimen>
<dimen name="scrollCorner">8dp</dimen>
<dimen name="iconPadding">16dp</dimen>
<dimen name="dockHeight">126dp</dimen>
<dimen name="pager_margin">32dp</dimen>
</resources>
\ No newline at end of file
Supports Markdown
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