From f0e7d6b1c806effee3f5040e5e8595e128c575e4 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Fri, 22 Jan 2016 04:33:10 +0100 Subject: [PATCH] Update selfcheck, add about fragment --- microg-ui-tools/build.gradle | 2 +- .../selfcheck/AbstractSelfCheckActivity.java | 65 --------- .../tools/ui/AbstractAboutFragment.java | 130 ++++++++++++++++++ .../tools/ui/AbstractSelfCheckFragment.java | 97 +++++++++++++ .../src/main/res/layout/about_root.xml | 67 +++++++++ .../src/main/res/layout/self_check.xml | 29 ++-- .../src/main/res/layout/self_check_entry.xml | 25 ++-- .../src/main/res/layout/self_check_group.xml | 40 ++++++ 8 files changed, 362 insertions(+), 93 deletions(-) delete mode 100644 microg-ui-tools/src/main/java/org/microg/tools/selfcheck/AbstractSelfCheckActivity.java create mode 100644 microg-ui-tools/src/main/java/org/microg/tools/ui/AbstractAboutFragment.java create mode 100644 microg-ui-tools/src/main/java/org/microg/tools/ui/AbstractSelfCheckFragment.java create mode 100644 microg-ui-tools/src/main/res/layout/about_root.xml create mode 100644 microg-ui-tools/src/main/res/layout/self_check_group.xml diff --git a/microg-ui-tools/build.gradle b/microg-ui-tools/build.gradle index 4cd39d2e..167a335e 100644 --- a/microg-ui-tools/build.gradle +++ b/microg-ui-tools/build.gradle @@ -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() diff --git a/microg-ui-tools/src/main/java/org/microg/tools/selfcheck/AbstractSelfCheckActivity.java b/microg-ui-tools/src/main/java/org/microg/tools/selfcheck/AbstractSelfCheckActivity.java deleted file mode 100644 index 885acd36..00000000 --- a/microg-ui-tools/src/main/java/org/microg/tools/selfcheck/AbstractSelfCheckActivity.java +++ /dev/null @@ -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 checks); - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.self_check); - setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); - - List selfCheckGroupList = new ArrayList(); - 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); - } -} diff --git a/microg-ui-tools/src/main/java/org/microg/tools/ui/AbstractAboutFragment.java b/microg-ui-tools/src/main/java/org/microg/tools/ui/AbstractAboutFragment.java new file mode 100644 index 00000000..a149dee1 --- /dev/null +++ b/microg-ui-tools/src/main/java/org/microg/tools/ui/AbstractAboutFragment.java @@ -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 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 libraries = new ArrayList(); + 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 { + + 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 { + 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()); + } + } +} diff --git a/microg-ui-tools/src/main/java/org/microg/tools/ui/AbstractSelfCheckFragment.java b/microg-ui-tools/src/main/java/org/microg/tools/ui/AbstractSelfCheckFragment.java new file mode 100644 index 00000000..56bf9863 --- /dev/null +++ b/microg-ui-tools/src/main/java/org/microg/tools/ui/AbstractSelfCheckFragment.java @@ -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 checks); + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View scrollRoot = inflater.inflate(R.layout.self_check, container, false); + List selfCheckGroupList = new ArrayList(); + 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); + } + }); + + } + } +} diff --git a/microg-ui-tools/src/main/res/layout/about_root.xml b/microg-ui-tools/src/main/res/layout/about_root.xml new file mode 100644 index 00000000..1fe0c283 --- /dev/null +++ b/microg-ui-tools/src/main/res/layout/about_root.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/microg-ui-tools/src/main/res/layout/self_check.xml b/microg-ui-tools/src/main/res/layout/self_check.xml index b8594924..47092f97 100644 --- a/microg-ui-tools/src/main/res/layout/self_check.xml +++ b/microg-ui-tools/src/main/res/layout/self_check.xml @@ -15,23 +15,16 @@ ~ limitations under the License. --> - + - + - - - - - - - \ No newline at end of file + + \ No newline at end of file diff --git a/microg-ui-tools/src/main/res/layout/self_check_entry.xml b/microg-ui-tools/src/main/res/layout/self_check_entry.xml index b371debb..ec5ad8d2 100644 --- a/microg-ui-tools/src/main/res/layout/self_check_entry.xml +++ b/microg-ui-tools/src/main/res/layout/self_check_entry.xml @@ -16,31 +16,38 @@ --> + 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"> + android:textAppearance="?attr/textAppearanceListItem" + android:textColor="?android:textColorPrimary"/> - + android:layout_centerVertical="true" + android:focusable="false"/> + android:textAppearance="@style/TextAppearance.AppCompat.Body1" + android:textColor="?android:textColorSecondary"/> \ No newline at end of file diff --git a/microg-ui-tools/src/main/res/layout/self_check_group.xml b/microg-ui-tools/src/main/res/layout/self_check_group.xml new file mode 100644 index 00000000..62af9c7e --- /dev/null +++ b/microg-ui-tools/src/main/res/layout/self_check_group.xml @@ -0,0 +1,40 @@ + + + + + + + + + + \ No newline at end of file