Fuck.
This commit is contained in:
parent
9dddd4eee7
commit
e9acdb15ab
|
|
@ -12,6 +12,10 @@
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.AndroidProjectCollection"
|
android:theme="@style/Theme.AndroidProjectCollection"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
|
<activity
|
||||||
|
android:name=".MenuExercise"
|
||||||
|
android:exported="false"
|
||||||
|
/>
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity_passing_intents_exercise2"
|
android:name=".activity_passing_intents_exercise2"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import androidx.core.view.WindowInsetsCompat;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
Button btn1,btn2,btn3,btn4,btn5;
|
Button btn1,btn2,btn3,btn4,btn5,btn6;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
@ -68,6 +68,15 @@ public class MainActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
btn6 = findViewById(R.id.btnMenu);
|
||||||
|
btn6.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
Intent startPI1 = new Intent(MainActivity.this, MenuExercise.class);
|
||||||
|
startActivity(startPI1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,123 @@
|
||||||
|
package com.example.androidprojectcollection;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.ParcelUuid;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.activity.EdgeToEdge;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import androidx.core.graphics.Insets;
|
||||||
|
import android.view.ViewGroup.LayoutParams;
|
||||||
|
import androidx.core.view.ViewCompat;
|
||||||
|
import androidx.core.view.WindowInsetsCompat;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class MenuExercise extends AppCompatActivity {
|
||||||
|
|
||||||
|
Button btn;
|
||||||
|
LayoutParams btnParams;
|
||||||
|
LayoutParams keepParam;
|
||||||
|
float keepX, keepY;
|
||||||
|
String text;
|
||||||
|
|
||||||
|
Random rand;
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
EdgeToEdge.enable(this);
|
||||||
|
setContentView(R.layout.activity_menu_exercise);
|
||||||
|
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
|
||||||
|
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||||
|
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||||
|
return insets;
|
||||||
|
});
|
||||||
|
|
||||||
|
btn = findViewById(R.id.mainButton);
|
||||||
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
|
btnParams = btn.getLayoutParams();
|
||||||
|
rand = new Random();
|
||||||
|
text = btn.getText().toString();
|
||||||
|
float density = getResources().getDisplayMetrics().density;
|
||||||
|
keepX = (213.5f * density + 0.5f);
|
||||||
|
keepY = (704 * density + 0.5f);
|
||||||
|
keepParam = new LayoutParams((int) (179 * density + 0.5f),(int) (145 * density + 0.5f));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
MenuInflater inflater = getMenuInflater();
|
||||||
|
inflater.inflate(R.menu.menu_menuexercise, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(@NonNull MenuItem item){
|
||||||
|
|
||||||
|
if(item.getItemId()==R.id.colorR){
|
||||||
|
btn.setBackgroundColor(Color.RED);
|
||||||
|
|
||||||
|
} else if (item.getItemId()==R.id.colorG) {
|
||||||
|
btn.setBackgroundColor(Color.GREEN);
|
||||||
|
|
||||||
|
}else if (item.getItemId()==R.id.colorB) {
|
||||||
|
btn.setBackgroundColor(Color.BLUE);
|
||||||
|
} else if (item.getItemId()==R.id.mItemSmall) {
|
||||||
|
btnParams.height = 200;
|
||||||
|
btnParams.width = 200;
|
||||||
|
btn.setLayoutParams(btnParams);
|
||||||
|
|
||||||
|
} else if (item.getItemId()==R.id.mItemMedium) {
|
||||||
|
btnParams.height = 400;
|
||||||
|
btnParams.width = 400;
|
||||||
|
btn.setLayoutParams(btnParams);
|
||||||
|
|
||||||
|
} else if (item.getItemId()==R.id.mItemLarge) {
|
||||||
|
btnParams.height = 600;
|
||||||
|
btnParams.width = 600;
|
||||||
|
btn.setLayoutParams(btnParams);
|
||||||
|
|
||||||
|
} else if (item.getItemId()==R.id.mItemDisable) {
|
||||||
|
if(btn.isEnabled()){
|
||||||
|
btn.setEnabled(false);
|
||||||
|
} else {
|
||||||
|
btn.setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (item.getItemId()==R.id.mItemChangePos) {
|
||||||
|
btn.setX(rand.nextInt(200));
|
||||||
|
btn.setX(rand.nextInt(200));
|
||||||
|
} else if (item.getItemId()==R.id.mItemRandomT) {
|
||||||
|
btn.setText(randomText());
|
||||||
|
} else if (item.getItemId()==R.id.mItemReset) {
|
||||||
|
btn.setLayoutParams(keepParam);
|
||||||
|
btn.setX(keepX);
|
||||||
|
btn.setY(keepY);
|
||||||
|
btn.setBackgroundColor(Color.rgb(204,189,250));
|
||||||
|
btn.setEnabled(true);
|
||||||
|
btn.setText(text);
|
||||||
|
} else if (item.getItemId()==R.id.mItemExit) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String randomText(){
|
||||||
|
String[] words = {"Bruh","Hello", "Hey", "Howdy", "Hi","Wammy","???","777"};
|
||||||
|
return words[rand.nextInt(8)];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -135,7 +135,7 @@
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button4"
|
android:id="@+id/btnMenu"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
|
|
|
||||||
34
app/src/main/res/layout/activity_menu_exercise.xml
Normal file
34
app/src/main/res/layout/activity_menu_exercise.xml
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/main"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".MenuExercise">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
android:background="?attr/colorPrimary"
|
||||||
|
android:elevation="4dp"
|
||||||
|
android:theme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar"
|
||||||
|
app:popupTheme="@style/ThemeOverlay.AppCompat.DayNight"
|
||||||
|
tools:ignore="MissingConstraints" />
|
||||||
|
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/mainButton"
|
||||||
|
android:layout_width="179dp"
|
||||||
|
android:layout_height="145dp"
|
||||||
|
android:layout_marginStart="116dp"
|
||||||
|
android:layout_marginTop="293dp"
|
||||||
|
android:layout_marginEnd="116dp"
|
||||||
|
android:layout_marginBottom="293dp"
|
||||||
|
android:text="Click Me!"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
62
app/src/main/res/menu/menu_menuexercise.xml
Normal file
62
app/src/main/res/menu/menu_menuexercise.xml
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:id="@+id/mItemChange"
|
||||||
|
android:title="Attribute Change">
|
||||||
|
<menu>
|
||||||
|
<item android:title="Change Color">
|
||||||
|
<menu>
|
||||||
|
<item
|
||||||
|
android:id="@+id/colorR"
|
||||||
|
android:title="R" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/colorG"
|
||||||
|
android:title="G" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/colorB"
|
||||||
|
android:title="B" />
|
||||||
|
</menu>
|
||||||
|
</item>
|
||||||
|
<item android:title="Change Size">
|
||||||
|
<menu>
|
||||||
|
<item
|
||||||
|
android:id="@+id/mItemSmall"
|
||||||
|
android:title="Small" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/mItemMedium"
|
||||||
|
android:title="Medium" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/mItemLarge"
|
||||||
|
android:title="Large" />
|
||||||
|
</menu>
|
||||||
|
</item>
|
||||||
|
<item android:title="Change State">
|
||||||
|
<menu>
|
||||||
|
<item
|
||||||
|
android:id="@+id/mItemDisable"
|
||||||
|
android:title="Disable" />
|
||||||
|
</menu>
|
||||||
|
</item>
|
||||||
|
<item android:title="Change Position" >
|
||||||
|
<menu >
|
||||||
|
<item
|
||||||
|
android:id="@+id/mItemChangePos"
|
||||||
|
android:title="Change Position" />
|
||||||
|
</menu>
|
||||||
|
</item>
|
||||||
|
<item android:title="Change Text" >
|
||||||
|
<menu >
|
||||||
|
<item
|
||||||
|
android:id="@+id/mItemRandomT"
|
||||||
|
android:title="Change Randomly" />
|
||||||
|
</menu>
|
||||||
|
</item>
|
||||||
|
</menu>
|
||||||
|
</item>
|
||||||
|
<item
|
||||||
|
android:id="@+id/mItemReset"
|
||||||
|
android:title="Reset" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/mItemExit"
|
||||||
|
android:title="Exit" />
|
||||||
|
</menu>
|
||||||
Loading…
Reference in New Issue
Block a user