added haptic feedback

This commit is contained in:
JG-Cody 2021-07-10 23:38:40 +02:00
parent d9504a4f9c
commit 169e1a9501
9 changed files with 72 additions and 161 deletions

View File

@ -20,6 +20,7 @@ import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Vibrator;
import android.provider.MediaStore;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
@ -139,7 +140,7 @@ public class MainActivity extends AppCompatActivity {
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_home, R.id.nav_einstellungen, R.id.nav_zeitsteuerung, R.id.nav_schlafzimmer, R.id.nav_tabs, R.id.nav_über, R.id.nav_konsole)
R.id.nav_home, R.id.nav_einstellungen, R.id.nav_zeitsteuerung, R.id.nav_tabs, R.id.nav_über, R.id.nav_konsole)
.setOpenableLayout(drawer)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
@ -148,6 +149,8 @@ public class MainActivity extends AppCompatActivity {
((Switch) navigationView.getMenu().getItem(3).getActionView().findViewById(R.id.switch_editmode)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
editmode = isChecked;
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
NavHostFragment nhf = (NavHostFragment) currentFragment;
@ -167,6 +170,8 @@ public class MainActivity extends AppCompatActivity {
navigationView.getMenu().getItem(4).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this);
@ -180,6 +185,8 @@ public class MainActivity extends AppCompatActivity {
mBuilder.setPositiveButton(R.string.menu_add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
String tabname = editText_name.getText().toString().trim();
SharedPreferences p = getSharedPreferences("appsettings", MODE_PRIVATE);
@ -220,6 +227,8 @@ public class MainActivity extends AppCompatActivity {
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
DrawerLayout mDrawerLayout;
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.closeDrawer(GravityCompat.START);
@ -243,6 +252,8 @@ public class MainActivity extends AppCompatActivity {
mBuilder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
}
});
@ -256,6 +267,8 @@ public class MainActivity extends AppCompatActivity {
navigationView.getMenu().getItem(5).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
SharedPreferences p = getSharedPreferences("appsettings", MODE_PRIVATE);
Set<String> tabs = new HashSet<>(p.getStringSet("tabs", new HashSet<>()));
Set<String> selectedTabs = new HashSet<>();
@ -278,6 +291,8 @@ public class MainActivity extends AppCompatActivity {
mBuilder.setPositiveButton("REMOVE", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
tabs.removeAll(selectedTabs);
SharedPreferences.Editor editor = p.edit();
editor.putStringSet("tabs", tabs);
@ -293,7 +308,8 @@ public class MainActivity extends AppCompatActivity {
mBuilder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
}
});
AlertDialog mDialog = mBuilder.create();
@ -309,6 +325,8 @@ public class MainActivity extends AppCompatActivity {
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
DrawerLayout mDrawerLayout;
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.closeDrawer(GravityCompat.START);
@ -377,6 +395,8 @@ public class MainActivity extends AppCompatActivity {
public void menurighttopeinstellungen(MenuItem i) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
NavHostFragment nhf = (NavHostFragment) currentFragment;
nhf.getChildFragmentManager().beginTransaction().replace(R.id.nav_host_fragment, new EinstellungenFragment()).commit();
@ -384,6 +404,8 @@ public class MainActivity extends AppCompatActivity {
}
public void menurighttopabout(MenuItem i) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
NavHostFragment nhf = (NavHostFragment) currentFragment;
nhf.getChildFragmentManager().beginTransaction().replace(R.id.nav_host_fragment, new CreditsFragment()).commit();
@ -391,11 +413,15 @@ public class MainActivity extends AppCompatActivity {
}
public void menurighttopdocumentation(MenuItem i) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.jg-cody.de/"));
startActivity(in);
}
public void menurighttopcloseapp(MenuItem i) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
finishAffinity();
} else {

View File

@ -12,6 +12,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -54,6 +55,8 @@ public class EinstellungenFragment extends Fragment {
Language.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Vibrator vr = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
showChangeLanguageDialog();
}
@ -62,6 +65,8 @@ public class EinstellungenFragment extends Fragment {
Reset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Vibrator vr = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.alert_error);
mp.start();
AlertDialog mDialog = new AlertDialog.Builder(getContext())
@ -72,6 +77,8 @@ public class EinstellungenFragment extends Fragment {
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Vibrator vr = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
try {
requireContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE).edit().clear().apply();
startActivity(requireActivity().getIntent());
@ -96,6 +103,8 @@ public class EinstellungenFragment extends Fragment {
choose_background.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Vibrator vr = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
showChangeBackgroundDialog();
@ -105,6 +114,8 @@ public class EinstellungenFragment extends Fragment {
theme1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Vibrator vr = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
SharedPreferences.Editor editor = requireContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit();
editor.putString("Theme", "RED_BLUE");
editor.apply();
@ -118,6 +129,8 @@ public class EinstellungenFragment extends Fragment {
theme2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Vibrator vr = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
SharedPreferences.Editor editor = requireContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit();
editor.putString("Theme", "GREEN_YELLOW");
editor.apply();
@ -131,6 +144,8 @@ public class EinstellungenFragment extends Fragment {
theme3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Vibrator vr = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
SharedPreferences.Editor editor = requireContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit();
editor.putString("Theme", "ORANGE_TURQUOISE");
editor.apply();
@ -144,6 +159,8 @@ public class EinstellungenFragment extends Fragment {
theme4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Vibrator vr = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
SharedPreferences.Editor editor = requireContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit();
editor.putString("Theme", "YELLOW_BLUE");
editor.apply();
@ -157,6 +174,8 @@ public class EinstellungenFragment extends Fragment {
theme5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Vibrator vr = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
SharedPreferences.Editor editor = requireContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit();
editor.putString("Theme", "PINK_GREEN");
editor.apply();
@ -177,6 +196,8 @@ public class EinstellungenFragment extends Fragment {
mBuilder.setSingleChoiceItems(listItems, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Vibrator vr = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
if (i == 0) {
setLocale("de");
startActivity(requireActivity().getIntent());
@ -202,6 +223,8 @@ public class EinstellungenFragment extends Fragment {
mBuilder.setSingleChoiceItems(listItems, -5, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Vibrator vr = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
if (i == 0) {
Intent a = new Intent(
Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

View File

@ -2,6 +2,7 @@ package de.jg_cody.Teraplex.ui.Konsole;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
@ -9,6 +10,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -63,6 +65,8 @@ public class KonsoleFragment extends Fragment {
SendCommandButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Vibrator vr = (Vibrator) v.getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
try {
if (befehlInput.getText().toString().trim().length() == 0) {
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_up);
@ -94,6 +98,8 @@ public class KonsoleFragment extends Fragment {
reboot_Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Vibrator vr = (Vibrator) v.getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_up);
mp.start();
AlertDialog mDialog = new AlertDialog.Builder(getContext())
@ -104,6 +110,8 @@ public class KonsoleFragment extends Fragment {
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Vibrator vr = (Vibrator) v.getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
try {
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_down);
mp.start();
@ -132,7 +140,8 @@ public class KonsoleFragment extends Fragment {
shutdown_Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Vibrator vr = (Vibrator) v.getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_up);
mp.start();
AlertDialog mDialog = new AlertDialog.Builder(getContext())
@ -143,6 +152,8 @@ public class KonsoleFragment extends Fragment {
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Vibrator vr = (Vibrator) v.getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
try {
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_down);
mp.start();

View File

@ -1,142 +0,0 @@
package de.jg_cody.Teraplex.ui.Schlafzimmer;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import java.util.Base64;
import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R;
import de.jg_cody.Teraplex.SSH_connection;
public class SchlafzimmerFragment extends Fragment {
public static String user, password, ip;
Button schlafzimmeru1aus;
Button schlafzimmeru1an;
Button schlafzimmeru2aus;
Button schlafzimmeru2an;
Button schlafzimmeru3aus;
Button schlafzimmeru3an;
private SchlafzimmerViewModel schlafzimmerViewModel;
@RequiresApi(api = Build.VERSION_CODES.O)
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
SharedPreferences prefs = requireContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE);
user = prefs.getString("user", null);
password = prefs.getString("password", null);
ip = prefs.getString("ip", null);
schlafzimmerViewModel =
new ViewModelProvider(this).get(SchlafzimmerViewModel.class);
View root = inflater.inflate(R.layout.fragment_schlafzimmer, container, false);
SharedPreferences p = requireContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
String Background = p.getString("Background", null);
if (Background != null) {
ImageView I = root.findViewById(R.id.Background);
byte[] BA = Base64.getDecoder().decode(Background);
I.setImageDrawable(new BitmapDrawable(getResources(), MainActivity.scaleCenterCrop(BitmapFactory.decodeByteArray(BA, 0, BA.length), MainActivity.getScreenHeight(), MainActivity.getScreenWidth())));
I.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
schlafzimmeru1aus = (Button) root.findViewById(R.id.schlafzimmeru1aus);
schlafzimmeru1aus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Toast.makeText(getContext(), "Lampe wird ausgeschaltet...", Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 4 0");
} catch (Exception ignored) {
}
}
});
schlafzimmeru1an = (Button) root.findViewById(R.id.schlafzimmeru1an);
schlafzimmeru1an.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Toast.makeText(getContext(), "Lampe wird angeschaltet...", Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 4 1");
} catch (Exception ignored) {
}
}
});
schlafzimmeru2aus = (Button) root.findViewById(R.id.schlafzimmeru2aus);
schlafzimmeru2aus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Toast.makeText(getContext(), "Lampe wird ausgeschaltet...", Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 2 0");
} catch (Exception ignored) {
}
}
});
schlafzimmeru2an = (Button) root.findViewById(R.id.schlafzimmeru2an);
schlafzimmeru2an.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Toast.makeText(getContext(), "Lampe wird angeschaltet...", Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 2 1");
} catch (Exception ignored) {
}
}
});
schlafzimmeru3aus = (Button) root.findViewById(R.id.schlafzimmeru3aus);
schlafzimmeru3aus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Toast.makeText(getContext(), "Lampe wird ausgeschaltet...", Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 3 0");
} catch (Exception ignored) {
}
}
});
schlafzimmeru3an = (Button) root.findViewById(R.id.schlafzimmeru3an);
schlafzimmeru3an.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Toast.makeText(getContext(), "Lampe wird angeschaltet...", Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 3 1");
} catch (Exception ignored) {
}
}
});
return root;
}
}

View File

@ -1,7 +0,0 @@
package de.jg_cody.Teraplex.ui.Schlafzimmer;
import androidx.lifecycle.ViewModel;
public class SchlafzimmerViewModel extends ViewModel {
}

View File

@ -9,6 +9,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -89,6 +90,8 @@ public class HomeFragment extends Fragment {
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Vibrator vr = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
if (userInput.getText().toString().trim().length() == 0 || ipInput.getText().toString().trim().length() == 0 || passwordInput.getText().toString().trim().length() == 0) {
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_up);
mp.start();
@ -136,6 +139,8 @@ public class HomeFragment extends Fragment {
logoutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Vibrator vr = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
requireContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE).edit().remove("ip").remove("user").remove("password").apply();
startActivity(requireActivity().getIntent());
requireActivity().finish();

View File

@ -2,6 +2,7 @@ package de.jg_cody.Teraplex.ui.rooms;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Vibrator;
import android.view.View;
import de.jg_cody.Teraplex.SSH_connection;
@ -14,6 +15,8 @@ public class CommandExecutor implements View.OnClickListener {
}
@Override
public void onClick(View v) {
Vibrator vr = (Vibrator) v.getContext().getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
SharedPreferences prefs = v.getContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE);
String user = prefs.getString("user", null);
String password = prefs.getString("password", null);

View File

@ -47,8 +47,6 @@
<group
android:id="@+id/dynamicgroup"
android:orderInCategory="3">
<item
android:id="@+id/nav_schlafzimmer"
android:title="@string/menu_schlafzimmer" />
</group>
</menu>

View File

@ -30,12 +30,6 @@
android:label="@string/menu_zeitsteuerung"
tools:layout="@layout/fragment_zeitsteuerung" />
<fragment
android:id="@+id/nav_schlafzimmer"
android:name="de.jg_cody.Teraplex.ui.Schlafzimmer.SchlafzimmerFragment"
android:label="@string/menu_schlafzimmer"
tools:layout="@layout/fragment_schlafzimmer" />
<fragment
android:id="@+id/nav_tabs"
android:name="de.jg_cody.Teraplex.ui.Tabs.TabsFragment"