Skip to content

Commit

Permalink
chore: update APIDemos folder comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wangela committed Aug 16, 2024
1 parent 1ace0a6 commit ac0a18f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 56 deletions.
2 changes: 1 addition & 1 deletion ApiDemos/java/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<!--
To add your Maps API key to this project:
1. Open the root project's local.properties file
1. Open the root project's secrets.properties file
2. Add this line, where YOUR_API_KEY is your API key:
MAPS_API_KEY=YOUR_API_KEY
-->
Expand Down
103 changes: 51 additions & 52 deletions ApiDemos/java/app/src/v3/java/com/example/mapdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.


package com.example.mapdemo;

import android.content.Context;
Expand All @@ -26,73 +25,73 @@
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

/**
* The main activity of the API library demo gallery.
* <p>
* The main layout lists the demonstrated features, with buttons to launch them.
*
* <p>The main layout lists the demonstrated features, with buttons to launch them.
*/
public final class MainActivity extends AppCompatActivity
implements AdapterView.OnItemClickListener {
implements AdapterView.OnItemClickListener {

/** A custom array adapter that shows a {@link FeatureView} containing details about the demo. */
private static class CustomArrayAdapter extends ArrayAdapter<DemoDetails> {

/**
* A custom array adapter that shows a {@link FeatureView} containing details about the demo.
* @param demos An array containing the details of the demos to be displayed.
*/
private static class CustomArrayAdapter extends ArrayAdapter<DemoDetails> {

/**
* @param demos An array containing the details of the demos to be displayed.
*/
public CustomArrayAdapter(Context context, DemoDetails[] demos) {
super(context, R.layout.feature, R.id.title, demos);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
FeatureView featureView;
if (convertView instanceof FeatureView) {
featureView = (FeatureView) convertView;
} else {
featureView = new FeatureView(getContext());
}

DemoDetails demo = getItem(position);

featureView.setTitleId(demo.titleId);
featureView.setDescriptionId(demo.descriptionId);

Resources resources = getContext().getResources();
String title = resources.getString(demo.titleId);
String description = resources.getString(demo.descriptionId);
featureView.setContentDescription(title + ". " + description);

return featureView;
}
public CustomArrayAdapter(Context context, DemoDetails[] demos) {
super(context, R.layout.feature, R.id.title, demos);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView list = findViewById(R.id.list);
public View getView(int position, View convertView, ViewGroup parent) {
FeatureView featureView;
if (convertView instanceof FeatureView) {
featureView = (FeatureView) convertView;
} else {
featureView = new FeatureView(getContext());
}

ListAdapter adapter = new CustomArrayAdapter(this, DemoDetailsList.DEMOS);
DemoDetails demo = getItem(position);

list.setAdapter(adapter);
list.setOnItemClickListener(this);
list.setEmptyView(findViewById(R.id.empty));
featureView.setTitleId(demo.titleId);
featureView.setDescriptionId(demo.descriptionId);

if (BuildConfig.MAPS_API_KEY.isEmpty()) {
Toast.makeText(this, "Add your own API key in local.properties as MAPS_API_KEY=YOUR_API_KEY", Toast.LENGTH_LONG).show();
}
}
Resources resources = getContext().getResources();
String title = resources.getString(demo.titleId);
String description = resources.getString(demo.descriptionId);
featureView.setContentDescription(title + ". " + description);

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
DemoDetails demo = (DemoDetails) parent.getAdapter().getItem(position);
startActivity(new Intent(this, demo.activityClass));
return featureView;
}
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView list = findViewById(R.id.list);

ListAdapter adapter = new CustomArrayAdapter(this, DemoDetailsList.DEMOS);

list.setAdapter(adapter);
list.setOnItemClickListener(this);
list.setEmptyView(findViewById(R.id.empty));

if (BuildConfig.MAPS_API_KEY.isEmpty()) {
Toast.makeText(
this,
"Add your own API key in secrets.properties as MAPS_API_KEY=YOUR_API_KEY",
Toast.LENGTH_LONG)
.show();
}
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
DemoDetails demo = (DemoDetails) parent.getAdapter().getItem(position);
startActivity(new Intent(this, demo.activityClass));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
}

if (BuildConfig.MAPS_API_KEY.isEmpty()) {
Toast.makeText(this, "Add your own API key in local.properties as MAPS_API_KEY=YOUR_API_KEY", Toast.LENGTH_LONG).show()
Toast.makeText(this, "Add your own API key in secrets.properties as MAPS_API_KEY=YOUR_API_KEY", Toast.LENGTH_LONG).show()
}
}

Expand Down
2 changes: 1 addition & 1 deletion ApiDemos/kotlin/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
android:theme="@style/AppTheme">
<!--
To add your Maps API key to this project:
1. Open the root project'sl local.properties file
1. Open the root project'sl secrets.properties file
2. Add this line, where YOUR_API_KEY is your API key:
MAPS_API_KEY=YOUR_API_KEY
-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
}

if (BuildConfig.MAPS_API_KEY.isEmpty()) {
Toast.makeText(this, "Add your own API key in local.properties as MAPS_API_KEY=YOUR_API_KEY", Toast.LENGTH_LONG).show()
Toast.makeText(this, "Add your own API key in secrets.properties as MAPS_API_KEY=YOUR_API_KEY", Toast.LENGTH_LONG).show()
}

}
Expand Down

0 comments on commit ac0a18f

Please sign in to comment.