Example #1
0
  protected void onStop() {
    super.onStop();
    App42API.initialize(
        getApplicationContext(),
        "33febecb03a579e972755eccde307dd94a279b5cfe348f845b8762f8e3feb2d6",
        "b5be405b4e76d40a94cdc01250311205b5a7c7b2dc4d003714f24d0df3e219f8");

    final UserService userService = App42API.buildUserService();
    App42API.setOfflineStorage(true);
    String username = mGameSettings.getString(GAME_PREFERENCES_USERNAME, null);
    String schl = mGameSettings.getString(GAME_PREFERENCES_SCHOOL, null);
    App42API.setLoggedInUser(username);
    String p = mGameSettings.getString(GAME_PREFERENCES_PASSWORD, null);
    String strEmailToSave = mGameSettings.getString(GAME_PREFERENCES_EMAIL, null);
    String pwd = p;
    String emailId = strEmailToSave;
    /* This will create user in App42 cloud and will return created User
    object in onSuccess callback method */
    userService.createUser(
        username,
        pwd,
        emailId,
        new App42CallBack() {
          public void onSuccess(Object response) {
            User user = (User) response;
            System.out.println("userName is " + user.getUserName());
            System.out.println("emailId is " + user.getEmail());
          }

          public void onException(Exception ex) {
            System.out.println("Exception Message" + ex.getMessage());
          }
        });

    User userObj = new User();
    userObj.setUserName(username);
    Profile profile = userObj.new Profile();
    Date date = new Date(); /* returns the current date object.User can set any date */
    profile.setFirstName(username);
    profile.setLine1(schl);
    /* Following will create user profile and returns User object
    which has profile object inside in onSuccess callback method */
    userService.createOrUpdateProfile(
        userObj,
        new App42CallBack() {
          public void onSuccess(Object response) {
            User user = (User) response;
            System.out.println("userName is " + user.getUserName());
            System.out.println("School  is " + user.getProfile().getLine1());
          }

          public void onException(Exception ex) {
            System.out.println("Exception Message" + ex.getMessage());
          }
        });
    Toast.makeText(getApplicationContext(), "User Settings Saved", Toast.LENGTH_SHORT).show();
    UtilSettings.this.finish();
  }
Example #2
0
  private void saveAvatar(Bitmap avatar) {
    // TODO: Save the Bitmap as a local file called avatar.jpg
    String strAvatarFilename = "avatar.jpg";
    try {
      avatar.compress(CompressFormat.JPEG, 100, openFileOutput(strAvatarFilename, MODE_PRIVATE));
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    // TODO: Determine the Uri to the local avatar.jpg file

    // TODO: Save the Uri path as a String preference
    Uri imageUri = Uri.fromFile(new File(getFilesDir(), strAvatarFilename));
    // TODO: Update the ImageButton with the new image
    ImageButton ava = (ImageButton) findViewById(R.id.avatar);

    ava.setImageURI(imageUri);
    String curimg = imageUri.getPath().toString();

    Editor edit = mGameSettings.edit();
    edit.putString(GAME_PREFERENCES_AVATAR, curimg);
    edit.commit();

    String userName = mGameSettings.getString(GAME_PREFERENCES_USERNAME, null);
    String avatarName = userName + "Avatar";
    String filePath = curimg;
    String description = "My player avatar ";
    App42API.initialize(
        this,
        "33febecb03a579e972755eccde307dd94a279b5cfe348f845b8762f8e3feb2d6",
        "b5be405b4e76d40a94cdc01250311205b5a7c7b2dc4d003714f24d0df3e219f8");
    AvatarService avatarService = App42API.buildAvatarService();
    App42API.setOfflineStorage(true);
    avatarService.createAvatar(
        avatarName,
        userName,
        filePath,
        description,
        new App42CallBack() {
          public void onSuccess(Object response) {
            Avatar avatar = (Avatar) response;
            System.out.println("avatarName is :" + avatar.getName());
            System.out.println("url is :" + avatar.getURL());
            System.out.println("tinyUrl is :" + avatar.getTinyURL());
            System.out.println("createdOn is :" + avatar.getCreatedOn());
            System.out.println("Description is :" + avatar.getDescription());
            System.out.println("Is Current :" + avatar.isCurrent());
            System.out.println("UserName is :" + avatar.getUserName());
          }

          public void onException(Exception ex) {
            System.out.println("Exception Message" + ex.getMessage());
          }
        });
  }
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   super.requestWindowFeature(Window.FEATURE_NO_TITLE);
   setContentView(R.layout.activity_main);
   responseTv = ((TextView) findViewById(R.id.response_msg));
   edUserName = ((EditText) findViewById(R.id.uname));
   edMessage = ((EditText) findViewById(R.id.message));
   buildSpinnerLayout();
   App42API.initialize(this, "Your API Key", "Your Secret Key");
   App42Log.setDebug(true);
   // UserName You want to register on App42
   App42API.setLoggedInUser("YourUserName");
 }
Example #4
0
  private void registerWithApp42(String regId) {
    App42Log.debug(" Registering on Server ....");
    App42API.buildPushNotificationService()
        .storeDeviceToken(
            App42API.getLoggedInUser(),
            regId,
            new App42CallBack() {
              @Override
              public void onSuccess(Object paramObject) {
                // TODO Auto-generated method stub
                App42Log.debug(" ..... Registeration Success ....");
                GCMRegistrar.setRegisteredOnServer(App42API.appContext, true);
              }

              @Override
              public void onException(Exception paramException) {
                App42Log.debug(" ..... Registeration Failed ....");
                App42Log.debug("storeDeviceToken :  Exception : on start up " + paramException);
              }
            });
  }
Example #5
0
  private void uploadScoresleaderboard() {

    final ListView listView = (ListView) findViewById(android.R.id.list);
    App42Log.setDebug(true);

    String gameName = "Ultipedia fun";

    int max = 15;
    App42API.initialize(
        this,
        "33febecb03a579e972755eccde307dd94a279b5cfe348f845b8762f8e3feb2d6",
        "b5be405b4e76d40a94cdc01250311205b5a7c7b2dc4d003714f24d0df3e219f8");
    ScoreBoardService scoreBoardService = App42API.buildScoreBoardService();
    scoreBoardService.getTopNRankings(
        gameName,
        max,
        new App42CallBack() {
          public void onSuccess(Object response) {
            Game game = (Game) response;
            ArrayList e = game.getScoreList();

            System.out.println("Game Name is : " + game.getName());
            for (int i = 0; i < game.getScoreList().size(); i++) {
              System.out.println("userName is : " + game.getScoreList().get(i).getUserName());
              System.out.println("score is : " + game.getScoreList().get(i).getValue());
              System.out.println("Created On is  :" + game.getScoreList().get(i).getCreatedOn());
              System.out.println("scoreId is : " + game.getScoreList().get(i).getScoreId());
            }
          }

          public void onException(Exception ex) {
            System.out.println("Exception Message" + ex.getMessage());
          }
        });

    // TODO Auto-generated method stub

  }
  /**
   * This function used to register GCM device Token on AppHQ
   *
   * @param userName
   * @param deviceToen
   * @param callBack
   */
  public static void registerOnApp42(
      String userName, String deviceToen, final App42GCMListener callBack) {
    App42API.buildPushNotificationService()
        .storeDeviceToken(
            userName,
            deviceToen,
            new App42CallBack() {
              @Override
              public void onSuccess(Object arg0) {
                App42Response response = (App42Response) arg0;
                callBack.onRegisterApp42(response.getStrResponse());
              }

              @Override
              public void onException(Exception arg0) {
                // TODO Auto-generated method stub
                callBack.onApp42Response(arg0.getMessage());
              }
            });
  }
  /**
   * Send a PushMessage to desired User
   *
   * @param userName
   * @param message
   * @param callBack
   */
  public static void sendPushToUser(
      String userName, String message, final App42GCMListener callBack) {
    App42API.buildPushNotificationService()
        .sendPushMessageToUser(
            userName,
            message,
            new App42CallBack() {

              @Override
              public void onSuccess(Object arg0) {
                // TODO Auto-generated method stub
                App42Response response = (App42Response) arg0;
                callBack.onApp42Response(response.getStrResponse());
              }

              @Override
              public void onException(Exception arg0) {
                // TODO Auto-generated method stub
                callBack.onApp42Response(arg0.getMessage());
              }
            });
  }
