Exemplo n.º 1
1
 /**
  * Register the device to Google Cloud Messaging service or return registration id if it's already
  * registered.
  *
  * @return registration id or empty string if it's not registered.
  */
 private static String gcmRegisterIfNot(Context context) {
   String regId = "";
   try {
     GCMRegistrar.checkDevice(context);
     GCMRegistrar.checkManifest(context);
     regId = GCMRegistrar.getRegistrationId(context);
     String gcmId = BuildConfig.GCM_ID;
     if (gcmId != null && TextUtils.isEmpty(regId)) {
       GCMRegistrar.register(context, gcmId);
     }
   } catch (UnsupportedOperationException e) {
     // GCMRegistrar.checkDevice throws an UnsupportedOperationException if the device
     // doesn't support GCM (ie. non-google Android)
     AppLog.e(T.NOTIFS, "Device doesn't support GCM: " + e.getMessage());
   } catch (IllegalStateException e) {
     // GCMRegistrar.checkManifest or GCMRegistrar.register throws an IllegalStateException if
     // Manifest
     // configuration is incorrect (missing a permission for instance) or if GCM dependencies are
     // missing
     AppLog.e(
         T.NOTIFS,
         "APK (manifest error or dependency missing) doesn't support GCM: " + e.getMessage());
   } catch (Exception e) {
     // SecurityException can happen on some devices without Google services (these devices
     // probably strip
     // the AndroidManifest.xml and remove unsupported permissions).
     AppLog.e(T.NOTIFS, e);
   }
   return regId;
 }
Exemplo n.º 2
0
  public void setupPushNotification() {

    // Make sure the device has the proper dependencies.
    GCMRegistrar.checkDevice(this);

    // Make sure the manifest was properly set - comment out this line
    // while developing the app, then uncomment it when it's ready.
    GCMRegistrar.checkManifest(this);

    // registerReceiver(mHandleMessageReceiver, new IntentFilter(DISPLAY_MESSAGE_ACTION));

    // Get GCM registration id
    String regId = GCMRegistrar.getRegistrationId(this);

    // Check if regid already presents
    if (regId.equals("")) {
      // Registration is not present, register now with GCM
      GCMRegistrar.register(this, ApplicationConstants.SENDER_ID);
    } else {
      // Device is already registered on GCM
      if (GCMRegistrar.isRegisteredOnServer(this)) {
        // Skips registration.
        Toast.makeText(getApplicationContext(), "Already registered with GCM", Toast.LENGTH_LONG)
            .show();
      }
    }
  }
Exemplo n.º 3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test_activity);

    gcmRegId = GCMRegistrar.getRegistrationId(this);
    jpushRegId = JPushInterface.getRegistrationID(this);

    tv = (TextView) findViewById(R.id.test_tv);

    tv.setText(
        "GCMregId:"
            + gcmRegId
            + LINE
            + "jpushRegId:"
            + jpushRegId
            + LINE
            + "string.xml server:"
            + getString(R.string.server_address)
            + LINE
            + "Server IP:"
            + Constants.hostUrl
            + LINE
            + "ETS Server:"
            + Constants.ETShostUrl);
  }
  /** @param context current context */
  public void onStartup(Context context, boolean registerAppOpen) {
    // check for manifest and permissions
    pushRegistrar.checkDevice(context);

    if (registerAppOpen) sendAppOpen(context);

    final String regId = GCMRegistrar.getRegistrationId(context);
    if (regId.equals("")) {
      // Automatically registers application on startup.
      pushRegistrar.registerPW(context);
    } else {
      if (context instanceof Activity) {
        if (((Activity) context).getIntent().hasExtra(PushManager.PUSH_RECEIVE_EVENT)) {
          // if this method calls because of push message, we don't need to register
          return;
        }
      }

      // if we need to re-register on Pushwoosh because of Pushwoosh App Id change
      if (forceRegister) {
        registerOnPushWoosh(context, regId);
      } else {
        if (neededToRequestPushWooshServer(context)) {
          registerOnPushWoosh(context, regId);
        } else {
          PushEventsTransmitter.onRegistered(context, regId);
        }
      }
    }
  }
 public void registerPushAccount() {
   GCMRegistrar.checkDevice(this);
   GCMRegistrar.checkManifest(this);
   if (GCMRegistrar.isRegistered(this)) {
     Log.d("info", GCMRegistrar.getRegistrationId(this));
   }
   String regId = GCMRegistrar.getRegistrationId(this);
   if (regId.equals("")) {
     GCMRegistrar.register(this, AppConstants.PUSH_NOTIFICATION_KEY);
     Log.d("info", GCMRegistrar.getRegistrationId(this));
     regId = GCMRegistrar.getRegistrationId(this);
   } else {
     Log.d("info", "already registered as" + regId);
   }
   prefsEditor.putString(AppConstants.PREFPUSHREGISTRATIONID, regId);
   Log.d("info", regId);
   prefsEditor.commit();
 }
Exemplo n.º 6
0
 private void registerForPush() {
   GCMRegistrar.checkDevice(this);
   GCMRegistrar.checkManifest(this);
   REG_ID = GCMRegistrar.getRegistrationId(this);
   if (REG_ID.equals("")) {
     GCMRegistrar.register(this, "336168193323");
   } else {
     System.out.println("Already Registered");
   }
 }
Exemplo n.º 7
0
  private void initGCM() {
    try {
      // Make sure the device has the proper dependencies.
      GCMRegistrar.checkDevice(this);

      final String regId = GCMRegistrar.getRegistrationId(this);
      if (regId.equals("")) {
        // Automatically registers application on startup.
        GCMRegistrar.register(this, SENDER_ID);
      }
    } catch (Exception e) {
      EasyTracker.getTracker().trackException("cannot init GCM", e, false);
    }
  }
    @Override
    public void run() {
      final Context context = SuperManActivity_No_Pusher.this;
      CommonUtilities.UUID = UUID;
      // Make sure the device has the proper dependencies.
      GCMRegistrar.checkDevice(context);
      // while developing the app, then uncomment it when it's ready.
      GCMRegistrar.checkManifest(context);
      registerReceiver(mHandleMessageReceiver, new IntentFilter(DISPLAY_MESSAGE_ACTION));
      final String regId = GCMRegistrar.getRegistrationId(context);
      Log.e(TAG, "regId: " + regId);
      if (regId.equals("")) {
        // Automatically registers application on startup.
        mRegisterTask =
            new AsyncTask<Void, Void, Void>() {

              @Override
              protected Void doInBackground(Void... params) {
                GCMRegistrar.register(context, SENDER_ID);
                return null;
              }

              @Override
              protected void onPostExecute(Void result) {
                mRegisterTask = null;
              }
            };
        mRegisterTask.execute(null, null, null);
      } else {
        // Device is already registered on GCM, check server.
        if (GCMRegistrar.isRegisteredOnServer(context)) {
          mRegisterTask =
              new AsyncTask<Void, Void, Void>() {

                @Override
                protected Void doInBackground(Void... params) {
                  ServerUtilities.register(context, regId);
                  return null;
                }

                @Override
                protected void onPostExecute(Void result) {
                  mRegisterTask = null;
                }
              };
          mRegisterTask.execute(null, null, null);
        }
      }
    }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Register application for Google Cloud Messaging
    GCMRegistrar.checkDevice(this);
    GCMRegistrar.checkManifest(this); // Remove in production
    final String regId = GCMRegistrar.getRegistrationId(this);
    if (regId.equals("")) {
      GCMRegistrar.register(this, Utils.SENDER_ID);
    } else {
      Log.v(TAG, "Already registered");
    }

    setContentView(R.layout.messages);
  }
Exemplo n.º 10
0
        @Override
        public void onClick(View v) {
          if (!status.getText().toString().equals("")) {
            lon = loc.getLongitude();
            lat = loc.getLatitude();

            sendUpdateStatus(
                GCMRegistrar.getRegistrationId(MainActivity.this),
                status.getText().toString(),
                Double.toString(lat),
                Double.toString(lon));
          } else {
            Toast.makeText(MainActivity.this, getString(R.string.status_blank), Toast.LENGTH_LONG)
                .show();
          }
        }
  protected void registerGCM() {
    try {
      String senderId = app.getAppJsonSetting().getSenderId();
      // GCM registration process
      GCMRegistrar.checkDevice(this);
      GCMRegistrar.checkManifest(this);
      final String regId = GCMRegistrar.getRegistrationId(this);
      if (regId.equals("")) {
        GCMRegistrar.register(this, senderId);
      } else {
        ((MonacaApplication) getApplication()).sendGCMRegisterIdToAppAPI(regId);
      }

    } catch (Exception e) {
      MyLog.d(TAG, "this device or application does not support GCM");
      e.printStackTrace();
    }
  }
  public static void getPushNotificationSettings(
      Context context, RestRequest.Listener listener, RestRequest.ErrorListener errorListener) {
    if (!WordPress.hasValidWPComCredentials(context)) {
      return;
    }

    String gcmToken = GCMRegistrar.getRegistrationId(context);
    if (TextUtils.isEmpty(gcmToken)) {
      return;
    }

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    String deviceID = settings.getString(WPCOM_PUSH_DEVICE_SERVER_ID, null);
    if (TextUtils.isEmpty(deviceID)) {
      AppLog.e(T.NOTIFS, "device_ID is null in preferences. Get device settings skipped.");
      return;
    }

    WordPress.getRestClientUtils().get("/device/" + deviceID, listener, errorListener);
  }
Exemplo n.º 13
0
 /**
  * Check if user has valid credentials, and that at least 2 minutes are passed since the last
  * ping, then try to update the PN token.
  */
 private void updatePushNotificationTokenIfNotLimited() {
   // Synch Push Notifications settings
   if (isPushNotificationPingNeeded() && AccountHelper.isSignedInWordPressDotCom()) {
     String token = null;
     try {
       // Register for Google Cloud Messaging
       GCMRegistrar.checkDevice(mContext);
       GCMRegistrar.checkManifest(mContext);
       token = GCMRegistrar.getRegistrationId(mContext);
       String gcmId = BuildConfig.GCM_ID;
       if (gcmId == null || token == null || token.equals("")) {
         AppLog.e(T.NOTIFS, "Could not ping the PNs backend, Token or gmcID not found");
       } else {
         // Send the token to WP.com
         NotificationsUtils.registerDeviceForPushNotifications(mContext, token);
       }
     } catch (Exception e) {
       AppLog.e(T.NOTIFS, "Could not ping the PNs backend: " + e.getMessage());
     }
   }
 }
Exemplo n.º 14
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    GCMRegistrar.checkDevice(this);
    GCMRegistrar.checkManifest(this);

    setContentView(R.layout.main);
    tv_sender_nickname = (TextView) findViewById(R.id.sender_nickname);
    tv_recipients_nickname = (TextView) findViewById(R.id.recipients_nickname);
    tv_message = (TextView) findViewById(R.id.message);
    btn_read_more_button = (Button) findViewById(R.id.read_more_button);

    final String regId = GCMRegistrar.getRegistrationId(this);
    Log.i(debugAppTag, "registration id ==  " + regId);

    if (regId.equals("")) {
      GCMRegistrar.register(this, ApplicationContext.getSenderID());
    } else {
      Log.v(debugAppTag, "Already registered");
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    cd = new ConnectionDetector(getApplicationContext());

    // Check if Internet present
    if (!cd.isConnectingToInternet()) {
      // Internet Connection is not present
      alert.showAlertDialog(
          RegisterActivity.this,
          "Internet Connection Error",
          "Please connect to working Internet connection",
          false);
      // stop executing code by return
      return;
    }

    // Check if GCM configuration is set
    if (SERVER_URL == null
        || SENDER_ID == null
        || SERVER_URL.length() == 0
        || SENDER_ID.length() == 0) {
      // GCM sernder id / server url is missing
      alert.showAlertDialog(
          RegisterActivity.this,
          "Configuration Error!",
          "Please set your Server URL and GCM Sender ID",
          false);
      // stop executing code by return
      return;
    }

    // Make sure the device has the proper dependencies.
    GCMRegistrar.checkDevice(this);

    // Make sure the manifest was properly set - comment out this line
    // while developing the app, then uncomment it when it's ready.
    GCMRegistrar.checkManifest(this);

    String reg_id = GCMRegistrar.getRegistrationId(this);

    // Check if regid already presents
    if (!reg_id.equals("")) {
      Intent i = new Intent(getApplicationContext(), MainActivity.class);
      startActivity(i);
      finish();
    }

    txtName = (EditText) findViewById(R.id.txtName);
    txtEmail = (EditText) findViewById(R.id.txtEmail);
    btnRegister = (Button) findViewById(R.id.btnRegister);

    /*
     * Click event on Register button
     * */
    btnRegister.setOnClickListener(
        new View.OnClickListener() {

          public void onClick(View arg0) {
            // Read EditText dat
            String name = txtName.getText().toString();
            String email = txtEmail.getText().toString();

            // Check if user filled the form
            if (name.trim().length() > 0 && email.trim().length() > 0) {
              // Launch Main Activity
              Intent i = new Intent(getApplicationContext(), MainActivity.class);

              // Registering user on our server
              // Sending registraiton details to MainActivity
              i.putExtra("name", name);
              i.putExtra("email", email);
              startActivity(i);
              finish();
            } else {
              // user doen't filled that data
              // ask him to fill the form
              alert.showAlertDialog(
                  RegisterActivity.this, "Registration Error!", "Please enter your details", false);
            }
          }
        });
  }
  public void init(Context cnt, String tkn, String appid, String ServerUrl)
      throws CommunicatorConnectorException {
    mContext = cnt.getApplicationContext();
    mUserAuthToken = tkn;

    mAppId = appid;
    mServerUrl = ServerUrl;

    CommunicatorConnector mConnector = null;
    try {
      mConnector = new CommunicatorConnector(mServerUrl, mAppId);

      String regId = "";
      // This registerClient() method checks the current device,
      // checks the
      // manifest for the appropriate rights, and then retrieves a
      // registration id
      // from the GCM cloud. If there is no registration id,
      // GCMRegistrar will
      // register this device for the specified project, which will
      // return a
      // registration id.
      // Check that the device supports GCM (should be in a try /
      // catch)
      GCMRegistrar.checkDevice(mContext);

      // Check the manifest to be sure this app has all the
      // required
      // permissions.
      GCMRegistrar.checkManifest(mContext);

      // Get the existing registration id, if it exists.
      regId = GCMRegistrar.getRegistrationId(mContext);

      if (regId.equals("")) {
        if (mConnector != null) {
          Map<String, Object> mapKey =
              mConnector.requestPublicConfigurationToPush("core.mobility", mUserAuthToken);

          // find senderid
          String senderid = String.valueOf(mapKey.get("GCM_SENDER_ID"));
          // register this device for this project
          //					senderid= "220741898329";
          GCMRegistrar.register(mContext, senderid);
          regId = GCMRegistrar.getRegistrationId(mContext);
          if (regId != null && regId.length() > 0) {
            UserSignature signUserSignature = new UserSignature();
            signUserSignature.setAppName("core.mobility");
            signUserSignature.setRegistrationId(regId);
            mConnector.registerUserToPush(signUserSignature, "core.mobility", mUserAuthToken);
          }
        }
      } else {
        // Already registered;
      }

      Log.i("GCM_REGID:", regId);
    } catch (Exception e) {
      Log.e(TAG, e.toString());
    }
  }
Exemplo n.º 17
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main_menu);
    login = getSharedPreferences("mec-data", 0);
    Log.d("Shr-Login", "username: "******"username", ""));
    Log.d("Shr-Login", "password: "******"password", ""));
    // GCM
    checkNotNull(SERVER_URL, "SERVER_URL");
    checkNotNull(SENDER_ID, "SENDER_ID");
    // Make sure the device has the proper dependencies.
    GCMRegistrar.checkDevice(this);
    // Make sure the manifest was properly set - comment out this line
    // while developing the app, then uncomment it when it's ready.
    GCMRegistrar.checkManifest(this);
    // setContentView(R.layout.main_menu);
    // hr = (TextView) findViewById(R.id.Hari);
    registerReceiver(mHandleMessageReceiver, new IntentFilter(DISPLAY_MESSAGE_ACTION));
    final String regId = GCMRegistrar.getRegistrationId(this);

    if (regId.equals("")) {
      // Automatically registers application on startup.
      GCMRegistrar.register(getApplicationContext(), SENDER_ID);
    } else {
      // Device is already registered on GCM, check server.
      if (GCMRegistrar.isRegisteredOnServer(this)) {
        // Skips registration.
        // hr.append(getString(R.string.already_registered) + "\n");
      } else {
        // Try to register again, but not in the UI thread.
        // It's also necessary to cancel the thread onDestroy(),
        // hence the use of AsyncTask instead of a raw thread.
        final Context context = this;
        mRegisterTask =
            new AsyncTask<Void, Void, Void>() {
              private ProgressDialog pDialog;
              protected Context applicationContext;

              @Override
              protected void onPreExecute() {
                super.onPreExecute();
                pDialog = new ProgressDialog(MainMenu.this);
                pDialog.setMessage("Registering device. Please wait...");
                pDialog.setIndeterminate(false);
                pDialog.setCancelable(false);
                pDialog.show();
              }

              @Override
              protected Void doInBackground(Void... params) {
                boolean registered = ServerUtilities.register(context, regId);
                // At this point all attempts to register with the app
                // server failed, so we need to unregister the device
                // from GCM - the app will try to register again when
                // it is restarted. Note that GCM will send an
                // unregistered callback upon completion, but
                // GCMIntentService.onUnregistered() will ignore it.
                if (!registered) {
                  GCMRegistrar.unregister(context);
                }
                return null;
              }

              @Override
              protected void onPostExecute(Void result) {
                mRegisterTask = null;
                pDialog.dismiss();
              }
            };
        mRegisterTask.execute(null, null, null);
      }
    }
    // END GCM
    View tugasButton = findViewById(R.id.tugas_button);
    tugasButton.setOnClickListener(this);
    View logoutButton = findViewById(R.id.logout_button);
    logoutButton.setOnClickListener(this);
    View exitButton = findViewById(R.id.exit_button);
    exitButton.setOnClickListener(this);
    /*View jadwalButton=findViewById(R.id.jadwal_button);
    jadwalButton.setOnClickListener(this);

    bv = (TextView) findViewById(R.id.jadwal_button);
    hr = (TextView) findViewById(R.id.Hari);*/
    // registerForContextMenu((View) findViewById(R.id.jadwal_button));
  }
  public static void setPushNotificationSettings(Context context) {
    if (!WordPress.hasValidWPComCredentials(context)) {
      return;
    }

    String gcmToken = GCMRegistrar.getRegistrationId(context);
    if (TextUtils.isEmpty(gcmToken)) {
      return;
    }

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    String deviceID = settings.getString(WPCOM_PUSH_DEVICE_SERVER_ID, null);
    if (TextUtils.isEmpty(deviceID)) {
      AppLog.e(T.NOTIFS, "device_ID is null in preferences. Set device settings skipped.");
      return;
    }

    String settingsJson = settings.getString(WPCOM_PUSH_DEVICE_NOTIFICATION_SETTINGS, null);
    if (settingsJson == null) return;

    Gson gson = new Gson();
    Map<String, StringMap<String>> notificationSettings =
        gson.fromJson(settingsJson, HashMap.class);
    Map<String, Object> updatedSettings = new HashMap<String, Object>();
    if (notificationSettings == null) return;

    // Build the settings object to send back to WP.com
    StringMap<?> mutedBlogsMap = notificationSettings.get("muted_blogs");
    StringMap<?> muteUntilMap = notificationSettings.get("mute_until");
    ArrayList<StringMap<Double>> blogsList =
        (ArrayList<StringMap<Double>>) mutedBlogsMap.get("value");
    notificationSettings.remove("muted_blogs");
    notificationSettings.remove("mute_until");

    for (Map.Entry<String, StringMap<String>> entry : notificationSettings.entrySet()) {
      StringMap<String> setting = entry.getValue();
      updatedSettings.put(entry.getKey(), setting.get("value"));
    }

    if (muteUntilMap != null && muteUntilMap.get("value") != null) {
      updatedSettings.put("mute_until", muteUntilMap.get("value"));
    }

    ArrayList<StringMap<Double>> mutedBlogsList = new ArrayList<StringMap<Double>>();
    for (StringMap<Double> userBlog : blogsList) {
      if (MapUtils.getMapBool(userBlog, "value")) {
        mutedBlogsList.add(userBlog);
      }
    }

    if (updatedSettings.size() == 0 && mutedBlogsList.size() == 0) return;

    updatedSettings.put(
        "muted_blogs",
        mutedBlogsList); // If muted blogs list is unchanged we can even skip this assignment.

    Map<String, String> contentStruct = new HashMap<String, String>();
    contentStruct.put("device_token", gcmToken);
    contentStruct.put("device_family", "android");
    contentStruct.put("app_secret_key", NotificationUtils.getAppPushNotificationsName());
    contentStruct.put("settings", gson.toJson(updatedSettings));
    WordPress.getRestClientUtils().post("/device/" + deviceID, contentStruct, null, null, null);
  }
  @SuppressLint("NewApi")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_authentication);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setCustomView(R.layout.custom_sherlock_bar);
    View homeIcon =
        findViewById(
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
                ? android.R.id.home
                : R.id.abs__home);
    ((View) homeIcon.getParent()).setVisibility(View.GONE);

    this.activity = AuthenticationActivity.this;
    this.context = AuthenticationActivity.this;
    deviceType = getResources().getString(R.string.device_enroll_type_byod);
    // txtLoadingEULA = (TextView)findViewById(R.id.txtLoadingEULA);
    txtDomain = (EditText) findViewById(R.id.txtDomain);
    username = (EditText) findViewById(R.id.editText1);
    password = (EditText) findViewById(R.id.editText2);
    radioBYOD = (RadioButton) findViewById(R.id.radioBYOD);
    radioCOPE = (RadioButton) findViewById(R.id.radioCOPE);
    txtDomain.setFocusable(true);
    txtDomain.requestFocus();
    if (CommonUtilities.DEBUG_MODE_ENABLED) {
      Log.v("check first username", username.getText().toString());
      Log.v("check first password", password.getText().toString());
    }
    AsyncTask<Void, Void, Void> mRegisterTask;
    authenticate = (Button) findViewById(R.id.btnRegister);
    authenticate.setEnabled(false);
    authenticate.setTag(TAG_BTN_AUTHENTICATE);
    authenticate.setOnClickListener(onClickListener_BUTTON_CLICKED);
    authenticate.setBackground(getResources().getDrawable(R.drawable.btn_grey));
    authenticate.setTextColor(getResources().getColor(R.color.black));
    /*txtLoadingEULA.setVisibility(View.VISIBLE);
    username.setVisibility(View.GONE);
    password.setVisibility(View.GONE);
    authenticate.setVisibility(View.GONE);*/

    DeviceInfo deviceInfo = new DeviceInfo(AuthenticationActivity.this);

    /*
     * optionBtn = (ImageView) findViewById(R.id.option_button);
     * optionBtn.setTag(TAG_BTN_OPTIONS);
     * optionBtn.setOnClickListener(onClickListener_BUTTON_CLICKED);
     */

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      if (extras.containsKey(getResources().getString(R.string.intent_extra_regid))) {
        regId = extras.getString(getResources().getString(R.string.intent_extra_regid));
      }
    }
    if (regId == null || regId.equals("")) {
      regId = GCMRegistrar.getRegistrationId(this);
    }

    username.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            enableSubmitIfReady();
          }

          @Override
          public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
            enableSubmitIfReady();
          }
        });

    password.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            enableSubmitIfReady();
          }

          @Override
          public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
            enableSubmitIfReady();
          }
        });
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gcm);

    cd = new ConnectionDetector(getApplicationContext());

    if (!cd.isConnectingToInternet()) {

      alert.showAlertDialog(
          ActivityGCM.this,
          "Internet Connection Error",
          "Please connect to working Internet connection",
          false);

      return;
    }

    Intent i = getIntent();

    name = i.getStringExtra("name");
    email = i.getStringExtra("email");

    GCMRegistrar.checkDevice(this);

    GCMRegistrar.checkManifest(this);

    lblMessage = (TextView) findViewById(R.id.lblMessage);

    registerReceiver(mHandleMessageReceiver, new IntentFilter(DISPLAY_MESSAGE_ACTION));

    final String regId = GCMRegistrar.getRegistrationId(this);

    if (regId.equals("")) {

      GCMRegistrar.register(this, SENDER_ID);
    } else {

      if (GCMRegistrar.isRegisteredOnServer(this)) {

        Toast.makeText(getApplicationContext(), "Already registered with GCM", Toast.LENGTH_LONG)
            .show();
      } else {

        final Context context = this;
        mRegisterTask =
            new AsyncTask<Void, Void, Void>() {

              @Override
              protected Void doInBackground(Void... params) {

                ServerUtilities.register(context, name, email, regId);
                return null;
              }

              @Override
              protected void onPostExecute(Void result) {
                mRegisterTask = null;
              }
            };
        mRegisterTask.execute(null, null, null);
      }
    }
  }
