How can I call getSupportActionBar() from simple java class - android

I have to add more code in following class, but I need to separate handleMenuSearch() in another class to organize my code. I can't call getSupportActionBar() in the separated class. How do I get support ActionBar in another class?
NewsakHome.java
package com.newsak;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
/**
* Created by Bassem on 8/26/2015.
*/
public class NewsakHome extends AppCompatActivity {
private Toolbar toolBar;
private MenuItem searchItem;
private EditText searchText;
private boolean isSearchOpened = false;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newsak_welcome);
toolBar = (Toolbar) findViewById(R.id.tool_bar_newsak);
// toolBar.setLogo(R.drawable.ic_launcher);
setSupportActionBar(toolBar);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId())
{
case R.id.search_bar_id:
handleMenuSearch();
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
searchItem = menu.findItem(R.id.search_bar_id);
return super.onPrepareOptionsMenu(menu);
}
protected void handleMenuSearch(){
ActionBar actionBar = getSupportActionBar();
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if(isSearchOpened) // is cloases
{
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayShowCustomEnabled(false);
// hide the Keyboard
inputManager.hideSoftInputFromWindow(searchText.getWindowToken() ,0);
//set the closed Icon
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
searchItem.setIcon(ContextCompat.getDrawable(this, R.drawable.search_icon_open));
} else
{
searchItem.setIcon(getResources().getDrawable(R.drawable.search_icon_open));
}
isSearchOpened = false;
}
else
{
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setCustomView(R.layout.search_bar);
actionBar.setDisplayShowCustomEnabled(true); // set our search layout
searchText = (EditText) actionBar.getCustomView().findViewById(R.id.search_text_id);
searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
doSearch(view.getText().toString());
return true;
}
return false;
}
});
searchText.requestFocus();
//open Keyboard
inputManager.showSoftInput(searchText, InputMethodManager.SHOW_IMPLICIT);
//set close icon
//set the closed Icon
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
searchItem.setIcon(ContextCompat.getDrawable(this, R.drawable.search_icon_closed));
} else
{
searchItem.setIcon(getResources().getDrawable(R.drawable.search_icon_closed));
}
isSearchOpened = true;
}
}
//You’d add this method too, to close the search entry with the backbutton:
public void onBackPressed() {
if(isSearchOpened)
{
handleMenuSearch();
return;
}
super.onBackPressed();
}
private void doSearch(String value) {
Toast.makeText(this, "your value is :"+value, Toast.LENGTH_LONG).show();
}
}

You could pass a reference of NewsakHome into your menu function, something like this:
// MenuSearchClass.java
public class MenuSearchClass() {
public static void handleMenuSearch(NewsakHome context) {
// use 'context' whenever you want to access one of NewsakHome's methods/members
ActionBar actionBar = context.getSupportActionBar();
InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
...
}
}
Then, pass this into handleMenuSearch() whenever you call it:
// NewsakHome.java
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId())
{
case R.id.search_bar_id:
// 'this' will become 'context' in handleMenuSearch()
// handleMenuSearch() is static to make the example easier to read
MenuSearchClass.handleMenuSearch(this);
return true;
}
return super.onOptionsItemSelected(item);
}
I do agree with #Peter Brittain though. You shouldn't be splitting a class just to make it smaller or more readable. Activity classes usually handle a lot of functionality, so it makes sense that they'd be some of the larger, more complex classes in your project.

Related

AsyncTask in RecyclerView