Example #8
0
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_util_scores);
    mGameSettings = getSharedPreferences(GAME_PREFERENCES, Context.MODE_PRIVATE);
    final TabHost tbh = (TabHost) findViewById(R.id.tabhost);
    tbh.setup();
    App42API.initialize(
        this,
        "33febecb03a579e972755eccde307dd94a279b5cfe348f845b8762f8e3feb2d6",
        "b5be405b4e76d40a94cdc01250311205b5a7c7b2dc4d003714f24d0df3e219f8");

    TabSpec FunScoresTab = tbh.newTabSpec("FunTab");
    FunScoresTab.setIndicator(
        getResources().getString(R.string.Fu),
        getResources().getDrawable(android.R.drawable.star_on));
    FunScoresTab.setContent(R.id.Scrollfun);
    tbh.addTab(FunScoresTab);

    TextView d = (TextView) findViewById(R.id.nmf);
    TextView ld = (TextView) findViewById(R.id.hilvlf);
    if (mGameSettings.contains(GAME_HIGHEST_LEVEL)) {
      String hl = mGameSettings.getString(GAME_HIGHEST_LEVEL, null);
      ld.setText(hl);

    } else {
      ld.setText("Not Played");
    }
    if (mGameSettings.contains(GAME_PREFERENCES_USERNAME)) {
      String q = mGameSettings.getString(GAME_PREFERENCES_USERNAME, null);
      d.setText(q);

    } else {
      d.setText("Username not set");
    }

    TextView e = (TextView) findViewById(R.id.scoref);
    if (mGameSettings.contains(GAME_PREFERENCES_SCORE_FUN)) {
      String ght = mGameSettings.getString(GAME_PREFERENCES_SCORE_FUN, null);
      e.setText(ght);
    }

    TabSpec SchoolScoresTab = tbh.newTabSpec("SchoolTab");
    SchoolScoresTab.setIndicator(
        getResources().getString(R.string.shu),
        getResources().getDrawable(android.R.drawable.star_on));
    SchoolScoresTab.setContent(R.id.ScrollSchool);
    tbh.addTab(SchoolScoresTab);

    TextView sm = (TextView) findViewById(R.id.nmMath);

    TextView sen = (TextView) findViewById(R.id.nmeng);
    TextView sk = (TextView) findViewById(R.id.nmkis);
    TextView ssi = (TextView) findViewById(R.id.nmsci);
    TextView ssst = (TextView) findViewById(R.id.nmsst);
    TextView scr = (TextView) findViewById(R.id.nmcre);

    TextView lm = (TextView) findViewById(R.id.hilvlMath);
    TextView len = (TextView) findViewById(R.id.hilvlEng);
    TextView lk = (TextView) findViewById(R.id.hilvlKis);
    TextView lsi = (TextView) findViewById(R.id.hilvlSci);
    TextView lsst = (TextView) findViewById(R.id.hilvlSst);
    TextView lcr = (TextView) findViewById(R.id.hilvlCre);

    mGameSettings = getSharedPreferences(GAME_PREFERENCES, Context.MODE_PRIVATE);

    if (mGameSettings.contains(GAME_PREFERENCES_USERNAME)) {
      String q = mGameSettings.getString(GAME_PREFERENCES_USERNAME, null);

      sm.setText(q);
      sen.setText(q);
      sk.setText(q);
      ssi.setText(q);
      ssst.setText(q);
      scr.setText(q);

    } else {

      sm.setText("Username not set");
      sen.setText("Username not set");
      sk.setText("Username not set");
      ssi.setText("Username not set");
      ssst.setText("Username not set");
      scr.setText("Username not set");
    }

    if (mGameSettings.contains(GAME_HIGHEST_LEVEL_MATH)) {
      String hlM = mGameSettings.getString(GAME_HIGHEST_LEVEL_MATH, null);
      lm.setText(hlM);

    } else {
      lm.setText("Not Played");
    }
    if (mGameSettings.contains(GAME_HIGHEST_LEVEL_ENG)) {
      String hlEng = mGameSettings.getString(GAME_HIGHEST_LEVEL_ENG, null);
      len.setText(hlEng);

    } else {
      len.setText("Not Played");
    }
    if (mGameSettings.contains(GAME_HIGHEST_LEVEL_KIS)) {
      String hlKis = mGameSettings.getString(GAME_HIGHEST_LEVEL_KIS, null);
      lk.setText(hlKis);

    } else {
      lk.setText("Not Played");
    }
    if (mGameSettings.contains(GAME_HIGHEST_LEVEL_SCI)) {
      String hlSci = mGameSettings.getString(GAME_HIGHEST_LEVEL_SCI, null);
      lsi.setText(hlSci);

    } else {
      lsi.setText("Not Played");
    }
    if (mGameSettings.contains(GAME_HIGHEST_LEVEL_SOCI)) {
      String hlSS = mGameSettings.getString(GAME_HIGHEST_LEVEL_SOCI, null);
      lsst.setText(hlSS);

    } else {
      lsst.setText("Not Played");
    }
    if (mGameSettings.contains(GAME_HIGHEST_LEVEL_CRE)) {
      String hlCre = mGameSettings.getString(GAME_HIGHEST_LEVEL_CRE, null);
      lcr.setText(hlCre);

    } else {
      lcr.setText("Not Played");
    }

    TextView m = (TextView) findViewById(R.id.scoreMath);
    if (mGameSettings.contains(GAME_PREFERENCES_SCORE_MATH)) {
      String sMath = mGameSettings.getString(GAME_PREFERENCES_SCORE_MATH, null);
      m.setText(sMath);

    } else {
      m.setText("Not Played");
    }
    TextView en = (TextView) findViewById(R.id.scoreeng);
    if (mGameSettings.contains(GAME_PREFERENCES_SCORE_ENG)) {
      String sEng = mGameSettings.getString(GAME_PREFERENCES_SCORE_ENG, null);
      en.setText(sEng);

    } else {
      en.setText("Not Played");
    }
    TextView k = (TextView) findViewById(R.id.scorekis);
    if (mGameSettings.contains(GAME_PREFERENCES_SCORE_KIS)) {
      String sKis = mGameSettings.getString(GAME_PREFERENCES_SCORE_KIS, null);
      k.setText(sKis);

    } else {
      k.setText("Not Played");
    }
    TextView s = (TextView) findViewById(R.id.scoresci);
    if (mGameSettings.contains(GAME_PREFERENCES_SCORE_SCI)) {
      String sSci = mGameSettings.getString(GAME_PREFERENCES_SCORE_SCI, null);
      s.setText(sSci);

    } else {
      s.setText("Not Played");
    }
    TextView sst = (TextView) findViewById(R.id.scoresst);
    if (mGameSettings.contains(GAME_PREFERENCES_SCORE_SST)) {
      String sSST = mGameSettings.getString(GAME_PREFERENCES_SCORE_SST, null);
      sst.setText(sSST);

    } else {
      sst.setText("Not Played");
    }
    TextView cr = (TextView) findViewById(R.id.scorecre);
    if (mGameSettings.contains(GAME_PREFERENCES_SCORE_CRE)) {
      String sCRE = mGameSettings.getString(GAME_PREFERENCES_SCORE_CRE, null);
      cr.setText(sCRE);

    } else {
      cr.setText("Not Played");
    }

    TabSpec LeaderBoardTab = tbh.newTabSpec("LeaderBoardTab");
    LeaderBoardTab.setIndicator(
        getResources().getString(R.string.lead),
        getResources().getDrawable(android.R.drawable.star_on));
    LeaderBoardTab.setContent(R.id.list);
    tbh.addTab(LeaderBoardTab);

    uploadScoresleaderboard();
  }
Example #9
0
 public void onCreate() {
   App42API.initialize(this, API_KEY, SECRET_KEY);
 }