Exemplo n.º 21
0
  /**
   * Register the username, email, and device ID information in the database.
   *
   * @param name Name of the user
   * @param email Email of the user
   */
  void register(final String name, final String email) {

    cd = new ConnectionDetector(getApplicationContext());

    // Check if Internet present
    if (!cd.isConnectingToInternet()) {
      // Internet Connection is not present
      alert.showAlertDialog(
          "Internet Connection Error", "Please connect to working Internet connection", false);
      // stop executing code by return
      // return;
    }

    // Make sure the device has the proper dependencies.
    GCMRegistrar.checkDevice(this);

    // Make sure the manifest was properly set - comment out this line
    // while developing the app, then uncomment it when it's ready.
    GCMRegistrar.checkManifest(this);

    // lblMessage = (TextView) findViewById(R.id.lblMessage);

    // registerReceiver(mHandleMessageReceiver, new IntentFilter(
    // DISPLAY_MESSAGE_ACTION));

    // Get GCM registration id
    final String regId = GCMRegistrar.getRegistrationId(this);

    // Check if regid already presents
    if (regId.equals("")) {
      // Registration is not present, register now with GCM
      Log.i(TAG, "regId is empty");
      GCMRegistrar.register(this, SENDER_ID);
    } else {
      // Device is already registered on GCM
      if (GCMRegistrar.isRegisteredOnServer(this)) {
        // Skips registration.
        Toast.makeText(getApplicationContext(), "Already registered with GCM", Toast.LENGTH_LONG)
            .show();
      } else {
        // Try to register again, but not in the UI thread.
        // It's also necessary to cancel the thread onDestroy(),
        // hence the use of AsyncTask instead of a raw thread.
        final Context context = this;
        mRegisterTask =
            new AsyncTask<Void, Void, Boolean>() {
              @Override
              protected Boolean doInBackground(Void... params) {
                // Register on our server
                // On server creates a new user
                Log.i(TAG, "Calling register from AsyncTask in RegisterActivity");
                boolean res = ServerUtilities.register(context, name, email, regId);

                Log.d(TAG, "Got here");
                if (res) {
                  Log.d(TAG, "successful registration");
                  Intent homeScreen =
                      new Intent(getApplicationContext(), LocalizationActivity.class);
                  startActivity(homeScreen);

                  return true;
                } else {
                  Log.d(TAG, "unsuccessful registration");
                }
                return false;
              }

              @Override
              protected void onPostExecute(Boolean result) {
                mRegisterTask = null;
              }
            };
        mRegisterTask.execute(null, null, null);
      }
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_screen);

    cd = new ConnectionDetector(getApplicationContext());

    // Check if Internet present
    if (!cd.isConnectingToInternet()) {
      // Internet Connection is not present
      alert.showAlertDialog(
          MainScreenActivity.this,
          "Internet Connection Error",
          "Please connect to working Internet connection",
          false);
      // stop executing code by return
      return;
    }

    Intent i = getIntent();
    name = i.getStringExtra("name");
    email = i.getStringExtra("email");

    // Make sure the device has the proper dependencies.
    GCMRegistrar.checkDevice(this);

    // Make sure the manifest was properly set - comment out this line
    // while developing the app, then uncomment it when it's ready.
    GCMRegistrar.checkManifest(this);

    lblMessage = (TextView) findViewById(R.id.lblMessage);

    registerReceiver(mHandleMessageReceiver, new IntentFilter(DISPLAY_MESSAGE_ACTION));

    // Get GCM registration id
    final String regId = GCMRegistrar.getRegistrationId(this);

    // Check if regid already presents
    if (regId.equals("")) {
      // Registration is not present, register now with GCM
      GCMRegistrar.register(this, SENDER_ID);
    } else {
      // Device is already registered on GCM
      if (GCMRegistrar.isRegisteredOnServer(this)) {
        // Skips registration.
        Toast.makeText(
                getApplicationContext(), "Registration with server is verified!", Toast.LENGTH_LONG)
            .show();
      } else {
        // Try to register again, but not in the UI thread.
        // It's also necessary to cancel the thread onDestroy(),
        // hence the use of AsyncTask instead of a raw thread.
        final Context context = this;
        mRegisterTask =
            new AsyncTask<Void, Void, Void>() {
              @Override
              protected Void doInBackground(Void... params) {
                // Register on our server
                // On server creates a new user
                ServerUtilities.register(context, name, email, regId);
                return null;
              }

              @Override
              protected void onPostExecute(Void result) {
                mRegisterTask = null;
              }
            };
        mRegisterTask.execute(null, null, null);
      }
    }

    File folder = new File(Environment.getExternalStorageDirectory() + "/itmpdf");

    if (!folder.exists()) {
      success = folder.mkdirs();
      if (success) {
        Log.i("directory created", "directory created");
      } else {
        Log.i("directory not created", "directory not created");
      }
    } else {
      Log.i("Directorylog", "Directory ALready Exists");
    }

    // Buttons
    btnViewResults = (ImageButton) findViewById(R.id.btnViewResults);
    btnViewEvents = (ImageButton) findViewById(R.id.btnViewNotices);
    btnViewAnnounce = (ImageButton) findViewById(R.id.btnViewAnnounce);
    btntt = (ImageButton) findViewById(R.id.btntt);
    btntalky = (ImageButton) findViewById(R.id.btntalky);
    btnabt = (ImageButton) findViewById(R.id.btnabt);
    dwnmanager = (ImageButton) findViewById(R.id.dwnmanager);
    ImageButton ratemyapp = (ImageButton) findViewById(R.id.ratemyapp);

    btnViewResults.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), AllResultsActivity.class);
            startActivity(i);
          }
        });

    btnViewEvents.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), AllEventsActivity.class);
            startActivity(i);
          }
        });

    btnViewAnnounce.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), AllAnnActivity.class);
            startActivity(i);
          }
        });

    btntt.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), TimetableActivity.class);
            startActivity(i);
          }
        });

    btntalky.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), TalkyLaunchActivity.class);
            startActivity(i);
          }
        });

    btnabt.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), AllAbtActivity.class);
            startActivity(i);
          }
        });

    dwnmanager.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), ScanPdf.class);
            startActivity(i);
          }
        });

    ratemyapp.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Uri uri = Uri.parse("market://details?id=" + getPackageName());
            Log.i("URI", uri.toString());
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
            try {
              startActivity(goToMarket);
            } catch (ActivityNotFoundException e) {
              Toast.makeText(getBaseContext(), "Couldn't launch the market", Toast.LENGTH_LONG)
                  .show();
            }
          }
        });
  }
