I am trying to fix up my app code and transition from Activities to Fragments, in order to transition to the navigation draw and eventually have some sliding tabs too.
Currently for navigation I am using the 3 dots drop down menu from the action bar which I know is not really right. Which is why I am trying to transition to fragments.
I want to keep my action bar menu so I can keep my search icon in the action bar but I want to add a navigation draw to it.
I currentley have a class called ActionBarMenu which extends activity. All my activities come form this because this class holds all the functions which open new activities for the action bar menu I have set up right now.
public class ActionbarMenu extends Activity {
public void goToSearch (MenuItem item) {
// go to search page
Intent i = new Intent(this,Search.class);
startActivity(i);
}
public void goToStatistics (MenuItem item) {
// go to search page
Intent i = new Intent(this,StatisticsPage.class);
startActivity(i);
}
public void goToFindBrewery (MenuItem item) {
// go to search page
Intent i = new Intent(this,FindBrewery.class);
startActivity(i);
}
public void goToContact (MenuItem item) {
// go to search page
Intent i = new Intent(this,ContactPage.class);
startActivity(i);
}
public void goToPortfolio (MenuItem item) {
// go to search page
Intent i = new Intent(this,Portfolio.class);
startActivity(i);
}
public void goToDiscover (MenuItem item) {
// go to search page
Intent i = new Intent(this,Discover.class);
startActivity(i);
}
public void scanBarcode (MenuItem item) {
//open scanner
IntentIntegrator scanIntegrator = new IntentIntegrator(this);
scanIntegrator.initiateScan();
}
//get result value
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
// retrieve scan result
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanningResult != null) {
// we have a result
String scanContent = scanningResult.getContents();
// launch async task for results
String url = "http://api.brewerydb.com/v2/search/upc?code=" + scanContent + "&key=0cdb22f84315834cc807c0176a927060&format=json&withBreweries=y";
new GetBeerDataFromUPCJSON(this).execute(url);
} else {
Toast toast = Toast.makeText(getApplicationContext(), "No scan data received!", Toast.LENGTH_SHORT);
toast.show();
}
}
}
I tried to change it to a fragment by changing extends activity to extends Fragment and all intents I build to launch new activities all get the red squiggly underline. I am just experimenting and trying to learn what's going on and whats the best way to transition my app from activities to Fragments, without having to recode everything.