Image in the app: https://assets/images.nasa.gov
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".DisasterDetails" | |
android:orientation="vertical" | |
android:layout_marginTop="20dp"> | |
<ImageView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:id="@+id/disImg" | |
android:src="@drawable/ic_launcher_background" | |
android:layout_gravity="center_horizontal"/> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginRight="20dp" | |
android:layout_marginLeft="20dp" | |
android:layout_marginTop="10dp" | |
android:id="@+id/title" | |
android:textAllCaps="true" | |
android:layout_gravity="center_horizontal" | |
android:text="title" | |
android:textSize="20sp" | |
android:textStyle="bold"/> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Discretion" | |
android:layout_marginRight="20dp" | |
android:layout_marginLeft="20dp" | |
android:layout_marginTop="10dp" | |
android:id="@+id/dis" | |
android:layout_gravity="center_horizontal" | |
android:textSize="18sp" | |
android:layout_marginBottom="20dp"/> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal"> | |
<LinearLayout | |
android:layout_width="200dp" | |
android:layout_height="100dp" | |
android:id="@+id/linearbefore" | |
android:orientation="vertical" | |
style="@style/textViewStyle" | |
android:layout_weight="1"> | |
<ImageView | |
android:layout_width="30dp" | |
android:layout_height="30dp" | |
android:src="@drawable/before" | |
android:layout_marginRight="16dp" | |
android:layout_marginBottom="16dp"/> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="Before Disaster" | |
android:id="@+id/before" | |
android:textAllCaps="true"/> | |
</LinearLayout> | |
<LinearLayout | |
android:layout_width="200dp" | |
android:layout_height="100dp" | |
android:id="@+id/linearduring" | |
android:orientation="vertical" | |
style="@style/textViewStyle" | |
android:layout_weight="1"> | |
<ImageView | |
android:layout_width="30dp" | |
android:layout_height="30dp" | |
android:src="@drawable/during" | |
android:layout_marginRight="16dp" | |
android:layout_marginBottom="16dp"/> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="During Disaster" | |
android:id="@+id/during" | |
android:textAllCaps="true"/> | |
</LinearLayout> | |
</LinearLayout> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal"> | |
<LinearLayout | |
android:layout_width="200dp" | |
android:layout_height="100dp" | |
android:id="@+id/linearafter" | |
android:orientation="vertical" | |
style="@style/textViewStyle" | |
android:layout_weight="1"> | |
<ImageView | |
android:layout_width="30dp" | |
android:layout_height="30dp" | |
android:src="@drawable/after" | |
android:layout_marginRight="16dp" | |
android:layout_marginBottom="16dp"/> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="After Disaster" | |
android:textAllCaps="true" /> | |
</LinearLayout> | |
<LinearLayout | |
android:layout_width="200dp" | |
android:layout_height="100dp" | |
android:orientation="vertical" | |
style="@style/textViewStyle" | |
android:layout_weight="1" | |
android:id="@+id/lineareme"> | |
<ImageView | |
android:layout_width="30dp" | |
android:layout_height="30dp" | |
android:src="@drawable/siren" | |
android:layout_marginRight="16dp" | |
android:layout_marginBottom="16dp"/> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="Emergency calls" | |
android:id="@+id/after" | |
android:textAllCaps="true" /> | |
</LinearLayout> | |
</LinearLayout> | |
</LinearLayout> |
packagecom.example.hanaalalawi.nasachallenge; | |
importandroid.content.Intent; | |
importandroid.support.annotation.NonNull; | |
importandroid.support.annotation.Nullable; | |
importandroid.support.v4.app.Fragment; | |
importandroid.support.v7.app.AppCompatActivity; | |
importandroid.os.Bundle; | |
importandroid.util.Log; | |
importandroid.view.LayoutInflater; | |
importandroid.view.View; | |
importandroid.view.ViewGroup; | |
importandroid.widget.Button; | |
importandroid.widget.EditText; | |
importandroid.widget.ImageView; | |
importandroid.widget.TextView; | |
publicclassBeforeFragmentextendsFragment { | |
TextView plan1, plan2, plan3, plan4, plan5, plan6, plan7, plan8User, titleB; | |
ImageView plan1check, plan2check, plan3check, plan4check, plan5check, plan6check, plan7check; | |
EditText userPlan; | |
Bundle bundle; | |
String disTitle; | |
Button save; | |
@Nullable | |
@Override | |
publicViewonCreateView(@NonNullLayoutInflaterinflater, @NullableViewGroupcontainer, @NullableBundlesavedInstanceState) { | |
LayoutInflater lf = getActivity().getLayoutInflater(); | |
View v = lf.inflate(R.layout.activity_before_fragment, container, false); | |
bundle = getActivity().getIntent().getExtras(); | |
disTitle = bundle.getString("dis_name"); | |
plan1 = (TextView) v.findViewById(R.id.step1); | |
plan2 = (TextView) v.findViewById(R.id.step2); | |
plan3 = (TextView) v.findViewById(R.id.step3); | |
plan4 = (TextView) v.findViewById(R.id.step4); | |
plan5 = (TextView) v.findViewById(R.id.step5); | |
plan6 = (TextView) v.findViewById(R.id.step6); | |
plan7 = (TextView) v.findViewById(R.id.step7); | |
titleB = (TextView) v.findViewById(R.id.title); | |
plan8User = (TextView) v.findViewById(R.id.userPlanResult); | |
userPlan = (EditText) v.findViewById(R.id.userPlan); | |
save = (Button) v.findViewById(R.id.save); | |
plan1check = (ImageView) v.findViewById(R.id.circle1); | |
plan2check = (ImageView) v.findViewById(R.id.circle2); | |
plan3check = (ImageView) v.findViewById(R.id.circle3); | |
plan4check = (ImageView) v.findViewById(R.id.circle4); | |
plan5check = (ImageView) v.findViewById(R.id.circle5); | |
plan6check = (ImageView) v.findViewById(R.id.circle6); | |
plan7check = (ImageView) v.findViewById(R.id.circle7); | |
plan8User.setVisibility(View.GONE); | |
titleB.setText(disTitle); | |
if (disTitle.equals("Earthquakes")) { | |
plan1.setText(R.string.beforeep1); | |
plan2.setText(R.string.beforeep2); | |
plan3.setText(R.string.beforeep3); | |
plan4.setText(R.string.beforeep4); | |
plan5.setText(R.string.beforeep5); | |
plan6.setText(R.string.beforeep6); | |
plan7.setText(R.string.beforeep7); | |
plan1check.setOnClickListener(newView.OnClickListener() { | |
@Override | |
publicvoidonClick(Viewv) { | |
plan1check.setImageResource(R.drawable.circle); | |
} | |
}); | |
plan2check.setOnClickListener(newView.OnClickListener() { | |
@Override | |
publicvoidonClick(Viewv) { | |
plan2check.setImageResource(R.drawable.circle); | |
} | |
}); | |
plan3check.setOnClickListener(newView.OnClickListener() { | |
@Override | |
publicvoidonClick(Viewv) { | |
plan3check.setImageResource(R.drawable.circle); | |
} | |
}); | |
plan4check.setOnClickListener(newView.OnClickListener() { | |
@Override | |
publicvoidonClick(Viewv) { | |
plan4check.setImageResource(R.drawable.circle); | |
} | |
}); | |
plan5check.setOnClickListener(newView.OnClickListener() { | |
@Override | |
publicvoidonClick(Viewv) { | |
plan5check.setImageResource(R.drawable.circle); | |
} | |
}); | |
plan6check.setOnClickListener(newView.OnClickListener() { | |
@Override | |
publicvoidonClick(Viewv) { | |
plan6check.setImageResource(R.drawable.circle); | |
} | |
}); | |
plan7check.setOnClickListener(newView.OnClickListener() { | |
@Override | |
publicvoidonClick(Viewv) { | |
plan7check.setImageResource(R.drawable.circle); | |
} | |
}); | |
save.setOnClickListener(newView.OnClickListener() { | |
@Override | |
publicvoidonClick(Viewv) { | |
String userplanstr = userPlan.getText().toString(); | |
plan8User.setText(userplanstr); | |
plan8User.setVisibility(View.VISIBLE); | |
} | |
}); | |
} | |
return v; | |
} | |
} | |
packagecom.example.hanaalalawi.nasachallenge; | |
importandroid.Manifest; | |
importandroid.annotation.SuppressLint; | |
importandroid.content.Intent; | |
importandroid.content.pm.PackageManager; | |
importandroid.net.Uri; | |
importandroid.support.v4.app.ActivityCompat; | |
importandroid.support.v7.app.AppCompatActivity; | |
importandroid.os.Bundle; | |
importandroid.util.Log; | |
importandroid.view.View; | |
importandroid.widget.ImageView; | |
importandroid.widget.LinearLayout; | |
importandroid.widget.TextView; | |
publicclassDisasterDetailsextendsAppCompatActivity { | |
TextView disDescription, beforeDis, afterDis, duringDis, title; | |
ImageView disImage; | |
Bundle bundle; | |
LinearLayout linearbefore, linearAfter, linearDuring, linearEme; | |
String discerption, disTitle; | |
String img; | |
@SuppressLint("SetTextI18n") | |
@Override | |
protectedvoidonCreate(BundlesavedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_disaster_details); | |
disDescription = (TextView) findViewById(R.id.dis); | |
beforeDis = (TextView) findViewById(R.id.before); | |
afterDis = (TextView) findViewById(R.id.after); | |
duringDis = (TextView) findViewById(R.id.during); | |
disImage = (ImageView) findViewById(R.id.disImg); | |
title = (TextView) findViewById(R.id.title); | |
linearbefore = (LinearLayout) findViewById(R.id.linearbefore); | |
linearAfter = (LinearLayout) findViewById(R.id.linearafter); | |
linearDuring = (LinearLayout) findViewById(R.id.linearduring); | |
linearEme = (LinearLayout) findViewById(R.id.lineareme); | |
bundle = getIntent().getExtras(); | |
disTitle = bundle.getString("dis_name"); | |
img = bundle.getString("dis_img"); | |
title.setText(disTitle); | |
disImage.setImageResource(Integer.parseInt(img)); | |
beforeDis.setText("Before "+ disTitle); | |
duringDis.setText("During "+ disTitle); | |
afterDis.setText("After "+ disTitle); | |
if (disTitle.equals("Earthquakes")) { | |
disDescription.setText(R.string.earthquake); | |
linearbefore.setOnClickListener(newView.OnClickListener() { | |
@Override | |
publicvoidonClick(Viewv) { | |
String name = disTitle; | |
Intent before =newIntent(DisasterDetails.this, PrepreationActivity.class); | |
Bundle bundle =newBundle(); | |
bundle.putString("dis_name", name); | |
before.putExtras(bundle); | |
before.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);//clear all activities before the signin | |
startActivity(before); | |
} | |
}); | |
linearEme.setOnClickListener(newView.OnClickListener() { | |
@Override | |
publicvoidonClick(Viewv) { | |
String name = disTitle; | |
Intent intent =newIntent(Intent.ACTION_CALL, Uri.parse("tel:"+"911")); | |
if (ActivityCompat.checkSelfPermission(DisasterDetails.this, Manifest.permission.CALL_PHONE) !=PackageManager.PERMISSION_GRANTED) { | |
return; | |
} | |
startActivity(intent); | |
} | |
}); | |
linearAfter.setOnClickListener(newView.OnClickListener() { | |
@Override | |
publicvoidonClick(Viewv) { | |
String name = disTitle; | |
Intent before =newIntent(DisasterDetails.this,PrepreationActivity.class); | |
Bundle bundle =newBundle(); | |
bundle.putString("dis_name", name); | |
before.putExtras(bundle); | |
before.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);//clear all activities before the signin | |
startActivity(before); | |
} | |
}); | |
linearDuring.setOnClickListener(newView.OnClickListener() { | |
@Override | |
publicvoidonClick(Viewv) { | |
String name = disTitle; | |
Intent before =newIntent(DisasterDetails.this,PrepreationActivity.class); | |
Bundle bundle =newBundle(); | |
bundle.putString("dis_name", name); | |
before.putExtras(bundle); | |
before.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);//clear all activities before the signin | |
startActivity(before); | |
} | |
}); | |
}elseif(disTitle.equals("Fires")){ | |
disDescription.setText(R.string.fire); | |
}elseif(disTitle.equals("Floods")){ | |
disDescription.setText(R.string.flood); | |
}elseif(disTitle.equals("Hurricane")){ | |
disDescription.setText(R.string.Hurricane); | |
}elseif(disTitle.equals("Volcano")){ | |
disDescription.setText(R.string.Volcano); | |
} | |
} | |
} |
packagecom.example.hanaalalawi.nasachallenge; | |
importandroid.content.Context; | |
importandroid.content.res.Resources; | |
importandroid.graphics.Rect; | |
importandroid.support.v7.app.AppCompatActivity; | |
importandroid.os.Bundle; | |
importandroid.support.v7.widget.DefaultItemAnimator; | |
importandroid.support.v7.widget.GridLayoutManager; | |
importandroid.support.v7.widget.LinearLayoutManager; | |
importandroid.support.v7.widget.RecyclerView; | |
importandroid.util.TypedValue; | |
importandroid.view.View; | |
importandroid.widget.ImageView; | |
importjava.util.ArrayList; | |
importjava.util.List; | |
publicclassMainActivityextendsAppCompatActivity { | |
privateRecyclerView recyclerView; | |
privateDisasterAdapter adapter; | |
privateList<Disaster> disList; | |
@Override | |
protectedvoidonCreate(BundlesavedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
recyclerView = (RecyclerView) findViewById(R.id.recycler_view); | |
disList =newArrayList<>(); | |
adapter =newDisasterAdapter(this, disList); | |
RecyclerView.LayoutManager mLayoutManager =newGridLayoutManager(this, 1); | |
recyclerView.setLayoutManager(mLayoutManager); | |
recyclerView.addItemDecoration(newGridSpacingItemDecoration(2, dpToPx(10), true)); | |
recyclerView.setItemAnimator(newDefaultItemAnimator()); | |
recyclerView.setAdapter(adapter); | |
disastersList(); | |
} | |
privatevoiddisastersList() { | |
int[] Disasters=newint[]{ | |
R.drawable.earthquake, | |
R.drawable.fires, | |
R.drawable.flood, | |
R.drawable.horicano, | |
R.drawable.volcano}; | |
Disaster disaster =newDisaster("Earthquakes", Disasters[0]); | |
disList.add(disaster); | |
disaster =newDisaster("Fires", Disasters[1]); | |
disList.add(disaster); | |
disaster =newDisaster("Floods", Disasters[2]); | |
disList.add(disaster); | |
disaster =newDisaster("Hurricane", Disasters[3]); | |
disList.add(disaster); | |
disaster =newDisaster("Volcano", Disasters[4]); | |
disList.add(disaster); | |
adapter.notifyDataSetChanged(); | |
} | |
publicclassGridSpacingItemDecorationextendsRecyclerView.ItemDecoration { | |
privateint spanCount; | |
privateint spacing; | |
privateboolean includeEdge; | |
publicGridSpacingItemDecoration(intspanCount, intspacing, booleanincludeEdge) { | |
this.spanCount = spanCount; | |
this.spacing = spacing; | |
this.includeEdge = includeEdge; | |
} | |
@Override | |
publicvoidgetItemOffsets(RectoutRect, Viewview, RecyclerViewparent, RecyclerView.Statestate) { | |
int position = parent.getChildAdapterPosition(view); | |
int column = position % spanCount; | |
if (includeEdge) { | |
outRect.left = spacing - column * spacing / spanCount; | |
outRect.right = (column +1) * spacing / spanCount; | |
if (position < spanCount) { | |
outRect.top = spacing; | |
} | |
outRect.bottom = spacing; | |
} else { | |
outRect.left = column * spacing / spanCount; | |
outRect.right = spacing - (column +1) * spacing / spanCount; | |
if (position >= spanCount) { | |
outRect.top = spacing; | |
} | |
} | |
} | |
} | |
privateintdpToPx(intdp) { | |
Resources r = getResources(); | |
returnMath.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics())); | |
} | |
} | |
packagecom.example.hanaalalawi.nasachallenge; | |
importandroid.support.annotation.NonNull; | |
importandroid.support.design.widget.BottomNavigationView; | |
importandroid.support.v4.app.Fragment; | |
importandroid.support.v7.app.AppCompatActivity; | |
importandroid.os.Bundle; | |
importandroid.view.MenuItem; | |
publicclassPrepreationActivityextendsAppCompatActivity { | |
@Override | |
protectedvoidonCreate(BundlesavedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_prepreation); | |
BottomNavigationView bottomNavigationView = findViewById(R.id.bottobNavigation); | |
bottomNavigationView.setOnNavigationItemSelectedListener(navList); | |
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_place,newBeforeFragment()).commit(); | |
} | |
privateBottomNavigationView.OnNavigationItemSelectedListener navList = | |
newBottomNavigationView.OnNavigationItemSelectedListener() { | |
@Override | |
publicbooleanonNavigationItemSelected(@NonNullMenuItemitem) { | |
Fragment selectedFragment =null; | |
switch (item.getItemId()){ | |
caseR.id.nav_before: | |
selectedFragment =newBeforeFragment(); | |
break; | |
caseR.id.nav_during: | |
selectedFragment =newDuringFragment(); | |
break; | |
caseR.id.nav_after: | |
selectedFragment =newAfterFragment(); | |
break; | |
} | |
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_place,selectedFragment).commit(); | |
returntrue; | |
} | |
}; | |
} |
SpaceApps is a NASA incubator innovation program.