I use RecycleView in my application and I want to implement AsyncTask so it will work faster, because it takes a few seconds until fragment is loaded.
To be more specific, when clicking to enter the fragment which contains the RecyclerView, it hangs a few seconds and I understood that by using AsyncTask it will load only the items that shown on screen and only if I scroll down it will load the the next items. So it will fix the delaying...
How to do it please?
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.Toast;
import entities.Order;
import entities.User;
public class HomeFragment extends Fragment implements TransAdapter.ClickListener {
private RecyclerView rvTrans;
private TransAdapter adapter;
private MenuItem mSearchAction;
private SearchView searchView;
private ActionBar actionBar;
private boolean isSearchOpened = false;
private EditText etSearch;
public HomeFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_home, container, false);
rvTrans = (RecyclerView) view.findViewById(R.id.rv_transactions);
rvTrans.setLayoutManager(new LinearLayoutManager(getActivity()));
adapter = new TransAdapter(getActivity());
adapter.setClickListener(this);
rvTrans.setAdapter(adapter);
try {
adapter.setOrderList(HomeActivity.backEnd.booksForSale());
} catch (Exception e) {
Toast.makeText(getActivity().getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
return view;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId())
{
case R.id.action_search:
handleMenuSearch();
break;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
mSearchAction = menu.findItem(R.id.action_search);
searchView = (SearchView) MenuItemCompat.getActionView(mSearchAction);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String query) {
adapter.clearData();
try {
adapter.setOrderList(HomeActivity.backEnd.bookGlobalSearch(query));
} catch (Exception e) {
Toast.makeText(getActivity().getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
return true;
}
#Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
}
#Override
public void itemClicked(Order order) {
Intent intent = new Intent(getActivity(), DetailsActivity.class);
intent.putExtra("BOOK_PICTURE", order.getBookPicture());
intent.putExtra("BOOK_NAME", order.getBookName());
intent.putExtra("BOOK_AUTHOR", order.getAuthorName());
intent.putExtra("BOOK_GENRE", order.getGenre());
intent.putExtra("BOOK_PUBLISHING", order.getPublishingYear());
startActivity(intent);
}
private void handleMenuSearch() {
actionBar = ((AppCompatActivity)getActivity()).getSupportActionBar(); //get the actionbar
if(isSearchOpened){ //test if the search is open
if(actionBar != null)
{
actionBar.setDisplayShowCustomEnabled(false); //disable a custom view inside the actionbar
actionBar.setDisplayShowTitleEnabled(true); //show the title in the action bar
}
// hides the keyboard
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(etSearch.getWindowToken(), 0);
isSearchOpened = false;
} else { // open the search entry
if(actionBar != null)
{
actionBar.setDisplayShowCustomEnabled(true); //enable it to display a
// custom view in the action bar.
// action.setCustomView(R.layout.search_bar);//add the custom view
actionBar.setDisplayShowTitleEnabled(false); //hide the title
}
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(etSearch, InputMethodManager.SHOW_IMPLICIT);
isSearchOpened = true;
}
}
}
Thanks!
May be you confuse using of async task.
Async task should be using in long operation to avoiding block UI thread (Ex. http request, pagination, etc.)
But this no mean your businness logic will be run too fast (this will run in parallel).
If in your recyclerView you load big image or image from url you need to manage directly your logic with cache pattern
you can start take a look how this logic work in project like picasso or Processing Bitmaps Off the UI Thread directly from google developers http://developer.android.com/training/displaying-bitmaps/process-bitmap.html#async-task
Hope this may help!!!

How to return list item selected to parent activity - android

I'm learning android development. And I trying to do the following:
An wellcome activity, with a TextView with the following text: "Please Select"
This Textview, has an OnClick Listener setted.
My intent is, when the user click on this textview, one new activity with a listview must be opened.
This listview cointains some values like: Country 1, Country 2, Country 3 and so on;
So, when the user select one value, this value must be returned to the parent activity.
In my parent activity I have the following:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
countrySamples = (TextView)findViewById(R.id.countrySamples);
countrySamples.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ListCountrySelectedFragment whatKindOjectIsThis = new ListCountrySelectedFragment();
whatKindOjectIsThis.setListCountrySelectedActivityDelegate(new ListCountrySelectedFragment.ListCountrySelectedActivityDelegate() {
#Override
public void selectCountry(String name) {
selectItem(name);
}
});
}
});
}
[...]
public void selectItem(String name) {
int index = valuesArray.indexOf(name);
if (index != -1) {
countryButton.setText(name);
}
}
And I've created an blank fragment with a list.
And added the following code:
public static interface ListCountrySelectedActivityDelegate {
public abstract void selectCountry(String name);
}
private ListCountrySelectedActivityDelegate delegate;
[...]
But, my fragment is never started.. The true is.. I have to create a Fragment to this? Or, must by an activity? Or I'm totally wrong?
Thanks
Edited (complete code):
Login Activity:
package com.testenum_13;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.testenum_13.R;
import com.testenum_13.adapters.CountryAdapter;
import org.w3c.dom.Text;
import java.util.ArrayList;
import java.util.HashMap;
public class Login extends ActionBarActivity {
TextView countryButton;
private EditText codeField;
private int countryState = 0;
private ArrayList<String> countriesArray = new ArrayList<String>();
private HashMap<String, String> countriesMap = new HashMap<String, String>();
private boolean ignoreOnTextChange = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
countryButton = (TextView)findViewById(R.id.countryButton);
countryButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Intent intent = new Intent(Login.this, CountrySelected.class);
CountrySelected fragment = new CountrySelected();
fragment.setCountrySelectActivityDelegate (new CountrySelected.CountrySelectActivityDelegate() {
#Override
public void countryWSelected(String name) {
selectCountry(name);
}
});
//startActivity(intent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_login, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void selectCountry(String name) {
int index = countriesArray.indexOf(name);
if (index != -1) {
ignoreOnTextChange = true;
codeField.setText(countriesMap.get(name));
countryButton.setText(name);
countryState = 0;
}
}
}
Country Activity:
package com.testenum_13;
import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.internal.widget.ActionBarOverlayLayout;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import com.testenum_13.adapters.CountryAdapter;
import com.testenum_13.adapters.CountryAdapter.Country;
import java.util.List;
public class CountrySelected extends FragmentActivity {
public static interface CountrySelectActivityDelegate {
public abstract void countryWSelected(String name);
}
private CountryAdapter listViewAdapter;
private CountrySelectActivityDelegate delegate;
ListView countryList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_country_selected);
countryList = (ListView)findViewById(R.id.countryList);
listViewAdapter = new CountryAdapter(getBaseContext());
countryList.setAdapter(listViewAdapter);
countryList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Country country = null;
int section = listViewAdapter.getSectionForPosition(position);
int row = listViewAdapter.getPositionInSectionForPosition(position);
if (row < 0 || section < 0) {
return;
}
country = listViewAdapter.getItem(section, row);
if (position < 0) {
return;
}
if (country != null && delegate != null)
{
delegate.countryWSelected(country.name);
}
finish();
}
});
}
public void setCountrySelectActivityDelegate(CountrySelectActivityDelegate delegate) {
this.delegate = delegate;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_country_selected, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Thanks
You could use startActivityForResult(Intent, int) in the parent Activity and override onActivityResult() in the child activity. See this tutorial for more details on how to implent this pattern.

Google Glass - Creating an options menu, nothing happens when item is clicked

I am creating an app for Glass that displays a list of saved items (RememberItem). Each item has its card, and when you tap it, a menu appears with the following options: Get directions (launch google nav to the location of saved item), delete (remove the item from the list).
However, nothing happens when we tap on the menu options.
Here's the code:
package com.adrianavecc.findit;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Message;
import android.speech.RecognizerIntent;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import com.adrianavecc.findit.adapter.ScrollAdapter;
import com.adrianavecc.findit.db.SqlHelper;
import com.adrianavecc.findit.domain.RememberItem;
import com.adrianavecc.findit.util.RememberUtils;
import com.google.android.glass.app.Card;
import com.google.android.glass.app.Card.ImageLayout;
import com.google.android.glass.widget.CardScrollView;
public class Find extends Activity implements Callback {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayList<String> voiceResults = getIntent().getExtras().getStringArrayList(RecognizerIntent.EXTRA_RESULTS);
String tag= voiceResults.get(0);
RememberItem item=SqlHelper.getInstance(this).findRememberItem(tag);
if(item!=null){
List<RememberItem> items=new ArrayList<RememberItem>();
items.add(item);
displayRememberItems(items);
} else{
if(RememberUtils.EVERY_THING.equalsIgnoreCase(tag)){
List<RememberItem> items=SqlHelper.getInstance(this).findAllRememberItem();
displayRememberItems(items);
}
else{
displayFailureView();
}
}
}
private void displayFailureView() {
Card fail = new Card(this);
fail.setText(R.string.storefailhead);
fail.setFootnote(R.string.storefailfoot);
fail.setImageLayout(Card.ImageLayout.FULL);
fail.addImage(R.drawable.storefailbackground);
View failView = fail.getView();
setContentView(failView);
}
private Card createCardOfRememberItem(RememberItem item) {
Card card = new Card(this);
card.setText(item.getTag());
card.setFootnote(String.format("%tc", item.getAddedDate()));
card.setImageLayout(ImageLayout.FULL);
card.addImage(BitmapFactory.decodeFile(item.getImagePath()));
return card;
}
private void launchGoogleMap(RememberItem item) {
Location location=item.getLocation();
Intent intent=RememberUtils.getGeoIntentFromLocation(location);
Find.this.startActivity(intent);
}
private void displayRememberItems(final List<RememberItem> items) {
List<Card> mCards = new ArrayList<Card>();
for(RememberItem item: items){
Card card=createCardOfRememberItem(item);
mCards.add(card);
}
CardScrollView mCardScrollView = new CardScrollView(this);
final ScrollAdapter adapter = new ScrollAdapter(mCards);
mCardScrollView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Card card=(Card)adapter.getItem(arg2);
RememberItem item=SqlHelper.getInstance(getApplicationContext()).findRememberItem(card.getText().toString());
openOptionsMenu();
}
});
mCardScrollView.setAdapter(adapter);
mCardScrollView.activate();
setContentView(mCardScrollView);
}
private void showSucessDeleteCard(RememberItem item){
Card card = new Card(this);
card.setText(R.string.object_delete);
card.setImageLayout(ImageLayout.FULL);
card.addImage(R.drawable.finditlogobg);
setContentView(card.getView());
Handler handler=new Handler(this);
handler.sendEmptyMessageDelayed(0, 3000);
}
#Override
public boolean handleMessage(Message msg) {
finish();
return false;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.saveditemmenu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem menuitem, RememberItem item) {
switch (menuitem.getItemId()) {
case R.id.menu_getdirections:
launchGoogleMap(item);
return true;
case R.id.menu_delete:
SqlHelper.getInstance(getApplication()).deleteRememberItem(item);
showSucessDeleteCard(item);
return true;
default:
return super.onOptionsItemSelected(menuitem);
}
}
}
You must override public boolean onOptionsItemSelected(MenuItem item) which is the event and then call onOptionsItemSelected(MenuItem menuitem, RememberItem item) from that method.
Maybe it is too late. Can you try this please
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER){
Log.d("TOUCH","DPAD_CENTER");
this.openOptionsMenu();
return true;
}
return super.onKeyDown(keyCode, event);
}

