Add prebuilt browseable samples as static files.
Change-Id: Ifb5382223343400882834d2dd9c182c3df602e34
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2013 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.donebar;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
/**
|
||||
* A sample activity demonstrating the "done bar" alternative action bar presentation. For a more
|
||||
* detailed description see {@link R.string.done_bar_description}.
|
||||
*/
|
||||
public class DoneBarActivity extends Activity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// BEGIN_INCLUDE (inflate_set_custom_view)
|
||||
// Inflate a "Done/Cancel" custom action bar view.
|
||||
final LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext()
|
||||
.getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||
final View customActionBarView = inflater.inflate(
|
||||
R.layout.actionbar_custom_view_done_cancel, null);
|
||||
customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// "Done"
|
||||
finish();
|
||||
}
|
||||
});
|
||||
customActionBarView.findViewById(R.id.actionbar_cancel).setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// "Cancel"
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
// Show the custom action bar view and hide the normal Home icon and title.
|
||||
final ActionBar actionBar = getActionBar();
|
||||
actionBar.setDisplayOptions(
|
||||
ActionBar.DISPLAY_SHOW_CUSTOM,
|
||||
ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME
|
||||
| ActionBar.DISPLAY_SHOW_TITLE);
|
||||
actionBar.setCustomView(customActionBarView,
|
||||
new ActionBar.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
// END_INCLUDE (inflate_set_custom_view)
|
||||
|
||||
setContentView(R.layout.activity_done_bar);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2013 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.donebar;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* A sample activity demonstrating the "done button" alternative action bar presentation. For a more
|
||||
* detailed description see {@link R.string.done_button_description}.
|
||||
*/
|
||||
public class DoneButtonActivity extends Activity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// BEGIN_INCLUDE (inflate_set_custom_view)
|
||||
// Inflate a "Done" custom action bar view to serve as the "Up" affordance.
|
||||
final LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext()
|
||||
.getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||
final View customActionBarView = inflater.inflate(
|
||||
R.layout.actionbar_custom_view_done, null);
|
||||
customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// "Done"
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
// Show the custom action bar view and hide the normal Home icon and title.
|
||||
final ActionBar actionBar = getActionBar();
|
||||
actionBar.setDisplayOptions(
|
||||
ActionBar.DISPLAY_SHOW_CUSTOM,
|
||||
ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME
|
||||
| ActionBar.DISPLAY_SHOW_TITLE);
|
||||
actionBar.setCustomView(customActionBarView);
|
||||
// END_INCLUDE (inflate_set_custom_view)
|
||||
|
||||
setContentView(R.layout.activity_done_button);
|
||||
}
|
||||
|
||||
// BEGIN_INCLUDE (handle_cancel)
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
getMenuInflater().inflate(R.menu.cancel, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.cancel:
|
||||
// "Cancel"
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
// END_INCLUDE (handle_cancel)
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright 2013 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.donebar;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.GridView;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* A simple launcher activity offering access to the individual samples in this project.
|
||||
*/
|
||||
public class MainActivity extends Activity implements AdapterView.OnItemClickListener {
|
||||
private Sample[] mSamples;
|
||||
private GridView mGridView;
|
||||
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
// Prepare list of samples in this dashboard.
|
||||
mSamples = new Sample[]{
|
||||
new Sample(R.string.donebaractivity_title, R.string.donebaractivity_description,
|
||||
DoneBarActivity.class),
|
||||
new Sample(R.string.donebuttonactivity_title, R.string.donebuttonactivity_description,
|
||||
DoneButtonActivity.class),
|
||||
};
|
||||
|
||||
// Prepare the GridView
|
||||
mGridView = (GridView) findViewById(android.R.id.list);
|
||||
mGridView.setAdapter(new SampleAdapter());
|
||||
mGridView.setOnItemClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> container, View view, int position, long id) {
|
||||
startActivity(mSamples[position].intent);
|
||||
}
|
||||
|
||||
private class SampleAdapter extends BaseAdapter {
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mSamples.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return mSamples[position];
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return mSamples[position].hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup container) {
|
||||
if (convertView == null) {
|
||||
convertView = getLayoutInflater().inflate(R.layout.sample_dashboard_item,
|
||||
container, false);
|
||||
}
|
||||
|
||||
((TextView) convertView.findViewById(android.R.id.text1)).setText(
|
||||
mSamples[position].titleResId);
|
||||
((TextView) convertView.findViewById(android.R.id.text2)).setText(
|
||||
mSamples[position].descriptionResId);
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
|
||||
private class Sample {
|
||||
int titleResId;
|
||||
int descriptionResId;
|
||||
Intent intent;
|
||||
|
||||
private Sample(int titleResId, int descriptionResId, Intent intent) {
|
||||
this.intent = intent;
|
||||
this.titleResId = titleResId;
|
||||
this.descriptionResId = descriptionResId;
|
||||
}
|
||||
|
||||
private Sample(int titleResId, int descriptionResId,
|
||||
Class<? extends Activity> activityClass) {
|
||||
this(titleResId, descriptionResId,
|
||||
new Intent(MainActivity.this, activityClass));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user