Android Open Source - nfcunlocker Discovered Activity






From Project

Back to project page nfcunlocker.

License

The source code is released under:

Apache License

If you think the Android project nfcunlocker listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.steelrat.nfcunlocker;
/*from   w  w w  .j a v a2s  .c o m*/
import com.steelrat.nfcunlocker.helpers.TagsStorage;
import com.steelrat.nfcunlocker.unlockmethods.UnlockMethod;
import com.steelrat.nfcunlocker.unlockmethods.UnlockMethodFactory;

import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.app.Activity;
import android.app.KeyguardManager;
import android.content.SharedPreferences;

public class DiscoveredActivity extends Activity {
  UnlockMethod mUnlockMethod;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        
    // Check tag existence.
    TagsStorage tagsStorage = new TagsStorage(this);
    String id = TagsStorage.bytesToHex(getIntent().getByteArrayExtra(NfcAdapter.EXTRA_ID));
    if (!tagsStorage.isExists(id)) {
      finish();
      return;
    }
    
    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
        String password = sharedPref.getString("password", "");    
        mUnlockMethod = UnlockMethodFactory.getUnlockMethod(this, sharedPref.getString("unlock_method", ""));
          
    // Finish activity if the screen is not locked, unlock method is not set or the password is empty.
    if (!keyguardManager.inKeyguardRestrictedInputMode() || mUnlockMethod == null || password.length() == 0) {
      // Unset unlock method to prevent from calling its events.
      mUnlockMethod = null;
      finish();
      return;
    }
        
        mUnlockMethod.unlock(password);  
    mUnlockMethod.onActivityEvent("onCreate");
    }
  
  @Override
  public void onAttachedToWindow() {  
    super.onAttachedToWindow();
  
    mUnlockMethod.onActivityEvent("onAttachedToWindow");
  }
  
  @Override
  protected void onDestroy() {
    super.onDestroy();
        
    if (mUnlockMethod != null) {
      mUnlockMethod.onActivityEvent("onDestroy");
    }
  }
}




Java Source Code List

com.steelrat.nfcunlocker.AddActivity.java
com.steelrat.nfcunlocker.DiscoveredActivity.java
com.steelrat.nfcunlocker.MainActivity.java
com.steelrat.nfcunlocker.NFCApplication.java
com.steelrat.nfcunlocker.helpers.AppDeviceAdminReceiver.java
com.steelrat.nfcunlocker.helpers.TagsStorage.java
com.steelrat.nfcunlocker.settingsactivity.SettingsActivityBase.java
com.steelrat.nfcunlocker.settingsactivity.SettingsActivityOA.java
com.steelrat.nfcunlocker.settingsactivity.SettingsActivity.java
com.steelrat.nfcunlocker.unlockmethods.DevicePolicyUnlockMethod.java
com.steelrat.nfcunlocker.unlockmethods.FlagUnlock.java
com.steelrat.nfcunlocker.unlockmethods.InputUnlock.java
com.steelrat.nfcunlocker.unlockmethods.KeyguardUnlock.java
com.steelrat.nfcunlocker.unlockmethods.UnlockMethodFactory.java
com.steelrat.nfcunlocker.unlockmethods.UnlockMethod.java