List of usage examples for android.widget Gallery getCount
@Override public int getCount()
From source file:com.cognizant.trumobi.PersonaLauncher.java
/** * ADW: Put the launcher in desktop edit mode We could be able to add, * remove and reorder screens//from w ww . j av a 2s. co m */ private void startDesktopEdit() { if (!mIsEditMode) { mIsEditMode = true; final PersonaWorkspace personaWorkspace = mWorkspace; if (personaWorkspace == null) return; personaWorkspace.enableChildrenCache(0, personaWorkspace.getChildCount()); hideDesktop(true); personaWorkspace.lock(); // Load a gallery view final PersonaScreensAdapter screens = new PersonaScreensAdapter(this, personaWorkspace.getChildAt(0).getWidth(), personaWorkspace.getChildAt(0).getHeight()); for (int i = 0; i < personaWorkspace.getChildCount(); i++) { screens.addScreen((PersonaCellLayout) personaWorkspace.getChildAt(i)); } mScreensEditor = mInflater.inflate(R.layout.pr_screens_editor, null); final Gallery gal = (Gallery) mScreensEditor.findViewById(R.id.gallery_screens); gal.setCallbackDuringFling(false); gal.setClickable(false); gal.setAdapter(screens); // Setup delete button event View deleteButton = mScreensEditor.findViewById(R.id.delete_screen); deleteButton.setOnClickListener(new android.view.View.OnClickListener() { public void onClick(View v) { final int screenToDelete = gal.getSelectedItemPosition(); if (personaWorkspace.getChildCount() > 1) { AlertDialog alertDialog = new AlertDialog.Builder(PersonaLauncher.this).create(); alertDialog.setTitle(getResources().getString(R.string.title_dialog_xml)); alertDialog.setMessage(getResources().getString(R.string.message_delete_desktop_screen)); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { personaWorkspace.removeScreen(screenToDelete); screens.removeScreen(screenToDelete); } }); alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); alertDialog.show(); } else { Toast t = Toast.makeText(PersonaLauncher.this, R.string.message_cannot_delete_desktop_screen, Toast.LENGTH_LONG); t.show(); } } }); // Setup add buttons events View addLeftButton = mScreensEditor.findViewById(R.id.add_left); addLeftButton.setOnClickListener(new android.view.View.OnClickListener() { public void onClick(View v) { if (screens.getCount() < MAX_SCREENS) { final int screenToAddLeft = gal.getSelectedItemPosition(); PersonaCellLayout newScreen = personaWorkspace.addScreen(screenToAddLeft); screens.addScreen(newScreen, screenToAddLeft); } else { Toast t = Toast.makeText(PersonaLauncher.this, R.string.message_cannot_add_desktop_screen, Toast.LENGTH_LONG); t.show(); } } }); View addRightButton = mScreensEditor.findViewById(R.id.add_right); addRightButton.setOnClickListener(new android.view.View.OnClickListener() { public void onClick(View v) { if (screens.getCount() < MAX_SCREENS) { final int screenToAddRight = gal.getSelectedItemPosition(); PersonaCellLayout newScreen = personaWorkspace.addScreen(screenToAddRight + 1); screens.addScreen(newScreen, screenToAddRight + 1); } else { Toast t = Toast.makeText(PersonaLauncher.this, R.string.message_cannot_add_desktop_screen, Toast.LENGTH_LONG); t.show(); } } }); final View swapLeftButton = mScreensEditor.findViewById(R.id.swap_left); swapLeftButton.setOnClickListener(new android.view.View.OnClickListener() { public void onClick(View v) { int currentScreen = gal.getSelectedItemPosition(); if (currentScreen > 0) { personaWorkspace.swapScreens(currentScreen - 1, currentScreen); screens.swapScreens(currentScreen - 1, currentScreen); } else { Toast t = Toast.makeText(PersonaLauncher.this, R.string.message_cannot_swap_desktop_screen, Toast.LENGTH_LONG); t.show(); } } }); final View swapRightButton = mScreensEditor.findViewById(R.id.swap_right); swapRightButton.setOnClickListener(new android.view.View.OnClickListener() { public void onClick(View v) { int currentScreen = gal.getSelectedItemPosition(); if (currentScreen < gal.getCount() - 1) { personaWorkspace.swapScreens(currentScreen, currentScreen + 1); screens.swapScreens(currentScreen, currentScreen + 1); } else { Toast t = Toast.makeText(PersonaLauncher.this, R.string.message_cannot_swap_desktop_screen, Toast.LENGTH_LONG); t.show(); } } }); final View setDefaultButton = mScreensEditor.findViewById(R.id.set_default); setDefaultButton.setOnClickListener(new android.view.View.OnClickListener() { public void onClick(View v) { int currentScreen = gal.getSelectedItemPosition(); if (currentScreen < mWorkspace.getChildCount()) { mWorkspace.setDefaultScreen(currentScreen); PersonaAlmostNexusSettingsHelper.setDefaultScreen(PersonaLauncher.this, currentScreen); Toast t = Toast.makeText(PersonaLauncher.this, R.string.pref_title_default_screen, Toast.LENGTH_LONG); t.show(); } } }); gal.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position <= 0) { swapLeftButton.setVisibility(View.GONE); } else { swapLeftButton.setVisibility(View.VISIBLE); } if (position < parent.getCount() - 1) { swapRightButton.setVisibility(View.VISIBLE); } else { swapRightButton.setVisibility(View.GONE); } } public void onNothingSelected(AdapterView<?> arg0) { } }); mDragLayer.addView(mScreensEditor); } }