Apps Category

Apps Category (1)

Apps I've created

I just created a Android application. ??It's called "Physical Spiritual --- Priorities & Inspiration." ??An app where you state your priorities, rate them based on importance factors, & assign inspirational quotes to the priorities. ??Then receive notifications each day to inspire you with your most 'important' priority.

??

Here is the link to the app in the Google Play Store: ??https://play.google.com/store/apps/details?id=evans.awesome.rune_star.physpi

Check the Play Store for more images

??


??

Here's the code for the main activity. ??After that code is some SQLite I needed to implement for the app.

??

public class MainActivity extends AppCompatActivity {




?? ?? @Override

?? ?? protected void onCreate(Bundle savedInstanceState) {

?? ?? ?? ?? super.onCreate(savedInstanceState);

?? ?? ?? ?? setContentView(R.layout.activity_main);




?? ?? ?? ?? runMainActivity();

?? ?? }




?? ?? @Override

?? ?? protected void onRestart() {

?? ?? ?? ?? super.onRestart();

?? ?? ?? ?? runMainActivity();

?? ?? }




?? ?? protected void runMainActivity() {

?? ?? ?? ?? try {

?? ?? ?? ?? ?? ?? highestRankingPriority(); // Update the database with highest values each time main activity is run

?? ?? ?? ?? ?? ?? SQLiteOpenHelper PhySpiDBHelper = new PhySpiDatabaseHelper(this);

?? ?? ?? ?? ?? ?? SQLiteDatabase db = PhySpiDBHelper.getReadableDatabase();




?? ?? ?? ?? ?? ?? Cursor cursor = db.query ("PRIORITIES",

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? new String[] {"_id", "PRIORITY_NAME"},

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? null, null, null, null,null);




?? ?? ?? ?? ?? ?? ArrayList<String> priorityNames = new ArrayList<>();




?? ?? ?? ?? ?? ?? while (cursor.moveToNext()) {

?? ?? ?? ?? ?? ?? ?? ?? priorityNames.add(cursor.getString(1));

?? ?? ?? ?? ?? ?? }




?? ?? ?? ?? ?? ?? ListView priorityListView = (ListView)findViewById(R.id.test4093);




?? ?? ?? ?? ?? ?? ArrayAdapter priorityListAdapter = new PriorityRecordAdapter(

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? this,

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? R.layout.main_priority_adapter,

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? priorityNames

?? ?? ?? ?? ?? ?? );




?? ?? ?? ?? ?? ?? priorityListView.setAdapter(priorityListAdapter);




?? ?? ?? ?? ?? ?? cursor.close();

?? ?? ?? ?? ?? ?? db.close();

?? ?? ?? ?? } catch(SQLiteException e) {

?? ?? ?? ?? ?? ?? Toast toast = Toast.makeText(this, "Database unavailable", Toast.LENGTH_SHORT);

?? ?? ?? ?? ?? ?? toast.show();

?? ?? ?? ?? }




?? ?? ?? ?? Button addDeleteImportanceButton = (Button)findViewById(R.id.addDeleteImportanceButton);

?? ?? ?? ?? addDeleteImportanceButton.setOnClickListener(new View.OnClickListener() {

?? ?? ?? ?? ?? ?? //

?? ?? ?? ?? ?? ?? @Override

?? ?? ?? ?? ?? ?? public void onClick(View view) {




?? ?? ?? ?? ?? ?? ?? ?? Intent addPriorityIntent = new Intent();

?? ?? ?? ?? ?? ?? ?? ?? addPriorityIntent.setClassName("evans.awesome.rune_star.physpi", "evans.awesome.rune_star.physpi.AddDeleteImportanceFactorsActivity");

?? ?? ?? ?? ?? ?? ?? ?? startActivity(addPriorityIntent);

?? ?? ?? ?? ?? ?? ?? ?? Toast.makeText(view.getContext(), "Add Importance Factors", Toast.LENGTH_SHORT).show();

?? ?? ?? ?? ?? ?? }

?? ?? ?? ?? });

?? ?? ?? ?? Button addDeleteQuoteButton = (Button)findViewById(R.id.addDeleteQuoteButton);

?? ?? ?? ?? addDeleteQuoteButton.setOnClickListener(new View.OnClickListener() {

?? ?? ?? ?? ?? ?? //

?? ?? ?? ?? ?? ?? @Override

?? ?? ?? ?? ?? ?? public void onClick(View view) {




?? ?? ?? ?? ?? ?? ?? ?? Intent addPriorityIntent = new Intent();

?? ?? ?? ?? ?? ?? ?? ?? addPriorityIntent.setClassName("evans.awesome.rune_star.physpi", "evans.awesome.rune_star.physpi.AddDeleteInspirationQuotesActivity");

?? ?? ?? ?? ?? ?? ?? ?? startActivity(addPriorityIntent);

?? ?? ?? ?? ?? ?? ?? ?? Toast.makeText(view.getContext(), "Add Inspiration Quotes", Toast.LENGTH_SHORT).show();

?? ?? ?? ?? ?? ?? }

?? ?? ?? ?? });

?? ?? ?? ?? Button addDeletePriorityButton = (Button)findViewById(R.id.addDeletePriorityButton);

?? ?? ?? ?? addDeletePriorityButton.setOnClickListener(new View.OnClickListener() {

?? ?? ?? ?? ?? ?? //

?? ?? ?? ?? ?? ?? @Override

?? ?? ?? ?? ?? ?? public void onClick(View view) {




?? ?? ?? ?? ?? ?? ?? ?? Intent addPriorityIntent = new Intent();

?? ?? ?? ?? ?? ?? ?? ?? addPriorityIntent.setClassName("evans.awesome.rune_star.physpi", "evans.awesome.rune_star.physpi.AddDeletePriorityActivity");

?? ?? ?? ?? ?? ?? ?? ?? startActivity(addPriorityIntent);

?? ?? ?? ?? ?? ?? ?? ?? Toast.makeText(view.getContext(), "Add Priorities", Toast.LENGTH_SHORT).show();

?? ?? ?? ?? ?? ?? }

?? ?? ?? ?? });

?? ?? }




?? ?? // Sets up the Priority Names and their Ratings, as well as the buttons, 'Importance' and 'Inspiration', for each priority

?? ?? public class PriorityRecordAdapter extends ArrayAdapter<String> implements View.OnClickListener {




?? ?? ?? ?? private ArrayList<String> priorityNames = new ArrayList<>();

?? ?? ?? ?? public PriorityRecordAdapter(Context context, int textViewResourceId, ArrayList<String> priorityNames) {

?? ?? ?? ?? ?? ?? super(context, textViewResourceId, priorityNames);

?? ?? ?? ?? ?? ?? this.priorityNames = priorityNames;

?? ?? ?? ?? }




?? ?? ?? ?? @Override

?? ?? ?? ?? public int getCount() {

?? ?? ?? ?? ?? ?? return super.getCount();

?? ?? ?? ?? }




?? ?? ?? ?? @Override

?? ?? ?? ?? public View getView(int position, View convertView, ViewGroup parent) {

?? ?? ?? ?? ?? ?? View v = convertView;

?? ?? ?? ?? ?? ?? LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

?? ?? ?? ?? ?? ?? v = inflater.inflate(R.layout.main_priority_adapter, null);




?? ?? ?? ?? ?? ?? final String aPriority = priorityNames.get(position);

?? ?? ?? ?? ?? ?? TextView priorityName = (TextView) v.findViewById(R.id.priorityText);



?? ?? ?? ?? ?? ?? if (priorityName != null) {

?? ?? ?? ?? ?? ?? ?? ?? priorityName.setText(aPriority);

?? ?? ?? ?? ?? ?? }




?? ?? ?? ?? ?? ?? Button importanceButton = (Button) v.findViewById(R.id.importanceButton);

?? ?? ?? ?? ?? ?? importanceButton.setOnClickListener(new View.OnClickListener() {

?? ?? ?? ?? ?? ?? ?? ?? //

?? ?? ?? ?? ?? ?? ?? ?? @Override

?? ?? ?? ?? ?? ?? ?? ?? public void onClick(View view) {

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? Intent addPriorityIntent = new Intent();

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? addPriorityIntent.setClassName("evans.awesome.rune_star.physpi", "evans.awesome.rune_star.physpi.AssignImportanceActivity");

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? addPriorityIntent.putExtra("priority", aPriority);

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? getContext().startActivity(addPriorityIntent);

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? Toast.makeText(view.getContext(), "Assign Importance", Toast.LENGTH_SHORT).show();

?? ?? ?? ?? ?? ?? ?? ?? }

?? ?? ?? ?? ?? ?? });

?? ?? ?? ?? ?? ?? Button inspirationButton = (Button) v.findViewById(R.id.inspirationButton);

?? ?? ?? ?? ?? ?? inspirationButton.setOnClickListener(new View.OnClickListener() {

?? ?? ?? ?? ?? ?? ?? ?? //

?? ?? ?? ?? ?? ?? ?? ?? @Override

?? ?? ?? ?? ?? ?? ?? ?? public void onClick(View view) {

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? Intent addPriorityIntent = new Intent();

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? addPriorityIntent.setClassName("evans.awesome.rune_star.physpi", "evans.awesome.rune_star.physpi.AssignQuotesActivity");

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? addPriorityIntent.putExtra("priority", aPriority);

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? getContext().startActivity(addPriorityIntent);

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? Toast.makeText(view.getContext(), "Assign Inspirational Quotes", Toast.LENGTH_SHORT).show();

?? ?? ?? ?? ?? ?? ?? ?? }

?? ?? ?? ?? ?? ?? });

// ?? ?? ?? ??//Add in what rank the priority is before the actual priority text

?? ?? ?? ?? ?? ?? TextView priorityRating = (TextView) v.findViewById(R.id.priorityRating);

?? ?? ?? ?? ?? ?? if (priorityRating != null) {

?? ?? ?? ?? ?? ?? ?? ?? try {

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? SQLiteOpenHelper PhySpiDBHelper = new PhySpiDatabaseHelper(this.getContext());

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? SQLiteDatabase db = PhySpiDBHelper.getWritableDatabase();




?? ?? ?? ?? ?? ?? ?? ?? ?? ?? Cursor cursor = db.query ("PRIORITIES",

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? new String[] {"_id", "PRIORITY_NAME", "IMPORTANCE_AVG"},

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? "PRIORITY_NAME = ?",new String[]{aPriority}, null, null,null);




?? ?? ?? ?? ?? ?? ?? ?? ?? ?? if (cursor.getCount() > 0) {

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? cursor.moveToNext();

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? String rating = Float.toString(cursor.getFloat(2));

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? if (rating.equals("-1.0")) {

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? priorityRating.setText("Unrated");

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? } else {

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? priorityRating.setText(rating);

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? }

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? }

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? cursor.close();

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? db.close();

?? ?? ?? ?? ?? ?? ?? ?? } catch(SQLiteException e) {

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? Toast toast = Toast.makeText(this.getContext(), "DatabaseTree unavailable", Toast.LENGTH_SHORT);

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? toast.show();

?? ?? ?? ?? ?? ?? ?? ?? }

?? ?? ?? ?? ?? ?? }

?? ?? ?? ?? ?? ?? return v;

?? ?? ?? ?? }




?? ?? ?? ?? @Override

?? ?? ?? ?? public void onClick(View v) {




?? ?? ?? ?? }

?? ?? }

}

