diff --git a/exercises/5_OOP-and-Intents/oop/src/Instrument.java b/exercises/5_OOP-and-Intents/oop/src/Instrument.java deleted file mode 100644 index e3f342e9..00000000 --- a/exercises/5_OOP-and-Intents/oop/src/Instrument.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Created by amyquispe on 4/30/15. - */ -public interface Instrument { - /* expected behavior: when play() is called, return a String that represents the Instrument's noise */ - public String play(); -} diff --git a/exercises/5_OOP-and-Intents/oop/src/Musician.java b/exercises/5_OOP-and-Intents/oop/src/Musician.java deleted file mode 100644 index fe90f5ff..00000000 --- a/exercises/5_OOP-and-Intents/oop/src/Musician.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Created by amyquispe on 4/30/15. - */ -public abstract class Musician { - /* expected behavior: when play_instrument() is called, return a String that represents the instrument's noise */ - public abstract String play_instrument(); -} diff --git a/homework/WK1_Horoscope/.gitignore b/homework/WK1_Horoscope/.gitignore new file mode 100644 index 00000000..afbdab33 --- /dev/null +++ b/homework/WK1_Horoscope/.gitignore @@ -0,0 +1,6 @@ +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build diff --git a/homework/WK1_Horoscope/.idea/.name b/homework/WK1_Horoscope/.idea/.name new file mode 100644 index 00000000..c75178ac --- /dev/null +++ b/homework/WK1_Horoscope/.idea/.name @@ -0,0 +1 @@ +WK1_Horoscope \ No newline at end of file diff --git a/homework/WK1_Horoscope/.idea/compiler.xml b/homework/WK1_Horoscope/.idea/compiler.xml new file mode 100644 index 00000000..217af471 --- /dev/null +++ b/homework/WK1_Horoscope/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/homework/WK1_Horoscope/.idea/copyright/profiles_settings.xml b/homework/WK1_Horoscope/.idea/copyright/profiles_settings.xml new file mode 100644 index 00000000..e7bedf33 --- /dev/null +++ b/homework/WK1_Horoscope/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/homework/WK1_Horoscope/.idea/encodings.xml b/homework/WK1_Horoscope/.idea/encodings.xml new file mode 100644 index 00000000..e206d70d --- /dev/null +++ b/homework/WK1_Horoscope/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/homework/WK1_Horoscope/.idea/gradle.xml b/homework/WK1_Horoscope/.idea/gradle.xml new file mode 100644 index 00000000..736c7b5c --- /dev/null +++ b/homework/WK1_Horoscope/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/homework/WK1_Horoscope/.idea/inspectionProfiles/Project_Default.xml b/homework/WK1_Horoscope/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..2071d1a6 --- /dev/null +++ b/homework/WK1_Horoscope/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/homework/WK1_Horoscope/.idea/inspectionProfiles/profiles_settings.xml b/homework/WK1_Horoscope/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 00000000..3b312839 --- /dev/null +++ b/homework/WK1_Horoscope/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/homework/WK1_Horoscope/.idea/misc.xml b/homework/WK1_Horoscope/.idea/misc.xml new file mode 100644 index 00000000..59436c98 --- /dev/null +++ b/homework/WK1_Horoscope/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/homework/WK1_Horoscope/.idea/modules.xml b/homework/WK1_Horoscope/.idea/modules.xml new file mode 100644 index 00000000..eed5ea16 --- /dev/null +++ b/homework/WK1_Horoscope/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/homework/WK1_Horoscope/.idea/scopes/scope_settings.xml b/homework/WK1_Horoscope/.idea/scopes/scope_settings.xml new file mode 100644 index 00000000..922003b8 --- /dev/null +++ b/homework/WK1_Horoscope/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/homework/WK1_Horoscope/.idea/vcs.xml b/homework/WK1_Horoscope/.idea/vcs.xml new file mode 100644 index 00000000..def6a6a1 --- /dev/null +++ b/homework/WK1_Horoscope/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/homework/WK1_Horoscope/WK1_Horoscope.iml b/homework/WK1_Horoscope/WK1_Horoscope.iml new file mode 100644 index 00000000..0bb6048a --- /dev/null +++ b/homework/WK1_Horoscope/WK1_Horoscope.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + diff --git a/homework/WK1_Horoscope/app/.gitignore b/homework/WK1_Horoscope/app/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/homework/WK1_Horoscope/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/homework/WK1_Horoscope/app/app.iml b/homework/WK1_Horoscope/app/app.iml new file mode 100644 index 00000000..dd7a4ee0 --- /dev/null +++ b/homework/WK1_Horoscope/app/app.iml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/homework/WK1_Horoscope/app/build.gradle b/homework/WK1_Horoscope/app/build.gradle new file mode 100644 index 00000000..a17b1335 --- /dev/null +++ b/homework/WK1_Horoscope/app/build.gradle @@ -0,0 +1,25 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 22 + buildToolsVersion "22.0.1" + + defaultConfig { + applicationId "hoshikoo.c4q.nyc.wk1_horoscope" + minSdkVersion 15 + targetSdkVersion 22 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:appcompat-v7:22.1.1' +} diff --git a/homework/WK1_Horoscope/app/proguard-rules.pro b/homework/WK1_Horoscope/app/proguard-rules.pro new file mode 100644 index 00000000..8ade1982 --- /dev/null +++ b/homework/WK1_Horoscope/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/Hoshiko/Library/Android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/homework/WK1_Horoscope/app/src/androidTest/java/hoshikoo/c4q/nyc/wk1_horoscope/ApplicationTest.java b/homework/WK1_Horoscope/app/src/androidTest/java/hoshikoo/c4q/nyc/wk1_horoscope/ApplicationTest.java new file mode 100644 index 00000000..fce47d14 --- /dev/null +++ b/homework/WK1_Horoscope/app/src/androidTest/java/hoshikoo/c4q/nyc/wk1_horoscope/ApplicationTest.java @@ -0,0 +1,13 @@ +package hoshikoo.c4q.nyc.wk1_horoscope; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/homework/WK1_Horoscope/app/src/main/AndroidManifest.xml b/homework/WK1_Horoscope/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..2a2fae95 --- /dev/null +++ b/homework/WK1_Horoscope/app/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + diff --git a/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/ChooseSignFragment.java b/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/ChooseSignFragment.java new file mode 100644 index 00000000..e1c2267a --- /dev/null +++ b/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/ChooseSignFragment.java @@ -0,0 +1,188 @@ +package hoshikoo.c4q.nyc.wk1_horoscope; + +import android.app.Activity; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; + + +/** + * A simple {@link Fragment} subclass. + * Activities that contain this fragment must implement the + * {@link ChooseSignFragment.ChooseSignFragmentInteractionListener} interface + * to handle interaction events. + * Use the {@link ChooseSignFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class ChooseSignFragment extends Fragment { + + private ChooseSignFragmentInteractionListener mListener; + private static ChooseSignFragment fragment = null; + + public static ChooseSignFragment newInstance() { + if (fragment == null) { + fragment = new ChooseSignFragment(); + } + return fragment; + } + + public ChooseSignFragment() { + // Required empty public constructor + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.fragment_choose_sign, container, false); + + setupZodiacSignListeners(view); + + return view; + } + + private void setupZodiacSignListeners(View view) { + Button ariesButton = (Button) view.findViewById(R.id.button_Aries); + ariesButton.setOnClickListener(signSelectButtonListner); + + Button tauruButton = (Button) view.findViewById(R.id.button_Taurus); + tauruButton.setOnClickListener(signSelectButtonListner); + + Button geminiButton = (Button) view.findViewById(R.id.button_Gemini); + geminiButton.setOnClickListener(signSelectButtonListner); + + Button leoButton = (Button) view.findViewById(R.id.button_Leo); + leoButton.setOnClickListener(signSelectButtonListner); + + Button libraButton = (Button) view.findViewById(R.id.button_Libra); + libraButton.setOnClickListener(signSelectButtonListner); + + Button cancerButton = (Button) view.findViewById(R.id.button_Cancer); + cancerButton.setOnClickListener(signSelectButtonListner); + + Button virgoButton = (Button) view.findViewById(R.id.button_Virgo); + virgoButton.setOnClickListener(signSelectButtonListner); + + Button scorpioButton = (Button) view.findViewById(R.id.button_Scorpio); + scorpioButton.setOnClickListener(signSelectButtonListner); + + Button sagittariusButton = (Button) view.findViewById(R.id.button_Sagittarius); + sagittariusButton.setOnClickListener(signSelectButtonListner); + + Button capricornButton = (Button) view.findViewById(R.id.button_Capricorn); + capricornButton.setOnClickListener(signSelectButtonListner); + + Button pisceButton = (Button) view.findViewById(R.id.button_Pisces); + pisceButton.setOnClickListener(signSelectButtonListner); + + Button aquariusButton = (Button) view.findViewById(R.id.button_Aquarius); + aquariusButton.setOnClickListener(signSelectButtonListner); + + + + } + + private View.OnClickListener signSelectButtonListner = (new View.OnClickListener() { + @Override + public void onClick(View view) { + + String sign = ""; + + + if (view.getId() == R.id.button_Aries) { + //sign = "Aries"; + sign = "Aries: Mar 21 to Apr 19 \nPeople falling under this sign are adventurous. They are generally self-willed and courageous. They may be seen as short-tempered individuals. They are clever and confident. On some occasions, they act impatiently. Their impulsiveness and quick temper can go against them. If they overcome these weaknesses, they can achieve success in life, owing to their confidence and clarity of thought."; + } + else if (view.getId() == R.id.button_Taurus) { + //sign = "Taurus"; + sign ="Taurus: Apr 20 to May 20 \n Those belonging to this zodiac sign are romantic. Their love for style and beauty is apparent in their way of living. They are warm at heart and prefer being secure in life. As friends, they are trustworthy and helpful. But they can be possessive about everything they have. This may translate to selfishness and greed. If on guard about these weak areas, a Taurus can make a good company and an excellent friend."; + } + else if (view.getId() == R.id.button_Gemini) { + //sign = "Gemini"; + sign ="Gemini: May 21 to Jun 20 \nPeople belonging to this sign are versatile and quick-witted. They are spontaneous in communication. They come across as intelligent people. Their love towards life is evident in their way of living! But they tend to worry too much on certain issues and fail in managing stress. They form opinions pretty quickly and sometimes appear to look at life superficially."; + } + else if (view.getId() == R.id.button_Leo) { + //sign = "Leo"; + sign ="Leo: Jul 23 to Aug 22\n Leos are generous and open-minded. They are caring in nature. They possess a dominating nature coupled with the knack of taking everyone along. This combination of traits makes them true leaders. They may be egoistic and bossy. They tend to lose their temper quite easily. They are open-minded and openhanded, and show great love for magnificence and luxury. Leos are the real kings!"; + } + else if (view.getId() == R.id.button_Libra) { + //sign = "Libra"; + sign ="Libra: Sep 23 to Oct 23\n Their romantic nature is coupled with serenity. They are balanced in nature and know how to keep their cool at all occasions. At times, they find it difficult to express themselves. Though they appear aloof, they are attached to their near ones. They tend to get influenced by the views of others. It makes them indecisive. Apart from these lacunae, they are reasonable and thoughtful."; + } + else if (view.getId() == R.id.button_Cancer) { + //sign = "Cancer"; + sign ="Cancer: Jun 21 to Jul 22\nThose falling under this zodiac sign are sentimental. They have a loving and caring nature. They are cautious in their actions. They are very protective towards their loved ones. This nature makes them excellent and caring parents. Cancers often have an imaginative and artistic side to their life. Their moods vary. Their overly emotional nature needs to be worked on. On the whole, they are good human beings."; + } + else if (view.getId() == R.id.button_Virgo) { + //sign = "Virgo"; + sign ="Virgo: Aug 23 to Sep 22\nThey are very analytical. They tend to think overly on any given subject and form conclusions after a long thought process and deep analysis. They have unidirectional talents. They are absolute purists. Their overcritical nature can become a cause of trouble but otherwise they are intelligent and good decision makers."; + } + else if (view.getId() == R.id.button_Scorpio) { + //sign = "Scorpio"; + sign ="Scorpio: Oct 24 to Nov 22\nScorpios are passionate individuals with a magnetic personality. They are forceful about going by their opinions. They have clarity of thought and expression. Due to their possessive nature, they become jealous quite easily. They are clever and courageous. They can be resentful and obsessive. They seek to take revenge of the wrongdoers."; + } + else if (view.getId() == R.id.button_Sagittarius) { + //sign = "Sagittarius"; + sign ="Sagittarius: Nov 23 to Dec 21\nThey are intelligent and philosophical. They know how to lighten up the atmosphere. They are fun-loving in nature. Sometimes their excessive optimism makes them behave carelessly. Their moods and whims can be bothersome but on the whole, they are intelligent people with a good sense of humor."; + } + else if (view.getId() == R.id.button_Capricorn) { + //sign = "Capricorn"; + sign ="Capricorn: Dec 22 to Jan 19\nThey are prudent and practical. Their ambitious nature does not allow them to give up easily. They are vigilant. They plan very carefully. They may come across as sadistic individuals who are orthodox and rigid. Perseverance and tolerance are their greatest qualities. They are generally upfront in fighting whatever comes in their way."; + } + else if (view.getId() == R.id.button_Pisces) { + //sign = "Pisces"; + sign ="Pisces: Feb 20 to Mar 20\nThey are sensitive and sympathetic. They are kind and helpful. They can go out of their way to help their dear ones. This makes them excellent friends. The opinions of others can easily influence them due to which they may get carried away. They are not very determined or courageous. They are vague in thinking. But their idealism is their true differentiator."; + } + else if (view.getId() == R.id.button_Aquarius) { + //sign = "Aquarius"; + sign ="Aquarius: Jan 20 to Feb 19\nThey are of the intelligent type. A sense of humor, coupled with great intelligence and deep thinking make them stand out. They make loyal and honest friends. They are independent thinkers with great originality in their thoughts and actions. They may appear indifferent and less emotional. It is difficult to understand them."; + } + + + if (mListener != null) { + mListener.onSignChosen(sign); + } + } + }); + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + try { + mListener = (ChooseSignFragmentInteractionListener) activity; + } catch (ClassCastException e) { + throw new ClassCastException(activity.toString() + + " must implement ChooseSignFragmentInteractionListener"); + } + } + + @Override + public void onDetach() { + super.onDetach(); + mListener = null; + } + + /** + * This interface must be implemented by activities that contain this + * fragment to allow an interaction in this fragment to be communicated + * to the activity and potentially other fragments contained in that + * activity. + *

+ * See the Android Training lesson Communicating with Other Fragments for more information. + */ + public interface ChooseSignFragmentInteractionListener { + // TODO: Update argument type and name + public void onSignChosen(String sign); + } + +} diff --git a/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/CompatibiltyFragment.java b/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/CompatibiltyFragment.java new file mode 100644 index 00000000..6f12525c --- /dev/null +++ b/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/CompatibiltyFragment.java @@ -0,0 +1,195 @@ +package hoshikoo.c4q.nyc.wk1_horoscope; + +import android.app.Activity; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.Spinner; +import android.widget.TextView; + + +public class CompatibiltyFragment extends Fragment { + + public interface CompatibilityFragmentListener { + void onCompatiblityDone(String result); + } + + private static CompatibiltyFragment instance = null; + private CompatibilityFragmentListener mListener = null; + + public static CompatibiltyFragment getInstance() { + if (instance == null) { + instance = new CompatibiltyFragment(); + } + + return instance; + } + + + private void setupCompatibilityListeners(View view) { + Button submit = (Button) view.findViewById(R.id.btnSubmit); + submit.setOnClickListener(signSelectsubmitListner); + + } + + private View.OnClickListener signSelectsubmitListner = (new View.OnClickListener() { + @Override + public void onClick(View view) { + + } + }); + + + private Spinner spinner; + private Spinner spinner2; + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.compatibility_fragment, container, false); + configureListeners(view); + setSpinnerContent( view ); + return view; + + } + + private void setSpinnerContent( View view ) + { + spinner = (Spinner) view.findViewById( R.id.spinner); + spinner2 = (Spinner) view.findViewById( R.id.spinner2); + + ArrayAdapter adapter = ArrayAdapter.createFromResource( getActivity(), R.array.zodiac_array , android.R.layout.simple_spinner_item); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(adapter); + + ArrayAdapter adapter2 = ArrayAdapter.createFromResource( getActivity(), R.array.zodiac_array , android.R.layout.simple_spinner_item); + adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner2.setAdapter( adapter2 ); + + } + + private void configureListeners(View view) { + + + Button submitButton = (Button) view.findViewById(R.id.btnSubmit); + submitButton.setOnClickListener(compatibilityButtonListner); + +// TextView tv = (TextView) view.findViewById(R.id.matched_msg); +// +// tv.setText(result); + } + + String result = ""; + String signGroup1; + String signGroup2; + + private View.OnClickListener compatibilityButtonListner = (new View.OnClickListener() { + @Override + public void onClick(View view) { + + String sign1 = spinner.getSelectedItem().toString();; + String sign2 = spinner2.getSelectedItem().toString();; + + String fire = "fire"; + String water= "water"; + String wind = "wind"; + String ground = "ground"; + + + + + if (sign1.equalsIgnoreCase("Aries")||sign1.equalsIgnoreCase("Leo")||sign1.equalsIgnoreCase("Sagittarius")) { + signGroup1 = fire; + }else if (sign1.equalsIgnoreCase("Taurus")||sign1.equalsIgnoreCase("Virgo")||sign1.equalsIgnoreCase("Capricorn")){ + signGroup1 = ground; + }else if (sign1.equalsIgnoreCase("Cancer")||sign1.equalsIgnoreCase("Scorpio")||sign1.equalsIgnoreCase("Pisces")){ + signGroup1 = water; + }else if (sign1.equalsIgnoreCase("Gemini")||sign1.equalsIgnoreCase("Libra")||sign1.equalsIgnoreCase("Aquarius")){ + signGroup1 = wind; + }else{ + signGroup1=null; + } + + if (sign2.equalsIgnoreCase("Aries")||sign2.equalsIgnoreCase("Leo")||sign2.equalsIgnoreCase("Sagittarius")) { + signGroup2 = fire; + }else if (sign2.equalsIgnoreCase("Taurus")||sign2.equalsIgnoreCase("Virgo")||sign2.equalsIgnoreCase("Capricorn")){ + signGroup2 = ground; + }else if (sign2.equalsIgnoreCase("Cancer")||sign2.equalsIgnoreCase("Scorpio")||sign2.equalsIgnoreCase("Pisces")){ + signGroup2 = water; + }else if (sign2.equalsIgnoreCase("Gemini")||sign2.equalsIgnoreCase("Libra")||sign2.equalsIgnoreCase("Aquarius")){ + signGroup2 = wind; + }else{ + signGroup2 = null; + } + + if (signGroup1==null ||signGroup2==null){ + result = "Error"; + } + else if(signGroup1.equals(fire)&& signGroup2.equals(fire)){ + result = "Good"; + }else if(signGroup1.equals(water)&& signGroup2.equals(water)){ + result = "Good"; + }else if(signGroup1.equals(wind)&& signGroup2.equals(wind)){ + result = "Good"; + }else if(signGroup1.equals(ground)&& signGroup2.equals(ground)){ + result = "Good"; + }else if(signGroup1.equals(water)&& signGroup2.equals(wind)){ + result = "bad"; + }else if(signGroup2.equals(water)&& signGroup1.equals(wind)){ + result = "bad"; + } + else if(signGroup1.equals(fire)&& signGroup2.equals(ground)){ + result = "bad"; + } + else if(signGroup2.equals(fire)&& signGroup1.equals(ground)){ + result = "bad"; + }else if(signGroup1.equals(water)&& signGroup2.equals(fire)){ + result = "OK"; + }else if(signGroup2.equals(water)&& signGroup1.equals(fire)){ + result = "OK"; + }else if(signGroup1.equals(ground)&& signGroup2.equals(wind)){ + result = "OK"; + }else if(signGroup2.equals(ground)&& signGroup1.equals(wind)){ + result = "OK"; + }else if(signGroup1.equals(water)&& signGroup2.equals(ground)){ + result = "Great"; + }else if(signGroup2.equals(water)&& signGroup1.equals(ground)){ + result = "Great"; + }else if(signGroup1.equals(fire)&& signGroup2.equals(wind)){ + result = "Great"; + }else if(signGroup2.equals(fire)&& signGroup1.equals(wind)){ + result = "Great"; + } + + + + if (mListener != null) { + mListener.onCompatiblityDone(result); + } + } + }); + + + + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + mListener = (CompatibilityFragmentListener) activity; + } + + @Override + public void onDetach() { + super.onDetach(); + mListener = null; + } + + + + +} diff --git a/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/CustomOnItemSelectedListener.java b/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/CustomOnItemSelectedListener.java new file mode 100644 index 00000000..8cba1793 --- /dev/null +++ b/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/CustomOnItemSelectedListener.java @@ -0,0 +1,28 @@ +package hoshikoo.c4q.nyc.wk1_horoscope; + +/** + * Created by Hoshiko on 5/13/15. + */ +import android.view.View; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.Toast; + +public class CustomOnItemSelectedListener implements OnItemSelectedListener { + + public void onItemSelected(AdapterView parent, View view, int pos, + long id) { + + Toast.makeText(parent.getContext(), + "On Item Select : \n" + parent.getItemAtPosition(pos).toString(), + Toast.LENGTH_LONG).show(); + } + + @Override + public void onNothingSelected(AdapterView arg0) { + // TODO Auto-generated method stub + + } + +} + diff --git a/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/EnterBirthdayFragment.java b/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/EnterBirthdayFragment.java new file mode 100644 index 00000000..8e213c89 --- /dev/null +++ b/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/EnterBirthdayFragment.java @@ -0,0 +1,210 @@ +package hoshikoo.c4q.nyc.wk1_horoscope; + +import android.app.Activity; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.Spinner; +import android.widget.TextView; + + + +/** + * A simple {@link Fragment} subclass. + */ +public class EnterBirthdayFragment extends Fragment { + + +// public EnterBirthdayFragment() { +// // Required empty public constructor +// } + + + public interface EnterBirthdayFragmentListner { + + void onEnterBirthdayDone(String resultSign); + } + + private static EnterBirthdayFragment instance = null; + private EnterBirthdayFragmentListner mListener = null; + + public static EnterBirthdayFragment getInstance() { + if (instance == null) { + instance = new EnterBirthdayFragment(); + } + + return instance; + } + +// private void setupGetZodiacSignListeners(View view) { +// Button getZodiac = (Button) view.findViewById(R.id.get_zodiac_sign); +// getZodiac.setOnClickListener(getResultZodiacListner); +// +// } + +// private View.OnClickListener getResultZodiacListner = (new View.OnClickListener() { +// @Override +// public void onClick(View view) { +// +// } +// }); + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_enter_birthday, container, false); + + setupGetZodiacSignListeners(view); + setSpinnerContent(view); + return view; + + } +// +// private void birthdayListener(View view) { +// TextView tv = (TextView) view.findViewById(R.id.zodiac_sign_result); +// tv.setText(resultSign); +// } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + mListener = (EnterBirthdayFragmentListner) activity; + } + + @Override + public void onDetach() { + super.onDetach(); + mListener = null; + } + + private Spinner spinnerMonth; + private Spinner spinnerDate; + private void setSpinnerContent( View view ) + { + spinnerMonth = (Spinner) view.findViewById( R.id.spinner3); + spinnerDate = (Spinner) view.findViewById( R.id.spinner4); + + ArrayAdapter adapter3 = ArrayAdapter.createFromResource( getActivity(), R.array.month_array , android.R.layout.simple_spinner_item); + adapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinnerMonth.setAdapter(adapter3); + + ArrayAdapter adapter4 = ArrayAdapter.createFromResource( getActivity(), R.array.date_array , android.R.layout.simple_spinner_item); + adapter4.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinnerDate.setAdapter( adapter4 ); + + } + + private void setupGetZodiacSignListeners (View view) { + + + Button submitButton = (Button) view.findViewById(R.id.get_zodiac_sign); + submitButton.setOnClickListener(getResultZodiacListner); +// TextView zodiacSign =(TextView)view.findViewById(R.id.zodiac_sign_result); +// zodiacSign.setText(resultSign); + +// TextView tv = (TextView) view.findViewById(R.id.zodiac_sign_result); +// +// tv.setText(resultSign); + } + + String resultSign = ""; + + private View.OnClickListener getResultZodiacListner = (new View.OnClickListener() { + @Override + public void onClick(View view) { + + String month = spinnerMonth.getSelectedItem().toString(); + + if (month.equalsIgnoreCase("Jan")){ + month= "1"; + }else if (month.equalsIgnoreCase("Feb")){ + month= "2"; + }else if (month.equalsIgnoreCase("Mar")) { + month = "3"; + }else if (month.equalsIgnoreCase("Apr")) { + month = "4"; + } + else if (month.equalsIgnoreCase("May")) { + month = "5"; + } + else if (month.equalsIgnoreCase("Jun")) { + month = "6"; + } + else if (month.equalsIgnoreCase("Jul")) { + month = "7"; + } + else if (month.equalsIgnoreCase("Aug")) { + month = "8"; + } + else if (month.equalsIgnoreCase("Sep")) { + month = "9"; + } + else if (month.equalsIgnoreCase("Oct")) { + month = "10"; + }else if (month.equalsIgnoreCase("Nov")) { + month = "11"; + }else if (month.equalsIgnoreCase("Dec")) { + month = "12"; + } + + + + + String date = spinnerDate.getSelectedItem().toString(); + + int bd = Integer.parseInt(month+date); + + + if ( bd>=321 && bd<=331 || bd>=401 && bd <=419){ + resultSign = "Your Zodiac Sign is Aries"; + }else if ( bd>=420 && bd<=430 ||bd>=501 && bd<=520 ){ + resultSign = "Your Zodiac Sign is Taurus"; + }else if ( bd>=521 && bd<=531 ||bd>=601 && bd<=621 ){ + resultSign = "Your Zodiac Sign is Gemini"; + + }else if ( bd>=622 && bd<=630 ||bd>=701 && bd<=722 ){ + resultSign = "Your Zodiac Sign is Cancer"; + + }else if ( bd>=723 && bd<=731 ||bd>=801 && bd<=822 ) { + resultSign = "Your Zodiac Sign is Leo"; + + }else if ( bd>=823 && bd<=831 ||bd>=901 && bd<=922 ) { + resultSign = "Your Zodiac Sign is Virgo"; + + }else if ( bd>=923 && bd<=930 ||bd>=1001 && bd<=1023 ) { + resultSign = "Your Zodiac Sign is Libra"; + + }else if ( bd>=1024 && bd<=1031 ||bd>=1101 && bd<=1120 ) { + resultSign = "Your Zodiac Sign is Scorpio"; + + }else if ( bd>=1121 && bd<=1130 ||bd>=1201 && bd<=1222 ) { + resultSign = "Your Zodiac Sign is Sagittarius"; + + }else if ( bd>=1223 && bd<=1231 ||bd>=101 && bd<=120 ) { + resultSign = "Your Zodiac Sign is Capricorn"; + }else if ( bd>=121 && bd<=131 ||bd>=201 && bd<=221 ) { + resultSign = "Your Zodiac Sign is Aquarius"; + }else if ( bd>=222 && bd<=229 ||bd>=301 && bd<=320 ) { + resultSign = "Your Zodiac Sign is Pisces"; + }else { + resultSign = "You enter the wrong info. Please try again."; + } + + + + if (mListener != null) { + mListener.onEnterBirthdayDone(resultSign); + } + } + }); + + + + + +} diff --git a/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/GameFragment.java b/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/GameFragment.java new file mode 100644 index 00000000..193508d8 --- /dev/null +++ b/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/GameFragment.java @@ -0,0 +1,232 @@ +package hoshikoo.c4q.nyc.wk1_horoscope; + +import android.app.Activity; +import android.os.Bundle; +import android.os.CountDownTimer; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.Spinner; +import android.widget.TextView; + +import java.util.Random; + +/** + * A simple {@link Fragment} subclass. + */ +public class GameFragment extends Fragment { + + public interface GameFragmentListener { + void onGameDone(String answer, String rightWrong); + } + + private static GameFragment instance = null; + private GameFragmentListener mListener = null; + + public static GameFragment getInstance() { + if (instance == null) { + instance = new GameFragment(); + } + + return instance; + } + + + private Spinner spinner; + int birthMonth,birthDate; + String BDMonth =""; + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_game, container, false); + setupGameListeners(view); + setSpinnerContent(view); + setRandomBirthday(view); + setTimer(view); + // answerListeners(view); + setSpinnerContent( view ); + return view; + + } + + + + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + mListener = (GameFragmentListener) activity; + + } + + @Override + public void onDetach() { + super.onDetach(); + mListener = null; + } + + private void setTimer (final View view){ + new CountDownTimer(30000, 1000) { + TextView answerTV =(TextView)view.findViewById(R.id.answer); + + public void onTick(long millisUntilFinished) { + answerTV.setText("seconds remaining: " + millisUntilFinished / 1000); + } + + public void onFinish() { + answerTV.setText("Correct answer is "+answer); + } + }.start(); + } + + + private void setSpinnerContent( View view ) + { + spinner = (Spinner) view.findViewById( R.id.spinnerZodiac); + + ArrayAdapter adapter5 = ArrayAdapter.createFromResource( getActivity(), R.array.zodiac_array , android.R.layout.simple_spinner_item); + adapter5.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(adapter5); + } + + private void setupGameListeners(View view) { + Button submitbutton = (Button) view.findViewById(R.id.answerButton); + submitbutton.setOnClickListener(answerButtonListner); + } + + String answer = ""; + int bd; + private void setRandomBirthday(View view) { + + int date [] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}; + int month [] ={1,2,3,4,5,6,7,8,9,10,11,12}; + Random randomMonth = new Random(); + Random randomDate = new Random(); + + birthMonth = month[randomMonth.nextInt(month.length)]; + birthDate = date[randomDate.nextInt(date.length)]; + + + if(birthMonth==1){ + BDMonth = "Jan"; + }else if(birthMonth==2){ + BDMonth = "Feb"; + }else if(birthMonth==3){ + BDMonth = "Mar"; + }else if(birthMonth==4){ + BDMonth = "Apr"; + }else if(birthMonth==5){ + BDMonth = "May"; + }else if(birthMonth==6){ + BDMonth = "Jun"; + }else if(birthMonth==7){ + BDMonth = "Jul"; + }else if(birthMonth==8){ + BDMonth = "Aug"; + }else if(birthMonth==9){ + BDMonth = "Sep"; + }else if(birthMonth==10){ + BDMonth = "Oct"; + }else if(birthMonth==11){ + BDMonth = "Nov"; + }else if(birthMonth==12){ + BDMonth = "Dec"; + } + + TextView randomBd =(TextView)view.findViewById(R.id.randomBD); + randomBd.setText(BDMonth+" "+Integer.toString(birthDate)); + + } + +// private View.OnClickListener signAnswersubmitListner = (new View.OnClickListener() { +// @Override +// public void onClick(View view) { +// +// } +// }); + + + + + +// +// private void answerListeners(View view) { +// +// +// Button submitButton = (Button) view.findViewById(R.id.answerButton); +// submitButton.setOnClickListener(answerButtonListner ); +// +// TextView tv = (TextView) view.findViewById(R.id.matched_msg); +// +// tv.setText(result); +// } + String rightWrong = ""; + + private View.OnClickListener answerButtonListner = (new View.OnClickListener() { + @Override + public void onClick(View view) { + + String answerUser = spinner.getSelectedItem().toString(); + + String birthdayStr = Integer.toString(birthMonth)+Integer.toString(birthDate); + bd = Integer.parseInt(birthdayStr); + + + if ( bd>=321 && bd<=331 || bd>=401 && bd <=419){ + answer = "Aries"; + + }else if ( bd>=420 && bd<=430 ||bd>=501 && bd<=520 ){ + answer = "Taurus"; + + }else if ( bd>=521 && bd<=531 ||bd>=601 && bd<=621 ){ + answer = "Gemini"; + + }else if ( bd>=622 && bd<=630 ||bd>=701 && bd<=722 ){ + answer = "Cancer"; + + }else if ( bd>=723 && bd<=731 ||bd>=801 && bd<=822 ) { + answer = "Leo"; + + }else if ( bd>=823 && bd<=831 ||bd>=901 && bd<=922 ) { + answer = "Virgo"; + + }else if ( bd>=923 && bd<=930 ||bd>=1001 && bd<=1023 ) { + answer = "Libra"; + + }else if ( bd>=1024 && bd<=1031 ||bd>=1101 && bd<=1120 ) { + answer = "Scorpio"; + + }else if ( bd>=1121 && bd<=1130 ||bd>=1201 && bd<=1222 ) { + answer = "Sagittarius"; + + }else if ( bd>=1223 && bd<=1231 ||bd>=101 && bd<=120 ) { + answer = "Capricorn"; + + }else if ( bd>=121 && bd<=131 ||bd>=201 && bd<=221 ) { + answer = "Aquarius"; + + }else if ( bd>=222 && bd<=229 ||bd>=301 && bd<=320 ) { + answer = "Pisces"; + + } + + if(answerUser.equals(answer)){ + rightWrong = "You are collect"; + }else if(answerUser.equals("Select")){ + rightWrong = "Please select a zodiac sign"; + }else{ + rightWrong = "You are wrong"; + } + + + + if (mListener != null) { + mListener.onGameDone(answer, rightWrong); + } + } + }); +} diff --git a/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/MainActivity.java b/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/MainActivity.java new file mode 100644 index 00000000..a2c609f0 --- /dev/null +++ b/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/MainActivity.java @@ -0,0 +1,280 @@ +package hoshikoo.c4q.nyc.wk1_horoscope; + +import android.app.Activity; +import android.content.DialogInterface; +import android.content.res.Configuration; +import android.os.Bundle; +import android.os.CountDownTimer; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.widget.DrawerLayout; +import android.support.v7.app.ActionBar; +import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AlertDialog; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.TextView; +import android.widget.Toast; + +import java.util.ArrayList; +import java.util.List; + + +public class MainActivity extends ActionBarActivity + implements NavigationDrawerFragment.NavigationDrawerCallbacks, + ChooseSignFragment.ChooseSignFragmentInteractionListener, + CompatibiltyFragment.CompatibilityFragmentListener, EnterBirthdayFragment.EnterBirthdayFragmentListner, GameFragment.GameFragmentListener { + + +// @Override +// public void onConfigurationChanged(Configuration newConfig) { +// super.onConfigurationChanged(newConfig); +// if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { +// createHorizontalalLayout(); +// } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){ +// createVerticalLayout(); +// } +// } + + /** + * Fragment managing the behaviors, interactions and presentation of the navigation drawer. + */ + private NavigationDrawerFragment mNavigationDrawerFragment; + + /** + * Used to store the last screen title. For use in {@link #restoreActionBar()}. + */ + private CharSequence mTitle; + + private String chosenSign = null; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + mNavigationDrawerFragment = (NavigationDrawerFragment) + getSupportFragmentManager().findFragmentById(R.id.navigation_drawer); + mTitle = getTitle(); + + // Set up the drawer. + mNavigationDrawerFragment.setUp( + R.id.navigation_drawer, + (DrawerLayout) findViewById(R.id.drawer_layout)); + } + + @Override + public void onNavigationDrawerItemSelected(int position) { + // update the main content by replacing fragments + FragmentManager fragmentManager = getSupportFragmentManager(); + + if (position == 0) { + Fragment chooseSignFragment = ChooseSignFragment.newInstance(); + fragmentManager.beginTransaction() + .replace(R.id.container, chooseSignFragment) + .commit(); + + return; + } + + if (position == 1) { + Fragment enterBirthdayFragment = EnterBirthdayFragment.getInstance(); + fragmentManager.beginTransaction() + .replace(R.id.container, enterBirthdayFragment) + .commit(); + + return; + } + + + if (position == 2) { + Fragment compatFragment = CompatibiltyFragment.getInstance(); + fragmentManager.beginTransaction() + .replace(R.id.container, compatFragment) + .commit(); + + return; + } + + if (position == 3) { + Fragment gameFragment = GameFragment.getInstance(); + fragmentManager.beginTransaction() + .replace(R.id.container, gameFragment) + .commit(); + + return; + } + + fragmentManager.beginTransaction() + .replace(R.id.container, PlaceholderFragment.newInstance(position + 1)) + .commit(); + } + + public void onSectionAttached(int number) { + switch (number) { + case 1: + mTitle = getString(R.string.title_section1); + break; + case 2: + mTitle = getString(R.string.title_section2); + break; + case 3: + mTitle = getString(R.string.title_section3); + break; + case 4: + mTitle = getString(R.string.title_section4); + break; + } + } + + public void restoreActionBar() { + ActionBar actionBar = getSupportActionBar(); + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); + actionBar.setDisplayShowTitleEnabled(true); + actionBar.setTitle(mTitle); + } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + if (!mNavigationDrawerFragment.isDrawerOpen()) { + // Only show items in the action bar relevant to this screen + // if the drawer is not showing. Otherwise, let the drawer + // decide what to show in the action bar. + getMenuInflater().inflate(R.menu.main, menu); + restoreActionBar(); + return true; + } + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + if (id == R.id.action_settings) { + return true; + } + + return super.onOptionsItemSelected(item); + } + + @Override + public void onSignChosen(String sign) { +// Toast.makeText(this, "Sign selected: " + sign, Toast.LENGTH_SHORT).show(); +// chosenSign = sign; + + + AlertDialog.Builder builder1 = new AlertDialog.Builder(this); + builder1.setMessage(sign); + builder1.setCancelable(true); + builder1.setPositiveButton("Got it", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }); +// builder1.setNegativeButton("No", +// new DialogInterface.OnClickListener() { +// public void onClick(DialogInterface dialog, int id) { +// dialog.cancel(); +// } +// }); + + AlertDialog alert11 = builder1.create(); + alert11.show(); + } + + + + @Override + public void onCompatiblityDone(String result) { + Toast.makeText(this, "Your compatibility is "+result, Toast.LENGTH_SHORT).show(); + TextView compatibility =(TextView)findViewById(R.id.matched_msg); + compatibility.setText(result); + } + + + @Override + public void onEnterBirthdayDone(String resultSign) { + Toast.makeText(this, resultSign, Toast.LENGTH_SHORT).show(); + TextView zodiacSign =(TextView)findViewById(R.id.zodiac_sign_result); + zodiacSign.setText(resultSign); + + } + + @Override + public void onGameDone(final String answer, String rightWrong) { + +// new CountDownTimer(30000, 1000) { +// TextView answerTV =(TextView)findViewById(R.id.answer); +// +// public void onTick(long millisUntilFinished) { +// answerTV.setText("seconds remaining: " + millisUntilFinished / 1000); +// } +// +// public void onFinish() { +// answerTV.setText("Correct answer is "+answer); +// } +// }.start(); + + Toast.makeText(this, rightWrong, Toast.LENGTH_SHORT).show(); +// TextView answerTV =(TextView)findViewById(R.id.answer); +// answerTV.setText(answer); + TextView rightWrongTV =(TextView)findViewById(R.id.rightWrong); + rightWrongTV.setText(rightWrong); + } + + + /** + * A placeholder fragment containing a simple view. + */ + public static class PlaceholderFragment extends Fragment { + /** + * The fragment argument representing the section number for this + * fragment. + */ + private static final String ARG_SECTION_NUMBER = "section_number"; + + /** + * Returns a new instance of this fragment for the given section + * number. + */ + public static PlaceholderFragment newInstance(int sectionNumber) { + PlaceholderFragment fragment = new PlaceholderFragment(); + Bundle args = new Bundle(); + args.putInt(ARG_SECTION_NUMBER, sectionNumber); + fragment.setArguments(args); + return fragment; + } + + public PlaceholderFragment() { + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_main, container, false); + return rootView; + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + ((MainActivity) activity).onSectionAttached( + getArguments().getInt(ARG_SECTION_NUMBER)); + } + } + +} diff --git a/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/NavigationDrawerFragment.java b/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/NavigationDrawerFragment.java new file mode 100644 index 00000000..630c5fb3 --- /dev/null +++ b/homework/WK1_Horoscope/app/src/main/java/hoshikoo/c4q/nyc/wk1_horoscope/NavigationDrawerFragment.java @@ -0,0 +1,283 @@ +package hoshikoo.c4q.nyc.wk1_horoscope; + +import android.support.v7.app.ActionBarActivity; +import android.app.Activity; +import android.support.v7.app.ActionBar; +import android.support.v4.app.Fragment; +import android.support.v4.app.ActionBarDrawerToggle; +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.Toast; + +/** + * Fragment used for managing interactions for and presentation of a navigation drawer. + * See the + * design guidelines for a complete explanation of the behaviors implemented here. + */ +public class NavigationDrawerFragment extends Fragment { + + /** + * Remember the position of the selected item. + */ + private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position"; + + /** + * Per the design guidelines, you should show the drawer on launch until the user manually + * expands it. This shared preference tracks this. + */ + private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned"; + + /** + * A pointer to the current callbacks instance (the Activity). + */ + private NavigationDrawerCallbacks mCallbacks; + + /** + * Helper component that ties the action bar to the navigation drawer. + */ + private ActionBarDrawerToggle mDrawerToggle; + + private DrawerLayout mDrawerLayout; + private ListView mDrawerListView; + private View mFragmentContainerView; + + private int mCurrentSelectedPosition = 0; + private boolean mFromSavedInstanceState; + private boolean mUserLearnedDrawer; + + public NavigationDrawerFragment() { + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Read in the flag indicating whether or not the user has demonstrated awareness of the + // drawer. See PREF_USER_LEARNED_DRAWER for details. + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); + mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false); + + if (savedInstanceState != null) { + mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION); + mFromSavedInstanceState = true; + } + + // Select either the default item (0) or the last selected item. + selectItem(mCurrentSelectedPosition); + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + // Indicate that this fragment would like to influence the set of actions in the action bar. + setHasOptionsMenu(true); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + mDrawerListView = (ListView) inflater.inflate( + R.layout.fragment_navigation_drawer, container, false); + mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + selectItem(position); + } + }); + mDrawerListView.setAdapter(new ArrayAdapter( + getActionBar().getThemedContext(), + android.R.layout.simple_list_item_activated_1, + android.R.id.text1, + new String[]{ + getString(R.string.title_section1), + getString(R.string.title_section2), + getString(R.string.title_section3), + "Horoscope Game", + })); + mDrawerListView.setItemChecked(mCurrentSelectedPosition, true); + return mDrawerListView; + } + + public boolean isDrawerOpen() { + return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView); + } + + /** + * Users of this fragment must call this method to set up the navigation drawer interactions. + * + * @param fragmentId The android:id of this fragment in its activity's layout. + * @param drawerLayout The DrawerLayout containing this fragment's UI. + */ + public void setUp(int fragmentId, DrawerLayout drawerLayout) { + mFragmentContainerView = getActivity().findViewById(fragmentId); + mDrawerLayout = drawerLayout; + + // set a custom shadow that overlays the main content when the drawer opens + mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); + // set up the drawer's list view with items and click listener + + ActionBar actionBar = getActionBar(); + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setHomeButtonEnabled(true); + + // ActionBarDrawerToggle ties together the the proper interactions + // between the navigation drawer and the action bar app icon. + mDrawerToggle = new ActionBarDrawerToggle( + getActivity(), /* host Activity */ + mDrawerLayout, /* DrawerLayout object */ + R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ + R.string.navigation_drawer_open, /* "open drawer" description for accessibility */ + R.string.navigation_drawer_close /* "close drawer" description for accessibility */ + ) { + @Override + public void onDrawerClosed(View drawerView) { + super.onDrawerClosed(drawerView); + if (!isAdded()) { + return; + } + + getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu() + } + + @Override + public void onDrawerOpened(View drawerView) { + super.onDrawerOpened(drawerView); + if (!isAdded()) { + return; + } + + if (!mUserLearnedDrawer) { + // The user manually opened the drawer; store this flag to prevent auto-showing + // the navigation drawer automatically in the future. + mUserLearnedDrawer = true; + SharedPreferences sp = PreferenceManager + .getDefaultSharedPreferences(getActivity()); + sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); + } + + getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu() + } + }; + + // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, + // per the navigation drawer design guidelines. + if (!mUserLearnedDrawer && !mFromSavedInstanceState) { + mDrawerLayout.openDrawer(mFragmentContainerView); + } + + // Defer code dependent on restoration of previous instance state. + mDrawerLayout.post(new Runnable() { + @Override + public void run() { + mDrawerToggle.syncState(); + } + }); + + mDrawerLayout.setDrawerListener(mDrawerToggle); + } + + private void selectItem(int position) { + mCurrentSelectedPosition = position; + if (mDrawerListView != null) { + mDrawerListView.setItemChecked(position, true); + } + if (mDrawerLayout != null) { + mDrawerLayout.closeDrawer(mFragmentContainerView); + } + if (mCallbacks != null) { + mCallbacks.onNavigationDrawerItemSelected(position); + } + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + try { + mCallbacks = (NavigationDrawerCallbacks) activity; + } catch (ClassCastException e) { + throw new ClassCastException("Activity must implement NavigationDrawerCallbacks."); + } + } + + @Override + public void onDetach() { + super.onDetach(); + mCallbacks = null; + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + // Forward the new configuration the drawer toggle component. + mDrawerToggle.onConfigurationChanged(newConfig); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + // If the drawer is open, show the global app actions in the action bar. See also + // showGlobalContextActionBar, which controls the top-left area of the action bar. + if (mDrawerLayout != null && isDrawerOpen()) { + inflater.inflate(R.menu.global, menu); + showGlobalContextActionBar(); + } + super.onCreateOptionsMenu(menu, inflater); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (mDrawerToggle.onOptionsItemSelected(item)) { + return true; + } + + if (item.getItemId() == R.id.action_example) { + Toast.makeText(getActivity(), "Example action.", Toast.LENGTH_SHORT).show(); + return true; + } + + return super.onOptionsItemSelected(item); + } + + /** + * Per the navigation drawer design guidelines, updates the action bar to show the global app + * 'context', rather than just what's in the current screen. + */ + private void showGlobalContextActionBar() { + ActionBar actionBar = getActionBar(); + actionBar.setDisplayShowTitleEnabled(true); + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); + actionBar.setTitle(R.string.app_name); + } + + private ActionBar getActionBar() { + return ((ActionBarActivity) getActivity()).getSupportActionBar(); + } + + /** + * Callbacks interface that all activities using this fragment must implement. + */ + public static interface NavigationDrawerCallbacks { + /** + * Called when an item in the navigation drawer is selected. + */ + void onNavigationDrawerItemSelected(int position); + } +} diff --git a/homework/WK1_Horoscope/app/src/main/res/drawable-hdpi/drawer_shadow.9.png b/homework/WK1_Horoscope/app/src/main/res/drawable-hdpi/drawer_shadow.9.png new file mode 100644 index 00000000..236bff55 Binary files /dev/null and b/homework/WK1_Horoscope/app/src/main/res/drawable-hdpi/drawer_shadow.9.png differ diff --git a/homework/WK1_Horoscope/app/src/main/res/drawable-hdpi/ic_drawer.png b/homework/WK1_Horoscope/app/src/main/res/drawable-hdpi/ic_drawer.png new file mode 100644 index 00000000..c59f601c Binary files /dev/null and b/homework/WK1_Horoscope/app/src/main/res/drawable-hdpi/ic_drawer.png differ diff --git a/homework/WK1_Horoscope/app/src/main/res/drawable-mdpi/drawer_shadow.9.png b/homework/WK1_Horoscope/app/src/main/res/drawable-mdpi/drawer_shadow.9.png new file mode 100644 index 00000000..ffe3a28d Binary files /dev/null and b/homework/WK1_Horoscope/app/src/main/res/drawable-mdpi/drawer_shadow.9.png differ diff --git a/homework/WK1_Horoscope/app/src/main/res/drawable-mdpi/ic_drawer.png b/homework/WK1_Horoscope/app/src/main/res/drawable-mdpi/ic_drawer.png new file mode 100644 index 00000000..1ed2c56e Binary files /dev/null and b/homework/WK1_Horoscope/app/src/main/res/drawable-mdpi/ic_drawer.png differ diff --git a/homework/WK1_Horoscope/app/src/main/res/drawable-xhdpi/drawer_shadow.9.png b/homework/WK1_Horoscope/app/src/main/res/drawable-xhdpi/drawer_shadow.9.png new file mode 100644 index 00000000..fabe9d96 Binary files /dev/null and b/homework/WK1_Horoscope/app/src/main/res/drawable-xhdpi/drawer_shadow.9.png differ diff --git a/homework/WK1_Horoscope/app/src/main/res/drawable-xhdpi/ic_drawer.png b/homework/WK1_Horoscope/app/src/main/res/drawable-xhdpi/ic_drawer.png new file mode 100644 index 00000000..a5fa74de Binary files /dev/null and b/homework/WK1_Horoscope/app/src/main/res/drawable-xhdpi/ic_drawer.png differ diff --git a/homework/WK1_Horoscope/app/src/main/res/drawable-xxhdpi/drawer_shadow.9.png b/homework/WK1_Horoscope/app/src/main/res/drawable-xxhdpi/drawer_shadow.9.png new file mode 100644 index 00000000..b91e9d7f Binary files /dev/null and b/homework/WK1_Horoscope/app/src/main/res/drawable-xxhdpi/drawer_shadow.9.png differ diff --git a/homework/WK1_Horoscope/app/src/main/res/drawable-xxhdpi/ic_drawer.png b/homework/WK1_Horoscope/app/src/main/res/drawable-xxhdpi/ic_drawer.png new file mode 100644 index 00000000..9c4685d6 Binary files /dev/null and b/homework/WK1_Horoscope/app/src/main/res/drawable-xxhdpi/ic_drawer.png differ diff --git a/homework/WK1_Horoscope/app/src/main/res/drawable/background.jpg b/homework/WK1_Horoscope/app/src/main/res/drawable/background.jpg new file mode 100644 index 00000000..5ef77b80 Binary files /dev/null and b/homework/WK1_Horoscope/app/src/main/res/drawable/background.jpg differ diff --git a/homework/WK1_Horoscope/app/src/main/res/drawable/background2.gif b/homework/WK1_Horoscope/app/src/main/res/drawable/background2.gif new file mode 100644 index 00000000..4d74128f Binary files /dev/null and b/homework/WK1_Horoscope/app/src/main/res/drawable/background2.gif differ diff --git a/homework/WK1_Horoscope/app/src/main/res/layout-land/compatibility_fragment.xml b/homework/WK1_Horoscope/app/src/main/res/layout-land/compatibility_fragment.xml new file mode 100644 index 00000000..0ea0b6f4 --- /dev/null +++ b/homework/WK1_Horoscope/app/src/main/res/layout-land/compatibility_fragment.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + +