Update selfcheck, add about fragment

This commit is contained in:
Marvin W 2016-01-22 04:33:10 +01:00
parent f34d87bcc2
commit f0e7d6b1c8
8 changed files with 362 additions and 93 deletions

View File

@ -27,7 +27,7 @@ apply plugin: 'com.android.library'
String getMyVersionName() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags', '--always'
commandLine 'git', 'describe', '--tags', '--always', '--dirty'
standardOutput = stdout
}
return stdout.toString().trim()

View File

@ -1,65 +0,0 @@
/*
* Copyright 2013-2016 microG Project Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.microg.tools.selfcheck;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import org.microg.tools.ui.R;
import java.util.ArrayList;
import java.util.List;
public abstract class AbstractSelfCheckActivity extends AppCompatActivity implements SelfCheckGroup.ResultCollector {
protected abstract void prepareSelfCheckList(List<SelfCheckGroup> checks);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.self_check);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
List<SelfCheckGroup> selfCheckGroupList = new ArrayList<SelfCheckGroup>();
prepareSelfCheckList(selfCheckGroupList);
for (SelfCheckGroup group : selfCheckGroupList) {
group.doChecks(this, this);
}
}
public void addResult(String name, SelfCheckGroup.Result result, String resolution) {
if (result == null) return;
ViewGroup root = (ViewGroup) findViewById(R.id.self_check_root);
View resultEntry = LayoutInflater.from(this).inflate(R.layout.self_check_entry, root, false);
((TextView) resultEntry.findViewById(R.id.self_check_name)).setText(name);
if (result == SelfCheckGroup.Result.Positive) {
((ImageView) resultEntry.findViewById(R.id.self_check_result)).setImageResource(android.R.drawable.presence_online);
} else {
((TextView) resultEntry.findViewById(R.id.self_check_resolution)).setText(resolution);
((ImageView) resultEntry.findViewById(R.id.self_check_result))
.setImageResource(result == SelfCheckGroup.Result.Negative ? android.R.drawable.presence_busy : android.R.drawable.presence_invisible);
}
root.addView(resultEntry);
}
}

View File

@ -0,0 +1,130 @@
/*
* Copyright 2013-2016 microG Project Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.microg.tools.ui;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.*;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public abstract class AbstractAboutFragment extends Fragment {
protected abstract void collectLibraries(List<Library> libraries);
protected Drawable getIcon() {
try {
PackageManager pm = getContext().getPackageManager();
Drawable icon = pm.getPackageInfo(getContext().getPackageName(), 0).applicationInfo.loadIcon(pm);
if (icon == null) return getContext().getDrawable(android.R.drawable.ic_dialog_alert);
return icon;
} catch (PackageManager.NameNotFoundException e) {
// Never happens, self package always exists!
throw new RuntimeException(e);
}
}
protected String getAppName() {
try {
PackageManager pm = getContext().getPackageManager();
CharSequence label = pm.getPackageInfo(getContext().getPackageName(), 0).applicationInfo.loadLabel(pm);
if (TextUtils.isEmpty(label)) return getContext().getPackageName();
return label.toString();
} catch (PackageManager.NameNotFoundException e) {
// Never happens, self package always exists!
throw new RuntimeException(e);
}
}
protected String getLibVersion(String packageName) {
try {
String versionName = (String) Class.forName(packageName + ".BuildConfig").getField("VERSION_NAME").get(null);
if (TextUtils.isEmpty(versionName)) return "";
return versionName;
} catch (Exception e) {
return "";
}
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View aboutRoot = inflater.inflate(R.layout.about_root, container, false);
((ImageView) aboutRoot.findViewById(android.R.id.icon)).setImageDrawable(getIcon());
((TextView) aboutRoot.findViewById(android.R.id.title)).setText(getAppName());
((TextView) aboutRoot.findViewById(R.id.about_version)).setText("Version " + getLibVersion(getContext().getPackageName()));
List<Library> libraries = new ArrayList<Library>();
libraries.add(new Library("org.microg.tools.ui", "microG UI Tools", "Apache License 2.0, Copyright (c) microG Team"));
collectLibraries(libraries);
Collections.sort(libraries);
((ListView) aboutRoot.findViewById(android.R.id.list)).setAdapter(new LibraryAdapter(getContext(), libraries.toArray(new Library[libraries.size()])));
return aboutRoot;
}
private class LibraryAdapter extends ArrayAdapter<Library> {
public LibraryAdapter(Context context, Library[] libraries) {
super(context, android.R.layout.simple_list_item_2, android.R.id.text1, libraries);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
((TextView) v.findViewById(android.R.id.text1)).setText(getItem(position).name + " " + getLibVersion(getItem(position).packageName));
((TextView) v.findViewById(android.R.id.text2)).setText(getItem(position).copyright);
return v;
}
}
protected static class Library implements Comparable<Library> {
private final String packageName;
private final String name;
private final String copyright;
public Library(String packageName, String name, String copyright) {
this.packageName = packageName;
this.name = name;
this.copyright = copyright;
}
@Override
public String toString() {
return name + ", " + copyright;
}
@Override
public int compareTo(Library another) {
return name.toLowerCase().compareTo(another.name.toLowerCase());
}
}
}

View File

@ -0,0 +1,97 @@
/*
* Copyright 2013-2016 microG Project Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.microg.tools.ui;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
import org.microg.tools.selfcheck.SelfCheckGroup;
import java.util.ArrayList;
import java.util.List;
import static android.view.View.GONE;
import static android.view.View.INVISIBLE;
import static org.microg.tools.selfcheck.SelfCheckGroup.Result.Positive;
import static org.microg.tools.selfcheck.SelfCheckGroup.Result.Unknown;
public abstract class AbstractSelfCheckFragment extends Fragment {
protected abstract void prepareSelfCheckList(List<SelfCheckGroup> checks);
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View scrollRoot = inflater.inflate(R.layout.self_check, container, false);
List<SelfCheckGroup> selfCheckGroupList = new ArrayList<SelfCheckGroup>();
prepareSelfCheckList(selfCheckGroupList);
ViewGroup root = (ViewGroup) scrollRoot.findViewById(R.id.self_check_root);
for (SelfCheckGroup group : selfCheckGroupList) {
View groupView = inflater.inflate(R.layout.self_check_group, root, false);
((TextView) groupView.findViewById(android.R.id.title)).setText(group.getGroupName(getContext()));
final ViewGroup viewGroup = (ViewGroup) groupView.findViewById(R.id.group_content);
group.doChecks(getContext(), new GroupResultCollector(viewGroup));
root.addView(groupView);
}
return scrollRoot;
}
private class GroupResultCollector implements SelfCheckGroup.ResultCollector {
private final ViewGroup viewGroup;
public GroupResultCollector(ViewGroup viewGroup) {
this.viewGroup = viewGroup;
}
@Override
public void addResult(final String name, final SelfCheckGroup.Result result, final String resolution) {
if (result == null || getActivity() == null) return;
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
View resultEntry = LayoutInflater.from(getContext()).inflate(R.layout.self_check_entry, viewGroup, false);
((TextView) resultEntry.findViewById(R.id.self_check_name)).setText(name);
resultEntry.findViewById(R.id.self_check_result).setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
if (result == Positive) {
((CheckBox) resultEntry.findViewById(R.id.self_check_result)).setChecked(true);
resultEntry.findViewById(R.id.self_check_resolution).setVisibility(GONE);
} else {
((TextView) resultEntry.findViewById(R.id.self_check_resolution)).setText(resolution);
if (result == Unknown) {
resultEntry.findViewById(R.id.self_check_result).setVisibility(INVISIBLE);
}
}
viewGroup.addView(resultEntry);
}
});
}
}
}

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2013-2016 microG Project Team
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="10dp"
android:src="@android:drawable/ic_dialog_alert"/>
<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="microG UI Demo"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textColor="?attr/colorAccent"/>
<TextView
android:id="@+id/about_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Version v0.1.0"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"/>
<TextView
android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dip"
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
android:paddingRight="?attr/listPreferredItemPaddingRight"
android:paddingTop="16dip"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:text="Included libraries"
android:textColor="?attr/colorAccent"/>
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
tools:listitem="@android:layout/simple_list_item_2"/>
</LinearLayout>

View File

@ -15,23 +15,16 @@
~ limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/toolbar"/>
<LinearLayout
android:id="@+id/self_check_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/self_check_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@ -16,31 +16,38 @@
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
android:gravity="center_vertical"
android:paddingBottom="5dp"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
android:paddingRight="?attr/listPreferredItemPaddingRight"
android:paddingStart="?android:attr/listPreferredItemPaddingStart">
<TextView
android:paddingTop="5dp"
android:id="@+id/self_check_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is the title of a check: "
android:textStyle="bold"/>
android:textAppearance="?attr/textAppearanceListItem"
android:textColor="?android:textColorPrimary"/>
<ImageView
<CheckBox
android:id="@+id/self_check_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/self_check_name"
android:layout_alignParentRight="true"
android:layout_alignRight="@id/self_check_name"
android:src="@android:drawable/presence_busy"/>
android:layout_centerVertical="true"
android:focusable="false"/>
<TextView
android:id="@+id/self_check_resolution"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/self_check_name"
android:layout_below="@id/self_check_name"
android:layout_toLeftOf="@id/self_check_result"
android:text="This is a way to solve the issue that check above failed. It can consist of multiple lines."/>
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="?android:textColorSecondary"/>
</RelativeLayout>

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2013-2016 microG Project Team
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dip"
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
android:paddingRight="?attr/listPreferredItemPaddingRight"
android:paddingTop="16dip"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="?attr/colorAccent"/>
<LinearLayout
android:id="@+id/group_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</LinearLayout>