Skip to content

Commit 1051f49

Browse files
committedJul 28, 2016
[SVN] r2025 Inventory in /Libraries/twister-lib-android/
[ADD] Make About's app info clickable and open relevant activities
1 parent 70cf617 commit 1051f49

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed
 

‎libs/twister-lib-android/src/main/java/net/twisterrob/android/activity/AboutActivity.java

+48-8
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
import android.graphics.drawable.Drawable;
1313
import android.net.Uri;
1414
import android.os.Bundle;
15+
import android.provider.Settings;
1516
import android.support.annotation.*;
1617
import android.support.v7.app.AlertDialog;
1718
import android.support.v7.app.AlertDialog.Builder;
1819
import android.text.TextUtils;
1920
import android.text.method.LinkMovementMethod;
2021
import android.view.View;
22+
import android.view.View.OnClickListener;
2123
import android.widget.*;
2224

2325
import static android.widget.ArrayAdapter.*;
@@ -43,42 +45,60 @@ public class AboutActivity extends ListActivity {
4345
licenseContents = getResources().getTextArray(R.array.about_licenses_content);
4446
AndroidTools.displayedIf(findViewById(R.id.about_licenses_title), !getListAdapter().isEmpty());
4547

46-
final AboutInfo aboutInfo = getAboutInfo();
48+
AboutInfo aboutInfo = getAboutInfo();
4749
LOG.trace("About info: {}", aboutInfo);
50+
populateInfo(aboutInfo);
51+
}
4852

49-
TextView feedback = (TextView)findViewById(R.id.about_feedback);
50-
feedback.setOnClickListener(new View.OnClickListener() {
53+
protected void populateInfo(final AboutInfo aboutInfo) {
54+
OnClickListener feedbackAction = new OnClickListener() {
5155
@Override public void onClick(View v) {
5256
onFeedback(aboutInfo);
5357
}
54-
});
55-
populateInfo(aboutInfo);
56-
}
58+
};
59+
OnClickListener settingsAction = new OnClickListener() {
60+
@Override public void onClick(View v) {
61+
openInSettings(aboutInfo);
62+
}
63+
};
64+
OnClickListener playStoreAction = new OnClickListener() {
65+
@Override public void onClick(View v) {
66+
openInPlayStore(aboutInfo);
67+
}
68+
};
69+
70+
TextView feedback = (TextView)findViewById(R.id.about_feedback);
71+
feedback.setOnClickListener(feedbackAction);
5772

58-
protected void populateInfo(AboutInfo aboutInfo) {
5973
TextView nameText = (TextView)findViewById(R.id.about_name);
6074
nameText.setText(aboutInfo.appLabel);
6175
nameText.setSelected(true); // hack to start marquee
76+
nameText.setOnClickListener(playStoreAction);
6277

6378
ImageView iconImage = (ImageView)findViewById(R.id.about_icon);
6479
iconImage.setImageDrawable(aboutInfo.appIcon);
80+
iconImage.setOnClickListener(playStoreAction);
6581

6682
TextView versionText = (TextView)findViewById(R.id.about_version);
6783
versionText.setText(getString(R.string.about_version, aboutInfo.versionName));
6884
versionText.setSelected(true); // hack to start marquee
85+
versionText.setOnClickListener(settingsAction);
6986

7087
TextView versionCodeText = (TextView)findViewById(R.id.about_version_code);
7188
versionCodeText.setText(String.valueOf(aboutInfo.versionCode));
72-
versionCodeText.setVisibility(getResources().getBoolean(R.bool.in_test)? View.VISIBLE : View.GONE);
89+
versionCodeText.setOnClickListener(settingsAction);
90+
AndroidTools.displayedIf(versionCodeText, getResources().getBoolean(R.bool.in_test));
7391

7492
TextView packageText = (TextView)findViewById(R.id.about_package);
7593
packageText.setText(aboutInfo.applicationId);
7694
packageText.setSelected(true); // hack to start marquee
95+
packageText.setOnClickListener(settingsAction);
7796

7897
initSection(R.id.about_faq, R.id.about_faq_title);
7998
initSection(R.id.about_help, R.id.about_help_title);
8099
initSection(R.id.about_tips, R.id.about_tips_title);
81100
}
101+
82102
private void initSection(@IdRes int sectionContentID, @IdRes int sectionTitleID) {
83103
TextView contentView = (TextView)findViewById(sectionContentID);
84104
contentView.setMovementMethod(LinkMovementMethod.getInstance());
@@ -96,6 +116,26 @@ protected void onFeedback(AboutInfo aboutInfo) {
96116
}
97117
}
98118

119+
protected void openInSettings(AboutInfo aboutInfo) {
120+
try {
121+
startActivity(new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
122+
.setData(Uri.parse("package:" + aboutInfo.applicationId))
123+
);
124+
} catch (ActivityNotFoundException ex) {
125+
LOG.warn("Cannot open app info in Settings", ex);
126+
}
127+
}
128+
129+
protected void openInPlayStore(AboutInfo aboutInfo) {
130+
try {
131+
startActivity(new Intent(Intent.ACTION_VIEW)
132+
.setData(Uri.parse("market://details?id=" + aboutInfo.applicationId))
133+
);
134+
} catch (ActivityNotFoundException ex) {
135+
LOG.warn("Cannot open app info in Play Store", ex);
136+
}
137+
}
138+
99139
protected @NonNull Intent createFeedbackIntent(AboutInfo aboutInfo) {
100140
final Intent feedbackIntent = new Intent(Intent.ACTION_VIEW);
101141
feedbackIntent.setData(Uri.parse("mailto:" + aboutInfo.email));

‎libs/twister-lib-android/src/main/res/layout/inc_about_app.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
android:layout_gravity="center_horizontal"
2424
android:gravity="center"
2525
android:singleLine="true"
26-
android:textIsSelectable="true"
26+
android:textIsSelectable="false"
2727
tools:text="\@string/app_name"
2828
/>
2929
<TextView
@@ -32,7 +32,7 @@
3232
android:layout_height="wrap_content"
3333
android:layout_gravity="center_horizontal"
3434
android:gravity="center"
35-
android:textIsSelectable="true"
35+
android:textIsSelectable="false"
3636
tools:text="@string/about_version"
3737
/>
3838
<TextView
@@ -41,7 +41,7 @@
4141
android:layout_height="wrap_content"
4242
android:layout_gravity="center_horizontal"
4343
android:gravity="center"
44-
android:textIsSelectable="true"
44+
android:textIsSelectable="false"
4545
android:visibility="gone"
4646
tools:text="(2147483648)"
4747
tools:visibility="visible"
@@ -52,7 +52,7 @@
5252
android:layout_height="wrap_content"
5353
android:layout_gravity="center_horizontal"
5454
android:gravity="center"
55-
android:textIsSelectable="true"
55+
android:textIsSelectable="false"
5656
tools:text="\@string/app_package"
5757
/>
5858
<TextView

0 commit comments

Comments
 (0)