Slavchikk il y a 1 an
Parent
commit
b988c1f199

+ 11 - 2
app/src/main/AndroidManifest.xml

@@ -1,8 +1,10 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools">
-    <uses-permission android:name="android.permission.INTERNET"/>
-    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
+
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+
     <application
         android:allowBackup="true"
         android:dataExtractionRules="@xml/data_extraction_rules"
@@ -13,6 +15,13 @@
         android:supportsRtl="true"
         android:theme="@style/Theme.RecipeProj"
         tools:targetApi="31">
+        <activity
+            android:name=".ViewRecipe"
+            android:exported="false">
+            <meta-data
+                android:name="android.app.lib_name"
+                android:value="" />
+        </activity>
         <activity
             android:name=".Recipe"
             android:exported="false">

+ 142 - 0
app/src/main/java/com/example/recipeproj/ViewRecipe.java

@@ -0,0 +1,142 @@
+package com.example.recipeproj;
+
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.drawable.ColorDrawable;
+import android.net.Uri;
+import android.os.Bundle;
+import android.provider.MediaStore;
+import android.util.Log;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.TextView;
+import android.widget.Toast;
+import android.view.LayoutInflater;
+import androidx.activity.result.ActivityResultLauncher;
+import androidx.activity.result.contract.ActivityResultContracts;
+import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.app.AlertDialog;
+import androidx.appcompat.app.AppCompatActivity;
+
+import java.io.InputStream;
+
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+import retrofit2.Retrofit;
+import retrofit2.converter.gson.GsonConverterFactory;
+
+
+public class ViewRecipe extends AppCompatActivity {
+    Bundle arg;
+    Recipe recipe;
+    EditText fullN, nameN;
+    TextView fullText;
+    final Context context = this;
+    String itog;
+    int ves;
+    private TextView final_text;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_view_recipe);
+        fullText = findViewById(R.id.txtLog);
+        arg = getIntent().getExtras();
+        recipe = arg.getParcelable(Recipe.class.getSimpleName());
+        fullN = findViewById(R.id.txtFull);
+        nameN = findViewById(R.id.txtName);
+        final_text = (TextView) findViewById(R.id.txtWes);
+        fullN.setText(recipe.getFullRecipe());
+        nameN.setText(recipe.getNameRecipe());
+        fullText.setText("fffffffffffffffffffffffffffffffffffffffffffffffff" +
+                "ffffffffffffffffffffffffffffffffffffffffffffffffffffff" +
+                "ffffffffffffffffffffffffffffffffffffffffffffff" +
+                "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" +
+                "ffffffffffffffffffffffffffffffffffffffffffffffffffff" +
+                "fffffffffffffffffffffffffffffffffffffffffffffff" +
+                "fffffffffffffffffffffffffffffffffffffffffff" +
+                "ffffffffffffffffffffffffffffffffffffffffff" +
+                "fffffffffffffffffffffffffffffffffffffffffff" +
+                "ffffffffffffffffffffffffffffffffffffffffff" +
+                "fffffffffffffffffffffffffffffffffffffffffffff" +
+                "ffffffffffffffffffffffffffffffffffffffffffff");
+    }
+    public void calcWeight(View v)
+    {
+
+
+        LayoutInflater li = LayoutInflater.from(context);
+        View promptsView = li.inflate(R.layout.prompt, null);
+
+        //Создаем AlertDialog
+        AlertDialog.Builder mDialogBuilder = new AlertDialog.Builder(context);
+
+        //Настраиваем prompt.xml для нашего AlertDialog:
+        mDialogBuilder.setView(promptsView);
+
+        //Настраиваем отображение поля для ввода текста в открытом диалоге:
+        final EditText userInput = (EditText) promptsView.findViewById(R.id.input_text);
+
+        //Настраиваем сообщение в диалоговом окне:
+        mDialogBuilder
+                .setCancelable(false)
+                .setPositiveButton("OK",
+                        new DialogInterface.OnClickListener() {
+                            public void onClick(DialogInterface dialog,int id) {
+
+                                //Вводим текст и отображаем в строке ввода на основном экране:
+
+                                //final_text.setText(userInput.getText());
+                                itog =  userInput.getText().toString();
+                                ves = Integer.parseInt(itog);
+                                switch(recipe.getNameRecipe())
+                                {
+                                    case "тест":
+                                        ves = ves*10;
+                                        break;
+                                    case "рецепт":
+                                        ves = ves /10;
+                                        break;
+                                }
+                                final_text.setText("Кол-во еды в граммах: " + ves);
+                            }
+                        })
+                .setNegativeButton("Отмена",
+                        new DialogInterface.OnClickListener() {
+                            public void onClick(DialogInterface dialog,int id) {
+                                dialog.cancel();
+                            }
+                        });
+
+        //Создаем AlertDialog:
+        AlertDialog alertDialog = mDialogBuilder.create();
+
+        //и отображаем его:
+        alertDialog.show();
+
+
+
+
+      /*  AlertDialog.Builder builder = new AlertDialog.Builder(this);
+        builder
+                .setTitle("Рассчитать вес")
+                .setMessage("Введите вес")
+                .setIcon(android.R.drawable.ic_dialog_alert)
+                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+                    @Override
+                    public void onClick(DialogInterface dialogInterface, int i) {
+                        final_text.setText(userInput.getText());
+                        dialogInterface.dismiss();
+                    }
+                });
+        AlertDialog alert = builder.create();
+        alert.show();*/
+    }
+
+
+}

+ 86 - 0
app/src/main/res/layout/activity_view_recipe.xml

@@ -0,0 +1,86 @@
+<?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:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".ViewRecipe">
+
+    <ScrollView
+        android:id="@+id/scrollView2"
+        android:layout_width="0dp"
+        android:layout_height="0dp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+
+        app:layout_constraintHorizontal_bias="0.0"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/btnBack"
+        app:layout_constraintVertical_bias="0.0">
+
+        <TextView
+            android:id="@+id/txtLog"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+
+            android:text="Register"
+
+            android:textColor="#F4DC04"
+            android:textSize="40sp"
+            android:textStyle="bold"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" />
+
+    </ScrollView>
+
+    <EditText
+        android:id="@+id/txtName"
+        android:layout_width="124dp"
+        android:layout_height="46dp"
+
+        android:layout_marginTop="232dp"
+        app:layout_constraintBottom_toTopOf="@+id/btnBack"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintHorizontal_bias="0.853"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintVertical_bias="0.0" />
+
+    <TextView
+        android:id="@+id/txtWes"
+        android:layout_width="124dp"
+        android:layout_height="46dp"
+
+
+        android:layout_marginTop="300dp"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintHorizontal_bias="0.498"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <EditText
+        android:id="@+id/txtFull"
+        android:layout_width="122dp"
+        android:layout_height="49dp"
+
+        android:layout_marginTop="228dp"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintHorizontal_bias="0.166"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <androidx.appcompat.widget.AppCompatButton
+        android:id="@+id/btnBack"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+
+        android:layout_marginTop="88dp"
+        android:onClick="calcWeight"
+        android:text="Рассчитать вес"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintHorizontal_bias="0.498"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/txtFull"
+        tools:ignore="MissingConstraints" />
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 24 - 0
app/src/main/res/layout/prompt.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/layout_root"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:orientation="vertical"
+    android:padding="10dp" >
+
+    <TextView
+        android:id="@+id/tv"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="Напишите текст: "
+        android:textAppearance="?android:attr/textAppearanceLarge" />
+
+    <EditText
+        android:id="@+id/input_text"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content" >
+        <requestFocus />
+    </EditText>
+
+</LinearLayout>