Commit 4be6253a authored by PurkkaKoodari's avatar PurkkaKoodari

Alpha 0.3: rewrite most of UI, add settings menu, etc.

parent ea9d285f
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectCodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
<value />
</option>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="android" withSubpackages="true" static="false" />
<emptyLine />
<package name="com" withSubpackages="true" static="false" />
<emptyLine />
<package name="junit" withSubpackages="true" static="false" />
<emptyLine />
<package name="net" withSubpackages="true" static="false" />
<emptyLine />
<package name="org" withSubpackages="true" static="false" />
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<emptyLine />
<package name="javax" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="true" />
<emptyLine />
</value>
</option>
<option name="RIGHT_MARGIN" value="100" />
<AndroidXmlCodeStyleSettings>
<option name="USE_CUSTOM_SETTINGS" value="true" />
</AndroidXmlCodeStyleSettings>
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" />
<pair source="c" header="h" />
</extensions>
</Objective-C-extensions>
<XML>
<option name="XML_KEEP_LINE_BREAKS" value="false" />
<option name="XML_ALIGN_ATTRIBUTES" value="false" />
<option name="XML_SPACE_INSIDE_EMPTY_TAG" value="true" />
</XML>
<codeStyleSettings language="XML">
<option name="FORCE_REARRANGE_MODE" value="1" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:android</NAME>
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:.*</NAME>
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:id</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:name</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>name</NAME>
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>style</NAME>
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:layout_width</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:layout_height</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:layout_.*</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:width</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:height</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_NAMESPACE>.*</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
</value>
</option>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default (1)" />
</component>
</project>
\ No newline at end of file
......@@ -10,5 +10,11 @@
<option name="processLiterals" value="true" />
<option name="processComments" value="true" />
</inspection_tool>
<inspection_tool class="UnusedImport" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="WeakerAccess" enabled="true" level="WARNING" enabled_by_default="true">
<option name="SUGGEST_PACKAGE_LOCAL_FOR_MEMBERS" value="true" />
<option name="SUGGEST_PACKAGE_LOCAL_FOR_TOP_CLASSES" value="false" />
<option name="SUGGEST_PRIVATE_FOR_INNERS" value="false" />
</inspection_tool>
</profile>
</component>
\ No newline at end of file
......@@ -105,12 +105,18 @@
<orderEntry type="library" exported="" name="support-core-ui-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="support-core-utils-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="support-fragment-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="hamcrest-core-1.1" level="project" />
<orderEntry type="library" exported="" name="transition-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="support-v4-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="support-media-compat-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="json-simple-1.1.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="hamcrest-core-1.1" level="project" />
<orderEntry type="library" exported="" name="design-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="support-compat-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="junit-4.10" level="project" />
<orderEntry type="library" exported="" name="support-annotations-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-26.0.0-alpha1" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -21,4 +21,6 @@ android {
dependencies {
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile 'com.android.support:support-v4:26.+'
compile 'com.android.support:design:26.+'
compile 'com.android.support:appcompat-v7:26.+'
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.pietu1998.wordbasehacker"
android:versionCode="2"
android:versionName="alpha 0.2" >
package="net.pietu1998.wordbasehacker"
android:versionCode="3"
android:versionName="alpha 0.3">
<uses-sdk
android:minSdkVersion="21"
android:targetSdkVersion="26" />
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_SUPERUSER"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:name=".HackerApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme">
<activity
android:name=".GameListActivity"
android:label="@string/app_name" >
</activity>
<activity-alias
android:name=".GameListActivityNormal"
android:enabled="true"
android:label="@string/app_name"
android:targetActivity=".GameListActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias
android:name=".GameListActivityHorst"
android:enabled="false"
android:label="@string/app_name_horst"
android:targetActivity=".GameListActivity" >
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity-alias>
</activity>
<activity
android:name=".BoardActivity"
android:label="@string/hack_game" >
android:label="@string/hack_game">
</activity>
<service android:name="net.pietu1998.wordbasehacker.HudService" >
<service android:name=".HudService">
</service>
<receiver
android:name="net.pietu1998.wordbasehacker.BootReceiver"
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName=".GameListActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="net.pietu1998.wordbasehacker.GameListActivity"/>
</activity>
</application>
</manifest>
\ No newline at end of file
......@@ -19,22 +19,23 @@ import org.json.simple.JSONArray;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
......@@ -44,12 +45,13 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class BoardActivity extends Activity {
public class BoardActivity extends AppCompatActivity {
private Scoring currentScoring, scoring = Scoring.DEFAULT;
private boolean changingValues = false;
private Game game;
private List<Possibility> possibilities = new ArrayList<>();
private char[] tileLetters = null;
private boolean loaded = false;
@Override
......@@ -57,20 +59,35 @@ public class BoardActivity extends Activity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_board);
loadScoring();
Button scoring = (Button) findViewById(R.id.scoringBtn);
Button scoring = (Button) findViewById(R.id.scoring_btn);
scoring.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
scoringDialog();
}
});
Button play = (Button) findViewById(R.id.play_btn);
play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.wordbaseapp", "com.wordbaseapp.BoardActivity"));
intent.putExtra("game_id", (long) game.getId());
startActivity(intent);
}
});
Parcelable extra = getIntent().getParcelableExtra("game");
if (extra == null) {
if (!(extra instanceof Game)) {
Toast.makeText(this, R.string.internal_error, Toast.LENGTH_SHORT).show();
finish();
return;
}
game = (Game) extra;
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(getResources().getString(R.string.title_activity_board, game.getOpponent()));
actionBar.setDisplayHomeAsUpEnabled(true);
}
loaded = false;
}
......@@ -88,10 +105,18 @@ public class BoardActivity extends Activity {
task.execute();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
private class LoadTask extends AsyncTask<Void, Integer, Integer> {
private ProgressDialog dialog;
private List<Possibility> results;
private final ProgressDialog dialog;
public LoadTask(ProgressDialog dialog) {
this.dialog = dialog;
......@@ -163,7 +188,8 @@ public class BoardActivity extends Activity {
publishProgress(R.string.scoring_words);
board.scoreWords(game.isFlipped());
results = board.getResults();
tileLetters = board.getTileLetters();
possibilities = board.getResults();
return 0;
} catch (NumberFormatException | ParseException | SQLiteException | IndexOutOfBoundsException e) {
Log.e("WordbaseHacker", "Failed to read data.", e);
......@@ -188,7 +214,6 @@ public class BoardActivity extends Activity {
}
}).show();
} else {
possibilities = results;
updateView();
}
}
......@@ -209,7 +234,7 @@ public class BoardActivity extends Activity {
((TextView) findViewById(R.id.status)).setText(R.string.no_moves);
return;
}
((ImageView) findViewById(R.id.movePicture)).setImageDrawable(new BoardDrawable(best, game.isFlipped()));
((ImageView) findViewById(R.id.move_picture)).setImageDrawable(new BoardDrawable(best, tileLetters, game.isFlipped()));
((TextView) findViewById(R.id.status)).setText(getResources().getString(R.string.best_move, best.getWord(), max));
}
......@@ -266,10 +291,6 @@ public class BoardActivity extends Activity {
scoring = currentScoring;
saveScoring();
updateView();
if (scoring.equals(new Scoring(7, 0, 3, 3, 5, 6, false)))
enableDev();
if (scoring.equals(new Scoring(4, 0, 6, 7, 7, 8, false)))
toggleHorst();
}
});
final AlertDialog shown = dialog.create();
......@@ -302,7 +323,7 @@ public class BoardActivity extends Activity {
}
});
Button defaults = (Button) layout.findViewById(R.id.defaults);
Button defaults = layout.findViewById(R.id.defaults);
defaults.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......@@ -346,26 +367,4 @@ public class BoardActivity extends Activity {
}
}
private void enableDev() {
getSharedPreferences("WordbaseHacker", 0).edit().putBoolean("dev", true).commit();
Toast.makeText(this, R.string.dev_on, Toast.LENGTH_SHORT).show();
}
private void toggleHorst() {
SharedPreferences pref = getSharedPreferences("WordbaseHacker", 0);
boolean horst = !pref.getBoolean("horst", false);
pref.edit().putBoolean("horst", horst).commit();
getPackageManager()
.setComponentEnabledSetting(
new ComponentName(this, "net.pietu1998.wordbasehacker.GameListActivityHorst"),
horst ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
getPackageManager()
.setComponentEnabledSetting(
new ComponentName(this, "net.pietu1998.wordbasehacker.GameListActivityNormal"),
horst ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED : PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
Toast.makeText(this, R.string.horst_toggle, Toast.LENGTH_SHORT).show();
}
}
package net.pietu1998.wordbasehacker;
import net.pietu1998.wordbasehacker.solver.Coordinate;
import net.pietu1998.wordbasehacker.solver.Possibility;
import net.pietu1998.wordbasehacker.solver.Tile;
import android.graphics.Canvas;
......@@ -13,13 +12,15 @@ import android.support.annotation.NonNull;
public class BoardDrawable extends Drawable {
private Possibility pos;
private boolean flipped;
private final Possibility pos;
private final char[] tileLetters;
private final boolean flipped;
private final static float SQRT512 = (float) (16 * Math.sqrt(2));
public BoardDrawable(Possibility pos, boolean flipped) {
public BoardDrawable(Possibility pos, char[] tileLetters, boolean flipped) {
this.pos = pos;
this.tileLetters = tileLetters;
this.flipped = flipped;
}
......@@ -63,7 +64,6 @@ public class BoardDrawable extends Drawable {
path.setStrokeCap(Paint.Cap.ROUND);
path.setColor(0xFF009900);
char[] tileLetters = pos.getTileLetters();
int[] tileStates = pos.getResult();
for (int y = 0, index = 0; y < 13; y++) {
for (int x = 0; x < 10; x++, index++) {
......
......@@ -6,12 +6,14 @@ import android.content.Intent;
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent service = new Intent(context, HudService.class);
// TODO Remove condition when HUD working
if (BuildConfig.DEBUG)
context.startService(service);
}
@Override