This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ---- NSDate -> NSString ---- | |
| NSDateFormatter *formatter; | |
| NSString *dateString; | |
| formatter = [[NSDateFormatter alloc] init]; | |
| [formatter setDateFormat:@"dd-MM-yyyy HH:mm"]; // Change accordingly. | |
| dateString = [formatter stringFromDate:[NSDate date]]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public int getVersionCode() { | |
| int versionCode = 0; | |
| try { | |
| versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; | |
| } catch (PackageManager.NameNotFoundException e) { | |
| // Huh? Really? | |
| } | |
| return versionCode; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| To hide the navigation bar: | |
| [[self navigationController] setNavigationBarHidden:YES animated:YES]; | |
| To show it: | |
| [[self navigationController] setNavigationBarHidden:NO animated:YES]; | |
| See: http://stackoverflow.com/questions/2926914/navigation-bar-show-hide |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example.toolbarexample; | |
| import android.os.Bundle; | |
| import android.support.v7.app.ActionBarActivity; | |
| import android.support.v7.widget.Toolbar; | |
| import android.view.Menu; | |
| import android.view.MenuItem; | |
| public class MainActivity extends ActionBarActivity { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| startActivity(new Intent(Settings.ACTION_LOCALE_SETTINGS)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Add code to print out the key hash | |
| try { | |
| PackageInfo info = getPackageManager().getPackageInfo("my.app.packagename", | |
| PackageManager.GET_SIGNATURES); | |
| for (Signature signature : info.signatures) { | |
| MessageDigest md = MessageDigest.getInstance("SHA"); | |
| md.update(signature.toByteArray()); | |
| Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); | |
| } | |
| } catch (PackageManager.NameNotFoundException e) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Uri myImageContentUri; // A content Uri to the image you would like to share. | |
| String myAppId = "<Your_Facebook_App_Id>"; | |
| Intent shareIntent = new Intent(); | |
| shareIntent.setAction(Intent.ACTION_SEND); | |
| shareIntent.setType("image/*"); | |
| shareIntent.putExtra(Intent.EXTRA_STREAM, myImageContentUri); | |
| // Include your Facebook App Id for attribution | |
| shareIntent.putExtra("com.facebook.platform.extra.APPLICATION_ID", myAppId); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_resource); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| List of good posts about Android screenresolutions: | |
| http://stackoverflow.com/questions/6272384/most-popular-screen-sizes-resolutions-on-android-phones | |
| http://petrnohejl.github.io/Android-Cheatsheet-For-Graphic-Designers/ | |
| More to come... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class FizzBuzz { | |
| public static void main(String[] args) { | |
| for (int i = 1; i <= 100; i++) { | |
| if ((i % 5 == 0) && (i % 3 == 0)) { | |
| System.out.println("FizzBuzz"); | |
| } else if (i % 3 == 0) { | |
| System.out.println("Fizz"); | |
| } else if (i % 5 == 0) { | |
| System.out.println("Buzz"); | |
| } else { |