This include .java and .xml files that shows how android interact with its resources to work with the phone
<?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:orientation="vertical" android:layout_width="match_parent"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
android:id="@+id/custom_list_item"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="lutti"
android:id="@+id/miwok_text_view"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
tools:text="one"
android:id="@+id/default_text_view"/>
</LinearLayout>
package com.example.android.miwok;
import android.app.Activity;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;
/**
* Created by rober on 12/31/2017.
*/
public class WordAdapter extends ArrayAdapter<Word> {
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View listItemView = convertView;
if(listItemView == null){
listItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
}
// Get the {@link AndroidWord} object located at this position in the list
Word currentAndroiWord = getItem(position);
// Find the TextView in the list_item.xml layout with the ID version_name
TextView miwokTextView = (TextView) listItemView.findViewById(R.id.miwok_text_view);
// Get the version name from the current AndroidWord object and
// set this text on the name TextView
miwokTextView.setText(currentAndroiWord.getMiwokTranslation());
// Find the TextView in the list_item.xml layout with the ID version_number
TextView defaultTextView = (TextView) listItemView.findViewById(R.id.default_text_view);
// Get the version number from the current AndroidWord object and
// set this text on the number TextView
defaultTextView.setText(currentAndroiWord.getDefaultTranslation());
return listItemView;
//return super.getView(position, convertView, parent);
}
public WordAdapter(Activity context, Word[] words){
super(context, 0, words);
}
}
<?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.
-->
<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="match_parent"
android:background="@color/tan_background"
android:orientation="vertical"
tools:context="com.example.android.miwok.MainActivity">
<TextView
android:id="@+id/numbers"
style="@style/CategoryStyle"
android:background="@color/category_numbers"
android:text="@string/category_numbers" />
<TextView
android:id="@+id/family"
style="@style/CategoryStyle"
android:background="@color/category_family"
android:text="@string/category_family" />
<TextView
android:id="@+id/colors"
style="@style/CategoryStyle"
android:background="@color/category_colors"
android:text="@string/category_colors" />
<TextView
android:id="@+id/phrases"
style="@style/CategoryStyle"
android:background="@color/category_phrases"
android:text="@string/category_phrases" />
<TextView
android:id="@+id/body"
android:layout_width="match_parent"
android:layout_height="81dp"
android:autoText="false"
android:background="@android:color/darker_gray"
android:gravity="center_vertical|fill_vertical|center_horizontal"
android:text="@string/category_body"
android:textAppearance="@style/TextAppearance.AppCompat.Display1" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.miwok.BodyActivity">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/editText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintBottom_toTopOf="@+id/btn1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/progressBar" />
</android.support.constraint.ConstraintLayout>
<?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.
-->
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/numberView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.example.android.miwok.NumbersActivity">
</ListView>
/*
* 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;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.lang.reflect.Array;
import java.util.Arrays;
public class NumbersActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// this part is pre-added to set which xml file acts as layout for this activity
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_numbers);
// just create an array of words
String[] words = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"}; // new String[10];
// this uses a method to save memory by recycling views and only load the views that are visible, it means, on-demand
ArrayAdapter<String> itemAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, words);
ListView listView = (ListView) findViewById(R.id.numberView);
listView.setAdapter(itemAdapter);
// this commented code display a list in a linear layout but should only be used if we won't need to scroll to see more items
/*LinearLayout numberView = (LinearLayout) findViewById(R.id.numberView);
for (String word: words) {
TextView text = new TextView(this);
text.setText(word);
numberView.addView(text);
}*/
}
}
package com.example.android.miwok;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class BodyActivity extends AppCompatActivity {
private int plus = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_body);
// sets a onclick event on a button. Objects are searched by their id usin "R.id.objectId"
Button btn1 = (Button)findViewById(R.id.btn1);
btn1.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
// callImplicitIntent();
Log.v("BodyActivity", "current plus value is " + plus);
++plus;
}
});
}
public void callImplicitIntent(){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
if(intent.resolveActivity(getPackageManager()) != null){
startActivity(intent);
}
}
}
<?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.
-->
<resources>
<!-- Primary color of the app (shown in the app bar) -->
<color name="primary_color">#4A312A</color>
<!-- Primary dark color of the app (shown in the status bar) -->
<color name="primary_dark_color">#2F1D1A</color>
<!-- Background color for app -->
<color name="tan_background">#fff7da</color>
<!-- Background color for the numbers category -->
<color name="category_numbers">#FD8E09</color>
<!-- Background color for the family members category -->
<color name="category_family">#379237</color>
<!-- Background color for the colors category -->
<color name="category_colors">#8800A0</color>
<!-- Background color for the phrases category -->
<color name="category_phrases">#16AFCA</color>
</resources>
<!-- 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.
-->
<resources>
<!-- Title for the application. [CHAR LIMIT=12] -->
<string name="app_name">Miwok</string>
<!-- Category name for phrases [CHAR LIMIT=20] -->
<string name="category_phrases">Phrases</string>
<!-- Category name for the vocabulary words for colors [CHAR LIMIT=20] -->
<string name="category_colors">Colors</string>
<!-- Category name for the vocabulary words for numbers [CHAR LIMIT=20] -->
<string name="category_numbers">Numbers</string>
<!-- Category name for the vocabulary words for family members [CHAR LIMIT=20] -->
<string name="category_family">Family Members</string>
<string name="category_body">Body</string>
</resources>
<?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">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".NumbersActivity"
android:label="@string/category_numbers"
android:parentActivityName=".MainActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".FamilyActivity"
android:label="@string/category_family"
android:parentActivityName=".MainActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".ColorsActivity"
android:label="@string/category_colors"
android:parentActivityName=".MainActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".PhrasesActivity"
android:label="@string/category_phrases"
android:parentActivityName=".MainActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".BodyActivity"
android:label="@string/category_body"
android:parentActivityName=".MainActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
</manifest>
/*
* 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;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.TextureView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class MainActivity 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);
// Find the View that shows the numbers category
TextView numbers = (TextView) findViewById(R.id.numbers);
// Set a click listener on that View
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);
}
});
// Find the View that shows the family category
TextView family = (TextView) findViewById(R.id.family);
// Set a click listener on that View
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);
}
});
// Find the View that shows the colors category
TextView colors = (TextView) findViewById(R.id.colors);
// Set a click listener on that View
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);
}
});
// Find the View that shows the phrases category
TextView phrases = (TextView) findViewById(R.id.phrases);
// Set a click listener on that View
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);
}
});
TextView body = (TextView) findViewById(R.id.body);
body.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent bodyIntent = new Intent(MainActivity.this, BodyActivity.class);
startActivity(bodyIntent);
}
});
}
}