diff --git a/app/build.gradle b/app/build.gradle index 75bc5f7..cb494b2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,6 +31,7 @@ android { dependencies { implementation 'androidx.appcompat:appcompat:1.2.0' + implementation "androidx.cursoradapter:cursoradapter:1.0.0" implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' testImplementation 'junit:junit:4.+' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7cc09d3..0aca463 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,9 @@ + + + - + + diff --git a/app/src/main/java/com/aditya/hopon/DBManager.java b/app/src/main/java/com/aditya/hopon/DBManager.java new file mode 100644 index 0000000..20822c3 --- /dev/null +++ b/app/src/main/java/com/aditya/hopon/DBManager.java @@ -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); + } + +} + diff --git a/app/src/main/java/com/aditya/hopon/DatabaseHelper.java b/app/src/main/java/com/aditya/hopon/DatabaseHelper.java new file mode 100644 index 0000000..818b804 --- /dev/null +++ b/app/src/main/java/com/aditya/hopon/DatabaseHelper.java @@ -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); + } +} + diff --git a/app/src/main/java/com/aditya/hopon/MainActivity.java b/app/src/main/java/com/aditya/hopon/MainActivity.java index 6eec00e..9442d0e 100644 --- a/app/src/main/java/com/aditya/hopon/MainActivity.java +++ b/app/src/main/java/com/aditya/hopon/MainActivity.java @@ -1,11 +1,14 @@ package com.aditya.hopon; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.View; import android.widget.Button; +import android.widget.LinearLayout; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; @@ -16,6 +19,7 @@ public class MainActivity extends AppCompatActivity { public static final String SHARED_PREFS="sharedPrefs"; public static final String enable_dark_mode="enabledarkmode"; private boolean darkmodetoggle; + private LinearLayout patternmainlayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -30,6 +34,14 @@ protected void onCreate(Bundle savedInstanceState) { Toolbar toolbar=findViewById(R.id.main_toolbar); toolbar.setTitle(""); setSupportActionBar(toolbar); + patternmainlayout=findViewById(R.id.pattern_main_layout); + patternmainlayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent=new Intent(MainActivity.this,patternsActivity.class); + startActivity(intent); + } + }); } @Override diff --git a/app/src/main/java/com/aditya/hopon/patternsActivity.java b/app/src/main/java/com/aditya/hopon/patternsActivity.java new file mode 100644 index 0000000..5a27373 --- /dev/null +++ b/app/src/main/java/com/aditya/hopon/patternsActivity.java @@ -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); + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/box.xml b/app/src/main/res/drawable/box.xml new file mode 100644 index 0000000..4bf4dbd --- /dev/null +++ b/app/src/main/res/drawable/box.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index b1b60ee..79aafc6 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -25,7 +25,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_rowWeight="1" - android:clickable="true" android:layout_columnWeight="1" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" @@ -33,9 +32,11 @@ app:cardElevation="8dp" app:cardCornerRadius="8dp"> + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_emp_list.xml b/app/src/main/res/layout/fragment_emp_list.xml new file mode 100644 index 0000000..8469a44 --- /dev/null +++ b/app/src/main/res/layout/fragment_emp_list.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/pattern_view_layout.xml b/app/src/main/res/layout/pattern_view_layout.xml new file mode 100644 index 0000000..4ff1cc9 --- /dev/null +++ b/app/src/main/res/layout/pattern_view_layout.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/toolbar.xml b/app/src/main/res/layout/toolbar.xml index d315cf7..ff07877 100644 --- a/app/src/main/res/layout/toolbar.xml +++ b/app/src/main/res/layout/toolbar.xml @@ -7,6 +7,7 @@ android:elevation="4dp" android:theme="@style/ThemeOverlay.AppCompat.ActionBar">