Skip to content

Commit 3c855c0

Browse files
committed
Create Demo. Library improvments connected with icon position and small refactor.
1 parent 35eb8aa commit 3c855c0

File tree

10 files changed

+742
-203
lines changed

10 files changed

+742
-203
lines changed

app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ android {
2222

2323
dependencies {
2424
compile fileTree(include: ['*.jar'], dir: 'libs')
25-
compile 'com.android.support:appcompat-v7:23.0.0'
2625
compile project(':library')
26+
compile 'com.android.support:appcompat-v7:23.0.0'
27+
compile 'com.github.yukuku:ambilwarna:2.0'
2728
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package pl.sigmapoint;
2+
3+
4+
import android.os.Bundle;
5+
import android.support.v4.app.Fragment;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
import android.widget.CompoundButton;
10+
import android.widget.FrameLayout;
11+
import android.widget.ToggleButton;
12+
13+
import pl.sigmapoint.customview.CustomButton;
14+
15+
/**
16+
* A simple {@link Fragment} subclass.
17+
*/
18+
public class GeneratedFragment extends Fragment {
19+
20+
private View view;
21+
private ToggleButton enableTB;
22+
private CustomButton button;
23+
24+
public GeneratedFragment() {
25+
// Required empty public constructor
26+
}
27+
28+
29+
@Override
30+
public View onCreateView(LayoutInflater inflater, ViewGroup container,
31+
Bundle savedInstanceState) {
32+
// Inflate the layout for this fragment
33+
view = inflater.inflate(R.layout.fragment_generated, container, false);
34+
35+
enableTB = (ToggleButton) view.findViewById(R.id.enable);
36+
enableTB.setChecked(true);
37+
38+
return view;
39+
}
40+
41+
@Override
42+
public void onActivityCreated(Bundle savedInstanceState) {
43+
super.onActivityCreated(savedInstanceState);
44+
if (getActivity() instanceof MainActivity) {
45+
button = ((MainActivity) getActivity()).createdButton;
46+
((FrameLayout) view.findViewById(R.id.generated_container)).addView(button);
47+
}
48+
49+
enableTB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
50+
@Override
51+
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
52+
button.setEnabled(isChecked);
53+
}
54+
});
55+
56+
}
57+
}
Lines changed: 10 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,30 @@
11
package pl.sigmapoint;
22

3-
import android.content.res.ColorStateList;
4-
import android.graphics.Color;
5-
import android.graphics.drawable.GradientDrawable;
63
import android.os.Bundle;
74
import android.support.v7.app.AppCompatActivity;
8-
import android.view.Menu;
9-
import android.view.MenuItem;
10-
import android.view.View;
115

126
import pl.sigmapoint.customview.CustomButton;
137

148
public class MainActivity extends AppCompatActivity {
159

10+
public CustomButton createdButton;
11+
1612
@Override
1713
protected void onCreate(Bundle savedInstanceState) {
1814
super.onCreate(savedInstanceState);
1915
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();
7117
}
7218

7319
@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();
7825
}
7926

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();
9329
}
9430
}

0 commit comments

Comments
 (0)