\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{fabiobays} \pdfinfo{ /Title (csis-3175-mobile.pdf) /Creator (Cheatography) /Author (fabiobays) /Subject (CSIS 3175 Mobile Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{CSIS 3175 Mobile Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{fabiobays} via \textcolor{DarkBackground}{\uline{cheatography.com/80431/cs/19381/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}fabiobays \\ \uline{cheatography.com/fabiobays} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 18th April, 2019.\\ Updated 18th April, 2019.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Decimal Format}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{DecimalFormat currency = new DecimalFormat("\$\#\#\#,\#\#\#.\#\#"); \newline currency.format(totalCost));} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Pass And Get Value Into/From Another Activity}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Intent i = new Intent(MainActivity.this, \newline SecondActivity.class); \newline i.putExtra("data",totalCost); \newline startActivity(i); \newline \newline Intent intent = getIntent(); \newline Double value = itent.getDoubleExtra(Key,0);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Splash Activity}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{public class SplashActivity extends AppCompatActivity \{ \newline @Override \newline protected void onCreate(Bundle savedInstanceState) \{ \newline \seqsplit{super.onCreate(savedInstanceState);} \newline \seqsplit{setContentView(R.layout.activity\_splash);} \newline TimerTask task = new TimerTask() \{ \newline @Override \newline public void run() \{ \newline finish(); \newline startActivity(new \seqsplit{Intent(SplashActivity.this}, \newline MainActivity.class)); \newline \} \newline \}; \newline Timer t = new Timer(); \newline t.schedule(task,4000); \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Working with Files}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{FileOutputStream fout = \newline openFileOutput("File1.txt",MODE\_APPEND); \newline fout.write(data.getBytes()); \newline fout.write("\textbackslash{}n".getBytes()); \newline fout.close(); \newline FileInputStream fin = \seqsplit{openFileInput("File1.txt");} \newline String temp = ""; \newline int c; \newline char ch; \newline while((c=fin.read())!=-1)\{ \newline ch = (char)c; \newline temp += Character.toString(ch); \newline \} \newline output.setText(temp); \newline fin.close();} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Calling DBHelper}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{//to view student records \newline /*Cursor c = dbh.viewData(); \newline StringBuilder str = new StringBuilder(); \newline if(c.getCount()\textgreater{}0)\{ \newline while (c.moveToNext())\{ \newline str.append("ID : " +c.getString(0)); \newline str.append(" First Name : " +c.getString(1)); \newline str.append(" Last Name : "+c.getString(2)); \newline str.append(" Cell number : "+ c.getString(3)); \newline str.append(" prov Id : " + c.getString(4)); \newline str.append("\textbackslash{}n"); \newline \} \newline result.setText(str); \newline \newline //Create Record \newline boolean isAdded= \seqsplit{db.addRec(fn.getText().toString()},ln.getText().toString(), \newline cn.getText().toString(),pi.getText().toString());} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{New Page}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Database}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{public class DatabaseHelper extends SQLiteOpenHelper\{ \newline final static String DATABASE\_NAME = "Information.db"; \newline final static int DATABASE\_VERSION = 4; \newline \newline public DatabaseHelper(Context context) \{ \newline super(context, DATABASE\_NAME, null, DATABASE\_VERSION); \newline \} \newline \newline @Override \newline public void onCreate(SQLiteDatabase db) \{ \newline //creating student\_table and province\_table \newline String query = "Create Table {[}TABLENAME{]} ( {[}COLUMN{]} INTEGER PRIMARY KEY ,COLUMN2 TEXT,...)"; \newline //Only INTEGER, TEXT OR REAL \newline try\{ \newline db.execSQL(query); \newline \} \newline catch (Exception e)\{ \newline e.printStackTrace(); \newline \} \newline \} \newline \newline @Override \newline public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) \{ \newline db.execSQL("Drop table if exists " + TABLE1\_NAME); \newline db.execSQL("Drop table if exists " + TABLE2\_NAME); \newline onCreate(db); \newline \} \newline \newline //Add Record \newline SQLiteDatabase db = \seqsplit{this.getWritableDatabase();} \newline ContentValues values = new ContentValues(); \newline values.put("Column",value); \newline long r = db.insert(TABLE1\_NAME,null,values); \newline if(r == -1)\{ \newline return false; \newline \} \newline else\{ \newline return true; \newline \} \newline \newline //method to view data \newline public Cursor viewData()\{ \newline SQLiteDatabase db = \seqsplit{this.getWritableDatabase();} \newline String query = "Select * from " + TABLE1\_NAME; \newline Cursor c = db.rawQuery(query,null); \newline return c; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Play Media}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{mpG = new MediaPlayer(); \newline mpG = MediaPlayer.create(this,R.raw.ukulele); \newline mpD = new MediaPlayer(); \newline mpD = MediaPlayer.create(this,R.raw.drums); \newline mpG.start(); \newline mpG.pauset();} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Shared Prefs}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{final SharedPreferences sharedPref = \newline \seqsplit{PreferenceManager.getDefaultSharedPreferences} \newline (this); \newline \newline button.setOnClickListener(new View.OnClickListener() \{ \newline @Override \newline public void onClick(View v) \{ \newline intYear = \seqsplit{Integer.parseInt(years.getText().toString());} \newline decLoan = \seqsplit{Float.parseFloat(loan.getText().toString());} \newline decInterest = \seqsplit{Float.parseFloat(interest.getText().toString());} \newline SharedPreferences.Editor editor = sharedPref.edit(); \newline editor.putInt("key1",intYear); \newline editor.putFloat("key2",decLoan); \newline editor.putFloat("key3",decInterest); \newline editor.commit(); \newline startActivity(new Intent \newline (MainActivity.this,Payment.class)); \newline \} \newline \}); \newline \newline \newline //Get the values \newline SharedPreferences sp = PreferenceManager. \newline \seqsplit{getDefaultSharedPreferences(this);} \newline \newline int years = sp.getInt("key1",0); \newline float loan = sp.getFloat("key2",0); \newline float interest = sp.getFloat("key3",0);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Working With Fragments}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{public class FragmentOne extends Fragment \{ \newline @Override \newline public View \seqsplit{onCreateView(LayoutInflater} inflater, ViewGroup container, \newline Bundle savedInstanceState) \{ \newline // Inflate the layout for this fragment \newline return \seqsplit{inflater.inflate(R.layout.fragment\_fragment\_one}, container, false); \newline \} \newline //Main \newline public void clickOne(View view)\{ \newline FragmentManager fm = \seqsplit{getSupportFragmentManager();} \newline FragmentTransaction ft = fm.beginTransaction(); \newline FragmentOne f1 = new FragmentOne(); \newline ft.add(R.id.rlFrag1,f1); \newline ft.commit(); \newline \} \newline //Add this to the layout \newline android:onClick="clickOne" \newline //Dont forget to change fragment layout to relative} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}