From 10f5afe2067bdd16a77e5a7744d26b915ec63877 Mon Sep 17 00:00:00 2001 From: appt2 Date: Sun, 31 Mar 2024 12:07:57 +0330 Subject: [PATCH] add color from ui --- .androidide/editor/openedFiles.json | 50 +++++++++++++++++++ .../ninjacoder/listshset/MainActivity.java | 8 ++- .../src/main/java/adapter/ListAdapter.java | 22 ++++++-- library/src/main/java/widget/ItemRuner.java | 33 +++++++++++- .../src/main/res/layout/layout_adapter.xml | 7 ++- .../src/main/res/layout/layout_sheet_main.xml | 6 ++- 6 files changed, 115 insertions(+), 11 deletions(-) create mode 100644 .androidide/editor/openedFiles.json diff --git a/.androidide/editor/openedFiles.json b/.androidide/editor/openedFiles.json new file mode 100644 index 0000000..1e14bd0 --- /dev/null +++ b/.androidide/editor/openedFiles.json @@ -0,0 +1,50 @@ +{ + "allFiles": [ + { + "file": "/storage/emulated/0/AndroidIDEProjects/ListSheet/library/src/main/java/adapter/ListAdapter.java", + "selection": { + "end": { + "column": 35, + "index": 2004, + "line": 67 + }, + "start": { + "column": 35, + "index": 2004, + "line": 67 + } + } + }, + { + "file": "/storage/emulated/0/AndroidIDEProjects/ListSheet/library/src/main/java/widget/ItemRuner.java", + "selection": { + "end": { + "column": 32, + "index": 3030, + "line": 115 + }, + "start": { + "column": 14, + "index": 3012, + "line": 115 + } + } + }, + { + "file": "/storage/emulated/0/AndroidIDEProjects/ListSheet/app/src/main/java/com/ninjacoder/listshset/MainActivity.java", + "selection": { + "end": { + "column": 42, + "index": 1087, + "line": 31 + }, + "start": { + "column": 42, + "index": 1087, + "line": 31 + } + } + } + ], + "selectedFile": "/storage/emulated/0/AndroidIDEProjects/ListSheet/app/src/main/java/com/ninjacoder/listshset/MainActivity.java" +} \ No newline at end of file diff --git a/app/src/main/java/com/ninjacoder/listshset/MainActivity.java b/app/src/main/java/com/ninjacoder/listshset/MainActivity.java index 184b583..6807ffb 100644 --- a/app/src/main/java/com/ninjacoder/listshset/MainActivity.java +++ b/app/src/main/java/com/ninjacoder/listshset/MainActivity.java @@ -1,5 +1,6 @@ package com.ninjacoder.listshset; +import android.graphics.Color; import android.view.View; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; @@ -23,7 +24,12 @@ protected void onCreate(Bundle savedInstanceState) { runer.setCallBack((pos) ->{ runer.setDismiss(); }); - + runer.setTextColors(Color.CYAN); + runer.setColorFilter(Color.CYAN); + runer.serDivarColor(Color.BLUE); + runer.setTitleColor(Color.CYAN); + runer.setTitle("Hello"); + runer.setSheetBackground(Color.BLACK); runer.show(); diff --git a/library/src/main/java/adapter/ListAdapter.java b/library/src/main/java/adapter/ListAdapter.java index 41604b5..25738e3 100644 --- a/library/src/main/java/adapter/ListAdapter.java +++ b/library/src/main/java/adapter/ListAdapter.java @@ -1,5 +1,7 @@ package com.ninjacoder.listshset.library.adapter; +import android.graphics.Color; +import android.graphics.PorterDuff; import android.view.LayoutInflater; import android.view.ViewGroup; import android.view.View; @@ -16,6 +18,11 @@ public class ListAdapter extends BaseAdapter implements Adapter { protected List model; + private int colorText = Color.WHITE; + private int colorFilter = Color.WHITE; + private LinearLayout root; + protected ImageView img; + protected TextView tv; public ListAdapter(List model) { this.model = model; @@ -40,9 +47,9 @@ public long getItemId(int arg0) { public View getView(int pos, View views, ViewGroup par) { views = LayoutInflater.from(par.getContext()).inflate(R.layout.layout_adapter, par, false); var sheet = model.get(pos); - LinearLayout root = views.findViewById(R.id.root); - ImageView img = views.findViewById(R.id.icon); - TextView tv = views.findViewById(R.id.name); + root = views.findViewById(R.id.root); + img = views.findViewById(R.id.icon); + tv = views.findViewById(R.id.name); if (sheet.getIcon() == 0) { img.setVisibility(GONE); } @@ -50,6 +57,15 @@ public View getView(int pos, View views, ViewGroup par) { tv.setText(sheet.getName()); root.setEnabled(!sheet.getIsItem()); root.setAlpha(!sheet.getIsItem() ? 0.4f : 1f); + tv.setTextColor(colorText); + img.setColorFilter(colorFilter ,PorterDuff.Mode.SRC_IN); return views; } + public void setTextColor(int color){ + this.colorText = color; + } + public void setColorFilter(int colorFilter){ + this.colorFilter = colorFilter; + } + } diff --git a/library/src/main/java/widget/ItemRuner.java b/library/src/main/java/widget/ItemRuner.java index a6a13c6..6fda1f3 100644 --- a/library/src/main/java/widget/ItemRuner.java +++ b/library/src/main/java/widget/ItemRuner.java @@ -7,6 +7,7 @@ import android.widget.TextView; import androidx.annotation.IdRes; import com.google.android.material.bottomsheet.BottomSheetDialog; +import com.google.android.material.divider.MaterialDivider; import com.ninjacoder.listshset.library.R; import com.ninjacoder.listshset.library.adapter.ListAdapter; import com.ninjacoder.listshset.library.interfaces.OnItemClickEvent; @@ -22,12 +23,15 @@ public class ItemRuner { protected BottomSheetDialog dialog; protected SheetModel model; protected ListAdapter ad; + protected TextView title; + protected MaterialDivider divar; public ItemRuner(Context context) { this.context = context; var view = LayoutInflater.from(context).inflate(R.layout.layout_sheet_main, null); - TextView title = view.findViewById(R.id.title); + title = view.findViewById(R.id.title); listview = view.findViewById(R.id.listdata); + divar = view.findViewById(R.id.diver); listview.setScrollBarSize(0); listview.setDividerHeight(0); ad = new ListAdapter(list); @@ -85,4 +89,31 @@ public ListView getListview() { public void setListview(ListView listview) { this.listview = listview; } + + public void setTextColors(int colors) { + ad.setTextColor(colors); + } + + public void setColorFilter(int colors) { + ad.setColorFilter(colors); + } + + public void setTitle(String str) { + title.setText(str); + } + + public void setTitleColor(int color) { + title.setTextColor(color); + } + + public void serDivarColor(int color) { + divar.setDividerColor(color); + } + + public void serDivarColorFromRes(@IdRes int color) { + divar.setDividerColorResource(color); + } + public void setSheetBackground(int color){ + dialog.getWindow().getDecorView().setBackgroundColor(color); + } } diff --git a/library/src/main/res/layout/layout_adapter.xml b/library/src/main/res/layout/layout_adapter.xml index 51ef083..d0d06ae 100644 --- a/library/src/main/res/layout/layout_adapter.xml +++ b/library/src/main/res/layout/layout_adapter.xml @@ -10,8 +10,8 @@ android:id="@+id/root"> @@ -19,8 +19,7 @@ android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="16sp" - android:layout_marginLeft="2dp" - android:layout_marginRight="1dp" + android:layout_marginRight="4dp" android:textColor="#ffffffff" android:id="@+id/name" android:text="TextView" /> diff --git a/library/src/main/res/layout/layout_sheet_main.xml b/library/src/main/res/layout/layout_sheet_main.xml index 609f8c8..c709963 100644 --- a/library/src/main/res/layout/layout_sheet_main.xml +++ b/library/src/main/res/layout/layout_sheet_main.xml @@ -10,7 +10,9 @@ + android:paddingVertical="2dp" + android:orientation="vertical" + android:paddingHorizontal="2dp">