@Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater mInflater = (LayoutInflater) ((Activity) context).getLayoutInflater(); final int index = position; TextView tv = null; if (convertView == null) { convertView = mInflater.inflate(R.layout.list_videotype_item, null); tv = (TextView) convertView.findViewById(R.id.ItemVideo); // courseBeans[position].textView = tv; convertView.setTag(tv); } else { tv = (TextView) convertView.getTag(); } tv.setText(courseString.get(position)); // convertView.setPadding(0, 15, 0, 15); // Log.i("getView", "+++ postion" + selectedPosition); if (selectedPosition == index) { tv.setSelected(true); tv.setPressed(true); } else { tv.setSelected(false); tv.setPressed(false); } return convertView; }
private void setSelectedView() { String selected = Prefs.getKey(Prefs.MENU_SELECTED); if (selected.trim().length() > 0) { if (selected.equalsIgnoreCase(Global.NOTIFICATIONS)) { mTxtLeftMenuNotifications.setPressed(true); } else if (selected.equalsIgnoreCase(Global.TABLES)) { mTxtLeftMenuTables.setPressed(true); } else if (selected.equalsIgnoreCase(Global.ORDERS)) { mTxtLeftMenuOrders.setPressed(true); } else if (selected.equalsIgnoreCase(Global.SETTINGS)) { mTxtLeftMenuSettings.setPressed(true); } } }
@Override public void setPressed(boolean pressed) { super.setPressed(pressed); if (!mIgnorePressedStateChange) { updateIconState(); } }
void setState(int state) { text.setPressed(state == STATE_PRESSED); tab.setPressed(state == STATE_PRESSED); if (state == STATE_ACTIVE) { final int[] activeState = new int[] {com.android.internal.R.attr.state_active}; if (text.getBackground().isStateful()) { text.getBackground().setState(activeState); } if (tab.getBackground().isStateful()) { tab.getBackground().setState(activeState); } text.setTextAppearance(text.getContext(), R.style.TextAppearance_SlidingTabActive); } else { text.setTextAppearance(text.getContext(), R.style.TextAppearance_SlidingTabNormal); } currentState = state; }
/** Reload the 6 buttons with recent activities */ private void reloadButtons() { final Context context = getContext(); final PackageManager pm = context.getPackageManager(); final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); final List<ActivityManager.RecentTaskInfo> recentTasks = am.getRecentTasks(MAX_RECENT_TASKS, ActivityManager.RECENT_IGNORE_UNAVAILABLE); ActivityInfo homeInfo = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME).resolveActivityInfo(pm, 0); IconUtilities iconUtilities = new IconUtilities(getContext()); // Performance note: Our android performance guide says to prefer Iterator when // using a List class, but because we know that getRecentTasks() always returns // an ArrayList<>, we'll use a simple index instead. int index = 0; int numTasks = recentTasks.size(); for (int i = 0; i < numTasks && (index < NUM_BUTTONS); ++i) { final ActivityManager.RecentTaskInfo info = recentTasks.get(i); // for debug purposes only, disallow first result to create empty lists if (DBG_FORCE_EMPTY_LIST && (i == 0)) continue; Intent intent = new Intent(info.baseIntent); if (info.origActivity != null) { intent.setComponent(info.origActivity); } // Skip the current home activity. if (homeInfo != null) { if (homeInfo.packageName.equals(intent.getComponent().getPackageName()) && homeInfo.name.equals(intent.getComponent().getClassName())) { continue; } } intent.setFlags( (intent.getFlags() & ~Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) | Intent.FLAG_ACTIVITY_NEW_TASK); final ResolveInfo resolveInfo = pm.resolveActivity(intent, 0); if (resolveInfo != null) { final ActivityInfo activityInfo = resolveInfo.activityInfo; final String title = activityInfo.loadLabel(pm).toString(); Drawable icon = activityInfo.loadIcon(pm); if (title != null && title.length() > 0 && icon != null) { final TextView tv = mIcons[index]; tv.setText(title); icon = iconUtilities.createIconDrawable(icon); tv.setCompoundDrawables(null, icon, null, null); tv.setTag(intent); tv.setVisibility(View.VISIBLE); tv.setPressed(false); tv.clearFocus(); ++index; } } } // handle the case of "no icons to show" mNoAppsText.setVisibility((index == 0) ? View.VISIBLE : View.GONE); // hide the rest for (; index < NUM_BUTTONS; ++index) { mIcons[index].setVisibility(View.GONE); } }
private void resetTab(TextView tvTab, boolean isSelected) { tvTab.setTextSize(TypedValue.COMPLEX_UNIT_PX, isSelected ? mTextSizeSelected : mTextSizeNormal); tvTab.setSelected(isSelected); tvTab.setPressed(isSelected); }
@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(); }