Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Addressing "Increase generating limit #9"
Browse files Browse the repository at this point in the history
  • Loading branch information
milosmns committed May 12, 2016
1 parent af3f370 commit 54e60fb
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 54 deletions.
47 changes: 34 additions & 13 deletions app/src/main/java/me/angrybyte/contactsgenerator/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.Toast;

Expand All @@ -35,8 +36,8 @@
import me.angrybyte.contactsgenerator.service.ServiceApi;
import me.angrybyte.numberpicker.view.ActualNumberPicker;

public class MainActivity extends AppCompatActivity implements Toolbar.OnMenuItemClickListener, View.OnClickListener, ServiceConnection,
AlertDialog.OnClickListener {
public class MainActivity extends AppCompatActivity
implements Toolbar.OnMenuItemClickListener, View.OnClickListener, ServiceConnection, AlertDialog.OnClickListener {

private static final String TAG = MainActivity.class.getSimpleName();

Expand All @@ -47,14 +48,16 @@ public class MainActivity extends AppCompatActivity implements Toolbar.OnMenuIte
private static final String PERSISTENT_GENDER = "gender";
private static final String PERSISTENT_USAGE_OF_PHOTOS = "use_photos";

private Dialog mConfirmationDialog;
private CheckBox mUseAvatars;
private AlertDialog mAboutDialog;
private RadioButton mMales;
private RadioButton mFemales;
private RadioButton mBothGenders;
private AlertDialog mAboutDialog;
private ActualNumberPicker mPicker;
private Dialog mConfirmationDialog;
private ImageButton mIncrement;
private ImageButton mDecrement;
private ProgressDialog mProgressDialog;
private ActualNumberPicker mPicker;
private boolean mServiceDisconnected;

@SuppressWarnings("ConstantConditions")
Expand All @@ -72,11 +75,16 @@ protected void onCreate(Bundle savedInstanceState) {

// initialize views
mPicker = (ActualNumberPicker) findViewById(R.id.main_number_picker);
mMales = (RadioButton) findViewById(R.id.activity_main_gender_male);
mFemales = (RadioButton) findViewById(R.id.activity_main_gender_female);
mMales = (RadioButton) findViewById(R.id.main_gender_male);
mFemales = (RadioButton) findViewById(R.id.main_gender_female);
mUseAvatars = (CheckBox) findViewById(R.id.main_avatars_checkbox);
mBothGenders = (RadioButton) findViewById(R.id.activity_main_gender_both);
findViewById(R.id.activity_main_button_generate).setOnClickListener(this);
mBothGenders = (RadioButton) findViewById(R.id.main_gender_both);
mIncrement = (ImageButton) findViewById(R.id.main_button_increment);
mDecrement = (ImageButton) findViewById(R.id.main_button_decrement);

findViewById(R.id.main_button_generate).setOnClickListener(this);
mIncrement.setOnClickListener(this);
mDecrement.setOnClickListener(this);

// hack-fix for the buggy RadioGroup
mBothGenders.setChecked(true);
Expand Down Expand Up @@ -107,16 +115,28 @@ private String getChosenGender() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.activity_main_button_generate: {
case R.id.main_button_generate: {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
generateContacts();
} else {
ActivityCompat.requestPermissions(this, new String[]{
ActivityCompat.requestPermissions(this, new String[] {
Manifest.permission.WRITE_CONTACTS
}, PERMISSIONS_WRITE_REQUEST_CODE);
}
break;
}
case R.id.main_button_increment: {
mPicker.setValue(mPicker.getValue() + 1);
// not invalidating automatically to prevent a catastrophic number of invalidations in a single frame
mPicker.invalidate();
break;
}
case R.id.main_button_decrement: {
mPicker.setValue(mPicker.getValue() - 1);
// not invalidating automatically to prevent a catastrophic number of invalidations in a single frame
mPicker.invalidate();
break;
}
}
}

Expand Down Expand Up @@ -173,10 +193,11 @@ public void onClick(DialogInterface dialogInterface, int i) {
builder.setPositiveButton(R.string.delete_confirmation_positive_button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.WRITE_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
deleteGeneratedContacts();
} else {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{
ActivityCompat.requestPermissions(MainActivity.this, new String[] {
Manifest.permission.READ_CONTACTS
}, PERMISSIONS_READ_REQUEST_CODE);
}
Expand Down
78 changes: 56 additions & 22 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,58 @@
android:text="@string/how_many_contacts"
android:textSize="24sp" />

<me.angrybyte.numberpicker.view.ActualNumberPicker
android:id="@+id/main_number_picker"
style="@style/ContactsTheme.NumberPickerStyle"
android:layout_width="match_parent"
<LinearLayout
style="@style/ContactsTheme.NumberPickerContainerStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:bar_color="?attr/colorAccent"
app:draw_over_text="false"
app:max_value="1000"
app:min_value="1"
app:show_bars="true"
app:show_controls="false"
app:show_fast_controls="false"
app:show_highlight="false"
app:show_text="true"
app:text_color="?attr/colorAccent"
app:value="1" />
android:gravity="center"
android:orientation="horizontal">

<ImageButton
android:id="@+id/main_button_decrement"
style="@style/ContactsTheme.IncDecButtonStyle"
android:layout_width="@dimen/action_button_size"
android:layout_height="@dimen/action_button_size"
android:layout_marginLeft="@dimen/spacing_micro"
android:layout_marginStart="@dimen/spacing_micro"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/desc_ic_minus"
android:padding="@dimen/spacing_normal"
android:scaleType="centerInside"
android:src="@drawable/ic_decrement" />

<me.angrybyte.numberpicker.view.ActualNumberPicker
android:id="@+id/main_number_picker"
style="@style/ContactsTheme.NumberPickerStyle"
android:layout_width="0dp"
android:layout_weight="1"
app:bar_color="?attr/colorAccent"
app:draw_over_text="false"
app:max_value="8000"
app:min_value="1"
app:show_bars="true"
app:show_controls="false"
app:show_fast_controls="false"
app:show_highlight="false"
app:show_text="true"
app:text_color="?attr/colorAccent"
app:value="500" />

<ImageButton
android:id="@+id/main_button_increment"
style="@style/ContactsTheme.IncDecButtonStyle"
android:layout_width="@dimen/action_button_size"
android:layout_height="@dimen/action_button_size"
android:layout_marginEnd="@dimen/spacing_micro"
android:layout_marginRight="@dimen/spacing_micro"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/desc_ic_plus"
android:padding="@dimen/spacing_normal"
android:scaleType="centerInside"
android:src="@drawable/ic_increment" />

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
Expand All @@ -75,36 +111,34 @@
android:orientation="vertical">

<RadioButton
android:id="@+id/activity_main_gender_male"
android:id="@+id/main_gender_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/all_males"
android:textSize="18sp" />

<RadioButton
android:id="@+id/activity_main_gender_female"
android:id="@+id/main_gender_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/all_females"
android:textSize="18sp" />

<!-- checked by default, but from code - XML didn't work.. -->
<RadioButton
android:id="@+id/activity_main_gender_both"
android:id="@+id/main_gender_both"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/do_not_care"
android:textSize="18sp" />

</RadioGroup>

</LinearLayout>

</LinearLayout>

</ScrollView>

<ImageButton
android:id="@+id/activity_main_button_generate"
android:id="@+id/main_button_generate"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_gravity="bottom|end"
Expand Down
19 changes: 14 additions & 5 deletions app/src/main/res/values-land/view_styles.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<?xml version="1.0" encoding="utf-8"?><!-- Phone - landscape -->
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">

<style name="ContactsTheme.NumberPickerStyle" parent="Base.Theme.AppCompat">
<item name="android:layout_height">80dp</item>
<!-- Phone - landscape -->

<style name="ContactsTheme.NumberPickerContainerStyle">
<item name="android:layout_marginBottom">20dp</item>
<item name="android:layout_marginLeft">@dimen/spacing_huge</item>
<item name="android:layout_marginRight">@dimen/spacing_huge</item>
</style>

<style name="ContactsTheme.NumberPickerStyle">
<item name="android:layout_height">80dp</item>
<item name="android:layout_marginLeft">@dimen/spacing_normal</item>
<item name="android:layout_marginRight">@dimen/spacing_normal</item>
<item name="bar_width">1.2dp</item>
<item name="bars_count">40</item>
<item name="text_size">18sp</item>
</style>

<style name="ContactsTheme.IncDecButtonStyle">
<item name="android:visibility">gone</item>
</style>

<style name="ContactsTheme.MainAppBarTheme" parent="Widget.AppCompat.Toolbar">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/res/values-sw600dp-land/view_styles.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<?xml version="1.0" encoding="utf-8"?><!-- 7" Tablet - landscape -->
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">

<style name="ContactsTheme.NumberPickerStyle" parent="Base.Theme.AppCompat">
<item name="android:layout_height">100dp</item>
<!-- 7" Tablet - landscape -->

<style name="ContactsTheme.NumberPickerContainerStyle">
<item name="android:layout_marginBottom">20dp</item>
</style>

<style name="ContactsTheme.NumberPickerStyle">
<item name="android:layout_height">100dp</item>
<item name="android:layout_marginLeft">@dimen/spacing_huge</item>
<item name="android:layout_marginRight">@dimen/spacing_huge</item>
<item name="bar_width">1.4dp</item>
<item name="bars_count">42</item>
<item name="text_size">22sp</item>
</style>

<style name="ContactsTheme.IncDecButtonStyle">
<item name="android:visibility">visible</item>
</style>

<style name="ContactsTheme.MainAppBarTheme" parent="Widget.AppCompat.Toolbar">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/res/values-sw600dp/view_styles.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<?xml version="1.0" encoding="utf-8"?><!-- 7" Tablet - portrait -->
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">

<style name="ContactsTheme.NumberPickerStyle" parent="Base.Theme.AppCompat">
<item name="android:layout_height">100dp</item>
<!-- 7" Tablet - portrait -->

<style name="ContactsTheme.NumberPickerContainerStyle">
<item name="android:layout_marginBottom">30dp</item>
</style>

<style name="ContactsTheme.NumberPickerStyle">
<item name="android:layout_height">100dp</item>
<item name="android:layout_marginLeft">@dimen/spacing_normal</item>
<item name="android:layout_marginRight">@dimen/spacing_normal</item>
<item name="bar_width">1.4dp</item>
<item name="bars_count">30</item>
<item name="text_size">22sp</item>
</style>

<style name="ContactsTheme.IncDecButtonStyle">
<item name="android:visibility">visible</item>
</style>

<style name="ContactsTheme.MainAppBarTheme" parent="Widget.AppCompat.Toolbar">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/res/values-w720dp/view_styles.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<?xml version="1.0" encoding="utf-8"?><!-- Large tablet -->
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">

<style name="ContactsTheme.NumberPickerStyle" parent="Base.Theme.AppCompat">
<item name="android:layout_height">100dp</item>
<!-- Large tablet -->

<style name="ContactsTheme.NumberPickerContainerStyle">
<item name="android:layout_marginBottom">30dp</item>
</style>

<style name="ContactsTheme.NumberPickerStyle">
<item name="android:layout_height">100dp</item>
<item name="android:layout_marginLeft">@dimen/spacing_huge</item>
<item name="android:layout_marginRight">@dimen/spacing_huge</item>
<item name="bar_width">1.4dp</item>
<item name="bars_count">30</item>
<item name="text_size">22sp</item>
</style>

<style name="ContactsTheme.IncDecButtonStyle">
<item name="android:visibility">visible</item>
</style>

<style name="ContactsTheme.MainAppBarTheme" parent="Widget.AppCompat.Toolbar">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<dimen name="stats_activity_large_numbers_text_size">60sp</dimen>
<dimen name="stats_activity_small_text_size">14sp</dimen>

<dimen name="action_button_size">48dp</dimen>

<dimen name="spacing_nano">2dp</dimen>
<dimen name="spacing_micro">4dp</dimen>
<dimen name="spacing_small">8dp</dimen>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
<string name="desc_ic_name">Person\'s name</string>
<string name="desc_ic_phone">Person\'s phone</string>
<string name="desc_ic_email">Person\'s email</string>
<string name="desc_ic_plus">Increment</string>
<string name="desc_ic_minus">Decrement</string>

<!-- Deletion strings -->
<string name="delete_menu_generated_contacts">Delete generated contacts</string>
Expand Down
19 changes: 14 additions & 5 deletions app/src/main/res/values/view_styles.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<?xml version="1.0" encoding="utf-8"?><!-- Phone - portrait -->
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">

<style name="ContactsTheme.NumberPickerStyle" parent="Base.Theme.AppCompat">
<item name="android:layout_height">80dp</item>
<!-- Phone - portrait -->

<style name="ContactsTheme.NumberPickerContainerStyle">
<item name="android:layout_marginBottom">20dp</item>
<item name="android:layout_marginLeft">@dimen/spacing_small</item>
<item name="android:layout_marginRight">@dimen/spacing_small</item>
</style>

<style name="ContactsTheme.NumberPickerStyle">
<item name="android:layout_height">80dp</item>
<item name="android:layout_marginLeft">0dp</item>
<item name="android:layout_marginRight">0dp</item>
<item name="bar_width">1.2dp</item>
<item name="bars_count">26</item>
<item name="text_size">18sp</item>
</style>

<style name="ContactsTheme.IncDecButtonStyle">
<item name="android:visibility">visible</item>
</style>

<style name="ContactsTheme.MainAppBarTheme" parent="Widget.AppCompat.Toolbar">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
Expand Down

0 comments on commit 54e60fb

Please sign in to comment.