Skip to content

Commit

Permalink
Add sesion 3 sqliteopenhelper.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarkstar authored and jmarkstar committed Sep 21, 2017
1 parent 45a9d9e commit 220984d
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 3 deletions.
4 changes: 2 additions & 2 deletions s3_adapters_sqlite/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})

compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

compile 'com.jakewharton:butterknife:8.8.1'
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
3 changes: 2 additions & 1 deletion s3_adapters_sqlite/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ButterknifeActivity"></activity>
<activity android:name=".ButterknifeActivity" />
<activity android:name=".SqliteActivity"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
Expand All @@ -13,6 +14,11 @@
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindColor;
import butterknife.BindDimen;
import butterknife.BindDrawable;
import butterknife.BindString;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
Expand All @@ -38,6 +44,11 @@ public class ButterknifeActivity extends AppCompatActivity {
@BindView(R.id.m_btn_guardar)
Button mBtnGuardar;

@BindString(R.string.app_name) String appName;
@BindDrawable(R.drawable.ic_rabbit) Drawable mDwRabbit;
@BindColor(R.color.colorAccent) int colorAccent;
@BindDimen(R.dimen.ancho_photo) float mDmAnchoPhoto;

public static void start(Context context) {
Intent starter = new Intent(context, ButterknifeActivity.class);
context.startActivity(starter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ public class MainActivity extends AppCompatActivity {
public void onGoButterknife(View view){
ButterknifeActivity.start(this);
}

public void onGoSqlite(View view){
SqliteActivity.start(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.jmarkstar.s3;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class SqliteActivity extends AppCompatActivity {

public static void start(Context context) {
Intent starter = new Intent(context, SqliteActivity.class);
context.startActivity(starter);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sqlite);
getSQLiteVersion();
}


private void getSQLiteVersion(){
String query = "select sqlite_version() AS sqlite_version";
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(":memory:", null);
Cursor cursor = db.rawQuery(query, null);
String sqliteVersion = "";
if (cursor.moveToNext()) {
sqliteVersion = cursor.getString(0);
Log.v("SqliteActivity", "sqliteVersion = "+sqliteVersion);
}
cursor.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.jmarkstar.s3.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
* Created by jmarkstar on 9/20/17.
*/

public class MySQLiteHelper extends SQLiteOpenHelper {

private static final String DB_NAME = "mydb.db";
private static final int DB_VERSION = 1;

public MySQLiteHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}

@Override public void onCreate(SQLiteDatabase sqLiteDatabase) {

}

@Override public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

}
}
5 changes: 5 additions & 0 deletions s3_adapters_sqlite/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
android:layout_height="wrap_content" />


<Button
android:text="SQLite"
android:onClick="onGoSqlite"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>

Expand Down
9 changes: 9 additions & 0 deletions s3_adapters_sqlite/src/main/res/layout/activity_sqlite.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.jmarkstar.s3.SqliteActivity">

</android.support.constraint.ConstraintLayout>
4 changes: 4 additions & 0 deletions s3_adapters_sqlite/src/main/res/values/dimen.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="ancho_photo">12dp</dimen>
</resources>

0 comments on commit 220984d

Please sign in to comment.