Skip to content

Commit

Permalink
second commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya committed Feb 28, 2021
1 parent 2b0a27c commit 5be8f53
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.+'
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aditya.hopon">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.HopOn">
<activity android:name=".UserGenActivity"></activity>
<activity android:name=".patternsActivity"></activity>
<activity android:name=".UserGenActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
62 changes: 62 additions & 0 deletions app/src/main/java/com/aditya/hopon/DBManager.java
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);
}

}

41 changes: 41 additions & 0 deletions app/src/main/java/com/aditya/hopon/DatabaseHelper.java
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);
}
}

12 changes: 12 additions & 0 deletions app/src/main/java/com/aditya/hopon/MainActivity.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand All @@ -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
Expand Down
63 changes: 63 additions & 0 deletions app/src/main/java/com/aditya/hopon/patternsActivity.java
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);
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/box.xml
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>
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@
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"
android:layout_marginTop="16dp"
app:cardElevation="8dp"
app:cardCornerRadius="8dp">
<LinearLayout
android:id="@+id/pattern_main_layout"
android:layout_width="match_parent"
android:layout_height="175dp"
android:orientation="vertical"
android:clickable="true"
android:background="@drawable/gradient_1"
android:weightSum="2">
<LinearLayout
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/res/layout/activity_pattern.xml
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>
5 changes: 5 additions & 0 deletions app/src/main/res/layout/fragment_emp_list.xml
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>
45 changes: 45 additions & 0 deletions app/src/main/res/layout/pattern_view_layout.xml
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>
1 change: 1 addition & 0 deletions app/src/main/res/layout/toolbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
Expand Down

0 comments on commit 5be8f53

Please sign in to comment.