??


Here's the SQLite code

db.execSQL("CREATE TABLE PRIORITIES (_id INTEGER PRIMARY KEY AUTOINCREMENT, "

+ "PRIORITY_NAME TEXT UNIQUE, "

+ "IS_ACTIVE INTEGER, "

+ "IMPORTANCE_AVG REAL);");




db.execSQL("CREATE TABLE QUOTE_REPOSITORY (_id INTEGER PRIMARY KEY AUTOINCREMENT, "

+ "QUOTE TEXT UNIQUE);");




db.execSQL("CREATE TABLE PRIORITY_QUOTE (_id INTEGER PRIMARY KEY AUTOINCREMENT, "

+ "PRIORITY_NAME TEXT, "

+ "QUOTE TEXT, "

+ "FOREIGN KEY (PRIORITY_NAME) REFERENCES PRIORITIES (PRIORITY_NAME) ON UPDATE CASCADE ON DELETE CASCADE, "

+ "FOREIGN KEY (QUOTE) REFERENCES QUOTE_REPOSITORY (QUOTE) ON UPDATE CASCADE ON DELETE CASCADE);");




db.execSQL("CREATE TABLE IMPORTANCE_REPOSITORY (_id INTEGER PRIMARY KEY AUTOINCREMENT, "

+ "IMPORTANCE TEXT UNIQUE);");




