-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathAboutActivity.java
More file actions
299 lines (265 loc) · 12.3 KB
/
Copy pathAboutActivity.java
File metadata and controls
299 lines (265 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
* Copyright (C) 2014-2026 Arpit Khurana <arpitkh96@gmail.com>, Vishal Nehra <vishalmeham2@gmail.com>,
* Emmanuel Messulam<emmanuelbendavid@gmail.com>, Raymond Lai <airwave209gt at gmail.com> and Contributors.
*
* This file is part of Amaze File Manager.
*
* Amaze File Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.amaze.filemanager.ui.activities;
import static com.amaze.filemanager.utils.Utils.openURL;
import java.io.File;
import java.util.ArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.amaze.filemanager.LogHelper;
import com.amaze.filemanager.R;
import com.amaze.filemanager.adapters.ContributorAdapter;
import com.amaze.filemanager.adapters.LanguageAdapter;
import com.amaze.filemanager.ui.activities.superclasses.ThemedActivity;
import com.amaze.filemanager.ui.dialogs.share.ShareTask;
import com.amaze.filemanager.ui.theme.AppTheme;
import com.amaze.filemanager.utils.Billing;
import com.amaze.filemanager.utils.DataUtils;
import com.amaze.filemanager.utils.Utils;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.mikepenz.aboutlibraries.Libs;
import com.mikepenz.aboutlibraries.LibsBuilder;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.FileProvider;
import androidx.core.content.res.ResourcesCompat;
import androidx.palette.graphics.Palette;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
/** Created by vishal on 27/7/16. */
public class AboutActivity extends ThemedActivity implements View.OnClickListener {
private final Logger LOG = LoggerFactory.getLogger(AboutActivity.class);
private static final int HEADER_HEIGHT = 1024;
private static final int HEADER_WIDTH = 500;
private LanguageAdapter languageAdapter;
private ContributorAdapter contributorAdapter;
private RecyclerView recyclerView;
private RecyclerView contributorRecyclerView;
private AppBarLayout mAppBarLayout;
private CollapsingToolbarLayout mCollapsingToolbarLayout;
private AppCompatTextView mTitleTextView;
private View mAuthorsDivider, mDeveloper1Divider, mDeveloper2Divider;
private Billing billing;
private static final String URL_AUTHOR1_GITHUB = "https://github.com/arpitkh96";
private static final String URL_AUTHOR2_GITHUB = "https://github.com/VishalNehra";
private static final String URL_DEVELOPER1_GITHUB = "https://github.com/EmmanuelMess";
private static final String URL_DEVELOPER2_GITHUB = "https://github.com/TranceLove";
private static final String URL_DEVELOPER3_GITHUB = "https://github.com/VishnuSanal";
private static final String URL_REPO_CHANGELOG =
"https://github.com/TeamAmaze/AmazeFileManager/commits/master";
private static final String URL_REPO = "https://github.com/TeamAmaze/AmazeFileManager";
private static final String URL_REPO_ISSUES =
"https://github.com/TeamAmaze/AmazeFileManager/issues";
private static final String URL_REPO_TRANSLATE =
"https://www.transifex.com/amaze/amaze-file-manager/";
private static final String URL_REPO_XDA =
"http://forum.xda-developers.com/android/apps-games/app-amaze-file-managermaterial-theme-t2937314";
private static final String URL_REPO_RATE = "market://details?id=com.amaze.filemanager";
public static final String PACKAGE_AMAZE_UTILS = "com.amaze.fileutilities";
public static final String URL_AMAZE_UTILS = "market://details?id=" + PACKAGE_AMAZE_UTILS;
public static final String URL_AMAZE_UTILS_FDROID =
"https://f-droid.org/en/packages/" + PACKAGE_AMAZE_UTILS + "/";
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
if (getAppTheme().equals(AppTheme.DARK)) {
setTheme(R.style.aboutDark);
} else if (getAppTheme().equals(AppTheme.BLACK)) {
setTheme(R.style.aboutBlack);
} else {
setTheme(R.style.aboutLight);
}
}
setContentView(R.layout.activity_about);
recyclerView = findViewById(R.id.rvLanguage);
contributorRecyclerView = findViewById(R.id.rvContributors);
mAppBarLayout = findViewById(R.id.appBarLayout);
mCollapsingToolbarLayout = findViewById(R.id.collapsing_toolbar_layout);
mTitleTextView = findViewById(R.id.text_view_title);
mAuthorsDivider = findViewById(R.id.view_divider_authors);
mDeveloper1Divider = findViewById(R.id.view_divider_developers_1);
mDeveloper2Divider = findViewById(R.id.view_divider_developers_2);
mAppBarLayout.setLayoutParams(calculateHeaderViewParams());
Toolbar mToolbar = findViewById(R.id.toolBar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar()
.setHomeAsUpIndicator(
ResourcesCompat.getDrawable(
getResources(), com.afollestad.materialdialogs.R.drawable.md_nav_back, getTheme()));
getSupportActionBar().setDisplayShowTitleEnabled(false);
switchIcons();
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.about_header);
initAdapter();
// It will generate colors based on the image in an AsyncTask.
Palette.from(bitmap)
.generate(
palette -> {
int mutedColor =
palette.getMutedColor(Utils.getColor(AboutActivity.this, R.color.primary_blue));
int darkMutedColor =
palette.getDarkMutedColor(
Utils.getColor(AboutActivity.this, R.color.primary_blue));
mCollapsingToolbarLayout.setContentScrimColor(mutedColor);
mCollapsingToolbarLayout.setStatusBarScrimColor(darkMutedColor);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(darkMutedColor);
}
});
mAppBarLayout.addOnOffsetChangedListener(
(appBarLayout, verticalOffset) -> {
mTitleTextView.setAlpha(
Math.abs(verticalOffset / (float) appBarLayout.getTotalScrollRange()));
});
mAppBarLayout.setOnFocusChangeListener(
(v, hasFocus) -> {
mAppBarLayout.setExpanded(hasFocus, true);
});
}
private void initAdapter() {
languageAdapter = new LanguageAdapter(DataUtils.getLanguages(this));
recyclerView.setAdapter(languageAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
contributorAdapter = new ContributorAdapter(DataUtils.getContributors(this));
contributorRecyclerView.setAdapter(contributorAdapter);
contributorRecyclerView.setLayoutManager(new LinearLayoutManager(this));
}
/**
* Calculates aspect ratio for the Amaze header
*
* @return the layout params with new set of width and height attribute
*/
private CoordinatorLayout.LayoutParams calculateHeaderViewParams() {
// calculating cardview height as per the youtube video thumb aspect ratio
CoordinatorLayout.LayoutParams layoutParams =
(CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();
float vidAspectRatio = (float) HEADER_WIDTH / (float) HEADER_HEIGHT;
LOG.debug(vidAspectRatio + "");
int screenWidth = getResources().getDisplayMetrics().widthPixels;
float reqHeightAsPerAspectRatio = (float) screenWidth * vidAspectRatio;
LOG.debug(reqHeightAsPerAspectRatio + "");
LOG.debug("new width: " + screenWidth + " and height: " + reqHeightAsPerAspectRatio);
layoutParams.width = screenWidth;
layoutParams.height = (int) reqHeightAsPerAspectRatio;
return layoutParams;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
onBackPressed();
}
return super.onOptionsItemSelected(item);
}
/** Method switches icon resources as per current theme */
private void switchIcons() {
if (getAppTheme().equals(AppTheme.DARK) || getAppTheme().equals(AppTheme.BLACK)) {
// dark theme
mAuthorsDivider.setBackgroundColor(Utils.getColor(this, R.color.divider_dark_card));
mDeveloper1Divider.setBackgroundColor(Utils.getColor(this, R.color.divider_dark_card));
mDeveloper2Divider.setBackgroundColor(Utils.getColor(this, R.color.divider_dark_card));
}
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.relative_layout_source) {
openURL(URL_REPO, this);
} else if (v.getId() == R.id.relative_layout_issues) {
openURL(URL_REPO_ISSUES, this);
} else if (v.getId() == R.id.relative_layout_share_logs) {
try {
File logFile =
new File("/data/data/" + getApplicationContext().getPackageName() + "/cache/logs.txt");
Uri logUri =
FileProvider.getUriForFile(
getApplicationContext(), getApplicationContext().getPackageName(), logFile);
ArrayList<Uri> logUriList = new ArrayList<>();
logUriList.add(logUri);
new ShareTask(this, logUriList, this.getAppTheme(), getAccent()).execute("*/*");
} catch (Exception e) {
LOG.warn("failed to share logs", e);
}
} else if (v.getId() == R.id.click_layout_changelog) {
openURL(URL_REPO_CHANGELOG, this);
} else if (v.getId() == R.id.click_layout_licenses) {
LibsBuilder libsBuilder =
new LibsBuilder()
.withLibraries("apachemina") // Not auto-detected for some reason
.withActivityTitle(getString(R.string.libraries))
.withAboutIconShown(true)
.withAboutVersionShownName(true)
.withAboutVersionShownCode(false)
.withAboutDescription(getString(R.string.about_amaze))
.withAboutSpecial1(getString(R.string.license))
.withAboutSpecial1Description(getString(R.string.amaze_license))
.withLicenseShown(true);
switch (getAppTheme()) {
case LIGHT:
libsBuilder.withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR);
break;
case DARK:
libsBuilder.withActivityStyle(Libs.ActivityStyle.DARK);
break;
case BLACK:
libsBuilder.withActivityTheme(R.style.AboutLibrariesTheme_Black);
break;
default:
LogHelper.logOnProductionOrCrash("Incorrect value for switch");
}
libsBuilder.start(this);
} else if (v.getId() == R.id.text_view_author_1_github) {
openURL(URL_AUTHOR1_GITHUB, this);
} else if (v.getId() == R.id.text_view_author_2_github) {
openURL(URL_AUTHOR2_GITHUB, this);
} else if (v.getId() == R.id.text_view_developer_1_github) {
openURL(URL_DEVELOPER1_GITHUB, this);
} else if (v.getId() == R.id.text_view_developer_2_github) {
openURL(URL_DEVELOPER2_GITHUB, this);
} else if (v.getId() == R.id.text_view_developer_3_github) {
openURL(URL_DEVELOPER3_GITHUB, this);
} else if (v.getId() == R.id.relative_layout_translate) {
openURL(URL_REPO_TRANSLATE, this);
} else if (v.getId() == R.id.relative_layout_xda) {
openURL(URL_REPO_XDA, this);
} else if (v.getId() == R.id.relative_layout_rate) {
openURL(URL_REPO_RATE, this);
} else if (v.getId() == R.id.relative_layout_donate) {
billing = new Billing(this);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
LOG.debug("Destroying the manager.");
if (billing != null) {
billing.destroyBillingInstance();
}
}
}