Skip to content

Commit

Permalink
Add Word Object And Custom ArrayAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
HadyAhmed authored and [email protected] committed Sep 18, 2018
1 parent e1578cc commit 6f9e945
Show file tree
Hide file tree
Showing 21 changed files with 443 additions and 312 deletions.
40 changes: 13 additions & 27 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.miwok">

Expand All @@ -22,48 +8,48 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".activity.CategoryActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".NumbersActivity"
android:name=".activity.NumbersActivity"
android:label="@string/category_numbers"
android:parentActivityName=".MainActivity">
android:parentActivityName=".activity.CategoryActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
android:value=".activity.CategoryActivity"/>
</activity>
<activity
android:name=".FamilyActivity"
android:name=".activity.FamilyActivity"
android:label="@string/category_family"
android:parentActivityName=".MainActivity">
android:parentActivityName=".activity.CategoryActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
android:value=".activity.CategoryActivity"/>
</activity>
<activity
android:name=".ColorsActivity"
android:name=".activity.ColorsActivity"
android:label="@string/category_colors"
android:parentActivityName=".MainActivity">
android:parentActivityName=".activity.CategoryActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
android:value=".activity.CategoryActivity"/>
</activity>
<activity
android:name=".PhrasesActivity"
android:name=".activity.PhrasesActivity"
android:label="@string/category_phrases"
android:parentActivityName=".MainActivity">
android:parentActivityName=".activity.CategoryActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
android:value=".activity.CategoryActivity"/>
</activity>
</application>

Expand Down
28 changes: 0 additions & 28 deletions app/src/main/java/com/example/android/miwok/ColorsActivity.java

This file was deleted.

28 changes: 0 additions & 28 deletions app/src/main/java/com/example/android/miwok/FamilyActivity.java

This file was deleted.

28 changes: 0 additions & 28 deletions app/src/main/java/com/example/android/miwok/NumbersActivity.java

This file was deleted.

28 changes: 0 additions & 28 deletions app/src/main/java/com/example/android/miwok/PhrasesActivity.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,86 +13,73 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.miwok;
package com.example.android.miwok.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
import com.example.android.miwok.R;

public class CategoryActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Set the content of the activity to use the activity_main.xml layout file
setContentView(R.layout.activity_main);

// Set the content of the activity to use the activity_category.xml.xml layout file
setContentView(R.layout.activity_category);
// Find the View that shows the numbers category
TextView numbers = (TextView) findViewById(R.id.numbers);

// Set a click listener on that View
TextView numbers = findViewById(R.id.numbers);
numbers.setOnClickListener(new OnClickListener() {
// The code in this method will be executed when the numbers category is clicked on.
@Override
public void onClick(View view) {
// Create a new intent to open the {@link NumbersActivity}
Intent numbersIntent = new Intent(MainActivity.this, NumbersActivity.class);

// Start the new activity
startActivity(numbersIntent);
openActivity(CategoryActivity.this, NumbersActivity.class);
}
});

// Find the View that shows the family category
TextView family = (TextView) findViewById(R.id.family);

// Set a click listener on that View
TextView family = findViewById(R.id.family);
family.setOnClickListener(new OnClickListener() {
// The code in this method will be executed when the family category is clicked on.
@Override
public void onClick(View view) {
// Create a new intent to open the {@link FamilyActivity}
Intent familyIntent = new Intent(MainActivity.this, FamilyActivity.class);

// Start the new activity
startActivity(familyIntent);
openActivity(CategoryActivity.this, FamilyActivity.class);
}
});

// Find the View that shows the colors category
TextView colors = (TextView) findViewById(R.id.colors);

// Set a click listener on that View
TextView colors = findViewById(R.id.colors);
colors.setOnClickListener(new OnClickListener() {
// The code in this method will be executed when the colors category is clicked on.
@Override
public void onClick(View view) {
// Create a new intent to open the {@link ColorsActivity}
Intent colorsIntent = new Intent(MainActivity.this, ColorsActivity.class);

// Start the new activity
startActivity(colorsIntent);
openActivity(CategoryActivity.this, ColorsActivity.class);
}
});

// Find the View that shows the phrases category
TextView phrases = (TextView) findViewById(R.id.phrases);

// Set a click listener on that View
TextView phrases = findViewById(R.id.phrases);
phrases.setOnClickListener(new OnClickListener() {
// The code in this method will be executed when the phrases category is clicked on.
@Override
public void onClick(View view) {
// Create a new intent to open the {@link PhrasesActivity}
Intent phrasesIntent = new Intent(MainActivity.this, PhrasesActivity.class);

// Start the new activity
startActivity(phrasesIntent);
openActivity(CategoryActivity.this, PhrasesActivity.class);
}
});
}

/**
* This method will be responsible for opening a new activity
*
* @param packageContext is the current package for {@link CategoryActivity}
* @param cls is the activity needed to be opened.
*/
private void openActivity(Context packageContext, Class<?> cls) {
Intent intent = new Intent(packageContext, cls);
startActivity(intent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.miwok.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;

import com.example.android.miwok.R;
import com.example.android.miwok.adapter.WordAdapter;
import com.example.android.miwok.model.Word;

import java.util.ArrayList;

public class ColorsActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_content);

// Create a list of words
ArrayList<Word> words = new ArrayList<>();
words.add(new Word("red", "weṭeṭṭi", R.drawable.color_red));
words.add(new Word("mustard yellow", "chiwiiṭә", R.drawable.color_mustard_yellow));
words.add(new Word("dusty yellow", "ṭopiisә", R.drawable.color_dusty_yellow));
words.add(new Word("green", "chokokki", R.drawable.color_green));
words.add(new Word("brown", "ṭakaakki", R.drawable.color_brown));
words.add(new Word("gray", "ṭopoppi", R.drawable.color_gray));
words.add(new Word("black", "kululli", R.drawable.color_black));
words.add(new Word("white", "kelelli", R.drawable.color_white));

// Create an {@link WordAdapter}, whose data source is a list of {@link Word}s. The
// adapter knows how to create list items for each item in the list.
WordAdapter adapter = new WordAdapter(this, words,R.color.category_colors);

// Find the {@link ListView} object in the view hierarchy of the {@link Activity}.
// There should be a {@link ListView} with the view ID called list, which is declared in the
// word_list.xml layout file.
// Find The View That Shows The Item List For The Phrases
ListView itemList = findViewById(R.id.item_list_view);
itemList.setAdapter(adapter);
}
}
Loading

0 comments on commit 6f9e945

Please sign in to comment.