@Override
 public void onCreate() {
   super.onCreate();
   SharedPreferences prefs = getSharedPreferences("MisPreferencias", Context.MODE_PRIVATE);
   Boolean marcat = prefs.getBoolean("marcat", false);
   Log.i("marcat", marcat.toString());
   if (marcat == false) Pushbots.init(this, "490854279742", "5384b34d1d0ab1d2048b459f");
 }
  /** Clear session details */
  public void logoutUser() {

    Pushbots.sharedInstance().setPushEnabled(false);
    Pushbots.sharedInstance().unRegister();

    // Clearing all user data from Shared Preferences
    editor.clear();
    editor.commit();

    // After logout redirect user to Login Activity
    Intent i = new Intent(_context, LogInActivity.class);

    // Closing all the Activities
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    // Add new Flag to start new Activity
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // Staring Login Activity
    _context.startActivity(i);
  }
  // Create login session
  public void createUserLoginSession(String id, String stats) {

    Pushbots.sharedInstance().setPushEnabled(true);

    // Storing login value as TRUE
    editor.putBoolean(IS_USER_LOGIN, true);

    // Storing id number in pref
    editor.putString(KEY_ID, id);
    editor.putString(KEY_STATS, stats);

    // commit changes
    editor.commit();
  }
Example #4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Getting an array of country names
    mCountries = getResources().getStringArray(R.array.countries);

    // Title of the activity
    mTitle = (String) getTitle();

    // Getting a reference to the drawer listview
    mDrawerList = (ListView) findViewById(R.id.drawer_list);

    // Getting a reference to the sidebar drawer ( Title + ListView )
    mDrawer = (LinearLayout) findViewById(R.id.drawer);

    // Each row in the list stores country name, count and flag
    mList = new ArrayList<HashMap<String, String>>();
    for (int i = 0; i < 5; i++) {
      HashMap<String, String> hm = new HashMap<String, String>();
      hm.put(COUNTRY, mCountries[i]);
      hm.put(COUNT, mCount[i]);
      hm.put(FLAG, Integer.toString(mFlags[i]));
      mList.add(hm);
    }

    // Keys used in Hashmap
    String[] from = {FLAG, COUNTRY, COUNT};

    // Ids of views in listview_layout
    int[] to = {R.id.flag, R.id.country, R.id.count};

    // Instantiating an adapter to store each items
    // R.layout.drawer_layout defines the layout of each item
    mAdapter = new SimpleAdapter(this, mList, R.layout.drawer_layout, from, to);

    // Getting reference to DrawerLayout
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    // Creating a ToggleButton for NavigationDrawer with drawer event listener
    mDrawerToggle =
        new ActionBarDrawerToggle(
            this,
            mDrawerLayout,
            R.drawable.ic_drawer,
            R.string.drawer_open,
            R.string.drawer_close) {

          /** Called when drawer is closed */
          public void onDrawerClosed(View view) {
            highlightSelectedCountry();
            supportInvalidateOptionsMenu();
          }

          /** Called when a drawer is opened */
          public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle("UWindsor MSA");
            supportInvalidateOptionsMenu();
          }
        };

    // Setting event listener for the drawer
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    if (savedInstanceState == null) {
      // on first time display view for first nav item
      showFragment(0);
    }
    // ItemClick event handler for the drawer items
    mDrawerList.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {

            // Increment hit count of the drawer list item
            //                incrementHitCount(position);

            if (position < 6) { // Show fragment for countries : 0 to 4
              showFragment(position);
            }
            //                else{ // Show message box for countries : 5 to 9
            //                    Toast.makeText(getApplicationContext(), mCountries[position],
            // Toast.LENGTH_LONG).show();
            //                }

            // Closing the drawer
            mDrawerLayout.closeDrawer(mDrawer);
          }
        });

    // Enabling Up navigation
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    getSupportActionBar().setDisplayShowHomeEnabled(true);

    // Setting the adapter to the listView
    mDrawerList.setAdapter(mAdapter);

    //        Pushbots.init(this, SENDER_ID,PUSHBOTS_APPLICATION_ID);
    //        Pushbots.init(this, TEST_SENDER_ID, TEST_PUSHBOTS_APPLICATION_ID);
    Pushbots.sharedInstance().init(this);
  }