Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a button to controll the margin between App's labels #180

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ android {
versionName "0.19"
//resConfigs "en", "de"
buildConfigField "boolean", "enableColorSniffer", "false"
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
debug {
Expand Down Expand Up @@ -73,6 +74,10 @@ dependencies {
implementation 'com.github.promeg:tinypinyin:2.0.3' // Core lib of TinyPinyin, it is only 80KB.

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestImplementation 'com.android.support.test:rules:1.0.2'

debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.2'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.github.subhamtyagi.lastlauncher.utils.DbUtils;

import static io.github.subhamtyagi.lastlauncher.utils.Constants.MAX_PADDING_BOTTOM;
import static io.github.subhamtyagi.lastlauncher.utils.Constants.MAX_PADDING_INTERVAL;
import static io.github.subhamtyagi.lastlauncher.utils.Constants.MAX_PADDING_LEFT;
import static io.github.subhamtyagi.lastlauncher.utils.Constants.MAX_PADDING_RIGHT;
import static io.github.subhamtyagi.lastlauncher.utils.Constants.MAX_PADDING_TOP;
Expand All @@ -49,16 +50,17 @@ public class PaddingDialog extends Dialog implements View.OnLongClickListener, V
private TextView right;
private TextView top;
private TextView bottom;
private TextView interval;

private int topInt, leftInt, rightInt, bottomInt;

private int topInt, leftInt, rightInt, bottomInt, intervalInt;

private Runnable runnable;

public PaddingDialog(Context context, FlowLayout mHomeLayout) {
super(context);
homeLayout = mHomeLayout;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -80,6 +82,11 @@ protected void onCreate(Bundle savedInstanceState) {
TextView btnBottomMinus = findViewById(R.id.btn_bottom_minus);
btnBottomMinus.setOnLongClickListener(this);
btnBottomMinus.setOnClickListener(this);

TextView btnIntervalMinus = findViewById(R.id.btn_interval_minus);
btnIntervalMinus.setOnLongClickListener(this);
btnIntervalMinus.setOnClickListener(this);

TextView btnLeftPlus = findViewById(R.id.btn_left_plus);
btnLeftPlus.setOnLongClickListener(this);
btnLeftPlus.setOnClickListener(this);
Expand All @@ -95,20 +102,27 @@ protected void onCreate(Bundle savedInstanceState) {
btnBottomPlus.setOnLongClickListener(this);
btnBottomPlus.setOnClickListener(this);

TextView btnIntervalPlus = findViewById(R.id.btn_interval_plus);
btnIntervalPlus.setOnLongClickListener(this);
btnIntervalPlus.setOnClickListener(this);

left = findViewById(R.id.tv_left_padding);
right = findViewById(R.id.tv_right_padding);
top = findViewById(R.id.tv_top_padding);
bottom = findViewById(R.id.tv_bottom_padding);
interval = findViewById(R.id.tv_interval_padding);

leftInt = DbUtils.getPaddingLeft();
rightInt = DbUtils.getPaddingRight();
topInt = DbUtils.getPaddingTop();
bottomInt = DbUtils.getPaddingBottom();
intervalInt = DbUtils.getPaddingInterval();

left.setText(String.valueOf(leftInt));
right.setText(String.valueOf(rightInt));
top.setText(String.valueOf(topInt));
bottom.setText(String.valueOf(bottomInt));
interval.setText(String.valueOf(intervalInt));


}
Expand All @@ -123,6 +137,8 @@ protected void onStop() {
DbUtils.setPaddingRight(rightInt);
DbUtils.setPaddingTop(topInt);
DbUtils.setPaddingBottom(bottomInt);
DbUtils.setPaddingInterval(intervalInt);

}

@Override
Expand Down Expand Up @@ -152,6 +168,16 @@ public boolean onLongClick(View button) {
case R.id.btn_bottom_plus:
runner((TextView) button, bottom, 2, Padding.BOTTOM);
break;
case R.id.btn_interval_minus:
runner((TextView) button, interval, -2, Padding.INTERVAL);
break;
case R.id.btn_interval_plus:
runner((TextView) button, interval, 2, Padding.INTERVAL);
break;
default:
runner((TextView) button, interval, 2, Padding.INTERVAL);
break;

}

return true;
Expand Down Expand Up @@ -220,8 +246,29 @@ public void onClick(View view) {
}
bottom.setText(String.valueOf(bottomInt));
break;
case R.id.btn_interval_minus:
intervalInt--;
if(intervalInt < MIN_PADDING){
intervalInt = MIN_PADDING;
}
interval.setText(String.valueOf(intervalInt));
break;
case R.id.btn_interval_plus:
intervalInt ++;
if(intervalInt > MAX_PADDING_INTERVAL){
intervalInt = MAX_PADDING_INTERVAL;
}
interval.setText(String.valueOf(intervalInt));
default:
intervalInt ++;
if(intervalInt > MAX_PADDING_INTERVAL){
intervalInt = MAX_PADDING_INTERVAL;
}
interval.setText(String.valueOf(intervalInt));
break;
}
// apply all padding to home layout
homeLayout.changeMargin(20 + intervalInt, 20 +intervalInt, 20, 20);
homeLayout.setPadding(leftInt, topInt, rightInt, bottomInt);
}

Expand Down Expand Up @@ -298,10 +345,24 @@ private void runner(final TextView button, final TextView view, final int step,
}
view.setText(String.valueOf(bottomInt));
break;
case INTERVAL:
intervalInt += step;
if(step > 0){
if(intervalInt > MAX_PADDING_INTERVAL){
intervalInt = MAX_PADDING_INTERVAL;
}
}else{
if(intervalInt < MIN_PADDING){
intervalInt = MIN_PADDING;
}
}
view.setText(String.valueOf(intervalInt));
break;
}

// set the padding to home layout
homeLayout.setPadding(leftInt, topInt, rightInt, bottomInt);
homeLayout.changeMargin(20 + intervalInt, 20 +intervalInt, 20, 20);
// currently button is still pressed so again call this runnable
handler.postDelayed(runnable, DELAY);

Expand All @@ -314,7 +375,7 @@ private void runner(final TextView button, final TextView view, final int step,

//enums for better understanding
private enum Padding {
LEFT, RIGHT, TOP, BOTTOM
LEFT, RIGHT, TOP, BOTTOM, INTERVAL
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public class Constants {
public static final int MAX_PADDING_LEFT = 99;
public static final int MAX_PADDING_RIGHT = 99;
public static final int MAX_PADDING_TOP = 999;
public static final int MAX_PADDING_BOTTOM = 999;
public static final int MAX_PADDING_BOTTOM = 99;
public static final int MAX_PADDING_INTERVAL = 90;
public static final int MIN_PADDING = 0;
//TODO: Dynamic height
public static int dynamicHeight = 20;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class DbUtils {
private static final String PADDING_LEFT = "padding_left";
private static final String PADDING_RIGHT = "padding_right";
private static final String PADDING_BOTTOM = "padding_bottom";
private static final String PADDING_INTERVAL = "padding interval";

private static final String GLOBAL_SIZE_ADDITION_EXTRA = "global_size_addition_extra";
private static final String APPS_COLORS_DEFAULT = "apps_color_default";
Expand Down Expand Up @@ -325,6 +326,14 @@ public static void setPaddingBottom(int padding) {
SpUtils.getInstance().putInt(PADDING_BOTTOM, padding);
}

public static int getPaddingInterval() {
return SpUtils.getInstance().getInt(PADDING_INTERVAL, 0);
}

public static void setPaddingInterval(int padding) {
SpUtils.getInstance().putInt(PADDING_INTERVAL, padding);
}


public static void setGroupPrefix(String activityName, String prefix) {
activityName = activityName.replaceAll("\\.", "_") + "_group_prefix";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ public static boolean simpleFuzzySearch(CharSequence query, String strings) {

}



public static int getColor() {
Random random = new Random();
int c = random.nextInt(4);
Expand Down
62 changes: 62 additions & 0 deletions app/src/main/res/layout/dialog_padding.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,66 @@
android:textSize="42sp" />

</LinearLayout>


<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center|center_horizontal|center_vertical"
android:padding="2dp">

<TextView
android:id="@+id/btn_interval_minus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center|center_horizontal|center_vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="-"
android:textSize="42sp" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center|center_horizontal|center_vertical"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingTop="5dp"
android:paddingRight="20dp"
android:paddingBottom="5dp">

<TextView
android:id="@+id/tv_interval_padding"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center|center_horizontal|center_vertical"

android:text="34"
android:textSize="42sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Interval" />
</LinearLayout>

<TextView
android:id="@+id/btn_interval_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center|center_horizontal|center_vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="+"
android:textSize="42sp" />

</LinearLayout>





</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/layout/list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/name_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|center_horizontal|center_vertical"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class FlowLayout extends ViewGroup {
private final ConfigDefinition config;
List<LineDefinition> lines = new ArrayList<>();
List<ViewDefinition> views = new ArrayList<>();

public FlowLayout(Context context) {
super(context);
this.config = new ConfigDefinition();
Expand Down Expand Up @@ -66,6 +65,21 @@ private void readStyleParameters(Context context, AttributeSet attributeSet) {
a.recycle();
}
}
// add in https://github.com/SubhamTyagi/Last-Launcher/issues/185
/**
* This method is used to change the margin between each APP's label.
*
* @param leftMargin the left margin of an APP's label.
* @param rightMargin the right margin of an APP's label.
* @param topMargin the top margin of an APP's label.
* @param bottomMargin the bottom margin of an APP's label.
*/

public void changeMargin(final int leftMargin, final int rightMargin, final int topMargin, final int bottomMargin) {
for (ViewDefinition view : views) {
view.setMargins(leftMargin + 10, topMargin, rightMargin + 10, bottomMargin);
}
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Expand All @@ -91,7 +105,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
view.setNewLine(lp.isNewLine());
view.setGravity(lp.getGravity());
view.setWeight(lp.getWeight());
view.setMargins(lp.leftMargin, lp.topMargin, lp.rightMargin, lp.bottomMargin);
view.setMargins(lp.leftMargin + 15, lp.topMargin + 5, lp.rightMargin + 15, lp.bottomMargin + 5); // margin setting
views.add(view);
}

Expand All @@ -100,10 +114,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
this.config.setWidthMode(MeasureSpec.getMode(widthMeasureSpec));
this.config.setHeightMode(MeasureSpec.getMode(heightMeasureSpec));
this.config.setCheckCanFit(this.config.getLengthMode() != View.MeasureSpec.UNSPECIFIED);

CommonLogic.fillLines(views, lines, config);
CommonLogic.calculateLinesAndChildPosition(lines);

int contentLength = 0;
final int linesCount = lines.size();
for (int i = 0; i < linesCount; i++) {
Expand Down Expand Up @@ -136,7 +148,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
this.setMeasuredDimension(resolveSize(totalControlWidth, widthMeasureSpec), resolveSize(totalControlHeight, heightMeasureSpec));
}

private void applyPositionsToViews(LineDefinition line) {
public void applyPositionsToViews(LineDefinition line) {
final List<ViewDefinition> childViews = line.getViews();
final int childCount = childViews.size();
for (int i = 0; i < childCount; i++) {
Expand Down Expand Up @@ -196,7 +208,6 @@ public LayoutParams generateLayoutParams(AttributeSet attributeSet) {
protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
return new LayoutParams(p);
}

private void drawDebugInfo(Canvas canvas, View child) {
if (!isDebugDraw()) {
return;
Expand All @@ -206,7 +217,6 @@ private void drawDebugInfo(Canvas canvas, View child) {
Paint newLinePaint = this.createPaint(0xffff0000);

LayoutParams lp = (LayoutParams) child.getLayoutParams();

if (lp.rightMargin > 0) {
float x = child.getRight();
float y = child.getTop() + child.getHeight() / 2.0f;
Expand Down Expand Up @@ -238,7 +248,6 @@ private void drawDebugInfo(Canvas canvas, View child) {
canvas.drawLine(x - 4.0f, y - lp.topMargin + 4.0f, x, y - lp.topMargin, childPaint);
canvas.drawLine(x + 4.0f, y - lp.topMargin + 4.0f, x, y - lp.topMargin, childPaint);
}

if (lp.isNewLine()) {
if (this.config.getOrientation() == CommonLogic.HORIZONTAL) {
float x = child.getLeft();
Expand Down Expand Up @@ -360,7 +369,6 @@ public static class LayoutParams extends MarginLayoutParams {
@ViewDebug.IntToString(from = Gravity.CENTER, to = "CENTER"),
@ViewDebug.IntToString(from = Gravity.FILL, to = "FILL")
})

private boolean newLine = false;
private int gravity = Gravity.NO_GRAVITY;
private float weight = -1.0f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public void setMargins(int leftMargin, int topMargin, int rightMargin, int botto
this.rightMargin = rightMargin;
this.bottomMargin = bottomMargin;
}

public int getInlineX() {
return this.config.getOrientation() == CommonLogic.HORIZONTAL ? this.inlineStartLength : this.inlineStartThickness;
}
Expand Down
Binary file added 桌面 - 快捷方式.lnk
Binary file not shown.