List of usage examples for android.os Handler postDelayed
public final boolean postDelayed(Runnable r, long delayMillis)
From source file:com.cypress.cysmart.BLEServiceFragments.SensorHubService.java
/** * Display temperature data/* ww w . j a v a 2 s . co m*/ * * @param received_stemp */ void displaySTEMPData(final String received_stemp) { STEMP.setText(received_stemp); final Handler lHandler = new Handler(); Runnable lRunnable = new Runnable() { @Override public void run() { if (HANDLER_FLAG) { STEMPGraphLastXValue++; double value = Float.valueOf(received_stemp); mTemperatureDataSeries.add(STEMPGraphLastXValue, value); mTemperaturerChart.repaint(); } } }; lHandler.postDelayed(lRunnable, 1000); }
From source file:com.sentaroh.android.Utilities.Dialog.FileSelectDialogFragment.java
private void initViewWidget() { if (mDebugEnable) Log.v(APPLICATION_TAG, "initViewWidget"); if (mDebugEnable) Log.v(APPLICATION_TAG, "Create=" + mDialogEnableCreate + ", Title=" + mDialogTitle + ", lurl=" + mDialogLocalUrl + ", ldir=" + mDialogLocalDir + ", file name=" + mDialogFileName); mThemeColorList = ThemeUtil.getThemeColorList(getActivity()); mDialog.setContentView(R.layout.file_select_edit_dlg); LinearLayout title_view = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_title_view); title_view.setBackgroundColor(mThemeColorList.dialog_title_background_color); TextView title = (TextView) mDialog.findViewById(R.id.file_select_edit_dlg_title); title.setTextColor(mThemeColorList.text_color_dialog_title); title.setText(mDialogTitle);/*www .j a v a2s. c om*/ final TextView dlg_msg = (TextView) mDialog.findViewById(R.id.file_select_edit_dlg_msg); final Button btnHome = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_home_dir_btn); btnHome.setTextColor(mThemeColorList.text_color_primary); btnHome.setVisibility(Button.VISIBLE); final Button btnCreate = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_create_btn); btnCreate.setTextColor(mThemeColorList.text_color_primary); final Button btnOk = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_ok_btn); // btnOk.setTextColor(mThemeColorList.text_color_primary); final Button btnCancel = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_cancel_btn); btnCancel.setTextColor(mThemeColorList.text_color_primary); final Button btnRefresh = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_refresh_btn); btnRefresh.setTextColor(mThemeColorList.text_color_primary); LinearLayout ll_dlg_view = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_view); ll_dlg_view.setBackgroundColor(mThemeColorList.dialog_msg_background_color); final Activity activity = getActivity(); final Context context = activity.getApplicationContext(); if (mDialogEnableCreate) { btnCreate.setVisibility(TextView.VISIBLE); } mLocalMountPointSpinner = (Spinner) mDialog.findViewById(R.id.file_select_edit_dlg_rdir); setSpinnerBackground(context, mLocalMountPointSpinner, mThemeColorList.theme_is_light); mLocalMountPointSpinner.setVisibility(Spinner.VISIBLE); // Root directory spinner CustomSpinnerAdapter adapter = new CustomSpinnerAdapter(activity, R.layout.custom_simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mLocalMountPointSpinner.setPrompt(context.getString(R.string.msgs_file_select_edit_local_mount_point)); mLocalMountPointSpinner.setAdapter(adapter); int a_no = -1; ArrayList<String> ml = LocalMountPoint.getLocalMountPointList(context); mLocalMountPointSpinner.setOnItemSelectedListener(null); if (mDialogMpLimitInternalAndSdcard) { adapter.add(Environment.getExternalStorageDirectory().toString()); File[] fl = ContextCompat.getExternalFilesDirs(context, null); for (File item : fl) { if (!item.getPath().startsWith(Environment.getExternalStorageDirectory().toString())) { adapter.add(item.getPath().substring(0, item.getPath().indexOf("/Android"))); break; } } mLocalMountPointSpinner.setEnabled(true); for (int i = 0; i < adapter.getCount(); i++) { if (adapter.getItem(i).equals(mDialogLocalUrl)) { a_no = i; break; } } mLocalMountPointSpinner.setSelection(a_no); } else { if (ml.size() == 0) { if (mDialogIncludeRoot) adapter.add("/"); adapter.add(mDialogLocalUrl); mLocalMountPointSpinner.setEnabled(false); } else { mLocalMountPointSpinner.setEnabled(true); if (mDialogIncludeRoot) adapter.add("/"); for (int i = 0; i < ml.size(); i++) adapter.add(ml.get(i)); for (int i = 0; i < ml.size(); i++) { if (mDialogLocalUrl.startsWith(ml.get(i))) { a_no = i; break; } } mLocalMountPointSpinner.setSelection(a_no); } } LinearLayout ll_mp = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_mp_view); if (mDialogHideMp) ll_mp.setVisibility(LinearLayout.GONE); else ll_mp.setVisibility(LinearLayout.VISIBLE); // ll_mp.setVisibility(LinearLayout.GONE); // final TextView v_spacer=(TextView)mDialog.findViewById(R.id.file_select_edit_dlg_spacer); mTreeFileListView = (ListView) mDialog.findViewById(android.R.id.list); final CustomTextView dir_name = (CustomTextView) mDialog.findViewById(R.id.file_select_edit_dlg_dir_name); dir_name.setTextColor(mThemeColorList.text_color_primary); final EditText file_name = (EditText) mDialog.findViewById(R.id.file_select_edit_dlg_file_name); if (!mDialogSingleSelect) file_name.setVisibility(EditText.GONE); else file_name.setVisibility(EditText.VISIBLE); if (mDialogFileOnly) { file_name.setVisibility(EditText.VISIBLE); file_name.setEnabled(true); dir_name.setVisibility(EditText.VISIBLE); } else { if (mDialogDirectoryOnly) { file_name.setVisibility(EditText.GONE); file_name.setEnabled(false); dir_name.setVisibility(EditText.VISIBLE); btnHome.setVisibility(EditText.VISIBLE); } else { file_name.setVisibility(EditText.VISIBLE); file_name.setEnabled(true); dir_name.setVisibility(EditText.VISIBLE); btnHome.setVisibility(EditText.VISIBLE); } } file_name.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View arg0, int keyCode, KeyEvent event) { if (//event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { return true; } return false; } }); // if (dirs.size()<=2) v_spacer.setVisibility(TextView.VISIBLE); mTreeFilelistAdapter = new TreeFilelistAdapter(activity, mDialogSingleSelect, true); mTreeFileListView.setAdapter(mTreeFilelistAdapter); if (mDialogLocalUrl.equals("")) mDialogLocalUrl = ml.get(0); ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, mDialogLocalUrl, ""); if (tfl.size() == 0) { tfl.add(new TreeFilelistItem(context.getString(R.string.msgs_file_select_edit_dir_empty))); } else { mTreeFilelistAdapter.setDataList(tfl); if (!mDialogLocalDir.equals("")) { String sel_dir = mDialogLocalDir; String n_dir = "", e_dir = ""; if (sel_dir.startsWith("/")) n_dir = sel_dir.substring(1); else n_dir = sel_dir; if (n_dir.endsWith("/")) e_dir = n_dir.substring(0, n_dir.length() - 1); else e_dir = n_dir; // Log.v("","mp="+mDialogLocalUrl+", se;_dir="+sel_dir+", e_dir="+e_dir); selectLocalDirTree(e_dir); } if (!mDialogFileName.equals("")) selectLocalDirTreeFile(mDialogFileName); } mTreeFileListView.setScrollingCacheEnabled(false); mTreeFileListView.setScrollbarFadingEnabled(false); if (mSavedViewContentsValue != null && mSavedViewContentsValue.mainDialogFilename != null) { file_name.setText(mSavedViewContentsValue.mainDialogFilename); file_name.setSelection(mSavedViewContentsValue.mainDialogFilenameSelStart, mSavedViewContentsValue.mainDialogFilenameTextSelEnd); dir_name.setText(mSavedViewContentsValue.mainDialogDirName); } else { String d_name = mDialogLocalDir.equals("") ? mDialogLocalUrl + "/" : mDialogLocalUrl + mDialogLocalDir + "/"; dir_name.setText(d_name); file_name.setText(mDialogFileName); } if (!mDialogSingleSelect) btnOk.setEnabled(false); NotifyEvent cb_ntfy = new NotifyEvent(context); // set file list thread response listener cb_ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { int p = (Integer) o[0]; boolean p_chk = (Boolean) o[1]; String turl = (String) mLocalMountPointSpinner.getSelectedItem(); if (mDialogSingleSelect) { if (mTreeFilelistAdapter.getDataItem(p).isChecked() && !p_chk) { if (p != -1) { if (mTreeFilelistAdapter.getDataItem(p).isChecked()) { if (mTreeFilelistAdapter.getDataItem(p).isDir()) { dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath() + mTreeFilelistAdapter.getDataItem(p).getName() + "/"); // file_name.setText(""); } else { dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath()); file_name.setText(mTreeFilelistAdapter.getDataItem(p).getName()); } } } } if (mDialogFileOnly) { if (file_name.getText().length() > 0) { btnOk.setEnabled(true); putDlgMsg(dlg_msg, ""); } else { btnOk.setEnabled(false); putDlgMsg(dlg_msg, context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified)); } } else { if (mTreeFilelistAdapter.isDataItemIsSelected() || file_name.getText().length() > 0) { btnOk.setEnabled(true); putDlgMsg(dlg_msg, ""); } else { putDlgMsg(dlg_msg, context.getString(R.string.msgs_file_select_edit_dlg_directory_not_selected)); btnOk.setEnabled(false); } } } else { if (mTreeFilelistAdapter.getDataItem(p).isDir()) { dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath() + mTreeFilelistAdapter.getDataItem(p).getName() + "/"); // file_name.setText(""); } else { dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath()); file_name.setText(mTreeFilelistAdapter.getDataItem(p).getName()); } putDlgMsg(dlg_msg, ""); btnOk.setEnabled(true); } } @Override public void negativeResponse(Context c, Object[] o) { boolean checked = false; // int p=(Integer) o[0]; boolean p_chk = (Boolean) o[1]; if (mDialogSingleSelect) { if (p_chk) { for (int i = 0; i < mTreeFilelistAdapter.getDataItemCount(); i++) { if (mTreeFilelistAdapter.getDataItem(i).isChecked()) { checked = true; break; } } if (checked) btnOk.setEnabled(true); else btnOk.setEnabled(false); } } else { // Log.v("","sel="+p_chk); btnOk.setEnabled(false); for (int i = 0; i < mTreeFilelistAdapter.getDataItemCount(); i++) { if (mTreeFilelistAdapter.getDataItem(i).isChecked()) { btnOk.setEnabled(true); break; } } } } }); mTreeFilelistAdapter.setCbCheckListener(cb_ntfy); if (mDialogLocalUrl.equals(file_name.getText().toString())) btnOk.setEnabled(false); if (mDialogFileOnly && mDialogFileName.equals("")) { btnOk.setEnabled(false); putDlgMsg(dlg_msg, context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified)); } file_name.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { if (mDialogSingleSelect) { if (s.length() != 0) { btnOk.setEnabled(true); putDlgMsg(dlg_msg, ""); } else { btnOk.setEnabled(false); putDlgMsg(dlg_msg, context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified)); } } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); NotifyEvent ntfy_expand_close = new NotifyEvent(context); ntfy_expand_close.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { int idx = (Integer) o[0]; final int pos = mTreeFilelistAdapter.getItem(idx); final TreeFilelistItem tfi = mTreeFilelistAdapter.getDataItem(pos); if (tfi.getName().startsWith("---")) return; String turl = (String) mLocalMountPointSpinner.getSelectedItem(); if (tfi.isDir()) processLocalDirTree(mDialogFileOnly, turl, pos, tfi, mTreeFilelistAdapter); else { mTreeFilelistAdapter.setDataItemIsSelected(pos); dir_name.setText((turl + mTreeFilelistAdapter.getDataItem(pos).getPath())); file_name.setText(mTreeFilelistAdapter.getDataItem(pos).getName()); if (mTreeFilelistAdapter.getDataItem(pos).isDir() && mDialogFileOnly) btnOk.setEnabled(false); else btnOk.setEnabled(true); } } @Override public void negativeResponse(Context c, Object[] o) { } }); mTreeFilelistAdapter.setExpandCloseListener(ntfy_expand_close); mTreeFileListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> items, View view, int idx, long id) { final int pos = mTreeFilelistAdapter.getItem(idx); final TreeFilelistItem tfi = mTreeFilelistAdapter.getDataItem(pos); if (tfi.getName().startsWith("---")) return; String turl = (String) mLocalMountPointSpinner.getSelectedItem(); if (tfi.isDir()) processLocalDirTree(mDialogFileOnly, turl, pos, tfi, mTreeFilelistAdapter); else { mTreeFilelistAdapter.setDataItemIsSelected(pos); dir_name.setText((turl + mTreeFilelistAdapter.getDataItem(pos).getPath())); file_name.setText(mTreeFilelistAdapter.getDataItem(pos).getName()); if (mTreeFilelistAdapter.getDataItem(pos).isDir() && mDialogFileOnly) btnOk.setEnabled(false); else btnOk.setEnabled(true); } } }); mTreeFileListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) { return true; } }); btnHome.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dir_name.setText(mLocalMountPointSpinner.getSelectedItem().toString() + "/"); } }); //Create button btnCreate.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { NotifyEvent ntfy = new NotifyEvent(context); // set file list thread response listener ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { // btnRefresh.performClick(); } @Override public void negativeResponse(Context c, Object[] o) { } }); fileSelectEditDialogCreateBtn(activity, context, dir_name.getText().substring(0, dir_name.getText().length() - 1), "", mLocalMountPointSpinner.getSelectedItem().toString(), mTreeFilelistAdapter, ntfy, mTreeFileListView); } }); //Refresh button btnRefresh.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String mp = mLocalMountPointSpinner.getSelectedItem().toString(); ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, mp, "");//mDialogLocalUrl,""); if (tfl.size() < 1) tfl.add(new TreeFilelistItem(context.getString(R.string.msgs_file_select_edit_dir_empty))); mTreeFilelistAdapter.setDataList(tfl); } }); //OK button // btnOk.setEnabled(false); btnOk.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (mDialogSingleSelect) { String[] sl_array = new String[] { dir_name.getText() + file_name.getText().toString() }; if (mNotifyEvent != null) mNotifyEvent.notifyToListener(true, sl_array); } else { ArrayList<String> sl = new ArrayList<String>(); ArrayList<TreeFilelistItem> tfl = mTreeFilelistAdapter.getDataList(); for (TreeFilelistItem li : tfl) { if (li.isChecked()) { if (li.isDir()) sl.add(li.getPath() + li.getName()); else sl.add(li.getPath() + li.getName()); } } String[] sl_array = new String[sl.size()]; String mp = mLocalMountPointSpinner.getSelectedItem().toString(); for (int i = 0; i < sl.size(); i++) { if (mDialogSelectedFilePathWithMountPoint) sl_array[i] = mp + sl.get(i); else sl_array[i] = sl.get(i); // Log.v("","sel="+sl_array[i]); } if (mNotifyEvent != null) mNotifyEvent.notifyToListener(true, sl_array); } // mDialog.dismiss(); mFragment.dismiss(); } }); // CANCEL? btnCancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // mDialog.dismiss(); mFragment.dismiss(); if (mNotifyEvent != null) mNotifyEvent.notifyToListener(false, null); } }); Handler hndl = new Handler(); hndl.postDelayed(new Runnable() { @Override public void run() { mLocalMountPointSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // Log.v("","MP selected="+position); Spinner spinner = (Spinner) parent; String turl = (String) spinner.getSelectedItem(); ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, turl, ""); if (tfl.size() < 1) tfl.add(new TreeFilelistItem( context.getString(R.string.msgs_file_select_edit_dir_empty))); mTreeFilelistAdapter.setDataList(tfl); mTreeFilelistAdapter.notifyDataSetChanged(); if (turl.startsWith(mSafFileMgr.getExternalSdcardPath())) { if (mSafFileMgr.getSdcardSafFile() == null) btnCreate.setEnabled(false); else btnCreate.setEnabled(true); } else btnCreate.setEnabled(true); dir_name.setText(turl + "/"); Handler hndl_sel = new Handler(); hndl_sel.post(new Runnable() { @Override public void run() { mTreeFileListView.setSelection(0); } }); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); } }, 100); }
From source file:uk.co.jarofgreen.cityoutdoors.UI.BrowseMapActivity.java
/** * This is where we can add markers or lines, add listeners or move the camera. * <p>/* w ww .jav a2 s .c o m*/ * This should only be called once and when we are sure that {@link #mMap} is not null. */ private void setUpMap() { // first, do we start at a certain point or do we start at the default bounds? boolean zoomed = false; Bundle extras = getIntent().getExtras(); if (extras != null) { Float lat = extras.getFloat("lat"); Float lng = extras.getFloat("lng"); Log.d("LOADMAP", Float.toString(lat)); Log.d("LOADMAP", Float.toString(lng)); if (lat != 0.0 && lng != 0.0) { map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 18)); zoomed = true; } } if (!zoomed) { // We can't call newLatLngBounds at this point, the map isn't sized and app crashes. // So first we set the map to our hard coded range so it's at least sensible. map.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(STARTING_LAT, STARTING_LNG), STARTING_ZOOM)); // now set up a handler to zoom to correct place a second later. This feels like a bad hack. Handler handler = new Handler(); final Runnable r = new Runnable() { public void run() { SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(BrowseMapActivity.this); float startingBoundsMaxLat = settings.getFloat("startingBoundsMaxLat", 0); float startingBoundsMinLat = settings.getFloat("startingBoundsMinLat", 0); float startingBoundsMaxLng = settings.getFloat("startingBoundsMaxLng", 0); float startingBoundsMinLng = settings.getFloat("startingBoundsMinLng", 0); if (!(startingBoundsMaxLat == 0 && startingBoundsMinLat == 0 && startingBoundsMaxLng == 0 && startingBoundsMinLng == 0)) { LatLng southwest = new LatLng(startingBoundsMinLat, startingBoundsMinLng); LatLng northeast = new LatLng(startingBoundsMaxLat, startingBoundsMaxLng); try { map.moveCamera(CameraUpdateFactory .newLatLngBounds(new LatLngBounds(southwest, northeast), 10)); } catch (Exception e) { // this feels like a bad hack, so if it crashes just ignore it. We will still be zoomed to sensible bounds. } } } }; handler.postDelayed(r, 250); } // icons Storage s = ((OurApplication) getApplication()).getStorage(); for (Collection collection : s.getCollections()) { // normal icon BitmapDescriptor icon = null; if (collection.getIconURL() != null) { if (collection.getIconURL().contains("park")) { icon = BitmapDescriptorFactory.fromResource(R.drawable.marker_park); } else if (collection.getIconURL().contains("tree")) { icon = BitmapDescriptorFactory.fromResource(R.drawable.marker_tree); } else if (collection.getIconURL().contains("monument")) { icon = BitmapDescriptorFactory.fromResource(R.drawable.marker_monument); } else if (collection.getIconURL().contains("wc")) { icon = BitmapDescriptorFactory.fromResource(R.drawable.marker_wc); } else if (collection.getIconURL().contains("play")) { icon = BitmapDescriptorFactory.fromResource(R.drawable.marker_playground); } } if (icon != null) { collectionIcons.put(collection.getId(), icon); } // question icon BitmapDescriptor questionIcon = null; if (collection.getQuestionIconURL() != null) { if (collection.getQuestionIconURL().contains("park")) { questionIcon = BitmapDescriptorFactory.fromResource(R.drawable.marker_park_question); } else if (collection.getQuestionIconURL().contains("tree")) { questionIcon = BitmapDescriptorFactory.fromResource(R.drawable.marker_tree_question); } else if (collection.getQuestionIconURL().contains("monument")) { questionIcon = BitmapDescriptorFactory.fromResource(R.drawable.marker_monument_question); } else if (collection.getQuestionIconURL().contains("play")) { questionIcon = BitmapDescriptorFactory.fromResource(R.drawable.marker_playground_question); } } if (questionIcon != null) { collectionQuestionIcons.put(collection.getId(), questionIcon); } else if (icon != null) { // if we don't have a question icon but we have a normal icon, just reuse that. collectionQuestionIcons.put(collection.getId(), icon); } } // markers map.setOnCameraChangeListener(new OnCameraChangeListener() { public void onCameraChange(CameraPosition position) { LatLngBounds bounds = BrowseMapActivity.this.map.getProjection().getVisibleRegion().latLngBounds; new MarkerTask(bounds.northeast.latitude, bounds.southwest.latitude, bounds.southwest.longitude, bounds.northeast.longitude).execute(true); } }); map.setOnInfoWindowClickListener(this); }
From source file:com.corporatetaxi.TaxiOntheWay_Activity.java
private void animateMarker(final Marker marker, final LatLng toPosition, final boolean hideMarker) { final Handler handler = new Handler(); final long start = SystemClock.uptimeMillis(); Projection proj = map.getProjection(); Point startPoint = proj.toScreenLocation(marker.getPosition()); final LatLng startLatLng = proj.fromScreenLocation(startPoint);//marker1.getPosition(); final long duration = 600; final Interpolator interpolator = new LinearInterpolator(); handler.post(new Runnable() { @Override//from w w w . j a v a 2 s .c o m public void run() { long elapsed = SystemClock.uptimeMillis() - start; float t = interpolator.getInterpolation((float) elapsed / duration); double lng = t * toPosition.longitude + (1 - t) * startLatLng.longitude; double lat = t * toPosition.latitude + (1 - t) * startLatLng.latitude; marker.setPosition(new LatLng(lat, lng)); if (t < 1.0) { // Post again 16ms later. handler.postDelayed(this, 16); } else { if (hideMarker) { marker.setVisible(false); } else { marker.setVisible(true); } } map.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat, lng))); } }); }
From source file:com.corporatetaxi.TaxiArrived_Acitivity.java
private void animateMarker(final Marker marker, final LatLng toPosition, final boolean hideMarker) { final Handler handler = new Handler(); final long start = SystemClock.uptimeMillis(); Projection proj = map.getProjection(); Point startPoint = proj.toScreenLocation(marker.getPosition()); final LatLng startLatLng = proj.fromScreenLocation(startPoint); final long duration = 1000; final Interpolator interpolator = new LinearInterpolator(); handler.post(new Runnable() { @Override/*from w w w. ja v a2 s .co m*/ public void run() { long elapsed = SystemClock.uptimeMillis() - start; float t = interpolator.getInterpolation((float) elapsed / duration); double lng = t * toPosition.longitude + (1 - t) * startLatLng.longitude; double lat = t * toPosition.latitude + (1 - t) * startLatLng.latitude; marker.setPosition(new LatLng(lat, lng)); if (t < 1.0) { // Post again 16ms later. handler.postDelayed(this, 16); } else { if (hideMarker) { marker.setVisible(false); } else { marker.setVisible(true); } } map.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat, lng))); } }); }
From source file:de.geeksfactory.opacclient.frontend.AccountFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); view = inflater.inflate(R.layout.fragment_account, container, false); findViews();// w w w. ja v a2 s. co m app = (OpacClient) getActivity().getApplication(); account = app.getAccount(); swipeRefreshLayout.setColorSchemeResources(R.color.primary_red); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refresh(); } }); setHasOptionsMenu(true); accountSelected(app.getAccount()); final Handler handler = new Handler(); // schedule alarm here and post runnable as soon as scheduled handler.post(new Runnable() { @Override public void run() { refreshage(); handler.postDelayed(this, 60000); } }); return view; }
From source file:com.example.rx.ui.VLayoutActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity2); mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container); ;/* w ww . j av a 2s. c om*/ mFirstText = (TextView) findViewById(R.id.first); mLastText = (TextView) findViewById(R.id.last); mCountText = (TextView) findViewById(R.id.count); mTotalOffsetText = (TextView) findViewById(R.id.total_offset); final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view); findViewById(R.id.jump).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { EditText position = (EditText) findViewById(R.id.position); if (!TextUtils.isEmpty(position.getText())) { try { int pos = Integer.parseInt(position.getText().toString()); recyclerView.scrollToPosition(pos); } catch (Exception e) { Log.e("VlayoutActivity", e.getMessage(), e); } } else { recyclerView.requestLayout(); } } }); final VirtualLayoutManager layoutManager = new VirtualLayoutManager(this); recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) { } @Override public void onScrolled(RecyclerView recyclerView, int i, int i2) { mFirstText.setText("First: " + layoutManager.findFirstVisibleItemPosition()); mLastText.setText( "Existing: " + MainViewHolder.existing + " Created: " + MainViewHolder.createdTimes); mCountText.setText("Count: " + recyclerView.getChildCount()); mTotalOffsetText.setText("Total Offset: " + layoutManager.getOffsetToStart()); } }); recyclerView.setLayoutManager(layoutManager); // layoutManager.setReverseLayout(true); RecyclerView.ItemDecoration itemDecoration = new RecyclerView.ItemDecoration() { public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { int position = ((LayoutParams) view.getLayoutParams()).getViewPosition(); outRect.set(4, 4, 4, 4); } }; final RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool(); recyclerView.setRecycledViewPool(viewPool); // recyclerView.addItemDecoration(itemDecoration); viewPool.setMaxRecycledViews(0, 20); final DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, true); recyclerView.setAdapter(delegateAdapter); final List<DelegateAdapter.Adapter> adapters = new LinkedList<>(); if (BANNER_LAYOUT) { adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 1) { @Override public void onViewRecycled(MainViewHolder holder) { if (holder.itemView instanceof ViewPager) { ((ViewPager) holder.itemView).setAdapter(null); } } @Override public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { if (viewType == 1) return new MainViewHolder(LayoutInflater.from(VLayoutActivity.this) .inflate(R.layout.view_pager, parent, false)); return super.onCreateViewHolder(parent, viewType); } @Override public int getItemViewType(int position) { return 1; } @Override protected void onBindViewHolderWithOffset(MainViewHolder holder, int position, int offsetTotal) { } @Override public void onBindViewHolder(MainViewHolder holder, int position) { if (holder.itemView instanceof ViewPager) { ViewPager viewPager = (ViewPager) holder.itemView; viewPager.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200)); // from position to get adapter viewPager.setAdapter(new PagerAdapter(this, viewPool)); } } }); } //{ // GridLayoutHelper helper = new GridLayoutHelper(10); // helper.setAspectRatio(4f); // helper.setGap(10); // adapters.add(new SubAdapter(this, helper, 80)); //} if (FLOAT_LAYOUT) { FloatLayoutHelper layoutHelper = new FloatLayoutHelper(); layoutHelper.setAlignType(FixLayoutHelper.BOTTOM_RIGHT); layoutHelper.setDefaultLocation(100, 400); LayoutParams layoutParams = new LayoutParams(150, 150); adapters.add(new SubAdapter(this, layoutHelper, 1, layoutParams)); } if (LINEAR_LAYOUT) { LinearLayoutHelper layoutHelper1 = new LinearLayoutHelper(); layoutHelper1.setAspectRatio(2.0f); LinearLayoutHelper layoutHelper2 = new LinearLayoutHelper(); layoutHelper2.setAspectRatio(4.0f); layoutHelper2.setDividerHeight(10); layoutHelper2.setMargin(10, 30, 10, 10); layoutHelper2.setPadding(10, 30, 10, 10); layoutHelper2.setBgColor(0xFFF5A623); adapters.add(new SubAdapter(this, layoutHelper1, 1)); adapters.add(new SubAdapter(this, layoutHelper2, 6) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { if (position % 2 == 0) { LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300); layoutParams.mAspectRatio = 5; holder.itemView.setLayoutParams(layoutParams); } } }); } if (STICKY_LAYOUT) { StickyLayoutHelper layoutHelper = new StickyLayoutHelper(); layoutHelper.setOffset(100); layoutHelper.setAspectRatio(4); adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100))); } { RangeGridLayoutHelper layoutHelper = new RangeGridLayoutHelper(4); layoutHelper.setBgColor(Color.GREEN); layoutHelper.setWeights(new float[] { 20f, 26.665f }); layoutHelper.setPadding(15, 15, 15, 15); layoutHelper.setMargin(15, 15, 15, 15); layoutHelper.setHGap(10); layoutHelper.setVGap(10); GridRangeStyle rangeStyle = new GridRangeStyle(); rangeStyle.setBgColor(Color.RED); rangeStyle.setSpanCount(2); rangeStyle.setWeights(new float[] { 46.665f }); rangeStyle.setPadding(15, 15, 15, 15); rangeStyle.setMargin(15, 15, 15, 15); rangeStyle.setHGap(5); rangeStyle.setVGap(5); layoutHelper.addRangeStyle(4, 7, rangeStyle); GridRangeStyle rangeStyle1 = new GridRangeStyle(); rangeStyle1.setBgColor(Color.YELLOW); rangeStyle1.setSpanCount(2); rangeStyle1.setWeights(new float[] { 46.665f }); rangeStyle1.setPadding(15, 15, 15, 15); rangeStyle1.setMargin(15, 15, 15, 15); rangeStyle1.setHGap(5); rangeStyle1.setVGap(5); layoutHelper.addRangeStyle(8, 11, rangeStyle1); adapters.add(new SubAdapter(this, layoutHelper, 16)); } if (SINGLE_LAYOUT) { SingleLayoutHelper layoutHelper = new SingleLayoutHelper(); layoutHelper.setBgColor(Color.rgb(135, 225, 90)); layoutHelper.setAspectRatio(4); layoutHelper.setMargin(10, 20, 10, 20); layoutHelper.setPadding(10, 10, 10, 10); adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100))); } if (COLUMN_LAYOUT) { ColumnLayoutHelper layoutHelper = new ColumnLayoutHelper(); layoutHelper.setBgColor(0xff00f0f0); layoutHelper.setWeights(new float[] { 40.0f, Float.NaN, 40 }); adapters.add(new SubAdapter(this, layoutHelper, 5) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { if (position == 0) { LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300); layoutParams.mAspectRatio = 4; holder.itemView.setLayoutParams(layoutParams); } else { LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300); layoutParams.mAspectRatio = Float.NaN; holder.itemView.setLayoutParams(layoutParams); } } }); } if (ONEN_LAYOUT) { OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper(); helper.setBgColor(0xff876384); helper.setAspectRatio(4.0f); helper.setColWeights(new float[] { 40f, 45f }); helper.setMargin(10, 20, 10, 20); helper.setPadding(10, 10, 10, 10); adapters.add(new SubAdapter(this, helper, 2)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper(); helper.setBgColor(0xffef8ba3); helper.setAspectRatio(2.0f); helper.setColWeights(new float[] { 40f }); helper.setRowWeight(30f); helper.setMargin(10, 20, 10, 20); helper.setPadding(10, 10, 10, 10); adapters.add(new SubAdapter(this, helper, 4) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); LayoutParams lp = (LayoutParams) holder.itemView.getLayoutParams(); if (position == 0) { lp.rightMargin = 1; } else if (position == 1) { } else if (position == 2) { lp.topMargin = 1; lp.rightMargin = 1; } } }); } if (ONEN_LAYOUT) { adapters.add(new SubAdapter(this, new OnePlusNLayoutHelper(), 0)); OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper(); helper.setBgColor(0xff87e543); helper.setAspectRatio(1.8f); helper.setColWeights(new float[] { 33.33f, 50f, 40f }); helper.setMargin(10, 20, 10, 20); helper.setPadding(10, 10, 10, 10); LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); adapters.add(new SubAdapter(this, helper, 3, lp) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); LayoutParams lp = (LayoutParams) holder.itemView.getLayoutParams(); if (position == 0) { lp.rightMargin = 1; } } }); } if (COLUMN_LAYOUT) { adapters.add(new SubAdapter(this, new ColumnLayoutHelper(), 0)); adapters.add(new SubAdapter(this, new ColumnLayoutHelper(), 4)); } if (FIX_LAYOUT) { FixLayoutHelper layoutHelper = new FixLayoutHelper(10, 10); adapters.add(new SubAdapter(this, layoutHelper, 0)); layoutHelper = new FixLayoutHelper(FixLayoutHelper.TOP_RIGHT, 20, 20); adapters.add(new SubAdapter(this, layoutHelper, 1) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); LayoutParams layoutParams = new LayoutParams(200, 200); holder.itemView.setLayoutParams(layoutParams); } }); } if (STICKY_LAYOUT) { StickyLayoutHelper layoutHelper = new StickyLayoutHelper(false); adapters.add(new SubAdapter(this, layoutHelper, 0)); layoutHelper = new StickyLayoutHelper(false); layoutHelper.setOffset(100); adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100))); } if (GRID_LAYOUT) { GridLayoutHelper layoutHelper = new GridLayoutHelper(2); layoutHelper.setMargin(7, 0, 7, 0); layoutHelper.setWeights(new float[] { 46.665f }); layoutHelper.setHGap(3); adapters.add(new SubAdapter(this, layoutHelper, 2)); layoutHelper = new GridLayoutHelper(4); layoutHelper.setWeights(new float[] { 20f, 26.665f }); layoutHelper.setMargin(7, 0, 7, 0); layoutHelper.setHGap(3); adapters.add(new SubAdapter(this, layoutHelper, 8)); } if (GRID_LAYOUT) { adapters.add(new SubAdapter(this, new GridLayoutHelper(4), 0)); GridLayoutHelper helper = new GridLayoutHelper(4); helper.setAspectRatio(4f); //helper.setColWeights(new float[]{40, 20, 30, 30}); // helper.setMargin(0, 10, 0, 10); helper.setGap(10); adapters.add(new SubAdapter(this, helper, 80) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); LayoutParams lp = (LayoutParams) holder.itemView.getLayoutParams(); // lp.bottomMargin = 1; // lp.rightMargin = 1; } }); } if (FIX_LAYOUT) { adapters.add(new SubAdapter(this, new ScrollFixLayoutHelper(20, 20), 1) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); LayoutParams layoutParams = new LayoutParams(200, 200); holder.itemView.setLayoutParams(layoutParams); } }); } if (LINEAR_LAYOUT) adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 10)); if (GRID_LAYOUT) { GridLayoutHelper helper = new GridLayoutHelper(3); helper.setMargin(0, 10, 0, 10); adapters.add(new SubAdapter(this, helper, 3)); } if (STAGGER_LAYOUT) { // adapters.add(new SubAdapter(this, new StaggeredGridLayoutHelper(2, 0), 0)); final StaggeredGridLayoutHelper helper = new StaggeredGridLayoutHelper(2, 10); helper.setMargin(20, 10, 10, 10); helper.setPadding(10, 10, 20, 10); helper.setBgColor(0xFF86345A); adapters.add(new SubAdapter(this, helper, 27) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200); if (position % 2 == 0) { layoutParams.mAspectRatio = 1.0f; } else { layoutParams.height = 340 + position % 7 * 20; } holder.itemView.setLayoutParams(layoutParams); } }); } if (COLUMN_LAYOUT) { // adapters.add(new SubAdapter(this, new ColumnLayoutHelper(), 3)); } if (GRID_LAYOUT) { // adapters.add(new SubAdapter(this, new GridLayoutHelper(4), 24)); } delegateAdapter.setAdapters(adapters); final Handler mainHandler = new Handler(Looper.getMainLooper()); trigger = new Runnable() { @Override public void run() { //recyclerView.scrollToPosition(22); //recyclerView.getAdapter().notifyDataSetChanged(); //mainHandler.postDelayed(trigger, 1000); //List<DelegateAdapter.Adapter> newAdapters = new ArrayList<>(); //newAdapters.add((new SubAdapter(VLayoutActivity.this, new ColumnLayoutHelper(), 3))); //newAdapters.add((new SubAdapter(VLayoutActivity.this, new GridLayoutHelper(4), 24))); //delegateAdapter.addAdapter(0, new SubAdapter(VLayoutActivity.this, new ColumnLayoutHelper(), 3)); //delegateAdapter.addAdapter(1, new SubAdapter(VLayoutActivity.this, new GridLayoutHelper(4), 24)); //delegateAdapter.notifyDataSetChanged(); } }; mainHandler.postDelayed(trigger, 1000); mSwipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { mainHandler.postDelayed(new Runnable() { @Override public void run() { mSwipeRefreshLayout.setRefreshing(false); } }, 2000L); } }); setListenerToRootView(); }
From source file:org.numixproject.hermes.activity.ConversationActivity.java
/** * On activity result/*from ww w . j a v a2s .com*/ */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode != RESULT_OK) { // ignore other result codes return; } switch (requestCode) { case REQUEST_CODE_SPEECH: ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); if (matches.size() > 0) { input.setText(matches.get(0)); } break; case REQUEST_CODE_JOIN: addRecentRoom(data.getExtras().getString("channel")); joinChannelBuffer = data.getExtras().getString("channel"); final Handler handler2 = new Handler(); handler2.postDelayed(new Runnable() { @Override public void run() { refreshActivity(); } }, 100); break; case REQUEST_CODE_USERS: Intent intent = new Intent(this, UserActivity.class); intent.putExtra(Extra.USER, data.getStringExtra(Extra.USER)); startActivityForResult(intent, REQUEST_CODE_USER); break; case REQUEST_CODE_NICK_COMPLETION: insertNickCompletion((AutoCompleteTextView) findViewById(R.id.input), data.getExtras().getString(Extra.USER)); break; case REQUEST_CODE_USER: final int actionId = data.getExtras().getInt(Extra.ACTION); final String nickname = data.getExtras().getString(Extra.USER); final IRCConnection connection = binder.getService().getConnection(server.getId()); final String conversation = server.getSelectedConversation(); final Handler handler = new Handler(); // XXX: Implement me - The action should be handled after onResume() // to catch the broadcasts... now we just wait a second // Yes .. that's very ugly - we need some kind of queue that is handled after onResume() new Thread() { @Override public void run() { try { Thread.sleep(1000); } catch (InterruptedException e) { // Do nothing } String nicknameWithoutPrefix = nickname; while (nicknameWithoutPrefix.startsWith("@") || nicknameWithoutPrefix.startsWith("+") || nicknameWithoutPrefix.startsWith(".") || nicknameWithoutPrefix.startsWith("%")) { // Strip prefix(es) now nicknameWithoutPrefix = nicknameWithoutPrefix.substring(1); } switch (actionId) { case User.ACTION_REPLY: final String replyText = nicknameWithoutPrefix + ": "; handler.post(new Runnable() { @Override public void run() { input.setText(replyText); input.setSelection(replyText.length()); } }); break; case User.ACTION_QUERY: Conversation query = server.getConversation(nicknameWithoutPrefix); if (query == null) { // Open a query if there's none yet query = new Query(nicknameWithoutPrefix); query.setHistorySize(binder.getService().getSettings().getHistorySize()); server.addConversation(query); Intent intent = Broadcast.createConversationIntent(Broadcast.CONVERSATION_NEW, server.getId(), nicknameWithoutPrefix); binder.getService().sendBroadcast(intent); } break; case User.ACTION_WHOIS: connection.whois(conversation, nicknameWithoutPrefix); break; case User.ACTION_OP: connection.op(conversation, nicknameWithoutPrefix); break; case User.ACTION_DEOP: connection.deOp(conversation, nicknameWithoutPrefix); break; case User.ACTION_VOICE: connection.voice(conversation, nicknameWithoutPrefix); break; case User.ACTION_DEVOICE: connection.deVoice(conversation, nicknameWithoutPrefix); break; case User.ACTION_KICK: connection.kick(conversation, nicknameWithoutPrefix); break; case User.ACTION_BAN: connection.ban(conversation, nicknameWithoutPrefix + "!*@*"); break; } } }.start(); break; } }
From source file:com.example.android.supportv7.widget.vlayout.VLayoutActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container); mFirstText = (TextView) findViewById(R.id.first); mLastText = (TextView) findViewById(R.id.last); mCountText = (TextView) findViewById(R.id.count); mTotalOffsetText = (TextView) findViewById(R.id.total_offset); final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view); findViewById(R.id.jump).setOnClickListener(new View.OnClickListener() { @Override//from w w w . ja v a2 s. com public void onClick(View v) { EditText position = (EditText) findViewById(R.id.position); if (!TextUtils.isEmpty(position.getText())) { try { int pos = Integer.parseInt(position.getText().toString()); recyclerView.scrollToPosition(pos); } catch (Exception e) { Log.e("VlayoutActivity", e.getMessage(), e); } } else { recyclerView.requestLayout(); } } }); final VirtualLayoutManager layoutManager = new VirtualLayoutManager(this); recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) { } @Override public void onScrolled(RecyclerView recyclerView, int i, int i2) { mFirstText.setText("First: " + layoutManager.findFirstVisibleItemPosition()); mLastText.setText( "Existing: " + MainViewHolder.existing + " Created: " + MainViewHolder.createdTimes); mCountText.setText("Count: " + recyclerView.getChildCount()); mTotalOffsetText.setText("Total Offset: " + layoutManager.getOffsetToStart()); } }); //layoutManager.setRecycleOffset(300); recyclerView.setLayoutManager(layoutManager); // layoutManager.setReverseLayout(true); RecyclerView.ItemDecoration itemDecoration = new RecyclerView.ItemDecoration() { public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { int position = ((LayoutParams) view.getLayoutParams()).getViewPosition(); outRect.set(4, 4, 4, 4); } }; final RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool(); recyclerView.setRecycledViewPool(viewPool); // recyclerView.addItemDecoration(itemDecoration); viewPool.setMaxRecycledViews(0, 20); final DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, true); recyclerView.setAdapter(delegateAdapter); final List<DelegateAdapter.Adapter> adapters = new LinkedList<>(); if (BANNER_LAYOUT) { adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 1) { @Override public void onViewRecycled(MainViewHolder holder) { if (holder.itemView instanceof ViewPager) { ((ViewPager) holder.itemView).setAdapter(null); } } @Override public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { if (viewType == 1) return new MainViewHolder(LayoutInflater.from(VLayoutActivity.this) .inflate(R.layout.view_pager, parent, false)); return super.onCreateViewHolder(parent, viewType); } @Override public int getItemViewType(int position) { return 1; } @Override protected void onBindViewHolderWithOffset(MainViewHolder holder, int position, int offsetTotal) { } @Override public void onBindViewHolder(MainViewHolder holder, int position) { if (holder.itemView instanceof ViewPager) { ViewPager viewPager = (ViewPager) holder.itemView; viewPager.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200)); // from position to get adapter viewPager.setAdapter(new PagerAdapter(this, viewPool)); } } }); } //{ // GridLayoutHelper helper = new GridLayoutHelper(10); // helper.setAspectRatio(4f); // helper.setGap(10); // adapters.add(new SubAdapter(this, helper, 80)); //} if (FLOAT_LAYOUT) { FloatLayoutHelper layoutHelper = new FloatLayoutHelper(); layoutHelper.setAlignType(FixLayoutHelper.BOTTOM_RIGHT); layoutHelper.setDefaultLocation(100, 400); LayoutParams layoutParams = new LayoutParams(150, 150); adapters.add(new SubAdapter(this, layoutHelper, 1, layoutParams)); } if (LINEAR_LAYOUT) { LinearLayoutHelper layoutHelper1 = new LinearLayoutHelper(); layoutHelper1.setAspectRatio(2.0f); LinearLayoutHelper layoutHelper2 = new LinearLayoutHelper(); layoutHelper2.setAspectRatio(4.0f); layoutHelper2.setDividerHeight(10); layoutHelper2.setMargin(10, 30, 10, 10); layoutHelper2.setPadding(10, 30, 10, 10); layoutHelper2.setBgColor(0xFFF5A623); adapters.add(new SubAdapter(this, layoutHelper1, 1)); adapters.add(new SubAdapter(this, layoutHelper2, 6) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { if (position % 2 == 0) { LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300); layoutParams.mAspectRatio = 5; holder.itemView.setLayoutParams(layoutParams); } } }); } { SingleLayoutHelper layoutHelper = new SingleLayoutHelper(); layoutHelper.setBgColor(Color.BLUE); layoutHelper.setMargin(0, 30, 0, 200); adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100))); } if (STICKY_LAYOUT) { StickyLayoutHelper layoutHelper = new StickyLayoutHelper(); //layoutHelper.setOffset(100); layoutHelper.setAspectRatio(4); adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100))); } { //final StaggeredGridLayoutHelper helper = new StaggeredGridLayoutHelper(3, 10); //helper.setBgColor(0xFF86345A); //adapters.add(new SubAdapter(this, helper, 4) { // @Override // public void onBindViewHolder(MainViewHolder holder, int position) { // super.onBindViewHolder(holder, position); // LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300); // if (position % 2 == 0) { // layoutParams.mAspectRatio = 1.0f; // } else { // layoutParams.height = 340 + position % 7 * 20; // } // holder.itemView.setLayoutParams(layoutParams); // } //}); final GridLayoutHelper helper = new GridLayoutHelper(3, 4); helper.setBgColor(0xFF86345A); adapters.add(new SubAdapter(this, helper, 4) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300); holder.itemView.setLayoutParams(layoutParams); } }); } { RangeGridLayoutHelper layoutHelper = new RangeGridLayoutHelper(4); layoutHelper.setBgColor(Color.GREEN); layoutHelper.setWeights(new float[] { 20f, 26.665f }); layoutHelper.setPadding(15, 15, 15, 15); layoutHelper.setMargin(15, 15, 15, 15); layoutHelper.setHGap(10); layoutHelper.setVGap(10); GridRangeStyle rangeStyle = new GridRangeStyle(); rangeStyle.setBgColor(Color.RED); rangeStyle.setSpanCount(2); rangeStyle.setWeights(new float[] { 46.665f }); rangeStyle.setPadding(15, 15, 15, 15); rangeStyle.setMargin(15, 15, 15, 15); rangeStyle.setHGap(5); rangeStyle.setVGap(5); layoutHelper.addRangeStyle(4, 7, rangeStyle); GridRangeStyle rangeStyle1 = new GridRangeStyle(); rangeStyle1.setBgColor(Color.YELLOW); rangeStyle1.setSpanCount(2); rangeStyle1.setWeights(new float[] { 46.665f }); rangeStyle1.setPadding(15, 15, 15, 15); rangeStyle1.setMargin(15, 15, 15, 15); rangeStyle1.setHGap(5); rangeStyle1.setVGap(5); layoutHelper.addRangeStyle(8, 11, rangeStyle1); adapters.add(new SubAdapter(this, layoutHelper, 16)); } if (SINGLE_LAYOUT) { SingleLayoutHelper layoutHelper = new SingleLayoutHelper(); layoutHelper.setBgColor(Color.rgb(135, 225, 90)); layoutHelper.setAspectRatio(4); layoutHelper.setMargin(10, 20, 10, 20); layoutHelper.setPadding(10, 10, 10, 10); adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100))); } if (COLUMN_LAYOUT) { ColumnLayoutHelper layoutHelper = new ColumnLayoutHelper(); layoutHelper.setBgColor(0xff00f0f0); layoutHelper.setWeights(new float[] { 40.0f, Float.NaN, 40 }); adapters.add(new SubAdapter(this, layoutHelper, 5) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { if (position == 0) { LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300); layoutParams.mAspectRatio = 4; holder.itemView.setLayoutParams(layoutParams); } else { LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300); layoutParams.mAspectRatio = Float.NaN; holder.itemView.setLayoutParams(layoutParams); } } }); } if (ONEN_LAYOUT) { OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper(); helper.setBgColor(0xff876384); helper.setAspectRatio(4.0f); helper.setColWeights(new float[] { 40f, 45f }); helper.setMargin(10, 20, 10, 20); helper.setPadding(10, 10, 10, 10); adapters.add(new SubAdapter(this, helper, 2)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper(); helper.setBgColor(0xffef8ba3); helper.setAspectRatio(2.0f); helper.setColWeights(new float[] { 40f }); helper.setRowWeight(30f); helper.setMargin(10, 20, 10, 20); helper.setPadding(10, 10, 10, 10); adapters.add(new SubAdapter(this, helper, 4) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); LayoutParams lp = (LayoutParams) holder.itemView.getLayoutParams(); if (position == 0) { lp.rightMargin = 1; } else if (position == 1) { } else if (position == 2) { lp.topMargin = 1; lp.rightMargin = 1; } } }); } if (ONEN_LAYOUT) { adapters.add(new SubAdapter(this, new OnePlusNLayoutHelper(), 0)); OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper(); helper.setBgColor(0xff87e543); helper.setAspectRatio(1.8f); helper.setColWeights(new float[] { 33.33f, 50f, 40f }); helper.setMargin(10, 20, 10, 20); helper.setPadding(10, 10, 10, 10); LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); adapters.add(new SubAdapter(this, helper, 3, lp) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); LayoutParams lp = (LayoutParams) holder.itemView.getLayoutParams(); if (position == 0) { lp.rightMargin = 1; } } }); } if (COLUMN_LAYOUT) { adapters.add(new SubAdapter(this, new ColumnLayoutHelper(), 0)); adapters.add(new SubAdapter(this, new ColumnLayoutHelper(), 4)); } if (FIX_LAYOUT) { FixLayoutHelper layoutHelper = new FixLayoutHelper(10, 10); adapters.add(new SubAdapter(this, layoutHelper, 0)); layoutHelper = new FixLayoutHelper(FixLayoutHelper.TOP_RIGHT, 20, 20); adapters.add(new SubAdapter(this, layoutHelper, 1) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200); holder.itemView.setLayoutParams(layoutParams); } }); } //if (STICKY_LAYOUT) { // StickyLayoutHelper layoutHelper = new StickyLayoutHelper(false); // adapters.add(new SubAdapter(this, layoutHelper, 0)); // layoutHelper = new StickyLayoutHelper(false); // layoutHelper.setOffset(100); // adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100))); //} if (GRID_LAYOUT) { GridLayoutHelper layoutHelper = new GridLayoutHelper(2); layoutHelper.setMargin(7, 0, 7, 0); layoutHelper.setWeights(new float[] { 46.665f }); layoutHelper.setHGap(3); adapters.add(new SubAdapter(this, layoutHelper, 2)); layoutHelper = new GridLayoutHelper(4); layoutHelper.setWeights(new float[] { 20f, 26.665f }); layoutHelper.setMargin(7, 0, 7, 0); layoutHelper.setHGap(3); adapters.add(new SubAdapter(this, layoutHelper, 8)); } if (GRID_LAYOUT) { adapters.add(new SubAdapter(this, new GridLayoutHelper(4), 0)); GridLayoutHelper helper = new GridLayoutHelper(4); helper.setAspectRatio(4f); //helper.setColWeights(new float[]{40, 20, 30, 30}); // helper.setMargin(0, 10, 0, 10); helper.setGap(10); adapters.add(new SubAdapter(this, helper, 80) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); LayoutParams lp = (LayoutParams) holder.itemView.getLayoutParams(); // lp.bottomMargin = 1; // lp.rightMargin = 1; } }); } if (FIX_LAYOUT) { adapters.add(new SubAdapter(this, new ScrollFixLayoutHelper(20, 20), 1) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); LayoutParams layoutParams = new LayoutParams(200, 200); holder.itemView.setLayoutParams(layoutParams); } }); } if (LINEAR_LAYOUT) adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 10)); if (GRID_LAYOUT) { GridLayoutHelper helper = new GridLayoutHelper(3); helper.setMargin(0, 10, 0, 10); adapters.add(new SubAdapter(this, helper, 3)); } if (STAGGER_LAYOUT) { // adapters.add(new SubAdapter(this, new StaggeredGridLayoutHelper(2, 0), 0)); final StaggeredGridLayoutHelper helper = new StaggeredGridLayoutHelper(2, 10); helper.setMargin(20, 10, 10, 10); helper.setPadding(10, 10, 20, 10); helper.setBgColor(0xFF86345A); adapters.add(new SubAdapter(this, helper, 27) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200); if (position % 2 == 0) { layoutParams.mAspectRatio = 1.0f; } else { layoutParams.height = 340 + position % 7 * 20; } holder.itemView.setLayoutParams(layoutParams); } }); } if (COLUMN_LAYOUT) { // adapters.add(new SubAdapter(this, new ColumnLayoutHelper(), 3)); } if (GRID_LAYOUT) { // adapters.add(new SubAdapter(this, new GridLayoutHelper(4), 24)); } delegateAdapter.setAdapters(adapters); final Handler mainHandler = new Handler(Looper.getMainLooper()); trigger = new Runnable() { @Override public void run() { //recyclerView.scrollToPosition(22); //recyclerView.getAdapter().notifyDataSetChanged(); //mainHandler.postDelayed(trigger, 1000); //List<DelegateAdapter.Adapter> newAdapters = new ArrayList<>(); //newAdapters.add((new SubAdapter(VLayoutActivity.this, new ColumnLayoutHelper(), 3))); //newAdapters.add((new SubAdapter(VLayoutActivity.this, new GridLayoutHelper(4), 24))); //delegateAdapter.addAdapter(0, new SubAdapter(VLayoutActivity.this, new ColumnLayoutHelper(), 3)); //delegateAdapter.addAdapter(1, new SubAdapter(VLayoutActivity.this, new GridLayoutHelper(4), 24)); //delegateAdapter.notifyDataSetChanged(); } }; mainHandler.postDelayed(trigger, 1000); mSwipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { mainHandler.postDelayed(new Runnable() { @Override public void run() { mSwipeRefreshLayout.setRefreshing(false); } }, 2000L); } }); setListenerToRootView(); }
From source file:com.usertaxi.TaxiOntheWay_Activity.java
private void animateMarker(final Marker marker, final LatLng toPosition, final boolean hideMarker) { final Handler handler = new Handler(); final long start = SystemClock.uptimeMillis(); Projection proj = map.getProjection(); Point startPoint = proj.toScreenLocation(marker.getPosition()); final LatLng startLatLng = proj.fromScreenLocation(startPoint);//marker1.getPosition(); final long duration = 600; final Interpolator interpolator = new LinearInterpolator(); handler.post(new Runnable() { @Override/* ww w . j a v a2s. co m*/ public void run() { long elapsed = SystemClock.uptimeMillis() - start; float t = interpolator.getInterpolation((float) elapsed / duration); double lng = t * toPosition.longitude + (1 - t) * startLatLng.longitude; double lat = t * toPosition.latitude + (1 - t) * startLatLng.latitude; marker.setPosition(new LatLng(lat, lng)); if (t < 1.0) { // Post again 16ms later. handler.postDelayed(this, 16); } else { if (hideMarker) { marker.setVisible(false); } else { marker.setVisible(true); } } // map.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat, lng))); } }); AppPreferences.setPreviouslat(getApplicationContext(), AppPreferences.getCurrentlat(getApplicationContext())); AppPreferences.setPreviouslong(getApplicationContext(), AppPreferences.getCurrentlong(getApplicationContext())); }