-
Notifications
You must be signed in to change notification settings - Fork 1
/
BaseActionBarActivity.java
133 lines (126 loc) · 3.32 KB
/
BaseActionBarActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.androidbook.actionbar;
import android.app.ActionBar;
import android.app.SearchManager;
import android.app.SearchableInfo;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.SearchView;
import android.widget.TextView;
public abstract class BaseActionBarActivity
extends DebugActivity
{
private String tag=null;
public BaseActionBarActivity(String inTag)
{
super(R.menu.menu,
R.layout.main,
R.id.textViewId,
inTag);
tag = inTag;
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView tv = this.getTextView();
tv.setText(tag);
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
this.setupSearchView(menu);
return true;
}
protected boolean onMenuItemSelected(MenuItem item)
{
if (item.getItemId() == android.R.id.home) {
this.reportBack(tag,"Home Pressed");
return true;
}
if (item.getItemId() == R.id.menu_invoke_tabnav){
if (getNavMode() ==
ActionBar.NAVIGATION_MODE_TABS)
{
this.reportBack(tag,
"You are already in tab nav");
}
else {
this.invokeTabNav();
}
return true;
}
if (item.getItemId() == R.id.menu_invoke_listnav){
if (getNavMode() ==
ActionBar.NAVIGATION_MODE_LIST)
{
this.reportBack(tag,
"You are already in list nav");
}
else{
this.invokeListNav();
}
return true;
}
if (item.getItemId() == R.id.menu_invoke_standardnav){
if (getNavMode() ==
ActionBar.NAVIGATION_MODE_STANDARD)
{
this.reportBack(tag,
"You are already in standard nav");
}
else{
this.invokeStandardNav();
}
return true;
}
return false;
}
private int getNavMode(){
ActionBar bar = this.getActionBar();
return bar.getNavigationMode();
}
private void invokeTabNav(){
Intent i = new Intent(this,
TabNavigationActionBarActivity.class);
startActivity(i);
}
private void invokeListNav(){
Intent i = new Intent(this,
ListNavigationActionBarActivity.class);
startActivity(i);
}
private void invokeStandardNav(){
Intent i = new Intent(this,
StandardNavigationActionBarActivity.class);
startActivity(i);
}
private void setupSearchView(Menu menu)
{
SearchView searchView =
(SearchView) menu.findItem(R.id.menu_search).getActionView();
if (searchView == null)
{
this.reportBack(tag, "Failed to get search view");
return;
}
//setup searchview
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
ComponentName cn =
new ComponentName(this,SearchResultsActivity.class);
SearchableInfo info =
searchManager.getSearchableInfo(cn);
if (info == null)
{
this.reportBack(tag, "Failed to get search info");
return;
}
searchView.setSearchableInfo(info);
// Do not iconify the widget; expand it by default
searchView.setIconifiedByDefault(false);
}
}//eof-class