コード例 #1
0
ファイル: UserProvider.java プロジェクト: palcu/wouso-extras
  /** Loads search results from server */
  private Cursor search(String query) {
    String[] columns =
        new String[] {
          BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_TEXT_2
        };
    MatrixCursor res = new MatrixCursor(columns);
    if (query == null) return null;

    query = query.toLowerCase();
    ServerResponse result = ApiHandler.getArray(ApiHandler.searchURL + query, getContext());
    JSONArray mData = result.getArrayData();
    if (mData != null)
      for (int i = 0; i < mData.length(); i++) {
        JSONObject user;
        try {
          user = mData.getJSONObject(i);
          res.addRow(
              new String[] {
                user.getString("id"), user.getString("first_name"), user.getString("last_name")
              });
        } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }

    return res;
  }
コード例 #2
0
ファイル: UserProfile.java プロジェクト: iriina/wouso-extras
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.user_profile);

    final String username = getIntent().getExtras().getString("username");

    /** Gets user info from the server */
    userInfo = new UserInfo();
    ServerResponse resp = ApiHandler.get(ApiHandler.userInfoURL, this);
    if (resp.getStatus() == false) {
      Toast.makeText(this, resp.getError(), Toast.LENGTH_SHORT).show();
      return;
    } else
      try {
        userInfo.parseContent(resp.getData());
      } catch (JSONException e) {
        Toast.makeText(this, "Server response format error.", Toast.LENGTH_SHORT).show();
        return;
      }

    // Get interface elements.
    messageButton = (Button) findViewById(R.id.usermsgbtn);
    spellButton = (Button) findViewById(R.id.userspellbtn);
    challengeButton = (Button) findViewById(R.id.userchalbtn);
    userInfoLayout = (LinearLayout) findViewById(R.id.usercontainer);
    userAvatar = (ImageView) findViewById(R.id.useravatar);
    userLevelImage = (ImageView) findViewById(R.id.userlevelimg);
    userName = (TextView) findViewById(R.id.username);
    userPoints = (TextView) findViewById(R.id.userpoints);
    userRank = (TextView) findViewById(R.id.userrank);
    userLevel = (TextView) findViewById(R.id.userlevel);
    userRace = (TextView) findViewById(R.id.userrace);
    userGroup = (TextView) findViewById(R.id.usergroup);

    // Set background for main user profile.
    File sdcard = Environment.getExternalStorageDirectory();
    File background =
        new File(
            sdcard + File.separator + "awouso" + File.separator + "profiles",
            userInfo.getRace() + ".png");
    Bitmap backgroundBitmap = BitmapFactory.decodeFile(background.toString());
    @SuppressWarnings("deprecation")
    Drawable backgroundImage = new BitmapDrawable(backgroundBitmap);
    userInfoLayout.setBackgroundDrawable(backgroundImage);

    // Display user avatar.
    UserInfo.setAvatar(userAvatar, userInfo.getAvatarUrl());

    // Display user name.
    userName.setText(userInfo.getFirstName() + " " + userInfo.getLastName());

    // Display user points.
    userPoints.setText(userInfo.getPoints() + "");

    // Display user rank.
    userRank.setText("rank: " + "wat?");

    // Display user level icon.
    File iconFile =
        new File(
            sdcard + File.separator + "awouso" + File.separator + "levels",
            userInfo.getRace() + "-level-" + userInfo.getLevelNo() + ".png");
    Bitmap iconBitmap = BitmapFactory.decodeFile(iconFile.toString());
    userLevelImage.setImageBitmap(iconBitmap);

    // Display user level.
    userLevel.setText("Level " + userInfo.getLevelNo());

    // Display user race.
    userRace.setText(userInfo.getRace());

    // Display user group.
    userGroup.setText(userInfo.getGroup());

    // TODO Add spell list.

    // Set buttons listeners.
    messageButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            // TODO add send message action
            Toast.makeText(
                    getApplicationContext(),
                    "Send a message to " + userInfo.getFirstName() + " " + userInfo.getLastName(),
                    Toast.LENGTH_SHORT)
                .show();
          }
        });

    spellButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            // TODO add cast spell action
            Toast.makeText(
                    getApplicationContext(),
                    "Cast a spell on " + userInfo.getFirstName() + " " + userInfo.getLastName(),
                    Toast.LENGTH_SHORT)
                .show();
          }
        });

    challengeButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            ChallengeHandler.startChallenge(v.getContext(), username);
            Toast.makeText(getApplicationContext(), "Challenge started!", Toast.LENGTH_SHORT)
                .show();
          }
        });
  }