mirror of
https://github.com/FatttSnake/OxygenToolbox.git
synced 2026-04-06 08:21:27 +08:00
Add ToolsButtons
This commit is contained in:
@@ -1,23 +1,29 @@
|
||||
package com.fatapp.oxygentoolbox;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.content.pm.ShortcutManager;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
import android.view.Menu;
|
||||
|
||||
import com.fatapp.oxygentoolbox.layout.FoldLayout;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.navigation.ui.AppBarConfiguration;
|
||||
import androidx.navigation.ui.NavigationUI;
|
||||
|
||||
import com.fatapp.oxygentoolbox.layout.FoldLayout;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
@@ -32,12 +38,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
FloatingActionButton fab = findViewById(R.id.fab);
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();
|
||||
}
|
||||
fab.setOnClickListener(view -> {
|
||||
/*Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();*/
|
||||
});
|
||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
NavigationView navigationView = findViewById(R.id.nav_view);
|
||||
@@ -50,6 +53,29 @@ public class MainActivity extends AppCompatActivity {
|
||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
|
||||
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
|
||||
NavigationUI.setupWithNavController(navigationView, navController);
|
||||
|
||||
shortCutCreateTest();
|
||||
}
|
||||
|
||||
private void shortCutCreateTest() {
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1) {
|
||||
return;
|
||||
}
|
||||
Intent intent = new Intent();
|
||||
intent.setAction("android.intent.action.VIEW");
|
||||
intent.setClassName("com.fatapp.oxygentoolbox",
|
||||
"com.fatapp.oxygentoolbox.MainActivity");
|
||||
ShortcutInfo.Builder builder;
|
||||
builder = new ShortcutInfo.Builder(this, "dynamic shortcut")
|
||||
.setIntent(new Intent()
|
||||
.setAction("android.intent.action.VIEW")
|
||||
.setClassName("com.fatapp.oxygentoolbox", "com.fatapp.oxygentoolbox.MainActivity"))
|
||||
.setShortLabel("This is a dynamic shortcut")
|
||||
.setLongLabel("This is a dynamic shortcut with long label")
|
||||
.setIcon(Icon.createWithResource(this, R.drawable.ic_menu_camera));
|
||||
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
|
||||
shortcutManager.addDynamicShortcuts(Collections.singletonList(builder.build()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.fatapp.oxygentoolbox.layout;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class AutoLinefeedLayout extends ViewGroup {
|
||||
|
||||
public AutoLinefeedLayout(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
public AutoLinefeedLayout(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public AutoLinefeedLayout(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
layoutHorizontal();
|
||||
}
|
||||
|
||||
private void layoutHorizontal() {
|
||||
final int count = getChildCount();
|
||||
final int lineWidth = getMeasuredWidth() - getPaddingLeft()
|
||||
- getPaddingRight();
|
||||
int paddingTop = getPaddingTop();
|
||||
int childTop = 0;
|
||||
int childLeft = getPaddingLeft();
|
||||
|
||||
int availableLineWidth = lineWidth;
|
||||
int maxLineHight = 0;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
final View child = getChildAt(i);
|
||||
if (child == null) {
|
||||
continue;
|
||||
} else if (child.getVisibility() != GONE) {
|
||||
final int childWidth = child.getMeasuredWidth();
|
||||
final int childHeight = child.getMeasuredHeight();
|
||||
|
||||
if (availableLineWidth < childWidth) {
|
||||
availableLineWidth = lineWidth;
|
||||
paddingTop = paddingTop + maxLineHight;
|
||||
childLeft = getPaddingLeft();
|
||||
maxLineHight = 0;
|
||||
}
|
||||
childTop = paddingTop;
|
||||
setChildFrame(child, childLeft, childTop, childWidth,
|
||||
childHeight);
|
||||
childLeft += childWidth;
|
||||
availableLineWidth = availableLineWidth - childWidth;
|
||||
maxLineHight = Math.max(maxLineHight, childHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setChildFrame(View child, int left, int top, int width,
|
||||
int height) {
|
||||
child.layout(left, top, left + width, top + height);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
|
||||
int count = getChildCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
measureChild(getChildAt(i), widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
if (heightMode == MeasureSpec.AT_MOST||heightMode == MeasureSpec.UNSPECIFIED) {
|
||||
final int width = MeasureSpec.getSize(widthMeasureSpec);
|
||||
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(
|
||||
getDesiredHeight(width), MeasureSpec.EXACTLY));
|
||||
} else {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
}
|
||||
|
||||
private int getDesiredHeight(int width) {
|
||||
final int lineWidth = width - getPaddingLeft() - getPaddingRight();
|
||||
int availableLineWidth = lineWidth;
|
||||
int totalHeight = getPaddingTop() + getPaddingBottom();
|
||||
int lineHeight = 0;
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
View child = getChildAt(i);
|
||||
final int childWidth = child.getMeasuredWidth();
|
||||
final int childHeight = child.getMeasuredHeight();
|
||||
if (availableLineWidth < childWidth) {
|
||||
availableLineWidth = lineWidth;
|
||||
totalHeight = totalHeight + lineHeight;
|
||||
lineHeight = 0;
|
||||
}
|
||||
availableLineWidth = availableLineWidth - childWidth;
|
||||
lineHeight = Math.max(childHeight, lineHeight);
|
||||
}
|
||||
totalHeight = totalHeight + lineHeight;
|
||||
return totalHeight;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener{
|
||||
defaultView = LayoutInflater.from(context).inflate(layoutId, this,true);
|
||||
defaultView.setOnClickListener(this);
|
||||
content = new LinearLayout(context);
|
||||
LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
/*content.setShowDividers(SHOW_DIVIDER_BEGINNING|SHOW_DIVIDER_MIDDLE);
|
||||
content.setDividerDrawable(ContextCompat.getDrawable(context,R.drawable.item_divider));*/
|
||||
@@ -119,6 +119,8 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener{
|
||||
});
|
||||
init = true;
|
||||
hide();
|
||||
|
||||
showItem();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +143,7 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener{
|
||||
* Auto hide
|
||||
*/
|
||||
public void hide() {
|
||||
LayoutParams layoutParams = (LayoutParams) content.getLayoutParams();
|
||||
LinearLayout.LayoutParams layoutParams = (LayoutParams) content.getLayoutParams();
|
||||
layoutParams.height = 0;
|
||||
content.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,23 @@
|
||||
package com.fatapp.oxygentoolbox.ui.home;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.fatapp.oxygentoolbox.MainActivity;
|
||||
import com.fatapp.oxygentoolbox.R;
|
||||
import com.fatapp.oxygentoolbox.layout.FoldLayout;
|
||||
|
||||
@@ -22,6 +31,7 @@ public class HomeFragment extends Fragment {
|
||||
private HomeViewModel homeViewModel;
|
||||
|
||||
private FoldLayout foldLayout;
|
||||
private FoldLayout foldLayout1;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
@@ -34,11 +44,13 @@ public class HomeFragment extends Fragment {
|
||||
|
||||
private void initView() {
|
||||
foldLayout = (FoldLayout) root.findViewById(R.id.foldLayout);
|
||||
|
||||
List<View> viewList = new ArrayList<>();
|
||||
|
||||
viewList.add(getLayoutInflater().inflate(R.layout.layout_item, null));
|
||||
|
||||
foldLayout.addItemView(viewList);
|
||||
|
||||
foldLayout1 = (FoldLayout) root.findViewById(R.id.foldLayout1);
|
||||
List<View> viewList1 = new ArrayList<>();
|
||||
viewList1.add(getLayoutInflater().inflate(R.layout.layout_item, null));
|
||||
foldLayout1.addItemView(viewList1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user