Exemplo n.º 23
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_gcm);

    cd = new ConnectionDetector(getApplicationContext());

    // Check if Internet present
    if (!cd.isConnectingToInternet()) {
      // Internet Connection is not present
      alert.showDialog(
          TestGCMActivity.this,
          "Internet Connection Error",
          "Please connect to working Internet connection",
          false);
      // stop executing code by return
      return;
    }

    // Getting name, email from intent
    Intent i = getIntent();

    name = i.getStringExtra("name");
    email = i.getStringExtra("email");

    GCMRegistrar.checkDevice(this);
    // GCMRegistrar.checkManifest(this);

    // lblMessage = (TextView) findViewById(R.id.lblMessage);

    registerReceiver(mHandleMessageReceiver, new IntentFilter(DISPLAY_MESSAGE_ACTION));

    // Get GCM registration id
    final String regId = GCMRegistrar.getRegistrationId(this);

    // Check if regid already presents
    if (regId.equals("")) {
      // Registration is not present, register now with GCM
      GCMRegistrar.register(this, SENDER_ID);
    } else {
      // Device is already registered on GCM
      if (GCMRegistrar.isRegisteredOnServer(this)) {
        // Skips registration.
        Toast.makeText(getApplicationContext(), "Already registered with GCM", Toast.LENGTH_LONG)
            .show();
      } else {
        // Try to register again, but not in the UI thread.
        // It's also necessary to cancel the thread onDestroy(),
        // hence the use of AsyncTask instead of a raw thread.
        final Context context = this;
        mRegisterTask =
            new AsyncTask<Void, Void, Void>() {

              @Override
              protected Void doInBackground(Void... params) {
                // Register on our server
                // On server creates a new user
                ServerUtilities.register(context, name, email, regId);
                return null;
              }

              @Override
              protected void onPostExecute(Void result) {
                mRegisterTask = null;
              }
            };
        mRegisterTask.execute(null, null, null);
      }
    }
  }
