Skip to content

Commit

Permalink
Move settings button to menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ViliusKraujutis committed Mar 29, 2014
1 parent 6c28fd6 commit 0f545f4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 37 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/lt/andro/maistobankas/BaseFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @since 2014-02-08 13:04
*/
public class BaseFragment extends Fragment {

@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
Expand All @@ -22,6 +23,7 @@ public void onAttach(Activity activity) {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
Log.d("MBBaseFragment", "onCreate");
}

Expand Down
21 changes: 0 additions & 21 deletions app/src/main/java/lt/andro/maistobankas/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,6 @@ protected void onCreate(Bundle savedInstanceState) {
}
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, 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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null && resultCode == RESULT_OK) {
Expand Down
33 changes: 24 additions & 9 deletions app/src/main/java/lt/andro/maistobankas/MainFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import android.support.v4.app.FragmentActivity;
import android.util.Log;
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.widget.ListView;
Expand All @@ -29,15 +32,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);

rootView.findViewById(R.id.buttonSettings).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new ShopInformationFragment())
.commit();
}
});

rootView.findViewById(R.id.buttonScan).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down Expand Up @@ -73,4 +67,25 @@ private void showScannedItems(List<ScannedItem> scannedItems) {
final DatabaseHelper helper = ((MainActivity) activity).getHelper();
itemsList.setAdapter(new ScannedItemsAdapter(activity, scannedItems, helper));
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.main, menu);
}

@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();
if (id == R.id.action_settings) {
getActivity().getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new ShopInformationFragment())
.commit();
return true;
}
return super.onOptionsItemSelected(item);
}
}
7 changes: 0 additions & 7 deletions app/src/main/res/layout/fragment_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
android:text="@string/button_send"
android:id="@+id/buttonScan" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_settings"
android:id="@+id/buttonSettings" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down

0 comments on commit 0f545f4

Please sign in to comment.