tabname changes now

tabname can not be empty
tabname duplicates are not allowed
changed inputfield texts to hints
drawer now closes when custom tab is clicked
tabdialog headers are renamed
tabdialog inputfields is now own xml
added hint do console-command-textinput
This commit is contained in:
JG-Cody 2021-07-10 15:14:19 +02:00
parent a21fcb467b
commit 8ecc32829b
10 changed files with 171 additions and 38 deletions

View File

@ -16,6 +16,7 @@ import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.drawable.ColorDrawable;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@ -23,8 +24,10 @@ import android.provider.MediaStore;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.EditText;
@ -36,6 +39,7 @@ import android.widget.Toast;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
@ -76,10 +80,10 @@ public class MainActivity extends AppCompatActivity {
ListAdapter listAdapter;
ListView listView;
EditText editText_name;
ArrayList<ListItem> items;
Map < String, MenuItem > tabitems = new HashMap<>();
Map<String, MenuItem> tabitems = new HashMap<>();
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
@ -149,7 +153,7 @@ public class MainActivity extends AppCompatActivity {
Toast.makeText(MainActivity.this, "Checked", Toast.LENGTH_LONG).show();
editmode = isChecked;
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
NavHostFragment nhf = (NavHostFragment)currentFragment;
NavHostFragment nhf = (NavHostFragment) currentFragment;
Fragment childfragment = nhf.getChildFragmentManager().getFragments().get(0);
Toast.makeText(MainActivity.this, childfragment.toString(), Toast.LENGTH_LONG).show();
if (childfragment instanceof FlurFragment) {
@ -168,27 +172,71 @@ public class MainActivity extends AppCompatActivity {
@Override
public boolean onMenuItemClick(MenuItem item) {
AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this);
mBuilder.setTitle("CHOOSE ELEMENT");
EditText input = new EditText(MainActivity.this);
mBuilder.setView(input);
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.addtabdialog, null);
editText_name = view.findViewById(R.id.dialogtab_editText_name);
mBuilder.setView(view)
.setTitle(R.string.menu_add);
mBuilder.setPositiveButton(R.string.menu_add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String tabname = input.getText().toString();
MenuItem item = navigationView.getMenu().add(R.id.dynamicgroup, Menu.NONE, 3,tabname);
String tabname = editText_name.getText().toString().trim();
SharedPreferences p = getSharedPreferences("appsettings", MODE_PRIVATE);
Set<String> tabs = new HashSet<>(p.getStringSet("tabs", new HashSet<>()));
if(tabs.contains(tabname) ) {
MediaPlayer mp = MediaPlayer.create(MainActivity.this, R.raw.state_change_confirm_up);
mp.start();
AlertDialog mDialog = new AlertDialog.Builder(MainActivity.this)
.setTitle("TABNAME")
.setMessage("DER TABNAME EXISTIERT BEREITS!")
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, null )
.create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
return;
}
if(tabname.isEmpty()) {
MediaPlayer mp = MediaPlayer.create(MainActivity.this, R.raw.state_change_confirm_up);
mp.start();
AlertDialog mDialog = new AlertDialog.Builder(MainActivity.this)
.setTitle("TABNAME")
.setMessage("UNGÜLTIGER TABNAME")
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, null )
.create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
return;
}
MenuItem item = navigationView.getMenu().add(R.id.dynamicgroup, Menu.NONE, 3, tabname);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
DrawerLayout mDrawerLayout;
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.closeDrawer(GravityCompat.START);
Objects.requireNonNull(getSupportActionBar()).setTitle(tabname);
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
NavHostFragment nhf = (NavHostFragment)currentFragment;
nhf .getChildFragmentManager().beginTransaction().replace(R.id.nav_host_fragment, new FlurFragment(tabname)).commit();
NavHostFragment nhf = (NavHostFragment) currentFragment;
nhf.getChildFragmentManager().beginTransaction().replace(R.id.nav_host_fragment, new FlurFragment(tabname)).commit();
return true;
}
});
tabitems.put(tabname, item);
SharedPreferences p = getSharedPreferences("appsettings", MODE_PRIVATE);
Set<String> tabs = new HashSet<>(p.getStringSet("tabs", new HashSet<>()));
tabs.add(tabname);
SharedPreferences.Editor editor = p.edit();
editor.putStringSet("tabs", tabs);
@ -196,8 +244,15 @@ public class MainActivity extends AppCompatActivity {
}
});
mBuilder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
AlertDialog mDialog = mBuilder.create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
return true;
}
@ -207,23 +262,43 @@ public class MainActivity extends AppCompatActivity {
public boolean onMenuItemClick(MenuItem item) {
SharedPreferences p = getSharedPreferences("appsettings", MODE_PRIVATE);
Set<String> tabs = new HashSet<>(p.getStringSet("tabs", new HashSet<>()));
Set<String> selectedTabs = new HashSet<>();
String[] tabsarray = tabs.toArray(new String[0]);
AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this);
mBuilder.setTitle("CHOOSE ELEMENT");
mBuilder.setSingleChoiceItems(tabsarray, -1, new DialogInterface.OnClickListener() {
mBuilder.setTitle(R.string.menu_remove);
mBuilder.setMultiChoiceItems(tabsarray, null, new DialogInterface.OnMultiChoiceClickListener() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onClick(DialogInterface dialogInterface, int i, boolean isChecked) {
String selectedItem = tabsarray[i];
if (isChecked) {
selectedTabs.add(selectedItem);
} else {
selectedTabs.remove(selectedItem);
}
}
});
mBuilder.setPositiveButton("REMOVE", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String tab = tabsarray[i];
tabs.remove(tab);
tabs.removeAll(selectedTabs);
SharedPreferences.Editor editor = p.edit();
editor.putStringSet("tabs", tabs);
for (String tab : selectedTabs) {
editor.remove("listItems." + tab);
editor.apply();
navigationView.getMenu().removeItem(tabitems.get(tab).getItemId());
tabitems.remove(tab);
dialogInterface.dismiss();
}
}
});
mBuilder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
AlertDialog mDialog = mBuilder.create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
@ -232,14 +307,18 @@ public class MainActivity extends AppCompatActivity {
}
});
Set<String> tabs = new HashSet<>(p.getStringSet("tabs", new HashSet<>()));
for (String tab: tabs){
MenuItem item = navigationView.getMenu().add(R.id.dynamicgroup, Menu.NONE, 3,tab);
for (String tab : tabs) {
MenuItem item = navigationView.getMenu().add(R.id.dynamicgroup, Menu.NONE, 3, tab);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
DrawerLayout mDrawerLayout;
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.closeDrawer(GravityCompat.START);
Objects.requireNonNull(getSupportActionBar()).setTitle(tab);
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
NavHostFragment nhf = (NavHostFragment)currentFragment;
nhf .getChildFragmentManager().beginTransaction().replace(R.id.nav_host_fragment, new FlurFragment(tab)).commit();
NavHostFragment nhf = (NavHostFragment) currentFragment;
nhf.getChildFragmentManager().beginTransaction().replace(R.id.nav_host_fragment, new FlurFragment(tab)).commit();
return true;
}
});
@ -247,8 +326,6 @@ public class MainActivity extends AppCompatActivity {
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="600"/>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:shareInterpolator="true" >
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="1000"/>
<scale
android:fromXScale="0.8"
android:toXScale="1.0"
android:fromYScale="1.0"
android:toYScale="1.0"
android:pivotX="0.8"
android:pivotY="1.0"
android:duration="1000"/>
<translate
android:fromXDelta="100%"
android:toXDelta="100%"
android:fromYDelta="50%"
android:toYDelta="100%"
android:duration="1000"/>
<rotate
android:fromDegrees="25"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"/>
</set>

View File

@ -11,7 +11,7 @@
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
android:hint="NAME" />
<EditText
android:id="@+id/dialogSingle_editText_buttonName"
@ -19,7 +19,7 @@
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Button" />
android:hint="BUTTON" />
<EditText
android:id="@+id/dialogSingle_editText_command"
@ -27,5 +27,5 @@
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Command" />
android:hint="COMMAND" />
</LinearLayout>

View File

@ -12,7 +12,7 @@
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
android:hint="NAME" />
<EditText
android:id="@+id/dialogDouble_editText_command1"
@ -20,7 +20,7 @@
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Command1" />
android:hint="COMMAND1" />
<EditText
android:id="@+id/dialogDouble_editText_button1"
@ -28,7 +28,7 @@
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Button1" />
android:hint="BUTTON1" />
<EditText
android:id="@+id/dialogDouble_editText_command2"
@ -36,7 +36,7 @@
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Command2" />
android:hint="COMMAND2" />
<EditText
android:id="@+id/dialogDouble_editText_button2"
@ -44,5 +44,5 @@
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Button2" />
android:hint="BUTTON2" />
</LinearLayout>

View File

@ -11,6 +11,6 @@
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
android:hint="NAME" />
</LinearLayout>

View File

@ -0,0 +1,16 @@
<?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="match_parent"
android:padding="16dp"
android:orientation="vertical" >
<EditText
android:id="@+id/dialogtab_editText_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="TABNAME" />
</LinearLayout>

View File

@ -74,6 +74,7 @@
android:layout_height="wrap_content"
android:backgroundTint="@color/mtrl_btn_text_color_selector"
android:ems="10"
android:hint="COMMAND"
android:inputType="text"
android:textColor="@color/mtrl_btn_text_color_selector"
android:textColorHint="@color/mtrl_btn_text_color_selector"

View File

@ -72,7 +72,7 @@
<string name="menu_flur">HALL</string>
<string name="menu_küche">KITCHEN</string>
<string name="menu_add">ADD TAB</string>
<string name="menu_remove">REMOVE TAB</string>
<string name="menu_remove">REMOVE TABS</string>
<string name="menu_einstellungen">SETTINGS</string>
<string name="menu_frage">QUESTION</string>

View File

@ -20,9 +20,14 @@
<!-- Customize your theme here.-->
<item name="actionOverflowMenuStyle">@style/ActionPopupMenuStyle</item>
</style>
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">@android:anim/slide_in_left</item>
<item name="android:windowExitAnimation">@android:anim/fade_out</item>
</style>
<style name="ActionPopupMenuStyle" parent="Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">@drawable/button_round</item>
<item name="android:windowEnterAnimation">@anim/nav_default_pop_enter_anim</item>
<item name="android:windowExitAnimation">@anim/nav_default_pop_exit_anim</item>
</style>
<style name="Theme.red_blue.NoActionBar">