List of usage examples for android.widget AdapterView getChildAt
public View getChildAt(int index)
From source file:com.grupohqh.carservices.operator.ManipulateCarActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_manipulate_car); if (getIntent().getExtras().containsKey("userId")) userId = getIntent().getExtras().getInt("userId"); if (getIntent().getExtras().containsKey("carOwnerId")) carOwnerId = getIntent().getExtras().getInt("carOwnerId"); CARBRAND_URL = getString(R.string.base_url) + getString(R.string.carbrands_url); CARLINE_URL = getString(R.string.base_url) + getString(R.string.carmodels_url); SAVECAR_URL = getString(R.string.base_url) + "savecar/"; SAVEPHOTO_URL = getString(R.string.base_url) + "savephoto/"; hasCamera = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY); etTagNumber = (EditText) findViewById(R.id.etTagNumber); etUsernameOwner = (EditText) findViewById(R.id.etUsernameOwner); etCarBrand = (EditText) findViewById(R.id.etCarBrand); etCarModel = (EditText) findViewById(R.id.etCarModel); etCarYear = (EditText) findViewById(R.id.etCarYear); etColor = (EditText) findViewById(R.id.etCarColor); etSerialNumber = (EditText) findViewById(R.id.etSerialNumber); etLicensePlate = (EditText) findViewById(R.id.etLicensePlate); etKM = (EditText) findViewById(R.id.etKm); imgCar = (ImageView) findViewById(R.id.imgCar); spCarBrand = (Spinner) findViewById(R.id.spCarBrand); spCarModel = (Spinner) findViewById(R.id.spCarModel); btnSaveCar = (Button) findViewById(R.id.btnSaveCar); btnTakePicture = (Button) findViewById(R.id.btnTakePicture); bar = (ProgressBar) findViewById(R.id.progressBar); viewUsername = findViewById(R.id.viewUsername); if (savedInstanceState != null) { bm = savedInstanceState.getParcelable("bm"); if (bm != null) imgCar.setImageBitmap(bm);/* w ww. j a v a2 s.c om*/ } bar.setVisibility(View.GONE); etCarBrand.setVisibility(View.GONE); etCarModel.setVisibility(View.GONE); viewUsername.setVisibility(carOwnerId == 0 ? View.VISIBLE : View.GONE); btnTakePicture.setEnabled(hasCamera); btnTakePicture.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempFile(ManipulateCarActivity.this))); startActivityForResult(intent, CAPTURE_IMAGE); } }); btnSaveCar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (validate()) new SaveCarAsyncTask().execute(SAVECAR_URL); } }); spCarBrand.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position == 0) ((TextView) parent.getChildAt(position)).setTextColor(Color.GRAY); if (mapBrands.get(brands.get(position)) == otherId) { etCarBrand.setVisibility(View.VISIBLE); etCarModel.setVisibility(View.VISIBLE); spCarModel.setVisibility(View.GONE); etCarBrand.requestFocus(); } else { etCarBrand.setVisibility(View.GONE); etCarModel.setVisibility(View.GONE); spCarModel.setVisibility(View.VISIBLE); new LoadCarModelsAsyncTask().execute(CARLINE_URL + mapBrands.get(brands.get(position)) + "/"); reload = true; } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spCarModel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position == 0) ((TextView) parent.getChildAt(position)).setTextColor(Color.GRAY); if (mapModels.get(models.get(position)) == otherId) { etCarModel.setVisibility(View.VISIBLE); etCarModel.requestFocus(); } else { etCarModel.setVisibility(View.GONE); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); if (useMiniMe) { manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbCommunication = UsbCommunication.newInstance(); IntentFilter filter = new IntentFilter(); filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); // will intercept by system filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); filter.addAction(ACTION_USB_PERMISSION); registerReceiver(usbReceiver, filter); etEPC = (EditText) findViewById(R.id.etEPC); btnReadTAG = (Button) findViewById(R.id.btnReadTAG); txtStatus = (TextView) findViewById(R.id.txtStatus); btnReadTAG.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { etEPC.setText(""); if (txtStatus.getText().toString().equals("conectado")) { readTag(); } else { Toast.makeText(getBaseContext(), "dispositivo " + txtStatus.getText(), Toast.LENGTH_LONG) .show(); } } }); } etKM.addTextChangedListener(new NumberTextWatcher(etKM)); }
From source file:com.brucetoo.imagebrowse.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imgList.add(0, "http://cdn.at.cn/upload/146336617940.jpg"); imgList.add(1, "http://cdn.at.cn/upload/146540079128.jpg"); imgList.add(2, "http://cdn.at.cn/upload/146528287960.jpg"); imgList.add(3, "http://cdn.at.cn/upload/146271377052.jpg"); imgList.add(4, "http://cdn.at.cn/upload/146502027460.jpg"); imgList.add(5, "http://cdn.at.cn/upload/146296005117.jpg"); imgList.add(6, "http://cdn.at.cn/upload/146386101517.jpg"); imgList.add(7, "http://cdn.at.cn/upload/146289180072.jpg"); imgList.add(8, "http://cdn.at.cn/upload/146378563799.jpg"); // imgList.add(0, "http://img6.cache.netease.com/3g/2015/9/30/20150930091938133ad.jpg"); // imgList.add(1, "http://img2.cache.netease.com/3g/2015/9/30/2015093000515435aff.jpg"); // imgList.add(2, "http://img5.cache.netease.com/3g/2015/9/30/20150930075225737e5.jpg"); // imgList.add(3, "http://img5.cache.netease.com/3g/2015/9/29/20150929213007cd8cd.jpg"); // imgList.add(4, "http://img3.cache.netease.com/3g/2015/9/29/20150929162747a8bfa.jpg"); // imgList.add(5, "http://img2.cache.netease.com/3g/2015/9/30/20150930091208cf03c.jpg"); // imgList.add(6, "http://img2.cache.netease.com/3g/2015/9/30/2015093000515435aff.jpg"); // imgList.add(7, "http://img5.cache.netease.com/3g/2015/9/29/20150929213007cd8cd.jpg"); // imgList.add(8, "http://img3.cache.netease.com/3g/2015/9/29/20150929162747a8bfa.jpg"); gridView = (GridView) findViewById(R.id.gridview); root = findViewById(R.id.layout_root); final ImageAdapter adapter = new ImageAdapter(); gridView.setAdapter(adapter);/*from ww w. ja va2 s .c o m*/ gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> parent, final View view, final int position, long id) { if (view.isEnabled()) { //Use of ImageBrowseFragment Bundle bundle = new Bundle(); bundle.putStringArrayList(ImageInfo.INTENT_IMAGE_URLS, imgList); bundle.putParcelable(ImageInfo.INTENT_CLICK_IMAGE_INFO, ((PhotoView) view).getInfo()); bundle.putInt(ImageInfo.INTENT_CLICK_IMAGE_POSITION, position); imgImageInfos.clear(); //NOTE:if imgList.size >= the visible count in single screen,i will cause NullPointException //because item out of screen have been replaced/reused for (int i = 0; i < imgList.size(); i++) { imgImageInfos.add(((PhotoView) parent.getChildAt(i)).getInfo()); } parent.getChildAt(position); bundle.putParcelableArrayList(ImageInfo.INTENT_IMAGE_INFOS, imgImageInfos); getSupportFragmentManager() .beginTransaction().replace(Window.ID_ANDROID_CONTENT, ImageBrowseFragment.newInstance(bundle), "ViewPagerFragment") .addToBackStack(null).commit(); //Use of ImageBrowseDialogFragment // root.post(new Runnable() { // in case root view not inflate complete // @Override // public void run() { // Bundle bundle = new Bundle(); // bundle.putStringArrayList(ImageInfo.INTENT_IMAGE_URLS, imgList); // final ImageInfo preImgInfo = ((PhotoView) view).getInfo(); // bundle.putParcelable(ImageInfo.INTENT_CLICK_IMAGE_INFO, preImgInfo); // bundle.putInt(ImageInfo.INTENT_CLICK_IMAGE_POSITION, position); // imgImageInfos.clear(); // for (int i = 0; i < imgList.size(); i++) { // imgImageInfos.add(((PhotoView) parent.getChildAt(i)).getInfo()); // } // bundle.putParcelableArrayList(ImageInfo.INTENT_IMAGE_INFOS, imgImageInfos); // int[] position = new int[2]; // root.getLocationOnScreen(position); // //Must correct the ImageInfo in DialogFragment // preImgInfo.correct(position, getStatusBarHeight()); // for (ImageInfo item : imgImageInfos) { // item.correct(position,getStatusBarHeight()); // } // ImageBrowseDialogFragment.newInstance(bundle).show(getSupportFragmentManager(), ImageBrowseDialogFragment.class.getSimpleName()); // } // }); } } }); }
From source file:org.gots.ui.NewSeedActivity.java
/** * *///from w w w .ja v a2s. co m private void initSpecieList() { // final LocalSeedProvider helper = new LocalSeedProvider(getApplicationContext()); new AsyncTask<Void, Void, String[]>() { @Override protected String[] doInBackground(Void... params) { String[] specieList = seedManager.getArraySpecies(true); return specieList; } @Override protected void onPostExecute(String[] specieList) { // TODO Auto-generated method stub ListSpeciesAdapter listSpeciesAdapter = new ListSpeciesAdapter(getApplicationContext(), specieList, newSeed); gallerySpecies.setAdapter(listSpeciesAdapter); gallerySpecies.setSpacing(5); super.onPostExecute(specieList); } }.execute(); gallerySpecies.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { gallerySpecies.dispatchSetSelected(false); if (((String) view.getTag()).equals(newSeed.getSpecie())) { // clicked already selected item return; } // Selected specie changed -> remove background on others for (int i = 0; i < parent.getChildCount(); i++) { View childView = parent.getChildAt(i); if (childView != view) { childView.setBackgroundColor(0); } } view.setSelected(true); view.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_state_warning)); newSeed.setSpecie((String) view.getTag()); String family = seedManager.getFamilyBySpecie(newSeed.getSpecie()); newSeed.setFamily(family); seedWidgetLong.setSeed(newSeed); seedWidgetLong.invalidate(); } }); }
From source file:com.busticket.amedora.busticketsrl.TicketingHomeActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_ticket_home); myToolbar = (Toolbar) findViewById(R.id.my_toolbar); setSupportActionBar(myToolbar);/*from w ww . ja v a2s . c o m*/ //synchTrips(); assert getSupportActionBar() != null; getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); spBoard = (Spinner) findViewById(R.id.spBoard); spBuses = (Spinner) findViewById(R.id.spBusNo); spTrips = (Spinner) findViewById(R.id.spTripType); spHighlight = (Spinner) findViewById(R.id.spHighlight); mAccount = CreateSyncAccount(this); mQueue = Volley.newRequestQueue(getApplicationContext()); rQSyncTicket = Volley.newRequestQueue(getApplicationContext()); rQSyncTicketSynch = Volley.newRequestQueue(getApplicationContext()); rQSyncBalance = Volley.newRequestQueue(getApplicationContext()); rqTrip = Volley.newRequestQueue(getApplicationContext()); rQSyncTicketing = Volley.newRequestQueue(getApplicationContext()); rQSyncTicketingSynch = Volley.newRequestQueue(getApplicationContext()); //Key methods needed to be sent to server on activity created syncTicketing(); syncTickets(); apps = db.getApp(Installation.appId(getApplicationContext())); EMAIL = apps.getRoute_name(); NAME = "CODE: " + apps.getAgent_code().toUpperCase() + " Trip: " + apps.getTripCount(); // Get the content resolver for your app mResolver = getContentResolver(); /* * Turn on periodic syncing */ mTitle = mDrawerTitle = getTitle(); ContentResolver.addPeriodicSync(CreateSyncAccount(this), AUTHORITY, Bundle.EMPTY, SYNC_INTERVAL); String[] tdata = populateTerminals(); String[] bdata = populateBuses(); ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, tdata); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spBoard.setAdapter(adapter);/**/ ArrayAdapter Hadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, tdata); Hadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spHighlight.setAdapter(Hadapter); ArrayAdapter gadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, bdata); gadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spBuses.setAdapter(gadapter); ArrayAdapter<CharSequence> tadapter = ArrayAdapter.createFromResource(this, R.array.tripTypes, android.R.layout.simple_spinner_item); tadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); /*ArrayAdapter badapter =new ArrayAdapter(this,android.R.layout.simple_spinner_item,bdata); badapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);*/ spTrips.setAdapter(tadapter); spBuses.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE); //((TextView) parent.getChildAt(0)).setTextSize(25); bus = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spBoard.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE); //((TextView) parent.getChildAt(0)).setTextSize(25); board = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spHighlight.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE); //((TextView) parent.getChildAt(0)).setTextSize(25); highlight = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spTrips.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE); //((TextView) parent.getChildAt(0)).setTextSize(25); trip = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); btnGenerate = (Button) findViewById(R.id.btnGenerate); btnGenerate.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // get a new activity to show invoice preview sendData(); } }); mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are of fixed size mAdapter = new DrawerAdapter(TITLES, ICONS, NAME, EMAIL, PROFILE); // Creating the Adapter of MyAdapter class(which we are going to see in a bit) // And passing the titles,icons,header view name, header view email, // and header view profile picture // Setting the adapter to RecyclerView //mRecyclerView.setLayoutManager(mLayoutManager); // Setting the layout Manager LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext()); mRecyclerView.setLayoutManager(layoutManager); mRecyclerView.setAdapter(mAdapter); Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout); // Drawer object Assigned to the view mDrawerToggle = new ActionBarDrawerToggle(this, Drawer, toolbar, R.string.openDrawer, R.string.closeDrawer) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); // code here will execute once the drawer is opened( As I dont want anything happened whe drawer is // open I am not going to put anything here) invalidateOptionsMenu(); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); // Code here will execute once drawer is closed invalidateOptionsMenu(); } }; // Drawer Toggle Object Made Drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle mDrawerToggle.syncState(); // Finally we set the drawer toggle sync State final GestureDetector mGestureDetector = new GestureDetector(TicketingHomeActivity.this, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return true; } }); mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { @Override public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) { View child = recyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY()); if (child != null && mGestureDetector.onTouchEvent(motionEvent)) { Drawer.closeDrawers(); if (recyclerView.getChildPosition(child) == 1) { } else if (recyclerView.getChildPosition(child) == 2) { Intent intent = new Intent(TicketingHomeActivity.this, AccountActivity.class); startActivity(intent); } else if (recyclerView.getChildPosition(child) == 3) { Intent intent = new Intent(TicketingHomeActivity.this, TicketListActivity.class); startActivity(intent); } else if (recyclerView.getChildPosition(child) == 4) { syncTicketingSynchronize(); syncTicketsSynchronize(); synchAccount(); insertBuses(); //insertTerminals(); //syncTickets(); //dialog = ProgressDialog.show(TicketingHomeActivity.this, "", "Synchronizing App Data. Please wait...", true); /*new Thread(new Runnable() { @Override public void run() { Looper.prepare(); final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() {*/ // insertTerminals(); // insertBuses(); //getTickets(); //Toast.makeText(TicketingHomeActivity.this, "Looper startes ", Toast.LENGTH_SHORT).show(); /*handler.removeCallbacks(this); Looper.myLooper().quit(); } }, 30000); Looper.loop(); } }).start();*/ } else if (recyclerView.getChildPosition(child) == 5) { if (apps.getLicenceNo() != null) { Intent intent = new Intent(TicketingHomeActivity.this, TripHomeActivity.class); startActivity(intent); } else { //Intent intent = new Intent(TicketingHomeActivity.this,TestPrintActivity.class); //startActivity(intent); Toast.makeText(TicketingHomeActivity.this, "Application is in default mode you cannot use this menu", Toast.LENGTH_SHORT) .show(); } } else if (recyclerView.getChildPosition(child) == 6) { Intent intent = new Intent(TicketingHomeActivity.this, LogoutActivity.class); startActivity(intent); // Toast.makeText(TicketingHomeActivity.this, "The Item Clicked is: " + recyclerView.getChildPosition(child), Toast.LENGTH_SHORT).show(); } return true; } return false; } @Override public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) { } }); List<Ticket> issuedTickets = db.getIssuedTickets(); Log.e("SYNC LOG", issuedTickets.toString()); }
From source file:com.grottworkshop.gwsswipelayout.SwipeLayout.java
private void performAdapterViewItemClick(MotionEvent e) { ViewParent t = getParent();/* w w w .j a v a2 s . com*/ while (t != null) { if (t instanceof AdapterView) { AdapterView view = (AdapterView) t; int p = view.getPositionForView(SwipeLayout.this); if (p != AdapterView.INVALID_POSITION && view.performItemClick(view.getChildAt(p), p, view.getAdapter().getItemId(p))) return; } else { if (t instanceof View && ((View) t).performClick()) return; } t = t.getParent(); } }
From source file:sysnetlab.android.sdc.ui.CreateExperimentActivity.java
@Override public void onTagClicked_ExperimentRunTaggingFragment(AdapterView<?> gridview, View view, int position) { if (mPreviousTagPosition != position) { // pressed different tags or // first press Log.d("SensorDataCollector", "Tagging: first tag or different tag pressed."); Log.d("SensorDataCollector", "previous tag position = " + mPreviousTagPosition + "\t" + "current tag position = " + position); StateTag stateTag = (StateTag) gridview.getItemAtPosition(position); if (mPreviousTagPosition >= 0) { // pressed different tags switch (mStateTagPrevious.getState()) { case TAG_ON: // turn off previous tag mStateTagPrevious.setState(TaggingState.TAG_OFF); UserInterfaceUtils.setViewBackgroundCompatible(gridview.getChildAt(mPreviousTagPosition), mDrawableBackground); /*/*w w w. j a v a 2 s. c o m*/ * gridview.getChildAt(mPreviousTagPosition). * setBackgroundColor( * getResources().getColor(android.R. * color.background_light)); */ mExperiment.setLastTagging(new TaggingAction(mStateTagPrevious.getTag(), new ExperimentTime(), TaggingState.TAG_OFF)); break; case TAG_OFF: case TAG_CONTEXT: } } else { mDrawableBackground = view.getBackground(); } // turn on current tag stateTag.setState(TaggingState.TAG_ON); mExperiment.setLastTagging( new TaggingAction(stateTag.getTag(), new ExperimentTime(), TaggingState.TAG_ON)); view.setBackgroundColor(getResources().getColor(android.R.color.darker_gray)); mPreviousTagPosition = position; mStateTagPrevious = stateTag; } else { // pressed the same button Log.d("SensorDataCollector", "Tagging: first tag or different tag pressed."); Log.d("SensorDataCollector", "previous tag position = " + mPreviousTagPosition + "\t" + "current tag position = " + position); StateTag stateTag = (StateTag) gridview.getItemAtPosition(position); switch (stateTag.getState()) { case TAG_ON: // turn it off stateTag.setState(TaggingState.TAG_OFF); UserInterfaceUtils.setViewBackgroundCompatible(view, mDrawableBackground); /* * view.setBackgroundColor(getResources().getColor( * android.R.color.background_light)); */ mExperiment.setLastTagging( new TaggingAction(mStateTagPrevious.getTag(), new ExperimentTime(), TaggingState.TAG_OFF)); break; case TAG_OFF: // turn it on stateTag.setState(TaggingState.TAG_ON); view.setBackgroundColor(getResources().getColor(android.R.color.darker_gray)); mExperiment.setLastTagging( new TaggingAction(stateTag.getTag(), new ExperimentTime(), TaggingState.TAG_ON)); break; case TAG_CONTEXT: } mPreviousTagPosition = position; mStateTagPrevious = stateTag; } }
From source file:org.mozilla.gecko.tests.BaseTest.java
/** * Gets the view in the tabs panel at the specified index. * * @return View at index/*ww w . j a v a 2s .c o m*/ */ private View getTabViewAt(final int index) { final View[] childView = { null }; final AdapterView<ListAdapter> view = getTabsLayout(); runOnUiThreadSync(new Runnable() { @Override public void run() { view.setSelection(index); // The selection isn't updated synchronously; posting a // runnable to the view's queue guarantees we'll run after the // layout pass. view.post(new Runnable() { @Override public void run() { // getChildAt() is relative to the list of visible // views, but our index is relative to all views in the // list. Subtract the first visible list position for // the correct offset. childView[0] = view.getChildAt(index - view.getFirstVisiblePosition()); } }); } }); boolean result = waitForCondition(new Condition() { @Override public boolean isSatisfied() { return childView[0] != null; } }, MAX_WAIT_MS); mAsserter.ok(result, "list item at index " + index + " exists", null); return childView[0]; }
From source file:com.tweetlanes.android.core.view.TweetFeedFragment.java
private TwitterStatus getVisibleStatus() { TwitterStatus visibleStatus = null;//from ww w.j a v a 2 s.c o m if (getStatusFeed() != null && mTweetFeedListView != null && mTweetFeedListView.getRefreshableView() != null) { AdapterView view = mTweetFeedListView.getRefreshableView(); int visiblePosition = view.getFirstVisiblePosition(); if (visiblePosition == 1 && view != null && view.getChildAt(visiblePosition - 1) != null) { int previousTop = view.getChildAt(visiblePosition - 1).getTop(); int previousBottom = view.getChildAt(visiblePosition - 1).getBottom(); if (previousBottom > 0 && previousTop >= -10) { visiblePosition--; } } if (visiblePosition < getStatusFeed().getStatusCount()) { visibleStatus = getStatusFeed().getStatus(visiblePosition); if (visibleStatus != null) { String notifcationType = null; String pref = null; if (getLaneIndex() == getApp().getCurrentAccount() .getCurrentLaneIndex(Constant.LaneType.USER_MENTIONS)) { notifcationType = SharedPreferencesConstants.NOTIFICATION_TYPE_MENTION; pref = SharedPreferencesConstants.NOTIFICATION_LAST_DISPLAYED_MENTION_ID; } else if (getLaneIndex() == getApp().getCurrentAccount() .getCurrentLaneIndex(Constant.LaneType.DIRECT_MESSAGES)) { notifcationType = SharedPreferencesConstants.NOTIFICATION_TYPE_DIRECT_MESSAGE; pref = SharedPreferencesConstants.NOTIFICATION_LAST_DISPLAYED_DIRECT_MESSAGE_ID; } if (notifcationType != null && pref != null) { Notifier.saveLastNotificationActioned(getBaseLaneActivity(), getApp().getCurrentAccountKey(), notifcationType, visibleStatus.mId); Notifier.cancel(getBaseLaneActivity(), getApp().getCurrentAccountKey(), notifcationType); } } } } return visibleStatus; }
From source file:org.brandroid.openmanager.activities.OpenExplorer.java
private void onClipboardDropdown(View anchor) { ViewUtils.setViewsVisible(mStaticButtons, true, R.id.title_paste); if (anchor == null) anchor = ViewUtils.getFirstView(this, R.id.title_paste, R.id.title_icon, R.id.frag_holder); final BetterPopupWindow clipdrop = new BetterPopupWindow(this, anchor); View root = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.multiselect, null); GridView mGridCommands = (GridView) root.findViewById(R.id.multiselect_command_grid); final ListView mListClipboard = (ListView) root.findViewById(R.id.multiselect_item_list); mListClipboard.setAdapter(getClipboard()); mListClipboard.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> list, View view, final int pos, long id) { //OpenPath file = mClipboard.get(pos); //if(file.getParent().equals(mLastPath)) Animation anim = AnimationUtils.loadAnimation(OpenExplorer.this, R.anim.slide_out_left); //anim.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime)); list.getChildAt(pos).startAnimation(anim); new Handler().postDelayed(new Runnable() { public void run() { getClipboard().remove(pos); mListClipboard.invalidate(); if (getClipboard().getCount() == 0) clipdrop.dismiss(); }/*from www .ja va 2 s.com*/ }, anim.getDuration()); //else //getEventHandler().copyFile(file, mLastPath, OpenExplorer.this); } }); final Menu menu = IconContextMenu.newMenu(this, R.menu.multiselect); MenuUtils.setMenuChecked(menu, getClipboard().isMultiselect(), R.id.menu_multi); MenuUtils.setMenuEnabled(menu, getClipboard().hasPastable(), R.id.menu_multi_all_copy, R.id.menu_multi_all_copy, R.id.menu_multi_all_move); final IconContextMenuAdapter cmdAdapter = new IconContextMenuAdapter(this, menu); cmdAdapter.setTextLayout(R.layout.context_item); mGridCommands.setAdapter(cmdAdapter); mGridCommands.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> list, View view, int pos, long id) { MenuItem item = menu.getItem(pos); onClick(item.getItemId(), item, view); clipdrop.dismiss(); } }); float w = getResources().getDimension(R.dimen.popup_width) * (3 / 2); if (w > getWindowWidth()) w = getWindowWidth() - 20; clipdrop.setPopupWidth((int) w); clipdrop.setContentView(root); clipdrop.showLikePopDownMenu(); //dropdown.setAdapter(this, new IconContextMenuAdapter(context, menu)) //BetterPopupWindow win = new BetterPopupWindow(this, anchor); //ListView list = ((LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE)).inflate(R.layout.multiselect, null); //win.setContentView(root) }
From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java
private void setLocalFilelistItemClickListener() { if (localFileListView == null) return;/*from w ww . ja v a 2 s .c o m*/ localFileListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { for (int j = 0; j < parent.getChildCount(); j++) parent.getChildAt(j).setBackgroundColor(Color.TRANSPARENT); FileListItem item = localFileListAdapter.getItem(position); if (!isUiEnabled()) return; if (localFileListAdapter.isItemSelected()) { item.setChecked(!item.isChecked()); localFileListAdapter.notifyDataSetChanged(); } else { setUiEnabled(false); sendDebugLogMsg(1, "I", "Local filelist item clicked :" + item.getName()); if (item.isDir()) { FileListCacheItem dhi_c = getFileListCache(item.getPath() + "/" + item.getName(), localFileListCache); ArrayList<FileListItem> tfl = null; if (dhi_c == null) { tfl = createLocalFileList(false, item.getPath() + "/" + item.getName()); } else { tfl = dhi_c.file_list; } if (tfl == null) return; String t_dir = item.getPath() + "/" + item.getName(); localCurrFLI.pos_fv = localFileListView.getFirstVisiblePosition(); if (localFileListView.getChildAt(0) != null) localCurrFLI.pos_top = localFileListView.getChildAt(0).getTop(); localDir = t_dir.replace(localBase + "/", ""); localFileListAdapter.setDataList(tfl); localFileListAdapter.notifyDataSetChanged(); for (int j = 0; j < localFileListView.getChildCount(); j++) localFileListView.getChildAt(j).setBackgroundColor(Color.TRANSPARENT); setFilelistCurrDir(localFileListDirSpinner, localBase, localDir); setFileListPathName(localFileListPathBtn, localFileListCache, localBase, localDir); setEmptyFolderView(); localFileListView.setSelection(0); putDirHist(localBase, localDir, localDirHist); if (dhi_c == null) { FileListCacheItem dhi = new FileListCacheItem(); dhi.profile_name = localBase; dhi = new FileListCacheItem(); dhi = new FileListCacheItem(); dhi.base = localBase; dhi.directory = item.getPath() + "/" + item.getName(); dhi.file_list = tfl; dhi.directory_history.addAll(localDirHist); putFileListCache(dhi, localFileListCache); localCurrFLI = dhi; } else { localCurrFLI = dhi_c; } localFileListTopBtn.setEnabled(true); localFileListUpBtn.setEnabled(true); setUiEnabled(true); } else { if (isFileListItemSelected(localFileListAdapter)) { item.setChecked(!item.isChecked()); localFileListAdapter.notifyDataSetChanged(); setUiEnabled(true); } else { setUiEnabled(true); startLocalFileViewerIntent(item); } } } } }); }