예제 #1
0
  private void submitScore() {
    if (!getGamesClient().isConnected()) {
      return;
    }

    getGamesClient().unlockAchievement(getString(R.string.achievement_activate));

    int total = AppPreference.getInstance(getApplicationContext()).getTotalNumber();
    getGamesClient().submitScore(getString(R.string.leaderboard_total_pushups), total);

    if (total >= 100) {
      getGamesClient().unlockAchievement(getString(R.string.achievement_100_pushup));
    }

    if (total >= 500) {
      getGamesClient().unlockAchievement(getString(R.string.achievement_master_level500));
    }

    int totalDay = AppPreference.getInstance(getApplicationContext()).getHowManyDays();
    getGamesClient().submitScore(getString(R.string.leaderboard_total_days), totalDay);

    if (totalDay >= 2) {
      getGamesClient().unlockAchievement(getString(R.string.achievement_2days));
    }

    if (totalDay >= 10) {
      getGamesClient().unlockAchievement(getString(R.string.achievement_10days));
    }

    int numberOfTimes = AppPreference.getInstance(getApplicationContext()).getNumberOfTimes();
    getGamesClient().submitScore(getString(R.string.leaderboard_number_of_times), numberOfTimes);
  }
예제 #2
0
 private void showShare() {
   final String text =
       String.format(getString(R.string.share_text_full_total), appPreference.getTotalNumber());
   //        ScreenshotUtils.shotBitmap(MainActivity.this, shareFileName);
   //        Animation animation = AnimationUtils.loadAnimation(getApplicationContext(),
   // R.anim.fade_out);
   //        animation.setAnimationListener(new Animation.AnimationListener() {
   //            @Override
   //            public void onAnimationStart(Animation animation) {
   //            }
   //
   //            @Override
   //            public void onAnimationEnd(Animation animation) {
   //
   //            }
   //
   //            @Override
   //            public void onAnimationRepeat(Animation animation) {
   //
   //            }
   //        });
   //        share.startAnimation(animation);
   takeScreenshot();
   Utils.share(
       MainActivity.this, MainActivity.this.getString(R.string.app_name), text, shareFileName);
 }
예제 #3
0
  private void sendToWeChat() {
    final String text =
        String.format(getString(R.string.share_text_full_total), appPreference.getTotalNumber());
    ScreenshotUtils.shotBitmap2(this, shareFileName);
    weChatUtils.createAppendReq2(this.getString(R.string.app_name), text, shareFileName);

    Intent intent = new Intent();
    intent.setClass(this, me.pjq.pushup.activity.SendToWXActivity.class);
    startActivity(intent);

    Utils.overridePendingTransitionRight2Left(this);
  }
예제 #4
0
  private void playerInfo() {
    Player player = getGamesClient().getCurrentPlayer();
    String name = player.getDisplayName();
    Uri uri = player.getIconImageUri();

    String displayName;
    if (player == null) {
      Log.w(TAG, "mGamesClient.getCurrentPlayer() is NULL!");
      displayName = "???";
    } else {
      displayName = player.getDisplayName();
      appPreference.setLoginName(displayName);
    }

    userInfo.setText(String.format(getString(R.string.you_are_signed_in_as), displayName));
    // userIcon.setImageURI(uri);
  }
예제 #5
0
  /**
   * Defines a default (dummy) share intent to initialize the action provider. However, as soon as
   * the actual content to be used in the intent is known or changes, you must update the share
   * intent by again calling mShareActionProvider.setShareIntent()
   */
  private Intent updateShareIntent() {
    if (null == appPreference) {
      return null;
    }

    final String text =
        String.format(getString(R.string.share_text_full_total), appPreference.getTotalNumber());
    takeScreenshot();
    Intent intent =
        Utils.getShareIntent(
            MainActivity.this, MainActivity.this.getString(R.string.app_name), text, shareFileName);

    if (null != mShareActionProvider) {
      //            mShareActionProvider.setShareIntent(Utils.getShareRawIntent(this));
      mShareActionProvider.setShareIntent(intent);
    }

    return intent;
  }
