2015-12-30 08:58:21 +00:00
|
|
|
package eu.faircode.netguard;
|
|
|
|
|
|
|
|
/*
|
|
|
|
This file is part of NetGuard.
|
|
|
|
|
|
|
|
NetGuard 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.
|
|
|
|
|
|
|
|
NetGuard 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 NetGuard. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-01-01 13:52:09 +00:00
|
|
|
Copyright 2015-2016 by Marcel Bokhorst (M66B)
|
2015-12-30 08:58:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import android.content.Intent;
|
2015-12-31 09:03:32 +00:00
|
|
|
import android.os.Build;
|
2015-12-30 08:58:21 +00:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.v7.app.AppCompatActivity;
|
2015-12-31 09:03:32 +00:00
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.TextWatcher;
|
2016-01-21 13:33:19 +00:00
|
|
|
import android.text.util.Linkify;
|
2015-12-30 08:58:21 +00:00
|
|
|
import android.util.Log;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
2015-12-31 09:03:32 +00:00
|
|
|
import android.view.WindowManager;
|
2015-12-30 08:58:21 +00:00
|
|
|
import android.widget.Button;
|
2015-12-31 09:03:32 +00:00
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.LinearLayout;
|
2015-12-30 08:58:21 +00:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2016-01-21 13:33:19 +00:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
2015-12-30 08:58:21 +00:00
|
|
|
public class ActivityPro extends AppCompatActivity {
|
|
|
|
private static final String TAG = "NetGuard.Pro";
|
|
|
|
|
|
|
|
private IAB iab;
|
|
|
|
|
|
|
|
// adb shell pm clear com.android.vending
|
2016-01-03 08:51:36 +00:00
|
|
|
// android.test.purchased
|
2016-01-21 16:57:55 +00:00
|
|
|
public static final String SKU_LOG = "log";
|
2016-01-03 08:51:36 +00:00
|
|
|
public static final String SKU_NOTIFY = "notify";
|
2015-12-30 08:58:21 +00:00
|
|
|
public static final String SKU_SPEED = "speed";
|
2016-01-21 16:57:55 +00:00
|
|
|
public static final String SKU_THEME = "theme";
|
2016-01-11 10:58:53 +00:00
|
|
|
public static final String SKU_MULTI = "multi";
|
2015-12-30 08:58:21 +00:00
|
|
|
public static final String SKU_DONATION = "donation";
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
2015-12-31 09:18:00 +00:00
|
|
|
Log.i(TAG, "Create");
|
2016-01-02 15:38:24 +00:00
|
|
|
Util.setTheme(this);
|
2015-12-30 08:58:21 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.pro);
|
|
|
|
|
|
|
|
getSupportActionBar().setTitle(R.string.title_pro);
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
2015-12-31 09:03:32 +00:00
|
|
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
|
|
|
|
2015-12-31 15:55:39 +00:00
|
|
|
// Initial state
|
2015-12-30 08:58:21 +00:00
|
|
|
updateState();
|
|
|
|
|
2016-01-21 16:57:55 +00:00
|
|
|
TextView tvLogTitle = (TextView) findViewById(R.id.tvLogTitle);
|
2016-01-21 13:33:19 +00:00
|
|
|
TextView tvNotifyTitle = (TextView) findViewById(R.id.tvNotifyTitle);
|
|
|
|
TextView tvSpeedTitle = (TextView) findViewById(R.id.tvSpeedTitle);
|
2016-01-21 16:57:55 +00:00
|
|
|
TextView tvThemeTitle = (TextView) findViewById(R.id.tvThemeTitle);
|
2016-01-21 13:33:19 +00:00
|
|
|
TextView tvMultiTitle = (TextView) findViewById(R.id.tvMultiTitle);
|
|
|
|
|
|
|
|
Linkify.TransformFilter filter = new Linkify.TransformFilter() {
|
|
|
|
@Override
|
|
|
|
public String transformUrl(Matcher match, String url) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-01-21 16:57:55 +00:00
|
|
|
Linkify.addLinks(tvLogTitle, Pattern.compile(".*"), "http://www.netguard.me/#log", null, filter);
|
2016-01-21 13:33:19 +00:00
|
|
|
Linkify.addLinks(tvNotifyTitle, Pattern.compile(".*"), "http://www.netguard.me/#notify", null, filter);
|
|
|
|
Linkify.addLinks(tvSpeedTitle, Pattern.compile(".*"), "http://www.netguard.me/#speed", null, filter);
|
2016-01-21 16:57:55 +00:00
|
|
|
Linkify.addLinks(tvThemeTitle, Pattern.compile(".*"), "http://www.netguard.me/#theme", null, filter);
|
2016-01-21 13:33:19 +00:00
|
|
|
Linkify.addLinks(tvMultiTitle, Pattern.compile(".*"), "http://www.netguard.me/#multi", null, filter);
|
|
|
|
|
2015-12-31 15:55:39 +00:00
|
|
|
// Challenge
|
2015-12-31 09:03:32 +00:00
|
|
|
TextView tvChallenge = (TextView) findViewById(R.id.tvChallenge);
|
|
|
|
tvChallenge.setText(Build.SERIAL);
|
2015-12-31 15:55:39 +00:00
|
|
|
|
|
|
|
// Response
|
|
|
|
try {
|
|
|
|
final String response = Util.md5(Build.SERIAL, "NetGuard");
|
|
|
|
EditText etResponse = (EditText) findViewById(R.id.etResponse);
|
|
|
|
etResponse.addTextChangedListener(new TextWatcher() {
|
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable editable) {
|
|
|
|
if (response.equals(editable.toString().toUpperCase())) {
|
2015-12-31 09:03:32 +00:00
|
|
|
IAB.setBought(SKU_DONATION, ActivityPro.this);
|
|
|
|
updateState();
|
|
|
|
}
|
|
|
|
}
|
2015-12-31 15:55:39 +00:00
|
|
|
});
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
|
|
|
}
|
2015-12-31 09:03:32 +00:00
|
|
|
|
2015-12-30 08:58:21 +00:00
|
|
|
try {
|
|
|
|
iab = new IAB(new IAB.Delegate() {
|
|
|
|
@Override
|
|
|
|
public void onReady(final IAB iab) {
|
|
|
|
Log.i(TAG, "IAB ready");
|
|
|
|
try {
|
2015-12-31 15:55:39 +00:00
|
|
|
iab.updatePurchases();
|
|
|
|
updateState();
|
2015-12-30 08:58:21 +00:00
|
|
|
|
2016-01-21 16:57:55 +00:00
|
|
|
final Button btnLog = (Button) findViewById(R.id.btnLog);
|
2015-12-31 09:03:32 +00:00
|
|
|
final Button btnNotify = (Button) findViewById(R.id.btnNotify);
|
2015-12-30 08:58:21 +00:00
|
|
|
final Button btnSpeed = (Button) findViewById(R.id.btnSpeed);
|
2016-01-21 16:57:55 +00:00
|
|
|
final Button btnTheme = (Button) findViewById(R.id.btnTheme);
|
2016-01-11 10:58:53 +00:00
|
|
|
final Button btnMulti = (Button) findViewById(R.id.btnMulti);
|
2015-12-30 08:58:21 +00:00
|
|
|
|
|
|
|
View.OnClickListener listener = new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
try {
|
2016-01-21 16:57:55 +00:00
|
|
|
if (view == btnLog)
|
|
|
|
startIntentSenderForResult(iab.getBuyIntent(SKU_LOG).getIntentSender(), view.getId(), new Intent(), 0, 0, 0);
|
|
|
|
else if (view == btnNotify)
|
2015-12-31 09:03:32 +00:00
|
|
|
startIntentSenderForResult(iab.getBuyIntent(SKU_NOTIFY).getIntentSender(), view.getId(), new Intent(), 0, 0, 0);
|
2015-12-30 08:58:21 +00:00
|
|
|
else if (view == btnSpeed)
|
|
|
|
startIntentSenderForResult(iab.getBuyIntent(SKU_SPEED).getIntentSender(), view.getId(), new Intent(), 0, 0, 0);
|
2016-01-21 16:57:55 +00:00
|
|
|
else if (view == btnTheme)
|
|
|
|
startIntentSenderForResult(iab.getBuyIntent(SKU_THEME).getIntentSender(), view.getId(), new Intent(), 0, 0, 0);
|
2016-01-11 10:58:53 +00:00
|
|
|
else if (view == btnMulti)
|
|
|
|
startIntentSenderForResult(iab.getBuyIntent(SKU_MULTI).getIntentSender(), view.getId(), new Intent(), 0, 0, 0);
|
2015-12-30 08:58:21 +00:00
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.i(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
|
|
|
Util.sendCrashReport(ex, ActivityPro.this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-01-21 16:57:55 +00:00
|
|
|
btnLog.setOnClickListener(listener);
|
2015-12-31 09:03:32 +00:00
|
|
|
btnNotify.setOnClickListener(listener);
|
2015-12-30 08:58:21 +00:00
|
|
|
btnSpeed.setOnClickListener(listener);
|
2016-01-21 16:57:55 +00:00
|
|
|
btnTheme.setOnClickListener(listener);
|
2016-01-11 10:58:53 +00:00
|
|
|
btnMulti.setOnClickListener(listener);
|
2015-12-30 08:58:21 +00:00
|
|
|
|
2016-01-21 16:57:55 +00:00
|
|
|
btnLog.setEnabled(true);
|
2015-12-31 09:03:32 +00:00
|
|
|
btnNotify.setEnabled(true);
|
2015-12-30 08:58:21 +00:00
|
|
|
btnSpeed.setEnabled(true);
|
2016-01-21 16:57:55 +00:00
|
|
|
btnTheme.setEnabled(true);
|
2016-01-11 10:58:53 +00:00
|
|
|
btnMulti.setEnabled(true);
|
2015-12-30 08:58:21 +00:00
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
iab.bind();
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
2015-12-31 09:18:00 +00:00
|
|
|
Log.i(TAG, "Destroy");
|
2015-12-30 08:58:21 +00:00
|
|
|
iab.unbind();
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home:
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
|
switch (requestCode) {
|
2016-01-21 16:57:55 +00:00
|
|
|
case R.id.btnLog:
|
|
|
|
IAB.setBought(SKU_LOG, this);
|
2015-12-30 08:58:21 +00:00
|
|
|
updateState();
|
|
|
|
break;
|
2016-01-21 16:57:55 +00:00
|
|
|
case R.id.btnNotify:
|
|
|
|
IAB.setBought(SKU_NOTIFY, this);
|
2015-12-30 08:58:21 +00:00
|
|
|
updateState();
|
|
|
|
break;
|
|
|
|
case R.id.btnSpeed:
|
|
|
|
IAB.setBought(SKU_SPEED, this);
|
|
|
|
updateState();
|
|
|
|
break;
|
2016-01-21 16:57:55 +00:00
|
|
|
case R.id.btnTheme:
|
|
|
|
IAB.setBought(SKU_THEME, this);
|
2016-01-05 12:40:02 +00:00
|
|
|
updateState();
|
|
|
|
break;
|
2016-01-11 10:58:53 +00:00
|
|
|
case R.id.btnMulti:
|
|
|
|
IAB.setBought(SKU_MULTI, this);
|
|
|
|
updateState();
|
|
|
|
break;
|
2015-12-30 08:58:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateState() {
|
2016-01-21 16:57:55 +00:00
|
|
|
Button btnLog = (Button) findViewById(R.id.btnLog);
|
2015-12-31 09:03:32 +00:00
|
|
|
Button btnNotify = (Button) findViewById(R.id.btnNotify);
|
2015-12-30 08:58:21 +00:00
|
|
|
Button btnSpeed = (Button) findViewById(R.id.btnSpeed);
|
2016-01-21 16:57:55 +00:00
|
|
|
Button btnTheme = (Button) findViewById(R.id.btnTheme);
|
2016-01-11 10:58:53 +00:00
|
|
|
Button btnMulti = (Button) findViewById(R.id.btnMulti);
|
2016-01-21 16:57:55 +00:00
|
|
|
TextView tvLog = (TextView) findViewById(R.id.tvLog);
|
2015-12-31 09:03:32 +00:00
|
|
|
TextView tvNotify = (TextView) findViewById(R.id.tvNotify);
|
2015-12-30 08:58:21 +00:00
|
|
|
TextView tvSpeed = (TextView) findViewById(R.id.tvSpeed);
|
2016-01-21 16:57:55 +00:00
|
|
|
TextView tvTheme = (TextView) findViewById(R.id.tvTheme);
|
2016-01-11 10:58:53 +00:00
|
|
|
TextView tvMulti = (TextView) findViewById(R.id.tvMulti);
|
2015-12-31 09:03:32 +00:00
|
|
|
LinearLayout llChallenge = (LinearLayout) findViewById(R.id.llChallenge);
|
2015-12-30 08:58:21 +00:00
|
|
|
|
2016-01-21 16:57:55 +00:00
|
|
|
btnLog.setVisibility(IAB.isPurchased(SKU_LOG, this) ? View.GONE : View.VISIBLE);
|
2016-01-01 18:03:41 +00:00
|
|
|
btnNotify.setVisibility(IAB.isPurchased(SKU_NOTIFY, this) ? View.GONE : View.VISIBLE);
|
|
|
|
btnSpeed.setVisibility(IAB.isPurchased(SKU_SPEED, this) ? View.GONE : View.VISIBLE);
|
2016-01-21 16:57:55 +00:00
|
|
|
btnTheme.setVisibility(IAB.isPurchased(SKU_THEME, this) ? View.GONE : View.VISIBLE);
|
2016-01-11 10:58:53 +00:00
|
|
|
btnMulti.setVisibility(IAB.isPurchased(SKU_MULTI, this) ? View.GONE : View.VISIBLE);
|
2015-12-30 17:57:00 +00:00
|
|
|
|
2016-01-21 16:57:55 +00:00
|
|
|
tvLog.setVisibility(IAB.isPurchased(SKU_LOG, this) ? View.VISIBLE : View.GONE);
|
2016-01-01 18:03:41 +00:00
|
|
|
tvNotify.setVisibility(IAB.isPurchased(SKU_NOTIFY, this) ? View.VISIBLE : View.GONE);
|
|
|
|
tvSpeed.setVisibility(IAB.isPurchased(SKU_SPEED, this) ? View.VISIBLE : View.GONE);
|
2016-01-21 16:57:55 +00:00
|
|
|
tvTheme.setVisibility(IAB.isPurchased(SKU_THEME, this) ? View.VISIBLE : View.GONE);
|
2016-01-11 10:58:53 +00:00
|
|
|
tvMulti.setVisibility(IAB.isPurchased(SKU_MULTI, this) ? View.VISIBLE : View.GONE);
|
2015-12-31 09:03:32 +00:00
|
|
|
|
2016-01-01 18:03:41 +00:00
|
|
|
llChallenge.setVisibility(IAB.isPurchased(SKU_DONATION, this) ? View.GONE : View.VISIBLE);
|
2015-12-30 08:58:21 +00:00
|
|
|
}
|
|
|
|
}
|