|
1 | 1 | package pl.sigmapoint;
|
2 | 2 |
|
3 |
| -import android.content.res.ColorStateList; |
4 |
| -import android.graphics.Color; |
5 |
| -import android.graphics.drawable.GradientDrawable; |
6 | 3 | import android.os.Bundle;
|
7 | 4 | import android.support.v7.app.AppCompatActivity;
|
8 |
| -import android.view.Menu; |
9 |
| -import android.view.MenuItem; |
10 |
| -import android.view.View; |
11 | 5 |
|
12 | 6 | import pl.sigmapoint.customview.CustomButton;
|
13 | 7 |
|
14 | 8 | public class MainActivity extends AppCompatActivity {
|
15 | 9 |
|
| 10 | + public CustomButton createdButton; |
| 11 | + |
16 | 12 | @Override
|
17 | 13 | protected void onCreate(Bundle savedInstanceState) {
|
18 | 14 | super.onCreate(savedInstanceState);
|
19 | 15 | setContentView(R.layout.activity_main);
|
20 |
| - final CustomButton customButton = (CustomButton) findViewById(R.id.button); |
21 |
| - |
22 |
| - findViewById(R.id.change_background_color_button).setOnClickListener(new View.OnClickListener() { |
23 |
| - @Override |
24 |
| - public void onClick(View v) { |
25 |
| - customButton.setBackgroundColorStateList(new ColorStateList(new int[][]{new int[]{android.R.attr.state_enabled}, new int[]{android.R.attr.state_pressed}, new int[]{}}, new int[]{Color.GREEN, Color.MAGENTA, Color.RED})); |
26 |
| - } |
27 |
| - }); |
28 |
| - |
29 |
| - findViewById(R.id.change_text_button).setOnClickListener(new View.OnClickListener() { |
30 |
| - @Override |
31 |
| - public void onClick(View v) { |
32 |
| - customButton.setText("Custom"); |
33 |
| - } |
34 |
| - }); |
35 |
| - |
36 |
| - findViewById(R.id.enable_button).setOnClickListener(new View.OnClickListener() { |
37 |
| - @Override |
38 |
| - public void onClick(View v) { |
39 |
| - customButton.setEnabled(!customButton.isEnabled()); |
40 |
| - } |
41 |
| - }); |
42 |
| - |
43 |
| - findViewById(R.id.shape_button).setOnClickListener(new View.OnClickListener() { |
44 |
| - @Override |
45 |
| - public void onClick(View v) { |
46 |
| - customButton.setShapeBackground(GradientDrawable.OVAL, 40); |
47 |
| - } |
48 |
| - }); |
49 |
| - |
50 |
| - findViewById(R.id.text_color_button).setOnClickListener(new View.OnClickListener() { |
51 |
| - @Override |
52 |
| - public void onClick(View v) { |
53 |
| - customButton.setTextColor(Color.BLUE); |
54 |
| - } |
55 |
| - }); |
56 |
| - |
57 |
| - findViewById(R.id.elevation_button).setOnClickListener(new View.OnClickListener() { |
58 |
| - @Override |
59 |
| - public void onClick(View v) { |
60 |
| - customButton.setElevationEnabled(!customButton.isElevationEnabled()); |
61 |
| - } |
62 |
| - }); |
63 |
| - |
64 |
| - findViewById(R.id.frame_button).setOnClickListener(new View.OnClickListener() { |
65 |
| - @Override |
66 |
| - public void onClick(View v) { |
67 |
| - customButton.setFrame(Color.DKGRAY, 14); |
68 |
| - } |
69 |
| - }); |
70 |
| - |
| 16 | + getSupportFragmentManager().beginTransaction().add(R.id.main_container, new StartFragment()).commit(); |
71 | 17 | }
|
72 | 18 |
|
73 | 19 | @Override
|
74 |
| - public boolean onCreateOptionsMenu(Menu menu) { |
75 |
| - // Inflate the menu; this adds items to the action bar if it is present. |
76 |
| - getMenuInflater().inflate(R.menu.menu_main, menu); |
77 |
| - return true; |
| 20 | + public void onBackPressed() { |
| 21 | + if (getSupportFragmentManager().getBackStackEntryCount() > 1) |
| 22 | + getSupportFragmentManager().popBackStack(); |
| 23 | + else |
| 24 | + super.onBackPressed(); |
78 | 25 | }
|
79 | 26 |
|
80 |
| - @Override |
81 |
| - public boolean onOptionsItemSelected(MenuItem item) { |
82 |
| - // Handle action bar item clicks here. The action bar will |
83 |
| - // automatically handle clicks on the Home/Up button, so long |
84 |
| - // as you specify a parent activity in AndroidManifest.xml. |
85 |
| - int id = item.getItemId(); |
86 |
| - |
87 |
| - //noinspection SimplifiableIfStatement |
88 |
| - if (id == R.id.action_settings) { |
89 |
| - return true; |
90 |
| - } |
91 |
| - |
92 |
| - return super.onOptionsItemSelected(item); |
| 27 | + public void startGenerated() { |
| 28 | + getSupportFragmentManager().beginTransaction().replace(R.id.main_container, new GeneratedFragment()).addToBackStack(GeneratedFragment.class.getSimpleName()).commit(); |
93 | 29 | }
|
94 | 30 | }
|
0 commit comments