onPrepareSubMenu is never called even when hasSubMenu returns true

Below is my ActionProvider class
import java.util.Locale;
import android.content.Context;
import android.util.Log;
import android.view.ActionProvider;
import android.view.LayoutInflater;
import android.view.SubMenu;
import android.view.View;
import android.widget.ImageButton;
public class LocaleActionProvider extends ActionProvider {
private static final String TAG = "LocaleActionProvider";
Context mCtx;
public LocaleActionProvider(Context context) {
super(context);
mCtx = context;
}
#Override
#Deprecated
public View onCreateActionView() {
// Inflate the action view to be shown on the action bar.
LayoutInflater layoutInflater = LayoutInflater.from(mCtx);
View view = layoutInflater.inflate(R.layout.action_provider_locale,
null);
ImageButton button = (ImageButton) view.findViewById(R.id.localeButton);
// Set up flag icon for specific locale
Locale locale = Locale.getDefault();
String locLan = locale.getLanguage();
if (locLan.equals(Locale.CHINESE.getLanguage())) {
button.setImageResource(R.drawable.insready);
} else if (locLan.equals(Locale.ENGLISH.getLanguage())) {
button.setImageResource(R.drawable.ic_action_locale_en);
} else if (locLan.equals(Locale.FRENCH.getLanguage())) {
button.setImageResource(R.drawable.ic_action_search);
}
/*
* button.setOnClickListener(new View.OnClickListener() {
*
* #Override public void onClick(View v) { // Do something... } });
*/
return view;
}
#Override
public boolean hasSubMenu() {
return true;
}
#Override
public void onPrepareSubMenu(SubMenu subMenu) {
Log.i(TAG, "onPrepareSubMenu()");
// Clear since the order of items may change.
subMenu.clear();
subMenu.add(0, 0, 0, "简体中文");
subMenu.add(0, 1, 1, "English");
subMenu.add(0, 2, 2, "French");
}
#Override
public boolean onPerformDefaultAction() {
Log.i(this.getClass().getSimpleName(), "onPerformDefaultAction");
return super.onPerformDefaultAction();
}
}
I have tried to use debugger or Log.i() to monitor onPrepareSubMenu() function. But onPrepareSubMenu() is never called, in other words the debugger never stops at the breakpoint and there is no log entry.
I found out that in onCreateActionView() , you have to return null in order for the onPrepareSubMenu() being called. Then, all these setups in onCreateActionView() need to go in to onCreateOptionsMenu() in probably MainActivity

How extend main class to use Sherlock Action Bar and PhoneGap together on Android

i have a problem, i want to use Sherlock Action Bar and PhoneGap together on a Android Project.
I read i another stack overflow post that Android not support more than one extension.
This is my working code.
package com.inmo.mobile;
// import org.apache.cordova.DroidGap;
import android.os.Bundle;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import android.app.Activity;
import org.apache.cordova.*;
//public class Inmo extends DroidGap {
//
// #Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// super.setIntegerProperty("splashscreen", R.drawable.splash);
// super.loadUrl("file:///android_asset/www/index.html", 5000);
// }
//
//}
public class Inmo extends SherlockActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.favorites) {
//startActivity(new Intent(this, FavoritesActivity.class));
Toast.makeText(this, "favoritos pulsado", Toast.LENGTH_SHORT).show();
} else if (item.getItemId() == R.id.preferences) {
Toast.makeText(this, "configuración pulsado", Toast.LENGTH_SHORT).show();
}
return true;
}
}
The PhoneGap code it's commented, boths codes works when one it's commented and the other not, so i need two combine boths and extend the main class to sherlock and phonegap (to included to cordova webview).
This it's possible ?
Thanks in advance
Did you try using the static attachment method? Eg:
public class Inmo extends DroidGap implements ActionBar.TabListener,
OnCreateOptionsMenuListener, OnMenuItemSelectedListener {
private ActionBarSherlock mSherlock;
protected final ActionBarSherlock getSherlock() {
if (mSherlock == null) {
mSherlock = ActionBarSherlock.wrap(this);
}
return mSherlock;
}
//...
}

Categories

Resources