Exemplo n.º 24
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Make sure the device has the proper dependencies.
    GCMRegistrar.checkDevice(this);
    // Make sure the manifest was properly set - comment out this line
    // while developing the app, then uncomment it when it's ready.
    GCMRegistrar.checkManifest(this);
    setContentView(R.layout.activity_main);

    registerReceiver(mHandleMessageReceiver, new IntentFilter(EXTRA_MESSAGE));
    registrationID = GCMRegistrar.getRegistrationId(this);
    System.out.println("GCM Reg Id is = " + registrationID);
    if (registrationID.equals("")) {
      // Automatically registers application on startup.
      System.out.println("2 GCM Reg Id is = " + registrationID);
      GCMRegistrar.register(this, SENDER_ID);
      System.out.println("3 GCM Reg Id is = " + registrationID);
    } else {
      // Device is already registered on GCM, check server.
      if (GCMRegistrar.isRegisteredOnServer(this)) {
        // Skips registration.
        System.out.println(getString(R.string.already_registered) + "\n");
      } else {
        // Try to register again, but not in the UI thread.
        // It's also necessary to cancel the thread onDestroy(),
        // hence the use of AsyncTask instead of a raw thread.
        final Context context = this;
        mRegisterTask =
            new AsyncTask<Void, Void, Void>() {

              @Override
              protected Void doInBackground(Void... params) {
                ServerUtilities.register(context, registrationID);
                return null;
              }

              @Override
              protected void onPostExecute(Void result) {
                mRegisterTask = null;
              }
            };
        mRegisterTask.execute(null, null, null);
      }
    }

    /*-----------------------------------------------------------------
     *
     *    Bottom Button Bar Page Switching Function
     *
     *-----------------------------------------------------------------*/

    Button logIn = (Button) findViewById(R.id.login);
    logIn.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), LoginActivity.class);
            startActivityForResult(myIntent, 0);
          }
        });

    Button accountLogIn = (Button) findViewById(R.id.account_login);
    accountLogIn.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), LoginActivity.class);
            startActivityForResult(myIntent, 0);
          }
        });
    Button homePage = (Button) findViewById(R.id.home_page);
    homePage.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), MainActivity.class);
            startActivityForResult(myIntent, 0);
          }
        });

    testQuery();
  }