Making a simple email application - android

So the story is that basically, I'm making a very simple app so that my place of employment can send the closing logs every night with ease. I have all of the text boxes to enter the information, and then at the bottom there is a checkbox and submit like so..
There is a template for the email that we edit manually every night, and basically I want to take all of the information received in the text boxes (all have their own ID, etc.) and plug it into the email template that I currently have - and send it to the emails of the employees (6 people).
Can someone lead me in the right direction, or show me how I would go about this problem?
MainActivity.java
package savo.nicholas.bestb;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
I've constructed a bunch of these to get the values from the form. I'm looking to plug these values into a pre-formatted email and send them.
public EditText getGm() //$ of GM
{
return (EditText)findViewById(R.id.gm);
}
Thanks!
Nick

Related

I can't see my logs in Android Studio logcat

Here's a simple app, I'm trying to create logs in the printToLogs method.
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.v("Log0","test");
}
public void printToLogs(View view){
TextView menuTextView1 = findViewById(R.id.menu_item_1);
TextView menuTextView2 = findViewById(R.id.menu_item_2);
TextView menuTextView3 = findViewById(R.id.menu_item_3);
String item1 = (String) menuTextView1.getText();
String item2 = (String) menuTextView2.getText();
String item3 = (String) menuTextView3.getText();
Log.v("Log1",item1);
Log.v("Log2",item2);
Log.v("Log3",item3);
}
but logs with the tags Log1, Log2, Log3 are not shown at all in the logcat, what does show up is the Log0 in the onCreate method, but the other ones in printToLogs never show up when I search for them at all. I attempted re-installing the app and restarting logging. That didn't work.
The menu items are: Mango sorbet, Blueberry pie, Chocolate lava cake. And yes, I tried searching for them, and they are not in the logcat either.
If this is your actual code, you aren't even calling printToLogs in the onCreate method. You should be more diligent before posting something simple like this.
Barring a serious runtime environment issue, this problem should be fairly easy to solve.
It seems as if the printToLogs(View view) method is to be executed in response to the user clicking a button. If so, try including the following line in your activity_main.xml if you haven't already:
android:onClick="printToLogs"
This will bind the button on the UI with the printToLogs(View view) method.
If, on the other hand, printToLogs(View view) is intended to be a standalone method (i.e. one that should execute regardless of user input) it should not accept a View as an argument. For your purposes, its parameter list should be completely empty. In other words, the method signature should read:
public void printToLogs()
Also, it should be called within the onCreate(Bundle savedInstances) method. Add the following to the onCreate(Bundle savedInstances) method:
printToLogs();
This will initiate the execution of the method as soon as the app begins to run.
Make sure the logcat filter is set to "Verbose" when testing like so: (img is link since apparently I need 10 rep. to embed images into answers directly)
logcat filter
heyy add your method/function name in your button by using property section or just android:onClick in your xml file and then it will be solved

Android Studio - JavaDoc comments not generating

I have one problem with the comments in Android Studio.
My template file (File Header) Is like this:
/**
* Created by ${USER} on ${DATE}.
*/
When I create new class, or Interface my comment header gets automatically generated, and this works.
But when I generate: activity, fragment, application, services, the comment does not generate. I really do not know where is the problem.
Here is the Activity template description. But when I create new Activity, the comment does not appear, and every time I need to retype it.
package ${PACKAGE_NAME};
import android.app.Activity;
import android.os.Bundle;
#parse("File Header.java")
public class ${NAME} extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
Thanks!
To generate comments type /** above the method name and press enter. You can also use a tool under Android Studio menu:
Tools > Generate JavaDoc

how to fill string arraylist with userinput EditText android eclipse

i am beginner in android programming and English language :) !!
i want to get names from user and show the names that user inputs randomly by pressing a button.
how can i store a user input names in a array list?
and As regards I don't know how many names he wants to enter and don't show a name twice and after showing the name erase that name in array list.
tanks a LOT.
package farshid.mk.teststringarraylist;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class StringArraylistActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ArrayList<String> inputs = new ArrayList<String>();
Well, there are many ways to do this but one would be:
Create an EditText, a view that allows user input
Create a Button that the user would click to indicate that he/she is done entering the name in the EditText
Create an OnClickHanlder for the button so that you can get the text from the EditText, convert it to a String (EditText returns an Editable object), and add it to your ArrayList<String>
// add the string
myArrayList.add(myEditText.getText().toString().trim());
To remove duplicates from the List you will need to convert it to a Set... google "java arraylist remove duplicates (First Link)
Also, in Java, it's best practice to use Generics:
// psuedocode
List inputs = new ArrayList
There are many ways you could display this list of text to the user in Android, you will need to research that on your own.
You simply clear the ArrayList when you are done with the names.
This should get you going =)
There's a lot of things you'd need to do to achieve this:
Define the EditText in your layout's XML.
Get a reference to it from the Activity by calling findViewById(R.id.your_edittext_id).
From that reference, call getText().toString() to get the value from the EditText.
Add that String to your ArrayList.
That's basically the main idea behind what you're trying to achieve. I could give you the code but then perhaps its best for you to do it yourself (so that the next time you need to do this, you'd understand the concept).
Good luck! :)

Collect device data on android regularly

I managed to create an application that collects basic info from the device like android version,CPU,total RAM,free RAM,etc. Some of the data i need to collect is dynamic so i want my application to collect that data every minute.I also want my application to do so in the background. Here is how my code is setup:
public class Sniffer extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sniffer);
model_device=(TextView) findViewById(R.id.model1);
versiune_android=(TextView) findViewById(R.id.versiune1);
total_RAM=(TextView) findViewById(R.id.total_RAM1);
free_RAM=(TextView) findViewById(R.id.free_RAM1);
total_disk=(TextView) findViewById(R.id.total_disk1);
free_disk=(TextView) findViewById(R.id.free_disk1);
CPU=(TextView) findViewById(R.id.CPU1);
nivel_baterie=(TextView) findViewById(R.id.baterie1);
//get the requested data and set the corresponding text
getDeviceData();
}
Inside getDeviceData i read the /proc files and whatnot to obtain everything. Can i create a service that can run in the background and every x minutes update the data by calling getDeviceData again ? Let's take this scenario : start my app,check the data, leave app on, go check my email, listen to a song on youtube then i come back to my app (without closing it)and the collected data should have changed. How would i go about doing so using a service, i think this is the best solution. I need just a bump in the right direction, maybe a skeleton code on where my stuff should go. Thanks

Show different TextView's depending on the time of the day

I'm new to develop Android Apps and writing java. But, I only want to make a simple app that will give a different output on TextView depending on what time of the day it is.
F.ex. If the time is between 06:45 and 08:45 I want it to say "Good Morning", and so forth.
I have been playing with Eclipse and created a simple WebView-app but I can't seem to find any information to either choose which TextView I want shown on a specific time or show a different layout.
Do you have any tips?
This is my .java file in src for now.
package com.wao.texttime;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class TextTime extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv1 = (TextView) findViewById(R.id.TextView01);
tv1.setText("Good Morning");
}
}
There is no need to switch between different TextViews. If you just want to display different messages in your TextView I would simply call the setText function to update the TextView's text attribute.

Categories

Resources