Add "Where is my NFC reader?" feature to nfc waiting dialog
This commit is contained in:
parent
c07e808d24
commit
287d3251c5
12 changed files with 315 additions and 2 deletions
|
@ -823,6 +823,12 @@
|
|||
android:name=".ui.PanicExitActivity"
|
||||
android:theme="@android:style/Theme.NoDisplay" />
|
||||
|
||||
<activity
|
||||
android:name=".ui.ShowNfcSweetspotActivity"
|
||||
android:exported="false"
|
||||
android:theme="@style/Theme.Keychain.AppCompat.Transparent.Fullscreen"
|
||||
/>
|
||||
|
||||
<!-- Internal services/content providers (not exported) -->
|
||||
<service
|
||||
android:name=".service.PassphraseCacheService"
|
||||
|
|
|
@ -144,6 +144,10 @@ public class CreateKeyActivity extends BaseSecurityTokenActivity {
|
|||
|
||||
@Override
|
||||
protected void onSecurityTokenPostExecute() {
|
||||
handleTokenInfo(tokenInfo);
|
||||
}
|
||||
|
||||
public void handleTokenInfo(SecurityTokenInfo tokenInfo) {
|
||||
if (mCurrentFragment instanceof SecurityTokenListenerFragment) {
|
||||
((SecurityTokenListenerFragment) mCurrentFragment).onSecurityTokenPostExecute();
|
||||
return;
|
||||
|
|
|
@ -19,19 +19,24 @@ package org.sufficientlysecure.keychain.ui;
|
|||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.Animation;
|
||||
|
||||
import org.sufficientlysecure.keychain.BuildConfig;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.securitytoken.NfcSweetspotData;
|
||||
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenInfo;
|
||||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
||||
import org.sufficientlysecure.keychain.ui.base.BaseSecurityTokenActivity;
|
||||
|
@ -39,6 +44,7 @@ import org.sufficientlysecure.keychain.ui.token.ManageSecurityTokenFragment;
|
|||
|
||||
|
||||
public class CreateSecurityTokenWaitFragment extends Fragment {
|
||||
public static final int REQUEST_CODE_SWEETSPOT = 0;
|
||||
|
||||
public static boolean sDisableFragmentAnimations = false;
|
||||
|
||||
|
@ -88,6 +94,17 @@ public class CreateSecurityTokenWaitFragment extends Fragment {
|
|||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.create_security_token_wait_fragment, container, false);
|
||||
|
||||
boolean showLocateHotspot = NfcSweetspotData.SWEETSPOT_DATA.containsKey(Build.MODEL);
|
||||
View locateHotspotView = view.findViewById(R.id.button_locate_nfc);
|
||||
locateHotspotView.setVisibility(showLocateHotspot ? View.VISIBLE : View.GONE);
|
||||
locateHotspotView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(getActivity(), ShowNfcSweetspotActivity.class);
|
||||
startActivityForResult(intent, REQUEST_CODE_SWEETSPOT);
|
||||
}
|
||||
});
|
||||
|
||||
mBackButton = view.findViewById(R.id.create_key_back_button);
|
||||
|
||||
mBackButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -100,6 +117,22 @@ public class CreateSecurityTokenWaitFragment extends Fragment {
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == REQUEST_CODE_SWEETSPOT) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity instanceof BaseSecurityTokenActivity && data != null &&
|
||||
data.hasExtra(ShowNfcSweetspotActivity.EXTRA_TOKEN_INFO)) {
|
||||
SecurityTokenInfo tokenInfo = data.getParcelableExtra(ShowNfcSweetspotActivity.EXTRA_TOKEN_INFO);
|
||||
((CreateKeyActivity) activity).handleTokenInfo(tokenInfo);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Pair;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.securitytoken.NfcSweetspotData;
|
||||
import org.sufficientlysecure.keychain.ui.base.BaseSecurityTokenActivity;
|
||||
|
||||
|
||||
public class ShowNfcSweetspotActivity extends BaseSecurityTokenActivity {
|
||||
public static final String EXTRA_TOKEN_INFO = "token_info";
|
||||
|
||||
private View sweetspotIndicator;
|
||||
private View sweetspotIcon;
|
||||
private View sweetspotCircle1;
|
||||
private View sweetspotCircle2;
|
||||
private View sweetspotCircle3;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
overridePendingTransition(R.anim.fade_in_quick, R.anim.fade_out_quick);
|
||||
|
||||
setContentView(R.layout.show_nfc_sweetspot_activity);
|
||||
sweetspotIndicator = findViewById(R.id.nfc_sweetspot_indicator);
|
||||
|
||||
Pair<Double, Double> nfcPosition = NfcSweetspotData.SWEETSPOT_DATA.get(Build.MODEL);
|
||||
if (nfcPosition == null) {
|
||||
throw new IllegalArgumentException("No data available for this model. This activity should not be called!");
|
||||
}
|
||||
DisplayMetrics displayDimensions = getDisplaySize();
|
||||
|
||||
final float translationX = (float) (displayDimensions.widthPixels * nfcPosition.first);
|
||||
final float translationY = (float) (displayDimensions.heightPixels * nfcPosition.second);
|
||||
|
||||
sweetspotIndicator.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sweetspotIndicator.setTranslationX(translationX - sweetspotIndicator.getWidth() / 2);
|
||||
sweetspotIndicator.setTranslationY(translationY - sweetspotIndicator.getHeight() / 2);
|
||||
}
|
||||
});
|
||||
|
||||
sweetspotIcon = findViewById(R.id.nfc_sweetspot_icon);
|
||||
sweetspotCircle1 = findViewById(R.id.nfc_sweetspot_circle_1);
|
||||
sweetspotCircle2 = findViewById(R.id.nfc_sweetspot_circle_2);
|
||||
sweetspotCircle3 = findViewById(R.id.nfc_sweetspot_circle_3);
|
||||
|
||||
sweetspotIcon.setAlpha(0.0f);
|
||||
sweetspotCircle1.setAlpha(0.0f);
|
||||
sweetspotCircle2.setAlpha(0.0f);
|
||||
sweetspotCircle3.setAlpha(0.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnterAnimationComplete() {
|
||||
super.onEnterAnimationComplete();
|
||||
|
||||
DecelerateInterpolator interpolator = new DecelerateInterpolator();
|
||||
sweetspotIcon.animate().alpha(1.0f).setInterpolator(interpolator).setDuration(300).start();
|
||||
sweetspotCircle1.animate().alpha(1.0f).setInterpolator(interpolator).setDuration(500).setStartDelay(100).start();
|
||||
sweetspotCircle2.animate().alpha(1.0f).setInterpolator(interpolator).setDuration(700).setStartDelay(200).start();
|
||||
sweetspotCircle3.animate().alpha(1.0f).setInterpolator(interpolator).setDuration(1000).setStartDelay(300).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initTheme() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
super.finish();
|
||||
|
||||
overridePendingTransition(R.anim.fade_in_quick, R.anim.fade_out_quick);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSecurityTokenPostExecute() {
|
||||
Intent result = new Intent();
|
||||
result.putExtra(EXTRA_TOKEN_INFO, tokenInfo);
|
||||
setResult(Activity.RESULT_OK, result);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (event.getActionMasked() == MotionEvent.ACTION_UP) {
|
||||
setResult(Activity.RESULT_CANCELED);
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private DisplayMetrics getDisplaySize() {
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
|
||||
return metrics;
|
||||
}
|
||||
}
|
|
@ -57,7 +57,7 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||
super.onResume();
|
||||
onResumeChecks(this);
|
||||
|
||||
if (mThemeChanger.changeTheme()) {
|
||||
if (mThemeChanger != null && mThemeChanger.changeTheme()) {
|
||||
Intent intent = getIntent();
|
||||
finish();
|
||||
overridePendingTransition(0, 0);
|
||||
|
|
|
@ -73,7 +73,7 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity
|
|||
protected UsbConnectionDispatcher mUsbDispatcher;
|
||||
private boolean mTagHandlingEnabled;
|
||||
|
||||
private SecurityTokenInfo tokenInfo;
|
||||
protected SecurityTokenInfo tokenInfo;
|
||||
|
||||
/**
|
||||
* Override to change UI before SecurityToken handling (UI thread)
|
||||
|
|
6
OpenKeychain/src/main/res/drawable/circle.xml
Normal file
6
OpenKeychain/src/main/res/drawable/circle.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<vector android:height="120dp" android:viewportHeight="100.0"
|
||||
android:viewportWidth="100.0" android:width="120dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillAlpha="1" android:fillColor="#00000000"
|
||||
android:pathData="M50,50m-45,0a45,45 0,1 1,90 0a45,45 0,1 1,-90 0"
|
||||
android:strokeAlpha="1" android:strokeColor="#000000" android:strokeWidth="3"/>
|
||||
</vector>
|
|
@ -32,6 +32,22 @@
|
|||
android:layout_gravity="center_horizontal"
|
||||
custom:nfc_device="card_black"/>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:id="@+id/button_locate_nfc"
|
||||
android:text="@string/button_locate_nfc"
|
||||
style="?borderlessButtonStyle"
|
||||
/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#bb000000"
|
||||
>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/nfc_sweetspot_indicator"
|
||||
tools:layout_marginLeft="60dp"
|
||||
tools:layout_marginTop="100dp"
|
||||
tools:ignore="UselessParent">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/ic_nfc_white_24dp"
|
||||
android:id="@+id/nfc_sweetspot_icon"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/circle"
|
||||
android:id="@+id/nfc_sweetspot_circle_1"
|
||||
android:tint="@color/md_white_1000"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="95dp"
|
||||
android:layout_height="95dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/circle"
|
||||
android:id="@+id/nfc_sweetspot_circle_2"
|
||||
android:tint="@color/md_white_1000"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="130dp"
|
||||
android:layout_height="130dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/circle"
|
||||
android:id="@+id/nfc_sweetspot_circle_3"
|
||||
android:tint="@color/md_white_1000"
|
||||
/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</FrameLayout>
|
|
@ -1961,4 +1961,6 @@
|
|||
<item quantity="other">"Updating %d keys"</item>
|
||||
</plurals>
|
||||
|
||||
<string name="button_locate_nfc">"Where is my NFC reader?"</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -133,5 +133,18 @@
|
|||
<item name="windowNoTitle">true</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Keychain.AppCompat.Transparent" parent="Theme.AppCompat.NoActionBar">
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:colorBackgroundCacheHint">@null</item>
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<item name="android:windowFullscreen">true</item>
|
||||
<item name="android:windowAnimationStyle">@style/Animation.AppCompat.Dialog</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Keychain.AppCompat.Transparent.Fullscreen" parent="Theme.Keychain.AppCompat.Transparent">
|
||||
<item name="android:windowFullscreen">true</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Keychain.Transparent" parent="@android:style/Theme.NoDisplay" />
|
||||
</resources>
|
||||
|
|
63
graphics/drawables/circle.svg
Normal file
63
graphics/drawables/circle.svg
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="100mm"
|
||||
height="100mm"
|
||||
viewBox="0 0 100 100"
|
||||
version="1.1"
|
||||
id="svg8"
|
||||
inkscape:version="0.92.1 r15371"
|
||||
sodipodi:docname="circle.svg">
|
||||
<defs
|
||||
id="defs2" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="0.35"
|
||||
inkscape:cx="-477.14286"
|
||||
inkscape:cy="560"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1056"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="24"
|
||||
inkscape:window-maximized="0" />
|
||||
<metadata
|
||||
id="metadata5">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-197)">
|
||||
<circle
|
||||
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:3;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
id="path4485"
|
||||
cx="50"
|
||||
cy="247"
|
||||
r="49.864174" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.8 KiB |
Loading…
Add table
Reference in a new issue