List of usage examples for android.os Bundle getBoolean
public boolean getBoolean(String key)
From source file:de.sourcestream.movieDB.MainActivity.java
/** * First configure the Universal Image Downloader, * then we set the main layout to be activity_main.xml * and we add the slide menu items./* w w w . j a va2s .co m*/ * * @param savedInstanceState If non-null, this activity is being re-constructed from a previous saved state as given here. */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = mDrawerTitle = getTitle(); // load slide menu items navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.list_slidermenu); ViewGroup header = (ViewGroup) getLayoutInflater().inflate(R.layout.drawer_header, null, false); ImageView drawerBackButton = (ImageView) header.findViewById(R.id.drawerBackButton); drawerBackButton.setOnClickListener(onDrawerBackButton); mDrawerList.addHeaderView(header); mDrawerList.setOnItemClickListener(new SlideMenuClickListener()); // setting the nav drawer list adapter mDrawerList.setAdapter(new ArrayAdapter<>(this, R.layout.drawer_list_item, R.id.title, navMenuTitles)); toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar != null) { setSupportActionBar(toolbar); toolbar.bringToFront(); } mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ toolbar, R.string.app_name, // nav drawer open - description for accessibility R.string.app_name // nav drawer close - description for accessibility ) { public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); // calling onPrepareOptionsMenu() to show search view invalidateOptionsMenu(); syncState(); } public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); // calling onPrepareOptionsMenu() to hide search view invalidateOptionsMenu(); syncState(); } // updates the title, toolbar transparency and search view public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, slideOffset); if (slideOffset > .55 && !isDrawerOpen) { // opening drawer // mDrawerTitle is app title getSupportActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); isDrawerOpen = true; } else if (slideOffset < .45 && isDrawerOpen) { // closing drawer // mTitle is title of the current view, can be movies, tv shows or movie title getSupportActionBar().setTitle(mTitle); invalidateOptionsMenu(); isDrawerOpen = false; } } }; mDrawerLayout.setDrawerListener(mDrawerToggle); // Get the action bar title to set padding TextView titleTextView = null; try { Field f = toolbar.getClass().getDeclaredField("mTitleTextView"); f.setAccessible(true); titleTextView = (TextView) f.get(toolbar); } catch (NoSuchFieldException e) { } catch (IllegalAccessException e) { } if (titleTextView != null) { float scale = getResources().getDisplayMetrics().density; titleTextView.setPadding((int) scale * 15, 0, 0, 0); } phone = getResources().getBoolean(R.bool.portrait_only); searchDB = new SearchDB(getApplicationContext()); if (savedInstanceState == null) { // Check orientation and lock to portrait if we are on phone if (phone) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } // on first time display view for first nav item displayView(1); // Use hockey module to check for updates checkForUpdates(); // Universal Loader options and configuration. DisplayImageOptions options = new DisplayImageOptions.Builder() // Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888. .bitmapConfig(Bitmap.Config.RGB_565).imageScaleType(ImageScaleType.EXACTLY).cacheInMemory(false) .showImageOnLoading(R.drawable.placeholder_default) .showImageForEmptyUri(R.drawable.placeholder_default) .showImageOnFail(R.drawable.placeholder_default).cacheOnDisk(true).build(); Context context = this; File cacheDir = StorageUtils.getCacheDirectory(context); // Create global configuration and initialize ImageLoader with this config ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this) .diskCache(new UnlimitedDiscCache(cacheDir)) // default .defaultDisplayImageOptions(options).build(); ImageLoader.getInstance().init(config); // Check cache size long size = 0; File[] filesCache = cacheDir.listFiles(); for (File file : filesCache) { size += file.length(); } if (cacheDir.getUsableSpace() < MinFreeSpace || size > CacheSize) { ImageLoader.getInstance().getDiskCache().clear(); searchDB.cleanSuggestionRecords(); } } else { oldPos = savedInstanceState.getInt("oldPos"); currentMovViewPagerPos = savedInstanceState.getInt("currentMovViewPagerPos"); currentTVViewPagerPos = savedInstanceState.getInt("currentTVViewPagerPos"); restoreMovieDetailsState = savedInstanceState.getBoolean("restoreMovieDetailsState"); restoreMovieDetailsAdapterState = savedInstanceState.getBoolean("restoreMovieDetailsAdapterState"); movieDetailsBundle = savedInstanceState.getParcelableArrayList("movieDetailsBundle"); castDetailsBundle = savedInstanceState.getParcelableArrayList("castDetailsBundle"); tvDetailsBundle = savedInstanceState.getParcelableArrayList("tvDetailsBundle"); currOrientation = savedInstanceState.getInt("currOrientation"); lastVisitedSimMovie = savedInstanceState.getInt("lastVisitedSimMovie"); lastVisitedSimTV = savedInstanceState.getInt("lastVisitedSimTV"); lastVisitedMovieInCredits = savedInstanceState.getInt("lastVisitedMovieInCredits"); saveInMovieDetailsSimFragment = savedInstanceState.getBoolean("saveInMovieDetailsSimFragment"); FragmentManager fm = getFragmentManager(); // prevent the following bug: go to gallery preview -> swap orientation -> // go to movies list -> swap orientation -> action bar bugged // so if we are not on gallery preview we show toolbar if (fm.getBackStackEntryCount() == 0 || !fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1).getName().equals("galleryList")) { new Handler().post(new Runnable() { @Override public void run() { if (getSupportActionBar() != null && !getSupportActionBar().isShowing()) getSupportActionBar().show(); } }); } } // Get reference for the imageLoader imageLoader = ImageLoader.getInstance(); // Options used for the backdrop image in movie and tv details and gallery optionsWithFade = new DisplayImageOptions.Builder() // Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888. .bitmapConfig(Bitmap.Config.RGB_565).displayer(new FadeInBitmapDisplayer(500)) .imageScaleType(ImageScaleType.EXACTLY).cacheInMemory(false).showImageOnLoading(R.color.black) .showImageForEmptyUri(R.color.black).showImageOnFail(R.color.black).cacheOnDisk(true).build(); optionsWithoutFade = new DisplayImageOptions.Builder() // Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888. .bitmapConfig(Bitmap.Config.RGB_565).imageScaleType(ImageScaleType.EXACTLY).cacheInMemory(false) .showImageOnLoading(R.color.black).showImageForEmptyUri(R.color.black) .showImageOnFail(R.color.black).cacheOnDisk(true).build(); // Options used for the backdrop image in movie and tv details and gallery backdropOptionsWithFade = new DisplayImageOptions.Builder() // Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888. .bitmapConfig(Bitmap.Config.RGB_565).displayer(new FadeInBitmapDisplayer(500)) .imageScaleType(ImageScaleType.EXACTLY).cacheInMemory(false) .showImageOnLoading(R.drawable.placeholder_backdrop) .showImageForEmptyUri(R.drawable.placeholder_backdrop) .showImageOnFail(R.drawable.placeholder_backdrop).cacheOnDisk(true).build(); backdropOptionsWithoutFade = new DisplayImageOptions.Builder() // Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888. .bitmapConfig(Bitmap.Config.RGB_565).imageScaleType(ImageScaleType.EXACTLY).cacheInMemory(false) .showImageOnLoading(R.drawable.placeholder_backdrop) .showImageForEmptyUri(R.drawable.placeholder_backdrop) .showImageOnFail(R.drawable.placeholder_backdrop).cacheOnDisk(true).build(); trailerListView = new TrailerList(); galleryListView = new GalleryList(); if (currOrientation != getResources().getConfiguration().orientation) orientationChanged = true; currOrientation = getResources().getConfiguration().orientation; iconConstantSpecialCase = 0; if (phone) { iconMarginConstant = 0; iconMarginLandscape = 0; DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); int width = displayMetrics.widthPixels; int height = displayMetrics.heightPixels; if (width <= 480 && height <= 800) iconConstantSpecialCase = -70; // used in MovieDetails, CastDetails, TVDetails onMoreIconClick // to check whether the animation should be in up or down direction threeIcons = 128; threeIconsToolbar = 72; twoIcons = 183; twoIconsToolbar = 127; oneIcon = 238; oneIconToolbar = 182; } else { if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { iconMarginConstant = 232; iconMarginLandscape = 300; threeIcons = 361; threeIconsToolbar = 295; twoIcons = 416; twoIconsToolbar = 351; oneIcon = 469; oneIconToolbar = 407; } else { iconMarginConstant = 82; iconMarginLandscape = 0; threeIcons = 209; threeIconsToolbar = 146; twoIcons = 264; twoIconsToolbar = 200; oneIcon = 319; oneIconToolbar = 256; } } dateFormat = android.text.format.DateFormat.getDateFormat(this); }
From source file:net.homelinux.penecoptero.android.citybikes.app.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);//from www . ja v a2 s .c o m PreferenceManager.setDefaultValues(this, R.xml.preferences, false); mapView = (MapView) findViewById(R.id.mapview); mSlidingDrawer = (StationSlidingDrawer) findViewById(R.id.drawer); infoLayer = (InfoLayer) findViewById(R.id.info_layer); scale = getResources().getDisplayMetrics().density; //Log.i("CityBikes","ON CREATEEEEEEEEE!!!!!"); infoLayerPopulator = new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == InfoLayer.POPULATE) { infoLayer.inflateStation(stations.getCurrent()); } if (msg.what == CityBikes.BOOKMARK_CHANGE) { int id = msg.arg1; boolean bookmarked; if (msg.arg2 == 0) { bookmarked = false; } else { bookmarked = true; } StationOverlay station = stations.getById(id); try { BookmarkManager bm = new BookmarkManager(getApplicationContext()); bm.setBookmarked(station.getStation(), !bookmarked); } catch (Exception e) { Log.i("CityBikes", "Error bookmarking station"); e.printStackTrace(); } if (!view_all) { view_near(); } mapView.postInvalidate(); } } }; infoLayer.setHandler(infoLayerPopulator); RelativeLayout.LayoutParams zoomControlsLayoutParams = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); zoomControlsLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); zoomControlsLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL); mapView.addView(mapView.getZoomControls(), zoomControlsLayoutParams); modeButton = (ToggleButton) findViewById(R.id.mode_button); modeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { changeMode(!getBike); } }); applyMapViewLongPressListener(mapView); settings = getSharedPreferences(CityBikes.PREFERENCES_NAME, 0); List<Overlay> mapOverlays = mapView.getOverlays(); locator = new Locator(this, new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == Locator.LOCATION_CHANGED) { GeoPoint point = new GeoPoint(msg.arg1, msg.arg2); hOverlay.moveCenter(point); mapView.getController().animateTo(point); mDbHelper.setCenter(point); // Location has changed try { mDbHelper.updateDistances(point); infoLayer.update(); if (!view_all) { view_near(); } } catch (Exception e) { } ; } } }); hOverlay = new HomeOverlay(locator.getCurrentGeoPoint(), new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == HomeOverlay.MOTION_CIRCLE_STOP) { try { if (!view_all) { view_near(); } mapView.postInvalidate(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }); stations = new StationOverlayList(mapOverlays, new Handler() { @Override public void handleMessage(Message msg) { //Log.i("CityBikes","Message: "+Integer.toString(msg.what)+" "+Integer.toString(msg.arg1)); if (msg.what == StationOverlay.TOUCHED && msg.arg1 != -1) { // One station has been touched stations.setCurrent(msg.arg1, getBike); infoLayer.inflateStation(stations.getCurrent()); //Log.i("CityBikes","Station touched: "+Integer.toString(msg.arg1)); } } }); stations.addOverlay(hOverlay); mNDBAdapter = new NetworksDBAdapter(getApplicationContext()); mDbHelper = new StationsDBAdapter(this, mapView, new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case StationsDBAdapter.FETCH: break; case StationsDBAdapter.UPDATE_MAP: progressDialog.dismiss(); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("reload_network", false); editor.commit(); case StationsDBAdapter.UPDATE_DATABASE: StationOverlay current = stations.getCurrent(); if (current == null) { infoLayer.inflateMessage(getString(R.string.no_bikes_around)); } if (current != null) { infoLayer.inflateStation(current); if (view_all) view_all(); else view_near(); } else { } mapView.invalidate(); infoLayer.update(); ////Log.i("openBicing", "Database updated"); break; case StationsDBAdapter.NETWORK_ERROR: ////Log.i("openBicing", "Network error, last update from " + mDbHelper.getLastUpdated()); Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.network_error) + " " + mDbHelper.getLastUpdated(), Toast.LENGTH_LONG); toast.show(); break; } } }, stations); mDbHelper.setCenter(locator.getCurrentGeoPoint()); mSlidingDrawer.setHandler(new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case StationSlidingDrawer.ITEMCLICKED: StationOverlay clicked = (StationOverlay) msg.obj; stations.setCurrent(msg.arg1, getBike); Message tmp = new Message(); tmp.what = InfoLayer.POPULATE; tmp.arg1 = msg.arg1; infoLayerPopulator.dispatchMessage(tmp); mapView.getController().animateTo(clicked.getCenter()); } } }); if (savedInstanceState != null) { locator.unlockCenter(); hOverlay.setRadius(savedInstanceState.getInt("homeRadius")); this.view_all = savedInstanceState.getBoolean("view_all"); } else { updateHome(); } try { mDbHelper.loadStations(); if (savedInstanceState == null) { String strUpdated = mDbHelper.getLastUpdated(); Boolean dirty = settings.getBoolean("reload_network", false); if (strUpdated == null || dirty) { this.fillData(view_all); } else { Toast toast = Toast.makeText(this.getApplicationContext(), "Last Updated: " + mDbHelper.getLastUpdated(), Toast.LENGTH_LONG); toast.show(); Calendar cal = Calendar.getInstance(); long now = cal.getTime().getTime(); if (Math.abs(now - mDbHelper.getLastUpdatedTime()) > 60000 * 5) this.fillData(view_all); } } } catch (Exception e) { ////Log.i("openBicing", "SHIT ... SUCKS"); } ; if (view_all) view_all(); else view_near(); ////Log.i("openBicing", "CREATE!"); }
From source file:com.vegnab.vegnab.MainVNActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // // start following loader, does not use UI, but only gets a value to have ready for a menu action // getSupportLoaderManager().initLoader(VNContract.Loaders.HIDDEN_VISITS, null, this); //Get a Tracker (should auto-report) ((VNApplication) getApplication()).getTracker(VNApplication.TrackerName.APP_TRACKER); // set up some default Preferences SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor prefEditor; if (!sharedPref.contains(Prefs.TARGET_ACCURACY_OF_VISIT_LOCATIONS)) { prefEditor = sharedPref.edit();//from ww w . j a v a2 s . co m prefEditor.putFloat(Prefs.TARGET_ACCURACY_OF_VISIT_LOCATIONS, (float) 7.0); prefEditor.commit(); } if (!sharedPref.contains(Prefs.TARGET_ACCURACY_OF_MAPPED_LOCATIONS)) { prefEditor = sharedPref.edit(); prefEditor.putFloat(Prefs.TARGET_ACCURACY_OF_MAPPED_LOCATIONS, (float) 7.0); prefEditor.commit(); } if (!sharedPref.contains(Prefs.UNIQUE_DEVICE_ID)) { prefEditor = sharedPref.edit(); getUniqueDeviceId(this); // generate the ID and the source prefEditor.putString(Prefs.DEVICE_ID_SOURCE, mDeviceIdSource); prefEditor.putString(Prefs.UNIQUE_DEVICE_ID, mUniqueDeviceId); prefEditor.commit(); } // Is there a description of what "local" is (e.g. "Iowa")? Initially, no if (!sharedPref.contains(Prefs.LOCAL_SPECIES_LIST_DESCRIPTION)) { prefEditor = sharedPref.edit(); prefEditor.putString(Prefs.LOCAL_SPECIES_LIST_DESCRIPTION, this.getResources().getString(R.string.local_region_none)); prefEditor.commit(); } // Has the master species list been populated? As a default, assume not. if (!sharedPref.contains(Prefs.SPECIES_LIST_DOWNLOADED)) { prefEditor = sharedPref.edit(); prefEditor.putBoolean(Prefs.SPECIES_LIST_DOWNLOADED, false); prefEditor.commit(); } // start following loader, does not use UI, but tests if the master species list is populated getSupportLoaderManager().restartLoader(VNContract.Loaders.EXISTING_SPP, null, this); // Have the user verify each species entered as presence/absence? Initially, yes. // user will probably turn this one off each session, but turn it on on each restart prefEditor = sharedPref.edit(); prefEditor.putBoolean(Prefs.VERIFY_VEG_ITEMS_PRESENCE, true); prefEditor.commit(); // Set the default ID method to Digital Photograph if (!sharedPref.contains(Prefs.DEFAULT_IDENT_METHOD_ID)) { prefEditor = sharedPref.edit(); prefEditor.putLong(Prefs.DEFAULT_IDENT_METHOD_ID, 1); prefEditor.commit(); } // Set the default to allow species only once per subplot if (!sharedPref.contains(Prefs.SPECIES_ONCE)) { prefEditor = sharedPref.edit(); prefEditor.putBoolean(Prefs.SPECIES_ONCE, true); prefEditor.commit(); } // Set the default to use the "local species" feature if (!sharedPref.contains(Prefs.USE_LOCAL_SPP)) { prefEditor = sharedPref.edit(); prefEditor.putBoolean(Prefs.USE_LOCAL_SPP, true); prefEditor.commit(); } // Set if there is no "local" yet, use the default of not actually filtering for local species if (!sharedPref.contains(Prefs.LOCAL_SPP_CRIT)) { prefEditor = sharedPref.edit(); prefEditor.putString(Prefs.LOCAL_SPP_CRIT, "%"); prefEditor.commit(); } // set up in-app billing // following resource is in it's own file, listed in .gitignore String base64EncodedPublicKey = getString(R.string.app_license); // set up the list of products, for now only donations mSkuCkList.add(SKU_DONATE_SMALL); mSkuCkList.add(SKU_DONATE_MEDIUM); mSkuCkList.add(SKU_DONATE_LARGE); mSkuCkList.add(SKU_DONATE_XLARGE); if (LDebug.ON) Log.d(LOG_TAG, "Creating IAB helper."); mHelper = new IabHelper(this, base64EncodedPublicKey); // enable debug logging (for production application, set this to false). mHelper.enableDebugLogging(LDebug.ON); // Start setup. This is asynchronous. // The specified listener will be called once setup completes. if (LDebug.ON) Log.d(LOG_TAG, "Starting setup."); mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { if (LDebug.ON) Log.d(LOG_TAG, "Setup finished."); if (!result.isSuccess()) { // a problem. //Toast.makeText(this, // this.getResources().getString(R.string.in_app_bill_error) + result, // Toast.LENGTH_SHORT).show(); return; } // disposed? if (mHelper == null) return; // always a good idea to query inventory // even if products were supposed to be consumed there might have been some glitch if (LDebug.ON) Log.d(LOG_TAG, "Setup done. Querying inventory."); mHelper.queryInventoryAsync(true, mSkuCkList, mGotInventoryListener); } }); setContentView(R.layout.activity_vn_main); // viewPager = (ViewPager) findViewById(R.id.data_entry_pager); // FragmentManager fm = getSupportFragmentManager(); // viewPager.setAdapter(new dataPagerAdapter(fm)); /* put conditions to test below * such as whether the container even exists in this layout * e.g. if (findViewById(R.id.fragment_container) != null) * */ if (true) { if (savedInstanceState != null) { mVisitId = savedInstanceState.getLong(ARG_VISIT_ID); mConnectionRequested = savedInstanceState.getBoolean(ARG_CONNECTION_REQUESTED); mSubplotTypeId = savedInstanceState.getLong(ARG_SUBPLOT_TYPE_ID, 0); mNewPurcRecId = savedInstanceState.getLong(ARG_PURCH_REC_ID); // if restoring from a previous state, do not create view // could end up with overlapping views return; } // create an instance of New Visit fragment NewVisitFragment newVisitFrag = new NewVisitFragment(); // in case this activity were started with special instructions from an Intent // pass the Intent's Extras to the fragment as arguments newVisitFrag.setArguments(getIntent().getExtras()); // the tag is for the fragment now being added // it will stay with this fragment when put on the backstack FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.add(R.id.fragment_container, newVisitFrag, Tags.NEW_VISIT); transaction.commit(); } }
From source file:net.homelinux.penecoptero.android.citybikes.donation.app.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/*w ww .ja v a 2 s . c o m*/ PreferenceManager.setDefaultValues(this, R.xml.preferences, false); mapView = (MapView) findViewById(R.id.mapview); mSlidingDrawer = (StationSlidingDrawer) findViewById(R.id.drawer); infoLayer = (InfoLayer) findViewById(R.id.info_layer); scale = getResources().getDisplayMetrics().density; //Log.i("CityBikes","ON CREATEEEEEEEEE!!!!!"); infoLayerPopulator = new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == InfoLayer.POPULATE) { infoLayer.inflateStation(stations.getCurrent()); } if (msg.what == CityBikes.BOOKMARK_CHANGE) { int id = msg.arg1; boolean bookmarked; if (msg.arg2 == 0) { bookmarked = false; } else { bookmarked = true; } StationOverlay station = stations.getById(id); try { BookmarkManager bm = new BookmarkManager(getApplicationContext()); bm.setBookmarked(station.getStation(), !bookmarked); } catch (Exception e) { Log.i("CityBikes", "Error bookmarking station"); e.printStackTrace(); } if (!view_all) { view_near(); } mapView.postInvalidate(); } } }; infoLayer.setHandler(infoLayerPopulator); RelativeLayout.LayoutParams zoomControlsLayoutParams = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); zoomControlsLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); zoomControlsLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL); mapView.addView(mapView.getZoomControls(), zoomControlsLayoutParams); modeButton = (ToggleButton) findViewById(R.id.mode_button); modeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { changeMode(!getBike); } }); applyMapViewLongPressListener(mapView); settings = getSharedPreferences(CityBikes.PREFERENCES_NAME, 0); List<Overlay> mapOverlays = mapView.getOverlays(); locator = new Locator(this, new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == Locator.LOCATION_CHANGED) { GeoPoint point = new GeoPoint(msg.arg1, msg.arg2); hOverlay.moveCenter(point); mapView.getController().animateTo(point); mDbHelper.setCenter(point); // Location has changed try { mDbHelper.updateDistances(point); infoLayer.update(); if (!view_all) { view_near(); } } catch (Exception e) { } ; } } }); hOverlay = new HomeOverlay(locator.getCurrentGeoPoint(), new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == HomeOverlay.MOTION_CIRCLE_STOP) { try { if (!view_all) { view_near(); } mapView.postInvalidate(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }); stations = new StationOverlayList(mapOverlays, new Handler() { @Override public void handleMessage(Message msg) { //Log.i("CityBikes","Message: "+Integer.toString(msg.what)+" "+Integer.toString(msg.arg1)); if (msg.what == StationOverlay.TOUCHED && msg.arg1 != -1) { // One station has been touched stations.setCurrent(msg.arg1, getBike); infoLayer.inflateStation(stations.getCurrent()); //Log.i("CityBikes","Station touched: "+Integer.toString(msg.arg1)); } } }); stations.addOverlay(hOverlay); mNDBAdapter = new NetworksDBAdapter(getApplicationContext()); mDbHelper = new StationsDBAdapter(this, mapView, new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case StationsDBAdapter.FETCH: break; case StationsDBAdapter.UPDATE_MAP: progressDialog.dismiss(); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("reload_network", false); editor.commit(); case StationsDBAdapter.UPDATE_DATABASE: StationOverlay current = stations.getCurrent(); if (current == null) { infoLayer.inflateMessage(getString(R.string.no_bikes_around)); } if (current != null) { current.setSelected(true, getBike); infoLayer.inflateStation(current); if (view_all) view_all(); else view_near(); } else { } mapView.invalidate(); infoLayer.update(); ////Log.i("openBicing", "Database updated"); break; case StationsDBAdapter.NETWORK_ERROR: ////Log.i("openBicing", "Network error, last update from " + mDbHelper.getLastUpdated()); Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.network_error) + " " + mDbHelper.getLastUpdated(), Toast.LENGTH_LONG); toast.show(); break; } } }, stations); mDbHelper.setCenter(locator.getCurrentGeoPoint()); mSlidingDrawer.setHandler(new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case StationSlidingDrawer.ITEMCLICKED: StationOverlay clicked = (StationOverlay) msg.obj; stations.setCurrent(msg.arg1, getBike); Message tmp = new Message(); tmp.what = InfoLayer.POPULATE; tmp.arg1 = msg.arg1; infoLayerPopulator.dispatchMessage(tmp); mapView.getController().animateTo(clicked.getCenter()); } } }); if (savedInstanceState != null) { locator.unlockCenter(); hOverlay.setRadius(savedInstanceState.getInt("homeRadius")); this.view_all = savedInstanceState.getBoolean("view_all"); } else { updateHome(); } try { mDbHelper.loadStations(); if (savedInstanceState == null) { String strUpdated = mDbHelper.getLastUpdated(); Boolean dirty = settings.getBoolean("reload_network", false); if (strUpdated == null || dirty) { this.fillData(view_all); } else { Toast toast = Toast.makeText(this.getApplicationContext(), "Last Updated: " + mDbHelper.getLastUpdated(), Toast.LENGTH_LONG); toast.show(); Calendar cal = Calendar.getInstance(); long now = cal.getTime().getTime(); if (Math.abs(now - mDbHelper.getLastUpdatedTime()) > 60000 * 5) this.fillData(view_all); } } } catch (Exception e) { ////Log.i("openBicing", "SHIT ... SUCKS"); } ; if (view_all) view_all(); else view_near(); ////Log.i("openBicing", "CREATE!"); }
From source file:co.taqat.call.CallActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); instance = this; if (getResources().getBoolean(R.bool.orientation_portrait_only)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }/* w ww . j a v a2 s . c o m*/ getWindow().addFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); setContentView(R.layout.call); isTransferAllowed = getApplicationContext().getResources().getBoolean(R.bool.allow_transfers); if (!BluetoothManager.getInstance().isBluetoothHeadsetAvailable()) { BluetoothManager.getInstance().initBluetooth(); } cameraNumber = AndroidCameraConfiguration.retrieveCameras().length; try { // Yeah, this is hidden field. field = PowerManager.class.getClass().getField("PROXIMITY_SCREEN_OFF_WAKE_LOCK").getInt(null); } catch (Throwable ignored) { } powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(field, getLocalClassName()); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mListener = new LinphoneCoreListenerBase() { @Override public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) { displayMissedChats(); } @Override public void callState(LinphoneCore lc, final LinphoneCall call, LinphoneCall.State state, String message) { if (LinphoneManager.getLc().getCallsNb() == 0) { finish(); return; } if (state == State.IncomingReceived) { startIncomingCallActivity(); return; } else if (state == State.Paused || state == State.PausedByRemote || state == State.Pausing) { if (LinphoneManager.getLc().getCurrentCall() != null) { enabledVideoButton(false); } if (isVideoEnabled(call)) { showAudioView(); } } else if (state == State.Resuming) { if (LinphonePreferences.instance().isVideoEnabled()) { status.refreshStatusItems(call, isVideoEnabled(call)); if (call.getCurrentParamsCopy().getVideoEnabled()) { showVideoView(); } } if (LinphoneManager.getLc().getCurrentCall() != null) { enabledVideoButton(true); } } else if (state == State.StreamsRunning) { switchVideo(isVideoEnabled(call)); enableAndRefreshInCallActions(); if (status != null) { videoProgress.setVisibility(View.GONE); status.refreshStatusItems(call, isVideoEnabled(call)); } } else if (state == State.CallUpdatedByRemote) { // If the correspondent proposes video while audio call boolean videoEnabled = LinphonePreferences.instance().isVideoEnabled(); if (!videoEnabled) { acceptCallUpdate(false); } boolean remoteVideo = call.getRemoteParams().getVideoEnabled(); boolean localVideo = call.getCurrentParamsCopy().getVideoEnabled(); boolean autoAcceptCameraPolicy = true;//LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests(); if (remoteVideo && !localVideo && !autoAcceptCameraPolicy && !LinphoneManager.getLc().isInConference()) { showAcceptCallUpdateDialog(); timer = new CountDownTimer(SECONDS_BEFORE_DENYING_CALL_UPDATE, 1000) { public void onTick(long millisUntilFinished) { } public void onFinish() { //TODO dismiss dialog acceptCallUpdate(false); } }.start(); /*showAcceptCallUpdateDialog(); timer = new CountDownTimer(SECONDS_BEFORE_DENYING_CALL_UPDATE, 1000) { public void onTick(long millisUntilFinished) { } public void onFinish() { //TODO dismiss dialog } }.start();*/ } // else if (remoteVideo && !LinphoneManager.getLc().isInConference() && autoAcceptCameraPolicy) { // mHandler.post(new Runnable() { // @Override // public void run() { // acceptCallUpdate(true); // } // }); // } } refreshIncallUi(); transfer.setEnabled(LinphoneManager.getLc().getCurrentCall() != null); } @Override public void callEncryptionChanged(LinphoneCore lc, final LinphoneCall call, boolean encrypted, String authenticationToken) { if (status != null) { if (call.getCurrentParamsCopy().getMediaEncryption().equals(LinphoneCore.MediaEncryption.ZRTP) && !call.isAuthenticationTokenVerified()) { status.showZRTPDialog(call); } status.refreshStatusItems(call, call.getCurrentParamsCopy().getVideoEnabled()); } } }; if (findViewById(R.id.fragmentContainer) != null) { initUI(); if (LinphoneManager.getLc().getCallsNb() > 0) { LinphoneCall call = LinphoneManager.getLc().getCalls()[0]; if (LinphoneUtils.isCallEstablished(call)) { enableAndRefreshInCallActions(); } } if (savedInstanceState != null) { // Fragment already created, no need to create it again (else it will generate a memory leak with duplicated fragments) isSpeakerEnabled = savedInstanceState.getBoolean("Speaker"); isMicMuted = savedInstanceState.getBoolean("Mic"); isVideoCallPaused = savedInstanceState.getBoolean("VideoCallPaused"); refreshInCallActions(); return; } else { isSpeakerEnabled = LinphoneManager.getLc().isSpeakerEnabled(); isMicMuted = LinphoneManager.getLc().isMicMuted(); } Fragment callFragment; if (isVideoEnabled(LinphoneManager.getLc().getCurrentCall())) { callFragment = new CallVideoFragment(); videoCallFragment = (CallVideoFragment) callFragment; displayVideoCall(false); LinphoneManager.getInstance().routeAudioToSpeaker(); isSpeakerEnabled = true; } else { callFragment = new CallAudioFragment(); audioCallFragment = (CallAudioFragment) callFragment; } if (BluetoothManager.getInstance().isBluetoothHeadsetAvailable()) { BluetoothManager.getInstance().routeAudioToBluetooth(); } callFragment.setArguments(getIntent().getExtras()); getFragmentManager().beginTransaction().add(R.id.fragmentContainer, callFragment) .commitAllowingStateLoss(); } }
From source file:com.irccloud.android.activity.LoginActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= 21) { Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name), cloud, 0xff0b2e60));/*www. j ava 2 s .com*/ cloud.recycle(); } requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); setContentView(R.layout.activity_login); loading = findViewById(R.id.loading); connecting = findViewById(R.id.connecting); connectingMsg = (TextView) findViewById(R.id.connectingMsg); progressBar = (ProgressBar) findViewById(R.id.connectingProgress); loginHint = (LinearLayout) findViewById(R.id.loginHint); signupHint = (LinearLayout) findViewById(R.id.signupHint); hostHint = (TextView) findViewById(R.id.hostHint); login = findViewById(R.id.login); name = (EditText) findViewById(R.id.name); if (savedInstanceState != null && savedInstanceState.containsKey("name")) name.setText(savedInstanceState.getString("name")); email = (AutoCompleteTextView) findViewById(R.id.email); if (BuildConfig.ENTERPRISE) email.setHint(R.string.email_enterprise); ArrayList<String> accounts = new ArrayList<String>(); AccountManager am = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE); for (Account a : am.getAccounts()) { if (a.name.contains("@") && !accounts.contains(a.name)) accounts.add(a.name); } if (accounts.size() > 0) email.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, accounts.toArray(new String[accounts.size()]))); if (savedInstanceState != null && savedInstanceState.containsKey("email")) email.setText(savedInstanceState.getString("email")); password = (EditText) findViewById(R.id.password); password.setOnEditorActionListener(new OnEditorActionListener() { public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { new LoginTask().execute((Void) null); return true; } return false; } }); if (savedInstanceState != null && savedInstanceState.containsKey("password")) password.setText(savedInstanceState.getString("password")); host = (EditText) findViewById(R.id.host); if (BuildConfig.ENTERPRISE) host.setText(NetworkConnection.IRCCLOUD_HOST); else host.setVisibility(View.GONE); host.setOnEditorActionListener(new OnEditorActionListener() { public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { new LoginTask().execute((Void) null); return true; } return false; } }); if (savedInstanceState != null && savedInstanceState.containsKey("host")) host.setText(savedInstanceState.getString("host")); else host.setText(getSharedPreferences("prefs", 0).getString("host", BuildConfig.HOST)); if (host.getText().toString().equals("api.irccloud.com") || host.getText().toString().equals("www.irccloud.com")) host.setText(""); loginBtn = (Button) findViewById(R.id.loginBtn); loginBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new LoginTask().execute((Void) null); } }); loginBtn.setFocusable(true); loginBtn.requestFocus(); sendAccessLinkBtn = (Button) findViewById(R.id.sendAccessLink); sendAccessLinkBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { new ResetPasswordTask().execute((Void) null); } }); nextBtn = (Button) findViewById(R.id.nextBtn); nextBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (host.getText().length() > 0) { NetworkConnection.IRCCLOUD_HOST = host.getText().toString(); trimHost(); new EnterpriseConfigTask().execute((Void) null); } } }); TOS = (TextView) findViewById(R.id.TOS); TOS.setMovementMethod(new LinkMovementMethod()); forgotPassword = (TextView) findViewById(R.id.forgotPassword); forgotPassword.setOnClickListener(forgotPasswordClickListener); enterpriseLearnMore = (TextView) findViewById(R.id.enterpriseLearnMore); enterpriseLearnMore.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (isPackageInstalled("com.irccloud.android", LoginActivity.this)) { startActivity(getPackageManager().getLaunchIntentForPackage("com.irccloud.android")); } else { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.irccloud.android"))); } catch (Exception e) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.irccloud.android"))); } } } private boolean isPackageInstalled(String packagename, Context context) { PackageManager pm = context.getPackageManager(); try { pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES); return true; } catch (NameNotFoundException e) { return false; } } }); enterpriseHint = (LinearLayout) findViewById(R.id.enterpriseHint); EnterYourEmail = (TextView) findViewById(R.id.enterYourEmail); signupHint.setOnClickListener(signupHintClickListener); loginHint.setOnClickListener(loginHintClickListener); signupBtn = (Button) findViewById(R.id.signupBtn); signupBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { new LoginTask().execute((Void) null); } }); TextView version = (TextView) findViewById(R.id.version); try { version.setText("Version " + getPackageManager().getPackageInfo(getPackageName(), 0).versionName); } catch (NameNotFoundException e) { version.setVisibility(View.GONE); } Typeface LatoRegular = Typeface.createFromAsset(getAssets(), "Lato-Regular.ttf"); Typeface LatoLightItalic = Typeface.createFromAsset(getAssets(), "Lato-LightItalic.ttf"); for (int i = 0; i < signupHint.getChildCount(); i++) { View v = signupHint.getChildAt(i); if (v instanceof TextView) { ((TextView) v).setTypeface(LatoRegular); } } for (int i = 0; i < loginHint.getChildCount(); i++) { View v = loginHint.getChildAt(i); if (v instanceof TextView) { ((TextView) v).setTypeface(LatoRegular); } } LinearLayout IRCCloud = (LinearLayout) findViewById(R.id.IRCCloud); for (int i = 0; i < IRCCloud.getChildCount(); i++) { View v = IRCCloud.getChildAt(i); if (v instanceof TextView) { ((TextView) v).setTypeface(LatoRegular); } } notAProblem = (LinearLayout) findViewById(R.id.notAProblem); for (int i = 0; i < notAProblem.getChildCount(); i++) { View v = notAProblem.getChildAt(i); if (v instanceof TextView) { ((TextView) v).setTypeface((i == 0) ? LatoRegular : LatoLightItalic); } } loginSignupHint = (LinearLayout) findViewById(R.id.loginSignupHint); for (int i = 0; i < loginSignupHint.getChildCount(); i++) { View v = loginSignupHint.getChildAt(i); if (v instanceof TextView) { ((TextView) v).setTypeface(LatoRegular); ((TextView) v).setOnClickListener((i == 0) ? loginHintClickListener : signupHintClickListener); } } name.setTypeface(LatoRegular); email.setTypeface(LatoRegular); password.setTypeface(LatoRegular); host.setTypeface(LatoRegular); loginBtn.setTypeface(LatoRegular); signupBtn.setTypeface(LatoRegular); TOS.setTypeface(LatoRegular); EnterYourEmail.setTypeface(LatoRegular); hostHint.setTypeface(LatoLightItalic); if (BuildConfig.ENTERPRISE) { name.setVisibility(View.GONE); email.setVisibility(View.GONE); password.setVisibility(View.GONE); loginBtn.setVisibility(View.GONE); signupBtn.setVisibility(View.GONE); TOS.setVisibility(View.GONE); signupHint.setVisibility(View.GONE); loginHint.setVisibility(View.GONE); forgotPassword.setVisibility(View.GONE); loginSignupHint.setVisibility(View.GONE); EnterYourEmail.setVisibility(View.GONE); sendAccessLinkBtn.setVisibility(View.GONE); notAProblem.setVisibility(View.GONE); enterpriseLearnMore.setVisibility(View.VISIBLE); enterpriseHint.setVisibility(View.VISIBLE); host.setVisibility(View.VISIBLE); nextBtn.setVisibility(View.VISIBLE); hostHint.setVisibility(View.VISIBLE); host.requestFocus(); } if (savedInstanceState != null && savedInstanceState.containsKey("signup") && savedInstanceState.getBoolean("signup")) { signupHintClickListener.onClick(null); } if (savedInstanceState != null && savedInstanceState.containsKey("login") && savedInstanceState.getBoolean("login")) { loginHintClickListener.onClick(null); } if (savedInstanceState != null && savedInstanceState.containsKey("forgotPassword") && savedInstanceState.getBoolean("forgotPassword")) { forgotPasswordClickListener.onClick(null); } mResolvingError = savedInstanceState != null && savedInstanceState.getBoolean("resolving_error", false); mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Auth.CREDENTIALS_API) .addConnectionCallbacks(this).addOnConnectionFailedListener(this).build(); }