Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
staceybellerose committed Oct 1, 2018
2 parents 1f389c3 + 6f0ef4d commit 18e4afd
Show file tree
Hide file tree
Showing 53 changed files with 1,072 additions and 489 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ env:
global:
# install timeout in minutes (2 minutes by default)
- ADB_INSTALL_TIMEOUT=8

env:
matrix:
# uncomment the following lines to test the various emulators for speed
#- API=android-15 ABI=armeabi-v7a
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
[![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://raw.githubusercontent.com/staceybellerose/RandomWordGenerator/master/LICENSE)
[![Android](https://img.shields.io/badge/platform-android-green.svg)](https://developer.android.com/develop/index.html)
[![Latest Version](https://img.shields.io/github/release/staceybellerose/RandomWordGenerator.svg)](https://github.com/staceybellerose/RandomWordGenerator/releases)
[![BCH compliance](https://bettercodehub.com/edge/badge/staceybellerose/RandomWordGenerator?branch=develop)](https://bettercodehub.com/)
[![CodeFactor](https://www.codefactor.io/repository/github/staceybellerose/randomwordgenerator/badge)](https://www.codefactor.io/repository/github/staceybellerose/randomwordgenerator)
[![Known Vulnerabilities](https://snyk.io/test/github/staceybellerose/randomwordgenerator/badge.svg)](https://snyk.io/test/github/staceybellerose/randomwordgenerator)

The **Random Word Generator** Android app generates
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.staceybellerose.randomwordgenerator;

import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
Expand All @@ -22,6 +23,8 @@ protected void onCreate(final Bundle savedInstanceState) {
setContentView(R.layout.activity_changelog);
ButterKnife.bind(this);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
final ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.staceybellerose.randomwordgenerator;

import android.graphics.Color;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
Expand Down Expand Up @@ -51,9 +52,11 @@ protected void onCreate(final Bundle savedInstanceState) {
mToolbar.setTitleTextColor(Color.WHITE);
mToolbar.setSubtitleTextColor(Color.WHITE);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
final ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);

LibsSupportFragment fragment = new LibsBuilder()
final LibsSupportFragment fragment = new LibsBuilder()
.withFields(R.string.class.getFields())
.withAutoDetect(true)
.withAboutAppName(mAppName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

Expand All @@ -21,15 +22,17 @@ public class SettingsActivity extends AppCompatActivity implements SettingsFragm
/**
* The result intent to be used when this activity called from startActivityForResult
*/
private Intent mResultIntent = new Intent();
private final Intent mResultIntent = new Intent();

@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
ButterKnife.bind(this);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
final ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);

getFragmentManager().beginTransaction()
.replace(R.id.frame_container, new SettingsFragment()).commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,76 @@

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup;

import com.staceybellerose.randomwordgenerator.utils.Settings;

/**
* A Fragment to display the Settings
*/
public class SettingsFragment extends PreferenceFragment {
public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
/**
* The calling activity, implementing the notification interface.
*/
private OnPreferenceChangeListener mCallback;
/**
* Utility object to manage reading our shared preferences
*/
private Settings mSettings;

@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
Preference wordList = findPreference(getString(R.string.pref_word_list));
Preference.OnPreferenceChangeListener wordListChangeListener = (preference, newValue) -> {
mCallback.onWordListChanged();
return true;
};

wordList.setOnPreferenceChangeListener(wordListChangeListener);
Preference unrestricted = findPreference(getString(R.string.pref_unlimited_length_flag));
unrestricted.setOnPreferenceChangeListener(wordListChangeListener);
Preference maxLength = findPreference(getString(R.string.pref_max_word_length));
maxLength.setOnPreferenceChangeListener(wordListChangeListener);
Preference minLength = findPreference(getString(R.string.pref_min_word_length));
minLength.setOnPreferenceChangeListener(wordListChangeListener);
mSettings = Settings.getInstance(getActivity());

Preference cleanWordsPreference = findPreference(getString(R.string.pref_clean_words_flag));
if (BuildConfig.CLEAN_WORDS_ONLY) {
PreferenceGroup preferenceGroup = (PreferenceGroup) findPreference(getString(R.string.pref_filters_header));
final Preference cleanWordsPreference = findPreference(getString(R.string.pref_clean_words_flag));
final PreferenceGroup preferenceGroup
= (PreferenceGroup) findPreference(getString(R.string.pref_filters_header));
preferenceGroup.removePreference(cleanWordsPreference);
} else {
cleanWordsPreference.setOnPreferenceChangeListener(((preference, newValue) -> {
mCallback.onCleanWordsChanged();
return true;
}));
}
}

@Override
public void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}

@Override
public void onPause() {
super.onPause();
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
}

/**
* Called when a shared preference is changed, added, or removed. This may be called even if
* a preference is set to its existing value.
*
* @param sharedPreferences The SharedPreferences that received the change.
* @param key The key of the preference that was changed, added, or removed.
*/
@Override
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) {
if (key.equals(getString(R.string.pref_unlimited_length_flag))) {
mCallback.onWordListChanged();
} else if (key.equals(getString(R.string.pref_max_word_length))) {
mCallback.onWordListChanged();
} else if (key.equals(getString(R.string.pref_min_word_length))) {
mCallback.onWordListChanged();
} else if (key.equals(getString(R.string.pref_word_list))) {
mCallback.onWordListChanged();
} else if (key.equals(getString(R.string.pref_clean_words_flag))) {
mCallback.onCleanWordsChanged();
}
mSettings.refreshPreferences();
}

@Override
@SuppressWarnings("deprecation")
public void onAttach(final Activity activity) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.staceybellerose.randomwordgenerator;

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
Expand Down Expand Up @@ -33,12 +34,14 @@ protected void onCreate(final Bundle savedInstanceState) {
setContentView(R.layout.activity_word_list_details);
ButterKnife.bind(this);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
final ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);

mRecyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
final RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(layoutManager);
RecyclerView.Adapter adapter = new ListDetailsAdapter(this);
final RecyclerView.Adapter adapter = new ListDetailsAdapter(this);
mRecyclerView.setAdapter(adapter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.staceybellerose.randomwordgenerator.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
Expand All @@ -22,20 +23,21 @@ public class ListDetailsAdapter extends RecyclerView.Adapter<ListDetailsAdapter.
/**
* the list to display
*/
private ArrayList<WordList> mWordList = new ArrayList<>();
private final List<WordList> mWordList = new ArrayList<>();

/**
* Constructor
*
* @param context the activity context
*/
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public ListDetailsAdapter(final Context context) {
Resources res = context.getResources();
String[] listNames = res.getStringArray(R.array.word_list_descriptions);
String[] sources = res.getStringArray(R.array.list_sources);
int[] counts = res.getIntArray(R.array.list_lengths);
final Resources res = context.getResources();
final String[] listNames = res.getStringArray(R.array.word_list_descriptions);
final String[] sources = res.getStringArray(R.array.list_sources);
final int[] counts = res.getIntArray(R.array.list_lengths);
for (int i = 0; i < listNames.length; i++) {
String name = listNames[i];
final String name = listNames[i];
String source;
int count;
try {
Expand All @@ -54,14 +56,15 @@ public ListDetailsAdapter(final Context context) {

@Override
public DetailsViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.word_list_details_item, parent, false);
final View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.word_list_details_item, parent, false);
return new DetailsViewHolder(view);
}

@Override
public void onBindViewHolder(final DetailsViewHolder holder, final int position) {
Context context = holder.getContext();
WordList wordList = mWordList.get(position);
final Context context = holder.getContext();
final WordList wordList = mWordList.get(position);
holder.getListName().setText(wordList.getListName());
holder.getSourceText().setText(wordList.getSource());
holder.getCountText().setText(String.valueOf(wordList.getWordCount()));
Expand Down Expand Up @@ -213,7 +216,7 @@ int getWordCount() {
* @return the amount of entropy
*/
double getEntropy() {
double entropy = Math.log(mWordCount) / Math.log(2);
final double entropy = Math.log(mWordCount) / Math.log(2);
return Math.round(entropy * 10.0) / 10.0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
public class SpecialButtonListener extends SimpleLibsListener {
@Override
public boolean onExtraClicked(final View view, final Libs.SpecialButton specialButton) {
Context context = view.getContext();
final Context context = view.getContext();
Intent intent = null;
if (specialButton == Libs.SpecialButton.SPECIAL1) {
Intent intent = new Intent(context, SettingsActivity.class);
context.startActivity(intent);
return true;
intent = new Intent(context, SettingsActivity.class);
} else if (specialButton == Libs.SpecialButton.SPECIAL2) {
Intent intent = new Intent(context, WordListDetailsActivity.class);
context.startActivity(intent);
return true;
intent = new Intent(context, WordListDetailsActivity.class);
} else if (specialButton == Libs.SpecialButton.SPECIAL3) {
Intent intent = new Intent(context, ChangelogActivity.class);
intent = new Intent(context, ChangelogActivity.class);
}
if (intent != null) {
context.startActivity(intent);
return true;
}
Expand Down
Loading

0 comments on commit 18e4afd

Please sign in to comment.