;
13 | }
14 | -keepclassmembers,allowoptimization enum * {
15 | public static **[] values(); public static ** valueOf(java.lang.String);
16 | }
17 | -keepclassmembers class * implements java.io.Serializable {
18 | static final long serialVersionUID;
19 | private static final java.io.ObjectStreamField[] serialPersistentFields;
20 | private void writeObject(java.io.ObjectOutputStream);
21 | private void readObject(java.io.ObjectInputStream);
22 | java.lang.Object writeReplace();
23 | java.lang.Object readResolve();
24 | }
--------------------------------------------------------------------------------
/versioninfo/src/main/java/saschpe/android/versioninfo/VersionInfoUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Sascha Peilicke
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package saschpe.android.versioninfo;
18 |
19 | import android.content.Context;
20 |
21 | import java.util.GregorianCalendar;
22 |
23 | public final class VersionInfoUtils {
24 | private final static GregorianCalendar calendar;
25 |
26 | static {
27 | calendar = new GregorianCalendar(); // Needed for the 4-digit year
28 | }
29 |
30 | private VersionInfoUtils() {
31 | // No instance
32 | }
33 |
34 | /**
35 | * Returns the formatted version. To be used outside the dialog fragment, for instance
36 | * in activity or preference titles.
37 | *
38 | * @param context The almighty context
39 | * @param version The app's version
40 | * @return Version string
41 | */
42 | public static String getFormattedVersion(final Context context, final String version) {
43 | return getFormattedVersion(context, context.getPackageName(), version);
44 | }
45 |
46 | /**
47 | * Returns the formatted version. To be used outside the dialog fragment, for instance
48 | * in activity or preference titles.
49 | *
50 | * @param context The almighty context
51 | * @param packageName The app's package name
52 | * @param version The app's version
53 | * @return Version string
54 | */
55 | public static String getFormattedVersion(final Context context, final String packageName, final String version) {
56 | int versionInfoStringId = context.getResources().getIdentifier("version_template", "string", packageName);
57 | return context.getString(versionInfoStringId, version);
58 | }
59 |
60 | /**
61 | * Returns the formatted copyright. To be used outside the dialog fragment, for instance
62 | * in activity or preference titles.
63 | *
64 | * @param context The almighty context
65 | * @param owner The app onwer.
66 | * @return Copyright string
67 | */
68 | public static String getFormattedCopyright(final Context context, final String owner) {
69 | return getFormattedCopyright(context, context.getPackageName(), owner);
70 | }
71 |
72 | /**
73 | * Returns the formatted copyright. To be used outside the dialog fragment, for instance
74 | * in activity or preference titles.
75 | *
76 | * @param context The almighty context
77 | * @param packageName The app's package name
78 | * @param owner The app onwer.
79 | * @return Copyright string
80 | */
81 | public static String getFormattedCopyright(final Context context, final String packageName, final String owner) {
82 | int copyrightStringId = context.getResources().getIdentifier("copyright_template", "string", packageName);
83 | return context.getString(copyrightStringId, calendar, owner);
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/versioninfo/src/main/java/saschpe/android/versioninfo/widget/VersionInfoDialogFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Sascha Peilicke
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package saschpe.android.versioninfo.widget;
18 |
19 | import android.app.Dialog;
20 | import android.content.Context;
21 | import android.os.Bundle;
22 | import android.view.LayoutInflater;
23 | import android.view.View;
24 | import android.view.ViewGroup;
25 | import android.view.Window;
26 | import android.widget.ImageView;
27 | import android.widget.TextView;
28 |
29 | import androidx.annotation.NonNull;
30 | import androidx.fragment.app.DialogFragment;
31 | import saschpe.android.versioninfo.VersionInfoUtils;
32 |
33 | /**
34 | * Dialog fragment to display app name and version.
35 | */
36 | public final class VersionInfoDialogFragment extends DialogFragment {
37 | private static final String ARG_TITLE = "title";
38 | private static final String ARG_VERSION = "version";
39 | private static final String ARG_OWNER = "owner";
40 | private static final String ARG_IMAGE_ID = "image";
41 |
42 | /**
43 | * Factory method to create a new VersionInfoDialogFragment instance.
44 | *
45 | * @param title The title to display, like @string/app_name
46 | * @param version The version to display, like @see{BuildConfig.VERSION_NAME}
47 | * @param copyrightOwner The copyright owner, like "Sascha Peilicke"
48 | * @param imageId ID of a image resource to display, like e.g."@mipmap/ic_launcher"
49 | * @return A new instance of VersionInfoDialogFragment.
50 | */
51 | public static VersionInfoDialogFragment newInstance(final String title, final String version, final String copyrightOwner, final int imageId) {
52 | VersionInfoDialogFragment fragment = new VersionInfoDialogFragment();
53 | Bundle args = new Bundle();
54 | args.putString(ARG_TITLE, title);
55 | args.putString(ARG_VERSION, version);
56 | args.putString(ARG_OWNER, copyrightOwner);
57 | args.putInt(ARG_IMAGE_ID, imageId);
58 | fragment.setArguments(args);
59 | return fragment;
60 | }
61 |
62 | private String title;
63 | private String version;
64 | private String owner;
65 | private int imageId;
66 | private String packageName;
67 |
68 | public VersionInfoDialogFragment() {
69 | }
70 |
71 | @Override
72 | public void onCreate(Bundle savedInstanceState) {
73 | super.onCreate(savedInstanceState);
74 | Bundle args = getArguments();
75 | if (args != null) {
76 | title = args.getString(ARG_TITLE);
77 | version = args.getString(ARG_VERSION);
78 | owner = args.getString(ARG_OWNER);
79 | imageId = args.getInt(ARG_IMAGE_ID);
80 | }
81 | }
82 |
83 | @Override
84 | public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
85 | //noinspection ConstantConditions
86 | packageName = getContext().getPackageName();
87 |
88 | // R class is not generated for libraries, thus we have to go the long road...
89 | // See https://sites.google.com/a/android.com/tools/recent/dealingwithdependenciesinandroidprojects
90 | int fragmentId = getResources().getIdentifier("fragment_version_info", "layout", packageName);
91 | View view = inflater.inflate(fragmentId, container, false);
92 |
93 | int imageViewId = getResources().getIdentifier("image", "id", packageName);
94 | ImageView imageView = view.findViewById(imageViewId);
95 | imageView.setImageResource(imageId);
96 | imageView.setContentDescription(title);
97 |
98 | int titleViewId = getResources().getIdentifier("title", "id", packageName);
99 | TextView titleView = view.findViewById(titleViewId);
100 | titleView.setText(title);
101 |
102 | int versionViewId = getResources().getIdentifier("version", "id", packageName);
103 | TextView versionView = view.findViewById(versionViewId);
104 | versionView.setText(getFormattedVersion());
105 |
106 | int copyrightViewId = getResources().getIdentifier("my_copyright", "id", packageName);
107 | TextView copyrightView = view.findViewById(copyrightViewId);
108 | copyrightView.setText(getFormattedCopyright());
109 |
110 | return view;
111 | }
112 |
113 | /**
114 | * The system calls this only when creating the layout in a dialog.
115 | * */
116 | @NonNull
117 | @Override
118 | public Dialog onCreateDialog(Bundle savedInstanceState) {
119 | Dialog dialog = super.onCreateDialog(savedInstanceState);
120 | dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
121 | dialog.setCanceledOnTouchOutside(true);
122 | return dialog;
123 | }
124 |
125 | /**
126 | * Returns the formatted version. To be used outside the dialog fragment, for instance
127 | * in activity or preference titles.
128 | *
129 | * Only works if the fragment is attached to an {@link android.app.Activity}.
130 | * Otherwise use {@link VersionInfoUtils#getFormattedVersion(Context, String, String)}.
131 | *
132 | * @return Version string
133 | */
134 | public String getFormattedVersion() {
135 | if (isAdded()) {
136 | //noinspection ConstantConditions isAdded() already checked
137 | return VersionInfoUtils.getFormattedVersion(getContext(), packageName, version);
138 | }
139 | return null;
140 | }
141 |
142 | /**
143 | * Returns the formatted copyright. To be used outside the dialog fragment, for instance
144 | * in activity or preference titles.
145 | *
146 | * Only works if the fragment is attached to an {@link android.app.Activity}.
147 | * Otherwise use {@link VersionInfoUtils#getFormattedCopyright(Context, String, String)}.
148 | *
149 | * @return Copyright string
150 | */
151 | public String getFormattedCopyright() {
152 | if (isAdded()) {
153 | //noinspection ConstantConditions isAdded() already checked
154 | return VersionInfoUtils.getFormattedCopyright(getContext(), packageName, owner);
155 | }
156 | return null;
157 | }
158 | }
--------------------------------------------------------------------------------
/versioninfo/src/main/res/layout/fragment_version_info.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
28 |
29 |
36 |
37 |
41 |
42 |
47 |
48 |
54 |
55 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/versioninfo/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 | 64dp
21 |
22 |
23 |
--------------------------------------------------------------------------------
/versioninfo/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 | 16dp
21 | 16dp
22 |
23 |
--------------------------------------------------------------------------------
/versioninfo/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
20 |
21 |
22 | Version: %1$s
23 | \u00A9 %1$tY %2$s
24 |
25 |
26 |
--------------------------------------------------------------------------------