Recreate the info activity as a PySide QWebView.
Add in Markdown for the documentation assets.
This commit is contained in:
parent
d791840bdd
commit
0039466767
|
@ -1,104 +0,0 @@
|
|||
/*****************************************************************************
|
||||
InfoActivity.java - The activity that provides built-in information.
|
||||
*****************************************************************************
|
||||
|
||||
*****************************************************************************
|
||||
This file is part of justCheckers.
|
||||
|
||||
justCheckers is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
justCheckers is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with justCheckers. If not, see <http://www.gnu.org/licenses/>.
|
||||
*****************************************************************************/
|
||||
|
||||
package org.justcheckers.android;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.justcheckers.common.GlobalConstants;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class InfoActivity extends Activity {
|
||||
|
||||
private int flagInformationToDisplay;
|
||||
|
||||
//TODO: Clean this up into something more modularized.
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Setup the user interface for the main menu.
|
||||
this.setContentView(R.layout.info_screen);
|
||||
|
||||
// Figure out which text to load. The default
|
||||
if (savedInstanceState != null) {
|
||||
this.flagInformationToDisplay =
|
||||
savedInstanceState.getInt(GlobalConstants.EXTRA_INFORMATION_DISPLAY_FLAG);
|
||||
|
||||
} else {
|
||||
Bundle extras = this.getIntent().getExtras();
|
||||
if (extras != null) {
|
||||
this.flagInformationToDisplay =
|
||||
extras.getInt(GlobalConstants.EXTRA_INFORMATION_DISPLAY_FLAG);
|
||||
}
|
||||
}
|
||||
|
||||
// Load the right text.
|
||||
int rawInfoRes = 0;
|
||||
if (this.flagInformationToDisplay == GlobalConstants.FLAG_INFORMATION_DISPLAY_ABOUT_US) {
|
||||
rawInfoRes = R.raw.readme;
|
||||
} else if (this.flagInformationToDisplay == GlobalConstants.FLAG_INFORMATION_DISPLAY_LICENSE) {
|
||||
rawInfoRes = R.raw.gpl_3_license;
|
||||
} else {
|
||||
rawInfoRes = R.raw.readme;
|
||||
}
|
||||
|
||||
// Read the raw document into a string.
|
||||
InputStream docInfoStream = this.getResources().openRawResource(rawInfoRes);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(docInfoStream));
|
||||
String result = "Text here";
|
||||
|
||||
try {
|
||||
// Gather all the data.
|
||||
StringBuilder buildDoc = new StringBuilder();
|
||||
String docLine = reader.readLine();
|
||||
|
||||
while (docLine != null) {
|
||||
buildDoc.append(docLine + "\n");
|
||||
docLine = reader.readLine();
|
||||
}
|
||||
|
||||
result = buildDoc.toString();
|
||||
|
||||
} catch (IOException e) {
|
||||
Log.e("InfoActivity", "Input error: " + e.getMessage());
|
||||
}
|
||||
|
||||
TextView infoText = (TextView) this.findViewById(R.id.info_text);
|
||||
infoText.setText(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt(GlobalConstants.EXTRA_INFORMATION_DISPLAY_FLAG,
|
||||
this.flagInformationToDisplay);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/screen_root"
|
||||
android:background="@drawable/backdrop"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView android:id="@+id/app_logo"
|
||||
android:background="#DDFFFFFF"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="5dip"
|
||||
android:src="@drawable/logo" />
|
||||
|
||||
<ScrollView
|
||||
android:layout_below="@+id/app_logo"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dip"
|
||||
android:layout_width="fill_parent">
|
||||
<LinearLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent">
|
||||
|
||||
<TextView android:id="@+id/info_text"
|
||||
android:background="#BBFFFFFF"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:padding="5dip"
|
||||
android:textColor="#FF000000" />
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
</RelativeLayout>
|
|
@ -0,0 +1,84 @@
|
|||
#
|
||||
# Copyright (c) 2014 Dorian Pula <dorian.pula@amber-penguin-software.ca>
|
||||
#
|
||||
# justCheckers is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation, either version 3 of the License,
|
||||
# or (at your option) any later version.
|
||||
#
|
||||
# justCheckers is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with justCheckers. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Please share and enjoy!
|
||||
#
|
||||
|
||||
import codecs
|
||||
|
||||
import markdown
|
||||
from PySide import QtGui
|
||||
from PySide import QtWebKit
|
||||
|
||||
from justcheckers.ui import util
|
||||
|
||||
|
||||
class InfoView(QtGui.QWidget):
|
||||
"""Info viewer for the game's license, etc."""
|
||||
|
||||
# TODO Setup functional testing with PySide.QtTest
|
||||
|
||||
def __init__(self):
|
||||
super(InfoView, self).__init__()
|
||||
self.setup_components()
|
||||
|
||||
def setup_components(self):
|
||||
|
||||
self.info_viewer = QtWebKit.QWebView(self)
|
||||
about_html = self.generate_html_from_markdown('readme.txt')
|
||||
self.info_viewer.setHtml(about_html)
|
||||
|
||||
exit_button = QtGui.QPushButton('Back to Menu', self)
|
||||
exit_button.setFixedHeight(50)
|
||||
exit_button.clicked.connect(self.switch_to_menu_view)
|
||||
|
||||
credits_button = QtGui.QPushButton('Credits', self)
|
||||
credits_button.setFixedHeight(50)
|
||||
credits_button.clicked.connect(self.display_about_info)
|
||||
|
||||
license_button = QtGui.QPushButton('License', self)
|
||||
license_button.setFixedHeight(50)
|
||||
license_button.clicked.connect(self.display_license_info)
|
||||
|
||||
widget_layout = QtGui.QVBoxLayout(self)
|
||||
widget_layout.addWidget(self.info_viewer)
|
||||
|
||||
button_row = QtGui.QHBoxLayout(self)
|
||||
button_row.addWidget(exit_button)
|
||||
button_row.addWidget(credits_button)
|
||||
button_row.addWidget(license_button)
|
||||
|
||||
widget_layout.addLayout(button_row)
|
||||
|
||||
self.setLayout(widget_layout)
|
||||
|
||||
def switch_to_menu_view(self):
|
||||
self.parentWidget().setCurrentIndex(0)
|
||||
|
||||
def display_about_info(self):
|
||||
about_html = self.generate_html_from_markdown('readme.txt')
|
||||
self.info_viewer.setHtml(about_html)
|
||||
|
||||
def display_license_info(self):
|
||||
license_html = self.generate_html_from_markdown('gpl_3_license.txt')
|
||||
self.info_viewer.setHtml(license_html)
|
||||
|
||||
def generate_html_from_markdown(self, filename):
|
||||
file_path = util.path_to_asset(filename, asset_type=util.TEXT_ASSETS)
|
||||
with codecs.open(file_path, mode='r', encoding='utf-8') as markdown_file:
|
||||
text = markdown_file.read()
|
||||
return markdown.markdown(text)
|
||||
|
|
@ -40,7 +40,9 @@ class MainMenuView(QtGui.QWidget):
|
|||
self.open_game = self.create_menu_button('&Open Game')
|
||||
self.save_game = self.create_menu_button('&Save Game')
|
||||
|
||||
self.about_game = self.create_menu_button('About Game')
|
||||
self.about_game = self.create_menu_button('About Game', enabled=True)
|
||||
self.about_game.clicked.connect(self.switch_to_about_view)
|
||||
|
||||
# TODO Add links to site and display license inside about game widget.
|
||||
self.settings = self.create_menu_button('Settings')
|
||||
self.exit_button = self.create_menu_button('Exit', enabled=True)
|
||||
|
@ -80,3 +82,6 @@ class MainMenuView(QtGui.QWidget):
|
|||
def exit_app():
|
||||
"""Exits the application."""
|
||||
QtCore.QCoreApplication.instance().exit()
|
||||
|
||||
def switch_to_about_view(self):
|
||||
self.parentWidget().setCurrentIndex(1)
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">justCheckers</string>
|
||||
<string name="app_version">0.2-alpha</string>
|
||||
<string name="project_website">http://justcheckers.org/</string>
|
||||
<string-array name="checkers_variants">
|
||||
<item>American/Standard</item>
|
||||
<item>European</item>
|
||||
<item>Canadian</item>
|
||||
</string-array>
|
||||
</resources>
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
from PySide import QtGui
|
||||
|
||||
from justcheckers.ui.info_view import InfoView
|
||||
from justcheckers.ui.menu_view import MainMenuView
|
||||
from justcheckers.ui import util
|
||||
|
||||
|
@ -48,6 +49,7 @@ class DesktopGameWindow(QtGui.QMainWindow):
|
|||
"""Setup the components that make up the widget."""
|
||||
self.view_stack = QtGui.QStackedWidget()
|
||||
self.view_stack.addWidget(MainMenuView())
|
||||
self.view_stack.addWidget(InfoView())
|
||||
self.setCentralWidget(self.view_stack)
|
||||
|
||||
def center(self):
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
# User interface
|
||||
PySide==1.2.2
|
||||
Markdown==2.4.1
|
||||
|
||||
# Core logic
|
||||
enum34==0.9.19
|
||||
|
|
Loading…
Reference in New Issue