Skip to content

Commit

Permalink
Adding missed calles feature
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurzaczek committed May 11, 2014
1 parent 4e66847 commit 399761c
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 11 deletions.
3 changes: 3 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<activity
android:name=".DialerActivity"
android:screenOrientation="portrait" />
<activity
android:name=".MissedCallsActivity"
android:screenOrientation="portrait" />
</application>

</manifest>
24 changes: 24 additions & 0 deletions res/layout/missedcalls.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView
android:id="@+id/txtMain"
style="@style/Main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="@string/missedcalls" />

<TextView
android:id="@+id/txtHelp"
style="@style/Help"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtMain"
android:gravity="center"
android:text="@string/main_help" />

</RelativeLayout>
5 changes: 2 additions & 3 deletions src/net/zaczek/launcherforblind/DialerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,11 @@ private void callCurrentNumber() {
// length.
say(getString(R.string.invalid_number));
} else {
StringBuilder sb = new StringBuilder();
sb.append(getString(R.string.you_are_about_to_dial));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < dialedNumber.length(); i++) {
sb.append(dialedNumber.charAt(i) + " ");
}
say(sb.toString());
Helper.confirmDial(this, sb.toString());
confirmed = true;
}
} else {
Expand Down
10 changes: 9 additions & 1 deletion src/net/zaczek/launcherforblind/Helper.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package net.zaczek.launcherforblind;

import net.zaczek.launcherforblind.activitysupport.AbstractActivity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class Helper {
public static boolean actuallyDial = true;


public static void confirmDial(AbstractActivity ctx, String label) {
StringBuilder sb = new StringBuilder();
sb.append(ctx.getString(R.string.you_are_about_to_dial));
sb.append(" " + label);
ctx.say(sb.toString());
}

public static void dial(Context ctx, String number) {
if (actuallyDial) {
ctx.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
Expand Down
4 changes: 2 additions & 2 deletions src/net/zaczek/launcherforblind/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ protected ListEntry[] getList() {
PhoneBookActivity.class),
new NavigatorListEntry(getString(R.string.dialer), this,
DialerActivity.class),
// new NavigatorListEntry(getString(R.string.missedcalls), this,
// null),
new NavigatorListEntry(getString(R.string.missedcalls), this,
MissedCallsActivity.class),
// new NavigatorListEntry(getString(R.string.sms), this, null),
new TimeListEntry(getString(R.string.currenttime),
getString(R.string.time_format)), };
Expand Down
66 changes: 66 additions & 0 deletions src/net/zaczek/launcherforblind/MissedCallsActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package net.zaczek.launcherforblind;

import net.zaczek.launcherforblind.activitysupport.AbstractCursorActivity;
import net.zaczek.launcherforblind.listentries.ListEntry;
import net.zaczek.launcherforblind.listentries.MissedCallListEntry;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CallLog;
import android.text.format.DateUtils;
import android.util.Log;
import android.widget.TextView;

public class MissedCallsActivity extends AbstractCursorActivity {
private static final String TAG = "launcherforblind";

private static final String[] PROJECTION = new String[] {
CallLog.Calls.CACHED_NAME, CallLog.Calls.NUMBER, CallLog.Calls.DATE };
private static final String SELECTION = CallLog.Calls.TYPE + " = " + CallLog.Calls.MISSED_TYPE;

private boolean confirmed = false;
private TextView txtMain;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "onCreate");
setContentView(R.layout.missedcalls);

txtMain = (TextView) findViewById(R.id.txtMain);
}

@Override
protected Cursor getCursor() {
Cursor c = managedQuery(CallLog.Calls.CONTENT_URI, PROJECTION, SELECTION, null,
CallLog.Calls.DEFAULT_SORT_ORDER);
return c;
}

@Override
protected ListEntry getListEntry(Cursor c) {
int time = c.getInt(2);
return new MissedCallListEntry(c.getString(0), c.getString(1),
DateUtils.formatElapsedTime(time));
}

@Override
protected void giveFeedback(String label) {
txtMain.setText(label);
confirmed = false;
}

@Override
protected void onDoubleTap() {
super.onDoubleTap();
final MissedCallListEntry current = (MissedCallListEntry)getCurrentListEntry();
if(current == null) return;

if (!confirmed) {
Helper.confirmDial(this, current.getLabel());
confirmed = true;
} else {
// actually dial
Helper.dial(this, current.getNumber());
}
}
}
5 changes: 1 addition & 4 deletions src/net/zaczek/launcherforblind/PhoneBookActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ protected void onDoubleTap() {
if(current == null) return;

if (!confirmed) {
StringBuilder sb = new StringBuilder();
sb.append(getString(R.string.you_are_about_to_dial));
sb.append(" " + current.getLabel());
say(sb.toString());
Helper.confirmDial(this, current.getLabel());
confirmed = true;
} else {
// actually dial
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void destroyTTS() {

private CharSequence cachedSaying;

protected void say(CharSequence something) {
public void say(CharSequence something) {
if (TextUtils.isEmpty(something))
return;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.zaczek.launcherforblind.listentries;

public class MissedCallListEntry extends AbstractListEntry {
String mNumber;
String mDate;

public MissedCallListEntry(String label, String number, String date) {
super(label);
mNumber = number;
mDate = date;
}

@Override
public String getLabelToSay() {
return getLabel() + ", " + mDate;
}

@Override
public void onSelected() {
}

public String getNumber() {
return mNumber;
}

@Override
public String getTextToSay() {
return null;
}
}

0 comments on commit 399761c

Please sign in to comment.