add initial example UI

This commit is contained in:
Andrea Franz 2018-08-30 12:21:24 +02:00
parent a8e2f27624
commit c0ca7c2631
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
4 changed files with 147 additions and 4 deletions

View File

@ -1,5 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="5">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>

View File

@ -2,6 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="im.status.applet_installer_test.appletinstaller">
<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="android.hardware.nfc.hce"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"

View File

@ -2,12 +2,114 @@ package im.status.applet_installer_test.appletinstaller;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.nfc.tech.IsoDep;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.io.IOException;
import java.io.ByteArrayOutputStream;
import java.security.SecureRandom;
public class MainActivity extends AppCompatActivity {
public class MainActivity extends AppCompatActivity implements NfcAdapter.ReaderCallback {
private NfcAdapter nfcAdapter;
private TextView textView;
private Button buttonInstall;
private Tag tag;
private boolean installationAttempted;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nfcAdapter = NfcAdapter.getDefaultAdapter(this);
textView = (TextView) findViewById(R.id.textView);
buttonInstall = (Button) findViewById(R.id.buttonInstall);
buttonInstall.setEnabled(false);
buttonInstall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
disableInstallButton();
try {
install();
} catch (Exception e) {
Logger.log(e.getMessage());
}
}
});
}
public void install() throws Exception {
if (installationAttempted) {
throw new Exception("installation already attempted");
}
installationAttempted = true;
Logger.log("installing");
CardManager cm = new CardManager(tag);
cm.connect();
cm.install();
}
@Override
public void onResume() {
super.onResume();
if (nfcAdapter != null) {
nfcAdapter.enableReaderMode(this, this,
NfcAdapter.FLAG_READER_NFC_A |
NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK,
null);
}
}
@Override
public void onPause() {
super.onPause();
if (nfcAdapter != null) {
nfcAdapter.disableReaderMode(this);
}
}
@Override
public void onTagDiscovered (Tag tag) {
try {
start(tag);
} catch (final IOException e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
textView.append("\nexception: " + e.getMessage());
}
});
}
}
private void start(Tag tag) throws IOException {
this.tag = tag;
Logger.log("tag found");
this.enableInstallButton();
}
public void enableInstallButton() {
runOnUiThread(new Runnable() {
@Override
public void run() {
buttonInstall.setEnabled(true);
}
});
}
public void disableInstallButton() {
runOnUiThread(new Runnable() {
@Override
public void run() {
buttonInstall.setEnabled(false);
}
});
}
}

View File

@ -7,12 +7,24 @@
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:layout_width="368dp"
android:layout_height="405dp"
android:layout_marginEnd="8dp"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.014" />
<Button
android:id="@+id/buttonInstall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="install"
tools:layout_editor_absoluteX="148dp"
tools:layout_editor_absoluteY="446dp" />
</android.support.constraint.ConstraintLayout>