Ir al contenido principal

Entradas

Mostrando entradas de mayo, 2014

Android - Basic Steps (Alarms)

Alarms Remain active even if the device is asleep Are canceled on device shutdown/restart AlarmManager To get a reference use getSystemService(Context.ALARM_SERVICE) Methods Create Alarm set(...) Repeat setRepeating() setInexactRepeating() Alarm Type Constants RTC_WAKEUP - Execute the task at specific wall clock time. Wake up the device Use System.currentTimeMillis() to calculate the time RTC - Execute the task at specific wall clock time. Not wake up the device ELAPSE_REALTIME -  (time since boot, including sleep) Use  SystemClock.elapsedRealtime() to calculate the time ELAPSE_REALTIME_WAKEUP - 

Android - Basic Steps (Thread)

Thread UI Thread - Is the main thread UI Toolkit is not thread-safe Methods The following methods allows to  run in the UI Thread  View.post(Runnable r) Activity.runOnUiThread(Runnable r) AsyncTask Manage the Backgroud Thread & UI Thread Used for relative short tasks that lasting few seconds Background Thread Performs work Indicate progress UI Thread Does Setup Publishes intermediate progress Uses Results Workflow onPreExecute() Run in UI Thread before doInBackground() Do the setup doInBackground() Do the work in the background Return the result in a Result object pulishProgress() This method may be invoked onProgressUpdate() If pulishProgress() is invoked then this method continue Runs in the UI Thread onPostExecute Runs after  doInBackground() Handler Handle two threads of any kind One thread can hand off work to another thread by messages & posting runnables to handler associa...

Android - Basic Steps (Notifications)

User Notifications Types: Toast Notification Area Notifications Tip To use the notification vibration, establish the permission in the AndroidManifest.xml file    <uses-permission android:name="android.permission.VIBRATE" >     </uses-permission> Broadcast Base class for components that receive and react to events When event occur is represented as Intent, then are broadcast to system The Intent routes to BroadcastReceiver The BroadcastReceiver receive on the method onReceive() Broadcast Events can be broadcast in Order or Normal way Normal - Undefined order and if there are two or more BroadcastReceivers can process the event at the same time. Order - Deliver the intent one at the time in priority order Can also be Sticky or Not Sticky Sticky   Store intent after initial broadcast Is useful to record system changes like the battery status Is disposed after the event finish  Non Stick...

Github

Github Commands Upload the changes to GIT git add . git commit -m "Added associations" git push origin master Commands git init Initialize a Git repository git status Check if there are changes git add file_name Add specific file git add '*.txt' Add a type of files git rm '<file_name>' Delete a file git commit -m "Comment" Store our staged change git log Show all the changes git remote add origin https://github.com/<repository>/<repository_name>.git Push our local repository to Github server git push -u origin master  Push the changes to the server repo origin - is the name of the remote master - is the name of the branch -u - save the parameters, so the second time only type git push git pull origin master Down the changes from the server repo git diff HEAD Get the differences from our most recent commit git diff --staged See the changes you just staged git ...

Android - Basic Steps (UI)

View Elements Button ToggleButton Checkbox RatingBar AutoCompleteTextView ViewGroups RadioGroup TimePicker DatePicker WebView MapView Gallery Spinner Adapters & AdapterViews AdapterView are Views managed by an Adapter, who manage the data and provides data views AdapterView display the View ListView manage by ListAdapter Spinner manage by SpinnerAdapter Layouts match_parent - Occupy all the available space. D eprecated starting in API Level 8   fill_parent - Same asd match_parent but for API Level 8 LinearLayout Arrange all the child elements in one line RelativeLayout TableLayout GridView Menus Is defined in a resource XMLfile   res/menu/file.xml Use it on method OnCreate...Menu(), using the menu inflater Use method on...ItemSelection() to handle the item selection Types Options When user press a button In the method onCreateOptionsMenu() add the code to add the menu defined in res/menu/...

Android - Basic Steps (Fragments) II

Add a Fragment Dinamically The general steps are  While the activity is running can add a fragment to the layout  Get reference to the FragmentManager Begin a FragmentTransaction Add the Fragment  Commit the FragmentTransaction To change the previous application to add fragments dynamically, so: In the MainActivity.java override the onCreate method @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mTitleArray = getResources().getStringArray(R.array.Titles); mQuoteArray = getResources().getStringArray(R.array.Quotes); setContentView(R.layout.main); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.add(R.id.title_frame, new TitlesFragment()); fragmentTransaction.add(R.id.quote_frame, mQuoteFragment); fragmentTransaction.commit(); } I...

Android - Basic Steps (Fragments)

Fragments This functionality allows to support multiple UI panes / User behavior at the same time A fragment is part of an Activity Multiple Fragments can be embedded in an activity to create  a Multi-Pane UI A single fragment can be reused across multiple activities+ Fragment Lyfeclycle States Resumed Is visible in the sunning state Paused Another activity is in the foreground and has focus, containing activity is visible Stopped Fragment is not visible Fragment Lyfeclycle Methods  onAttach() Fragment is created and attached to the activity onCreate() Initialize the fragment onCreateView Fragments set up &returns its user inferface onActivityCreated activity has completed the onCreate() method and the fragment has been installed onStart() when activity become visible onResume Become visible and ready for user interaction onPause activity is visible without the focus onStop activity is no longer visible onDe...

Android - Basic Steps (Permissions)

Permissions User Permissions Are declared in the AndroidManifest.xml as strings They are in the tag <user-permission> <user-permission android:name="android.permission.CAMERA"> <user-permission android:name="android.permission.INTERNET"> <uses-permission android:name="android.permission.READ_CONTACTS" > - Allows to read the contact information from your list These permissions must be accepted before the application runs App Permissions The application's permissions to interact with another application is specified in the tag <permission> How to use permissions between Apps Invoking application In the AndroidManifest.xml add the <user-permission> that is allow by the application <uses-permission android:name="course.examples.permissionexample.BOOM_PERM" /> Calling application In the AndroidManifest.xml define the permission with the tag <permission> <permi...

Android - Basic Steps (Intent)

Application Components Activity Primary class for user interaction Provide the GUI Main 3 components Services - Support ground back operations Support interaction with remote processes BroadcastReceiver - Responds to an event on the device An example is the sms ContentProvider - Allow to share data among applications Uses database-style inferface Building an App http://developer.android.com/tools/building/index.html Define resources Package Manifest http://developer.android.com/guide/topics/manifest/manifest-intro.html Install & Run Signing the app  http://developer.android.com/tools/publishing/app-signing.html Activity The activity order is established in the task backstack The activity lifecycle Resumed / Running Paused Stopped Methods for an activity onCreate onStart - when the app become visible onResume - when is able to interact with the user onPause onStop - when the app become invisible onDestroy - i...

Android - Basic Steps II

Connect to an Emulator Run the emulator Open a terminal Type:  telnet localhost #cellphone_number Ex: telnet localhost 5554 Commands Enable Edge network network speed edge Enable 3G network network speed umts Establish not limit in the network  network speed full Establish power level power capacity #level Ex: power capacity 50 Not charging power status not-charging Establish coordinates  geo fix #coordinates Send an sms sms send #number "message_text" http://developer.android.com/tools/devices/emulator.html

Android - Basic Steps

Android Architecture Linux Kernel Contains the basic services Security  Memory & process managenemt File & network I/O Device drivers Specific Features as: Power management android shared memory low memory killer Libraries System C libraries Surface Mgr (Display management) Media Framework (Audio / Video) Webkit (Browser engine) OpenGL (Grpahics engine) Android Runtime (are the ones who runs the applications) Core Libraries  Basic Java classes JAVA.* , JAVAX.* App lifeclycle   ANDROID.* Internet / WS  ORG.* Unit test  JUNIT.* Dalvik virtual machine run the applications as a classes.dex; transforms java bytecode to classes.dex file  this virtual  machine is design to run in limited resources https://www.youtube.com/watch?v=ptjedOZEXPM Application Framework Package Manager - Contains all the application in the device Window Manager  View System - Provide the icons, tabs Resource Manager...

Rails - Basic Steps VI

Commands time_ago_in_words()  - As the name said put a date in words redirect_to - Redirect to an URL params[:attribute] - Get in the controller the parameters from the session Authentication In the controller root_app\app\controllers\*.rb At the beginning of the file add :   before_action :authenticate, except: [:index, :show] Where  authenticate  is a method, that need to be defined Then add at the final of the file the method definition     def authenticate         authenticate_or_request_with_http_basic do |name, password|           name == "admin" && password == "123"         end     end Ajax (Video 8 6:56 min) In the View  root_app\views\post\show.html.erb In the form tag, add a parameter to the form_for method:   remote: true In the Controller  root_app\controller\comment_controllers Add the line:   format...