-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aditya
committed
Feb 28, 2021
1 parent
2b0a27c
commit 5be8f53
Showing
12 changed files
with
271 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.aditya.hopon; | ||
|
||
import android.content.ContentValues; | ||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.database.SQLException; | ||
import android.database.sqlite.SQLiteDatabase; | ||
|
||
public class DBManager { | ||
|
||
private DatabaseHelper dbHelper; | ||
|
||
private Context context; | ||
|
||
private SQLiteDatabase database; | ||
|
||
public DBManager(Context c) { | ||
context = c; | ||
} | ||
|
||
public DBManager open() throws SQLException { | ||
dbHelper = new DatabaseHelper(context); | ||
database = dbHelper.getWritableDatabase(); | ||
return this; | ||
} | ||
|
||
public void close() { | ||
dbHelper.close(); | ||
} | ||
|
||
public void insert(String name, String sequence,int mode) { | ||
ContentValues contentValue = new ContentValues(); | ||
contentValue.put(DatabaseHelper.NAME, name); | ||
contentValue.put(DatabaseHelper.SEQUENCE, sequence); | ||
contentValue.put(DatabaseHelper.MODE,mode); | ||
database.insert(DatabaseHelper.TABLE_NAME, null, contentValue); | ||
} | ||
|
||
public Cursor fetch() { | ||
String[] columns = new String[] { DatabaseHelper._ID, DatabaseHelper.NAME, DatabaseHelper.SEQUENCE,DatabaseHelper.MODE }; | ||
Cursor cursor = database.query(DatabaseHelper.TABLE_NAME, columns, null, null, null, null, null); | ||
if (cursor != null) { | ||
cursor.moveToFirst(); | ||
} | ||
return cursor; | ||
} | ||
|
||
public int update(long _id, String name, String desc,int mode) { | ||
ContentValues contentValues = new ContentValues(); | ||
contentValues.put(DatabaseHelper.NAME, name); | ||
contentValues.put(DatabaseHelper.SEQUENCE, desc); | ||
contentValues.put(DatabaseHelper.MODE,mode); | ||
int i = database.update(DatabaseHelper.TABLE_NAME, contentValues, DatabaseHelper._ID + " = " + _id, null); | ||
return i; | ||
} | ||
|
||
public void delete(long _id) { | ||
database.delete(DatabaseHelper.TABLE_NAME, DatabaseHelper._ID + "=" + _id, null); | ||
} | ||
|
||
} | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.aditya.hopon; | ||
|
||
import android.content.Context; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteOpenHelper; | ||
|
||
public class DatabaseHelper extends SQLiteOpenHelper { | ||
|
||
// Table Name | ||
public static final String TABLE_NAME = "Patterns"; | ||
|
||
// Table columns | ||
public static final String _ID = "_id"; | ||
public static final String NAME = "name"; | ||
public static final String SEQUENCE = "sequence"; | ||
public static final String MODE = "mode"; | ||
// Database Information | ||
static final String DB_NAME = "Hopon_Patterns.DB"; | ||
|
||
// database version | ||
static final int DB_VERSION = 1; | ||
// Creating table query | ||
private static final String CREATE_TABLE = "create table " + TABLE_NAME + "(" + _ID | ||
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + NAME + " TEXT NOT NULL, " + SEQUENCE + " TEXT, " + MODE +" INTEGER);"; | ||
|
||
public DatabaseHelper(Context context) { | ||
super(context, DB_NAME, null, DB_VERSION); | ||
} | ||
|
||
@Override | ||
public void onCreate(SQLiteDatabase db) { | ||
db.execSQL(CREATE_TABLE); | ||
} | ||
|
||
@Override | ||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | ||
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); | ||
onCreate(db); | ||
} | ||
} | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.aditya.hopon; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.appcompat.widget.Toolbar; | ||
import androidx.cursoradapter.widget.SimpleCursorAdapter; | ||
|
||
import android.content.ContentValues; | ||
import android.content.SharedPreferences; | ||
import android.database.Cursor; | ||
import android.os.Bundle; | ||
import android.view.MenuItem; | ||
import android.widget.AdapterView; | ||
import android.widget.ListView; | ||
import android.widget.TextView; | ||
|
||
public class patternsActivity extends AppCompatActivity { | ||
private TextView toolbartitle; | ||
private DBManager dbManager; | ||
private ListView listView; | ||
private SimpleCursorAdapter adapter; | ||
final String[] from = new String[] { DatabaseHelper._ID, | ||
DatabaseHelper.NAME, DatabaseHelper.SEQUENCE,DatabaseHelper.MODE}; | ||
final int[] to = new int[] { R.id.patternid, R.id.patternname, R.id.patternsequence , R.id.patternmode}; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_pattern); | ||
Toolbar toolbar = findViewById(R.id.pattern_toolbar); | ||
toolbar.setTitle("Patterns"); | ||
toolbartitle = findViewById(R.id.toolbar_title); | ||
toolbartitle.setText(""); | ||
setSupportActionBar(toolbar); | ||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||
SharedPreferences sharedPreferences=getSharedPreferences("sharedPrefs",MODE_PRIVATE); | ||
boolean firstStart=sharedPreferences.getBoolean("firstStart",true); | ||
dbManager = new DBManager(this); | ||
dbManager.open(); | ||
if(firstStart){ | ||
dbManager.insert("Regular","122426182A2C",1); | ||
SharedPreferences.Editor editor=sharedPreferences.edit(); | ||
editor.putBoolean("firstStart",false); | ||
editor.apply(); | ||
} | ||
Cursor cursor = dbManager.fetch(); | ||
|
||
listView = (ListView) findViewById(R.id.patterns_list); | ||
listView.setEmptyView(findViewById(R.id.emptytextpattern)); | ||
|
||
adapter = new SimpleCursorAdapter(this, R.layout.pattern_view_layout, cursor, from, to, 0); | ||
adapter.notifyDataSetChanged(); | ||
listView.setAdapter(adapter); | ||
|
||
} | ||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
switch (item.getItemId()) { | ||
case android.R.id.home: | ||
finish(); | ||
return true; | ||
} | ||
return super.onOptionsItemSelected(item); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item> | ||
<shape android:shape="rectangle"> | ||
<solid android:color="@color/white"/> | ||
<corners android:radius="1dp"/> | ||
</shape> | ||
</item> | ||
</selector> |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout 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" | ||
android:background="?attr/colorOnPrimary" | ||
tools:context=".patternsActivity"> | ||
<include | ||
android:id="@+id/pattern_toolbar" | ||
layout="@layout/toolbar" /> | ||
<ListView | ||
android:layout_below="@+id/pattern_toolbar" | ||
android:id="@+id/patterns_list" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:padding="10dp" | ||
android:dividerHeight="1dp"/> | ||
<TextView | ||
android:id="@+id/emptytextpattern" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerInParent="true" | ||
android:text="Empty"/> | ||
</RelativeLayout> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" android:layout_height="match_parent"> | ||
|
||
</RelativeLayout> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" > | ||
<TextView | ||
android:id="@+id/patternid" | ||
android:layout_width="25dp" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentTop="true" | ||
android:layout_marginRight="6dp" | ||
android:padding="3dp" | ||
android:visibility="visible" /> | ||
|
||
<TextView | ||
android:id="@+id/patternname" | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginLeft="10dp" | ||
android:layout_toRightOf="@id/patternid" | ||
android:maxLines="1" | ||
android:padding="3dp" | ||
android:textSize="17sp" | ||
android:textStyle="bold" /> | ||
|
||
<TextView | ||
android:id="@+id/patternsequence" | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/patternname" | ||
android:layout_marginLeft="10dp" | ||
android:layout_toRightOf="@id/patternid" | ||
android:ellipsize="end" | ||
android:maxLines="2" | ||
android:padding="3dp" | ||
android:visibility="visible" /> | ||
|
||
<TextView | ||
android:id="@+id/patternmode" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@+id/patternsequence" /> | ||
|
||
</RelativeLayout> |
This file contains 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