Skip to content

Commit a2af990

Browse files
niccokunzmanndbrgn
authored andcommittedApr 15, 2023
Add information about the app to settings
- Version information - License - Repository URL and button to visit it
1 parent 4a63bd8 commit a2af990

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package io.spaceapi.community.myhackerspace;
2+
3+
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
4+
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
5+
6+
import android.Manifest;
7+
import android.content.Context;
8+
import android.content.Intent;
9+
import android.net.Uri;
10+
import android.util.AttributeSet;
11+
import android.view.LayoutInflater;
12+
import android.view.View;
13+
import android.view.ViewGroup;
14+
import android.widget.Button;
15+
import android.widget.LinearLayout;
16+
import android.widget.TextView;
17+
18+
import androidx.annotation.Nullable;
19+
20+
public class AboutLayout extends LinearLayout {
21+
22+
public AboutLayout(Context context) {
23+
super(context);
24+
}
25+
26+
public AboutLayout(Context context, @Nullable AttributeSet attrs) {
27+
super(context, attrs);
28+
}
29+
30+
public AboutLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
31+
super(context, attrs, defStyleAttr);
32+
}
33+
34+
public AboutLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
35+
super(context, attrs, defStyleAttr, defStyleRes);
36+
}
37+
38+
public void init() {
39+
Button openRepoButton = findViewById(R.id.about_open_repo_button);
40+
openRepoButton.setOnClickListener(new OnClickListener() {
41+
@Override
42+
public void onClick(View v) {
43+
TextView repository = (TextView)findViewById(R.id.about_repository);
44+
String url = (String) repository.getText();
45+
openWebPage(url);
46+
}
47+
});
48+
TextView version = findViewById(R.id.about_version_text);
49+
version.setText(BuildConfig.VERSION_NAME + " (" + Integer.toString(BuildConfig.VERSION_CODE) + ")");
50+
}
51+
52+
public static AboutLayout create(Context context) {
53+
// use xml layout, see https://stackoverflow.com/a/13889257
54+
LayoutInflater layoutInflater = LayoutInflater.from(context);
55+
AboutLayout about = (AboutLayout) layoutInflater.inflate(R.layout.about, null, false);
56+
about.init();
57+
return about;
58+
}
59+
60+
public void openWebPage(String url) {
61+
// from https://stackoverflow.com/a/43981160
62+
Uri webpage = Uri.parse(url);
63+
64+
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
65+
66+
if (intent.resolveActivity(getContext().getPackageManager()) != null) {
67+
getContext().startActivity(intent);
68+
}else{
69+
//Page not found
70+
}
71+
}
72+
73+
}

‎app/src/main/java/io/spaceapi/community/myhackerspace/Prefs.java

+6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
*/
66
package io.spaceapi.community.myhackerspace;
77

8+
import static android.view.ViewGroup.LayoutParams.*;
9+
810
import android.content.SharedPreferences;
911
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
1012
import android.os.Bundle;
1113
import android.preference.PreferenceActivity;
1214
import android.preference.PreferenceScreen;
15+
import android.view.LayoutInflater;
16+
import android.view.ViewGroup;
17+
import android.widget.LinearLayout;
1318

1419
public class Prefs extends PreferenceActivity implements
1520
OnSharedPreferenceChangeListener {
@@ -31,6 +36,7 @@ public class Prefs extends PreferenceActivity implements
3136
public void onCreate(Bundle savedInstanceState) {
3237
super.onCreate(savedInstanceState);
3338
addPreferencesFromResource(R.xml.preferences);
39+
this.getListView().addFooterView(AboutLayout.create(this)); // tried addContentView
3440
PreferenceScreen ps = getPreferenceScreen();
3541
ps.getSharedPreferences()
3642
.registerOnSharedPreferenceChangeListener(this);

‎app/src/main/res/layout/about.xml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<io.spaceapi.community.myhackerspace.AboutLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical">
6+
7+
<LinearLayout
8+
android:layout_width="match_parent"
9+
android:layout_height="wrap_content"
10+
android:orientation="horizontal">
11+
12+
<TextView
13+
android:id="@+id/about_version_title"
14+
android:layout_width="wrap_content"
15+
android:layout_height="wrap_content"
16+
android:text="@string/about_version_title" />
17+
18+
<TextView
19+
android:id="@+id/about_version_text"
20+
android:layout_width="0dp"
21+
android:layout_height="wrap_content"
22+
android:layout_weight="1"
23+
android:text="1.0.0" />
24+
</LinearLayout>
25+
26+
<LinearLayout
27+
android:layout_width="match_parent"
28+
android:layout_height="wrap_content"
29+
android:orientation="horizontal">
30+
31+
<TextView
32+
android:id="@+id/about_license_title"
33+
android:layout_width="wrap_content"
34+
android:layout_height="wrap_content"
35+
android:text="@string/about_license_title" />
36+
37+
<TextView
38+
android:id="@+id/about_license_text"
39+
android:layout_width="0dp"
40+
android:layout_height="wrap_content"
41+
android:layout_weight="1"
42+
android:text="@string/about_license_text" />
43+
</LinearLayout>
44+
45+
<TextView
46+
android:id="@+id/about_repository"
47+
android:layout_width="match_parent"
48+
android:layout_height="wrap_content"
49+
android:text="@string/about_repository_url" />
50+
51+
<Button
52+
android:id="@+id/about_open_repo_button"
53+
android:layout_width="match_parent"
54+
android:layout_height="wrap_content"
55+
android:text="@string/about_visit_repository" />
56+
57+
</io.spaceapi.community.myhackerspace.AboutLayout>

‎app/src/main/res/values/strings.xml

+8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Licensed under GNU's GPL 3, see README
4444
<string name="prefs_transparent_summary">Widget\'s background will be transparent instead of gray</string>
4545
<string name="prefs_text_title">Show status text</string>
4646
<string name="prefs_text_summary">Add a text with the status under the widget</string>
47+
<string name="prefs_about_title">About This App</string>
4748

4849
<string name="api_status">Status</string>
4950
<string name="api_lastchange">Last change: </string>
@@ -88,4 +89,11 @@ Licensed under GNU's GPL 3, see README
8889
<string name="api_sensor_radiation">Radiation</string>
8990
<string name="api_sensor_total_member_count">Member Count</string>
9091
<string name="api_sensor_account_balance">Account Balance</string>
92+
93+
94+
<string name="about_version_title">App Version:</string>
95+
<string name="about_license_title">License:</string>
96+
<string name="about_license_text">GNU GENERAL PUBLIC LICENSE Version 3</string>
97+
<string name="about_visit_repository">Visit Repository</string>
98+
<string name="about_repository_url" translatable="false">https://github.com/spaceapi-community/my-hackerspace</string>
9199
</resources>

‎app/src/main/res/xml/preferences.xml

+3
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@
4343
android:defaultValue="30"
4444
android:inputType="number" />
4545

46+
<PreferenceCategory android:title="@string/prefs_about_title">
47+
</PreferenceCategory>
48+
4649
</PreferenceScreen>

0 commit comments

Comments
 (0)
Please sign in to comment.