diff --git a/.gitignore b/.gitignore index e77debe72..ab375b2ab 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,10 @@ /build /gradle /captures +.idea +build/ +.DS_Store +*.iml +*.apk +*.aar +*.zip diff --git a/build.gradle b/build.gradle index e4873fbe3..286338a08 100644 --- a/build.gradle +++ b/build.gradle @@ -2,11 +2,13 @@ // vim: ts=4 sts=4 sw=4 expandtab buildscript { + ext.kotlin_version = '1.1.4-2' repositories { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.0.0-beta2' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/mobile/build.gradle b/mobile/build.gradle index 413448435..5a890c681 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -1,12 +1,14 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 26 - buildToolsVersion "26.0.0" + buildToolsVersion '26.0.1' defaultConfig { applicationId "com.example.android.apis" - minSdkVersion 15 + minSdkVersion 23 targetSdkVersion 26 versionCode 1 versionName "1.0" @@ -25,6 +27,10 @@ android { dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:support-v4:26.0.0-beta2' - compile 'com.android.support:appcompat-v7:26.0.0-beta2' + compile 'com.android.support:support-v4:26.0.1' + compile 'com.android.support:appcompat-v7:26.0.1' + compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" +} +repositories { + mavenCentral() } diff --git a/mobile/src/main/java/com/example/android/apis/view/Animation1.java b/mobile/src/main/java/com/example/android/apis/view/Animation1.kt similarity index 50% rename from mobile/src/main/java/com/example/android/apis/view/Animation1.java rename to mobile/src/main/java/com/example/android/apis/view/Animation1.kt index 73563f310..43861a55b 100644 --- a/mobile/src/main/java/com/example/android/apis/view/Animation1.java +++ b/mobile/src/main/java/com/example/android/apis/view/Animation1.kt @@ -14,32 +14,29 @@ * limitations under the License. */ -package com.example.android.apis.view; +package com.example.android.apis.view // Need the following import to get access to the app resources, since this // class is in a sub-package. -import com.example.android.apis.R; +import com.example.android.apis.R -import android.app.Activity; -import android.os.Bundle; -import android.view.View; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; +import android.app.Activity +import android.os.Bundle +import android.view.View +import android.view.animation.AnimationUtils +import kotlinx.android.synthetic.main.animation_1.* -public class Animation1 extends Activity implements View.OnClickListener { +class Animation1 : Activity(), View.OnClickListener { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.animation_1); - - View loginButton = findViewById(R.id.login); - loginButton.setOnClickListener(this); + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.animation_1) + login.setOnClickListener(this) } - public void onClick(View v) { - Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake); - findViewById(R.id.pw).startAnimation(shake); + override fun onClick(v: View) { + val shake = AnimationUtils.loadAnimation(this, R.anim.shake) + pw.startAnimation(shake) } } diff --git a/mobile/src/main/java/com/example/android/apis/view/Animation2.java b/mobile/src/main/java/com/example/android/apis/view/Animation2.java deleted file mode 100644 index 041794e0e..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/Animation2.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2007 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.apis.view; - -// Need the following import to get access to the app resources, since this -// class is in a sub-package. -import com.example.android.apis.R; - -import android.app.Activity; -import android.os.Bundle; -import android.view.View; -import android.view.animation.AnimationUtils; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.Spinner; -import android.widget.ViewFlipper; - - -public class Animation2 extends Activity implements - AdapterView.OnItemSelectedListener { - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.animation_2); - - mFlipper = ((ViewFlipper) this.findViewById(R.id.flipper)); - mFlipper.startFlipping(); - - Spinner s = (Spinner) findViewById(R.id.spinner); - ArrayAdapter adapter = new ArrayAdapter(this, - android.R.layout.simple_spinner_item, mStrings); - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - s.setAdapter(adapter); - s.setOnItemSelectedListener(this); - } - - public void onItemSelected(AdapterView parent, View v, int position, long id) { - switch (position) { - - case 0: - mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, - R.anim.push_up_in)); - mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, - R.anim.push_up_out)); - break; - case 1: - mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, - R.anim.push_left_in)); - mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, - R.anim.push_left_out)); - break; - case 2: - mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, - android.R.anim.fade_in)); - mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, - android.R.anim.fade_out)); - break; - default: - mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, - R.anim.hyperspace_in)); - mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, - R.anim.hyperspace_out)); - break; - } - } - - public void onNothingSelected(AdapterView parent) { - } - - private String[] mStrings = { - "Push up", "Push left", "Cross fade", "Hyperspace"}; - - private ViewFlipper mFlipper; - -} diff --git a/mobile/src/main/java/com/example/android/apis/view/Animation2.kt b/mobile/src/main/java/com/example/android/apis/view/Animation2.kt new file mode 100644 index 000000000..d9eb6077b --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/Animation2.kt @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2007 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.apis.view + +// Need the following import to get access to the app resources, since this +// class is in a sub-package. +import com.example.android.apis.R + +import android.app.Activity +import android.os.Bundle +import android.view.View +import android.view.animation.AnimationUtils +import android.widget.AdapterView +import android.widget.ArrayAdapter +import android.widget.ViewFlipper +import kotlinx.android.synthetic.main.animation_2.* + + +class Animation2 : Activity(), AdapterView.OnItemSelectedListener { + + private val mStrings = arrayOf("Push up", "Push left", "Cross fade", "Hyperspace") + + lateinit private var mFlipper: ViewFlipper + + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.animation_2) + + mFlipper = this.flipper + mFlipper.startFlipping() + + ArrayAdapter(this, + android.R.layout.simple_spinner_item, mStrings).let { + it.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) + spinner.run { + adapter = it + onItemSelectedListener = this@Animation2 + } + } + } + + override fun onItemSelected(parent: AdapterView<*>, v: View, position: Int, id: Long) { + val (inAnim, outAnim) = when (position) { + + 0 -> { + arrayOf(AnimationUtils.loadAnimation(this, R.anim.push_up_in) + , AnimationUtils.loadAnimation(this, R.anim.push_up_out)) + } + 1 -> { + arrayOf(AnimationUtils.loadAnimation(this, R.anim.push_left_in) + , AnimationUtils.loadAnimation(this, R.anim.push_left_out)) + } + 2 -> { + arrayOf(AnimationUtils.loadAnimation(this, android.R.anim.fade_in) + , AnimationUtils.loadAnimation(this, android.R.anim.fade_out)) + } + else -> { + arrayOf(AnimationUtils.loadAnimation(this, R.anim.hyperspace_in) + , AnimationUtils.loadAnimation(this, R.anim.hyperspace_out)) + } + } + mFlipper.inAnimation = inAnim + mFlipper.outAnimation = outAnim + } + + override fun onNothingSelected(parent: AdapterView<*>) {} +} diff --git a/mobile/src/main/java/com/example/android/apis/view/Animation3.java b/mobile/src/main/java/com/example/android/apis/view/Animation3.java deleted file mode 100644 index 2cd760579..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/Animation3.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2009 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.apis.view; - -// Need the following import to get access to the app resources, since this -// class is in a sub-package. -import com.example.android.apis.R; - -import android.app.Activity; -import android.os.Bundle; -import android.view.View; -import android.view.animation.AnimationUtils; -import android.view.animation.Animation; -import android.view.animation.TranslateAnimation; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.Spinner; - -public class Animation3 extends Activity implements AdapterView.OnItemSelectedListener { - private static final String[] INTERPOLATORS = { - "Accelerate", "Decelerate", "Accelerate/Decelerate", - "Anticipate", "Overshoot", "Anticipate/Overshoot", - "Bounce" - }; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.animation_3); - - Spinner s = (Spinner) findViewById(R.id.spinner); - ArrayAdapter adapter = new ArrayAdapter(this, - android.R.layout.simple_spinner_item, INTERPOLATORS); - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - s.setAdapter(adapter); - s.setOnItemSelectedListener(this); - } - - public void onItemSelected(AdapterView parent, View v, int position, long id) { - final View target = findViewById(R.id.target); - final View targetParent = (View) target.getParent(); - - Animation a = new TranslateAnimation(0.0f, - targetParent.getWidth() - target.getWidth() - targetParent.getPaddingLeft() - - targetParent.getPaddingRight(), 0.0f, 0.0f); - a.setDuration(1000); - a.setStartOffset(300); - a.setRepeatMode(Animation.RESTART); - a.setRepeatCount(Animation.INFINITE); - - switch (position) { - case 0: - a.setInterpolator(AnimationUtils.loadInterpolator(this, - android.R.anim.accelerate_interpolator)); - break; - case 1: - a.setInterpolator(AnimationUtils.loadInterpolator(this, - android.R.anim.decelerate_interpolator)); - break; - case 2: - a.setInterpolator(AnimationUtils.loadInterpolator(this, - android.R.anim.accelerate_decelerate_interpolator)); - break; - case 3: - a.setInterpolator(AnimationUtils.loadInterpolator(this, - android.R.anim.anticipate_interpolator)); - break; - case 4: - a.setInterpolator(AnimationUtils.loadInterpolator(this, - android.R.anim.overshoot_interpolator)); - break; - case 5: - a.setInterpolator(AnimationUtils.loadInterpolator(this, - android.R.anim.anticipate_overshoot_interpolator)); - break; - case 6: - a.setInterpolator(AnimationUtils.loadInterpolator(this, - android.R.anim.bounce_interpolator)); - break; - } - - target.startAnimation(a); - } - - public void onNothingSelected(AdapterView parent) { - } -} \ No newline at end of file diff --git a/mobile/src/main/java/com/example/android/apis/view/Animation3.kt b/mobile/src/main/java/com/example/android/apis/view/Animation3.kt new file mode 100644 index 000000000..5b6dcda9d --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/Animation3.kt @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2009 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.apis.view + +// Need the following import to get access to the app resources, since this +// class is in a sub-package. +import com.example.android.apis.R + +import android.app.Activity +import android.os.Bundle +import android.view.View +import android.view.animation.AnimationUtils +import android.view.animation.Animation +import android.view.animation.TranslateAnimation +import android.widget.AdapterView +import android.widget.ArrayAdapter +import kotlinx.android.synthetic.main.animation_3.* + +class Animation3 : Activity(), AdapterView.OnItemSelectedListener { + + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.animation_3) + + ArrayAdapter(this, + android.R.layout.simple_spinner_item, INTERPOLATORS).let { + it.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) + spinner.run { + adapter = it + onItemSelectedListener = this@Animation3 + } + } + } + + override fun onItemSelected(parent: AdapterView<*>, v: View, position: Int, id: Long) { + val targetParent = target.run { parent } + + val animation = TranslateAnimation(0.0f, + (targetParent.width - target.width - targetParent.paddingLeft - + targetParent.paddingRight).toFloat(), 0.0f, 0.0f).apply { + duration = 1000 + startOffset = 300 + repeatMode = Animation.RESTART + repeatCount = Animation.INFINITE + } + + animation.interpolator = when (position) { + 0 -> AnimationUtils.loadInterpolator(this, + android.R.anim.accelerate_interpolator) + 1 -> AnimationUtils.loadInterpolator(this, + android.R.anim.decelerate_interpolator) + 2 -> AnimationUtils.loadInterpolator(this, + android.R.anim.accelerate_decelerate_interpolator) + 3 -> AnimationUtils.loadInterpolator(this, + android.R.anim.anticipate_interpolator) + 4 -> AnimationUtils.loadInterpolator(this, + android.R.anim.overshoot_interpolator) + 5 -> AnimationUtils.loadInterpolator(this, + android.R.anim.anticipate_overshoot_interpolator) + else -> AnimationUtils.loadInterpolator(this, + android.R.anim.bounce_interpolator) + } + + target.startAnimation(animation) + } + + override fun onNothingSelected(parent: AdapterView<*>) {} + + companion object { + private val INTERPOLATORS = arrayOf("Accelerate", "Decelerate", + "Accelerate/Decelerate", "Anticipate", "Overshoot", "Anticipate/Overshoot", + "Bounce") + } +} \ No newline at end of file diff --git a/mobile/src/main/java/com/example/android/apis/view/AutoComplete1.java b/mobile/src/main/java/com/example/android/apis/view/AutoComplete1.java deleted file mode 100644 index a13a742ba..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/AutoComplete1.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2007 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.apis.view; - -import com.example.android.apis.R; - -import android.app.Activity; -import android.widget.ArrayAdapter; -import android.widget.AutoCompleteTextView; -import android.os.Bundle; - -public class AutoComplete1 extends Activity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.autocomplete_1); - - ArrayAdapter adapter = new ArrayAdapter(this, - android.R.layout.simple_dropdown_item_1line, COUNTRIES); - AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.edit); - textView.setAdapter(adapter); - } - - static final String[] COUNTRIES = new String[] { - "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", - "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", - "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", - "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", - "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", - "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", - "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burundi", - "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde", - "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", - "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", - "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia", - "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic", - "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", - "Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland", - "Former Yugoslav Republic of Macedonia", "France", "French Guiana", "French Polynesia", - "French Southern Territories", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar", - "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", - "Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary", - "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", - "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos", - "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", - "Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", - "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova", - "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", - "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", - "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Marianas", - "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", - "Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar", - "Reunion", "Romania", "Russia", "Rwanda", "Sqo Tome and Principe", "Saint Helena", - "Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon", - "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Saudi Arabia", "Senegal", - "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", - "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Korea", - "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden", - "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas", - "The Gambia", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", - "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Virgin Islands", "Uganda", - "Ukraine", "United Arab Emirates", "United Kingdom", - "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", - "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara", - "Yemen", "Yugoslavia", "Zambia", "Zimbabwe" - }; -} diff --git a/mobile/src/main/java/com/example/android/apis/view/AutoComplete1.kt b/mobile/src/main/java/com/example/android/apis/view/AutoComplete1.kt new file mode 100644 index 000000000..865e333bd --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/AutoComplete1.kt @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2007 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.apis.view + +import android.app.Activity +import android.os.Bundle +import android.widget.ArrayAdapter +import com.example.android.apis.R +import kotlinx.android.synthetic.main.autocomplete_1.* + +class AutoComplete1 : Activity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.autocomplete_1) + + val adapter = ArrayAdapter(this, + android.R.layout.simple_dropdown_item_1line, COUNTRIES) + edit.setAdapter(adapter) + } + + companion object { + + val COUNTRIES = arrayOf("Afghanistan", "Albania", "Algeria", + "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", + "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", + "Azerbaijan", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", + "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", + "Bouvet Island", "Brazil", "British Indian Ocean Territory", + "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", + "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde", + "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", + "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", + "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia", + "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", + "Dominican Republic", "East Timor", "Ecuador", "Egypt", "El Salvador", + "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Faeroe Islands", + "Falkland Islands", "Fiji", "Finland", "Former Yugoslav Republic of Macedonia", + "France", "French Guiana", "French Polynesia", "French Southern Territories", + "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", + "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", + "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary", + "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", + "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", + "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", + "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Madagascar", "Malawi", + "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", + "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova", "Monaco", + "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", + "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", + "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", + "Northern Marianas", "Norway", "Oman", "Pakistan", "Palau", "Panama", + "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn Islands", + "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russia", + "Rwanda", "Sqo Tome and Principe", "Saint Helena", "Saint Kitts and Nevis", + "Saint Lucia", "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", + "Samoa", "San Marino", "Saudi Arabia", "Senegal", "Seychelles", "Sierra Leone", + "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", + "South Georgia and the South Sandwich Islands", "South Korea", "Spain", "Sri Lanka", + "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", + "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas", "The Gambia" + , "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", + "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Virgin Islands", "Uganda", + "Ukraine", "United Arab Emirates", "United Kingdom", "United States", + "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", + "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara", + "Yemen", "Yugoslavia", "Zambia", "Zimbabwe") + } +} diff --git a/mobile/src/main/java/com/example/android/apis/view/AutoComplete2.java b/mobile/src/main/java/com/example/android/apis/view/AutoComplete2.java deleted file mode 100644 index 2dcfc129d..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/AutoComplete2.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2007 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.apis.view; - -import com.example.android.apis.R; - -import android.app.Activity; -import android.os.Bundle; -import android.widget.ArrayAdapter; -import android.widget.AutoCompleteTextView; - - -public class AutoComplete2 extends Activity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.autocomplete_2); - - ArrayAdapter adapter = new ArrayAdapter(this, - android.R.layout.simple_dropdown_item_1line, - AutoComplete1.COUNTRIES); - AutoCompleteTextView textView = (AutoCompleteTextView) - findViewById(R.id.edit); - textView.setAdapter(adapter); - } -} diff --git a/mobile/src/main/java/com/example/android/apis/view/AutoComplete2.kt b/mobile/src/main/java/com/example/android/apis/view/AutoComplete2.kt new file mode 100644 index 000000000..3e492f431 --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/AutoComplete2.kt @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2007 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.apis.view + +import com.example.android.apis.R + +import android.app.Activity +import android.os.Bundle +import android.widget.ArrayAdapter +import kotlinx.android.synthetic.main.autocomplete_2.* + + +class AutoComplete2 : Activity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.autocomplete_2) + + val adapter = ArrayAdapter(this, + android.R.layout.simple_dropdown_item_1line, + AutoComplete1.COUNTRIES) + edit.setAdapter(adapter) + } +} diff --git a/mobile/src/main/java/com/example/android/apis/view/AutoComplete3.java b/mobile/src/main/java/com/example/android/apis/view/AutoComplete3.java deleted file mode 100644 index bb9408f37..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/AutoComplete3.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2007 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.apis.view; - -import com.example.android.apis.R; - -import android.app.Activity; -import android.os.Bundle; -import android.widget.ArrayAdapter; -import android.widget.AutoCompleteTextView; - - -public class AutoComplete3 extends Activity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.autocomplete_3); - - ArrayAdapter adapter = new ArrayAdapter(this, - android.R.layout.simple_dropdown_item_1line, - AutoComplete1.COUNTRIES); - AutoCompleteTextView textView = (AutoCompleteTextView) - findViewById(R.id.edit); - textView.setAdapter(adapter); - textView = (AutoCompleteTextView) findViewById(R.id.edit2); - textView.setAdapter(adapter); - } -} diff --git a/mobile/src/main/java/com/example/android/apis/view/AutoComplete3.kt b/mobile/src/main/java/com/example/android/apis/view/AutoComplete3.kt new file mode 100644 index 000000000..52e9a2505 --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/AutoComplete3.kt @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2007 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.apis.view + +import com.example.android.apis.R + +import android.app.Activity +import android.os.Bundle +import android.widget.ArrayAdapter +import kotlinx.android.synthetic.main.autocomplete_3.* + + +class AutoComplete3 : Activity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.autocomplete_3) + + val adapter = ArrayAdapter(this, + android.R.layout.simple_dropdown_item_1line, + AutoComplete1.COUNTRIES) + edit.setAdapter(adapter) + edit2.setAdapter(adapter) + } +} diff --git a/mobile/src/main/java/com/example/android/apis/view/AutoComplete4.java b/mobile/src/main/java/com/example/android/apis/view/AutoComplete4.java deleted file mode 100644 index 3d63a9183..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/AutoComplete4.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2007 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.apis.view; - -import com.example.android.apis.R; - -import android.app.Activity; -import android.content.ContentResolver; -import android.content.Context; -import android.database.Cursor; -import android.net.Uri; -import android.os.Bundle; -import android.provider.ContactsContract.Contacts; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AutoCompleteTextView; -import android.widget.CursorAdapter; -import android.widget.FilterQueryProvider; -import android.widget.Filterable; -import android.widget.TextView; - -public class AutoComplete4 extends Activity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.autocomplete_4); - - ContentResolver content = getContentResolver(); - Cursor cursor = content.query(Contacts.CONTENT_URI, - CONTACT_PROJECTION, null, null, null); - - ContactListAdapter adapter = new ContactListAdapter(this, cursor); - - AutoCompleteTextView textView = (AutoCompleteTextView) - findViewById(R.id.edit); - textView.setAdapter(adapter); - } - - // XXX compiler bug in javac 1.5.0_07-164, we need to implement Filterable - // to make compilation work - public static class ContactListAdapter extends CursorAdapter implements Filterable { - public ContactListAdapter(Context context, Cursor c) { - super(context, c); - mContent = context.getContentResolver(); - } - - @Override - public View newView(Context context, Cursor cursor, ViewGroup parent) { - final LayoutInflater inflater = LayoutInflater.from(context); - final TextView view = (TextView) inflater.inflate( - android.R.layout.simple_dropdown_item_1line, parent, false); - view.setText(cursor.getString(COLUMN_DISPLAY_NAME)); - return view; - } - - @Override - public void bindView(View view, Context context, Cursor cursor) { - ((TextView) view).setText(cursor.getString(COLUMN_DISPLAY_NAME)); - } - - @Override - public String convertToString(Cursor cursor) { - return cursor.getString(COLUMN_DISPLAY_NAME); - } - - @Override - public Cursor runQueryOnBackgroundThread(CharSequence constraint) { - FilterQueryProvider filter = getFilterQueryProvider(); - if (filter != null) { - return filter.runQuery(constraint); - } - - Uri uri = Uri.withAppendedPath( - Contacts.CONTENT_FILTER_URI, - Uri.encode(constraint.toString())); - return mContent.query(uri, CONTACT_PROJECTION, null, null, null); - } - - private ContentResolver mContent; - } - - public static final String[] CONTACT_PROJECTION = new String[] { - Contacts._ID, - Contacts.DISPLAY_NAME - }; - - private static final int COLUMN_DISPLAY_NAME = 1; -} \ No newline at end of file diff --git a/mobile/src/main/java/com/example/android/apis/view/AutoComplete4.kt b/mobile/src/main/java/com/example/android/apis/view/AutoComplete4.kt new file mode 100644 index 000000000..5247ae966 --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/AutoComplete4.kt @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2007 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.apis.view + +import android.Manifest +import com.example.android.apis.R + +import android.app.Activity +import android.app.AlertDialog +import android.content.* +import android.content.pm.PackageManager +import android.database.Cursor +import android.net.Uri +import android.os.Bundle +import android.provider.ContactsContract +import android.provider.ContactsContract.Contacts +import android.provider.Settings +import android.support.v4.app.ActivityCompat +import android.support.v4.content.ContextCompat +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.* +import kotlinx.android.synthetic.main.autocomplete_4.* + +class AutoComplete4 : Activity() { + val contactPermission: ContactPermission = ContactPermission() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.autocomplete_4) + + contactPermission.checkPermission(this, this, edit, contentResolver) + } + + override fun onRequestPermissionsResult(requestCode: Int, + permissions: Array, grantResults: IntArray) { + when (requestCode) { + MY_PERMISSIONS_REQUEST_READ_CONTACTS -> { + // If request is cancelled, the result arrays are empty. + if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + // permission was granted, yay! Do the + // contacts-related task you need to do. + contactPermission.autoCompleteContacts(this, edit, contentResolver) + } else { + // permission denied, boo! Disable the + // functionality that depends on this permission. + showRequestAgainDialog() + } + return + } + }// other 'case' lines to check for other + // permissions this app might request + } + + /** + * When user denied READ_CONTACTS permission than show this dialog for persuasion. + */ + fun showRequestAgainDialog(): Unit { + val builder: AlertDialog.Builder = AlertDialog.Builder(this) + builder.setMessage(R.string.autocomplete_4_showRequestAgainDialog) + builder.setPositiveButton(R.string.autocomplete_4_setPositiveButton) { + _, _ -> + try { + val intent: Intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) + .setData(Uri.parse("package:" + packageName)) + startActivity(intent) + } catch (e: ActivityNotFoundException) { + e.printStackTrace() + val intent: Intent = Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS) + startActivity(intent) + } + } + builder.setNegativeButton(R.string.autocomplete_4_setNegativeButton) { + _, _ -> + finish() + } + builder.create() + builder.show() + } + + // XXX compiler bug in javac 1.5.0_07-164, we need to implement Filterable + // to make compilation work + class ContactListAdapter(context: Context, c: Cursor, flags: Int) : CursorAdapter(context, c, flags), Filterable { + private var mContent: ContentResolver = context.contentResolver + + override fun newView(context: Context, cursor: Cursor, parent: ViewGroup): View { + val inflater = LayoutInflater.from(context) + val view = inflater.inflate( + android.R.layout.simple_dropdown_item_1line, parent, false) as TextView + view.text = cursor.getString(COLUMN_DISPLAY_NAME) + return view + } + + override fun bindView(view: View, context: Context?, cursor: Cursor) { + (view as TextView).text = cursor.getString(COLUMN_DISPLAY_NAME) + } + + override fun convertToString(cursor: Cursor): String { + return cursor.getString(COLUMN_DISPLAY_NAME) + } + + override fun runQueryOnBackgroundThread(constraint: CharSequence?): Cursor { + val filter: FilterQueryProvider? = filterQueryProvider + if (filter != null) { + return if (constraint != null) filter.runQuery(constraint) else filter.runQuery("") + } + + val uri = Uri.withAppendedPath( + ContactsContract.Contacts.CONTENT_FILTER_URI, + Uri.encode(constraint.toString())) + return mContent.query(uri, CONTACT_PROJECTION, null, null, null) + } + } + + companion object { + val CONTACT_PROJECTION = arrayOf(ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME) + private val COLUMN_DISPLAY_NAME = 1 + val MY_PERMISSIONS_REQUEST_READ_CONTACTS = 1 + } +} \ No newline at end of file diff --git a/mobile/src/main/java/com/example/android/apis/view/AutoComplete5.java b/mobile/src/main/java/com/example/android/apis/view/AutoComplete5.java deleted file mode 100644 index 2009d8a20..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/AutoComplete5.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2007 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.apis.view; - -import com.example.android.apis.R; - -import android.app.Activity; -import android.content.ContentResolver; -import android.database.Cursor; -import android.os.Bundle; -import android.provider.ContactsContract.Contacts; -import android.widget.AutoCompleteTextView; - -public class AutoComplete5 extends Activity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.autocomplete_5); - - ContentResolver content = getContentResolver(); - Cursor cursor = content.query(Contacts.CONTENT_URI, - AutoComplete4.CONTACT_PROJECTION, null, null, null); - AutoComplete4.ContactListAdapter adapter = - new AutoComplete4.ContactListAdapter(this, cursor); - - AutoCompleteTextView textView = (AutoCompleteTextView) - findViewById(R.id.edit); - textView.setAdapter(adapter); - } -} \ No newline at end of file diff --git a/mobile/src/main/java/com/example/android/apis/view/AutoComplete5.kt b/mobile/src/main/java/com/example/android/apis/view/AutoComplete5.kt new file mode 100644 index 000000000..ff76cd649 --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/AutoComplete5.kt @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2007 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.apis.view + +import android.Manifest +import com.example.android.apis.R + +import android.app.Activity +import android.app.AlertDialog +import android.content.ActivityNotFoundException +import android.content.ContentResolver +import android.content.Context +import android.content.Intent +import android.content.pm.PackageManager +import android.database.Cursor +import android.net.Uri +import android.os.Bundle +import android.provider.ContactsContract.Contacts +import android.provider.Settings +import android.support.v4.app.ActivityCompat +import android.support.v4.content.ContextCompat +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.CursorAdapter +import android.widget.Filterable +import android.widget.TextView +import android.widget.Toast +import kotlinx.android.synthetic.main.autocomplete_5.* + +class AutoComplete5 : Activity() { + val contactPermission: ContactPermission = ContactPermission() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.autocomplete_5) + + contactPermission.checkPermission(this, this, edit, contentResolver) + } + + override fun onRequestPermissionsResult(requestCode: Int, + permissions: Array, grantResults: IntArray) { + when (requestCode) { + AutoComplete4.MY_PERMISSIONS_REQUEST_READ_CONTACTS -> { + // If request is cancelled, the result arrays are empty. + if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + // permission was granted, yay! Do the + // contacts-related task you need to do. + contactPermission.autoCompleteContacts(this, edit, contentResolver) + } else { + // permission denied, boo! Disable the + // functionality that depends on this permission. + showRequestAgainDialog() + } + return + } + }// other 'case' lines to check for other + // permissions this app might request + } + + /** + * When user denied READ_CONTACTS permission than show this dialog for persuasion. + */ + fun showRequestAgainDialog(): Unit { + val builder: AlertDialog.Builder = AlertDialog.Builder(this) + builder.setMessage(R.string.autocomplete_5_showRequestAgainDialog) + builder.setPositiveButton(R.string.autocomplete_5_setPositiveButton) { + _, _ -> + try { + val intent: Intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) + .setData(Uri.parse("package:" + packageName)) + startActivity(intent) + } catch (e: ActivityNotFoundException) { + e.printStackTrace() + val intent: Intent = Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS) + startActivity(intent) + } + } + builder.setNegativeButton(R.string.autocomplete_5_setNegativeButton) { + _, _ -> + finish() + } + builder.create() + builder.show() + } + +} \ No newline at end of file diff --git a/mobile/src/main/java/com/example/android/apis/view/AutoComplete6.java b/mobile/src/main/java/com/example/android/apis/view/AutoComplete6.java deleted file mode 100644 index 0d4b48ef5..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/AutoComplete6.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2007 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.apis.view; - -import com.example.android.apis.R; - -import android.app.Activity; -import android.widget.ArrayAdapter; -import android.widget.MultiAutoCompleteTextView; -import android.os.Bundle; - -public class AutoComplete6 extends Activity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.autocomplete_6); - - ArrayAdapter adapter = new ArrayAdapter(this, - android.R.layout.simple_dropdown_item_1line, COUNTRIES); - MultiAutoCompleteTextView textView = (MultiAutoCompleteTextView) findViewById(R.id.edit); - textView.setAdapter(adapter); - textView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); - } - - static final String[] COUNTRIES = new String[] { - "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", - "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", - "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", - "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", - "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", - "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", - "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burundi", - "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde", - "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", - "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", - "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia", - "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic", - "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", - "Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland", - "Former Yugoslav Republic of Macedonia", "France", "French Guiana", "French Polynesia", - "French Southern Territories", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar", - "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", - "Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary", - "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", - "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos", - "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", - "Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", - "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova", - "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", - "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", - "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Marianas", - "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", - "Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar", - "Reunion", "Romania", "Russia", "Rwanda", "Sqo Tome and Principe", "Saint Helena", - "Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon", - "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Saudi Arabia", "Senegal", - "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", - "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Korea", - "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden", - "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas", - "The Gambia", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", - "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Virgin Islands", "Uganda", - "Ukraine", "United Arab Emirates", "United Kingdom", - "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", - "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara", - "Yemen", "Yugoslavia", "Zambia", "Zimbabwe" - }; -} diff --git a/mobile/src/main/java/com/example/android/apis/view/AutoComplete6.kt b/mobile/src/main/java/com/example/android/apis/view/AutoComplete6.kt new file mode 100644 index 000000000..08d653e92 --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/AutoComplete6.kt @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2007 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.apis.view + +import com.example.android.apis.R + +import android.app.Activity +import android.widget.ArrayAdapter +import android.widget.MultiAutoCompleteTextView +import android.os.Bundle +import kotlinx.android.synthetic.main.autocomplete_6.* + +class AutoComplete6 : Activity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.autocomplete_6) + + val adapter = ArrayAdapter(this, + android.R.layout.simple_dropdown_item_1line, COUNTRIES) + + with(edit) { + setAdapter(adapter) + setTokenizer(MultiAutoCompleteTextView.CommaTokenizer()) + } + } + + companion object { + + internal val COUNTRIES = arrayOf("Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia", "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland", "Former Yugoslav Republic of Macedonia", "France", "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Marianas", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russia", "Rwanda", "Sqo Tome and Principe", "Saint Helena", "Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Saudi Arabia", "Senegal", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Korea", "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas", "The Gambia", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Virgin Islands", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara", "Yemen", "Yugoslavia", "Zambia", "Zimbabwe") + } +} diff --git a/mobile/src/main/java/com/example/android/apis/view/Baseline1.java b/mobile/src/main/java/com/example/android/apis/view/Baseline1.kt similarity index 67% rename from mobile/src/main/java/com/example/android/apis/view/Baseline1.java rename to mobile/src/main/java/com/example/android/apis/view/Baseline1.kt index c77b71f5a..70af15445 100644 --- a/mobile/src/main/java/com/example/android/apis/view/Baseline1.java +++ b/mobile/src/main/java/com/example/android/apis/view/Baseline1.kt @@ -14,22 +14,21 @@ * limitations under the License. */ -package com.example.android.apis.view; +package com.example.android.apis.view -import com.example.android.apis.R; +import com.example.android.apis.R -import android.app.Activity; -import android.os.Bundle; +import android.app.Activity +import android.os.Bundle /** * Baseline alignment in LinearLayout. */ -public class Baseline1 extends Activity { +class Baseline1 : Activity() { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.baseline_1); + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.baseline_1) } } diff --git a/mobile/src/main/java/com/example/android/apis/view/Baseline2.java b/mobile/src/main/java/com/example/android/apis/view/Baseline2.kt similarity index 67% rename from mobile/src/main/java/com/example/android/apis/view/Baseline2.java rename to mobile/src/main/java/com/example/android/apis/view/Baseline2.kt index 7189fe844..5da10dc58 100644 --- a/mobile/src/main/java/com/example/android/apis/view/Baseline2.java +++ b/mobile/src/main/java/com/example/android/apis/view/Baseline2.kt @@ -14,22 +14,21 @@ * limitations under the License. */ -package com.example.android.apis.view; +package com.example.android.apis.view -import com.example.android.apis.R; +import com.example.android.apis.R -import android.app.Activity; -import android.os.Bundle; +import android.app.Activity +import android.os.Bundle /** * Baseline alignment in LinearLayout with a BOTTOM gravity. */ -public class Baseline2 extends Activity { +class Baseline2 : Activity() { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.baseline_2); + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.baseline_2) } } diff --git a/mobile/src/main/java/com/example/android/apis/view/Baseline3.java b/mobile/src/main/java/com/example/android/apis/view/Baseline3.kt similarity index 70% rename from mobile/src/main/java/com/example/android/apis/view/Baseline3.java rename to mobile/src/main/java/com/example/android/apis/view/Baseline3.kt index 9261c5cfc..3cf94a868 100644 --- a/mobile/src/main/java/com/example/android/apis/view/Baseline3.java +++ b/mobile/src/main/java/com/example/android/apis/view/Baseline3.kt @@ -14,23 +14,22 @@ * limitations under the License. */ -package com.example.android.apis.view; +package com.example.android.apis.view -import com.example.android.apis.R; +import com.example.android.apis.R -import android.app.Activity; -import android.os.Bundle; +import android.app.Activity +import android.os.Bundle /** * Baseline alignement in LinearLayout with a center_vertical gravity. This sample shows that * using a center_vertical gravity disables baseline alignment. */ -public class Baseline3 extends Activity { +class Baseline3 : Activity() { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.baseline_3); + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.baseline_3) } } diff --git a/mobile/src/main/java/com/example/android/apis/view/Baseline4.java b/mobile/src/main/java/com/example/android/apis/view/Baseline4.kt similarity index 67% rename from mobile/src/main/java/com/example/android/apis/view/Baseline4.java rename to mobile/src/main/java/com/example/android/apis/view/Baseline4.kt index bedfde7e0..63351d6b3 100644 --- a/mobile/src/main/java/com/example/android/apis/view/Baseline4.java +++ b/mobile/src/main/java/com/example/android/apis/view/Baseline4.kt @@ -14,22 +14,21 @@ * limitations under the License. */ -package com.example.android.apis.view; +package com.example.android.apis.view -import com.example.android.apis.R; +import com.example.android.apis.R -import android.app.Activity; -import android.os.Bundle; +import android.app.Activity +import android.os.Bundle /** * Baseline alignment in LinearLayout with mixed gravities. */ -public class Baseline4 extends Activity { +class Baseline4 : Activity() { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.baseline_4); + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.baseline_4) } } diff --git a/mobile/src/main/java/com/example/android/apis/view/Baseline6.java b/mobile/src/main/java/com/example/android/apis/view/Baseline6.kt similarity index 67% rename from mobile/src/main/java/com/example/android/apis/view/Baseline6.java rename to mobile/src/main/java/com/example/android/apis/view/Baseline6.kt index e96e10af8..a0fddf76f 100644 --- a/mobile/src/main/java/com/example/android/apis/view/Baseline6.java +++ b/mobile/src/main/java/com/example/android/apis/view/Baseline6.kt @@ -14,22 +14,21 @@ * limitations under the License. */ -package com.example.android.apis.view; +package com.example.android.apis.view -import com.example.android.apis.R; +import com.example.android.apis.R -import android.app.Activity; -import android.os.Bundle; +import android.app.Activity +import android.os.Bundle /** * Baseline alignment in RelativeLayout. */ -public class Baseline6 extends Activity { +class Baseline6 : Activity() { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.baseline_6); + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.baseline_6) } } diff --git a/mobile/src/main/java/com/example/android/apis/view/Baseline7.java b/mobile/src/main/java/com/example/android/apis/view/Baseline7.kt similarity index 68% rename from mobile/src/main/java/com/example/android/apis/view/Baseline7.java rename to mobile/src/main/java/com/example/android/apis/view/Baseline7.kt index 1795e7d4f..10411bd5f 100644 --- a/mobile/src/main/java/com/example/android/apis/view/Baseline7.java +++ b/mobile/src/main/java/com/example/android/apis/view/Baseline7.kt @@ -14,22 +14,21 @@ * limitations under the License. */ -package com.example.android.apis.view; +package com.example.android.apis.view -import com.example.android.apis.R; +import com.example.android.apis.R -import android.app.Activity; -import android.os.Bundle; +import android.app.Activity +import android.os.Bundle /** * Baseline alignment in RelativeLayout with various font weights. */ -public class Baseline7 extends Activity { +class Baseline7 : Activity() { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.baseline_7); + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.baseline_7) } } diff --git a/mobile/src/main/java/com/example/android/apis/view/BaselineNested1.java b/mobile/src/main/java/com/example/android/apis/view/BaselineNested1.kt similarity index 64% rename from mobile/src/main/java/com/example/android/apis/view/BaselineNested1.java rename to mobile/src/main/java/com/example/android/apis/view/BaselineNested1.kt index ab7898cb2..ce002d27c 100644 --- a/mobile/src/main/java/com/example/android/apis/view/BaselineNested1.java +++ b/mobile/src/main/java/com/example/android/apis/view/BaselineNested1.kt @@ -14,23 +14,22 @@ * limitations under the License. */ -package com.example.android.apis.view; +package com.example.android.apis.view -import com.example.android.apis.R; +import com.example.android.apis.R -import android.app.Activity; -import android.os.Bundle; +import android.app.Activity +import android.os.Bundle /** * Baseline alignment includes elements within nested vertical - * {@link android.widget.LinearLayout}s. + * [android.widget.LinearLayout]s. */ -public class BaselineNested1 extends Activity { +class BaselineNested1 : Activity() { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) - setContentView(R.layout.baseline_nested_1); + setContentView(R.layout.baseline_nested_1) } } diff --git a/mobile/src/main/java/com/example/android/apis/view/BaselineNested2.java b/mobile/src/main/java/com/example/android/apis/view/BaselineNested2.kt similarity index 64% rename from mobile/src/main/java/com/example/android/apis/view/BaselineNested2.java rename to mobile/src/main/java/com/example/android/apis/view/BaselineNested2.kt index 1b2c5857b..ef239bd69 100644 --- a/mobile/src/main/java/com/example/android/apis/view/BaselineNested2.java +++ b/mobile/src/main/java/com/example/android/apis/view/BaselineNested2.kt @@ -14,23 +14,22 @@ * limitations under the License. */ -package com.example.android.apis.view; +package com.example.android.apis.view -import com.example.android.apis.R; +import com.example.android.apis.R -import android.app.Activity; -import android.os.Bundle; +import android.app.Activity +import android.os.Bundle /** * Baseline alignment includes an element within a nested horizontal - * {@link android.widget.LinearLayout}. + * [android.widget.LinearLayout]. */ -public class BaselineNested2 extends Activity { +class BaselineNested2 : Activity() { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) - setContentView(R.layout.baseline_nested_2); + setContentView(R.layout.baseline_nested_2) } } diff --git a/mobile/src/main/java/com/example/android/apis/view/BaselineNested3.java b/mobile/src/main/java/com/example/android/apis/view/BaselineNested3.java deleted file mode 100644 index 854a10fe2..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/BaselineNested3.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2007 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.apis.view; - -import com.example.android.apis.R; - -import android.app.Activity; -import android.os.Bundle; - -/** - * Baseline alignment includes a {@link android.widget.LinearLayout} - * within another {@link android.widget.LinearLayout}. - */ -public class BaselineNested3 extends Activity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.baseline_nested_3); - } -} diff --git a/mobile/src/main/java/com/example/android/apis/view/BaselineNested3.kt b/mobile/src/main/java/com/example/android/apis/view/BaselineNested3.kt new file mode 100644 index 000000000..85b3b99a4 --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/BaselineNested3.kt @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2007 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.apis.view + +import com.example.android.apis.R + +import android.app.Activity +import android.os.Bundle + +/** + * Baseline alignment includes a [android.widget.LinearLayout] + * within another [android.widget.LinearLayout]. + */ +class BaselineNested3 : Activity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContentView(R.layout.baseline_nested_3) + } +} diff --git a/mobile/src/main/java/com/example/android/apis/view/ContactPermission.kt b/mobile/src/main/java/com/example/android/apis/view/ContactPermission.kt new file mode 100644 index 000000000..452e281f9 --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/ContactPermission.kt @@ -0,0 +1,53 @@ +package com.example.android.apis.view + +import android.Manifest +import android.app.Activity +import android.content.ContentResolver +import android.content.Context +import android.content.pm.PackageManager +import android.provider.ContactsContract +import android.support.v4.app.ActivityCompat +import android.support.v4.content.ContextCompat +import android.widget.* + +class ContactPermission { + fun checkPermission(context: Context, activity: Activity, edit: AutoCompleteTextView, contentResolver: ContentResolver) { + // Here, thisActivity is the current activity + if (ContextCompat.checkSelfPermission(context, + Manifest.permission.READ_CONTACTS) + != PackageManager.PERMISSION_GRANTED) { + + // Should we show an explanation? + if (ActivityCompat.shouldShowRequestPermissionRationale(activity, + Manifest.permission.READ_CONTACTS)) { + + // Show an expanation to the user *asynchronously* -- don't block + // this thread waiting for the user's response! After the user + // sees the explanation, try again to request the permission. + ActivityCompat.requestPermissions(activity, + arrayOf(Manifest.permission.READ_CONTACTS), + AutoComplete4.MY_PERMISSIONS_REQUEST_READ_CONTACTS) + } else { + + // No explanation needed, we can request the permission. + ActivityCompat.requestPermissions(activity, + arrayOf(Manifest.permission.READ_CONTACTS), + AutoComplete4.MY_PERMISSIONS_REQUEST_READ_CONTACTS) + + // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an + // app-defined int constant. The callback method gets the + // result of the request. + } + } else { + autoCompleteContacts(context, edit, contentResolver) + } + } + + fun autoCompleteContacts(context: Context, edit: AutoCompleteTextView, contentResolver: ContentResolver) { + val content = contentResolver + val cursor = content.query(ContactsContract.Contacts.CONTENT_URI, + AutoComplete4.CONTACT_PROJECTION, null, null, null) + val adapter = AutoComplete4.ContactListAdapter(context, cursor, 0) + edit.setAdapter(adapter) + } +} \ No newline at end of file diff --git a/mobile/src/main/java/com/example/android/apis/view/LinearLayout9.java b/mobile/src/main/java/com/example/android/apis/view/LinearLayout9.kt similarity index 59% rename from mobile/src/main/java/com/example/android/apis/view/LinearLayout9.java rename to mobile/src/main/java/com/example/android/apis/view/LinearLayout9.kt index d120b1e76..320c80586 100644 --- a/mobile/src/main/java/com/example/android/apis/view/LinearLayout9.java +++ b/mobile/src/main/java/com/example/android/apis/view/LinearLayout9.kt @@ -14,28 +14,27 @@ * limitations under the License. */ -package com.example.android.apis.view; +package com.example.android.apis.view -import com.example.android.apis.R; +import com.example.android.apis.R -import android.app.Activity; -import android.os.Bundle; -import android.widget.ListView; -import android.widget.ArrayAdapter; +import android.app.Activity +import android.os.Bundle +import android.widget.ArrayAdapter +import kotlinx.android.synthetic.main.linear_layout_9.* /** * Demonstrates how the layout_weight attribute can shrink an element too big * to fit on screen. */ -public class LinearLayout9 extends Activity { +class LinearLayout9 : Activity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.linear_layout_9) + list.adapter = ArrayAdapter(this, + android.R.layout.simple_list_item_1, AutoComplete1.COUNTRIES) - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.linear_layout_9); - ListView list = (ListView) findViewById(R.id.list); - list.setAdapter(new ArrayAdapter(this, - android.R.layout.simple_list_item_1, AutoComplete1.COUNTRIES)); } } diff --git a/mobile/src/main/java/com/example/android/apis/view/List1.java b/mobile/src/main/java/com/example/android/apis/view/List1.kt similarity index 59% rename from mobile/src/main/java/com/example/android/apis/view/List1.java rename to mobile/src/main/java/com/example/android/apis/view/List1.kt index f103e51d5..5d0a5bb02 100644 --- a/mobile/src/main/java/com/example/android/apis/view/List1.java +++ b/mobile/src/main/java/com/example/android/apis/view/List1.kt @@ -14,29 +14,28 @@ * limitations under the License. */ -package com.example.android.apis.view; +package com.example.android.apis.view -import android.app.ListActivity; -import android.os.Bundle; -import android.widget.ArrayAdapter; +import android.app.ListActivity +import android.os.Bundle +import android.widget.ArrayAdapter /** - * A list view example where the + * A list view example where the * data for the list comes from an array of strings. */ -public class List1 extends ListActivity { +class List1 : ListActivity() { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) // Use an existing ListAdapter that will map an array // of strings to TextViews - setListAdapter(new ArrayAdapter(this, - android.R.layout.simple_list_item_1, mStrings)); - getListView().setTextFilterEnabled(true); + listAdapter = ArrayAdapter(this, + android.R.layout.simple_list_item_1, mStrings) + listView.isTextFilterEnabled = true } - private String[] mStrings = Cheeses.sCheeseStrings; + private val mStrings = Cheeses.sCheeseStrings } diff --git a/mobile/src/main/java/com/example/android/apis/view/List10.java b/mobile/src/main/java/com/example/android/apis/view/List10.kt similarity index 51% rename from mobile/src/main/java/com/example/android/apis/view/List10.java rename to mobile/src/main/java/com/example/android/apis/view/List10.kt index 57e0bb152..e9a741f27 100644 --- a/mobile/src/main/java/com/example/android/apis/view/List10.java +++ b/mobile/src/main/java/com/example/android/apis/view/List10.kt @@ -14,36 +14,35 @@ * limitations under the License. */ -package com.example.android.apis.view; +package com.example.android.apis.view -import android.app.ListActivity; -import android.os.Bundle; -import android.widget.ArrayAdapter; -import android.widget.ListView; +import android.app.ListActivity +import android.os.Bundle +import android.widget.ArrayAdapter +import android.widget.ListView /** - * This example shows how to use choice mode on a list. This list is + * This example shows how to use choice mode on a list. This list is * in CHOICE_MODE_SINGLE mode, which means the items behave like * checkboxes. */ -public class List10 extends ListActivity { - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); +class List10 : ListActivity() { - setListAdapter(new ArrayAdapter(this, - android.R.layout.simple_list_item_single_choice, GENRES)); - - final ListView listView = getListView(); + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) - listView.setItemsCanFocus(false); - listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); - } + listAdapter = ArrayAdapter(this, + android.R.layout.simple_list_item_single_choice, GENRES) + listView.apply { + itemsCanFocus = false + choiceMode = ListView.CHOICE_MODE_SINGLE + } + } - private static final String[] GENRES = new String[] { - "Action", "Adventure", "Animation", "Children", "Comedy", "Documentary", "Drama", - "Foreign", "History", "Independent", "Romance", "Sci-Fi", "Television", "Thriller" - }; + companion object { + private val GENRES = arrayOf("Action", "Adventure", "Animation", "Children", "Comedy", + "Documentary", "Drama", "Foreign", "History", "Independent", "Romance", "Sci-Fi", + "Television", "Thriller") + } } diff --git a/mobile/src/main/java/com/example/android/apis/view/List11.java b/mobile/src/main/java/com/example/android/apis/view/List11.kt similarity index 51% rename from mobile/src/main/java/com/example/android/apis/view/List11.java rename to mobile/src/main/java/com/example/android/apis/view/List11.kt index 71d77e579..571e2a718 100644 --- a/mobile/src/main/java/com/example/android/apis/view/List11.java +++ b/mobile/src/main/java/com/example/android/apis/view/List11.kt @@ -14,36 +14,35 @@ * limitations under the License. */ -package com.example.android.apis.view; +package com.example.android.apis.view -import android.app.ListActivity; -import android.os.Bundle; -import android.widget.ArrayAdapter; -import android.widget.ListView; +import android.app.ListActivity +import android.os.Bundle +import android.widget.ArrayAdapter +import android.widget.ListView /** - * This example shows how to use choice mode on a list. This list is + * This example shows how to use choice mode on a list. This list is * in CHOICE_MODE_MULTIPLE mode, which means the items behave like * checkboxes. */ -public class List11 extends ListActivity { - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); +class List11 : ListActivity() { - setListAdapter(new ArrayAdapter(this, - android.R.layout.simple_list_item_multiple_choice, GENRES)); - - final ListView listView = getListView(); + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) - listView.setItemsCanFocus(false); - listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); - } + listAdapter = ArrayAdapter(this, + android.R.layout.simple_list_item_multiple_choice, GENRES) + listView.apply { + itemsCanFocus = false + choiceMode = ListView.CHOICE_MODE_MULTIPLE + } + } - private static final String[] GENRES = new String[] { - "Action", "Adventure", "Animation", "Children", "Comedy", "Documentary", "Drama", - "Foreign", "History", "Independent", "Romance", "Sci-Fi", "Television", "Thriller" - }; + companion object { + private val GENRES = arrayOf("Action", "Adventure", "Animation", "Children", "Comedy", + "Documentary", "Drama", "Foreign", "History", "Independent", "Romance", "Sci-Fi", + "Television", "Thriller") + } } diff --git a/mobile/src/main/java/com/example/android/apis/view/List12.java b/mobile/src/main/java/com/example/android/apis/view/List12.java deleted file mode 100644 index 0867fc59e..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/List12.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2007 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.apis.view; - -import android.app.ListActivity; -import android.os.Bundle; -import android.view.KeyEvent; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.View.OnKeyListener; -import android.widget.ArrayAdapter; -import android.widget.EditText; - -import com.example.android.apis.R; - -import java.util.ArrayList; - -/** - * Demonstrates the using a list view in transcript mode - * - */ -public class List12 extends ListActivity implements OnClickListener, OnKeyListener { - - private EditText mUserText; - - private ArrayAdapter mAdapter; - - private ArrayList mStrings = new ArrayList(); - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.list_12); - - mAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, mStrings); - - setListAdapter(mAdapter); - - mUserText = (EditText) findViewById(R.id.userText); - - mUserText.setOnClickListener(this); - mUserText.setOnKeyListener(this); - } - - public void onClick(View v) { - sendText(); - } - - private void sendText() { - String text = mUserText.getText().toString(); - mAdapter.add(text); - mUserText.setText(null); - } - - public boolean onKey(View v, int keyCode, KeyEvent event) { - if (event.getAction() == KeyEvent.ACTION_DOWN) { - switch (keyCode) { - case KeyEvent.KEYCODE_DPAD_CENTER: - case KeyEvent.KEYCODE_ENTER: - sendText(); - return true; - } - } - return false; - } - - -} diff --git a/mobile/src/main/java/com/example/android/apis/view/List12.kt b/mobile/src/main/java/com/example/android/apis/view/List12.kt new file mode 100644 index 000000000..d0c3e25ef --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/List12.kt @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2007 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.apis.view + +import android.app.ListActivity +import android.os.Bundle +import android.view.KeyEvent +import android.view.View +import android.view.View.OnClickListener +import android.view.View.OnKeyListener +import android.widget.ArrayAdapter +import android.widget.EditText + +import com.example.android.apis.R +import kotlinx.android.synthetic.main.list_12.* + +import java.util.ArrayList + +/** + * Demonstrates the using a list view in transcript mode + * + */ +class List12 : ListActivity(), OnClickListener, OnKeyListener { + + private val mUserText: EditText by lazy { userText } + + private val mAdapter: ArrayAdapter + by lazy { ArrayAdapter(this, android.R.layout.simple_list_item_1, mStrings) } + + private val mStrings = ArrayList() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContentView(R.layout.list_12) + + listAdapter = mAdapter + + mUserText.setOnClickListener(this) + mUserText.setOnKeyListener(this) + } + + override fun onClick(v: View) { + sendText() + } + + private fun sendText() { + val text = mUserText.text.toString() + mAdapter.add(text) + mUserText.text = null + } + + override fun onKey(v: View, keyCode: Int, event: KeyEvent): Boolean { + if (event.action == KeyEvent.ACTION_DOWN) { + when (keyCode) { + KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER -> { + sendText() + return true + } + } + } + return false + } +} diff --git a/mobile/src/main/java/com/example/android/apis/view/List13.java b/mobile/src/main/java/com/example/android/apis/view/List13.java deleted file mode 100644 index 68179ed3c..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/List13.java +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright (C) 2008 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.apis.view; - -import android.app.ListActivity; -import android.content.Context; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AbsListView; -import android.widget.BaseAdapter; -import android.widget.ListView; -import android.widget.TextView; -import android.widget.AbsListView.OnScrollListener; - -import com.example.android.apis.R; - - -/** - * Demonstrates how a list can avoid expensive operations during scrolls or flings. In this - * case, we pretend that binding a view to its data is slow (even though it really isn't). When - * a scroll/fling is happening, the adapter binds the view to temporary data. After the scroll/fling - * has finished, the temporary data is replace with the actual data. - * - */ -public class List13 extends ListActivity implements ListView.OnScrollListener { - - private TextView mStatus; - - private boolean mBusy = false; - - /** - * Will not bind views while the list is scrolling - * - */ - private class SlowAdapter extends BaseAdapter { - private LayoutInflater mInflater; - - public SlowAdapter(Context context) { - mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - } - - /** - * The number of items in the list is determined by the number of speeches - * in our array. - * - * @see android.widget.ListAdapter#getCount() - */ - public int getCount() { - return mStrings.length; - } - - /** - * Since the data comes from an array, just returning the index is - * sufficent to get at the data. If we were using a more complex data - * structure, we would return whatever object represents one row in the - * list. - * - * @see android.widget.ListAdapter#getItem(int) - */ - public Object getItem(int position) { - return position; - } - - /** - * Use the array index as a unique id. - * - * @see android.widget.ListAdapter#getItemId(int) - */ - public long getItemId(int position) { - return position; - } - - /** - * Make a view to hold each row. - * - * @see android.widget.ListAdapter#getView(int, android.view.View, - * android.view.ViewGroup) - */ - public View getView(int position, View convertView, ViewGroup parent) { - TextView text; - - if (convertView == null) { - text = (TextView)mInflater.inflate(android.R.layout.simple_list_item_1, parent, false); - } else { - text = (TextView)convertView; - } - - if (!mBusy) { - text.setText(mStrings[position]); - // Null tag means the view has the correct data - text.setTag(null); - } else { - text.setText("Loading..."); - // Non-null tag means the view still needs to load it's data - text.setTag(this); - } - - return text; - } - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.list_13); - mStatus = (TextView) findViewById(R.id.status); - mStatus.setText("Idle"); - - // Use an existing ListAdapter that will map an array - // of strings to TextViews - setListAdapter(new SlowAdapter(this)); - - getListView().setOnScrollListener(this); - } - - - public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, - int totalItemCount) { - } - - - public void onScrollStateChanged(AbsListView view, int scrollState) { - switch (scrollState) { - case OnScrollListener.SCROLL_STATE_IDLE: - mBusy = false; - - int first = view.getFirstVisiblePosition(); - int count = view.getChildCount(); - for (int i=0; i { + mBusy = false + + val first = view.firstVisiblePosition + val count = view.childCount + for (i in 0 until count - 1) { + (view.getChildAt(i) as TextView).apply { + if (tag != null) { + text = mStrings[first + i] + tag = null + } + } + } + + mStatus.text = "Idle" + } + OnScrollListener.SCROLL_STATE_TOUCH_SCROLL -> { + mBusy = true + mStatus.text = "Touch scroll" + } + OnScrollListener.SCROLL_STATE_FLING -> { + mBusy = true + mStatus.text = "Fling" + } + } + } + + private val mStrings = arrayOf("Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler", "Alverca", "Ambert", "American Cheese", "Ami du Chambertin", "Anejo Enchilado", "Anneau du Vic-Bilh", "Anthoriro", "Appenzell", "Aragon", "Ardi Gasna", "Ardrahan", "Armenian String", "Aromes au Gene de Marc", "Asadero", "Asiago", "Aubisque Pyrenees", "Autun", "Avaxtskyr", "Baby Swiss", "Babybel", "Baguette Laonnaise", "Bakers", "Baladi", "Balaton", "Bandal", "Banon", "Barry's Bay Cheddar", "Basing", "Basket Cheese", "Bath Cheese", "Bavarian Bergkase", "Baylough", "Beaufort", "Beauvoorde", "Beenleigh Blue", "Beer Cheese", "Bel Paese", "Bergader", "Bergere Bleue", "Berkswell", "Beyaz Peynir", "Bierkase", "Bishop Kennedy", "Blarney", "Bleu d'Auvergne", "Bleu de Gex", "Bleu de Laqueuille", "Bleu de Septmoncel", "Bleu Des Causses", "Blue", "Blue Castello", "Blue Rathgore", "Blue Vein (Australian)", "Blue Vein Cheeses", "Bocconcini", "Bocconcini (Australian)", "Boeren Leidenkaas", "Bonchester", "Bosworth", "Bougon", "Boule Du Roves", "Boulette d'Avesnes", "Boursault", "Boursin", "Bouyssou", "Bra", "Braudostur", "Breakfast Cheese", "Brebis du Lavort", "Brebis du Lochois", "Brebis du Puyfaucon", "Bresse Bleu", "Brick", "Brie", "Brie de Meaux", "Brie de Melun", "Brillat-Savarin", "Brin", "Brin d' Amour", "Brin d'Amour", "Brinza (Burduf Brinza)", "Briquette de Brebis", "Briquette du Forez", "Broccio", "Broccio Demi-Affine", "Brousse du Rove", "Bruder Basil", "Brusselae Kaas (Fromage de Bruxelles)", "Bryndza", "Buchette d'Anjou", "Buffalo", "Burgos", "Butte", "Butterkase", "Button (Innes)", "Buxton Blue", "Cabecou", "Caboc", "Cabrales", "Cachaille", "Caciocavallo", "Caciotta", "Caerphilly", "Cairnsmore", "Calenzana", "Cambazola", "Camembert de Normandie", "Canadian Cheddar", "Canestrato", "Cantal", "Caprice des Dieux", "Capricorn Goat", "Capriole Banon", "Carre de l'Est", "Casciotta di Urbino", "Cashel Blue", "Castellano", "Castelleno", "Castelmagno", "Castelo Branco", "Castigliano", "Cathelain", "Celtic Promise", "Cendre d'Olivet", "Cerney", "Chabichou", "Chabichou du Poitou", "Chabis de Gatine", "Chaource", "Charolais", "Chaumes", "Cheddar", "Cheddar Clothbound", "Cheshire", "Chevres", "Chevrotin des Aravis", "Chontaleno", "Civray", "Coeur de Camembert au Calvados", "Coeur de Chevre", "Colby", "Cold Pack", "Comte", "Coolea", "Cooleney", "Coquetdale", "Corleggy", "Cornish Pepper", "Cotherstone", "Cotija", "Cottage Cheese", "Cottage Cheese (Australian)", "Cougar Gold", "Coulommiers", "Coverdale", "Crayeux de Roncq", "Cream Cheese", "Cream Havarti", "Crema Agria", "Crema Mexicana", "Creme Fraiche", "Crescenza", "Croghan", "Crottin de Chavignol", "Crottin du Chavignol", "Crowdie", "Crowley", "Cuajada", "Curd", "Cure Nantais", "Curworthy", "Cwmtawe Pecorino", "Cypress Grove Chevre", "Danablu (Danish Blue)", "Danbo", "Danish Fontina", "Daralagjazsky", "Dauphin", "Delice des Fiouves", "Denhany Dorset Drum", "Derby", "Dessertnyj Belyj", "Devon Blue", "Devon Garland", "Dolcelatte", "Doolin", "Doppelrhamstufel", "Dorset Blue Vinney", "Double Gloucester", "Double Worcester", "Dreux a la Feuille", "Dry Jack", "Duddleswell", "Dunbarra", "Dunlop", "Dunsyre Blue", "Duroblando", "Durrus", "Dutch Mimolette (Commissiekaas)", "Edam", "Edelpilz", "Emental Grand Cru", "Emlett", "Emmental", "Epoisses de Bourgogne", "Esbareich", "Esrom", "Etorki", "Evansdale Farmhouse Brie", "Evora De L'Alentejo", "Exmoor Blue", "Explorateur", "Feta", "Feta (Australian)", "Figue", "Filetta", "Fin-de-Siecle", "Finlandia Swiss", "Finn", "Fiore Sardo", "Fleur du Maquis", "Flor de Guia", "Flower Marie", "Folded", "Folded cheese with mint", "Fondant de Brebis", "Fontainebleau", "Fontal", "Fontina Val d'Aosta", "Formaggio di capra", "Fougerus", "Four Herb Gouda", "Fourme d' Ambert", "Fourme de Haute Loire", "Fourme de Montbrison", "Fresh Jack", "Fresh Mozzarella", "Fresh Ricotta", "Fresh Truffles", "Fribourgeois", "Friesekaas", "Friesian", "Friesla", "Frinault", "Fromage a Raclette", "Fromage Corse", "Fromage de Montagne de Savoie", "Fromage Frais", "Fruit Cream Cheese", "Frying Cheese", "Fynbo", "Gabriel", "Galette du Paludier", "Galette Lyonnaise", "Galloway Goat's Milk Gems", "Gammelost", "Gaperon a l'Ail", "Garrotxa", "Gastanberra", "Geitost", "Gippsland Blue", "Gjetost", "Gloucester", "Golden Cross", "Gorgonzola", "Gornyaltajski", "Gospel Green", "Gouda", "Goutu", "Gowrie", "Grabetto", "Graddost", "Grafton Village Cheddar", "Grana", "Grana Padano", "Grand Vatel", "Grataron d' Areches", "Gratte-Paille", "Graviera", "Greuilh", "Greve", "Gris de Lille", "Gruyere", "Gubbeen", "Guerbigny", "Halloumi", "Halloumy (Australian)", "Haloumi-Style Cheese", "Harbourne Blue", "Havarti", "Heidi Gruyere", "Hereford Hop", "Herrgardsost", "Herriot Farmhouse", "Herve", "Hipi Iti", "Hubbardston Blue Cow", "Hushallsost", "Iberico", "Idaho Goatster", "Idiazabal", "Il Boschetto al Tartufo", "Ile d'Yeu", "Isle of Mull", "Jarlsberg", "Jermi Tortes", "Jibneh Arabieh", "Jindi Brie", "Jubilee Blue", "Juustoleipa", "Kadchgall", "Kaseri", "Kashta", "Kefalotyri", "Kenafa", "Kernhem", "Kervella Affine", "Kikorangi", "King Island Cape Wickham Brie", "King River Gold", "Klosterkaese", "Knockalara", "Kugelkase", "L'Aveyronnais", "L'Ecir de l'Aubrac", "La Taupiniere", "La Vache Qui Rit", "Laguiole", "Lairobell", "Lajta", "Lanark Blue", "Lancashire", "Langres", "Lappi", "Laruns", "Lavistown", "Le Brin", "Le Fium Orbo", "Le Lacandou", "Le Roule", "Leafield", "Lebbene", "Leerdammer", "Leicester", "Leyden", "Limburger", "Lincolnshire Poacher", "Lingot Saint Bousquet d'Orb", "Liptauer", "Little Rydings", "Livarot", "Llanboidy", "Llanglofan Farmhouse", "Loch Arthur Farmhouse", "Loddiswell Avondale", "Longhorn", "Lou Palou", "Lou Pevre", "Lyonnais", "Maasdam", "Macconais", "Mahoe Aged Gouda", "Mahon", "Malvern", "Mamirolle", "Manchego", "Manouri", "Manur", "Marble Cheddar", "Marbled Cheeses", "Maredsous", "Margotin", "Maribo", "Maroilles", "Mascares", "Mascarpone", "Mascarpone (Australian)", "Mascarpone Torta", "Matocq", "Maytag Blue", "Meira", "Menallack Farmhouse", "Menonita", "Meredith Blue", "Mesost", "Metton (Cancoillotte)", "Meyer Vintage Gouda", "Mihalic Peynir", "Milleens", "Mimolette", "Mine-Gabhar", "Mini Baby Bells", "Mixte", "Molbo", "Monastery Cheeses", "Mondseer", "Mont D'or Lyonnais", "Montasio", "Monterey Jack", "Monterey Jack Dry", "Morbier", "Morbier Cru de Montagne", "Mothais a la Feuille", "Mozzarella", "Mozzarella (Australian)", "Mozzarella di Bufala", "Mozzarella Fresh, in water", "Mozzarella Rolls", "Munster", "Murol", "Mycella", "Myzithra", "Naboulsi", "Nantais", "Neufchatel", "Neufchatel (Australian)", "Niolo", "Nokkelost", "Northumberland", "Oaxaca", "Olde York", "Olivet au Foin", "Olivet Bleu", "Olivet Cendre", "Orkney Extra Mature Cheddar", "Orla", "Oschtjepka", "Ossau Fermier", "Ossau-Iraty", "Oszczypek", "Oxford Blue", "P'tit Berrichon", "Palet de Babligny", "Paneer", "Panela", "Pannerone", "Pant ys Gawn", "Parmesan (Parmigiano)", "Parmigiano Reggiano", "Pas de l'Escalette", "Passendale", "Pasteurized Processed", "Pate de Fromage", "Patefine Fort", "Pave d'Affinois", "Pave d'Auge", "Pave de Chirac", "Pave du Berry", "Pecorino", "Pecorino in Walnut Leaves", "Pecorino Romano", "Peekskill Pyramid", "Pelardon des Cevennes", "Pelardon des Corbieres", "Penamellera", "Penbryn", "Pencarreg", "Perail de Brebis", "Petit Morin", "Petit Pardou", "Petit-Suisse", "Picodon de Chevre", "Picos de Europa", "Piora", "Pithtviers au Foin", "Plateau de Herve", "Plymouth Cheese", "Podhalanski", "Poivre d'Ane", "Polkolbin", "Pont l'Eveque", "Port Nicholson", "Port-Salut", "Postel", "Pouligny-Saint-Pierre", "Pourly", "Prastost", "Pressato", "Prince-Jean", "Processed Cheddar", "Provolone", "Provolone (Australian)", "Pyengana Cheddar", "Pyramide", "Quark", "Quark (Australian)", "Quartirolo Lombardo", "Quatre-Vents", "Quercy Petit", "Queso Blanco", "Queso Blanco con Frutas --Pina y Mango", "Queso de Murcia", "Queso del Montsec", "Queso del Tietar", "Queso Fresco", "Queso Fresco (Adobera)", "Queso Iberico", "Queso Jalapeno", "Queso Majorero", "Queso Media Luna", "Queso Para Frier", "Queso Quesadilla", "Rabacal", "Raclette", "Ragusano", "Raschera", "Reblochon", "Red Leicester", "Regal de la Dombes", "Reggianito", "Remedou", "Requeson", "Richelieu", "Ricotta", "Ricotta (Australian)", "Ricotta Salata", "Ridder", "Rigotte", "Rocamadour", "Rollot", "Romano", "Romans Part Dieu", "Roncal", "Roquefort", "Roule", "Rouleau De Beaulieu", "Royalp Tilsit", "Rubens", "Rustinu", "Saaland Pfarr", "Saanenkaese", "Saga", "Sage Derby", "Sainte Maure", "Saint-Marcellin", "Saint-Nectaire", "Saint-Paulin", "Salers", "Samso", "San Simon", "Sancerre", "Sap Sago", "Sardo", "Sardo Egyptian", "Sbrinz", "Scamorza", "Schabzieger", "Schloss", "Selles sur Cher", "Selva", "Serat", "Seriously Strong Cheddar", "Serra da Estrela", "Sharpam", "Shelburne Cheddar", "Shropshire Blue", "Siraz", "Sirene", "Smoked Gouda", "Somerset Brie", "Sonoma Jack", "Sottocenare al Tartufo", "Soumaintrain", "Sourire Lozerien", "Spenwood", "Sraffordshire Organic", "St. Agur Blue Cheese", "Stilton", "Stinking Bishop", "String", "Sussex Slipcote", "Sveciaost", "Swaledale", "Sweet Style Swiss", "Swiss", "Syrian (Armenian String)", "Tala", "Taleggio", "Tamie", "Tasmania Highland Chevre Log", "Taupiniere", "Teifi", "Telemea", "Testouri", "Tete de Moine", "Tetilla", "Texas Goat Cheese", "Tibet", "Tillamook Cheddar", "Tilsit", "Timboon Brie", "Toma", "Tomme Brulee", "Tomme d'Abondance", "Tomme de Chevre", "Tomme de Romans", "Tomme de Savoie", "Tomme des Chouans", "Tommes", "Torta del Casar", "Toscanello", "Touree de L'Aubier", "Tourmalet", "Trappe (Veritable)", "Trois Cornes De Vendee", "Tronchon", "Trou du Cru", "Truffe", "Tupi", "Turunmaa", "Tymsboro", "Tyn Grug", "Tyning", "Ubriaco", "Ulloa", "Vacherin-Fribourgeois", "Valencay", "Vasterbottenost", "Venaco", "Vendomois", "Vieux Corse", "Vignotte", "Vulscombe", "Waimata Farmhouse Blue", "Washed Rind Cheese (Australian)", "Waterloo", "Weichkaese", "Wellington", "Wensleydale", "White Stilton", "Whitestone Farmhouse", "Wigmore", "Woodside Cabecou", "Xanadu", "Xynotyro", "Yarg Cornish", "Yarra Valley Pyramid", "Yorkshire Blue", "Zamorano", "Zanetti Grana Padano", "Zanetti Parmigiano Reggiano") +} diff --git a/mobile/src/main/java/com/example/android/apis/view/List14.java b/mobile/src/main/java/com/example/android/apis/view/List14.kt similarity index 50% rename from mobile/src/main/java/com/example/android/apis/view/List14.java rename to mobile/src/main/java/com/example/android/apis/view/List14.kt index 55f3b2286..a5bae2451 100644 --- a/mobile/src/main/java/com/example/android/apis/view/List14.java +++ b/mobile/src/main/java/com/example/android/apis/view/List14.kt @@ -14,20 +14,20 @@ * limitations under the License. */ -package com.example.android.apis.view; - -import android.app.ListActivity; -import android.content.Context; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.TextView; -import android.widget.ImageView; -import android.graphics.BitmapFactory; -import android.graphics.Bitmap; -import com.example.android.apis.R; +package com.example.android.apis.view + +import android.app.ListActivity +import android.content.Context +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.BaseAdapter +import android.widget.TextView +import android.widget.ImageView +import android.graphics.BitmapFactory +import android.graphics.Bitmap +import com.example.android.apis.R /** * Demonstrates how to write an efficient list adapter. The adapter used in this example binds @@ -41,30 +41,23 @@ * getView(). This data structures contains references to the views we want to bind data to, thus * avoiding calls to findViewById() every time getView() is invoked. */ -public class List14 extends ListActivity { +class List14 : ListActivity() { - private static class EfficientAdapter extends BaseAdapter { - private LayoutInflater mInflater; - private Bitmap mIcon1; - private Bitmap mIcon2; - - public EfficientAdapter(Context context) { - // Cache the LayoutInflate to avoid asking for a new one each time. - mInflater = LayoutInflater.from(context); - - // Icons bound to the rows. - mIcon1 = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon48x48_1); - mIcon2 = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon48x48_2); - } + private class EfficientAdapter(context: Context) : BaseAdapter() { + // Cache the LayoutInflate to avoid asking for a new one each time. + private val mInflater: LayoutInflater = LayoutInflater.from(context) + // Icons bound to the rows. + private val mIcon1: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.icon48x48_1) + private val mIcon2: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.icon48x48_2) /** * The number of items in the list is determined by the number of speeches * in our array. * - * @see android.widget.ListAdapter#getCount() + * @see android.widget.ListAdapter.getCount */ - public int getCount() { - return DATA.length; + override fun getCount(): Int { + return DATA.size } /** @@ -73,69 +66,70 @@ public int getCount() { * structure, we would return whatever object represents one row in the * list. * - * @see android.widget.ListAdapter#getItem(int) + * @see android.widget.ListAdapter.getItem */ - public Object getItem(int position) { - return position; + override fun getItem(position: Int): Any { + return position } /** * Use the array index as a unique id. * - * @see android.widget.ListAdapter#getItemId(int) + * @see android.widget.ListAdapter.getItemId */ - public long getItemId(int position) { - return position; + override fun getItemId(position: Int): Long { + return position.toLong() } /** * Make a view to hold each row. * - * @see android.widget.ListAdapter#getView(int, android.view.View, - * android.view.ViewGroup) + * @see android.widget.ListAdapter.getView */ - public View getView(int position, View convertView, ViewGroup parent) { - // A ViewHolder keeps references to children views to avoid unneccessary calls + override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { + var convertView = convertView + // A ViewHolder keeps references to children views to avoid unnecessary calls // to findViewById() on each row. - ViewHolder holder; + val holder: ViewHolder // When convertView is not null, we can reuse it directly, there is no need - // to reinflate it. We only inflate a new View when the convertView supplied + // to re-inflate it. We only inflate a new View when the convertView supplied // by ListView is null. if (convertView == null) { - convertView = mInflater.inflate(R.layout.list_item_icon_text, null); + convertView = mInflater.inflate(R.layout.list_item_icon_text, parent, false) // Creates a ViewHolder and store references to the two children views // we want to bind data to. - holder = new ViewHolder(); - holder.text = (TextView) convertView.findViewById(R.id.text); - holder.icon = (ImageView) convertView.findViewById(R.id.icon); + holder = ViewHolder() + holder.text = convertView.findViewById(R.id.text) as TextView + holder.icon = convertView.findViewById(R.id.icon) as ImageView - convertView.setTag(holder); + convertView.tag = holder } else { // Get the ViewHolder back to get fast access to the TextView // and the ImageView. - holder = (ViewHolder) convertView.getTag(); + holder = convertView.tag as ViewHolder } // Bind the data efficiently with the holder. - holder.text.setText(DATA[position]); - holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2); + holder.text.text = DATA[position] + holder.icon.setImageBitmap(if ((position and 1) == 1) mIcon1 else mIcon2) - return convertView; + return convertView!! } - static class ViewHolder { - TextView text; - ImageView icon; + internal class ViewHolder { + lateinit var text: TextView + lateinit var icon: ImageView } } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setListAdapter(new EfficientAdapter(this)); + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + listAdapter = EfficientAdapter(this) } - private static final String[] DATA = Cheeses.sCheeseStrings; + companion object { + private val DATA = Cheeses.sCheeseStrings + } } diff --git a/mobile/src/main/java/com/example/android/apis/view/List15.java b/mobile/src/main/java/com/example/android/apis/view/List15.java deleted file mode 100644 index 9fa7c6427..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/List15.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2010 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.apis.view; - -import com.example.android.apis.R; - -import android.app.ListActivity; -import android.os.Bundle; -import android.view.ActionMode; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.widget.ArrayAdapter; -import android.widget.ListView; -import android.widget.Toast; - -/** - * This demo illustrates the use of CHOICE_MODE_MULTIPLE_MODAL, a.k.a. selection mode on ListView. - */ -public class List15 extends ListActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ListView lv = getListView(); - lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); - lv.setMultiChoiceModeListener(new ModeCallback()); - setListAdapter(new ArrayAdapter(this, - android.R.layout.simple_list_item_checked, mStrings)); - } - - @Override - protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - getActionBar().setSubtitle("Long press to start selection"); - } - - private class ModeCallback implements ListView.MultiChoiceModeListener { - - public boolean onCreateActionMode(ActionMode mode, Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.list_select_menu, menu); - mode.setTitle("Select Items"); - setSubtitle(mode); - return true; - } - - public boolean onPrepareActionMode(ActionMode mode, Menu menu) { - return true; - } - - public boolean onActionItemClicked(ActionMode mode, MenuItem item) { - switch (item.getItemId()) { - case R.id.share: - Toast.makeText(List15.this, "Shared " + getListView().getCheckedItemCount() + - " items", Toast.LENGTH_SHORT).show(); - mode.finish(); - break; - default: - Toast.makeText(List15.this, "Clicked " + item.getTitle(), - Toast.LENGTH_SHORT).show(); - break; - } - return true; - } - - public void onDestroyActionMode(ActionMode mode) { - } - - public void onItemCheckedStateChanged(ActionMode mode, - int position, long id, boolean checked) { - setSubtitle(mode); - } - - private void setSubtitle(ActionMode mode) { - final int checkedCount = getListView().getCheckedItemCount(); - switch (checkedCount) { - case 0: - mode.setSubtitle(null); - break; - case 1: - mode.setSubtitle("One item selected"); - break; - default: - mode.setSubtitle("" + checkedCount + " items selected"); - break; - } - } - } - - private String[] mStrings = Cheeses.sCheeseStrings; -} diff --git a/mobile/src/main/java/com/example/android/apis/view/List15.kt b/mobile/src/main/java/com/example/android/apis/view/List15.kt new file mode 100644 index 000000000..a8a9d0e75 --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/List15.kt @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2010 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.apis.view + +import com.example.android.apis.R + +import android.app.ListActivity +import android.os.Bundle +import android.view.ActionMode +import android.view.Menu +import android.view.MenuItem +import android.widget.AbsListView +import android.widget.ArrayAdapter +import android.widget.ListView +import android.widget.Toast + +/** + * This demo illustrates the use of CHOICE_MODE_MULTIPLE_MODAL, a.k.a. selection mode on ListView. + */ +class List15 : ListActivity(){ + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + listView.apply { + choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL + setMultiChoiceModeListener(ModeCallback()) + } + + listAdapter = ArrayAdapter(this, + android.R.layout.simple_list_item_checked, mStrings) + } + + override fun onPostCreate(savedInstanceState: Bundle?) { + super.onPostCreate(savedInstanceState) + actionBar.subtitle = "Long press to start selection" + } + + private inner class ModeCallback : AbsListView.MultiChoiceModeListener { + + override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { + val inflater = menuInflater + inflater.inflate(R.menu.list_select_menu, menu) + mode.title = "Select Items" + setSubtitle(mode) + return true + } + + override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean { + return true + } + + override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { + when (item.itemId) { + R.id.share -> { + Toast.makeText(this@List15, "Shared " + listView.checkedItemCount + + " items", Toast.LENGTH_SHORT).show() + mode.finish() + } + else -> Toast.makeText(this@List15, "Clicked " + item.title, + Toast.LENGTH_SHORT).show() + } + return true + } + + override fun onDestroyActionMode(mode: ActionMode) {} + + override fun onItemCheckedStateChanged(mode: ActionMode, + position: Int, id: Long, checked: Boolean) { + setSubtitle(mode) + } + + private fun setSubtitle(mode: ActionMode) { + val checkedCount = listView.checkedItemCount + when (checkedCount) { + 0 -> mode.subtitle = null + 1 -> mode.subtitle = "One item selected" + else -> mode.subtitle = "" + checkedCount + " items selected" + } + } + } + + private val mStrings = Cheeses.sCheeseStrings +} diff --git a/mobile/src/main/java/com/example/android/apis/view/List16.java b/mobile/src/main/java/com/example/android/apis/view/List16.java deleted file mode 100644 index bfea6edef..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/List16.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2010 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.apis.view; - -import com.example.android.apis.R; - -import android.app.ListActivity; -import android.os.Bundle; -import android.view.ActionMode; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.widget.ArrayAdapter; -import android.widget.ListView; -import android.widget.Toast; - -/** - * This demo illustrates the use of CHOICE_MODE_MULTIPLE_MODAL, a.k.a. selection mode on ListView - * couple with the new simple_list_item_activated_1 which uses a highlighted border for selected - * items. - */ -public class List16 extends ListActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ListView lv = getListView(); - lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); - lv.setMultiChoiceModeListener(new ModeCallback()); - setListAdapter(new ArrayAdapter(this, - android.R.layout.simple_list_item_activated_1, Cheeses.sCheeseStrings)); - } - - @Override - protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - getActionBar().setSubtitle("Long press to start selection"); - } - - private class ModeCallback implements ListView.MultiChoiceModeListener { - - public boolean onCreateActionMode(ActionMode mode, Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.list_select_menu, menu); - mode.setTitle("Select Items"); - return true; - } - - public boolean onPrepareActionMode(ActionMode mode, Menu menu) { - return true; - } - - public boolean onActionItemClicked(ActionMode mode, MenuItem item) { - switch (item.getItemId()) { - case R.id.share: - Toast.makeText(List16.this, "Shared " + getListView().getCheckedItemCount() + - " items", Toast.LENGTH_SHORT).show(); - mode.finish(); - break; - default: - Toast.makeText(List16.this, "Clicked " + item.getTitle(), - Toast.LENGTH_SHORT).show(); - break; - } - return true; - } - - public void onDestroyActionMode(ActionMode mode) { - } - - public void onItemCheckedStateChanged(ActionMode mode, - int position, long id, boolean checked) { - final int checkedCount = getListView().getCheckedItemCount(); - switch (checkedCount) { - case 0: - mode.setSubtitle(null); - break; - case 1: - mode.setSubtitle("One item selected"); - break; - default: - mode.setSubtitle("" + checkedCount + " items selected"); - break; - } - } - - } -} diff --git a/mobile/src/main/java/com/example/android/apis/view/List16.kt b/mobile/src/main/java/com/example/android/apis/view/List16.kt new file mode 100644 index 000000000..519c4095c --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/List16.kt @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2010 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.apis.view + +import com.example.android.apis.R + +import android.app.ListActivity +import android.os.Bundle +import android.view.ActionMode +import android.view.Menu +import android.view.MenuItem +import android.widget.AbsListView +import android.widget.ArrayAdapter +import android.widget.ListView +import android.widget.Toast + +/** + * This demo illustrates the use of CHOICE_MODE_MULTIPLE_MODAL, a.k.a. selection mode on ListView + * couple with the new simple_list_item_activated_1 which uses a highlighted border for selected + * items. + */ +class List16 : ListActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + listView.apply { + choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL + setMultiChoiceModeListener(ModeCallback()) + } + listAdapter = ArrayAdapter(this, + android.R.layout.simple_list_item_activated_1, Cheeses.sCheeseStrings) + } + + override fun onPostCreate(savedInstanceState: Bundle?) { + super.onPostCreate(savedInstanceState) + actionBar.subtitle = "Long press to start selection" + } + + private inner class ModeCallback : AbsListView.MultiChoiceModeListener { + + override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { + val inflater = menuInflater + inflater.inflate(R.menu.list_select_menu, menu) + mode.title = "Select Items" + return true + } + + override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean { + return true + } + + override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { + when (item.itemId) { + R.id.share -> { + Toast.makeText(this@List16, "Shared " + listView.checkedItemCount + + " items", Toast.LENGTH_SHORT).show() + mode.finish() + } + else -> Toast.makeText(this@List16, "Clicked " + item.title, + Toast.LENGTH_SHORT).show() + } + return true + } + + override fun onDestroyActionMode(mode: ActionMode) {} + + override fun onItemCheckedStateChanged(mode: ActionMode, + position: Int, id: Long, checked: Boolean) { + val checkedCount = listView.checkedItemCount + when (checkedCount) { + 0 -> mode.subtitle = null + 1 -> mode.subtitle = "One item selected" + else -> mode.subtitle = "" + checkedCount + " items selected" + } + } + + } +} diff --git a/mobile/src/main/java/com/example/android/apis/view/List17.java b/mobile/src/main/java/com/example/android/apis/view/List17.kt similarity index 51% rename from mobile/src/main/java/com/example/android/apis/view/List17.java rename to mobile/src/main/java/com/example/android/apis/view/List17.kt index 67fa0bdee..5ffbafb48 100644 --- a/mobile/src/main/java/com/example/android/apis/view/List17.java +++ b/mobile/src/main/java/com/example/android/apis/view/List17.kt @@ -14,44 +14,44 @@ * limitations under the License. */ -package com.example.android.apis.view; - -import android.app.ListActivity; -import android.os.Bundle; -import android.view.View; -import android.widget.ArrayAdapter; -import android.widget.ListView; +package com.example.android.apis.view +import android.app.ListActivity +import android.os.Bundle +import android.view.View +import android.widget.ArrayAdapter +import android.widget.ListView /** * A list view where the last item the user clicked is placed in * the "activated" state, causing its background to highlight. */ -public class List17 extends ListActivity { +class List17 : ListActivity() { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) // Use the built-in layout for showing a list item with a single // line of text whose background is changes when activated. - setListAdapter(new ArrayAdapter(this, - android.R.layout.simple_list_item_activated_1, mStrings)); - getListView().setTextFilterEnabled(true); - - // Tell the list view to show one checked/activated item at a time. - getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); - - // Start with first item activated. - // Make the newly clicked item the currently selected one. - getListView().setItemChecked(0, true); + listAdapter = ArrayAdapter(this, + android.R.layout.simple_list_item_activated_1, mStrings) + + listView.apply { + isTextFilterEnabled = true + + // Tell the list view to show one checked/activated item at a time. + choiceMode = ListView.CHOICE_MODE_SINGLE + + // Start with first item activated. + // Make the newly clicked item the currently selected one. + listView.setItemChecked(0, true) + } } - @Override - protected void onListItemClick(ListView l, View v, int position, long id) { + override fun onListItemClick(l: ListView, v: View, position: Int, id: Long) { // Make the newly clicked item the currently selected one. - getListView().setItemChecked(position, true); + listView.setItemChecked(position, true) } - private String[] mStrings = Cheeses.sCheeseStrings; + private val mStrings = Cheeses.sCheeseStrings } diff --git a/mobile/src/main/java/com/example/android/apis/view/List2.java b/mobile/src/main/java/com/example/android/apis/view/List2.java deleted file mode 100644 index 4dca2a76e..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/List2.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2007 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.apis.view; - -import android.app.ListActivity; -import android.database.Cursor; -import android.provider.ContactsContract.Contacts; -import android.os.Bundle; -import android.widget.ListAdapter; -import android.widget.SimpleCursorAdapter; - -/** - * A list view example where the - * data comes from a cursor. - */ -public class List2 extends ListActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - // Get a cursor with all people - Cursor c = getContentResolver().query(Contacts.CONTENT_URI, - CONTACT_PROJECTION, null, null, null); - startManagingCursor(c); - - ListAdapter adapter = new SimpleCursorAdapter(this, - // Use a template that displays a text view - android.R.layout.simple_list_item_1, - // Give the cursor to the list adatper - c, - // Map the NAME column in the people database to... - new String[] {Contacts.DISPLAY_NAME}, - // The "text1" view defined in the XML template - new int[] {android.R.id.text1}); - setListAdapter(adapter); - } - - private static final String[] CONTACT_PROJECTION = new String[] { - Contacts._ID, - Contacts.DISPLAY_NAME - }; -} \ No newline at end of file diff --git a/mobile/src/main/java/com/example/android/apis/view/List2.kt b/mobile/src/main/java/com/example/android/apis/view/List2.kt new file mode 100644 index 000000000..e4e6758ba --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/List2.kt @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2007 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.apis.view + +import android.app.ListActivity +import android.app.LoaderManager +import android.content.CursorLoader +import android.content.Loader +import android.database.Cursor +import android.provider.ContactsContract.Contacts +import android.os.Bundle +import android.widget.SimpleCursorAdapter + +/** + * A list view example where the + * data comes from a cursor. + */ +class List2 : ListActivity(), LoaderManager.LoaderCallbacks { + + // Get a cursor with all people + private val mCursor: Cursor by lazy { + contentResolver.query(Contacts.CONTENT_URI, + CONTACT_PROJECTION, null, null, null) + } + + private val mAdapter: SimpleCursorAdapter by lazy { + SimpleCursorAdapter(this@List2, + // Use a template that displays a text view + android.R.layout.simple_list_item_1, + // Give the cursor to the list adatper + mCursor, + // Map the NAME column in the people database to... + arrayOf(Contacts.DISPLAY_NAME), + // The "text1" view defined in the XML template + intArrayOf(android.R.id.text1), + 0) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + listAdapter = mAdapter + + loaderManager.initLoader(0, null, this) + } + + override fun onCreateLoader(id: Int, args: Bundle?): Loader { + return CursorLoader(this@List2, Contacts.CONTENT_URI, CONTACT_PROJECTION, null, null, null); + } + + override fun onLoadFinished(loader: Loader?, cursor: Cursor?) { + mAdapter.swapCursor(cursor) + } + + override fun onLoaderReset(loader: Loader?) { + mAdapter.swapCursor(null) + } + + companion object { + private val CONTACT_PROJECTION = arrayOf(Contacts._ID, Contacts.DISPLAY_NAME) + } +} \ No newline at end of file diff --git a/mobile/src/main/java/com/example/android/apis/view/List3.java b/mobile/src/main/java/com/example/android/apis/view/List3.java deleted file mode 100644 index 9c3b4b428..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/List3.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2007 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.apis.view; - -import android.app.ListActivity; -import android.database.Cursor; -import android.os.Bundle; -import android.provider.ContactsContract.CommonDataKinds.Phone; -import android.view.View; -import android.widget.SimpleCursorAdapter; -import android.widget.TextView; - - /** - * A list view example where the - * data comes from a cursor, and a - * SimpleCursorListAdapter is used to map each item to a two-line - * display. - */ -public class List3 extends ListActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - // Get a cursor with all phones - Cursor c = getContentResolver().query(Phone.CONTENT_URI, - PHONE_PROJECTION, null, null, null); - startManagingCursor(c); - - // Map Cursor columns to views defined in simple_list_item_2.xml - SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, - android.R.layout.simple_list_item_2, c, - new String[] { - Phone.TYPE, - Phone.NUMBER - }, - new int[] { android.R.id.text1, android.R.id.text2 }); - //Used to display a readable string for the phone type - adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { - public boolean setViewValue(View view, Cursor cursor, int columnIndex) { - //Let the adapter handle the binding if the column is not TYPE - if (columnIndex != COLUMN_TYPE) { - return false; - } - int type = cursor.getInt(COLUMN_TYPE); - String label = null; - //Custom type? Then get the custom label - if (type == Phone.TYPE_CUSTOM) { - label = cursor.getString(COLUMN_LABEL); - } - //Get the readable string - String text = (String) Phone.getTypeLabel(getResources(), type, label); - //Set text - ((TextView) view).setText(text); - return true; - } - }); - setListAdapter(adapter); - } - - private static final String[] PHONE_PROJECTION = new String[] { - Phone._ID, - Phone.TYPE, - Phone.LABEL, - Phone.NUMBER - }; - - private static final int COLUMN_TYPE = 1;; - private static final int COLUMN_LABEL = 2; -} \ No newline at end of file diff --git a/mobile/src/main/java/com/example/android/apis/view/List3.kt b/mobile/src/main/java/com/example/android/apis/view/List3.kt new file mode 100644 index 000000000..bbc237f7f --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/List3.kt @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2007 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.apis.view + +import android.app.ListActivity +import android.database.Cursor +import android.os.Bundle +import android.provider.ContactsContract.CommonDataKinds.Phone +import android.widget.SimpleCursorAdapter +import android.widget.TextView + +/** + * A list view example where the + * data comes from a cursor, and a + * SimpleCursorListAdapter is used to map each item to a two-line + * display. + */ +class List3 : ListActivity() { + // Get a cursor with all phones + private val mCursor: Cursor by lazy { + contentResolver.query(Phone.CONTENT_URI, + PHONE_PROJECTION, null, null, null) + } + private val mAdapter: SimpleCursorAdapter by lazy { + // Map Cursor columns to views defined in simple_list_item_2.xml + SimpleCursorAdapter(this, + android.R.layout.simple_list_item_2, mCursor, + arrayOf(Phone.TYPE, Phone.NUMBER), + intArrayOf(android.R.id.text1, android.R.id.text2), 0) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + //Used to display a readable string for the phone type + mAdapter.viewBinder = SimpleCursorAdapter.ViewBinder { view, cursor, columnIndex -> + //Let the adapter handle the binding if the column is not TYPE + if (columnIndex != COLUMN_TYPE) { + return@ViewBinder false + } + val type = cursor.getInt(COLUMN_TYPE) + var label: String? = null + //Custom type? Then get the custom label + if (type == Phone.TYPE_CUSTOM) { + label = cursor.getString(COLUMN_LABEL) + } + //Get the readable string + val text = Phone.getTypeLabel(resources, type, label) as String + //Set text + (view as TextView).text = text + true + } + + listAdapter = mAdapter + } + + companion object { + private val PHONE_PROJECTION = arrayOf(Phone._ID, Phone.TYPE, Phone.LABEL, Phone.NUMBER) + + private val COLUMN_TYPE = 1 + private val COLUMN_LABEL = 2 + } +} \ No newline at end of file diff --git a/mobile/src/main/java/com/example/android/apis/view/List4.java b/mobile/src/main/java/com/example/android/apis/view/List4.java deleted file mode 100644 index 9c18a5d4b..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/List4.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (C) 2007 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.apis.view; - -import com.example.android.apis.Shakespeare; - -import android.app.ListActivity; -import android.content.Context; -import android.os.Bundle; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.LinearLayout; -import android.widget.TextView; - - -/** - * A list view example where the data comes from a custom ListAdapter - */ -public class List4 extends ListActivity { - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - // Use our own list adapter - setListAdapter(new SpeechListAdapter(this)); - } - - - /** - * A sample ListAdapter that presents content from arrays of speeches and - * text. - * - */ - private class SpeechListAdapter extends BaseAdapter { - public SpeechListAdapter(Context context) { - mContext = context; - } - - /** - * The number of items in the list is determined by the number of speeches - * in our array. - * - * @see android.widget.ListAdapter#getCount() - */ - public int getCount() { - return Shakespeare.TITLES.length; - } - - /** - * Since the data comes from an array, just returning the index is - * sufficent to get at the data. If we were using a more complex data - * structure, we would return whatever object represents one row in the - * list. - * - * @see android.widget.ListAdapter#getItem(int) - */ - public Object getItem(int position) { - return position; - } - - /** - * Use the array index as a unique id. - * - * @see android.widget.ListAdapter#getItemId(int) - */ - public long getItemId(int position) { - return position; - } - - /** - * Make a SpeechView to hold each row. - * - * @see android.widget.ListAdapter#getView(int, android.view.View, - * android.view.ViewGroup) - */ - public View getView(int position, View convertView, ViewGroup parent) { - SpeechView sv; - if (convertView == null) { - sv = new SpeechView(mContext, Shakespeare.TITLES[position], - Shakespeare.DIALOGUE[position]); - } else { - sv = (SpeechView) convertView; - sv.setTitle(Shakespeare.TITLES[position]); - sv.setDialogue(Shakespeare.DIALOGUE[position]); - } - - return sv; - } - - /** - * Remember our context so we can use it when constructing views. - */ - private Context mContext; - } - - /** - * We will use a SpeechView to display each speech. It's just a LinearLayout - * with two text fields. - * - */ - private class SpeechView extends LinearLayout { - public SpeechView(Context context, String title, String words) { - super(context); - - this.setOrientation(VERTICAL); - - // Here we build the child views in code. They could also have - // been specified in an XML file. - - mTitle = new TextView(context); - mTitle.setText(title); - addView(mTitle, new LinearLayout.LayoutParams( - LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); - - mDialogue = new TextView(context); - mDialogue.setText(words); - addView(mDialogue, new LinearLayout.LayoutParams( - LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); - } - - /** - * Convenience method to set the title of a SpeechView - */ - public void setTitle(String title) { - mTitle.setText(title); - } - - /** - * Convenience method to set the dialogue of a SpeechView - */ - public void setDialogue(String words) { - mDialogue.setText(words); - } - - private TextView mTitle; - private TextView mDialogue; - } -} diff --git a/mobile/src/main/java/com/example/android/apis/view/List4.kt b/mobile/src/main/java/com/example/android/apis/view/List4.kt new file mode 100644 index 000000000..ea402d8fb --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/List4.kt @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2007 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.apis.view + +import com.example.android.apis.Shakespeare + +import android.app.ListActivity +import android.content.Context +import android.os.Bundle +import android.view.View +import android.view.ViewGroup +import android.widget.BaseAdapter +import android.widget.LinearLayout +import android.widget.TextView + + +/** + * A list view example where the data comes from a custom ListAdapter + */ +class List4 : ListActivity() { + + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + // Use our own list adapter + listAdapter = SpeechListAdapter(this) + } + + + /** + * A sample ListAdapter that presents content from arrays of speeches and + * text. + * + */ + private inner class SpeechListAdapter( + /** + * Remember our context so we can use it when constructing views. + */ + private val mContext: Context) : BaseAdapter() { + + /** + * The number of items in the list is determined by the number of speeches + * in our array. + * + * @see android.widget.ListAdapter.getCount + */ + override fun getCount(): Int { + return Shakespeare.TITLES.size + } + + /** + * Since the data comes from an array, just returning the index is + * sufficent to get at the data. If we were using a more complex data + * structure, we would return whatever object represents one row in the + * list. + * + * @see android.widget.ListAdapter.getItem + */ + override fun getItem(position: Int): Any { + return position + } + + /** + * Use the array index as a unique id. + * + * @see android.widget.ListAdapter.getItemId + */ + override fun getItemId(position: Int): Long { + return position.toLong() + } + + /** + * Make a SpeechView to hold each row. + * + * @see android.widget.ListAdapter.getView + */ + override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { + val sv: SpeechView + if (convertView == null) { + sv = SpeechView(mContext, Shakespeare.TITLES[position], + Shakespeare.DIALOGUE[position]) + } else { + sv = convertView as SpeechView + sv.setTitle(Shakespeare.TITLES[position]) + sv.setDialogue(Shakespeare.DIALOGUE[position]) + } + + return sv + } + } + + /** + * We will use a SpeechView to display each speech. It's just a LinearLayout + * with two text fields. + * + */ + private inner class SpeechView(context: Context, title: String, words: String) : LinearLayout(context) { + private val mTitle: TextView + private val mDialogue: TextView + + init { + this.orientation = LinearLayout.VERTICAL + + // Here we build the child views in code. They could also have + // been specified in an XML file. + + mTitle = TextView(context) + mTitle.text = title + addView(mTitle, LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)) + + mDialogue = TextView(context) + mDialogue.text = words + addView(mDialogue, LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)) + } + + /** + * Convenience method to set the title of a SpeechView + */ + fun setTitle(title: String) { + mTitle.text = title + } + + /** + * Convenience method to set the dialogue of a SpeechView + */ + fun setDialogue(words: String) { + mDialogue.text = words + } + } +} diff --git a/mobile/src/main/java/com/example/android/apis/view/List5.java b/mobile/src/main/java/com/example/android/apis/view/List5.java deleted file mode 100644 index 76b446926..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/List5.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2007 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.apis.view; - -// Need the following import to get access to the app resources, since this -// class is in a sub-package. -import android.app.ListActivity; -import android.content.Context; -import android.os.Bundle; -import android.view.View; -import android.view.ViewGroup; -import android.view.LayoutInflater; -import android.widget.BaseAdapter; -import android.widget.TextView; - - -/** - * A list view example with separators. - */ -public class List5 extends ListActivity { - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setListAdapter(new MyListAdapter(this)); - } - - private class MyListAdapter extends BaseAdapter { - public MyListAdapter(Context context) { - mContext = context; - } - - public int getCount() { - return mStrings.length; - } - - @Override - public boolean areAllItemsEnabled() { - return false; - } - - @Override - public boolean isEnabled(int position) { - return !mStrings[position].startsWith("-"); - } - - public Object getItem(int position) { - return position; - } - - public long getItemId(int position) { - return position; - } - - public View getView(int position, View convertView, ViewGroup parent) { - TextView tv; - if (convertView == null) { - tv = (TextView) LayoutInflater.from(mContext).inflate( - android.R.layout.simple_expandable_list_item_1, parent, false); - } else { - tv = (TextView) convertView; - } - tv.setText(mStrings[position]); - return tv; - } - - private Context mContext; - } - - private String[] mStrings = { - "----------", - "----------", - "Abbaye de Belloc", - "Abbaye du Mont des Cats", - "Abertam", - "----------", - "Abondance", - "----------", - "Ackawi", - "Acorn", - "Adelost", - "Affidelice au Chablis", - "Afuega'l Pitu", - "Airag", - "----------", - "Airedale", - "Aisy Cendre", - "----------", - "Allgauer Emmentaler", - "Alverca", - "Ambert", - "American Cheese", - "Ami du Chambertin", - "----------", - "----------", - "Anejo Enchilado", - "Anneau du Vic-Bilh", - "Anthoriro", - "----------", - "----------" - }; - -} diff --git a/mobile/src/main/java/com/example/android/apis/view/List5.kt b/mobile/src/main/java/com/example/android/apis/view/List5.kt new file mode 100644 index 000000000..367f78bbd --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/List5.kt @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2007 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.apis.view + +// Need the following import to get access to the app resources, since this +// class is in a sub-package. +import android.app.ListActivity +import android.content.Context +import android.os.Bundle +import android.view.View +import android.view.ViewGroup +import android.view.LayoutInflater +import android.widget.BaseAdapter +import android.widget.TextView + +/** + * A list view example with separators. + */ +class List5 : ListActivity() { + + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + listAdapter = MyListAdapter(this) + } + + private inner class MyListAdapter(private val mContext: Context) : BaseAdapter() { + + override fun getCount(): Int { + return mStrings.size + } + + override fun areAllItemsEnabled(): Boolean { + return false + } + + override fun isEnabled(position: Int): Boolean { + return !mStrings[position].startsWith("-") + } + + override fun getItem(position: Int): Any { + return position + } + + override fun getItemId(position: Int): Long { + return position.toLong() + } + + override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { + val tv: TextView + if (convertView == null) { + tv = LayoutInflater.from(mContext).inflate( + android.R.layout.simple_expandable_list_item_1, parent, false) as TextView + } else { + tv = convertView as TextView + } + tv.text = mStrings[position] + return tv + } + } + + private val mStrings = arrayOf("----------", "----------", "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "----------", "Abondance", "----------", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "----------", "Airedale", "Aisy Cendre", "----------", "Allgauer Emmentaler", "Alverca", "Ambert", "American Cheese", "Ami du Chambertin", "----------", "----------", "Anejo Enchilado", "Anneau du Vic-Bilh", "Anthoriro", "----------", "----------") +} \ No newline at end of file diff --git a/mobile/src/main/java/com/example/android/apis/view/List6.java b/mobile/src/main/java/com/example/android/apis/view/List6.java deleted file mode 100644 index 2d4536ff6..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/List6.java +++ /dev/null @@ -1,410 +0,0 @@ -/* - * Copyright (C) 2007 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.apis.view; - -import android.app.ListActivity; -import android.content.Context; -import android.os.Bundle; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.LinearLayout; -import android.widget.ListView; -import android.widget.TextView; - - -/** - * A list view example where the - * data comes from a custom - * ListAdapter - */ -public class List6 extends ListActivity -{ - - @Override - public void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - - // Use our own list adapter - setListAdapter(new SpeechListAdapter(this)); - } - - - @Override - protected void onListItemClick(ListView l, View v, int position, long id) - { - ((SpeechListAdapter)getListAdapter()).toggle(position); - } - - /** - * A sample ListAdapter that presents content - * from arrays of speeches and text. - * - */ - private class SpeechListAdapter extends BaseAdapter { - public SpeechListAdapter(Context context) - { - mContext = context; - } - - - /** - * The number of items in the list is determined by the number of speeches - * in our array. - * - * @see android.widget.ListAdapter#getCount() - */ - public int getCount() { - return mTitles.length; - } - - /** - * Since the data comes from an array, just returning - * the index is sufficent to get at the data. If we - * were using a more complex data structure, we - * would return whatever object represents one - * row in the list. - * - * @see android.widget.ListAdapter#getItem(int) - */ - public Object getItem(int position) { - return position; - } - - /** - * Use the array index as a unique id. - * @see android.widget.ListAdapter#getItemId(int) - */ - public long getItemId(int position) { - return position; - } - - /** - * Make a SpeechView to hold each row. - * @see android.widget.ListAdapter#getView(int, android.view.View, android.view.ViewGroup) - */ - public View getView(int position, View convertView, ViewGroup parent) { - SpeechView sv; - if (convertView == null) { - sv = new SpeechView(mContext, mTitles[position], mDialogue[position], mExpanded[position]); - } else { - sv = (SpeechView)convertView; - sv.setTitle(mTitles[position]); - sv.setDialogue(mDialogue[position]); - sv.setExpanded(mExpanded[position]); - } - - return sv; - } - - public void toggle(int position) { - mExpanded[position] = !mExpanded[position]; - notifyDataSetChanged(); - } - - /** - * Remember our context so we can use it when constructing views. - */ - private Context mContext; - - /** - * Our data, part 1. - */ - private String[] mTitles = - { - "Henry IV (1)", - "Henry V", - "Henry VIII", - "Richard II", - "Richard III", - "Merchant of Venice", - "Othello", - "King Lear" - }; - - /** - * Our data, part 2. - */ - private String[] mDialogue = - { - "So shaken as we are, so wan with care," + - "Find we a time for frighted peace to pant," + - "And breathe short-winded accents of new broils" + - "To be commenced in strands afar remote." + - "No more the thirsty entrance of this soil" + - "Shall daub her lips with her own children's blood;" + - "Nor more shall trenching war channel her fields," + - "Nor bruise her flowerets with the armed hoofs" + - "Of hostile paces: those opposed eyes," + - "Which, like the meteors of a troubled heaven," + - "All of one nature, of one substance bred," + - "Did lately meet in the intestine shock" + - "And furious close of civil butchery" + - "Shall now, in mutual well-beseeming ranks," + - "March all one way and be no more opposed" + - "Against acquaintance, kindred and allies:" + - "The edge of war, like an ill-sheathed knife," + - "No more shall cut his master. Therefore, friends," + - "As far as to the sepulchre of Christ," + - "Whose soldier now, under whose blessed cross" + - "We are impressed and engaged to fight," + - "Forthwith a power of English shall we levy;" + - "Whose arms were moulded in their mothers' womb" + - "To chase these pagans in those holy fields" + - "Over whose acres walk'd those blessed feet" + - "Which fourteen hundred years ago were nail'd" + - "For our advantage on the bitter cross." + - "But this our purpose now is twelve month old," + - "And bootless 'tis to tell you we will go:" + - "Therefore we meet not now. Then let me hear" + - "Of you, my gentle cousin Westmoreland," + - "What yesternight our council did decree" + - "In forwarding this dear expedience.", - - "Hear him but reason in divinity," + - "And all-admiring with an inward wish" + - "You would desire the king were made a prelate:" + - "Hear him debate of commonwealth affairs," + - "You would say it hath been all in all his study:" + - "List his discourse of war, and you shall hear" + - "A fearful battle render'd you in music:" + - "Turn him to any cause of policy," + - "The Gordian knot of it he will unloose," + - "Familiar as his garter: that, when he speaks," + - "The air, a charter'd libertine, is still," + - "And the mute wonder lurketh in men's ears," + - "To steal his sweet and honey'd sentences;" + - "So that the art and practic part of life" + - "Must be the mistress to this theoric:" + - "Which is a wonder how his grace should glean it," + - "Since his addiction was to courses vain," + - "His companies unletter'd, rude and shallow," + - "His hours fill'd up with riots, banquets, sports," + - "And never noted in him any study," + - "Any retirement, any sequestration" + - "From open haunts and popularity.", - - "I come no more to make you laugh: things now," + - "That bear a weighty and a serious brow," + - "Sad, high, and working, full of state and woe," + - "Such noble scenes as draw the eye to flow," + - "We now present. Those that can pity, here" + - "May, if they think it well, let fall a tear;" + - "The subject will deserve it. Such as give" + - "Their money out of hope they may believe," + - "May here find truth too. Those that come to see" + - "Only a show or two, and so agree" + - "The play may pass, if they be still and willing," + - "I'll undertake may see away their shilling" + - "Richly in two short hours. Only they" + - "That come to hear a merry bawdy play," + - "A noise of targets, or to see a fellow" + - "In a long motley coat guarded with yellow," + - "Will be deceived; for, gentle hearers, know," + - "To rank our chosen truth with such a show" + - "As fool and fight is, beside forfeiting" + - "Our own brains, and the opinion that we bring," + - "To make that only true we now intend," + - "Will leave us never an understanding friend." + - "Therefore, for goodness' sake, and as you are known" + - "The first and happiest hearers of the town," + - "Be sad, as we would make ye: think ye see" + - "The very persons of our noble story" + - "As they were living; think you see them great," + - "And follow'd with the general throng and sweat" + - "Of thousand friends; then in a moment, see" + - "How soon this mightiness meets misery:" + - "And, if you can be merry then, I'll say" + - "A man may weep upon his wedding-day.", - - "First, heaven be the record to my speech!" + - "In the devotion of a subject's love," + - "Tendering the precious safety of my prince," + - "And free from other misbegotten hate," + - "Come I appellant to this princely presence." + - "Now, Thomas Mowbray, do I turn to thee," + - "And mark my greeting well; for what I speak" + - "My body shall make good upon this earth," + - "Or my divine soul answer it in heaven." + - "Thou art a traitor and a miscreant," + - "Too good to be so and too bad to live," + - "Since the more fair and crystal is the sky," + - "The uglier seem the clouds that in it fly." + - "Once more, the more to aggravate the note," + - "With a foul traitor's name stuff I thy throat;" + - "And wish, so please my sovereign, ere I move," + - "What my tongue speaks my right drawn sword may prove.", - - "Now is the winter of our discontent" + - "Made glorious summer by this sun of York;" + - "And all the clouds that lour'd upon our house" + - "In the deep bosom of the ocean buried." + - "Now are our brows bound with victorious wreaths;" + - "Our bruised arms hung up for monuments;" + - "Our stern alarums changed to merry meetings," + - "Our dreadful marches to delightful measures." + - "Grim-visaged war hath smooth'd his wrinkled front;" + - "And now, instead of mounting barded steeds" + - "To fright the souls of fearful adversaries," + - "He capers nimbly in a lady's chamber" + - "To the lascivious pleasing of a lute." + - "But I, that am not shaped for sportive tricks," + - "Nor made to court an amorous looking-glass;" + - "I, that am rudely stamp'd, and want love's majesty" + - "To strut before a wanton ambling nymph;" + - "I, that am curtail'd of this fair proportion," + - "Cheated of feature by dissembling nature," + - "Deformed, unfinish'd, sent before my time" + - "Into this breathing world, scarce half made up," + - "And that so lamely and unfashionable" + - "That dogs bark at me as I halt by them;" + - "Why, I, in this weak piping time of peace," + - "Have no delight to pass away the time," + - "Unless to spy my shadow in the sun" + - "And descant on mine own deformity:" + - "And therefore, since I cannot prove a lover," + - "To entertain these fair well-spoken days," + - "I am determined to prove a villain" + - "And hate the idle pleasures of these days." + - "Plots have I laid, inductions dangerous," + - "By drunken prophecies, libels and dreams," + - "To set my brother Clarence and the king" + - "In deadly hate the one against the other:" + - "And if King Edward be as true and just" + - "As I am subtle, false and treacherous," + - "This day should Clarence closely be mew'd up," + - "About a prophecy, which says that 'G'" + - "Of Edward's heirs the murderer shall be." + - "Dive, thoughts, down to my soul: here" + - "Clarence comes.", - - "To bait fish withal: if it will feed nothing else," + - "it will feed my revenge. He hath disgraced me, and" + - "hindered me half a million; laughed at my losses," + - "mocked at my gains, scorned my nation, thwarted my" + - "bargains, cooled my friends, heated mine" + - "enemies; and what's his reason? I am a Jew. Hath" + - "not a Jew eyes? hath not a Jew hands, organs," + - "dimensions, senses, affections, passions? fed with" + - "the same food, hurt with the same weapons, subject" + - "to the same diseases, healed by the same means," + - "warmed and cooled by the same winter and summer, as" + - "a Christian is? If you prick us, do we not bleed?" + - "if you tickle us, do we not laugh? if you poison" + - "us, do we not die? and if you wrong us, shall we not" + - "revenge? If we are like you in the rest, we will" + - "resemble you in that. If a Jew wrong a Christian," + - "what is his humility? Revenge. If a Christian" + - "wrong a Jew, what should his sufferance be by" + - "Christian example? Why, revenge. The villany you" + - "teach me, I will execute, and it shall go hard but I" + - "will better the instruction.", - - "Virtue! a fig! 'tis in ourselves that we are thus" + - "or thus. Our bodies are our gardens, to the which" + - "our wills are gardeners: so that if we will plant" + - "nettles, or sow lettuce, set hyssop and weed up" + - "thyme, supply it with one gender of herbs, or" + - "distract it with many, either to have it sterile" + - "with idleness, or manured with industry, why, the" + - "power and corrigible authority of this lies in our" + - "wills. If the balance of our lives had not one" + - "scale of reason to poise another of sensuality, the" + - "blood and baseness of our natures would conduct us" + - "to most preposterous conclusions: but we have" + - "reason to cool our raging motions, our carnal" + - "stings, our unbitted lusts, whereof I take this that" + - "you call love to be a sect or scion.", - - "Blow, winds, and crack your cheeks! rage! blow!" + - "You cataracts and hurricanoes, spout" + - "Till you have drench'd our steeples, drown'd the cocks!" + - "You sulphurous and thought-executing fires," + - "Vaunt-couriers to oak-cleaving thunderbolts," + - "Singe my white head! And thou, all-shaking thunder," + - "Smite flat the thick rotundity o' the world!" + - "Crack nature's moulds, an germens spill at once," + - "That make ingrateful man!" - }; - - /** - * Our data, part 3. - */ - private boolean[] mExpanded = - { - false, - false, - false, - false, - false, - false, - false, - false - }; - } - - /** - * We will use a SpeechView to display each speech. It's just a LinearLayout - * with two text fields. - * - */ - private class SpeechView extends LinearLayout { - public SpeechView(Context context, String title, String dialogue, boolean expanded) { - super(context); - - this.setOrientation(VERTICAL); - - // Here we build the child views in code. They could also have - // been specified in an XML file. - - mTitle = new TextView(context); - mTitle.setText(title); - addView(mTitle, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); - - mDialogue = new TextView(context); - mDialogue.setText(dialogue); - addView(mDialogue, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); - - mDialogue.setVisibility(expanded ? VISIBLE : GONE); - } - - /** - * Convenience method to set the title of a SpeechView - */ - public void setTitle(String title) { - mTitle.setText(title); - } - - /** - * Convenience method to set the dialogue of a SpeechView - */ - public void setDialogue(String words) { - mDialogue.setText(words); - } - - /** - * Convenience method to expand or hide the dialogue - */ - public void setExpanded(boolean expanded) { - mDialogue.setVisibility(expanded ? VISIBLE : GONE); - } - - private TextView mTitle; - private TextView mDialogue; - } -} diff --git a/mobile/src/main/java/com/example/android/apis/view/List6.kt b/mobile/src/main/java/com/example/android/apis/view/List6.kt new file mode 100644 index 000000000..f526b9a97 --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/List6.kt @@ -0,0 +1,375 @@ +/* + * Copyright (C) 2007 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.apis.view + +import android.app.ListActivity +import android.content.Context +import android.os.Bundle +import android.view.View +import android.view.ViewGroup +import android.widget.BaseAdapter +import android.widget.LinearLayout +import android.widget.ListView +import android.widget.TextView + +/** + * A list view example where the + * data comes from a custom + * ListAdapter + */ +class List6 : ListActivity() { + + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + // Use our own list adapter + listAdapter = SpeechListAdapter(this) + } + + + override fun onListItemClick(l: ListView, v: View, position: Int, id: Long) { + (listAdapter as SpeechListAdapter).toggle(position) + } + + /** + * A sample ListAdapter that presents content + * from arrays of speeches and text. + * + */ + private inner class SpeechListAdapter( + /** + * Remember our context so we can use it when constructing views. + */ + private val mContext: Context) : BaseAdapter() { + + + /** + * The number of items in the list is determined by the number of speeches + * in our array. + * + * @see android.widget.ListAdapter.getCount + */ + override fun getCount(): Int { + return mTitles.size + } + + /** + * Since the data comes from an array, just returning + * the index is sufficent to get at the data. If we + * were using a more complex data structure, we + * would return whatever object represents one + * row in the list. + * + * @see android.widget.ListAdapter.getItem + */ + override fun getItem(position: Int): Any { + return position + } + + /** + * Use the array index as a unique id. + * @see android.widget.ListAdapter.getItemId + */ + override fun getItemId(position: Int): Long { + return position.toLong() + } + + /** + * Make a SpeechView to hold each row. + * @see android.widget.ListAdapter.getView + */ + override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { + return when (convertView) { + null -> SpeechView(mContext, mTitles[position], mDialogue[position], mExpanded[position]) + else -> + (convertView as SpeechView).apply { + setTitle(mTitles[position]) + setDialogue(mDialogue[position]) + setExpanded(mExpanded[position]) + } + } + } + + fun toggle(position: Int) { + mExpanded[position] = !mExpanded[position] + notifyDataSetChanged() + } + + /** + * Our data, part 1. + */ + private val mTitles = arrayOf("Henry IV (1)", "Henry V", "Henry VIII", "Richard II", "Richard III", "Merchant of Venice", "Othello", "King Lear") + + /** + * Our data, part 2. + */ + private val mDialogue = arrayOf("So shaken as we are, so wan with care," + + "Find we a time for frighted peace to pant," + + "And breathe short-winded accents of new broils" + + "To be commenced in strands afar remote." + + "No more the thirsty entrance of this soil" + + "Shall daub her lips with her own children's blood;" + + "Nor more shall trenching war channel her fields," + + "Nor bruise her flowerets with the armed hoofs" + + "Of hostile paces: those opposed eyes," + + "Which, like the meteors of a troubled heaven," + + "All of one nature, of one substance bred," + + "Did lately meet in the intestine shock" + + "And furious close of civil butchery" + + "Shall now, in mutual well-beseeming ranks," + + "March all one way and be no more opposed" + + "Against acquaintance, kindred and allies:" + + "The edge of war, like an ill-sheathed knife," + + "No more shall cut his master. Therefore, friends," + + "As far as to the sepulchre of Christ," + + "Whose soldier now, under whose blessed cross" + + "We are impressed and engaged to fight," + + "Forthwith a power of English shall we levy;" + + "Whose arms were moulded in their mothers' womb" + + "To chase these pagans in those holy fields" + + "Over whose acres walk'd those blessed feet" + + "Which fourteen hundred years ago were nail'd" + + "For our advantage on the bitter cross." + + "But this our purpose now is twelve month old," + + "And bootless 'tis to tell you we will go:" + + "Therefore we meet not now. Then let me hear" + + "Of you, my gentle cousin Westmoreland," + + "What yesternight our council did decree" + + "In forwarding this dear expedience.", + + "Hear him but reason in divinity," + + "And all-admiring with an inward wish" + + "You would desire the king were made a prelate:" + + "Hear him debate of commonwealth affairs," + + "You would say it hath been all in all his study:" + + "List his discourse of war, and you shall hear" + + "A fearful battle render'd you in music:" + + "Turn him to any cause of policy," + + "The Gordian knot of it he will unloose," + + "Familiar as his garter: that, when he speaks," + + "The air, a charter'd libertine, is still," + + "And the mute wonder lurketh in men's ears," + + "To steal his sweet and honey'd sentences;" + + "So that the art and practic part of life" + + "Must be the mistress to this theoric:" + + "Which is a wonder how his grace should glean it," + + "Since his addiction was to courses vain," + + "His companies unletter'd, rude and shallow," + + "His hours fill'd up with riots, banquets, sports," + + "And never noted in him any study," + + "Any retirement, any sequestration" + + "From open haunts and popularity.", + + "I come no more to make you laugh: things now," + + "That bear a weighty and a serious brow," + + "Sad, high, and working, full of state and woe," + + "Such noble scenes as draw the eye to flow," + + "We now present. Those that can pity, here" + + "May, if they think it well, let fall a tear;" + + "The subject will deserve it. Such as give" + + "Their money out of hope they may believe," + + "May here find truth too. Those that come to see" + + "Only a show or two, and so agree" + + "The play may pass, if they be still and willing," + + "I'll undertake may see away their shilling" + + "Richly in two short hours. Only they" + + "That come to hear a merry bawdy play," + + "A noise of targets, or to see a fellow" + + "In a long motley coat guarded with yellow," + + "Will be deceived; for, gentle hearers, know," + + "To rank our chosen truth with such a show" + + "As fool and fight is, beside forfeiting" + + "Our own brains, and the opinion that we bring," + + "To make that only true we now intend," + + "Will leave us never an understanding friend." + + "Therefore, for goodness' sake, and as you are known" + + "The first and happiest hearers of the town," + + "Be sad, as we would make ye: think ye see" + + "The very persons of our noble story" + + "As they were living; think you see them great," + + "And follow'd with the general throng and sweat" + + "Of thousand friends; then in a moment, see" + + "How soon this mightiness meets misery:" + + "And, if you can be merry then, I'll say" + + "A man may weep upon his wedding-day.", + + "First, heaven be the record to my speech!" + + "In the devotion of a subject's love," + + "Tendering the precious safety of my prince," + + "And free from other misbegotten hate," + + "Come I appellant to this princely presence." + + "Now, Thomas Mowbray, do I turn to thee," + + "And mark my greeting well; for what I speak" + + "My body shall make good upon this earth," + + "Or my divine soul answer it in heaven." + + "Thou art a traitor and a miscreant," + + "Too good to be so and too bad to live," + + "Since the more fair and crystal is the sky," + + "The uglier seem the clouds that in it fly." + + "Once more, the more to aggravate the note," + + "With a foul traitor's name stuff I thy throat;" + + "And wish, so please my sovereign, ere I move," + + "What my tongue speaks my right drawn sword may prove.", + + "Now is the winter of our discontent" + + "Made glorious summer by this sun of York;" + + "And all the clouds that lour'd upon our house" + + "In the deep bosom of the ocean buried." + + "Now are our brows bound with victorious wreaths;" + + "Our bruised arms hung up for monuments;" + + "Our stern alarums changed to merry meetings," + + "Our dreadful marches to delightful measures." + + "Grim-visaged war hath smooth'd his wrinkled front;" + + "And now, instead of mounting barded steeds" + + "To fright the souls of fearful adversaries," + + "He capers nimbly in a lady's chamber" + + "To the lascivious pleasing of a lute." + + "But I, that am not shaped for sportive tricks," + + "Nor made to court an amorous looking-glass;" + + "I, that am rudely stamp'd, and want love's majesty" + + "To strut before a wanton ambling nymph;" + + "I, that am curtail'd of this fair proportion," + + "Cheated of feature by dissembling nature," + + "Deformed, unfinish'd, sent before my time" + + "Into this breathing world, scarce half made up," + + "And that so lamely and unfashionable" + + "That dogs bark at me as I halt by them;" + + "Why, I, in this weak piping time of peace," + + "Have no delight to pass away the time," + + "Unless to spy my shadow in the sun" + + "And descant on mine own deformity:" + + "And therefore, since I cannot prove a lover," + + "To entertain these fair well-spoken days," + + "I am determined to prove a villain" + + "And hate the idle pleasures of these days." + + "Plots have I laid, inductions dangerous," + + "By drunken prophecies, libels and dreams," + + "To set my brother Clarence and the king" + + "In deadly hate the one against the other:" + + "And if King Edward be as true and just" + + "As I am subtle, false and treacherous," + + "This day should Clarence closely be mew'd up," + + "About a prophecy, which says that 'G'" + + "Of Edward's heirs the murderer shall be." + + "Dive, thoughts, down to my soul: here" + + "Clarence comes.", + + "To bait fish withal: if it will feed nothing else," + + "it will feed my revenge. He hath disgraced me, and" + + "hindered me half a million; laughed at my losses," + + "mocked at my gains, scorned my nation, thwarted my" + + "bargains, cooled my friends, heated mine" + + "enemies; and what's his reason? I am a Jew. Hath" + + "not a Jew eyes? hath not a Jew hands, organs," + + "dimensions, senses, affections, passions? fed with" + + "the same food, hurt with the same weapons, subject" + + "to the same diseases, healed by the same means," + + "warmed and cooled by the same winter and summer, as" + + "a Christian is? If you prick us, do we not bleed?" + + "if you tickle us, do we not laugh? if you poison" + + "us, do we not die? and if you wrong us, shall we not" + + "revenge? If we are like you in the rest, we will" + + "resemble you in that. If a Jew wrong a Christian," + + "what is his humility? Revenge. If a Christian" + + "wrong a Jew, what should his sufferance be by" + + "Christian example? Why, revenge. The villany you" + + "teach me, I will execute, and it shall go hard but I" + + "will better the instruction.", + + "Virtue! a fig! 'tis in ourselves that we are thus" + + "or thus. Our bodies are our gardens, to the which" + + "our wills are gardeners: so that if we will plant" + + "nettles, or sow lettuce, set hyssop and weed up" + + "thyme, supply it with one gender of herbs, or" + + "distract it with many, either to have it sterile" + + "with idleness, or manured with industry, why, the" + + "power and corrigible authority of this lies in our" + + "wills. If the balance of our lives had not one" + + "scale of reason to poise another of sensuality, the" + + "blood and baseness of our natures would conduct us" + + "to most preposterous conclusions: but we have" + + "reason to cool our raging motions, our carnal" + + "stings, our unbitted lusts, whereof I take this that" + + "you call love to be a sect or scion.", + + "Blow, winds, and crack your cheeks! rage! blow!" + + "You cataracts and hurricanoes, spout" + + "Till you have drench'd our steeples, drown'd the cocks!" + + "You sulphurous and thought-executing fires," + + "Vaunt-couriers to oak-cleaving thunderbolts," + + "Singe my white head! And thou, all-shaking thunder," + + "Smite flat the thick rotundity o' the world!" + + "Crack nature's moulds, an germens spill at once," + + "That make ingrateful man!") + + /** + * Our data, part 3. + */ + private val mExpanded = booleanArrayOf(false, false, false, false, false, false, false, false) + } + + /** + * We will use a SpeechView to display each speech. It's just a LinearLayout + * with two text fields. + * + */ + private inner class SpeechView(context: Context, title: String, dialogue: String, expanded: Boolean) : LinearLayout(context) { + + private val mTitle: TextView + private val mDialogue: TextView + + init { + this.orientation = LinearLayout.VERTICAL + + // Here we build the child views in code. They could also have + // been specified in an XML file. + + mTitle = TextView(context).apply { + text = title + addView(this, LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)) + } + + mDialogue = TextView(context).apply { + text = dialogue + addView(this, LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)) + + visibility = if (expanded) View.VISIBLE else View.GONE + } + } + + /** + * Convenience method to set the title of a SpeechView + */ + fun setTitle(title: String) { + mTitle.text = title + } + + /** + * Convenience method to set the dialogue of a SpeechView + */ + fun setDialogue(words: String) { + mDialogue.text = words + } + + /** + * Convenience method to expand or hide the dialogue + */ + fun setExpanded(expanded: Boolean) { + mDialogue.visibility = if (expanded) View.VISIBLE else View.GONE + } + } +} diff --git a/mobile/src/main/java/com/example/android/apis/view/List7.java b/mobile/src/main/java/com/example/android/apis/view/List7.java deleted file mode 100644 index ff5406ffe..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/List7.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2007 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.apis.view; - -// Need the following import to get access to the app resources, since this -// class is in a sub-package. -import com.example.android.apis.R; - - -import android.app.ListActivity; -import android.database.Cursor; -import android.provider.ContactsContract.CommonDataKinds.Phone; -import android.os.Bundle; -import android.view.View; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemSelectedListener; -import android.widget.ListAdapter; -import android.widget.SimpleCursorAdapter; -import android.widget.TextView; - -/** - * A list view example where the data comes from a cursor. - */ -public class List7 extends ListActivity implements OnItemSelectedListener { - - private TextView mPhone; - - private static final String[] PHONE_PROJECTION = new String[] { - Phone._ID, - Phone.TYPE, - Phone.LABEL, - Phone.NUMBER, - Phone.DISPLAY_NAME - }; - - private static final int COLUMN_PHONE_TYPE = 1; - private static final int COLUMN_PHONE_LABEL = 2; - private static final int COLUMN_PHONE_NUMBER = 3; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.list_7); - mPhone = (TextView) findViewById(R.id.phone); - getListView().setOnItemSelectedListener(this); - - // Get a cursor with all numbers. - // This query will only return contacts with phone numbers - Cursor c = getContentResolver().query(Phone.CONTENT_URI, - PHONE_PROJECTION, Phone.NUMBER + " NOT NULL", null, null); - startManagingCursor(c); - - ListAdapter adapter = new SimpleCursorAdapter(this, - // Use a template that displays a text view - android.R.layout.simple_list_item_1, - // Give the cursor to the list adapter - c, - // Map the DISPLAY_NAME column to... - new String[] {Phone.DISPLAY_NAME}, - // The "text1" view defined in the XML template - new int[] {android.R.id.text1}); - setListAdapter(adapter); - } - - public void onItemSelected(AdapterView parent, View v, int position, long id) { - if (position >= 0) { - //Get current cursor - Cursor c = (Cursor) parent.getItemAtPosition(position); - int type = c.getInt(COLUMN_PHONE_TYPE); - String phone = c.getString(COLUMN_PHONE_NUMBER); - String label = null; - //Custom type? Then get the custom label - if (type == Phone.TYPE_CUSTOM) { - label = c.getString(COLUMN_PHONE_LABEL); - } - //Get the readable string - String numberType = (String) Phone.getTypeLabel(getResources(), type, label); - String text = numberType + ": " + phone; - mPhone.setText(text); - } - } - - public void onNothingSelected(AdapterView parent) { - } -} diff --git a/mobile/src/main/java/com/example/android/apis/view/List7.kt b/mobile/src/main/java/com/example/android/apis/view/List7.kt new file mode 100644 index 000000000..ca2222546 --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/List7.kt @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2007 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.apis.view + +// Need the following import to get access to the app resources, since this +// class is in a sub-package. +import com.example.android.apis.R + + +import android.app.ListActivity +import android.app.LoaderManager +import android.content.CursorLoader +import android.content.Loader +import android.database.Cursor +import android.provider.ContactsContract.CommonDataKinds.Phone +import android.os.Bundle +import android.provider.ContactsContract +import android.view.View +import android.widget.AdapterView +import android.widget.AdapterView.OnItemSelectedListener +import android.widget.SimpleCursorAdapter +import android.widget.TextView +import kotlinx.android.synthetic.main.list_7.* + +/** + * A list view example where the data comes from a cursor. + */ +class List7 : ListActivity(), OnItemSelectedListener, LoaderManager.LoaderCallbacks { + + private val mPhone: TextView by lazy { phone } + + // Get a cursor with all numbers. + // This query will only return contacts with phone numbers + private val mCursor: Cursor by lazy { + contentResolver.query(Phone.CONTENT_URI, + PHONE_PROJECTION, Phone.NUMBER + " NOT NULL", null, null) + } + + private val mAdapter: SimpleCursorAdapter by lazy { + SimpleCursorAdapter(this, + // Use a template that displays a text view + android.R.layout.simple_list_item_1, + // Give the cursor to the list adapter + mCursor, + // Map the DISPLAY_NAME column to... + arrayOf(Phone.DISPLAY_NAME), + // The "text1" view defined in the XML template + intArrayOf(android.R.id.text1), + 0) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.list_7) + listView.onItemSelectedListener = this + + listAdapter = mAdapter + } + + override fun onItemSelected(parent: AdapterView<*>, v: View, position: Int, id: Long) { + if (position >= 0) { + //Get current cursor + val c = parent.getItemAtPosition(position) as Cursor + val type = c.getInt(COLUMN_PHONE_TYPE) + val phone = c.getString(COLUMN_PHONE_NUMBER) + var label: String? = null + //Custom type? Then get the custom label + if (type == Phone.TYPE_CUSTOM) { + label = c.getString(COLUMN_PHONE_LABEL) + } + //Get the readable string + val numberType = Phone.getTypeLabel(resources, type, label) as String + val text = numberType + ": " + phone + mPhone.text = text + } + } + + override fun onNothingSelected(parent: AdapterView<*>) {} + + override fun onCreateLoader(id: Int, args: Bundle?): Loader { + return CursorLoader(this@List7, ContactsContract.Contacts.CONTENT_URI, PHONE_PROJECTION, null, null, null); + } + + override fun onLoadFinished(loader: Loader?, cursor: Cursor?) { + mAdapter.swapCursor(cursor) + } + + override fun onLoaderReset(loader: Loader?) { + mAdapter.swapCursor(null) + } + + companion object { + + private val PHONE_PROJECTION = arrayOf(Phone._ID, Phone.TYPE, Phone.LABEL, Phone.NUMBER, Phone.DISPLAY_NAME) + + private val COLUMN_PHONE_TYPE = 1 + private val COLUMN_PHONE_LABEL = 2 + private val COLUMN_PHONE_NUMBER = 3 + } +} diff --git a/mobile/src/main/java/com/example/android/apis/view/List8.java b/mobile/src/main/java/com/example/android/apis/view/List8.java deleted file mode 100644 index 1a54aa79c..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/List8.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2007 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.apis.view; - -import com.example.android.apis.R; - -import android.app.ListActivity; -import android.content.Context; -import android.os.Bundle; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewGroup.LayoutParams; -import android.widget.BaseAdapter; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.AbsListView; - -import java.util.ArrayList; - - -/** - * A list view that demonstrates the use of setEmptyView. This example alos uses - * a custom layout file that adds some extra buttons to the screen. - */ -public class List8 extends ListActivity { - - PhotoAdapter mAdapter; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - // Use a custom layout file - setContentView(R.layout.list_8); - - // Tell the list view which view to display when the list is empty - getListView().setEmptyView(findViewById(R.id.empty)); - - // Set up our adapter - mAdapter = new PhotoAdapter(this); - setListAdapter(mAdapter); - - // Wire up the clear button to remove all photos - Button clear = (Button) findViewById(R.id.clear); - clear.setOnClickListener(new View.OnClickListener() { - - public void onClick(View v) { - mAdapter.clearPhotos(); - } }); - - // Wire up the add button to add a new photo - Button add = (Button) findViewById(R.id.add); - add.setOnClickListener(new View.OnClickListener() { - - public void onClick(View v) { - mAdapter.addPhotos(); - } }); - } - - /** - * A simple adapter which maintains an ArrayList of photo resource Ids. - * Each photo is displayed as an image. This adapter supports clearing the - * list of photos and adding a new photo. - * - */ - public class PhotoAdapter extends BaseAdapter { - - private Integer[] mPhotoPool = { - R.drawable.sample_thumb_0, R.drawable.sample_thumb_1, R.drawable.sample_thumb_2, - R.drawable.sample_thumb_3, R.drawable.sample_thumb_4, R.drawable.sample_thumb_5, - R.drawable.sample_thumb_6, R.drawable.sample_thumb_7}; - - private ArrayList mPhotos = new ArrayList(); - - public PhotoAdapter(Context c) { - mContext = c; - } - - public int getCount() { - return mPhotos.size(); - } - - public Object getItem(int position) { - return position; - } - - public long getItemId(int position) { - return position; - } - - public View getView(int position, View convertView, ViewGroup parent) { - // Make an ImageView to show a photo - ImageView i = new ImageView(mContext); - - i.setImageResource(mPhotos.get(position)); - i.setAdjustViewBounds(true); - i.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.WRAP_CONTENT, - LayoutParams.WRAP_CONTENT)); - // Give it a nice background - i.setBackgroundResource(R.drawable.picture_frame); - return i; - } - - private Context mContext; - - public void clearPhotos() { - mPhotos.clear(); - notifyDataSetChanged(); - } - - public void addPhotos() { - int whichPhoto = (int)Math.round(Math.random() * (mPhotoPool.length - 1)); - int newPhoto = mPhotoPool[whichPhoto]; - mPhotos.add(newPhoto); - notifyDataSetChanged(); - } - - } -} diff --git a/mobile/src/main/java/com/example/android/apis/view/List8.kt b/mobile/src/main/java/com/example/android/apis/view/List8.kt new file mode 100644 index 000000000..74ee19eb1 --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/List8.kt @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2007 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.apis.view + +import com.example.android.apis.R + +import android.app.ListActivity +import android.content.Context +import android.os.Bundle +import android.view.View +import android.view.ViewGroup +import android.view.ViewGroup.LayoutParams +import android.widget.BaseAdapter +import android.widget.Button +import android.widget.ImageView +import android.widget.AbsListView +import kotlinx.android.synthetic.main.list_8.* + +import java.util.ArrayList + + +/** + * A list view that demonstrates the use of setEmptyView. This example alos uses + * a custom layout file that adds some extra buttons to the screen. + */ +class List8 : ListActivity() { + + internal val mAdapter: PhotoAdapter by lazy { + PhotoAdapter(this) + } + + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + // Use a custom layout file + setContentView(R.layout.list_8) + + // Tell the list view which view to display when the list is empty + listView.emptyView = empty + + // Set up our adapter + listAdapter = mAdapter + + // Wire up the clear button to remove all photos + clear.setOnClickListener { mAdapter.clearPhotos() } + + // Wire up the add button to add a new photo + add.setOnClickListener { mAdapter.addPhotos() } + } + + /** + * A simple adapter which maintains an ArrayList of photo resource Ids. + * Each photo is displayed as an image. This adapter supports clearing the + * list of photos and adding a new photo. + * + */ + inner class PhotoAdapter(private val mContext: Context) : BaseAdapter() { + + private val mPhotoPool = arrayOf(R.drawable.sample_thumb_0, R.drawable.sample_thumb_1, R.drawable.sample_thumb_2, R.drawable.sample_thumb_3, R.drawable.sample_thumb_4, R.drawable.sample_thumb_5, R.drawable.sample_thumb_6, R.drawable.sample_thumb_7) + + private val mPhotos = ArrayList() + + override fun getCount(): Int { + return mPhotos.size + } + + override fun getItem(position: Int): Any { + return position + } + + override fun getItemId(position: Int): Long { + return position.toLong() + } + + override fun getView(position: Int, convertView: View?, parent: ViewGroup): View = + // Make an ImageView to show a photo + ImageView(mContext).apply { + setImageResource(mPhotos[position]) + adjustViewBounds = true + layoutParams = AbsListView.LayoutParams(LayoutParams.WRAP_CONTENT, + LayoutParams.WRAP_CONTENT) + // Give it a nice background + setBackgroundResource(R.drawable.picture_frame) + } + + fun clearPhotos() { + mPhotos.clear() + notifyDataSetChanged() + } + + fun addPhotos() { + val whichPhoto = Math.round(Math.random() * (mPhotoPool.size - 1)).toInt() + val newPhoto = mPhotoPool[whichPhoto] + mPhotos.add(newPhoto) + notifyDataSetChanged() + } + + } +} diff --git a/mobile/src/main/java/com/example/android/apis/view/List9.java b/mobile/src/main/java/com/example/android/apis/view/List9.java deleted file mode 100644 index b50bd5264..000000000 --- a/mobile/src/main/java/com/example/android/apis/view/List9.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2007 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.apis.view; - -import com.example.android.apis.R; - -import android.app.ListActivity; -import android.content.Context; -import android.graphics.PixelFormat; -import android.os.Bundle; -import android.os.Handler; -import android.view.View; -import android.view.LayoutInflater; -import android.view.WindowManager; -import android.view.WindowManager.LayoutParams; -import android.widget.AbsListView; -import android.widget.ArrayAdapter; -import android.widget.ListView; -import android.widget.TextView; - - -/** - * Another variation of the list of cheeses. In this case, we use - * {@link AbsListView#setOnScrollListener(AbsListView.OnScrollListener) - * AbsListView#setOnItemScrollListener(AbsListView.OnItemScrollListener)} to display the - * first letter of the visible range of cheeses. - */ -public class List9 extends ListActivity implements ListView.OnScrollListener { - - private final class RemoveWindow implements Runnable { - public void run() { - removeWindow(); - } - } - - private RemoveWindow mRemoveWindow = new RemoveWindow(); - Handler mHandler = new Handler(); - private WindowManager mWindowManager; - private TextView mDialogText; - private boolean mShowing; - private boolean mReady; - private char mPrevLetter = Character.MIN_VALUE; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - mWindowManager = (WindowManager)getSystemService(Context.WINDOW_SERVICE); - - // Use an existing ListAdapter that will map an array - // of strings to TextViews - setListAdapter(new ArrayAdapter(this, - android.R.layout.simple_list_item_1, mStrings)); - - getListView().setOnScrollListener(this); - - LayoutInflater inflate = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); - - mDialogText = (TextView) inflate.inflate(R.layout.list_position, null); - mDialogText.setVisibility(View.INVISIBLE); - - mHandler.post(new Runnable() { - - public void run() { - mReady = true; - WindowManager.LayoutParams lp = new WindowManager.LayoutParams( - LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, - WindowManager.LayoutParams.TYPE_APPLICATION, - WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE - | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, - PixelFormat.TRANSLUCENT); - mWindowManager.addView(mDialogText, lp); - }}); - } - - @Override - protected void onResume() { - super.onResume(); - mReady = true; - } - - - @Override - protected void onPause() { - super.onPause(); - removeWindow(); - mReady = false; - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mWindowManager.removeView(mDialogText); - mReady = false; - } - - - - - public void onScroll(AbsListView view, int firstVisibleItem, - int visibleItemCount, int totalItemCount) { - if (mReady) { - char firstLetter = mStrings[firstVisibleItem].charAt(0); - - if (!mShowing && firstLetter != mPrevLetter) { - - mShowing = true; - mDialogText.setVisibility(View.VISIBLE); - } - mDialogText.setText(((Character)firstLetter).toString()); - mHandler.removeCallbacks(mRemoveWindow); - mHandler.postDelayed(mRemoveWindow, 3000); - mPrevLetter = firstLetter; - } - } - - - public void onScrollStateChanged(AbsListView view, int scrollState) { - } - - - private void removeWindow() { - if (mShowing) { - mShowing = false; - mDialogText.setVisibility(View.INVISIBLE); - } - } - - private String[] mStrings = Cheeses.sCheeseStrings; -} diff --git a/mobile/src/main/java/com/example/android/apis/view/List9.kt b/mobile/src/main/java/com/example/android/apis/view/List9.kt new file mode 100644 index 000000000..8d3aa70c3 --- /dev/null +++ b/mobile/src/main/java/com/example/android/apis/view/List9.kt @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2007 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.apis.view + +import com.example.android.apis.R + +import android.app.ListActivity +import android.content.Context +import android.graphics.PixelFormat +import android.os.Bundle +import android.os.Handler +import android.view.View +import android.view.LayoutInflater +import android.view.WindowManager +import android.view.WindowManager.LayoutParams +import android.widget.AbsListView +import android.widget.ArrayAdapter +import android.widget.TextView + + +/** + * Another variation of the list of cheeses. In this case, we use + * [ AbsListView#setOnItemScrollListener(AbsListView.OnItemScrollListener)][AbsListView.setOnScrollListener] to display the + * first letter of the visible range of cheeses. + */ +class List9 : ListActivity(), AbsListView.OnScrollListener { + + private inner class RemoveWindow : Runnable { + override fun run() { + removeWindow() + } + } + + private val mRemoveWindow = RemoveWindow() + private val mWindowManager: WindowManager + by lazy { getSystemService(Context.WINDOW_SERVICE) as WindowManager } + private val inflate: LayoutInflater + by lazy { getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater } + private val mDialogText: TextView + by lazy { inflate.inflate(R.layout.list_position, null) as TextView } + private var mHandler = Handler() + private var mShowing: Boolean = false + private var mReady: Boolean = false + private var mPrevLetter = Character.MIN_VALUE + + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + // Use an existing ListAdapter that will map an array + // of strings to TextViews + listAdapter = ArrayAdapter(this, + android.R.layout.simple_list_item_1, mStrings) + + listView.setOnScrollListener(this) + + mDialogText.visibility = View.INVISIBLE + + mHandler.post { + mReady = true + val lp = WindowManager.LayoutParams( + LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, + WindowManager.LayoutParams.TYPE_APPLICATION, + WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, + PixelFormat.TRANSLUCENT) + mWindowManager.addView(mDialogText, lp) + } + } + + override fun onResume() { + super.onResume() + mReady = true + } + + + override fun onPause() { + super.onPause() + removeWindow() + mReady = false + } + + override fun onDestroy() { + super.onDestroy() + mWindowManager.removeView(mDialogText) + mReady = false + } + + + override fun onScroll(view: AbsListView, firstVisibleItem: Int, + visibleItemCount: Int, totalItemCount: Int) { + if (mReady) { + val firstLetter = mStrings[firstVisibleItem][0] + + if (!mShowing && firstLetter != mPrevLetter) { + + mShowing = true + mDialogText.visibility = View.VISIBLE + } + mDialogText.text = firstLetter.toString() + mHandler.removeCallbacks(mRemoveWindow) + mHandler.postDelayed(mRemoveWindow, 3000) + mPrevLetter = firstLetter + } + } + + + override fun onScrollStateChanged(view: AbsListView, scrollState: Int) {} + + + private fun removeWindow() { + if (mShowing) { + mShowing = false + mDialogText.visibility = View.INVISIBLE + } + } + + private val mStrings = Cheeses.sCheeseStrings +} diff --git a/mobile/src/main/res/layout/animation_1.xml b/mobile/src/main/res/layout/animation_1.xml index 8380fc485..791665111 100644 --- a/mobile/src/main/res/layout/animation_1.xml +++ b/mobile/src/main/res/layout/animation_1.xml @@ -32,7 +32,7 @@ android:layout_height="wrap_content" android:clickable="true" android:singleLine="true" - android:password="true" + android:inputType="numberPassword" />