db.execSQL("CREATE TABLE PRIORITY_IMPORTANCE (_id INTEGER PRIMARY KEY AUTOINCREMENT, "

+ "IMPORTANCE TEXT, "

+ "PRIORITY_NAME TEXT, "

+ "RATING TEXT, "

+ "FOREIGN KEY (PRIORITY_NAME) REFERENCES PRIORITIES (PRIORITY_NAME) ON UPDATE CASCADE ON DELETE CASCADE, "

+ "FOREIGN KEY (IMPORTANCE) REFERENCES IMPORTANCE_REPOSITORY (IMPORTANCE) ON UPDATE CASCADE ON DELETE CASCADE);");





public static long insertPriority(SQLiteDatabase db, String name,

??int isActive, Double importanceAvg) {

ContentValues priorityValues = new ContentValues();

priorityValues.put("PRIORITY_NAME", name);

priorityValues.put("IS_ACTIVE", isActive);

priorityValues.put("IMPORTANCE_AVG", importanceAvg);

//priorityValues.put("PRIORITY_IMAGE", image);

return db.insert("PRIORITIES", null, priorityValues);

}

public static long insertQuoteRepository(SQLiteDatabase db, String quote) {

ContentValues quoteRepositoryValues = new ContentValues();

quoteRepositoryValues.put("QUOTE", quote);

return db.insert("QUOTE_REPOSITORY", null, quoteRepositoryValues);

}

public static long insertQuotePriority(SQLiteDatabase db, String priorityName,

String quote) {

ContentValues quoteValues = new ContentValues();

quoteValues.put("PRIORITY_NAME", priorityName);

quoteValues.put("QUOTE", quote);

return db.insert("PRIORITY_QUOTE", null, quoteValues);

}

public static long insertImportanceRepository(SQLiteDatabase db, String importanceText) {

ContentValues importanceRepositoryValues = new ContentValues();

importanceRepositoryValues.put("IMPORTANCE", importanceText);

return db.insert("IMPORTANCE_REPOSITORY", null, importanceRepositoryValues);

}

public static long insertImportancePriority(SQLiteDatabase db, String importance, String priorityName, String rating) {

ContentValues priorityImportanceValues = new ContentValues();

priorityImportanceValues.put("IMPORTANCE", importance);

priorityImportanceValues.put("PRIORITY_NAME", priorityName);

priorityImportanceValues.put("RATING", rating);

return db.insert("PRIORITY_IMPORTANCE", null, priorityImportanceValues);

}
© 2015-2016 Evan Sevy. All Rights Reserved. Designed By Evan Sevy