예제 #6
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_drawer);
    CONTENT_VIEW_ID = R.id.content_frame;

    Utils.showUserGuardIfNeed(this, UserGuideActivity.START_FROM_SPLASH);

    mTitle = mDrawerTitle = getTitle();
    //        mDrawerItems = getResources().getStringArray(R.array.drawer_items_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    drawerListAdapter = new DrawerListAdapter(getApplicationContext());
    drawerItemArrayList = new ArrayList<Object>();
    drawerItemArrayList.add(
        new DrawerListAdapter.DrawerItem(
            Constants.DRAWER_ITEM_DASHBOARD, getString(R.string.menu_item_dashboard)));
    drawerItemArrayList.add(
        new DrawerListAdapter.DrawerItem(
            Constants.DRAWER_ITEM_PUSHUPS, getString(R.string.menu_item_pushup)));
    drawerItemArrayList.add(
        new DrawerListAdapter.DrawerItem(
            Constants.DRAWER_ITEM_MULTI, getString(R.string.menu_item_multi)));
    drawerItemArrayList.add(
        new DrawerListAdapter.DrawerItem(
            Constants.DRAWER_ITEM_WRIST, getString(R.string.menu_item_wrist)));
    drawerItemArrayList.add(
        new DrawerListAdapter.DrawerItem(
            Constants.DRAWER_ITEM_GOOGLE, getString(R.string.menu_item_google)));
    drawerItemArrayList.add(
        new DrawerListAdapter.DrawerItem(
            Constants.DRAWER_ITEM_LEADERBOARD, getString(R.string.menu_item_leaderboard)));
    drawerItemArrayList.add(
        new DrawerListAdapter.DrawerItem(
            Constants.DRAWER_ITEM_ARCHIEVEMENT, getString(R.string.menu_item_archievement)));
    drawerItemArrayList.add(
        new DrawerListAdapter.DrawerItem(
            Constants.DRAWER_ITEM_HELPER, getString(R.string.menu_item_helper)));
    drawerItemArrayList.add(
        new DrawerListAdapter.DrawerItem(
            Constants.DRAWER_ITEM_ABOUT, getString(R.string.menu_item_about)));

    drawerListAdapter.setDataList(drawerItemArrayList);
    mDrawerList.setAdapter(drawerListAdapter);

    //        mDrawerList.setAdapter(new ArrayAdapter<String>(this,
    //                R.layout.drawer_list_item, mDrawerItems));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBarImpl().setDisplayHomeAsUpEnabled(true);
    getActionBarImpl().setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle =
        new ActionBarDrawerToggle(
            this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */) {
          public void onDrawerClosed(View view) {
            getActionBarImpl().setTitle(mTitle);
            supportInvalidateOptionsMenu();
            //                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }

          public void onDrawerOpened(View drawerView) {
            getActionBarImpl().setTitle(mDrawerTitle);
            supportInvalidateOptionsMenu();
            //                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }
        };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
      selectItem((DrawerListAdapter.DrawerItem) drawerListAdapter.getItem(0));
    } else {
      selectItem((DrawerListAdapter.DrawerItem) drawerListAdapter.getItem(0));
    }

    bus = ServiceProvider.getBus();
    bus.register(this);

    appPreference = AppPreference.getInstance(getApplicationContext());
    titlebarHelper =
        new TitlebarHelper(
            MainActivity.this,
            new TitlebarHelper.OnTitlebarClickListener() {
              @Override
              public void onClickIcon() {}

              @Override
              public void onClickTitle() {}
            });

    userIcon = (ImageView) findViewById(R.id.user_icon);
    userInfo = (TextView) findViewById(R.id.user_info);
    share = (TextView) findViewById(R.id.share_textview);

    userInfo.setOnClickListener(this);
    userIcon.setOnClickListener(this);
    share.setOnClickListener(this);
    findViewById(R.id.button_sign_in).setOnClickListener(this);
    findViewById(R.id.button_sign_out).setOnClickListener(this);

    getGamesClient()
        .registerConnectionCallbacks(
            new GooglePlayServicesClient.ConnectionCallbacks() {
              @Override
              public void onConnected(Bundle bundle) {
                submitScore();
              }

              @Override
              public void onDisconnected() {
                showAlert("Connect", "Disconnected!");
              }
            });

    getGamesClient().connect();

    //        if (!isSignedIn()) {
    //            beginUserInitiatedSignIn();
    //        }

    //        showDashboardFragment();
    initWeChat();
  }