forked from Quarx2k/android_frameworks_base
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Framework: Add NFC Tile to Quick Settings (2 of 2)
Need to figure out how to instantiate a new NFC adapter after the Tile is created. Change-Id: I5ad99f1ac8f4730653c9697c2c0d0e86b7d4facd
- Loading branch information
Showing
9 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/SystemUI/src/com/android/systemui/quicksettings/NfcTile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.android.systemui.quicksettings; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.nfc.NfcAdapter; | ||
import android.util.Log; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
|
||
import com.android.systemui.R; | ||
import com.android.systemui.statusbar.phone.QuickSettingsContainerView; | ||
import com.android.systemui.statusbar.phone.QuickSettingsController; | ||
|
||
|
||
public class NfcTile extends QuickSettingsTile { | ||
|
||
private static String TAG = "NfcTile"; | ||
private static NfcAdapter mNfcAdapter; | ||
private static final int NFC_ADAPTER_UNKNOWN = -100; | ||
|
||
public NfcTile(Context context, LayoutInflater inflater, | ||
QuickSettingsContainerView container, | ||
QuickSettingsController qsc) { | ||
super(context, inflater, container, qsc); | ||
|
||
setState(NFC_ADAPTER_UNKNOWN); | ||
|
||
mOnClick = new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
toggleState(); | ||
applyNfcChanges(); | ||
} | ||
}; | ||
|
||
mOnLongClick = new View.OnLongClickListener() { | ||
@Override | ||
public boolean onLongClick(View v) { | ||
Intent intent = new Intent("android.settings.NFC_SETTINGS"); | ||
intent.addCategory(Intent.CATEGORY_DEFAULT); | ||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
startSettingsActivity(intent); | ||
return true; | ||
} | ||
}; | ||
|
||
qsc.registerAction(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED, this); | ||
} | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
applyNfcChanges(); | ||
} | ||
|
||
private void applyNfcChanges() { | ||
updateTileState(); | ||
updateQuickSettings(); | ||
} | ||
|
||
protected void toggleState() { | ||
int state = getNfcState(); | ||
switch (state) { | ||
case NfcAdapter.STATE_TURNING_ON: | ||
case NfcAdapter.STATE_ON: | ||
mNfcAdapter.disable(); | ||
break; | ||
case NfcAdapter.STATE_TURNING_OFF: | ||
case NfcAdapter.STATE_OFF: | ||
mNfcAdapter.enable(); | ||
break; | ||
} | ||
} | ||
|
||
private void updateTileState() { | ||
// Get the initial label | ||
mLabel = mContext.getString(R.string.quick_settings_nfc); | ||
setState(getNfcState()); | ||
} | ||
|
||
private void setState(int state) { | ||
switch (state) { | ||
case NfcAdapter.STATE_TURNING_ON: | ||
case NfcAdapter.STATE_ON: | ||
mDrawable = R.drawable.ic_qs_nfc_on; | ||
break; | ||
case NfcAdapter.STATE_TURNING_OFF: | ||
case NfcAdapter.STATE_OFF: | ||
default: | ||
mDrawable = R.drawable.ic_qs_nfc_off; | ||
mLabel += " " + mContext.getString(R.string.quick_settings_label_disabled); | ||
break; | ||
} | ||
} | ||
|
||
private int getNfcState() { | ||
if (mNfcAdapter != null || (mNfcAdapter = NfcAdapter.getDefaultAdapter(mContext)) != null) { | ||
return mNfcAdapter.getAdapterState(); | ||
} else { | ||
Log.d(TAG, "No NFC adapter available"); | ||
return NFC_ADAPTER_UNKNOWN; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters