• Home
  • About me
  • Curriculum
  • Projects
Facebook Linkedin Twitter

MauroCerbai

Software Engineer

We both know that programming Android is mostly rewriting a number of times the same things.
Well here we are, save this page on the bookmarks and copy/paste when you need it.

FINDVIEWBYID

 mWeatherTextView = (TextView) findViewById(R.id.tv_weather_data);  

READ JSON DATA

 JSONObject weatherdata = new JSONObject (JSONstring);  
 JSONObject weather = weatherdata.getJSONObject("weather");  
 String condition = weather.getString("condition");  

BUILD URI AND CONVERT TO URL

 Uri builturi = Uri.parse(BASE_URL).buildUpon()  
     .appendQueryParameter(QUERY_PARAM, param)  
     .build();  
 URL url = null;  
 try {  
   url = new URL(builturi.toString());  
 } catch (MalformedURLException e) {  
   e.printStackTrace();  
 }  
 return url;  

EXECUTE ASYNCTASK

 new GithubQueryTask().execute(githubSearchUrl);  


ADD MENU IN TOP BAR

 @Override  
 public boolean onCreateOptionsMenu(Menu menu) {  
   MenuInflater inflater = getMenuInflater();  
   inflater.inflate(R.menu.forecast, menu);  
   return true;  
 } 

 @Override  
 public boolean onOptionsItemSelected(MenuItem item) {  
   if (item.getItemId() == R.id.action_refresh) {  
     mWeatherTextView.setText("");  
     loadWeatherData();  
     return true;  
   }  
   return super.onOptionsItemSelected(item);  
 }  

EXPLICIT INTENT

 Intent intent = new Intent(this, SettingsActivity.class);  
 startActivity(intent);  


INTENT FOR EXTERNAL MAP

 Intent intent = new Intent(Intent.ACTION_VIEW);  
 Uri uri = new Uri.Builder().scheme("geo").path("0,0").query("california").build();  
 intent.setData(uri);  
 if (intent.resolveActivity(getPackageManager()) != null) {  
   startActivity(intent);  
 }  

SHARE INTENT

 Intent shareIntent = ShareCompat.IntentBuilder.from(activity)  
  .setType("text/plain")  
  .setText(shareText)  
  .getIntent();  
 if (shareIntent.resolveActivity(getPackageManager()) != null) {  
  startActivity(shareIntent);  
 }  

ITEM IN THE ACTION BAR

 <item  
   android:id="@+id/action_share"  
   android:title="Share"  
   android:orderInCategory="1"  
   app:showAsAction="ifRoom"/>  

ASYNCTASKLOADER

(it handles lifecycle)
 @Override  
 public Loader<String[]> onCreateLoader(int id, Bundle args) {  
   return new AsyncTaskLoader<String[]>(this) {  
     String[] weatherData = null; //Cache data  
     @Override protected void onStartLoading() {}//Check cache data and show progress bar then forceLoad()  
     @Override public String[] loadInBackground() {}//Get data from prefences or bundle and do network request  
     @Override public void deliverResult(String[] data) {}//save data in cache  
   };  
 }  

USE PREFERENCEFRAGMENT

SHAREDPREFERENCES

 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);  
 sharedPreferences.getBoolean("show_bass", true);  


LISTEN TO SWYPE ON RECYCLEVIEW

 new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {  
   @Override  
   public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {  
     return false;  
   }  
   @Override  
   public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {  
     long id = (long) viewHolder.itemView.getTag();  
     removeGuest(id);  
     mAdapter.swapCursor(getAllGuests());  
   }  
 }).attachToRecyclerView(waitlistRecyclerView);  


Here some interesting images too:



Share
Tweet
Pin
Share
No commenti
Newer Posts
Older Posts

About me


Smiley face
Computer Science Degree, technology enthusiast, programmer, interested in startup & innovation, curious, precise & organized.

Follow Me

  • Facebook
  • Linkedin
  • Twitter
  • Bitbucket
  • Github

recent posts

Categories

  • dev
  • development
  • software
  • learn
  • learning
  • machine
  • machine learning
  • study
  • android
  • google
  • job
  • scikit
  • sklearn
  • app
  • udacity
  • gdg
  • google play
  • html
  • code
  • electronics
  • linux
  • script
  • uda
  • webgl
  • database
  • gdgmilano
  • help
  • open source
  • programming
  • smartphone
  • torino
  • weekend
  • work
  • workshop
  • 3d
  • firebase
  • gps
  • greatmind
  • hardware
  • location
  • personal computer
  • start up
  • .bashrc
  • GB
  • PS3
  • Vallée des Merveilles
  • action
  • analytics
  • audio
  • avi
  • bayes
  • books
  • bug
  • cpu
  • dinolib
  • docker
  • fake
  • ffmpeg
  • force
  • francaise
  • france
  • francia
  • free
  • gear 360
  • gglass
  • git
  • gitconfig
  • glass
  • hdd
  • hike
  • hiring
  • jenkins
  • joke
  • kde
  • kmix
  • magnetism
  • material
  • materialdesign
  • merge-it
  • messaging
  • microservices
  • mint
  • naive bayes
  • navigation drawer
  • nemo
  • nikola
  • nikolatesla
  • pc
  • ram
  • reading
  • refuge
  • samsung
  • space
  • spain
  • ssd
  • steam
  • tesla
  • unturned
  • valle delle meraviglie
  • veromix
  • versioning
  • windows
  • wizard
  • wolley
  • wolleybuy
  • xvid

Blog Archive

  • ottobre (1)
  • settembre (1)
  • gennaio (1)
  • novembre (1)
  • maggio (1)
  • aprile (1)
  • marzo (3)
  • febbraio (3)
  • gennaio (1)
  • novembre (7)
  • ottobre (4)
  • settembre (3)
  • agosto (1)
  • luglio (1)
  • settembre (1)
  • agosto (1)
  • giugno (2)
  • aprile (2)
  • marzo (1)
  • febbraio (3)
  • gennaio (2)
  • novembre (1)
  • agosto (2)
  • luglio (2)
  • giugno (3)
  • marzo (1)
  • novembre (1)
  • ottobre (1)
  • agosto (1)
  • giugno (1)
  • maggio (2)
  • marzo (2)
  • febbraio (1)
Facebook Linkedin Twitter Bitbucket Github

Created with by ThemeXpose | Distributed By Gooyaabi Templates