Home » Newcomers » Newcomers » Need Help, cant seem to call INTENT on another class file
Need Help, cant seem to call INTENT on another class file [message #1710311] |
Mon, 05 October 2015 23:03  |
Eclipse User |
|
|
|
I have created an app that would do a to-do list with alarm and a simple alarm on the other one. i have coded all in the android manifest as stated:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
package="tmtl.planner"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme"
>
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AlarmListActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="tmtl.planner.AlarmListActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".AddAlarmActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="tmtl.planner.AddAlarmActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name=".SettingsActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MainMenu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="tmtl.planner.MainMenu" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MainActivityNotes"
android:label="@string/app_name" >
<intent-filter>
<action android:name="tmtl.planner.MainActivityNotes" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="tmtl.planner.AlarmScreen" />
<activity android:name="tmtl.planner.AlarmDetailsActivity" />
<receiver android:name="tmtl.planner.AlarmReceiver"></receiver>
<receiver android:name="tmtl.planner.AlarmSetter">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver android:name="tmtl.planner.AlarmManagerHelper" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="tmtl.planner.AlarmService2"
android:enabled="true"></service>
<service android:name="tmtl.planner.AlarmServices"></service>
</application>
</manifest>
the main activity for the to-do-list:
package tmtl.planner;
import java.util.Calendar;
import java.util.Date;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleCursorAdapter;
import android.widget.SimpleCursorAdapter.ViewBinder;
import android.widget.TextView;
import android.widget.Toast;
import tmtl.planner.R;
import tmtl.planner.model.Alarm;
import tmtl.planner.model.AlarmMsg;
public class MainActivityNotes extends ListActivity {
// private static final String TAG = "MainActivity";
private TextView headingText;
private TextView rangeText;
// private ViewSwitcher vs;
private SQLiteDatabase db;
private Typeface font;
private AlertDialog disclaimer;
public final Calendar cal = Calendar.getInstance();
public final Date dt = new Date();
private String[] monthArr;
private Alarm alarm = new Alarm();
private AlarmMsg alarmMsg = new AlarmMsg();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.mainnotes);
findViews();
db = RemindMe.db;
font = Typeface.createFromAsset(getAssets(), "fonts/OpenSans-Semibold.ttf");
headingText.setTypeface(font);
monthArr = getResources().getStringArray(R.array.spinner3_arr);
int r = RemindMe.getDateRange();
switch(r) {
case 3: // Yearly
cal.set(Calendar.MONTH, 0);
case 2: // Monthly
cal.set(Calendar.DATE, 1);
case 1: // Weekly
if (r==1) cal.set(Calendar.DATE, cal.getFirstDayOfWeek());
case 0: // Daily
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
}
registerForContextMenu(getListView());
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putLong("cal", cal.getTimeInMillis());
}
@Override
protected void onRestoreInstanceState(Bundle state) {
super.onRestoreInstanceState(state);
cal.setTimeInMillis(state.getLong("cal"));
}
private void findViews() {
headingText = (TextView) findViewById(R.id.heading_tv);
rangeText = (TextView) findViewById(R.id.range_tv);
// vs = (ViewSwitcher) findViewById(R.id.view_switcher);
}
private String getRangeStr() {
int date = cal.get(Calendar.DATE);
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
dt.setTime(System.currentTimeMillis());
switch(RemindMe.getDateRange()) {
case 0: // Daily
if (date==dt.getDate() && month==dt.getMonth() && year==dt.getYear()+1900) return "Today";
else return date+" "+monthArr[month+1];
case 1: // Weekly
return date+" "+monthArr[month+1] + move(+1) + " - " + cal.get(Calendar.DATE)+" "+monthArr[cal.get(Calendar.MONTH)+1] + move(-1);
case 2: // Monthly
return monthArr[month+1]+" "+year;
case 3: // Yearly
return year+"";
}
return null;
}
private Cursor createCursor() {
Cursor c = RemindMe.dbaseHelper.listNotifications(db, cal.getTimeInMillis()+move(+1), cal.getTimeInMillis()+move(-1));
startManagingCursor(c);
return c;
}
@Override
protected void onResume() {
super.onResume();
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
this,
R.layout.rows,
createCursor(),
new String[]{Alarm.COL_NAME, AlarmMsg.COL_DATETIME, AlarmMsg.COL_DATETIME, AlarmMsg.COL_DATETIME, AlarmMsg.COL_DATETIME},
new int[]{R.id.msg_tv, R.id.year_tv, R.id.month_tv, R.id.date_tv, R.id.time_tv});
adapter.setViewBinder(new ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (view.getId() == R.id.msg_tv) return false;
TextView tv = (TextView)view;
long time = cursor.getLong(columnIndex);
dt.setTime(time);
switch(view.getId()) {
case R.id.year_tv:
tv.setText(String.valueOf(dt.getYear()+1900));
break;
case R.id.month_tv:
tv.setText(monthArr[dt.getMonth()+1]);
break;
case R.id.date_tv:
tv.setText(String.valueOf(dt.getDate()));
break;
case R.id.time_tv:
long now = System.currentTimeMillis();
String txt = RemindMe.showRemainingTime() ? Util.getRemainingTime(time, now) : Util.getActualTime(dt.getHours(), dt.getMinutes());
if (TextUtils.isEmpty(txt)) txt = Util.getActualTime(dt.getHours(), dt.getMinutes());
tv.setText(txt);
RelativeLayout parent = (RelativeLayout)tv.getParent();
TextView tv2 = (TextView) parent.findViewById(R.id.msg_tv);
if (time < now) tv2.setTextColor(Color.parseColor("#555555"));
else tv2.setTextColor(Color.parseColor("#587498"));
break;
}
return true;
}
});
setListAdapter(adapter);
rangeText.setText(getRangeStr());
}
private String move(int step) {
switch(RemindMe.getDateRange()) {
case 0:
cal.add(Calendar.DATE, 1*step);
break;
case 1:
cal.add(Calendar.DATE, 7*step);
break;
case 2:
cal.add(Calendar.MONTH, 1*step);
break;
case 3:
cal.add(Calendar.YEAR, 1*step);
break;
}
return "";
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.imageButton1:
startActivity(new Intent(this, SettingsActivity.class));
break;
case R.id.imageButton2:
startActivity(new Intent(this, AddAlarmActivity.class));
break;
case R.id.imageButton3:
move(-1);
rangeText.setText(getRangeStr());
((SimpleCursorAdapter)getListAdapter()).changeCursor(createCursor());
break;
case R.id.imageButton4:
move(+1);
rangeText.setText(getRangeStr());
((SimpleCursorAdapter)getListAdapter()).changeCursor(createCursor());
break;
/* case R.id.toggleButton1:
vs.showNext();
break;*/
}
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
if (v.getId() == android.R.id.list) {
getMenuInflater().inflate(R.menu.context_menu, menu);
menu.setHeaderTitle("Choose an Option");
menu.setHeaderIcon(R.drawable.ic_dialog_menu_generic);
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
alarmMsg.setId(info.id);
alarmMsg.load(db);
if (alarmMsg.getDateTime() < System.currentTimeMillis())
menu.removeItem(R.id.menu_edit);
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
boolean refresh = false;
switch (item.getItemId()) {
case R.id.menu_edit:
alarmMsg.setId(info.id);
alarmMsg.load(db);
alarm.reset();
alarm.setId(alarmMsg.getAlarmId());
alarm.load(db);
showDialog(R.id.menu_edit);
break;
case R.id.menu_delete:
RemindMe.dbaseHelper.cancelNotification(db, info.id, false);
refresh = true;
Intent cancelThis = new Intent(this, AlarmServices.class);
cancelThis.putExtra(AlarmMsg.COL_ID, String.valueOf(info.id));
cancelThis.setAction(AlarmServices.CANCEL);
startService(cancelThis);
break;
case R.id.menu_delete_repeating:
alarmMsg.setId(info.id);
alarmMsg.load(db);
RemindMe.dbaseHelper.cancelNotification(db, alarmMsg.getAlarmId(), true);
refresh = true;
Intent cancelRepeating = new Intent(this, AlarmServices.class);
cancelRepeating.putExtra(AlarmMsg.COL_ALARMID, String.valueOf(alarmMsg.getAlarmId()));
cancelRepeating.setAction(AlarmServices.CANCEL);
startService(cancelRepeating);
break;
}
if (refresh) {
SimpleCursorAdapter adapter = (SimpleCursorAdapter) getListAdapter();
adapter.getCursor().requery();
adapter.notifyDataSetChanged();
}
return true;
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
openContextMenu(v);
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case R.id.menu_edit:
return new AlertDialog.Builder(this)
.setTitle("Edit")
.setView(getLayoutInflater().inflate(R.layout.edit, null))
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Dialog d = (Dialog) dialog;
EditText msgEdit = (EditText) d.findViewById(R.id.msg_et);
CheckBox soundCb = (CheckBox) d.findViewById(R.id.sound_cb);
alarm.setSound(soundCb.isChecked());
if (!TextUtils.isEmpty(msgEdit.getText())) {
alarm.setName(msgEdit.getText().toString());
alarm.persist(db);
SimpleCursorAdapter adapter = (SimpleCursorAdapter) getListAdapter();
adapter.getCursor().requery();
adapter.notifyDataSetChanged();
} else {
Toast.makeText(MainActivityNotes.this, "Enter a message", Toast.LENGTH_SHORT).show();
}
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.create();
}
return super.onCreateDialog(id);
}
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
super.onPrepareDialog(id, dialog);
switch (id) {
case R.id.menu_edit:
EditText msgEdit = (EditText) dialog.findViewById(R.id.msg_et);
CheckBox soundCb = (CheckBox) dialog.findViewById(R.id.sound_cb);
msgEdit.setText(alarm.getName());
soundCb.setChecked(alarm.getSound());
break;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.options_menu, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if (getListAdapter().isEmpty()) {
menu.findItem(R.id.menu_delete_all).setEnabled(false);
} else {
menu.findItem(R.id.menu_delete_all).setEnabled(true);
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_delete_all:
String startTime = cal.getTimeInMillis()+move(+1);
String endTime = cal.getTimeInMillis()+move(-1);
RemindMe.dbaseHelper.cancelNotification(db, startTime, endTime);
Intent cancelAll = new Intent(this, AlarmServices.class);
cancelAll.putExtra(Alarm.COL_FROMDATE, startTime);
cancelAll.putExtra(Alarm.COL_TODATE, endTime);
cancelAll.setAction(AlarmServices.CANCEL);
startService(cancelAll);
SimpleCursorAdapter adapter = (SimpleCursorAdapter) getListAdapter();
adapter.getCursor().requery();
adapter.notifyDataSetChanged();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onDestroy() {
if (disclaimer != null)
disclaimer.dismiss();
super.onDestroy();
}
}
and for the menu that separates the two apps together:
package tmtl.planner;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
public class MainMenu extends Activity implements OnClickListener {
Button btnAlarm;
Button btnNotes;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.setContentView(R.layout.menu);
btnAlarm = (Button)findViewById(R.id.alarm);
btnNotes = (Button)findViewById(R.id.notes);
btnAlarm.setOnClickListener(this);
btnNotes.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId()==R.id.alarm){
Intent intent = new Intent("tmtl.planner.AlarmListActivity");
startActivity(intent);
}
else if(v.getId()==R.id.notes){
Intent intent = new Intent("tmtl.planner.notes.MainActivityNotes");
startActivity(intent);
}
}
}
well this frustrates me for i am only a newbie when it comes to programming android. can someone please help me on this project? thanks
|
|
| |
Goto Forum:
Current Time: Sat Apr 19 15:02:14 EDT 2025
Powered by FUDForum. Page generated in 0.07138 seconds
|