-
Notifications
You must be signed in to change notification settings - Fork 126
/
Copy pathCustomActivity.java
133 lines (117 loc) · 4.46 KB
/
CustomActivity.java
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
package com.actionbarsherlock.sample.demos;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import com.rampo.updatechecker.UpdateChecker;
import com.rampo.updatechecker.UpdateCheckerResult;
public class CustomActivity extends Activity implements UpdateCheckerResult {
TextView result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_activity);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setSubtitle(R.string.custom);
result = (TextView) findViewById(R.id.result);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.xml.activity_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.info:
startActivity(new Intent(this, Infos.class));
return true;
}
return super.onOptionsItemSelected(item);
}
public void custom_impl(View view) {
UpdateChecker checker = new UpdateChecker(this, this);
checker.setSuccessfulChecksRequired(2);
checker.start();
result.setText(R.string.loading);
}
/**
* versionDownloadable isn't equal to manifest versionName -> New update available.
* Show the Notice because it's the first time or the number of the checks made is a multiple of the argument of setSuccessfulChecksRequired(int) method. (If you don't call setSuccessfulChecksRequired(int) the default is 5).
*
* @param versionDownloadable version downloadable from the Store.
* @see com.rampo.updatechecker.UpdateChecker#setSuccessfulChecksRequired(int)
*/
@Override
public void foundUpdateAndShowIt(String versionDownloadable) {
result.setText("Update available\n" + "Version downloadable: " + versionDownloadable + "\nVersion installed: " + getVersionInstalled());
}
/**
* versionDownloadable isn't equal to manifest versionName -> New update available.
* Show the Notice because it's the first time or the number of the checks made is a multiple of the argument of setSuccessfulChecksRequired(int) method. (If you don't call setSuccessfulChecksRequired(int) the default is 5).
*
* @param versionDownloadable version downloadable from the Store.
* @see com.rampo.updatechecker.UpdateChecker#setSuccessfulChecksRequired(int)
*/
@Override
public void foundUpdateAndDontShowIt(String versionDownloadable) {
result.setText("Already Shown\n" + "Version downloadable: " + versionDownloadable + "\nVersion installed: " + getVersionInstalled());
}
/**
* versionDownloadable is equal to manifest versionName -> No new update available.
* Don't show the Notice
*
* @param versionDownloadable version downloadable from the Store.
*/
@Override
public void returnUpToDate(String versionDownloadable) {
result.setText("Updated\n" + "Version downloadable: " + versionDownloadable + "\nVersion installed: " + getVersionInstalled());
}
/**
* Can't get the versionName from the Store.
* See #1
*
* @see <a href="https://github.com/rampo/UpdateChecker/issues/1">Issue #1</a>
*/
@Override
public void returnMultipleApksPublished() {
result.setText("Error #1");
}
/**
* Can't download the store page.
*/
@Override
public void returnNetworkError() {
result.setText("Network Error");
}
/**
* Can't find the store page for this app.
*/
@Override
public void returnAppUnpublished() {
result.setText("App unpublished");
}
/**
* The check returns null for new version downloadble
*/
@Override
public void returnStoreError() {
result.setText("Store Error");
}
public String getVersionInstalled() {
try {
return getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException ignored) {
}
return null;
}
}