List of usage examples for android.widget ListView setAdapter
@Override public void setAdapter(ListAdapter adapter)
From source file:com.sharedcab.batchcar.MainActivity.java
private void setNewListAdapter() { ListView list; DrawerAdapter adapter;//from w w w. j av a2s . c om ArrayList<HashMap<String, String>> menuList = new ArrayList<HashMap<String, String>>(); HashMap<String, String> map = new HashMap<String, String>(); map.put("text", "Book a Ride"); map.put("icon", "ride"); menuList.add(map); map = new HashMap<String, String>(); map.put("text", "Booking History"); map.put("icon", "bookings"); menuList.add(map); map = new HashMap<String, String>(); map.put("text", "Account Details"); map.put("icon", "details"); menuList.add(map); map = new HashMap<String, String>(); map.put("text", "How to Use?"); map.put("icon", "help"); menuList.add(map); list = (ListView) findViewById(R.id.left_drawer); adapter = new DrawerAdapter(this, menuList); list.setAdapter(adapter); }
From source file:de.j4velin.mapsmeasure.Map.java
@SuppressLint("NewApi") @Override/*from w ww .ja v a 2 s . c o m*/ public void onCreate(final Bundle savedInstanceState) { try { super.onCreate(savedInstanceState); } catch (final BadParcelableException bpe) { bpe.printStackTrace(); } setContentView(R.layout.activity_map); formatter_no_dec.setMaximumFractionDigits(0); formatter_two_dec.setMaximumFractionDigits(2); final SharedPreferences prefs = getSharedPreferences("settings", Context.MODE_PRIVATE); // use metric a the default everywhere, except in the US metric = prefs.getBoolean("metric", !Locale.getDefault().equals(Locale.US)); final View topCenterOverlay = findViewById(R.id.topCenterOverlay); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); final View menuButton = findViewById(R.id.menu); if (menuButton != null) { menuButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { mDrawerLayout.openDrawer(GravityCompat.START); } }); } if (mDrawerLayout != null) { mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() { private boolean menuButtonVisible = true; @Override public void onDrawerStateChanged(int newState) { } @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onDrawerSlide(final View drawerView, final float slideOffset) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) topCenterOverlay.setAlpha(1 - slideOffset); if (menuButtonVisible && menuButton != null && slideOffset > 0) { menuButton.setVisibility(View.INVISIBLE); menuButtonVisible = false; } } @Override public void onDrawerOpened(final View drawerView) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) topCenterOverlay.setVisibility(View.INVISIBLE); } @Override public void onDrawerClosed(final View drawerView) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) topCenterOverlay.setVisibility(View.VISIBLE); if (menuButton != null) { menuButton.setVisibility(View.VISIBLE); menuButtonVisible = true; } } }); } mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); if (mMap == null) { Dialog d = GooglePlayServicesUtil .getErrorDialog(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this), this, 0); d.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { finish(); } }); d.show(); return; } marker = BitmapDescriptorFactory.fromResource(R.drawable.marker); mMap.setOnMarkerClickListener(new OnMarkerClickListener() { @Override public boolean onMarkerClick(final Marker click) { addPoint(click.getPosition()); return true; } }); mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() { @Override public boolean onMyLocationButtonClick() { if (mMap.getMyLocation() != null) { LatLng myLocation = new LatLng(mMap.getMyLocation().getLatitude(), mMap.getMyLocation().getLongitude()); double distance = SphericalUtil.computeDistanceBetween(myLocation, mMap.getCameraPosition().target); // Only if the distance is less than 50cm we are on our location, add the marker if (distance < 0.5) { Toast.makeText(Map.this, R.string.marker_on_current_location, Toast.LENGTH_SHORT).show(); addPoint(myLocation); } } return false; } }); // check if open with csv file if (Intent.ACTION_VIEW.equals(getIntent().getAction())) { try { Util.loadFromFile(getIntent().getData(), this); if (!trace.isEmpty()) mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(trace.peek(), 16)); } catch (IOException e) { Toast.makeText(this, getString(R.string.error, e.getClass().getSimpleName() + "\n" + e.getMessage()), Toast.LENGTH_LONG).show(); e.printStackTrace(); } } mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(final Bundle bundle) { Location l = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); if (l != null && mMap.getCameraPosition().zoom <= 2) { mMap.moveCamera(CameraUpdateFactory .newLatLngZoom(new LatLng(l.getLatitude(), l.getLongitude()), 16)); } mGoogleApiClient.disconnect(); } @Override public void onConnectionSuspended(int cause) { } }).build(); mGoogleApiClient.connect(); valueTv = (TextView) findViewById(R.id.distance); updateValueText(); valueTv.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { if (type == MeasureType.DISTANCE) changeType(MeasureType.AREA); // only switch to elevation mode is an internet connection is // available and user has access to this feature else if (type == MeasureType.AREA && Util.checkInternetConnection(Map.this) && PRO_VERSION) changeType(MeasureType.ELEVATION); else changeType(MeasureType.DISTANCE); } }); View delete = findViewById(R.id.delete); delete.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { removeLast(); } }); delete.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(final View v) { AlertDialog.Builder builder = new AlertDialog.Builder(Map.this); builder.setMessage(getString(R.string.delete_all, trace.size())); builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { clear(); dialog.dismiss(); } }); builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); return true; } }); mMap.setOnMapClickListener(new OnMapClickListener() { @Override public void onMapClick(final LatLng center) { addPoint(center); } }); // Drawer stuff ListView drawerList = (ListView) findViewById(R.id.left_drawer); drawerListAdapert = new DrawerListAdapter(this); drawerList.setAdapter(drawerListAdapert); drawerList.setDivider(null); drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> parent, final View view, int position, long id) { switch (position) { case 0: // Search before Android 5.0 Dialogs.getSearchDialog(Map.this).show(); closeDrawer(); break; case 2: // Units Dialogs.getUnits(Map.this, distance, SphericalUtil.computeArea(trace)).show(); closeDrawer(); break; case 3: // distance changeType(MeasureType.DISTANCE); break; case 4: // area changeType(MeasureType.AREA); break; case 5: // elevation if (PRO_VERSION) { changeType(MeasureType.ELEVATION); } else { Dialogs.getElevationAccessDialog(Map.this, mService).show(); } break; case 7: // map changeView(GoogleMap.MAP_TYPE_NORMAL); break; case 8: // satellite changeView(GoogleMap.MAP_TYPE_HYBRID); break; case 9: // terrain changeView(GoogleMap.MAP_TYPE_TERRAIN); break; case 11: // save Dialogs.getSaveNShare(Map.this, trace).show(); closeDrawer(); break; case 12: // more apps try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:j4velin")) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (ActivityNotFoundException anf) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/developer?id=j4velin")) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } break; case 13: // about Dialogs.getAbout(Map.this).show(); closeDrawer(); break; default: break; } } }); changeView(prefs.getInt("mapView", GoogleMap.MAP_TYPE_NORMAL)); changeType(MeasureType.DISTANCE); // KitKat translucent decor enabled? -> Add some margin/padding to the // drawer and the map if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { int statusbar = Util.getStatusBarHeight(this); FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) topCenterOverlay.getLayoutParams(); lp.setMargins(0, statusbar + 10, 0, 0); topCenterOverlay.setLayoutParams(lp); // on most devices and in most orientations, the navigation bar // should be at the bottom and therefore reduces the available // display height int navBarHeight = Util.getNavigationBarHeight(this); DisplayMetrics total, available; total = new DisplayMetrics(); available = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(available); API17Wrapper.getRealMetrics(getWindowManager().getDefaultDisplay(), total); boolean navBarOnRight = getResources() .getConfiguration().orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE && (total.widthPixels - available.widthPixels > 0); if (navBarOnRight) { // in landscape on phones, the navigation bar might be at the // right side, reducing the available display width mMap.setPadding(mDrawerLayout == null ? Util.dpToPx(this, 200) : 0, statusbar, navBarHeight, 0); drawerList.setPadding(0, statusbar + 10, 0, 0); if (menuButton != null) menuButton.setPadding(0, 0, 0, 0); } else { mMap.setPadding(0, statusbar, 0, navBarHeight); drawerList.setPadding(0, statusbar + 10, 0, 0); drawerListAdapert.setMarginBottom(navBarHeight); if (menuButton != null) menuButton.setPadding(0, 0, 0, navBarHeight); } } mMap.setMyLocationEnabled(true); PRO_VERSION |= prefs.getBoolean("pro", false); if (!PRO_VERSION) { bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND") .setPackage("com.android.vending"), mServiceConn, Context.BIND_AUTO_CREATE); } }
From source file:com.mdlive.sav.MDLiveSearchProvider.java
/** * Instantiating array adapter to populate the listView * The layout android.R.layout.simple_list_item_single_choice creates radio button for each listview item * * @param list : Dependent users array list */// w w w. ja va2 s . com private void showListViewDialog(final ArrayList<String> list, final TextView selectedText, final String key, final ArrayList<HashMap<String, String>> typeList) { /*We need to get the instance of the LayoutInflater*/ final AlertDialog.Builder alertDialog = new AlertDialog.Builder(MDLiveSearchProvider.this); LayoutInflater inflater = getLayoutInflater(); View convertView = inflater.inflate(R.layout.mdlive_screen_popup, null); alertDialog.setView(convertView); ListView lv = (ListView) convertView.findViewById(R.id.popupListview); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list); lv.setAdapter(adapter); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); final AlertDialog dialog = alertDialog.create(); dialog.show(); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String SelectedText = list.get(position); HashMap<String, String> localMap = typeList.get(position); for (Map.Entry entry : localMap.entrySet()) { if (SelectedText.equals(entry.getValue().toString())) { postParams.put(key, entry.getKey().toString()); break; //breaking because its one to one map } } specialityBasedOnProvider(SelectedText, key); String oldChoice = selectedText.getText().toString(); selectedText.setText(SelectedText); dialog.dismiss(); // if user selects a different Provider type, then reload this screen if (!oldChoice.equals(SelectedText)) { SharedPreferences sharedpreferences = getSharedPreferences( PreferenceConstants.MDLIVE_USER_PREFERENCES, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PreferenceConstants.PROVIDER_MODE, SelectedText); int providerType = MDLiveConfig.PROVIDERTYPE_MAP.get(SelectedText) == null ? MDLiveConfig.UNMAPPED : MDLiveConfig.PROVIDERTYPE_MAP.get(SelectedText); if (providerType == MDLiveConfig.UNMAPPED) editor.putString(PreferenceConstants.PROVIDERTYPE_ID, ""); else editor.putString(PreferenceConstants.PROVIDERTYPE_ID, String.valueOf(providerType)); editor.commit(); // now reload the screen //recreate(); } } }); }
From source file:net.stefanopallicca.android.awsmonitor.MainActivity.java
public void launchMainApp() { setContentView(R.layout.main);// ww w . jav a2s .c om //mDisplay = (TextView) findViewById(R.id.display); context = getApplicationContext(); /* * Check device for Play Services APK. * If check succeeds, proceed with GSN server registration and download available virtual sensors. */ if (checkPlayServices()) { gcm = GoogleCloudMessaging.getInstance(this); regid = getRegistrationId(context); server = new GsnServer(_sharedPref.getString("pref_server_url", ""), Integer.parseInt(_sharedPref.getString("pref_server_port", ""))); /*if (regid.isEmpty()) { registerInBackground(); } else { Log.i(TAG, "This version has already been registered to GCM "+regid); }*/ boolean registered_to_gsnserver = false; try { registered_to_gsnserver = server.checkDeviceRegistration(regid); if (!registered_to_gsnserver) registered_to_gsnserver = server.sendRegistrationIdToBackend(regid); } catch (ConnectTimeoutException e) { int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, getString(R.string.connect_timeout) + " " + server.getURL() + ":" + server.getPort(), duration); toast.show(); } catch (HttpException e) { int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, getString(R.string.service_not_found), duration); toast.show(); } if (!regid.isEmpty() && registered_to_gsnserver) { Log.i(TAG, "This device has been registered to GSN server"); //mDisplay.append("Device ready to receive notifications from GSN server " + _sharedPref.getString("pref_server_url", "")); server.getSummary(); setContentView(R.layout.main); ListView listView = getListView(); mDisplay = (TextView) findViewById(R.id.main_header); mDisplay.append(server.getName()); List<VirtualSensor> list = new LinkedList<VirtualSensor>(); for (int i = 0; i < server.virtualSensors.size(); i++) { // only add virtual sensors with fields to list (skip app-generated virtual sensors) if (server.virtualSensors.get(i).getNumFields() > 0) list.add(server.virtualSensors.get(i)); } VirtualSensorListAdapter adapter = new VirtualSensorListAdapter(this, R.layout.vs_row, list); listView.setAdapter(adapter); } else { //mDisplay.append("This device is not ready to receive notifications from a GSN server. Go to settings to configure a GSN server"); } } else { Log.i(TAG, "No valid Google Play Services APK found."); } }
From source file:com.example.innf.newchangtu.Map.view.activity.MainActivity.java
private void fastSend() { Log.d(TAG, "fastSend: is called"); String[] remark = { "?", "", "" }; ArrayAdapter<String> adapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, remark);//from ww w. j a v a2 s . c o m View view1 = View.inflate(MainActivity.this, R.layout.show_dialog, null); final ListView listView = (ListView) view1.findViewById(R.id.dialog_list_view); listView.setAdapter(adapter); AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); final AlertDialog dialog = builder.setTitle("?").setView(view1) .setPositiveButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { sendSMS(); } }).setNegativeButton("?", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { } }).show(); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { if (i == 2) { final EditText editText = new EditText(MainActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); AlertDialog dialog = builder.setTitle("").setView(editText) .setPositiveButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { setRemark(editText.getText().toString()); sendSMS(); Log.d(TAG, editText.getText().toString()); } }).setNegativeButton("?", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { } }).show(); } else { setRemark(listView.getItemAtPosition(i).toString()); sendSMS(); } dialog.dismiss(); } }); }
From source file:be.artoria.belfortapp.fragments.MapFragment.java
private void initRouteInstructions(Road road) { if (road != null && road.mNodes != null) { final ListView lstRouteDesc = (ListView) getView().findViewById(R.id.lstRouteDesc); final List<DescriptionRow> descriptions = new ArrayList<DescriptionRow>(); int waypoint = 0; for (int i = 0; i < road.mNodes.size(); i++) { final RoadNode node = road.mNodes.get(i); String instructions = node.mInstructions; if (node.mInstructions.toUpperCase() .contains(getResources().getString(R.string.destination).toUpperCase())) { instructions = RouteManager.getInstance().getWaypoints().get(waypoint).getName(); waypoint++;/*from ww w. j a va2s. c o m*/ } descriptions.add(new DescriptionRow(getIconForManeuver(node.mManeuverType), instructions)); } lstRouteDesc.setAdapter( new RouteDescAdapter(getActivity(), android.R.layout.simple_list_item_1, descriptions)); } }
From source file:com.dirkgassen.wator.ui.activity.MainActivity.java
/** * Initializes this activity/* w w w . j ava2s .c om*/ * @param savedInstanceState if this parameter is not {@code null} the activity state is restored to the information * in this Bundle */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_layout); Toolbar myToolbar = (Toolbar) findViewById(R.id.main_toolbar); setSupportActionBar(myToolbar); // More info: http://codetheory.in/difference-between-setdisplayhomeasupenabled-sethomebuttonenabled-and-setdisplayshowhomeenabled/ getSupportActionBar().setDisplayHomeAsUpEnabled(true); newWorldView = findViewById(R.id.new_world_fragment_container); fpsOkColor = ContextCompat.getColor(this, R.color.fps_ok_color); fpsWarningColor = ContextCompat.getColor(this, R.color.fps_warning_color); desiredFpsSlider = (RangeSlider) findViewById(R.id.desired_fps); threadsSlider = (RangeSlider) findViewById(R.id.threads); desiredFpsSlider.setOnTouchListener(new View.OnTouchListener() { @SuppressLint("ClickableViewAccessibility") @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: v.getParent().requestDisallowInterceptTouchEvent(true); break; case MotionEvent.ACTION_UP: v.getParent().requestDisallowInterceptTouchEvent(false); break; } v.onTouchEvent(event); return true; } }); desiredFpsSlider.setOnValueChangeListener(new RangeSlider.OnValueChangeListener() { @Override public void onValueChange(RangeSlider slider, int oldVal, int newVal, boolean fromUser) { synchronized (MainActivity.this) { if (newVal == 0) { if (currentDrawFps != null) { currentDrawFps.setVisibility(View.INVISIBLE); } } else { if (currentDrawFps != null) { currentDrawFps.setVisibility(View.VISIBLE); } } if (fromUser) { if (simulatorRunnable.setTargetFps(newVal)) { startSimulatorThread(); } } } } }); threadsSlider.setOnTouchListener(new View.OnTouchListener() { @SuppressLint("ClickableViewAccessibility") @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: v.getParent().requestDisallowInterceptTouchEvent(true); break; case MotionEvent.ACTION_UP: v.getParent().requestDisallowInterceptTouchEvent(false); break; } v.onTouchEvent(event); return true; } }); threadsSlider.setOnValueChangeListener(new RangeSlider.OnValueChangeListener() { @Override public void onValueChange(RangeSlider slider, int oldVal, int newVal, boolean fromUser) { simulatorRunnable.setThreadCount(newVal); } }); handler = new Handler(); updateFpsRunnable = new Runnable() { @Override public void run() { synchronized (MainActivity.this) { if (currentSimFps != null) { if (simulatorRunnable.getTargetFps() == 0) { currentSimFps.setText(getString(R.string.paused)); currentSimFps.setTextColor(fpsOkColor); } else { int fps = (int) simulatorRunnable.getAvgFps(); currentSimFps.setText(getString(R.string.current_simulation_fps, fps)); int newTextColor = fps < simulatorRunnable.getTargetFps() ? fpsWarningColor : fpsOkColor; currentSimFps.setTextColor(newTextColor); } } if (currentDrawFps != null) { float fps = drawingAverageTime.getAverage(); if (fps != 0f) { fps = 1000 / fps; } currentDrawFps.setText(getString(R.string.current_drawing_fps, (int) fps)); int newTextColor = fps < simulatorRunnable.getTargetFps() ? fpsWarningColor : fpsOkColor; currentDrawFps.setTextColor(newTextColor); } } } }; if (savedInstanceState == null) { simulator = new Simulator(new WorldParameters()); } else { WorldParameters parameters = new WorldParameters() .setWidth(savedInstanceState.getShort(WorldKeys.WORLD_WIDTH_KEY)) .setHeight(savedInstanceState.getShort(WorldKeys.WORLD_HEIGHT_KEY)) .setFishBreedTime(savedInstanceState.getShort(WorldKeys.FISH_BREED_TIME_KEY)) .setSharkBreedTime(savedInstanceState.getShort(WorldKeys.SHARK_BREED_TIME_KEY)) .setSharkStarveTime(savedInstanceState.getShort(WorldKeys.SHARK_STARVE_TIME_KEY)) .setInitialFishCount(0).setInitialSharkCount(0); simulator = new Simulator(parameters); short[] fishAge = savedInstanceState.getShortArray(WorldKeys.FISH_AGE_KEY); if (fishAge != null) { short[] fishPosX = savedInstanceState.getShortArray(WorldKeys.FISH_POSITIONS_X_KEY); if (fishPosX != null) { short[] fishPosY = savedInstanceState.getShortArray(WorldKeys.FISH_POSITIONS_Y_KEY); if (fishPosY != null) { for (int fishNo = 0; fishNo < fishAge.length; fishNo++) { simulator.setFish(fishPosX[fishNo], fishPosY[fishNo], fishAge[fishNo]); } } } } short[] sharkAge = savedInstanceState.getShortArray(WorldKeys.SHARK_AGE_KEY); if (sharkAge != null) { short[] sharkHunger = savedInstanceState.getShortArray(WorldKeys.SHARK_HUNGER_KEY); if (sharkHunger != null) { short[] sharkPosX = savedInstanceState.getShortArray(WorldKeys.SHARK_POSITIONS_X_KEY); if (sharkPosX != null) { short[] sharkPosY = savedInstanceState.getShortArray(WorldKeys.SHARK_POSITIONS_Y_KEY); if (sharkPosY != null) { for (int sharkNo = 0; sharkNo < sharkAge.length; sharkNo++) { simulator.setShark(sharkPosX[sharkNo], sharkPosY[sharkNo], sharkAge[sharkNo], sharkHunger[sharkNo]); } } } } } if (savedInstanceState.containsKey(WorldKeys.INITIAL_FISH_COUNT_KEY) || savedInstanceState.containsKey(WorldKeys.INITIAL_SHARK_COUNT_KEY)) { if (savedInstanceState.containsKey(WorldKeys.INITIAL_FISH_COUNT_KEY)) { parameters.setInitialFishCount(savedInstanceState.getInt(WorldKeys.INITIAL_FISH_COUNT_KEY)); } if (savedInstanceState.containsKey(WorldKeys.INITIAL_SHARK_COUNT_KEY)) { parameters.setInitialSharkCount(savedInstanceState.getInt(WorldKeys.INITIAL_SHARK_COUNT_KEY)); } previousWorldParameters = parameters; } } simulatorRunnable = new SimulatorRunnable(simulator); if (savedInstanceState != null && savedInstanceState.containsKey(WorldKeys.TARGET_FPS_KEY)) { simulatorRunnable.setTargetFps(savedInstanceState.getInt(WorldKeys.TARGET_FPS_KEY)); } simulatorRunnable.registerSimulatorRunnableObserver(this); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); final ListView drawerList = (ListView) findViewById(R.id.drawer_commands); drawerList.setAdapter(new DrawerListAdapter(getDrawerCommands())); drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { DrawerCommandItem command = (DrawerCommandItem) drawerList.getItemAtPosition(position); if (command != null) { command.execute(); } } }); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.open_drawer_description, R.string.close_drawer_description) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); supportInvalidateOptionsMenu(); synchronized (MainActivity.this) { currentSimFps = (TextView) findViewById(R.id.fps_simulator); currentDrawFps = (TextView) findViewById(R.id.fps_drawing); } } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); supportInvalidateOptionsMenu(); synchronized (MainActivity.this) { currentSimFps = null; currentDrawFps = null; } } }; drawerLayout.addDrawerListener(drawerToggle); }
From source file:com.ibuildapp.romanblack.MultiContactsPlugin.ContactDetailsActivity.java
@Override public void create() { try {// w w w . j a v a 2s. c o m setContentView(R.layout.grouped_contacts_details); Intent currentIntent = getIntent(); Bundle store = currentIntent.getExtras(); widget = (Widget) store.getSerializable("Widget"); if (widget == null) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100); return; } person = (Person) store.getSerializable("person"); if (person == null) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100); return; } setTopBarTitle(widget.getTitle()); Boolean single = currentIntent.getBooleanExtra("single", true); setTopBarLeftButtonTextAndColor( single ? getResources().getString(R.string.common_home_upper) : getResources().getString(R.string.common_back_upper), getResources().getColor(android.R.color.black), true, new View.OnClickListener() { @Override public void onClick(View view) { finish(); } }); setTopBarTitleColor(getResources().getColor(android.R.color.black)); setTopBarBackgroundColor(Statics.color1); if ((Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_MAIL))) || (Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_SMS))) || (Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_SMS)))) { ImageView shareButton = (ImageView) getLayoutInflater() .inflate(R.layout.grouped_contacts_share_button, null); shareButton.setLayoutParams( new LinearLayout.LayoutParams((int) (29 * getResources().getDisplayMetrics().density), (int) (39 * getResources().getDisplayMetrics().density))); shareButton.setColorFilter(Color.BLACK); setTopBarRightButton(shareButton, getString(R.string.multicontacts_list_share), new View.OnClickListener() { @Override public void onClick(View v) { DialogSharing.Configuration.Builder sharingDialogBuilder = new DialogSharing.Configuration.Builder(); if (Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_MAIL))) sharingDialogBuilder .setEmailSharingClickListener(new DialogSharing.Item.OnClickListener() { @Override public void onClick() { String message = getContactInfo(); Intent email = new Intent(Intent.ACTION_SEND); email.putExtra(Intent.EXTRA_TEXT, message); email.setType("message/rfc822"); startActivity(Intent.createChooser(email, getString(R.string.choose_email_client))); } }); if (Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_SMS))) sharingDialogBuilder .setSmsSharingClickListener(new DialogSharing.Item.OnClickListener() { @Override public void onClick() { String message = getContactInfo(); try { Utils.sendSms(ContactDetailsActivity.this, message); } catch (ActivityNotFoundException e) { e.printStackTrace(); } } }); if (Boolean.TRUE.equals(widget.getParameter(PARAM_ADD_CONTACT))) sharingDialogBuilder.addCustomListener(R.string.multicontacts_add_to_phonebook, R.drawable.gc_add_to_contacts, true, new DialogSharing.Item.OnClickListener() { @Override public void onClick() { createNewContact(person.getName(), person.getPhone(), person.getEmail()); } }); showDialogSharing(sharingDialogBuilder.build()); } }); } boolean hasSchema = store.getBoolean("hasschema"); cachePath = widget.getCachePath() + "/contacts-" + widget.getOrder(); contacts = person.getContacts(); if (widget.getTitle().length() > 0) { setTitle(widget.getTitle()); } root = (LinearLayout) findViewById(R.id.grouped_contacts_details_root); if (hasSchema) { root.setBackgroundColor(Statics.color1); } else if (widget.isBackgroundURL()) { cacheBackgroundFile = cachePath + "/" + Utils.md5(widget.getBackgroundURL()); File backgroundFile = new File(cacheBackgroundFile); if (backgroundFile.exists()) { root.setBackgroundDrawable( new BitmapDrawable(BitmapFactory.decodeStream(new FileInputStream(backgroundFile)))); } else { BackgroundDownloadTask dt = new BackgroundDownloadTask(); dt.execute(widget.getBackgroundURL()); } } else if (widget.isBackgroundInAssets()) { AssetManager am = this.getAssets(); root.setBackgroundDrawable(new BitmapDrawable(am.open(widget.getBackgroundURL()))); } if (contacts != null) { ImageView avatarImage = (ImageView) findViewById(R.id.grouped_contacts_details_avatar); avatarImage.setImageResource(R.drawable.gc_profile_avatar); if (person.hasAvatar() && NetworkUtils.isOnline(this)) { avatarImage.setVisibility(View.VISIBLE); Glide.with(this).load(person.getAvatarUrl()).placeholder(R.drawable.gc_profile_avatar) .dontAnimate().into(avatarImage); } else { avatarImage.setVisibility(View.VISIBLE); avatarImage.setImageResource(R.drawable.gc_profile_avatar); } String name = ""; neededContacts = new ArrayList<>(); for (Contact con : contacts) { if ((con.getType() == 5) || (con.getDescription().length() == 0)) { } else { if (con.getType() == 0) { name = con.getDescription(); } else neededContacts.add(con); } } if (neededContacts.isEmpty()) { handler.sendEmptyMessage(THERE_IS_NO_CONTACT_DATA); return; } headSeparator = findViewById(R.id.gc_head_separator); bottomSeparator = findViewById(R.id.gc_bottom_separator); imageBottom = findViewById(R.id.gc_image_bottom_layout); personName = (TextView) findViewById(R.id.gc_details_description); if ("".equals(name)) personName.setVisibility(View.GONE); else { personName.setVisibility(View.VISIBLE); personName.setText(name); personName.setTextColor(Statics.color3); } if (Statics.isLight) { headSeparator.setBackgroundColor(Color.parseColor("#4d000000")); bottomSeparator.setBackgroundColor(Color.parseColor("#4d000000")); } else { headSeparator.setBackgroundColor(Color.parseColor("#4dFFFFFF")); bottomSeparator.setBackgroundColor(Color.parseColor("#4dFFFFFF")); } ViewUtils.setBackgroundLikeHeader(imageBottom, Statics.color1); ListView list = (ListView) findViewById(R.id.grouped_contacts_details_list_view); list.setDivider(null); ContactDetailsAdapter adapter = new ContactDetailsAdapter(ContactDetailsActivity.this, R.layout.grouped_contacts_details_item, neededContacts, isChemeDark(Statics.color1)); list.setAdapter(adapter); list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View view, int position, long id) { listViewItemClick(position); } }); } if (widget.hasParameter("add_contact")) { HashMap<String, String> hm = new HashMap<>(); for (int i = 0; i < contacts.size(); i++) { switch (contacts.get(i).getType()) { case 0: { hm.put("contactName", contacts.get(i).getDescription()); } break; case 1: { hm.put("contactNumber", contacts.get(i).getDescription()); } break; case 2: { hm.put("contactEmail", contacts.get(i).getDescription()); } break; case 3: { hm.put("contactSite", contacts.get(i).getDescription()); } break; } } addNativeFeature(NATIVE_FEATURES.ADD_CONTACT, null, hm); } if (widget.hasParameter("send_sms")) { HashMap<String, String> hm = new HashMap<>(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < contacts.size(); i++) { sb.append(contacts.get(i).getDescription()); if (i < contacts.size() - 1) { sb.append(", "); } } hm.put("text", sb.toString()); addNativeFeature(NATIVE_FEATURES.SMS, null, hm); } if (widget.hasParameter("send_mail")) { HashMap<String, CharSequence> hm = new HashMap<>(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < contacts.size(); i++) { switch (contacts.get(i).getType()) { case 0: { sb.append("Name: "); } break; case 1: { sb.append("Phone: "); } break; case 2: { sb.append("Email: "); } break; case 3: { sb.append("Site: "); } break; case 4: { sb.append("Address: "); } break; } sb.append(contacts.get(i).getDescription()); sb.append("<br/>"); } if (widget.isHaveAdvertisement()) { sb.append("<br>\n (sent from <a href=\"http://ibuildapp.com\">iBuildApp</a>)"); } hm.put("text", sb.toString()); hm.put("subject", "Contacts"); addNativeFeature(NATIVE_FEATURES.EMAIL, null, hm); } } catch (Exception e) { Log.e(TAG, e.getMessage()); e.printStackTrace(); } }
From source file:com.abroad.ruianju.im.ui.RobotsActivity.java
@Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); setContentView(R.layout.em_fragment_robots); inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); ListView mListView = (ListView) findViewById(R.id.list); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout); if (android.os.Build.VERSION.SDK_INT >= 14) { swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); }/* w w w .j a v a 2 s . c o m*/ progressBar = findViewById(R.id.progress_bar); swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { getRobotNamesFromServer(); } }); Map<String, RobotUser> robotMap = DemoHelper.getInstance().getRobotList(); if (robotMap != null) { robotList.addAll(robotMap.values()); } else { progressBar.setVisibility(View.VISIBLE); getRobotNamesFromServer(); } adapter = new RobotAdapter(this, 1, robotList); mListView.setAdapter(adapter); mListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { RobotUser user = (RobotUser) parent.getItemAtPosition(position); Intent intent = new Intent(); intent.setClass(RobotsActivity.this, ChatActivity.class); intent.putExtra("userId", user.getUsername()); startActivity(intent); } }); mListView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); }
From source file:com.avcall.app.ui.RobotsActivity.java
@Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); setContentView(R.layout.em_fragment_robots); inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); ListView mListView = (ListView) findViewById(R.id.list); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout); if (android.os.Build.VERSION.SDK_INT >= 14) { swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); }/*w w w . j a va 2 s .c o m*/ progressBar = findViewById(R.id.progress_bar); swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { getRobotNamesFromServer(); } }); Map<String, RobotUser> robotMap = AvcallHelper.getInstance().getRobotList(); if (robotMap != null) { robotList.addAll(robotMap.values()); } else { progressBar.setVisibility(View.VISIBLE); getRobotNamesFromServer(); } adapter = new RobotAdapter(this, 1, robotList); mListView.setAdapter(adapter); mListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { RobotUser user = (RobotUser) parent.getItemAtPosition(position); Intent intent = new Intent(); intent.setClass(RobotsActivity.this, ChatActivity.class); intent.putExtra("userId", user.getUsername()); startActivity(intent); } }); mListView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); }