Beispiel #1
0
 /**
  * Returns whether we should or should not offer to set up wifi. If asCard == true this will
  * decide whether or not to offer wifi setup actively (as a card, for instance). If asCard ==
  * false, this will return whether or not to offer wifi setup passively (in the overflow menu, for
  * instance).
  */
 public static boolean shouldOfferToSetupWifi(final Context context, boolean actively) {
   long now = UIUtils.getCurrentTime(context);
   if (now < Config.WIFI_SETUP_OFFER_START) {
     // too early to offer
     return false;
   }
   if (now > Config.CONFERENCE_END_MILLIS) {
     // too late
     return false;
   }
   if (!WiFiUtils.isWiFiEnabled(context)) {
     // no wifi, no offer
     return false;
   }
   if (!PrefUtils.isAttendeeAtVenue(context)) {
     // wifi setup not relevant
     return false;
   }
   if (WiFiUtils.isWiFiApConfigured(context)) {
     // already set up
     return false;
   }
   if (actively && PrefUtils.hasDeclinedWifiSetup(context)) {
     // user said no
     return false;
   }
   return true;
 }
 public void retryAuthByUserRequest() {
   LOGD(TAG, "Retrying sign-in/auth (user-initiated).");
   if (!mGoogleApiClient.isConnected()) {
     sCanShowAuthUi = sCanShowSignInUi = true;
     PrefUtils.markUserRefusedSignIn(mAppContext, false);
     mGoogleApiClient.connect();
   } else if (!AccountUtils.hasToken(mAppContext, mAccountName)) {
     sCanShowAuthUi = sCanShowSignInUi = true;
     PrefUtils.markUserRefusedSignIn(mAppContext, false);
     mTokenTask = new GetTokenTask();
     mTokenTask.execute();
   } else {
     LOGD(TAG, "No need to retry auth: GoogleApiClient is connected and we have auth token.");
   }
 }
  /** Handles an Activity result. Call this from your Activity's onActivityResult(). */
  public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
    Activity activity = getActivity("onActivityResult()");
    if (activity == null) {
      return false;
    }

    if (requestCode == REQUEST_AUTHENTICATE
        || requestCode == REQUEST_RECOVER_FROM_AUTH_ERROR
        || requestCode == REQUEST_PLAY_SERVICES_ERROR_DIALOG) {

      LOGD(TAG, "onActivityResult, req=" + requestCode + ", result=" + resultCode);
      if (requestCode == REQUEST_RECOVER_FROM_PLAY_SERVICES_ERROR) {
        mResolving = false;
      }

      if (resultCode == Activity.RESULT_OK) {
        if (mGoogleApiClient != null) {
          LOGD(TAG, "Since activity result was RESULT_OK, reconnecting client.");
          mGoogleApiClient.connect();
        } else {
          LOGD(TAG, "Activity result was RESULT_OK, but we have no client to reconnect.");
        }
      } else if (resultCode == Activity.RESULT_CANCELED) {
        LOGD(TAG, "User explicitly cancelled sign-in/auth flow.");
        // save this as a preference so we don't annoy the user again
        PrefUtils.markUserRefusedSignIn(mAppContext);
      } else {
        LOGW(TAG, "Failed to recover from a login/auth failure, resultCode=" + resultCode);
      }
      return true;
    }
    return false;
  }
  @Override
  protected void onPause() {
    super.onPause();
    //  Toast.makeText(MainActivity.this, "MainActivity pause call", Toast.LENGTH_SHORT).show();
    // viewPager.stopAutoScroll();
    Log.e("pause call", "pause call");

    PrefUtils.setKioskModeActive(false, getApplicationContext());
    mHomeKeyLocker.unlock();
  }
 @Override
 protected void onResume() {
   super.onResume();
   // viewPager.startAutoScroll();
   // Toast.makeText(MainActivity.this, "MainActivity resume call", Toast.LENGTH_SHORT).show();
   // if (chkupgrade == true) {
   PrefUtils.setKioskModeActive(true, getApplicationContext());
   mHomeKeyLocker.lock(MainActivity.this);
   // }
 }
 public LoginAndAuthHelper(Activity activity, Callbacks callbacks, String accountName) {
   LOGD(TAG, "Helper created. Account: " + mAccountName);
   mActivityRef = new WeakReference<Activity>(activity);
   mCallbacksRef = new WeakReference<Callbacks>(callbacks);
   mAppContext = activity.getApplicationContext();
   mAccountName = accountName;
   if (PrefUtils.hasUserRefusedSignIn(activity)) {
     // If we know the user refused sign-in, let's not annoy them.
     sCanShowSignInUi = sCanShowAuthUi = false;
   }
 }
Beispiel #7
0
 public static String createAttachKey() {
   String attachKey;
   DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
   String date = dateFormat.format(Calendar.getInstance().getTime());
   String s = date + " " + PrefUtils.getPrefUid();
   try {
     MessageDigest mdInst = MessageDigest.getInstance("MD5");
     mdInst.update(s.getBytes());
     attachKey = bytesToHexString(mdInst.digest());
   } catch (NoSuchAlgorithmException e) {
     attachKey = String.valueOf(s.hashCode());
   }
   return attachKey;
 }
  @SuppressWarnings("deprecation")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub

    super.onCreate(savedInstanceState);
    getWindow().setType(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    getWindow()
        .addFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    setContentView(R.layout.activity_main);
    sLockscreenActivityContext = this;

    WindowManager manager =
        ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE));
    WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
    localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
    localLayoutParams.gravity = Gravity.TOP;
    localLayoutParams.flags =
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
            | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
    localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
    localLayoutParams.height = (int) (50 * getResources().getDisplayMetrics().scaledDensity);
    localLayoutParams.format = PixelFormat.TRANSPARENT;
    customViewGroup view = new customViewGroup(this);
    manager.addView(view, localLayoutParams);

    setLockGuard();

    mHomeKeyLocker = new HomeKeyLocker();
    PrefUtils.setKioskModeActive(true, getApplicationContext());
    mHomeKeyLocker.lock(MainActivity.this);
  }