コード例 #1
0
  @SuppressWarnings("unchecked")
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Global.logd(TAG + " on create called ");

    setContentView(R.layout.activity_settings);
    mLanguageManager = LanguageManager.getInstance();

    SlidingMenu menu = new SlidingMenu(this);
    menu.setShadowWidthRes(R.dimen.shadow_res);
    menu.setFadeDegree(0.35f);

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = inflater.inflate(R.layout.layout_left_menu, null);

    setBehindContentView(view);

    // changes as on 2nd Jan 2014
    StartActivity.currentIntent = getIntent();
    // changes end here

    getSlidingMenu().setFadeEnabled(true);
    getSlidingMenu().setFadeDegree(0.35f);
    getSlidingMenu().setSlidingEnabled(true);
    getSlidingMenu().setSelectorEnabled(true);
    getSlidingMenu().setSelected(true);
    getSlidingMenu().setShadowDrawable(R.drawable.drop_shadow_for_menu);
    getSlidingMenu().setBehindOffset((int) getWidth() / 3);
    getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);

    // registerReceiver(SettingsFragment.this);

    if (getIntent().getExtras() != null) {
      if (getIntent().getStringExtra(Global.FROM_ACTIVITY) != null) {
        mFrom = getIntent().getStringExtra(Global.FROM_ACTIVITY);
      }

      if (getIntent().getStringExtra(Global.TIME_STAMP) != null) {
        mTimestamp = getIntent().getStringExtra(Global.TIME_STAMP);
      }

      if (getIntent().getStringExtra(Global.PREVIOUS) != null) {
        previousValue = getIntent().getStringExtra(Global.PREVIOUS);
      }

      if (getIntent().getStringExtra(Global.TABLE_ID) != null) {
        mTableId = getIntent().getStringExtra(Global.TABLE_ID);
      }

      if (getIntent().getStringExtra(Global.TABLE_NUMBER) != null) {
        mTableNumber = getIntent().getStringExtra(Global.TABLE_NUMBER);
      }
    }

    txtHeader = (TextView) findViewById(R.id.txtHeader);
    txtSectionSelection = (TextView) findViewById(R.id.txtSectionSelection);
    txtLanguage = (TextView) findViewById(R.id.txtLanguage);
    txtConfigureSettings = (TextView) findViewById(R.id.txtConfigureSettings);
    txtForceSync = (TextView) findViewById(R.id.txtForceSync);
    txtSyncMenu = (TextView) findViewById(R.id.txtSyncMenu);
    txtSendLog = (TextView) findViewById(R.id.txtSendLog);
    txtLogout = (TextView) findViewById(R.id.txtLogout);
    lnrSectionBox = (LinearLayout) findViewById(R.id.lnrSectionSelection);
    mTxtNotificationsEnabled = (TextView) findViewById(R.id.txtNotificationSettings);
    lnrLanguageBox = (LinearLayout) findViewById(R.id.lnrLanguage);
    mTxtNotificationCount = (TextView) findViewById(R.id.txtNotificationNumber);
    mRelNotificationCentre = (RelativeLayout) findViewById(R.id.relNotificationCentre);

    // changes as on 16th july 2013
    mTxtLeftMenuWaiterName = (TextView) view.findViewById(R.id.txtWaiterName);
    mTxtLeftMenuOrders = (TextView) view.findViewById(R.id.txtOrdersLeftMenu);
    mTxtLeftMenuSettings = (TextView) view.findViewById(R.id.txtSettingsLeftMenu);
    mTxtLeftMenuLink = (TextView) view.findViewById(R.id.txtLeftMenuLink);
    mTxtLeftMenuNotifications = (TextView) view.findViewById(R.id.txtNotificationsLeftMenu);
    mTxtLeftMenuTables = (TextView) view.findViewById(R.id.txtTablesLeftMenu);
    mBtnLockLeftMenu = (Button) view.findViewById(R.id.btnLeftMenuLock);
    mBtnWaiterChangeLeftMenu = (Button) view.findViewById(R.id.btnLeftMenuWaiterChange);
    mBtnPlaceOrderLeftMenu = (Button) view.findViewById(R.id.btnPlaceOrderLeftMenu);
    imageMenuIcon = (ImageButton) findViewById(R.id.menuIcon);

    // changes as on 6th December 2013
    mSwitchForNotifications = (Switch) findViewById(R.id.switchForNotifications);

    if (Prefs.getKey_boolean_with_default_true(this, Prefs.ARE_NOTIFICATIONS_ENABLED)) {
      mSwitchForNotifications.setChecked(true);
    } else {
      mSwitchForNotifications.setChecked(false);
    }

    mSwitchForNotifications.setOnCheckedChangeListener(
        new OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Log.i("dhara", "isChecked : " + isChecked);

            Prefs.addKey(SettingsActivity.this, Prefs.ARE_NOTIFICATIONS_ENABLED, isChecked);
          }
        });

    mSwitchForNotifications.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View view) {
            // do nothing
          }
        });
    // changes end here

    mTxtLeftMenuLink.setMovementMethod(LinkMovementMethod.getInstance());
    mTxtLeftMenuLink.setLinksClickable(true);

    mTxtLeftMenuOrders.setOnClickListener(this);
    mTxtLeftMenuSettings.setOnClickListener(this);
    mTxtLeftMenuNotifications.setOnClickListener(this);
    mTxtLeftMenuTables.setOnClickListener(this);
    mBtnPlaceOrderLeftMenu.setOnClickListener(this);
    mBtnLockLeftMenu.setOnClickListener(this);
    mBtnWaiterChangeLeftMenu.setOnClickListener(this);
    imageMenuIcon.setOnClickListener(this);
    mTxtLeftMenuLink.setOnClickListener(this);
    mRelNotificationCentre.setOnClickListener(this);

    sectionCache = SectionManager.getInstance().getSectionCache();
    mUtils = new Utils(SettingsActivity.this);
    sectionId = Prefs.getKey(Prefs.SECTION_ID);
    sectionName = Prefs.getKey(Prefs.SECTION_NAME);
    waiterName = Prefs.getKey(Prefs.WAITER_NAME);

    mTxtLeftMenuWaiterName.setText(waiterName);

    // Get the language selection value from shared preferences
    // show it on the screen
    langSelection = Prefs.getKey(Prefs.LANGUAGE_SELECTED);

    // Gets the list of languages
    mLanguageList =
        (List<String>) LanguageManager.getInstance().getLanguageCache().get(Global.LANGUAGES);

    Log.i(TAG, "value of mLanguageList " + mLanguageList);

    if (mLanguageList != null && mLanguageList.size() > 0) {
      // set the first value
      if (langSelection != null && langSelection.trim().length() > 0) {
        // Get the language xml file to set the values of the GUI
        String language = mLanguageManager.getStartNode();

        if (!langSelection.equalsIgnoreCase(language)) {
          getLanguageXmlAsyncTask =
              new GetLanguageXmlAsyncTask(SettingsActivity.this, langSelection);
          getLanguageXmlAsyncTask.execute();
        } else {
          setGuiLabels();
        }
      }
    }

    if (sectionId != null && sectionId.trim().length() > 0) {
      if (Prefs.getKey(Prefs.SECTION_NAME) != null
          && Prefs.getKey(Prefs.SECTION_NAME).trim().length() > 0) {
        txtSectionSelection.setText(mLanguageManager.getSelectedSection() + ": " + sectionName);
      }
    }

    txtHeader.setText(mLanguageManager.getSettings());

    txtSectionSelection.setOnClickListener(SettingsActivity.this);
    txtLanguage.setOnClickListener(SettingsActivity.this);
    txtConfigureSettings.setOnClickListener(SettingsActivity.this);
    txtForceSync.setOnClickListener(SettingsActivity.this);
    txtSyncMenu.setOnClickListener(SettingsActivity.this);
    txtSendLog.setOnClickListener(SettingsActivity.this);
    txtLogout.setOnClickListener(SettingsActivity.this);
    lnrLanguageBox.setOnClickListener(SettingsActivity.this);
    lnrSectionBox.setOnClickListener(SettingsActivity.this);

    Prefs.addKey(SettingsActivity.this, Prefs.MENU_SELECTED, Global.SETTINGS);
    mTxtLeftMenuSettings.setPressed(true);

    setGuiLabels();
  }