add menu item to enable NFC to RepoDetails view
It is now possible to beam a repo config via NFC but just selecting the repo in FDroid, then touching two NFC devices together, and clicking on the FDroid one. There is no indication that NFC is off, so this commit adds a menu item that makes it easy to enable the required NFC settings for sending a repo to another device via NFC.
This commit is contained in:
parent
4489037619
commit
ea7f82ed1a
@ -9,6 +9,7 @@
|
||||
<string name="version">Version</string>
|
||||
<string name="edit">Edit</string>
|
||||
<string name="delete">Delete</string>
|
||||
<string name="enable_nfc_send">Enable NFC Send…</string>
|
||||
<string name="cache_downloaded">App cache</string>
|
||||
<string name="cache_downloaded_on">Keep downloaded apk files on SD card</string>
|
||||
<string name="cache_downloaded_off">Do not keep any apk files</string>
|
||||
@ -73,6 +74,8 @@
|
||||
<string name="process_wait_title">Please Wait</string>
|
||||
<string name="process_update_msg">Updating application list…</string>
|
||||
<string name="download_server">Getting application from</string>
|
||||
<string name="nfc_is_not_enabled">NFC is not enabled!</string>
|
||||
<string name="go_to_nfc_settings">Go to NFC Settings…</string>
|
||||
|
||||
<string name="repo_add_url">Repository address</string>
|
||||
<string name="repo_add_fingerprint">Fingerprint (optional)</string>
|
||||
|
43
src/org/fdroid/fdroid/NfcNotEnabledActivity.java
Normal file
43
src/org/fdroid/fdroid/NfcNotEnabledActivity.java
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
package org.fdroid.fdroid;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.nfc.NfcAdapter;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
|
||||
@TargetApi(14)
|
||||
// aka Android 4.0 aka Ice Cream Sandwich
|
||||
public class NfcNotEnabledActivity extends Activity {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
final Intent intent = new Intent();
|
||||
if (Build.VERSION.SDK_INT >= 16) {
|
||||
/*
|
||||
* ACTION_NFC_SETTINGS was added in 4.1 aka Jelly Bean MR1 as a
|
||||
* separate thing from ACTION_NFCSHARING_SETTINGS. It is now
|
||||
* possible to have NFC enabled, but not "Android Beam", which is
|
||||
* needed for NDEF. Therefore, we detect the current state of NFC,
|
||||
* and steer the user accordingly.
|
||||
*/
|
||||
if (NfcAdapter.getDefaultAdapter(this).isEnabled())
|
||||
intent.setAction(Settings.ACTION_NFCSHARING_SETTINGS);
|
||||
else
|
||||
intent.setAction(Settings.ACTION_NFC_SETTINGS);
|
||||
} else if (Build.VERSION.SDK_INT >= 14) {
|
||||
// this API was added in 4.0 aka Ice Cream Sandwich
|
||||
intent.setAction(Settings.ACTION_NFCSHARING_SETTINGS);
|
||||
} else {
|
||||
// no NFC support, so nothing to do here
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}
|
@ -1,9 +1,13 @@
|
||||
package org.fdroid.fdroid.views.fragments;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ContentValues;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.nfc.NfcAdapter;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
@ -50,6 +54,9 @@ public class RepoDetailsFragment extends Fragment {
|
||||
|
||||
private static final int DELETE = 0;
|
||||
private static final int UPDATE = 1;
|
||||
private static final int ENABLE_NFC = 2;
|
||||
|
||||
private MenuItem enableNfc = null;
|
||||
|
||||
// TODO: Currently initialised in onCreateView. Not sure if that is the
|
||||
// best way to go about this...
|
||||
@ -244,18 +251,51 @@ public class RepoDetailsFragment extends Fragment {
|
||||
MenuItemCompat.setShowAsAction(delete,
|
||||
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM |
|
||||
MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
if (Build.VERSION.SDK_INT >= 14)
|
||||
prepareNfcMenuItems(menu);
|
||||
}
|
||||
|
||||
@TargetApi(16)
|
||||
private void prepareNfcMenuItems(Menu menu) {
|
||||
boolean needsEnableNfcMenuItem = false;
|
||||
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
|
||||
if (Build.VERSION.SDK_INT < 16)
|
||||
needsEnableNfcMenuItem = !nfcAdapter.isEnabled();
|
||||
else
|
||||
needsEnableNfcMenuItem = !nfcAdapter.isNdefPushEnabled();
|
||||
if (needsEnableNfcMenuItem) {
|
||||
if (enableNfc != null)
|
||||
return; // already created
|
||||
enableNfc = menu.add(Menu.NONE, ENABLE_NFC, 0, R.string.enable_nfc_send);
|
||||
enableNfc.setIcon(android.R.drawable.ic_menu_preferences);
|
||||
MenuItemCompat.setShowAsAction(enableNfc,
|
||||
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM |
|
||||
MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
|
||||
} else if (enableNfc != null) {
|
||||
// remove the existing MenuItem since NFC is now enabled
|
||||
menu.removeItem(enableNfc.getItemId());
|
||||
enableNfc = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
if (item.getItemId() == DELETE) {
|
||||
switch (item.getItemId()) {
|
||||
case DELETE:
|
||||
promptForDelete();
|
||||
return true;
|
||||
} else if (item.getItemId() == UPDATE) {
|
||||
case UPDATE:
|
||||
performUpdate();
|
||||
return true;
|
||||
case ENABLE_NFC:
|
||||
Intent intent = new Intent(getActivity(), NfcNotEnabledActivity.class);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user