Skip to content

Commit

Permalink
Fixes #4: Add an About Box.
Browse files Browse the repository at this point in the history
  • Loading branch information
justdave committed Jan 20, 2015
1 parent 0ae0d9d commit 555357c
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 0 deletions.
81 changes: 81 additions & 0 deletions app/src/main/java/net/justdave/mcstatus/AboutDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package net.justdave.mcstatus;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.app.Dialog;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.text.Html;
import android.text.util.Linkify;
import android.util.Log;
import android.graphics.Color;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class AboutDialog extends Dialog {
private static Context mContext = null;
private static final String TAG = AboutDialog.class.getSimpleName();

public AboutDialog(Context context) {
super(context);
mContext = context;
}

@Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.about);

PackageInfo p;
String version = "???";
int vCode = 0;
TextView tv = (TextView) findViewById(R.id.info_text);
tv.setText(Html.fromHtml(readRawTextFile(R.raw.about_info)));
tv.setLinkTextColor(Color.BLUE);
Linkify.addLinks(tv, Linkify.ALL);
TextView ver = (TextView) findViewById(R.id.version_string);
Context aContext = mContext.getApplicationContext();
try {
p = aContext.getPackageManager().getPackageInfo(aContext.getPackageName(), 0);
version = p.versionName;
vCode = p.versionCode;
} catch (NameNotFoundException e) {
Log.i(TAG, "Failed to retrieve package name");
e.printStackTrace();
}
ver.setText(aContext.getResources().getString(R.string.about_version, version, vCode));
Button button = (Button) findViewById(R.id.about_ok_button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dismiss();
}
});

}

public static String readRawTextFile(int id) {

InputStream inputStream = mContext.getResources().openRawResource(id);

InputStreamReader in = new InputStreamReader(inputStream);
BufferedReader buf = new BufferedReader(in);

String line;

StringBuilder text = new StringBuilder();
try {
while ((line = buf.readLine()) != null)
text.append(line);
} catch (IOException e) {
return null;
}

return text.toString();
}

}
5 changes: 5 additions & 0 deletions app/src/main/java/net/justdave/mcstatus/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ public boolean onPrepareOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem menuitem) {
switch (menuitem.getItemId()) {
case R.id.action_about:
AboutDialog about = new AboutDialog(this);
about.setTitle(getResources().getIdentifier("action_about", "string", getPackageName()));
about.show();
break;
case R.id.action_addserver:
View promptsView = LayoutInflater.from(this).inflate(
R.layout.addserver_dialog, null);
Expand Down
73 changes: 73 additions & 0 deletions app/src/main/res/layout/about.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="vertical" >

<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:stretchColumns="*" >

<TableRow>

<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_gravity="left|center"
android:contentDescription="@string/icon"
android:src="@drawable/meterblocks" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/app_name"
android:textSize="18sp" />

<TextView
android:id="@+id/version_string"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="18sp" />
</LinearLayout>
</TableRow>

<TableRow>

<TextView
android:id="@+id/info_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dip"
android:layout_span="2"
android:textAlignment="center"
android:textColor="#444444"
android:textSize="12sp"
android:textStyle="italic" />
</TableRow>

<TableRow>

<Button
android:id="@+id/about_ok_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="8dip"
android:layout_span="2"
android:gravity="center"
android:text="@string/ok" />
</TableRow>
</TableLayout>

</ScrollView>
5 changes: 5 additions & 0 deletions app/src/main/res/menu/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@
android:orderInCategory="101"
android:showAsAction="ifRoom"
android:title="@string/action_addserver"/>
<item
android:id="@+id/action_about"
android:orderInCategory="102"
android:showAsAction="never"
android:title="@string/action_about"/>

</menu>
6 changes: 6 additions & 0 deletions app/src/main/res/raw/about_info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
To request new features or file bug reports, please visit<br>
<b>https://github.com/justdave/MCStatus</b><br>
<br>
Copyright 2014-2015 David D. Miller<br>
<br>
Licensed under the MIT License<br>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
<resources>

<string name="app_name">MCStatus</string>
<string name="about_version">Version %1$s (Build %2$d)</string>
<string name="action_refresh">Refresh</string>
<string name="action_addserver">Add Server</string>
<string name="action_deleteserver">Delete Server(s)</string>
<string name="action_editserver">Edit Server</string>
<string name="action_about">About This App</string>
<string name="icon_description">Server FavIcon</string>
<string name="edit_server_name">Enter Server Name:</string>
<string name="empty_left">Please touch the</string>
Expand All @@ -14,5 +16,7 @@
<string name="edit_server_address">Enter Server Address:</string>
<string name="edit_server_address_hint">serveraddress[:port]</string>
<string name="userlist_header">Users online:</string>
<string name="icon">Icon</string>
<string name="ok">OK</string>

</resources>

0 comments on commit 555357c

Please sign in to comment.