Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. package se.molk.feedme;
  2.  
  3. import android.app.ActionBar;
  4. import android.app.Activity;
  5. import android.graphics.Color;
  6. import android.graphics.drawable.ColorDrawable;
  7. import android.os.Bundle;
  8. import android.view.Menu;
  9. import android.view.MenuItem;
  10. import android.view.View;
  11. import android.widget.AdapterView;
  12. import android.widget.ArrayAdapter;
  13. import android.widget.Button;
  14. import android.widget.ListView;
  15.  
  16. import com.cengalabs.flatui.FlatUI;
  17. import com.cengalabs.flatui.views.FlatButton;
  18.  
  19. import java.util.ArrayList;
  20.  
  21. public class MainActivity extends Activity {
  22. public ArrayList<Integer> backgrounds = new ArrayList<Integer>();
  23.  
  24. ListView listView; // Själva listan, den som visas i appen
  25. ArrayList<String> ingredients = new ArrayList<String>(); // Här inne hamnar alla ingredienser
  26. ArrayAdapter<String> ingredientsAdapter; // Den här saken länkar ovanstående två saker
  27.  
  28. @Override
  29. protected void onCreate(Bundle savedInstanceState) {
  30. super.onCreate(savedInstanceState);
  31.  
  32. setContentView(R.layout.activity_main);
  33.  
  34. ActionBar bar = getActionBar();
  35. bar.setBackgroundDrawable(new ColorDrawable(Color.rgb(192, 57, 43)));
  36. backgrounds.add(FlatUI.SAND);
  37. backgrounds.add(FlatUI.ORANGE);
  38. backgrounds.add(FlatUI.CANDY);
  39. backgrounds.add(FlatUI.BLOSSOM);
  40. backgrounds.add(FlatUI.GRAPE);
  41. // backgrounds.add(FlatUI.DEEP);
  42. backgrounds.add(FlatUI.SKY);
  43. backgrounds.add(FlatUI.GRASS);
  44. // backgrounds.add(FlatUI.DARK);
  45. // backgrounds.add(FlatUI.SNOW);
  46. backgrounds.add(FlatUI.SEA);
  47. // backgrounds.add(FlatUI.BLOOD);
  48.  
  49. Button butt = (Button) findViewById(R.id.goButton);
  50. butt.setOnClickListener(new View.OnClickListener() {
  51. @Override
  52. public void onClick(View v) {
  53. backgrounds.add(backgrounds.get(0));
  54. backgrounds.remove(0);
  55.  
  56. // Collections.shuffle(backgrounds);
  57.  
  58. FlatButton butt = (FlatButton) findViewById(R.id.goButton);
  59. butt.getAttributes().setTheme(backgrounds.get(0), getResources());
  60. }
  61. });
  62.  
  63. listView = (ListView) findViewById(R.id.listView);
  64. ingredientsAdapter = new ArrayAdapter<String>(
  65. this, // Kontexten, vetefan vad det är egentligen men det är samma som om man kör getApplicationContext()
  66. R.layout.list_item_ingredient, // Layouten för en rad/item
  67. R.id.label, // ID på elementet ingrediensen ska visas på
  68. ingredients // Arrayen vi samlar alla ingredienser i
  69. );
  70. listView.setAdapter(ingredientsAdapter);
  71. // Klicka på något i listan = ta bort den
  72. listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  73. @Override
  74. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  75. ingredients.remove(position);
  76. ingredientsAdapter.notifyDataSetChanged();
  77. }
  78. });
  79.  
  80. addIngredient("Bröd");
  81. addIngredient("Smör");
  82. addIngredient("Ost");
  83. addIngredient("Brödsmulor");
  84. addIngredient("Rakblad");
  85. addIngredient("Tårar");
  86. addIngredient("Tårar");
  87. addIngredient("Tårar");
  88. addIngredient("Tårar");
  89. addIngredient("Tårar");
  90.  
  91. // Nästa steg... fixa så man får ut vad man skrivit när man trycker på + (eller enter)
  92. }
  93.  
  94.  
  95.  
  96.  
  97. @Override
  98. public boolean onCreateOptionsMenu(Menu menu) {
  99. // Inflate the menu; this adds items to the action bar if it is present.
  100. getMenuInflater().inflate(R.menu.menu_main, menu);
  101. return true;
  102. }
  103.  
  104. @Override
  105. public boolean onOptionsItemSelected(MenuItem item) {
  106. // Handle action bar item clicks here. The action bar will
  107. // automatically handle clicks on the Home/Up button, so long
  108. // as you specify a parent activity in AndroidManifest.xml.
  109. int id = item.getItemId();
  110.  
  111. //noinspection SimplifiableIfStatement
  112. if (id == R.id.action_settings) {
  113. return true;
  114. }
  115.  
  116. return super.onOptionsItemSelected(item);
  117. }
  118.  
  119. public void addIngredient(String name) {
  120. ingredients.add(name);
  121. ingredientsAdapter.notifyDataSetChanged();
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement