Last active
May 28, 2018 10:48
-
-
Save abusoid/a7206f1532a73e40fc649a96439efda2 to your computer and use it in GitHub Desktop.
Энциклопедия аквариумиста приложение на Андроид
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout 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" | |
android:orientation="vertical" | |
tools:context=".MainActivity"> | |
<TextView | |
android:id="@+id/freshwater" | |
style="@style/CategoryStyle" | |
android:background="@color/category_freshwater" | |
android:text="@string/freshwater_category" | |
android:onClick="freshwaterClick"/> | |
<TextView | |
android:id="@+id/saltwater" | |
style="@style/CategoryStyle" | |
android:background="@color/category_saltwater" | |
android:text="@string/saltwater_category" | |
android:onClick="saltwaterClick"/> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<TextView | |
android:id="@+id/calc_category" | |
style="@style/CategoryStyle" | |
android:layout_gravity="bottom" | |
android:layout_alignParentBottom="true" | |
android:background="@color/category_calc" | |
android:onClick="calcClick" | |
android:text="@string/calc_category" /> | |
</LinearLayout> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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:orientation="vertical"> | |
<TextView | |
android:id="@+id/description_title" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:text="TITLE" /> | |
<ImageView | |
android:id="@+id/description_image" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:src="@mipmap/ic_launcher_round"/> | |
<TextView | |
android:id="@+id/description_text" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:text="Давай протестируем, что у нас получается. ХМММ МММММММ МММММММММММ, а что будет если добавить побольше текста"/> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mogilevskiydenis.aquariumvici; | |
public class Item { | |
//Название рыбы | |
private String mName; | |
//id картинки к рыбе | |
private int mImageResourceId = NO_IMAGE_PROVIDED; | |
//константа на случай если нет изображения к рыбке | |
private static final int NO_IMAGE_PROVIDED = -1; | |
private String mDescriptionText; | |
public Item(String Name, int imageResourceId, String descriptionText){ | |
mName = Name; | |
mImageResourceId = imageResourceId; | |
mDescriptionText = descriptionText; | |
} | |
public String getName() { return mName; } | |
public int getImageResourceId(){ return mImageResourceId; } | |
public boolean hasImage() { | |
return mImageResourceId != NO_IMAGE_PROVIDED; | |
} | |
public String getDescriptionText () { | |
return mDescriptionText; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mogilevskiydenis.aquariumvici; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.support.v4.content.ContextCompat; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ArrayAdapter; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import java.util.ArrayList; | |
public class ItemAdapter extends ArrayAdapter<Item> { | |
//Id фона текста | |
private int mColorResourceId; | |
public ItemAdapter(Context context, ArrayList<Item> items, int colorResourceId) { | |
super(context, 0, items); | |
mColorResourceId = colorResourceId; | |
} | |
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
// Check if an existing view is being reused, otherwise inflate the view | |
View listItemView = convertView; | |
if (listItemView == null) { | |
listItemView = LayoutInflater.from(getContext()).inflate( | |
R.layout.list_item, parent, false); | |
} | |
// Get the {@link Word} object located at this position in the list | |
Item currentItem = getItem(position); | |
// Find the TextView in the list_item.xml layout with the ID name_text_view. | |
TextView miwokTextView = (TextView) listItemView.findViewById(R.id.name_text_view); | |
miwokTextView.setText(currentItem.getName()); | |
// Find the ImageView in the list_item.xml layout with the ID image. | |
ImageView imageView = (ImageView) listItemView.findViewById(R.id.image); | |
// Check if an image is provided for this word or not | |
if (currentItem.hasImage()) { | |
// If an image is available, display the provided image based on the resource ID | |
imageView.setImageResource(currentItem.getImageResourceId()); | |
// Make sure the view is visible | |
imageView.setVisibility(View.VISIBLE); | |
} else { | |
// Otherwise hide the ImageView (set visibility to GONE) | |
imageView.setVisibility(View.GONE); | |
} | |
// Set the theme color for the list item | |
View textContainer = listItemView.findViewById(R.id.text_container); | |
// Find the color that the resource ID maps to | |
int color = ContextCompat.getColor(getContext(), mColorResourceId); | |
// Set the background color of the text container View | |
textContainer.setBackgroundColor(color); | |
// Return the whole list item layout (containing 2 TextViews) so that it can be shown in | |
// the ListView. | |
return listItemView; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:background="@color/tan_background" | |
android:minHeight="@dimen/list_item_height" | |
android:orientation="horizontal"> | |
<ImageView | |
android:id="@+id/image" | |
android:layout_width="@dimen/list_item_height" | |
android:layout_height="@dimen/list_item_height" /> | |
<LinearLayout | |
android:id="@+id/text_container" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
android:paddingLeft="16dp" | |
android:layout_alignParentRight="true" | |
android:layout_alignParentTop="true" | |
android:layout_alignParentBottom="true" | |
android:layout_toRightOf="@+id/image"> | |
<TextView | |
android:id="@+id/name_text_view" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:gravity="center" | |
android:textAppearance="?android:textAppearanceMedium" | |
android:textColor="@android:color/white" | |
android:textStyle="bold" /> | |
</LinearLayout> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mogilevskiydenis.aquariumvici; | |
import android.content.Intent; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
public void freshwaterClick(View view){ | |
Intent freshwaterIntent = new Intent(MainActivity.this, SecondMenu.class); | |
// Start the new activity | |
startActivity(freshwaterIntent); | |
} | |
public void saltwaterClick(View view){ | |
Intent freshwaterIntent = new Intent(MainActivity.this, SaltwaterSecondMenu.class); | |
// Start the new activity | |
startActivity(freshwaterIntent); | |
} | |
public void calcClick(View view){ | |
Intent freshwaterIntent = new Intent(MainActivity.this, calcMenu.class); | |
// Start the new activity | |
startActivity(freshwaterIntent); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mogilevskiydenis.aquariumvici; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.EditText; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
public class Volume extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.volume); | |
} | |
public void calculate(View view) { | |
EditText length = (EditText) findViewById(R.id.length); | |
EditText width = (EditText) findViewById(R.id.width); | |
EditText height = (EditText) findViewById(R.id.height); | |
double a = 0, b = 0, c = 0; | |
if (length.getText().toString().equals("")) { | |
Toast.makeText(this, "Введите длину", Toast.LENGTH_SHORT).show(); | |
} | |
else | |
{ | |
a = Double.parseDouble(length.getText().toString()); | |
} | |
if (width.getText().toString().equals("")) { | |
Toast.makeText(this, "Введите ширину", Toast.LENGTH_SHORT).show(); | |
} | |
else | |
{ | |
b = Double.parseDouble(width.getText().toString()); | |
} | |
if (height.getText().toString().equals("")) { | |
Toast.makeText(this, "Введите высоту", Toast.LENGTH_SHORT).show(); | |
} | |
else { | |
c = Double.parseDouble(height.getText().toString()); | |
} | |
double volume = (a*b*c)/1000; | |
TextView answer = (TextView) findViewById(R.id.answer); | |
answer.setText(Double.toString(volume) + "л."); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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:orientation="vertical"> | |
<TextView | |
android:layout_marginTop="30dp" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:text="Длина в см" | |
android:textSize="25sp"/> | |
<EditText | |
android:id="@+id/length" | |
android:layout_height="50dp" | |
android:layout_width="match_parent" | |
android:layout_gravity="center" | |
android:hint="Введите здесь длину" | |
android:gravity="center" | |
android:maxLines="1" | |
android:maxLength="20" | |
android:inputType="numberDecimal"/> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Ширина в см" | |
android:layout_gravity="center" | |
android:textSize="25sp" | |
/> | |
<EditText | |
android:id="@+id/width" | |
android:layout_height="50dp" | |
android:layout_width="match_parent" | |
android:layout_gravity="center" | |
android:gravity="center" | |
android:hint="Введите здесь ширину" | |
android:maxLines="1" | |
android:maxLength="20" | |
android:inputType="numberDecimal"/> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Высота в см" | |
android:layout_gravity="center" | |
android:textSize="25sp" /> | |
<EditText | |
android:id="@+id/height" | |
android:layout_height="50dp" | |
android:layout_width="match_parent" | |
android:layout_gravity="center" | |
android:gravity="center" | |
android:hint="Введите здесь высоту" | |
android:maxLines="1" | |
android:maxLength="20" | |
android:inputType="numberDecimal" | |
/> | |
<Button | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:text="Рассчитать" | |
android:onClick="calculate"/> | |
<TextView | |
android:id="@+id/answer" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="32dp" | |
android:textSize="60sp" | |
android:textAllCaps="true" | |
android:textStyle="bold" | |
android:layout_gravity="center" | |
/> | |
</LinearLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment