6 |
--------------------------------------------------------------------------------
/ShippingwithSqlLite/gen/com/binarybricks/shippingwithsqllite/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.binarybricks.shippingwithsqllite;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/ShippingwithSqlLite/README.md:
--------------------------------------------------------------------------------
1 | Shipping With Sqllite
2 | ===================
3 |
4 | This example shows how you can ship SqlLite db with your android app. Many times you want to pre ship database with your android app with this sample code you can incorprate that functionality in your app
--------------------------------------------------------------------------------
/ShippingwithSqlLite/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ShippingwithSqlLite
3 | Hello world!
4 | Settings
5 | MainActivity
6 |
--------------------------------------------------------------------------------
/AndroidHelpOverlay/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidHelpOverlay
3 | Hello world!
4 | Settings
5 | HelpOverlay
6 |
--------------------------------------------------------------------------------
/AndroidHelpOverlay/res/menu/activity_help_overlay.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Android Examples
2 | ===================
3 |
4 | Repo for Simple android examples, This examples can be use for adding different functionalities into your app use this for rapid prototyping your app
5 |
6 | => Shipping with Sqllite
7 | This example shows how you can ship SqlLite db with your android app
8 |
9 | => Android help Overlay
10 | This example shows how you can create simple Coach Marks/Help overlays in your android app to make users aware of different functionality of your app.
11 |
--------------------------------------------------------------------------------
/AndroidHelpOverlay/res/layout/overlay_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
13 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/ShippingwithSqlLite/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
13 |
14 |
--------------------------------------------------------------------------------
/AndroidHelpOverlay/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-15
15 |
--------------------------------------------------------------------------------
/ShippingwithSqlLite/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-8
15 |
--------------------------------------------------------------------------------
/AndroidHelpOverlay/README.md:
--------------------------------------------------------------------------------
1 | Android help Overlay
2 | ===================
3 | This is a simple example which helps you in creating simple Coach Marks/Help overlays in your android app to make users aware of different functionality of your app.
4 |
5 | If you have use apps like Pulse or EX file explorer you would have notice that when you use the app for the first time it presents you with nice help overlays explaining different functionality of app.
6 |
7 | We are trying to achive the same thing with this example code
8 |
9 |
10 | Updated the code with more simplified method which will work in fragments
11 |
12 |
13 | 
14 |
--------------------------------------------------------------------------------
/ShippingwithSqlLite/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
8 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/AndroidHelpOverlay/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
8 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/AndroidHelpOverlay/res/layout/activity_help_overlay.xml:
--------------------------------------------------------------------------------
1 |
6 |
12 |
20 |
--------------------------------------------------------------------------------
/AndroidHelpOverlay/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/ShippingwithSqlLite/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/ShippingwithSqlLite/gen/com/binarybricks/shippingwithsqllite/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package com.binarybricks.shippingwithsqllite;
9 |
10 | public final class R {
11 | public static final class attr {
12 | }
13 | public static final class drawable {
14 | public static final int ic_action_search=0x7f020000;
15 | public static final int ic_launcher=0x7f020001;
16 | }
17 | public static final class id {
18 | public static final int helloworld=0x7f070000;
19 | public static final int menu_settings=0x7f070001;
20 | }
21 | public static final class layout {
22 | public static final int activity_main=0x7f030000;
23 | }
24 | public static final class menu {
25 | public static final int activity_main=0x7f060000;
26 | }
27 | public static final class string {
28 | public static final int app_name=0x7f040000;
29 | public static final int hello_world=0x7f040001;
30 | public static final int menu_settings=0x7f040002;
31 | public static final int title_activity_main=0x7f040003;
32 | }
33 | public static final class style {
34 | public static final int AppTheme=0x7f050000;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/ShippingwithSqlLite/src/com/binarybricks/shippingwithsqllite/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.binarybricks.shippingwithsqllite;
2 |
3 | import com.binarybricks.DBHelper.DataBaseHelper;
4 |
5 | import android.os.Bundle;
6 | import android.app.Activity;
7 | import android.database.Cursor;
8 | import android.database.sqlite.SQLiteDatabase;
9 | import android.view.Menu;
10 | import android.widget.TextView;
11 |
12 | public class MainActivity extends Activity {
13 |
14 | @Override
15 | public void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_main);
18 |
19 | //This methos will be used to copy db if doesn't exsist
20 | DataBaseHelper mydatabaseHelper = new DataBaseHelper(this);
21 |
22 | //Get Reference of your db
23 | SQLiteDatabase myDataBase = mydatabaseHelper.openDataBase();
24 | Cursor result =myDataBase.rawQuery("SELECT * FROM HelloSQL",null);
25 | if (result != null) {
26 | while(result.moveToNext()) {
27 | String appname = result.getString(result.getColumnIndex("Hello"));
28 | TextView helloName = (TextView)findViewById(R.id.helloworld);
29 | helloName.setText(appname);
30 | break;
31 | }
32 | }
33 | }
34 |
35 | @Override
36 | public boolean onCreateOptionsMenu(Menu menu) {
37 | getMenuInflater().inflate(R.menu.activity_main, menu);
38 | return true;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/AndroidHelpOverlay/gen/com/binarybricks/androidhelpoverlay/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package com.binarybricks.androidhelpoverlay;
9 |
10 | public final class R {
11 | public static final class attr {
12 | }
13 | public static final class drawable {
14 | public static final int ic_action_search=0x7f020000;
15 | public static final int ic_launcher=0x7f020001;
16 | public static final int overlay=0x7f020002;
17 | }
18 | public static final class id {
19 | public static final int analogClock1=0x7f070000;
20 | public static final int button1=0x7f070001;
21 | public static final int imageView1=0x7f070003;
22 | public static final int menu_settings=0x7f070004;
23 | public static final int overlayLayout=0x7f070002;
24 | }
25 | public static final class layout {
26 | public static final int activity_help_overlay=0x7f030000;
27 | public static final int overlay_view=0x7f030001;
28 | }
29 | public static final class menu {
30 | public static final int activity_help_overlay=0x7f060000;
31 | }
32 | public static final class string {
33 | public static final int app_name=0x7f040000;
34 | public static final int hello_world=0x7f040001;
35 | public static final int menu_settings=0x7f040002;
36 | public static final int title_activity_help_overlay=0x7f040003;
37 | }
38 | public static final class style {
39 | public static final int AppTheme=0x7f050000;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## Eclipse
3 | #################
4 |
5 | *.pydevproject
6 | .project
7 | .metadata
8 | bin/
9 | tmp/
10 | *.tmp
11 | *.bak
12 | *.swp
13 | *~.nib
14 | local.properties
15 | .classpath
16 | .settings/
17 | .loadpath
18 |
19 | # External tool builders
20 | .externalToolBuilders/
21 |
22 | # Locally stored "Eclipse launch configurations"
23 | *.launch
24 |
25 | # CDT-specific
26 | .cproject
27 |
28 | # PDT-specific
29 | .buildpath
30 |
31 |
32 | #################
33 | ## Visual Studio
34 | #################
35 |
36 | ## Ignore Visual Studio temporary files, build results, and
37 | ## files generated by popular Visual Studio add-ons.
38 |
39 | # User-specific files
40 | *.suo
41 | *.user
42 | *.sln.docstates
43 |
44 | # Build results
45 | [Dd]ebug/
46 | [Rr]elease/
47 | *_i.c
48 | *_p.c
49 | *.ilk
50 | *.meta
51 | *.obj
52 | *.pch
53 | *.pdb
54 | *.pgc
55 | *.pgd
56 | *.rsp
57 | *.sbr
58 | *.tlb
59 | *.tli
60 | *.tlh
61 | *.tmp
62 | *.vspscc
63 | .builds
64 | *.dotCover
65 |
66 | ## TODO: If you have NuGet Package Restore enabled, uncomment this
67 | #packages/
68 |
69 | # Visual C++ cache files
70 | ipch/
71 | *.aps
72 | *.ncb
73 | *.opensdf
74 | *.sdf
75 |
76 | # Visual Studio profiler
77 | *.psess
78 | *.vsp
79 |
80 | # ReSharper is a .NET coding add-in
81 | _ReSharper*
82 |
83 | # Installshield output folder
84 | [Ee]xpress
85 |
86 | # DocProject is a documentation generator add-in
87 | DocProject/buildhelp/
88 | DocProject/Help/*.HxT
89 | DocProject/Help/*.HxC
90 | DocProject/Help/*.hhc
91 | DocProject/Help/*.hhk
92 | DocProject/Help/*.hhp
93 | DocProject/Help/Html2
94 | DocProject/Help/html
95 |
96 | # Click-Once directory
97 | publish
98 |
99 | # Others
100 | [Bb]in
101 | [Oo]bj
102 | sql
103 | TestResults
104 | *.Cache
105 | ClientBin
106 | stylecop.*
107 | ~$*
108 | *.dbmdl
109 | Generated_Code #added for RIA/Silverlight projects
110 |
111 | # Backup & report files from converting an old project file to a newer
112 | # Visual Studio version. Backup files are not needed, because we have git ;-)
113 | _UpgradeReport_Files/
114 | Backup*/
115 | UpgradeLog*.XML
116 |
117 |
118 |
119 | ############
120 | ## Windows
121 | ############
122 |
123 | # Windows image file caches
124 | Thumbs.db
125 |
126 | # Folder config file
127 | Desktop.ini
128 |
129 |
130 | #############
131 | ## Python
132 | #############
133 |
134 | *.py[co]
135 |
136 | # Packages
137 | *.egg
138 | *.egg-info
139 | dist
140 | build
141 | eggs
142 | parts
143 | bin
144 | var
145 | sdist
146 | develop-eggs
147 | .installed.cfg
148 |
149 | # Installer logs
150 | pip-log.txt
151 |
152 | # Unit test / coverage reports
153 | .coverage
154 | .tox
155 |
156 | #Translations
157 | *.mo
158 |
159 | #Mr Developer
160 | .mr.developer.cfg
161 |
162 | # Mac crap
163 | .DS_Store
164 |
--------------------------------------------------------------------------------
/AndroidHelpOverlay/src/com/binarybricks/androidhelpoverlay/HelpOverlay.java:
--------------------------------------------------------------------------------
1 | package com.binarybricks.androidhelpoverlay;
2 |
3 | import android.app.Activity;
4 | import android.app.Dialog;
5 | import android.content.Context;
6 | import android.os.Bundle;
7 | import android.view.View;
8 | import android.view.View.OnClickListener;
9 | import android.widget.LinearLayout;
10 |
11 | /**
12 | * Copyright (C) 2012
13 | * @author Pranay Airan
14 | * AndroidHelpOverlay
15 | * com.binarybricks.androidhelpoverlay
16 | *
17 | * This is a simple example of creating Help overlay screen
18 | * for android apps, this overlays/Coach marks helps first time
19 | * users of your app to get all information while they are using
20 | * the app, this overlay/coach marks helps in explaining different
21 | * functionality your app offers
22 | */
23 | public class HelpOverlay extends Activity {
24 |
25 | Context ctx;
26 | @Override
27 | public void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | ctx = this;
30 | setContentView(R.layout.activity_help_overlay);
31 |
32 | //Call the set overlay, you can put the logic of checking if overlay is already called with a simple sharedpreference
33 | showOverLay();
34 |
35 | /*
36 | * This is an old method which does't work in lot of cases please see the new method
37 | * Create a new framelayout so that we can associate child layouts with it
38 |
39 | final FrameLayout overlayFramelayout = new FrameLayout(getApplicationContext());
40 |
41 | //Set the framelayout as root layout in your activity
42 | setContentView(overlayFramelayout);
43 |
44 | //Get the reference of your main layout and reference of overlay layout
45 | View view = getLayoutInflater().inflate(R.layout.activity_help_overlay, overlayFramelayout,false);
46 | final View overlay_view = getLayoutInflater().inflate(R.layout.overlay_view, overlayFramelayout,false);
47 |
48 | //Add both layout to the frame layout
49 | overlayFramelayout.addView(view);
50 | overlayFramelayout.addView(overlay_view);
51 |
52 |
53 | * In your application you might want to remove the overlay when some one clicks on it.
54 | * Put a ontouch or onclick listner so that we can remove overlay layout from the framelayout
55 |
56 | overlayFramelayout.setOnTouchListener(new OnTouchListener() {
57 |
58 | public boolean onTouch(View v, MotionEvent event) {
59 |
60 | // Determine if framelayout has overlay before removing it to prevent error
61 | if(overlayFramelayout.getChildCount()>1)
62 | overlayFramelayout.removeView(overlay_view);
63 |
64 |
65 | return true;
66 | }
67 | });*/
68 | }
69 |
70 | private void showOverLay(){
71 |
72 | final Dialog dialog = new Dialog(ctx, android.R.style.Theme_Translucent_NoTitleBar);
73 |
74 | dialog.setContentView(R.layout.overlay_view);
75 |
76 | LinearLayout layout = (LinearLayout) dialog.findViewById(R.id.overlayLayout);
77 |
78 | layout.setOnClickListener(new OnClickListener() {
79 |
80 | @Override
81 |
82 | public void onClick(View arg0) {
83 |
84 | dialog.dismiss();
85 |
86 | }
87 |
88 | });
89 |
90 | dialog.show();
91 |
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/ShippingwithSqlLite/src/com/binarybricks/DBHelper/DataBaseHelper.java:
--------------------------------------------------------------------------------
1 | package com.binarybricks.DBHelper;
2 |
3 | import java.io.FileOutputStream;
4 | import java.io.InputStream;
5 | import java.io.OutputStream;
6 |
7 | import android.content.Context;
8 | import android.database.SQLException;
9 | import android.database.sqlite.SQLiteDatabase;
10 | import android.database.sqlite.SQLiteException;
11 | import android.database.sqlite.SQLiteOpenHelper;
12 |
13 | /**
14 | *
15 | * Copyright (C) 2012
16 | * @code from http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
17 | * ShippingwithSqlLite
18 | * com.binarybricks.DBHelper
19 | * This helper Class helps in shipping android app with database
20 | * this class will help in copying a database from your android app Asset folder to your app
21 | * once the db is copied you can use it in the same way as you do when you create a new db
22 | */
23 | public class DataBaseHelper extends SQLiteOpenHelper{
24 |
25 | //The Android's default system path of your application database.
26 | //replace com.binarybricks.shippingwithsqllite with you Application package nae
27 | //This should be same as which you used package section in your manifest
28 | private static String DB_PATH = "/data/data/com.binarybricks.shippingwithsqllite/databases/";
29 |
30 | //replace this with name of your db file which you copied into asset folder
31 | private static String DB_NAME = "dexterology";
32 |
33 | private SQLiteDatabase myDataBase;
34 |
35 | private final Context myContext;
36 |
37 | /**
38 | * Constructor
39 | * Takes and keeps a reference of the passed context in order to access to the application assets and resources.
40 | * @param context
41 | */
42 | public DataBaseHelper(Context context) {
43 |
44 | super(context, DB_NAME, null, 1);
45 | this.myContext = context;
46 | this.createDataBase();
47 | }
48 |
49 | /**
50 | * Creates a empty database on the system and rewrites it with your own database.
51 | * */
52 | public void createDataBase(){
53 | try {
54 | boolean dbExist = checkDataBase();
55 |
56 | if(dbExist){
57 | //do nothing - database already exist
58 | }else{
59 | //By calling this method and empty database will be created into the default system path
60 | //of your application so we are gonna be able to overwrite that database with our database.
61 | this.getReadableDatabase();
62 |
63 |
64 | copyDataBase();
65 |
66 | }
67 | }
68 | catch (Exception e) {
69 |
70 | }
71 | }
72 |
73 | /**
74 | * Check if the database already exist to avoid re-copying the file each time you open the application.
75 | * @return true if it exists, false if it doesn't
76 | */
77 | private boolean checkDataBase(){
78 |
79 | SQLiteDatabase checkDB = null;
80 |
81 | try{
82 | String myPath = DB_PATH + DB_NAME;
83 | checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
84 |
85 | }catch(SQLiteException e){
86 |
87 | //database does't exist yet.
88 |
89 | }
90 |
91 | if(checkDB != null){
92 |
93 | checkDB.close();
94 |
95 | }
96 |
97 | return checkDB != null ? true : false;
98 | }
99 |
100 | /**
101 | * Copies your database from your local assets-folder to the just created empty database in the
102 | * system folder, from where it can be accessed and handled.
103 | * This is done by transfering bytestream.
104 | * */
105 | private void copyDataBase(){
106 |
107 | try{
108 | //Open your local db as the input stream
109 | InputStream myInput = myContext.getAssets().open(DB_NAME);
110 |
111 | // Path to the just created empty db
112 | String outFileName = DB_PATH + DB_NAME;
113 |
114 | //Open the empty db as the output stream
115 | OutputStream myOutput = new FileOutputStream(outFileName);
116 |
117 | //transfer bytes from the inputfile to the outputfile
118 | byte[] buffer = new byte[1024];
119 | int length;
120 | while ((length = myInput.read(buffer))>0){
121 | myOutput.write(buffer, 0, length);
122 | }
123 |
124 | //Close the streams
125 | myOutput.flush();
126 | myOutput.close();
127 | myInput.close();
128 | }
129 | catch (Exception e) {
130 | //catch exception
131 | }
132 | }
133 |
134 | public SQLiteDatabase openDataBase() throws SQLException{
135 |
136 | //Open the database
137 | String myPath = DB_PATH + DB_NAME;
138 | myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
139 | return myDataBase;
140 |
141 | }
142 |
143 | @Override
144 | public synchronized void close() {
145 |
146 | if(myDataBase != null)
147 | { myDataBase.close();}
148 |
149 | super.close();
150 |
151 | }
152 |
153 | @Override
154 | public void onCreate(SQLiteDatabase db) {
155 |
156 | }
157 |
158 | @Override
159 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
160 |
161 | }
162 |
163 |
164 | }
--------------------------------------------------------------------------------